Class: TXDB

wallet~TXDB(wdb)

TXDB

Constructor

new TXDB(wdb)

Create a TXDB.

Parameters:
Name Type Description
wdb WalletDB
Source:

Methods

(async, private) _toDetails(wtx) → {Promise}

Convert transaction to transaction details.

Parameters:
Name Type Description
wtx TXRecord
Source:
Returns:
Type
Promise

(async) abandon(hash) → {Promise}

Abandon transaction.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
Type
Promise

(async, private) add(tx) → {Promise}

Add transaction without a batch.

Parameters:
Name Type Description
tx TX
Source:
Returns:
Type
Promise

(async) addBlock(hash, block) → {Promise}

Append to the global block record.

Parameters:
Name Type Description
hash Hash
block BlockMeta
Source:
Returns:
Type
Promise

addBlockMap(height) → {Promise}

Append to global map.

Parameters:
Name Type Description
height Number
Source:
Returns:
Type
Promise

addOutpointMap(hash, index) → {Promise}

Append to global map.

Parameters:
Name Type Description
hash Hash
index Number
Source:
Returns:
Type
Promise

addTXMap(hash) → {Promise}

Append to global map.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
Type
Promise

(async, private) confirm(wtx, block) → {Promise}

Attempt to confirm a transaction.

Parameters:
Name Type Description
wtx TXRecord
block BlockMeta
Source:
Returns:
Type
Promise

(async) disconnect(wtx) → {Promise}

Unconfirm a transaction. Necessary after a reorg.

Parameters:
Name Type Description
wtx TXRecord
Source:
Returns:
Type
Promise

(private) emit(event, data, details)

Emit transaction event.

Parameters:
Name Type Description
event String
data Object
details Details
Source:

(async, private) erase(wtx) → {Promise}

Remove a transaction from the database. Disconnect inputs.

Parameters:
Name Type Description
wtx TXRecord
Source:
Returns:
Type
Promise

filterLocked(coins) → {Array}

Filter array of coins or outpoints for only unlocked ones.

Parameters:
Name Type Description
coins Array.<Coin> | Array.<Outpoint>
Source:
Returns:
Type
Array

(async) getAccountBalance(acct) → {Promise}

Calculate balance by account.

Parameters:
Name Type Description
acct Number
Source:
Returns:
  • Returns Balance.
Type
Promise

(async) getAccountCoins(acct) → {Promise}

Get coins by account.

Parameters:
Name Type Description
acct Number
Source:
Returns:
  • Returns Coin[].
Type
Promise

(async) getAccountCredits(acct) → {Promise}

Get coins by account.

Parameters:
Name Type Description
acct Number
Source:
Returns:
  • Returns Coin[].
Type
Promise

getAccountHeightRangeHashes(acct, options) → {Promise}

Get TX hashes by height range.

Parameters:
Name Type Description
acct Number
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.

Source:
Returns:
Type
Promise

(async) getAccountHistory(acct) → {Promise}

Get all acct transactions.

Parameters:
Name Type Description
acct Number
Source:
Returns:
  • Returns TX[].
Type
Promise

getAccountHistoryHashes(acct) → {Promise}

Get hashes of all transactions in the database.

Parameters:
Name Type Description
acct Number
Source:
Returns:
Type
Promise

getAccountOutpoints(acct) → {Promise}

Get all coin hashes in the database.

Parameters:
Name Type Description
acct Number
Source:
Returns:
Type
Promise

getAccountPendingHashes(acct) → {Promise}

Get hashes of all unconfirmed transactions in the database.

Parameters:
Name Type Description
acct Number
Source:
Returns:
Type
Promise

getAccountRangeHashes(acct, options) → {Promise}

Get TX hashes by timestamp range.

Parameters:
Name Type Description
acct Number
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.

Source:
Returns:
Type
Promise

(async) getBalance(accountnullable) → {Promise}

Calculate balance.

Parameters:
Name Type Attributes Description
account Number <nullable>
Source:
Returns:
  • Returns Balance.
Type
Promise

(async) getBlock(height) → {Promise}

Get block record.

Parameters:
Name Type Description
height Number
Source:
Returns:
Type
Promise

getBlocks() → {Promise}

List block records.

Source:
Returns:
Type
Promise

(async) getCoin(hash, index) → {Promise}

Get coin.

Parameters:
Name Type Description
hash Hash
index Number
Source:
Returns:
  • Returns Coin.
Type
Promise

(async) getCoins(acct) → {Promise}

Get coins.

Parameters:
Name Type Description
acct Number
Source:
Returns:
  • Returns Coin[].
Type
Promise

(async) getCoinView(tx) → {Promise}

Get a coin viewpoint.

Parameters:
Name Type Description
tx TX
Source:
Returns:
  • Returns CoinView.
Type
Promise

(async) getCredit(hash, index) → {Promise}

Get coin.

Parameters:
Name Type Description
hash Hash
index Number
Source:
Returns:
  • Returns Coin.
Type
Promise

getCredits(acct) → {Promise}

Get coins.

Parameters:
Name Type Description
acct Number
Source:
Returns:
  • Returns Coin[].
Type
Promise

(async) getDetails(hash) → {Promise}

Get transaction details.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
  • Returns TXDetails.
Type
Promise

getHeightHashes(height) → {Promise}

Get TX hashes by height.

Parameters:
Name Type Description
height Number
Source:
Returns:
Type
Promise

getHeightRangeHashes(acct, options) → {Promise}

Get TX hashes by height range.

Parameters:
Name Type Description
acct Number
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.

Source:
Returns:
Type
Promise

getHistory(acct) → {Promise}

Get all transactions.

Parameters:
Name Type Description
acct Number
Source:
Returns:
  • Returns TX[].
Type
Promise

getHistoryHashes(acct) → {Promise}

Get hashes of all transactions in the database.

Parameters:
Name Type Description
acct Number
Source:
Returns:
Type
Promise

getLast(acct, limit) → {Promise}

Get last N transactions.

Parameters:
Name Type Description
acct Number
limit Number

Max number of transactions.

Source:
Returns:
  • Returns TX[].
Type
Promise

getLocked() → {Array.<Outpoint>}

Return an array of all locked outpoints.

Source:
Returns:
Type
Array.<Outpoint>

getOutpoints(acct) → {Promise}

Get all coin hashes in the database.

Parameters:
Name Type Description
acct Number
Source:
Returns:
Type
Promise

getPath(output) → {Promise}

Get wallet path for output.

Parameters:
Name Type Description
output Output
Source:
Returns:
  • Returns Path.
Type
Promise

(async) getPending(acct) → {Promise}

Get unconfirmed transactions.

Parameters:
Name Type Description
acct Number
Source:
Returns:
  • Returns TX[].
Type
Promise

getPendingHashes(acct) → {Promise}

Get hashes of all unconfirmed transactions in the database.

Parameters:
Name Type Description
acct Number
Source:
Returns:
Type
Promise

(async) getRange(acct, options) → {Promise}

Get transactions by timestamp range.

Parameters:
Name Type Description
acct Number
options Object
Properties
Name Type Attributes Description
start Number

Start time.

end Number

End time.

limit Number <nullable>

Max number of records.

reverse Boolean <nullable>

Reverse order.

Source:
Returns:
  • Returns TX[].
Type
Promise

getRangeHashes(acct, options) → {Promise}

Get TX hashes by timestamp range.

Parameters:
Name Type Description
acct Number
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.

Source:
Returns:
Type
Promise

(async) getSpent(hash, index) → {Promise}

Test a whether a coin has been spent.

Parameters:
Name Type Description
hash Hash
index Number
Source:
Returns:
  • Returns Boolean.
Type
Promise

(async) getSpentCoin(spent, prevout) → {Promise}

Get spender coin.

Parameters:
Name Type Description
spent Outpoint
prevout Outpoint
Source:
Returns:
  • Returns Coin.
Type
Promise

(async) getSpentCoins(tx) → {Promise}

Get historical coins for a transaction.

Parameters:
Name Type Description
tx TX
Source:
Returns:
  • Returns TX.
Type
Promise

(async) getSpentCredits(tx) → {Promise}

Fill a transaction with coins (all historical coins).

Parameters:
Name Type Description
tx TX
Source:
Returns:
  • Returns TX.
Type
Promise

(async) getSpentView(tx) → {Promise}

Get historical coin viewpoint.

Parameters:
Name Type Description
tx TX
Source:
Returns:
  • Returns CoinView.
Type
Promise

(async) getTX(hash) → {Promise}

Get transaction.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
  • Returns TX.
Type
Promise

(async) getWalletBalance() → {Promise}

Calculate balance.

Source:
Returns:
  • Returns Balance.
Type
Promise

(async) hasCoin(hash) → {Promise}

Test whether the database has a transaction.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
  • Returns Boolean.
Type
Promise

hasPath(output) → {Promise}

Test whether path exists for output.

Parameters:
Name Type Description
output Output
Source:
Returns:
  • Returns Boolean.
Type
Promise

(async) hasPending(hash) → {Promise}

Test whether the database has a pending transaction.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
  • Returns Boolean.
Type
Promise

hasSpentCoin(spent) → {Promise}

Test whether the database has a spent coin.

Parameters:
Name Type Description
spent Outpoint
Source:
Returns:
  • Returns Coin.
Type
Promise

hasTX(hash) → {Promise}

Test whether the database has a transaction.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
  • Returns Boolean.
Type
Promise

(async, private) insert(wtx, block) → {Promise}

Insert transaction.

Parameters:
Name Type Description
wtx TXRecord
block BlockMeta
Source:
Returns:
Type
Promise

isLocked(coin)

Test locked status of a single coin.

Parameters:
Name Type Description
coin Coin | Outpoint
Source:

isSpent(hash, index) → {Promise}

Test a whether a coin has been spent.

Parameters:
Name Type Description
hash Hash
index Number
Source:
Returns:
  • Returns Boolean.
Type
Promise

lockCoin(coin)

Lock a single coin.

Parameters:
Name Type Description
coin Coin | Outpoint
Source:

lockTX(tx)

Lock all coins in a transaction.

Parameters:
Name Type Description
tx TX
Source:

(async) open() → {Promise}

Open TXDB.

Source:
Returns:
Type
Promise

(async) remove(hash) → {Promise}

Recursively remove a transaction from the database.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
Type
Promise

(async) removeBlock(hash, height) → {Promise}

Remove from the global block record.

Parameters:
Name Type Description
hash Hash
height Number
Source:
Returns:
Type
Promise

removeBlockMap(height) → {Promise}

Remove from global map.

Parameters:
Name Type Description
height Number
Source:
Returns:
Type
Promise

(async, private) removeConflict(hash, ref) → {Promise}

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.

Source:
Returns:
  • Returns Boolean.
Type
Promise

(async, private) removeConflicts(tx) → {Promise}

Retrieve coins for own inputs, remove double spenders, and verify inputs.

Parameters:
Name Type Description
tx TX
Source:
Returns:
Type
Promise

(async) removeCredit(credit, path)

Remove credit.

Parameters:
Name Type Description
credit Credit
path Path
Source:

(async) removeInput(tx, index)

Remove input record.

Parameters:
Name Type Description
tx TX
index Number
Source:

removeOutpointMap(hash, index) → {Promise}

Remove from global map.

Parameters:
Name Type Description
hash Hash
index Number
Source:
Returns:
Type
Promise

(async, private) removeRecursive(wtx) → {Promise}

Remove a transaction and recursively remove all of its spenders.

Parameters:
Name Type Description
wtx TXRecord
Source:
Returns:
Type
Promise

removeTXMap(hash) → {Promise}

Remove from global map.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
Type
Promise

(async) revert(height) → {Promise}

Revert a block.

Parameters:
Name Type Description
height Number
Source:
Returns:
Type
Promise

(async) saveCredit(credit, path)

Save credit.

Parameters:
Name Type Description
credit Credit
path Path
Source:

spendCredit(credit, tx, index)

Spend credit.

Parameters:
Name Type Description
credit Credit
tx TX
index Number
Source:

(async) spliceBlock(hash, height) → {Promise}

Remove from the global block record.

Parameters:
Name Type Description
hash Hash
height Number
Source:
Returns:
Type
Promise

(async) toDetails(wtxs) → {Promise}

Convert transaction to transaction details.

Parameters:
Name Type Description
wtxs Array.<TXRecord>
Source:
Returns:
Type
Promise

(async, private) unconfirm(hash) → {Promise}

Unconfirm a transaction without a batch.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
Type
Promise

unlockCoin(coin)

Unlock a single coin.

Parameters:
Name Type Description
coin Coin | Outpoint
Source:

unlockCoins()

Unlock all coins.

Source:

unlockTX(tx)

Unlock all coins in a transaction.

Parameters:
Name Type Description
tx TX
Source:

unspendCredit(tx, index)

Unspend credit.

Parameters:
Name Type Description
tx TX
index Number
Source:

(async) updateAccountBalance(acct, delta)

Update account balance.

Parameters:
Name Type Description
acct Number
delta Balance
Source:

(async) updateBalance(state)

Update wallet balance.

Parameters:
Name Type Description
state BalanceDelta
Source:

(async) updateSpentCoin(tx, index, height) → {Promise}

Update spent coin height in storage.

Parameters:
Name Type Description
tx TX

Sending transaction.

index Number
height Number
Source:
Returns:
Type
Promise

(async) writeInput(tx, index)

Write input record.

Parameters:
Name Type Description
tx TX
index Number
Source:

(async) zap(acct, age) → {Promise}

Zap pending transactions older than age.

Parameters:
Name Type Description
acct Number
age Number

Age delta.

Source:
Returns:
Type
Promise