diff --git a/contracts/eosio.system/eosio.system.abi b/contracts/eosio.system/eosio.system.abi index 8ae709721b81b7117288bfded329239b6c1e80a4..41278cf63429b5d38fe7d97831ceeda929e5bc2a 100644 --- a/contracts/eosio.system/eosio.system.abi +++ b/contracts/eosio.system/eosio.system.abi @@ -29,7 +29,22 @@ "fields": [ {"name":"value", "type":"string"} ] + },{ + "name": "regproducer", + "base": "", + "fields": [ + {"name":"producer", "type":"account_name"} + {"name":"producer_key", "type":"bytes"} + ] + },{ + "name": "stakevote", + "base": "", + "fields": [ + {"name":"voter", "type":"account_name"} + {"name":"amount", "type":"asset"} + ] } + ], "actions": [{ "name": "transfer", @@ -40,6 +55,12 @@ },{ "name": "nonce", "type": "nonce" + },{ + "name": "regproducer", + "type": "regproducer" + },{ + "name": "stakevote", + "type": "stakevote" } ], "tables": [{ @@ -50,4 +71,4 @@ "key_types" : ["name"] } ] -} \ No newline at end of file +} diff --git a/contracts/eosio.system/eosio.system.cpp b/contracts/eosio.system/eosio.system.cpp index ee50cc7ea602da6b277487e0600910de94a8b64d..de6316284e48a1f416cd9bbe36ee29735a071e9c 100644 --- a/contracts/eosio.system/eosio.system.cpp +++ b/contracts/eosio.system/eosio.system.cpp @@ -11,6 +11,7 @@ extern "C" { /// The apply method implements the dispatch of events to this contract void apply( uint64_t code, uint64_t act ) { + print( name(code), "::", name(act) ); eosiosystem::contract::apply( code, act ); } } diff --git a/contracts/eosio.system/eosio.system.hpp b/contracts/eosio.system/eosio.system.hpp index e4419c96a67611e5b7f46172679127916f7d4d7d..834d37a321996af5fcc6e37d78078aceec5ddd95 100644 --- a/contracts/eosio.system/eosio.system.hpp +++ b/contracts/eosio.system/eosio.system.hpp @@ -23,6 +23,7 @@ namespace eosiosystem { using eosio::bytes; using std::map; using std::pair; + using eosio::print; template class contract { @@ -116,10 +117,10 @@ namespace eosiosystem { }; ACTION( SystemAccount, regproducer ) { - account_name producer_to_register; + account_name producer; bytes producer_key; - EOSLIB_SERIALIZE( regproducer, (producer_to_register)(producer_key) ); + EOSLIB_SERIALIZE( regproducer, (producer)(producer_key) ); }; ACTION( SystemAccount, regproxy ) { @@ -250,7 +251,7 @@ namespace eosiosystem { /** - * This method will create a producr_config and producer_votes object for 'producer_to_register' + * This method will create a producr_config and producer_votes object for 'producer' * * @pre producer is not already registered * @pre producer to register is an account @@ -258,7 +259,7 @@ namespace eosiosystem { * */ static void on( const regproducer& reg ) { - auto producer = reg.producer_to_register; + auto producer = reg.producer; require_auth( producer ); producer_votes_index_type votes( SystemAccount, SystemAccount ); @@ -279,14 +280,16 @@ namespace eosiosystem { ACTION( SystemAccount, stakevote ) { account_name voter; - system_token_type amount_to_stake; + system_token_type amount; - EOSLIB_SERIALIZE( stakevote, (voter)(amount_to_stake) ) + EOSLIB_SERIALIZE( stakevote, (voter)(amount) ) }; static void on( const stakevote& sv ) { - eosio_assert( sv.amount_to_stake.quantity > 0, "must stake some tokens" ); + print( "on stake vote\n" ); + eosio_assert( sv.amount.quantity > 0, "must stake some tokens" ); require_auth( sv.voter ); + return; account_votes_index_type avotes( SystemAccount, SystemAccount ); @@ -300,7 +303,7 @@ namespace eosiosystem { } uint128_t old_weight = acv->staked.quantity; - uint128_t new_weight = old_weight + sv.amount_to_stake.quantity; + uint128_t new_weight = old_weight + sv.amount.quantity; producer_votes_index_type votes( SystemAccount, SystemAccount ); @@ -313,10 +316,10 @@ namespace eosiosystem { avotes.update( *acv, 0, [&]( auto av ) { av.last_update = now(); - av.staked += sv.amount_to_stake; + av.staked += sv.amount; }); - currency::inline_transfer( sv.voter, SystemAccount, sv.amount_to_stake, "stake for voting" ); + // currency::inline_transfer( sv.voter, SystemAccount, sv.amount, "stake for voting" ); }; ACTION( SystemAccount, voteproducer ) { diff --git a/libraries/chain/apply_context.cpp b/libraries/chain/apply_context.cpp index 149e7939cf8d7bdeeda1a36f567961d3defba0fd..bc8f757b1f0524f4e599e875fef390f2031f5ebb 100644 --- a/libraries/chain/apply_context.cpp +++ b/libraries/chain/apply_context.cpp @@ -116,6 +116,7 @@ bool apply_context::is_account( const account_name& account )const { void apply_context::require_authorization( const account_name& account )const { for( const auto& auth : act.authorization ) if( auth.actor == account ) return; + wdump((act)); EOS_ASSERT( false, tx_missing_auth, "missing authority of ${account}", ("account",account)); } void apply_context::require_authorization(const account_name& account, diff --git a/libraries/chain/include/eosio/chain/account_object.hpp b/libraries/chain/include/eosio/chain/account_object.hpp index d0ea6b9d21850f532ccf78829ab792fed8ef51ac..403c99c19826b34473759d4a9424c71265bb22dd 100644 --- a/libraries/chain/include/eosio/chain/account_object.hpp +++ b/libraries/chain/include/eosio/chain/account_object.hpp @@ -36,6 +36,13 @@ namespace eosio { namespace chain { fc::datastream ds( abi.data(), abi.size() ); fc::raw::pack( ds, a ); } + + eosio::chain::contracts::abi_def get_abi()const { + eosio::chain::contracts::abi_def a; + fc::datastream ds( abi.data(), abi.size() ); + fc::raw::unpack( ds, a ); + return a; + } }; using account_id_type = account_object::id_type; diff --git a/libraries/testing/include/eosio/testing/tester.hpp b/libraries/testing/include/eosio/testing/tester.hpp index bd89e5414a15d42a72c31247607806f7e4b4ce66..5f629c7b1a8c2dbfc11958b7b72d229476362acd 100644 --- a/libraries/testing/include/eosio/testing/tester.hpp +++ b/libraries/testing/include/eosio/testing/tester.hpp @@ -29,7 +29,11 @@ namespace eosio { namespace testing { transaction_trace push_transaction( packed_transaction& trx ); transaction_trace push_transaction( signed_transaction& trx ); - action_result push_action(action&& cert_act, uint64_t authorizer); + action_result push_action(action&& cert_act, uint64_t authorizer); + + transaction_trace push_action( const account_name& code, const action_name& act, const account_name& signer, const variant_object &data ); + + void set_tapos( signed_transaction& trx ) const; void create_accounts( vector names, bool multisig = false ) { diff --git a/libraries/testing/tester.cpp b/libraries/testing/tester.cpp index 9e5a9e5ac5855b3eaf8e5948315eaa1530eeb353..3492390931f304baaeefeff6c8c02aa0896f7a45 100644 --- a/libraries/testing/tester.cpp +++ b/libraries/testing/tester.cpp @@ -366,4 +366,30 @@ namespace eosio { namespace testing { return s; } + transaction_trace tester::push_action( const account_name& code, + const action_name& acttype, + const account_name& actor, + const variant_object& data + ) + { try { + chain::contracts::abi_serializer abis( control->get_database().get(code).get_abi() ); + + string action_type_name = abis.get_action_type(acttype); + + action act; + act.account = code; + act.name = acttype; + act.authorization = vector{{actor, config::active_name}}; + act.data = abis.variant_to_binary(action_type_name, data); + wdump((act)); + + signed_transaction trx; + trx.actions.emplace_back(std::move(act)); + set_tapos(trx); + trx.sign(get_private_key(actor, "active"), chain_id_type()); + wdump((get_public_key( actor, "active" )));; + + return push_transaction(trx); + } FC_CAPTURE_AND_RETHROW( (code)(acttype)(actor) ) } + } } /// eosio::test