Skip to content

Commit

Permalink
fix 根据币种查询交易记录
Browse files Browse the repository at this point in the history
Fixed #63
  • Loading branch information
xuyz committed Dec 25, 2018
1 parent 6d40025 commit d57a6e7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion plugins/transfer/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 8 additions & 1 deletion plugins/transfer/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d57a6e7

Please sign in to comment.