gpt4 book ai didi

database - 如何使用 LevelDB 访问 GoEthereum Transaction Trie

转载 作者:行者123 更新时间:2023-12-05 08:03:30 25 4
gpt4 key购买 nike

我想使用 LevelDB 访问 Ethereum Transaction Trie,但它只适用于区 block 0,对于任何其他区 block ,它都没有给我任何数据。只是想知道 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, parentHash:"0x17d0dee586ef5064cfcd835e4c40d34f6a5683449cd3a1a1f0f705a2bab6a938",receiptsRoot:"0x056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2",sha3Uncles:"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",size: 647, stateRoot:"0xb2ae3c859e0873667bdc088217be87cab1fed2a068e9e6baa124922915c83419",timestamp: 1654920279, totalDifficulty: 39858713, transactions:["0x50a949ef9cab9d8edad24d8b6b33b3023ef499a6f43aabd8db1a7db85daf68f7"],transactionsRoot:"0x51736d42e0e8fe95c3e609e5e5fb70da476613d24b5cd0d710d68190649c39f4",uncles: [] }

最佳答案

我相信这是您使用 SecureTrie 而不是 Trie 来进行交易。 Transaction 和 Receipts trie 不像 State 和 Storage 那样散列。我有同样的问题去看看我的代码 https://ethereum.stackexchange.com/questions/130716/prove-transactionhash-of-block-using-ethereumjs-tx-and-merkle-patricia-tree

关于database - 如何使用 LevelDB 访问 GoEthereum Transaction Trie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72582211/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com