Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
bridge-backend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
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
movabridge
bridge-backend
Commits
36eed812
Commit
36eed812
authored
Sep 18, 2025
by
vicotor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update code
parent
e0bb6f74
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
22 deletions
+78
-22
sync.go
chain/sync.go
+12
-12
builder.go
dao/builder.go
+30
-10
db.go
model/db/db.go
+36
-0
No files found.
chain/sync.go
View file @
36eed812
...
...
@@ -30,28 +30,28 @@ type ChainSync struct {
syncmode
bool
}
func
(
s
*
ChainSync
)
ParseTransferOut
(
log
types
.
Log
)
(
*
bridge
.
BridgeContractTransferOut
,
error
)
{
return
s
.
bridgeCa
.
ParseTransferOut
(
log
)
func
(
s
*
ChainSync
)
ParseTransferOut
(
log
*
types
.
Log
)
(
*
bridge
.
BridgeContractTransferOut
,
error
)
{
return
s
.
bridgeCa
.
ParseTransferOut
(
*
log
)
}
func
(
s
*
ChainSync
)
ParseTransferIn
(
log
types
.
Log
)
(
*
bridge
.
BridgeContractTransferIn
,
error
)
{
return
s
.
bridgeCa
.
ParseTransferIn
(
log
)
func
(
s
*
ChainSync
)
ParseTransferIn
(
log
*
types
.
Log
)
(
*
bridge
.
BridgeContractTransferIn
,
error
)
{
return
s
.
bridgeCa
.
ParseTransferIn
(
*
log
)
}
func
(
s
*
ChainSync
)
ParseTransferInExecution
(
log
types
.
Log
)
(
*
bridge
.
BridgeContractTransferInExecution
,
error
)
{
return
s
.
bridgeCa
.
ParseTransferInExecution
(
log
)
func
(
s
*
ChainSync
)
ParseTransferInExecution
(
log
*
types
.
Log
)
(
*
bridge
.
BridgeContractTransferInExecution
,
error
)
{
return
s
.
bridgeCa
.
ParseTransferInExecution
(
*
log
)
}
func
(
s
*
ChainSync
)
ParseTransferInRejection
(
log
types
.
Log
)
(
*
bridge
.
BridgeContractTransferInRejection
,
error
)
{
return
s
.
bridgeCa
.
ParseTransferInRejection
(
log
)
func
(
s
*
ChainSync
)
ParseTransferInRejection
(
log
*
types
.
Log
)
(
*
bridge
.
BridgeContractTransferInRejection
,
error
)
{
return
s
.
bridgeCa
.
ParseTransferInRejection
(
*
log
)
}
func
(
s
*
ChainSync
)
ParseTransferInConfirmation
(
log
types
.
Log
)
(
*
bridge
.
BridgeContractTransferInConfirmation
,
error
)
{
return
s
.
bridgeCa
.
ParseTransferInConfirmation
(
log
)
func
(
s
*
ChainSync
)
ParseTransferInConfirmation
(
log
*
types
.
Log
)
(
*
bridge
.
BridgeContractTransferInConfirmation
,
error
)
{
return
s
.
bridgeCa
.
ParseTransferInConfirmation
(
*
log
)
}
func
(
s
*
ChainSync
)
ParseTokenConfigChanged
(
log
types
.
Log
)
(
*
bridge
.
BridgeContractTokenConfigChanged
,
error
)
{
return
s
.
bridgeCa
.
ParseTokenConfigChanged
(
log
)
func
(
s
*
ChainSync
)
ParseTokenConfigChanged
(
log
*
types
.
Log
)
(
*
bridge
.
BridgeContractTokenConfigChanged
,
error
)
{
return
s
.
bridgeCa
.
ParseTokenConfigChanged
(
*
log
)
}
func
(
s
*
ChainSync
)
GetReceiveToken
(
token
common
.
Address
,
toChainId
int64
)
(
string
,
error
)
{
...
...
dao/builder.go
View file @
36eed812
...
...
@@ -17,12 +17,12 @@ type ChainInterface interface {
Name
()
string
GetChain
()
*
config
.
ChainConfig
IsSyncing
()
bool
ParseTransferOut
(
log
types
.
Log
)
(
*
bridge
.
BridgeContractTransferOut
,
error
)
ParseTransferIn
(
log
types
.
Log
)
(
*
bridge
.
BridgeContractTransferIn
,
error
)
ParseTransferInExecution
(
log
types
.
Log
)
(
*
bridge
.
BridgeContractTransferInExecution
,
error
)
ParseTransferInRejection
(
log
types
.
Log
)
(
*
bridge
.
BridgeContractTransferInRejection
,
error
)
ParseTransferInConfirmation
(
log
types
.
Log
)
(
*
bridge
.
BridgeContractTransferInConfirmation
,
error
)
ParseTokenConfigChanged
(
log
types
.
Log
)
(
*
bridge
.
BridgeContractTokenConfigChanged
,
error
)
ParseTransferOut
(
log
*
types
.
Log
)
(
*
bridge
.
BridgeContractTransferOut
,
error
)
ParseTransferIn
(
log
*
types
.
Log
)
(
*
bridge
.
BridgeContractTransferIn
,
error
)
ParseTransferInExecution
(
log
*
types
.
Log
)
(
*
bridge
.
BridgeContractTransferInExecution
,
error
)
ParseTransferInRejection
(
log
*
types
.
Log
)
(
*
bridge
.
BridgeContractTransferInRejection
,
error
)
ParseTransferInConfirmation
(
log
*
types
.
Log
)
(
*
bridge
.
BridgeContractTransferInConfirmation
,
error
)
ParseTokenConfigChanged
(
log
*
types
.
Log
)
(
*
bridge
.
BridgeContractTokenConfigChanged
,
error
)
GetReceiveToken
(
token
common
.
Address
,
toChainId
int64
)
(
string
,
error
)
}
...
...
@@ -42,6 +42,26 @@ func (s *Dao) HandleEvents(chain ChainInterface, logs []types.Log) error {
cname
:=
chain
.
Name
()
// refetch all logs
var
txs
[]
common
.
Hash
var
txexist
=
make
(
map
[
common
.
Hash
]
bool
)
for
_
,
lg
:=
range
logs
{
if
_
,
ok
:=
txexist
[
lg
.
TxHash
];
!
ok
{
txs
=
append
(
txs
,
lg
.
TxHash
)
txexist
[
lg
.
TxHash
]
=
true
}
}
var
allLogs
[]
*
types
.
Log
client
:=
s
.
chainGroup
[
chain
.
GetChain
()
.
ChainId
]
.
cli
for
_
,
tx
:=
range
txs
{
receipt
,
err
:=
client
.
TransactionReceipt
(
context
.
Background
(),
tx
)
if
err
!=
nil
{
log
.
WithField
(
"chain"
,
cname
)
.
WithError
(
err
)
.
Error
(
"get tx receipt failed"
)
return
err
}
allLogs
=
append
(
allLogs
,
receipt
.
Logs
...
)
}
// begin orm transaction
//supportSession := s.SupportsTransactions()
var
ctx
context
.
Context
=
context
.
Background
()
...
...
@@ -60,7 +80,7 @@ func (s *Dao) HandleEvents(chain ChainInterface, logs []types.Log) error {
//}
var
ormTxErr
error
for
_
,
txLog
:=
range
l
ogs
{
for
_
,
txLog
:=
range
allL
ogs
{
if
err
:=
s
.
filterTransferOut
(
chain
,
txLog
,
ctx
);
err
!=
nil
{
ormTxErr
=
err
break
...
...
@@ -100,7 +120,7 @@ func (s *Dao) HandleEvents(chain ChainInterface, logs []types.Log) error {
}
// filterTransferOut 用户从当前链跨出事件.
func
(
s
*
Dao
)
filterTransferOut
(
chain
ChainInterface
,
txLog
types
.
Log
,
ctx
context
.
Context
)
error
{
func
(
s
*
Dao
)
filterTransferOut
(
chain
ChainInterface
,
txLog
*
types
.
Log
,
ctx
context
.
Context
)
error
{
if
len
(
txLog
.
Topics
)
==
0
{
return
nil
}
...
...
@@ -137,7 +157,7 @@ func (s *Dao) filterTransferOut(chain ChainInterface, txLog types.Log, ctx conte
}
// filterTransferIn 用户从目标链跨入事件及执行结束事件.
func
(
s
*
Dao
)
filterTransferIn
(
chain
ChainInterface
,
txLog
types
.
Log
,
ctx
context
.
Context
)
error
{
func
(
s
*
Dao
)
filterTransferIn
(
chain
ChainInterface
,
txLog
*
types
.
Log
,
ctx
context
.
Context
)
error
{
if
len
(
txLog
.
Topics
)
==
0
{
return
nil
}
...
...
@@ -270,7 +290,7 @@ func (s *Dao) filterTransferIn(chain ChainInterface, txLog types.Log, ctx contex
return
nil
}
func
(
s
*
Dao
)
filterTokenConfigChanged
(
chain
ChainInterface
,
txLog
types
.
Log
,
ctx
context
.
Context
)
error
{
func
(
s
*
Dao
)
filterTokenConfigChanged
(
chain
ChainInterface
,
txLog
*
types
.
Log
,
ctx
context
.
Context
)
error
{
if
len
(
txLog
.
Topics
)
==
0
{
return
nil
}
...
...
model/db/db.go
View file @
36eed812
...
...
@@ -14,6 +14,42 @@ func (h *Height) TableName() string {
return
"heights"
}
type
TransferOutEvent
struct
{
ID
primitive
.
ObjectID
`bson:"_id,omitempty"`
FromChain
int64
`bson:"from_chain"`
OutTimestamp
int64
`bson:"out_timestamp"`
FromToken
string
`bson:"from_token"`
FromAddress
string
`bson:"from_address"`
FromChainTxHash
string
`bson:"from_chain_tx_hash"`
SendAmount
string
`bson:"send_amount"`
FeeAmount
string
`bson:"fee_amount"`
Receiver
string
`bson:"receiver"`
ToChain
int64
`bson:"to_chain"`
ToToken
string
`bson:"to_token"`
ReceiveAmount
string
`bson:"receive_amount"`
OutId
int64
`bson:"out_id"`
}
func
(
t
*
TransferOutEvent
)
TableName
()
string
{
return
"transfer_out_events"
}
type
TransferInEvent
struct
{
ID
primitive
.
ObjectID
`bson:"_id,omitempty"`
ChainId
int64
`bson:"chain_id"`
InTimestamp
int64
`bson:"in_timestamp"`
InId
int64
`bson:"in_id"`
ToContract
string
`bson:"to_contract"`
ToChainTxHash
string
`bson:"to_chain_tx_hash"`
ToChainStatus
int
`bson:"to_chain_status"`
ConfirmedValidators
[]
string
`bson:"confirmed_validators"`
RejectedValidators
[]
string
`bson:"rejected_validators"`
}
func
(
t
*
TransferInEvent
)
TableName
()
string
{
return
"transfer_in_events"
}
type
BridgeEvent
struct
{
ID
primitive
.
ObjectID
`bson:"_id,omitempty"`
FromChain
int64
`bson:"from_chain"`
...
...
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