Skip to content

Commit

Permalink
Merge branch 'main' into http_max_inflight_reqs
Browse files Browse the repository at this point in the history
  • Loading branch information
linh2931 authored Jun 28, 2022
2 parents 234ed11 + 609f55d commit c0d4b9e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
34 changes: 20 additions & 14 deletions programs/cleos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ using namespace eosio::client::http;
using namespace eosio::client::localize;
using namespace eosio::client::config;
using namespace boost::filesystem;
using auth_type = std::variant<public_key_type, permission_level>;

FC_DECLARE_EXCEPTION( explained_exception, 9000000, "explained exception, see error log" );
FC_DECLARE_EXCEPTION( localized_exception, 10000000, "an error occured" );
Expand Down Expand Up @@ -643,14 +642,14 @@ chain::permission_level to_permission_level(const std::string& s) {
return permission_level { name(s.substr(0, at_pos)), name(s.substr(at_pos + 1)) };
}

chain::action create_newaccount(const name& creator, const name& newaccount, auth_type owner, auth_type active) {
chain::action create_newaccount(const name& creator, const name& newaccount, authority owner, authority active) {
return action {
get_account_permissions(tx_permission, {creator,config::active_name}),
eosio::chain::newaccount{
.creator = creator,
.name = newaccount,
.owner = std::holds_alternative<public_key_type>(owner) ? authority(std::get<public_key_type>(owner)) : authority(std::get<permission_level>(owner)),
.active = std::holds_alternative<public_key_type>(active) ? authority(std::get<public_key_type>(active)) : authority(std::get<permission_level>(active))
.owner = owner,
.active = active
}
};
}
Expand Down Expand Up @@ -1121,8 +1120,8 @@ struct create_account_subcommand {
);
createAccount->add_option("creator", creator, localized("The name of the account creating the new account"))->required();
createAccount->add_option("name", account_name, localized("The name of the new account"))->required();
createAccount->add_option("OwnerKey", owner_key_str, localized("The owner public key or permission level for the new account"))->required();
createAccount->add_option("ActiveKey", active_key_str, localized("The active public key or permission level for the new account"));
createAccount->add_option("OwnerKey", owner_key_str, localized("The owner public key, permission level, or authority for the new account"))->required();
createAccount->add_option("ActiveKey", active_key_str, localized("The active public key, permission level, or authority for the new account"));

if (!simple) {
createAccount->add_option("--stake-net", stake_net,
Expand All @@ -1142,27 +1141,34 @@ struct create_account_subcommand {
add_standard_transaction_options(createAccount, "creator@active");

createAccount->callback([this] {
auth_type owner, active;

if( owner_key_str.find('@') != string::npos ) {
authority owner, active;
if( owner_key_str.find('{') != string::npos ) {
try{
owner = parse_json_authority_or_key(owner_key_str);
} EOS_RETHROW_EXCEPTIONS( explained_exception, "Invalid owner authority: ${authority}", ("authority", owner_key_str) )
} else if( owner_key_str.find('@') != string::npos ) {
try {
owner = to_permission_level(owner_key_str);
owner = authority(to_permission_level(owner_key_str));
} EOS_RETHROW_EXCEPTIONS( explained_exception, "Invalid owner permission level: ${permission}", ("permission", owner_key_str) )
} else {
try {
owner = public_key_type(owner_key_str);
owner = authority(public_key_type(owner_key_str));
} EOS_RETHROW_EXCEPTIONS( public_key_type_exception, "Invalid owner public key: ${public_key}", ("public_key", owner_key_str) );
}

if( active_key_str.empty() ) {
active = owner;
} else if( active_key_str.find('@') != string::npos ) {
} else if ( active_key_str.find('{') != string::npos ) {
try{
active = parse_json_authority_or_key(active_key_str);
} EOS_RETHROW_EXCEPTIONS( explained_exception, "Invalid active authority: ${authority}", ("authority", owner_key_str) )
}else if( active_key_str.find('@') != string::npos ) {
try {
active = to_permission_level(active_key_str);
active = authority(to_permission_level(active_key_str));
} EOS_RETHROW_EXCEPTIONS( explained_exception, "Invalid active permission level: ${permission}", ("permission", active_key_str) )
} else {
try {
active = public_key_type(active_key_str);
active = authority(public_key_type(active_key_str));
} EOS_RETHROW_EXCEPTIONS( public_key_type_exception, "Invalid active public key: ${public_key}", ("public_key", active_key_str) );
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Node.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def isTransFinalized(self, transId):
# Create & initialize account and return creation transactions. Return transaction json object
def createInitializeAccount(self, account, creatorAccount, stakedDeposit=1000, waitForTransBlock=False, stakeNet=100, stakeCPU=100, buyRAM=10000, exitOnError=False, additionalArgs=''):
cmdDesc="system newaccount"
cmd='%s -j %s %s %s %s --stake-net "%s %s" --stake-cpu "%s %s" --buy-ram "%s %s" %s' % (
cmd='%s -j %s %s \'%s\' \'%s\' --stake-net "%s %s" --stake-cpu "%s %s" --buy-ram "%s %s" %s' % (
cmdDesc, creatorAccount.name, account.name, account.ownerPublicKey,
account.activePublicKey, stakeNet, CORE_SYMBOL, stakeCPU, CORE_SYMBOL, buyRAM, CORE_SYMBOL, additionalArgs)
msg="(creator account=%s, account=%s)" % (creatorAccount.name, account.name);
Expand Down
10 changes: 9 additions & 1 deletion tests/nodeos_run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
Print("Validating system accounts after bootstrap")
cluster.validateAccounts(None)

accounts=Cluster.createAccountKeys(3)
accounts=Cluster.createAccountKeys(4)
if accounts is None:
errorExit("FAILURE - create keys")
testeraAccount=accounts[0]
Expand All @@ -101,6 +101,11 @@
currencyAccount.name="currency1111"
exchangeAccount=accounts[2]
exchangeAccount.name="exchange1111"
# account to test newaccount with authority
testerbAccount=accounts[3]
testerbAccount.name="testerb11111"
testerbOwner = testerbAccount.ownerPublicKey
testerbAccount.ownerPublicKey = '{"threshold":1, "accounts":[{"permission":{"actor": "' + testeraAccount.name + '", "permission":"owner"}, "weight": 1}],"keys":[{"key": "' +testerbOwner + '", "weight": 1}],"waits":[]}'

PRV_KEY1=testeraAccount.ownerPrivateKey
PUB_KEY1=testeraAccount.ownerPublicKey
Expand Down Expand Up @@ -210,6 +215,9 @@
Print("Create new account %s via %s" % (testeraAccount.name, cluster.defproduceraAccount.name))
transId=node.createInitializeAccount(testeraAccount, cluster.defproduceraAccount, stakedDeposit=0, waitForTransBlock=False, exitOnError=True)

Print("Create new account %s via %s" % (testerbAccount.name, cluster.defproduceraAccount.name))
transId=node.createInitializeAccount(testerbAccount, cluster.defproduceraAccount, stakedDeposit=0, waitForTransBlock=False, exitOnError=True)

Print("Create new account %s via %s" % (currencyAccount.name, cluster.defproduceraAccount.name))
transId=node.createInitializeAccount(currencyAccount, cluster.defproduceraAccount, buyRAM=200000, stakedDeposit=5000, exitOnError=True)

Expand Down

0 comments on commit c0d4b9e

Please sign in to comment.