@@ -24,23 +24,26 @@ type BlockResponse struct {
2424}
2525
2626type BlockTransactionResponse struct {
27- Hash string `json:"hash"`
28- From string `json:"from"`
29- Nonce uint64 `json:"nonce"`
30- GasPrice * big.Int `json:"gasPrice"`
31- Type byte `json:"type"`
32- Data transaction.Data `json:"data"`
33- Payload []byte `json:"payload"`
34- ServiceData []byte `json:"serviceData"`
35- Gas int64 `json:"gas"`
27+ Hash string `json:"hash"`
28+ RawTx string `json:"raw_tx"`
29+ From string `json:"from"`
30+ Nonce uint64 `json:"nonce"`
31+ GasPrice * big.Int `json:"gas_price"`
32+ Type byte `json:"type"`
33+ Data transaction.Data `json:"data"`
34+ Payload []byte `json:"payload"`
35+ ServiceData []byte `json:"service_data"`
36+ Gas int64 `json:"gas"`
37+ TxResult ResponseDeliverTx `json:"tx_result"`
3638}
3739
3840func Block (w http.ResponseWriter , r * http.Request ) {
3941
4042 vars := mux .Vars (r )
4143 height , _ := strconv .ParseInt (vars ["height" ], 10 , 64 )
4244
43- result , err := client .Block (& height )
45+ block , err := client .Block (& height )
46+ blockResults , err := client .BlockResults (& height )
4447
4548 w .Header ().Set ("Content-Type" , "application/json; charset=UTF-8" )
4649
@@ -55,14 +58,15 @@ func Block(w http.ResponseWriter, r *http.Request) {
5558
5659 w .WriteHeader (http .StatusOK )
5760
58- txs := make ([]BlockTransactionResponse , len (result .Block .Data .Txs ))
61+ txs := make ([]BlockTransactionResponse , len (block .Block .Data .Txs ))
5962
60- for i , rawTx := range result .Block .Data .Txs {
63+ for i , rawTx := range block .Block .Data .Txs {
6164 tx , _ := transaction .DecodeFromBytes (rawTx )
6265 sender , _ := tx .Sender ()
6366
6467 txs [i ] = BlockTransactionResponse {
6568 Hash : fmt .Sprintf ("Mt%x" , types .Tx (rawTx ).Hash ()),
69+ RawTx : fmt .Sprintf ("%x" , rawTx ),
6670 From : sender .String (),
6771 Nonce : tx .Nonce ,
6872 GasPrice : tx .GasPrice ,
@@ -71,16 +75,25 @@ func Block(w http.ResponseWriter, r *http.Request) {
7175 Payload : tx .Payload ,
7276 ServiceData : tx .ServiceData ,
7377 Gas : tx .Gas (),
78+ TxResult : ResponseDeliverTx {
79+ Code : blockResults .Results .DeliverTx [i ].Code ,
80+ Data : blockResults .Results .DeliverTx [i ].Data ,
81+ Log : blockResults .Results .DeliverTx [i ].Log ,
82+ Info : blockResults .Results .DeliverTx [i ].Info ,
83+ GasWanted : blockResults .Results .DeliverTx [i ].GasWanted ,
84+ GasUsed : blockResults .Results .DeliverTx [i ].GasUsed ,
85+ Tags : blockResults .Results .DeliverTx [i ].Tags ,
86+ },
7487 }
7588 }
7689
7790 response := BlockResponse {
78- Hash : result .Block .Hash (),
79- Height : result .Block .Height ,
80- Time : result .Block .Time ,
81- NumTxs : result .Block .NumTxs ,
82- TotalTxs : result .Block .TotalTxs ,
83- Precommits : result .Block .LastCommit .Precommits ,
91+ Hash : block .Block .Hash (),
92+ Height : block .Block .Height ,
93+ Time : block .Block .Time ,
94+ NumTxs : block .Block .NumTxs ,
95+ TotalTxs : block .Block .TotalTxs ,
96+ Precommits : block .Block .LastCommit .Precommits ,
8497 Transactions : txs ,
8598 }
8699
0 commit comments