From 698f44d3efa72e189849083d88f3847358008d70 Mon Sep 17 00:00:00 2001 From: James Sangalli Date: Sun, 2 Sep 2018 14:38:25 +0800 Subject: [PATCH 1/2] fix sample call pages --- .idea/btcrelay.iml | 12 + .idea/misc.xml | 12 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .idea/workspace.xml | 350 +++++++++++++++++++++++++++++ examples/btc-eth.html | 4 +- examples/sampleCall.html | 34 +-- examples/testnetSampleCall.html | 2 +- examples/testnetSampleRelayTx.html | 70 +++--- solidity/btcChainInterface.sol | 47 ++++ 10 files changed, 494 insertions(+), 51 deletions(-) create mode 100644 .idea/btcrelay.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 solidity/btcChainInterface.sol diff --git a/.idea/btcrelay.iml b/.idea/btcrelay.iml new file mode 100644 index 0000000..24643cc --- /dev/null +++ b/.idea/btcrelay.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..3d4de8e --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + false + + false + false + + + ApexVCS + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..b35fb65 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..74a5e7d --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,350 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + btc.blockr.io/api/v1/tx/raw/ + txHexText + web3 + grelaycont + gRelayContract + var rawTx + + + blockexplorer.com/api/tx/ + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + project + + + true + + + + DIRECTORY + + false + + + + + + + + + 1535865048683 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/btc-eth.html b/examples/btc-eth.html index d87573f..500aa99 100644 --- a/examples/btc-eth.html +++ b/examples/btc-eth.html @@ -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) diff --git a/examples/sampleCall.html b/examples/sampleCall.html index 17a9fcd..a4200a9 100644 --- a/examples/sampleCall.html +++ b/examples/sampleCall.html @@ -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() { @@ -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); + }); }) }) } diff --git a/examples/testnetSampleCall.html b/examples/testnetSampleCall.html index e48c7ef..c10da19 100644 --- a/examples/testnetSampleCall.html +++ b/examples/testnetSampleCall.html @@ -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); diff --git a/examples/testnetSampleRelayTx.html b/examples/testnetSampleRelayTx.html index 6e62bb1..6ddc1d4 100644 --- a/examples/testnetSampleRelayTx.html +++ b/examples/testnetSampleRelayTx.html @@ -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); + }) + }); }) - }) + }); }) } diff --git a/solidity/btcChainInterface.sol b/solidity/btcChainInterface.sol new file mode 100644 index 0000000..bf5dedc --- /dev/null +++ b/solidity/btcChainInterface.sol @@ -0,0 +1,47 @@ +pragma solidity ^0.4.17; +contract btcChainInterface +{ + + function m_saveAncestors(bytes32 blockHashArg, bytes32 hashPrevBlockArg); + + // # private (to prevent leeching) + // # returns 1 if 'txBlockHash' is in the main chain, ie not a fork + // # otherwise returns 0 + function priv_inMainChain__(bytes32 txBlockHash) private returns(bool); + + + // # private (to prevent leeching) + // # callers must ensure 2 things: + // # * blockHeight is greater than 0 (otherwise infinite loop since + // # minimum height is 1) + // # * blockHeight is less than the height of heaviestBlock, otherwise the + // # heaviestBlock is returned + function priv_fastGetBlockHash__(uint256 blockHeight) returns(bytes32); + + // # + // # macros + // # + + + // # a block's _ancestor storage slot contains 8 indexes into internalBlock, so + // # this macro returns the index that can be used to lookup the desired ancestor + // # eg. for combined usage, self.internalBlock[m_getAncestor(someBlock, 2)] will + // # return the block hash of someBlock's 3rd ancestor + function m_getAncestor(bytes32 blockHash, uint256 whichAncestor) returns(uint256); + + //# index should be 0 to 7, so this returns 1, 5, 25 ... 78125 + function m_getAncDepth(uint256 index) returns(uint256); + + // # write $int32 to memory at $addrLoc + // # This is useful for writing 32bit ints inside one 32 byte word + function m_mwrite32(int32 addrLoc, int32 int32Var); + + // # write $int24 to memory at $addrLoc + // # This is useful for writing 24bit ints inside one 32 byte word + function m_mwrite24(int24 addrLoc, int24 varInt24); + + // # write $int16 to memory at $addrLoc + // # This is useful for writing 16bit ints inside one 32 byte word + function m_mwrite16(int16 addrLoc, int16 varInt16); + +} From d83812e8150b09601aabaf5be11cab805e430fe1 Mon Sep 17 00:00:00 2001 From: James Sangalli Date: Sun, 2 Sep 2018 14:39:17 +0800 Subject: [PATCH 2/2] remove irrelevant files and dir --- .idea/btcrelay.iml | 12 -- .idea/misc.xml | 12 -- .idea/modules.xml | 8 - .idea/vcs.xml | 6 - .idea/workspace.xml | 350 --------------------------------- solidity/btcChainInterface.sol | 47 ----- 6 files changed, 435 deletions(-) delete mode 100644 .idea/btcrelay.iml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml delete mode 100644 .idea/workspace.xml delete mode 100644 solidity/btcChainInterface.sol diff --git a/.idea/btcrelay.iml b/.idea/btcrelay.iml deleted file mode 100644 index 24643cc..0000000 --- a/.idea/btcrelay.iml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 3d4de8e..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - false - - false - false - - - ApexVCS - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index b35fb65..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index 74a5e7d..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,350 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - btc.blockr.io/api/v1/tx/raw/ - txHexText - web3 - grelaycont - gRelayContract - var rawTx - - - blockexplorer.com/api/tx/ - - - - - - - - - - - true - DEFINITION_ORDER - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - project - - - true - - - - DIRECTORY - - false - - - - - - - - - 1535865048683 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/solidity/btcChainInterface.sol b/solidity/btcChainInterface.sol deleted file mode 100644 index bf5dedc..0000000 --- a/solidity/btcChainInterface.sol +++ /dev/null @@ -1,47 +0,0 @@ -pragma solidity ^0.4.17; -contract btcChainInterface -{ - - function m_saveAncestors(bytes32 blockHashArg, bytes32 hashPrevBlockArg); - - // # private (to prevent leeching) - // # returns 1 if 'txBlockHash' is in the main chain, ie not a fork - // # otherwise returns 0 - function priv_inMainChain__(bytes32 txBlockHash) private returns(bool); - - - // # private (to prevent leeching) - // # callers must ensure 2 things: - // # * blockHeight is greater than 0 (otherwise infinite loop since - // # minimum height is 1) - // # * blockHeight is less than the height of heaviestBlock, otherwise the - // # heaviestBlock is returned - function priv_fastGetBlockHash__(uint256 blockHeight) returns(bytes32); - - // # - // # macros - // # - - - // # a block's _ancestor storage slot contains 8 indexes into internalBlock, so - // # this macro returns the index that can be used to lookup the desired ancestor - // # eg. for combined usage, self.internalBlock[m_getAncestor(someBlock, 2)] will - // # return the block hash of someBlock's 3rd ancestor - function m_getAncestor(bytes32 blockHash, uint256 whichAncestor) returns(uint256); - - //# index should be 0 to 7, so this returns 1, 5, 25 ... 78125 - function m_getAncDepth(uint256 index) returns(uint256); - - // # write $int32 to memory at $addrLoc - // # This is useful for writing 32bit ints inside one 32 byte word - function m_mwrite32(int32 addrLoc, int32 int32Var); - - // # write $int24 to memory at $addrLoc - // # This is useful for writing 24bit ints inside one 32 byte word - function m_mwrite24(int24 addrLoc, int24 varInt24); - - // # write $int16 to memory at $addrLoc - // # This is useful for writing 16bit ints inside one 32 byte word - function m_mwrite16(int16 addrLoc, int16 varInt16); - -}