- account_name to std:string
auto username = name{from};
std::string from_name = username.to_string();
- std::string to account_name
account_name from_name = string_to_name(username);
auto username = name{from};
std::string from_name = username.to_string();
account_name from_name = string_to_name(username);
I have a simple struct with one member and want to pass this to an action.
struct field {
bool is_private;
};
// @abi action
// Create a new profile
void create(const account_name& account, const field& first_name);
The .abi looks like this:
"structs": [{
"name": "field",
"base": "",
"fields": [{
"name": "is_private",
"type": "bool"
}
]
},{
"name": "create",
"base": "",
"fields": [{
"name": "account",
"type": "name"
},{
"name": "first_name",
"type": "field"
}
]
}
...
I tried a lot of different variations along the lines of cleos push action "contract" "create" '[acc_name, {"is_private": "true"}]' -p acc_name@active. But none of them seem to work. Are structs supported and if yes how do you pass the argument?
Thanks a lot!
Found the solution myself. You have to recreate the .abi structure in json:
cleos push action contract create '{"account":"acc_name","first_name":{"is_private":true"}}' -p acc_name@active
麒麟测试网部署测试合约时出现一下错误
suroudeMacBook-Pro:contracts surou$ cleos -u http://api.kylin.eosbeijing.one:8880 get table cryptokylinq cryptokylinq results
2018-10-10T14:09:41.215 thread-0 main.cpp:3143 main ] Failed with error: Out of Range (8)
read datastream of length 9 over by 1
开始部署合约中表的结构为
//@abi table results i64
struct approval_info{
account_name name;
uint8_t iresult;
uint64_t primary_key()const { return name; }
EOSLIB_SERIALIZE(approval_info, (name)(iresult))
};
typedef eosio::multi_index<N(results),approval_info> result_table;
然后直接修改了 iresult
为std::string
//@abi table results i64
struct approval_info{
account_name name;
std::string iresult;
uint64_t primary_key()const { return name; }
EOSLIB_SERIALIZE(approval_info, (name)(iresult))
};
typedef eosio::multi_index<N(results),approval_info> result_table;
由于前面合约已部署,就像数据库中表字段的类型已经建好了,下次再部署时,导致表错乱,所以改个表名或者重新部署个账号测试把。等后面发现好的办法再跟帖