refactor verification.
This commit is contained in:
parent
e2a8b95651
commit
ecadec5878
@ -321,11 +321,12 @@ function Block(data) {
|
|||||||
self[key] = data[key];
|
self[key] = data[key];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.toHex();
|
||||||
}
|
}
|
||||||
|
|
||||||
Block.prototype.verify = function() {
|
Block.prototype.verify = function() {
|
||||||
return this._verified = this._verified
|
return this.verified = this.verified || bitcoindjs.verifyBlock(this);
|
||||||
|| bitcoindjs.verifyBlock(this.toHex());
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Block.prototype.toBinary = function() {
|
Block.prototype.toBinary = function() {
|
||||||
@ -394,7 +395,7 @@ Block.toBinary = function(block, type) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Block.prototype.toHex = function() {
|
Block.prototype.toHex = function() {
|
||||||
return this._hex = this._hex || Block.toHex(this);
|
return this.hex = this.hex || Block.toHex(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
Block.toHex = function(block) {
|
Block.toHex = function(block) {
|
||||||
@ -443,8 +444,7 @@ function Transaction(data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Transaction.prototype.verify = function() {
|
Transaction.prototype.verify = function() {
|
||||||
return this._verified = this._verified
|
return this.verified = this.verified || bitcoindjs.verifyTransaction(this);
|
||||||
|| bitcoindjs.verifyTransaction(this.toHex());
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Transaction.prototype.getSerializeSize = function() {
|
Transaction.prototype.getSerializeSize = function() {
|
||||||
|
|||||||
@ -1093,16 +1093,18 @@ async_broadcast_tx_after(uv_work_t *req) {
|
|||||||
NAN_METHOD(VerifyBlock) {
|
NAN_METHOD(VerifyBlock) {
|
||||||
NanScope();
|
NanScope();
|
||||||
|
|
||||||
if (args.Length() < 1 || !args[0]->IsString()) {
|
if (args.Length() < 1 || !args[0]->IsObject()) {
|
||||||
return NanThrowError(
|
return NanThrowError(
|
||||||
"Usage: bitcoindjs.verifyBlock(blockHex)");
|
"Usage: bitcoindjs.verifyBlock(block)");
|
||||||
}
|
}
|
||||||
|
|
||||||
String::Utf8Value blockHex_(args[0]->ToString());
|
Local<Object> js_block = Local<Object>::Cast(args[0]);
|
||||||
std::string blockHex = std::string(*blockHex_);
|
|
||||||
|
String::Utf8Value block_hex_(js_block->Get(NanNew<String>("hex"))->ToString());
|
||||||
|
std::string block_hex = std::string(*block_hex_);
|
||||||
|
|
||||||
CBlock block;
|
CBlock block;
|
||||||
CDataStream ssData(ParseHex(blockHex), SER_NETWORK, PROTOCOL_VERSION);
|
CDataStream ssData(ParseHex(block_hex), SER_NETWORK, PROTOCOL_VERSION);
|
||||||
ssData >> block;
|
ssData >> block;
|
||||||
|
|
||||||
CValidationState state;
|
CValidationState state;
|
||||||
@ -1118,16 +1120,18 @@ NAN_METHOD(VerifyBlock) {
|
|||||||
NAN_METHOD(VerifyTransaction) {
|
NAN_METHOD(VerifyTransaction) {
|
||||||
NanScope();
|
NanScope();
|
||||||
|
|
||||||
if (args.Length() < 1 || !args[0]->IsString()) {
|
if (args.Length() < 1 || !args[0]->IsObject()) {
|
||||||
return NanThrowError(
|
return NanThrowError(
|
||||||
"Usage: bitcoindjs.verifyTransaction(txHex)");
|
"Usage: bitcoindjs.verifyTransaction(tx)");
|
||||||
}
|
}
|
||||||
|
|
||||||
String::Utf8Value txHex_(args[0]->ToString());
|
Local<Object> js_tx = Local<Object>::Cast(args[0]);
|
||||||
std::string txHex = std::string(*txHex_);
|
|
||||||
|
String::Utf8Value tx_hex_(js_tx->Get(NanNew<String>("hex"))->ToString());
|
||||||
|
std::string tx_hex = std::string(*tx_hex_);
|
||||||
|
|
||||||
CTransaction tx;
|
CTransaction tx;
|
||||||
CDataStream ssData(ParseHex(txHex), SER_NETWORK, PROTOCOL_VERSION);
|
CDataStream ssData(ParseHex(tx_hex), SER_NETWORK, PROTOCOL_VERSION);
|
||||||
ssData >> tx;
|
ssData >> tx;
|
||||||
|
|
||||||
CValidationState state;
|
CValidationState state;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user