xuperchain / xuperchain

A highly flexible blockchain architecture with great transaction performance.

Home Page:https://xuper.baidu.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

部署wasm合约报错

YOURCarl opened this issue · comments

Brief of the issue
使用xchain-cli指令部署wasm合约时,出现报错如下错误:contract error status:500 message:missing owner address

Your environment
使用的windows子系统Ubuntu(WSL2)
XuperChain-master
go version go1.13.4 linux/amd64
gcc version 11.3.0 (Ubuntu 11.3.0-1ubuntu1~22.04)

请问下这个500错误怎么解决

commented

把合约代码和执行步骤贴一下吧

都是按照官方文档进行的操作,运行:
$ xchain-cli wasm deploy --account XC3106491690191722@xuper --cname hello --fee 5200000 --runtime c ./hello.wasm

contract error status:500 message:missing creator

合约代码也是用的官方的contract-sdk-cpp/example/counter.cc编译得的wasm

cft@Cheery-PC:~/XuperChain/xuperchain-master/output$ sh control.sh start
/home/cft/XuperChain/xuperchain-master/output/bin/xchain
/home/cft/XuperChain/xuperchain-master/output/conf/env.yaml
start xchain. cmd:nohup /home/cft/XuperChain/xuperchain-master/output/bin/xchain startup --conf /home/cft/XuperChain/xuperchain-master/output/conf/env.yaml >/home/cft/XuperChain/xuperchain-master/output/logs/nohup.out 2>&1 &
.start proc succ.
start finish.pid:25915
Done!

cft@Cheery-PC:~/XuperChain/xuperchain-master/output$ xchain-cli account new --account 3106491690191722 --fee 2000
contract response:
{
"pm": {
"rule": 1,
"acceptValue": 1.0
},
"aksWeight": {
"TeyyPLpp9L7QAcxHangtcHTu7HUZ6iydY": 1.0
}
}

The gas you cousume is: 1000
The fee you pay is: 2000
Tx id: dee315fff39f790da066fcddd850e7c578361d7b67755c6242dca7cb632ec587
account name: XC3106491690191722@xuper

cft@Cheery-PC:~/XuperChain/xuperchain-master/output$ xchain-cli transfer --to XC3106491690191722@xuper --amount 520000000
827f8c11f8217b7eff4a3cded91ec3fc3c32efb7d9e3d8cc1d5391ac9cebef48

cft@Cheery-PC:~/XuperChain/xuperchain-master/output$ xchain-cli wasm deploy --account XC3106491690191722@xuper --cname hello --fee 5200000 --runtime c ./hello.wasm
contract error status:500 message:missing creator

cft@Cheery-PC:~/XuperChain/xuperchain-master/output$ cat /home/cft/DJ_Work/xdev-code/hello/src/main.cc
#include "xchain/xchain.h"

struct Counter : public xchain::Contract {};

DEFINE_METHOD(Counter, initialize) {
xchain::Context* ctx = self.context();
const std::string& creator = ctx->arg("creator");
if (creator.empty()) {
ctx->error("missing creator");
return;
}
ctx->put_object("creator", creator);
ctx->ok("initialize succeed");
}

DEFINE_METHOD(Counter, increase) {
xchain::Context* ctx = self.context();
const std::string& key = ctx->arg("key");
std::string value;
ctx->get_object(key, &value);
int cnt = 0;
cnt = atoi(value.c_str());
ctx->logf("get value %s -> %d", key.c_str(), cnt);
char buf[32];
snprintf(buf, 32, "%d", cnt + 1);
ctx->put_object(key, buf);

ctx->emit_event("increase", buf);

ctx->ok(buf);

}

DEFINE_METHOD(Counter, get) {
xchain::Context* ctx = self.context();
const std::string& key = ctx->arg("key");
std::string value;
if (ctx->get_object(key, &value)) {
ctx->ok(value);
} else {
ctx->error("key not found");
}
}

commented

DEFINE_METHOD(Counter, initialize) {
xchain::Context* ctx = self.context();
const std::string& creator = ctx->arg("creator");
if (creator.empty()) {
ctx->error("missing creator");
return;
}
ctx->put_object("creator", creator);
ctx->ok("initialize succeed");
}

看代码逻辑,你是不是调用时没有传入参数(-a) creator