3

Anyone is working on some ICO/Payment contacts?
What I would like to learn are following functionalities within the contract:

  1. Payment, where the fee is split into 3 accounts.

    a) So user sends a fee in some token (defined in separate contract), there is a check if the balance is positibe, and then fee is divided and send to three accounts.

  2. A user sends EOS (SYS) token and receives application token with a given exchange rate

  3. The transaction can be executed only within certain time frames. If not then it is rejected.

Any github sample to share?

3

Look at this example:

https://gist.github.com/MikkySnow/feac6fd5a9d49da207b9bd59d3c672c4

Hope it will help you

#include <eosiolib/eosio.hpp>
#include <eosiolib/currency.hpp>

using namespace eosio;

class hello : public eosio::contract {
  public:
      using contract::contract;

      hello(account_name self) : contract(self) {}

      /// @abi table 
      struct account {
        account_name owner;
        uint64_t balance;

        uint64_t primary_key() const { return owner; };
      };

      typedef eosio::multi_index<N(account), account> accs; 

      /// @abi action 
      void addbalance(account_name owner, uint64_t amount) {
         accs accounts(_self, owner);
         auto existing = accounts.find(owner);

         if (existing == accounts.end())
         {
            /* Add new account */
            accounts.emplace(_self, [&](auto& a) {
                a.owner = owner;
                a.balance = amount;
            });
         } else {
            /* Update existing account */
            const auto& st = *existing;
            accounts.modify(st, 0, [&](auto& a) {
                a.balance += amount;
            });
         }
      }

      void on(const currency::transfer& t) {
        if (t.to == _self) {
            addbalance(t.from, t.quantity.amount);
        }
      }

      void use(account_name contract, account_name act) {
        if (act == N(transfer)) {
            on(unpack_action_data<currency::transfer>());
            return;
        }

        auto& thiscontract = *this;
        switch( act ) {
            EOSIO_API( hello, (addbalance));
        };
      }
};

extern "C" {
   [[noreturn]] void apply( uint64_t receiver, uint64_t code, uint64_t action ) {
      hello  h( receiver );
      h.use( code, action );
      eosio_exit(0);
   }
}
  • I would like to Update this code to CDT 1.5 or CDT 1.6. What I need change ? – Efraim May 27 '19 at 11:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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