Class: WalletDB

wallet.WalletDB

new WalletDB(options)

WalletDB

Parameters:
Name Type Description
options Object
Properties
Name Type Attributes Description
name String <nullable>

Database name.

location String <nullable>

Database file location.

db String <nullable>

Database backend ("leveldb" by default).

verify Boolean <nullable>

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

Properties:
Name Type Description
loaded Boolean
Source:

Members

(static) layout :Object

Database layout.

Type:
  • Object
Source:

(private) _addBlock

Add a block's transactions without a lock.

Source:

(private) _create

Create a new wallet, save to database without a lock.

Source:

(private) _get

Get a wallet from the database without a lock.

Source:

(private) _insert

Add a transaction to the database without a lock.

Source:

(private) _removeBlock

Unconfirm a block's transactions.

Source:

(private) _rename

Rename a wallet without a lock.

Source:

(private) _rescan

Force a rescan (without a lock).

Source:

(private) _resetChain

Handle a chain reset without a lock.

Source:

(private) _unconfirm

Unconfirm a transaction from all relevant wallets without a lock.

Source:

addBlock

Add a block's transactions and write the new best hash.

Source:

addTX

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

Source:

auth

Get a wallet with token auth first.

Source:

(private) commit

Save batch.

Source:

connect

Connect to the node server (client required).

Source:

create

Create a new wallet, save to database, setup watcher.

Source:

decryptKeys

Decrypt all imported keys for a wallet.

Source:

disconnect

Disconnect from node server (client required).

Source:

encryptKeys

Encrypt all imported keys for a wallet.

Source:

ensure

Attempt to create wallet, return wallet if already exists.

Source:

estimateFee

Estimate smart fee from chain server.

Source:

get

Get a wallet from the database, setup watcher.

Source:

(private) getAccount

Get an account from the database by wid.

Source:

getAccountIndex

Lookup the corresponding account name's index.

Source:

getAccountName

Lookup the corresponding account index's name.

Source:

getBlock

Get a wallet block meta.

Source:

getBlockMap

Get a block->wallet map.

Source:

(private) getDepth

Get current wallet wid depth.

Source:

getOutpointMap

Get a Unspent->Wallet map.

Source:

getPath

Retrieve path by hash.

Source:

getPathMap

Lookup the corresponding account name's index.

Source:

getState

Get the best block hash.

Source:

getTip

Get wallet tip.

Source:

getWalletID

Map wallet id to wid.

Source:

getWalletPaths

Get all paths for a wallet.

Source:

getWalletsByTX

Get all wallet ids by output addresses and outpoints.

Source:

has

Test for the existence of a wallet.

Source:

init

Initialize and write initial sync state.

Source:

load

Load the walletdb.

Source:

maybeMark

Mark the start block once a confirmed tx is seen.

Source:

removeBlock

Unconfirm a block's transactions and write the new best hash (SPV version).

Source:

rename

Rename a wallet.

Source:

rescan

Force a rescan.

Source:

(private) rescanBlock

Rescan a block.

Source:

resend

Resend all pending transactions.

Source:

(private) resendPending

Resend all pending transactions for a specific wallet.

Source:

resetChain

Handle a chain reset.

Source:

resetState

Reset the chain state to a tip/start-block.

Source:

revert

Revert TXDB to an older state.

Source:

rollback

Sync with chain height.

Source:

savePath

Save a path to the path map.

The path map exists in the form of:

  • p[address-hash] -> wid map
  • P[wid][address-hash] -> path data
  • r[wid][account-index][address-hash] -> dummy
Source:

(private) scan

Rescan blockchain from a given height.

Source:

send

Broadcast a transaction via chain server.

Source:

(private) sync

Connect and sync with the chain server.

Source:

syncState

Sync the current chain state to tip.

Source:

(private) watch

Watch addresses and outpoints.

Source:

wipe

Wipe the txdb - NEVER USE.

Source:

Methods

(private) _init()

Initialize walletdb.

Source:

(private) addFilter(data) → {Promise}

Add data to remote filter.

Parameters:
Name Type Description
data Buffer
Source:
Returns:
Type
Promise

(private) addHash(hash)

Add hash to local and remote filters.

Parameters:
Name Type Description
hash Hash
Source:

(private) addOutpoint(hash, index)

Add outpoint to local filter.

Parameters:
Name Type Description
hash Hash
index Number
Source:

backup(path) → {Promise}

Backup the wallet db.

Parameters:
Name Type Description
path String
Source:
Returns:
Type
Promise

(private) batch(wid) → {Leveldown.Batch}

Get batch.

Parameters:
Name Type Description
wid WalletID
Source:
Returns:
Type
Leveldown.Batch

(private) bind()

Bind to node events.

Source:

(private) clear(wid)

Clear batch.

Parameters:
Name Type Description
wid WalletID
Source:

(private) drop(wid)

Drop batch.

Parameters:
Name Type Description
wid WalletID
Source:

dump() → {Promise}

Dump database (for debugging).

Source:
Returns:
  • Returns Object.
Type
Promise

getAccountHashes(wid, account) → {Promise}

Get all account address hashes.

Parameters:
Name Type Description
wid WalletID
account Number
Source:
Returns:
Type
Promise

getAccounts(wid) → {Promise}

List account names and indexes from the db.

Parameters:
Name Type Description
wid WalletID
Source:
Returns:
  • Returns Array.
Type
Promise

getHashes() → {Promise}

Get all address hashes.

Source:
Returns:
Type
Promise

getOutpoints() → {Promise}

Get all outpoints.

Source:
Returns:
Type
Promise

getWalletHashes(wid) → {Promise}

Get all address hashes.

Parameters:
Name Type Description
wid WalletID
Source:
Returns:
Type
Promise

getWallets() → {Promise}

Get all wallet ids.

Source:
Returns:
Type
Promise

hasAccount(wid, acct) → {Promise}

Test for the existence of an account.

Parameters:
Name Type Description
wid WalletID
acct String | Number
Source:
Returns:
  • Returns Boolean.
Type
Promise

hasPath(wid, hash) → {Promise}

Test whether a wallet contains a path.

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

register(object)

Register an object with the walletdb.

Parameters:
Name Type Description
object Object
Source:

renameAccount(account, name)

Rename an account.

Parameters:
Name Type Description
account Account
name String
Source:

(private) resetFilter() → {Promise}

Reset remote filter.

Source:
Returns:
Type
Promise

save(wallet)

Save a wallet to the database.

Parameters:
Name Type Description
wallet Wallet
Source:

saveAccount(account) → {Promise}

Save an account to the database.

Parameters:
Name Type Description
account Account
Source:
Returns:
Type
Promise

saveKey(wallet, ring) → {Promise}

Save an address to the path map.

Parameters:
Name Type Description
wallet Wallet
ring WalletKey
Source:
Returns:
Type
Promise

(private) setFilter() → {Promise}

Send filter to the remote node.

Source:
Returns:
Type
Promise

(private) start(wid)

Start batch.

Parameters:
Name Type Description
wid WalletID
Source:

(private) testFilter(hash) → {Boolean}

Test the bloom filter against a tx or address hash.

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

unregister(object) → {Boolean}

Unregister a object with the walletdb.

Parameters:
Name Type Description
object Object
Source:
Returns:
Type
Boolean

unwriteBlockMap(wallet, height)

Remove a block from the global block map.

Parameters:
Name Type Description
wallet Wallet
height Number
Source:

unwriteOutpointMap(wallet, hash, index)

Remove an outpoint from global unspent map.

Parameters:
Name Type Description
wallet Wallet
hash Hash
index Number
Source:

writeBlockMap(wallet, height, block)

Add block to the global block map.

Parameters:
Name Type Description
wallet Wallet
height Number
block BlockMapRecord
Source:

writeOutpointMap(wallet, hash, index, map)

Add an outpoint to global unspent map.

Parameters:
Name Type Description
wallet Wallet
hash Hash
index Number
map OutpointMapRecord
Source: