Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.

Commit 6f16967

Browse files
authored
Merge pull request #810 from EOSIO/feature/action_results
Feature/action results
2 parents 32b6f24 + 2c37881 commit 6f16967

31 files changed

+396
-720
lines changed

libraries/eosiolib/capi/eosio/action.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ capi_name current_receiver( void );
176176
* @pre `return_value` is a valid pointer to an array at least `size` bytes long
177177
*/
178178
__attribute__((eosio_wasm_import))
179-
void set_action_return_value(char *return_value, size_t size);
179+
void set_action_return_value(void *return_value, size_t size);
180180

181181
#ifdef __cplusplus
182182
}

libraries/eosiolib/contracts/eosio/action.hpp

+10-25
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ namespace eosio {
5252

5353
__attribute__((eosio_wasm_import))
5454
uint64_t current_receiver();
55-
56-
__attribute__((eosio_wasm_import))
57-
void set_action_return_value(char *return_value, size_t size);
5855
}
5956
};
6057

@@ -153,18 +150,6 @@ namespace eosio {
153150
return name{internal_use_do_not_use::current_receiver()};
154151
}
155152

156-
/**
157-
* Set the action return value which will be included in action_receipt
158-
* @ingroup action
159-
* @tparam T type of return value
160-
* @param v the return value to set
161-
*/
162-
template<typename T>
163-
inline void set_action_return_value( const T& v ) {
164-
auto packed_value = pack( v );
165-
internal_use_do_not_use::set_action_return_value( &packed_value[0], packed_value.size() );
166-
}
167-
168153
/**
169154
* Copy up to length bytes of current action data to the specified location
170155
*
@@ -448,9 +433,9 @@ namespace eosio {
448433
}
449434

450435
/**
451-
* Wrapper for an action object.
436+
* Wrapper for an action object.
452437
*
453-
* @brief Used to wrap an a particular action to simplify the process of other contracts sending inline actions to "wrapped" action.
438+
* @brief Used to wrap an a particular action to simplify the process of other contracts sending inline actions to "wrapped" action.
454439
* Example:
455440
* @code
456441
* // defined by contract writer of the actions
@@ -591,23 +576,23 @@ INLINE_ACTION_SENDER3( CONTRACT_CLASS, NAME, ::eosio::name(#NAME) )
591576
* Send an inline-action from inside a contract.
592577
*
593578
* @brief A macro to simplify calling inline actions
594-
* @details The send inline action macro is intended to simplify the process of calling inline actions. When calling new actions from existing actions
579+
* @details The send inline action macro is intended to simplify the process of calling inline actions. When calling new actions from existing actions
595580
* EOSIO supports two communication models, inline and deferred. Inline actions are executed as part of the current transaction. This macro
596581
* creates an @ref action using the supplied parameters and automatically calls action.send() on this newly created action.
597582
*
598583
* Example:
599584
* @code
600585
* SEND_INLINE_ACTION( *this, transfer, {st.issuer,N(active)}, {st.issuer, to, quantity, memo} );
601586
* @endcode
602-
*
603-
* The example above is taken from eosio.token.
604-
* This example:
605-
* uses the passed in, dereferenced `this` pointer, to call this.get_self() i.e. the eosio.token contract;
606-
* calls the eosio.token::transfer() action;
587+
*
588+
* The example above is taken from eosio.token.
589+
* This example:
590+
* uses the passed in, dereferenced `this` pointer, to call this.get_self() i.e. the eosio.token contract;
591+
* calls the eosio.token::transfer() action;
607592
* uses the active permission of the "issuer" account;
608-
* uses parameters st.issuer, to, quantity and memo.
593+
* uses parameters st.issuer, to, quantity and memo.
609594
* This macro creates an action struct used to 'send()' (call) transfer(account_name from, account_name to, asset quantity, string memo)
610-
*
595+
*
611596
* @param CONTRACT - The contract to call, which contains the action being sent, maps to the @ref account
612597
* @param NAME - The name of the action to be called, maps to a @ref name
613598
* @param ... - The authorising permission, maps to an @ref authorization , followed by the parameters of the action, maps to a @ref data.

libraries/native/intrinsics.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ extern "C" {
292292
capi_name current_receiver() {
293293
return intrinsics::get().call<intrinsics::current_receiver>();
294294
}
295-
void set_action_return_value( char* rv, size_t len ) {
295+
void set_action_return_value( void* rv, size_t len ) {
296296
intrinsics::get().call<intrinsics::set_action_return_value>(rv, len);
297297
}
298298
void require_recipient( capi_name name ) {

modules/InstallCDT.cmake

-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ eosio_tool_install_and_symlink(eosio-wasm2wast eosio-wasm2wast)
7272
eosio_tool_install_and_symlink(eosio-cc eosio-cc)
7373
eosio_tool_install_and_symlink(eosio-cpp eosio-cpp)
7474
eosio_tool_install_and_symlink(eosio-ld eosio-ld)
75-
eosio_tool_install_and_symlink(eosio-abigen eosio-abigen)
7675
eosio_tool_install_and_symlink(eosio-abidiff eosio-abidiff)
7776
eosio_tool_install_and_symlink(eosio-init eosio-init)
7877

modules/TestsExternalProject.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ExternalProject_Add(
66
EosioWasmTests
77
SOURCE_DIR "${CMAKE_SOURCE_DIR}/tests/unit"
88
BINARY_DIR "${CMAKE_BINARY_DIR}/tests/unit"
9-
CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_BINARY_DIR}/lib/cmake/eosio.cdt/EosioWasmToolchain.cmake -DCMAKE_BUILD_TYPE=Debug -DEOSIO_CDT_BIN=${CMAKE_BINARY_DIR}/lib/cmake/eosio.cdt/ -DBASE_BINARY_DIR=${CMAKE_BINARY_DIR} -D__APPLE=${APPLE}
9+
CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_BINARY_DIR}/lib/cmake/eosio.cdt/EosioWasmToolchain.cmake -DCMAKE_BUILD_TYPE=Debug -DEOSIO_CDT_BIN=${CMAKE_BINARY_DIR}/lib/cmake/eosio.cdt/ -DBASE_BINARY_DIR=${CMAKE_BINARY_DIR} -D__APPLE=${APPLE} -DCMAKE_MODULE_PATH=${CMAKE_MODULE_PATH} -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
1010
UPDATE_COMMAND ""
1111
PATCH_COMMAND ""
1212
TEST_COMMAND ""

pipeline.jsonc

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"pipeline-branch": "master",
55
"dependencies": // dependencies to pull for cdt integration tests, by branch, tag, or commit hash
66
{
7-
"eosio": "release/1.7.x"
7+
"eosio": "develop"
88
}
99
}
10-
}
10+
}

scripts/generate_tarball.sh

+9-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ NAME=$1
44
CDT_PREFIX=${PREFIX}/${SUBPREFIX}
55
mkdir -p ${PREFIX}/bin/
66
mkdir -p ${PREFIX}/lib/cmake/${PROJECT}
7-
mkdir -p ${CDT_PREFIX}/bin
7+
mkdir -p ${CDT_PREFIX}/bin
88
mkdir -p ${CDT_PREFIX}/include
99
mkdir -p ${CDT_PREFIX}/lib/cmake/${PROJECT}
1010
mkdir -p ${CDT_PREFIX}/cmake
@@ -13,7 +13,7 @@ mkdir -p ${CDT_PREFIX}/licenses
1313

1414
#echo "${PREFIX} ** ${SUBPREFIX} ** ${CDT_PREFIX}"
1515

16-
# install binaries
16+
# install binaries
1717
cp -R ${BUILD_DIR}/bin/* ${CDT_PREFIX}/bin || exit 1
1818
cp -R ${BUILD_DIR}/licenses/* ${CDT_PREFIX}/licenses || exit 1
1919

@@ -50,10 +50,16 @@ create_symlink eosio-cpp eosio-cpp
5050
create_symlink eosio-ld eosio-ld
5151
create_symlink eosio-pp eosio-pp
5252
create_symlink eosio-init eosio-init
53-
create_symlink eosio-abigen eosio-abigen
5453
create_symlink eosio-wasm2wast eosio-wasm2wast
5554
create_symlink eosio-wast2wasm eosio-wast2wasm
5655
create_symlink eosio-ar eosio-ar
56+
create_symlink eosio-abidiff eosio-abidiff
57+
create_symlink eosio-nm eosio-nm
58+
create_symlink eosio-objcopy eosio-objcopy
59+
create_symlink eosio-objdump eosio-objdump
60+
create_symlink eosio-ranlib eosio-ranlib
61+
create_symlink eosio-readelf eosio-readelf
62+
create_symlink eosio-strip eosio-strip
5763

5864
echo "Generating Tarball $NAME.tar.gz..."
5965
tar -cvzf $NAME.tar.gz ./${PREFIX}/* || exit 1

tests/integration/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required( VERSION 3.5 )
22

3-
set(EOSIO_VERSION_MIN "1.4")
4-
set(EOSIO_VERSION_SOFT_MAX "2.0")
3+
set(EOSIO_VERSION_MIN "2.0")
4+
set(EOSIO_VERSION_SOFT_MAX "3.0")
55
#set(EOSIO_VERSION_HARD_MAX "")
66

77
find_package(eosio)
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <boost/test/unit_test.hpp>
2+
#include <eosio/testing/tester.hpp>
3+
#include <eosio/chain/abi_serializer.hpp>
4+
5+
#include <Runtime/Runtime.h>
6+
7+
#include <fc/variant_object.hpp>
8+
9+
#include <contracts.hpp>
10+
11+
using namespace eosio;
12+
using namespace eosio::testing;
13+
using namespace eosio::chain;
14+
using namespace eosio::testing;
15+
using namespace fc;
16+
17+
using mvo = fc::mutable_variant_object;
18+
19+
BOOST_AUTO_TEST_SUITE(action_results_tests_suite)
20+
21+
BOOST_FIXTURE_TEST_CASE( action_results_tests, tester ) try {
22+
create_accounts( { N(test) } );
23+
produce_block();
24+
25+
set_code( N(test), contracts::action_results_test_wasm() );
26+
set_abi( N(test), contracts::action_results_test_abi().data() );
27+
28+
produce_blocks();
29+
auto trace = push_action(N(test), N(action1), N(test), mvo());
30+
// need to fix this test after Kevin fixes action_return
31+
wdump((trace));
32+
33+
trace = push_action(N(test), N(action2), N(test), mvo());
34+
wdump((trace));
35+
36+
trace = push_action(N(test), N(action3), N(test), mvo());
37+
wdump((trace));
38+
39+
} FC_LOG_AND_RETHROW()
40+
41+
BOOST_AUTO_TEST_SUITE_END()

tests/integration/capi_tests.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ BOOST_AUTO_TEST_SUITE(capi_tests)
2121
BOOST_FIXTURE_TEST_CASE( capi_tests, tester ) try {
2222
create_accounts( { N(test) } );
2323
produce_block();
24+
2425
set_code( N(test), contracts::capi_tests_wasm() );
2526
set_abi( N(test), contracts::capi_tests_abi().data() );
2627
produce_blocks();

tests/integration/contracts.hpp.in

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ struct contracts {
1919
static std::vector<uint8_t> capi_tests_wasm() { return read_wasm("${CMAKE_BINARY_DIR}/../unit/test_contracts/capi_tests.wasm"); }
2020
static std::vector<char> capi_tests_abi() { return read_abi("${CMAKE_BINARY_DIR}/../unit/test_contracts/capi_tests.abi"); }
2121

22+
static std::vector<uint8_t> action_results_test_wasm() { return read_wasm("${CMAKE_BINARY_DIR}/../unit/test_contracts/action_results_test.wasm"); }
23+
static std::vector<char> action_results_test_abi() { return read_abi("${CMAKE_BINARY_DIR}/../unit/test_contracts/action_results_test.abi"); }
2224
};
2325

2426
}} //ns eosio::testing
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"____comment": "This file was generated with eosio-abigen. DO NOT EDIT ",
3+
"version": "eosio::abi/1.2",
4+
"types": [],
5+
"structs": [
6+
{
7+
"name": "action1",
8+
"base": "",
9+
"fields": []
10+
},
11+
{
12+
"name": "action2",
13+
"base": "",
14+
"fields": []
15+
},
16+
{
17+
"name": "action3",
18+
"base": "",
19+
"fields": []
20+
}
21+
],
22+
"actions": [
23+
{
24+
"name": "action1",
25+
"type": "action1",
26+
"ricardian_contract": ""
27+
},
28+
{
29+
"name": "action2",
30+
"type": "action2",
31+
"ricardian_contract": ""
32+
},
33+
{
34+
"name": "action3",
35+
"type": "action3",
36+
"ricardian_contract": ""
37+
}
38+
],
39+
"tables": [],
40+
"ricardian_clauses": [],
41+
"variants": [],
42+
"action_results": [
43+
{
44+
"name": "action2",
45+
"result_type": "uint32"
46+
},
47+
{
48+
"name": "action3",
49+
"result_type": "string"
50+
}
51+
]
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <eosio/eosio.hpp>
2+
3+
using namespace eosio;
4+
5+
class [[eosio::contract]] action_results_test : public contract {
6+
public:
7+
using contract::contract;
8+
9+
[[eosio::action]]
10+
void action1() {}
11+
12+
[[eosio::action]]
13+
uint32_t action2() { return 42; }
14+
15+
[[eosio::action]]
16+
std::string action3() { return "foo"; }
17+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"tests" : [
3+
{
4+
"expected" : {
5+
"abi-file" : "action_results_test.abi"
6+
}
7+
}
8+
]
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"____comment": "This file was generated with eosio-abigen. DO NOT EDIT ",
3+
"version": "eosio::abi/1.2",
4+
"types": [
5+
{
6+
"new_type_name": "str",
7+
"type": "string"
8+
}
9+
],
10+
"structs": [
11+
{
12+
"name": "hi",
13+
"base": "",
14+
"fields": [
15+
{
16+
"name": "v",
17+
"type": "variant_uint64_str"
18+
}
19+
]
20+
}
21+
],
22+
"actions": [
23+
{
24+
"name": "hi",
25+
"type": "hi",
26+
"ricardian_contract": ""
27+
}
28+
],
29+
"tables": [],
30+
"ricardian_clauses": [],
31+
"variants": [
32+
{
33+
"name": "variant_uint64_str",
34+
"types": ["uint64","str"]
35+
}
36+
],
37+
"action_results": []
38+
}

tests/toolchain/abigen-pass/aliased_type_variant_template_arg.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
"tests": [
33
{
44
"expected": {
5-
"abi": "{\n \"____comment\": \"This file was generated with eosio-abigen. DO NOT EDIT \",\n \"version\": \"eosio::abi\/1.1\",\n \"types\": [\n {\n \"new_type_name\": \"str\",\n \"type\": \"string\"\n }\n ],\n \"structs\": [\n {\n \"name\": \"hi\",\n \"base\": \"\",\n \"fields\": [\n {\n \"name\": \"v\",\n \"type\": \"variant_uint64_str\"\n }\n ]\n }\n ],\n \"actions\": [\n {\n \"name\": \"hi\",\n \"type\": \"hi\",\n \"ricardian_contract\": \"\"\n }\n ],\n \"tables\": [],\n \"ricardian_clauses\": [],\n \"variants\": [\n {\n \"name\": \"variant_uint64_str\",\n \"types\": [\"uint64\",\"str\"]\n }\n ]\n}"
5+
"abi-file": "aliased_type_variant_template_arg.abi"
66
}
77
}
88
]
99
}
10-

0 commit comments

Comments
 (0)