Commit a517c50d authored by hezhengjun's avatar hezhengjun

support decimal set for erc20

parent 51797b6c
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
##编译solidity,并产生bin文件,abi文件,和相应的go文件 ##编译solidity,并产生bin文件,abi文件,和相应的go文件
SRC_BEP := bep20 SRC_BEP := bep20
SRC_ERC20 := erc20
SRC_CONTRACT0 := contracts4chain33 SRC_CONTRACT0 := contracts4chain33
SRC_CONTRACT1 := contracts4eth SRC_CONTRACT1 := contracts4eth
SRC_MULTISIGN := gnosis/safe-contracts/contracts SRC_MULTISIGN := gnosis/safe-contracts/contracts
...@@ -10,6 +11,7 @@ GO_OUT0 := ${SRC_CONTRACT0}/generated ...@@ -10,6 +11,7 @@ GO_OUT0 := ${SRC_CONTRACT0}/generated
GO_OUT1 := ${SRC_CONTRACT1}/generated GO_OUT1 := ${SRC_CONTRACT1}/generated
GO_OUT_MULTISIGN := gnosis/generated GO_OUT_MULTISIGN := gnosis/generated
GO_OUT_BEP20 := bep20/generated GO_OUT_BEP20 := bep20/generated
GO_OUT_ERC20 := erc20/generated
PACKAGE := generated PACKAGE := generated
proj := "build" proj := "build"
...@@ -30,6 +32,9 @@ multisign: ...@@ -30,6 +32,9 @@ multisign:
bep20Bin: bep20Bin:
@abigen --sol $(SRC_BEP)/BEP20.sol --pkg $(PACKAGE) --out $(GO_OUT_BEP20)/bep20.go @abigen --sol $(SRC_BEP)/BEP20.sol --pkg $(PACKAGE) --out $(GO_OUT_BEP20)/bep20.go
erc20Bin:
@abigen --sol $(SRC_ERC20)/ERC20.sol --pkg $(PACKAGE) --out $(GO_OUT_ERC20)/erc20.go
clean: clean:
@rm -fr $(GO_OUT)/* @rm -fr $(GO_OUT)/*
......
...@@ -312,6 +312,8 @@ func DeployERC20Flags(cmd *cobra.Command) { ...@@ -312,6 +312,8 @@ func DeployERC20Flags(cmd *cobra.Command) {
_ = cmd.MarkFlagRequired("symbol") _ = cmd.MarkFlagRequired("symbol")
cmd.Flags().StringP("amount", "m", "0", "amount") cmd.Flags().StringP("amount", "m", "0", "amount")
_ = cmd.MarkFlagRequired("amount") _ = cmd.MarkFlagRequired("amount")
cmd.Flags().Uint8P("decimals", "d", 8, "default set to 8, and can't be greater than 18")
} }
func DeployERC20(cmd *cobra.Command, args []string) { func DeployERC20(cmd *cobra.Command, args []string) {
...@@ -320,12 +322,19 @@ func DeployERC20(cmd *cobra.Command, args []string) { ...@@ -320,12 +322,19 @@ func DeployERC20(cmd *cobra.Command, args []string) {
name, _ := cmd.Flags().GetString("name") name, _ := cmd.Flags().GetString("name")
symbol, _ := cmd.Flags().GetString("symbol") symbol, _ := cmd.Flags().GetString("symbol")
amount, _ := cmd.Flags().GetString("amount") amount, _ := cmd.Flags().GetString("amount")
decimals, _ := cmd.Flags().GetUint8("decimals")
if decimals > 18 {
fmt.Println("decimals can't be greater than 18")
return
}
para := ebTypes.ERC20Token{ para := ebTypes.ERC20Token{
Owner: owner, Owner: owner,
Name: name, Name: name,
Symbol: symbol, Symbol: symbol,
Amount: amount, Amount: amount,
Decimals: int32(decimals),
} }
var res rpctypes.Reply var res rpctypes.Reply
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Manager.DeployERC20", para, &res) ctx := jsonclient.NewRPCCtx(rpcLaddr, "Manager.DeployERC20", para, &res)
......
...@@ -222,6 +222,7 @@ message ERC20Token { ...@@ -222,6 +222,7 @@ message ERC20Token {
string name = 2; string name = 2;
string symbol = 3; string symbol = 3;
string amount = 4; string amount = 4;
int32 decimals = 5;
} }
message ETHTokenLockAddress { message ETHTokenLockAddress {
......
...@@ -332,12 +332,12 @@ func (ethRelayer *Relayer4Ethereum) AddToken2LockList(symbol, token string) (str ...@@ -332,12 +332,12 @@ func (ethRelayer *Relayer4Ethereum) AddToken2LockList(symbol, token string) (str
} }
//DeployERC20 ... //DeployERC20 ...
func (ethRelayer *Relayer4Ethereum) DeployERC20(ownerAddr, name, symbol, amount string) (string, error) { func (ethRelayer *Relayer4Ethereum) DeployERC20(ownerAddr, name, symbol, amount string, decimals uint8) (string, error) {
bn := big.NewInt(1) bn := big.NewInt(1)
bn, _ = bn.SetString(utils.TrimZeroAndDot(amount), 10) bn, _ = bn.SetString(utils.TrimZeroAndDot(amount), 10)
ethRelayer.rwLock.RLock() ethRelayer.rwLock.RLock()
defer ethRelayer.rwLock.RUnlock() defer ethRelayer.rwLock.RUnlock()
return ethtxs.DeployERC20(ownerAddr, name, symbol, bn, ethRelayer.clientSpec, ethRelayer.operatorInfo) return ethtxs.DeployERC20(ownerAddr, name, symbol, bn, decimals, ethRelayer.clientSpec, ethRelayer.operatorInfo)
} }
//ApproveAllowance ... //ApproveAllowance ...
......
...@@ -499,7 +499,7 @@ finished: ...@@ -499,7 +499,7 @@ finished:
return x2EthContracts, deployInfo, nil return x2EthContracts, deployInfo, nil
} }
func DeployERC20(ownerAddr, name, symbol string, amount *big.Int, client ethinterface.EthClientSpec, para *OperatorInfo) (string, error) { func DeployERC20(ownerAddr, name, symbol string, amount *big.Int, decimals uint8, client ethinterface.EthClientSpec, para *OperatorInfo) (string, error) {
if nil == para { if nil == para {
return "", errors.New("no operator private key configured") return "", errors.New("no operator private key configured")
} }
...@@ -523,7 +523,7 @@ func DeployERC20(ownerAddr, name, symbol string, amount *big.Int, client ethinte ...@@ -523,7 +523,7 @@ func DeployERC20(ownerAddr, name, symbol string, amount *big.Int, client ethinte
txslog.Info("DeployERC20", "ownerAddr", ownerAddr, "name", name, "symbol", symbol, "amount", amount, "client", client) txslog.Info("DeployERC20", "ownerAddr", ownerAddr, "name", name, "symbol", symbol, "amount", amount, "client", client)
Erc20OwnerAddr := common.HexToAddress(ownerAddr) Erc20OwnerAddr := common.HexToAddress(ownerAddr)
Erc20Addr, deployTx, _, err := erc20.DeployERC20(operatorAuth, client, name, symbol, amount, Erc20OwnerAddr) Erc20Addr, deployTx, _, err := erc20.DeployERC20(operatorAuth, client, name, symbol, amount, Erc20OwnerAddr, decimals)
if nil != err { if nil != err {
txslog.Error("DeployERC20", "Failed to DeployErc20 with err:", err.Error()) txslog.Error("DeployERC20", "Failed to DeployErc20 with err:", err.Error())
return "", err return "", err
......
...@@ -485,7 +485,7 @@ func (manager *Manager) DeployERC20(Erc20Token relayerTypes.ERC20Token, result * ...@@ -485,7 +485,7 @@ func (manager *Manager) DeployERC20(Erc20Token relayerTypes.ERC20Token, result *
return err return err
} }
Erc20Addr, err := manager.ethRelayer.DeployERC20(Erc20Token.Owner, Erc20Token.Name, Erc20Token.Symbol, Erc20Token.Amount) Erc20Addr, err := manager.ethRelayer.DeployERC20(Erc20Token.Owner, Erc20Token.Name, Erc20Token.Symbol, Erc20Token.Amount, uint8(Erc20Token.Decimals))
if nil != err { if nil != err {
return err return err
} }
......
...@@ -2129,10 +2129,11 @@ type ERC20Token struct { ...@@ -2129,10 +2129,11 @@ type ERC20Token struct {
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
Owner string `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty"` Owner string `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
Symbol string `protobuf:"bytes,3,opt,name=symbol,proto3" json:"symbol,omitempty"` Symbol string `protobuf:"bytes,3,opt,name=symbol,proto3" json:"symbol,omitempty"`
Amount string `protobuf:"bytes,4,opt,name=amount,proto3" json:"amount,omitempty"` Amount string `protobuf:"bytes,4,opt,name=amount,proto3" json:"amount,omitempty"`
Decimals int32 `protobuf:"varint,5,opt,name=decimals,proto3" json:"decimals,omitempty"`
} }
func (x *ERC20Token) Reset() { func (x *ERC20Token) Reset() {
...@@ -2195,6 +2196,13 @@ func (x *ERC20Token) GetAmount() string { ...@@ -2195,6 +2196,13 @@ func (x *ERC20Token) GetAmount() string {
return "" return ""
} }
func (x *ERC20Token) GetDecimals() int32 {
if x != nil {
return x.Decimals
}
return 0
}
type ETHTokenLockAddress struct { type ETHTokenLockAddress struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
...@@ -2568,28 +2576,30 @@ var file_relayer_proto_rawDesc = []byte{ ...@@ -2568,28 +2576,30 @@ var file_relayer_proto_rawDesc = []byte{
0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x4b, 0x65, 0x79, 0x12, 0x2a, 0x0a, 0x10, 0x6f, 0x77, 0x6e, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x4b, 0x65, 0x79, 0x12, 0x2a, 0x0a, 0x10, 0x6f, 0x77, 0x6e,
0x65, 0x72, 0x50, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x4b, 0x65, 0x79, 0x73, 0x18, 0x05, 0x20, 0x65, 0x72, 0x50, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x4b, 0x65, 0x79, 0x73, 0x18, 0x05, 0x20,
0x03, 0x28, 0x09, 0x52, 0x10, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x50, 0x72, 0x69, 0x76, 0x61, 0x74, 0x03, 0x28, 0x09, 0x52, 0x10, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x50, 0x72, 0x69, 0x76, 0x61, 0x74,
0x65, 0x4b, 0x65, 0x79, 0x73, 0x22, 0x66, 0x0a, 0x0a, 0x45, 0x52, 0x43, 0x32, 0x30, 0x54, 0x6f, 0x65, 0x4b, 0x65, 0x79, 0x73, 0x22, 0x82, 0x01, 0x0a, 0x0a, 0x45, 0x52, 0x43, 0x32, 0x30, 0x54,
0x6b, 0x65, 0x6e, 0x12, 0x14, 0x0a, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x14, 0x0a, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x18, 0x01, 0x20,
0x28, 0x09, 0x52, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x01, 0x28, 0x09, 0x52, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61,
0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16,
0x06, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x0a, 0x06, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06,
0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74,
0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x47, 0x0a, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x1a,
0x13, 0x45, 0x54, 0x48, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x4c, 0x6f, 0x63, 0x6b, 0x41, 0x64, 0x64, 0x0a, 0x08, 0x64, 0x65, 0x63, 0x69, 0x6d, 0x61, 0x6c, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05,
0x72, 0x65, 0x73, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x52, 0x08, 0x64, 0x65, 0x63, 0x69, 0x6d, 0x61, 0x6c, 0x73, 0x22, 0x47, 0x0a, 0x13, 0x45, 0x54,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x16, 0x48, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x4c, 0x6f, 0x63, 0x6b, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73,
0x0a, 0x06, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01,
0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x22, 0x89, 0x01, 0x0a, 0x1b, 0x45, 0x54, 0x48, 0x43, 0x6f, 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x73,
0x6e, 0x66, 0x69, 0x67, 0x4c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x4f, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x79, 0x6d,
0x66, 0x66, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x62, 0x6f, 0x6c, 0x22, 0x89, 0x01, 0x0a, 0x1b, 0x45, 0x54, 0x48, 0x43, 0x6f, 0x6e, 0x66, 0x69,
0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x67, 0x4c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x4f, 0x66, 0x66, 0x6c,
0x12, 0x16, 0x0a, 0x06, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x69, 0x6e, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01,
0x52, 0x06, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x68, 0x72, 0x65, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x16, 0x0a,
0x73, 0x68, 0x6f, 0x6c, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x74, 0x68, 0x72, 0x06, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73,
0x65, 0x73, 0x68, 0x6f, 0x6c, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x65, 0x72, 0x63, 0x65, 0x6e, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x68, 0x72, 0x65, 0x73, 0x68, 0x6f,
0x74, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x70, 0x65, 0x72, 0x63, 0x65, 0x6e, 0x6c, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x74, 0x68, 0x72, 0x65, 0x73, 0x68,
0x74, 0x73, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x62, 0x06, 0x6f, 0x6c, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x65, 0x72, 0x63, 0x65, 0x6e, 0x74, 0x73, 0x18,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x70, 0x65, 0x72, 0x63, 0x65, 0x6e, 0x74, 0x73, 0x42,
0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x33,
} }
var ( var (
......
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