mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
staticaddr/deposit: discover all active addresses
Filter wallet UTXOs against every active static-address script and attach the matching address parameters to new deposits. This makes deposits to derived receive addresses visible to the deposit manager.
This commit is contained in:
parent
a56621cf47
commit
eb03aacf6c
6 changed files with 70 additions and 5 deletions
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/lightninglabs/loop/fsm"
|
||||
"github.com/lightninglabs/loop/staticaddr/address"
|
||||
"github.com/lightninglabs/loop/staticaddr/script"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
|
|
@ -76,7 +77,7 @@ type Deposit struct {
|
|||
// AddressParams are the static address parameters that produced this
|
||||
// deposit's pkScript. Spending code must use these per-deposit
|
||||
// parameters rather than assuming all deposits belong to one address.
|
||||
AddressParams *script.Parameters
|
||||
AddressParams *address.Parameters
|
||||
}
|
||||
|
||||
// IsInFinalState returns true if the deposit is final.
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
"github.com/lightninglabs/loop/staticaddr/address"
|
||||
"github.com/lightninglabs/loop/staticaddr/script"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
)
|
||||
|
|
@ -39,6 +40,14 @@ type AddressManager interface {
|
|||
GetStaticAddressParameters(ctx context.Context) (*script.Parameters,
|
||||
error)
|
||||
|
||||
// GetStaticAddressID returns the database ID for the static address
|
||||
// behind the given pkScript.
|
||||
GetStaticAddressID(ctx context.Context, pkScript []byte) (int32, error)
|
||||
|
||||
// GetParameters returns active static address parameters for the given
|
||||
// pkScript.
|
||||
GetParameters(pkScript []byte) *address.Parameters
|
||||
|
||||
// GetStaticAddress returns the deposit address for the given
|
||||
// client and server public keys.
|
||||
GetStaticAddress(ctx context.Context) (*script.StaticAddress, error)
|
||||
|
|
|
|||
|
|
@ -376,6 +376,17 @@ func (m *Manager) createNewDeposit(ctx context.Context,
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
addressParams := m.cfg.AddressManager.GetParameters(utxo.PkScript)
|
||||
if addressParams == nil {
|
||||
return nil, fmt.Errorf("missing static address parameters "+
|
||||
"for deposit %v", utxo.OutPoint)
|
||||
}
|
||||
if addressParams.ID <= 0 {
|
||||
return nil, fmt.Errorf("missing static address ID for deposit %v",
|
||||
utxo.OutPoint)
|
||||
}
|
||||
|
||||
deposit := &Deposit{
|
||||
ID: id,
|
||||
state: Deposited,
|
||||
|
|
@ -383,6 +394,7 @@ func (m *Manager) createNewDeposit(ctx context.Context,
|
|||
Value: utxo.Value,
|
||||
ConfirmationHeight: confirmationHeight,
|
||||
TimeOutSweepPkScript: timeoutSweepPkScript,
|
||||
AddressParams: addressParams,
|
||||
}
|
||||
|
||||
err = m.cfg.Store.CreateDeposit(ctx, deposit)
|
||||
|
|
|
|||
|
|
@ -112,6 +112,16 @@ type mockAddressManager struct {
|
|||
mock.Mock
|
||||
}
|
||||
|
||||
func (m *mockAddressManager) hasExpectation(method string) bool {
|
||||
for _, call := range m.ExpectedCalls {
|
||||
if call.Method == method {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (m *mockAddressManager) GetStaticAddressParameters(ctx context.Context) (
|
||||
*script.Parameters, error) {
|
||||
|
||||
|
|
@ -121,6 +131,39 @@ func (m *mockAddressManager) GetStaticAddressParameters(ctx context.Context) (
|
|||
args.Error(1)
|
||||
}
|
||||
|
||||
func (m *mockAddressManager) GetStaticAddressID(ctx context.Context,
|
||||
pkScript []byte) (int32, error) {
|
||||
|
||||
if !m.hasExpectation("GetStaticAddressID") {
|
||||
return 1, nil
|
||||
}
|
||||
|
||||
args := m.Called(ctx, pkScript)
|
||||
|
||||
return int32(args.Int(0)), args.Error(1)
|
||||
}
|
||||
|
||||
func (m *mockAddressManager) GetParameters(
|
||||
pkScript []byte) *address.Parameters {
|
||||
|
||||
if !m.hasExpectation("GetParameters") {
|
||||
return &address.Parameters{
|
||||
ID: 1,
|
||||
ClientPubkey: defaultServerPubkey,
|
||||
ServerPubkey: defaultServerPubkey,
|
||||
Expiry: defaultExpiry,
|
||||
PkScript: pkScript,
|
||||
}
|
||||
}
|
||||
|
||||
args := m.Called(pkScript)
|
||||
if args.Get(0) == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return args.Get(0).(*address.Parameters)
|
||||
}
|
||||
|
||||
func (m *mockAddressManager) GetStaticAddress(ctx context.Context) (
|
||||
*script.StaticAddress, error) {
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import (
|
|||
"github.com/lightninglabs/loop/fsm"
|
||||
"github.com/lightninglabs/loop/loopdb"
|
||||
"github.com/lightninglabs/loop/loopdb/sqlc"
|
||||
"github.com/lightninglabs/loop/staticaddr/script"
|
||||
"github.com/lightninglabs/loop/staticaddr/address"
|
||||
"github.com/lightninglabs/loop/staticaddr/version"
|
||||
"github.com/lightningnetwork/lnd/clock"
|
||||
"github.com/lightningnetwork/lnd/keychain"
|
||||
|
|
@ -439,7 +439,7 @@ func toDeposit(row depositRow, lastUpdate sqlc.DepositUpdate) (*Deposit,
|
|||
return nil, err
|
||||
}
|
||||
|
||||
deposit.AddressParams = &script.Parameters{
|
||||
deposit.AddressParams = &address.Parameters{
|
||||
ID: row.StaticAddressID.Int32,
|
||||
ClientPubkey: clientPubkey,
|
||||
ServerPubkey: serverPubkey,
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ func TestCreateMusig2Session_Success(t *testing.T) {
|
|||
serverKey, err := btcec.NewPrivateKey()
|
||||
require.NoError(t, err)
|
||||
|
||||
params := &script.Parameters{
|
||||
params := &address.Parameters{
|
||||
ClientPubkey: clientKey.PubKey(),
|
||||
ServerPubkey: serverKey.PubKey(),
|
||||
Expiry: 10,
|
||||
|
|
@ -203,7 +203,7 @@ func TestCreateMusig2Sessions_Multiple(t *testing.T) {
|
|||
serverKey, err := btcec.NewPrivateKey()
|
||||
require.NoError(t, err)
|
||||
|
||||
params := &script.Parameters{
|
||||
params := &address.Parameters{
|
||||
ClientPubkey: clientKey.PubKey(),
|
||||
ServerPubkey: serverKey.PubKey(),
|
||||
Expiry: 12,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue