Skip to content
This repository was archived by the owner on Feb 11, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/btc-eth.html
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@

var urlJsonTx;
if (gBtcTestnet) {
urlJsonTx = "https://tbtc.blockr.io/api/v1/tx/raw/" + txid;
urlJsonTx = "https://testnet.blockexplorer.com/api/rawtx/" + txid;
}
else {
urlJsonTx = "https://btc.blockr.io/api/v1/tx/raw/" + txid;
urlJsonTx = "https://blockexplorer.com/api/tx/" + txid;
}
$.getJSON(urlJsonTx, function(data) {
console.log('@@@ data: ', data)
Expand Down
34 changes: 18 additions & 16 deletions examples/sampleCall.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@
// gFeeVerifyFinney is transferred! coinbase must have it or verifyTx fails
var feeWei = web3.toWei(gFeeVerifyFinney, 'finney');
var objParam = { from: '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae', value: feeWei, gas: 3000000 };
var res = gRelayContract.verifyTx.call(txBytes, txIndex, merkleSibling, txBlockHash, objParam);

document.getElementById('result').innerText = res.toString(16);
gRelayContract.verifyTx.call(txBytes, txIndex, merkleSibling, txBlockHash, objParam, function(err, data) {
console.log("HAHAHA" + data)
document.getElementById('result').innerText = data.toString(16);
});
}

function callContract() {
Expand All @@ -84,30 +85,31 @@
// includes sample of using the bitcoin-proof module
function getTxInfo() {
var txid = $('#transHex').val();
var urlJsonTx = "https://btc.blockr.io/api/v1/tx/raw/" + txid;
var urlJsonTx = "https://blockexplorer.com/api/tx/" + txid;
$.getJSON(urlJsonTx, function(data) {
$('#txHexText').val(data.data.tx.hex);

var blockNum = data.data.tx.blockhash;
var blockInfoUrl = "http://btc.blockr.io/api/v1/block/raw/"+blockNum;
$('#txHexText').val(data.txid);
var blockHash = data.blockhash;
var blockInfoUrl = "https://blockexplorer.com/api/block/" + blockHash;
$.getJSON(blockInfoUrl, function(res) {
gBlockHashOfTx = res.data.hash;
$('#txBlockHash').text(gBlockHashOfTx)
gBlockHashOfTx = blockHash;
$('#txBlockHash').text(gBlockHashOfTx);

var txIndex;
for (var key in res.data.tx) {
if (res.data.tx[key] == txid) {
for (var key in res.tx) {
if (res.tx[key] == txid) {
txIndex = key;
break;
}
}

gMerkleProof = btcproof.getProof(res.data.tx, txIndex);
console.log('merkle proof: ', gMerkleProof)
gMerkleProof = btcproof.getProof(res.tx, txIndex);
console.log('merkle proof: ', gMerkleProof);
$('#mProof').val(JSON.stringify(gMerkleProof));

gFeeVerifyFinney = web3.fromWei(gRelayContract.getFeeAmount.call('0x'+gBlockHashOfTx), 'finney');
$('#feeVerifyTx').text(gFeeVerifyFinney);
gRelayContract.getFeeAmount.call(('0x' + gBlockHashOfTx), 'finney', function(err, data) {
gFeeVerifyFinney = web3.fromWei(data);
$('#feeVerifyTx').text(gFeeVerifyFinney);
});
})
})
}
Expand Down
2 changes: 1 addition & 1 deletion examples/testnetSampleCall.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
// This function also shows how to use the bitcoin-proof module.
function getTxInfo() {
var txid = $('#transHex').val();
var urlJsonTx = "https://btc.blockr.io/api/v1/tx/raw/" + txid;
var urlJsonTx = "https://blockexplorer.com/api/tx/" + txid;
$.getJSON(urlJsonTx, function(data) {
$('#txHexText').val(data.data.tx.hex);

Expand Down
70 changes: 38 additions & 32 deletions examples/testnetSampleRelayTx.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,44 +96,50 @@
// This function also shows how to use the bitcoin-proof module.
function getTxInfo() {
var txid = $('#transHex').val();
var urlJsonTx = "https://btc.blockr.io/api/v1/tx/raw/" + txid;
var urlJsonTx = "https://blockexplorer.com/api/rawtx/" + txid;
$.getJSON(urlJsonTx, function(data) {
var rawTx = data.data.tx.hex;
console.log("here is the data" + JSON.stringify(data));
var rawTx = data.rawtx;
$('#txHexText').val(rawTx);

var urlGetBlockInfo = "https://blockexplorer.com/api/tx/" + txid;
// A separate call is needed because the transaction index, the position
// of the transaction in the block, is needed to be able to compute the
// Merkle proof
var blockNum = data.data.tx.blockhash;
var blockInfoUrl = "//btc.blockr.io/api/v1/block/raw/"+blockNum;
$.getJSON(blockInfoUrl, function(res) {
gBlockHashOfTx = res.data.hash;
$('#txBlockHash').text(gBlockHashOfTx)

var txIndex;
for (var key in res.data.tx) {
if (res.data.tx[key] == txid) {
txIndex = key;
break;
}
}

// Proof can now be computed from the raw transaction and
// transaction index
gMerkleProof = btcproof.getProof(res.data.tx, txIndex);
console.log('merkle proof: ', gMerkleProof)
$('#mProof').val(JSON.stringify(gMerkleProof));

gRelayContract.getFeeAmount.call('0x'+gBlockHashOfTx, function(err, feeWei) {
if (err) {
console.log('@@@ getFeeAmount error');
return;
}

gFeeVerifyFinney = web3.fromWei(feeWei, 'finney');
$('#feeVerifyTx').text(gFeeVerifyFinney);
//TODO this is a lot of api calls
$.getJSON(urlGetBlockInfo, function(data) {
var blockNum = data.blockheight;
var blockHashUrl = "https://blockexplorer.com/api/block-index/" + blockNum;
$.getJSON(blockHashUrl, function(res) {
gBlockHashOfTx = res.blockHash;
$('#txBlockHash').text(gBlockHashOfTx);
var blockInfoURL = "https://blockexplorer.com/api/block/" + gBlockHashOfTx;
$.getJSON(blockInfoURL, function(res) {
var txIndex;
for (var key in res.tx) {
if (res.tx[key] == txid) {
txIndex = key;
break;
}
}

// Proof can now be computed from the raw transaction and
// transaction index
gMerkleProof = btcproof.getProof(res.tx, txIndex);
console.log('merkle proof: ', gMerkleProof);
$('#mProof').val(JSON.stringify(gMerkleProof));

gRelayContract.getFeeAmount.call('0x' + gBlockHashOfTx, function(err, feeWei) {
if (err) {
console.log('@@@ getFeeAmount error');
return;
}

gFeeVerifyFinney = web3.fromWei(feeWei, 'finney');
$('#feeVerifyTx').text(gFeeVerifyFinney);
})
});
})
})
});
})
}

Expand Down