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
2f23c22f
Commit
2f23c22f
authored
Nov 26, 2025
by
vicotor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update error
parent
40378b99
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
17 deletions
+17
-17
db.go
dao/db.go
+14
-14
controller.go
server/controller.go
+3
-3
No files found.
dao/db.go
View file @
2f23c22f
...
@@ -340,7 +340,7 @@ func (d *Dao) QuoteBridge(param apiModel.QuoteBridgeParam) (quote apiModel.Quote
...
@@ -340,7 +340,7 @@ func (d *Dao) QuoteBridge(param apiModel.QuoteBridgeParam) (quote apiModel.Quote
chainInfo
,
err
:=
d
.
GetChainConfig
(
param
.
FromChainId
)
chainInfo
,
err
:=
d
.
GetChainConfig
(
param
.
FromChainId
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Error
(
"not found chain config for chain id:"
,
param
.
FromChainId
)
log
.
Error
(
"not found chain config for chain id:"
,
param
.
FromChainId
)
return
quote
,
nil
return
quote
,
fmt
.
Errorf
(
"not found chain config for chain id: %s"
,
param
.
FromChainId
)
}
}
outConfig
,
err
:=
d
.
GetOutConfig
(
param
.
FromChainId
,
common
.
HexToAddress
(
param
.
FromToken
),
param
.
ToChainId
)
outConfig
,
err
:=
d
.
GetOutConfig
(
param
.
FromChainId
,
common
.
HexToAddress
(
param
.
FromToken
),
param
.
ToChainId
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -350,7 +350,7 @@ func (d *Dao) QuoteBridge(param apiModel.QuoteBridgeParam) (quote apiModel.Quote
...
@@ -350,7 +350,7 @@ func (d *Dao) QuoteBridge(param apiModel.QuoteBridgeParam) (quote apiModel.Quote
"to_chain"
:
param
.
ToChainId
,
"to_chain"
:
param
.
ToChainId
,
"error"
:
err
,
"error"
:
err
,
})
.
Error
(
"get out config failed"
)
})
.
Error
(
"get out config failed"
)
return
quote
,
err
return
quote
,
fmt
.
Errorf
(
"internal error"
)
}
}
_
,
balance
,
err
:=
d
.
tokenRepo
.
RetriveTokenInfoAndBalance
(
chainInfo
.
cli
,
param
.
FromToken
,
param
.
User
)
_
,
balance
,
err
:=
d
.
tokenRepo
.
RetriveTokenInfoAndBalance
(
chainInfo
.
cli
,
param
.
FromToken
,
param
.
User
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -360,7 +360,7 @@ func (d *Dao) QuoteBridge(param apiModel.QuoteBridgeParam) (quote apiModel.Quote
...
@@ -360,7 +360,7 @@ func (d *Dao) QuoteBridge(param apiModel.QuoteBridgeParam) (quote apiModel.Quote
"user"
:
param
.
User
,
"user"
:
param
.
User
,
"error"
:
err
,
"error"
:
err
,
})
.
Error
(
"get user balance failed"
)
})
.
Error
(
"get user balance failed"
)
return
quote
,
err
return
quote
,
fmt
.
Errorf
(
"internal error"
)
}
}
// check balance and param.InputAmount
// check balance and param.InputAmount
// check param.InputAmount and outConfig.Limit
// check param.InputAmount and outConfig.Limit
...
@@ -370,7 +370,7 @@ func (d *Dao) QuoteBridge(param apiModel.QuoteBridgeParam) (quote apiModel.Quote
...
@@ -370,7 +370,7 @@ func (d *Dao) QuoteBridge(param apiModel.QuoteBridgeParam) (quote apiModel.Quote
log
.
WithFields
(
log
.
Fields
{
log
.
WithFields
(
log
.
Fields
{
"input_amount"
:
param
.
InputAmount
,
"input_amount"
:
param
.
InputAmount
,
})
.
Error
(
"invalid input amount"
)
})
.
Error
(
"invalid input amount"
)
return
quote
,
nil
return
quote
,
fmt
.
Errorf
(
"invalid input amount"
)
}
}
if
balance
.
Cmp
(
inputAmount
)
<
0
{
if
balance
.
Cmp
(
inputAmount
)
<
0
{
log
.
WithFields
(
log
.
Fields
{
log
.
WithFields
(
log
.
Fields
{
...
@@ -418,7 +418,7 @@ func (d *Dao) QuoteBridge(param apiModel.QuoteBridgeParam) (quote apiModel.Quote
...
@@ -418,7 +418,7 @@ func (d *Dao) QuoteBridge(param apiModel.QuoteBridgeParam) (quote apiModel.Quote
"inputAmount"
:
inputAmount
.
String
(),
"inputAmount"
:
inputAmount
.
String
(),
"error"
:
err
,
"error"
:
err
,
})
.
Error
(
"build bridge payload failed"
)
})
.
Error
(
"build bridge payload failed"
)
return
quote
,
err
return
quote
,
fmt
.
Errorf
(
"internal error"
)
}
}
quote
.
Payload
=
common
.
Bytes2Hex
(
payload
)
quote
.
Payload
=
common
.
Bytes2Hex
(
payload
)
return
quote
,
nil
return
quote
,
nil
...
@@ -432,7 +432,7 @@ func (d *Dao) GetAllChainSwapConfig() (map[int64]*apiModel.ChainSwapConfig, erro
...
@@ -432,7 +432,7 @@ func (d *Dao) GetAllChainSwapConfig() (map[int64]*apiModel.ChainSwapConfig, erro
cursor
,
err
:=
collection
.
Find
(
ctx
,
bson
.
M
{})
cursor
,
err
:=
collection
.
Find
(
ctx
,
bson
.
M
{})
if
err
!=
nil
{
if
err
!=
nil
{
return
res
,
err
return
res
,
fmt
.
Errorf
(
"internal error"
)
}
}
defer
cursor
.
Close
(
ctx
)
defer
cursor
.
Close
(
ctx
)
...
@@ -591,7 +591,7 @@ func (d *Dao) QuoteSwap(param apiModel.QuoteSwapParam) (quote apiModel.QuoteResu
...
@@ -591,7 +591,7 @@ func (d *Dao) QuoteSwap(param apiModel.QuoteSwapParam) (quote apiModel.QuoteResu
chainInfo
,
err
:=
d
.
GetChainConfig
(
param
.
FromChainId
)
chainInfo
,
err
:=
d
.
GetChainConfig
(
param
.
FromChainId
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Error
(
"not found chain config for chain id:"
,
param
.
FromChainId
)
log
.
Error
(
"not found chain config for chain id:"
,
param
.
FromChainId
)
return
quote
,
nil
return
quote
,
fmt
.
Errorf
(
"not found chain for chain id"
)
}
}
_
,
balance
,
err
:=
d
.
tokenRepo
.
RetriveTokenInfoAndBalance
(
chainInfo
.
cli
,
param
.
Path
.
SwapFromToken
,
param
.
User
)
_
,
balance
,
err
:=
d
.
tokenRepo
.
RetriveTokenInfoAndBalance
(
chainInfo
.
cli
,
param
.
Path
.
SwapFromToken
,
param
.
User
)
...
@@ -602,7 +602,7 @@ func (d *Dao) QuoteSwap(param apiModel.QuoteSwapParam) (quote apiModel.QuoteResu
...
@@ -602,7 +602,7 @@ func (d *Dao) QuoteSwap(param apiModel.QuoteSwapParam) (quote apiModel.QuoteResu
"user"
:
param
.
User
,
"user"
:
param
.
User
,
"error"
:
err
,
"error"
:
err
,
})
.
Error
(
"get user balance failed"
)
})
.
Error
(
"get user balance failed"
)
return
quote
,
err
return
quote
,
fmt
.
Errorf
(
"internal error"
)
}
}
// check balance and param.InputAmount
// check balance and param.InputAmount
inputAmount
,
ok
:=
new
(
big
.
Int
)
.
SetString
(
param
.
InputAmount
,
10
)
inputAmount
,
ok
:=
new
(
big
.
Int
)
.
SetString
(
param
.
InputAmount
,
10
)
...
@@ -610,7 +610,7 @@ func (d *Dao) QuoteSwap(param apiModel.QuoteSwapParam) (quote apiModel.QuoteResu
...
@@ -610,7 +610,7 @@ func (d *Dao) QuoteSwap(param apiModel.QuoteSwapParam) (quote apiModel.QuoteResu
log
.
WithFields
(
log
.
Fields
{
log
.
WithFields
(
log
.
Fields
{
"input_amount"
:
param
.
InputAmount
,
"input_amount"
:
param
.
InputAmount
,
})
.
Error
(
"invalid input amount"
)
})
.
Error
(
"invalid input amount"
)
return
quote
,
nil
return
quote
,
fmt
.
Errorf
(
"invalid input amount"
)
}
}
if
balance
.
Cmp
(
inputAmount
)
<
0
{
if
balance
.
Cmp
(
inputAmount
)
<
0
{
log
.
WithFields
(
log
.
Fields
{
log
.
WithFields
(
log
.
Fields
{
...
@@ -650,7 +650,7 @@ func (d *Dao) QuoteSwap(param apiModel.QuoteSwapParam) (quote apiModel.QuoteResu
...
@@ -650,7 +650,7 @@ func (d *Dao) QuoteSwap(param apiModel.QuoteSwapParam) (quote apiModel.QuoteResu
"input_amount"
:
inputAmount
.
String
(),
"input_amount"
:
inputAmount
.
String
(),
"error"
:
err
,
"error"
:
err
,
})
.
Error
(
"get swap amounts out failed"
)
})
.
Error
(
"get swap amounts out failed"
)
return
quote
,
err
return
quote
,
fmt
.
Errorf
(
"internal error"
)
}
}
inputAmount
=
swapFromAmount
inputAmount
=
swapFromAmount
}
}
...
@@ -663,7 +663,7 @@ func (d *Dao) QuoteSwap(param apiModel.QuoteSwapParam) (quote apiModel.QuoteResu
...
@@ -663,7 +663,7 @@ func (d *Dao) QuoteSwap(param apiModel.QuoteSwapParam) (quote apiModel.QuoteResu
"to_chain"
:
param
.
ToChainId
,
"to_chain"
:
param
.
ToChainId
,
"error"
:
err
,
"error"
:
err
,
})
.
Error
(
"get out config failed"
)
})
.
Error
(
"get out config failed"
)
return
quote
,
err
return
quote
,
fmt
.
Errorf
(
"internal error"
)
}
}
if
outConfig
.
ReceiveToken
!=
common
.
HexToAddress
(
param
.
Path
.
BridgeToToken
)
{
if
outConfig
.
ReceiveToken
!=
common
.
HexToAddress
(
param
.
Path
.
BridgeToToken
)
{
log
.
WithFields
(
log
.
Fields
{
log
.
WithFields
(
log
.
Fields
{
...
@@ -699,7 +699,7 @@ func (d *Dao) QuoteSwap(param apiModel.QuoteSwapParam) (quote apiModel.QuoteResu
...
@@ -699,7 +699,7 @@ func (d *Dao) QuoteSwap(param apiModel.QuoteSwapParam) (quote apiModel.QuoteResu
"swap_to_token"
:
param
.
Path
.
SwapToToken
,
"swap_to_token"
:
param
.
Path
.
SwapToToken
,
"error"
:
err
,
"error"
:
err
,
})
.
Error
(
"not found swap config for bridge to token to swap to token"
)
})
.
Error
(
"not found swap config for bridge to token to swap to token"
)
return
quote
,
err
return
quote
,
fmt
.
Errorf
(
"internal error"
)
}
}
swapToAmount
,
err
:=
router
.
GetAmountsOut
(
chainInfo
.
cli
,
common
.
HexToAddress
(
param
.
User
),
common
.
HexToAddress
(
swapConfig
.
SwapContract
),
outAmount
,
swapConfig
.
SwapPath
)
swapToAmount
,
err
:=
router
.
GetAmountsOut
(
chainInfo
.
cli
,
common
.
HexToAddress
(
param
.
User
),
common
.
HexToAddress
(
swapConfig
.
SwapContract
),
outAmount
,
swapConfig
.
SwapPath
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -710,7 +710,7 @@ func (d *Dao) QuoteSwap(param apiModel.QuoteSwapParam) (quote apiModel.QuoteResu
...
@@ -710,7 +710,7 @@ func (d *Dao) QuoteSwap(param apiModel.QuoteSwapParam) (quote apiModel.QuoteResu
"input_amount"
:
outAmount
.
String
(),
"input_amount"
:
outAmount
.
String
(),
"error"
:
err
,
"error"
:
err
,
})
.
Error
(
"get swap amounts out failed"
)
})
.
Error
(
"get swap amounts out failed"
)
return
quote
,
err
return
quote
,
fmt
.
Errorf
(
"internal error"
)
}
}
quote
.
OutAmount
=
swapToAmount
.
String
()
quote
.
OutAmount
=
swapToAmount
.
String
()
}
}
...
@@ -725,7 +725,7 @@ func (d *Dao) QuoteSwap(param apiModel.QuoteSwapParam) (quote apiModel.QuoteResu
...
@@ -725,7 +725,7 @@ func (d *Dao) QuoteSwap(param apiModel.QuoteSwapParam) (quote apiModel.QuoteResu
"inputAmount"
:
inputAmount
.
String
(),
"inputAmount"
:
inputAmount
.
String
(),
"error"
:
err
,
"error"
:
err
,
})
.
Error
(
"build swap payload failed"
)
})
.
Error
(
"build swap payload failed"
)
return
quote
,
err
return
quote
,
fmt
.
Errorf
(
"internal error"
)
}
}
quote
.
Payload
=
common
.
Bytes2Hex
(
payload
)
quote
.
Payload
=
common
.
Bytes2Hex
(
payload
)
return
quote
,
nil
return
quote
,
nil
...
...
server/controller.go
View file @
2f23c22f
...
@@ -116,7 +116,7 @@ func bridgeQuote(c *gin.Context) {
...
@@ -116,7 +116,7 @@ func bridgeQuote(c *gin.Context) {
quote
,
err
:=
_querier
.
QuoteBridge
(
queryParam
)
quote
,
err
:=
_querier
.
QuoteBridge
(
queryParam
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Errorf
(
"get bridge quote error: %v"
,
err
)
log
.
Errorf
(
"get bridge quote error: %v"
,
err
)
c
.
JSON
(
500
,
withError
(
constant
.
InternalError
))
c
.
JSON
(
500
,
withError
(
err
.
Error
()
))
return
return
}
}
c
.
JSON
(
200
,
withSuccess
(
quote
))
c
.
JSON
(
200
,
withSuccess
(
quote
))
...
@@ -188,7 +188,7 @@ func swapQuote(c *gin.Context) {
...
@@ -188,7 +188,7 @@ func swapQuote(c *gin.Context) {
quote
,
err
:=
_querier
.
QuoteSwap
(
queryParam
)
quote
,
err
:=
_querier
.
QuoteSwap
(
queryParam
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Errorf
(
"get swap quote error: %v"
,
err
)
log
.
Errorf
(
"get swap quote error: %v"
,
err
)
c
.
JSON
(
500
,
withError
(
constant
.
InternalError
))
c
.
JSON
(
500
,
withError
(
err
.
Error
()
))
return
return
}
}
c
.
JSON
(
200
,
withSuccess
(
quote
))
c
.
JSON
(
200
,
withSuccess
(
quote
))
...
@@ -214,7 +214,7 @@ func getSwapRoutersByChainId(c *gin.Context) {
...
@@ -214,7 +214,7 @@ func getSwapRoutersByChainId(c *gin.Context) {
config
,
err
:=
_querier
.
GetSwapConfig
(
chainId
)
config
,
err
:=
_querier
.
GetSwapConfig
(
chainId
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Errorf
(
"get swap config for chain %d error: %v"
,
chainId
,
err
)
log
.
Errorf
(
"get swap config for chain %d error: %v"
,
chainId
,
err
)
c
.
JSON
(
500
,
withError
(
constant
.
InternalError
))
c
.
JSON
(
500
,
withError
(
err
.
Error
()
))
return
return
}
}
c
.
JSON
(
200
,
withSuccess
(
config
))
c
.
JSON
(
200
,
withSuccess
(
config
))
...
...
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