Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ListSettlementCmd = &cmds.Command{ Helptext: cmds.HelpText{ Tagline: "list all settlements.", }, RunTimeout: 5 * time.Minute, Options: []cmds.Option{ cmds.StringOption(tokencfg.TokenTypeName, "tk", "file storage with token type,default WBTT, other TRX/USDD/USDT.").WithDefault("WBTT"), }, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { err := utils.CheckSimpleMode(env) if err != nil { return err } tokenStr := req.Options[tokencfg.TokenTypeName].(string) token, bl := tokencfg.MpTokenAddr[tokenStr] if !bl { return errors.New("your input token is none. ") } settlementsSent, err := chain.SettleObject.SwapService.SettlementsSent(token) if err != nil { return err } settlementsReceived, err := chain.SettleObject.SwapService.SettlementsReceived(token) if err != nil { return err } totalReceived := big.NewInt(0) totalReceivedCashed := big.NewInt(0) totalSent := big.NewInt(0) settlementResponses := make(map[string]settlementResponse) for a, b := range settlementsSent { settlementResponses[a] = settlementResponse{ Peer: a, SettlementSent: b, SettlementReceived: big.NewInt(0), } totalSent.Add(b, totalSent) } for a, b := range settlementsReceived { if _, ok := settlementResponses[a]; ok { t := settlementResponses[a] t.SettlementReceived = b settlementResponses[a] = t } else { settlementResponses[a] = settlementResponse{ Peer: a, SettlementSent: big.NewInt(0), SettlementReceived: b, } } totalReceived.Add(b, totalReceived) if has, err := chain.SettleObject.SwapService.HasCashoutAction(context.Background(), a, token); err == nil && has { totalReceivedCashed.Add(b, totalReceivedCashed) } } settlementResponsesArray := make([]settlementResponse, len(settlementResponses)) i := 0 for k := range settlementResponses { settlementResponsesArray[i] = settlementResponses[k] i++ } totalPaidOut, err := chain.SettleObject.VaultService.TotalPaidOut(context.Background(), token) if err != nil { return err } rsp := settlementsResponse{ TotalSettlementReceived: totalReceived, TotalSettlementSent: totalSent, SettlementReceivedCashed: totalReceivedCashed, SettlementSentCashed: totalPaidOut, Settlements: settlementResponsesArray, } return cmds.EmitOnce(res, &rsp) }, Type: &settlementsResponse{}, }
View Source
var PeerSettlementCmd = &cmds.Command{ Helptext: cmds.HelpText{ Tagline: "Get chequebook balance.", }, RunTimeout: 5 * time.Minute, Arguments: []cmds.Argument{ cmds.StringArg("peer-id", true, false, "Peer id."), }, Options: []cmds.Option{ cmds.StringOption(tokencfg.TokenTypeName, "tk", "file storage with token type,default WBTT, other TRX/USDD/USDT.").WithDefault("WBTT"), }, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { err := utils.CheckSimpleMode(env) if err != nil { return err } peerID := req.Arguments[0] peerexists := false tokenStr := req.Options[tokencfg.TokenTypeName].(string) token, bl := tokencfg.MpTokenAddr[tokenStr] if !bl { return errors.New("your input token is none. ") } received, err := chain.SettleObject.SwapService.TotalReceived(peerID, token) if err != nil { if !errors.Is(err, settlement.ErrPeerNoSettlements) { return err } else { received = big.NewInt(0) } } if err == nil { peerexists = true } sent, err := chain.SettleObject.SwapService.TotalSent(peerID, token) if err != nil { if !errors.Is(err, settlement.ErrPeerNoSettlements) { return err } else { sent = big.NewInt(0) } } if err == nil { peerexists = true } if !peerexists { return fmt.Errorf("can not get settlements for peer:%s", peerID) } rsp := settlementResponse{ Peer: peerID, SettlementReceived: received, SettlementSent: sent, } return cmds.EmitOnce(res, &rsp) }, Type: &settlementResponse{}, }
View Source
var SettlementCmd = &cmds.Command{ Helptext: cmds.HelpText{ Tagline: "Interact with chequebook services on BTFS.", }, Subcommands: map[string]*cmds.Command{ "list": ListSettlementCmd, "peer": PeerSettlementCmd, }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.