Skip to content

Commit d1eb253

Browse files
committed
multi: rename ExtractPreCommitFromProof to NewPreCommitFromProof
Renamed supplyverifier.ExtractPreCommitFromProof to NewPreCommitFromProof for clearer semantics and consistency with naming conventions.
1 parent 3e1a9a8 commit d1eb253

File tree

3 files changed

+56
-54
lines changed

3 files changed

+56
-54
lines changed

tapdb/universe.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/lightninglabs/taproot-assets/proof"
1717
"github.com/lightninglabs/taproot-assets/tapdb/sqlc"
1818
"github.com/lightninglabs/taproot-assets/universe"
19-
"github.com/lightninglabs/taproot-assets/universe/supplyverifier"
19+
"github.com/lightninglabs/taproot-assets/universe/supplycommit"
2020
lfn "github.com/lightningnetwork/lnd/fn/v2"
2121
"github.com/lightningnetwork/lnd/keychain"
2222
)
@@ -628,7 +628,7 @@ func maybeUpsertSupplyPreCommit(ctx context.Context, dbTx UpsertAssetStore,
628628
return err
629629
}
630630

631-
preCommitOutput, err := supplyverifier.ExtractPreCommitOutput(
631+
preCommitOutput, err := supplycommit.NewPreCommitFromProof(
632632
issuanceProof, delegationKey,
633633
)
634634
if err != nil {

universe/supplycommit/env.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,57 @@ type PreCommitment struct {
365365
GroupPubKey btcec.PublicKey
366366
}
367367

368+
// NewPreCommitFromProof extracts and returns the supply pre-commitment from the
369+
// given issuance proof and delegation key.
370+
func NewPreCommitFromProof(issuanceProof proof.Proof,
371+
delegationKey btcec.PublicKey) (PreCommitment, error) {
372+
373+
var zero PreCommitment
374+
375+
// Identify txOut in mint anchor transaction which corresponds to the
376+
// supply pre-commitment output.
377+
//
378+
// Construct the expected pre-commit tx out.
379+
expectedTxOut, err := tapgarden.PreCommitTxOut(delegationKey)
380+
if err != nil {
381+
return zero, fmt.Errorf("unable to derive expected pre-commit "+
382+
"txout: %w", err)
383+
}
384+
385+
var preCommitTxOutIndex int32 = -1
386+
for idx := range issuanceProof.AnchorTx.TxOut {
387+
txOut := *issuanceProof.AnchorTx.TxOut[idx]
388+
389+
// Compare txOut to the expected pre-commit tx out.
390+
isValueEqual := txOut.Value == expectedTxOut.Value
391+
isPkScriptEqual := bytes.Equal(
392+
txOut.PkScript, expectedTxOut.PkScript,
393+
)
394+
395+
if isValueEqual && isPkScriptEqual {
396+
preCommitTxOutIndex = int32(idx)
397+
break
398+
}
399+
}
400+
401+
// If we didn't find the pre-commit tx out, then return an error.
402+
if preCommitTxOutIndex == -1 {
403+
return zero, fmt.Errorf("unable to find pre-commit tx out in " +
404+
"issuance anchor tx")
405+
}
406+
407+
// Calculate the outpoint of the supply pre-commitment.
408+
return PreCommitment{
409+
BlockHeight: issuanceProof.BlockHeight,
410+
MintingTxn: &issuanceProof.AnchorTx,
411+
OutIdx: uint32(preCommitTxOutIndex),
412+
InternalKey: keychain.KeyDescriptor{
413+
PubKey: &delegationKey,
414+
},
415+
GroupPubKey: issuanceProof.Asset.GroupKey.GroupPubKey,
416+
}, nil
417+
}
418+
368419
// TxIn returns the transaction input that corresponds to the pre-commitment.
369420
func (p *PreCommitment) TxIn() *wire.TxIn {
370421
return &wire.TxIn{

universe/supplyverifier/verifier.go

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"github.com/lightninglabs/taproot-assets/proof"
1717
"github.com/lightninglabs/taproot-assets/tapgarden"
1818
"github.com/lightninglabs/taproot-assets/universe/supplycommit"
19-
"github.com/lightningnetwork/lnd/keychain"
2019
)
2120

2221
// VerifierCfg is the configuration for the verifier.
@@ -539,7 +538,9 @@ func (v *Verifier) verifyIssuanceLeaf(ctx context.Context,
539538

540539
// Attempt to extract the pre-commitment output from the issuance proof
541540
// anchor transaction.
542-
_, err = ExtractPreCommitOutput(issuanceProof, delegationKey)
541+
_, err = supplycommit.NewPreCommitFromProof(
542+
issuanceProof, delegationKey,
543+
)
543544
if err != nil {
544545
return fmt.Errorf("unable to extract pre-commit output from "+
545546
"issuance proof anchor tx: %w", err)
@@ -822,53 +823,3 @@ func (v *Verifier) VerifyCommit(ctx context.Context,
822823
unspentPreCommits,
823824
)
824825
}
825-
826-
// ExtractPreCommitOutput extracts and returns the supply pre-commitment output
827-
// from the given issuance proof and asset metadata reveal.
828-
func ExtractPreCommitOutput(issuanceProof proof.Proof,
829-
delegationKey btcec.PublicKey) (supplycommit.PreCommitment, error) {
830-
831-
var zero supplycommit.PreCommitment
832-
833-
// Identify txOut in mint anchor transaction which corresponds to the
834-
// supply pre-commitment output.
835-
//
836-
// Construct the expected pre-commit tx out.
837-
expectedTxOut, err := tapgarden.PreCommitTxOut(delegationKey)
838-
if err != nil {
839-
return zero, fmt.Errorf("unable to derive expected pre-commit "+
840-
"txout: %w", err)
841-
}
842-
843-
var preCommitTxOutIndex int32 = -1
844-
for idx := range issuanceProof.AnchorTx.TxOut {
845-
txOut := *issuanceProof.AnchorTx.TxOut[idx]
846-
847-
// Compare txOut to the expected pre-commit tx out.
848-
isValueEqual := txOut.Value == expectedTxOut.Value
849-
isPkScriptEqual := bytes.Equal(
850-
txOut.PkScript, expectedTxOut.PkScript,
851-
)
852-
853-
if isValueEqual && isPkScriptEqual {
854-
preCommitTxOutIndex = int32(idx)
855-
}
856-
}
857-
858-
// If we didn't find the pre-commit tx out, then return an error.
859-
if preCommitTxOutIndex == -1 {
860-
return zero, fmt.Errorf("unable to find pre-commit tx out in " +
861-
"issuance anchor tx")
862-
}
863-
864-
// Calculate the outpoint of the supply pre-commitment.
865-
return supplycommit.PreCommitment{
866-
BlockHeight: issuanceProof.BlockHeight,
867-
MintingTxn: &issuanceProof.AnchorTx,
868-
OutIdx: uint32(preCommitTxOutIndex),
869-
InternalKey: keychain.KeyDescriptor{
870-
PubKey: &delegationKey,
871-
},
872-
GroupPubKey: issuanceProof.Asset.GroupKey.GroupPubKey,
873-
}, nil
874-
}

0 commit comments

Comments
 (0)