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

addNameMap(hash, index) → {Promise}

Append to global map.

Parameters:
Name Type Description
hash Hash
index 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) applyNameUndo(b, hash)

Apply namestate undo data by hash without transaction. Should only be called directly to undo namestate transitions that do not affect wallet balance like a TRANSFER for a name that is in the nameMap but does not involve wallet addresses.

Parameters:
Name Type Description
b Object
hash Hash
Source:

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

Attempt to confirm a transaction.

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

(async) connectNames(b, tx, i, path, height) → {Object|Boolean|Boolean}

Handle incoming covenant.

Parameters:
Name Type Description
b Object
tx TX
i Number
path Path
height Number
Source:
Returns:
  • out

    Type
    Object
  • out.updated

    Type
    Boolean
  • out.index

    Type
    Boolean

(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) getBid(nameHash, outpoint) → {BlindBid}

Get a bid if present.

Parameters:
Name Type Description
nameHash Buffer
outpoint Outpoint
Source:
Returns:
Type
BlindBid

(async) getBids(nameHash) → {Array.<BlindBid>}

Get all bids for name.

Parameters:
Name Type Description
nameHash Buffer
Source:
Returns:
Type
Array.<BlindBid>

(async) getBlind(blind) → {BlindValue}

Get a blind value if present.

Parameters:
Name Type Description
blind Buffer

Blind hash.

Source:
Returns:
Type
BlindValue

(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>

(async) getNames() → {Array.<NameState>}

Get all names.

Source:
Returns:
Type
Array.<NameState>

(async) getNameState(nameHash) → {NameState}

Get a name state if present.

Parameters:
Name Type Description
nameHash Buffer
Source:
Returns:
Type
NameState

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) getReveal(nameHash, outpoint) → {BidReveal}

Get a reveal if present.

Parameters:
Name Type Description
nameHash Buffer
outpoint Outpoint
Source:
Returns:
Type
BidReveal

(async) getReveals(nameHash) → {Array.<BidReveal>}

Get all reveals by name.

Parameters:
Name Type Description
nameHash Buffer
Source:
Returns:
Type
Array.<BidReveal>

(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) hasBid(nameHash, outpoint) → {Boolean}

Test whether we have a bid.

Parameters:
Name Type Description
nameHash Buffer
outpoint Outpoint
Source:
Returns:
Type
Boolean

(async) hasBlind(blind) → {Boolean}

Test whether a blind value is present.

Parameters:
Name Type Description
blind Buffer

Blind hash.

Source:
Returns:
Type
Boolean

(async) hasCoin(hash) → {Promise}

Test whether the database has a transaction.

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

hasCoinByAccount(acct, hash, number) → {Promise}

Test whether an account owns a coin.

Parameters:
Name Type Description
acct Number
hash Hash
number Index
Source:
Returns:
  • Returns Boolean.
Type
Promise

(async) hasNameState(nameHash) → {Boolean}

Test whether we have a name.

Parameters:
Name Type Description
nameHash Buffer
Source:
Returns:
Type
Boolean

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

(async) hasReveal(nameHash, outpoint) → {Boolean}

Test whether we have a reveal.

Parameters:
Name Type Description
nameHash Buffer
outpoint Outpoint
Source:
Returns:
Type
Boolean

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

(private) indexOpens(b, tx)

Index open covenants.

Parameters:
Name Type Description
b Batch
tx TX
Source:

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

Insert transaction.

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

(async) isDoubleOpen(tx) → {Promise.<Boolean>}

Test whether the transaction has a duplicate open.

Parameters:
Name Type Description
tx TX
Source:
Returns:
Type
Promise.<Boolean>

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

(async) lockBalances(b, state, tx, i, path, height)

Lock balances according to covenants.

Parameters:
Name Type Description
b Object
state State
tx TX
i Number
path Path
height Number
Source:

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

putBid(b, nameHash, outpoint, options)

Write a bid.

Parameters:
Name Type Description
b Object
nameHash Buffer
outpoint Outpoint
options Object
Source:

putBlind(b, blind, options)

Write a blind value.

Parameters:
Name Type Description
b Object
blind Buffer
options Object
Source:

putReveal(b, nameHash, outpoint, options)

Write a reveal.

Parameters:
Name Type Description
b Object
nameHash Buffer
outpoint Outpoint
options Object
Source:

(async) remove(hash) → {Promise}

Recursively remove a transaction from the database.

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

removeBid(b, nameHash, outpoint)

Delete a bid.

Parameters:
Name Type Description
b Object
nameHash Buffer
outpoint Outpoint
Source:

(async) removeBids(nameHash)

Remove all bids for name.

Parameters:
Name Type Description
nameHash Buffer
Source:

removeBlind(b, blind)

Delete a blind value.

Parameters:
Name Type Description
b Object
blind Buffer
Source:

(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, private) removeDoubleOpen(tx)

Remove duplicate opens.

Parameters:
Name Type Description
tx TX
Source:

(async) removeInput(tx, index)

Remove input record.

Parameters:
Name Type Description
tx TX
index Number
Source:

removeNameMap(hash, index) → {Promise}

Remove from global map.

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

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

removeReveal(b, nameHash, outpoint)

Delete a reveal.

Parameters:
Name Type Description
b Object
nameHash Buffer
outpoint Outpoint
Source:

(async) removeReveals(b, nameHash)

Remove all reveals by name.

Parameters:
Name Type Description
b Object
nameHash Buffer
Source:

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) saveBlind(blind, options)

Save blind value.

Parameters:
Name Type Description
blind Buffer
options Object
Source:

(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, height) → {Promise}

Unconfirm a transaction without a batch.

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

(async) undoNameState(b, tx, i, path, height)

Handle reorg'd covenant.

Parameters:
Name Type Description
b Object
tx TX
i Number
path Path
height Number
Source:

(private) unindexOpens(b, tx)

Unindex open covenants.

Parameters:
Name Type Description
b Batch
tx TX
Source:

(async) unlockBalances(b, state, tx, i, path, height)

Unlock balances according to covenants.

Parameters:
Name Type Description
b Object
state State
tx TX
i Number
path Path
height Number
Source:

unlockCoin(coin)

Unlock a single coin.

Parameters:
Name Type Description
coin Coin | Outpoint
Source:

unlockCoins()

Unlock all locked 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