簡體   English   中英

如何使用 LevelDB 訪問 GoEthereum Transaction Trie

[英]How to access GoEthereum Transaction Trie using LevelDB

我想使用 LevelDB 訪問 Ethereum Transaction Trie,但它僅適用於塊 0,對於任何其他塊,它都沒有給我任何數據。 只是想知道 web3.eth.getTransaction() 如何在內部工作:這是代碼:

 const Trie1 = require ('merkle-patricia-tree').SecureTrie const { Account, BN, bufferToHex, rlp } = require ('ethereumjs-util'); var levelup = require('levelup'); var leveldown = require('leveldown'); const gethDbPath = '/Users/AK/gethDataDir/geth/chaindata' const db = new levelup(leveldown(gethDbPath)) async function test() { const txnRoot = '0x51736d42e0e8fe95c3e609e5e5fb70da476613d24b5cd0d710d68190649c39f4' const txnRootBuffer = Buffer.from(txnRoot.slice(2), 'hex') const trie1 = new Trie1(db,txnRootBuffer) const stream = trie1.createReadStream() stream.on('data', (data) => { console.log(`key: ${bufferToHex(data.key)}`) console.log(`Value: ${bufferToHex(rlp.decode(data.value))}`) }).on('end', () => { console.log('1111--->>> Finished') }) } test();

下面是我試圖直接訪問 levelDB 的事務。 我嘗試了幾乎所有的組合,如 TxnRoot、TxnHash,有或沒有 Kecak256 等

{ difficulty: 149904, extraData: "0xd983010a10846765746888676f312e31372e368664617277696e", gasLimit: 2770332, gasUsed: 21000, hash: "0xa98255eed7b9a16b30013b8cabf8adf07def8cb772ba9d3110f72a97fd351ad7", logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", miner: "0x3f457dd6c71534bc7955c29b6a097cf39b96bfd7", mixHash: "0x366ff733fc9e2768595a25299edec785688deb4c8fe2d53543b860e8ee0724fc", nonce: "0x24bc70e55ec61f1d", number :284,父哈希:“0x17d0dee586ef5064cfcd835e4c40d34f6a5683449cd3a1a1f0 f705a2bab6a938", receiptsRoot: "0x056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2", sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", size: 647, stateRoot: "0xb2ae3c859e0873667bdc088217be87cab1fed2a068e9e6baa124922915c83419", timestamp: 1654920279, totalDifficulty: 39858713, transactions: ["0x50a949ef9cab9d8edad24d8b6b33b3023ef499a6f43aabd8db1a7db85daf68f7"], transactionsRoot: "0x51736d42e0e8fe95c3e609e5e5fb70da476613d24b5cd0d710d68190649c39f4", uncles: [ ] }

我相信這是您將SecureTrie用於transanstion trie 而不是Trie Transaction 和 Receipts trie 不像 State 和 Storage 那樣散列。 我有同樣的問題 go 看看我的代碼https://ethereum.stackexchange.com/questions/130716/prove-transactionhash-of-block-using-ethereumjs-tx-and-merkle-patricia-tree

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM