Skip to content

Commit

Permalink
chore: fix lint after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
renaynay committed Jul 27, 2022
1 parent 7757d7b commit 7d6cea2
Showing 1 changed file with 1 addition and 61 deletions.
62 changes: 1 addition & 61 deletions service/state/core_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/cosmos/cosmos-sdk/api/tendermint/abci"
"github.com/cosmos/cosmos-sdk/types"
sdktypes "github.com/cosmos/cosmos-sdk/types"
sdktx "github.com/cosmos/cosmos-sdk/types/tx"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
proofutils "github.com/cosmos/ibc-go/v4/modules/core/23-commitment/types"
rpcclient "github.com/tendermint/tendermint/rpc/client"
Expand Down Expand Up @@ -180,67 +181,6 @@ func (ca *CoreAccessor) BalanceForAddress(ctx context.Context, addr Address) (*B
}, nil
}

func (ca *CoreAccessor) VerifiedBalance(ctx context.Context) (*Balance, error) {
addr, err := ca.signer.GetSignerInfo().GetAddress()
if err != nil {
return nil, err
}
return ca.VerifiedBalanceForAddress(ctx, addr)
}

func (ca *CoreAccessor) VerifiedBalanceForAddress(ctx context.Context, addr Address) (*Balance, error) {
head, err := ca.getter.Head(ctx)
if err != nil {
return nil, err
}
// construct an ABCI query for the height at head-1 because
// the AppHash contained in the head is actually the hash of
// the transactions contained in the previous blocks.
// TODO @renaynay: once https://github.com/cosmos/cosmos-sdk/pull/12674 is merged, use this method instead
prefixedAccountKey := append(bank_types.CreateAccountBalancesPrefix(addr.Bytes()), []byte(app.BondDenom)...)
abciReq := abci.RequestQuery{
// TODO @renayay: once https://github.com/cosmos/cosmos-sdk/pull/12674 is merged, use const instead
Path: fmt.Sprintf("store/%s/key", banktypes.StoreKey),
Height: head.Height - 1,
Data: prefixedAccountKey,
Prove: true,
}
opts := rpcclient.ABCIQueryOptions{
Height: abciReq.Height,
Prove: abciReq.Prove,
}
result, err := ca.rpcCli.ABCIQueryWithOptions(ctx, abciReq.Path, abciReq.Data, opts)
if err != nil {
return nil, err
}
if !result.Response.IsOK() {
return nil, sdkErrorToGRPCError(result.Response)
}
// unmarshal balance information
value := result.Response.Value
coin, ok := sdktypes.NewIntFromString(string(value))
if !ok {
return nil, fmt.Errorf("cannot convert %s into sdktypes.Int", string(value))
}
// convert proofs into a more digestible format
merkleproof, err := proofutils.ConvertProofs(result.Response.GetProofOps())
if err != nil {
return nil, err
}
root := proofutils.NewMerkleRoot(head.AppHash)
// VerifyMembership expects the path as:
// []string{<store key of module>, <actual key corresponding to requested value>}
path := proofutils.NewMerklePath(banktypes.StoreKey, string(prefixedAccountKey))
err = merkleproof.VerifyMembership(proofutils.GetSDKSpecs(), root, path, value)
if err != nil {
return nil, err
}
return &Balance{
Denom: app.BondDenom,
Amount: coin,
}, nil
}

func (ca *CoreAccessor) SubmitTx(ctx context.Context, tx Tx) (*TxResponse, error) {
txResp, err := apptypes.BroadcastTx(ctx, ca.coreConn, sdktx.BroadcastMode_BROADCAST_MODE_BLOCK, tx)
if err != nil {
Expand Down

0 comments on commit 7d6cea2

Please sign in to comment.