Class: TXDB

TXDB

new TXDB(prefix, db, optionsnullable)

TXDB

Parameters:
Name Type Attributes Description
prefix String

The prefix for the database (txdb/ by default).

db LowlevelUp
options Object <nullable>
Properties
Name Type Attributes Description
mapAddress Boolean <nullable>

Map addresses to IDs.

indexAddress Boolean <nullable>

Index addresses/IDs.

indexExtra Boolean <nullable>

Index timestamps, heights, etc.

verify Boolean <nullable>

Verify transactions as they come in (note that this will not happen on the worker pool).

Properties:
Name Type Description
prefix String
Source:

Methods

(private) _addOrphan(key, hash, index, callback)

Add an orphan (tx hash + input index) to orphan list. Stored by its required coin ID.

Parameters:
Name Type Description
key String

Required coin hash + index.

hash Hash

Orphan transaction hash.

index Number

Orphan input index.

callback function

Returns [Error, Buffer].

Source:

(private) _confirm(tx, map, callback)

Attempt to confirm a transaction.

Parameters:
Name Type Description
tx TX
map AddressMap
callback function

Returns [Error, Boolean]. false if the transaction should be added to the database, true if the transaction was confirmed, or should be ignored.

Source:

(private) _getOrphans(key, callback)

Retrieve orphan list by coin ID.

Parameters:
Name Type Description
key String
callback function

Returns [Error, Orphan].

Source:

(private) _remove(tx, map, callback)

Remove a transaction from the database. Disconnect inputs.

Parameters:
Name Type Description
tx TX
map AddressMap
callback function

Returns [Error].

Source:

(private) _removeSpenders(hash, ref, callback)

Remove spenders that have not been confirmed. We do this in the odd case of stuck transactions or when a coin is double-spent by a newer transaction. All previously-spending transactions of that coin that are not confirmed will be removed from the database.

Parameters:
Name Type Description
hash Hash
ref TX

Reference tx, the tx that double-spent.

callback function

Returns [Error, Boolean].

Source:

_unconfirm(hash, map, callback)

Unconfirm a transaction. This is usually necessary after a reorg.

Parameters:
Name Type Description
hash Hash
map AddressMap
callback function
Source:

add(tx, callback)

Add a transaction to the database, map addresses to wallet IDs, potentially store orphans, resolve orphans, or confirm a transaction.

Parameters:
Name Type Description
tx TX
callback function

Returns [Error].

Source:

fillCoins(tx, callback)

Fill a transaction with coins.

Parameters:
Name Type Description
tx TX
callback function

Returns [Error, TX].

Source:

fillHistory(tx, callback)

Fill a transaction with coins (all historical coins).

Parameters:
Name Type Description
tx TX
callback function

Returns [Error, TX].

Source:

getBalance(address, callback)

Calculate balance.

Parameters:
Name Type Description
address WalletID | Array.<WalletID>

By address (can be null).

callback function

Returns [Error, Balance].

Source:

getBalanceByAddress(address, callback)

Calculate balance.

Parameters:
Name Type Description
address WalletID | Array.<WalletID>

By address (can be null).

callback function

Returns [Error, Balance].

Source:

getCoin(hash, index, callback)

Get coin.

Parameters:
Name Type Description
hash Hash
index Number
callback function

Returns [Error, Coin].

Source:

getCoinHashes(address, callback)

Get all coin hashes in the database.

Parameters:
Name Type Description
address WalletID | Array.<WalletID>

By address (can be null).

callback function

Returns [Error, Hash[]].

Source:

getCoins(address, callback)

Get coins.

Parameters:
Name Type Description
address WalletID | Array.<WalletID>

By address (can be null).

callback function

Returns [Error, Coin[]].

Source:

getCoinsByAddress(address, callback)

Get coins.

Parameters:
Name Type Description
address WalletID | Array.<WalletID>

By address (can be null).

callback function

Returns [Error, Coin[]].

Source:

getHeightHashes(height, callback)

Get TX hashes by height.

Parameters:
Name Type Description
height Number
callback function

Returns [Error, Hash[]].

Source:

getHeightRangeHashes(address, options, callback)

Get TX hashes by height range.

Parameters:
Name Type Description
address WalletID | Array.<WalletID>

By address (can be null).

options Object
Properties
Name Type Attributes Description
start Number

Start height.

end Number

End height.

limit Number <nullable>

Max number of records.

reverse Boolean <nullable>

Reverse order.

callback function

Returns [Error, Hash[]].

Source:

getHistory(address, callback)

Get all transactions.

Parameters:
Name Type Description
address WalletID | Array.<WalletID>

By address (can be null).

callback function

Returns [Error, TX[]].

Source:

getHistoryByAddress(address, callback)

Get all transactions.

Parameters:
Name Type Description
address WalletID | Array.<WalletID>

By address (can be null).

callback function

Returns [Error, TX[]].

Source:

getHistoryHashes(address, callback)

Get hashes of all transactions in the database.

Parameters:
Name Type Description
address WalletID | Array.<WalletID>

By address (can be null).

callback function

Returns [Error, Hash[]].

Source:

getHistoryHashesByAddress(address, callback)

Get hashes of all transactions in the database.

Parameters:
Name Type Description
address WalletID | Array.<WalletID>

By address (can be null).

callback function

Returns [Error, Hash[]].

Source:

getLast(address, limit, callback)

Get last N transactions.

Parameters:
Name Type Description
address WalletID | Array.<WalletID>

By address (can be null).

limit Number

Max number of transactions.

callback function

Returns [Error, TX[]].

Source:

getLastTime(address, callback)

Get last active timestamp and height.

Parameters:
Name Type Description
address WalletID | Array.<WalletID>

By address (can be null).

callback function

Returns [Error, Number(ts), Number(height)].

Source:

getMap(tx, callback)

Map a transactions' addresses to wallet IDs.

Parameters:
Name Type Description
tx TX
callback function

Returns [Error, AddressMap].

Source:

getRange(address, options, callback)

Get transactions by timestamp range.

Parameters:
Name Type Description
address WalletID | Array.<WalletID>

By address (can be null).

options Object
Properties
Name Type Attributes Description
start Number

Start height.

end Number

End height.

limit Number <nullable>

Max number of records.

reverse Boolean <nullable>

Reverse order.

callback function

Returns [Error, TX[]].

Source:

getRangeHashes(address, options, callback)

Get TX hashes by timestamp range.

Parameters:
Name Type Description
address WalletID | Array.<WalletID>

By address (can be null).

options Object
Properties
Name Type Attributes Description
start Number

Start height.

end Number

End height.

limit Number <nullable>

Max number of records.

reverse Boolean <nullable>

Reverse order.

callback function

Returns [Error, Hash[]].

Source:

getTX(hash, callback)

Get transaction.

Parameters:
Name Type Description
hash Hash
callback function

Returns [Error, TX].

Source:

getUnconfirmed(address, callback)

Get unconfirmed transactions.

Parameters:
Name Type Description
address WalletID | Array.<WalletID>

By address (can be null).

callback function

Returns [Error, TX[]].

Source:

getUnconfirmedByAddress(address, callback)

Get unconfirmed transactions.

Parameters:
Name Type Description
address WalletID | Array.<WalletID>

By address (can be null).

callback function

Returns [Error, TX[]].

Source:

getUnconfirmedHashes(address, callback)

Get hashes of all unconfirmed transactions in the database.

Parameters:
Name Type Description
address WalletID | Array.<WalletID>

By address (can be null).

callback function

Returns [Error, Hash[]].

Source:

hasCoin(hash, callback)

Test whether the database has a transaction.

Parameters:
Name Type Description
hash Hash
callback function

Returns [Error, Boolean].

Source:

hasTX(hash, callback)

Test whether the database has a transaction.

Parameters:
Name Type Description
hash Hash
callback function

Returns [Error, Boolean].

Source:

isDoubleSpend(tx, callback)

Test an entire transaction to see if any of its outpoints are a double-spend.

Parameters:
Name Type Description
tx TX
callback function

Returns [Error, Boolean].

Source:

isSpent(hash, index, callback)

Test a whether a coin has been spent.

Parameters:
Name Type Description
hash Hash
index Number
callback function

Returns [Error, Boolean].

Source:

lazyRemove(tx, callback)

Remove a transaction from the database, but do not look up the transaction. Use the passed-in transaction to disconnect.

Parameters:
Name Type Description
tx TX
callback function

Returns [Error].

Source:

mapAddresses(address, callback)

Map an address to a wallet ID.

Parameters:
Name Type Description
address Base58Address | Array.<Base58Address>
callback function

Returns [Error, AddressTable].

Source:

remove(hash, callback)

Remove a transaction from the database. Disconnect inputs.

Parameters:
Name Type Description
hash Hash
callback function

Returns [Error].

Source:

unconfirm(hash, callback)

Unconfirm a transaction. This is usually necessary after a reorg.

Parameters:
Name Type Description
hash Hash
callback function
Source:

zap(address, now, age, callback)

Parameters:
Name Type Description
address WalletID | Array.<WalletID>

By address (can be null).

now Number

Current time.

age Number

Age delta (delete transactions older than now - age).

callback function
Source: