Skip to content

Commit b3dc71a

Browse files
committed
staticaddr: open channel manager
1 parent 5cb7d6a commit b3dc71a

File tree

7 files changed

+1245
-0
lines changed

7 files changed

+1245
-0
lines changed

staticaddr/address/manager_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ type mockStaticAddressClient struct {
3232
mock.Mock
3333
}
3434

35+
func (m *mockStaticAddressClient) SignOpenChannelPsbt(ctx context.Context,
36+
in *swapserverrpc.SignOpenChannelPsbtRequest,
37+
opts ...grpc.CallOption) (
38+
*swapserverrpc.SignOpenChannelPsbtResponse, error) {
39+
40+
args := m.Called(ctx, in, opts)
41+
42+
return args.Get(0).(*swapserverrpc.SignOpenChannelPsbtResponse),
43+
args.Error(1)
44+
}
45+
3546
func (m *mockStaticAddressClient) ServerStaticAddressLoopIn(ctx context.Context,
3647
in *swapserverrpc.ServerStaticAddressLoopInRequest,
3748
opts ...grpc.CallOption) (

staticaddr/deposit/manager_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,17 @@ func (m *MockChainNotifier) RegisterSpendNtfn(ctx context.Context,
209209
args.Get(1).(chan error), args.Error(2)
210210
}
211211

212+
func (m *mockStaticAddressClient) SignOpenChannelPsbt(ctx context.Context,
213+
in *swapserverrpc.SignOpenChannelPsbtRequest,
214+
opts ...grpc.CallOption) (
215+
*swapserverrpc.SignOpenChannelPsbtResponse, error) {
216+
217+
args := m.Called(ctx, in, opts)
218+
219+
return args.Get(0).(*swapserverrpc.SignOpenChannelPsbtResponse),
220+
args.Error(1)
221+
}
222+
212223
// TestManager checks that the manager processes the right channel notifications
213224
// while a deposit is expiring.
214225
func TestManager(t *testing.T) {

staticaddr/log.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/lightninglabs/loop/staticaddr/address"
66
"github.com/lightninglabs/loop/staticaddr/deposit"
77
"github.com/lightninglabs/loop/staticaddr/loopin"
8+
"github.com/lightninglabs/loop/staticaddr/openchannel"
89
"github.com/lightninglabs/loop/staticaddr/withdraw"
910
"github.com/lightningnetwork/lnd/build"
1011
)
@@ -29,4 +30,5 @@ func UseLogger(logger btclog.Logger) {
2930
deposit.UseLogger(log)
3031
withdraw.UseLogger(log)
3132
loopin.UseLogger(log)
33+
openchannel.UseLogger(log)
3234
}

staticaddr/openchannel/interface.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package openchannel
2+
3+
import (
4+
"context"
5+
6+
"github.com/btcsuite/btcd/wire"
7+
"github.com/lightninglabs/loop/fsm"
8+
"github.com/lightninglabs/loop/staticaddr/address"
9+
"github.com/lightninglabs/loop/staticaddr/deposit"
10+
"github.com/lightninglabs/loop/staticaddr/script"
11+
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
12+
)
13+
14+
// Estimator is an interface that allows us to estimate the fee rate in sat/kw.
15+
type Estimator interface {
16+
// EstimateFeeRate estimates the fee rate in sat/kw for a transaction to
17+
// be confirmed in the given number of blocks.
18+
EstimateFeeRate(ctx context.Context, target int32) (
19+
chainfee.SatPerKWeight, error)
20+
}
21+
22+
// AddressManager handles fetching of address parameters.
23+
type AddressManager interface {
24+
// GetStaticAddressParameters returns the static address parameters.
25+
GetStaticAddressParameters(ctx context.Context) (*address.Parameters,
26+
error)
27+
28+
// GetStaticAddress returns the deposit address for the given
29+
// client and server public keys.
30+
GetStaticAddress(ctx context.Context) (*script.StaticAddress, error)
31+
}
32+
33+
type DepositManager interface {
34+
// AllOutpointsActiveDeposits returns all deposits that are in the
35+
// given state. If the state filter is fsm.StateTypeNone, all deposits
36+
// are returned.
37+
AllOutpointsActiveDeposits(outpoints []wire.OutPoint,
38+
stateFilter fsm.StateType) ([]*deposit.Deposit, bool)
39+
40+
// GetActiveDepositsInState returns all deposits that are in the
41+
// given state.
42+
GetActiveDepositsInState(stateFilter fsm.StateType) ([]*deposit.Deposit,
43+
error)
44+
45+
// TransitionDeposits transitions the deposits to the given state.
46+
TransitionDeposits(ctx context.Context, deposits []*deposit.Deposit,
47+
event fsm.EventType, expectedFinalState fsm.StateType) error
48+
}

staticaddr/openchannel/log.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package openchannel
2+
3+
import (
4+
"github.com/btcsuite/btclog/v2"
5+
"github.com/lightningnetwork/lnd/build"
6+
)
7+
8+
// Subsystem defines the sub system name of this package.
9+
const Subsystem = "SCHOPEN"
10+
11+
// log is a logger that is initialized with no output filters. This means the
12+
// package will not perform any logging by default until the caller requests it.
13+
var log btclog.Logger
14+
15+
// The default amount of logging is none.
16+
func init() {
17+
UseLogger(build.NewSubLogger(Subsystem, nil))
18+
}
19+
20+
// UseLogger uses a specified Logger to output package logging info. This should
21+
// be used in preference to SetLogWriter if the caller is also using btclog.
22+
func UseLogger(logger btclog.Logger) {
23+
log = logger
24+
}

0 commit comments

Comments
 (0)