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

has_contract() : Determine whether a account deploied contract #18

Merged
merged 1 commit into from
Dec 18, 2018
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 @@ -108,6 +108,13 @@ extern "C" {
*/
void get_action_sequence(uint64_t* seq);

/**
* Get the code_hash of the account
* @param name : account name
* @return : Return has code
*/
bool has_contract( account_name name);

/**
* Get the producer's signature for the action
* @param sig : Memory buffer
Expand Down
7 changes: 7 additions & 0 deletions libraries/chain/wasm_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,12 @@ class context_free_transaction_api : public context_aware_api {
seq = context.global_action_sequence;
}

bool has_contract(account_name name){
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) );
return accnt->code.size() > 0;
}

int expiration() {
return context.trx_context.trx.expiration.sec_since_epoch();
}
Expand Down Expand Up @@ -1946,6 +1952,7 @@ REGISTER_INTRINSICS(context_free_transaction_api,
(transaction_size, int() )
(get_transaction_id, void(int) )
(get_action_sequence, void(int) )
(has_contract, int(int64_t) )
(expiration, int() )
(tapos_block_prefix, int() )
(tapos_block_num, int() )
Expand Down
22 changes: 21 additions & 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-11-17T13:26:02",
"____comment": "This file was generated by eosio-abigen. DO NOT EDIT - 2018-12-18T07:34:45",
"version": "eosio::abi/1.0",
"types": [],
"structs": [{
Expand Down Expand Up @@ -45,6 +45,22 @@
"name": "clear",
"base": "",
"fields": []
},{
"name": "args_name",
"base": "",
"fields": [{
"name": "name",
"type": "name"
}
]
},{
"name": "printcode",
"base": "",
"fields": [{
"name": "t",
"type": "args_name"
}
]
},{
"name": "args_inline",
"base": "",
Expand Down Expand Up @@ -74,6 +90,10 @@
"name": "clear",
"type": "clear",
"ricardian_contract": ""
},{
"name": "printcode",
"type": "printcode",
"ricardian_contract": ""
},{
"name": "inlineact",
"type": "inlineact",
Expand Down
12 changes: 11 additions & 1 deletion unittests/actiondemo/actiondemo.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "actiondemo.hpp"
#include "../../contracts/eosiolib/print.hpp"
#include "../../contracts/eosiolib/types.hpp"
#include "../../contracts/eosiolib/transaction.hpp"
#include "../../contracts/eosiolib/transaction.h"

namespace spaceaction {

Expand All @@ -19,6 +19,9 @@ namespace spaceaction {
case N(clear):
clear();
return;
case N(printcode):
printcode(unpack_action_data<args_name>());
return;
}
}

Expand All @@ -33,6 +36,8 @@ namespace spaceaction {
}
}



std::string to_hex( const char* d, uint32_t s )
{
std::string r;
Expand All @@ -43,6 +48,11 @@ namespace spaceaction {
return r;
}

void actiondemo::printcode(const args_name& t){
bool r = has_contract(t.name);
print_f("% code hash:%", name{t.name}.to_string(),r);
}

void actiondemo::generate(const args& t){
for (int i = 0; i < t.loop; ++i) {
transaction_id_type txid;
Expand Down
6 changes: 6 additions & 0 deletions unittests/actiondemo/actiondemo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ namespace spaceaction {
//@abi action
void clear();

struct args_name{
account_name name;
};
//@abi action
void printcode(const args_name& t);


struct args_inline{
account_name payer;
Expand Down
8 changes: 8 additions & 0 deletions unittests/actiondemo/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ def stepGenerate():
run(args.cleos + 'get table %s %s seedobjs' %(args.contract2, args.contract2) )
print ("sleep 5")

def stepGetCode():
print ("=========================== set stepGetCode ===========================" )
run(args.cleos + 'push action %s printcode \'[{"name":"eosio.token"}]\' -p %s ' %(args.contract,args.contract))
run(args.cleos + 'push action %s printcode \'[{"name":"eosio"}]\' -p %s ' %(args.contract,args.contract))
run(args.cleos + 'push action %s printcode \'[{"name":"eosio.ram"}]\' -p %s ' %(args.contract,args.contract))
print ("sleep 5")


parser = argparse.ArgumentParser()

Expand All @@ -169,6 +176,7 @@ def stepGenerate():
('i', 'init', stepInitCaee, True, "stepInitCaee"),
('c', 'clear', stepClear, True, "stepInitCaee"),
('g', 'generate', stepGenerate, True, "stepInitCaee"),
('d', 'getcode', stepGetCode, True, "stepGetCode"),
]

parser.add_argument('--public-key', metavar='', help="EOSIO Public Key", default='EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV', dest="public_key")
Expand Down