EOS smart contract new compiler version 1.3.2 major change to syntax

in #programming5 years ago (edited)


Hello Steemit friends, so not long ago EOS introduced a new compiler called eosio.cdt version 1.3.2 which make a super drastic change to all the existing syntax, I would have to say at first I was extremely worried but later on I do find the new syntax is way cleaner and easier to code

Below is some area of changes

  • no more account_name, replace with eosio::name
  • no more N(variable), replace with "variable"_n
  • EOSIO_ABI replace with EOSIO_DISPATCH
  • S(4,SYS) replace with symbol("SYS", 4)
  • Action:
    • Old Syntax

    • [[eosio::action]]
              void myaction()
      
    • New Syntax
    • ACTION myaction()
      
  • Apply function that detect incoming transaction:
    • Old syntax
    • #undef EOSIO_ABI
      
      #define EOSIO_ABI( TYPE, MEMBERS ) \
      extern "C" { \
         void apply( uint64_t receiver, uint64_t code, uint64_t action ) { \
            auto self = receiver; \
            TYPE thiscontract( self ); \
            if( action == N(onerror)) { \
               /* onerror is only valid if it is for the "eosio" code account and authorized by "eosio"'s "active permission */ \
               eosio_assert(code == N(eosio), "onerror action's are only valid from the \"eosio\" system account"); \
            } \
            if( code == self ) { \
               if (action != N(transfer)) {\
                  switch( action ) { \
                      EOSIO_API( TYPE, MEMBERS ) \
                  } \
                  /* does not allow destructor of thiscontract to run: eosio_exit(0); */ \
               }\
            } \
            else if (code == N(eosio.token) && action == N(transfer) ) {\
                execute_action(&thiscontract, &dice::add);\
            }\
         } \
      }
      
    • New syntax
    • extern "C" {
          void apply(uint64_t receiver, uint64_t code, uint64_t action) {
              if(code==receiver)
              {
                  switch(action)
                  {
                      EOSIO_DISPATCH_HELPER( dice, (add) )
                  }
              }
              else if(code=="eosio.token"_n.value && action=="transfer"_n.value) {
                  execute_action( name(receiver), name(code), &dice::add);
              }
          }
      };
      
  • Table:
old syntax:
struct [[eosio::table]] mystruct3
      {
         uint64_t     key;
         uint64_t     secondid;
         std::string  name;
         account_name  account;
        std::string  memo1;
        std::string  memo2;
        std::string  memo3;
        std::string  memo4;
        asset quantity;

        mystruct3()
        : quantity(0, S(4, EOS))
        {}

         uint64_t primary_key() const { return key; } // getter for primary key
         uint64_t by_id() const {return secondid; } // getter for additional key

        EOSLIB_SERIALIZE(mystruct3,(key)(secondid)(name)(account)(memo1)(memo2)(memo3)(memo4)(quantity))



      };

        typedef eosio::multi_index<N(mystruct3), mystruct3> datastore;

New syntax:

TABLE mystruct3
      {
         uint64_t     key;
         uint64_t     secondid;
         std::string  name;
         eosio::name  account;
        std::string  memo1;
        std::string  memo2;
        std::string  memo3;
        std::string  memo4;
        eosio::asset quantity;

        

         uint64_t primary_key() const { return key; } // getter for primary key
         uint64_t by_id() const {return secondid; } // getter for additional key

      
      };

        typedef eosio::multi_index<"mystruct3"_n, mystruct3> datastore;

See how clean it is?

So yeah, I am glad the new syntax is way more cleaner and easier to code

thanks for reading <br /><center><hr/><em>Posted from my blog with <a href='https://wordpress.org/plugins/steempress/'>SteemPress</a> : http://fundurian.vornix.blog/2018/11/07/eos-smart-contract-new-compiler-version-1-3-2-major-change-to-syntax/ </em><hr/></center>

Sort:  

You’ve been upvoted by TeamMalaysia community. Here are trending posts by other TeamMalaysia authors at http://steemit.com/trending/teammalaysia

To support the growth of TeamMalaysia Follow our upvotes by using steemauto.com and follow trail of @myach

Vote TeamMalaysia witness bitrocker2020 using this link vote for witness

Hello! Your post has been resteemed and upvoted by @ilovecoding because we love coding! Keep up good work! Consider upvoting this comment to support the @ilovecoding and increase your future rewards! ^_^ Steem On!

Reply !stop to disable the comment. Thanks!

帅哥/美女!新人吗?《steemit指南》拿一份吧,以免迷路; 另外一定要去 @team-cn 的新手村看看,超级热闹的大家庭。如果不想再收到我的留言,请回复“取消”。

Congratulations! This post has been upvoted from the communal account, @minnowsupport, by fundurian from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows. Please find us at the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.

If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: 50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP.
Be sure to leave at least 50SP undelegated on your account.

Hi @fundurian!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your UA account score is currently 3.927 which ranks you at #3926 across all Steem accounts.
Your rank has dropped 17 places in the last three days (old rank 3909).

In our last Algorithmic Curation Round, consisting of 425 contributions, your post is ranked at #299.

Evaluation of your UA score:
  • You're on the right track, try to gather more followers.
  • The readers like your work!
  • Try to work on user engagement: the more people that interact with you via the comments, the higher your UA score!

Feel free to join our @steem-ua Discord server

Coin Marketplace

STEEM 0.26
TRX 0.11
JST 0.033
BTC 63851.10
ETH 3059.36
USDT 1.00
SBD 3.85