Constructor
new WalletDB(options)
Create a wallet db.
Extends:
- EventEmitter
Parameters:
Name | Type | Description |
---|---|---|
options |
Object |
- Source:
Extends
- EventEmitter
Methods
(async, private) _addBlock(entry, txs) → {Promise}
Add a block's transactions without a lock.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry | |
txs |
Array.<TX> |
- Source:
Returns:
- Type
- Promise
(async, private) _addTX(tx, block) → {Promise}
Add a transaction to the database without a lock.
Parameters:
Name | Type | Description |
---|---|---|
tx |
TX | |
block |
BlockMeta |
- Source:
Returns:
- Type
- Promise
(private) _bind()
Bind to node events.
- Source:
(async, private) _create(options) → {Promise}
Create a new wallet, save to database without a lock.
Parameters:
Name | Type | Description |
---|---|---|
options |
Object | See Wallet. |
- Source:
Returns:
- Returns Wallet.
- Type
- Promise
(async, private) _get(wid) → {Promise}
Get a wallet from the database without a lock.
Parameters:
Name | Type | Description |
---|---|---|
wid |
Number |
- Source:
Returns:
- Returns Wallet.
- Type
- Promise
(async, private) _remove(wid) → {Promise}
Remove a wallet (without a lock).
Parameters:
Name | Type | Description |
---|---|---|
wid |
Number |
- Source:
Returns:
- Type
- Promise
(async, private) _removeBlock(entry) → {Promise}
Unconfirm a block's transactions.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry |
- Source:
Returns:
- Type
- Promise
(async, private) _rename(wallet, id) → {Promise}
Rename a wallet without a lock.
Parameters:
Name | Type | Description |
---|---|---|
wallet |
Wallet | |
id |
String |
- Source:
Returns:
- Type
- Promise
(async, private) _rescan(height) → {Promise}
Force a rescan (without a lock).
Parameters:
Name | Type | Description |
---|---|---|
height |
Number |
- Source:
Returns:
- Type
- Promise
(async, private) _resetChain(entry) → {Promise}
Handle a chain reset without a lock.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry |
- Source:
Returns:
- Type
- Promise
(async) addBlock(entry) → {Promise}
Add a block's transactions and write the new best hash.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry |
- Source:
Returns:
- Type
- Promise
(async) addBlockMap(wallet, key, wid)
Add wid to a wallet map.
Parameters:
Name | Type | Description |
---|---|---|
wallet |
Wallet | |
key |
Buffer | |
wid |
Number |
- 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:
(async) addMap(wallet, key, wid)
Add wid to a wallet map.
Parameters:
Name | Type | Description |
---|---|---|
wallet |
Wallet | |
key |
Buffer | |
wid |
Number |
- Source:
(private) addOutpoint(hash, index)
Add outpoint to local filter.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash | |
index |
Number |
- Source:
(async) addOutpointMap(wallet, key, wid)
Add wid to a wallet map.
Parameters:
Name | Type | Description |
---|---|---|
wallet |
Wallet | |
key |
Buffer | |
wid |
Number |
- Source:
(async) addPathMap(wallet, key, wid)
Add wid to a wallet map.
Parameters:
Name | Type | Description |
---|---|---|
wallet |
Wallet | |
key |
Buffer | |
wid |
Number |
- Source:
(async) addTX(tx, blocknullable) → {Promise}
Add a transaction to the database, map addresses to wallet IDs, potentially store orphans, resolve orphans, or confirm a transaction.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
tx |
TX | ||
block |
BlockMeta |
<nullable> |
- Source:
Returns:
- Type
- Promise
(async) addTXMap(wallet, key, wid)
Add wid to a wallet map.
Parameters:
Name | Type | Description |
---|---|---|
wallet |
Wallet | |
key |
Buffer | |
wid |
Number |
- Source:
(async) auth(id, token) → {Promise}
Get a wallet with token auth first.
Parameters:
Name | Type | Description |
---|---|---|
id |
Number | String | |
token |
Buffer |
- Source:
Returns:
- Returns Wallet.
- Type
- Promise
backup(path) → {Promise}
Backup the wallet db.
Parameters:
Name | Type | Description |
---|---|---|
path |
String |
- Source:
Returns:
- Type
- Promise
(async) close() → {Promise}
Close the walletdb, wait for the database to close.
- Source:
Returns:
- Type
- Promise
(async) connect() → {Promise}
Connect to the node server (client required).
- Source:
Returns:
- Type
- Promise
(async) create(options) → {Promise}
Create a new wallet, save to database, setup watcher.
Parameters:
Name | Type | Description |
---|---|---|
options |
Object | See Wallet. |
- Source:
Returns:
- Returns Wallet.
- Type
- Promise
(async) decryptKeys(wid, key) → {Promise}
Decrypt all imported keys for a wallet.
Parameters:
Name | Type | Description |
---|---|---|
wid |
Number | |
key |
Buffer |
- Source:
Returns:
- Type
- Promise
(async) disconnect() → {Promise}
Disconnect from node server (client required).
- Source:
Returns:
- Type
- Promise
dump() → {Promise}
Dump database (for debugging).
- Source:
Returns:
- Returns Object.
- Type
- Promise
(async) encryptKeys(wid, key) → {Promise}
Encrypt all imported keys for a wallet.
Parameters:
Name | Type | Description |
---|---|---|
wid |
Number | |
key |
Buffer |
- Source:
Returns:
- Type
- Promise
(async) ensure(options) → {Promise}
Attempt to create wallet, return wallet if already exists.
Parameters:
Name | Type | Description |
---|---|---|
options |
Object | See Wallet. |
- Source:
Returns:
- Type
- Promise
(async) ensureWID(id) → {Promise}
Map wallet id to wid.
Parameters:
Name | Type | Description |
---|---|---|
id |
String | Number |
- Source:
Returns:
- Returns {Number}.
- Type
- Promise
(async) estimateFee(blocks) → {Promise}
Estimate smart fee from chain server.
Parameters:
Name | Type | Description |
---|---|---|
blocks |
Number |
- Source:
Returns:
- Type
- Promise
(async) get(id) → {Promise}
Get a wallet from the database, setup watcher.
Parameters:
Name | Type | Description |
---|---|---|
id |
Number | String |
- Source:
Returns:
- Returns Wallet.
- Type
- Promise
(async, private) getAccount(wid, index) → {Promise}
Get an account from the database by wid.
Parameters:
Name | Type | Description |
---|---|---|
wid |
Number | |
index |
Number | Account index. |
- Source:
Returns:
- Returns Wallet.
- Type
- Promise
(async) getAccountHashes(wid, account) → {Promise}
Get all account address hashes.
Parameters:
Name | Type | Description |
---|---|---|
wid |
Number | |
account |
Number |
- Source:
Returns:
- Type
- Promise
(async) getAccountIndex(wid, name) → {Promise}
Lookup the corresponding account name's index.
Parameters:
Name | Type | Description |
---|---|---|
wid |
Number | |
name |
String | Account name/index. |
- Source:
Returns:
- Returns Number.
- Type
- Promise
(async) getAccountName(wid, index) → {Promise}
Lookup the corresponding account index's name.
Parameters:
Name | Type | Description |
---|---|---|
wid |
Number | |
index |
Number |
- Source:
Returns:
- Returns Number.
- Type
- Promise
(async) getAccounts(wid) → {Promise}
List account names and indexes from the db.
Parameters:
Name | Type | Description |
---|---|---|
wid |
Number |
- Source:
Returns:
- Returns Array.
- Type
- Promise
(async) getBlock(hash) → {Promise}
Get a wallet block meta.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
Returns:
- Type
- Promise
(async) getBlockMap(key) → {Promise}
Get a wallet map.
Parameters:
Name | Type | Description |
---|---|---|
key |
Buffer |
- Source:
Returns:
- Type
- Promise
(async, private) getDepth() → {Promise}
Get current wallet wid depth.
- Source:
Returns:
- Type
- Promise
(async) getHashes() → {Promise}
Get all address hashes.
- Source:
Returns:
- Type
- Promise
(async) getID(wid) → {Promise}
Map wallet wid to id.
Parameters:
Name | Type | Description |
---|---|---|
wid |
Number |
- Source:
Returns:
- Returns {String}.
- Type
- Promise
(async) getMap(key) → {Promise}
Get a wallet map.
Parameters:
Name | Type | Description |
---|---|---|
key |
Buffer |
- Source:
Returns:
- Type
- Promise
(async) getOutpointMap(key) → {Promise}
Get a wallet map.
Parameters:
Name | Type | Description |
---|---|---|
key |
Buffer |
- Source:
Returns:
- Type
- Promise
(async) getOutpoints() → {Promise}
Get all outpoints.
- Source:
Returns:
- Type
- Promise
(async) getPath(wid, hash) → {Promise}
Retrieve path by hash.
Parameters:
Name | Type | Description |
---|---|---|
wid |
Number | |
hash |
Hash |
- Source:
Returns:
- Type
- Promise
(async) getPathMap(key) → {Promise}
Get a wallet map.
Parameters:
Name | Type | Description |
---|---|---|
key |
Buffer |
- Source:
Returns:
- Type
- Promise
(async) getState() → {Promise}
Get the best block hash.
- Source:
Returns:
- Type
- Promise
(async) getTip(hash) → {Promise}
Get wallet tip.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
Returns:
- Type
- Promise
(async) getTXMap(key) → {Promise}
Get a wallet map.
Parameters:
Name | Type | Description |
---|---|---|
key |
Buffer |
- Source:
Returns:
- Type
- Promise
(async) getWalletHashes(wid) → {Promise}
Get all address hashes.
Parameters:
Name | Type | Description |
---|---|---|
wid |
Number |
- Source:
Returns:
- Type
- Promise
(async) getWalletPaths(wid) → {Promise}
Get all paths for a wallet.
Parameters:
Name | Type | Description |
---|---|---|
wid |
Number |
- Source:
Returns:
- Type
- Promise
(async) getWallets() → {Promise}
Get all wallet ids.
- Source:
Returns:
- Type
- Promise
(async) getWalletsByTX(hashes) → {Promise}
Get all wallet ids by output addresses and outpoints.
Parameters:
Name | Type | Description |
---|---|---|
hashes |
Array.<Hash> |
- Source:
Returns:
- Type
- Promise
(async) getWID(id) → {Promise}
Map wallet id to wid.
Parameters:
Name | Type | Description |
---|---|---|
id |
String |
- Source:
Returns:
- Returns {Number}.
- Type
- Promise
(async) has(id) → {Promise}
Test for the existence of a wallet.
Parameters:
Name | Type | Description |
---|---|---|
id |
Number | String |
- Source:
Returns:
- Type
- Promise
(async) hasAccount(wid, acct) → {Promise}
Test for the existence of an account.
Parameters:
Name | Type | Description |
---|---|---|
wid |
Number | |
acct |
String | Number |
- Source:
Returns:
- Returns Boolean.
- Type
- Promise
(async) hasPath(wid, hash) → {Promise}
Test whether a wallet contains a path.
Parameters:
Name | Type | Description |
---|---|---|
wid |
Number | |
hash |
Hash |
- Source:
Returns:
- Type
- Promise
increment(b, wid)
Increment the wid depth.
Parameters:
Name | Type | Description |
---|---|---|
b |
Batch | |
wid |
Number |
- Source:
(private) init()
Initialize walletdb.
- Source:
liveHeight() → {Number}
Will return the current height and will increment to the current height of a block currently being added to the wallet.
- Source:
Returns:
- Type
- Number
(async) markState(block) → {Promise}
Mark current state.
Parameters:
Name | Type | Description |
---|---|---|
block |
BlockMeta |
- Source:
Returns:
- Type
- Promise
(async, private) migrateState(state) → {Promise}
Migrate sync state.
Parameters:
Name | Type | Description |
---|---|---|
state |
ChainState |
- Source:
Returns:
- Type
- Promise
(async) open() → {Promise}
Open the walletdb, wait for the database to load.
- Source:
Returns:
- Type
- Promise
(async) readPath(wid, hash) → {Promise}
Retrieve path by hash.
Parameters:
Name | Type | Description |
---|---|---|
wid |
Number | |
hash |
Hash |
- Source:
Returns:
- Type
- Promise
register(object)
Register an object with the walletdb.
Parameters:
Name | Type | Description |
---|---|---|
object |
Object |
- Source:
(async) remove(id) → {Promise}
Remove a wallet.
Parameters:
Name | Type | Description |
---|---|---|
id |
Number | String |
- Source:
Returns:
- Type
- Promise
(async) removeBlock(entry) → {Promise}
Unconfirm a block's transactions and write the new best hash (SPV version).
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry |
- Source:
Returns:
- Type
- Promise
(async) removeBlockMap(wallet, key, wid)
Remove wid from a wallet map.
Parameters:
Name | Type | Description |
---|---|---|
wallet |
Wallet | |
key |
Buffer | |
wid |
Number |
- Source:
(async) removeMap(wallet, key, wid)
Remove wid from a wallet map.
Parameters:
Name | Type | Description |
---|---|---|
wallet |
Wallet | |
key |
Buffer | |
wid |
Number |
- Source:
(async) removeOutpointMap(wallet, key, wid)
Remove wid from a wallet map.
Parameters:
Name | Type | Description |
---|---|---|
wallet |
Wallet | |
key |
Buffer | |
wid |
Number |
- Source:
(async) removePathMap(wallet, key, wid)
Remove wid from a wallet map.
Parameters:
Name | Type | Description |
---|---|---|
wallet |
Wallet | |
key |
Buffer | |
wid |
Number |
- Source:
(async) removeTXMap(wallet, key, wid)
Remove wid from a wallet map.
Parameters:
Name | Type | Description |
---|---|---|
wallet |
Wallet | |
key |
Buffer | |
wid |
Number |
- Source:
(async) rename(wallet, id) → {Promise}
Rename a wallet.
Parameters:
Name | Type | Description |
---|---|---|
wallet |
Wallet | |
id |
String |
- Source:
Returns:
- Type
- Promise
renameAccount(account, name)
Rename an account.
Parameters:
Name | Type | Description |
---|---|---|
account |
Account | |
name |
String |
- Source:
(async) rescan(height) → {Promise}
Force a rescan.
Parameters:
Name | Type | Description |
---|---|---|
height |
Number |
- Source:
Returns:
- Type
- Promise
(async, private) rescanBlock(entry, txs) → {Promise}
Rescan a block.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry | |
txs |
Array.<TX> |
- Source:
Returns:
- Type
- Promise
(async) resend() → {Promise}
Resend all pending transactions.
- Source:
Returns:
- Type
- Promise
(async, private) resendPending(wid) → {Promise}
Resend all pending transactions for a specific wallet.
Parameters:
Name | Type | Description |
---|---|---|
wid |
Number |
- Source:
Returns:
- Type
- Promise
(async) resetChain(entry) → {Promise}
Handle a chain reset.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry |
- Source:
Returns:
- Type
- Promise
(private) resetFilter() → {Promise}
Reset remote filter.
- Source:
Returns:
- Type
- Promise
(async) revert(target) → {Promise}
Revert TXDB to an older state.
Parameters:
Name | Type | Description |
---|---|---|
target |
Number |
- Source:
Returns:
- Type
- Promise
(async) rollback(height) → {Promise}
Sync with chain height.
Parameters:
Name | Type | Description |
---|---|---|
height |
Number |
- 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
(async) saveKey(wallet, ring) → {Promise}
Save an address to the path map.
Parameters:
Name | Type | Description |
---|---|---|
wallet |
Wallet | |
ring |
WalletKey |
- Source:
Returns:
- Type
- Promise
(async) savePath(wallet, path) → {Promise}
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
Parameters:
Name | Type | Description |
---|---|---|
wallet |
Wallet | |
path |
Path |
- Source:
Returns:
- Type
- Promise
(async, private) scan(heightnullable) → {Promise}
Rescan blockchain from a given height.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
height |
Number |
<nullable> |
- Source:
Returns:
- Type
- Promise
(async) send(tx) → {Promise}
Broadcast a transaction via chain server.
Parameters:
Name | Type | Description |
---|---|---|
tx |
TX |
- Source:
Returns:
- Type
- Promise
(async) setTip(tip) → {Promise}
Sync the current chain state to tip.
Parameters:
Name | Type | Description |
---|---|---|
tip |
BlockMeta |
- Source:
Returns:
- Type
- Promise
(async, private) syncChain() → {Promise}
Connect and sync with the chain server.
- Source:
Returns:
- Type
- Promise
(private) syncFilter() → {Promise}
Send filter to the remote node.
- Source:
Returns:
- Type
- Promise
(async) syncNode() → {Promise}
Sync state with server on every connect.
- Source:
Returns:
- Type
- Promise
(async) syncState() → {Promise}
Initialize and write initial sync state.
- Source:
Returns:
- Type
- Promise
(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
(async) verifyNetwork() → {Promise}
Verify network.
- Source:
Returns:
- Type
- Promise
(async, private) watch() → {Promise}
Watch addresses and outpoints.
- Source:
Returns:
- Type
- Promise
(async) wipe() → {Promise}
Wipe the txdb - NEVER USE.
- Source:
Returns:
- Type
- Promise