-
-
Save Alex-Werner/06a196d880116d506c4d919d2cf894bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
// import blockchain parameters for Dash | |
var params = require('webcoin-dash').blockchain | |
var levelup = require('levelup'); | |
// create a LevelUp database where the block data should be stored | |
var db = levelup('dash.chain', { db: require('memdown') }) | |
var DBH = require('dash-blockchain-helpers'); | |
var dbh = new DBH({ | |
insightAPI_URI:"http://192.168.0.19:3001/insight-api-dash" | |
}); | |
// create blockchain | |
var Blockchain = require('./index.js');//replace with blockchain-spv-dash | |
var chain = new Blockchain(params, db) | |
// wait for the blockchain to be ready | |
chain.on('ready', async function () { | |
console.log('chain is ready'); | |
//1) GET LAST HASH | |
let tip = chain.getTip(); | |
console.log('\n'); | |
console.log('---tip from webcoin-dash).blockchain'); | |
console.log(tip); | |
console.log('----reversed and tohexed string'); | |
console.log((reverse(tip.hash).toString('hex'))); | |
function reverse (src) { | |
var buffer = new Buffer(src.length) | |
for (var i = 0, j = src.length - 1; i <= j; ++i, --j) { | |
buffer[i] = src[j] | |
buffer[j] = src[i] | |
} | |
return buffer | |
} | |
let headers = (await dbh.retrieveBlockHeaders(0,1)).headers; | |
//hash must be buffer | |
console.log('\n'); | |
console.log('----data from block0') | |
headers = headers.filter(function(_h){ | |
// console.log(reverse(new Buffer("e0028eb9648db56b1ac77cf090b99048a8007e2bb64b68f092c03c7f56a662c7",'hex'))); | |
_h.hash = new Buffer(_h.hash, "hex"); | |
if(_h.hasOwnProperty('prevHash')) | |
_h.prevHash = new Buffer(_h.prevHash, 'hex'); | |
if(_h.hasOwnProperty('nextHash')) | |
_h.nextHash = new Buffer(_h.nextHash, 'hex'); | |
_h.chainWork = new Buffer(_h.chainWork, 'hex'); | |
_h.merkleRoot = new Buffer(_h.merkleRoot, 'hex'); | |
return _h; | |
}) | |
console.log(headers); | |
/*chain.addHeaders(headers, function(err, header){ | |
console.log(err, header); | |
console.log(chain.getTip()); | |
});*/ | |
//chain.getBlockAtHeight(0, function(err, block){ | |
// console.log('block', block); | |
//}) | |
// use the blockchain | |
}) | |
process.on('unhandledRejection',(e)=>{console.log(e);}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment