Skip to content

Commit ee0309f

Browse files
committed
instantout: add instantout store
1 parent 56ed6f7 commit ee0309f

File tree

9 files changed

+958
-3
lines changed

9 files changed

+958
-3
lines changed

instantout/store.go

Lines changed: 432 additions & 0 deletions
Large diffs are not rendered by default.

instantout/store_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package instantout
2+
3+
import (
4+
"crypto/rand"
5+
"testing"
6+
7+
"github.com/lightninglabs/loop/instantout/reservation"
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
func TestConvertingReservations(t *testing.T) {
12+
var resId1, resId2 reservation.ID
13+
14+
// fill the ids with random values.
15+
if _, err := rand.Read(resId1[:]); err != nil {
16+
t.Fatal(err)
17+
}
18+
19+
if _, err := rand.Read(resId2[:]); err != nil {
20+
t.Fatal(err)
21+
}
22+
23+
reservations := []*reservation.Reservation{
24+
{ID: resId1}, {ID: resId2},
25+
}
26+
27+
byteSlice := reservationIdsToByteSlice(reservations)
28+
require.Len(t, byteSlice, 64)
29+
30+
reservationIds, err := byteSliceToReservationIds(byteSlice)
31+
require.NoError(t, err)
32+
33+
require.Len(t, reservationIds, 2)
34+
require.Equal(t, resId1, reservationIds[0])
35+
require.Equal(t, resId2, reservationIds[1])
36+
}

loopdb/sql_store.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ func ConvertLoopOutRow(network *chaincfg.Params, row sqlc.GetLoopOutSwapRow,
543543
}
544544

545545
if row.OutgoingChanSet != "" {
546-
chanSet, err := convertOutgoingChanSet(row.OutgoingChanSet)
546+
chanSet, err := ConvertOutgoingChanSet(row.OutgoingChanSet)
547547
if err != nil {
548548
return nil, err
549549
}
@@ -666,9 +666,9 @@ func getSwapEvents(updates []sqlc.SwapUpdate) ([]*LoopEvent, error) {
666666
return events, nil
667667
}
668668

669-
// convertOutgoingChanSet converts a comma separated string of channel IDs into
669+
// ConvertOutgoingChanSet converts a comma separated string of channel IDs into
670670
// a ChannelSet.
671-
func convertOutgoingChanSet(outgoingChanSet string) (ChannelSet, error) {
671+
func ConvertOutgoingChanSet(outgoingChanSet string) (ChannelSet, error) {
672672
// Split the string into a slice of strings
673673
chanStrings := strings.Split(outgoingChanSet, ",")
674674
channels := make([]uint64, len(chanStrings))

loopdb/sqlc/instantout.sql.go

Lines changed: 329 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
DROP INDEX IF EXISTS instantout_updates_swap_hash_idx;
2+
DROP INDEX IF EXISTS instantout_swap_hash_idx;
3+
DROP TABLE IF EXISTS instantout_updates;
4+
DROP TABLE IF EXISTS instantout_swaps;

0 commit comments

Comments
 (0)