Skip to content

Commit

Permalink
Merge pull request #429 from bittorrent/feat/batch-cash
Browse files Browse the repository at this point in the history
feat[cheque]: add command about batch cashing cheque
  • Loading branch information
Shawn-Huang-Tron authored May 23, 2024
2 parents 1605460 + 22326d8 commit f59cbab
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
53 changes: 51 additions & 2 deletions core/commands/cheque/cheque.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package cheque
import (
"errors"
"fmt"
"github.com/bittorrent/go-btfs/chain/tokencfg"
"github.com/bittorrent/go-btfs/utils"
"io"
"math/big"
"time"

"github.com/bittorrent/go-btfs/chain/tokencfg"
"github.com/bittorrent/go-btfs/utils"

cmds "github.com/bittorrent/go-btfs-cmds"
"github.com/bittorrent/go-btfs/chain"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -80,6 +81,7 @@ Vault services include issue cheque to peer, receive cheque and store operations
},
Subcommands: map[string]*cmds.Command{
"cash": CashChequeCmd,
"batch-cash": BatchCashChequeCmd,
"cashstatus": ChequeCashStatusCmd,
"cashlist": ChequeCashListCmd,
"price": StorePriceCmd,
Expand Down Expand Up @@ -257,3 +259,50 @@ var CashChequeCmd = &cmds.Command{
}),
},
}

var BatchCashChequeCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Batch cash the cheques by peerIDs.",
},
Arguments: []cmds.Argument{
cmds.StringArg("peer-ids", true, true, "Peer id tobe cashed."),
},
Options: []cmds.Option{
cmds.StringOption(tokencfg.TokenTypeName, "tk", "file storage with token type,default WBTT, other TRX/USDD/USDT.").WithDefault("WBTT"),
},
RunTimeout: 5 * time.Minute,
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
err := utils.CheckSimpleMode(env)
if err != nil {
return err
}

peerIDs := req.Arguments
tokenStr := req.Options[tokencfg.TokenTypeName].(string)
token, bl := tokencfg.MpTokenAddr[tokenStr]
if !bl {
return errors.New("your input token is none. ")
}

for _, peerID := range peerIDs {
tx_hash, err := chain.SettleObject.SwapService.CashCheque(req.Context, peerID, token)
if err != nil {
return err
}
err = res.Emit(&CashChequeRet{
TxHash: tx_hash.String(),
})
if err != nil {
return err
}
}
return nil
},
Type: CashChequeRet{},
Encoders: cmds.EncoderMap{
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *CashChequeRet) error {
_, err := fmt.Fprintf(w, "the hash of transaction: %s", out.TxHash)
return err
}),
},
}
1 change: 1 addition & 0 deletions core/commands/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ func TestCommands(t *testing.T) {
"/cheque/token_balance",
"/cheque/all_token_balance",
"/cheque/cash",
"/cheque/batch-cash",
"/cheque/cashstatus",
"/cheque/chaininfo",
"/cheque/price",
Expand Down

0 comments on commit f59cbab

Please sign in to comment.