Skip to content

Commit

Permalink
tapdb+tapsend+tapfreighter:add prevIds to constraints;valid for 1 prevId
Browse files Browse the repository at this point in the history
  • Loading branch information
habibitcoin committed Nov 4, 2024
1 parent 64fbf4a commit 100f726
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tapdb/assets_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,18 @@ func (a *AssetStore) constraintsToDbFilter(
assetFilter.AssetIDFilter = assetIDBytes
assetFilter.KeyGroupFilter = groupKeyBytes

// Check if there's exactly one PrevID and set the filters accordingly.
if len(query.PrevIDs) == 1 {
prevID := query.PrevIDs[0]
encodedOutpoint, err := encodeOutpoint(prevID.OutPoint)
if err == nil {
assetFilter.AnchorPoint = encodedOutpoint
assetFilter.TweakedScriptKey = prevID.ScriptKey.CopyBytes()
}
// If there's an error, we simply skip setting the fields
// TODO, maybe log error or return it?
}

// TODO(roasbeef): only want to allow asset ID or other and not
// both?

Expand Down
1 change: 1 addition & 0 deletions tapfreighter/coin_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func (s *CoinSelect) SelectCoins(ctx context.Context,
AssetSpecifier: constraints.AssetSpecifier,
MinAmt: 1,
CoinSelectType: constraints.CoinSelectType,
PrevIDs: constraints.PrevIDs,
}
eligibleCommitments, err := s.coinLister.ListEligibleCoins(
ctx, listConstraints,
Expand Down
3 changes: 3 additions & 0 deletions tapfreighter/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ type CommitmentConstraints struct {
// to satisfy the constraints.
MinAmt uint64

// PrevIDs are the set of inputs allowed to be used
PrevIDs []*asset.PrevID

// CoinSelectType is the type of coins that should be selected.
CoinSelectType tapsend.CoinSelectType
}
Expand Down
6 changes: 6 additions & 0 deletions tapfreighter/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ func (f *AssetWallet) FundAddressSend(ctx context.Context,
return nil, fmt.Errorf("unable to describe recipients: %w", err)
}

// We need to constrain the prevIDs if they are provided.
if len(prevIds) > 0 {
fundDesc.PrevIDs = prevIds
}

fundDesc.CoinSelectType = coinSelectType
fundedVPkt, err := f.FundPacket(ctx, fundDesc, vPkt)
if err != nil {
Expand Down Expand Up @@ -373,6 +378,7 @@ func (f *AssetWallet) FundPacket(ctx context.Context,
AssetSpecifier: fundDesc.AssetSpecifier,
MinAmt: fundDesc.Amount,
CoinSelectType: fundDesc.CoinSelectType,
PrevIDs: fundDesc.PrevIDs,
}

anchorVersion, err := tappsbt.CommitmentVersion(vPkt.Version)
Expand Down
3 changes: 3 additions & 0 deletions tapsend/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ type FundingDescriptor struct {
// Amount is the amount of the asset to transfer.
Amount uint64

// PrevIDs is the set of inputs that can be used to fund the transfer.
PrevIDs []*asset.PrevID

// CoinSelectType specifies the type of coins that should be selected.
CoinSelectType CoinSelectType
}
Expand Down

0 comments on commit 100f726

Please sign in to comment.