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
e865d202
Commit
e865d202
authored
Nov 20, 2025
by
vicotor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add swap token config support.
parent
b086b896
Changes
11
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
1277 additions
and
24 deletions
+1277
-24
sync.go
chain/sync.go
+5
-0
constant.go
constant/constant.go
+1
-0
Bridge.go
contract/bridge/Bridge.go
+923
-12
bridge.json
contract/bridge/bridge.json
+157
-12
builder.go
dao/builder.go
+51
-0
db.go
dao/db.go
+70
-0
dbtx.go
dao/dbtx.go
+13
-0
model.go
model/api/model.go
+17
-0
db.go
model/db/db.go
+15
-0
controller.go
server/controller.go
+24
-0
router.go
server/router.go
+1
-0
No files found.
chain/sync.go
View file @
e865d202
...
@@ -54,6 +54,10 @@ func (s *ChainSync) ParseTokenConfigChanged(log *types.Log) (*bridge.BridgeContr
...
@@ -54,6 +54,10 @@ func (s *ChainSync) ParseTokenConfigChanged(log *types.Log) (*bridge.BridgeContr
return
s
.
bridgeCa
.
ParseTokenOutConfigChanged
(
*
log
)
return
s
.
bridgeCa
.
ParseTokenOutConfigChanged
(
*
log
)
}
}
func
(
s
*
ChainSync
)
ParseSwapConfigChanged
(
log
*
types
.
Log
)
(
*
bridge
.
BridgeContractSwapConfigChanged
,
error
)
{
return
s
.
bridgeCa
.
ParseSwapConfigChanged
(
*
log
)
}
func
(
s
*
ChainSync
)
GetReceiveToken
(
token
common
.
Address
,
toChainId
int64
)
(
string
,
error
)
{
func
(
s
*
ChainSync
)
GetReceiveToken
(
token
common
.
Address
,
toChainId
int64
)
(
string
,
error
)
{
callOpt
:=
&
bind
.
CallOpts
{
callOpt
:=
&
bind
.
CallOpts
{
BlockNumber
:
nil
,
BlockNumber
:
nil
,
...
@@ -206,6 +210,7 @@ func (s *ChainSync) SyncLogs(beginHeight, endHeight int64) error {
...
@@ -206,6 +210,7 @@ func (s *ChainSync) SyncLogs(beginHeight, endHeight int64) error {
dao
.
TransferInRejectionEvent
.
ID
.
Hex
(),
dao
.
TransferInRejectionEvent
.
ID
.
Hex
(),
dao
.
TransferInExecutionEvent
.
ID
.
Hex
(),
dao
.
TransferInExecutionEvent
.
ID
.
Hex
(),
dao
.
TokenConfigChangedEvent
.
ID
.
Hex
(),
dao
.
TokenConfigChangedEvent
.
ID
.
Hex
(),
dao
.
SwapConfigChangedEvent
.
ID
.
Hex
(),
}
}
logs
,
err
:=
s
.
d
.
GetLogs
(
s
.
chain
,
beginHeight
,
endHeight
,
topics
,
[]
string
{
logs
,
err
:=
s
.
d
.
GetLogs
(
s
.
chain
,
beginHeight
,
endHeight
,
topics
,
[]
string
{
...
...
constant/constant.go
View file @
e865d202
...
@@ -46,6 +46,7 @@ const (
...
@@ -46,6 +46,7 @@ const (
EVENT_TRANSFER_IN_REJECTION
=
"TransferInRejection"
EVENT_TRANSFER_IN_REJECTION
=
"TransferInRejection"
EVENT_TRANSFER_IN_EXECUTION
=
"TransferInExecution"
EVENT_TRANSFER_IN_EXECUTION
=
"TransferInExecution"
EVENT_TOKENCONFIGCHANGED
=
"TokenOutConfigChanged"
EVENT_TOKENCONFIGCHANGED
=
"TokenOutConfigChanged"
EVENT_SWAPCONFIGCHANGED
=
"SwapConfigChanged"
)
)
type
ValidatorOp
int
type
ValidatorOp
int
...
...
contract/bridge/Bridge.go
View file @
e865d202
This diff is collapsed.
Click to expand it.
contract/bridge/bridge.json
View file @
e865d202
[
[
{
{
"anonymous"
:
false
,
"inputs"
:
[
"inputs"
:
[
{
{
"indexed"
:
false
,
"internalType"
:
"address"
,
"internalType"
:
"address"
,
"name"
:
"initialOwner"
,
"name"
:
"previousAdmin"
,
"type"
:
"address"
},
{
"indexed"
:
false
,
"internalType"
:
"address"
,
"name"
:
"newAdmin"
,
"type"
:
"address"
"type"
:
"address"
}
}
],
],
"
stateMutability"
:
"nonpayable
"
,
"
name"
:
"AdminChanged
"
,
"type"
:
"
constructor
"
"type"
:
"
event
"
},
},
{
{
"anonymous"
:
false
,
"inputs"
:
[
"inputs"
:
[
{
{
"indexed"
:
true
,
"internalType"
:
"address"
,
"internalType"
:
"address"
,
"name"
:
"
owner
"
,
"name"
:
"
beacon
"
,
"type"
:
"address"
"type"
:
"address"
}
}
],
],
"name"
:
"
OwnableInvalidOwner
"
,
"name"
:
"
BeaconUpgraded
"
,
"type"
:
"e
rror
"
"type"
:
"e
vent
"
},
},
{
{
"anonymous"
:
false
,
"inputs"
:
[
"inputs"
:
[
{
{
"indexed"
:
true
,
"internalType"
:
"address"
,
"name"
:
"oldReceiver"
,
"type"
:
"address"
},
{
"indexed"
:
true
,
"internalType"
:
"address"
,
"internalType"
:
"address"
,
"name"
:
"
account
"
,
"name"
:
"
newReceiver
"
,
"type"
:
"address"
"type"
:
"address"
}
}
],
],
"name"
:
"
OwnableUnauthorizedAccount
"
,
"name"
:
"
FeeReceiverChanged
"
,
"type"
:
"e
rror
"
"type"
:
"e
vent
"
},
},
{
{
"anonymous"
:
false
,
"anonymous"
:
false
,
...
@@ -70,6 +88,37 @@
...
@@ -70,6 +88,37 @@
"name"
:
"RequirementChange"
,
"name"
:
"RequirementChange"
,
"type"
:
"event"
"type"
:
"event"
},
},
{
"anonymous"
:
false
,
"inputs"
:
[
{
"indexed"
:
true
,
"internalType"
:
"address"
,
"name"
:
"fromToken"
,
"type"
:
"address"
},
{
"indexed"
:
true
,
"internalType"
:
"address"
,
"name"
:
"toToken"
,
"type"
:
"address"
},
{
"indexed"
:
true
,
"internalType"
:
"address"
,
"name"
:
"swap"
,
"type"
:
"address"
},
{
"indexed"
:
false
,
"internalType"
:
"address[]"
,
"name"
:
"path"
,
"type"
:
"address[]"
}
],
"name"
:
"SwapConfigChanged"
,
"type"
:
"event"
},
{
{
"anonymous"
:
false
,
"anonymous"
:
false
,
"inputs"
:
[
"inputs"
:
[
...
@@ -211,19 +260,19 @@
...
@@ -211,19 +260,19 @@
"anonymous"
:
false
,
"anonymous"
:
false
,
"inputs"
:
[
"inputs"
:
[
{
{
"indexed"
:
fals
e
,
"indexed"
:
tru
e
,
"internalType"
:
"uint256"
,
"internalType"
:
"uint256"
,
"name"
:
"outId"
,
"name"
:
"outId"
,
"type"
:
"uint256"
"type"
:
"uint256"
},
},
{
{
"indexed"
:
fals
e
,
"indexed"
:
tru
e
,
"internalType"
:
"uint256"
,
"internalType"
:
"uint256"
,
"name"
:
"fromChainID"
,
"name"
:
"fromChainID"
,
"type"
:
"uint256"
"type"
:
"uint256"
},
},
{
{
"indexed"
:
fals
e
,
"indexed"
:
tru
e
,
"internalType"
:
"address"
,
"internalType"
:
"address"
,
"name"
:
"sender"
,
"name"
:
"sender"
,
"type"
:
"address"
"type"
:
"address"
...
@@ -349,6 +398,19 @@
...
@@ -349,6 +398,19 @@
"name"
:
"TreasuryTransfer"
,
"name"
:
"TreasuryTransfer"
,
"type"
:
"event"
"type"
:
"event"
},
},
{
"anonymous"
:
false
,
"inputs"
:
[
{
"indexed"
:
true
,
"internalType"
:
"address"
,
"name"
:
"implementation"
,
"type"
:
"address"
}
],
"name"
:
"Upgraded"
,
"type"
:
"event"
},
{
{
"anonymous"
:
false
,
"anonymous"
:
false
,
"inputs"
:
[
"inputs"
:
[
...
@@ -560,6 +622,19 @@
...
@@ -560,6 +622,19 @@
"stateMutability"
:
"nonpayable"
,
"stateMutability"
:
"nonpayable"
,
"type"
:
"function"
"type"
:
"function"
},
},
{
"inputs"
:
[],
"name"
:
"feeReceiver"
,
"outputs"
:
[
{
"internalType"
:
"address"
,
"name"
:
""
,
"type"
:
"address"
}
],
"stateMutability"
:
"view"
,
"type"
:
"function"
},
{
{
"inputs"
:
[
"inputs"
:
[
{
{
...
@@ -686,6 +761,19 @@
...
@@ -686,6 +761,19 @@
"stateMutability"
:
"view"
,
"stateMutability"
:
"view"
,
"type"
:
"function"
"type"
:
"function"
},
},
{
"inputs"
:
[
{
"internalType"
:
"address"
,
"name"
:
"initialOwner"
,
"type"
:
"address"
}
],
"name"
:
"initialize"
,
"outputs"
:
[],
"stateMutability"
:
"nonpayable"
,
"type"
:
"function"
},
{
{
"inputs"
:
[
"inputs"
:
[
{
{
...
@@ -993,6 +1081,19 @@
...
@@ -993,6 +1081,19 @@
"stateMutability"
:
"view"
,
"stateMutability"
:
"view"
,
"type"
:
"function"
"type"
:
"function"
},
},
{
"inputs"
:
[],
"name"
:
"proxiableUUID"
,
"outputs"
:
[
{
"internalType"
:
"bytes32"
,
"name"
:
""
,
"type"
:
"bytes32"
}
],
"stateMutability"
:
"view"
,
"type"
:
"function"
},
{
{
"inputs"
:
[
"inputs"
:
[
{
{
...
@@ -1072,6 +1173,19 @@
...
@@ -1072,6 +1173,19 @@
"stateMutability"
:
"nonpayable"
,
"stateMutability"
:
"nonpayable"
,
"type"
:
"function"
"type"
:
"function"
},
},
{
"inputs"
:
[
{
"internalType"
:
"address"
,
"name"
:
"newReceiver"
,
"type"
:
"address"
}
],
"name"
:
"setFeeReceiver"
,
"outputs"
:
[],
"stateMutability"
:
"nonpayable"
,
"type"
:
"function"
},
{
{
"inputs"
:
[
"inputs"
:
[
{
{
...
@@ -1276,6 +1390,37 @@
...
@@ -1276,6 +1390,37 @@
"stateMutability"
:
"view"
,
"stateMutability"
:
"view"
,
"type"
:
"function"
"type"
:
"function"
},
},
{
"inputs"
:
[
{
"internalType"
:
"address"
,
"name"
:
"newImplementation"
,
"type"
:
"address"
}
],
"name"
:
"upgradeTo"
,
"outputs"
:
[],
"stateMutability"
:
"nonpayable"
,
"type"
:
"function"
},
{
"inputs"
:
[
{
"internalType"
:
"address"
,
"name"
:
"newImplementation"
,
"type"
:
"address"
},
{
"internalType"
:
"bytes"
,
"name"
:
"data"
,
"type"
:
"bytes"
}
],
"name"
:
"upgradeToAndCall"
,
"outputs"
:
[],
"stateMutability"
:
"payable"
,
"type"
:
"function"
},
{
{
"inputs"
:
[],
"inputs"
:
[],
"name"
:
"validRequired"
,
"name"
:
"validRequired"
,
...
...
dao/builder.go
View file @
e865d202
...
@@ -23,6 +23,7 @@ type ChainInterface interface {
...
@@ -23,6 +23,7 @@ type ChainInterface interface {
ParseTransferInRejection
(
log
*
types
.
Log
)
(
*
bridge
.
BridgeContractTransferInRejection
,
error
)
ParseTransferInRejection
(
log
*
types
.
Log
)
(
*
bridge
.
BridgeContractTransferInRejection
,
error
)
ParseTransferInConfirmation
(
log
*
types
.
Log
)
(
*
bridge
.
BridgeContractTransferInConfirmation
,
error
)
ParseTransferInConfirmation
(
log
*
types
.
Log
)
(
*
bridge
.
BridgeContractTransferInConfirmation
,
error
)
ParseTokenConfigChanged
(
log
*
types
.
Log
)
(
*
bridge
.
BridgeContractTokenOutConfigChanged
,
error
)
ParseTokenConfigChanged
(
log
*
types
.
Log
)
(
*
bridge
.
BridgeContractTokenOutConfigChanged
,
error
)
ParseSwapConfigChanged
(
log
*
types
.
Log
)
(
*
bridge
.
BridgeContractSwapConfigChanged
,
error
)
GetReceiveToken
(
token
common
.
Address
,
toChainId
int64
)
(
string
,
error
)
GetReceiveToken
(
token
common
.
Address
,
toChainId
int64
)
(
string
,
error
)
}
}
...
@@ -34,6 +35,7 @@ var (
...
@@ -34,6 +35,7 @@ var (
TransferInRejectionEvent
=
bridgeAbi
.
Events
[
EVENT_TRANSFER_IN_REJECTION
]
TransferInRejectionEvent
=
bridgeAbi
.
Events
[
EVENT_TRANSFER_IN_REJECTION
]
TransferInConfirmationEvent
=
bridgeAbi
.
Events
[
EVENT_TRANSFER_IN_CONFIRMATION
]
TransferInConfirmationEvent
=
bridgeAbi
.
Events
[
EVENT_TRANSFER_IN_CONFIRMATION
]
TokenConfigChangedEvent
=
bridgeAbi
.
Events
[
EVENT_TOKENCONFIGCHANGED
]
TokenConfigChangedEvent
=
bridgeAbi
.
Events
[
EVENT_TOKENCONFIGCHANGED
]
SwapConfigChangedEvent
=
bridgeAbi
.
Events
[
EVENT_SWAPCONFIGCHANGED
]
)
)
func
(
s
*
Dao
)
HandleEvents
(
chain
ChainInterface
,
logs
[]
types
.
Log
)
error
{
func
(
s
*
Dao
)
HandleEvents
(
chain
ChainInterface
,
logs
[]
types
.
Log
)
error
{
...
@@ -43,6 +45,7 @@ func (s *Dao) HandleEvents(chain ChainInterface, logs []types.Log) error {
...
@@ -43,6 +45,7 @@ func (s *Dao) HandleEvents(chain ChainInterface, logs []types.Log) error {
var
allTransferOut
=
make
([]
types
.
Log
,
0
)
var
allTransferOut
=
make
([]
types
.
Log
,
0
)
var
allTransferIn
=
make
([]
types
.
Log
,
0
)
var
allTransferIn
=
make
([]
types
.
Log
,
0
)
var
allTokenConfigChanged
=
make
([]
types
.
Log
,
0
)
var
allTokenConfigChanged
=
make
([]
types
.
Log
,
0
)
var
allSwapConfigChanged
=
make
([]
types
.
Log
,
0
)
var
allExecuted
=
make
([]
types
.
Log
,
0
)
var
allExecuted
=
make
([]
types
.
Log
,
0
)
var
allRejected
=
make
([]
types
.
Log
,
0
)
var
allRejected
=
make
([]
types
.
Log
,
0
)
var
allConfirmed
=
make
([]
types
.
Log
,
0
)
var
allConfirmed
=
make
([]
types
.
Log
,
0
)
...
@@ -55,6 +58,8 @@ func (s *Dao) HandleEvents(chain ChainInterface, logs []types.Log) error {
...
@@ -55,6 +58,8 @@ func (s *Dao) HandleEvents(chain ChainInterface, logs []types.Log) error {
allTransferIn
=
append
(
allTransferIn
,
lg
)
allTransferIn
=
append
(
allTransferIn
,
lg
)
case
TokenConfigChangedEvent
.
ID
.
Hex
()
:
case
TokenConfigChangedEvent
.
ID
.
Hex
()
:
allTokenConfigChanged
=
append
(
allTokenConfigChanged
,
lg
)
allTokenConfigChanged
=
append
(
allTokenConfigChanged
,
lg
)
case
SwapConfigChangedEvent
.
ID
.
Hex
()
:
allSwapConfigChanged
=
append
(
allSwapConfigChanged
,
lg
)
case
TransferInExecutionEvent
.
ID
.
Hex
()
:
case
TransferInExecutionEvent
.
ID
.
Hex
()
:
allExecuted
=
append
(
allExecuted
,
lg
)
allExecuted
=
append
(
allExecuted
,
lg
)
case
TransferInRejectionEvent
.
ID
.
Hex
()
:
case
TransferInRejectionEvent
.
ID
.
Hex
()
:
...
@@ -70,6 +75,7 @@ func (s *Dao) HandleEvents(chain ChainInterface, logs []types.Log) error {
...
@@ -70,6 +75,7 @@ func (s *Dao) HandleEvents(chain ChainInterface, logs []types.Log) error {
allLogs
=
append
(
allLogs
,
allRejected
...
)
allLogs
=
append
(
allLogs
,
allRejected
...
)
allLogs
=
append
(
allLogs
,
allConfirmed
...
)
allLogs
=
append
(
allLogs
,
allConfirmed
...
)
allLogs
=
append
(
allLogs
,
allExecuted
...
)
allLogs
=
append
(
allLogs
,
allExecuted
...
)
allLogs
=
append
(
allLogs
,
allSwapConfigChanged
...
)
// disable the code.
// disable the code.
if
false
{
if
false
{
...
@@ -128,6 +134,10 @@ func (s *Dao) HandleEvents(chain ChainInterface, logs []types.Log) error {
...
@@ -128,6 +134,10 @@ func (s *Dao) HandleEvents(chain ChainInterface, logs []types.Log) error {
ormTxErr
=
err
ormTxErr
=
err
break
break
}
}
if
err
:=
s
.
filterSwapConfigChanged
(
chain
,
txLog
,
ctx
);
err
!=
nil
{
ormTxErr
=
err
break
}
}
}
// commit or rollback.
// commit or rollback.
...
@@ -394,3 +404,44 @@ func (s *Dao) filterTokenConfigChanged(chain ChainInterface, txLog *types.Log, c
...
@@ -394,3 +404,44 @@ func (s *Dao) filterTokenConfigChanged(chain ChainInterface, txLog *types.Log, c
}
}
return
nil
return
nil
}
}
func
(
s
*
Dao
)
filterSwapConfigChanged
(
chain
ChainInterface
,
txLog
*
types
.
Log
,
ctx
context
.
Context
)
error
{
if
len
(
txLog
.
Topics
)
==
0
{
return
nil
}
if
txLog
.
Topics
[
0
]
.
Hex
()
==
SwapConfigChangedEvent
.
ID
.
Hex
()
{
configure
,
err
:=
chain
.
ParseSwapConfigChanged
(
txLog
)
if
err
!=
nil
{
return
err
}
info
:=
&
dbModel
.
SwapTokenInfo
{
ChainId
:
chain
.
GetChain
()
.
ChainId
,
Contract
:
strings
.
ToLower
(
txLog
.
Address
.
String
()),
Token
:
strings
.
ToLower
(
configure
.
FromToken
.
String
()),
SwapContract
:
strings
.
ToLower
(
configure
.
Swap
.
String
()),
ToToken
:
strings
.
ToLower
(
configure
.
ToToken
.
String
()),
SwapPath
:
make
([]
string
,
0
),
}
for
_
,
addr
:=
range
configure
.
Path
{
info
.
SwapPath
=
append
(
info
.
SwapPath
,
strings
.
ToLower
(
addr
.
String
()))
}
if
tokenInfo
,
err
:=
s
.
tokenRepo
.
RetriveTokenInfo
(
chain
.
GetChain
()
.
ChainId
,
configure
.
FromToken
.
Hex
());
err
==
nil
{
info
.
TokenName
=
tokenInfo
.
Symbol
}
err
=
s
.
CreateSwapTokenInfo
(
ctx
,
info
)
if
err
!=
nil
{
log
.
WithFields
(
log
.
Fields
{
"chain"
:
chain
.
Name
(),
"token"
:
configure
.
FromToken
.
Hex
(),
"toToken"
:
configure
.
ToToken
.
Hex
(),
"swap"
:
configure
.
Swap
.
Hex
(),
"swapPath"
:
info
.
SwapPath
,
})
.
WithError
(
err
)
.
Error
(
"db create or update token config failed"
)
return
err
}
}
return
nil
}
dao/db.go
View file @
e865d202
...
@@ -191,3 +191,73 @@ func (d *Dao) GetHistoryInfo(user string) (history apiModel.History, err error)
...
@@ -191,3 +191,73 @@ func (d *Dao) GetHistoryInfo(user string) (history apiModel.History, err error)
return
history
,
nil
return
history
,
nil
}
}
func
(
d
*
Dao
)
GetSwapConfig
(
chainId
int64
)
(
config
apiModel
.
SwapConfigs
,
err
error
)
{
collection
:=
d
.
db
.
Collection
(
new
(
dbModel
.
SwapTokenInfo
)
.
TableName
())
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
10
*
time
.
Second
)
defer
cancel
()
// Find all swap token info fillter by chain_id.
cursor
,
err
:=
collection
.
Find
(
ctx
,
bson
.
M
{})
if
err
!=
nil
{
return
config
,
err
}
defer
cursor
.
Close
(
ctx
)
var
swaps
[]
dbModel
.
SwapTokenInfo
err
=
cursor
.
All
(
ctx
,
&
swaps
)
if
err
!=
nil
{
return
config
,
err
}
config
.
SwapPairs
=
make
(
map
[
string
]
apiModel
.
SwapPair
)
// Convert database model to API model
for
_
,
info
:=
range
swaps
{
if
info
.
ChainId
!=
chainId
{
continue
}
swap
:=
apiModel
.
SwapPair
{
From
:
apiModel
.
TokenInfo
{
Contract
:
info
.
Token
,
Name
:
info
.
TokenName
,
},
To
:
apiModel
.
TokenInfo
{
Contract
:
info
.
ToToken
,
Name
:
""
,
},
SwapContract
:
info
.
SwapContract
,
SwapPath
:
make
([]
string
,
0
),
}
for
_
,
pathToken
:=
range
info
.
SwapPath
{
swap
.
SwapPath
=
append
(
swap
.
SwapPath
,
pathToken
)
}
if
swap
.
From
.
Name
==
""
{
tokenInfo
,
err
:=
d
.
tokenRepo
.
RetriveTokenInfo
(
info
.
ChainId
,
info
.
Token
)
if
err
!=
nil
{
log
.
WithFields
(
log
.
Fields
{
"chain_id"
:
info
.
ChainId
,
"token"
:
info
.
Token
,
"error"
:
err
,
})
.
Error
(
"not found token info with tokenrepo, skip symbol info"
)
}
else
{
swap
.
From
.
Name
=
tokenInfo
.
Symbol
}
}
if
swap
.
To
.
Name
==
""
{
toTokenInfo
,
err
:=
d
.
tokenRepo
.
RetriveTokenInfo
(
info
.
ChainId
,
info
.
ToToken
)
if
err
!=
nil
{
log
.
WithFields
(
log
.
Fields
{
"chain_id"
:
info
.
ChainId
,
"token"
:
info
.
ToToken
,
"error"
:
err
,
})
.
Error
(
"not found token info with tokenrepo, skip symbol info"
)
}
else
{
swap
.
To
.
Name
=
toTokenInfo
.
Symbol
}
}
config
.
SwapPairs
[
swap
.
From
.
Name
]
=
swap
}
return
config
,
nil
}
dao/dbtx.go
View file @
e865d202
...
@@ -228,3 +228,16 @@ func (d *Dao) GetTokenInfo(address string) (info dbModel.TokenInfo, err error) {
...
@@ -228,3 +228,16 @@ func (d *Dao) GetTokenInfo(address string) (info dbModel.TokenInfo, err error) {
}
}
return
info
,
err
return
info
,
err
}
}
func
(
d
*
Dao
)
CreateSwapTokenInfo
(
ctx
context
.
Context
,
info
*
dbModel
.
SwapTokenInfo
)
error
{
collection
:=
d
.
db
.
Collection
(
info
.
TableName
())
filter
:=
bson
.
M
{
"chain_id"
:
info
.
ChainId
,
"token"
:
info
.
Token
,
"contract"
:
info
.
Contract
}
update
:=
bson
.
D
{
{
"$set"
,
info
},
}
opts
:=
options
.
Update
()
.
SetUpsert
(
true
)
_
,
err
:=
collection
.
UpdateOne
(
ctx
,
filter
,
update
,
opts
)
return
err
}
model/api/model.go
View file @
e865d202
...
@@ -15,6 +15,22 @@ type ChainConfig struct {
...
@@ -15,6 +15,22 @@ type ChainConfig struct {
RpcUrl
string
`json:"rpc" bson:"rpc"`
RpcUrl
string
`json:"rpc" bson:"rpc"`
}
}
type
TokenInfo
struct
{
Name
string
`json:"name" bson:"name"`
Contract
string
`json:"contract" bson:"contract"`
}
type
SwapPair
struct
{
From
TokenInfo
`json:"from" bson:"from"`
To
TokenInfo
`json:"to" bson:"to"`
SwapContract
string
`json:"swap_contract" bson:"swap_contract"`
SwapPath
[]
string
`json:"swap_path" bson:"swap_path"`
}
type
SwapConfigs
struct
{
SwapPairs
map
[
string
]
SwapPair
`json:"swap_pairs" bson:"swap_pairs"`
}
type
BridgeConfig
struct
{
type
BridgeConfig
struct
{
Chains
map
[
string
]
ChainConfig
`json:"chains" bson:"chains"`
Chains
map
[
string
]
ChainConfig
`json:"chains" bson:"chains"`
}
}
...
@@ -42,5 +58,6 @@ type History struct {
...
@@ -42,5 +58,6 @@ type History struct {
type
Querier
interface
{
type
Querier
interface
{
GetBridgeConfig
()
(
config
BridgeConfig
,
err
error
)
GetBridgeConfig
()
(
config
BridgeConfig
,
err
error
)
GetSwapConfig
(
chainId
int64
)
(
config
SwapConfigs
,
err
error
)
GetHistoryInfo
(
user
string
)
(
history
History
,
err
error
)
GetHistoryInfo
(
user
string
)
(
history
History
,
err
error
)
}
}
model/db/db.go
View file @
e865d202
...
@@ -92,6 +92,21 @@ func (b *BridgeTokenInfo) TableName() string {
...
@@ -92,6 +92,21 @@ func (b *BridgeTokenInfo) TableName() string {
return
"bridge_token_info"
return
"bridge_token_info"
}
}
type
SwapTokenInfo
struct
{
ID
primitive
.
ObjectID
`bson:"_id,omitempty"`
ChainId
int64
`bson:"chain_id"`
Contract
string
`bson:"contract"`
Token
string
`bson:"token"`
TokenName
string
`bson:"token_name"`
SwapContract
string
`bson:"swap_contract"`
ToToken
string
`bson:"to_token"`
SwapPath
[]
string
`bson:"swap_path"`
}
func
(
b
*
SwapTokenInfo
)
TableName
()
string
{
return
"swap_token_info"
}
type
TokenInfo
struct
{
type
TokenInfo
struct
{
ID
primitive
.
ObjectID
`bson:"_id,omitempty"`
ID
primitive
.
ObjectID
`bson:"_id,omitempty"`
Address
string
`bson:"address"`
Address
string
`bson:"address"`
...
...
server/controller.go
View file @
e865d202
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"code.wuban.net.cn/movabridge/bridge-backend/constant"
"code.wuban.net.cn/movabridge/bridge-backend/constant"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
log
"github.com/sirupsen/logrus"
log
"github.com/sirupsen/logrus"
"strconv"
"strings"
"strings"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
...
@@ -45,3 +46,26 @@ func getHistory(c *gin.Context) {
...
@@ -45,3 +46,26 @@ func getHistory(c *gin.Context) {
}
}
c
.
JSON
(
200
,
withSuccess
(
history
))
c
.
JSON
(
200
,
withSuccess
(
history
))
}
}
func
getSwapConfig
(
c
*
gin
.
Context
)
{
chainIdStr
:=
c
.
DefaultQuery
(
"chain"
,
""
)
chainId
,
err
:=
strconv
.
ParseInt
(
chainIdStr
,
10
,
64
)
if
err
!=
nil
{
log
.
Errorf
(
"convert chainId(%s) to int error: %v"
,
chainIdStr
,
err
)
c
.
JSON
(
200
,
withError
(
constant
.
InvalidParam
))
}
if
_querier
==
nil
{
log
.
Error
(
"querier is nil"
)
c
.
JSON
(
500
,
withError
(
constant
.
InternalError
))
return
}
configs
,
err
:=
_querier
.
GetSwapConfig
(
chainId
)
if
err
!=
nil
{
log
.
Errorf
(
"get swap config error: %v"
,
err
)
c
.
JSON
(
500
,
withError
(
constant
.
InternalError
))
return
}
c
.
JSON
(
200
,
withSuccess
(
configs
))
}
server/router.go
View file @
e865d202
...
@@ -16,4 +16,5 @@ func initRouter(conf *config.Config, e *gin.Engine) {
...
@@ -16,4 +16,5 @@ func initRouter(conf *config.Config, e *gin.Engine) {
user
.
GET
(
"/history"
,
getHistory
)
user
.
GET
(
"/history"
,
getHistory
)
}
}
v1
.
GET
(
"/params"
,
getParam
)
v1
.
GET
(
"/params"
,
getParam
)
v1
.
GET
(
"/swapconfig"
,
getSwapConfig
)
}
}
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