Skip to content

Commit dc2ef25

Browse files
committed
rpcserver: use new asset group flags in MintAsset
1 parent 5b1c032 commit dc2ef25

File tree

1 file changed

+45
-19
lines changed

1 file changed

+45
-19
lines changed

rpcserver.go

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,37 @@ func (r *rpcServer) MintAsset(ctx context.Context,
357357
specificGroupKey := len(req.Asset.GroupKey) != 0
358358
specificGroupAnchor := len(req.Asset.GroupAnchor) != 0
359359

360+
switch {
361+
// New grouped asset and grouped asset cannot both be set.
362+
case req.Asset.NewGroupedAsset && req.Asset.GroupedAsset:
363+
return nil, fmt.Errorf("cannot set both new grouped asset " +
364+
"and grouped asset",
365+
)
366+
360367
// Using a specific group key or anchor implies disabling emission.
361-
if req.EnableEmission {
368+
case req.Asset.NewGroupedAsset:
362369
if specificGroupKey || specificGroupAnchor {
363370
return nil, fmt.Errorf("must disable emission to " +
364371
"specify a group")
365372
}
373+
374+
// If the asset is intended to be part of an existing group, a group key
375+
// or anchor must be specified, but not both.
376+
case req.Asset.GroupedAsset:
377+
if !specificGroupKey && !specificGroupAnchor {
378+
return nil, fmt.Errorf("must specify a group key or" +
379+
"group anchor")
380+
}
381+
382+
if specificGroupKey && specificGroupAnchor {
383+
return nil, fmt.Errorf("cannot specify both a group " +
384+
"key and a group anchor")
385+
}
386+
387+
// A group was specified without GroupedAsset being set.
388+
case specificGroupKey || specificGroupAnchor:
389+
return nil, fmt.Errorf("must set grouped asset to mint into " +
390+
"a specific group")
366391
}
367392

368393
assetVersion, err := taprpc.UnmarshalAssetVersion(
@@ -377,29 +402,24 @@ func (r *rpcServer) MintAsset(ctx context.Context,
377402
AssetType: asset.Type(req.Asset.AssetType),
378403
AssetName: req.Asset.Name,
379404
Amount: req.Asset.Amount,
380-
EnableEmission: req.EnableEmission,
405+
EnableEmission: req.Asset.NewGroupedAsset,
381406
}
382407

383408
rpcsLog.Infof("[MintAsset]: version=%v, type=%v, name=%v, amt=%v, "+
384409
"issuance=%v", seedling.AssetVersion, seedling.AssetType,
385410
seedling.AssetName, seedling.Amount, seedling.EnableEmission)
386411

412+
switch {
387413
// If a group key is provided, parse the provided group public key
388414
// before creating the asset seedling.
389-
if specificGroupKey {
390-
if specificGroupAnchor {
391-
return nil, fmt.Errorf("cannot specify a group key " +
392-
"and a group anchor")
393-
}
394-
415+
case specificGroupKey:
395416
groupTweakedKey, err := btcec.ParsePubKey(req.Asset.GroupKey)
396417
if err != nil {
397418
return nil, fmt.Errorf("invalid group key: %w", err)
398419
}
399420

400421
err = r.checkBalanceOverflow(
401-
ctx, nil, groupTweakedKey,
402-
req.Asset.Amount,
422+
ctx, nil, groupTweakedKey, req.Asset.Amount,
403423
)
404424
if err != nil {
405425
return nil, err
@@ -410,11 +430,10 @@ func (r *rpcServer) MintAsset(ctx context.Context,
410430
GroupPubKey: *groupTweakedKey,
411431
},
412432
}
413-
}
414433

415434
// If a group anchor is provided, propoate the name to the seedling.
416435
// We cannot do any name validation from outside the minter.
417-
if specificGroupAnchor {
436+
case specificGroupAnchor:
418437
seedling.GroupAnchor = &req.Asset.GroupAnchor
419438
}
420439

@@ -2500,9 +2519,10 @@ func marshalMintingBatch(batch *tapgarden.MintingBatch,
25002519

25012520
// marshalSeedlings marshals the seedlings into the RPC counterpart.
25022521
func marshalSeedlings(
2503-
seedlings map[string]*tapgarden.Seedling) ([]*mintrpc.MintAsset, error) {
2522+
seedlings map[string]*tapgarden.Seedling) ([]*mintrpc.PendingAsset,
2523+
error) {
25042524

2505-
rpcAssets := make([]*mintrpc.MintAsset, 0, len(seedlings))
2525+
rpcAssets := make([]*mintrpc.PendingAsset, 0, len(seedlings))
25062526
for _, seedling := range seedlings {
25072527
var groupKeyBytes []byte
25082528
if seedling.HasGroupKey() {
@@ -2534,25 +2554,31 @@ func marshalSeedlings(
25342554
return nil, err
25352555
}
25362556

2537-
rpcAssets = append(rpcAssets, &mintrpc.MintAsset{
2557+
nextSeedling := &mintrpc.PendingAsset{
25382558
AssetType: taprpc.AssetType(seedling.AssetType),
25392559
AssetVersion: assetVersion,
25402560
Name: seedling.AssetName,
25412561
AssetMeta: seedlingMeta,
25422562
Amount: seedling.Amount,
25432563
GroupKey: groupKeyBytes,
25442564
GroupAnchor: groupAnchor,
2545-
})
2565+
}
2566+
2567+
if seedling.EnableEmission {
2568+
nextSeedling.NewGroupedAsset = true
2569+
}
2570+
2571+
rpcAssets = append(rpcAssets, nextSeedling)
25462572
}
25472573

25482574
return rpcAssets, nil
25492575
}
25502576

25512577
// marshalSprouts marshals the sprouts into the RPC counterpart.
25522578
func marshalSprouts(sprouts []*asset.Asset,
2553-
metas tapgarden.AssetMetas) []*mintrpc.MintAsset {
2579+
metas tapgarden.AssetMetas) []*mintrpc.PendingAsset {
25542580

2555-
rpcAssets := make([]*mintrpc.MintAsset, 0, len(sprouts))
2581+
rpcAssets := make([]*mintrpc.PendingAsset, 0, len(sprouts))
25562582
for _, sprout := range sprouts {
25572583
scriptKey := asset.ToSerialized(sprout.ScriptKey.PubKey)
25582584

@@ -2573,7 +2599,7 @@ func marshalSprouts(sprouts []*asset.Asset,
25732599
groupKeyBytes = gpk.SerializeCompressed()
25742600
}
25752601

2576-
rpcAssets = append(rpcAssets, &mintrpc.MintAsset{
2602+
rpcAssets = append(rpcAssets, &mintrpc.PendingAsset{
25772603
AssetType: taprpc.AssetType(sprout.Type),
25782604
Name: sprout.Tag,
25792605
AssetMeta: assetMeta,

0 commit comments

Comments
 (0)