@@ -13,12 +13,9 @@ import (
13
13
"go.vocdoni.io/dvote/crypto/zk/circuit"
14
14
"go.vocdoni.io/dvote/httprouter"
15
15
"go.vocdoni.io/dvote/httprouter/apirest"
16
- "go.vocdoni.io/dvote/types"
17
16
"go.vocdoni.io/dvote/util"
18
- "go.vocdoni.io/dvote/vochain"
19
17
"go.vocdoni.io/dvote/vochain/genesis"
20
18
"go.vocdoni.io/dvote/vochain/indexer"
21
- "go.vocdoni.io/dvote/vochain/indexer/indexertypes"
22
19
"go.vocdoni.io/dvote/vochain/state"
23
20
)
24
21
@@ -167,7 +164,7 @@ func (a *API) enableChainHandlers() error {
167
164
"/chain/blocks/{height}" ,
168
165
"GET" ,
169
166
apirest .MethodAccessTypePublic ,
170
- a .chainBlockHandler ,
167
+ a .chainBlockByHeightHandler ,
171
168
); err != nil {
172
169
return err
173
170
}
@@ -690,14 +687,6 @@ func (a *API) chainTxHandler(_ *apirest.APIdata, ctx *httprouter.HTTPContext) er
690
687
if err != nil {
691
688
return err
692
689
}
693
- stx , err := a .vocapp .GetTx (uint32 (height ), int32 (index ))
694
- if err != nil {
695
- if errors .Is (err , vochain .ErrTransactionNotFound ) {
696
- return ErrTransactionNotFound
697
- }
698
- return ErrVochainGetTxFailed .WithErr (err )
699
- }
700
-
701
690
ref , err := a .indexer .GetTransactionByHeightAndIndex (height , index )
702
691
if err != nil {
703
692
if errors .Is (err , indexer .ErrTransactionNotFound ) {
@@ -706,9 +695,8 @@ func (a *API) chainTxHandler(_ *apirest.APIdata, ctx *httprouter.HTTPContext) er
706
695
return ErrVochainGetTxFailed .WithErr (err )
707
696
}
708
697
tx := & GenericTransactionWithInfo {
709
- TxContent : []byte (protoFormat (stx .Tx )),
710
- Signature : stx .Signature ,
711
- TxInfo : * ref ,
698
+ TxContent : []byte (protoFormat (ref .RawTx )),
699
+ TxInfo : ref ,
712
700
}
713
701
data , err := json .Marshal (tx )
714
702
if err != nil {
@@ -758,6 +746,8 @@ func (a *API) chainTxRefByIndexHandler(_ *apirest.APIdata, ctx *httprouter.HTTPC
758
746
// @Param limit query number false "Items per page"
759
747
// @Param height query number false "Block height"
760
748
// @Param type query string false "Tx type"
749
+ // @Param subtype query string false "Tx subtype"
750
+ // @Param signer query string false "Tx signer"
761
751
// @Success 200 {object} TransactionsList "List of transactions references"
762
752
// @Router /chain/transactions [get]
763
753
func (a * API ) chainTxListHandler (_ * apirest.APIdata , ctx * httprouter.HTTPContext ) error {
@@ -766,6 +756,8 @@ func (a *API) chainTxListHandler(_ *apirest.APIdata, ctx *httprouter.HTTPContext
766
756
ctx .QueryParam (ParamLimit ),
767
757
ctx .QueryParam (ParamHeight ),
768
758
ctx .QueryParam (ParamType ),
759
+ ctx .QueryParam (ParamSubtype ),
760
+ ctx .QueryParam (ParamSigner ),
769
761
)
770
762
if err != nil {
771
763
return err
@@ -797,6 +789,8 @@ func (a *API) chainTxListByPageHandler(_ *apirest.APIdata, ctx *httprouter.HTTPC
797
789
"" ,
798
790
"" ,
799
791
"" ,
792
+ "" ,
793
+ "" ,
800
794
)
801
795
if err != nil {
802
796
return err
@@ -833,6 +827,8 @@ func (a *API) chainTxListByHeightAndPageHandler(_ *apirest.APIdata, ctx *httprou
833
827
"" ,
834
828
ctx .URLParam (ParamHeight ),
835
829
"" ,
830
+ "" ,
831
+ "" ,
836
832
)
837
833
if err != nil {
838
834
return err
@@ -859,6 +855,8 @@ func (a *API) transactionList(params *TransactionParams) (*TransactionsList, err
859
855
params .Page * params .Limit ,
860
856
params .Height ,
861
857
params .Type ,
858
+ params .Subtype ,
859
+ params .Signer ,
862
860
)
863
861
if err != nil {
864
862
return nil , ErrIndexerQueryFailed .WithErr (err )
@@ -911,7 +909,7 @@ func (a *API) chainValidatorsHandler(_ *apirest.APIdata, ctx *httprouter.HTTPCon
911
909
return ctx .Send (data , apirest .HTTPstatusOK )
912
910
}
913
911
914
- // chainBlockHandler
912
+ // chainBlockByHeightHandler
915
913
//
916
914
// @Summary Get block (by height)
917
915
// @Description Returns the full block information at the given height
@@ -921,23 +919,34 @@ func (a *API) chainValidatorsHandler(_ *apirest.APIdata, ctx *httprouter.HTTPCon
921
919
// @Param height path int true "Block height"
922
920
// @Success 200 {object} api.Block
923
921
// @Router /chain/blocks/{height} [get]
924
- func (a * API ) chainBlockHandler (_ * apirest.APIdata , ctx * httprouter.HTTPContext ) error {
922
+ func (a * API ) chainBlockByHeightHandler (_ * apirest.APIdata , ctx * httprouter.HTTPContext ) error {
925
923
height , err := strconv .ParseUint (ctx .URLParam (ParamHeight ), 10 , 64 )
926
924
if err != nil {
927
925
return err
928
926
}
929
- tmblock := a .vocapp .GetBlockByHeight (int64 (height ))
930
- if tmblock == nil {
931
- return ErrBlockNotFound
927
+ idxblock , err := a .indexer .BlockByHeight (int64 (height ))
928
+ if err != nil {
929
+ if errors .Is (err , indexer .ErrBlockNotFound ) {
930
+ return ErrBlockNotFound
931
+ }
932
+ return ErrBlockNotFound .WithErr (err )
933
+ }
934
+ txcount , err := a .indexer .CountTransactionsByHeight (int64 (height ))
935
+ if err != nil {
936
+ return ErrIndexerQueryFailed .WithErr (err )
932
937
}
933
938
block := & Block {
934
- Block : comettypes.Block {
935
- Header : tmblock .Header ,
936
- Data : tmblock .Data ,
937
- Evidence : tmblock .Evidence ,
938
- LastCommit : tmblock .LastCommit ,
939
+ Header : comettypes.Header {
940
+ ChainID : idxblock .ChainID ,
941
+ Height : idxblock .Height ,
942
+ Time : idxblock .Time ,
943
+ ProposerAddress : []byte (idxblock .ProposerAddress ),
944
+ LastBlockID : comettypes.BlockID {
945
+ Hash : []byte (idxblock .LastBlockHash ),
946
+ },
939
947
},
940
- Hash : types .HexBytes (tmblock .Hash ()),
948
+ Hash : idxblock .Hash ,
949
+ TxCount : txcount ,
941
950
}
942
951
data , err := json .Marshal (block )
943
952
if err != nil {
@@ -961,18 +970,29 @@ func (a *API) chainBlockByHashHandler(_ *apirest.APIdata, ctx *httprouter.HTTPCo
961
970
if err != nil {
962
971
return err
963
972
}
964
- tmblock := a .vocapp .GetBlockByHash (hash )
965
- if tmblock == nil {
966
- return ErrBlockNotFound
973
+ idxblock , err := a .indexer .BlockByHash (hash )
974
+ if err != nil {
975
+ if errors .Is (err , indexer .ErrBlockNotFound ) {
976
+ return ErrBlockNotFound
977
+ }
978
+ return ErrBlockNotFound .WithErr (err )
979
+ }
980
+ txcount , err := a .indexer .CountTransactionsByHeight (idxblock .Height )
981
+ if err != nil {
982
+ return ErrIndexerQueryFailed .WithErr (err )
967
983
}
968
984
block := & Block {
969
- Block : comettypes.Block {
970
- Header : tmblock .Header ,
971
- Data : tmblock .Data ,
972
- Evidence : tmblock .Evidence ,
973
- LastCommit : tmblock .LastCommit ,
985
+ Header : comettypes.Header {
986
+ ChainID : idxblock .ChainID ,
987
+ Height : idxblock .Height ,
988
+ Time : idxblock .Time ,
989
+ ProposerAddress : []byte (idxblock .ProposerAddress ),
990
+ LastBlockID : comettypes.BlockID {
991
+ Hash : []byte (idxblock .LastBlockHash ),
992
+ },
974
993
},
975
- Hash : types .HexBytes (tmblock .Hash ()),
994
+ Hash : idxblock .Hash ,
995
+ TxCount : txcount ,
976
996
}
977
997
data , err := json .Marshal (block )
978
998
if err != nil {
@@ -1015,39 +1035,7 @@ func (a *API) chainBlockListHandler(_ *apirest.APIdata, ctx *httprouter.HTTPCont
1015
1035
//
1016
1036
// Errors returned are always of type APIerror.
1017
1037
func (a * API ) sendBlockList (ctx * httprouter.HTTPContext , params * BlockParams ) error {
1018
- // TODO: replace this by a.indexer.BlockList when it's available
1019
- blockList := func (limit , offset int , _ , _ , _ string ) ([]* indexertypes.Block , uint64 , error ) {
1020
- if offset < 0 {
1021
- return nil , 0 , fmt .Errorf ("invalid value: offset cannot be %d" , offset )
1022
- }
1023
- if limit <= 0 {
1024
- return nil , 0 , fmt .Errorf ("invalid value: limit cannot be %d" , limit )
1025
- }
1026
- height := a .vocapp .Height ()
1027
- total := uint64 (height ) - uint64 (a .vocapp .Node .BlockStore ().Base ())
1028
- start := height - uint32 (params .Page * params .Limit )
1029
- end := start - uint32 (params .Limit )
1030
- list := []* indexertypes.Block {}
1031
- for h := start ; h > end ; h -- {
1032
- tmblock := a .vocapp .GetBlockByHeight (int64 (h ))
1033
- if tmblock == nil {
1034
- break
1035
- }
1036
- list = append (list , & indexertypes.Block {
1037
- ChainID : tmblock .ChainID ,
1038
- Height : tmblock .Height ,
1039
- Time : tmblock .Time ,
1040
- Hash : types .HexBytes (tmblock .Hash ()),
1041
- ProposerAddress : tmblock .ProposerAddress .Bytes (),
1042
- LastBlockHash : tmblock .LastBlockID .Hash .Bytes (),
1043
- TxCount : int64 (len (tmblock .Txs )),
1044
- })
1045
- }
1046
-
1047
- return list , uint64 (total ), nil
1048
- }
1049
-
1050
- blocks , total , err := blockList (
1038
+ blocks , total , err := a .indexer .BlockList (
1051
1039
params .Limit ,
1052
1040
params .Page * params .Limit ,
1053
1041
params .ChainID ,
@@ -1401,7 +1389,7 @@ func parseTransfersParams(paramPage, paramLimit, paramAccountId, paramAccountIdF
1401
1389
}
1402
1390
1403
1391
// parseTransactionParams returns an TransactionParams filled with the passed params
1404
- func parseTransactionParams (paramPage , paramLimit , paramHeight , paramType string ) (* TransactionParams , error ) {
1392
+ func parseTransactionParams (paramPage , paramLimit , paramHeight , paramType , paramSubtype , paramSigner string ) (* TransactionParams , error ) {
1405
1393
pagination , err := parsePaginationParams (paramPage , paramLimit )
1406
1394
if err != nil {
1407
1395
return nil , err
@@ -1416,6 +1404,8 @@ func parseTransactionParams(paramPage, paramLimit, paramHeight, paramType string
1416
1404
PaginationParams : pagination ,
1417
1405
Height : uint64 (height ),
1418
1406
Type : paramType ,
1407
+ Subtype : paramSubtype ,
1408
+ Signer : paramSigner ,
1419
1409
}, nil
1420
1410
}
1421
1411
0 commit comments