Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat[cheque]: add command about batch cashing cheque #429

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading