status-go/services/wallet
Roman Volosovskyi 9d5684162a
Stop fetching new blocks while app is not active
Saves some traffic (blocks with transactions are heavy) and infura
requests.
2020-03-11 08:39:41 +02:00
..
erc20 Add api method to query token balances 2019-07-05 08:38:29 +03:00
ierc20 Add api method to query token balances 2019-07-05 08:38:29 +03:00
README.md Cleanup after tx fetching changes 2020-02-09 12:05:36 +02:00
api.go Cleanup after tx fetching changes 2020-02-09 12:05:36 +02:00
async.go Watch new accounts aftter they were saved to accounts table (#1569) 2019-08-28 10:49:03 +03:00
balance.go Use goimports instead of gofmt 2020-01-06 10:17:23 +01:00
balance_cache.go status-im/status-react#9203 Faster tx fetching with less request 2020-01-23 10:36:11 +02:00
balance_test.go Use goimports instead of gofmt 2020-01-06 10:17:23 +01:00
commands.go [status-im/status-react#9927] Fast blocks sync after delay 2020-01-30 17:25:56 +02:00
commands_test.go [status-im/status-react#9927] Fast blocks sync after delay 2020-01-30 17:25:56 +02:00
concurrent.go [status-im/status-react#9927] Fast blocks sync after delay 2020-01-30 17:25:56 +02:00
concurrent_test.go [status-im/status-react#9927] Fast blocks sync after delay 2020-01-30 17:25:56 +02:00
database.go Cleanup after tx fetching changes 2020-02-09 12:05:36 +02:00
database_test.go status-im/status-react#9203 Faster tx fetching with less request 2020-01-23 10:36:11 +02:00
downloader.go status-im/status-react#9203 Faster tx fetching with less request 2020-01-23 10:36:11 +02:00
downloader_test.go Remove protocol and eth-node submodules (#1835) 2020-02-10 12:22:37 +01:00
events.go [status-im/status-react#9927] Fast blocks sync after delay 2020-01-30 17:25:56 +02:00
iterative.go status-im/status-react#9203 Faster tx fetching with less request 2020-01-23 10:36:11 +02:00
iterative_test.go status-im/status-react#9203 Faster tx fetching with less request 2020-01-23 10:36:11 +02:00
reactor.go [status-im/status-react#9927] Fast blocks sync after delay 2020-01-30 17:25:56 +02:00
service.go Stop fetching new blocks while app is not active 2020-03-11 08:39:41 +02:00
service_test.go Stop fetching new blocks while app is not active 2020-03-11 08:39:41 +02:00
transfer_view.go Simplify transfer object (#1521) 2019-07-15 14:16:07 +03:00
transfers_query.go Cleanup after tx fetching changes 2020-02-09 12:05:36 +02:00
transmitter.go status-im/status-react#9203 Faster tx fetching with less request 2020-01-23 10:36:11 +02:00

README.md

Wallet

Wallet service starts a loop that watches for new transfers (eth and erc20). To correctly start the service two values need to be changed in the config:

  1. Set Enable to true in WalletConfig
{
  "WalletConfig": {
    "Enabled": true,
  }
}
  1. And expose wallet API with APIModules
{
  APIModules: "eth,net,web3,peer,wallet",
}

API

wallet_getTransfersByAddress

Returns avaiable transfers in a given range.

Parameters
  • address: HEX - ethereum address encoded in hex
  • toBlock: BIGINT - end of the range. if nil query will return last transfers.
  • limit: BIGINT - limit of returned transfers.
Examples
{"jsonrpc":"2.0","id":7,"method":"wallet_getTransfersByAddress","params":["0xb81a6845649fa8c042dfaceb3f7a684873406993","0x0","0x5"]}
Returns

Objects in the same format.

wallet_getTokensBalances

Returns tokens balances mapping for every account. See section below for the response example.

Parameters
  • accounts HEX - list of ethereum addresses encoded in hex
  • tokens HEX - list of ethereum addresses encoded in hex
{"jsonrpc":"2.0","id":11,"method":"wallet_getTokensBalances","params":[["0x066ed5c2ed45d70ad72f40de0b4dd97bd67d84de", "0x0ed535be4c0aa276942a1a782669790547ad8768"], ["0x5e4bbdc178684478a615354d83c748a4393b20f0", "0x5e4bbdc178684478a615354d83c748a4393b20f0"]]}

Returns

First level keys accounts, second level keys are tokens.

{
  "0x066ed5c2ed45d70ad72f40de0b4dd97bd67d84de": {
    "0x1dfb2099f936b3e98bfc9b7059a8fb04edcce5b3": 12,
    "0x5e4bbdc178684478a615354d83c748a4393b20f0": 12
  },
  "0x0ed535be4c0aa276942a1a782669790547ad8768": {
    "0x1dfb2099f936b3e98bfc9b7059a8fb04edcce5b3": 14,
    "0x5e4bbdc178684478a615354d83c748a4393b20f0": 14
  }
}

Signals

Two signals can be emitted:

  1. newblock signal

Emitted when transfers from new block were added to the database. In this case block number if the number of this new block. Client expected to request transfers starting from received block.

{
  "type": "wallet",
  "event": {
    "type": "newblock",
    "blockNumber": 0,
    "accounts": [
      "0x42c8f505b4006d417dd4e0ba0e880692986adbd8",
      "0x3129mdasmeo132128391fml1130410k312312mll"
    ]
  }
}
  1. reorg signal.

Emitted when part of blocks were removed. Starting from a given block number all transfers were removed. Client expected to request new transfers from received block and replace transfers that were received previously.

{
  "type": "wallet",
  "event": {
    "type": "reorg",
    "blockNumber": 0,
    "accounts": [
      "0x42c8f505b4006d417dd4e0ba0e880692986adbd8"
    ]
  }
}
  1. history signal

Emmited when historical transfers were downloaded. Block number will refer the first block where historical transfers were found.

{
  "type": "wallet",
  "event": {
    "type": "history",
    "blockNumber": 0,
    "accounts": [
      "0x42c8f505b4006d417dd4e0ba0e880692986adbd8"
    ]
  }
}