bttc

package
v0.0.0-...-c0cc0bc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2024 License: Apache-2.0, MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BttcBtt2WbttCmd = &cmds.Command{
	Helptext: cmds.HelpText{
		Tagline: "Swap BTT to WBTT at you bttc address",
	},
	Arguments: []cmds.Argument{
		cmds.StringArg("amount", true, false, "amount you want to swap"),
	},
	RunTimeout: 5 * time.Minute,
	Type:       &BttcBtt2WbttCmdRet{},
	Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) (err error) {
		err = utils.CheckSimpleMode(env)
		if err != nil {
			return err
		}

		amountStr := utils.RemoveSpaceAndComma(req.Arguments[0])
		amount, ok := new(big.Int).SetString(amountStr, 10)
		if !ok {
			return fmt.Errorf("invalid argument amount %s", req.Arguments[0])
		}
		trx, err := chain.SettleObject.BttcService.SwapBtt2Wbtt(context.Background(), amount)
		if err != nil {
			return
		}
		return cmds.EmitOnce(res, &BttcBtt2WbttCmdRet{Hash: trx.String()})
	},
	Encoders: cmds.EncoderMap{
		cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *BttcBtt2WbttCmdRet) error {
			_, err := fmt.Fprintf(w, "the hash of transaction: %s\n", out.Hash)
			return err
		}),
	},
}
View Source
var BttcCmd = &cmds.Command{
	Helptext: cmds.HelpText{
		Tagline: "Interact with bttc related services.",
	},
	Subcommands: map[string]*cmds.Command{
		"btt2wbtt":      BttcBtt2WbttCmd,
		"wbtt2btt":      BttcWbtt2BttCmd,
		"send-btt-to":   BttcSendBttToCmd,
		"send-wbtt-to":  BttcSendWbttToCmd,
		"send-token-to": BttcSendTokenToCmd,
	},
}
View Source
var BttcSendBttToCmd = &cmds.Command{
	Helptext: cmds.HelpText{
		Tagline: "Transfer your BTT to other bttc address",
	},
	Arguments: []cmds.Argument{
		cmds.StringArg("addr", true, false, "target bttc address"),
		cmds.StringArg("amount", true, false, "amount you want to send"),
	},
	RunTimeout: 5 * time.Minute,
	Type:       &BttcSendBttToCmdRet{},
	Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) (err error) {
		err = utils.CheckSimpleMode(env)
		if err != nil {
			return err
		}

		addressStr := req.Arguments[0]
		if !common.IsHexAddress(addressStr) {
			return fmt.Errorf("invalid bttc address %s", addressStr)
		}
		amount, ok := new(big.Int).SetString(utils.RemoveSpaceAndComma(req.Arguments[1]), 10)
		if !ok {
			return fmt.Errorf("invalid argument amount %s", req.Arguments[1])
		}
		trx, err := chain.SettleObject.BttcService.SendBttTo(context.Background(), common.HexToAddress(addressStr), amount)
		if err != nil {
			return
		}
		return cmds.EmitOnce(res, &BttcSendBttToCmdRet{Hash: trx.String()})
	},
	Encoders: cmds.EncoderMap{
		cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *BttcSendBttToCmdRet) error {
			_, err := fmt.Fprintf(w, "the hash of transaction: %s\n", out.Hash)
			return err
		}),
	},
}
View Source
var BttcSendTokenToCmd = &cmds.Command{
	Helptext: cmds.HelpText{
		Tagline: "Transfer your WBTT to other bttc address",
	},
	Arguments: []cmds.Argument{
		cmds.StringArg("addr", true, false, "target bttc address"),
		cmds.StringArg("amount", true, false, "amount you want to send"),
	},
	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,
	Type:       &BttcSendTokenToCmdRet{},
	Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) (err error) {
		err = utils.CheckSimpleMode(env)
		if err != nil {
			return err
		}

		addressStr := req.Arguments[0]
		if !common.IsHexAddress(addressStr) {
			return fmt.Errorf("invalid bttc address %s", addressStr)
		}

		tokenStr := req.Options[tokencfg.TokenTypeName].(string)

		_, bl := tokencfg.MpTokenAddr[tokenStr]
		if !bl {
			return errors.New("your input token is none. ")
		}

		amount, ok := new(big.Int).SetString(utils.RemoveSpaceAndComma(req.Arguments[1]), 10)
		if !ok {
			return fmt.Errorf("invalid argument amount %s", req.Arguments[1])
		}

		trx, err := chain.SettleObject.BttcService.SendTokenTo(context.Background(), common.HexToAddress(addressStr), amount, tokenStr)
		if err != nil {
			return
		}

		return cmds.EmitOnce(res, &BttcSendTokenToCmdRet{Hash: trx.String()})
	},
	Encoders: cmds.EncoderMap{
		cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *BttcSendTokenToCmdRet) error {
			_, err := fmt.Fprintf(w, "the hash of transaction: %s\n", out.Hash)
			return err
		}),
	},
}
View Source
var BttcSendWbttToCmd = &cmds.Command{
	Helptext: cmds.HelpText{
		Tagline: "Transfer your WBTT to other bttc address",
	},
	Arguments: []cmds.Argument{
		cmds.StringArg("addr", true, false, "target bttc address"),
		cmds.StringArg("amount", true, false, "amount you want to send"),
	},
	RunTimeout: 5 * time.Minute,
	Type:       &BttcSendWbttToCmdRet{},
	Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) (err error) {
		err = utils.CheckSimpleMode(env)
		if err != nil {
			return err
		}

		addressStr := req.Arguments[0]
		if !common.IsHexAddress(addressStr) {
			return fmt.Errorf("invalid bttc address %s", addressStr)
		}
		amount, ok := new(big.Int).SetString(utils.RemoveSpaceAndComma(req.Arguments[1]), 10)
		if !ok {
			return fmt.Errorf("invalid argument amount %s", req.Arguments[1])
		}
		trx, err := chain.SettleObject.BttcService.SendWbttTo(context.Background(), common.HexToAddress(addressStr), amount)
		if err != nil {
			return
		}
		return cmds.EmitOnce(res, &BttcSendWbttToCmdRet{Hash: trx.String()})
	},
	Encoders: cmds.EncoderMap{
		cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *BttcSendWbttToCmdRet) error {
			_, err := fmt.Fprintf(w, "the hash of transaction: %s\n", out.Hash)
			return err
		}),
	},
}
View Source
var BttcWbtt2BttCmd = &cmds.Command{
	Helptext: cmds.HelpText{
		Tagline: "Swap WBTT to BTT at you bttc address",
	},
	Arguments: []cmds.Argument{
		cmds.StringArg("amount", true, false, "amount you want to swap"),
	},
	RunTimeout: 5 * time.Minute,
	Type:       &BttcWbtt2BttCmdRet{},
	Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) (err error) {
		err = utils.CheckSimpleMode(env)
		if err != nil {
			return err
		}

		amountStr := utils.RemoveSpaceAndComma(req.Arguments[0])
		amount, ok := new(big.Int).SetString(amountStr, 10)
		if !ok {
			return fmt.Errorf("invalid argument amount %s", req.Arguments[0])
		}
		trx, err := chain.SettleObject.BttcService.SwapWbtt2Btt(context.Background(), amount)
		if err != nil {
			return
		}
		return cmds.EmitOnce(res, &BttcWbtt2BttCmdRet{Hash: trx.String()})
	},
	Encoders: cmds.EncoderMap{
		cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *BttcWbtt2BttCmdRet) error {
			_, err := fmt.Fprintf(w, "the hash of transaction: %s\n", out.Hash)
			return err
		}),
	},
}

Functions

This section is empty.

Types

type BttcBtt2WbttCmdRet

type BttcBtt2WbttCmdRet struct {
	Hash string `json:"hash"`
}

type BttcSendBttToCmdRet

type BttcSendBttToCmdRet struct {
	Hash string `json:"hash"`
}

type BttcSendTokenToCmdRet

type BttcSendTokenToCmdRet struct {
	Hash string `json:"hash"`
}

type BttcSendWbttToCmdRet

type BttcSendWbttToCmdRet struct {
	Hash string `json:"hash"`
}

type BttcWbtt2BttCmdRet

type BttcWbtt2BttCmdRet struct {
	Hash string `json:"hash"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL