Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
a517c50d
Commit
a517c50d
authored
Dec 08, 2021
by
hezhengjun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support decimal set for erc20
parent
51797b6c
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
56 additions
and
29 deletions
+56
-29
Makefile
plugin/dapp/cross2eth/contracts/Makefile
+5
-0
ERC20.sol
plugin/dapp/cross2eth/contracts/erc20/ERC20.sol
+4
-2
erc20.go
plugin/dapp/cross2eth/contracts/erc20/generated/erc20.go
+0
-0
ethereumRelayerCmd.go
plugin/dapp/cross2eth/ebcli/ethereumRelayerCmd.go
+9
-0
relayer.proto
plugin/dapp/cross2eth/ebrelayer/proto/relayer.proto
+1
-0
ethereum.go
plugin/dapp/cross2eth/ebrelayer/relayer/ethereum/ethereum.go
+2
-2
deploy.go
...app/cross2eth/ebrelayer/relayer/ethereum/ethtxs/deploy.go
+2
-2
manager.go
plugin/dapp/cross2eth/ebrelayer/relayer/manager.go
+1
-1
relayer.pb.go
plugin/dapp/cross2eth/ebrelayer/types/relayer.pb.go
+32
-22
No files found.
plugin/dapp/cross2eth/contracts/Makefile
View file @
a517c50d
...
...
@@ -2,6 +2,7 @@
##编译solidity,并产生bin文件,abi文件,和相应的go文件
SRC_BEP
:=
bep20
SRC_ERC20
:=
erc20
SRC_CONTRACT0
:=
contracts4chain33
SRC_CONTRACT1
:=
contracts4eth
SRC_MULTISIGN
:=
gnosis/safe-contracts/contracts
...
...
@@ -10,6 +11,7 @@ GO_OUT0 := ${SRC_CONTRACT0}/generated
GO_OUT1
:=
${
SRC_CONTRACT1
}
/generated
GO_OUT_MULTISIGN
:=
gnosis/generated
GO_OUT_BEP20
:=
bep20/generated
GO_OUT_ERC20
:=
erc20/generated
PACKAGE
:=
generated
proj
:=
"build"
...
...
@@ -30,6 +32,9 @@ multisign:
bep20Bin
:
@
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
:
@
rm
-fr
$(GO_OUT)
/
*
...
...
plugin/dapp/cross2eth/contracts/erc20/ERC20.sol
View file @
a517c50d
...
...
@@ -15,6 +15,7 @@ contract ERC20 is Context, IERC20 {
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for {name} and {symbol}.
...
...
@@ -25,10 +26,11 @@ contract ERC20 is Context, IERC20 {
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name_, string memory symbol_,uint256 supply, address owner
) {
constructor (string memory name_, string memory symbol_,uint256 supply, address owner
, uint8 decimals_) {
_name = name_;
_symbol = symbol_;
_totalSupply=supply;
_decimals = decimals_;
_balances[owner] = supply;
}
...
...
@@ -61,7 +63,7 @@ contract ERC20 is Context, IERC20 {
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual returns (uint8) {
return
8;
return
_decimals;
}
/**
...
...
plugin/dapp/cross2eth/contracts/erc20/generated/
ERC
20.go
→
plugin/dapp/cross2eth/contracts/erc20/generated/
erc
20.go
View file @
a517c50d
This diff is collapsed.
Click to expand it.
plugin/dapp/cross2eth/ebcli/ethereumRelayerCmd.go
View file @
a517c50d
...
...
@@ -312,6 +312,8 @@ func DeployERC20Flags(cmd *cobra.Command) {
_
=
cmd
.
MarkFlagRequired
(
"symbol"
)
cmd
.
Flags
()
.
StringP
(
"amount"
,
"m"
,
"0"
,
"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
)
{
...
...
@@ -320,12 +322,19 @@ func DeployERC20(cmd *cobra.Command, args []string) {
name
,
_
:=
cmd
.
Flags
()
.
GetString
(
"name"
)
symbol
,
_
:=
cmd
.
Flags
()
.
GetString
(
"symbol"
)
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
{
Owner
:
owner
,
Name
:
name
,
Symbol
:
symbol
,
Amount
:
amount
,
Decimals
:
int32
(
decimals
),
}
var
res
rpctypes
.
Reply
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"Manager.DeployERC20"
,
para
,
&
res
)
...
...
plugin/dapp/cross2eth/ebrelayer/proto/relayer.proto
View file @
a517c50d
...
...
@@ -222,6 +222,7 @@ message ERC20Token {
string
name
=
2
;
string
symbol
=
3
;
string
amount
=
4
;
int32
decimals
=
5
;
}
message
ETHTokenLockAddress
{
...
...
plugin/dapp/cross2eth/ebrelayer/relayer/ethereum/ethereum.go
View file @
a517c50d
...
...
@@ -332,12 +332,12 @@ func (ethRelayer *Relayer4Ethereum) AddToken2LockList(symbol, token string) (str
}
//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
,
_
=
bn
.
SetString
(
utils
.
TrimZeroAndDot
(
amount
),
10
)
ethRelayer
.
rwLock
.
RLock
()
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 ...
...
...
plugin/dapp/cross2eth/ebrelayer/relayer/ethereum/ethtxs/deploy.go
View file @
a517c50d
...
...
@@ -499,7 +499,7 @@ finished:
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
{
return
""
,
errors
.
New
(
"no operator private key configured"
)
}
...
...
@@ -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
)
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
{
txslog
.
Error
(
"DeployERC20"
,
"Failed to DeployErc20 with err:"
,
err
.
Error
())
return
""
,
err
...
...
plugin/dapp/cross2eth/ebrelayer/relayer/manager.go
View file @
a517c50d
...
...
@@ -485,7 +485,7 @@ func (manager *Manager) DeployERC20(Erc20Token relayerTypes.ERC20Token, result *
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
{
return
err
}
...
...
plugin/dapp/cross2eth/ebrelayer/types/relayer.pb.go
View file @
a517c50d
...
...
@@ -2133,6 +2133,7 @@ type ERC20Token struct {
Name
string
`protobuf:"bytes,2,opt,name=name,proto3" json:"name,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"`
Decimals
int32
`protobuf:"varint,5,opt,name=decimals,proto3" json:"decimals,omitempty"`
}
func
(
x
*
ERC20Token
)
Reset
()
{
...
...
@@ -2195,6 +2196,13 @@ func (x *ERC20Token) GetAmount() string {
return
""
}
func
(
x
*
ERC20Token
)
GetDecimals
()
int32
{
if
x
!=
nil
{
return
x
.
Decimals
}
return
0
}
type
ETHTokenLockAddress
struct
{
state
protoimpl
.
MessageState
sizeCache
protoimpl
.
SizeCache
...
...
@@ -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
,
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
,
0x65
,
0x4b
,
0x65
,
0x79
,
0x73
,
0x22
,
0x66
,
0x0a
,
0x0a
,
0x45
,
0x52
,
0x43
,
0x32
,
0x30
,
0x54
,
0x6f
,
0x6b
,
0x65
,
0x6e
,
0x12
,
0x14
,
0x0a
,
0x05
,
0x6f
,
0x77
,
0x6e
,
0x65
,
0x72
,
0x18
,
0x01
,
0x20
,
0x01
,
0x28
,
0x09
,
0x52
,
0x05
,
0x6f
,
0x77
,
0x6e
,
0x65
,
0x72
,
0x12
,
0x12
,
0x0a
,
0x04
,
0x6e
,
0x61
,
0x6d
,
0x65
,
0x18
,
0x02
,
0x20
,
0x01
,
0x28
,
0x09
,
0x52
,
0x04
,
0x6e
,
0x61
,
0x6d
,
0x65
,
0x12
,
0x16
,
0x0a
,
0x06
,
0x73
,
0x79
,
0x6d
,
0x62
,
0x6f
,
0x6c
,
0x18
,
0x03
,
0x20
,
0x01
,
0x28
,
0x09
,
0x52
,
0x06
,
0x73
,
0x79
,
0x6d
,
0x62
,
0x6f
,
0x6c
,
0x12
,
0x16
,
0x0a
,
0x06
,
0x61
,
0x6d
,
0x6f
,
0x75
,
0x6e
,
0x74
,
0x18
,
0x04
,
0x20
,
0x01
,
0x28
,
0x09
,
0x52
,
0x06
,
0x61
,
0x6d
,
0x6f
,
0x75
,
0x6e
,
0x74
,
0x22
,
0x47
,
0x0a
,
0x13
,
0x45
,
0x54
,
0x48
,
0x54
,
0x6f
,
0x6b
,
0x65
,
0x6e
,
0x4c
,
0x6f
,
0x63
,
0x6b
,
0x41
,
0x64
,
0x64
,
0x72
,
0x65
,
0x73
,
0x73
,
0x12
,
0x18
,
0x0a
,
0x07
,
0x61
,
0x64
,
0x64
,
0x72
,
0x65
,
0x73
,
0x73
,
0x18
,
0x01
,
0x20
,
0x01
,
0x28
,
0x09
,
0x52
,
0x07
,
0x61
,
0x64
,
0x64
,
0x72
,
0x65
,
0x73
,
0x73
,
0x12
,
0x16
,
0x0a
,
0x06
,
0x73
,
0x79
,
0x6d
,
0x62
,
0x6f
,
0x6c
,
0x18
,
0x02
,
0x20
,
0x01
,
0x28
,
0x09
,
0x52
,
0x06
,
0x73
,
0x79
,
0x6d
,
0x62
,
0x6f
,
0x6c
,
0x22
,
0x89
,
0x01
,
0x0a
,
0x1b
,
0x45
,
0x54
,
0x48
,
0x43
,
0x6f
,
0x6e
,
0x66
,
0x69
,
0x67
,
0x4c
,
0x6f
,
0x63
,
0x6b
,
0x65
,
0x64
,
0x54
,
0x6f
,
0x6b
,
0x65
,
0x6e
,
0x4f
,
0x66
,
0x66
,
0x6c
,
0x69
,
0x6e
,
0x65
,
0x12
,
0x18
,
0x0a
,
0x07
,
0x61
,
0x64
,
0x64
,
0x72
,
0x65
,
0x73
,
0x73
,
0x18
,
0x01
,
0x20
,
0x01
,
0x28
,
0x09
,
0x52
,
0x07
,
0x61
,
0x64
,
0x64
,
0x72
,
0x65
,
0x73
,
0x73
,
0x12
,
0x16
,
0x0a
,
0x06
,
0x73
,
0x79
,
0x6d
,
0x62
,
0x6f
,
0x6c
,
0x18
,
0x02
,
0x20
,
0x01
,
0x28
,
0x09
,
0x52
,
0x06
,
0x73
,
0x79
,
0x6d
,
0x62
,
0x6f
,
0x6c
,
0x12
,
0x1c
,
0x0a
,
0x09
,
0x74
,
0x68
,
0x72
,
0x65
,
0x73
,
0x68
,
0x6f
,
0x6c
,
0x64
,
0x18
,
0x03
,
0x20
,
0x01
,
0x28
,
0x09
,
0x52
,
0x09
,
0x74
,
0x68
,
0x72
,
0x65
,
0x73
,
0x68
,
0x6f
,
0x6c
,
0x64
,
0x12
,
0x1a
,
0x0a
,
0x08
,
0x70
,
0x65
,
0x72
,
0x63
,
0x65
,
0x6e
,
0x74
,
0x73
,
0x18
,
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
,
0x65
,
0x4b
,
0x65
,
0x79
,
0x73
,
0x22
,
0x82
,
0x01
,
0x0a
,
0x0a
,
0x45
,
0x52
,
0x43
,
0x32
,
0x30
,
0x54
,
0x6f
,
0x6b
,
0x65
,
0x6e
,
0x12
,
0x14
,
0x0a
,
0x05
,
0x6f
,
0x77
,
0x6e
,
0x65
,
0x72
,
0x18
,
0x01
,
0x20
,
0x01
,
0x28
,
0x09
,
0x52
,
0x05
,
0x6f
,
0x77
,
0x6e
,
0x65
,
0x72
,
0x12
,
0x12
,
0x0a
,
0x04
,
0x6e
,
0x61
,
0x6d
,
0x65
,
0x18
,
0x02
,
0x20
,
0x01
,
0x28
,
0x09
,
0x52
,
0x04
,
0x6e
,
0x61
,
0x6d
,
0x65
,
0x12
,
0x16
,
0x0a
,
0x06
,
0x73
,
0x79
,
0x6d
,
0x62
,
0x6f
,
0x6c
,
0x18
,
0x03
,
0x20
,
0x01
,
0x28
,
0x09
,
0x52
,
0x06
,
0x73
,
0x79
,
0x6d
,
0x62
,
0x6f
,
0x6c
,
0x12
,
0x16
,
0x0a
,
0x06
,
0x61
,
0x6d
,
0x6f
,
0x75
,
0x6e
,
0x74
,
0x18
,
0x04
,
0x20
,
0x01
,
0x28
,
0x09
,
0x52
,
0x06
,
0x61
,
0x6d
,
0x6f
,
0x75
,
0x6e
,
0x74
,
0x12
,
0x1a
,
0x0a
,
0x08
,
0x64
,
0x65
,
0x63
,
0x69
,
0x6d
,
0x61
,
0x6c
,
0x73
,
0x18
,
0x05
,
0x20
,
0x01
,
0x28
,
0x05
,
0x52
,
0x08
,
0x64
,
0x65
,
0x63
,
0x69
,
0x6d
,
0x61
,
0x6c
,
0x73
,
0x22
,
0x47
,
0x0a
,
0x13
,
0x45
,
0x54
,
0x48
,
0x54
,
0x6f
,
0x6b
,
0x65
,
0x6e
,
0x4c
,
0x6f
,
0x63
,
0x6b
,
0x41
,
0x64
,
0x64
,
0x72
,
0x65
,
0x73
,
0x73
,
0x12
,
0x18
,
0x0a
,
0x07
,
0x61
,
0x64
,
0x64
,
0x72
,
0x65
,
0x73
,
0x73
,
0x18
,
0x01
,
0x20
,
0x01
,
0x28
,
0x09
,
0x52
,
0x07
,
0x61
,
0x64
,
0x64
,
0x72
,
0x65
,
0x73
,
0x73
,
0x12
,
0x16
,
0x0a
,
0x06
,
0x73
,
0x79
,
0x6d
,
0x62
,
0x6f
,
0x6c
,
0x18
,
0x02
,
0x20
,
0x01
,
0x28
,
0x09
,
0x52
,
0x06
,
0x73
,
0x79
,
0x6d
,
0x62
,
0x6f
,
0x6c
,
0x22
,
0x89
,
0x01
,
0x0a
,
0x1b
,
0x45
,
0x54
,
0x48
,
0x43
,
0x6f
,
0x6e
,
0x66
,
0x69
,
0x67
,
0x4c
,
0x6f
,
0x63
,
0x6b
,
0x65
,
0x64
,
0x54
,
0x6f
,
0x6b
,
0x65
,
0x6e
,
0x4f
,
0x66
,
0x66
,
0x6c
,
0x69
,
0x6e
,
0x65
,
0x12
,
0x18
,
0x0a
,
0x07
,
0x61
,
0x64
,
0x64
,
0x72
,
0x65
,
0x73
,
0x73
,
0x18
,
0x01
,
0x20
,
0x01
,
0x28
,
0x09
,
0x52
,
0x07
,
0x61
,
0x64
,
0x64
,
0x72
,
0x65
,
0x73
,
0x73
,
0x12
,
0x16
,
0x0a
,
0x06
,
0x73
,
0x79
,
0x6d
,
0x62
,
0x6f
,
0x6c
,
0x18
,
0x02
,
0x20
,
0x01
,
0x28
,
0x09
,
0x52
,
0x06
,
0x73
,
0x79
,
0x6d
,
0x62
,
0x6f
,
0x6c
,
0x12
,
0x1c
,
0x0a
,
0x09
,
0x74
,
0x68
,
0x72
,
0x65
,
0x73
,
0x68
,
0x6f
,
0x6c
,
0x64
,
0x18
,
0x03
,
0x20
,
0x01
,
0x28
,
0x09
,
0x52
,
0x09
,
0x74
,
0x68
,
0x72
,
0x65
,
0x73
,
0x68
,
0x6f
,
0x6c
,
0x64
,
0x12
,
0x1a
,
0x0a
,
0x08
,
0x70
,
0x65
,
0x72
,
0x63
,
0x65
,
0x6e
,
0x74
,
0x73
,
0x18
,
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
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment