我正在使用 eos.cdt v1.3.2 处理智能合约。我已经尝试尽可能地重构以跟上 eos.cdt 中所做的更改。这是合同:
#include <eosiolib/eosio.hpp>
#include <eosiolib/name.hpp>
using namespace eosio;
using namespace std;
class addressbook: contract {
struct address {
uint64_t account_name;
string first_name;
string last_name;
string street;
string city;
string state;
auto primary_key() const { return account_name; }
EOSLIB_SERIALIZE( address, (account_name)(first_name)(last_name)(street)(city)(state) )
};
public:
using contract::contract;
addressbook(name receiver, name code, datastream<const char*> ds):contract(receiver, code, ds) {}
typedef eosio::multi_index< "address"_n, address > address_index;
void myaction() {
address_index addresses(_code, _code.value); // code, scope
// add to table, first argument is account to bill for storage
addresses.emplace(_self, [&](auto& address) {
address.account_name = name("foo");
address.first_name = "Daniel";
address.last_name = "Larimer";
address.street = "1 EOS Way";
address.city = "Blacksburg";
address.state = "VA";
});
auto user = addresses.get(name("foo"));
eosio_assert(user.first_name == "Daniel", "Couldn't get him.");
}
}
EOSIO_ABI( addressbook, (myaction) )
当我尝试从命令行编译时,我收到以下错误消息:
get.cpp:34:33: error: no viable conversion from 'eosio::name' to 'uint64_t' (aka
'unsigned long long')
auto user = addresses.get(name("foo"));
^~~~~~~~~~~
/usr/local/eosio.cdt/bin/../include/eosiolib/name.hpp:131:17: note: candidate
function
constexpr operator raw()const { return raw(value); }
^
/usr/local/eosio.cdt/bin/../include/eosiolib/multi_index.hpp:1963:30: note:
passing argument to parameter 'primary' here
const T& get( uint64_t primary, const char* error_msg = "unable t...
^
get.cpp:38:26: error: C++ requires a type specifier for all declarations
EOSIO_ABI( addressbook, (myaction) )
^
get.cpp:38:37: error: expected function body after function declarator
EOSIO_ABI( addressbook, (myaction) )
^
get.cpp:27:32: error: assigning to 'uint64_t' (aka 'unsigned long long') from
incompatible type 'eosio::name'
address.account_name = name("foo");
^~~~~~~~~~~
/usr/local/eosio.cdt/bin/../include/eosiolib/multi_index.hpp:1691:13: note: in
instantiation of function template specialization
'addressbook::myaction()::(anonymous
class)::operator()<addressbook::address>' requested here
constructor( obj );
^
get.cpp:26:17: note: in instantiation of function template specialization
'eosio::multi_index<3626371193025593344,
addressbook::address>::emplace<(lambda at get.cpp:26:32)>' requested here
addresses.emplace(_self, [&](auto& address) {
^
4 errors generated.
我最关心的是 get.cpp:34:33: 错误消息:没有可行的从 'eosio::name' 到 'uint64_t' (又名'unsigned long long')的转换,因为这个消息是由于eos.cbt 的变化。但是,似乎没有关于如何纠正此问题的解决方案。有没有人能够解决这个问题?