-
Notifications
You must be signed in to change notification settings - Fork 3
/
spv.js
72 lines (49 loc) · 1.35 KB
/
spv.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var params = require('webcoin-bitcoin').blockchain;
console.log(params.genesisHeader)
var levelup = require('level');
var db = levelup('bitcoin.chain', { db: require('memdown') });
var Blockchain = require('blockchain-spv');
var chain = new Blockchain(params.genesisHeader , db);
var u = require('bitcoin-util');
var newheader = [{
version: 2,
prevHash: u.toHash('4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b'),
merkleRoot: u.toHash('37f752dccde0e359ce5b028fed86a4e2f937e2d3091d99f795096198cbf5c67c'),
timestamp: 1434257763,
bits: 0x18162043,
nonce: 1801335478
},
{
version: 3,
prevHash: u.toHash('37f752dccde0e359ce5b028fed86a4e2f937e2d3091d99f795096198cbf5c67c'),
merkleRoot: u.toHash('36f752dccde0e359ce5b028fed86a4e2f937e2d3091d99f795096198cbf5c67c'),
timestamp: 1434257987,
bits: 0x18162042,
nonce: 1801367879
}
]
for(var head in newheader){
chain.addHeaders(head,(err, head)=>{
if(err){
return cb(err)
}
});
}
for(var head in newheader){
db.get(head,function(err,value){
if(err){
return cb(err)
}
})
}
//returns a stream that takes in the array of headers and add them to the chain
//console.log(params.genesisHeader);
chain.on('ready',function(err,chain){
if(err){
return cb(err);
}
else{
console.log(chain);
console.log(db);
}
})