walletdb: fee handling.

This commit is contained in:
Christopher Jeffrey 2016-11-05 18:14:10 -07:00
parent 5069ec1bfb
commit d6b97efcc4
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 19 additions and 31 deletions

View File

@ -1434,7 +1434,7 @@ Wallet.prototype._fund = co(function* fund(tx, options) {
hardFee: options.hardFee,
subtractFee: options.subtractFee,
changeAddress: account.change.getAddress(),
height: this.db.height,
height: this.db.state.height,
rate: rate,
maxFee: options.maxFee,
m: account.m,
@ -1455,7 +1455,7 @@ Wallet.prototype._fund = co(function* fund(tx, options) {
Wallet.prototype.createTX = co(function* createTX(options, force) {
var outputs = options.outputs;
var i, tx, total;
var i, tx, total, output;
if (!Array.isArray(outputs) || outputs.length === 0)
throw new Error('No outputs.');
@ -1464,8 +1464,11 @@ Wallet.prototype.createTX = co(function* createTX(options, force) {
tx = new MTX();
// Add the outputs
for (i = 0; i < outputs.length; i++)
for (i = 0; i < outputs.length; 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
yield this.fund(tx, options, force);
@ -1478,18 +1481,18 @@ Wallet.prototype.createTX = co(function* createTX(options, force) {
// if (options.locktime != null)
// tx.setLocktime(options.locktime);
// else
// tx.avoidFeeSniping(this.db.height);
// tx.avoidFeeSniping(this.db.state.height);
if (!tx.isSane())
throw new Error('CheckTransaction failed.');
if (!tx.checkInputs(this.db.height))
if (!tx.checkInputs(this.db.state.height))
throw new Error('CheckInputs failed.');
total = yield this.template(tx);
if (total === 0)
throw new Error('template failed.');
throw new Error('Templating failed.');
return tx;
});
@ -1531,6 +1534,8 @@ Wallet.prototype._send = co(function* send(options, passphrase) {
tx = tx.toTX();
assert(tx.getFee() <= constants.tx.MAX_FEE, 'TX exceeds maxfee.');
yield this.db.addTX(tx);
this.logger.debug('Sending wallet tx (%s): %s', this.id, tx.rhash);

View File

@ -972,19 +972,15 @@ WalletDB.prototype.getAccount = co(function* getAccount(wid, index) {
* @returns {Promise} - Returns Array.
*/
WalletDB.prototype.getAccounts = co(function* getAccounts(wid) {
var i, items;
items = yield this.db.values({
WalletDB.prototype.getAccounts = function getAccounts(wid) {
return this.db.values({
gte: layout.n(wid, 0x00000000),
lte: layout.n(wid, 0xffffffff)
});
for (i = 0; i < items.length; i++)
items[i] = items[i].toString('ascii');
return items;
});
lte: layout.n(wid, 0xffffffff),
parse: function(data) {
return data.toString('ascii');
}
}
};
/**
* 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.
* @returns {Promise}