diff --git a/Block.js b/Block.js index 85ff6361e..940aff97c 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 000000000..a80d13e5d --- /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; +} + diff --git a/RpcClient.js b/RpcClient.js index 625611726..f9d5b1b8f 100644 --- a/RpcClient.js +++ b/RpcClient.js @@ -62,6 +62,7 @@ function ClassSpec(b) { getTxOutSetInfo: '', getWork: '', help: '', + importAddress: 'str str bool', importPrivKey: 'str str bool', keypoolRefill: '', listAccounts: 'int',