Demonstrate transaction confidence using Chain.com's Bitcoin API
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
var chain = require('chain-node'); | |
var confidant = function(txid, retries, cb) { | |
chain.getTransaction(txid, function(err, resp) { | |
if(resp.propagation_level > 0.9) { | |
cb(resp.propagation_level); | |
} else { | |
if(retries > 60) { | |
cb(null); | |
} else { | |
setTimeout(function() { | |
confidant(txid, retries + 1, cb); | |
}, 500); | |
} | |
} | |
}); | |
} | |
chain.sendTransaction('0100000001ec...'), function(err, resp) { | |
var startTime = new Date(); | |
confidant(resp.hash, 0, function(level) { | |
if(level) { | |
var ttc = startTime - new Date(); | |
console.log("Chain reports propagation level: " + level); | |
console.log("Time to confidence level: " + ttc); | |
} else { | |
console.log("Chain was unable to report high propagation level."); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
19 sould be
chain.sendTransaction('0100000001ec...', function(err, resp) {
it has one extra)