wallet: all async methods.
This commit is contained in:
parent
c6d7c43485
commit
c16e85e485
@ -49,10 +49,6 @@ function Account(wdb, options) {
|
|||||||
this.wdb = wdb;
|
this.wdb = wdb;
|
||||||
this.network = wdb.network;
|
this.network = wdb.network;
|
||||||
|
|
||||||
this.receive = null;
|
|
||||||
this.change = null;
|
|
||||||
this.nested = null;
|
|
||||||
|
|
||||||
this.wid = 0;
|
this.wid = 0;
|
||||||
this.id = null;
|
this.id = null;
|
||||||
this.name = null;
|
this.name = null;
|
||||||
@ -242,27 +238,6 @@ Account.prototype.init = async function init(b) {
|
|||||||
await this.initDepth(b);
|
await this.initDepth(b);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Open the account (done after retrieval).
|
|
||||||
* @returns {Promise}
|
|
||||||
*/
|
|
||||||
|
|
||||||
Account.prototype.open = function open() {
|
|
||||||
if (!this.initialized)
|
|
||||||
return Promise.resolve();
|
|
||||||
|
|
||||||
if (this.receive)
|
|
||||||
return Promise.resolve();
|
|
||||||
|
|
||||||
this.receive = this.deriveReceive(this.receiveDepth - 1);
|
|
||||||
this.change = this.deriveChange(this.changeDepth - 1);
|
|
||||||
|
|
||||||
if (this.witness)
|
|
||||||
this.nested = this.deriveNested(this.nestedDepth - 1);
|
|
||||||
|
|
||||||
return Promise.resolve();
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a public account key to the account (multisig).
|
* Add a public account key to the account (multisig).
|
||||||
* Does not update the database.
|
* Does not update the database.
|
||||||
@ -600,10 +575,9 @@ Account.prototype.savePath = function savePath(b, path) {
|
|||||||
|
|
||||||
Account.prototype.initDepth = async function initDepth(b) {
|
Account.prototype.initDepth = async function initDepth(b) {
|
||||||
// Receive Address
|
// Receive Address
|
||||||
this.receive = this.deriveReceive(0);
|
|
||||||
this.receiveDepth = 1;
|
this.receiveDepth = 1;
|
||||||
|
|
||||||
await this.saveKey(b, this.receive);
|
await this.saveKey(b, this.deriveReceive(0));
|
||||||
|
|
||||||
// Lookahead
|
// Lookahead
|
||||||
for (let i = 0; i < this.lookahead; i++) {
|
for (let i = 0; i < this.lookahead; i++) {
|
||||||
@ -612,10 +586,9 @@ Account.prototype.initDepth = async function initDepth(b) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Change Address
|
// Change Address
|
||||||
this.change = this.deriveChange(0);
|
|
||||||
this.changeDepth = 1;
|
this.changeDepth = 1;
|
||||||
|
|
||||||
await this.saveKey(b, this.change);
|
await this.saveKey(b, this.deriveChange(0));
|
||||||
|
|
||||||
// Lookahead
|
// Lookahead
|
||||||
for (let i = 0; i < this.lookahead; i++) {
|
for (let i = 0; i < this.lookahead; i++) {
|
||||||
@ -625,10 +598,9 @@ Account.prototype.initDepth = async function initDepth(b) {
|
|||||||
|
|
||||||
// Nested Address
|
// Nested Address
|
||||||
if (this.witness) {
|
if (this.witness) {
|
||||||
this.nested = this.deriveNested(0);
|
|
||||||
this.nestedDepth = 1;
|
this.nestedDepth = 1;
|
||||||
|
|
||||||
await this.saveKey(b, this.nested);
|
await this.saveKey(b, this.deriveNested(0));
|
||||||
|
|
||||||
// Lookahead
|
// Lookahead
|
||||||
for (let i = 0; i < this.lookahead; i++) {
|
for (let i = 0; i < this.lookahead; i++) {
|
||||||
@ -722,15 +694,11 @@ Account.prototype.setLookahead = async function setLookahead(b, lookahead) {
|
|||||||
const diff = this.lookahead - lookahead;
|
const diff = this.lookahead - lookahead;
|
||||||
|
|
||||||
this.receiveDepth += diff;
|
this.receiveDepth += diff;
|
||||||
this.receive = this.deriveReceive(this.receiveDepth - 1);
|
|
||||||
|
|
||||||
this.changeDepth += diff;
|
this.changeDepth += diff;
|
||||||
this.change = this.deriveChange(this.changeDepth - 1);
|
|
||||||
|
|
||||||
if (this.witness) {
|
if (this.witness)
|
||||||
this.nestedDepth += diff;
|
this.nestedDepth += diff;
|
||||||
this.nested = this.deriveNested(this.nestedDepth - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.lookahead = lookahead;
|
this.lookahead = lookahead;
|
||||||
|
|
||||||
@ -774,51 +742,84 @@ Account.prototype.setLookahead = async function setLookahead(b, lookahead) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get current receive address.
|
* Get current receive key.
|
||||||
* @param {String?} enc - `"base58"` or `null`.
|
* @returns {WalletKey}
|
||||||
* @returns {Address|Base58Address}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Account.prototype.getAddress = function getAddress(enc) {
|
Account.prototype.receiveKey = function receiveKey() {
|
||||||
return this.getReceive(enc);
|
if (!this.initialized)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return this.deriveReceive(this.receiveDepth - 1);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current change key.
|
||||||
|
* @returns {WalletKey}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Account.prototype.changeKey = function changeKey() {
|
||||||
|
if (!this.initialized)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return this.deriveChange(this.changeDepth - 1);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current nested key.
|
||||||
|
* @returns {WalletKey}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Account.prototype.nestedKey = function nestedKey() {
|
||||||
|
if (!this.initialized)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if (!this.witness)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return this.deriveNested(this.nestedDepth - 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get current receive address.
|
* Get current receive address.
|
||||||
* @param {String?} enc - `"base58"` or `null`.
|
* @returns {Address}
|
||||||
* @returns {Address|Base58Address}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Account.prototype.getReceive = function getReceive(enc) {
|
Account.prototype.receiveAddress = function receiveAddress() {
|
||||||
if (!this.receive)
|
const key = this.receiveKey();
|
||||||
|
|
||||||
|
if (!key)
|
||||||
return null;
|
return null;
|
||||||
return this.receive.getAddress(enc);
|
|
||||||
|
return key.getAddress();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get current change address.
|
* Get current change address.
|
||||||
* @param {String?} enc - `"base58"` or `null`.
|
* @returns {Address}
|
||||||
* @returns {Address|Base58Address}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Account.prototype.getChange = function getChange(enc) {
|
Account.prototype.changeAddress = function changeAddress() {
|
||||||
if (!this.change)
|
const key = this.changeKey();
|
||||||
|
|
||||||
|
if (!key)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return this.change.getAddress(enc);
|
return key.getAddress();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get current nested address.
|
* Get current nested address.
|
||||||
* @param {String?} enc - `"base58"` or `null`.
|
* @returns {Address}
|
||||||
* @returns {Address|Base58Address}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Account.prototype.getNested = function getNested(enc) {
|
Account.prototype.nestedAddress = function nestedAddress() {
|
||||||
if (!this.nested)
|
const key = this.nestedKey();
|
||||||
|
|
||||||
|
if (!key)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return this.nested.getAddress(enc);
|
return key.getAddress();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -842,16 +843,11 @@ Account.prototype.inspect = function inspect() {
|
|||||||
changeDepth: this.changeDepth,
|
changeDepth: this.changeDepth,
|
||||||
nestedDepth: this.nestedDepth,
|
nestedDepth: this.nestedDepth,
|
||||||
lookahead: this.lookahead,
|
lookahead: this.lookahead,
|
||||||
address: this.initialized
|
receiveAddress: this.receiveAddress(),
|
||||||
? this.receive.getAddress()
|
changeAddress: this.changeAddress(),
|
||||||
: null,
|
nestedAddress: this.nestedAddress(),
|
||||||
nestedAddress: this.initialized && this.nested
|
|
||||||
? this.nested.getAddress()
|
|
||||||
: null,
|
|
||||||
accountKey: this.accountKey.toBase58(),
|
accountKey: this.accountKey.toBase58(),
|
||||||
keys: this.keys.map((key) => {
|
keys: this.keys.map(key => key.toBase58())
|
||||||
return key.toBase58();
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -862,6 +858,10 @@ Account.prototype.inspect = function inspect() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Account.prototype.toJSON = function toJSON(minimal) {
|
Account.prototype.toJSON = function toJSON(minimal) {
|
||||||
|
const receive = this.receiveAddress();
|
||||||
|
const change = this.changeAddress();
|
||||||
|
const nested = this.nestedAddress();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
wid: minimal ? undefined : this.wid,
|
wid: minimal ? undefined : this.wid,
|
||||||
id: minimal ? undefined : this.id,
|
id: minimal ? undefined : this.id,
|
||||||
@ -877,19 +877,11 @@ Account.prototype.toJSON = function toJSON(minimal) {
|
|||||||
changeDepth: this.changeDepth,
|
changeDepth: this.changeDepth,
|
||||||
nestedDepth: this.nestedDepth,
|
nestedDepth: this.nestedDepth,
|
||||||
lookahead: this.lookahead,
|
lookahead: this.lookahead,
|
||||||
receiveAddress: this.receive
|
receiveAddress: receive ? receive.toString() : null,
|
||||||
? this.receive.getAddress('string')
|
changeAddress: change ? change.toString() : null,
|
||||||
: null,
|
nestedAddress: nested ? nested.toString() : null,
|
||||||
nestedAddress: this.nested
|
|
||||||
? this.nested.getAddress('string')
|
|
||||||
: null,
|
|
||||||
changeAddress: this.change
|
|
||||||
? this.change.getAddress('string')
|
|
||||||
: null,
|
|
||||||
accountKey: this.accountKey.toBase58(),
|
accountKey: this.accountKey.toBase58(),
|
||||||
keys: this.keys.map((key) => {
|
keys: this.keys.map(key => key.toBase58())
|
||||||
return key.toBase58();
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -308,7 +308,7 @@ HTTPServer.prototype.initRouter = function initRouter() {
|
|||||||
const passphrase = valid.str('passphrase');
|
const passphrase = valid.str('passphrase');
|
||||||
const old = valid.str('old');
|
const old = valid.str('old');
|
||||||
|
|
||||||
enforce(old || new_, 'Passphrase is required.');
|
enforce(passphrase, 'Passphrase is required.');
|
||||||
|
|
||||||
await req.wallet.setPassphrase(passphrase, old);
|
await req.wallet.setPassphrase(passphrase, old);
|
||||||
|
|
||||||
@ -715,7 +715,7 @@ HTTPServer.prototype.initRouter = function initRouter() {
|
|||||||
const result = [];
|
const result = [];
|
||||||
|
|
||||||
for (const item of details)
|
for (const item of details)
|
||||||
result.push(item.toJSON());
|
result.push(item.toJSON(this.network));
|
||||||
|
|
||||||
res.send(200, result);
|
res.send(200, result);
|
||||||
});
|
});
|
||||||
@ -732,7 +732,7 @@ HTTPServer.prototype.initRouter = function initRouter() {
|
|||||||
const result = [];
|
const result = [];
|
||||||
|
|
||||||
for (const item of details)
|
for (const item of details)
|
||||||
result.push(item.toJSON());
|
result.push(item.toJSON(this.network));
|
||||||
|
|
||||||
res.send(200, result);
|
res.send(200, result);
|
||||||
});
|
});
|
||||||
@ -754,7 +754,7 @@ HTTPServer.prototype.initRouter = function initRouter() {
|
|||||||
const result = [];
|
const result = [];
|
||||||
|
|
||||||
for (const item of details)
|
for (const item of details)
|
||||||
result.push(item.toJSON());
|
result.push(item.toJSON(this.network));
|
||||||
|
|
||||||
res.send(200, result);
|
res.send(200, result);
|
||||||
});
|
});
|
||||||
@ -769,7 +769,7 @@ HTTPServer.prototype.initRouter = function initRouter() {
|
|||||||
const result = [];
|
const result = [];
|
||||||
|
|
||||||
for (const item of details)
|
for (const item of details)
|
||||||
result.push(item.toJSON());
|
result.push(item.toJSON(this.network));
|
||||||
|
|
||||||
res.send(200, result);
|
res.send(200, result);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -19,7 +19,6 @@ const records = require('./records');
|
|||||||
const layout = require('./layout').txdb;
|
const layout = require('./layout').txdb;
|
||||||
const encoding = require('../utils/encoding');
|
const encoding = require('../utils/encoding');
|
||||||
const policy = require('../protocol/policy');
|
const policy = require('../protocol/policy');
|
||||||
const Script = require('../script/script');
|
|
||||||
const TXRecord = records.TXRecord;
|
const TXRecord = records.TXRecord;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -13,7 +13,6 @@ const Network = require('../protocol/network');
|
|||||||
const util = require('../utils/util');
|
const util = require('../utils/util');
|
||||||
const encoding = require('../utils/encoding');
|
const encoding = require('../utils/encoding');
|
||||||
const Lock = require('../utils/lock');
|
const Lock = require('../utils/lock');
|
||||||
const MappedLock = require('../utils/mappedlock');
|
|
||||||
const digest = require('../crypto/digest');
|
const digest = require('../crypto/digest');
|
||||||
const cleanse = require('../crypto/cleanse');
|
const cleanse = require('../crypto/cleanse');
|
||||||
const BufferReader = require('../utils/reader');
|
const BufferReader = require('../utils/reader');
|
||||||
@ -85,7 +84,6 @@ function Wallet(wdb, options) {
|
|||||||
this.master = new MasterKey();
|
this.master = new MasterKey();
|
||||||
|
|
||||||
this.txdb = new TXDB(this.wdb);
|
this.txdb = new TXDB(this.wdb);
|
||||||
this.account = null;
|
|
||||||
|
|
||||||
if (options)
|
if (options)
|
||||||
this.fromOptions(options);
|
this.fromOptions(options);
|
||||||
@ -198,8 +196,6 @@ Wallet.prototype.init = async function init(options) {
|
|||||||
const account = await this._createAccount(options, passphrase);
|
const account = await this._createAccount(options, passphrase);
|
||||||
assert(account);
|
assert(account);
|
||||||
|
|
||||||
this.account = account;
|
|
||||||
|
|
||||||
this.logger.info('Wallet initialized (%s).', this.id);
|
this.logger.info('Wallet initialized (%s).', this.id);
|
||||||
|
|
||||||
await this.txdb.open(this);
|
await this.txdb.open(this);
|
||||||
@ -218,8 +214,6 @@ Wallet.prototype.open = async function open() {
|
|||||||
if (!account)
|
if (!account)
|
||||||
throw new Error('Default account not found.');
|
throw new Error('Default account not found.');
|
||||||
|
|
||||||
this.account = account;
|
|
||||||
|
|
||||||
this.logger.info('Wallet opened (%s).', this.id);
|
this.logger.info('Wallet opened (%s).', this.id);
|
||||||
|
|
||||||
await this.txdb.open(this);
|
await this.txdb.open(this);
|
||||||
@ -723,11 +717,6 @@ Wallet.prototype.getAccountHashes = async function getAccountHashes(acct) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Wallet.prototype.getAccount = async function getAccount(acct) {
|
Wallet.prototype.getAccount = async function getAccount(acct) {
|
||||||
if (this.account) {
|
|
||||||
if (acct === 0 || acct === 'default')
|
|
||||||
return this.account;
|
|
||||||
}
|
|
||||||
|
|
||||||
const index = await this.getAccountIndex(acct);
|
const index = await this.getAccountIndex(acct);
|
||||||
|
|
||||||
if (index === -1)
|
if (index === -1)
|
||||||
@ -742,8 +731,6 @@ Wallet.prototype.getAccount = async function getAccount(acct) {
|
|||||||
account.id = this.id;
|
account.id = this.id;
|
||||||
account.watchOnly = this.watchOnly;
|
account.watchOnly = this.watchOnly;
|
||||||
|
|
||||||
await account.open();
|
|
||||||
|
|
||||||
return account;
|
return account;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1162,17 +1149,11 @@ Wallet.prototype._fund = async function _fund(mtx, options) {
|
|||||||
if (this.watchOnly)
|
if (this.watchOnly)
|
||||||
throw new Error('Cannot fund from watch-only wallet.');
|
throw new Error('Cannot fund from watch-only wallet.');
|
||||||
|
|
||||||
let account;
|
const acct = options.account || 0;
|
||||||
if (options.account != null) {
|
const change = await this.changeAddress(acct);
|
||||||
account = await this.getAccount(options.account);
|
|
||||||
if (!account)
|
|
||||||
throw new Error('Account not found.');
|
|
||||||
} else {
|
|
||||||
account = this.account;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!account.initialized)
|
if (!change)
|
||||||
throw new Error('Account is not initialized.');
|
throw new Error('Account not found.');
|
||||||
|
|
||||||
let rate = options.rate;
|
let rate = options.rate;
|
||||||
if (rate == null)
|
if (rate == null)
|
||||||
@ -1193,7 +1174,7 @@ Wallet.prototype._fund = async function _fund(mtx, options) {
|
|||||||
hardFee: options.hardFee,
|
hardFee: options.hardFee,
|
||||||
subtractFee: options.subtractFee,
|
subtractFee: options.subtractFee,
|
||||||
subtractIndex: options.subtractIndex,
|
subtractIndex: options.subtractIndex,
|
||||||
changeAddress: account.change.getAddress(),
|
changeAddress: change,
|
||||||
height: this.wdb.state.height,
|
height: this.wdb.state.height,
|
||||||
rate: rate,
|
rate: rate,
|
||||||
maxFee: options.maxFee,
|
maxFee: options.maxFee,
|
||||||
@ -2155,43 +2136,133 @@ Wallet.prototype.getLast = async function getLast(acct, limit) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get current receive address.
|
* Get account key.
|
||||||
* @param {String?} enc - `"base58"` or `null`.
|
* @param {Number} [acct=0]
|
||||||
* @returns {Address|Base58Address}
|
* @returns {HDPublicKey}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Wallet.prototype.getAddress = function getAddress(enc) {
|
Wallet.prototype.accountKey = async function accountKey(acct = 0) {
|
||||||
return this.account.getAddress(enc);
|
const account = await this.getAccount(acct);
|
||||||
|
if (!account)
|
||||||
|
throw new Error('Account not found.');
|
||||||
|
return account.accountKey;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current receive depth.
|
||||||
|
* @param {Number} [acct=0]
|
||||||
|
* @returns {Number}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Wallet.prototype.receiveDepth = async function receiveDepth(acct = 0) {
|
||||||
|
const account = await this.getAccount(acct);
|
||||||
|
if (!account)
|
||||||
|
throw new Error('Account not found.');
|
||||||
|
return account.receiveDepth;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current change depth.
|
||||||
|
* @param {Number} [acct=0]
|
||||||
|
* @returns {Number}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Wallet.prototype.changeDepth = async function changeDepth(acct = 0) {
|
||||||
|
const account = await this.getAccount(acct);
|
||||||
|
if (!account)
|
||||||
|
throw new Error('Account not found.');
|
||||||
|
return account.changeDepth;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current nested depth.
|
||||||
|
* @param {Number} [acct=0]
|
||||||
|
* @returns {Number}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Wallet.prototype.nestedDepth = async function nestedDepth(acct = 0) {
|
||||||
|
const account = await this.getAccount(acct);
|
||||||
|
if (!account)
|
||||||
|
throw new Error('Account not found.');
|
||||||
|
return account.nestedDepth;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get current receive address.
|
* Get current receive address.
|
||||||
* @param {String?} enc - `"base58"` or `null`.
|
* @param {Number} [acct=0]
|
||||||
* @returns {Address|Base58Address}
|
* @returns {Address}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Wallet.prototype.getReceive = function getReceive(enc) {
|
Wallet.prototype.receiveAddress = async function receiveAddress(acct = 0) {
|
||||||
return this.account.getReceive(enc);
|
const account = await this.getAccount(acct);
|
||||||
|
if (!account)
|
||||||
|
throw new Error('Account not found.');
|
||||||
|
return account.receiveAddress();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get current change address.
|
* Get current change address.
|
||||||
* @param {String?} enc - `"base58"` or `null`.
|
* @param {Number} [acct=0]
|
||||||
* @returns {Address|Base58Address}
|
* @returns {Address}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Wallet.prototype.getChange = function getChange(enc) {
|
Wallet.prototype.changeAddress = async function changeAddress(acct = 0) {
|
||||||
return this.account.getChange(enc);
|
const account = await this.getAccount(acct);
|
||||||
|
if (!account)
|
||||||
|
throw new Error('Account not found.');
|
||||||
|
return account.changeAddress();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get current nested address.
|
* Get current nested address.
|
||||||
* @param {String?} enc - `"base58"` or `null`.
|
* @param {Number} [acct=0]
|
||||||
* @returns {Address|Base58Address}
|
* @returns {Address}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Wallet.prototype.getNested = function getNested(enc) {
|
Wallet.prototype.nestedAddress = async function nestedAddress(acct = 0) {
|
||||||
return this.account.getNested(enc);
|
const account = await this.getAccount(acct);
|
||||||
|
if (!account)
|
||||||
|
throw new Error('Account not found.');
|
||||||
|
return account.nestedAddress();
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current receive key.
|
||||||
|
* @param {Number} [acct=0]
|
||||||
|
* @returns {WalletKey}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Wallet.prototype.receiveKey = async function receiveKey(acct = 0) {
|
||||||
|
const account = await this.getAccount(acct);
|
||||||
|
if (!account)
|
||||||
|
throw new Error('Account not found.');
|
||||||
|
return account.receiveKey();
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current change key.
|
||||||
|
* @param {Number} [acct=0]
|
||||||
|
* @returns {WalletKey}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Wallet.prototype.changeKey = async function changeKey(acct = 0) {
|
||||||
|
const account = await this.getAccount(acct);
|
||||||
|
if (!account)
|
||||||
|
throw new Error('Account not found.');
|
||||||
|
return account.changeKey();
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current nested key.
|
||||||
|
* @param {Number} [acct=0]
|
||||||
|
* @returns {WalletKey}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Wallet.prototype.nestedKey = async function nestedKey(acct = 0) {
|
||||||
|
const account = await this.getAccount(acct);
|
||||||
|
if (!account)
|
||||||
|
throw new Error('Account not found.');
|
||||||
|
return account.nestedKey();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2209,8 +2280,7 @@ Wallet.prototype.inspect = function inspect() {
|
|||||||
token: this.token.toString('hex'),
|
token: this.token.toString('hex'),
|
||||||
tokenDepth: this.tokenDepth,
|
tokenDepth: this.tokenDepth,
|
||||||
state: this.txdb.state ? this.txdb.state.toJSON(true) : null,
|
state: this.txdb.state ? this.txdb.state.toJSON(true) : null,
|
||||||
master: this.master,
|
master: this.master
|
||||||
account: this.account
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2233,8 +2303,7 @@ Wallet.prototype.toJSON = function toJSON(unsafe) {
|
|||||||
token: this.token.toString('hex'),
|
token: this.token.toString('hex'),
|
||||||
tokenDepth: this.tokenDepth,
|
tokenDepth: this.tokenDepth,
|
||||||
state: this.txdb.state.toJSON(true),
|
state: this.txdb.state.toJSON(true),
|
||||||
master: this.master.toJSON(unsafe),
|
master: this.master.toJSON(unsafe)
|
||||||
account: this.account.toJSON(true)
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -136,7 +136,7 @@ WalletDB.prototype._open = async function _open() {
|
|||||||
await this.logger.open();
|
await this.logger.open();
|
||||||
|
|
||||||
await this.db.open();
|
await this.db.open();
|
||||||
await this.db.checkVersion('V', 6);
|
await this.db.checkVersion('V', 7);
|
||||||
|
|
||||||
this.depth = await this.getDepth();
|
this.depth = await this.getDepth();
|
||||||
|
|
||||||
@ -157,7 +157,7 @@ WalletDB.prototype._open = async function _open() {
|
|||||||
|
|
||||||
this.logger.info(
|
this.logger.info(
|
||||||
'Loaded primary wallet (id=%s, wid=%d, address=%s)',
|
'Loaded primary wallet (id=%s, wid=%d, address=%s)',
|
||||||
wallet.id, wallet.wid, wallet.getAddress());
|
wallet.id, wallet.wid, await wallet.receiveAddress());
|
||||||
|
|
||||||
this.primary = wallet;
|
this.primary = wallet;
|
||||||
this.rpc.wallet = wallet;
|
this.rpc.wallet = wallet;
|
||||||
@ -1299,15 +1299,14 @@ WalletDB.prototype.decryptKeys = async function decryptKeys(b, wid, key) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
WalletDB.prototype.resend = async function resend() {
|
WalletDB.prototype.resend = async function resend() {
|
||||||
const keys = await this.db.keys({
|
const wids = await this.db.keys({
|
||||||
gte: layout.w(0x00000000),
|
gte: layout.w(0x00000000),
|
||||||
lte: layout.w(0xffffffff)
|
lte: layout.w(0xffffffff),
|
||||||
|
parse: k => layout.ww(k)
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const key of keys) {
|
for (const wid of wids)
|
||||||
const wid = layout.ww(key);
|
|
||||||
await this.resendPending(wid);
|
await this.resendPending(wid);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1319,26 +1318,27 @@ WalletDB.prototype.resend = async function resend() {
|
|||||||
|
|
||||||
WalletDB.prototype.resendPending = async function resendPending(wid) {
|
WalletDB.prototype.resendPending = async function resendPending(wid) {
|
||||||
const layout = layouts.txdb;
|
const layout = layouts.txdb;
|
||||||
|
const prefix = layout.prefix(wid);
|
||||||
|
const b = this.db.bucket(prefix);
|
||||||
|
|
||||||
const keys = await this.db.keys({
|
const hashes = await b.keys({
|
||||||
gte: layout.prefix(wid, layout.p(encoding.NULL_HASH)),
|
gte: layout.p(encoding.NULL_HASH),
|
||||||
lte: layout.prefix(wid, layout.p(encoding.HIGH_HASH))
|
lte: layout.p(encoding.HIGH_HASH),
|
||||||
|
parse: k => layout.pp(k)
|
||||||
});
|
});
|
||||||
|
|
||||||
if (keys.length === 0)
|
if (hashes.length === 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.logger.info(
|
this.logger.info(
|
||||||
'Rebroadcasting %d transactions for %d.',
|
'Rebroadcasting %d transactions for %d.',
|
||||||
keys.length,
|
hashes.length,
|
||||||
wid);
|
wid);
|
||||||
|
|
||||||
const txs = [];
|
const txs = [];
|
||||||
|
|
||||||
for (const key of keys) {
|
for (const hash of hashes) {
|
||||||
const hash = layout.pp(key);
|
const data = await b.get(layout.t(hash));
|
||||||
const tkey = layout.prefix(wid, layout.t(hash));
|
|
||||||
const data = await this.db.get(tkey);
|
|
||||||
|
|
||||||
if (!data)
|
if (!data)
|
||||||
continue;
|
continue;
|
||||||
@ -1718,7 +1718,7 @@ WalletDB.prototype.rollback = async function rollback(height) {
|
|||||||
|
|
||||||
if (height === this.state.height) {
|
if (height === this.state.height) {
|
||||||
this.logger.debug('Rolled back to same height (%d).', height);
|
this.logger.debug('Rolled back to same height (%d).', height);
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.info(
|
this.logger.info(
|
||||||
@ -1730,8 +1730,6 @@ WalletDB.prototype.rollback = async function rollback(height) {
|
|||||||
|
|
||||||
await this.revert(tip.height);
|
await this.revert(tip.height);
|
||||||
await this.syncState(tip);
|
await this.syncState(tip);
|
||||||
|
|
||||||
return true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2011,13 +2009,7 @@ WalletDB.prototype._resetChain = async function _resetChain(entry) {
|
|||||||
if (entry.height > this.state.height)
|
if (entry.height > this.state.height)
|
||||||
throw new Error('WDB: Bad reset height.');
|
throw new Error('WDB: Bad reset height.');
|
||||||
|
|
||||||
// Try to rollback.
|
await this.rollback(entry.height);
|
||||||
if (await this.rollback(entry.height))
|
|
||||||
return;
|
|
||||||
|
|
||||||
// If we rolled back to the
|
|
||||||
// start block, we need a rescan.
|
|
||||||
await this.scan();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -44,8 +44,8 @@ async function mineBlock(tip, tx) {
|
|||||||
|
|
||||||
spend.addTX(tx, 0);
|
spend.addTX(tx, 0);
|
||||||
|
|
||||||
spend.addOutput(wallet.getReceive(), 25 * 1e8);
|
spend.addOutput(await wallet.receiveAddress(), 25 * 1e8);
|
||||||
spend.addOutput(wallet.getChange(), 5 * 1e8);
|
spend.addOutput(await wallet.changeAddress(), 5 * 1e8);
|
||||||
|
|
||||||
spend.setLocktime(chain.height);
|
spend.setLocktime(chain.height);
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ describe('Node', function() {
|
|||||||
it('should open walletdb', async () => {
|
it('should open walletdb', async () => {
|
||||||
wallet = await wdb.create();
|
wallet = await wdb.create();
|
||||||
miner.addresses.length = 0;
|
miner.addresses.length = 0;
|
||||||
miner.addAddress(wallet.getReceive());
|
miner.addAddress(await wallet.receiveAddress());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should mine a block', async () => {
|
it('should mine a block', async () => {
|
||||||
@ -258,8 +258,8 @@ describe('Node', function() {
|
|||||||
assert.strictEqual(balance.unconfirmed, 1250 * 1e8);
|
assert.strictEqual(balance.unconfirmed, 1250 * 1e8);
|
||||||
assert.strictEqual(balance.confirmed, 750 * 1e8);
|
assert.strictEqual(balance.confirmed, 750 * 1e8);
|
||||||
|
|
||||||
assert(wallet.account.receiveDepth >= 7);
|
assert((await wallet.receiveDepth()) >= 7);
|
||||||
assert(wallet.account.changeDepth >= 6);
|
assert((await wallet.changeDepth()) >= 6);
|
||||||
|
|
||||||
assert.strictEqual(wdb.state.height, chain.height);
|
assert.strictEqual(wdb.state.height, chain.height);
|
||||||
|
|
||||||
@ -447,7 +447,7 @@ describe('Node', function() {
|
|||||||
|
|
||||||
it('should rescan for transactions', async () => {
|
it('should rescan for transactions', async () => {
|
||||||
await wdb.rescan(0);
|
await wdb.rescan(0);
|
||||||
assert.strictEqual(wallet.txdb.state.confirmed, 1289250000000);
|
assert.strictEqual((await wallet.getBalance()).confirmed, 1289250000000);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reset miner mempool', async () => {
|
it('should reset miner mempool', async () => {
|
||||||
@ -572,7 +572,7 @@ describe('Node', function() {
|
|||||||
rate: 100000,
|
rate: 100000,
|
||||||
outputs: [{
|
outputs: [{
|
||||||
value: 100000,
|
value: 100000,
|
||||||
address: wallet.getAddress()
|
address: await wallet.receiveAddress()
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -582,7 +582,7 @@ describe('Node', function() {
|
|||||||
|
|
||||||
const tx = mtx.toTX();
|
const tx = mtx.toTX();
|
||||||
|
|
||||||
await wallet.wdb.addTX(tx);
|
await wdb.addTX(tx);
|
||||||
|
|
||||||
const missing = await node.mempool.addTX(tx);
|
const missing = await node.mempool.addTX(tx);
|
||||||
assert(!missing);
|
assert(!missing);
|
||||||
@ -597,7 +597,7 @@ describe('Node', function() {
|
|||||||
rate: 1000,
|
rate: 1000,
|
||||||
outputs: [{
|
outputs: [{
|
||||||
value: 50000,
|
value: 50000,
|
||||||
address: wallet.getAddress()
|
address: await wallet.receiveAddress()
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -607,7 +607,7 @@ describe('Node', function() {
|
|||||||
|
|
||||||
const tx = mtx.toTX();
|
const tx = mtx.toTX();
|
||||||
|
|
||||||
await wallet.wdb.addTX(tx);
|
await wdb.addTX(tx);
|
||||||
|
|
||||||
const missing = await node.mempool.addTX(tx);
|
const missing = await node.mempool.addTX(tx);
|
||||||
assert(!missing);
|
assert(!missing);
|
||||||
|
|||||||
@ -37,11 +37,6 @@ let importedKey = null;
|
|||||||
let doubleSpendWallet = null;
|
let doubleSpendWallet = null;
|
||||||
let doubleSpendCoin = null;
|
let doubleSpendCoin = null;
|
||||||
|
|
||||||
function prevBlock(wdb) {
|
|
||||||
assert(wdb.state.height > 0);
|
|
||||||
return fakeBlock(wdb.state.height - 1);
|
|
||||||
};
|
|
||||||
|
|
||||||
function curBlock(wdb) {
|
function curBlock(wdb) {
|
||||||
return fakeBlock(wdb.state.height);
|
return fakeBlock(wdb.state.height);
|
||||||
};
|
};
|
||||||
@ -73,21 +68,24 @@ function dummyInput() {
|
|||||||
|
|
||||||
async function testP2PKH(witness, nesting) {
|
async function testP2PKH(witness, nesting) {
|
||||||
const flags = Script.flags.STANDARD_VERIFY_FLAGS;
|
const flags = Script.flags.STANDARD_VERIFY_FLAGS;
|
||||||
|
const receiveAddress = nesting ? 'nestedAddress' : 'receiveAddress';
|
||||||
|
const type = witness ? Address.types.WITNESS : Address.types.PUBKEYHASH;
|
||||||
const wallet = await wdb.create({ witness });
|
const wallet = await wdb.create({ witness });
|
||||||
|
|
||||||
const addr = Address.fromString(wallet.getAddress('string'));
|
const waddr = await wallet.receiveAddress();
|
||||||
|
const addr = Address.fromString(waddr.toString());
|
||||||
|
|
||||||
const type = witness ? Address.types.WITNESS : Address.types.PUBKEYHASH;
|
|
||||||
assert.strictEqual(addr.type, type);
|
assert.strictEqual(addr.type, type);
|
||||||
|
assert.strictEqual(addr.type, waddr.type);
|
||||||
|
|
||||||
const src = new MTX();
|
const src = new MTX();
|
||||||
src.addInput(dummyInput());
|
src.addInput(dummyInput());
|
||||||
src.addOutput(nesting ? wallet.getNested() : wallet.getAddress(), 5460 * 2);
|
src.addOutput(await wallet[receiveAddress](), 5460 * 2);
|
||||||
src.addOutput(new Address(), 2 * 5460);
|
src.addOutput(new Address(), 2 * 5460);
|
||||||
|
|
||||||
const mtx = new MTX();
|
const mtx = new MTX();
|
||||||
mtx.addTX(src, 0);
|
mtx.addTX(src, 0);
|
||||||
mtx.addOutput(wallet.getAddress(), 5460);
|
mtx.addOutput(await wallet.receiveAddress(), 5460);
|
||||||
|
|
||||||
await wallet.sign(mtx);
|
await wallet.sign(mtx);
|
||||||
|
|
||||||
@ -98,7 +96,7 @@ async function testP2PKH(witness, nesting) {
|
|||||||
|
|
||||||
async function testP2SH(witness, nesting) {
|
async function testP2SH(witness, nesting) {
|
||||||
const flags = Script.flags.STANDARD_VERIFY_FLAGS;
|
const flags = Script.flags.STANDARD_VERIFY_FLAGS;
|
||||||
const receive = nesting ? 'nested' : 'receive';
|
const receiveAddress = nesting ? 'nestedAddress' : 'receiveAddress';
|
||||||
const receiveDepth = nesting ? 'nestedDepth' : 'receiveDepth';
|
const receiveDepth = nesting ? 'nestedDepth' : 'receiveDepth';
|
||||||
const vector = witness ? 'witness' : 'script';
|
const vector = witness ? 'witness' : 'script';
|
||||||
|
|
||||||
@ -115,17 +113,17 @@ async function testP2SH(witness, nesting) {
|
|||||||
const carol = await wdb.create(options);
|
const carol = await wdb.create(options);
|
||||||
const recipient = await wdb.create();
|
const recipient = await wdb.create();
|
||||||
|
|
||||||
await alice.addSharedKey(0, bob.account.accountKey);
|
await alice.addSharedKey(0, await bob.accountKey(0));
|
||||||
await alice.addSharedKey(0, carol.account.accountKey);
|
await alice.addSharedKey(0, await carol.accountKey(0));
|
||||||
|
|
||||||
await bob.addSharedKey(0, alice.account.accountKey);
|
await bob.addSharedKey(0, await alice.accountKey(0));
|
||||||
await bob.addSharedKey(0, carol.account.accountKey);
|
await bob.addSharedKey(0, await carol.accountKey(0));
|
||||||
|
|
||||||
await carol.addSharedKey(0, alice.account.accountKey);
|
await carol.addSharedKey(0, await alice.accountKey(0));
|
||||||
await carol.addSharedKey(0, bob.account.accountKey);
|
await carol.addSharedKey(0, await bob.accountKey(0));
|
||||||
|
|
||||||
// Our p2sh address
|
// Our p2sh address
|
||||||
const addr1 = alice.account[receive].getAddress();
|
const addr1 = await alice[receiveAddress]();
|
||||||
|
|
||||||
if (witness) {
|
if (witness) {
|
||||||
const type = nesting ? Address.types.SCRIPTHASH : Address.types.WITNESS;
|
const type = nesting ? Address.types.SCRIPTHASH : Address.types.WITNESS;
|
||||||
@ -134,17 +132,17 @@ async function testP2SH(witness, nesting) {
|
|||||||
assert.strictEqual(addr1.type, Address.types.SCRIPTHASH);
|
assert.strictEqual(addr1.type, Address.types.SCRIPTHASH);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(alice.account[receive].getAddress().equals(addr1));
|
assert((await alice[receiveAddress]()).equals(addr1));
|
||||||
assert(bob.account[receive].getAddress().equals(addr1));
|
assert((await bob[receiveAddress]()).equals(addr1));
|
||||||
assert(carol.account[receive].getAddress().equals(addr1));
|
assert((await carol[receiveAddress]()).equals(addr1));
|
||||||
|
|
||||||
const nestedAddr1 = alice.getNested();
|
const nestedAddr1 = await alice.nestedAddress();
|
||||||
|
|
||||||
if (witness) {
|
if (witness) {
|
||||||
assert(nestedAddr1);
|
assert(nestedAddr1);
|
||||||
assert(alice.getNested().equals(nestedAddr1));
|
assert((await alice.nestedAddress()).equals(nestedAddr1));
|
||||||
assert(bob.getNested().equals(nestedAddr1));
|
assert((await bob.nestedAddress()).equals(nestedAddr1));
|
||||||
assert(carol.getNested().equals(nestedAddr1));
|
assert((await carol.nestedAddress()).equals(nestedAddr1));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -154,25 +152,25 @@ async function testP2SH(witness, nesting) {
|
|||||||
fund.addOutput(nesting ? nestedAddr1 : addr1, 5460 * 10);
|
fund.addOutput(nesting ? nestedAddr1 : addr1, 5460 * 10);
|
||||||
|
|
||||||
// Simulate a confirmation
|
// Simulate a confirmation
|
||||||
assert.strictEqual(alice.account[receiveDepth], 1);
|
assert.strictEqual(await alice[receiveDepth](), 1);
|
||||||
|
|
||||||
await wdb.addBlock(nextBlock(wdb), [fund.toTX()]);
|
await wdb.addBlock(nextBlock(wdb), [fund.toTX()]);
|
||||||
|
|
||||||
assert.strictEqual(alice.account[receiveDepth], 2);
|
assert.strictEqual(await alice[receiveDepth](), 2);
|
||||||
assert.strictEqual(alice.account.changeDepth, 1);
|
assert.strictEqual(await alice.changeDepth(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const addr2 = alice.account[receive].getAddress();
|
const addr2 = await alice[receiveAddress]();
|
||||||
assert(!addr2.equals(addr1));
|
assert(!addr2.equals(addr1));
|
||||||
|
|
||||||
assert(alice.account[receive].getAddress().equals(addr2));
|
assert((await alice[receiveAddress]()).equals(addr2));
|
||||||
assert(bob.account[receive].getAddress().equals(addr2));
|
assert((await bob[receiveAddress]()).equals(addr2));
|
||||||
assert(carol.account[receive].getAddress().equals(addr2));
|
assert((await carol[receiveAddress]()).equals(addr2));
|
||||||
|
|
||||||
// Create a tx requiring 2 signatures
|
// Create a tx requiring 2 signatures
|
||||||
const send = new MTX();
|
const send = new MTX();
|
||||||
|
|
||||||
send.addOutput(recipient.getAddress(), 5460);
|
send.addOutput(await recipient.receiveAddress(), 5460);
|
||||||
|
|
||||||
assert(!send.verify(flags));
|
assert(!send.verify(flags));
|
||||||
|
|
||||||
@ -190,30 +188,30 @@ async function testP2SH(witness, nesting) {
|
|||||||
const [tx, view] = send.commit();
|
const [tx, view] = send.commit();
|
||||||
assert(tx.verify(view, flags));
|
assert(tx.verify(view, flags));
|
||||||
|
|
||||||
assert.strictEqual(alice.account.changeDepth, 1);
|
assert.strictEqual(await alice.changeDepth(), 1);
|
||||||
|
|
||||||
const change = alice.account.change.getAddress();
|
const change = await alice.changeAddress();
|
||||||
|
|
||||||
assert(alice.account.change.getAddress().equals(change));
|
assert((await alice.changeAddress()).equals(change));
|
||||||
assert(bob.account.change.getAddress().equals(change));
|
assert((await bob.changeAddress()).equals(change));
|
||||||
assert(carol.account.change.getAddress().equals(change));
|
assert((await carol.changeAddress()).equals(change));
|
||||||
|
|
||||||
// Simulate a confirmation
|
// Simulate a confirmation
|
||||||
{
|
{
|
||||||
await wdb.addBlock(nextBlock(wdb), [tx]);
|
await wdb.addBlock(nextBlock(wdb), [tx]);
|
||||||
|
|
||||||
assert.strictEqual(alice.account[receiveDepth], 2);
|
assert.strictEqual(await alice[receiveDepth](), 2);
|
||||||
assert.strictEqual(alice.account.changeDepth, 2);
|
assert.strictEqual(await alice.changeDepth(), 2);
|
||||||
|
|
||||||
assert(alice.account[receive].getAddress().equals(addr2));
|
assert((await alice[receiveAddress]()).equals(addr2));
|
||||||
assert(!alice.account.change.getAddress().equals(change));
|
assert(!(await alice.changeAddress()).equals(change));
|
||||||
}
|
}
|
||||||
|
|
||||||
const change2 = alice.account.change.getAddress();
|
const change2 = await alice.changeAddress();
|
||||||
|
|
||||||
assert(alice.account.change.getAddress().equals(change2));
|
assert((await alice.changeAddress()).equals(change2));
|
||||||
assert(bob.account.change.getAddress().equals(change2));
|
assert((await bob.changeAddress()).equals(change2));
|
||||||
assert(carol.account.change.getAddress().equals(change2));
|
assert((await carol.changeAddress()).equals(change2));
|
||||||
|
|
||||||
const input = tx.inputs[0];
|
const input = tx.inputs[0];
|
||||||
input[vector].setData(2, encoding.ZERO_SIG);
|
input[vector].setData(2, encoding.ZERO_SIG);
|
||||||
@ -234,7 +232,7 @@ describe('Wallet', function() {
|
|||||||
it('should generate new key and address', async () => {
|
it('should generate new key and address', async () => {
|
||||||
const wallet = await wdb.create();
|
const wallet = await wdb.create();
|
||||||
|
|
||||||
const addr1 = wallet.getAddress();
|
const addr1 = await wallet.receiveAddress();
|
||||||
assert(addr1);
|
assert(addr1);
|
||||||
|
|
||||||
const str = addr1.toString();
|
const str = addr1.toString();
|
||||||
@ -284,7 +282,7 @@ describe('Wallet', function() {
|
|||||||
await wallet.addSharedKey(0, key);
|
await wallet.addSharedKey(0, key);
|
||||||
|
|
||||||
const script = Script.fromMultisig(1, 2, [
|
const script = Script.fromMultisig(1, 2, [
|
||||||
wallet.account.receive.getPublicKey(),
|
(await wallet.receiveKey()).publicKey,
|
||||||
key.derivePath('m/0/0').publicKey
|
key.derivePath('m/0/0').publicKey
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -296,7 +294,7 @@ describe('Wallet', function() {
|
|||||||
|
|
||||||
const tx = new MTX();
|
const tx = new MTX();
|
||||||
tx.addTX(src, 0);
|
tx.addTX(src, 0);
|
||||||
tx.addOutput(wallet.getAddress(), 5460);
|
tx.addOutput(await wallet.receiveAddress(), 5460);
|
||||||
|
|
||||||
const maxSize = await tx.estimateSize();
|
const maxSize = await tx.estimateSize();
|
||||||
|
|
||||||
@ -306,7 +304,7 @@ describe('Wallet', function() {
|
|||||||
assert(tx.verify());
|
assert(tx.verify());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle missed and invalid txs', async () => {
|
it('should handle missed txs', async () => {
|
||||||
const alice = await wdb.create();
|
const alice = await wdb.create();
|
||||||
const bob = await wdb.create();
|
const bob = await wdb.create();
|
||||||
|
|
||||||
@ -314,13 +312,13 @@ describe('Wallet', function() {
|
|||||||
// balance: 51000
|
// balance: 51000
|
||||||
const t1 = new MTX();
|
const t1 = new MTX();
|
||||||
t1.addInput(dummyInput());
|
t1.addInput(dummyInput());
|
||||||
t1.addOutput(alice.getAddress(), 50000);
|
t1.addOutput(await alice.receiveAddress(), 50000);
|
||||||
t1.addOutput(alice.getAddress(), 1000);
|
t1.addOutput(await alice.receiveAddress(), 1000);
|
||||||
|
|
||||||
const t2 = new MTX();
|
const t2 = new MTX();
|
||||||
t2.addTX(t1, 0); // 50000
|
t2.addTX(t1, 0); // 50000
|
||||||
t2.addOutput(alice.getAddress(), 24000);
|
t2.addOutput(await alice.receiveAddress(), 24000);
|
||||||
t2.addOutput(alice.getAddress(), 24000);
|
t2.addOutput(await alice.receiveAddress(), 24000);
|
||||||
|
|
||||||
// Save for later.
|
// Save for later.
|
||||||
doubleSpendWallet = alice;
|
doubleSpendWallet = alice;
|
||||||
@ -332,7 +330,7 @@ describe('Wallet', function() {
|
|||||||
const t3 = new MTX();
|
const t3 = new MTX();
|
||||||
t3.addTX(t1, 1); // 1000
|
t3.addTX(t1, 1); // 1000
|
||||||
t3.addTX(t2, 0); // 24000
|
t3.addTX(t2, 0); // 24000
|
||||||
t3.addOutput(alice.getAddress(), 23000);
|
t3.addOutput(await alice.receiveAddress(), 23000);
|
||||||
|
|
||||||
// balance: 47000
|
// balance: 47000
|
||||||
await alice.sign(t3);
|
await alice.sign(t3);
|
||||||
@ -340,15 +338,15 @@ describe('Wallet', function() {
|
|||||||
const t4 = new MTX();
|
const t4 = new MTX();
|
||||||
t4.addTX(t2, 1); // 24000
|
t4.addTX(t2, 1); // 24000
|
||||||
t4.addTX(t3, 0); // 23000
|
t4.addTX(t3, 0); // 23000
|
||||||
t4.addOutput(alice.getAddress(), 11000);
|
t4.addOutput(await alice.receiveAddress(), 11000);
|
||||||
t4.addOutput(alice.getAddress(), 11000);
|
t4.addOutput(await alice.receiveAddress(), 11000);
|
||||||
|
|
||||||
// balance: 22000
|
// balance: 22000
|
||||||
await alice.sign(t4);
|
await alice.sign(t4);
|
||||||
|
|
||||||
const f1 = new MTX();
|
const f1 = new MTX();
|
||||||
f1.addTX(t4, 1); // 11000
|
f1.addTX(t4, 1); // 11000
|
||||||
f1.addOutput(bob.getAddress(), 10000);
|
f1.addOutput(await bob.receiveAddress(), 10000);
|
||||||
|
|
||||||
// balance: 11000
|
// balance: 11000
|
||||||
await alice.sign(f1);
|
await alice.sign(f1);
|
||||||
@ -433,7 +431,6 @@ describe('Wallet', function() {
|
|||||||
return wtx.tx.hash('hex') === f1.hash('hex');
|
return wtx.tx.hash('hex') === f1.hash('hex');
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should cleanup spenders after double-spend', async () => {
|
it('should cleanup spenders after double-spend', async () => {
|
||||||
@ -461,7 +458,7 @@ describe('Wallet', function() {
|
|||||||
{
|
{
|
||||||
const tx = new MTX();
|
const tx = new MTX();
|
||||||
tx.addCoin(doubleSpendCoin);
|
tx.addCoin(doubleSpendCoin);
|
||||||
tx.addOutput(wallet.getAddress(), 5000);
|
tx.addOutput(await wallet.receiveAddress(), 5000);
|
||||||
|
|
||||||
await wallet.sign(tx);
|
await wallet.sign(tx);
|
||||||
|
|
||||||
@ -482,22 +479,22 @@ describe('Wallet', function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle missed txs without resolution', async () => {
|
it('should handle more missed txs', async () => {
|
||||||
const alice = await wdb.create();
|
const alice = await wdb.create();
|
||||||
const bob = await wdb.create();
|
const bob = await wdb.create();
|
||||||
|
|
||||||
// Coinbase
|
// Coinbase
|
||||||
const t1 = new MTX();
|
const t1 = new MTX();
|
||||||
t1.addInput(dummyInput());
|
t1.addInput(dummyInput());
|
||||||
t1.addOutput(alice.getAddress(), 50000);
|
t1.addOutput(await alice.receiveAddress(), 50000);
|
||||||
t1.addOutput(alice.getAddress(), 1000);
|
t1.addOutput(await alice.receiveAddress(), 1000);
|
||||||
|
|
||||||
// balance: 51000
|
// balance: 51000
|
||||||
|
|
||||||
const t2 = new MTX();
|
const t2 = new MTX();
|
||||||
t2.addTX(t1, 0); // 50000
|
t2.addTX(t1, 0); // 50000
|
||||||
t2.addOutput(alice.getAddress(), 24000);
|
t2.addOutput(await alice.receiveAddress(), 24000);
|
||||||
t2.addOutput(alice.getAddress(), 24000);
|
t2.addOutput(await alice.receiveAddress(), 24000);
|
||||||
|
|
||||||
// balance: 49000
|
// balance: 49000
|
||||||
await alice.sign(t2);
|
await alice.sign(t2);
|
||||||
@ -505,7 +502,7 @@ describe('Wallet', function() {
|
|||||||
const t3 = new MTX();
|
const t3 = new MTX();
|
||||||
t3.addTX(t1, 1); // 1000
|
t3.addTX(t1, 1); // 1000
|
||||||
t3.addTX(t2, 0); // 24000
|
t3.addTX(t2, 0); // 24000
|
||||||
t3.addOutput(alice.getAddress(), 23000);
|
t3.addOutput(await alice.receiveAddress(), 23000);
|
||||||
|
|
||||||
// balance: 47000
|
// balance: 47000
|
||||||
await alice.sign(t3);
|
await alice.sign(t3);
|
||||||
@ -513,15 +510,15 @@ describe('Wallet', function() {
|
|||||||
const t4 = new MTX();
|
const t4 = new MTX();
|
||||||
t4.addTX(t2, 1); // 24000
|
t4.addTX(t2, 1); // 24000
|
||||||
t4.addTX(t3, 0); // 23000
|
t4.addTX(t3, 0); // 23000
|
||||||
t4.addOutput(alice.getAddress(), 11000);
|
t4.addOutput(await alice.receiveAddress(), 11000);
|
||||||
t4.addOutput(alice.getAddress(), 11000);
|
t4.addOutput(await alice.receiveAddress(), 11000);
|
||||||
|
|
||||||
// balance: 22000
|
// balance: 22000
|
||||||
await alice.sign(t4);
|
await alice.sign(t4);
|
||||||
|
|
||||||
const f1 = new MTX();
|
const f1 = new MTX();
|
||||||
f1.addTX(t4, 1); // 11000
|
f1.addTX(t4, 1); // 11000
|
||||||
f1.addOutput(bob.getAddress(), 10000);
|
f1.addOutput(await bob.receiveAddress(), 10000);
|
||||||
|
|
||||||
// balance: 11000
|
// balance: 11000
|
||||||
await alice.sign(f1);
|
await alice.sign(f1);
|
||||||
@ -599,16 +596,16 @@ describe('Wallet', function() {
|
|||||||
// Coinbase
|
// Coinbase
|
||||||
const t1 = new MTX();
|
const t1 = new MTX();
|
||||||
t1.addInput(dummyInput());
|
t1.addInput(dummyInput());
|
||||||
t1.addOutput(alice.getAddress(), 5460);
|
t1.addOutput(await alice.receiveAddress(), 5460);
|
||||||
t1.addOutput(alice.getAddress(), 5460);
|
t1.addOutput(await alice.receiveAddress(), 5460);
|
||||||
t1.addOutput(alice.getAddress(), 5460);
|
t1.addOutput(await alice.receiveAddress(), 5460);
|
||||||
t1.addOutput(alice.getAddress(), 5460);
|
t1.addOutput(await alice.receiveAddress(), 5460);
|
||||||
|
|
||||||
await wdb.addTX(t1.toTX());
|
await wdb.addTX(t1.toTX());
|
||||||
|
|
||||||
// Create new transaction
|
// Create new transaction
|
||||||
const m2 = new MTX();
|
const m2 = new MTX();
|
||||||
m2.addOutput(bob.getAddress(), 5460);
|
m2.addOutput(await bob.receiveAddress(), 5460);
|
||||||
|
|
||||||
await alice.fund(m2, {
|
await alice.fund(m2, {
|
||||||
rate: 10000,
|
rate: 10000,
|
||||||
@ -627,7 +624,7 @@ describe('Wallet', function() {
|
|||||||
|
|
||||||
// Create new transaction
|
// Create new transaction
|
||||||
const t3 = new MTX();
|
const t3 = new MTX();
|
||||||
t3.addOutput(bob.getAddress(), 15000);
|
t3.addOutput(await bob.receiveAddress(), 15000);
|
||||||
|
|
||||||
let err;
|
let err;
|
||||||
try {
|
try {
|
||||||
@ -655,16 +652,16 @@ describe('Wallet', function() {
|
|||||||
// Coinbase
|
// Coinbase
|
||||||
const t1 = new MTX();
|
const t1 = new MTX();
|
||||||
t1.addOutpoint(new Outpoint(encoding.NULL_HASH, 0));
|
t1.addOutpoint(new Outpoint(encoding.NULL_HASH, 0));
|
||||||
t1.addOutput(alice.getAddress(), 5460);
|
t1.addOutput(await alice.receiveAddress(), 5460);
|
||||||
t1.addOutput(alice.getAddress(), 5460);
|
t1.addOutput(await alice.receiveAddress(), 5460);
|
||||||
t1.addOutput(alice.getAddress(), 5460);
|
t1.addOutput(await alice.receiveAddress(), 5460);
|
||||||
t1.addOutput(alice.getAddress(), 5460);
|
t1.addOutput(await alice.receiveAddress(), 5460);
|
||||||
|
|
||||||
await wdb.addTX(t1.toTX());
|
await wdb.addTX(t1.toTX());
|
||||||
|
|
||||||
// Create new transaction
|
// Create new transaction
|
||||||
const m2 = new MTX();
|
const m2 = new MTX();
|
||||||
m2.addOutput(bob.getAddress(), 5460);
|
m2.addOutput(await bob.receiveAddress(), 5460);
|
||||||
|
|
||||||
await alice.fund(m2, {
|
await alice.fund(m2, {
|
||||||
rate: 10000
|
rate: 10000
|
||||||
@ -697,7 +694,7 @@ describe('Wallet', function() {
|
|||||||
|
|
||||||
// Create new transaction
|
// Create new transaction
|
||||||
const t3 = new MTX();
|
const t3 = new MTX();
|
||||||
t3.addOutput(bob.getAddress(), 15000);
|
t3.addOutput(await bob.receiveAddress(), 15000);
|
||||||
|
|
||||||
let err;
|
let err;
|
||||||
try {
|
try {
|
||||||
@ -721,25 +718,25 @@ describe('Wallet', function() {
|
|||||||
// Coinbase
|
// Coinbase
|
||||||
const t1 = new MTX();
|
const t1 = new MTX();
|
||||||
t1.addInput(dummyInput());
|
t1.addInput(dummyInput());
|
||||||
t1.addOutput(alice.getAddress(), 5460);
|
t1.addOutput(await alice.receiveAddress(), 5460);
|
||||||
t1.addOutput(alice.getAddress(), 5460);
|
t1.addOutput(await alice.receiveAddress(), 5460);
|
||||||
t1.addOutput(alice.getAddress(), 5460);
|
t1.addOutput(await alice.receiveAddress(), 5460);
|
||||||
t1.addOutput(alice.getAddress(), 5460);
|
t1.addOutput(await alice.receiveAddress(), 5460);
|
||||||
|
|
||||||
// Coinbase
|
// Coinbase
|
||||||
const t2 = new MTX();
|
const t2 = new MTX();
|
||||||
t2.addInput(dummyInput());
|
t2.addInput(dummyInput());
|
||||||
t2.addOutput(bob.getAddress(), 5460);
|
t2.addOutput(await bob.receiveAddress(), 5460);
|
||||||
t2.addOutput(bob.getAddress(), 5460);
|
t2.addOutput(await bob.receiveAddress(), 5460);
|
||||||
t2.addOutput(bob.getAddress(), 5460);
|
t2.addOutput(await bob.receiveAddress(), 5460);
|
||||||
t2.addOutput(bob.getAddress(), 5460);
|
t2.addOutput(await bob.receiveAddress(), 5460);
|
||||||
|
|
||||||
await wdb.addTX(t1.toTX());
|
await wdb.addTX(t1.toTX());
|
||||||
await wdb.addTX(t2.toTX());
|
await wdb.addTX(t2.toTX());
|
||||||
|
|
||||||
// Create our tx with an output
|
// Create our tx with an output
|
||||||
const tx = new MTX();
|
const tx = new MTX();
|
||||||
tx.addOutput(carol.getAddress(), 5460);
|
tx.addOutput(await carol.receiveAddress(), 5460);
|
||||||
|
|
||||||
const coins1 = await alice.getCoins();
|
const coins1 = await alice.getCoins();
|
||||||
const coins2 = await bob.getCoins();
|
const coins2 = await bob.getCoins();
|
||||||
@ -799,16 +796,16 @@ describe('Wallet', function() {
|
|||||||
// Coinbase
|
// Coinbase
|
||||||
const t1 = new MTX();
|
const t1 = new MTX();
|
||||||
t1.addInput(dummyInput());
|
t1.addInput(dummyInput());
|
||||||
t1.addOutput(account.receive.getAddress(), 5460);
|
t1.addOutput(account.receiveAddress(), 5460);
|
||||||
t1.addOutput(account.receive.getAddress(), 5460);
|
t1.addOutput(account.receiveAddress(), 5460);
|
||||||
t1.addOutput(account.receive.getAddress(), 5460);
|
t1.addOutput(account.receiveAddress(), 5460);
|
||||||
t1.addOutput(account.receive.getAddress(), 5460);
|
t1.addOutput(account.receiveAddress(), 5460);
|
||||||
|
|
||||||
await wdb.addTX(t1.toTX());
|
await wdb.addTX(t1.toTX());
|
||||||
|
|
||||||
// Create new transaction
|
// Create new transaction
|
||||||
const t2 = new MTX();
|
const t2 = new MTX();
|
||||||
t2.addOutput(bob.getAddress(), 5460);
|
t2.addOutput(await bob.receiveAddress(), 5460);
|
||||||
|
|
||||||
await alice.fund(t2, {
|
await alice.fund(t2, {
|
||||||
rate: 10000,
|
rate: 10000,
|
||||||
@ -825,7 +822,7 @@ describe('Wallet', function() {
|
|||||||
|
|
||||||
// Create new transaction
|
// Create new transaction
|
||||||
const t3 = new MTX();
|
const t3 = new MTX();
|
||||||
t3.addOutput(bob.getAddress(), 15000);
|
t3.addOutput(await bob.receiveAddress(), 15000);
|
||||||
|
|
||||||
let err;
|
let err;
|
||||||
try {
|
try {
|
||||||
@ -858,27 +855,23 @@ describe('Wallet', function() {
|
|||||||
const account = await wallet.getAccount('foo');
|
const account = await wallet.getAccount('foo');
|
||||||
assert.strictEqual(account.name, 'foo');
|
assert.strictEqual(account.name, 'foo');
|
||||||
assert.strictEqual(account.accountIndex, 1);
|
assert.strictEqual(account.accountIndex, 1);
|
||||||
assert.strictEqual(wallet.account.accountIndex, 0);
|
|
||||||
|
|
||||||
assert(!account.receive.getAddress().equals(
|
assert(!account.receiveAddress().equals(await wallet.receiveAddress()));
|
||||||
wallet.account.receive.getAddress()));
|
|
||||||
|
|
||||||
assert(wallet.getAddress().equals(wallet.account.receive.getAddress()));
|
|
||||||
|
|
||||||
// Coinbase
|
// Coinbase
|
||||||
const t1 = new MTX();
|
const t1 = new MTX();
|
||||||
t1.addInput(dummyInput());
|
t1.addInput(dummyInput());
|
||||||
t1.addOutput(wallet.getAddress(), 5460);
|
t1.addOutput(await wallet.receiveAddress(), 5460);
|
||||||
t1.addOutput(wallet.getAddress(), 5460);
|
t1.addOutput(await wallet.receiveAddress(), 5460);
|
||||||
t1.addOutput(wallet.getAddress(), 5460);
|
t1.addOutput(await wallet.receiveAddress(), 5460);
|
||||||
t1.addOutput(account.receive.getAddress(), 5460);
|
t1.addOutput(account.receiveAddress(), 5460);
|
||||||
|
|
||||||
await wdb.addTX(t1.toTX());
|
await wdb.addTX(t1.toTX());
|
||||||
|
|
||||||
// Should fill from `foo` and fail
|
// Should fill from `foo` and fail
|
||||||
const t2 = new MTX();
|
const t2 = new MTX();
|
||||||
|
|
||||||
t2.addOutput(wallet.getAddress(), 5460);
|
t2.addOutput(await wallet.receiveAddress(), 5460);
|
||||||
|
|
||||||
let err;
|
let err;
|
||||||
try {
|
try {
|
||||||
@ -895,7 +888,7 @@ describe('Wallet', function() {
|
|||||||
|
|
||||||
// Should fill from whole wallet and succeed
|
// Should fill from whole wallet and succeed
|
||||||
const t3 = new MTX();
|
const t3 = new MTX();
|
||||||
t3.addOutput(wallet.getAddress(), 5460);
|
t3.addOutput(await wallet.receiveAddress(), 5460);
|
||||||
|
|
||||||
await wallet.fund(t3, {
|
await wallet.fund(t3, {
|
||||||
rate: 10000,
|
rate: 10000,
|
||||||
@ -905,15 +898,15 @@ describe('Wallet', function() {
|
|||||||
// Coinbase
|
// Coinbase
|
||||||
const t4 = new MTX();
|
const t4 = new MTX();
|
||||||
t4.addInput(dummyInput());
|
t4.addInput(dummyInput());
|
||||||
t4.addOutput(account.receive.getAddress(), 5460);
|
t4.addOutput(await wallet.receiveAddress('foo'), 5460);
|
||||||
t4.addOutput(account.receive.getAddress(), 5460);
|
t4.addOutput(await wallet.receiveAddress('foo'), 5460);
|
||||||
t4.addOutput(account.receive.getAddress(), 5460);
|
t4.addOutput(await wallet.receiveAddress('foo'), 5460);
|
||||||
|
|
||||||
await wdb.addTX(t4.toTX());
|
await wdb.addTX(t4.toTX());
|
||||||
|
|
||||||
// Should fill from `foo` and succeed
|
// Should fill from `foo` and succeed
|
||||||
const t5 = new MTX();
|
const t5 = new MTX();
|
||||||
t5.addOutput(wallet.getAddress(), 5460);
|
t5.addOutput(await wallet.receiveAddress(), 5460);
|
||||||
|
|
||||||
await wallet.fund(t5, {
|
await wallet.fund(t5, {
|
||||||
rate: 10000,
|
rate: 10000,
|
||||||
@ -959,16 +952,16 @@ describe('Wallet', function() {
|
|||||||
// Coinbase
|
// Coinbase
|
||||||
const t1 = new MTX();
|
const t1 = new MTX();
|
||||||
t1.addInput(dummyInput());
|
t1.addInput(dummyInput());
|
||||||
t1.addOutput(wallet.getAddress(), 5460);
|
t1.addOutput(await wallet.receiveAddress(), 5460);
|
||||||
t1.addOutput(wallet.getAddress(), 5460);
|
t1.addOutput(await wallet.receiveAddress(), 5460);
|
||||||
t1.addOutput(wallet.getAddress(), 5460);
|
t1.addOutput(await wallet.receiveAddress(), 5460);
|
||||||
t1.addOutput(wallet.getAddress(), 5460);
|
t1.addOutput(await wallet.receiveAddress(), 5460);
|
||||||
|
|
||||||
await wdb.addTX(t1.toTX());
|
await wdb.addTX(t1.toTX());
|
||||||
|
|
||||||
// Create new transaction
|
// Create new transaction
|
||||||
const t2 = new MTX();
|
const t2 = new MTX();
|
||||||
t2.addOutput(wallet.getAddress(), 5460);
|
t2.addOutput(await wallet.receiveAddress(), 5460);
|
||||||
|
|
||||||
await wallet.fund(t2, {
|
await wallet.fund(t2, {
|
||||||
rate: 10000,
|
rate: 10000,
|
||||||
@ -998,16 +991,16 @@ describe('Wallet', function() {
|
|||||||
// Coinbase
|
// Coinbase
|
||||||
const t1 = new MTX();
|
const t1 = new MTX();
|
||||||
t1.addInput(dummyInput());
|
t1.addInput(dummyInput());
|
||||||
t1.addOutput(alice.getAddress(), 5460);
|
t1.addOutput(await alice.receiveAddress(), 5460);
|
||||||
t1.addOutput(alice.getAddress(), 5460);
|
t1.addOutput(await alice.receiveAddress(), 5460);
|
||||||
t1.addOutput(alice.getAddress(), 5460);
|
t1.addOutput(await alice.receiveAddress(), 5460);
|
||||||
t1.addOutput(alice.getAddress(), 5460);
|
t1.addOutput(await alice.receiveAddress(), 5460);
|
||||||
|
|
||||||
await wdb.addTX(t1.toTX());
|
await wdb.addTX(t1.toTX());
|
||||||
|
|
||||||
// Create new transaction
|
// Create new transaction
|
||||||
const t2 = new MTX();
|
const t2 = new MTX();
|
||||||
t2.addOutput(bob.getAddress(), 21840);
|
t2.addOutput(await bob.receiveAddress(), 21840);
|
||||||
|
|
||||||
await alice.fund(t2, {
|
await alice.fund(t2, {
|
||||||
rate: 10000,
|
rate: 10000,
|
||||||
@ -1031,10 +1024,10 @@ describe('Wallet', function() {
|
|||||||
// Coinbase
|
// Coinbase
|
||||||
const t1 = new MTX();
|
const t1 = new MTX();
|
||||||
t1.addInput(dummyInput());
|
t1.addInput(dummyInput());
|
||||||
t1.addOutput(alice.getAddress(), 5460);
|
t1.addOutput(await alice.receiveAddress(), 5460);
|
||||||
t1.addOutput(alice.getAddress(), 5460);
|
t1.addOutput(await alice.receiveAddress(), 5460);
|
||||||
t1.addOutput(alice.getAddress(), 5460);
|
t1.addOutput(await alice.receiveAddress(), 5460);
|
||||||
t1.addOutput(alice.getAddress(), 5460);
|
t1.addOutput(await alice.receiveAddress(), 5460);
|
||||||
|
|
||||||
await wdb.addTX(t1.toTX());
|
await wdb.addTX(t1.toTX());
|
||||||
|
|
||||||
@ -1042,7 +1035,7 @@ describe('Wallet', function() {
|
|||||||
subtractFee: true,
|
subtractFee: true,
|
||||||
rate: 10000,
|
rate: 10000,
|
||||||
round: true,
|
round: true,
|
||||||
outputs: [{ address: bob.getAddress(), value: 21840 }]
|
outputs: [{ address: await bob.receiveAddress(), value: 21840 }]
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create new transaction
|
// Create new transaction
|
||||||
@ -1063,20 +1056,20 @@ describe('Wallet', function() {
|
|||||||
// Coinbase
|
// Coinbase
|
||||||
const t1 = new MTX();
|
const t1 = new MTX();
|
||||||
t1.addInput(dummyInput());
|
t1.addInput(dummyInput());
|
||||||
t1.addOutput(alice.getAddress(), 5460);
|
t1.addOutput(await alice.receiveAddress(), 5460);
|
||||||
t1.addOutput(alice.getAddress(), 5460);
|
t1.addOutput(await alice.receiveAddress(), 5460);
|
||||||
t1.addOutput(alice.getAddress(), 5460);
|
t1.addOutput(await alice.receiveAddress(), 5460);
|
||||||
t1.addOutput(alice.getAddress(), 5460);
|
t1.addOutput(await alice.receiveAddress(), 5460);
|
||||||
|
|
||||||
await wdb.addTX(t1.toTX());
|
await wdb.addTX(t1.toTX());
|
||||||
|
|
||||||
// Coinbase
|
// Coinbase
|
||||||
const t2 = new MTX();
|
const t2 = new MTX();
|
||||||
t2.addInput(dummyInput());
|
t2.addInput(dummyInput());
|
||||||
t2.addOutput(alice.getAddress(), 5460);
|
t2.addOutput(await alice.receiveAddress(), 5460);
|
||||||
t2.addOutput(alice.getAddress(), 5460);
|
t2.addOutput(await alice.receiveAddress(), 5460);
|
||||||
t2.addOutput(alice.getAddress(), 5460);
|
t2.addOutput(await alice.receiveAddress(), 5460);
|
||||||
t2.addOutput(alice.getAddress(), 5460);
|
t2.addOutput(await alice.receiveAddress(), 5460);
|
||||||
|
|
||||||
await wdb.addBlock(nextBlock(wdb), [t2.toTX()]);
|
await wdb.addBlock(nextBlock(wdb), [t2.toTX()]);
|
||||||
|
|
||||||
@ -1095,7 +1088,7 @@ describe('Wallet', function() {
|
|||||||
subtractFee: true,
|
subtractFee: true,
|
||||||
rate: 1000,
|
rate: 1000,
|
||||||
depth: 1,
|
depth: 1,
|
||||||
outputs: [{ address: bob.getAddress(), value: 1461 }]
|
outputs: [{ address: await bob.receiveAddress(), value: 1461 }]
|
||||||
});
|
});
|
||||||
|
|
||||||
const coins = await alice.getSmartCoins();
|
const coins = await alice.getSmartCoins();
|
||||||
@ -1127,7 +1120,7 @@ describe('Wallet', function() {
|
|||||||
smart: true,
|
smart: true,
|
||||||
rate: 10000,
|
rate: 10000,
|
||||||
outputs: [{
|
outputs: [{
|
||||||
address: bob.getAddress(),
|
address: await bob.receiveAddress(),
|
||||||
value: total
|
value: total
|
||||||
}]
|
}]
|
||||||
};
|
};
|
||||||
@ -1228,7 +1221,7 @@ describe('Wallet', function() {
|
|||||||
rate: 10000,
|
rate: 10000,
|
||||||
round: true,
|
round: true,
|
||||||
outputs: [{
|
outputs: [{
|
||||||
address: wallet.getAddress(),
|
address: await wallet.receiveAddress(),
|
||||||
value: 7000
|
value: 7000
|
||||||
}]
|
}]
|
||||||
};
|
};
|
||||||
@ -1357,7 +1350,7 @@ describe('Wallet', function() {
|
|||||||
master: KEY1
|
master: KEY1
|
||||||
});
|
});
|
||||||
|
|
||||||
const addr = alice.getAddress();
|
const addr = await alice.receiveAddress();
|
||||||
|
|
||||||
// Coinbase
|
// Coinbase
|
||||||
const t1 = new MTX();
|
const t1 = new MTX();
|
||||||
@ -1417,7 +1410,7 @@ describe('Wallet', function() {
|
|||||||
master: KEY1
|
master: KEY1
|
||||||
});
|
});
|
||||||
|
|
||||||
const addr = alice.getAddress();
|
const addr = await alice.receiveAddress();
|
||||||
|
|
||||||
// Coinbase
|
// Coinbase
|
||||||
const t1 = new MTX();
|
const t1 = new MTX();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user