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
e4c0fd52
Commit
e4c0fd52
authored
Dec 21, 2021
by
hezhengjun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add error process
parent
02f466b7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
24 deletions
+42
-24
ethereum.go
plugin/dapp/cross2eth/ebrelayer/relayer/ethereum/ethereum.go
+35
-22
store.go
plugin/dapp/cross2eth/ebrelayer/relayer/ethereum/store.go
+7
-2
No files found.
plugin/dapp/cross2eth/ebrelayer/relayer/ethereum/ethereum.go
View file @
e4c0fd52
...
@@ -551,18 +551,7 @@ func (ethRelayer *Relayer4Ethereum) checkPermissionWithinOneDay(withdrawTx *ebTy
...
@@ -551,18 +551,7 @@ func (ethRelayer *Relayer4Ethereum) checkPermissionWithinOneDay(withdrawTx *ebTy
func
(
ethRelayer
*
Relayer4Ethereum
)
handleLogWithdraw
(
chain33Msg
*
events
.
Chain33Msg
)
{
func
(
ethRelayer
*
Relayer4Ethereum
)
handleLogWithdraw
(
chain33Msg
*
events
.
Chain33Msg
)
{
//只有通过代理人登录的中继器,才处理提币事件
//只有通过代理人登录的中继器,才处理提币事件
if
!
ethRelayer
.
processWithDraw
{
var
err
error
relayerLog
.
Info
(
"handleLogWithdraw"
,
"Needn't process withdraw for this relay validator"
,
ethRelayer
.
ethSender
)
return
}
relayerLog
.
Info
(
"handleLogWithdraw"
,
"Received chain33Msg"
,
chain33Msg
,
"tx hash string"
,
common
.
Bytes2Hex
(
chain33Msg
.
TxHash
))
withdrawFromChain33TokenInfo
,
exist
:=
ethRelayer
.
symbol2LockAddr
[
chain33Msg
.
Symbol
]
if
!
exist
{
//因为是withdraw操作,必须从允许lock的token地址中进行查询
relayerLog
.
Error
(
"handleLogWithdraw"
,
"Failed to fetch locked Token Info for symbol"
,
chain33Msg
.
Symbol
)
return
}
now
:=
time
.
Now
()
now
:=
time
.
Now
()
year
,
month
,
day
:=
now
.
Date
()
year
,
month
,
day
:=
now
.
Date
()
withdrawTx
:=
&
ebTypes
.
WithdrawTx
{
withdrawTx
:=
&
ebTypes
.
WithdrawTx
{
...
@@ -577,15 +566,34 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33
...
@@ -577,15 +566,34 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33
Day
:
int32
(
day
),
Day
:
int32
(
day
),
}
}
//检查用户提币权限是否得到满足:比如是否超过累计提币额度
if
!
ethRelayer
.
processWithDraw
{
var
feeAmount
*
big
.
Int
relayerLog
.
Info
(
"handleLogWithdraw"
,
"Needn't process withdraw for this relay validator"
,
ethRelayer
.
ethSender
)
var
err
error
return
if
feeAmount
,
err
=
ethRelayer
.
checkPermissionWithinOneDay
(
withdrawTx
);
nil
!=
err
{
}
withdrawTx
.
Status
=
err
.
Error
()
defer
func
()
{
if
err
!=
nil
{
withdrawTx
.
Status
=
err
.
Error
()
relayerLog
.
Error
(
"handleLogWithdraw"
,
"Failed to withdraw due to:"
,
err
.
Error
())
}
err
:=
ethRelayer
.
setWithdraw
(
withdrawTx
)
err
:=
ethRelayer
.
setWithdraw
(
withdrawTx
)
if
nil
!=
err
{
if
nil
!=
err
{
relayerLog
.
Error
(
"handleLogWithdraw"
,
"Failed to setWithdraw due to:"
,
err
.
Error
())
relayerLog
.
Error
(
"handleLogWithdraw"
,
"Failed to setWithdraw due to:"
,
err
.
Error
())
}
}
}()
relayerLog
.
Info
(
"handleLogWithdraw"
,
"Received chain33Msg"
,
chain33Msg
,
"tx hash string"
,
common
.
Bytes2Hex
(
chain33Msg
.
TxHash
))
withdrawFromChain33TokenInfo
,
exist
:=
ethRelayer
.
symbol2LockAddr
[
chain33Msg
.
Symbol
]
if
!
exist
{
//因为是withdraw操作,必须从允许lock的token地址中进行查询
relayerLog
.
Error
(
"handleLogWithdraw"
,
"Failed to fetch locked Token Info for symbol"
,
chain33Msg
.
Symbol
)
err
=
errors
.
New
(
"ErrFetchLockedTokenInfo"
)
return
}
//检查用户提币权限是否得到满足:比如是否超过累计提币额度
var
feeAmount
*
big
.
Int
if
feeAmount
,
err
=
ethRelayer
.
checkPermissionWithinOneDay
(
withdrawTx
);
nil
!=
err
{
return
return
}
}
...
@@ -597,6 +605,7 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33
...
@@ -597,6 +605,7 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33
value
,
exist
:=
utils
.
Decimal2value
[
int
(
dist
)]
value
,
exist
:=
utils
.
Decimal2value
[
int
(
dist
)]
if
!
exist
{
if
!
exist
{
relayerLog
.
Error
(
"handleLogWithdraw"
,
"does support for decimal, %d"
,
withdrawFromChain33TokenInfo
.
Decimal
)
relayerLog
.
Error
(
"handleLogWithdraw"
,
"does support for decimal, %d"
,
withdrawFromChain33TokenInfo
.
Decimal
)
err
=
errors
.
New
(
"ErrDecimalNotSupport"
)
return
return
}
}
chain33Msg
.
Amount
.
Mul
(
chain33Msg
.
Amount
,
big
.
NewInt
(
value
))
chain33Msg
.
Amount
.
Mul
(
chain33Msg
.
Amount
,
big
.
NewInt
(
value
))
...
@@ -605,6 +614,7 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33
...
@@ -605,6 +614,7 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33
value
,
exist
:=
utils
.
Decimal2value
[
int
(
dist
)]
value
,
exist
:=
utils
.
Decimal2value
[
int
(
dist
)]
if
!
exist
{
if
!
exist
{
relayerLog
.
Error
(
"handleLogWithdraw"
,
"does support for decimal, %d"
,
withdrawFromChain33TokenInfo
.
Decimal
)
relayerLog
.
Error
(
"handleLogWithdraw"
,
"does support for decimal, %d"
,
withdrawFromChain33TokenInfo
.
Decimal
)
err
=
errors
.
New
(
"ErrDecimalNotSupport"
)
return
return
}
}
chain33Msg
.
Amount
.
Div
(
chain33Msg
.
Amount
,
big
.
NewInt
(
value
))
chain33Msg
.
Amount
.
Div
(
chain33Msg
.
Amount
,
big
.
NewInt
(
value
))
...
@@ -613,7 +623,8 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33
...
@@ -613,7 +623,8 @@ 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
())
if
chain33Msg
.
Amount
.
Cmp
(
feeAmount
)
<
0
{
if
chain33Msg
.
Amount
.
Cmp
(
feeAmount
)
<
0
{
relayerLog
.
Error
(
"handleLogWithdraw"
,
"does support for decimal, %d"
,
withdrawFromChain33TokenInfo
.
Decimal
)
relayerLog
.
Error
(
"handleLogWithdraw"
,
"ErrWithdrawAmountLessThanFee feeAmount"
,
feeAmount
.
String
(),
"Withdraw Amount"
,
chain33Msg
.
Amount
.
String
())
err
=
errors
.
New
(
"ErrWithdrawAmountLessThanFee"
)
return
return
}
}
amount2transfer
:=
chain33Msg
.
Amount
.
Sub
(
chain33Msg
.
Amount
,
feeAmount
)
amount2transfer
:=
chain33Msg
.
Amount
.
Sub
(
chain33Msg
.
Amount
,
feeAmount
)
...
@@ -632,12 +643,14 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33
...
@@ -632,12 +643,14 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33
intputData
,
err
=
ethRelayer
.
packTransferData
(
chain33Msg
.
EthereumReceiver
,
amount2transfer
)
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
)
err
=
errors
.
New
(
"ErrPackTransferData"
)
return
return
}
}
//用签名的账户地址作为pack参数,toAddr作为合约地址
//用签名的账户地址作为pack参数,toAddr作为合约地址
balanceOfData
,
err
=
ethRelayer
.
packBalanceOfData
(
chain33Msg
.
EthereumReceiver
)
balanceOfData
,
err
=
ethRelayer
.
packBalanceOfData
(
chain33Msg
.
EthereumReceiver
)
if
err
!=
nil
{
if
err
!=
nil
{
relayerLog
.
Error
(
"handleLogWithdraw"
,
"callEvmBalanceData err"
,
err
)
relayerLog
.
Error
(
"handleLogWithdraw"
,
"callEvmBalanceData err"
,
err
)
err
=
errors
.
New
(
"ErrPackBalanceOfData"
)
return
return
}
}
}
else
{
}
else
{
...
@@ -649,6 +662,7 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33
...
@@ -649,6 +662,7 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33
//校验余额是否充足
//校验余额是否充足
if
ok
,
err
:=
ethRelayer
.
checkBalanceEnough
(
toAddr
,
amount2transfer
,
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
())
err
=
errors
.
New
(
"ErrBalanceNotEnough"
)
return
return
}
}
//param: from,to,evm-packdata,amount
//param: from,to,evm-packdata,amount
...
@@ -656,6 +670,7 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33
...
@@ -656,6 +670,7 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33
tx
,
err
:=
ethRelayer
.
newTx
(
ethRelayer
.
ethSender
,
toAddr
,
intputData
,
value
)
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
)
err
=
errors
.
New
(
"ErrNewTx"
)
return
return
}
}
...
@@ -663,22 +678,20 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33
...
@@ -663,22 +678,20 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33
signedTx
,
err
:=
ethRelayer
.
signTx
(
tx
,
ethRelayer
.
privateKey4Ethereum
)
signedTx
,
err
:=
ethRelayer
.
signTx
(
tx
,
ethRelayer
.
privateKey4Ethereum
)
if
err
!=
nil
{
if
err
!=
nil
{
relayerLog
.
Error
(
"handleLogWithdraw"
,
"SignTx err"
,
err
)
relayerLog
.
Error
(
"handleLogWithdraw"
,
"SignTx err"
,
err
)
err
=
errors
.
New
(
"ErrSignTx"
)
return
return
}
}
//交易发送
//交易发送
err
=
ethRelayer
.
clientSpec
.
SendTransaction
(
timeout
,
signedTx
)
err
=
ethRelayer
.
clientSpec
.
SendTransaction
(
timeout
,
signedTx
)
if
err
!=
nil
{
if
err
!=
nil
{
relayerLog
.
Error
(
"handleLogWithdraw"
,
"SendTransaction err"
,
err
)
relayerLog
.
Error
(
"handleLogWithdraw"
,
"SendTransaction err"
,
err
)
err
=
errors
.
New
(
"ErrSendTransaction"
)
return
return
}
}
relayerLog
.
Info
(
"handleLogWithdraw"
,
"SendTransaction Hash"
,
signedTx
.
Hash
())
relayerLog
.
Info
(
"handleLogWithdraw"
,
"SendTransaction Hash"
,
signedTx
.
Hash
())
withdrawTx
.
Status
=
"Withdraw Tx has been sent to Ethereum"
withdrawTx
.
Status
=
"Withdraw Tx has been sent to Ethereum"
withdrawTx
.
TxHashOnEthereum
=
signedTx
.
Hash
()
.
String
()
withdrawTx
.
TxHashOnEthereum
=
signedTx
.
Hash
()
.
String
()
err
=
ethRelayer
.
setWithdraw
(
withdrawTx
)
if
nil
!=
err
{
relayerLog
.
Error
(
"handleLogWithdraw"
,
"Failed to setWithdraw due to:"
,
err
.
Error
())
}
return
return
}
}
...
...
plugin/dapp/cross2eth/ebrelayer/relayer/ethereum/store.go
View file @
e4c0fd52
...
@@ -29,7 +29,8 @@ var (
...
@@ -29,7 +29,8 @@ var (
ethBurnTxUpdateTxIndex
=
[]
byte
(
"eth-ethBurnTxUpdateTxIndex"
)
ethBurnTxUpdateTxIndex
=
[]
byte
(
"eth-ethBurnTxUpdateTxIndex"
)
multiSignAddressPrefix
=
[]
byte
(
"eth-multiSignAddress"
)
multiSignAddressPrefix
=
[]
byte
(
"eth-multiSignAddress"
)
withdrawParaKey
=
[]
byte
(
"eth-withdrawPara"
)
withdrawParaKey
=
[]
byte
(
"eth-withdrawPara"
)
withdrawTokenPrefix
=
[]
byte
(
"eth-withdrawTokenPrefix"
)
withdrawTokenPrefix
=
[]
byte
(
"eth-withdrawToken"
)
withdrawTokenListPrefix
=
[]
byte
(
"eth-withdrawTokenList"
)
)
)
func
ethTokenSymbol2AddrKey
(
symbol
string
)
[]
byte
{
func
ethTokenSymbol2AddrKey
(
symbol
string
)
[]
byte
{
...
@@ -434,6 +435,10 @@ func calcWithdrawKeyPrefix(chain33Sender, symbol string, year, month, day int) [
...
@@ -434,6 +435,10 @@ func calcWithdrawKeyPrefix(chain33Sender, symbol string, year, month, day int) [
return
[]
byte
(
fmt
.
Sprintf
(
"%s-%s-%s-%d-%d-%d"
,
withdrawTokenPrefix
,
chain33Sender
,
symbol
,
year
,
month
,
day
))
return
[]
byte
(
fmt
.
Sprintf
(
"%s-%s-%s-%d-%d-%d"
,
withdrawTokenPrefix
,
chain33Sender
,
symbol
,
year
,
month
,
day
))
}
}
func
calcWithdrawListKey
(
nonce
int64
)
[]
byte
{
return
[]
byte
(
fmt
.
Sprintf
(
"%s-%d"
,
withdrawTokenListPrefix
,
nonce
))
}
func
(
ethRelayer
*
Relayer4Ethereum
)
setWithdraw
(
withdrawTx
*
ebTypes
.
WithdrawTx
)
error
{
func
(
ethRelayer
*
Relayer4Ethereum
)
setWithdraw
(
withdrawTx
*
ebTypes
.
WithdrawTx
)
error
{
chain33Sender
:=
withdrawTx
.
Chain33Sender
chain33Sender
:=
withdrawTx
.
Chain33Sender
symbol
:=
withdrawTx
.
Symbol
symbol
:=
withdrawTx
.
Symbol
...
@@ -442,8 +447,8 @@ func (ethRelayer *Relayer4Ethereum) setWithdraw(withdrawTx *ebTypes.WithdrawTx)
...
@@ -442,8 +447,8 @@ func (ethRelayer *Relayer4Ethereum) setWithdraw(withdrawTx *ebTypes.WithdrawTx)
day
:=
withdrawTx
.
Day
day
:=
withdrawTx
.
Day
key
:=
calcWithdrawKey
(
chain33Sender
,
symbol
,
int
(
year
),
int
(
month
),
int
(
day
),
withdrawTx
.
Nonce
)
key
:=
calcWithdrawKey
(
chain33Sender
,
symbol
,
int
(
year
),
int
(
month
),
int
(
day
),
withdrawTx
.
Nonce
)
bytes
:=
chain33Types
.
Encode
(
withdrawTx
)
bytes
:=
chain33Types
.
Encode
(
withdrawTx
)
return
ethRelayer
.
db
.
Set
(
key
,
bytes
)
return
ethRelayer
.
db
.
Set
(
key
,
bytes
)
}
}
...
...
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