Skip to content

Commit c451688

Browse files
author
micro-machine
committed
scrypt and pos updates
(some commits from sdcdev/insight)
1 parent 915566f commit c451688

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

lib/Block.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,20 @@ Block.prototype.parse = function parse(parser, headerOnly) {
7373
tx.parse(parser);
7474
this.txs.push(tx);
7575
}
76+
lastByte = parser.buffer(1);
77+
78+
//log.info('lastByte ', lastByte);
79+
if (lastByte.length > 0 && lastByte.readUInt8(0) > 0)
80+
{
81+
this.vchBlockSig = parser.buffer(lastByte.readUInt8(0));
82+
//log.info('this.vchBlockSig ' + this.vchBlockSig.toString('hex'));
83+
}
7684
};
7785

7886
Block.prototype.calcHash = function calcHash() {
7987
var header = this.getHeader();
8088

81-
return util.twoSha256(header);
89+
return util.scrypt(header);
8290
};
8391

8492
Block.prototype.checkHash = function checkHash() {

lib/Transaction.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,9 @@ Transaction.prototype.isStandard = function isStandard() {
151151
Transaction.prototype.serialize = function serialize() {
152152
var bufs = [];
153153

154-
var buf = new Buffer(4);
154+
var buf = new Buffer(8);
155155
buf.writeUInt32LE(this.version, 0);
156+
buf.writeUInt32LE(this.nTime, 4);
156157
bufs.push(buf);
157158

158159
bufs.push(util.varIntBuf(this.ins.length));
@@ -165,7 +166,7 @@ Transaction.prototype.serialize = function serialize() {
165166
bufs.push(txout.serialize());
166167
});
167168

168-
var buf = new Buffer(4);
169+
buf = new Buffer(4);
169170
buf.writeUInt32LE(this.lock_time, 0);
170171
bufs.push(buf);
171172

@@ -539,6 +540,8 @@ Transaction.prototype.parse = function(parser) {
539540
var i, sLen, startPos = parser.pos;
540541

541542
this.version = parser.word32le();
543+
544+
this.nTime = parser.word32le();
542545

543546
var txinCount = parser.varInt();
544547

package.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@
8686
"gulp-concat": "~2.2.0",
8787
"gulp": "~3.8.2",
8888
"preconditions": "^1.0.7",
89-
"asn1.js": "0.4.1"
89+
"asn1.js": "0.4.1",
90+
"scryptsy": "0.2.x"
9091
},
9192
"testling": {
9293
"harness": "mocha-bdd",
@@ -114,6 +115,13 @@
114115
"engines": {
115116
"node": ">=0.10"
116117
},
118+
"readmeFilename": "README.md",
119+
"gypfile": true,
120+
"bugs": {
121+
"url": "https://github.com/bitpay/bitcore/issues"
122+
},
123+
"homepage": "https://github.com/bitpay/bitcore",
124+
117125
"devDependencies": {
118126
"sinon": "^1.10.3",
119127
"express": "4.6.1",

util/util.js

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var bignum = require('bignum');
33
var Binary = require('binary');
44
var Put = require('bufferput');
55
var buffertools = require('buffertools');
6+
var node_scrypt = require('scryptsy').scrypt;
67
var sjcl = require('../lib/sjcl');
78
if (process.browser) {
89
var hashjs = require('hash.js');
@@ -58,6 +59,11 @@ var sha256ripe160 = exports.sha256ripe160 = function(data) {
5859
return ripe160(sha256(data));
5960
};
6061

62+
var scrypt = exports.scrypt = function(data) {
63+
// scrypt(passwd, salt, N, r, p, dkLen)
64+
return node_scrypt(data, data, 1024, 1, 1, 32);
65+
};
66+
6167
/**
6268
* Format a block hash like the official client does.
6369
*/

0 commit comments

Comments
 (0)