remove traverse arg.
This commit is contained in:
parent
c4f204dfa8
commit
eeec6573ae
@ -380,13 +380,11 @@ Bitcoin.prototype.getBlockHeight = function(height, callback) {
|
|||||||
|
|
||||||
Bitcoin.prototype.getTransaction =
|
Bitcoin.prototype.getTransaction =
|
||||||
Bitcoin.prototype.getTx = function(txid, blockhash, callback) {
|
Bitcoin.prototype.getTx = function(txid, blockhash, callback) {
|
||||||
var traverse = true;
|
|
||||||
if (typeof txid === 'object' && txid) {
|
if (typeof txid === 'object' && txid) {
|
||||||
var options = txid;
|
var options = txid;
|
||||||
callback = blockhash;
|
callback = blockhash;
|
||||||
txid = options.txid || options.tx || options.txhash || options.id || options.hash;
|
txid = options.txid || options.tx || options.txhash || options.id || options.hash;
|
||||||
blockhash = options.blockhash || options.block;
|
blockhash = options.blockhash || options.block;
|
||||||
traverse = options.traverse !== false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof blockhash === 'function') {
|
if (typeof blockhash === 'function') {
|
||||||
@ -405,13 +403,13 @@ Bitcoin.prototype.getTx = function(txid, blockhash, callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return bitcoindjs.getTransaction(txid, blockhash, traverse, function(err, tx) {
|
return bitcoindjs.getTransaction(txid, blockhash, function(err, tx) {
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
return callback(null, bitcoin.tx(tx));
|
return callback(null, bitcoin.tx(tx));
|
||||||
});
|
});
|
||||||
|
|
||||||
if (blockhash && typeof blockhash === 'string') {
|
if (blockhash && typeof blockhash === 'string') {
|
||||||
return bitcoindjs.getTransaction(txid, blockhash, traverse, function(err, tx) {
|
return bitcoindjs.getTransaction(txid, blockhash, function(err, tx) {
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
if (tx.blockhash) {
|
if (tx.blockhash) {
|
||||||
bitcoin.db.set('tx-block/' + txid,
|
bitcoin.db.set('tx-block/' + txid,
|
||||||
@ -422,8 +420,7 @@ Bitcoin.prototype.getTx = function(txid, blockhash, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return bitcoin.db.get('tx-block/' + txid, function(err, block) {
|
return bitcoin.db.get('tx-block/' + txid, function(err, block) {
|
||||||
// Will traverse blockchain if no block - slow:
|
return bitcoinjs.getTransaction(txid, block ? block.hash : '', function(err, tx) {
|
||||||
return bitcoinjs.getTransaction(txid, block ? block.hash : '', traverse, function(err, tx) {
|
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
if (!block && tx.blockhash) {
|
if (!block && tx.blockhash) {
|
||||||
bitcoin.db.set('tx-block/' + txid,
|
bitcoin.db.set('tx-block/' + txid,
|
||||||
|
|||||||
@ -403,7 +403,7 @@ static int64_t
|
|||||||
SatoshiFromAmount(const CAmount& amount);
|
SatoshiFromAmount(const CAmount& amount);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
get_tx(uint256 txid, uint256& blockhash, const bool traverse, CTransaction& ctx);
|
get_tx(uint256 txid, uint256& blockhash, CTransaction& ctx);
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void
|
||||||
init(Handle<Object>);
|
init(Handle<Object>);
|
||||||
@ -460,7 +460,6 @@ struct async_tx_data {
|
|||||||
std::string err_msg;
|
std::string err_msg;
|
||||||
std::string txid;
|
std::string txid;
|
||||||
std::string blockhash;
|
std::string blockhash;
|
||||||
bool traverse;
|
|
||||||
CTransaction ctx;
|
CTransaction ctx;
|
||||||
Persistent<Function> callback;
|
Persistent<Function> callback;
|
||||||
};
|
};
|
||||||
@ -1117,23 +1116,14 @@ NAN_METHOD(GetTransaction) {
|
|||||||
if (args.Length() < 3
|
if (args.Length() < 3
|
||||||
|| !args[0]->IsString()
|
|| !args[0]->IsString()
|
||||||
|| !args[1]->IsString()
|
|| !args[1]->IsString()
|
||||||
|| (!args[2]->IsFunction() && !(args[2]->IsBoolean() && args[3]->IsFunction()))) {
|
|| !args[2]->IsFunction()) {
|
||||||
return NanThrowError(
|
return NanThrowError(
|
||||||
"Usage: bitcoindjs.getTransaction(txid, [blockhash], [traverse], callback)");
|
"Usage: bitcoindjs.getTransaction(txid, [blockhash], callback)");
|
||||||
}
|
}
|
||||||
|
|
||||||
String::Utf8Value txid_(args[0]->ToString());
|
String::Utf8Value txid_(args[0]->ToString());
|
||||||
String::Utf8Value blockhash_(args[1]->ToString());
|
String::Utf8Value blockhash_(args[1]->ToString());
|
||||||
|
Local<Function> callback = Local<Function>::Cast(args[2]);
|
||||||
bool traverse = true;
|
|
||||||
Local<Function> callback;
|
|
||||||
|
|
||||||
if (args[2]->IsBoolean()) {
|
|
||||||
traverse = args[2]->ToBoolean()->IsTrue();
|
|
||||||
callback = Local<Function>::Cast(args[3]);
|
|
||||||
} else {
|
|
||||||
callback = Local<Function>::Cast(args[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string txid = std::string(*txid_);
|
std::string txid = std::string(*txid_);
|
||||||
std::string blockhash = std::string(*blockhash_);
|
std::string blockhash = std::string(*blockhash_);
|
||||||
@ -1146,7 +1136,6 @@ NAN_METHOD(GetTransaction) {
|
|||||||
data->err_msg = std::string("");
|
data->err_msg = std::string("");
|
||||||
data->txid = txid;
|
data->txid = txid;
|
||||||
data->blockhash = blockhash;
|
data->blockhash = blockhash;
|
||||||
data->traverse = traverse;
|
|
||||||
data->callback = Persistent<Function>::New(callback);
|
data->callback = Persistent<Function>::New(callback);
|
||||||
|
|
||||||
uv_work_t *req = new uv_work_t();
|
uv_work_t *req = new uv_work_t();
|
||||||
@ -1169,8 +1158,12 @@ async_get_tx(uv_work_t *req) {
|
|||||||
uint256 blockhash(data->blockhash);
|
uint256 blockhash(data->blockhash);
|
||||||
CTransaction ctx;
|
CTransaction ctx;
|
||||||
|
|
||||||
//if (get_tx(hash, blockhash, data->traverse, ctx)) {
|
if (pwalletMain->mapWallet.count(hash)) {
|
||||||
if (get_tx(hash, blockhash, true, ctx)) {
|
const CWalletTx& wtx = pwalletMain->mapWallet[hash];
|
||||||
|
blockhash.SetHex(wtx.hashBlock.GetHex());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (get_tx(hash, blockhash, ctx)) {
|
||||||
data->ctx = ctx;
|
data->ctx = ctx;
|
||||||
data->blockhash = blockhash.GetHex();
|
data->blockhash = blockhash.GetHex();
|
||||||
} else {
|
} else {
|
||||||
@ -5846,10 +5839,10 @@ cblock_to_jsblock(const CBlock& cblock, CBlockIndex* cblock_index, Local<Object>
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
get_tx(uint256 txid, uint256& blockhash, const bool traverse, CTransaction& ctx) {
|
get_tx(uint256 txid, uint256& blockhash, CTransaction& ctx) {
|
||||||
if (GetTransaction(txid, ctx, blockhash, true)) {
|
if (GetTransaction(txid, ctx, blockhash, true)) {
|
||||||
return 1;
|
return 1;
|
||||||
} else if (traverse && blockhash != 0) {
|
} else if (blockhash != 0) {
|
||||||
CBlock block;
|
CBlock block;
|
||||||
CBlockIndex* pblockindex = mapBlockIndex[blockhash];
|
CBlockIndex* pblockindex = mapBlockIndex[blockhash];
|
||||||
if (ReadBlockFromDisk(block, pblockindex)) {
|
if (ReadBlockFromDisk(block, pblockindex)) {
|
||||||
@ -5904,7 +5897,7 @@ ctx_to_jstx(const CTransaction& ctx, uint256 blockhash, Local<Object> jstx) {
|
|||||||
|
|
||||||
Local<Object> jsprev = NanNew<Object>();
|
Local<Object> jsprev = NanNew<Object>();
|
||||||
CTransaction prev_tx;
|
CTransaction prev_tx;
|
||||||
//if (get_tx(txin.prevout.hash, blockhash, true, prev_tx)) {
|
//if (get_tx(txin.prevout.hash, blockhash, prev_tx)) {
|
||||||
if (GetTransaction(txin.prevout.hash, prev_tx, blockhash, true)) {
|
if (GetTransaction(txin.prevout.hash, prev_tx, blockhash, true)) {
|
||||||
CTxDestination from;
|
CTxDestination from;
|
||||||
CTxOut prev_out = prev_tx.vout[txin.prevout.n];
|
CTxOut prev_out = prev_tx.vout[txin.prevout.n];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user