export Keccak256ToCID funtion
This commit is contained in:
parent
ae5ab3d9b0
commit
50d08bcb36
@ -105,11 +105,11 @@ func (as *EthAccountSnapshot) Resolve(p []string) (interface{}, []string, error)
|
||||
case "balance":
|
||||
return as.Balance, nil, nil
|
||||
case "codeHash":
|
||||
return &node.Link{Cid: keccak256ToCid(RawBinary, as.CodeHash)}, nil, nil
|
||||
return &node.Link{Cid: Keccak256ToCid(RawBinary, as.CodeHash)}, nil, nil
|
||||
case "nonce":
|
||||
return as.Nonce, nil, nil
|
||||
case "root":
|
||||
return &node.Link{Cid: keccak256ToCid(MEthStorageTrie, as.Root)}, nil, nil
|
||||
return &node.Link{Cid: Keccak256ToCid(MEthStorageTrie, as.Root)}, nil, nil
|
||||
default:
|
||||
return nil, nil, ErrInvalidLink
|
||||
}
|
||||
@ -167,9 +167,9 @@ func (as *EthAccountSnapshot) Size() (uint64, error) {
|
||||
func (as *EthAccountSnapshot) MarshalJSON() ([]byte, error) {
|
||||
out := map[string]interface{}{
|
||||
"balance": as.Balance,
|
||||
"codeHash": keccak256ToCid(RawBinary, as.CodeHash),
|
||||
"codeHash": Keccak256ToCid(RawBinary, as.CodeHash),
|
||||
"nonce": as.Nonce,
|
||||
"root": keccak256ToCid(MEthStorageTrie, as.Root),
|
||||
"root": Keccak256ToCid(MEthStorageTrie, as.Root),
|
||||
}
|
||||
return json.Marshal(out)
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ func (rt *logTrie) getNodeFromDB(key []byte) (*EthLogTrie, error) {
|
||||
return nil, err
|
||||
}
|
||||
tn := &TrieNode{
|
||||
cid: keccak256ToCid(MEthLogTrie, key),
|
||||
cid: Keccak256ToCid(MEthLogTrie, key),
|
||||
rawdata: rawdata,
|
||||
}
|
||||
return &EthLogTrie{TrieNode: tn}, nil
|
||||
|
@ -167,7 +167,7 @@ func (rt *rctTrie) getNodeFromDB(key []byte) (*EthRctTrie, error) {
|
||||
return nil, err
|
||||
}
|
||||
tn := &TrieNode{
|
||||
cid: keccak256ToCid(MEthTxReceiptTrie, key),
|
||||
cid: Keccak256ToCid(MEthTxReceiptTrie, key),
|
||||
rawdata: rawdata,
|
||||
}
|
||||
|
||||
|
@ -64,6 +64,10 @@ func FromStateTrieRLP(raw []byte) (*EthStateTrie, error) {
|
||||
return DecodeEthStateTrie(c, raw)
|
||||
}
|
||||
|
||||
func FromStateTrieRLPAndHash(raw, hash []byte) (*EthStateTrie, error) {
|
||||
c, err := Keccak256ToCid(MEthStateTrie, hash)
|
||||
}
|
||||
|
||||
/*
|
||||
OUTPUT
|
||||
*/
|
||||
|
@ -136,7 +136,7 @@ func (tt *txTrie) getNodes() ([]*EthTxTrie, error) {
|
||||
return nil, err
|
||||
}
|
||||
tn := &TrieNode{
|
||||
cid: keccak256ToCid(MEthTxTrie, k),
|
||||
cid: Keccak256ToCid(MEthTxTrie, k),
|
||||
rawdata: rawdata,
|
||||
}
|
||||
out = append(out, &EthTxTrie{TrieNode: tn})
|
||||
|
@ -69,9 +69,9 @@ func RawdataToCid(codec uint64, rawdata []byte, multiHash uint64) (cid.Cid, erro
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// keccak256ToCid takes a keccak256 hash and returns its cid based on
|
||||
// Keccak256ToCid takes a keccak256 hash and returns its cid based on
|
||||
// the codec given.
|
||||
func keccak256ToCid(codec uint64, h []byte) cid.Cid {
|
||||
func Keccak256ToCid(codec uint64, h []byte) cid.Cid {
|
||||
buf, err := mh.Encode(h, mh.KECCAK_256)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
@ -143,7 +143,7 @@ func decodeCompactKey(i []interface{}) (string, []interface{}, error) {
|
||||
func parseTrieNodeExtension(i []interface{}, codec uint64) ([]interface{}, error) {
|
||||
return []interface{}{
|
||||
i[0].([]byte),
|
||||
keccak256ToCid(codec, i[1].([]byte)),
|
||||
Keccak256ToCid(codec, i[1].([]byte)),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -163,7 +163,7 @@ func parseTrieNodeBranch(i []interface{}, codec uint64) ([]interface{}, error) {
|
||||
case 0:
|
||||
out = append(out, nil)
|
||||
case 32:
|
||||
out = append(out, keccak256ToCid(codec, v))
|
||||
out = append(out, Keccak256ToCid(codec, v))
|
||||
default:
|
||||
return nil, fmt.Errorf("unrecognized object: %v", v)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user