good-wallet

Table of Contents

QueryEvent

the HDWallet account to use. we use different accounts for different actions in order to preserve privacy and simplify things for user in background

Type: {event: string, contract: Web3.eth.Contract, filterPred: {}, fromBlock: any, toBlock: (any | "latest")?}

Properties

  • event string

  • contract Web3.eth.Contract

  • filterPred {}

  • fromBlock any

  • toBlock (any | "latest")?

listenTxUpdates

Subscribes to Transfer events (from and to) the current account This is used to verify account balance changes

Parameters

  • fromBlock string defaultValue: '0'

Returns (Promise<R> | Promise<(R | any)> | Promise<any>)

subscribeToEvent

Sets an id and place a callback function for this id, for the sent event

Parameters

Returns object subscriber id and eventName

unsubscribeFromEvent

removes subscriber from subscriber list with the specified id and event name

Parameters

  • event event

    • event.eventName

    • event.id

getSubscribers

Gets all subscribers as array for given eventName

Parameters

Returns Function a json object containing all subscribers for the specified event name

balanceChanged

Listen to balance changes for the current account

Parameters

Returns Promise<void>

getBlockNumber

Retrieves current Block Number and returns it as converted to a BN instance

Returns Promise<BN> Current block number in BN instance

getEvents

Client side event filter. Requests all events for a particular contract, then filters them and returns the event Object

Parameters

  • $0 any

    • $0.event

    • $0.contract

    • $0.filterPred

    • $0.fromBlock (optional, default ZERO)

    • $0.toBlock

  • event String Event to subscribe to

  • contract Object Contract from which event will be queried

  • filterPred Object Event's filter. Does not required to be indexed as it's filtered locally

  • fromBlock BN Lower blocks range value

  • toBlock BN Higher blocks range value

Returns Promise<any>

oneTimeEvents

Subscribes to a particular event and returns the result based on options specified

Parameters

  • $0 any

    • $0.event

    • $0.contract

    • $0.filterPred

    • $0.fromBlock

    • $0.toBlock

  • callback Function Function to be called once an event is received

  • event String Event to subscribe to

  • contract Object Contract from which event will be queried

  • filterPred Object Event's filter. Does not required to be indexed as it's filtered locally

  • fromBlock BN Lower blocks range value

  • toBlock BN Higher blocks range value

Returns Promise<void>

pollForEvents

Polls for events every INTERVAL defined by BLOCK_TIME and BLOCK_COUNT, the result is based on specified options It queries the range 'fromBlock'-'toBlock' and then continues querying the blockchain for most recent events, from the 'lastProcessedBlock' to the 'latest' every INTERVAL

Parameters

  • $0 any

    • $0.event

    • $0.contract

    • $0.filterPred

    • $0.fromBlock

    • $0.toBlock

  • callback Function Function to be called once an event is received

  • event String Event to subscribe to

  • contract Object Contract from which event will be queried

  • filterPred Object Event's filter. Does not required to be indexed as it's filtered locally

  • fromBlock BN Lower blocks range value

  • toBlock BN Higher blocks range value

  • lastProcessedBlock BN Used for recursion. It's not required to be set by the user. Initial value: ZERO

Returns Promise<void>

sendTransaction

Helper function to handle a tx Send call

Parameters

  • tx any

  • txCallbacks PromiEvents (optional, default defaultPromiEvents)

  • gasValues object (optional, default {gas:undefined,gasPrice:undefined})

  • promiEvents object

Returns Promise<(Promise | Q.Promise<any> | Promise<any> | Promise<any> | Promise<any> | any)>

receipt handling happens already in polling events

Source

https://github.com/GoodDollar/GoodDAPP/src/lib/wallet/GoodWallet.js