未验证 提交 d933f16a 编写于 作者: K Kevin Heifner 提交者: GitHub

Merge pull request #2757 from EOSIO/gh#2738-buyram-newaccount

Gh#2738 buyram newaccount
......@@ -10,6 +10,7 @@
*.dot
*.abi.hpp
*.cmake
*.ninja
\#*
\.#*
CMakeCache.txt
......@@ -29,6 +30,9 @@ libraries/egenesis/egenesis_full.cpp
libraries/egenesis/embed_genesis
libraries/types/type_generator
libraries/types/types_test
libraries/fc/test/crypto/test_cypher_suites
libraries/testing/chain_tester
libraries/wallet/Doxyfile
libraries/wallet/api_documentation.cpp
......@@ -39,26 +43,24 @@ libraries/wasm-jit/Source/Programs/Disassemble
libraries/wasm-jit/Source/Programs/Test
libraries/wasm-jit/Source/Programs/wavm
programs/cli_wallet/cli_wallet
programs/cleos/cleos
programs/js_operation_serializer/js_operation_serializer
programs/witness_node/witness_node
programs/data-dir
programs/eos-walletd/eos-walletd
programs/eosiod/eosiod
programs/eosioc/eosioc
programs/launcher/launcher
programs/eosio-abigen/eosio-abigen
programs/cleos/config.hpp
programs/eosio-applesedemo/eosio-applesedemo
programs/eosio-launcher/config.hpp
programs/eosio-launcher/eosio-launcher
programs/keosd/keosd
programs/nodeos/config.hpp
programs/nodeos/nodeos
scripts/tn_init.sh
tests/app_test
tests/chain_bench
tests/chain_test
tests/intense_test
tests/performance_test
tests/plugin_test
tests/config.hpp
unittests/config.hpp
unittests/unit_test
doxygen
......@@ -67,10 +69,6 @@ witness_node_data_dir
*.wallet
programs/witness_node/object_database/*
object_database/*
*.pyc
*.pyo
......
......@@ -63,10 +63,10 @@ namespace eosio {
static constexpr uint8_t max_precision = 18;
explicit symbol(uint8_t p, const char* s): m_value(string_to_symbol(p, s)) {
FC_ASSERT(valid(), "invalid symbol", ("s",s));
FC_ASSERT(valid(), "invalid symbol: ${s}", ("s",s));
}
explicit symbol(uint64_t v = SY(4, EOS)): m_value(v) {
FC_ASSERT(valid(), "invalid symbol", ("name",name()));
FC_ASSERT(valid(), "invalid symbol: ${name}", ("name",name()));
}
static symbol from_string(const string& from)
{
......
......@@ -401,6 +401,24 @@ chain::action create_action(const vector<permission_level>& authorization, const
return chain::action{authorization, code, act, result.get_object()["binargs"].as<bytes>()};
}
chain::action create_buyram(const name& creator, const name& newaccount, const asset& quantity) {
fc::variant act_payload = fc::mutable_variant_object()
("payer", creator.to_string())
("receiver", newaccount.to_string())
("quant", quantity.to_string());
return create_action(tx_permission.empty() ? vector<chain::permission_level>{{creator,config::active_name}} : get_account_permissions(tx_permission),
config::system_account_name, N(buyram), act_payload);
}
chain::action create_buyrambytes(const name& creator, const name& newaccount, uint32_t numbytes) {
fc::variant act_payload = fc::mutable_variant_object()
("payer", creator.to_string())
("receiver", newaccount.to_string())
("bytes", numbytes);
return create_action(tx_permission.empty() ? vector<chain::permission_level>{{creator,config::active_name}} : get_account_permissions(tx_permission),
config::system_account_name, N(buyrambytes), act_payload);
}
fc::variant regproducer_variant(const account_name& producer,
public_key_type key,
string url) {
......@@ -923,12 +941,18 @@ int main( int argc, char** argv ) {
string account_name;
string owner_key_str;
string active_key_str;
uint32_t buy_ram_bytes_in_kbytes = 8;
string buy_ram_eos;
auto createAccount = create->add_subcommand("account", localized("Create a new account on the blockchain"), false);
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 for the new account"))->required();
createAccount->add_option("ActiveKey", active_key_str, localized("The active public key for the new account"))->required();
createAccount->add_option("--buy-ram-bytes", buy_ram_bytes_in_kbytes,
(localized("The amount of RAM bytes to purchase for the new account in kilobytes KiB, default is 8 KiB")));
createAccount->add_option("--buy-ram-EOS", buy_ram_eos,
(localized("The amount of RAM bytes to purchase for the new account in EOS")));
add_standard_transaction_options(createAccount, "creator@active");
createAccount->set_callback([&] {
public_key_type owner_key, active_key;
......@@ -938,7 +962,15 @@ int main( int argc, char** argv ) {
try {
active_key = public_key_type(active_key_str);
} EOS_RETHROW_EXCEPTIONS(public_key_type_exception, "Invalid active public key: ${public_key}", ("public_key", active_key_str))
send_actions({create_newaccount(creator, account_name, owner_key, active_key)});
if( !buy_ram_eos.empty() ) {
action buyact = create_buyram(creator, account_name, asset::from_string(buy_ram_eos));
send_actions({create_newaccount(creator, account_name, owner_key, active_key), buyact});
} else if( buy_ram_bytes_in_kbytes > 0 ){
action buyact = create_buyrambytes(creator, account_name, buy_ram_bytes_in_kbytes * 1024 * 1024);
send_actions({create_newaccount(creator, account_name, owner_key, active_key), buyact});
} else {
send_actions({create_newaccount(creator, account_name, owner_key, active_key)});
}
});
// Get subcommand
......
......@@ -488,7 +488,7 @@ class Node(object):
# Create account and return creation transactions. Return transaction json object
# waitForTransBlock: wait on creation transaction id to appear in a block
def createAccount(self, account, creatorAccount, stakedDeposit=1000, waitForTransBlock=False):
cmd="%s %s create account -j %s %s %s %s" % (
cmd="%s %s create account -j --buy-ram-bytes 0 %s %s %s %s" % (
Utils.EosClientPath, self.endpointArgs, creatorAccount.name, account.name,
account.ownerPublicKey, account.activePublicKey)
......
......@@ -43,6 +43,7 @@ class currency_tester : public TESTER {
signed_transaction trx;
trx.actions.emplace_back(std::move(act));
set_transaction_headers(trx);
trx.sign(get_private_key(signer, "active"), chain_id_type());
return push_transaction(trx);
......@@ -316,7 +317,7 @@ BOOST_FIXTURE_TEST_CASE(test_symbol, TESTER) try {
// invalid - contains lower case characters, no validation
{
BOOST_CHECK_EXCEPTION(symbol malformed(SY(6,EoS)),
fc::assert_exception, fc_assert_exception_message_is("invalid symbol"));
fc::assert_exception, fc_assert_exception_message_is("invalid symbol: EoS"));
}
// invalid - contains lower case characters, exception thrown
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册