Skip to content

Commit 826f241

Browse files
committed
Update apply function signature for every contract
1 parent a427722 commit 826f241

File tree

23 files changed

+242
-272
lines changed

23 files changed

+242
-272
lines changed

contracts/asserter/asserter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ static int global_variable = 45;
1111

1212
extern "C" {
1313
/// The apply method implements the dispatch of events to this contract
14-
void apply( uint64_t code, uint64_t action ) {
14+
void apply( uint64_t receiver, uint64_t code, uint64_t action ) {
1515
if( code == N(asserter) ) {
1616
if( action == N(procassert) ) {
1717
assertdef check;

contracts/bancor/bancor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace bancor {
1010
extern "C" {
1111

1212
/// The apply method implements the dispatch of events to this contract
13-
void apply( uint64_t c, uint64_t a ) {
13+
void apply( uint64_t r, uint64_t c, uint64_t a ) {
1414
bancor::example_converter::apply( c, a );
1515
}
1616
}

contracts/currency/currency.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
extern "C" {
99
/// The apply method implements the dispatch of events to this contract
10-
void apply( uint64_t code, uint64_t action ) {
11-
eosio::currency().apply( code, action );
10+
void apply( uint64_t receiver, uint64_t code, uint64_t action ) {
11+
eosio::currency(receiver).apply( code, action );
1212
}
1313
}

contracts/eosio.system/eosio.system.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ using namespace eosiosystem;
1010
extern "C" {
1111

1212
/// The apply method implements the dispatch of events to this contract
13-
void apply( uint64_t code, uint64_t act ) {
13+
void apply( uint64_t receiver, uint64_t code, uint64_t act ) {
1414
//print( eosio::name(code), "::", eosio::name(act) );
1515
eosiosystem::contract<N(eosio)>::apply( code, act );
1616
}

contracts/eosiolib/action.h

-13
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@ extern "C" {
5858
* require_auth(N(inita)); // Do nothing since inita exists in the auth list
5959
* require_auth(N(initb)); // Throws an exception
6060
*
61-
* account_name code = current_receiver();
62-
* print(Name(code)); // Output: eos
63-
*
64-
* eosio_assert(Name(current_receiver()) === "eos", "This action expects to be received by eos"); // Do nothing
65-
* eosio_assert(Name(current_receiver()) === "inita", "This action expects to be received by inita"); // Throws exception and roll back transfer transaction
66-
*
6761
* print(now()); // Output: timestamp of last accepted block
6862
*
6963
* @endcode
@@ -104,13 +98,6 @@ extern "C" {
10498
void require_auth( account_name name );
10599
bool has_auth( account_name name );
106100

107-
/**
108-
* Get the account which specifies the code that is being run
109-
* @brief Get the account which specifies the code that is being run
110-
* @return the account which specifies the code that is being run
111-
*/
112-
account_name current_receiver();
113-
114101
/**
115102
* Send an inline action in the context of this action's parent transaction
116103
* @param serialized_action - serialized action

contracts/eosiolib/currency.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace eosio {
1212
*/
1313
class currency {
1414
public:
15-
currency( account_name contract = current_receiver() )
15+
currency( account_name contract )
1616
:_contract(contract)
1717
{ }
1818

contracts/exchange/exchange.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ namespace eosio {
242242

243243

244244
extern "C" {
245-
void apply( uint64_t code, uint64_t action ) {
246-
eosio::exchange ex( current_receiver() );
245+
void apply( uint64_t receiver, uint64_t code, uint64_t action ) {
246+
eosio::exchange ex( receiver );
247247
ex.apply( code, action );
248248
eosio_exit(0);
249249
}

contracts/identity/identity.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
extern "C" {
44
/// The apply method implements the dispatch of events to this contract
5-
void apply( uint64_t code, uint64_t action ) {
5+
void apply( uint64_t receiver, uint64_t code, uint64_t action ) {
66
identity::contract< N(identity) >::apply( code, action );
77
}
88
}

contracts/identity/identity.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ namespace identity {
169169
return accounts_table::get_or_default(acnt, 0);
170170
}
171171

172-
static account_name get_owner_for_identity( identity_name ident ) {
172+
static account_name get_owner_for_identity( uint64_t receiver, identity_name ident ) {
173173
// for each trusted owner certification
174174
// check to see if the certification is still trusted
175175
// check to see if the account has claimed it
@@ -189,7 +189,7 @@ namespace identity {
189189
//contradiction found: different owners certified for the same identity
190190
return 0;
191191
}
192-
} else if (DeployToAccount == current_receiver()){
192+
} else if (DeployToAccount == receiver){
193193
//the certifier is no longer trusted, need to unset the flag
194194
idx.modify(itr, 0, [&](certrow& r) {
195195
r.trusted = 0;
@@ -214,7 +214,7 @@ namespace identity {
214214
if (sizeof(account_name) == itr->data.size()) {
215215
account_name account = *reinterpret_cast<const account_name*>(itr->data.data());
216216
if (ident == get_claimed_identity(account) && is_trusted(itr->certifier)) {
217-
if (DeployToAccount == current_receiver()) {
217+
if (DeployToAccount == receiver) {
218218
// the certifier became trusted and we have permissions to update the flag
219219
idx.modify(itr, 0, [&](certrow& r) {
220220
r.trusted = 1;
@@ -235,11 +235,11 @@ namespace identity {
235235
return owner;
236236
}
237237

238-
static identity_name get_identity_for_account( account_name acnt ) {
238+
static identity_name get_identity_for_account( uint64_t receiver, account_name acnt ) {
239239
// check what identity the account has self certified owner
240240
// verify that a trusted certifier has confirmed owner
241241
auto identity = get_claimed_identity(acnt);
242-
return (identity != 0 && acnt == get_owner_for_identity(identity)) ? identity : 0;
242+
return (identity != 0 && acnt == get_owner_for_identity(receiver, identity)) ? identity : 0;
243243
}
244244

245245
static bool is_trusted_by( account_name trusted, account_name by ) {

contracts/identity/test/identity_test.cpp

+15-10
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ namespace identity_test {
1414

1515
class contract {
1616
public:
17-
18-
static const uint64_t code = N(identitytest);
17+
static const uint64_t code = N(identitytest);
1918
typedef identity::contract< N(identity) > identity_contract;
2019
typedef identity_contract::identity_name identity_name;
2120
typedef identity_contract::property_name property_name;
@@ -36,18 +35,24 @@ namespace identity_test {
3635

3736
typedef singleton<code, N(result), code, uint64_t> result_table;
3837

39-
static void on( const get_owner_for_identity& c ) {
40-
account_name owner = identity_contract::get_owner_for_identity(c.identity);
38+
static void on( uint64_t receiver, const get_owner_for_identity& c ) {
39+
account_name owner = identity_contract::get_owner_for_identity(receiver, c.identity);
4140
result_table::set(owner, 0); //use scope = 0 for simplicity
4241
}
4342

44-
static void on( const get_identity_for_account& c ) {
45-
identity_name idnt = identity_contract::get_identity_for_account(c.account);
43+
static void on( uint64_t receiver, const get_identity_for_account& c ) {
44+
identity_name idnt = identity_contract::get_identity_for_account(receiver, c.account);
4645
result_table::set(idnt, 0); //use scope = 0 for simplicity
4746
}
4847

49-
static void apply( account_name c, action_name act) {
50-
eosio::dispatch<contract, get_owner_for_identity, get_identity_for_account>(c,act);
48+
static void apply( uint64_t receiver, account_name c, action_name act) {
49+
if( code == N(identitytest) ) {
50+
if ( act == N(getowner) ) {
51+
contract::on( receiver, eosio::unpack_action_data<get_owner_for_identity>() );
52+
} else if ( act == N(getidentity) ) {
53+
contract::on( receiver, eosio::unpack_action_data<get_identity_for_account>() );
54+
}
55+
}
5156
}
5257

5358
};
@@ -56,7 +61,7 @@ namespace identity_test {
5661

5762
extern "C" {
5863
/// The apply method implements the dispatch of events to this contract
59-
void apply( uint64_t code, uint64_t action ) {
60-
identity_test::contract::apply( code, action );
64+
void apply( uint64_t receiver, uint64_t code, uint64_t action ) {
65+
identity_test::contract::apply( receiver, code, action );
6166
}
6267
}

contracts/infinite/infinite.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
extern "C" {
88

99
/// The apply method just prints forever
10-
void apply( uint64_t, uint64_t ) {
10+
void apply( uint64_t, uint64_t, uint64_t ) {
1111
int idx = 0;
1212
while(true) {
1313
eosio::print(idx++);

contracts/noop/noop.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace noop {
99
extern "C" {
1010
/// The apply method implements the dispatch of events to this contract
11-
void apply( uint64_t code, uint64_t action ) {
11+
void apply( uint64_t receiver, uint64_t code, uint64_t action ) {
1212
eosio::dispatch<noop, noop::anyaction>(code, action);
1313
}
1414
}

contracts/proxy/proxy.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ namespace proxy {
3434
};
3535

3636
template<typename T>
37-
void apply_transfer(account_name code, const T& transfer) {
37+
void apply_transfer(uint64_t receiver, account_name code, const T& transfer) {
3838
config code_config;
39-
const auto self = current_receiver();
39+
const auto self = receiver;
4040
auto get_res = configs::get(code_config, self);
4141
eosio_assert(get_res, "Attempting to use unconfigured proxy");
4242
if (transfer.from == self) {
@@ -56,8 +56,8 @@ namespace proxy {
5656
}
5757
}
5858

59-
void apply_setowner(set_owner params) {
60-
const auto self = current_receiver();
59+
void apply_setowner(uint64_t receiver, set_owner params) {
60+
const auto self = receiver;
6161
config code_config;
6262
configs::get(code_config, self);
6363
code_config.owner = params.owner;
@@ -67,9 +67,9 @@ namespace proxy {
6767
}
6868

6969
template<size_t ...Args>
70-
void apply_onerror( const deferred_transaction& failed_dtrx ) {
70+
void apply_onerror(uint64_t receiver, const deferred_transaction& failed_dtrx ) {
7171
eosio::print("starting onerror\n");
72-
const auto self = current_receiver();
72+
const auto self = receiver;
7373
config code_config;
7474
eosio_assert(configs::get(code_config, self), "Attempting use of unconfigured proxy");
7575

@@ -87,20 +87,20 @@ using namespace eosio;
8787
extern "C" {
8888

8989
/// The apply method implements the dispatch of events to this contract
90-
void apply( uint64_t code, uint64_t action ) {
90+
void apply( uint64_t receiver, uint64_t code, uint64_t action ) {
9191
if ( code == N(eosio)) {
9292
if (action == N(onerror)) {
93-
apply_onerror(deferred_transaction::from_current_action());
93+
apply_onerror(receiver, deferred_transaction::from_current_action());
9494
} if( action == N(transfer) ) {
95-
apply_transfer(code, unpack_action_data<eosiosystem::contract<N(eosio.system)>::currency::transfer_memo>());
95+
apply_transfer(receiver, code, unpack_action_data<eosiosystem::contract<N(eosio.system)>::currency::transfer_memo>());
9696
}
9797
} else if ( code == N(currency) ) {
9898
if( action == N(transfer) ) {
99-
apply_transfer(code, unpack_action_data<eosio::currency::transfer>());
99+
apply_transfer(receiver, code, unpack_action_data<eosio::currency::transfer>());
100100
}
101-
} else if (code == current_receiver() ) {
101+
} else if (code == receiver ) {
102102
if ( action == N(setowner)) {
103-
apply_setowner(current_action_data<set_owner>());
103+
apply_setowner(receiver, current_action_data<set_owner>());
104104
}
105105
}
106106
}

contracts/skeleton/skeleton.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
extern "C" {
1212

1313
/// The apply method implements the dispatch of events to this contract
14-
void apply( uint64_t code, uint64_t action ) {
14+
void apply( uint64_t receiver, uint64_t code, uint64_t action ) {
1515
eosio::print( "Hello World: ", eosio::name(code), "->", eosio::name(action), "\n" );
1616
}
1717

contracts/stltest/stltest.cpp

+4-9
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,7 @@ namespace stltest {
156156
prints("~MSTR");
157157
}
158158
};
159-
160-
/*
161-
std::string s = "abcdef";
162-
eosio::string s2 = "abcdef";;
163-
MSTR global;
164-
*/
165-
159+
166160
class contract {
167161
public:
168162
typedef eosio::token<N(mycurrency),S(4,MYCUR)> token_type;
@@ -176,7 +170,7 @@ namespace stltest {
176170
account_name to;
177171
//string msg;
178172

179-
static uint64_t get_account() { return current_receiver(); }
173+
static uint64_t get_account() { return N(stltest); }
180174
static uint64_t get_name() { return N(message); }
181175

182176
template<typename DataStream>
@@ -272,7 +266,8 @@ namespace stltest {
272266

273267
extern "C" {
274268
/// The apply method implements the dispatch of events to this contract
275-
void apply( uint64_t code, uint64_t action ) {
269+
void apply( uint64_t receiver, uint64_t code, uint64_t action ) {
270+
(void)receiver;
276271
stltest::contract::apply( code, action );
277272
}
278273
}

contracts/test_api/test_action.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ void test_action::read_action_normal() {
1919
char buffer[100];
2020
uint32_t total = 0;
2121

22-
eosio_assert( current_receiver() == N(testapi), "current_receiver() == N(testapi)" );
23-
2422
eosio_assert(action_data_size() == sizeof(dummy_action), "action_size() == sizeof(dummy_action)");
2523

2624
total = read_action_data(buffer, 30);
@@ -131,13 +129,14 @@ void test_action::test_cf_action() {
131129

132130
}
133131

134-
void test_action::require_notice() {
135-
if( current_receiver() == N(testapi) ) {
132+
void test_action::require_notice(uint64_t receiver, uint64_t code, uint64_t action) {
133+
(void)code;(void)action;
134+
if( receiver == N(testapi) ) {
136135
eosio::require_recipient( N(acc1) );
137136
eosio::require_recipient( N(acc2) );
138137
eosio::require_recipient( N(acc1), N(acc2) );
139138
eosio_assert(false, "Should've failed");
140-
} else if ( current_receiver() == N(acc1) || current_receiver() == N(acc2) ) {
139+
} else if ( receiver == N(acc1) || receiver == N(acc2) ) {
141140
return;
142141
}
143142
eosio_assert(false, "Should've failed");
@@ -168,11 +167,12 @@ void test_action::test_publication_time() {
168167
eosio_assert( pub_time == publication_time(), "pub_time == publication_time()" );
169168
}
170169

171-
void test_action::test_current_receiver() {
170+
void test_action::test_current_receiver(uint64_t receiver, uint64_t code, uint64_t action) {
171+
(void)code;(void)action;
172172
account_name cur_rec;
173173
read_action_data(&cur_rec, sizeof(account_name));
174174

175-
eosio_assert( current_receiver() == cur_rec, "the current receiver does not match" );
175+
eosio_assert( receiver == cur_rec, "the current receiver does not match" );
176176
}
177177

178178
void test_action::test_current_sender() {

contracts/test_api/test_api.cpp

+3-7
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@
1919

2020
extern "C" {
2121

22-
void init() {
23-
24-
}
25-
26-
void apply( unsigned long long, unsigned long long action ) {
22+
void apply( uint64_t receiver, uint64_t code, uint64_t action ) {
2723
//eosio::print("==> CONTRACT: ", code, " ", action, "\n");
2824
//test_types
2925
WASM_TEST_HANDLER(test_types, types_size);
@@ -50,13 +46,13 @@ extern "C" {
5046
WASM_TEST_HANDLER(test_action, read_action_normal);
5147
WASM_TEST_HANDLER(test_action, read_action_to_0);
5248
WASM_TEST_HANDLER(test_action, read_action_to_64k);
53-
WASM_TEST_HANDLER(test_action, require_notice);
49+
WASM_TEST_HANDLER_EX(test_action, require_notice);
5450
WASM_TEST_HANDLER(test_action, require_auth);
5551
WASM_TEST_HANDLER(test_action, assert_false);
5652
WASM_TEST_HANDLER(test_action, assert_true);
5753
WASM_TEST_HANDLER(test_action, now);
5854
WASM_TEST_HANDLER(test_action, test_abort);
59-
WASM_TEST_HANDLER(test_action, test_current_receiver);
55+
WASM_TEST_HANDLER_EX(test_action, test_current_receiver);
6056
WASM_TEST_HANDLER(test_action, test_current_sender);
6157
WASM_TEST_HANDLER(test_action, test_publication_time);
6258

0 commit comments

Comments
 (0)