From f3919d976c554030829d1d82ffdea6d41e1b93cc Mon Sep 17 00:00:00 2001 From: sputn1ck Date: Fri, 1 Mar 2024 14:24:17 +0100 Subject: [PATCH] instantout: export value and expiry --- instantout/actions.go | 18 +++++++++--------- instantout/instantout.go | 38 +++++++++++++++++++------------------- instantout/store.go | 18 +++++++++--------- 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/instantout/actions.go b/instantout/actions.go index 977cd04..71a411f 100644 --- a/instantout/actions.go +++ b/instantout/actions.go @@ -185,13 +185,13 @@ func (f *FSM) InitInstantOutAction(eventCtx fsm.EventContext) fsm.EventType { protocolVersion: ProtocolVersionFullReservation, initiationHeight: initCtx.initationHeight, outgoingChanSet: initCtx.outgoingChanSet, - cltvExpiry: initCtx.cltvExpiry, + CltvExpiry: initCtx.cltvExpiry, clientPubkey: keyRes.PubKey, serverPubkey: serverPubkey, - value: btcutil.Amount(reservationAmt), + Value: btcutil.Amount(reservationAmt), htlcFeeRate: feeRate, swapInvoice: instantOutResponse.SwapInvoice, - reservations: reservations, + Reservations: reservations, keyLocator: keyRes.KeyLocator, sweepAddress: sweepAddress, } @@ -211,7 +211,7 @@ func (f *FSM) InitInstantOutAction(eventCtx fsm.EventContext) fsm.EventType { func (f *FSM) PollPaymentAcceptedAction(_ fsm.EventContext) fsm.EventType { // Now that we're doing the swap, we first lock the reservations // so that they can't be used for other swaps. - for _, reservation := range f.InstantOut.reservations { + for _, reservation := range f.InstantOut.Reservations { err := f.cfg.ReservationManager.LockReservation( f.ctx, reservation.ID, ) @@ -227,7 +227,7 @@ func (f *FSM) PollPaymentAcceptedAction(_ fsm.EventContext) fsm.EventType { Invoice: f.InstantOut.swapInvoice, Timeout: defaultSendpaymentTimeout, MaxParts: defaultMaxParts, - MaxFee: getMaxRoutingFee(f.InstantOut.value), + MaxFee: getMaxRoutingFee(f.InstantOut.Value), }, ) if err != nil { @@ -301,7 +301,7 @@ func (f *FSM) BuildHTLCAction(eventCtx fsm.EventContext) fsm.EventType { return f.handleErrorAndUnlockReservations(err) } - if len(htlcInitRes.HtlcServerNonces) != len(f.InstantOut.reservations) { + if len(htlcInitRes.HtlcServerNonces) != len(f.InstantOut.Reservations) { return f.handleErrorAndUnlockReservations( errors.New("invalid number of server nonces"), ) @@ -435,8 +435,8 @@ func (f *FSM) PushPreimageAction(eventCtx fsm.EventContext) fsm.EventType { return OnErrorPublishHtlc } - f.InstantOut.finalizedSweeplessSweepTx = sweepTx - txHash := f.InstantOut.finalizedSweeplessSweepTx.TxHash() + f.InstantOut.FinalizedSweeplessSweepTx = sweepTx + txHash := f.InstantOut.FinalizedSweeplessSweepTx.TxHash() f.InstantOut.SweepTxHash = &txHash @@ -598,7 +598,7 @@ func (f *FSM) handleErrorAndUnlockReservations(err error) fsm.EventType { defer cancel() // Unlock the reservations. - for _, reservation := range f.InstantOut.reservations { + for _, reservation := range f.InstantOut.Reservations { err := f.cfg.ReservationManager.UnlockReservation( ctx, reservation.ID, ) diff --git a/instantout/instantout.go b/instantout/instantout.go index 162fef2..5fc1923 100644 --- a/instantout/instantout.go +++ b/instantout/instantout.go @@ -35,16 +35,16 @@ type InstantOut struct { // State is the current state of the swap. State fsm.StateType - // cltvExpiry is the expiry of the swap. - cltvExpiry int32 + // CltvExpiry is the expiry of the swap. + CltvExpiry int32 // outgoingChanSet optionally specifies the short channel ids of the // channels that may be used to loop out. outgoingChanSet loopdb.ChannelSet - // reservations are the reservations that are used in as inputs for the + // Reservations are the Reservations that are used in as inputs for the // instant out swap. - reservations []*reservation.Reservation + Reservations []*reservation.Reservation // protocolVersion is the version of the protocol that is used for the // swap. @@ -53,8 +53,8 @@ type InstantOut struct { // initiationHeight is the height at which the swap was initiated. initiationHeight int32 - // value is the amount that is swapped. - value btcutil.Amount + // Value is the amount that is swapped. + Value btcutil.Amount // keyLocator is the key locator that is used for the swap. keyLocator keychain.KeyLocator @@ -81,9 +81,9 @@ type InstantOut struct { // SweepTxHash is the hash of the sweep transaction. SweepTxHash *chainhash.Hash - // finalizedSweeplessSweepTx is the transaction that is used to sweep + // FinalizedSweeplessSweepTx is the transaction that is used to sweep // the funds in the cooperative path. - finalizedSweeplessSweepTx *wire.MsgTx + FinalizedSweeplessSweepTx *wire.MsgTx // sweepConfirmationHeight is the height at which the sweep // transaction was confirmed. @@ -93,7 +93,7 @@ type InstantOut struct { // getHtlc returns the swap.htlc for the instant out. func (i *InstantOut) getHtlc(chainParams *chaincfg.Params) (*swap.Htlc, error) { return swap.NewHtlcV2( - i.cltvExpiry, pubkeyTo33ByteSlice(i.serverPubkey), + i.CltvExpiry, pubkeyTo33ByteSlice(i.serverPubkey), pubkeyTo33ByteSlice(i.clientPubkey), i.SwapHash, chainParams, ) } @@ -104,11 +104,11 @@ func (i *InstantOut) createMusig2Session(ctx context.Context, [][]byte, error) { // Create the htlc musig2 context. - musig2Sessions := make([]*input.MuSig2SessionInfo, len(i.reservations)) - clientNonces := make([][]byte, len(i.reservations)) + musig2Sessions := make([]*input.MuSig2SessionInfo, len(i.Reservations)) + clientNonces := make([][]byte, len(i.Reservations)) // Create the sessions and nonces from the reservations. - for idx, reservation := range i.reservations { + for idx, reservation := range i.Reservations { session, err := reservation.Musig2CreateSession(ctx, signer) if err != nil { return nil, nil, err @@ -123,12 +123,12 @@ func (i *InstantOut) createMusig2Session(ctx context.Context, // getInputReservation returns the input reservation for the instant out. func (i *InstantOut) getInputReservations() (InputReservations, error) { - if len(i.reservations) == 0 { + if len(i.Reservations) == 0 { return nil, errors.New("no reservations") } - inputs := make(InputReservations, len(i.reservations)) - for idx, reservation := range i.reservations { + inputs := make(InputReservations, len(i.Reservations)) + for idx, reservation := range i.Reservations { pkScript, err := reservation.GetPkScript() if err != nil { return nil, err @@ -170,7 +170,7 @@ func (i *InstantOut) createHtlcTransaction(network *chaincfg.Params) ( // Estimate the fee weight := htlcWeight(len(inputReservations)) fee := i.htlcFeeRate.FeeForWeight(weight) - if fee > i.value/5 { + if fee > i.Value/5 { return nil, errors.New("fee is higher than 20% of " + "sweep value") } @@ -182,7 +182,7 @@ func (i *InstantOut) createHtlcTransaction(network *chaincfg.Params) ( // Create the sweep output sweepOutput := &wire.TxOut{ - Value: int64(i.value) - int64(fee), + Value: int64(i.Value) - int64(fee), PkScript: htlc.PkScript, } @@ -214,7 +214,7 @@ func (i *InstantOut) createSweeplessSweepTx(feerate chainfee.SatPerKWeight) ( // Estimate the fee weight := sweeplessSweepWeight(len(inputReservations)) fee := feerate.FeeForWeight(weight) - if fee > i.value/5 { + if fee > i.Value/5 { return nil, errors.New("fee is higher than 20% of " + "sweep value") } @@ -226,7 +226,7 @@ func (i *InstantOut) createSweeplessSweepTx(feerate chainfee.SatPerKWeight) ( // Create the sweep output sweepOutput := &wire.TxOut{ - Value: int64(i.value) - int64(fee), + Value: int64(i.Value) - int64(fee), PkScript: pkscript, } diff --git a/instantout/store.go b/instantout/store.go index 39b16d3..6d622b0 100644 --- a/instantout/store.go +++ b/instantout/store.go @@ -94,8 +94,8 @@ func (s *SQLStore) CreateInstantLoopOut(ctx context.Context, SwapHash: instantOut.SwapHash[:], Preimage: instantOut.swapPreimage[:], InitiationTime: s.clock.Now(), - AmountRequested: int64(instantOut.value), - CltvExpiry: instantOut.cltvExpiry, + AmountRequested: int64(instantOut.Value), + CltvExpiry: instantOut.CltvExpiry, MaxMinerFee: 0, MaxSwapFee: 0, InitiationHeight: instantOut.initiationHeight, @@ -114,7 +114,7 @@ func (s *SQLStore) CreateInstantLoopOut(ctx context.Context, } reservationIdByteSlice := reservationIdsToByteSlice( - instantOut.reservations, + instantOut.Reservations, ) instantOutArgs := sqlc.InsertInstantOutParams{ SwapHash: instantOut.SwapHash[:], @@ -172,9 +172,9 @@ func (s *SQLStore) UpdateInstantLoopOut(ctx context.Context, } var finalSweeplessSweepTx []byte - if instantOut.finalizedSweeplessSweepTx != nil { + if instantOut.FinalizedSweeplessSweepTx != nil { var buffer bytes.Buffer - err := instantOut.finalizedSweeplessSweepTx.Serialize( + err := instantOut.FinalizedSweeplessSweepTx.Serialize( &buffer, ) if err != nil { @@ -355,12 +355,12 @@ func (s *SQLStore) sqlInstantOutToInstantOut(ctx context.Context, instantOut := &InstantOut{ SwapHash: swapHash, swapPreimage: swapPreImage, - cltvExpiry: row.CltvExpiry, + CltvExpiry: row.CltvExpiry, outgoingChanSet: outgoingChanSet, - reservations: reservations, + Reservations: reservations, protocolVersion: ProtocolVersion(row.ProtocolVersion), initiationHeight: row.InitiationHeight, - value: btcutil.Amount(row.AmountRequested), + Value: btcutil.Amount(row.AmountRequested), keyLocator: keychain.KeyLocator{ Family: keychain.KeyFamily(row.ClientKeyFamily), Index: uint32(row.ClientKeyIndex), @@ -372,7 +372,7 @@ func (s *SQLStore) sqlInstantOutToInstantOut(ctx context.Context, sweepAddress: sweepAddress, finalizedHtlcTx: finalizedHtlcTx, SweepTxHash: sweepTxHash, - finalizedSweeplessSweepTx: finalizedSweepLessSweepTx, + FinalizedSweeplessSweepTx: finalizedSweepLessSweepTx, sweepConfirmationHeight: uint32(deserializeNullInt32( row.SweepConfirmationHeight, )),