Skip to content

Instantly share code, notes, and snippets.

@ryandotsmith
Last active August 29, 2015 14:05
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ryandotsmith/0917fcf650b92cd4d493 to your computer and use it in GitHub Desktop.
Demonstrate transaction confidence using Chain.com's Bitcoin API
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.");
}
});
});
@mishak87
Copy link

19 sould be chain.sendTransaction('0100000001ec...', function(err, resp) { it has one extra )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment