Private-Blockchain

我在哪裡可以獲得我的鏈的本地 merkle-patricia-tree 根以在 Nodejs 中查看它?

  • November 27, 2017

除了我的上一個問題

所以我想從我的本地鏈中獲取數據。為此,我使用範例表單wanderer.github.io。我打開我的鏈並獲取原始數據,因此根據範例,這些數據 - 只是鏈中的原始節點。接下來我需要查看該節點中鍵的值。為此,我理解:所有密鑰都隱藏在 merkle-patricia-tree 的底部。

說說我的問題吧。我想在 github 中做類似的事情:打開我的本地錢包並查看有關它的資訊,為此我查看了範例:

//the genesis state root
var root = '12582945fc5ad12c3e7b67c4fc37a68fc0d52d995bb7f7291ff41a2739a7ca16';
var trie = new Trie(db, root);

//gav's address
var gav = new Buffer('8a40bfaa73256b60764c1bf40675a99083efb075', 'hex');

trie.get(gav, function (err, val) {
 var decoded = rlp.decode(val);
 console.log(decoded);
});

並用修復問題編寫了我自己的程式碼Invalid root length. Roots are 32 bytes

var root = new Buffer('e5be92145a301820111f91866566e3e99ee344d155569e4556a39bc71238f3bc', 'hex'), 
   wallet = new Buffer('234132b22de7037e50b9fc4ebd7476315647869e', 'hex');

// work normally and get tree
var trie = new Trie(db, root);

trie.get(

   // what need to view
   wallet,

   // function which work with wallet info
   function (err, value)
   {
       console.log(err);
       console.log(value);

       var decoded = rlp.decode(value);
       console.log(decoded);
   }
);

這是工作,但無法獲取資訊。我沒有root在我的本地連鎖店中找到,例如:

//the genesis state root
var root = '12582945fc5ad12c3e7b67c4fc37a68fc0d52d995bb7f7291ff41a2739a7ca16';
var trie = new Trie(db, root);

任何人,讓我們幫助 Dora 找到正確的本地鏈的根。這是我的鏈中的 0、1 和最後一個塊 - 也許它會幫助你:

debug.printBlock(0)

“塊(#0):大小:507.00 B { MinerHash:e521eab0c63dfd8bc7c6007e8b2ce954a66f9df3ab72ccf059e5aa49aeb149d8 標頭(e5be92145a301820111f91866566e3e99ee3434d155719ebf845)

$$ ParentHash: 0000000000000000000000000000000000000000000000000000000000000000 UncleHash: 1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347 Coinbase:0000000000000000000000000000000000000000 Root: 9178d0f23c965d81f0834a4c72c6253ce6830f4022b1359aaebfc1ecba442d4e TxSha 56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421 ReceiptSha: 56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421 Bloom: 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 Difficulty:131072 Number:0 GasLimit:4712388 GasUsed:0 Time:0 Extra: MixDigest: 0000000000000000000000000000000000000000000000000000000000000000 Nonce:000000000000002a $$ 交易:$$ $$ 叔叔們:$$ $$ }"

debug.printBlock(1)

“塊(#1):大小:536.00 B {MinerHash:d8cebba1edfdd6f0364183ace1c5bdd8b5efb2999068aa8084c84043c4a5eb5e 標頭(3ab5cb6c29e583c50b90e413dca4a6df802d87dd0eb9569dff7526d):

$$ ParentHash: e5be92145a301820111f91866566e3e99ee344d155569e4556a39bc71238f3bc UncleHash: 1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347 Coinbase: 234132b22de7037e50b9fc4ebd7476315647869e Root: 9c12c460f11fcf78d993119e08727e3e45266b3287e68fd42ef90bc730d275f6 TxSha 56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421 ReceiptSha: 56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421 Bloom: 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 Difficulty: 131072 Number: 1 GasLimit: 4712388 GasUsed: 0 Time: 1511614605 Extra: \u0603\x01\a\x02�geth�go1.9.2�darwin MixDigest: 1d51851bf1fca11a0e670fb359b7420f1393074c8c2f1760edfa3a638652a7f7 Nonce: 33c0052eafe0f837 $$交易:$$ $$叔叔們:$$ $$}"

> debug.printBlock(81)

“塊(#81):大小:536.00 B { MinerHash:5fc817cc85c1ca755186f81e7a96699b68e43e53dc834a529de53bb8adcccaad Header(0dc9b40ee5b8039f2caad3542289000b22319aba762ae8531954e)

$$ ParentHash: d9e010a5154b44cd18706decb2d47b739c71d83e4b9b53d2d14d19b6aa423001 UncleHash: 1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347 Coinbase: 234132b22de7037e50b9fc4ebd7476315647869e Root: 2aeb24f3daa4f2ed2accc00ca9af287784cc9f7292bb1bc42641490f56e235e2 TxSha 56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421 ReceiptSha: 56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421 Bloom: 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 Difficulty: 132928 Number: 81 GasLimit: 4712388 GasUsed: 0 Time: 1511643645 Extra: \u0603\x01\a\x02�geth�go1.9.2�darwin MixDigest: 486a097820216125cfe87aa9e8f67b7f64b51591026db5e205aec9e8bf4f1d5e Nonce: 21ac7e333ca8a7c4 $$交易:$$ $$叔叔們:$$ $$} "

我嘗試使用 genesis 作為 root,但這不起作用:

“0xe5be92145a301820111f91866566e3e99ee344d155569e4556a39bc71238f3bc”

您可以使用 Geth 的dump命令來抓取 block 0,然後抓取輸出的頂部:

$ geth  dump  0  | head
INFO [11-26|19:58:18] Allocated cache and file handles         database=/home/richard/.ethereum/geth/chaindata cache=128 handles=1024
INFO [11-26|19:58:18] Disk storage enabled for ethash caches   dir=/home/richard/.ethereum/geth/ethash count=3
INFO [11-26|19:58:18] Disk storage enabled for ethash DAGs     dir=/home/richard/.ethash               count=2
INFO [11-26|19:58:18] Loaded most recent local header          number=18048 hash=a57baa…6c2b4d td=8705769076450279
INFO [11-26|19:58:18] Loaded most recent local full block      number=0     hash=d4e567…cb8fa3 td=17179869184
INFO [11-26|19:58:18] Loaded most recent local fast block      number=18048 hash=a57baa…6c2b4d td=8705769076450279
{
   "root": "d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544",
   "accounts": {
       "000d836201318ec6899a67540690382780743280": {
           "balance": "200000000000000000000",
           "nonce": 0,
           "root": "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
           "codeHash": "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
           "code": "",
           "storage": {}

第一個root應該是狀態根的雜湊。

(如果您的鏈數據位於非標準位置,您也需要使用該--datadir標誌。)

引用自:https://ethereum.stackexchange.com/questions/31674