-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #331 from eosnetworkfoundation/elmato/merge-kayan_…
…evmtx_order_test-to-main [1.0 ->main] integration test for evmtx order
- Loading branch information
Showing
5 changed files
with
227 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ | ||
"____comment": "This file was generated with eosio-abigen. DO NOT EDIT ", | ||
"version": "eosio::abi/1.2", | ||
"types": [ | ||
{ | ||
"new_type_name": "bridge_message", | ||
"type": "variant_bridge_message_v0" | ||
} | ||
], | ||
"structs": [ | ||
{ | ||
"name": "bridge_message_v0", | ||
"base": "", | ||
"fields": [ | ||
{ | ||
"name": "receiver", | ||
"type": "name" | ||
}, | ||
{ | ||
"name": "sender", | ||
"type": "bytes" | ||
}, | ||
{ | ||
"name": "timestamp", | ||
"type": "time_point" | ||
}, | ||
{ | ||
"name": "value", | ||
"type": "bytes" | ||
}, | ||
{ | ||
"name": "data", | ||
"type": "bytes" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "onbridgemsg", | ||
"base": "", | ||
"fields": [ | ||
{ | ||
"name": "message", | ||
"type": "bridge_message" | ||
} | ||
] | ||
} | ||
], | ||
"actions": [ | ||
{ | ||
"name": "onbridgemsg", | ||
"type": "onbridgemsg", | ||
"ricardian_contract": "" | ||
} | ||
], | ||
"tables": [], | ||
"ricardian_clauses": [], | ||
"variants": [ | ||
{ | ||
"name": "variant_bridge_message_v0", | ||
"types": ["bridge_message_v0"] | ||
} | ||
], | ||
"action_results": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include <vector> | ||
#include <variant> | ||
#include <eosio/eosio.hpp> | ||
#include <eosio/contract.hpp> | ||
|
||
using namespace eosio; | ||
using namespace std; | ||
|
||
extern "C" { | ||
__attribute__((eosio_wasm_import)) | ||
void set_action_return_value(void*, size_t); | ||
|
||
__attribute__((eosio_wasm_import)) | ||
uint64_t get_sender(); | ||
} | ||
|
||
typedef std::vector<char> bytes; | ||
|
||
struct bridge_message_v0 { | ||
name receiver; | ||
bytes sender; | ||
time_point timestamp; | ||
bytes value; | ||
bytes data; | ||
|
||
EOSLIB_SERIALIZE(bridge_message_v0, (receiver)(sender)(timestamp)(value)(data)); | ||
}; | ||
|
||
using bridge_message = std::variant<bridge_message_v0>; | ||
|
||
class [[eosio::contract("evmbridge")]] evmbridge : public contract { | ||
public: | ||
using contract::contract; | ||
[[eosio::action]] void onbridgemsg(const bridge_message& message); | ||
|
||
|
||
class contract_actions { | ||
public: | ||
void call(eosio::name from, const bytes &to, const bytes& value, const bytes &data, uint64_t gas_limit); | ||
void assertnonce(eosio::name account, uint64_t next_nonce); | ||
}; | ||
|
||
using call_action = action_wrapper<"call"_n, &contract_actions::call>; | ||
}; | ||
|
||
void evmbridge::onbridgemsg(const bridge_message& message) { | ||
const bridge_message_v0 &msg = std::get<bridge_message_v0>(message); | ||
const char method[4] = {'\x00','\x8f','\xcf','\x3e'}; // function assertdata(uint256) payable | ||
|
||
uint8_t value_buffer[32] = {}; | ||
|
||
if (msg.data.size() >= 32) { | ||
std::copy(msg.data.end() - 32, msg.data.end(), value_buffer); | ||
} | ||
|
||
bytes call_data; | ||
call_data.reserve(4 + 32); | ||
call_data.insert(call_data.end(), method, method + 4); | ||
call_data.insert(call_data.end(), value_buffer, value_buffer + 32); | ||
|
||
call_action call_act("eosio.evm"_n, {{get_self(), "active"_n}}); | ||
|
||
bytes value; | ||
value.resize(32, 0); | ||
value[31] = 100; | ||
|
||
call_act.send(get_self() /*from*/, msg.sender /*to*/, value /*value*/, call_data /*data*/, 100000 /*gas_limit*/); | ||
} | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters