I am trying to calculate proof that a specific Transaction is mined with a specific difficulty. So far I got the Block via JSON_RPC and all its Transactions.
I am Using the trie Library for Python 3.6
For the sake of testing everything I'm using a Block with no Transactions.
txTrie = HexaryTrie(db={}) #make new trie
print('txRoot: \t', block['transactionsRoot'])
print('txTrieRootS: \t 0x' + txTrie.root_hash.hex())
For this Code both Print-Statements return the same value.
Now I run the same code with a Block that contains one transaciton
txTrie = HexaryTrie(db={}) #make new trie
txTrie[transactionIndex] = transacionHash #add the transaction to the Trie
print('txRoot: \t', block['transactionsRoot'])
print('txTrieRootS: \t 0x' + txTrie.root_hash.hex())
And now the two print statements don't return the same value.
Can anyone help me how to get Proof that a Transaction is in a specific Block at a specific index? I just can't figure this out.
EDIT: Here is the full code:
import requests
import json
import lib.mpt as mpt
import lib.rlp as rlp
from trie import HexaryTrie
url = 'https://mainnet.infura.io/ffn6QLIJrYtke3b07YLp'
headers = {
"Content-Type": "application/json"
}
data = {}
data['jsonrpc'] = '2.0'
data['id'] = 1
data['method'] = 'eth_getBlockByNumber'
data['params'] = [hex(100004), True]
data = json.dumps(data)
response = requests.post(url, headers=headers, data=str(data) )
block = json.loads(response.text)
result = block['result']
transactions = result['transactions']
print('txRoot: \t', result['transactionsRoot'])
txTrie = HexaryTrie(db={})
print('txTrieRootS: \t 0x' + txTrie.root_hash.hex())
for x in transactions:
txTrie[b'0'] = bytes.fromhex(x['hash'][2:])
print(txTrie[str.encode(x['transactionIndex'][2:])])
print('txTrieRootA: \t 0x' + txTrie.root_hash.hex())
block,transactionIndex, andtransactionHash. Including which network you are connecting to and which block number you're using, so that everyone can reproduce along with you. – carver Jul 31 '18 at 00:50