We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
XuperChain使用Go-SDK调用模板合约“文件hash上链时,更改文件hash_id后仍出现”such hash has existed already的报错 image 我在“工作台”中“合约管理”中调用中修改不同的hash_id均成功了,但是在本地调用时修改不同的hash_id出现了such hash has existed already的报错 智能合约中的存证函数如下: void storeFileInfo() { xchain::Context* ctx = this->context(); std::string user_id = ctx->arg("user_id"); std::string hash_id = ctx->arg("hash_id"); std::string file_name = ctx->arg("file_name"); const std::string userKey = UserBucket + "/" + user_id + "/" + hash_id; const std::string hashKey = HashBucket + "/" + hash_id; std::string value = user_id + "\t" + hash_id + "\t" + file_name; std::string tempVal; if (ctx->get_object(hashKey, &tempVal)) { ctx->error("storeFileInfo failed, such hash has existed already"); return; } if (ctx->put_object(userKey, value) && ctx->put_object(hashKey, value)) { ctx->ok("storeFileInfo success"); return; } ctx->error("storeFileInfo failed"); } 后续更新: 去除了智能合约中的唯一性约束代码: if (ctx->get_object(hashKey, &tempVal)) { ctx->error("storeFileInfo failed, such hash has existed already"); return; 多次使用不同的hash_id运行成功,两次使用相同的hash_id上链存储也成功运行。但是实际的区块链存证业务场景中要求对存证文件的唯一性约束,请问错误是处在SDK上还是智能合约上?
The text was updated successfully, but these errors were encountered:
合约执行逻辑与SDK无关,问题应该出在合约上
Sorry, something went wrong.
No branches or pull requests
XuperChain使用Go-SDK调用模板合约“文件hash上链时,更改文件hash_id后仍出现”such hash has existed already的报错
image
我在“工作台”中“合约管理”中调用中修改不同的hash_id均成功了,但是在本地调用时修改不同的hash_id出现了such hash has existed already的报错
智能合约中的存证函数如下:
void storeFileInfo() {
xchain::Context* ctx = this->context();
std::string user_id = ctx->arg("user_id");
std::string hash_id = ctx->arg("hash_id");
std::string file_name = ctx->arg("file_name");
const std::string userKey = UserBucket + "/" + user_id + "/" + hash_id;
const std::string hashKey = HashBucket + "/" + hash_id;
std::string value = user_id + "\t" + hash_id + "\t" + file_name;
std::string tempVal;
if (ctx->get_object(hashKey, &tempVal)) {
ctx->error("storeFileInfo failed, such hash has existed already");
return;
}
if (ctx->put_object(userKey, value) && ctx->put_object(hashKey, value)) {
ctx->ok("storeFileInfo success");
return;
}
ctx->error("storeFileInfo failed");
}
后续更新:
去除了智能合约中的唯一性约束代码:
if (ctx->get_object(hashKey, &tempVal)) {
ctx->error("storeFileInfo failed, such hash has existed already");
return;
多次使用不同的hash_id运行成功,两次使用相同的hash_id上链存储也成功运行。但是实际的区块链存证业务场景中要求对存证文件的唯一性约束,请问错误是处在SDK上还是智能合约上?
The text was updated successfully, but these errors were encountered: