cleos create account を調べる
目的
cleos create account を cleos push action でやってみる。
環境
nodeos v1.5.0
eosio.cdt v1.4.1
はじめに
※テストネットなどで行いたい場合や、違うアカウント名を使いたい場合は適宜読み替えてください。
※メインネットやテストネットのアカウント名は原則12文字です。
新しく charlie のアカウントを cleos のコマンドで作ってみます。
code:invoke01.sh
cleos create account alice charlie EOS7hnP2sZGr2DAwfL5fSZ8btYF99gjmeEBbKftFeWWhG4jSK3zRo
code:response01.txt
executed transaction: 15830e259905d60ddd31b6a29e7cde6daeaa361b30dbe5299bf66ddb10698516 200 bytes 464 us
# eosio <= eosio::newaccount {"creator":"alice","name":"charlie","owner":{"threshold":1,"keys":[{"key":"EOS7hnP2sZGr2DAwfL5fSZ8bt...
warning: transaction executed locally, but may not be confirmed by the network yet ]
トランザクションの詳細を見ます。executed transaction の後ろに書いてある数字がトランザクションの ID です。
code:invoke02.sh
cleos get transaction 15830e259905d60ddd31b6a29e7cde6daeaa361b30dbe5299bf66ddb10698516
code:response02.json
{
"id": "15830e259905d60ddd31b6a29e7cde6daeaa361b30dbe5299bf66ddb10698516",
"trx": {
"trx": {
"actions": [{
"account": "eosio",
"name": "newaccount",
"authorization": [{
"actor": "alice",
"permission": "active"
}
],
"data": {
"creator": "alice",
"name": "charlie",
"owner": {
"threshold": 1,
"keys": [{
"key": "EOS7hnP2sZGr2DAwfL5fSZ8btYF99gjmeEBbKftFeWWhG4jSK3zRo",
"weight": 1
}
],
"accounts": [],
"waits": []
},
"active": {
"threshold": 1,
"keys": [{
"key": "EOS7hnP2sZGr2DAwfL5fSZ8btYF99gjmeEBbKftFeWWhG4jSK3zRo",
"weight": 1
}
],
"accounts": [],
"waits": []
}
}
}
]
}
}
}
※いらない部分を削ぎ落としています。
この JSON を和訳すると、
eosio アカウントにある newaccount アクションを eosio@active の権限で呼び出し、creator, name, owner, active という4つの引数を渡しています。
owner と active には、 threshold, keys, accounts, waits という4つのキーをもつオブジェクトが入っています。これは、authority 構造体のオブジェクトです。"eosio authority struct" でググると、
がヒットすると思うので、中を見て、構造体に関する部分を抜き出してみます。足りない情報はさらに検索します。
code:authority-struct.cpp
typedef uint16_t weight_type;
typedef uint64_t account_name;
typedef uint64_t permission_name;
struct authority {
uint32_t threshold;
vector<key_weight> keys;
vector<permission_level_weight> accounts;
vector<wait_weight> waits;
};
struct key_weight {
public_key key;
weight_type weight;
};
struct public_key {
};
struct permission_level_weight {
permission_level permission;
weight_type weight;
};
struct permission_level {
account_name actor;
permission_name permission;
}
struct wait_weight {
uint32_t wait_sec;
weight_type weight;
};
さて、先ほどのトランザクションを真似すれば、cleos create account を使わなくてもアカウントを作ることができます。
code:invoke03.sh
cleos push action eosio newaccount '["alice","dave",{"threshold":1,"keys":{"key":"EOS7hnP2sZGr2DAwfL5fSZ8btYF99gjmeEBbKftFeWWhG4jSK3zRo","weight":1},"accounts":[],"waits":[]},{"threshold":1,"keys":{"key":"EOS7hnP2sZGr2DAwfL5fSZ8btYF99gjmeEBbKftFeWWhG4jSK3zRo","weight":1},"accounts":[],"waits":[]}]' -p alice@active code:response03.txt
executed transaction: 88d97023269a1de5bdc004479850d9558ddba695cc334932aff4aa1e0bb11186 200 bytes 753 us
# eosio <= eosio::newaccount {"creator":"alice","name":"dave","owner":{"threshold":1,"keys":[{"key":"EOS7hnP2sZGr2DAwfL5fSZ8btYF9...
warning: transaction executed locally, but may not be confirmed by the network yet ]
authority 構造体を定義したコントラクトの中で、アカウントを作るインラインアクションを行うこともできますが、ここでは省略します。
関連ワード