mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-20 21:54:30 +00:00
* all: rework trie and trie committer * all: get rid of internal cache in trie * all: fixes * trie: polish * core, trie: address comments * trie: fix imports * core/state: address comments * core/state/snapshot: polish * trie: remove unused code * trie: update tests * trie: don't set db as nil * trie: address comments * trie: unskip test Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package ethapi
|
|
|
|
import (
|
|
"bytes"
|
|
|
|
"github.com/XinFinOrg/XDPoSChain/common"
|
|
"github.com/XinFinOrg/XDPoSChain/common/hexutil"
|
|
"github.com/XinFinOrg/XDPoSChain/core/types"
|
|
"github.com/XinFinOrg/XDPoSChain/rlp"
|
|
"github.com/XinFinOrg/XDPoSChain/trie"
|
|
)
|
|
|
|
// proofPairList implements ethdb.KeyValueWriter and collects the proofs as
|
|
// hex-strings of key and value for delivery to rpc-caller.
|
|
type proofPairList struct {
|
|
keys []string
|
|
values []string
|
|
}
|
|
|
|
func (n *proofPairList) Put(key []byte, value []byte) error {
|
|
n.keys = append(n.keys, hexutil.Encode(key))
|
|
n.values = append(n.values, hexutil.Encode(value))
|
|
return nil
|
|
}
|
|
|
|
func (n *proofPairList) Delete(key []byte) error {
|
|
panic("not supported")
|
|
}
|
|
|
|
// modified from core/types/derive_sha.go
|
|
func deriveTrie(list types.DerivableList) *trie.Trie {
|
|
buf := new(bytes.Buffer)
|
|
trie := trie.NewEmpty(nil)
|
|
for i := range list.Len() {
|
|
buf.Reset()
|
|
rlp.Encode(buf, uint(i))
|
|
key := common.CopyBytes(buf.Bytes())
|
|
buf.Reset()
|
|
list.EncodeIndex(i, buf)
|
|
value := common.CopyBytes(buf.Bytes())
|
|
trie.Update(key, value)
|
|
}
|
|
return trie
|
|
}
|