-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
121 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
*.dylib | ||
*.abi | ||
*.bin | ||
/cmd/issueToken/issueToken | ||
|
||
# IDEs | ||
/.idea | ||
|
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,119 @@ | ||
/* | ||
* Copyright (c) 2018 Dabank | ||
* Use of this work is governed by a MIT License. | ||
* You may find a license copy under project root. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"encoding/hex" | ||
"flag" | ||
"fmt" | ||
"math/big" | ||
"os" | ||
"strings" | ||
|
||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
|
||
"github.com/ethereum/go-ethereum/ethclient" | ||
|
||
"math" | ||
|
||
"github.com/dabankio/TokenIssuer" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
) | ||
|
||
var ( | ||
rpcURL string | ||
name string | ||
symbol string | ||
totalSupply uint64 | ||
decimals uint64 | ||
owner string | ||
prikeyStr string | ||
) | ||
|
||
func init() { | ||
flag.StringVar(&rpcURL, "rpc", "https://mainnet.infura.io", "Ethereum RPC endpoint") | ||
flag.StringVar(&name, "name", "My Lovely Token", "token Name") | ||
flag.StringVar(&symbol, "symbol", "MLT", "token symbol") | ||
flag.Uint64Var(&totalSupply, "total", 42, "initial supply for token") | ||
flag.StringVar(&owner, "owner", "", "owner of token, default to message sender") | ||
flag.Uint64Var(&decimals, "decimals", 6, "decimals of token") | ||
flag.StringVar(&prikeyStr, "prikey", "", "prikey of message sender") | ||
} | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
var err error | ||
defer func() { | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
}() | ||
|
||
if decimals > math.MaxUint8 { | ||
err = fmt.Errorf("decimals should be less than 255, got %v", decimals) | ||
return | ||
} | ||
if totalSupply > math.MaxInt64 { | ||
err = fmt.Errorf("total should be less than 9223372036854775807") | ||
return | ||
} | ||
|
||
bigTotalSupply := new(big.Int). | ||
Mul(big.NewInt(int64(totalSupply)), | ||
new(big.Int).Exp(big.NewInt(10), big.NewInt(int64(decimals)), nil)) | ||
|
||
prikeyStr = strings.TrimLeft(prikeyStr, "0x") | ||
prikeyStr = strings.TrimLeft(prikeyStr, "0X") | ||
|
||
prikeyBytes, err := hex.DecodeString(prikeyStr) | ||
if err != nil { | ||
err = fmt.Errorf("can not decode prikey from hex: %v", err) | ||
return | ||
} | ||
|
||
prikey, err := crypto.ToECDSA(prikeyBytes) | ||
if err != nil { | ||
err = fmt.Errorf("can not convert prikey to ECDSA: %v", err) | ||
return | ||
} | ||
|
||
var ownerAddr common.Address | ||
if len(owner) == 0 { | ||
ownerAddr = crypto.PubkeyToAddress(prikey.PublicKey) | ||
} else { | ||
ownerAddr = common.HexToAddress(owner) | ||
if strings.ToLower(ownerAddr.Hex()) != strings.ToLower(owner) { | ||
err = fmt.Errorf("invalid owner input") | ||
return | ||
} | ||
} | ||
|
||
coon, err := ethclient.Dial(rpcURL) | ||
if err != nil { | ||
err = fmt.Errorf("can not dial Ethereum RPC: %v", err) | ||
return | ||
} | ||
|
||
opts := bind.NewKeyedTransactor(prikey) | ||
|
||
tokenAddr, tx, _, err := TokenIssuer.DeployToken(opts, coon, name, symbol, ownerAddr, bigTotalSupply, uint8(decimals)) | ||
if err != nil { | ||
err = fmt.Errorf("deploy failed: %v", err) | ||
return | ||
} | ||
|
||
fmt.Printf(`Congradulations! Your %s(%s) will be addressed at | ||
%s | ||
after tx %s is mined. :) | ||
`, name, symbol, | ||
tokenAddr.Hex(), | ||
tx.Hash().Hex()) | ||
} |
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