Skip to content

Commit 132c319

Browse files
committed
format: apply llformat baseline
1 parent 650eac6 commit 132c319

183 files changed

Lines changed: 5117 additions & 2837 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

assets/client.go

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type TapdConfig struct {
5050
// assets daemon.
5151
func DefaultTapdConfig() *TapdConfig {
5252
defaultConf := tapcfg.DefaultConfig()
53+
5354
return &TapdConfig{
5455
Activate: false,
5556
Host: "localhost:10029",
@@ -83,14 +84,18 @@ func NewTapdClient(config *TapdConfig) (*TapdClient, error) {
8384

8485
// Create the TapdClient.
8586
client := &TapdClient{
86-
assetNameCache: make(map[string]string),
87-
cc: conn,
88-
cfg: config,
89-
TaprootAssetsClient: taprpc.NewTaprootAssetsClient(conn),
90-
TaprootAssetChannelsClient: tapchannelrpc.NewTaprootAssetChannelsClient(conn),
91-
PriceOracleClient: priceoraclerpc.NewPriceOracleClient(conn),
92-
RfqClient: rfqrpc.NewRfqClient(conn),
93-
UniverseClient: universerpc.NewUniverseClient(conn),
87+
assetNameCache: make(map[string]string),
88+
cc: conn,
89+
cfg: config,
90+
TaprootAssetsClient: taprpc.NewTaprootAssetsClient(conn),
91+
TaprootAssetChannelsClient: tapchannelrpc.NewTaprootAssetChannelsClient(
92+
conn,
93+
),
94+
PriceOracleClient: priceoraclerpc.NewPriceOracleClient(
95+
conn,
96+
),
97+
RfqClient: rfqrpc.NewRfqClient(conn),
98+
UniverseClient: universerpc.NewUniverseClient(conn),
9499
}
95100

96101
return client, nil
@@ -104,9 +109,8 @@ func (c *TapdClient) Close() {
104109
// GetRfqForAsset returns a RFQ for the given asset with the given amount and
105110
// to the given peer.
106111
func (c *TapdClient) GetRfqForAsset(ctx context.Context,
107-
satAmount btcutil.Amount, assetId, peerPubkey []byte,
108-
expiry int64, feeLimitMultiplier float64) (
109-
*rfqrpc.PeerAcceptedSellQuote, error) {
112+
satAmount btcutil.Amount, assetId, peerPubkey []byte, expiry int64,
113+
feeLimitMultiplier float64) (*rfqrpc.PeerAcceptedSellQuote, error) {
110114

111115
// paymentMaxAmt is the maximum amount we are willing to pay for the
112116
// payment.
@@ -149,8 +153,8 @@ func (c *TapdClient) GetRfqForAsset(ctx context.Context,
149153
}
150154

151155
// GetAssetName returns the human-readable name of the asset.
152-
func (c *TapdClient) GetAssetName(ctx context.Context,
153-
assetId []byte) (string, error) {
156+
func (c *TapdClient) GetAssetName(ctx context.Context, assetId []byte) (string,
157+
error) {
154158

155159
c.assetNameMutex.Lock()
156160
defer c.assetNameMutex.Unlock()
@@ -220,13 +224,15 @@ func (c *TapdClient) GetAssetPrice(ctx context.Context, assetID string,
220224
}
221225

222226
if rfq.GetInvalidQuote() != nil {
223-
return 0, fmt.Errorf("peer %v sent an invalid quote response %v for "+
224-
"asset %v", peerPubkey, rfq.GetInvalidQuote(), assetID)
227+
return 0, fmt.Errorf("peer %v sent an invalid quote response "+
228+
"%v for asset %v", peerPubkey, rfq.GetInvalidQuote(),
229+
assetID)
225230
}
226231

227232
if rfq.GetRejectedQuote() != nil {
228233
return 0, fmt.Errorf("peer %v rejected the quote request for "+
229-
"asset %v, %v", peerPubkey, assetID, rfq.GetRejectedQuote())
234+
"asset %v, %v", peerPubkey, assetID,
235+
rfq.GetRejectedQuote())
230236
}
231237

232238
acceptedRes := rfq.GetAcceptedQuote()
@@ -240,8 +246,8 @@ func (c *TapdClient) GetAssetPrice(ctx context.Context, assetID string,
240246

241247
// getSatsFromAssetAmt returns the amount in satoshis for the given asset amount
242248
// and asset rate.
243-
func getSatsFromAssetAmt(assetAmt uint64, assetRate *rfqrpc.FixedPoint) (
244-
btcutil.Amount, error) {
249+
func getSatsFromAssetAmt(assetAmt uint64,
250+
assetRate *rfqrpc.FixedPoint) (btcutil.Amount, error) {
245251

246252
rateFP, err := rpcutils.UnmarshalRfqFixedPoint(assetRate)
247253
if err != nil {
@@ -257,8 +263,8 @@ func getSatsFromAssetAmt(assetAmt uint64, assetRate *rfqrpc.FixedPoint) (
257263

258264
// getPaymentMaxAmount returns the milisat amount we are willing to pay for the
259265
// payment.
260-
func getPaymentMaxAmount(satAmount btcutil.Amount, feeLimitMultiplier float64) (
261-
lnwire.MilliSatoshi, error) {
266+
func getPaymentMaxAmount(satAmount btcutil.Amount,
267+
feeLimitMultiplier float64) (lnwire.MilliSatoshi, error) {
262268

263269
if satAmount == 0 {
264270
return 0, fmt.Errorf("satAmount cannot be zero")
@@ -273,7 +279,10 @@ func getPaymentMaxAmount(satAmount btcutil.Amount, feeLimitMultiplier float64) (
273279
// The resulting maximum amount we're willing to pay is 300k sats.
274280
// The response asset amount will be for those 300k sats.
275281
return lnrpc.UnmarshallAmt(
276-
int64(satAmount.MulF64(feeLimitMultiplier)), 0,
282+
int64(
283+
satAmount.MulF64(feeLimitMultiplier),
284+
),
285+
0,
277286
)
278287
}
279288

assets/client_test.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,27 +76,38 @@ func TestGetSatsFromAssetAmt(t *testing.T) {
7676
expectError bool
7777
}{
7878
{
79-
assetAmt: 1000,
80-
assetRate: &rfqrpc.FixedPoint{Coefficient: "100000", Scale: 0},
79+
assetAmt: 1000,
80+
assetRate: &rfqrpc.FixedPoint{
81+
Coefficient: "100000",
82+
Scale: 0,
83+
},
8184
expected: btcutil.Amount(1000000),
8285
expectError: false,
8386
},
8487
{
85-
assetAmt: 500000,
86-
assetRate: &rfqrpc.FixedPoint{Coefficient: "200000000", Scale: 0},
88+
assetAmt: 500000,
89+
assetRate: &rfqrpc.FixedPoint{
90+
Coefficient: "200000000",
91+
Scale: 0,
92+
},
8793
expected: btcutil.Amount(250000),
8894
expectError: false,
8995
},
9096
{
91-
assetAmt: 0,
92-
assetRate: &rfqrpc.FixedPoint{Coefficient: "100000000", Scale: 0},
97+
assetAmt: 0,
98+
assetRate: &rfqrpc.FixedPoint{
99+
Coefficient: "100000000",
100+
Scale: 0,
101+
},
93102
expected: btcutil.Amount(0),
94103
expectError: false,
95104
},
96105
}
97106

98107
for _, test := range tests {
99-
result, err := getSatsFromAssetAmt(test.assetAmt, test.assetRate)
108+
result, err := getSatsFromAssetAmt(
109+
test.assetAmt, test.assetRate,
110+
)
100111
if test.expectError {
101112
require.NotNil(t, err)
102113
} else {

client.go

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ var (
8686
// defaultRFQExpiry is the default expiry time for RFQs.
8787
defaultRFQExpiry = 5 * time.Minute
8888

89-
// defaultRFQMaxLimitMultiplier is the default maximum fee multiplier for
90-
// RFQs.
89+
// defaultRFQMaxLimitMultiplier is the default maximum fee multiplier
90+
// for RFQs.
9191
defaultRFQMaxLimitMultiplier = 1.2
9292
)
9393

@@ -179,8 +179,8 @@ type ClientConfig struct {
179179

180180
// NewClient returns a new instance to initiate swaps with.
181181
func NewClient(dbDir string, loopDB loopdb.SwapStore,
182-
sweeperDb sweepbatcher.BatcherStore, cfg *ClientConfig) (
183-
*Client, func(), error) {
182+
sweeperDb sweepbatcher.BatcherStore, cfg *ClientConfig) (*Client,
183+
func(), error) {
184184

185185
l402Store, err := l402.NewFileStore(dbDir)
186186
if err != nil {
@@ -209,7 +209,9 @@ func NewClient(dbDir string, loopDB loopdb.SwapStore,
209209
Lnd: cfg.Lnd,
210210
}
211211

212-
verifySchnorrSig := func(pubKey *btcec.PublicKey, hash, sig []byte) error {
212+
verifySchnorrSig := func(pubKey *btcec.PublicKey, hash,
213+
sig []byte) error {
214+
213215
schnorrSig, err := schnorr.ParseSignature(sig)
214216
if err != nil {
215217
return err
@@ -226,8 +228,9 @@ func NewClient(dbDir string, loopDB loopdb.SwapStore,
226228
loopDB, cfg.Lnd.ChainParams,
227229
)
228230
if err != nil {
229-
return nil, nil, fmt.Errorf("sweepbatcher."+
230-
"NewSweepFetcherFromSwapStore failed: %w", err)
231+
return nil, nil, fmt.Errorf(
232+
"sweepbatcher.NewSweepFetcherFromSwapStore failed: %w",
233+
err)
231234
}
232235

233236
// There is circular dependency between executor and sweepbatcher, as
@@ -281,9 +284,11 @@ func NewClient(dbDir string, loopDB loopdb.SwapStore,
281284
}
282285
skippedTxns[*txid] = struct{}{}
283286
}
284-
batcherOpts = append(batcherOpts, sweepbatcher.WithSkippedTxns(
285-
skippedTxns,
286-
))
287+
batcherOpts = append(
288+
batcherOpts, sweepbatcher.WithSkippedTxns(
289+
skippedTxns,
290+
),
291+
)
287292
}
288293

289294
batcher := sweepbatcher.NewBatcher(
@@ -533,15 +538,14 @@ func (s *Client) resumeSwaps(ctx context.Context,
533538
// automatically after restarts.
534539
//
535540
// The return value is a hash that uniquely identifies the new swap.
536-
func (s *Client) LoopOut(globalCtx context.Context,
537-
request *OutRequest) (*LoopOutSwapInfo, error) {
541+
func (s *Client) LoopOut(globalCtx context.Context, request *OutRequest) (
542+
*LoopOutSwapInfo, error) {
538543

539544
if request.AssetId != nil {
540545
if request.AssetPrepayRfqId == nil ||
541546
request.AssetSwapRfqId == nil {
542-
543-
return nil, errors.New("asset prepay and swap rfq ids " +
544-
"must be set when using an asset id")
547+
return nil, errors.New("asset prepay and swap rfq " +
548+
"ids must be set when using an asset id")
545549
}
546550

547551
// Verify that if we have an asset id set, we have a valid asset
@@ -551,14 +555,11 @@ func (s *Client) LoopOut(globalCtx context.Context,
551555
"when using an asset id")
552556
}
553557

554-
log.Infof("LoopOut %v sats to %v with asset %x",
555-
request.Amount, request.DestAddr, request.AssetId,
556-
)
558+
log.Infof("LoopOut %v sats to %v with asset %x", request.Amount,
559+
request.DestAddr, request.AssetId)
557560
} else {
558-
log.Infof("LoopOut %v to %v (channels: %v)",
559-
request.Amount, request.DestAddr,
560-
request.OutgoingChanSet,
561-
)
561+
log.Infof("LoopOut %v to %v (channels: %v)", request.Amount,
562+
request.DestAddr, request.OutgoingChanSet)
562563
}
563564

564565
if err := s.waitForInitialized(globalCtx); err != nil {
@@ -750,13 +751,10 @@ func (s *Client) waitForInitialized(ctx context.Context) error {
750751
}
751752

752753
// LoopIn initiates a loop in swap.
753-
func (s *Client) LoopIn(globalCtx context.Context,
754-
request *LoopInRequest) (*LoopInSwapInfo, error) {
754+
func (s *Client) LoopIn(globalCtx context.Context, request *LoopInRequest) (
755+
*LoopInSwapInfo, error) {
755756

756-
log.Infof("Loop in %v (last hop: %v)",
757-
request.Amount,
758-
request.LastHop,
759-
)
757+
log.Infof("Loop in %v (last hop: %v)", request.Amount, request.LastHop)
760758

761759
if err := s.waitForInitialized(globalCtx); err != nil {
762760
return nil, err
@@ -802,8 +800,8 @@ func (s *Client) LoopIn(globalCtx context.Context,
802800
// LoopInQuote takes an amount and returns a breakdown of estimated costs for
803801
// the client. Both the swap server and the on-chain fee estimator are queried
804802
// to get to build the quote response.
805-
func (s *Client) LoopInQuote(ctx context.Context,
806-
request *LoopInQuoteRequest) (*LoopInQuote, error) {
803+
func (s *Client) LoopInQuote(ctx context.Context, request *LoopInQuoteRequest) (
804+
*LoopInQuote, error) {
807805

808806
// Retrieve current server terms to calculate swap fee.
809807
terms, err := s.Server.GetLoopInTerms(ctx, request.Initiator)
@@ -945,8 +943,10 @@ func wrapGrpcError(message string, err error) error {
945943
grpcStatus, _ := status.FromError(err)
946944

947945
return status.Error(
948-
grpcStatus.Code(), fmt.Sprintf("%v: %v", message,
949-
grpcStatus.Message()),
946+
grpcStatus.Code(),
947+
fmt.Sprintf(
948+
"%v: %v", message, grpcStatus.Message(),
949+
),
950950
)
951951
}
952952

@@ -976,6 +976,7 @@ func (s *Client) AbandonSwap(ctx context.Context,
976976
case s.abandonChans[req.SwapHash] <- struct{}{}:
977977
case <-ctx.Done():
978978
return ctx.Err()
979+
979980
default:
980981
// This is to avoid writing to a full channel.
981982
}
@@ -988,8 +989,8 @@ func (s *Client) getAssetRfq(ctx context.Context, quote *LoopOutQuote,
988989
request *LoopOutQuoteRequest) (*LoopOutRfq, error) {
989990

990991
if s.AssetClient == nil {
991-
return nil, errors.New("asset client must be set " +
992-
"when trying to loop out with an asset")
992+
return nil, errors.New("asset client must be set when trying " +
993+
"to loop out with an asset")
993994
}
994995
rfqReq := request.AssetRFQRequest
995996
if rfqReq.Expiry == 0 {
@@ -1002,9 +1003,8 @@ func (s *Client) getAssetRfq(ctx context.Context, quote *LoopOutQuote,
10021003

10031004
// First we'll get the prepay rfq.
10041005
prepayRfq, err := s.AssetClient.GetRfqForAsset(
1005-
ctx, quote.PrepayAmount, rfqReq.AssetId,
1006-
rfqReq.AssetEdgeNode, rfqReq.Expiry,
1007-
rfqReq.MaxLimitMultiplier,
1006+
ctx, quote.PrepayAmount, rfqReq.AssetId, rfqReq.AssetEdgeNode,
1007+
rfqReq.Expiry, rfqReq.MaxLimitMultiplier,
10081008
)
10091009
if err != nil {
10101010
return nil, err
@@ -1023,9 +1023,8 @@ func (s *Client) getAssetRfq(ctx context.Context, quote *LoopOutQuote,
10231023
quote.PrepayAmount
10241024

10251025
swapRfq, err := s.AssetClient.GetRfqForAsset(
1026-
ctx, invoiceAmt, rfqReq.AssetId,
1027-
rfqReq.AssetEdgeNode, rfqReq.Expiry,
1028-
rfqReq.MaxLimitMultiplier,
1026+
ctx, invoiceAmt, rfqReq.AssetId, rfqReq.AssetEdgeNode,
1027+
rfqReq.Expiry, rfqReq.MaxLimitMultiplier,
10291028
)
10301029
if err != nil {
10311030
return nil, err

client_test.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,13 @@ func TestLoopOutSuccess(t *testing.T) {
8484
signalPrepaymentResult := ctx.AssertPaid(prepayInvoiceDesc)
8585

8686
// Expect client to register for conf.
87-
confIntent := ctx.Context.AssertRegisterConf(false, req.HtlcConfirmations)
87+
confIntent := ctx.Context.AssertRegisterConf(
88+
false, req.HtlcConfirmations,
89+
)
8890

89-
testLoopOutSuccess(ctx, testRequest.Amount, info.SwapHash,
90-
signalPrepaymentResult, signalSwapPaymentResult, false,
91-
confIntent, swap.HtlcV3,
91+
testLoopOutSuccess(
92+
ctx, testRequest.Amount, info.SwapHash, signalPrepaymentResult,
93+
signalSwapPaymentResult, false, confIntent, swap.HtlcV3,
9294
)
9395
}
9496

@@ -267,8 +269,10 @@ func testLoopOutResume(t *testing.T, confs uint32, expired, preimageRevealed,
267269
},
268270
},
269271
Loop: loopdb.Loop{
270-
Events: []*loopdb.LoopEvent{&update},
271-
Hash: hash,
272+
Events: []*loopdb.LoopEvent{
273+
&update,
274+
},
275+
Hash: hash,
272276
},
273277
}
274278

@@ -310,16 +314,17 @@ func testLoopOutResume(t *testing.T, confs uint32, expired, preimageRevealed,
310314
ctx.assertStatus(loopdb.StateFailTimeout)
311315
ctx.assertStoreFinished(loopdb.StateFailTimeout)
312316
ctx.finish()
317+
313318
return
314319
}
315320

316321
// Because there is no reliable payment yet, an invoice is assumed to be
317322
// paid after resume.
318-
testLoopOutSuccess(ctx, amt, hash,
319-
func(r error) {},
323+
testLoopOutSuccess(
324+
ctx, amt, hash,
320325
func(r error) {},
321-
preimageRevealed,
322-
confIntent, utils.GetHtlcScriptVersion(protocolVersion),
326+
func(r error) {}, preimageRevealed, confIntent,
327+
utils.GetHtlcScriptVersion(protocolVersion),
323328
)
324329
}
325330

0 commit comments

Comments
 (0)