Skip to content

Commit 7a6ee2e

Browse files
committed
multi: hook up new CoinSelectType field
1 parent 7d9cbb1 commit 7a6ee2e

File tree

6 files changed

+41
-8
lines changed

6 files changed

+41
-8
lines changed

rpcserver.go

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,6 +2019,12 @@ func (r *rpcServer) FundVirtualPsbt(ctx context.Context,
20192019
req *wrpc.FundVirtualPsbtRequest) (*wrpc.FundVirtualPsbtResponse,
20202020
error) {
20212021

2022+
coinSelectType, err := unmarshalCoinSelectType(req.CoinSelectType)
2023+
if err != nil {
2024+
return nil, fmt.Errorf("error parsing coin select type: %w",
2025+
err)
2026+
}
2027+
20222028
var fundedVPkt *tapfreighter.FundedVPacket
20232029
switch {
20242030
case req.GetPsbt() != nil:
@@ -2040,9 +2046,8 @@ func (r *rpcServer) FundVirtualPsbt(ctx context.Context,
20402046
"recipients: %w", err)
20412047
}
20422048

2043-
fundedVPkt, err = r.cfg.AssetWallet.FundPacket(
2044-
ctx, desc, vPkt,
2045-
)
2049+
desc.CoinSelectType = coinSelectType
2050+
fundedVPkt, err = r.cfg.AssetWallet.FundPacket(ctx, desc, vPkt)
20462051
if err != nil {
20472052
return nil, fmt.Errorf("error funding packet: %w", err)
20482053
}
@@ -2073,7 +2078,9 @@ func (r *rpcServer) FundVirtualPsbt(ctx context.Context,
20732078
return nil, fmt.Errorf("no recipients specified")
20742079
}
20752080

2076-
fundedVPkt, err = r.cfg.AssetWallet.FundAddressSend(ctx, addr)
2081+
fundedVPkt, err = r.cfg.AssetWallet.FundAddressSend(
2082+
ctx, coinSelectType, addr,
2083+
)
20772084
if err != nil {
20782085
return nil, fmt.Errorf("error funding address send: "+
20792086
"%w", err)
@@ -2117,6 +2124,26 @@ func (r *rpcServer) FundVirtualPsbt(ctx context.Context,
21172124
return response, nil
21182125
}
21192126

2127+
// unmarshalCoinSelectType converts an RPC select type into a native one.
2128+
func unmarshalCoinSelectType(
2129+
coinSelectType wrpc.CoinSelectType) (tapsend.CoinSelectType, error) {
2130+
2131+
switch coinSelectType {
2132+
case wrpc.CoinSelectType_COIN_SELECT_DEFAULT:
2133+
return tapsend.DefaultCoinSelectType, nil
2134+
2135+
case wrpc.CoinSelectType_COIN_SELECT_BIP86_ONLY:
2136+
return tapsend.Bip86Only, nil
2137+
2138+
case wrpc.CoinSelectType_COIN_SELECT_SCRIPT_TREES_ALLOWED:
2139+
return tapsend.ScriptTreesAllowed, nil
2140+
2141+
default:
2142+
return 0, fmt.Errorf("unknown coin select type: %d",
2143+
coinSelectType)
2144+
}
2145+
}
2146+
21202147
// SignVirtualPsbt signs the inputs of a virtual transaction and prepares the
21212148
// commitments of the inputs and outputs.
21222149
func (r *rpcServer) SignVirtualPsbt(ctx context.Context,

tapchannel/aux_funding_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ func (f *FundingController) fundVirtualPacket(ctx context.Context,
697697

698698
// Fund the packet. This will derive an anchor internal key for us, but
699699
// we'll overwrite that later on.
700+
fundDesc.CoinSelectType = tapsend.Bip86Only
700701
return f.cfg.AssetWallet.FundPacket(ctx, fundDesc, pktTemplate)
701702
}
702703

tapfreighter/chain_porter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ func (p *ChainPorter) stateStep(currentPkg sendPackage) (*sendPackage, error) {
994994
"address parcel")
995995
}
996996
fundSendRes, err := p.cfg.AssetWallet.FundAddressSend(
997-
ctx, addrParcel.destAddrs...,
997+
ctx, tapsend.Bip86Only, addrParcel.destAddrs...,
998998
)
999999
if err != nil {
10001000
return nil, fmt.Errorf("unable to fund address send: "+

tapfreighter/interface.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ type CoinSelector interface {
131131
SelectCoins(ctx context.Context, constraints CommitmentConstraints,
132132
strategy MultiCommitmentSelectStrategy,
133133
maxVersion commitment.TapCommitmentVersion,
134-
) ([]*AnchoredCommitment,
135-
error)
134+
) ([]*AnchoredCommitment, error)
136135

137136
// ReleaseCoins releases/unlocks coins that were previously leased and
138137
// makes them available for coin selection again.

tapfreighter/wallet.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ type Wallet interface {
6868
// asset re-anchors and the Taproot Asset level commitment of the
6969
// selected assets.
7070
FundAddressSend(ctx context.Context,
71+
coinSelectType tapsend.CoinSelectType,
7172
receiverAddrs ...*address.Tap) (*FundedVPacket, error)
7273

7374
// FundPacket funds a virtual transaction, selecting assets to spend
@@ -234,6 +235,7 @@ type FundedVPacket struct {
234235
//
235236
// NOTE: This is part of the Wallet interface.
236237
func (f *AssetWallet) FundAddressSend(ctx context.Context,
238+
coinSelectType tapsend.CoinSelectType,
237239
receiverAddrs ...*address.Tap) (*FundedVPacket, error) {
238240

239241
// We start by creating a new virtual transaction that will be used to
@@ -251,6 +253,7 @@ func (f *AssetWallet) FundAddressSend(ctx context.Context,
251253
return nil, fmt.Errorf("unable to describe recipients: %w", err)
252254
}
253255

256+
fundDesc.CoinSelectType = coinSelectType
254257
fundedVPkt, err := f.FundPacket(ctx, fundDesc, vPkt)
255258
if err != nil {
256259
return nil, err
@@ -367,7 +370,7 @@ func (f *AssetWallet) FundPacket(ctx context.Context,
367370
constraints := CommitmentConstraints{
368371
AssetSpecifier: fundDesc.AssetSpecifier,
369372
MinAmt: fundDesc.Amount,
370-
CoinSelectType: tapsend.Bip86Only,
373+
CoinSelectType: fundDesc.CoinSelectType,
371374
}
372375

373376
anchorVersion, err := tappsbt.CommitmentVersion(vPkt.Version)

tapsend/send.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ type FundingDescriptor struct {
192192

193193
// Amount is the amount of the asset to transfer.
194194
Amount uint64
195+
196+
// CoinSelectType specifies the type of coins that should be selected.
197+
CoinSelectType CoinSelectType
195198
}
196199

197200
// TapCommitmentKey is the key that maps to the root commitment for the asset

0 commit comments

Comments
 (0)