Skip to content

XuperChain使用Go-SDK调用模板合约“文件hash上链时,更改文件hash_id后仍出现”such hash has existed already的报错 #75

Description

@husun001

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上还是智能合约上?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions