Commit 1394bb36 authored by hezhengjun's avatar hezhengjun

add bep20 deploy tool

parent 0728e1aa
......@@ -6,6 +6,7 @@ import (
"math/big"
"strings"
bep20 "github.com/33cn/plugin/plugin/dapp/cross2eth/contracts/bep20/generated"
"github.com/33cn/plugin/plugin/dapp/cross2eth/contracts/contracts4eth/generated"
erc20 "github.com/33cn/plugin/plugin/dapp/cross2eth/contracts/erc20/generated"
tetherUSDT "github.com/33cn/plugin/plugin/dapp/cross2eth/contracts/usdt/generated"
......@@ -31,6 +32,86 @@ import (
./boss4x ethereum offline send -f deploysigntxs.txt
*/
func DeployBEP20Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "deploy_bep20",
Short: "deploy BEP20 contracts",
Run: DeployBEP20,
}
DeployBEP20Flags(cmd)
return cmd
}
func DeployBEP20Flags(cmd *cobra.Command) {
cmd.Flags().StringP("deployAddr", "a", "", "addr to deploy contract ")
_ = cmd.MarkFlagRequired("deployAddr")
cmd.Flags().StringP("owner", "o", "", "owner address")
_ = cmd.MarkFlagRequired("owner")
cmd.Flags().StringP("symbol", "s", "", "BEP20 symbol")
_ = cmd.MarkFlagRequired("symbol")
cmd.Flags().StringP("totalSupply", "m", "0", "total supply")
_ = cmd.MarkFlagRequired("totalSupply")
cmd.Flags().IntP("decimal", "d", 8, "decimal")
_ = cmd.MarkFlagRequired("decimal")
}
func DeployBEP20(cmd *cobra.Command, _ []string) {
url, _ := cmd.Flags().GetString("rpc_laddr_ethereum")
deployerAddr, _ := cmd.Flags().GetString("deployAddr")
owner, _ := cmd.Flags().GetString("owner")
symbol, _ := cmd.Flags().GetString("symbol")
totalSupply, _ := cmd.Flags().GetString("totalSupply")
decimal, _ := cmd.Flags().GetInt("decimal")
bnAmount := big.NewInt(1)
bnAmount, _ = bnAmount.SetString(utils.TrimZeroAndDot(totalSupply), 10)
client, err := ethclient.Dial(url)
if err != nil {
fmt.Println("ethclient Dial error", err.Error())
return
}
symbol = strings.ToUpper(symbol)
ctx := context.Background()
startNonce, err := client.PendingNonceAt(ctx, common.HexToAddress(deployerAddr))
if nil != err {
fmt.Println("PendingNonceAt error", err.Error())
return
}
var infos []*DeployInfo
parsed, err := abi.JSON(strings.NewReader(bep20.BEP20TokenABI))
if err != nil {
fmt.Println("abi.JSON(strings.NewReader(erc20.ERC20ABI)) error", err.Error())
return
}
bin := common.FromHex(bep20.BEP20TokenBin)
BEP20OwnerAddr := common.HexToAddress(owner)
//constructor (string memory name_, string memory symbol_,uint256 totalSupply_, uint8 decimals_, address owner_) public {
tokenName := symbol + " Token"
packdata, err := parsed.Pack("", tokenName, symbol, bnAmount, uint8(decimal), BEP20OwnerAddr)
if err != nil {
fmt.Println("Pack error", err.Error())
return
}
BEP20Addr := crypto.CreateAddress(common.HexToAddress(deployerAddr), startNonce)
deployInfo := DeployInfo{
PackData: append(bin, packdata...),
ContractorAddr: BEP20Addr,
Name: "BEP20: " + symbol,
Nonce: startNonce,
To: nil,
}
infos = append(infos, &deployInfo)
fileName := fmt.Sprintf("deployBEP20%s.txt", symbol)
err = NewTxWrite(infos, common.HexToAddress(deployerAddr), url, fileName)
if err != nil {
fmt.Println("NewTxWrite error", err.Error())
return
}
}
func DeployERC20Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "create_erc20",
......
......@@ -34,6 +34,7 @@ func DeployOfflineContractsCmd() *cobra.Command {
CreateCmd(), //构造交易
CreateWithFileCmd(),
DeployERC20Cmd(),
DeployBEP20Cmd(),
DeployTetherUSDTCmd(),
//CreateCfgAccountTxCmd(), // set_offline_addr 设置离线多签地址
//SetupCmd(),
......
......@@ -352,14 +352,24 @@ contract BEP20Token is Context, IBEP20, Ownable {
string private _symbol;
string private _name;
constructor() public {
_name = "BUSD Token";
_symbol = "BUSD";
_decimals = 18;
_totalSupply = 31000000000000000000000000;
_balances[msg.sender] = _totalSupply;
emit Transfer(address(0), msg.sender, _totalSupply);
// constructor() public {
// _name = "BUSD Token";
// _symbol = "BUSD";
// _decimals = 18;
// _totalSupply = 31000000000000000000000000;
// _balances[msg.sender] = _totalSupply;
//
// emit Transfer(address(0), msg.sender, _totalSupply);
// }
constructor (string memory name_, string memory symbol_,uint256 totalSupply_, uint8 decimals_, address owner_) public {
_name = name_;
_symbol = symbol_;
_decimals = decimals_;
_totalSupply = totalSupply_;
_balances[owner_] = totalSupply_;
emit Transfer(address(0), owner_, totalSupply_);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment