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
c92b55a0
Commit
c92b55a0
authored
Dec 17, 2021
by
hezhengjun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add withdraw
parent
8850975d
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
233 additions
and
36 deletions
+233
-36
BridgeBank.sol
...eth/contracts/contracts4chain33/BridgeBank/BridgeBank.sol
+35
-1
EthereumBank.sol
...h/contracts/contracts4chain33/BridgeBank/EthereumBank.sol
+63
-8
main.go
plugin/dapp/cross2eth/ebrelayer/main.go
+1
-0
config.proto
plugin/dapp/cross2eth/ebrelayer/proto/config.proto
+1
-0
relayer.toml
plugin/dapp/cross2eth/ebrelayer/relayer.toml
+1
-0
chain33.go
plugin/dapp/cross2eth/ebrelayer/relayer/chain33/chain33.go
+10
-5
evm.go
plugin/dapp/cross2eth/ebrelayer/relayer/chain33/evm.go
+4
-1
ethereum.go
plugin/dapp/cross2eth/ebrelayer/relayer/ethereum/ethereum.go
+64
-17
chain33Event.go
...n/dapp/cross2eth/ebrelayer/relayer/events/chain33Event.go
+53
-4
events.go
plugin/dapp/cross2eth/ebrelayer/relayer/events/events.go
+1
-0
No files found.
plugin/dapp/cross2eth/contracts/contracts4chain33/BridgeBank/BridgeBank.sol
View file @
c92b55a0
...
...
@@ -106,6 +106,18 @@ contract BridgeBank is EthereumBank, Chain33Bank {
}
/*
* @dev: set a proxy address to receive and it's transfer asset on Ethereum
*
* @param _proxyReceiver: The address to receive asset
* @return: indicate whether set successfully or not
*/
function setWithdrawProxy(address payable _proxyReceiver) public onlyOperator returns(bool)
{
proxyReceiver = _proxyReceiver;
return true;
}
/*
* @dev: Mints new BankTokens
*
* @param _ethereumSender: The sender's Ethereum address in bytes.
...
...
@@ -137,7 +149,7 @@ contract BridgeBank is EthereumBank, Chain33Bank {
* @dev: Burns bank tokens
*
* @param _ethereumReceiver: The _ethereum receiver address in bytes.
* @param _ethereumTokenAddress: The
currency type
* @param _ethereumTokenAddress: The
token address mint on chain33 and it's origin from Ethereum
* @param _amount: number of ethereum tokens to be burned
*/
function burnBridgeTokens(
...
...
@@ -156,6 +168,28 @@ contract BridgeBank is EthereumBank, Chain33Bank {
}
/*
* @dev: withdraw asset via Proxy
*
* @param _ethereumReceiver: The _ethereum receiver address in bytes.
* @param _bridgeTokenAddress: The bridge Token Address issued in chain33 and it's origin from Ethereum/BSC
* @param _amount: number of bridge tokens to be transferred to proxy address
*/
function withdrawViaProxy(
bytes memory _ethereumReceiver,
address _bridgeTokenAddress,
uint256 _amount
)
public
{
return burnEthereumTokens(
msg.sender,
_ethereumReceiver,
_ethereumTokenAddress,
_amount
);
}
/*
* @dev: addToken2LockList used to add token with the specified address to be
* allowed locked from Ethereum
*
...
...
plugin/dapp/cross2eth/contracts/contracts4chain33/BridgeBank/EthereumBank.sol
View file @
c92b55a0
...
...
@@ -14,11 +14,12 @@ contract EthereumBank {
using SafeMath for uint256;
uint256 public bridgeTokenCount;
address payable proxyReceiver;
mapping(address => bool) public bridgeTokenWhitelist;
mapping(bytes32 => bool) public bridgeTokenCreated;
mapping(bytes32 => EthereumDeposit) ethereumDeposits;
mapping(bytes32 => EthereumBurn) ethereumBurns;
mapping(address => DepositBurn
Count) depositBurn
Counts;
mapping(address => DepositBurn
WithdrawCount) depositBurnWithdraw
Counts;
mapping(bytes32 => address) public token2address;
struct EthereumDeposit {
...
...
@@ -30,9 +31,11 @@ contract EthereumBank {
uint256 nonce;
}
struct DepositBurnCount {
struct DepositBurn
Withdraw
Count {
uint256 depositCount;
uint256 burnCount;
uint256 withdrawCount;
}
struct EthereumBurn {
...
...
@@ -67,6 +70,16 @@ contract EthereumBank {
uint256 _nonce
);
event LogEthereumTokenWithdraw(
address _bridgeToken,
string _symbol,
uint256 _amount,
address _ownerFrom,
bytes _ethereumReceiver,
address _proxyReceiver,
uint256 _nonce
);
/*
* @dev: Modifier to make sure this symbol not created now
*/
...
...
@@ -127,9 +140,9 @@ contract EthereumBank {
internal
returns(bytes32)
{
DepositBurn
Count memory depositBurnCount = depositBurn
Counts[_token];
DepositBurn
WithdrawCount memory depositBurnCount = depositBurnWithdraw
Counts[_token];
depositBurnCount.depositCount = depositBurnCount.depositCount.add(1);
depositBurnCounts[_token] = depositBurnCount;
depositBurn
Withdraw
Counts[_token] = depositBurnCount;
bytes32 depositID = keccak256(
abi.encodePacked(
...
...
@@ -217,7 +230,7 @@ contract EthereumBank {
bridgeTokenWhitelist[newBridgeTokenAddress] = true;
bytes32 symHash = keccak256(abi.encodePacked(_symbol));
bridgeTokenCreated[symHash] = true;
depositBurn
Counts[newBridgeTokenAddress] = DepositBurn
Count(
depositBurn
WithdrawCounts[newBridgeTokenAddress] = DepositBurnWithdraw
Count(
uint256(0),
uint256(0));
token2address[symHash] = newBridgeTokenAddress;
...
...
@@ -284,7 +297,7 @@ contract EthereumBank {
* @param _from: The address to be burned from
* @param _ethereumReceiver: The receiver's Ethereum address in bytes.
* @param _ethereumTokenAddress: The token address of ethereum asset issued on chain33
* @param _amount: number of ethereum tokens to be
mint
ed
* @param _amount: number of ethereum tokens to be
burn
ed
*/
function burnEthereumTokens(
address payable _from,
...
...
@@ -304,13 +317,13 @@ contract EthereumBank {
BridgeToken bridgeTokenInstance = BridgeToken(_ethereumTokenAddress);
bridgeTokenInstance.burnFrom(_from, _amount);
DepositBurn
Count memory depositBurnCount = depositBurn
Counts[_ethereumTokenAddress];
DepositBurn
WithdrawCount memory depositBurnCount = depositBurnWithdraw
Counts[_ethereumTokenAddress];
require(
depositBurnCount.burnCount + 1 > depositBurnCount.burnCount,
"burn nonce is not available"
);
depositBurnCount.burnCount = depositBurnCount.burnCount.add(1);
depositBurnCounts[_ethereumTokenAddress] = depositBurnCount;
depositBurn
Withdraw
Counts[_ethereumTokenAddress] = depositBurnCount;
newEthereumBurn(
_ethereumReceiver,
...
...
@@ -331,6 +344,48 @@ contract EthereumBank {
}
/*
* @dev: withdraw ethereum tokens
*
* @param _from: The address to be withdrew from
* @param _ethereumReceiver: The receiver's Ethereum address in bytes.
* @param _bridgeTokenAddress: The token address of ethereum asset issued on chain33
* @param _amount: number of ethereum tokens to be withdrew
*/
function withdrawEthereumTokens(
address payable _from,
bytes memory _ethereumReceiver,
address _bridgeTokenAddress,
uint256 _amount
)
internal
{
// Must be whitelisted bridge token
require(bridgeTokenWhitelist[_bridgeTokenAddress], "Token must be a whitelisted bridge token");
// burn bridge tokens
BridgeToken bridgeTokenInstance = BridgeToken(_bridgeTokenAddress);
bridgeTokenInstance.transferFrom(_from, proxyReceiver, _amount);
DepositBurnWithdrawCount memory withCount = depositBurnWithdrawCounts[_bridgeTokenAddress];
require(
withCount.withdrawCount + 1 > withCount.withdrawCount,
"burn nonce is not available"
);
withCount.withdrawCount = withCount.withdrawCount.add(1);
depositBurnWithdrawCounts[_bridgeTokenAddress] = withCount;
emit LogEthereumTokenWithdraw(
_bridgeTokenAddress,
bridgeTokenInstance.symbol(),
_amount,
_from,
_ethereumReceiver,
proxyReceiver,
withCount.withdrawCount
);
}
/*
* @dev: Checks if an individual EthereumDeposit exists.
*
* @param _id: The unique EthereumDeposit's id.
...
...
plugin/dapp/cross2eth/ebrelayer/main.go
View file @
c92b55a0
...
...
@@ -98,6 +98,7 @@ func main() {
BlockInterval
:
cfg
.
EthBlockFetchPeriod
,
EthBridgeClaimChan
:
ethBridgeClaimChan
,
Chain33MsgChan
:
chain33MsgChan
,
ProcessWithDraw
:
cfg
.
ProcessWithDraw
,
}
ethRelayerService
:=
ethRelayer
.
StartEthereumRelayer
(
ethStartPara
)
...
...
plugin/dapp/cross2eth/ebrelayer/proto/config.proto
View file @
c92b55a0
...
...
@@ -47,6 +47,7 @@ message RelayerConfig {
string
bridgeRegistryOnChain33
=
12
;
string
chainName
=
13
;
int32
chainID4Chain33
=
14
;
bool
processWithDraw
=
15
;
}
message
SyncTxReceiptConfig
{
...
...
plugin/dapp/cross2eth/ebrelayer/relayer.toml
View file @
c92b55a0
...
...
@@ -11,6 +11,7 @@ EthMaturityDegree=10
EthBlockFetchPeriod
=
5000
BridgeRegistryOnChain33
=
""
BridgeRegistry
=
""
ProcessWithDraw
=
false
[SyncTxConfig]
chain33Host
=
"http://localhost:8801"
...
...
plugin/dapp/cross2eth/ebrelayer/relayer/chain33/chain33.go
View file @
c92b55a0
...
...
@@ -51,6 +51,7 @@ type Relayer4Chain33 struct {
unlockChan
chan
int
bridgeBankEventLockSig
string
bridgeBankEventBurnSig
string
bridgeBankEventWithdrawSig
string
bridgeBankAbi
abi
.
ABI
deployInfo
*
ebTypes
.
Deploy
totalTx4RelayEth2chai33
int64
...
...
@@ -235,12 +236,14 @@ func (chain33Relayer *Relayer4Chain33) onNewHeightProc(currentHeight int64) {
evmEventType
=
events
.
Chain33EventLogBurn
}
else
if
chain33Relayer
.
bridgeBankEventLockSig
==
common
.
ToHex
(
evmlog
.
Topic
[
0
])
{
evmEventType
=
events
.
Chain33EventLogLock
}
else
if
chain33Relayer
.
bridgeBankEventWithdrawSig
==
common
.
ToHex
(
evmlog
.
Topic
[
0
])
{
evmEventType
=
events
.
Chain33EventLogWithdraw
}
else
{
continue
}
if
err
:=
chain33Relayer
.
handleBurnLockEvent
(
evmEventType
,
evmlog
.
Data
,
tx
.
Hash
());
nil
!=
err
{
errInfo
:=
fmt
.
Sprintf
(
"Failed to handleBurnLockEvent due to:%s"
,
err
.
Error
())
if
err
:=
chain33Relayer
.
handleBurnLock
Withdraw
Event
(
evmEventType
,
evmlog
.
Data
,
tx
.
Hash
());
nil
!=
err
{
errInfo
:=
fmt
.
Sprintf
(
"Failed to handleBurnLock
Withdraw
Event due to:%s"
,
err
.
Error
())
panic
(
errInfo
)
}
}
...
...
@@ -251,8 +254,8 @@ func (chain33Relayer *Relayer4Chain33) onNewHeightProc(currentHeight int64) {
}
// handleBurnLockMsg : parse event data as a Chain33Msg, package it into a ProphecyClaim, then relay tx to the Ethereum Network
func
(
chain33Relayer
*
Relayer4Chain33
)
handleBurnLockEvent
(
evmEventType
events
.
Chain33EvmEvent
,
data
[]
byte
,
chain33TxHash
[]
byte
)
error
{
relayerLog
.
Info
(
"handleBurnLockEvent"
,
"Received tx with hash"
,
ethCommon
.
Bytes2Hex
(
chain33TxHash
))
func
(
chain33Relayer
*
Relayer4Chain33
)
handleBurnLock
Withdraw
Event
(
evmEventType
events
.
Chain33EvmEvent
,
data
[]
byte
,
chain33TxHash
[]
byte
)
error
{
relayerLog
.
Info
(
"handleBurnLock
Withdraw
Event"
,
"Received tx with hash"
,
ethCommon
.
Bytes2Hex
(
chain33TxHash
))
// Parse the witnessed event's data into a new Chain33Msg
chain33Msg
,
err
:=
events
.
ParseBurnLock4chain33
(
evmEventType
,
data
,
chain33Relayer
.
bridgeBankAbi
,
chain33TxHash
)
...
...
@@ -306,11 +309,13 @@ func (chain33Relayer *Relayer4Chain33) ResendChain33Event(height int64) (err err
evmEventType
=
events
.
Chain33EventLogBurn
}
else
if
chain33Relayer
.
bridgeBankEventLockSig
==
common
.
ToHex
(
evmlog
.
Topic
[
0
])
{
evmEventType
=
events
.
Chain33EventLogLock
}
else
if
chain33Relayer
.
bridgeBankEventWithdrawSig
==
common
.
ToHex
(
evmlog
.
Topic
[
0
])
{
evmEventType
=
events
.
Chain33EventLogWithdraw
}
else
{
continue
}
if
err
:=
chain33Relayer
.
handleBurnLockEvent
(
evmEventType
,
evmlog
.
Data
,
tx
.
Hash
());
nil
!=
err
{
if
err
:=
chain33Relayer
.
handleBurnLock
Withdraw
Event
(
evmEventType
,
evmlog
.
Data
,
tx
.
Hash
());
nil
!=
err
{
return
err
}
}
...
...
plugin/dapp/cross2eth/ebrelayer/relayer/chain33/evm.go
View file @
c92b55a0
...
...
@@ -20,8 +20,11 @@ func (relayer *Relayer4Chain33) prePareSubscribeEvent() {
relayer
.
bridgeBankEventLockSig
=
contractABI
.
Events
[
eventName
]
.
ID
.
Hex
()
eventName
=
events
.
Chain33EventLogBurn
.
String
()
relayer
.
bridgeBankEventBurnSig
=
contractABI
.
Events
[
eventName
]
.
ID
.
Hex
()
eventName
=
events
.
Chain33EventLogWithdraw
.
String
()
relayer
.
bridgeBankEventWithdrawSig
=
contractABI
.
Events
[
eventName
]
.
ID
.
Hex
()
relayer
.
bridgeBankAbi
=
contractABI
relayerLog
.
Info
(
"prePareSubscribeEvent"
,
"bridgeBankEventLockSig"
,
relayer
.
bridgeBankEventLockSig
,
"bridgeBankEventBurnSig"
,
relayer
.
bridgeBankEventBurnSig
)
"bridgeBankEventBurnSig"
,
relayer
.
bridgeBankEventBurnSig
,
"bridgeBankEventWithdrawSig"
,
relayer
.
bridgeBankEventWithdrawSig
)
}
plugin/dapp/cross2eth/ebrelayer/relayer/ethereum/ethereum.go
View file @
c92b55a0
...
...
@@ -50,8 +50,8 @@ type Relayer4Ethereum struct {
privateKey4Ethereum
*
ecdsa
.
PrivateKey
ethSender
common
.
Address
processWithDraw
bool
ethValidator
common
.
Address
unlockchan
chan
int
maturityDegree
int32
fetchHeightPeriodMs
int32
...
...
@@ -95,6 +95,7 @@ type EthereumStartPara struct {
BlockInterval
int32
EthBridgeClaimChan
chan
<-
*
ebTypes
.
EthBridgeClaim
Chain33MsgChan
<-
chan
*
events
.
Chain33Msg
ProcessWithDraw
bool
}
//StartEthereumRelayer ///
...
...
@@ -108,6 +109,7 @@ func StartEthereumRelayer(startPara *EthereumStartPara) *Relayer4Ethereum {
db
:
startPara
.
DbHandle
,
unlockchan
:
make
(
chan
int
,
2
),
bridgeRegistryAddr
:
common
.
HexToAddress
(
startPara
.
BridgeRegistryAddr
),
processWithDraw
:
startPara
.
ProcessWithDraw
,
deployInfo
:
startPara
.
DeployInfo
,
maturityDegree
:
startPara
.
Degree
,
fetchHeightPeriodMs
:
startPara
.
BlockInterval
,
...
...
@@ -278,7 +280,7 @@ func (ethRelayer *Relayer4Ethereum) GetBalance(tokenAddr, owner string) (string,
func
(
ethRelayer
*
Relayer4Ethereum
)
ShowMultiBalance
(
tokenAddr
,
owner
string
)
(
string
,
error
)
{
relayerLog
.
Info
(
"ShowMultiBalance"
,
"tokenAddr"
,
tokenAddr
,
"owner"
,
owner
)
opts
:=
&
bind
.
CallOpts
{
From
:
ethRelayer
.
eth
Validato
r
,
From
:
ethRelayer
.
eth
Sende
r
,
Context
:
context
.
Background
(),
}
...
...
@@ -334,7 +336,7 @@ func (ethRelayer *Relayer4Ethereum) ShowLockedTokenAddress(tokenSymbol string) (
//IsProphecyPending ...
func
(
ethRelayer
*
Relayer4Ethereum
)
IsProphecyPending
(
claimID
[
32
]
byte
)
(
bool
,
error
)
{
return
ethtxs
.
IsProphecyPending
(
claimID
,
ethRelayer
.
eth
Validato
r
,
ethRelayer
.
x2EthContracts
.
Chain33Bridge
)
return
ethtxs
.
IsProphecyPending
(
claimID
,
ethRelayer
.
eth
Sende
r
,
ethRelayer
.
x2EthContracts
.
Chain33Bridge
)
}
//CreateBridgeToken ...
...
...
@@ -453,9 +455,7 @@ func (ethRelayer *Relayer4Ethereum) proc() {
}
ethRelayer
.
rwLock
.
Unlock
()
relayerLog
.
Info
(
"^-^ ^-^ Succeed to recover corresponding solidity contract handler"
)
//if nil != ethRelayer.recoverDeployPara() {
// panic("Failed to recoverDeployPara")
//}
ethRelayer
.
unlockchan
<-
start
}
...
...
@@ -497,7 +497,57 @@ latter:
}
func
(
ethRelayer
*
Relayer4Ethereum
)
handleChain33Msg
(
chain33Msg
*
events
.
Chain33Msg
)
{
relayerLog
.
Info
(
"handleChain33Msg"
,
"Received chain33Msg"
,
chain33Msg
,
"tx hash string"
,
common
.
Bytes2Hex
(
chain33Msg
.
TxHash
))
if
chain33Msg
.
ClaimType
==
events
.
ClaimTypeWithdraw
{
ethRelayer
.
handleLogWithdraw
(
chain33Msg
)
return
}
ethRelayer
.
handleLogLockBurn
(
chain33Msg
)
return
}
func
(
ethRelayer
*
Relayer4Ethereum
)
handleLogWithdraw
(
chain33Msg
*
events
.
Chain33Msg
)
{
if
!
ethRelayer
.
processWithDraw
{
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
}
tokenAddr
:=
common
.
HexToAddress
(
withdrawFromChain33TokenInfo
.
Address
)
//从chain33进行withdraw回来的token需要根据精度进行相应的缩放
if
8
!=
withdrawFromChain33TokenInfo
.
Decimal
{
if
withdrawFromChain33TokenInfo
.
Decimal
>
8
{
dist
:=
withdrawFromChain33TokenInfo
.
Decimal
-
8
value
,
exist
:=
utils
.
Decimal2value
[
int
(
dist
)]
if
!
exist
{
relayerLog
.
Error
(
"handleLogWithdraw"
,
"does support for decimal, %d"
,
withdrawFromChain33TokenInfo
.
Decimal
)
return
}
chain33Msg
.
Amount
.
Mul
(
chain33Msg
.
Amount
,
big
.
NewInt
(
value
))
}
else
{
dist
:=
8
-
withdrawFromChain33TokenInfo
.
Decimal
value
,
exist
:=
utils
.
Decimal2value
[
int
(
dist
)]
if
!
exist
{
relayerLog
.
Error
(
"handleLogWithdraw"
,
"does support for decimal, %d"
,
withdrawFromChain33TokenInfo
.
Decimal
)
return
}
chain33Msg
.
Amount
.
Div
(
chain33Msg
.
Amount
,
big
.
NewInt
(
value
))
}
}
relayerLog
.
Info
(
"handleLogWithdraw"
,
"token address"
,
tokenAddr
.
String
(),
"amount"
,
chain33Msg
.
Amount
.
String
(),
"Receiver on Ethereum"
,
chain33Msg
.
EthereumReceiver
.
String
())
//TODO:此处需要完成在以太坊发送以太或者ERC20数字资产的操作
}
func
(
ethRelayer
*
Relayer4Ethereum
)
handleLogLockBurn
(
chain33Msg
*
events
.
Chain33Msg
)
{
relayerLog
.
Info
(
"handleLogLockBurn"
,
"Received chain33Msg"
,
chain33Msg
,
"tx hash string"
,
common
.
Bytes2Hex
(
chain33Msg
.
TxHash
))
// Parse the Chain33Msg into a ProphecyClaim for relay to Ethereum
prophecyClaim
:=
ethtxs
.
Chain33MsgToProphecyClaim
(
*
chain33Msg
)
...
...
@@ -507,7 +557,7 @@ func (ethRelayer *Relayer4Ethereum) handleChain33Msg(chain33Msg *events.Chain33M
if
chain33Msg
.
ClaimType
==
events
.
ClaimTypeLock
{
tokenAddr
,
exist
=
ethRelayer
.
symbol2Addr
[
prophecyClaim
.
Symbol
]
if
!
exist
{
relayerLog
.
Info
(
"handle
Chain33Msg
"
,
"Query address from ethereum for symbol"
,
prophecyClaim
.
Symbol
)
relayerLog
.
Info
(
"handle
LogLockBurn
"
,
"Query address from ethereum for symbol"
,
prophecyClaim
.
Symbol
)
//因为是lock操作,则需要从创建的bridgeToken中进行查询
addr
,
err
:=
ethRelayer
.
ShowTokenAddrBySymbol
(
prophecyClaim
.
Symbol
)
if
err
!=
nil
{
...
...
@@ -521,7 +571,7 @@ func (ethRelayer *Relayer4Ethereum) handleChain33Msg(chain33Msg *events.Chain33M
err
=
ethRelayer
.
SetTokenAddress
(
token2set
)
if
nil
!=
err
{
// 尽管设置数据失败,但是不影响运行,只是relayer启动时,每次从节点远程获取bridge token地址而已
relayerLog
.
Error
(
"handle
Chain33Msg
"
,
"Failed to SetTokenAddress due to"
,
err
.
Error
())
relayerLog
.
Error
(
"handle
LogLockBurn
"
,
"Failed to SetTokenAddress due to"
,
err
.
Error
())
}
tokenAddr
=
common
.
HexToAddress
(
addr
)
}
...
...
@@ -529,14 +579,11 @@ func (ethRelayer *Relayer4Ethereum) handleChain33Msg(chain33Msg *events.Chain33M
burnFromChain33TokenInfo
,
exist
:=
ethRelayer
.
symbol2LockAddr
[
prophecyClaim
.
Symbol
]
if
!
exist
{
//因为是burn操作,必须从允许lock的token地址中进行查询
relayerLog
.
Error
(
"handle
Chain33Msg
"
,
"Failed to fetch locked Token Info for symbol"
,
prophecyClaim
.
Symbol
)
relayerLog
.
Error
(
"handle
LogLockBurn
"
,
"Failed to fetch locked Token Info for symbol"
,
prophecyClaim
.
Symbol
)
return
}
tokenAddr
=
common
.
HexToAddress
(
burnFromChain33TokenInfo
.
Address
)
//if lockedTokenInfo.Decimal == 18 {
// prophecyClaim.Amount = prophecyClaim.Amount.Mul(prophecyClaim.Amount, big.NewInt(int64(1e10)))
//}
//从chain33进行withdraw回来的token需要根据精度进行相应的缩放
if
8
!=
burnFromChain33TokenInfo
.
Decimal
{
if
burnFromChain33TokenInfo
.
Decimal
>
8
{
...
...
@@ -562,12 +609,12 @@ func (ethRelayer *Relayer4Ethereum) handleChain33Msg(chain33Msg *events.Chain33M
if
nil
!=
err
{
panic
(
"RelayOracleClaimToEthereum failed due to"
+
err
.
Error
())
}
relayerLog
.
Info
(
"handle
Chain33Msg
"
,
"RelayOracleClaimToEthereum with tx hash"
,
txhash
)
relayerLog
.
Info
(
"handle
LogLockBurn
"
,
"RelayOracleClaimToEthereum with tx hash"
,
txhash
)
//保存交易hash,方便查询
txIndex
:=
atomic
.
AddInt64
(
&
ethRelayer
.
totalTxRelayFromChain33
,
1
)
if
err
=
ethRelayer
.
updateTotalTxAmount2chain33
(
txIndex
);
nil
!=
err
{
relayerLog
.
Error
(
"handle
Chain33Msg
"
,
"Failed to RelayLockToChain33 due to:"
,
err
.
Error
())
relayerLog
.
Error
(
"handle
LogLockBurn
"
,
"Failed to RelayLockToChain33 due to:"
,
err
.
Error
())
return
}
statics
:=
&
ebTypes
.
Chain33ToEthereumStatics
{
...
...
@@ -585,7 +632,7 @@ func (ethRelayer *Relayer4Ethereum) handleChain33Msg(chain33Msg *events.Chain33M
}
data
:=
chain33Types
.
Encode
(
statics
)
if
err
=
ethRelayer
.
setLastestStatics
(
int32
(
chain33Msg
.
ClaimType
),
txIndex
,
data
);
nil
!=
err
{
relayerLog
.
Error
(
"handle
Chain33Msg
"
,
"Failed to RelayLockToChain33 due to:"
,
err
.
Error
())
relayerLog
.
Error
(
"handle
LogLockBurn
"
,
"Failed to RelayLockToChain33 due to:"
,
err
.
Error
())
return
}
relayerLog
.
Info
(
"RelayOracleClaimToEthereum::successful"
,
...
...
@@ -876,7 +923,7 @@ func (ethRelayer *Relayer4Ethereum) IsValidatorActive(addr string) (bool, error)
//ShowOperator ...
func
(
ethRelayer
*
Relayer4Ethereum
)
ShowOperator
()
(
string
,
error
)
{
operator
,
err
:=
ethtxs
.
GetOperator
(
ethRelayer
.
clientSpec
,
ethRelayer
.
eth
Validato
r
,
ethRelayer
.
bridgeBankAddr
)
operator
,
err
:=
ethtxs
.
GetOperator
(
ethRelayer
.
clientSpec
,
ethRelayer
.
eth
Sende
r
,
ethRelayer
.
bridgeBankAddr
)
if
nil
!=
err
{
return
""
,
err
}
...
...
plugin/dapp/cross2eth/ebrelayer/relayer/events/chain33Event.go
View file @
c92b55a0
...
...
@@ -18,11 +18,13 @@ const (
Chain33EventLogLock
//在chain33的evm合约中产生了burn事件
Chain33EventLogBurn
//在chain33的evm合约中产生了withdraw事件
Chain33EventLogWithdraw
)
// String : returns the event type as a string
func
(
d
Chain33EvmEvent
)
String
()
string
{
return
[
...
]
string
{
"unknown-event"
,
"LogLock"
,
"LogEthereumTokenBurn"
}[
d
]
return
[
...
]
string
{
"unknown-event"
,
"LogLock"
,
"LogEthereumTokenBurn"
,
"LogEthereumTokenWithdraw"
}[
d
]
}
// Chain33Msg : contains data from MsgBurn and MsgLock events
...
...
@@ -47,6 +49,17 @@ type LockEventOnChain33 struct {
Nonce
*
big
.
Int
}
// 发生在chain33 evm上的withdraw事件,当用户发起通过代理人提币交易时,则弹射出该事件信息
type
WithdrawEventOnChain33
struct
{
BridgeToken
chain33EvmCommon
.
Hash160Address
Symbol
string
Amount
*
big
.
Int
OwnerFrom
chain33EvmCommon
.
Hash160Address
EthereumReceiver
[]
byte
ProxyReceiver
chain33EvmCommon
.
Hash160Address
Nonce
*
big
.
Int
}
// 发生在chain33evm上的burn事件,当eth/erc20资产需要提币回到以太坊链上时,会发生该种事件
type
BurnEventOnChain33
struct
{
Token
chain33EvmCommon
.
Hash160Address
...
...
@@ -94,12 +107,31 @@ func UnpackChain33LogBurn(contractAbi abi.ABI, eventName string, eventData []byt
return
burnEvent
,
nil
}
// ParseBurnLock4chain33 ParseBurnLockTxReceipt : parses data from a Burn/Lock event witnessed on chain33 into a Chain33Msg struct
func
UnpackLogWithdraw
(
contractAbi
abi
.
ABI
,
eventName
string
,
eventData
[]
byte
)
(
withdrawEvent
*
WithdrawEventOnChain33
,
err
error
)
{
withdrawEvent
=
&
WithdrawEventOnChain33
{}
err
=
contractAbi
.
UnpackIntoInterface
(
withdrawEvent
,
eventName
,
eventData
)
if
err
!=
nil
{
eventsLog
.
Error
(
"UnpackLogWithdraw"
,
"Failed to unpack abi due to:"
,
err
.
Error
())
return
nil
,
err
}
eventsLog
.
Info
(
"UnpackLogWithdraw"
,
"bridge token addr on chain33 evm"
,
withdrawEvent
.
BridgeToken
.
ToAddress
()
.
String
(),
"symbol"
,
withdrawEvent
.
Symbol
,
"Amount"
,
withdrawEvent
.
Amount
.
String
(),
"Owner address from chain33"
,
withdrawEvent
.
OwnerFrom
.
ToAddress
()
.
String
(),
"EthereumReceiver"
,
common
.
BytesToAddress
(
withdrawEvent
.
EthereumReceiver
)
.
String
(),
"ProxyReceiver"
,
withdrawEvent
.
ProxyReceiver
.
ToAddress
()
.
String
(),
"nonce"
,
withdrawEvent
.
Nonce
.
String
())
return
withdrawEvent
,
nil
}
// ParseBurnLock4chain33 ParseBurnLockTxReceipt : parses data from a Burn/Lock/Withdraw event witnessed on chain33 into a Chain33Msg struct
func
ParseBurnLock4chain33
(
evmEventType
Chain33EvmEvent
,
data
[]
byte
,
bridgeBankAbi
abi
.
ABI
,
chain33TxHash
[]
byte
)
(
*
Chain33Msg
,
error
)
{
if
Chain33EventLogLock
==
evmEventType
{
lockEvent
,
err
:=
UnpackChain33LogLock
(
bridgeBankAbi
,
evmEventType
.
String
(),
data
)
if
nil
!=
err
{
eventsLog
.
Error
(
"UnpackChain33LogLock"
,
"failed due to"
,
err
.
Error
())
return
nil
,
err
}
...
...
@@ -118,7 +150,6 @@ func ParseBurnLock4chain33(evmEventType Chain33EvmEvent, data []byte, bridgeBank
}
else
if
Chain33EventLogBurn
==
evmEventType
{
burnEvent
,
err
:=
UnpackChain33LogBurn
(
bridgeBankAbi
,
evmEventType
.
String
(),
data
)
if
nil
!=
err
{
eventsLog
.
Error
(
"UnpackChain33LogBurn"
,
"failed due to"
,
err
.
Error
())
return
nil
,
err
}
...
...
@@ -133,6 +164,24 @@ func ParseBurnLock4chain33(evmEventType Chain33EvmEvent, data []byte, bridgeBank
Nonce
:
burnEvent
.
Nonce
.
Int64
(),
}
return
chain33Msg
,
nil
}
else
if
Chain33EventLogWithdraw
==
evmEventType
{
burnEvent
,
err
:=
UnpackLogWithdraw
(
bridgeBankAbi
,
evmEventType
.
String
(),
data
)
if
nil
!=
err
{
return
nil
,
err
}
chain33Msg
:=
&
Chain33Msg
{
ClaimType
:
ClaimTypeBurn
,
Chain33Sender
:
burnEvent
.
OwnerFrom
.
ToAddress
(),
EthereumReceiver
:
common
.
BytesToAddress
(
burnEvent
.
EthereumReceiver
),
TokenContractAddress
:
burnEvent
.
BridgeToken
.
ToAddress
(),
Symbol
:
burnEvent
.
Symbol
,
Amount
:
burnEvent
.
Amount
,
TxHash
:
chain33TxHash
,
Nonce
:
burnEvent
.
Nonce
.
Int64
(),
}
return
chain33Msg
,
nil
}
return
nil
,
errors
.
New
(
"unknown-event"
)
...
...
plugin/dapp/cross2eth/ebrelayer/relayer/events/events.go
View file @
c92b55a0
...
...
@@ -13,6 +13,7 @@ const (
ClaimTypeUnknown
=
ClaimType
(
0
)
ClaimTypeBurn
=
ClaimType
(
1
)
ClaimTypeLock
=
ClaimType
(
2
)
ClaimTypeWithdraw
=
ClaimType
(
3
)
)
const
(
...
...
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