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
d63b29b1
Commit
d63b29b1
authored
Dec 21, 2021
by
hezhengjun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add fee process to the withdraw
parent
cd8c1025
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
12 deletions
+18
-12
ethereum.go
plugin/dapp/cross2eth/ebrelayer/relayer/ethereum/ethereum.go
+18
-12
No files found.
plugin/dapp/cross2eth/ebrelayer/relayer/ethereum/ethereum.go
View file @
d63b29b1
...
@@ -522,22 +522,24 @@ func (ethRelayer *Relayer4Ethereum) handleChain33Msg(chain33Msg *events.Chain33M
...
@@ -522,22 +522,24 @@ func (ethRelayer *Relayer4Ethereum) handleChain33Msg(chain33Msg *events.Chain33M
return
return
}
}
func
(
ethRelayer
*
Relayer4Ethereum
)
checkPermissionWithinOneDay
(
withdrawTx
*
ebTypes
.
WithdrawTx
)
error
{
func
(
ethRelayer
*
Relayer4Ethereum
)
checkPermissionWithinOneDay
(
withdrawTx
*
ebTypes
.
WithdrawTx
)
(
int64
,
error
)
{
totalAlready
,
err
:=
ethRelayer
.
getWithdrawsWithinSameDay
(
withdrawTx
)
totalAlready
,
err
:=
ethRelayer
.
getWithdrawsWithinSameDay
(
withdrawTx
)
if
nil
!=
err
{
if
nil
!=
err
{
relayerLog
.
Error
(
"checkPermissionWithinOneDay"
,
"Failed to getWithdrawsWithinSameDay due to"
,
err
.
Error
())
relayerLog
.
Error
(
"checkPermissionWithinOneDay"
,
"Failed to getWithdrawsWithinSameDay due to"
,
err
.
Error
())
return
errors
.
New
(
"ErrGetWithdrawsWithinSameDay"
)
return
0
,
errors
.
New
(
"ErrGetWithdrawsWithinSameDay"
)
}
}
withdrawPara
,
ok
:=
ethRelayer
.
withdrawFee
[
withdrawTx
.
Symbol
]
withdrawPara
,
ok
:=
ethRelayer
.
withdrawFee
[
withdrawTx
.
Symbol
]
if
!
ok
{
if
!
ok
{
relayerLog
.
Error
(
"checkPermissionWithinOneDay"
,
"No withdraw parameter configured for symbol "
,
withdrawTx
.
Symbol
)
relayerLog
.
Error
(
"checkPermissionWithinOneDay"
,
"No withdraw parameter configured for symbol "
,
withdrawTx
.
Symbol
)
return
errors
.
New
(
"ErrNoWithdrawParaCfged"
)
return
0
,
errors
.
New
(
"ErrNoWithdrawParaCfged"
)
}
}
if
totalAlready
+
withdrawTx
.
Amount
>
withdrawPara
.
AmountPerDay
{
if
totalAlready
+
withdrawTx
.
Amount
>
withdrawPara
.
AmountPerDay
{
relayerLog
.
Error
(
"checkPermissionWithinOneDay"
,
"No withdraw parameter configured for symbol "
,
withdrawTx
.
Symbol
)
relayerLog
.
Error
(
"checkPermissionWithinOneDay"
,
"No withdraw parameter configured for symbol "
,
withdrawTx
.
Symbol
)
return
errors
.
New
(
"ErrWithdrawAmountTooBig"
)
return
0
,
errors
.
New
(
"ErrWithdrawAmountTooBig"
)
}
}
return
nil
relayerLog
.
Info
(
"checkPermissionWithinOneDay"
,
"total withdraw already"
,
totalAlready
,
"Chain33Sender"
,
withdrawTx
.
Chain33Sender
,
"Symbol"
,
withdrawTx
.
Symbol
)
return
withdrawPara
.
Fee
,
nil
}
}
func
(
ethRelayer
*
Relayer4Ethereum
)
handleLogWithdraw
(
chain33Msg
*
events
.
Chain33Msg
)
{
func
(
ethRelayer
*
Relayer4Ethereum
)
handleLogWithdraw
(
chain33Msg
*
events
.
Chain33Msg
)
{
...
@@ -569,7 +571,9 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33
...
@@ -569,7 +571,9 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33
}
}
//检查用户提币权限是否得到满足:比如是否超过累计提币额度
//检查用户提币权限是否得到满足:比如是否超过累计提币额度
if
err
:=
ethRelayer
.
checkPermissionWithinOneDay
(
withdrawTx
);
nil
!=
err
{
var
feeAmount
int64
var
err
error
if
feeAmount
,
err
=
ethRelayer
.
checkPermissionWithinOneDay
(
withdrawTx
);
nil
!=
err
{
withdrawTx
.
Status
=
err
.
Error
()
withdrawTx
.
Status
=
err
.
Error
()
err
:=
ethRelayer
.
setWithdraw
(
withdrawTx
)
err
:=
ethRelayer
.
setWithdraw
(
withdrawTx
)
if
nil
!=
err
{
if
nil
!=
err
{
...
@@ -602,18 +606,20 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33
...
@@ -602,18 +606,20 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33
relayerLog
.
Info
(
"handleLogWithdraw"
,
"token address"
,
tokenAddr
.
String
(),
"amount"
,
chain33Msg
.
Amount
.
String
(),
relayerLog
.
Info
(
"handleLogWithdraw"
,
"token address"
,
tokenAddr
.
String
(),
"amount"
,
chain33Msg
.
Amount
.
String
(),
"Receiver on Ethereum"
,
chain33Msg
.
EthereumReceiver
.
String
())
"Receiver on Ethereum"
,
chain33Msg
.
EthereumReceiver
.
String
())
amount2transfer
:=
big
.
NewInt
(
chain33Msg
.
Amount
.
Int64
()
-
feeAmount
)
value
:=
big
.
NewInt
(
0
)
//此处需要完成在以太坊发送以太或者ERC20数字资产的操作
//此处需要完成在以太坊发送以太或者ERC20数字资产的操作
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
timeout
,
cancel
:=
context
.
WithTimeout
(
ctx
,
time
.
Second
*
2
)
timeout
,
cancel
:=
context
.
WithTimeout
(
ctx
,
time
.
Second
*
2
)
defer
cancel
()
defer
cancel
()
var
intputData
[]
byte
// ERC20 or BEP20 token transfer pack data
var
intputData
[]
byte
// ERC20 or BEP20 token transfer pack data
var
err
error
var
toAddr
common
.
Address
var
toAddr
common
.
Address
var
balanceOfData
[]
byte
// ERC20 or BEP20 token balanceof pack data
var
balanceOfData
[]
byte
// ERC20 or BEP20 token balanceof pack data
if
tokenAddr
.
String
()
!=
ethtxs
.
EthNullAddr
{
//判断是否要Pack EVM数据
if
tokenAddr
.
String
()
!=
ethtxs
.
EthNullAddr
{
//判断是否要Pack EVM数据
toAddr
=
tokenAddr
toAddr
=
tokenAddr
intputData
,
err
=
ethRelayer
.
packTransferData
(
chain33Msg
.
EthereumReceiver
,
chain33Msg
.
Amount
)
intputData
,
err
=
ethRelayer
.
packTransferData
(
chain33Msg
.
EthereumReceiver
,
amount2transfer
)
if
err
!=
nil
{
if
err
!=
nil
{
relayerLog
.
Error
(
"handleLogWithdraw"
,
"CallEvmData err"
,
err
)
relayerLog
.
Error
(
"handleLogWithdraw"
,
"CallEvmData err"
,
err
)
return
return
...
@@ -624,20 +630,20 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33
...
@@ -624,20 +630,20 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33
relayerLog
.
Error
(
"handleLogWithdraw"
,
"callEvmBalanceData err"
,
err
)
relayerLog
.
Error
(
"handleLogWithdraw"
,
"callEvmBalanceData err"
,
err
)
return
return
}
}
}
else
{
}
else
{
//如果tokenAddr为空,则把toAddr设置为用户指定的地址
//如果tokenAddr为空,则把toAddr设置为用户指定的地址
toAddr
=
chain33Msg
.
EthereumReceiver
toAddr
=
chain33Msg
.
EthereumReceiver
value
=
amount2transfer
}
}
//校验余额是否充足
//校验余额是否充足
if
ok
,
err
:=
ethRelayer
.
checkBalanceEnough
(
toAddr
,
chain33Msg
.
Amount
,
balanceOfData
);
!
ok
{
if
ok
,
err
:=
ethRelayer
.
checkBalanceEnough
(
toAddr
,
amount2transfer
,
balanceOfData
);
!
ok
{
relayerLog
.
Error
(
"handleLogWithdraw"
,
"Failed to checkBalanceEnough:"
,
err
.
Error
())
relayerLog
.
Error
(
"handleLogWithdraw"
,
"Failed to checkBalanceEnough:"
,
err
.
Error
())
return
return
}
}
//param: from,to,evm-packdata,amount
//param: from,to,evm-packdata,amount
//交易构造
//交易构造
tx
,
err
:=
ethRelayer
.
newTx
(
ethRelayer
.
ethSender
,
toAddr
,
intputData
,
chain33Msg
.
Amount
)
tx
,
err
:=
ethRelayer
.
newTx
(
ethRelayer
.
ethSender
,
toAddr
,
intputData
,
value
)
if
err
!=
nil
{
if
err
!=
nil
{
relayerLog
.
Error
(
"handleLogWithdraw"
,
"newTx err"
,
err
)
relayerLog
.
Error
(
"handleLogWithdraw"
,
"newTx err"
,
err
)
return
return
...
...
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