Skip to content

Instantly share code, notes, and snippets.

@williamcotton
Created June 17, 2015 18:51
Show Gist options
  • Save williamcotton/a343c94c89658823bd0c to your computer and use it in GitHub Desktop.
Save williamcotton/a343c94c89658823bd0c to your computer and use it in GitHub Desktop.
var blockcast = require("blockcast");
document.getElementById("scan-address").addEventListener("click", function(event) {
getTransaction = function(txHash, callback) {
xhr("https://www.blockai.com/chain/testnet/tx/" + txHash, function(err, res, body) {
var rawTx = JSON.parse(body);
var rawOutputs = rawTx.outputs;
var rawInputs = rawTx.inputs;
var outputs = [];
rawOutputs.forEach(function(rawOutput) {
outputs.push({
scriptPubKey: rawOutput.script_hex,
nextTxHash: rawOutput.spending_transaction
});
});
var inputs = [];
rawInputs.forEach(function(rawInput) {
inputs.push({
address: rawInput.addresses[0]
});
});
var transaction = {
inputs: inputs,
outputs: outputs
}
callback(err, transaction);
});
}
xhr("https://www.blockai.com/chain/testnet/addresses/" + address, function(err, res, body) {
var data = JSON.parse(body);
var transactions = data.transactions;
var openPublishDocuments = [];
transactions.forEach(function(tx) {
blockcast.scanSingle({
txHash: tx.hash,
getTransaction: getTransaction
}, function(err, message) {
if (!message) {
return;
}
var data = JSON.parse(message);
if (!data) {
return;
}
if (data.op == "r") {
var openPublishDocJSON = JSON.stringify(data, null, 4);
document.getElementById("open-publish-transactions").innerHTML = document.getElementById("open-publish-transactions").innerHTML + "\n\n" + openPublishDocJSON;
}
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment