mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
* all: port boring changes from pbss * core, trie: address comments from martin * trie: minor fixes * core/rawdb: update comment * core, eth, tests, trie: address comments * tests, trie: add extra check when update trie database * trie/triedb/hashdb: degrade the error to warning Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package ethapi
|
|
|
|
import (
|
|
"bytes"
|
|
|
|
"github.com/XinFinOrg/XDPoSChain/common"
|
|
"github.com/XinFinOrg/XDPoSChain/common/hexutil"
|
|
"github.com/XinFinOrg/XDPoSChain/core/rawdb"
|
|
"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)
|
|
db := trie.NewDatabase(rawdb.NewMemoryDatabase())
|
|
trie := trie.NewEmpty(db)
|
|
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
|
|
}
|