Skip to content

Commit 1f211e5

Browse files
committed
swapclientserver: add listinstantouts
1 parent 1f96a61 commit 1f211e5

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

loopd/perms/perms.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,8 @@ var RequiredPermissions = map[string][]bakery.Op{
108108
Entity: "swap",
109109
Action: "read",
110110
}},
111+
"/looprpc.SwapClient/ListInstantOuts": {{
112+
Entity: "swap",
113+
Action: "read",
114+
}},
111115
}

loopd/swapclient_server.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,47 @@ func (s *swapClientServer) InstantOutQuote(ctx context.Context,
12311231
}, nil
12321232
}
12331233

1234+
// ListInstantOuts returns a list of all currently known instant out swaps and
1235+
// their current status.
1236+
func (s *swapClientServer) ListInstantOuts(ctx context.Context,
1237+
_ *clientrpc.ListInstantOutsRequest) (
1238+
*clientrpc.ListInstantOutsResponse, error) {
1239+
1240+
instantOuts, err := s.instantOutManager.ListInstantOuts(ctx)
1241+
if err != nil {
1242+
return nil, err
1243+
}
1244+
1245+
rpcSwaps := make([]*clientrpc.InstantOut, 0, len(instantOuts))
1246+
for _, instantOut := range instantOuts {
1247+
rpcSwaps = append(rpcSwaps, rpcInstantOut(instantOut))
1248+
}
1249+
1250+
return &clientrpc.ListInstantOutsResponse{
1251+
Swaps: rpcSwaps,
1252+
}, nil
1253+
}
1254+
1255+
func rpcInstantOut(instantOut *instantout.InstantOut) *clientrpc.InstantOut {
1256+
var sweepTxId string
1257+
if instantOut.SweepTxHash != nil {
1258+
sweepTxId = instantOut.SweepTxHash.String()
1259+
}
1260+
1261+
reservations := make([][]byte, len(instantOut.Reservations))
1262+
for i, res := range instantOut.Reservations {
1263+
reservations[i] = res.ID[:]
1264+
}
1265+
1266+
return &clientrpc.InstantOut{
1267+
SwapHash: instantOut.SwapHash[:],
1268+
State: string(instantOut.State),
1269+
Amount: uint64(instantOut.Value),
1270+
SweepTxId: sweepTxId,
1271+
ReservationIds: reservations,
1272+
}
1273+
}
1274+
12341275
func rpcAutoloopReason(reason liquidity.Reason) (clientrpc.AutoReason, error) {
12351276
switch reason {
12361277
case liquidity.ReasonNone:

0 commit comments

Comments
 (0)