Merge pull request #56 from braydonf/estimatefee
Expose estimateFee method.
This commit is contained in:
commit
7461a3dcd2
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -29,3 +29,4 @@ NAN_METHOD(GetMempoolOutputs);
|
|||
NAN_METHOD(AddMempoolUncheckedTransaction);
|
||||
NAN_METHOD(VerifyScript);
|
||||
NAN_METHOD(SendTransaction);
|
||||
NAN_METHOD(EstimateFee);
|
||||
|
|
Loading…
Reference in New Issue