File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 1
1
package handler
2
2
3
3
import (
4
+ "encoding/base64"
4
5
"encoding/json"
5
6
"fmt"
6
7
"net/http"
7
8
"strconv"
8
9
"strings"
9
10
11
+ "github.com/gnolang/gno/pkgs/amino"
10
12
"github.com/gnolang/gno/pkgs/bft/rpc/client"
13
+ "github.com/gnolang/gno/pkgs/std"
11
14
12
15
"github.com/gorilla/mux"
13
16
)
@@ -73,6 +76,40 @@ func AuthQueryHandler(cli client.ABCIClient) http.HandlerFunc {
73
76
}
74
77
}
75
78
79
+ func TxDecodeHandler (cli client.ABCIClient ) http.HandlerFunc {
80
+ return func (w http.ResponseWriter , r * http.Request ) {
81
+ params := r .URL .Query ()
82
+ txParam := params .Get ("tx" )
83
+ if txParam == "" {
84
+ writeError (w , fmt .Errorf ("tx param is required" ))
85
+ return
86
+ }
87
+
88
+ txData , err := base64 .StdEncoding .DecodeString (txParam )
89
+ if err != nil {
90
+ writeError (w , err )
91
+ return
92
+ }
93
+
94
+ var tx std.Tx
95
+ err = amino .Unmarshal (txData , & tx )
96
+ if err != nil {
97
+ writeError (w , err )
98
+ return
99
+ }
100
+
101
+ jsonData , err := amino .MarshalJSON (& tx )
102
+ if err != nil {
103
+ writeError (w , err )
104
+ return
105
+ }
106
+
107
+ w .WriteHeader (http .StatusOK )
108
+ w .Header ().Set ("Content-Type" , "application/json" )
109
+ fmt .Fprint (w , string (jsonData ))
110
+ }
111
+ }
112
+
76
113
func BankQueryHandler (cli client.ABCIClient ) http.HandlerFunc {
77
114
return func (w http.ResponseWriter , r * http.Request ) {
78
115
vars := mux .Vars (r )
Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ func main() {
41
41
r .HandleFunc ("/cosmos/bank/v1beta1/balances/{address}" , handler .BankQueryHandler (cli ))
42
42
r .HandleFunc ("/cosmos/staking/v1beta1/delegations/{address}" , handler .StakingQueryHandler (cli ))
43
43
r .HandleFunc ("/cosmos/staking/v1beta1/delegators/{address}/unbonding_delegations" , handler .StakingUnbondingQueryHandler (cli ))
44
+ r .HandleFunc ("/txs/decode" , handler .TxDecodeHandler (cli )).Methods (http .MethodGet )
44
45
r .HandleFunc ("/txs" , handler .TxsHandler (cli )).Methods (http .MethodPost )
45
46
46
47
fmt .Println ("Running on port" , apiPort )
You can’t perform that action at this time.
0 commit comments