From d57a6e777b687ef5ca331d10e1cbed3c3c40c749 Mon Sep 17 00:00:00 2001 From: xutao Date: Tue, 25 Dec 2018 12:22:38 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E6=A0=B9=E6=8D=AE=E5=B8=81=E7=A7=8D?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E4=BA=A4=E6=98=93=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed #63 --- plugins/transfer/handler.go | 3 ++- plugins/transfer/service.go | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/plugins/transfer/handler.go b/plugins/transfer/handler.go index 8e3f3e3..f21769b 100644 --- a/plugins/transfer/handler.go +++ b/plugins/transfer/handler.go @@ -23,6 +23,7 @@ func TransferGin() gin.HandlerFunc { //chainID := c.Param("chainId") address := c.Param("address") offset, limit := int64(0), int64(20) + coin := c.Query("coin") if d, err := strconv.ParseInt(c.Param("offset"), 10, 64); err == nil { offset = d @@ -32,7 +33,7 @@ func TransferGin() gin.HandlerFunc { limit = d } - txs, err := ListByAddress(address, offset, limit) + txs, err := ListByAddress(address, offset, limit, &SearchOpt{Coin: coin}) if err != nil { c.JSON(http.StatusOK, types.RPCInternalError("", err)) return diff --git a/plugins/transfer/service.go b/plugins/transfer/service.go index d2c89f6..485c2ca 100644 --- a/plugins/transfer/service.go +++ b/plugins/transfer/service.go @@ -37,11 +37,18 @@ func converToTxTransfer(mtt model.TxTransfer) TxTransfer { } } -func ListByAddress(address string, offset, limint int64) ([]TxTransfer, error) { +type SearchOpt struct { + Coin string +} + +func ListByAddress(address string, offset, limint int64, opt *SearchOpt) ([]TxTransfer, error) { var res []TxTransfer var wheres []string wheres = append(wheres, fmt.Sprintf(" %s = '%s' ", "address", address)) + if opt.Coin != "" { + wheres = append(wheres, fmt.Sprintf(" %s = '%s' ", "coin", opt.Coin)) + } mtts, err := model.TxTransferFilter(db.Db, strings.Join(wheres, " and "), " order by time desc ", offset, limint) if err != nil {