VerifyTransaction
This commit is contained in:
parent
41c0cb5a4e
commit
e2a8b95651
@ -324,7 +324,8 @@ function Block(data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Block.prototype.verify = function() {
|
Block.prototype.verify = function() {
|
||||||
return this._verified = this._verified || bitcoindjs.verifyBlock(this.toHex());
|
return this._verified = this._verified
|
||||||
|
|| bitcoindjs.verifyBlock(this.toHex());
|
||||||
};
|
};
|
||||||
|
|
||||||
Block.prototype.toBinary = function() {
|
Block.prototype.toBinary = function() {
|
||||||
@ -441,6 +442,11 @@ function Transaction(data) {
|
|||||||
this.toHex();
|
this.toHex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Transaction.prototype.verify = function() {
|
||||||
|
return this._verified = this._verified
|
||||||
|
|| bitcoindjs.verifyTransaction(this.toHex());
|
||||||
|
};
|
||||||
|
|
||||||
Transaction.prototype.getSerializeSize = function() {
|
Transaction.prototype.getSerializeSize = function() {
|
||||||
;
|
;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -127,6 +127,7 @@ NAN_METHOD(PollBlocks);
|
|||||||
NAN_METHOD(PollMempool);
|
NAN_METHOD(PollMempool);
|
||||||
NAN_METHOD(BroadcastTx);
|
NAN_METHOD(BroadcastTx);
|
||||||
NAN_METHOD(VerifyBlock);
|
NAN_METHOD(VerifyBlock);
|
||||||
|
NAN_METHOD(VerifyTransaction);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
async_start_node_work(uv_work_t *req);
|
async_start_node_work(uv_work_t *req);
|
||||||
@ -1102,7 +1103,6 @@ NAN_METHOD(VerifyBlock) {
|
|||||||
|
|
||||||
CBlock block;
|
CBlock block;
|
||||||
CDataStream ssData(ParseHex(blockHex), SER_NETWORK, PROTOCOL_VERSION);
|
CDataStream ssData(ParseHex(blockHex), SER_NETWORK, PROTOCOL_VERSION);
|
||||||
CTransaction tx;
|
|
||||||
ssData >> block;
|
ssData >> block;
|
||||||
|
|
||||||
CValidationState state;
|
CValidationState state;
|
||||||
@ -1111,6 +1111,34 @@ NAN_METHOD(VerifyBlock) {
|
|||||||
NanReturnValue(NanNew<Boolean>(valid));
|
NanReturnValue(NanNew<Boolean>(valid));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VerifyTransaction
|
||||||
|
*/
|
||||||
|
|
||||||
|
NAN_METHOD(VerifyTransaction) {
|
||||||
|
NanScope();
|
||||||
|
|
||||||
|
if (args.Length() < 1 || !args[0]->IsString()) {
|
||||||
|
return NanThrowError(
|
||||||
|
"Usage: bitcoindjs.verifyTransaction(txHex)");
|
||||||
|
}
|
||||||
|
|
||||||
|
String::Utf8Value txHex_(args[0]->ToString());
|
||||||
|
std::string txHex = std::string(*txHex_);
|
||||||
|
|
||||||
|
CTransaction tx;
|
||||||
|
CDataStream ssData(ParseHex(txHex), SER_NETWORK, PROTOCOL_VERSION);
|
||||||
|
ssData >> tx;
|
||||||
|
|
||||||
|
CValidationState state;
|
||||||
|
bool valid = CheckTransaction(tx, state);
|
||||||
|
|
||||||
|
string reason;
|
||||||
|
bool standard = IsStandardTx(tx, reason);
|
||||||
|
|
||||||
|
NanReturnValue(NanNew<Boolean>(valid && standard));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Conversions
|
* Conversions
|
||||||
*/
|
*/
|
||||||
@ -1343,6 +1371,7 @@ init(Handle<Object> target) {
|
|||||||
NODE_SET_METHOD(target, "pollMempool", PollMempool);
|
NODE_SET_METHOD(target, "pollMempool", PollMempool);
|
||||||
NODE_SET_METHOD(target, "broadcastTx", BroadcastTx);
|
NODE_SET_METHOD(target, "broadcastTx", BroadcastTx);
|
||||||
NODE_SET_METHOD(target, "verifyBlock", VerifyBlock);
|
NODE_SET_METHOD(target, "verifyBlock", VerifyBlock);
|
||||||
|
NODE_SET_METHOD(target, "verifyTransaction", VerifyTransaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
NODE_MODULE(bitcoindjs, init)
|
NODE_MODULE(bitcoindjs, init)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user