Skip to content

Commit 3e1a9a8

Browse files
committed
supplyverifier: refactor fetchDelegationKey into standalone function
Allows fetching the delegation key without instantiating a Verifier.
1 parent c7656dd commit 3e1a9a8

File tree

2 files changed

+38
-25
lines changed

2 files changed

+38
-25
lines changed

universe/supplyverifier/util.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package supplyverifier
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/btcsuite/btcd/btcec/v2"
8+
"github.com/lightninglabs/taproot-assets/asset"
9+
"github.com/lightninglabs/taproot-assets/universe/supplycommit"
10+
)
11+
12+
// FetchDelegationKey fetches the delegation key for the given asset specifier.
13+
func FetchDelegationKey(ctx context.Context,
14+
assetLookup supplycommit.AssetLookup,
15+
assetSpec asset.Specifier) (btcec.PublicKey, error) {
16+
17+
var zero btcec.PublicKey
18+
19+
metaReveal, err := supplycommit.FetchLatestAssetMetadata(
20+
ctx, assetLookup, assetSpec,
21+
)
22+
if err != nil {
23+
return zero, fmt.Errorf("unable to fetch asset "+
24+
"metadata: %w", err)
25+
}
26+
27+
delegationKey, err := metaReveal.DelegationKey.UnwrapOrErr(
28+
fmt.Errorf("missing delegation key in asset metadata"),
29+
)
30+
if err != nil {
31+
return zero, err
32+
}
33+
34+
return delegationKey, nil
35+
}

universe/supplyverifier/verifier.go

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -727,30 +727,6 @@ func (v *Verifier) verifySupplyLeaves(ctx context.Context,
727727
return nil
728728
}
729729

730-
// fetchDelegationKey fetches the delegation key for the given asset specifier.
731-
func (v *Verifier) fetchDelegationKey(ctx context.Context,
732-
assetSpec asset.Specifier) (btcec.PublicKey, error) {
733-
734-
var zero btcec.PublicKey
735-
736-
metaReveal, err := supplycommit.FetchLatestAssetMetadata(
737-
ctx, v.cfg.AssetLookup, assetSpec,
738-
)
739-
if err != nil {
740-
return zero, fmt.Errorf("unable to fetch asset "+
741-
"metadata: %w", err)
742-
}
743-
744-
delegationKey, err := metaReveal.DelegationKey.UnwrapOrErr(
745-
fmt.Errorf("missing delegation key in asset metadata"),
746-
)
747-
if err != nil {
748-
return zero, err
749-
}
750-
751-
return delegationKey, nil
752-
}
753-
754730
// VerifyCommit verifies a supply commitment for a given asset group.
755731
// Verification succeeds only if all previous supply commitment dependencies
756732
// are known and verified. The dependency chain must be traceable back to the
@@ -801,7 +777,9 @@ func (v *Verifier) VerifyCommit(ctx context.Context,
801777
"commitment with given outpoint: %w", err)
802778
}
803779

804-
delegationKey, err := v.fetchDelegationKey(ctx, assetSpec)
780+
delegationKey, err := FetchDelegationKey(
781+
ctx, v.cfg.AssetLookup, assetSpec,
782+
)
805783
if err != nil {
806784
return fmt.Errorf("unable to fetch delegation key: %w", err)
807785
}

0 commit comments

Comments
 (0)