Skip to content

Commit 4861718

Browse files
committed
multi: add asset specifier field to FundingDescriptor struct
This commit replaces the asset ID and asset group public key fields in the `FundingDescriptor` struct with an asset specifier field.
1 parent c8a0304 commit 4861718

File tree

4 files changed

+64
-30
lines changed

4 files changed

+64
-30
lines changed

rpcserver.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3202,11 +3202,14 @@ func (r *rpcServer) BurnAsset(ctx context.Context,
32023202
"burn_amount=%d)", assetID[:], serializedGroupKey,
32033203
in.AmountToBurn)
32043204

3205+
assetSpecifier := asset.NewSpecifierOptionalGroupPubKey(
3206+
assetID, groupKey,
3207+
)
3208+
32053209
fundResp, err := r.cfg.AssetWallet.FundBurn(
32063210
ctx, &tapsend.FundingDescriptor{
3207-
ID: assetID,
3208-
GroupKey: groupKey,
3209-
Amount: in.AmountToBurn,
3211+
AssetSpecifier: assetSpecifier,
3212+
Amount: in.AmountToBurn,
32103213
},
32113214
)
32123215
if err != nil {

tapfreighter/wallet.go

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,20 @@ func (f *AssetWallet) FundPacket(ctx context.Context,
362362
return nil, address.ErrMismatchedHRP
363363
}
364364

365+
// Extract the asset ID and group key from the funding descriptor.
366+
assetId := fundDesc.AssetSpecifier.UnwrapIdToPtr()
367+
if assetId == nil {
368+
return nil, fmt.Errorf("unable to unwrap asset ID")
369+
}
370+
371+
groupKey := fundDesc.AssetSpecifier.UnwrapGroupKeyToPtr()
372+
365373
// We need to find a commitment that has enough assets to satisfy this
366374
// send request. We'll map the address to a set of constraints, so we
367375
// can use that to do Taproot asset coin selection.
368376
constraints := CommitmentConstraints{
369-
GroupKey: fundDesc.GroupKey,
370-
AssetID: &fundDesc.ID,
377+
GroupKey: groupKey,
378+
AssetID: assetId,
371379
MinAmt: fundDesc.Amount,
372380
Bip86ScriptKeysOnly: true,
373381
}
@@ -396,12 +404,20 @@ func (f *AssetWallet) FundPacket(ctx context.Context,
396404
func (f *AssetWallet) FundBurn(ctx context.Context,
397405
fundDesc *tapsend.FundingDescriptor) (*FundedVPacket, error) {
398406

407+
// Extract the asset ID and group key from the funding descriptor.
408+
assetId, err := fundDesc.AssetSpecifier.UnwrapIdOrErr()
409+
if err != nil {
410+
return nil, err
411+
}
412+
413+
groupKey := fundDesc.AssetSpecifier.UnwrapGroupKeyToPtr()
414+
399415
// We need to find a commitment that has enough assets to satisfy this
400416
// send request. We'll map the address to a set of constraints, so we
401417
// can use that to do Taproot asset coin selection.
402418
constraints := CommitmentConstraints{
403-
GroupKey: fundDesc.GroupKey,
404-
AssetID: &fundDesc.ID,
419+
GroupKey: groupKey,
420+
AssetID: assetId,
405421
MinAmt: fundDesc.Amount,
406422
}
407423
selectedCommitments, err := f.cfg.CoinSelector.SelectCoins(
@@ -433,7 +449,7 @@ func (f *AssetWallet) FundBurn(ctx context.Context,
433449

434450
activeAssets := fn.Filter(
435451
selectedCommitments, func(c *AnchoredCommitment) bool {
436-
return c.Asset.ID() == fundDesc.ID
452+
return c.Asset.ID() == assetId
437453
},
438454
)
439455

@@ -467,7 +483,7 @@ func (f *AssetWallet) FundBurn(ctx context.Context,
467483
vPkt := &tappsbt.VPacket{
468484
Inputs: []*tappsbt.VInput{{
469485
PrevID: asset.PrevID{
470-
ID: fundDesc.ID,
486+
ID: assetId,
471487
},
472488
}},
473489
Outputs: []*tappsbt.VOutput{{
@@ -554,8 +570,13 @@ func (f *AssetWallet) fundPacketWithInputs(ctx context.Context,
554570
fundDesc *tapsend.FundingDescriptor, vPkt *tappsbt.VPacket,
555571
selectedCommitments []*AnchoredCommitment) (*FundedVPacket, error) {
556572

573+
assetId, err := fundDesc.AssetSpecifier.UnwrapIdOrErr()
574+
if err != nil {
575+
return nil, err
576+
}
577+
557578
log.Infof("Selected %v asset inputs for send of %d to %x",
558-
len(selectedCommitments), fundDesc.Amount, fundDesc.ID[:])
579+
len(selectedCommitments), fundDesc.Amount, assetId[:])
559580

560581
assetType := selectedCommitments[0].Asset.Type
561582

tapsend/send.go

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,8 @@ type AssetGroupQuerier interface {
159159
// verify input assets in order to send to a specific recipient. It is a subset
160160
// of the information contained in a Taproot Asset address.
161161
type FundingDescriptor struct {
162-
// ID is the asset ID of the asset being transferred.
163-
ID asset.ID
164-
165-
// GroupKey is the optional group key of the asset to transfer.
166-
GroupKey *btcec.PublicKey
162+
// AssetSpecifier is the asset specifier.
163+
AssetSpecifier asset.Specifier
167164

168165
// Amount is the amount of the asset to transfer.
169166
Amount uint64
@@ -172,12 +169,7 @@ type FundingDescriptor struct {
172169
// TapCommitmentKey is the key that maps to the root commitment for the asset
173170
// group specified by a recipient descriptor.
174171
func (r *FundingDescriptor) TapCommitmentKey() [32]byte {
175-
assetSpecifier := asset.NewIdSpecifier(r.ID)
176-
if r.GroupKey != nil {
177-
assetSpecifier = asset.NewSpecifier(r.ID, *r.GroupKey)
178-
}
179-
180-
return asset.TapCommitmentKey(assetSpecifier)
172+
return asset.TapCommitmentKey(r.AssetSpecifier)
181173
}
182174

183175
// DescribeRecipients extracts the recipient descriptors from a Taproot Asset
@@ -204,9 +196,12 @@ func DescribeRecipients(ctx context.Context, vPkt *tappsbt.VPacket,
204196
return nil, fmt.Errorf("unable to query asset group: %w", err)
205197
}
206198

199+
assetSpecifier := asset.NewSpecifierOptionalGroupPubKey(
200+
firstInput.PrevID.ID, groupPubKey,
201+
)
202+
207203
desc := &FundingDescriptor{
208-
ID: firstInput.PrevID.ID,
209-
GroupKey: groupPubKey,
204+
AssetSpecifier: assetSpecifier,
210205
}
211206
for idx := range vPkt.Outputs {
212207
desc.Amount += vPkt.Outputs[idx].Amount
@@ -223,9 +218,13 @@ func DescribeAddrs(addrs []*address.Tap) (*FundingDescriptor, error) {
223218
}
224219

225220
firstAddr := addrs[0]
221+
222+
assetSpecifier := asset.NewSpecifierOptionalGroupPubKey(
223+
firstAddr.AssetID, firstAddr.GroupKey,
224+
)
225+
226226
desc := &FundingDescriptor{
227-
ID: firstAddr.AssetID,
228-
GroupKey: firstAddr.GroupKey,
227+
AssetSpecifier: assetSpecifier,
229228
}
230229
for idx := range addrs {
231230
desc.Amount += addrs[idx].Amount
@@ -251,10 +250,18 @@ func AssetFromTapCommitment(tapCommitment *commitment.TapCommitment,
251250
ErrMissingInputAsset)
252251
}
253252

253+
// Determine whether issuance is disabled for the asset.
254+
issuanceDisabled := !desc.AssetSpecifier.HasGroupPubKey()
255+
256+
assetId, err := desc.AssetSpecifier.UnwrapIdOrErr()
257+
if err != nil {
258+
return nil, err
259+
}
260+
254261
// The asset tree must have a non-empty Asset at the location
255262
// specified by the sender's script key.
256263
assetCommitmentKey := asset.AssetCommitmentKey(
257-
desc.ID, &inputScriptKey, desc.GroupKey == nil,
264+
assetId, &inputScriptKey, issuanceDisabled,
258265
)
259266
inputAsset, ok := assetCommitment.Asset(assetCommitmentKey)
260267
if !ok {

tapsend/send_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,10 +1810,13 @@ func TestAddressValidInput(t *testing.T) {
18101810
}
18111811

18121812
func addrToFundDesc(addr address.Tap) *tapsend.FundingDescriptor {
1813+
assetSpecifier := asset.NewSpecifierOptionalGroupPubKey(
1814+
addr.AssetID, addr.GroupKey,
1815+
)
1816+
18131817
return &tapsend.FundingDescriptor{
1814-
ID: addr.AssetID,
1815-
GroupKey: addr.GroupKey,
1816-
Amount: addr.Amount,
1818+
AssetSpecifier: assetSpecifier,
1819+
Amount: addr.Amount,
18171820
}
18181821
}
18191822

@@ -2419,7 +2422,7 @@ func TestValidateAnchorOutputs(t *testing.T) {
24192422
vOutCommitmentProof := proof.CommitmentProof{
24202423
Proof: commitment.Proof{
24212424
TaprootAssetProof: commitment.
2422-
TaprootAssetProof{
2425+
TaprootAssetProof{
24232426
Version: asset1Commitment.Version,
24242427
},
24252428
},

0 commit comments

Comments
 (0)