Skip to content

Instantly share code, notes, and snippets.

@0xAshish
Created May 17, 2019 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xAshish/da7dd0d57885fdcd8f8e296e4f669a81 to your computer and use it in GitHub Desktop.
Save 0xAshish/da7dd0d57885fdcd8f8e296e4f669a81 to your computer and use it in GitHub Desktop.
import 'isomorphic-fetch'
import Web3 from 'web3'
import utils from 'ethereumjs-util'
import queryString from 'query-string'
import Trie from 'merkle-patricia-tree'
import EthereumTx from 'ethereumjs-tx'
import EthereumBlock from 'ethereumjs-block/from-rpc'
import {
getTxBytes,
getReceiptBytes,
getTxProof,
getReceiptProof,
verifyTxProof,
verifyReceiptProof,
verifyHeaderProof,
} from './helpers/proofs'
import { getHeaders, getBlockHeader } from './helpers/blocks'
import MerkleTree from './helpers/merkle-tree'
import RootChainArtifacts from '../artifacts/RootChain'
import ChildERC20Artifacts from '../artifacts/ChildERC20'
import ChildERC721Artifacts from '../artifacts/ChildERC721'
import StandardTokenArtifacts from '../artifacts/StandardToken'
import WithdrawManagerArtifacts from '../artifacts/WithdrawManager'
import DepositManagerArtifacts from '../artifacts/DepositManager'
const rlp = utils.rlp
let yo = async function() {
let web3 = new Web3('https://ropsten.infura.io/matic')
let web3Child = new Web3('https://testnet2.matic.network')
let withdrawManager = new web3.eth.Contract(
WithdrawManagerArtifacts.abi,
'0x4ef2b60cdd4611fa0bc815792acc14de4c158d22'
)
const block = 53770
const withdrawBlock1 = await web3Child.eth.getBlock(block, true)
console.log(withdrawBlock1)
const transactionHash =
'0x8458a6e9e7b17bd6d7f5f7719089412066883c86b39a557b12e2ca32c7e9d743'
const blockHash =
'0x86310d542defe3906f3493826df3a78bd93a7b7244a29c208617dd99e75bf85c'
const withdraw = await web3Child.eth.getTransaction(transactionHash)
// const withdrawBlock = await web3Child.eth.getBlock(blockHash, true)
const withdrawReceipt = await web3Child.eth.getTransactionReceipt(
transactionHash
)
console.log(withdrawReceipt)
// const headers = await getHeaders(39680, 39935, web3Child)
// const tree = new MerkleTree(headers)
// const headerRoot = utils.bufferToHex(tree.getRoot())
// console.log(headerRoot)
// const headerNumber = 1300000
// // set header block (mocking header block)
// // await rootChain.setHeaderBlock(
// // headerNumber,
// // headerRoot,
// // start,
// // end,
// // withdrawBlock.timestamp
// // )
// const blockHeader = getBlockHeader(withdrawBlock)
// const headerProof = await tree.getProof(blockHeader)
// // tree.verify(
// // blockHeader,
// // withdrawBlock.number - 52480,
// // tree.getRoot(),
// // headerProof0x91aad8a4d3691e7cde2491530e3a545be3b94ca76ee9a9cedddc54aa2ff25711
// // )
// // console.log(ff)
// // validate tx proof
// const txProof = await getTxProof(withdraw, withdrawBlock)
// console.log('blah')
// // console.log(txProof)
// verifyTxProof(txProof)
// // validate receipt proof
// const receiptProof = await getReceiptProof(
// withdrawReceipt,
// withdrawBlock,
// web3Child
// )
// verifyReceiptProof(receiptProof)
// console.log([
// headerNumber, // header block
// utils.bufferToHex(Buffer.concat(headerProof)), // header proof
// withdrawBlock.number, // block number
// withdrawBlock.timestamp, // block timestamp
// utils.bufferToHex(withdrawBlock.transactionsRoot), // tx root
// utils.bufferToHex(withdrawBlock.receiptsRoot), // tx root
// utils.bufferToHex(rlp.encode(receiptProof.path)), // key for trie (both tx and receipt)
// utils.bufferToHex(getTxBytes(withdraw)), // tx bytes
// utils.bufferToHex(rlp.encode(txProof.parentNodes)), // tx proof nodes
// utils.bufferToHex(getReceiptBytes(withdrawReceipt)), // receipt bytes
// utils.bufferToHex(rlp.encode(receiptProof.parentNodes)), // reciept proof nodes
// ])
// // const burnWithdrawReceipt = await withdrawManager.withdrawBurntTokens(
// // headerNumber, // header block
// // utils.bufferToHex(Buffer.concat(headerProof)), // header proof
// // withdrawBlock.number, // block number
// // withdrawBlock.timestamp, // block timestamp
// // utils.bufferToHex(withdrawBlock.transactionsRoot), // tx root
// // utils.bufferToHex(withdrawBlock.receiptsRoot), // tx root
// // utils.bufferToHex(rlp.encode(receiptProof.path)), // key for trie (both tx and receipt)
// // utils.bufferToHex(getTxBytes(withdraw)), // tx bytes
// // utils.bufferToHex(rlp.encode(txProof.parentNodes)), // tx proof nodes
// // utils.bufferToHex(getReceiptBytes(withdrawReceipt)), // receipt bytes
// // utils.bufferToHex(rlp.encode(receiptProof.parentNodes)), // reciept proof nodes
// // {
// // from: user,
// // }
// // )
// console.log()
}
yo()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment