-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add merkle prove query RPC and smoketest for it
- Loading branch information
brewmaster012
committed
Sep 14, 2023
1 parent
6bf8451
commit 5060dba
Showing
6 changed files
with
910 additions
and
143 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
eth "github.com/ethereum/go-ethereum/common" | ||
ethtypes "github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/rlp" | ||
"github.com/zeta-chain/zetacore/x/observer/types" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
func (k Keeper) Prove(c context.Context, req *types.QueryProveRequest) (*types.QueryProveResponse, error) { | ||
if req == nil { | ||
return nil, status.Error(codes.InvalidArgument, "invalid request") | ||
} | ||
ctx := sdk.UnwrapSDKContext(c) | ||
|
||
blockHash := eth.HexToHash(req.BlockHash) | ||
res, found := k.GetBlockHeader(ctx, blockHash.Bytes()) | ||
if !found { | ||
return nil, status.Error(codes.NotFound, "block header not found") | ||
} | ||
var header ethtypes.Header | ||
err := rlp.DecodeBytes(res.Header, &header) | ||
if err != nil { | ||
return nil, status.Error(codes.Internal, fmt.Sprintf("failed to decode header: %s", err)) | ||
} | ||
proven := false | ||
if found { | ||
val, err := req.Proof.Verify(header.TxHash, int(req.TxIndex)) | ||
if err == nil { | ||
var txx ethtypes.Transaction | ||
err = txx.UnmarshalBinary(val) | ||
if err != nil { | ||
return nil, status.Error(codes.Internal, fmt.Sprintf("failed to unmarshal transaction: %s", err)) | ||
} | ||
proven = true | ||
} | ||
} | ||
return &types.QueryProveResponse{ | ||
Valid: proven, | ||
}, nil | ||
} |
Oops, something went wrong.