From 5e745a7526c7edc817a4bac66244e43a40195d7c Mon Sep 17 00:00:00 2001 From: Jeff Garzik Date: Thu, 18 Jul 2013 16:53:47 -0400 Subject: [PATCH 1/2] Block: add header parsing. Begin new Deserialize module. --- Block.js | 22 ++++++++++++++++++++++ Deserialize.js | 8 ++++++++ 2 files changed, 30 insertions(+) create mode 100644 Deserialize.js diff --git a/Block.js b/Block.js index 85ff636..940aff9 100644 --- a/Block.js +++ b/Block.js @@ -5,6 +5,7 @@ function spec(b) { var Debug1 = b.Debug1 || function() {}; var Script = b.Script || require('./Script').class(); var Bignum = b.Bignum || require('bignum'); + var Binary = b.Binary || require('binary'); var Put = b.Put || require('bufferput'); var Step = b.Step || require('step'); var Transaction = b.Transaction || require('./Transaction').class(); @@ -47,6 +48,27 @@ function spec(b) { return put.buffer(); }; + Block.prototype.parseHeader = function parseHeader(buf) { + if (buf.length != 80) + throw new VerificationError('Block header length invalid'); + + var vars = Binary.parse(buf) + .word32lu('version') + .buffer('prev_hash', 32) + .buffer('merkle_root', 32) + .word32lu('timestamp') + .word32lu('bits') + .word32lu('nonce') + .vars; + + this.version = vars.version; + this.prev_hash = vars.prev_hash; + this.merkle_root = vars.merkle_root; + this.timestamp = vars.timestamp; + this.bits = vars.bits; + this.nonce = vars.nonce; + }; + Block.prototype.calcHash = function calcHash() { var header = this.getHeader(); diff --git a/Deserialize.js b/Deserialize.js new file mode 100644 index 0000000..a80d13e --- /dev/null +++ b/Deserialize.js @@ -0,0 +1,8 @@ + +exports.intFromCompact = function(c) +{ + var bytes = (c >> 24) & 0xff; + var v = (c & 0xffffff) << (8 * (bytes - 3)); + return v; +} + From 6ae356bf1f2a1880789ddba097a3f6556308e4c6 Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Thu, 18 Jul 2013 17:16:54 -0400 Subject: [PATCH 2/2] importAddress for commands list --- RpcClient.js | 1 + 1 file changed, 1 insertion(+) diff --git a/RpcClient.js b/RpcClient.js index 53bef8d..bdb8b78 100644 --- a/RpcClient.js +++ b/RpcClient.js @@ -61,6 +61,7 @@ function ClassSpec(b) { getTxOutSetInfo: '', getWork: '', help: '', + importAddress: 'str str bool', importPrivKey: 'str str bool', keypoolRefill: '', listAccounts: 'int',