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
3d238249
Commit
3d238249
authored
Dec 28, 2021
by
QM
Committed by
33cn
Dec 29, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add setWithdrawStatics
parent
cfcea967
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
57 additions
and
46 deletions
+57
-46
statics.go
plugin/dapp/cross2eth/ebcli/statics.go
+14
-5
relayer.proto
plugin/dapp/cross2eth/ebrelayer/proto/relayer.proto
+1
-1
ethereum.go
plugin/dapp/cross2eth/ebrelayer/relayer/ethereum/ethereum.go
+14
-40
store.go
plugin/dapp/cross2eth/ebrelayer/relayer/ethereum/store.go
+28
-0
config.pb.go
plugin/dapp/cross2eth/ebrelayer/types/config.pb.go
+0
-0
relayer.pb.go
plugin/dapp/cross2eth/ebrelayer/types/relayer.pb.go
+0
-0
No files found.
plugin/dapp/cross2eth/ebcli/statics.go
View file @
3d238249
...
...
@@ -25,7 +25,7 @@ func ShowStaticsFlags(cmd *cobra.Command) {
cmd
.
Flags
()
.
StringP
(
"symbol"
,
"s"
,
""
,
"token symbol(optional)"
)
cmd
.
Flags
()
.
Int32P
(
"from"
,
"f"
,
0
,
"source chain, 0=ethereum, and 1=chain33"
)
_
=
cmd
.
MarkFlagRequired
(
"from"
)
cmd
.
Flags
()
.
Int32P
(
"operation"
,
"o"
,
0
,
"operation type, 1=burn, 2=lock, 3
=withdraw"
)
cmd
.
Flags
()
.
StringP
(
"operation"
,
"o"
,
"b"
,
"operation type, b=burn, l=lock, w
=withdraw"
)
_
=
cmd
.
MarkFlagRequired
(
"operation"
)
cmd
.
Flags
()
.
Int32P
(
"status"
,
"u"
,
0
,
"show with specified status, default to show all, 1=pending, 2=successful, 3=failed"
)
cmd
.
Flags
()
.
Int32P
(
"count"
,
"n"
,
0
,
"count to show, default to show all"
)
...
...
@@ -37,7 +37,7 @@ func ShowStatics(cmd *cobra.Command, args []string) {
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
symbol
,
_
:=
cmd
.
Flags
()
.
GetString
(
"symbol"
)
from
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"from"
)
operation
,
_
:=
cmd
.
Flags
()
.
Get
Int32
(
"operation"
)
operation
,
_
:=
cmd
.
Flags
()
.
Get
String
(
"operation"
)
status
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"status"
)
count
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"count"
)
index
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"index"
)
...
...
@@ -47,8 +47,8 @@ func ShowStatics(cmd *cobra.Command, args []string) {
return
}
if
operation
!=
2
&&
1
!=
operation
&&
operation
!=
3
{
fmt
.
Println
(
"Pls set correct operation type,
1=burn, 2=lock, 3
=withdraw"
)
if
operation
!=
"b"
&&
"l"
!=
operation
&&
operation
!=
"w"
{
fmt
.
Println
(
"Pls set correct operation type,
b=burn, l=lock, w
=withdraw"
)
return
}
...
...
@@ -57,10 +57,19 @@ func ShowStatics(cmd *cobra.Command, args []string) {
return
}
var
operationInt
int32
if
operation
==
"b"
{
operationInt
=
1
}
else
if
operation
==
"l"
{
operationInt
=
2
}
else
if
operation
==
"w"
{
operationInt
=
3
}
para
:=
&
ebTypes
.
TokenStaticsRequest
{
Symbol
:
symbol
,
From
:
from
,
Operation
:
operation
,
Operation
:
operation
Int
,
Status
:
status
,
TxIndex
:
int64
(
index
),
Count
:
count
,
...
...
plugin/dapp/cross2eth/ebrelayer/proto/relayer.proto
View file @
3d238249
...
...
@@ -151,7 +151,7 @@ message Chain33ToEthereumStatics {
string
ethTxstatus
=
1
;
string
chain33Txhash
=
2
;
string
EthereumTxhash
=
3
;
int32
burnLock
=
4
;
int32
burnLock
Withdraw
=
4
;
//该笔lock或者burn交易的chain33发起人
string
chain33Sender
=
5
;
string
ethereumReceiver
=
6
;
...
...
plugin/dapp/cross2eth/ebrelayer/relayer/ethereum/ethereum.go
View file @
3d238249
...
...
@@ -579,6 +579,11 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33
if
nil
!=
err
{
relayerLog
.
Error
(
"handleLogWithdraw"
,
"Failed to setWithdraw due to:"
,
err
.
Error
())
}
err
=
ethRelayer
.
setWithdrawStatics
(
withdrawTx
,
chain33Msg
)
if
nil
!=
err
{
relayerLog
.
Error
(
"handleLogWithdraw"
,
"Failed to setWithdrawStatics due to:"
,
err
.
Error
())
}
}()
relayerLog
.
Info
(
"handleLogWithdraw"
,
"Received chain33Msg"
,
chain33Msg
,
"tx hash string"
,
common
.
Bytes2Hex
(
chain33Msg
.
TxHash
))
...
...
@@ -653,7 +658,8 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33
}
//校验余额是否充足
if
ok
,
err
:=
ethRelayer
.
checkBalanceEnough
(
toAddr
,
amount2transfer
,
balanceOfData
);
!
ok
{
err
=
ethRelayer
.
checkBalanceEnough
(
toAddr
,
amount2transfer
,
balanceOfData
)
if
err
!=
nil
{
relayerLog
.
Error
(
"handleLogWithdraw"
,
"Failed to checkBalanceEnough:"
,
err
.
Error
())
err
=
errors
.
New
(
"ErrBalanceNotEnough"
)
return
...
...
@@ -687,40 +693,10 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33
withdrawTx
.
StatusDescription
=
ethtxs
.
WDPending
.
String
()
withdrawTx
.
TxHashOnEthereum
=
signedTx
.
Hash
()
.
String
()
txIndex
:=
atomic
.
AddInt64
(
&
ethRelayer
.
totalTxRelayFromChain33
,
1
)
operationType
:=
chain33Msg
.
ClaimType
.
String
()
statics
:=
&
ebTypes
.
Chain33ToEthereumStatics
{
EthTxstatus
:
ebTypes
.
Tx_Status_Pending
,
Chain33Txhash
:
common
.
Bytes2Hex
(
chain33Msg
.
TxHash
),
EthereumTxhash
:
withdrawTx
.
TxHashOnEthereum
,
BurnLock
:
int32
(
chain33Msg
.
ClaimType
),
Chain33Sender
:
chain33Msg
.
Chain33Sender
.
String
(),
EthereumReceiver
:
chain33Msg
.
EthereumReceiver
.
String
(),
Symbol
:
chain33Msg
.
Symbol
,
Amount
:
chain33Msg
.
Amount
.
String
(),
Nonce
:
chain33Msg
.
Nonce
,
TxIndex
:
txIndex
,
OperationType
:
operationType
,
}
data
:=
chain33Types
.
Encode
(
statics
)
if
err
=
ethRelayer
.
setLastestStatics
(
int32
(
chain33Msg
.
ClaimType
),
txIndex
,
data
);
nil
!=
err
{
relayerLog
.
Error
(
"handleLogLockBurn"
,
"Failed to RelayLockToChain33 due to:"
,
err
.
Error
())
return
}
relayerLog
.
Info
(
"RelayOracleClaimToEthereum::successful"
,
"txIndex"
,
txIndex
,
"Chain33Txhash"
,
statics
.
Chain33Txhash
,
"EthereumTxhash"
,
statics
.
EthereumTxhash
,
"type"
,
operationType
,
"Symbol"
,
chain33Msg
.
Symbol
,
"Amount"
,
chain33Msg
.
Amount
,
"EthereumReceiver"
,
statics
.
EthereumReceiver
,
"Chain33Sender"
,
statics
.
Chain33Sender
)
return
}
func
(
ethRelayer
*
Relayer4Ethereum
)
checkBalanceEnough
(
addr
common
.
Address
,
amount
*
big
.
Int
,
inputdata
[]
byte
)
(
bool
,
error
)
{
func
(
ethRelayer
*
Relayer4Ethereum
)
checkBalanceEnough
(
addr
common
.
Address
,
amount
*
big
.
Int
,
inputdata
[]
byte
)
error
{
//检测地址余额
var
balance
*
big
.
Int
var
err
error
...
...
@@ -730,7 +706,7 @@ func (ethRelayer *Relayer4Ethereum) checkBalanceEnough(addr common.Address, amou
//retry
balance
,
err
=
ethRelayer
.
clientSpec
.
BalanceAt
(
context
.
Background
(),
addr
,
nil
)
if
err
!=
nil
{
return
false
,
err
return
err
}
}
}
else
{
...
...
@@ -742,24 +718,22 @@ func (ethRelayer *Relayer4Ethereum) checkBalanceEnough(addr common.Address, amou
//retry
result
,
err
=
ethRelayer
.
clientSpec
.
CallContract
(
context
.
Background
(),
msg
,
nil
)
if
err
!=
nil
{
return
false
,
err
return
err
}
}
var
ok
bool
balance
,
ok
=
big
.
NewInt
(
1
)
.
SetString
(
common
.
Bytes2Hex
(
result
),
16
)
if
!
ok
{
return
false
,
errors
.
New
(
fmt
.
Sprintf
(
"token balance err:%v"
,
common
.
Bytes2Hex
(
result
)))
return
errors
.
New
(
fmt
.
Sprintf
(
"token balance err:%v"
,
common
.
Bytes2Hex
(
result
)))
}
}
//与要发动的金额大小进行比较
if
balance
.
Cmp
(
amount
)
>
0
{
return
true
,
nil
return
nil
}
relayerLog
.
Error
(
"Insufficient balance"
,
"balance"
,
balance
,
"amount"
,
amount
)
return
false
,
errors
.
New
(
"Insufficient balance"
)
return
errors
.
New
(
"Insufficient balance"
)
}
func
(
ethRelayer
*
Relayer4Ethereum
)
signTx
(
tx
*
types
.
Transaction
,
key
*
ecdsa
.
PrivateKey
)
(
*
types
.
Transaction
,
error
)
{
...
...
@@ -880,7 +854,7 @@ func (ethRelayer *Relayer4Ethereum) handleLogLockBurn(chain33Msg *events.Chain33
EthTxstatus
:
ebTypes
.
Tx_Status_Pending
,
Chain33Txhash
:
common
.
Bytes2Hex
(
chain33Msg
.
TxHash
),
EthereumTxhash
:
txhash
,
BurnLock
:
int32
(
chain33Msg
.
ClaimType
),
BurnLock
Withdraw
:
int32
(
chain33Msg
.
ClaimType
),
Chain33Sender
:
chain33Msg
.
Chain33Sender
.
String
(),
EthereumReceiver
:
chain33Msg
.
EthereumReceiver
.
String
(),
Symbol
:
chain33Msg
.
Symbol
,
...
...
plugin/dapp/cross2eth/ebrelayer/relayer/ethereum/store.go
View file @
3d238249
...
...
@@ -4,7 +4,9 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/33cn/plugin/plugin/dapp/cross2eth/ebrelayer/relayer/ethereum/ethtxs"
"math/big"
"sync/atomic"
"github.com/ethereum/go-ethereum/common"
...
...
@@ -460,6 +462,32 @@ func (ethRelayer *Relayer4Ethereum) setWithdraw(withdrawTx *ebTypes.WithdrawTx)
return
ethRelayer
.
db
.
Set
(
listKey
,
listData
)
}
func
(
ethRelayer
*
Relayer4Ethereum
)
setWithdrawStatics
(
withdrawTx
*
ebTypes
.
WithdrawTx
,
chain33Msg
*
events
.
Chain33Msg
)
error
{
txIndex
:=
atomic
.
AddInt64
(
&
ethRelayer
.
totalTxRelayFromChain33
,
1
)
operationType
:=
chain33Msg
.
ClaimType
.
String
()
statics
:=
&
ebTypes
.
Chain33ToEthereumStatics
{
EthTxstatus
:
ebTypes
.
Tx_Status_Pending
,
Chain33Txhash
:
common
.
Bytes2Hex
(
chain33Msg
.
TxHash
),
EthereumTxhash
:
withdrawTx
.
TxHashOnEthereum
,
BurnLockWithdraw
:
int32
(
chain33Msg
.
ClaimType
),
Chain33Sender
:
chain33Msg
.
Chain33Sender
.
String
(),
EthereumReceiver
:
chain33Msg
.
EthereumReceiver
.
String
(),
Symbol
:
chain33Msg
.
Symbol
,
Amount
:
chain33Msg
.
Amount
.
String
(),
Nonce
:
chain33Msg
.
Nonce
,
TxIndex
:
txIndex
,
OperationType
:
operationType
,
}
if
withdrawTx
.
Status
==
int32
(
ethtxs
.
WDError
)
{
statics
.
EthTxstatus
=
ebTypes
.
Tx_Status_Failed
}
relayerLog
.
Info
(
"setWithdrawStatics::successful"
,
"txIndex"
,
txIndex
,
"Chain33Txhash"
,
statics
.
Chain33Txhash
,
"EthereumTxhash"
,
statics
.
EthereumTxhash
,
"type"
,
operationType
,
"Symbol"
,
chain33Msg
.
Symbol
,
"Amount"
,
chain33Msg
.
Amount
,
"EthereumReceiver"
,
statics
.
EthereumReceiver
,
"Chain33Sender"
,
statics
.
Chain33Sender
)
data
:=
chain33Types
.
Encode
(
statics
)
return
ethRelayer
.
setLastestStatics
(
int32
(
chain33Msg
.
ClaimType
),
txIndex
,
data
)
}
func
(
ethRelayer
*
Relayer4Ethereum
)
getWithdrawsWithinSameDay
(
withdrawTx
*
ebTypes
.
WithdrawTx
)
(
*
big
.
Int
,
error
)
{
chain33Sender
:=
withdrawTx
.
Chain33Sender
symbol
:=
withdrawTx
.
Symbol
...
...
plugin/dapp/cross2eth/ebrelayer/types/config.pb.go
View file @
3d238249
This diff is collapsed.
Click to expand it.
plugin/dapp/cross2eth/ebrelayer/types/relayer.pb.go
View file @
3d238249
This source diff could not be displayed because it is too large. You can
view the blob
instead.
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