Last active
August 29, 2015 14:05
-
-
Save ryandotsmith/0917fcf650b92cd4d493 to your computer and use it in GitHub Desktop.
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)