diff --git a/libraries/chain/chain_controller.cpp b/libraries/chain/chain_controller.cpp index b22ce6ca386..98ce7710889 100644 --- a/libraries/chain/chain_controller.cpp +++ b/libraries/chain/chain_controller.cpp @@ -808,16 +808,26 @@ void chain_controller::initialize_genesis(std::function ge } inhibitor(*this); - /// create the system contract + /// create the native contract accounts _db.create([&](account_object& a) { - a.name = "sys"; + a.name = config::SystemContractName; }); -#define MACRO(r, data, elem) register_type("sys"); - BOOST_PP_SEQ_FOR_EACH(MACRO, x, EOS_SYSTEM_CONTRACT_FUNCTIONS) + _db.create([&](account_object& a) { + a.name = config::EosContractName; + }); + _db.create([&](account_object& a) { + a.name = config::StakedBalanceContractName; + }); + + // Register native contract message types +#define MACRO(r, data, elem) register_type(data); + BOOST_PP_SEQ_FOR_EACH(MACRO, config::SystemContractName, EOS_SYSTEM_CONTRACT_FUNCTIONS) + BOOST_PP_SEQ_FOR_EACH(MACRO, config::EosContractName, EOS_CONTRACT_FUNCTIONS) + BOOST_PP_SEQ_FOR_EACH(MACRO, config::StakedBalanceContractName, EOS_STAKED_BALANCE_CONTRACT_FUNCTIONS) #undef MACRO - // Create initial accounts - for (const auto& acct : genesis_state.initial_accounts) { + // Create initial accounts + for (const auto& acct : genesis_state.initial_accounts) { _db.create([&acct](account_object& a) { a.name = acct.name.c_str(); a.balance = acct.balance; diff --git a/libraries/chain/include/eos/chain/config.hpp b/libraries/chain/include/eos/chain/config.hpp index 7d7666b3326..7bc52adeb8c 100644 --- a/libraries/chain/include/eos/chain/config.hpp +++ b/libraries/chain/include/eos/chain/config.hpp @@ -34,6 +34,10 @@ using types::Asset; const static char KeyPrefix[] = "EOS"; +const static char SystemContractName[] = "sys"; +const static char EosContractName[] = "eos"; +const static char StakedBalanceContractName[] = "sbc"; + const static int BlockIntervalSeconds = 3; /** Percentages are fixed point with a denominator of 10,000 */ diff --git a/libraries/chain/include/eos/chain/types.hpp b/libraries/chain/include/eos/chain/types.hpp index 812fdf2fd1f..2b0b2a9c02e 100644 --- a/libraries/chain/include/eos/chain/types.hpp +++ b/libraries/chain/include/eos/chain/types.hpp @@ -65,8 +65,9 @@ { c(*this); } #define OBJECT_CTOR(...) BOOST_PP_OVERLOAD(OBJECT_CTOR, __VA_ARGS__)(__VA_ARGS__) -#define EOS_SYSTEM_CONTRACT_FUNCTIONS (Transfer)(CreateAccount)(CreateProducer)(UpdateProducer) \ - (DefineStruct)(SetMessageHandler) +#define EOS_SYSTEM_CONTRACT_FUNCTIONS (CreateAccount)(DefineStruct)(SetMessageHandler) +#define EOS_CONTRACT_FUNCTIONS (Transfer) +#define EOS_STAKED_BALANCE_CONTRACT_FUNCTIONS (CreateProducer)(UpdateProducer) namespace eos { namespace chain { using std::map; diff --git a/plugins/native_system_contract_plugin/native_system_contract_plugin.cpp b/plugins/native_system_contract_plugin/native_system_contract_plugin.cpp index 774fac600f5..2a7cc747408 100644 --- a/plugins/native_system_contract_plugin/native_system_contract_plugin.cpp +++ b/plugins/native_system_contract_plugin/native_system_contract_plugin.cpp @@ -37,13 +37,15 @@ void native_system_contract_plugin::plugin_shutdown() { } void native_system_contract_plugin::install(chain_controller& db) { -#define SET_HANDLERS(name) \ - db.set_validate_handler("sys", "sys", #name, &name::validate); \ - db.set_precondition_validate_handler("sys", "sys", #name, &name::validate_preconditions); \ - db.set_apply_handler("sys", "sys", #name, &name::apply); -#define FWD_SET_HANDLERS(r, data, elem) SET_HANDLERS(elem) - - BOOST_PP_SEQ_FOR_EACH(FWD_SET_HANDLERS, x, EOS_SYSTEM_CONTRACT_FUNCTIONS) +#define SET_HANDLERS(contractname, handlername) \ + db.set_validate_handler(contractname, contractname, #handlername, &handlername::validate); \ + db.set_precondition_validate_handler(contractname, contractname, #handlername, &handlername::validate_preconditions); \ + db.set_apply_handler(contractname, contractname, #handlername, &handlername::apply); +#define FWD_SET_HANDLERS(r, data, elem) SET_HANDLERS(data, elem) + + BOOST_PP_SEQ_FOR_EACH(FWD_SET_HANDLERS, config::SystemContractName, EOS_SYSTEM_CONTRACT_FUNCTIONS) + BOOST_PP_SEQ_FOR_EACH(FWD_SET_HANDLERS, config::EosContractName, EOS_CONTRACT_FUNCTIONS) + BOOST_PP_SEQ_FOR_EACH(FWD_SET_HANDLERS, config::StakedBalanceContractName, EOS_STAKED_BALANCE_CONTRACT_FUNCTIONS) } } diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index cdd9597381c..5f7f02b06cc 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -289,6 +289,8 @@ class testing_network { * Use Make_Account to create an account, including keys. The changes will be applied via a transaction applied to the * provided database object. The changes will not be incorporated into a block; they will be left in the pending state. * + * Unless overridden, new accounts are created with a balance of Asset(100) + * * Example: * @code{.cpp} * Make_Account(db, joe) diff --git a/tests/common/macro_support.hpp b/tests/common/macro_support.hpp index 31e2b74c504..ea9944c5bdf 100644 --- a/tests/common/macro_support.hpp +++ b/tests/common/macro_support.hpp @@ -22,7 +22,7 @@ #define MKACCT_IMPL(db, name, creator, active, owner, recovery, deposit) \ { \ eos::chain::SignedTransaction trx; \ - trx.emplaceMessage(#creator, "sys", vector{}, "CreateAccount", \ + trx.emplaceMessage(#creator, config::SystemContractName, vector{}, "CreateAccount", \ types::CreateAccount{#creator, #name, owner, active, recovery, deposit}); \ trx.expiration = db.head_block_time() + 100; \ trx.set_reference_block(db.head_block_id()); \ @@ -48,7 +48,7 @@ #define XFER5(db, sender, recipient, amount, memo) \ { \ eos::chain::SignedTransaction trx; \ - trx.emplaceMessage(#sender, "sys", vector{#recipient}, "Transfer", \ + trx.emplaceMessage(#sender, config::EosContractName, vector{#recipient}, "Transfer", \ types::Transfer{#sender, #recipient, amount, memo}); \ trx.expiration = db.head_block_time() + 100; \ trx.set_reference_block(db.head_block_id()); \ @@ -56,11 +56,11 @@ } #define XFER4(db, sender, recipient, amount) XFER5(db, sender, recipient, amount, "") -#define MKPDCR4(db, owner, key, config) \ +#define MKPDCR4(db, owner, key, cfg) \ { \ eos::chain::SignedTransaction trx; \ - trx.emplaceMessage(#owner, "sys", vector{}, "CreateProducer", \ - types::CreateProducer{#owner, key, config}); \ + trx.emplaceMessage(#owner, config::StakedBalanceContractName, vector{}, "CreateProducer", \ + types::CreateProducer{#owner, key, cfg}); \ trx.expiration = db.head_block_time() + 100; \ trx.set_reference_block(db.head_block_id()); \ db.push_transaction(trx); \ @@ -70,11 +70,11 @@ Make_Key(owner ## _producer); \ MKPDCR4(db, owner, owner ## _producer_public_key, BlockchainConfiguration{}); -#define UPPDCR4(db, owner, key, config) \ +#define UPPDCR4(db, owner, key, cfg) \ { \ eos::chain::SignedTransaction trx; \ - trx.emplaceMessage(owner, "sys", vector{}, "UpdateProducer", \ - types::UpdateProducer{owner, key, config}); \ + trx.emplaceMessage(owner, config::StakedBalanceContractName, vector{}, "UpdateProducer", \ + types::UpdateProducer{owner, key, cfg}); \ trx.expiration = db.head_block_time() + 100; \ trx.set_reference_block(db.head_block_id()); \ db.push_transaction(trx); \ diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index dbd063799f4..975bf9ed033 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -96,7 +96,7 @@ BOOST_FIXTURE_TEST_CASE(create_script, testing_fixture) types::SetMessageHandler handler; handler.processor = "init1"; - handler.recipient = "sys"; + handler.recipient = config::EosContractName; handler.type = "Transfer"; handler.apply = R"( @@ -114,7 +114,7 @@ BOOST_FIXTURE_TEST_CASE(create_script, testing_fixture) )"; trx.setMessage(0, "SetMessageHandler", handler); - + idump((trx)); db.push_transaction(trx); db.produce_blocks(1); diff --git a/tests/tests/system_contract_tests.cpp b/tests/tests/system_contract_tests.cpp index fff2b38102b..cf11cb64320 100644 --- a/tests/tests/system_contract_tests.cpp +++ b/tests/tests/system_contract_tests.cpp @@ -88,7 +88,7 @@ BOOST_FIXTURE_TEST_CASE(transfer, testing_fixture) trx.set_reference_block(db.head_block_id()); trx.expiration = db.head_block_time() + 100; trx.messages[0].sender = "init1"; - trx.messages[0].recipient = "sys"; + trx.messages[0].recipient = config::EosContractName; trx.messages[0].type = "Undefined"; BOOST_REQUIRE_THROW( db.push_transaction(trx), message_validate_exception ); // "Type Undefined is not defined"