Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove timeout block height from claimable swaps query #362

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions database/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,11 @@ FROM chainSwaps swaps
WHERE data.lockupTransactionId != ''
AND data.transactionId == ''
AND state != ?
AND data.timeoutBlockheight > ?
`

func (database *Database) QueryClaimableChainSwaps(tenantId *Id, currency boltz.Currency, currentBlockHeight uint32) ([]*ChainSwap, error) {
func (database *Database) QueryClaimableChainSwaps(tenantId *Id, currency boltz.Currency) ([]*ChainSwap, error) {
query := claimableChainSwapsQuery
values := []any{currency, boltzrpc.SwapState_REFUNDED, currentBlockHeight}
values := []any{currency, boltzrpc.SwapState_REFUNDED}
if tenantId != nil {
query += " AND tenantId = ?"
values = append(values, tenantId)
Expand Down
6 changes: 3 additions & 3 deletions database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,12 +480,12 @@ func (database *Database) QueryAllRefundableSwaps(tenantId *Id, currency boltz.C
return swaps, chainSwaps, nil
}

func (database *Database) QueryAllClaimableSwaps(tenantId *Id, currency boltz.Currency, currentHeight uint32) ([]*ReverseSwap, []*ChainSwap, error) {
reverseSwaps, err := database.QueryClaimableReverseSwaps(tenantId, currency, currentHeight)
func (database *Database) QueryAllClaimableSwaps(tenantId *Id, currency boltz.Currency) ([]*ReverseSwap, []*ChainSwap, error) {
reverseSwaps, err := database.QueryClaimableReverseSwaps(tenantId, currency)
if err != nil {
return nil, nil, err
}
chainSwaps, err := database.QueryClaimableChainSwaps(tenantId, currency, currentHeight)
chainSwaps, err := database.QueryClaimableChainSwaps(tenantId, currency)
if err != nil {
return nil, nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions database/reverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,11 @@ SELECT * FROM reverseSwaps
WHERE fromCurrency = ?
AND reverseSwaps.lockupTransactionId != ''
AND reverseSwaps.claimTransactionId == ''
AND reverseSwaps.timeoutBlockheight > ?
`

func (database *Database) QueryClaimableReverseSwaps(tenantId *Id, currency boltz.Currency, currentBlockHeight uint32) ([]*ReverseSwap, error) {
func (database *Database) QueryClaimableReverseSwaps(tenantId *Id, currency boltz.Currency) ([]*ReverseSwap, error) {
query := claimableSwapsQuery
values := []any{currency, currentBlockHeight}
values := []any{currency}
if tenantId != nil {
query += " AND tenantId = ?"
values = append(values, *tenantId)
Expand Down
27 changes: 10 additions & 17 deletions rpcserver/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,24 +168,22 @@ func (server *routedBoltzServer) queryRefundableSwaps(ctx context.Context, heigh
return
}

func (server *routedBoltzServer) queryClaimableSwaps(ctx context.Context, heights *boltzrpc.BlockHeights) (
func (server *routedBoltzServer) queryClaimableSwaps(ctx context.Context) (
reverseSwaps []*database.ReverseSwap, chainSwaps []*database.ChainSwap, err error,
) {
tenantId := macaroons.TenantIdFromContext(ctx)
reverseSwaps, chainSwaps, err = server.database.QueryAllClaimableSwaps(tenantId, boltz.CurrencyBtc, heights.Btc)
reverseSwaps, chainSwaps, err = server.database.QueryAllClaimableSwaps(tenantId, boltz.CurrencyBtc)
if err != nil {
return
}

if heights.Liquid != nil {
liquidReverseSwaps, liquidChainSwaps, liquidErr := server.database.QueryAllClaimableSwaps(tenantId, boltz.CurrencyLiquid, *heights.Liquid)
if liquidErr != nil {
err = liquidErr
return
}
reverseSwaps = append(reverseSwaps, liquidReverseSwaps...)
chainSwaps = append(chainSwaps, liquidChainSwaps...)
liquidReverseSwaps, liquidChainSwaps, liquidErr := server.database.QueryAllClaimableSwaps(tenantId, boltz.CurrencyLiquid)
if liquidErr != nil {
err = liquidErr
return
}
reverseSwaps = append(reverseSwaps, liquidReverseSwaps...)
chainSwaps = append(chainSwaps, liquidChainSwaps...)

return
}
Expand Down Expand Up @@ -226,7 +224,7 @@ func (server *routedBoltzServer) GetInfo(ctx context.Context, _ *boltzrpc.GetInf
return nil, err
}

claimableReverseSwaps, claimableChainSwaps, err := server.queryClaimableSwaps(ctx, blockHeights)
claimableReverseSwaps, claimableChainSwaps, err := server.queryClaimableSwaps(ctx)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -482,12 +480,7 @@ func (server *routedBoltzServer) ClaimSwaps(ctx context.Context, request *boltzr
var chainSwaps []*database.ChainSwap
var currency boltz.Currency

heights, err := server.queryHeights()
if err != nil {
return nil, err
}

claimableReverseSwaps, claimableChainSwaps, err := server.queryClaimableSwaps(ctx, heights)
claimableReverseSwaps, claimableChainSwaps, err := server.queryClaimableSwaps(ctx)
if err != nil {
return nil, err
}
Expand Down
Loading