I'm trying to add a new smart contract API to wasm_interface.cpp.
I did the same things like context_free_transaction_api::tapos_block_prefix(), https://github.com/EOSIO/eos/pull/1217, adding max_net_usage() function to eosiolib/transaction.h and its implementation on wasm_interface.cpp, and built nodeos and hello contract as API caller using eosio_build.sh.
diff --git a/contracts/eosiolib/transaction.h b/contracts/eosiolib/transaction.h
index bb29f159a..f7d2654c4 100644
--- a/contracts/eosiolib/transaction.h
+++ b/contracts/eosiolib/transaction.h
@@ -115,5 +115,7 @@ extern "C" {
*/
int get_context_free_data( uint32_t index, char* buff, size_t size );
+ int max_net_usage();
+
///@ } transactioncapi
}
diff --git a/contracts/hello/hello.cpp b/contracts/hello/hello.cpp
index 7c52afa9b..4b9f1d09d 100644
--- a/contracts/hello/hello.cpp
+++ b/contracts/hello/hello.cpp
@@ -1,4 +1,5 @@
#include <eosiolib/eosio.hpp>
+#include <eosiolib/transaction.h>
using namespace eosio;
class hello : public eosio::contract {
@@ -8,6 +9,8 @@ class hello : public eosio::contract {
/// @abi action
void hi( account_name user ) {
print( "Hello, ", name{user} );
+ print("\n");
+ print("max_net_usage=", max_net_usage());
}
};
diff --git a/libraries/chain/wasm_interface.cpp b/libraries/chain/wasm_interface.cpp
index 18cf81362..0833a21e6 100644
--- a/libraries/chain/wasm_interface.cpp
+++ b/libraries/chain/wasm_interface.cpp
@@ -1368,6 +1368,10 @@ class context_free_transaction_api : public context_aware_api {
int get_action( uint32_t type, uint32_t index, array_ptr<char> buffer, size_t buffer_size )const {
return context.get_action( type, index, buffer, buffer_size );
}
+
+ int max_net_usage() const {
+ return context.trx_context.trx.max_net_usage_words;
+ }
};
class compiler_builtins : public context_aware_api {
@@ -1819,6 +1823,7 @@ REGISTER_INTRINSICS(context_free_transaction_api,
(tapos_block_prefix, int() )
(tapos_block_num, int() )
(get_action, int (int, int, int, int) )
+ (max_net_usage, int() )
);
REGISTER_INTRINSICS(transaction_api,
Build was successful, but contract deployment was failed with this error.
$ cleos set contract hello build/contracts/hello -p hello Reading WAST/WASM from build/contracts/hello/hello.wasm... Using already assembled WASM... Publishing contract... 689825ms thread-0
main.cpp:2659 main ] Failed with error: Assert Exception (10) !"unresolvable": env.max_net_usage
What am I missing? Is there a WASM command to add max_net_usage symbol up to env?