Created
July 18, 2024 15:34
-
-
Save thaarok/2144a17ee96b12b025d612cf7ff46112 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
"github.com/ethereum/go-ethereum/common" | |
"github.com/ethereum/go-ethereum/common/hexutil" | |
"github.com/ethereum/go-ethereum/rlp" | |
"github.com/ethereum/go-ethereum/rpc" | |
) | |
type Proof struct { | |
Address common.Address | |
AccountProof []hexutil.Bytes | |
StorageHash common.Hash | |
StorageProof []struct { | |
Key common.Hash | |
//Value common.Hash // fails to unmarshall 0x0 | |
Proof []hexutil.Bytes | |
} | |
} | |
func getStorageProof(client *rpc.Client, address common.Address, slotIndex common.Hash, blockNum string) (*Proof, error) { | |
var proof Proof | |
err := client.CallContext(context.Background(), &proof, "eth_getProof", address, []common.Hash{slotIndex}, blockNum) | |
if err != nil { | |
return nil, err | |
} | |
return &proof, nil | |
} | |
func (p *Proof) GetAccountProof() ([]byte, error) { | |
return rlp.EncodeToBytes(p.AccountProof) | |
} | |
func (p *Proof) GetStorageProof() ([]byte, error) { | |
return rlp.EncodeToBytes(p.StorageProof[0].Proof) | |
} | |
func (p *Proof) GetProof() ([]byte, error) { | |
accountProof, err := p.GetAccountProof() | |
if err != nil { | |
return nil, err | |
} | |
storageProof, err := p.GetStorageProof() | |
if err != nil { | |
return nil, err | |
} | |
fmt.Printf("accountProof=%x\n", accountProof) | |
fmt.Printf("storageProof=%x\n", storageProof) | |
return rlp.EncodeToBytes([][]byte{ | |
accountProof, | |
storageProof, | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment