Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get the code of the deployment contract #26

Merged
merged 1 commit into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions contracts/eosiolib/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ extern "C" {
*/
bool has_contract( account_name name);

/**
wirtecode marked this conversation as resolved.
Show resolved Hide resolved
* Get the code of the deployment contract
* @param name : account name
* @param code : return contract code
*/
void get_contract_code( account_name name, checksum256* code);

/**
* Get the producer's signature for the action
* @param sig : Memory buffer
Expand Down
12 changes: 12 additions & 0 deletions libraries/chain/wasm_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,17 @@ class context_free_transaction_api : public context_aware_api {
return accnt->code.size() > 0;
}

void get_contract_code(account_name name, fc::sha256& code ) {
const auto accnt = context.db.find<account_object,by_name>( name );
EOS_ASSERT( accnt != nullptr, action_validate_exception, "account '${account}' does not exist", ("account", name) );

if( accnt->code.size() > 0) {
code = fc::sha256::hash( accnt->code.data(), accnt->code.size() );
} else {
code = fc::sha256();
}
}

int expiration() {
return context.trx_context.trx.expiration.sec_since_epoch();
}
Expand Down Expand Up @@ -1953,6 +1964,7 @@ REGISTER_INTRINSICS(context_free_transaction_api,
(get_transaction_id, void(int) )
(get_action_sequence, void(int) )
(has_contract, int(int64_t) )
(get_contract_code, void(int64_t, int) )
(expiration, int() )
(tapos_block_prefix, int() )
(tapos_block_num, int() )
Expand Down
2 changes: 1 addition & 1 deletion unittests/actiondemo/actiondemo.abi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"____comment": "This file was generated by eosio-abigen. DO NOT EDIT - 2018-12-18T11:11:23",
"____comment": "This file was generated by eosio-abigen. DO NOT EDIT - 2019-01-07T10:42:22",
"version": "eosio::abi/1.0",
"types": [],
"structs": [{
Expand Down
9 changes: 9 additions & 0 deletions unittests/actiondemo/actiondemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ namespace spaceaction {
void actiondemo::hascontract(const args_name& t){
bool r = has_contract(t.name);
print_f("% has_contract:%", name{t.name}.to_string(),r);

// if (r) {
checksum256 code;
get_contract_code(t.name, &code);

std::string s = to_hex((char*)&code.hash, 32);
print_f("% contract_code:%", name{t.name}.to_string(),s);
// }

}

void actiondemo::generate(const args& t){
Expand Down
6 changes: 4 additions & 2 deletions unittests/actiondemo/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def stepStartWallet():
importKeys()
# run('rm -rf ~/.local/share/eosio/nodeos/data ')
run("rm -rf ./data/*")
background(args.nodeos + ' -e -p eosio --blocks-dir ./data/block/ --genesis-json %s --config-dir ./ --data-dir ./data/ --plugin eosio::http_plugin --plugin eosio::chain_api_plugin --plugin eosio::producer_plugin --plugin eosio::history_api_plugin> eos.log 2>&1 &' % args.genesis)
background(args.nodeos + ' -e -p eosio --blocks-dir ./data/block/ --genesis-json %s --config-dir ./ --data-dir ./data/ --plugin eosio::http_plugin --plugin eosio::chain_api_plugin --plugin eosio::producer_plugin --plugin eosio::history_api_plugin --plugin eosio::history_plugin> eos.log 2>&1 &' % args.genesis)
run("rm -rf ./data2/*")
background(args.nodeos + ' --blocks-dir ./data2/block/ --genesis-json %s --data-dir ./data2/ --config-dir ./ --p2p-peer-address 127.0.0.1:9876 --http-server-address 0.0.0.0:8001 --p2p-listen-endpoint 0.0.0.0:9001 --plugin eosio::http_plugin --plugin eosio::chain_api_plugin --plugin eosio::producer_plugin --plugin eosio::history_api_plugin > eos2.log 2>&1 &' % args.genesis)
sleep(30)
Expand All @@ -103,6 +103,7 @@ def createAccounts():
run(args.cleos + 'set contract eosio.msig ' + args.contracts_dir + 'eosio.msig/')
run(args.cleos + 'push action eosio.token create \'["eosio", "10000000000.0000 %s"]\' -p eosio.token' % (args.symbol))
run(args.cleos + 'push action eosio.token issue \'["eosio", "%s %s", "memo"]\' -p eosio' % ("1000000.0000", args.symbol))
run(args.cleos + 'push action eosio.token issue \'["%s", "%s %s", "memo"]\' -p eosio' % (args.contract, "1000.0000", args.symbol))
retry(args.cleos + 'set contract eosio ' + args.contracts_dir + 'eosio.system/ -p eosio')
sleep(1)
run(args.cleos + 'push action eosio setpriv' + jsonArg(['eosio.msig', 1]) + '-p eosio@active')
Expand Down Expand Up @@ -164,6 +165,7 @@ def stepGetCode():
run(args.cleos + 'push action %s hascontract \'[{"name":"eosio.token"}]\' -p %s ' %(args.contract,args.contract))
run(args.cleos + 'push action %s hascontract \'[{"name":"eosio"}]\' -p %s ' %(args.contract,args.contract))
run(args.cleos + 'push action %s hascontract \'[{"name":"eosio.ram"}]\' -p %s ' %(args.contract,args.contract))
run(args.cleos + 'push action %s hascontract \'[{"name":"caeeregright"}]\' -p %s ' %(args.contract,args.contract))
print ("sleep 5")


Expand Down Expand Up @@ -211,7 +213,7 @@ def stepGetCode():


accnum = 26
accounts = []
accounts = ['caeeregright']
# for i in range(97,97+accnum):
# accounts.append("user%c"% chr(i))
# accounts.append("payman")
Expand Down