-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'pre_v2.3.0_union_logic' into pre_v2.3.0_union
- Loading branch information
Showing
8 changed files
with
197 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package bttc | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"github.com/bittorrent/go-btfs/chain/tokencfg" | ||
"io" | ||
"math/big" | ||
"time" | ||
|
||
cmds "github.com/bittorrent/go-btfs-cmds" | ||
"github.com/bittorrent/go-btfs/chain" | ||
"github.com/bittorrent/go-btfs/utils" | ||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
type BttcSendTokenToCmdRet struct { | ||
Hash string `json:"hash"` | ||
} | ||
|
||
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) { | ||
addressStr := req.Arguments[0] | ||
if !common.IsHexAddress(addressStr) { | ||
return fmt.Errorf("invalid bttc address %s", addressStr) | ||
} | ||
|
||
tokenStr := req.Options[tokencfg.TokenTypeName].(string) | ||
fmt.Printf("... token:%+v\n", tokenStr) | ||
_, 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 | ||
}), | ||
}, | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package cheque | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"github.com/bittorrent/go-btfs/chain/tokencfg" | ||
"io" | ||
"math/big" | ||
"time" | ||
|
||
cmds "github.com/bittorrent/go-btfs-cmds" | ||
"github.com/bittorrent/go-btfs/chain" | ||
"github.com/ethereum/go-ethereum/common" | ||
"golang.org/x/net/context" | ||
) | ||
|
||
var ChequeAllTokenBalanceCmd = &cmds.Command{ | ||
Helptext: cmds.HelpText{ | ||
Tagline: "Get all token balance by addr.", | ||
}, | ||
Arguments: []cmds.Argument{ | ||
cmds.StringArg("addr", true, false, "bttc account address"), | ||
}, | ||
RunTimeout: 5 * time.Minute, | ||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { | ||
addr := req.Arguments[0] | ||
|
||
mp := make(map[string]*big.Int, 0) | ||
for k := range tokencfg.MpTokenAddr { | ||
balance, err := chain.SettleObject.VaultService.TokenBalanceOf(context.Background(), common.HexToAddress(addr), k) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
mp[k] = balance | ||
} | ||
|
||
return cmds.EmitOnce(res, &mp) | ||
}, | ||
Type: &ChequeBttBalanceCmdRet{}, | ||
Encoders: cmds.EncoderMap{ | ||
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *ChequeBttBalanceCmdRet) error { | ||
_, err := fmt.Fprintf(w, "the balance is: %v\n", out.Balance) | ||
return err | ||
}), | ||
}, | ||
} | ||
|
||
var ChequeTokenBalanceCmd = &cmds.Command{ | ||
Helptext: cmds.HelpText{ | ||
Tagline: "Get one token balance by addr.", | ||
}, | ||
Arguments: []cmds.Argument{ | ||
cmds.StringArg("addr", true, false, "bttc account address"), | ||
}, | ||
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 { | ||
addr := req.Arguments[0] | ||
|
||
tokenStr := req.Options[tokencfg.TokenTypeName].(string) | ||
fmt.Printf("... token:%+v\n", tokenStr) | ||
_, bl := tokencfg.MpTokenAddr[tokenStr] | ||
if !bl { | ||
return errors.New("your input token is none. ") | ||
} | ||
|
||
balance, err := chain.SettleObject.VaultService.TokenBalanceOf(context.Background(), common.HexToAddress(addr), tokenStr) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return cmds.EmitOnce(res, &ChequeBttBalanceCmdRet{ | ||
Balance: balance, | ||
}) | ||
}, | ||
Type: &ChequeBttBalanceCmdRet{}, | ||
Encoders: cmds.EncoderMap{ | ||
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *ChequeBttBalanceCmdRet) error { | ||
_, err := fmt.Fprintf(w, "the balance is: %v\n", out.Balance) | ||
return err | ||
}), | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters