Skip to content

Conversation

@linh2931
Copy link
Contributor

@linh2931 linh2931 commented Jul 8, 2025

Change Description

Work in progress:

This PR adds support of long sync call function names. Now a sync call function name can be any valid C++ identifier with max length of 128 characters. This provides much flexibilities in choosing sync call function names than using eosio::name.

Please note, this is a quick implementation for dev-preview-1. Internal implementation might be changed in dev-preview-2 but user-faced interface should keep the same.

Resolves #361

The following is a working example of using C++ identifiers for sync call function names.

#include <eosio/call.hpp>
#include <eosio/eosio.hpp>

struct struct1_t {
   int64_t a;
   uint64_t b;
};

struct struct2_t {
   char a;
   bool b;
   int64_t c;
   uint64_t d;
};

class [[eosio::contract]] sync_call_callee : public eosio::contract{
public:
   using contract::contract;

   [[eosio::call]]
   uint32_t return_ten();

   [[eosio::call]]
   uint32_t echo_input(uint32_t in);

   [[eosio::call]]
   void void_func();

   [[eosio::call]]
   uint32_t sum(uint32_t a, uint32_t b, uint32_t c);

   // pass in a struct and return it
   [[eosio::call]]
   struct1_t pass_single_struct(struct1_t s);

   // pass in two structs and an integer, multiply each field in the struct by
   // the integer, add last two fields of the second struct, and return the result
   [[eosio::call]]
   struct1_t pass_multi_structs(struct1_t s1, int32_t m, struct2_t s2);

   using return_ten_func = eosio::call_wrapper<"return_ten"_i, &sync_call_callee::return_ten>;
   using echo_input_func = eosio::call_wrapper<"echo_input"_i, &sync_call_callee::echo_input>;
   using void_func_func = eosio::call_wrapper<"void_func"_i, &sync_call_callee::void_func>;
   using sum_func = eosio::call_wrapper<"sum"_i, &sync_call_callee::sum>;
   using pass_single_struct_func = eosio::call_wrapper<"pass_single_struct"_i, &sync_call_callee::pass_single_struct>;
   using pass_multi_structs_func = eosio::call_wrapper<"pass_multi_structs"_i, &sync_call_callee::pass_multi_structs>;

   using void_no_op_success_func = eosio::call_wrapper<"void_func"_i, &sync_call_callee::void_func, eosio::access_mode::read_write, eosio::support_mode::no_op>;
   using sum_no_op_success_func = eosio::call_wrapper<"sum"_i, &sync_call_callee::sum, eosio::access_mode::read_write, eosio::support_mode::no_op>;
};

ABI for sync calls looks like

    "calls": [
        {
            "name": "echo_input",
            "type": "echo_input",
            "id": 8246257893603280403
        },
        {
            "name": "pass_multi_structs",
            "type": "pass_multi_structs",
            "id": 6647878943616557085
        },
...

API Changes

  • API Changes

Documentation Additions

  • Documentation Additions

@linh2931 linh2931 marked this pull request as draft July 8, 2025 19:13
@linh2931 linh2931 marked this pull request as ready for review July 9, 2025 18:20
@linh2931 linh2931 requested review from heifner and spoonincode July 9, 2025 18:20
@linh2931 linh2931 linked an issue Jul 9, 2025 that may be closed by this pull request
Base automatically changed from call_abi to sync_call July 9, 2025 21:00

// Validate the input `str` is a valid C/C++ identifier
template <typename Lambda>
void validate_identifier( const std::string& str, Lambda&& error_handler ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should rename to validate_hash_id.

}
}

uint64_t identifier_to_id(std::string str) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should rename to to_hash_id

@linh2931 linh2931 merged commit 3793b76 into sync_call Jul 11, 2025
7 checks passed
@linh2931 linh2931 deleted the long_names branch July 11, 2025 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SC: Support long sync call function names

3 participants