wallet

package
v0.79.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2021 License: MPL-2.0 Imports: 32 Imported by: 0

README

Wallet service API

Wallet service provides RPC API for checking transfers history and other methods related to wallet functionality. To enable 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.
  • fetchMore: BOOLEAN - if true, there are less than limit fetched transfers in the database, and zero block is not reached yet, history will be scanned for more transfers. If false only transfers which are already fetched to the app's database will be returned.
Examples
{
  "jsonrpc":"2.0",
  "id":7,
  "method":"wallet_getTransfersByAddress",
  "params":[
    "0xb81a6845649fa8c042dfaceb3f7a684873406993",
    "0x0",
    "0x5",
    true
  ]
}
Returns
[
  {
    "id":"0xb1a8adeaa0e6727bf01d6d8431b6238bdefa915e19ae7e8ceb16886c9f5e",
    "type":"eth",
    "address":"0xd65f3cb52605a54a833ae118fb13",
    "blockNumber":"0xb7190",
    "blockhash":"0x8d98aa2297fe322d0093b24372e2ead98414959093b479baf670",
    "timestamp":"0x6048ec6",
    "gasPrice":"0x346308a00",
    "gasLimit":"0x508",
    "gasUsed":"0x520",
    "nonce":"0x13",
    "txStatus":"0x1",
    "input":"0x",
    "txHash":"0x1adeaa0e672d7e67bf01d8431b6238bdef15e19ae7e8ceb16886c",
    "value":"0x1",
    "from":"0x2f865fb5dfdf0dfdf54a833ae118fb1363aaasd",
    "to":"0xaaaaaaf3cb52605a54a833ae118fb1363a123123",
    "contract":"0x0000000000000000000000000000000000000000",
    "NetworkID":1
  },...
]
wallet_setInitialBlocksRange

Sets zero block - latest block range as scanned for an account. It is used when a new multiaccount is generated to avoid scanning transfers history.

Example
{"jsonrpc":"2.0","id":7,"method":"wallet_setInitialBlocksRange","params":[]}
wallet_watchTransaction

Starts watching for transaction confirmation/rejection. If transaction was not confirmed/rejected in 10 minutes the call is timed out with error.

Parameters
  • tx-id: HEX - transaction hash
Example
{
  "jsonrpc":"2.0",
  "id":7,
  "method":"wallet_watchTransaction",
  "params":[
    "0xaaaaaaaa11111112222233333333"
  ]
}
wallet_checkRecentHistory
Parameters
  • addresses: []HEX - array of addresses to be checked
Example
{
  "jsonrpc":"2.0",
  "id":1,
  "method":"wallet_checkRecentHistory",
  "params":[
    [
      "0x23458d65f3cB52605a54AaA833ae118fb1111aaa",
      "0x24568B4166D11aaa1194097C60Cdc714F7e11111"
    ]
  ]
}
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
Request
{"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
  }
}
wallet_storePendingTransaction

Stores pending transation in the database.

Parameters
  • transaction OBJECT - list of ethereum addresses encoded in hex
Transaction
  • hash HEX
  • timestamp ``INT`
  • from HEX
  • to HEX
  • symbol VARCHAR - "ETH" for ethereum, otherwise ERC20 tokaen name, null for contract call
  • gasPrice BIGINT
  • gasLimit BIGINT
  • value BIGINT
  • data TEXT - transaction's data field
  • type VARCHAR
  • additionalData TEXT - arbitrary additional data
Request example
{
  "jsonrpc":"2.0",
  "id":1,
  "method":"wallet_storePendingTransaction",
  "params":[
    {
      "hash":"0x3bce2c2d0fffbd2862ef3ec61a62872e54954551585fa0072d8e5c2f6be3523e",
      "symbol":"ETH",
      "gasPrice":"2000000000",
      "value":"1000000000000000",
      "from":"0xaaaad65f3cB52605433ae118fb1363aaaaad2",
      "timestamp":1618584138787,
      "gasLimit":"21000",
      "to":"0x237f8B4166D64a2b94097C60Cdc714F7eC3aa079",
      "data":null
    }
  ]
}
wallet_getPendingTransactions

Returns all stored pending transactions.

Request
{"jsonrpc":"2.0","id":1,"method":"wallet_getPendingTransactions","params":[]}
Returns

First level keys accounts, second level keys are tokens.

{
  "jsonrpc":"2.0",
  "id":1,
  "result":[
    {
      "hash":"0x3bce2c2d0fffbd2862ef3ec61a62872e54954551585fa0072d8e5c2f6be3523e",
      "timestamp":1618584138787,
      "value":"1000000000000000",
      "from":"0xaaaaaaaa605a54a833ae118fb1aaaaaaaaaaa",
      "to":"0x237f8b4166d64a2b94097c60cdc714f7ec3aa079",
      "data":"",
      "symbol":"ETH",
      "gasPrice":"2000000000",
      "gasLimit":"21000",
      "type":"",
      "additionalData":""
    },
    ...
  ]
}
wallet_getPendingOutboundTransactionsByAddress

Returns all stored pending transaction sent from address.

Parameters
  • address HEX
Request
{
  "jsonrpc":"2.0",
  "id":1,
  "method":"wallet_getPendingOutboundTransactionsByAddress",
  "params":[
    "0xaaaaaaaa605a54a833ae118fb1aaaaaaaaaaa"
  ]
}
Returns

First level keys accounts, second level keys are tokens.

{
  "jsonrpc":"2.0",
  "id":1,
  "result":[
    {
      "hash":"0x3bce2c2d0fffbd2862ef3ec61a62872e54954551585fa0072d8e5c2f6be3523e",
      "timestamp":1618584138787,
      "value":"1000000000000000",
      "from":"0xaaaaaaaa605a54a833ae118fb1aaaaaaaaaaa",
      "to":"0x237f8b4166d64a2b94097c60cdc714f7ec3aa079",
      "data":"",
      "symbol":"ETH",
      "gasPrice":"2000000000",
      "gasLimit":"21000",
      "type":"",
      "additionalData":""
    },
    ...
  ]
}
wallet_deletePendingTransaction

Deletes pending transaction from the database by hash.

Parameters
  • hash HEX
Request
{
  "jsonrpc":"2.0",
  "id":1,
  "method":"wallet_deletePendingTransaction",
  "params":[
    "0x3bce2c2d0fffbd2862ef3ec61a62872e54954551585fa0072d8e5c2f6be3523e"
  ]
}

Signals


All events are of the same format:

{
  "type": "wallet",
  "event": {
    "type": "event-type",
    "blockNumber": 0,
    "accounts": [
      "0x42c8f505b4006d417dd4e0ba0e880692986adbd8",
      "0x3129mdasmeo132128391fml1130410k312312mll"
    ],
    "message": "something might be here"
  }
}
  1. new-transfers

Emitted when transfers are detected. In this case block number is a block number of the latest found transfer. Client expected to request transfers starting from received block.

  1. recent-history-fetching

Emitted when history scanning is started.

  1. recent-history-ready

Emitted when history scanning is ended.

  1. fetching-history-error

Emitted when when history can't be fetched because some error. Error's decritption can be found in message field.

  1. non-archival-node-detected

Emitted when the application is connected to a non-archival node.

Flows

Account creation

When a new multiaccount is created corresponding address will not contain any transaction. Thus no point in checking history, it will be empty.

  1. Call wallet_setInitialRange
  2. Call wallet_checkRecentHistory
  3. On recent-history-ready request transactions via wallet_getTransfersByAddress
  4. Repeat wallet_checkRecentHistory in N minutes (currently 20 minutes in status-react for upstream RPC node. If a custom node is used interval can be arbitrary)
Logging into application
  1. Call wallet_checkRecentHistory
  2. On recent-history-ready request transactions via wallet_getTransfersByAddress
  3. Repeat wallet_checkRecentHistory in N minutes (currently 20 minutes in status-react for upstream RPC node. If a custom node is used interval can be arbitrary)
Watching transaction
  1. Call wallet_watchTransaction
  2. On success call wallet_checkRecentHistory
  3. On recent-history-ready request transactions via wallet_getTransfersByAddress

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrServiceNotInitialized returned when wallet is not initialized/started,.
	ErrServiceNotInitialized = errors.New("wallet service is not initialized")
)

Functions

func GetTokensBalances

func GetTokensBalances(parent context.Context, client *walletClient, accounts, tokens []common.Address) (map[common.Address]map[common.Address]*hexutil.Big, error)

GetTokensBalances takes list of accounts and tokens and returns mapping of token balances for each account.

func IsTokenTransfer added in v0.39.6

func IsTokenTransfer(logs []*types.Log) bool

func WatchAccountsChanges

func WatchAccountsChanges(ctx context.Context, feed *event.Feed, initial []common.Address, reactor *Reactor) error

WatchAccountsChanges subsribes to a feed and watches for changes in accounts list. If there are new or removed accounts reactor will be restarted.

Types

type API

type API struct {
	// contains filtered or unexported fields
}

API is class with methods available over RPC.

func NewAPI

func NewAPI(s *Service) *API

func (*API) AddCustomToken added in v0.38.1

func (api *API) AddCustomToken(ctx context.Context, token Token) error

func (*API) AddFavourite added in v0.62.2

func (api *API) AddFavourite(ctx context.Context, favourite Favourite) error

func (*API) CheckRecentHistory added in v0.75.0

func (api *API) CheckRecentHistory(ctx context.Context, addresses []common.Address) error

func (*API) DeleteCustomToken added in v0.38.1

func (api *API) DeleteCustomToken(ctx context.Context, address common.Address) error

func (*API) DeletePendingTransaction added in v0.62.0

func (api *API) DeletePendingTransaction(ctx context.Context, transactionHash common.Hash) error

func (*API) GetCachedBalances added in v0.79.4

func (api *API) GetCachedBalances(ctx context.Context, addresses []common.Address) ([]LastKnownBlockView, error)

func (*API) GetCryptoOnRamps added in v0.71.4

func (api *API) GetCryptoOnRamps(ctx context.Context) ([]CryptoOnRamp, error)

func (*API) GetCustomTokens added in v0.38.1

func (api *API) GetCustomTokens(ctx context.Context) ([]*Token, error)

func (*API) GetFavourites added in v0.62.2

func (api *API) GetFavourites(ctx context.Context) ([]*Favourite, error)

func (*API) GetPendingOutboundTransactionsByAddress added in v0.62.0

func (api *API) GetPendingOutboundTransactionsByAddress(ctx context.Context, address common.Address) ([]*PendingTransaction, error)

func (*API) GetPendingTransactions added in v0.62.0

func (api *API) GetPendingTransactions(ctx context.Context) ([]*PendingTransaction, error)

func (*API) GetTokensBalances

func (api *API) GetTokensBalances(ctx context.Context, accounts, tokens []common.Address) (map[common.Address]map[common.Address]*hexutil.Big, error)

GetTokensBalances return mapping of token balances for every account.

func (*API) GetTransfersByAddress

func (api *API) GetTransfersByAddress(ctx context.Context, address common.Address, toBlock, limit *hexutil.Big, fetchMore bool) ([]TransferView, error)

GetTransfersByAddress returns transfers for a single address

func (*API) SetInitialBlocksRange added in v0.73.1

func (api *API) SetInitialBlocksRange(ctx context.Context) error

SetInitialBlocksRange sets initial blocks range

func (*API) StorePendingTransaction added in v0.62.0

func (api *API) StorePendingTransaction(ctx context.Context, trx PendingTransaction) error

func (*API) WatchTransaction added in v0.74.1

func (api *API) WatchTransaction(ctx context.Context, transactionHash common.Hash) error

type AtomicGroup

type AtomicGroup struct {
	// contains filtered or unexported fields
}

AtomicGroup terminates as soon as first goroutine terminates..

func NewAtomicGroup

func NewAtomicGroup(parent context.Context) *AtomicGroup

func (*AtomicGroup) Add

func (d *AtomicGroup) Add(cmd Command)

Go spawns function in a goroutine and stores results or errors.

func (*AtomicGroup) Error

func (d *AtomicGroup) Error() error

Error stores an error that was reported by any of the downloader. Should be called after Wait.

func (*AtomicGroup) Stop

func (d *AtomicGroup) Stop()

func (*AtomicGroup) Wait

func (d *AtomicGroup) Wait()

Wait for all downloaders to finish.

func (*AtomicGroup) WaitAsync

func (d *AtomicGroup) WaitAsync() <-chan struct{}

type BalanceCache added in v0.40.0

type BalanceCache interface {
	BalanceAt(ctx context.Context, client BalanceReader, account common.Address, blockNumber *big.Int) (*big.Int, error)
	NonceAt(ctx context.Context, client BalanceReader, account common.Address, blockNumber *big.Int) (*int64, error)
}

type BalanceReader

type BalanceReader interface {
	BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
	NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)
	HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
}

BalanceReader interface for reading balance at a specifeid address.

type BatchDownloader

type BatchDownloader interface {
	GetHeadersInRange(ctx context.Context, from, to *big.Int) ([]*DBHeader, error)
}

BatchDownloader interface for loading transfers in batches in speificed range of blocks.

type BigInt added in v0.77.0

type BigInt struct {
	*big.Int
}

func (BigInt) MarshalJSON added in v0.77.0

func (b BigInt) MarshalJSON() ([]byte, error)

func (*BigInt) UnmarshalJSON added in v0.77.0

func (b *BigInt) UnmarshalJSON(p []byte) error

type BlocksRange added in v0.70.1

type BlocksRange struct {
	// contains filtered or unexported fields
}

type Command

type Command func(context.Context) error

type ConcurrentDownloader

type ConcurrentDownloader struct {
	*AtomicGroup
	*Result
}

func NewConcurrentDownloader

func NewConcurrentDownloader(ctx context.Context) *ConcurrentDownloader

NewConcurrentDownloader creates ConcurrentDownloader instance.

type CryptoOnRamp added in v0.71.4

type CryptoOnRamp struct {
	Name        string            `json:"name"`
	Description string            `json:"description"`
	Fees        string            `json:"fees"`
	LogoURL     string            `json:"logoUrl"`
	SiteURL     string            `json:"siteUrl"`
	Hostname    string            `json:"hostname"`
	Params      map[string]string `json:"params"` // TODO implement params in JSON and parsing status-react
}

type CryptoOnRampManager added in v0.71.4

type CryptoOnRampManager struct {
	LastCalled time.Time
	// contains filtered or unexported fields
}

func NewCryptoOnRampManager added in v0.71.4

func NewCryptoOnRampManager(options *CryptoOnRampOptions) *CryptoOnRampManager

func (*CryptoOnRampManager) Get added in v0.71.4

func (c *CryptoOnRampManager) Get() ([]CryptoOnRamp, error)

type CryptoOnRampOptions added in v0.71.4

type CryptoOnRampOptions struct {
	// contains filtered or unexported fields
}

type DBHeader

type DBHeader struct {
	Number         *big.Int
	Hash           common.Hash
	Timestamp      uint64
	Erc20Transfers []*Transfer
	Network        uint64
	Address        common.Address
	// Head is true if the block was a head at the time it was pulled from chain.
	Head bool
	// Loaded is true if trasfers from this block has been already fetched
	Loaded bool
}

DBHeader fields from header that are stored in database.

type DataSourceType added in v0.71.4

type DataSourceType int
const (
	DataSourceHTTP DataSourceType = iota + 1
	DataSourceStatic
)

type Database

type Database struct {
	// contains filtered or unexported fields
}

Database sql wrapper for operations with wallet objects.

func NewDB

func NewDB(db *sql.DB, network uint64) *Database

func (*Database) AddCustomToken added in v0.38.1

func (db *Database) AddCustomToken(token Token) error

func (*Database) AddFavourite added in v0.62.2

func (db *Database) AddFavourite(favourite Favourite) error

func (Database) Close

func (db Database) Close() error

Close closes database.

func (*Database) DeleteCustomToken added in v0.38.1

func (db *Database) DeleteCustomToken(address common.Address) error

func (*Database) GetBlocks added in v0.40.0

func (db *Database) GetBlocks() (rst []*DBHeader, err error)

func (*Database) GetBlocksByAddress added in v0.40.0

func (db *Database) GetBlocksByAddress(address common.Address, limit int) (rst []*big.Int, err error)

GetBlocksByAddress loads blocks for a given address.

func (*Database) GetCustomTokens added in v0.38.1

func (db *Database) GetCustomTokens() ([]*Token, error)

func (*Database) GetFavourites added in v0.62.2

func (db *Database) GetFavourites() ([]*Favourite, error)

func (*Database) GetFirstKnownBlock added in v0.40.0

func (db *Database) GetFirstKnownBlock(address common.Address) (rst *big.Int, err error)

func (*Database) GetHeaderByNumber

func (db *Database) GetHeaderByNumber(number *big.Int) (header *DBHeader, err error)

GetHeaderByNumber selects header using block number.

func (*Database) GetLastBlockByAddress added in v0.40.0

func (db *Database) GetLastBlockByAddress(address common.Address, limit int) (rst *big.Int, err error)

func (*Database) GetLastKnownBlockByAddress added in v0.40.0

func (db *Database) GetLastKnownBlockByAddress(address common.Address) (block *LastKnownBlock, err error)

func (*Database) GetLastKnownBlockByAddresses added in v0.40.0

func (db *Database) GetLastKnownBlockByAddresses(addresses []common.Address) (map[common.Address]*LastKnownBlock, []common.Address, error)

func (*Database) GetLastSavedBlock added in v0.40.0

func (db *Database) GetLastSavedBlock() (rst *DBHeader, err error)

func (*Database) GetLastSavedBlockBefore added in v0.40.0

func (db *Database) GetLastSavedBlockBefore(block *big.Int) (rst *DBHeader, err error)

func (*Database) GetPreloadedTransactions added in v0.40.0

func (db *Database) GetPreloadedTransactions(address common.Address, blockHash common.Hash) (rst []Transfer, err error)

func (*Database) GetTransactionsLog added in v0.40.0

func (db *Database) GetTransactionsLog(address common.Address, transactionHash common.Hash) (*types.Log, error)

func (*Database) GetTransfers

func (db *Database) GetTransfers(start, end *big.Int) (rst []Transfer, err error)

GetTransfers load transfers transfer betweeen two blocks.

func (*Database) GetTransfersByAddress

func (db *Database) GetTransfersByAddress(address common.Address, toBlock *big.Int, limit int64) (rst []Transfer, err error)

GetTransfersByAddress loads transfers for a given address between two blocks.

func (*Database) GetTransfersByAddressAndBlock added in v0.62.16

func (db *Database) GetTransfersByAddressAndBlock(address common.Address, block *big.Int, limit int64) (rst []Transfer, err error)

GetTransfersByAddressAndBlock loads transfers for a given address and block.

func (*Database) GetTransfersInRange added in v0.40.0

func (db *Database) GetTransfersInRange(address common.Address, start, end *big.Int) (rst []Transfer, err error)

GetTransfersInRange loads transfers for a given address between two blocks.

func (Database) ProcessBlocks added in v0.40.0

func (db Database) ProcessBlocks(account common.Address, from *big.Int, to *LastKnownBlock, headers []*DBHeader) (err error)

func (Database) ProcessTranfers

func (db Database) ProcessTranfers(transfers []Transfer, removed []*DBHeader) (err error)

ProcessTranfers atomically adds/removes blocks and adds new tranfers.

func (*Database) RemoveBlockWithTransfer added in v0.40.0

func (db *Database) RemoveBlockWithTransfer(address common.Address, block *big.Int) error

func (Database) SaveBlocks added in v0.40.0

func (db Database) SaveBlocks(account common.Address, headers []*DBHeader) (err error)

func (*Database) SaveHeaders

func (db *Database) SaveHeaders(headers []*types.Header, address common.Address) (err error)

SaveHeaders stores a list of headers atomically.

func (Database) SaveTranfers added in v0.40.0

func (db Database) SaveTranfers(address common.Address, transfers []Transfer, blocks []*big.Int) (err error)

SaveTranfers

func (*Database) UpsertRange added in v0.73.1

func (db *Database) UpsertRange(account common.Address, network uint64, from, to, balance *big.Int, nonce uint64) error

type ERC20TransfersDownloader

type ERC20TransfersDownloader struct {
	// contains filtered or unexported fields
}

ERC20TransfersDownloader is a downloader for erc20 tokens transfers.

func NewERC20TransfersDownloader

func NewERC20TransfersDownloader(client *walletClient, accounts []common.Address, signer types.Signer) *ERC20TransfersDownloader

NewERC20TransfersDownloader returns new instance.

func (*ERC20TransfersDownloader) GetHeadersInRange added in v0.40.0

func (d *ERC20TransfersDownloader) GetHeadersInRange(parent context.Context, from, to *big.Int) ([]*DBHeader, error)

GetHeadersInRange returns transfers between two blocks. time to get logs for 100000 blocks = 1.144686979s. with 249 events in the result set.

func (*ERC20TransfersDownloader) GetTransfers

func (d *ERC20TransfersDownloader) GetTransfers(ctx context.Context, header *DBHeader) ([]Transfer, error)

GetTransfers for erc20 uses eth_getLogs rpc with Transfer event signature and our address acount.

type ETHTransferDownloader

type ETHTransferDownloader struct {
	// contains filtered or unexported fields
}

ETHTransferDownloader downloads regular eth transfers.

func (*ETHTransferDownloader) GetTransfers

func (d *ETHTransferDownloader) GetTransfers(ctx context.Context, header *DBHeader) (rst []Transfer, err error)

GetTransfers checks if the balance was changed between two blocks. If so it downloads transaction that transfer ethereum from that block.

func (*ETHTransferDownloader) GetTransfersByNumber

func (d *ETHTransferDownloader) GetTransfersByNumber(ctx context.Context, number *big.Int) ([]Transfer, error)

type Event

type Event struct {
	Type        EventType        `json:"type"`
	BlockNumber *big.Int         `json:"blockNumber"`
	Accounts    []common.Address `json:"accounts"`
	Message     string           `json:"message"`
}

Event is a type for wallet events.

type EventType

type EventType string

EventType type for event types.

const (
	// EventNewTransfers emitted when new block was added to the same canonical chan.
	EventNewTransfers EventType = "new-transfers"
	// EventFetchingRecentHistory emitted when fetching of lastest tx history is started
	EventFetchingRecentHistory EventType = "recent-history-fetching"
	// EventRecentHistoryReady emitted when fetching of lastest tx history is started
	EventRecentHistoryReady EventType = "recent-history-ready"
	// EventFetchingHistoryError emitted when fetching of tx history failed
	EventFetchingHistoryError EventType = "fetching-history-error"
	// EventNonArchivalNodeDetected emitted when a connection to a non archival node is detected
	EventNonArchivalNodeDetected EventType = "non-archival-node-detected"
)

type Favourite added in v0.62.2

type Favourite struct {
	Address common.Address `json:"address"`
	Name    string         `json:"name"`
}

type FiniteCommand

type FiniteCommand struct {
	Interval time.Duration
	Runable  func(context.Context) error
}

FiniteCommand terminates when error is nil.

func (FiniteCommand) Run

func (c FiniteCommand) Run(ctx context.Context) error

type Group

type Group struct {
	// contains filtered or unexported fields
}

func NewGroup

func NewGroup(parent context.Context) *Group

func (*Group) Add

func (g *Group) Add(cmd Command)

func (*Group) Stop

func (g *Group) Stop()

func (*Group) Wait

func (g *Group) Wait()

func (*Group) WaitAsync

func (g *Group) WaitAsync() <-chan struct{}

type HeaderReader

type HeaderReader interface {
	HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)
	HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
}

HeaderReader interface for reading headers using block number or hash.

type InfiniteCommand

type InfiniteCommand struct {
	Interval time.Duration
	Runable  func(context.Context) error
}

InfiniteCommand runs until context is closed.

func (InfiniteCommand) Run

func (c InfiniteCommand) Run(ctx context.Context) error

type IterativeDownloader

type IterativeDownloader struct {
	// contains filtered or unexported fields
}

IterativeDownloader downloads batches of transfers in a specified size.

func SetupIterativeDownloader

func SetupIterativeDownloader(
	db *Database, client HeaderReader, address common.Address,
	downloader BatchDownloader, size *big.Int, to *big.Int, from *big.Int) (*IterativeDownloader, error)

SetupIterativeDownloader configures IterativeDownloader with last known synced block.

func (*IterativeDownloader) Finished

func (d *IterativeDownloader) Finished() bool

Finished true when earliest block with given sync option is zero.

func (*IterativeDownloader) Header

func (d *IterativeDownloader) Header() *big.Int

Header return last synced header.

func (*IterativeDownloader) Next

func (d *IterativeDownloader) Next(parent context.Context) ([]*DBHeader, *big.Int, *big.Int, error)

Next moves closer to the end on every new iteration.

func (*IterativeDownloader) Revert

func (d *IterativeDownloader) Revert()

Revert reverts last step progress. Should be used if application failed to process transfers. For example failed to persist them.

type JSONBlob

type JSONBlob struct {
	// contains filtered or unexported fields
}

JSONBlob type for marshaling/unmarshaling inner type to json.

func (*JSONBlob) Scan

func (blob *JSONBlob) Scan(value interface{}) error

Scan implements interface.

func (*JSONBlob) Value

func (blob *JSONBlob) Value() (driver.Value, error)

Value implements interface.

type LastKnownBlock added in v0.73.4

type LastKnownBlock struct {
	Number  *big.Int
	Balance *big.Int
	Nonce   *int64
}

type LastKnownBlockView added in v0.79.4

type LastKnownBlockView struct {
	Address common.Address `json:"address"`
	Number  *big.Int       `json:"blockNumber"`
	Balance BigInt         `json:"balance"`
	Nonce   *int64         `json:"nonce"`
}

type PendingTransaction added in v0.62.0

type PendingTransaction struct {
	Hash           common.Hash    `json:"hash"`
	Timestamp      uint64         `json:"timestamp"`
	Value          BigInt         `json:"value"`
	From           common.Address `json:"from"`
	To             common.Address `json:"to"`
	Data           string         `json:"data"`
	Symbol         string         `json:"symbol"`
	GasPrice       BigInt         `json:"gasPrice"`
	GasLimit       BigInt         `json:"gasLimit"`
	Type           PendingTrxType `json:"type"`
	AdditionalData string         `json:"additionalData"`
}

type PendingTrxType added in v0.62.0

type PendingTrxType string
const (
	RegisterENS    PendingTrxType = "RegisterENS"
	ReleaseENS     PendingTrxType = "ReleaseENS"
	SetPubKey      PendingTrxType = "SetPubKey"
	BuyStickerPack PendingTrxType = "BuyStickerPack"
	WalletTransfer PendingTrxType = "WalletTransfer"
)

type Reactor

type Reactor struct {
	// contains filtered or unexported fields
}

Reactor listens to new blocks and stores transfers into the database.

func NewReactor

func NewReactor(db *Database, feed *event.Feed, client *ethclient.Client, chain *big.Int) *Reactor

NewReactor creates instance of the Reactor.

func (*Reactor) Start

func (r *Reactor) Start(accounts []common.Address) error

Start runs reactor loop in background.

func (*Reactor) Stop

func (r *Reactor) Stop()

Stop stops reactor loop and waits till it exits.

type Result

type Result struct {
	// contains filtered or unexported fields
}

func (*Result) Get

func (r *Result) Get() []Transfer

func (*Result) GetHeaders added in v0.40.0

func (r *Result) GetHeaders() []*DBHeader

func (*Result) GetRanges added in v0.40.0

func (r *Result) GetRanges() [][]*big.Int

func (*Result) Push

func (r *Result) Push(transfers ...Transfer)

func (*Result) PushHeader added in v0.40.0

func (r *Result) PushHeader(block *DBHeader)

func (*Result) PushRange added in v0.40.0

func (r *Result) PushRange(blockRange []*big.Int)

type SQLBigInt

type SQLBigInt big.Int

SQLBigInt type for storing uint256 in the databse. FIXME(dshulyak) SQL big int is max 64 bits. Maybe store as bytes in big endian and hope that lexographical sorting will work.

func (*SQLBigInt) Scan

func (i *SQLBigInt) Scan(value interface{}) error

Scan implements interface.

func (*SQLBigInt) Value

func (i *SQLBigInt) Value() (driver.Value, error)

Value implements interface.

type SQLBigIntBytes added in v0.73.4

type SQLBigIntBytes big.Int

SQLBigIntBytes type for storing big.Int as BLOB in the databse.

func (*SQLBigIntBytes) Scan added in v0.73.4

func (i *SQLBigIntBytes) Scan(value interface{}) error

func (*SQLBigIntBytes) Value added in v0.73.4

func (i *SQLBigIntBytes) Value() (driver.Value, error)

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is a wallet service.

func NewService

func NewService(db *Database, accountsFeed *event.Feed) *Service

NewService initializes service instance.

func (*Service) APIs

func (s *Service) APIs() []rpc.API

APIs returns list of available RPC APIs.

func (*Service) GetFeed added in v0.62.16

func (s *Service) GetFeed() *event.Feed

GetFeed returns signals feed.

func (*Service) IsStarted added in v0.48.8

func (s *Service) IsStarted() bool

func (*Service) MergeBlocksRanges added in v0.70.1

func (s *Service) MergeBlocksRanges(accounts []common.Address, chain uint64) error

MergeBlocksRanges merge old blocks ranges if possible

func (*Service) Protocols

func (s *Service) Protocols() []p2p.Protocol

Protocols returns list of p2p protocols.

func (*Service) SetClient added in v0.69.3

func (s *Service) SetClient(client *ethclient.Client)

SetClient sets ethclient

func (*Service) SetInitialBlocksRange added in v0.73.1

func (s *Service) SetInitialBlocksRange(network uint64) error

func (*Service) Start

func (s *Service) Start(*p2p.Server) error

Start signals transmitter.

func (*Service) StartReactor

func (s *Service) StartReactor(client *ethclient.Client, accounts []common.Address, chain *big.Int) error

StartReactor separately because it requires known ethereum address, which will become available only after login.

func (*Service) Stop

func (s *Service) Stop() error

Stop reactor, signals transmitter and close db.

func (*Service) StopReactor

func (s *Service) StopReactor() error

StopReactor stops reactor and closes database.

type SignalsTransmitter

type SignalsTransmitter struct {
	// contains filtered or unexported fields
}

SignalsTransmitter transmits received events as wallet signals.

func (*SignalsTransmitter) Start

func (tmr *SignalsTransmitter) Start() error

Start runs loop in background.

func (*SignalsTransmitter) Stop

func (tmr *SignalsTransmitter) Stop()

Stop stops the loop and waits till it exits.

type SyncOption

type SyncOption uint

SyncOption is used to specify that application processed transfers for that block.

type Token added in v0.38.1

type Token struct {
	Address common.Address `json:"address"`
	Name    string         `json:"name"`
	Symbol  string         `json:"symbol"`
	Color   string         `json:"color"`

	// Decimals defines how divisible the token is. For example, 0 would be
	// indivisible, whereas 18 would allow very small amounts of the token
	// to be traded.
	Decimals uint `json:"decimals"`
}

type Transfer

type Transfer struct {
	Type        TransferType       `json:"type"`
	ID          common.Hash        `json:"-"`
	Address     common.Address     `json:"address"`
	BlockNumber *big.Int           `json:"blockNumber"`
	BlockHash   common.Hash        `json:"blockhash"`
	Timestamp   uint64             `json:"timestamp"`
	Transaction *types.Transaction `json:"transaction"`
	Loaded      bool
	NetworkID   uint64
	// From is derived from tx signature in order to offload this computation from UI component.
	From    common.Address `json:"from"`
	Receipt *types.Receipt `json:"receipt"`
	// Log that was used to generate erc20 transfer. Nil for eth transfer.
	Log *types.Log `json:"log"`
}

Transfer stores information about transfer.

type TransferDownloader

type TransferDownloader interface {
	GetTransfersByNumber(context.Context, *big.Int) ([]Transfer, error)
}

TransferDownloader downloads transfers from single block using number.

type TransferType

type TransferType string

TransferType type of the asset that was transferred.

type TransferView

type TransferView struct {
	ID          common.Hash    `json:"id"`
	Type        TransferType   `json:"type"`
	Address     common.Address `json:"address"`
	BlockNumber *hexutil.Big   `json:"blockNumber"`
	BlockHash   common.Hash    `json:"blockhash"`
	Timestamp   hexutil.Uint64 `json:"timestamp"`
	GasPrice    *hexutil.Big   `json:"gasPrice"`
	GasLimit    hexutil.Uint64 `json:"gasLimit"`
	GasUsed     hexutil.Uint64 `json:"gasUsed"`
	Nonce       hexutil.Uint64 `json:"nonce"`
	TxStatus    hexutil.Uint64 `json:"txStatus"`
	Input       hexutil.Bytes  `json:"input"`
	TxHash      common.Hash    `json:"txHash"`
	Value       *hexutil.Big   `json:"value"`
	From        common.Address `json:"from"`
	To          common.Address `json:"to"`
	Contract    common.Address `json:"contract"`
	NetworkID   uint64
}

TransferView stores only fields used by a client and ensures that all relevant fields are encoded in hex.

func CastToTransferView added in v0.62.16

func CastToTransferView(t Transfer) TransferView

CastToTransferView transforms a raw Transfer into an enriched one

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL