0

I'm learning to make my own contract and I'm having a hard time getting LNX that is transferred to the contract to be recorded ad a balance.

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

using namespace std;
using namespace eosio;

class [[eosio::contract]] elevated : public eosio::contract {

  public:
    const symbol _symbol;
    elevated(name receiver, name code, datastream<const char*> ds ):contract(receiver, code, ds),_symbol("LNX", 8) {}

    [[eosio::action]]
    void login (name username) {
      require_auth(username);
      users_table _users(get_self(), get_first_receiver().value);
      auto iterator = _users.find(username.value);

      if (iterator == _users.end()) {
        iterator = _users.emplace(username, [&](auto& new_user) {
          new_user.username = username;
        });
      }

    };

    [[eosio::on_notify("eosio.token::transfer")]]
    void deposit(name from, name to, eosio::asset quantity, std::string memo) {
      if (from == get_self() || to != get_self())
      {
        print("This doesnt print");
        return;
      }
      balance_table _balance(get_self(), from.value);
      auto iterator = _balance.find(_symbol.raw());

      if (iterator == _balance.end())
        iterator = _balance.emplace(get_self(), [&](auto& new_balance) {
          new_balance.funds = quantity;
        });
      else _balance.modify(iterator, get_self(), [&](auto& new_balance) {
        new_balance.funds += quantity;
      });
    }

  private:

    struct [[eosio::table]] user_info {
      name username;
      auto primary_key() const {
        return username.value;
      }
    };
    typedef eosio::multi_index<name("users"), user_info> users_table;

    struct [[eosio::table]] balance {
      eosio::asset funds;
      uint64_t primary_key() const { 
        return funds.symbol.raw();
        }
    };
    typedef eosio::multi_index<name("balance"), balance> balance_table;

};

I'm calling the contract with cleos -u https://testnet.lynx.eosdetroit.io:443 transfer account00001 account00002 '1.00000000 LNX' 'Test Balance' -p account00001@active

Your Answer

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

Browse other questions tagged or ask your own question.