@@ -7,16 +7,23 @@ import (
7
7
"net/http"
8
8
9
9
"github.com/gnolang/gno/pkgs/amino"
10
- abci "github.com/gnolang/gno/pkgs/bft/abci/types"
11
10
"github.com/gnolang/gno/pkgs/bft/rpc/client"
12
11
ctypes "github.com/gnolang/gno/pkgs/bft/rpc/core/types"
13
12
"github.com/gnolang/gno/pkgs/std"
14
13
)
15
14
16
- type BroadcastResponse struct {
17
- Result abci.ResponseDeliverTx `json:"result"`
18
- Hash string `json:"hash"`
19
- Height int64 `json:"height"`
15
+ type BroadcastTxResponse struct {
16
+ TxResponse * TxResponse `json:"tx_response,omitempty"`
17
+ }
18
+
19
+ type TxResponse struct {
20
+ Height int64 `json:"height,omitempty"`
21
+ TxHash string `json:"txhash,omitempty"`
22
+ Code uint32 `json:"code,omitempty"`
23
+ Data string `json:"data,omitempty"`
24
+ RawLog string `json:"raw_log,omitempty"`
25
+ GasWanted int64 `json:"gas_wanted,omitempty"`
26
+ GasUsed int64 `json:"gas_used,omitempty"`
20
27
}
21
28
22
29
func TxsHandler (cli client.ABCIClient ) http.HandlerFunc {
@@ -48,20 +55,17 @@ func TxsHandler(cli client.ABCIClient) http.HandlerFunc {
48
55
return
49
56
}
50
57
51
- if res .CheckTx .IsErr () {
52
- writeError (w , fmt .Errorf ("transaction failed %#v\n log %s" , res , res .CheckTx .Log ))
53
- return
54
- }
55
-
56
- if res .DeliverTx .IsErr () {
57
- writeError (w , fmt .Errorf ("transaction failed %#v\n log %s" , res , res .DeliverTx .Log ))
58
- return
59
- }
60
-
61
- result := BroadcastResponse {
62
- Hash : fmt .Sprintf ("%X" , res .Hash ),
63
- Height : res .Height ,
64
- Result : res .DeliverTx ,
58
+ code , log := getCodeLog (res )
59
+ result := BroadcastTxResponse {
60
+ TxResponse : & TxResponse {
61
+ TxHash : fmt .Sprintf ("%X" , res .Hash ),
62
+ Height : res .Height ,
63
+ Code : code ,
64
+ Data : string (res .DeliverTx .Data ),
65
+ RawLog : log ,
66
+ GasWanted : res .DeliverTx .GasWanted ,
67
+ GasUsed : res .DeliverTx .GasUsed ,
68
+ },
65
69
}
66
70
67
71
w .Header ().Set ("Content-Type" , "application/json" )
@@ -94,20 +98,17 @@ func ProtoTxsHandler(cli client.ABCIClient) http.HandlerFunc {
94
98
return
95
99
}
96
100
97
- if res .CheckTx .IsErr () {
98
- writeError (w , fmt .Errorf ("transaction failed %#v\n log %s" , res , res .CheckTx .Log ))
99
- return
100
- }
101
-
102
- if res .DeliverTx .IsErr () {
103
- writeError (w , fmt .Errorf ("transaction failed %#v\n log %s" , res , res .DeliverTx .Log ))
104
- return
105
- }
106
-
107
- result := BroadcastResponse {
108
- Hash : fmt .Sprintf ("%X" , res .Hash ),
109
- Height : res .Height ,
110
- Result : res .DeliverTx ,
101
+ code , log := getCodeLog (res )
102
+ result := BroadcastTxResponse {
103
+ TxResponse : & TxResponse {
104
+ TxHash : fmt .Sprintf ("%X" , res .Hash ),
105
+ Height : res .Height ,
106
+ Code : code ,
107
+ Data : string (res .DeliverTx .Data ),
108
+ RawLog : log ,
109
+ GasWanted : res .DeliverTx .GasWanted ,
110
+ GasUsed : res .DeliverTx .GasUsed ,
111
+ },
111
112
}
112
113
113
114
w .Header ().Set ("Content-Type" , "application/json" )
@@ -116,6 +117,18 @@ func ProtoTxsHandler(cli client.ABCIClient) http.HandlerFunc {
116
117
}
117
118
}
118
119
120
+ func getCodeLog (res * ctypes.ResultBroadcastTxCommit ) (uint32 , string ) {
121
+ if res .CheckTx .IsErr () {
122
+ return 1 , res .CheckTx .Log
123
+ }
124
+
125
+ if res .DeliverTx .IsErr () {
126
+ return 2 , res .DeliverTx .Log
127
+ }
128
+
129
+ return 0 , ""
130
+ }
131
+
119
132
func BroadcastHandler (cli client.ABCIClient , tx std.Tx ) (* ctypes.ResultBroadcastTxCommit , error ) {
120
133
bz , err := amino .Marshal (tx )
121
134
if err != nil {
0 commit comments