2

Any help why I'm getting empty actions?

{
  "____comment": "This file was generated by eosio-abigen. DO NOT EDIT - 2018-08-22T01:21:53",
  "version": "eosio::abi/1.0",
  "types": [],
  "structs": [{
      "name": "account",
      "base": "",
      "fields": [{
          "name": "balance",
          "type": "asset"
        }
      ]
    },{
      "name": "currencystat",
      "base": "",
      "fields": [{
          "name": "supply",
          "type": "asset"
        },{
          "name": "max_supply",
          "type": "asset"
        },{
          "name": "issuer",
          "type": "name"
        }
      ]
    }
  ],
  "actions": [],
  "tables": [{
      "name": "accounts",
      "index_type": "i64",
      "key_names": [
        "balance"
      ],
      "key_types": [
        "asset"
      ],
      "type": "account"
    },{
      "name": "stat",
      "index_type": "i64",
      "key_names": [
        "supply"
      ],
      "key_types": [
        "asset"
      ],
      "type": "currencystat"
    }
  ],
  "ricardian_clauses": [],
  "error_messages": [],
  "abi_extensions": []
}

My .cpp file

#include "eosio.token.hpp"

namespace eosio {

   using std::string;

   class token : public contract {
      public:
         token( account_name self ):contract(self){}

          //@abi action
         void create( account_name issuer,
                    asset        maximum_supply )
          {
              require_auth( _self );

              auto sym = maximum_supply.symbol;
              eosio_assert( sym.is_valid(), "invalid symbol name" );
              eosio_assert( maximum_supply.is_valid(), "invalid supply");
              eosio_assert( maximum_supply.amount > 0, "max-supply must be positive");

              stats statstable( _self, sym.name() );
              auto existing = statstable.find( sym.name() );
              eosio_assert( existing == statstable.end(), "token with symbol already exists" );

              statstable.emplace( _self, [&]( auto& s ) {
                 s.supply.symbol = maximum_supply.symbol;
                 s.max_supply    = maximum_supply;
                 s.issuer        = issuer;
              });
          }
          //@abi action
         void issue( account_name to, asset quantity, string memo )
          {
              auto sym = quantity.symbol;
              eosio_assert( sym.is_valid(), "invalid symbol name" );
              eosio_assert( memo.size() <= 256, "memo has more than 256 bytes" );

              auto sym_name = sym.name();
              stats statstable( _self, sym_name );
              auto existing = statstable.find( sym_name );
              eosio_assert( existing != statstable.end(), "token with symbol does not exist, create token before issue" );
              const auto& st = *existing;

              require_auth( st.issuer );
              eosio_assert( quantity.is_valid(), "invalid quantity" );
              eosio_assert( quantity.amount > 0, "must issue positive quantity" );

              eosio_assert( quantity.symbol == st.supply.symbol, "symbol precision mismatch" );
              eosio_assert( quantity.amount <= st.max_supply.amount - st.supply.amount, "quantity exceeds available supply");

              statstable.modify( st, 0, [&]( auto& s ) {
                 s.supply += quantity;
              });

              add_balance( st.issuer, quantity, st.issuer );

              if( to != st.issuer ) {
                 SEND_INLINE_ACTION( *this, transfer, {st.issuer,N(active)}, {st.issuer, to, quantity, memo} );
              }
          }

          //@abi action
         void transfer( account_name from,
                      account_name to,
                      asset        quantity,
                      string       memo )
          {
              eosio_assert( from != to, "cannot transfer to self" );
              require_auth( from );
              eosio_assert( is_account( to ), "to account does not exist");
              auto sym = quantity.symbol.name();
              stats statstable( _self, sym );
              const auto& st = statstable.get( sym );

              require_recipient( from );
              require_recipient( to );

              eosio_assert( quantity.is_valid(), "invalid quantity" );
              eosio_assert( quantity.amount > 0, "must transfer positive quantity" );
              eosio_assert( quantity.symbol == st.supply.symbol, "symbol precision mismatch" );
              eosio_assert( memo.size() <= 256, "memo has more than 256 bytes" );


              sub_balance( from, quantity );
              add_balance( to, quantity, from );
          }


         inline asset get_supply( symbol_name sym )const;

         inline asset get_balance( account_name owner, symbol_name sym )const;

      private:
  // @abi table accounts i64
         struct account {
            asset    balance;

            uint64_t primary_key()const { return balance.symbol.name(); }
         };

  // @abi table stat i64
         struct currencystat {
            asset          supply;
            asset          max_supply;
            account_name   issuer;

            uint64_t primary_key()const { return supply.symbol.name(); }
         };

         typedef eosio::multi_index<N(accounts), account> accounts;
         typedef eosio::multi_index<N(stat), currencystat> stats;

         void sub_balance( account_name owner, asset value ) {
           accounts from_acnts( _self, owner );

           const auto& from = from_acnts.get( value.symbol.name(), "no balance object found" );
           eosio_assert( from.balance.amount >= value.amount, "overdrawn balance" );


           if( from.balance.amount == value.amount ) {
              from_acnts.erase( from );
           } else {
              from_acnts.modify( from, owner, [&]( auto& a ) {
                  a.balance -= value;
              });
           }
        }

        void add_balance( account_name owner, asset value, account_name ram_payer )
        {
           accounts to_acnts( _self, owner );
           auto to = to_acnts.find( value.symbol.name() );
           if( to == to_acnts.end() ) {
              to_acnts.emplace( ram_payer, [&]( auto& a ){
                a.balance = value;
              });
           } else {
              to_acnts.modify( to, 0, [&]( auto& a ) {
                a.balance += value;
              });
           }
        }

      public:
         struct transfer_args {
            account_name  from;
            account_name  to;
            asset         quantity;
            string        memo;
         };
   };

   asset token::get_supply( symbol_name sym )const
   {
      stats statstable( _self, sym );
      const auto& st = statstable.get( sym );
      return st.supply;
   }

   asset token::get_balance( account_name owner, symbol_name sym )const
   {
      accounts accountstable( _self, owner );
      const auto& ac = accountstable.get( sym );
      return ac.balance;
   }

} /// namespace eosio

EOSIO_ABI( eosio::token, (create)(issue)(transfer) )

1 Answer 1

2

Your code should be like this

// @abi action 
void token::create( account_name issuer,
                    asset        maximum_supply )
{
    require_auth( _self );

    auto sym = maximum_supply.symbol;
    eosio_assert( sym.is_valid(), "invalid symbol name" );
    eosio_assert( maximum_supply.is_valid(), "invalid supply");
    eosio_assert( maximum_supply.amount > 0, "max-supply must be positive");

    stats statstable( _self, sym.name() );
    auto existing = statstable.find( sym.name() );
    eosio_assert( existing == statstable.end(), "token with symbol already exists" );

    statstable.emplace( _self, [&]( auto& s ) {
       s.supply.symbol = maximum_supply.symbol;
       s.max_supply    = maximum_supply;
       s.issuer        = issuer;
    });
}

write the class name token before your function definition .Like I write ,But for better practice you should not copy and paste eosio.token.cpp function in your code ,give permission of eosio.code and just use them .

One more thing I want to add : I think you are using eosio.token.cpp functions in your contract .I will suggest you not to do that instead of this you can import eosio.token.hpp into your contract.You can use eosio.token to assign token and even you can use transfer function of eosio.token without copying the code . For that you have to provide permission just like this

cleos set account permission your_account_1 active '{"threshold": 1,"keys": [{"key": "active_key of your_account_1","weight": 1}],"accounts": [{"permission":{"actor":"your_account2","permission":"eosio.code"},"weight":1}]}' owner -p your_account_1

where your_account_1 is that account by which you set the contract and your_account2 which you are setting permission .Now you can use these function without rewriting them into your contract.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.