Added a binding for Add to mempool.
This commit is contained in:
parent
54edc851e0
commit
ef3abbcb6c
|
@ -135,6 +135,39 @@ describe('Basic Functionality', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('add to mempool', function() {
|
||||||
|
it('will add an uncheckedTransaction', function() {
|
||||||
|
var fromAddress = 'mszYqVnqKoQx4jcTdJXxwKAissE3Jbrrc1';
|
||||||
|
var utxo = {
|
||||||
|
address: fromAddress,
|
||||||
|
txId: 'a477af6b2667c29670467e4e0728b685ee07b240235771862318e29ddbe58458',
|
||||||
|
outputIndex: 0,
|
||||||
|
script: Script.buildPublicKeyHashOut(fromAddress).toString(),
|
||||||
|
satoshis: 100000
|
||||||
|
};
|
||||||
|
var toAddress = 'mrU9pEmAx26HcbKVrABvgL7AwA5fjNFoDc';
|
||||||
|
var changeAddress = 'mgBCJAsvzgT2qNNeXsoECg2uPKrUsZ76up';
|
||||||
|
var changeAddressP2SH = '2N7T3TAetJrSCruQ39aNrJvYLhG1LJosujf';
|
||||||
|
var privateKey = 'cSBnVM4xvxarwGQuAfQFwqDg9k5tErHUHzgWsEfD4zdwUasvqRVY';
|
||||||
|
var private1 = '6ce7e97e317d2af16c33db0b9270ec047a91bff3eff8558afb5014afb2bb5976';
|
||||||
|
var private2 = 'c9b26b0f771a0d2dad88a44de90f05f416b3b385ff1d989343005546a0032890';
|
||||||
|
var tx = new bitcore.Transaction();
|
||||||
|
tx.from(utxo);
|
||||||
|
tx.to(toAddress, 50000);
|
||||||
|
tx.change(changeAddress);
|
||||||
|
tx.sign(privateKey);
|
||||||
|
var added = bitcoind.addMempoolUncheckedTransaction(tx.toBuffer());
|
||||||
|
added.should.equal(true);
|
||||||
|
bitcoind.getTransaction(tx.hash, true, function(err, tx) {
|
||||||
|
if(err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
tx.toString('hex').should.equal(tx.toBuffer().toString('hex'));
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('get outputs by address from the mempool', function() {
|
describe('get outputs by address from the mempool', function() {
|
||||||
it('will do it', function() {
|
it('will do it', function() {
|
||||||
var outputs = bitcoind.getMempoolOutputs('n28S35tqEMbt6vNad7A5K3mZ7vdn8dZ86X');
|
var outputs = bitcoind.getMempoolOutputs('n28S35tqEMbt6vNad7A5K3mZ7vdn8dZ86X');
|
||||||
|
@ -142,4 +175,6 @@ describe('Basic Functionality', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1039,6 +1039,26 @@ NAN_METHOD(GetMempoolOutputs) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AddMempoolUncheckedTransaction
|
||||||
|
*/
|
||||||
|
NAN_METHOD(AddMempoolUncheckedTransaction) {
|
||||||
|
if (!node::Buffer::HasInstance(args[0])) {
|
||||||
|
return NanThrowTypeError("First argument should be a Buffer.");
|
||||||
|
}
|
||||||
|
|
||||||
|
CTransaction tx;
|
||||||
|
const char *arg = node::Buffer::Data(args[0]);
|
||||||
|
std::string strArg = std::string(arg);
|
||||||
|
|
||||||
|
if (!DecodeHexTx(tx, strArg)) {
|
||||||
|
return NanThrowError("could not decode tx");
|
||||||
|
}
|
||||||
|
bool added = mempool.addUnchecked(tx.GetHash(), CTxMemPoolEntry(tx, 0, 0, 0.0, 1));
|
||||||
|
NanReturnValue(NanNew<Boolean>(added));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helpers
|
* Helpers
|
||||||
*/
|
*/
|
||||||
|
@ -1077,6 +1097,7 @@ init(Handle<Object> target) {
|
||||||
NODE_SET_METHOD(target, "isSpent", IsSpent);
|
NODE_SET_METHOD(target, "isSpent", IsSpent);
|
||||||
NODE_SET_METHOD(target, "getChainWork", GetChainWork);
|
NODE_SET_METHOD(target, "getChainWork", GetChainWork);
|
||||||
NODE_SET_METHOD(target, "getMempoolOutputs", GetMempoolOutputs);
|
NODE_SET_METHOD(target, "getMempoolOutputs", GetMempoolOutputs);
|
||||||
|
NODE_SET_METHOD(target, "addMempoolUncheckedTransaction", AddMempoolUncheckedTransaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
NODE_MODULE(bitcoindjs, init)
|
NODE_MODULE(bitcoindjs, init)
|
||||||
|
|
|
@ -1,11 +1,3 @@
|
||||||
/**
|
|
||||||
* bitcoind.js
|
|
||||||
* Copyright (c) 2015, BitPay (MIT License)
|
|
||||||
*
|
|
||||||
* bitcoindjs.h:
|
|
||||||
* A bitcoind node.js binding header file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "addrman.h"
|
#include "addrman.h"
|
||||||
#include "alert.h"
|
#include "alert.h"
|
||||||
|
@ -18,6 +10,7 @@
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#include "nan.h"
|
#include "nan.h"
|
||||||
#include "scheduler.h"
|
#include "scheduler.h"
|
||||||
|
#include "core_io.h"
|
||||||
|
|
||||||
NAN_METHOD(StartBitcoind);
|
NAN_METHOD(StartBitcoind);
|
||||||
NAN_METHOD(OnBlocksReady);
|
NAN_METHOD(OnBlocksReady);
|
||||||
|
@ -30,4 +23,4 @@ NAN_METHOD(GetInfo);
|
||||||
NAN_METHOD(IsSpent);
|
NAN_METHOD(IsSpent);
|
||||||
NAN_METHOD(GetChainWork);
|
NAN_METHOD(GetChainWork);
|
||||||
NAN_METHOD(GetMempoolOutputs);
|
NAN_METHOD(GetMempoolOutputs);
|
||||||
|
NAN_METHOD(AddMempoolUncheckedTransaction);
|
||||||
|
|
Loading…
Reference in New Issue