Skip to main content
2 of 10
added 37 characters in body
Nat
  • 3.4k
  • 14
  • 23

Current account balance is held in a row in the multi index container which is RAM.

From the eosio.token contract:

struct account {
    asset    balance;

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

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

So when you want to transfer, the contract will iterate through the multi index container to find your "balance" based on your account name. From there you can see the logic for a transfer here:

void token::transfer( account_name from,
                      account_name to,
                      asset        quantity,
                      string       memo )
{
    eosio_assert( from != to, "cannot transfer to self" );
    require_auth( from ); // requiring signature
    eosio_assert( is_account( to ), "to account does not exist");
    auto sym = quantity.symbol.name();
    stats statstable( _self, sym ); //pulling multi index container
    const auto& st = statstable.get( sym );

    require_recipient( from );
    require_recipient( to );
    // Assertions (if any fail, entire transaction is unwound)
    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 );
}

So in essence, the contract isn't going through all of your previous transactions to prove that you have that balance, it trusts the balance it pulls from the multi index container and acts off of it.


To get the historical actions from an account, you don't need the mongodb database for that, you can use cleos or the RPC api and do:

./cleos -u https://nodes.get-scatter.com:443 get actions moonaccount1

If you want to go further back, just add the action you want to start with at the end of the call.

./cleos -u https://nodes.get-scatter.com:443 get actions moonaccount1 20

#    0   2018-11-22T05:36:09.500     eosio.token::transfer => moonaccount1  edd0c861... {"from":"fairdapp1111","to":"moonaccount1","quantity":"200.0...
#    1   2018-11-22T05:36:56.500     chintailease::prepare => chintailease  32636812... {"memo":"moonaccount1|1|2000|0.0055|28|1.0000|3lmgzl0ybr"}...
#    2   2018-11-22T05:36:56.500     eosio.token::transfer => eosio.token   32636812... {"from":"moonaccount1","to":"chintailease","quantity":"11.00...
#    3   2018-11-22T05:36:56.500     eosio.token::transfer => moonaccount1  32636812... {"from":"moonaccount1","to":"chintailease","quantity":"11.00...
#    4   2018-11-22T05:36:56.500     eosio.token::transfer => chintailease  32636812... {"from":"moonaccount1","to":"chintailease","quantity":"11.00...
#    5   2018-11-22T05:36:56.500    chintailease::activate => chintailease  32636812... {"memo":"moonaccount1|1|2000|0.0055|28|1.0000|3lmgzl0ybr"}...
#    6   2018-11-22T05:50:08.500     eosio.token::transfer => eosio.token   3d87fcdd... {"from":"moonaccount1","to":"eospokerwins","quantity":"3.000...
#    7   2018-11-22T05:50:08.500     eosio.token::transfer => moonaccount1  3d87fcdd... {"from":"moonaccount1","to":"eospokerwins","quantity":"3.000...
#    8   2018-11-22T05:50:08.500     eosio.token::transfer => eospokerwins  3d87fcdd... {"from":"moonaccount1","to":"eospokerwins","quantity":"3.000...
#    9   2018-11-22T05:50:18.500         eospokerwins::hit => eospokerwins  b3e0ebb4... {"player":"moonaccount1","hand":1,"slot":3}...
#   10   2018-11-22T05:50:19.000    eospokercoin::transfer => moonaccount1  be9f0010... {"from":"eospokermine","to":"moonaccount1","quantity":"0.056...
#   11   2018-11-22T05:50:35.500     eosio.token::transfer => eosio.token   73f1f85d... {"from":"moonaccount1","to":"eospokerwins","quantity":"3.000...
#   12   2018-11-22T05:50:35.500     eosio.token::transfer => moonaccount1  73f1f85d... {"from":"moonaccount1","to":"eospokerwins","quantity":"3.000...
#   13   2018-11-22T05:50:35.500     eosio.token::transfer => eospokerwins  73f1f85d... {"from":"moonaccount1","to":"eospokerwins","quantity":"3.000...
#   14   2018-11-22T05:50:47.000       eospokerwins::stand => eospokerwins  f314b6f8... {"player":"moonaccount1","hand":1}...
#   15   2018-11-22T05:50:48.000     eosio.token::transfer => moonaccount1  7dc88fe9... {"from":"eospokerwins","to":"moonaccount1","quantity":"3.000...
#   16   2018-11-22T05:50:48.000    eospokercoin::transfer => moonaccount1  7dc88fe9... {"from":"eospokermine","to":"moonaccount1","quantity":"0.056...
#   17   2018-11-22T05:51:02.500     eosio.token::transfer => eosio.token   47e6de1f... {"from":"moonaccount1","to":"eospokerwins","quantity":"3.000...
#   18   2018-11-22T05:51:02.500     eosio.token::transfer => moonaccount1  47e6de1f... {"from":"moonaccount1","to":"eospokerwins","quantity":"3.000...
#   19   2018-11-22T05:51:02.500     eosio.token::transfer => eospokerwins  47e6de1f... {"from":"moonaccount1","to":"eospokerwins","quantity":"3.000...
#   20   2018-11-22T05:51:12.000       eospokerwins::stand => eospokerwins  d876a62a... {"player":"moonaccount1","hand":1}...
Nat
  • 3.4k
  • 14
  • 23