Skip to content
This repository was archived by the owner on Apr 4, 2024. It is now read-only.

Commit 5f0bd98

Browse files
committed
add getHexProofs
1 parent a7d32c8 commit 5f0bd98

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

rpc/backend/account_info.go

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
rpctypes "github.com/evmos/ethermint/rpc/types"
1414
evmtypes "github.com/evmos/ethermint/x/evm/types"
1515
"github.com/pkg/errors"
16+
"github.com/tendermint/tendermint/proto/tendermint/crypto"
1617
)
1718

1819
// GetCode returns the contract code at the given address and block number.
@@ -34,6 +35,17 @@ func (b *Backend) GetCode(address common.Address, blockNrOrHash rpctypes.BlockNu
3435
return res.Code, nil
3536
}
3637

38+
func getHexProofs(proof *crypto.ProofOps) []string {
39+
var proofs []string
40+
// check for proof
41+
if proof != nil {
42+
for _, p := range proof.Ops {
43+
proofs = append(proofs, hexutil.Encode(p.Data))
44+
}
45+
}
46+
return proofs
47+
}
48+
3749
// GetProof returns an account object with proof and any storage proofs
3850
func (b *Backend) GetProof(address common.Address, storageKeys []string, blockNrOrHash rpctypes.BlockNumberOrHash) (*rpctypes.AccountResult, error) {
3951
blockNum, err := b.BlockNumberFromTendermint(blockNrOrHash)
@@ -75,18 +87,10 @@ func (b *Backend) GetProof(address common.Address, storageKeys []string, blockNr
7587
return nil, err
7688
}
7789

78-
// check for proof
79-
var storeProofs []string
80-
if proof != nil {
81-
for _, p := range proof.Ops {
82-
storeProofs = append(storeProofs, hexutil.Encode(p.Data))
83-
}
84-
}
85-
8690
storageProofs[i] = rpctypes.StorageResult{
8791
Key: key,
8892
Value: (*hexutil.Big)(new(big.Int).SetBytes(valueBz)),
89-
Proof: storeProofs,
93+
Proof: getHexProofs(proof),
9094
}
9195
}
9296

@@ -107,22 +111,14 @@ func (b *Backend) GetProof(address common.Address, storageKeys []string, blockNr
107111
return nil, err
108112
}
109113

110-
// check for proof
111-
var accProofs []string
112-
if proof != nil {
113-
for _, p := range proof.Ops {
114-
accProofs = append(accProofs, hexutil.Encode(p.Data))
115-
}
116-
}
117-
118114
balance, ok := sdkmath.NewIntFromString(res.Balance)
119115
if !ok {
120116
return nil, errors.New("invalid balance")
121117
}
122118

123119
return &rpctypes.AccountResult{
124120
Address: address,
125-
AccountProof: accProofs,
121+
AccountProof: getHexProofs(proof),
126122
Balance: (*hexutil.Big)(balance.BigInt()),
127123
CodeHash: common.HexToHash(res.CodeHash),
128124
Nonce: hexutil.Uint64(res.Nonce),

0 commit comments

Comments
 (0)