Merge branch 'master' of github.com:gasteve/node-libcoin

This commit is contained in:
Stephen Pair 2013-07-18 21:24:36 -04:00
commit 415ba958c6
3 changed files with 31 additions and 0 deletions

View File

@ -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();

8
Deserialize.js Normal file
View File

@ -0,0 +1,8 @@
exports.intFromCompact = function(c)
{
var bytes = (c >> 24) & 0xff;
var v = (c & 0xffffff) << (8 * (bytes - 3));
return v;
}

View File

@ -62,6 +62,7 @@ function ClassSpec(b) {
getTxOutSetInfo: '',
getWork: '',
help: '',
importAddress: 'str str bool',
importPrivKey: 'str str bool',
keypoolRefill: '',
listAccounts: 'int',