Expose estimateFee method.

This commit is contained in:
Braydon Fuller 2015-07-28 16:03:55 -04:00
parent bee86257ca
commit 2ca3a48884
4 changed files with 41 additions and 0 deletions

View File

@ -232,6 +232,13 @@ describe('Daemon Binding Functionality', function() {
});
describe('fee estimation', function() {
it('will estimate fees', function() {
var fees = bitcoind.estimateFee();
fees.should.equal(-1);
});
});
describe('tip updates', function() {
it('will get an event when the tip is new', function(done) {
this.timeout(4000);

View File

@ -296,6 +296,10 @@ Daemon.prototype.getBlockIndex = function(blockHash) {
return bitcoindjs.getBlockIndex(blockHash);
};
Daemon.prototype.estimateFee = function(blocks) {
return bitcoindjs.estimateFee(blocks);
};
Daemon.prototype.sendTransaction = function(transaction, allowAbsurdFees) {
return bitcoindjs.sendTransaction(transaction, allowAbsurdFees);
};

View File

@ -1121,6 +1121,33 @@ NAN_METHOD(GetInfo) {
NanReturnValue(obj);
}
/**
* Estimate Fee
* @blocks {number} - The number of blocks until confirmed
*/
NAN_METHOD(EstimateFee) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
int nBlocks = args[0]->NumberValue();
if (nBlocks < 1) {
nBlocks = 1;
}
CFeeRate feeRate = mempool.estimateFee(nBlocks);
if (feeRate == CFeeRate(0)) {
NanReturnValue(NanNew<Number>(-1.0));
return;
}
CAmount nFee = feeRate.GetFeePerK();
NanReturnValue(NanNew<Number>(nFee));
}
/**
* Send Transaction
* bitcoindjs.sendTransaction()
@ -1319,6 +1346,8 @@ init(Handle<Object> target) {
NODE_SET_METHOD(target, "addMempoolUncheckedTransaction", AddMempoolUncheckedTransaction);
NODE_SET_METHOD(target, "verifyScript", VerifyScript);
NODE_SET_METHOD(target, "sendTransaction", SendTransaction);
NODE_SET_METHOD(target, "estimateFee", EstimateFee);
}
NODE_MODULE(bitcoindjs, init)

View File

@ -29,3 +29,4 @@ NAN_METHOD(GetMempoolOutputs);
NAN_METHOD(AddMempoolUncheckedTransaction);
NAN_METHOD(VerifyScript);
NAN_METHOD(SendTransaction);
NAN_METHOD(EstimateFee);