walletdb: fee handling.
This commit is contained in:
parent
5069ec1bfb
commit
d6b97efcc4
@ -1434,7 +1434,7 @@ Wallet.prototype._fund = co(function* fund(tx, options) {
|
|||||||
hardFee: options.hardFee,
|
hardFee: options.hardFee,
|
||||||
subtractFee: options.subtractFee,
|
subtractFee: options.subtractFee,
|
||||||
changeAddress: account.change.getAddress(),
|
changeAddress: account.change.getAddress(),
|
||||||
height: this.db.height,
|
height: this.db.state.height,
|
||||||
rate: rate,
|
rate: rate,
|
||||||
maxFee: options.maxFee,
|
maxFee: options.maxFee,
|
||||||
m: account.m,
|
m: account.m,
|
||||||
@ -1455,7 +1455,7 @@ Wallet.prototype._fund = co(function* fund(tx, options) {
|
|||||||
|
|
||||||
Wallet.prototype.createTX = co(function* createTX(options, force) {
|
Wallet.prototype.createTX = co(function* createTX(options, force) {
|
||||||
var outputs = options.outputs;
|
var outputs = options.outputs;
|
||||||
var i, tx, total;
|
var i, tx, total, output;
|
||||||
|
|
||||||
if (!Array.isArray(outputs) || outputs.length === 0)
|
if (!Array.isArray(outputs) || outputs.length === 0)
|
||||||
throw new Error('No outputs.');
|
throw new Error('No outputs.');
|
||||||
@ -1464,8 +1464,11 @@ Wallet.prototype.createTX = co(function* createTX(options, force) {
|
|||||||
tx = new MTX();
|
tx = new MTX();
|
||||||
|
|
||||||
// Add the outputs
|
// Add the outputs
|
||||||
for (i = 0; i < outputs.length; i++)
|
for (i = 0; i < outputs.length; i++) {
|
||||||
tx.addOutput(outputs[i]);
|
tx.addOutput(outputs[i]);
|
||||||
|
if (tx.outputs[i].isDust(constants.tx.MIN_RELAY))
|
||||||
|
throw new Error('Output is dust.');
|
||||||
|
}
|
||||||
|
|
||||||
// Fill the inputs with unspents
|
// Fill the inputs with unspents
|
||||||
yield this.fund(tx, options, force);
|
yield this.fund(tx, options, force);
|
||||||
@ -1478,18 +1481,18 @@ Wallet.prototype.createTX = co(function* createTX(options, force) {
|
|||||||
// if (options.locktime != null)
|
// if (options.locktime != null)
|
||||||
// tx.setLocktime(options.locktime);
|
// tx.setLocktime(options.locktime);
|
||||||
// else
|
// else
|
||||||
// tx.avoidFeeSniping(this.db.height);
|
// tx.avoidFeeSniping(this.db.state.height);
|
||||||
|
|
||||||
if (!tx.isSane())
|
if (!tx.isSane())
|
||||||
throw new Error('CheckTransaction failed.');
|
throw new Error('CheckTransaction failed.');
|
||||||
|
|
||||||
if (!tx.checkInputs(this.db.height))
|
if (!tx.checkInputs(this.db.state.height))
|
||||||
throw new Error('CheckInputs failed.');
|
throw new Error('CheckInputs failed.');
|
||||||
|
|
||||||
total = yield this.template(tx);
|
total = yield this.template(tx);
|
||||||
|
|
||||||
if (total === 0)
|
if (total === 0)
|
||||||
throw new Error('template failed.');
|
throw new Error('Templating failed.');
|
||||||
|
|
||||||
return tx;
|
return tx;
|
||||||
});
|
});
|
||||||
@ -1531,6 +1534,8 @@ Wallet.prototype._send = co(function* send(options, passphrase) {
|
|||||||
|
|
||||||
tx = tx.toTX();
|
tx = tx.toTX();
|
||||||
|
|
||||||
|
assert(tx.getFee() <= constants.tx.MAX_FEE, 'TX exceeds maxfee.');
|
||||||
|
|
||||||
yield this.db.addTX(tx);
|
yield this.db.addTX(tx);
|
||||||
|
|
||||||
this.logger.debug('Sending wallet tx (%s): %s', this.id, tx.rhash);
|
this.logger.debug('Sending wallet tx (%s): %s', this.id, tx.rhash);
|
||||||
|
|||||||
@ -972,19 +972,15 @@ WalletDB.prototype.getAccount = co(function* getAccount(wid, index) {
|
|||||||
* @returns {Promise} - Returns Array.
|
* @returns {Promise} - Returns Array.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
WalletDB.prototype.getAccounts = co(function* getAccounts(wid) {
|
WalletDB.prototype.getAccounts = function getAccounts(wid) {
|
||||||
var i, items;
|
return this.db.values({
|
||||||
|
|
||||||
items = yield this.db.values({
|
|
||||||
gte: layout.n(wid, 0x00000000),
|
gte: layout.n(wid, 0x00000000),
|
||||||
lte: layout.n(wid, 0xffffffff)
|
lte: layout.n(wid, 0xffffffff),
|
||||||
});
|
parse: function(data) {
|
||||||
|
return data.toString('ascii');
|
||||||
for (i = 0; i < items.length; i++)
|
}
|
||||||
items[i] = items[i].toString('ascii');
|
}
|
||||||
|
};
|
||||||
return items;
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lookup the corresponding account name's index.
|
* Lookup the corresponding account name's index.
|
||||||
@ -1179,19 +1175,6 @@ WalletDB.prototype.getHashes = function getHashes() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all tx hashes.
|
|
||||||
* @returns {Promise}
|
|
||||||
*/
|
|
||||||
|
|
||||||
WalletDB.prototype.getTXHashes = function getTXHashes() {
|
|
||||||
return this.db.keys({
|
|
||||||
gte: layout.e(constants.NULL_HASH),
|
|
||||||
lte: layout.e(constants.HIGH_HASH),
|
|
||||||
parse: layout.ee
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all tx hashes.
|
* Get all tx hashes.
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user