Class: TXDB

wallet.TXDB

new TXDB(wallet)

TXDB

Parameters:
Name Type Description
wallet Wallet
Source:

Members

(static) layout :Object

Database layout.

Type:
  • Object
Source:

(private) _add

Add transaction without a batch.

Source:

(private) _confirm

Attempt to confirm a transaction.

Source:

(private) _toDetails

Convert transaction to transaction details.

Source:

(private) _unconfirm

Unconfirm a transaction without a batch.

Source:

abandon

Abandon transaction.

Source:

add

Add transaction, potentially runs confirm() and removeConflicts().

Source:

addBlock

Append to the global block record.

Source:

addBlockMap

Append to the global block record.

Source:

addBlockSlow

Append to the global block record.

Source:

addOutpointMap

Append to the global unspent record.

Source:

commit

Save batch.

Source:

(private) confirm

Attempt to confirm a transaction.

Source:

disconnect

Unconfirm a transaction. Necessary after a reorg.

Source:

(private) erase

Remove a transaction from the database. Disconnect inputs.

Source:

getAccountBalance

Calculate balance by account.

Source:

getAccountCoins

Get coins by account.

Source:

getAccountCredits

Get coins by account.

Source:

getAccountHistory

Get all account transactions.

Source:

getBalance

Calculate balance.

Source:

getBlock

Get block record.

Source:

getCoin

Get coin.

Source:

getCoins

Get coins.

Source:

getCoinView

Get a coin viewpoint.

Source:

getCredit

Get coin.

Source:

getDetails

Get transaction details.

Source:

getPending

Get unconfirmed transactions.

Source:

getRange

Get transactions by timestamp range.

Source:

getSpent

Test a whether a coin has been spent.

Source:

getSpentCoin

Get spender coin.

Source:

getSpentCoins

Get historical coins for a transaction.

Source:

getSpentCredits

Fill a transaction with coins (all historical coins).

Source:

getSpentView

Get historical coin viewpoint.

Source:

getState

Get TXDB state.

Source:

getTX

Get transaction.

Source:

getWalletBalance

Calculate balance.

Source:

(private) insert

Insert transaction.

Source:

isDoubleSpend

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

Source:

isRBF

Test an entire transaction to see if any of its outpoints are replace by fee.

Source:

open

Open TXDB.

Source:

remove

Recursively remove a transaction from the database.

Source:

removeBlock

Remove from the global block record.

Source:

removeBlockMap

Remove from the global block record.

Source:

removeBlockSlow

Remove from the global block record.

Source:

(private) removeConflict

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.

Source:

(private) removeConflicts

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

Source:

removeCredit

Remove credit.

Source:

removeOutpointMap

Remove from the global unspent record.

Source:

(private) removeRecursive

Remove a transaction and recursively remove all of its spenders.

Source:

resolveInput

Resolve orphan input.

Source:

saveCredit

Save credit.

Source:

toDetails

Convert transaction to transaction details.

Source:

unconfirm

Unconfirm a transaction. Necessary after a reorg.

Source:

updateSpentCoin

Update spent coin height in storage.

Source:

(private) verifyInput

Attempt to verify an input.

Source:

zap

Zap pending transactions older than age.

Source:

Methods

(private) clear()

Clear batch.

Source:

del(key)

Delete key from current batch.

Parameters:
Name Type Description
key String
Source:

(private) drop()

Drop batch.

Source:

(private) emit(event, data, details)

Emit transaction event.

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

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

get(key)

Get.

Parameters:
Name Type Description
key String
Source:

getAccountHeightRangeHashes(accountnullable, options) → {Promise}

Get TX hashes by height range.

Parameters:
Name Type Attributes Description
account Number <nullable>
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

getAccountHistoryHashes(accountnullable) → {Promise}

Get hashes of all transactions in the database.

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

getAccountOutpoints(accountnullable) → {Promise}

Get all coin hashes in the database.

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

getAccountPendingHashes(accountnullable) → {Promise}

Get hashes of all unconfirmed transactions in the database.

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

getAccountRangeHashes(accountnullable, options) → {Promise}

Get TX hashes by timestamp range.

Parameters:
Name Type Attributes Description
account Number <nullable>
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

getBlocks() → {Promise}

List block records.

Source:
Returns:
Type
Promise

getCredits(accountnullable) → {Promise}

Get coins.

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

getHeightHashes(height) → {Promise}

Get TX hashes by height.

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

getHeightRangeHashes(accountnullable, options) → {Promise}

Get TX hashes by height range.

Parameters:
Name Type Attributes Description
account Number <nullable>
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(accountnullable) → {Promise}

Get all transactions.

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

getHistoryHashes(accountnullable) → {Promise}

Get hashes of all transactions in the database.

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

getLast(accountnullable, limit) → {Promise}

Get last N transactions.

Parameters:
Name Type Attributes Description
account Number <nullable>
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(accountnullable) → {Promise}

Get all coin hashes in the database.

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

getPath(output) → {Promise}

Get wallet path for output.

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

getPendingHashes(accountnullable) → {Promise}

Get hashes of all unconfirmed transactions in the database.

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

getRangeHashes(accountnullable, options) → {Promise}

Get TX hashes by timestamp range.

Parameters:
Name Type Attributes Description
account Number <nullable>
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

has(key)

Has.

Parameters:
Name Type Description
key String
Source:

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

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

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

keys(options) → {Promise}

Iterate.

Parameters:
Name Type Description
options Object
Source:
Returns:
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:

prefix(key) → {Buffer}

Prefix a key.

Parameters:
Name Type Description
key Buffer
Source:
Returns:

Prefixed key.

Type
Buffer

put(key, value)

Put key and value to current batch.

Parameters:
Name Type Description
key String
value Buffer
Source:

range(options) → {Promise}

Iterate.

Parameters:
Name Type Description
options Object
Source:
Returns:
Type
Promise

removeInput(tx, index)

Remove input record.

Parameters:
Name Type Description
tx TX
index Number
Source:

spendCredit(credit, tx, index)

Spend credit.

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

(private) start()

Start batch.

Source:

unlockCoin(coin)

Unlock a single coin.

Parameters:
Name Type Description
coin Coin | Outpoint
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:

values(options) → {Promise}

Iterate.

Parameters:
Name Type Description
options Object
Source:
Returns:
Type
Promise

writeInput(tx, index)

Write input record.

Parameters:
Name Type Description
tx TX
index Number
Source: