/
single_result.go
executable file
·124 lines (106 loc) · 3.61 KB
/
single_result.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package proof
// import (
// "context"
// "encoding/json"
// "net/http"
// "strconv"
// tmbytes "github.com/cometbft/cometbft/libs/bytes"
// rpcclient "github.com/cometbft/cometbft/rpc/client"
// "github.com/ethereum/go-ethereum/accounts/abi"
// "github.com/gorilla/mux"
// "github.com/cosmos/cosmos-sdk/client"
// "github.com/cosmos/cosmos-sdk/testutil/rest"
// "github.com/ODIN-PROTOCOL/odin-core/pkg/obi"
// oracletypes "github.com/ODIN-PROTOCOL/odin-core/x/oracle/types"
// )
// type JsonProof struct {
// BlockHeight uint64 `json:"block_height"`
// OracleDataProof OracleDataProof `json:"oracle_data_proof"`
// BlockRelayProof BlockRelayProof `json:"block_relay_proof"`
// }
// type Proof struct {
// JsonProof JsonProof `json:"json_proof"`
// EVMProofBytes tmbytes.HexBytes `json:"evm_proof_bytes"`
// }
// func GetProofHandlerFn(cliCtx client.Context) http.HandlerFunc {
// return func(w http.ResponseWriter, r *http.Request) {
// ctx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
// if !ok {
// return
// }
// height := &ctx.Height
// if ctx.Height == 0 {
// height = nil
// }
// // Parse Request ID
// vars := mux.Vars(r)
// intRequestID, err := strconv.ParseUint(vars[RequestIDTag], 10, 64)
// if err != nil {
// rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
// return
// }
// requestID := oracletypes.RequestID(intRequestID)
// commit, err := ctx.Client.Commit(context.Background(), height)
// if err != nil {
// rest.WriteErrorResponse(w, http.StatusNotFound, err.Error())
// return
// }
// value, iavlEp, multiStoreEp, err := getProofsByKey(
// ctx,
// oracletypes.ResultStoreKey(requestID),
// rpcclient.ABCIQueryOptions{Height: commit.Height - 1, Prove: true},
// true,
// )
// if err != nil {
// rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
// return
// }
// signatures, err := GetSignaturesAndPrefix(&commit.SignedHeader)
// if err != nil {
// rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
// return
// }
// blockRelay := BlockRelayProof{
// MultiStoreProof: GetMultiStoreProof(multiStoreEp),
// BlockHeaderMerkleParts: GetBlockHeaderMerkleParts(commit.Header),
// Signatures: signatures,
// }
// var rs oracletypes.Result
// obi.MustDecode(value, &rs)
// oracleData := OracleDataProof{
// Result: rs,
// Version: decodeIAVLLeafPrefix(iavlEp.Leaf.Prefix),
// MerklePaths: GetMerklePaths(iavlEp),
// }
// // Calculate byte for proofbytes
// var relayAndVerifyArguments abi.Arguments
// format := `[{"type":"bytes"},{"type":"bytes"}]`
// err = json.Unmarshal([]byte(format), &relayAndVerifyArguments)
// if err != nil {
// panic(err)
// }
// blockRelayBytes, err := blockRelay.encodeToEthData()
// if err != nil {
// rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
// return
// }
// oracleDataBytes, err := oracleData.encodeToEthData(uint64(commit.Height))
// if err != nil {
// rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
// return
// }
// evmProofBytes, err := relayAndVerifyArguments.Pack(blockRelayBytes, oracleDataBytes)
// if err != nil {
// rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
// return
// }
// rest.PostProcessResponse(w, ctx, Proof{
// JsonProof: JsonProof{
// BlockHeight: uint64(commit.Height),
// OracleDataProof: oracleData,
// BlockRelayProof: blockRelay,
// },
// EVMProofBytes: evmProofBytes,
// })
// }
// }