Skip to content

Commit

Permalink
multi: remove output type for passive asset
Browse files Browse the repository at this point in the history
With the passive assets now being treated exactly like any active asset
virtual transaction, we no longer need the special output types that
were added just for marking where to anchor the passive assets.
  • Loading branch information
guggero committed Feb 19, 2024
1 parent 139378f commit c22283d
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 298 deletions.
9 changes: 0 additions & 9 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2494,15 +2494,6 @@ func marshalOutputType(outputType tappsbt.VOutputType) (taprpc.OutputType,
case tappsbt.TypeSplitRoot:
return taprpc.OutputType_OUTPUT_TYPE_SPLIT_ROOT, nil

case tappsbt.TypePassiveAssetsOnly:
return taprpc.OutputType_OUTPUT_TYPE_PASSIVE_ASSETS_ONLY, nil

case tappsbt.TypePassiveSplitRoot:
return taprpc.OutputType_OUTPUT_TYPE_PASSIVE_SPLIT_ROOT, nil

case tappsbt.TypeSimplePassiveAssets:
return taprpc.OutputType_OUTPUT_TYPE_SIMPLE_PASSIVE_ASSETS, nil

default:
return 0, fmt.Errorf("unknown output type: %d", outputType)
}
Expand Down
4 changes: 1 addition & 3 deletions tapdb/assets_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2632,9 +2632,7 @@ func (a *AssetStore) ConfirmParcelDelivery(ctx context.Context,
isNumsKey := scriptPubKey.IsEqual(asset.NUMSPubKey)
isTombstone := isNumsKey &&
out.Amount == 0 &&
out.OutputType != int16(
tappsbt.TypePassiveAssetsOnly,
)
out.OutputType == int16(tappsbt.TypeSplitRoot)
isBurn := !isNumsKey && len(witnessData) > 0 &&
asset.IsBurnKey(scriptPubKey, witnessData[0])

Expand Down
7 changes: 0 additions & 7 deletions tapfreighter/chain_porter.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,6 @@ func (p *ChainPorter) storeProofs(sendPkg *sendPackage) error {
for idx := range parcel.Outputs {
out := parcel.Outputs[idx]

// For outputs without assets (=anchor for passive assets), we
// don't need to store explicit proofs, they were created and
// imported above.
if out.Type == tappsbt.TypePassiveAssetsOnly {
continue
}

parsedSuffix := &proof.Proof{}
err := parsedSuffix.Decode(bytes.NewReader(out.ProofSuffix))
if err != nil {
Expand Down
76 changes: 1 addition & 75 deletions tappsbt/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@ var (
return o.Type.IsSplitRoot()
}

// VOutCanCarryPassive is a predicate that returns true if the virtual
// output can carry passive assets.
VOutCanCarryPassive = func(o *VOutput) bool {
return o.Type.CanCarryPassive()
}

// VOutIsNotSplitRoot is a predicate that returns true if the virtual
// output is NOT a split root output.
VOutIsNotSplitRoot = func(o *VOutput) bool {
Expand Down Expand Up @@ -227,18 +221,6 @@ func (p *VPacket) SplitRootOutput() (*VOutput, error) {
return fn.First(p.Outputs, VOutIsSplitRoot)
}

// PassiveAssetsOutput returns the output in the virtual transaction that can
// carry passive assets, or an error if there is none or more than one.
func (p *VPacket) PassiveAssetsOutput() (*VOutput, error) {
count := fn.Count(p.Outputs, VOutCanCarryPassive)
if count != 1 {
return nil, fmt.Errorf("expected 1 passive assets carrier "+
"output, got %d", count)
}

return fn.First(p.Outputs, VOutCanCarryPassive)
}

// FirstNonSplitRootOutput returns the first non-change output in the virtual
// transaction.
func (p *VPacket) FirstNonSplitRootOutput() (*VOutput, error) {
Expand Down Expand Up @@ -401,59 +383,12 @@ const (
// split or a tombstone from a non-interactive full value send output.
// In either case, the asset of this output has a tx witness.
TypeSplitRoot VOutputType = 1

// TypePassiveAssetsOnly indicates that this output only carries passive
// assets and therefore the asset in this output is nil. The passive
// assets themselves are signed in their own virtual transactions and
// are not present in this packet.
TypePassiveAssetsOnly VOutputType = 2

// TypePassiveSplitRoot is a split root output that carries the change
// from a split or a tombstone from a non-interactive full value send
// output, as well as passive assets.
TypePassiveSplitRoot VOutputType = 3

// TypeSimplePassiveAssets is a plain full-value interactive send output
// that also carries passive assets. This is a special case where we
// send the full value of a single asset in a commitment to a new script
// key, but also carry passive assets in the same output. This is useful
// for key rotation (send-to-self) scenarios or asset burns where we
// burn the full supply of a single asset within a commitment.
TypeSimplePassiveAssets VOutputType = 4
)

// IsSplitRoot returns true if the output type is a split root, indicating that
// the asset has a tx witness instead of a split witness.
func (t VOutputType) IsSplitRoot() bool {
return t == TypeSplitRoot || t == TypePassiveSplitRoot
}

// CanBeInteractive returns true if the output type is compatible with being an
// interactive send.
func (t VOutputType) CanBeInteractive() bool {
switch t {
case TypeSimple, TypeSplitRoot, TypePassiveAssetsOnly,
TypePassiveSplitRoot, TypeSimplePassiveAssets:

return true

default:
return false
}
}

// CanCarryPassive returns true if the output type is compatible with carrying
// passive assets.
func (t VOutputType) CanCarryPassive() bool {
switch t {
case TypePassiveAssetsOnly, TypePassiveSplitRoot,
TypeSimplePassiveAssets:

return true

default:
return false
}
return t == TypeSplitRoot
}

// String returns a human-readable string representation of the output type.
Expand All @@ -465,15 +400,6 @@ func (t VOutputType) String() string {
case TypeSplitRoot:
return "split_root"

case TypePassiveAssetsOnly:
return "passive_assets_only"

case TypePassiveSplitRoot:
return "passive_split_root"

case TypeSimplePassiveAssets:
return "simple_passive_assets"

default:
return fmt.Sprintf("unknown <%d>", t)
}
Expand Down
7 changes: 2 additions & 5 deletions taprpc/assetwalletrpc/assetwallet.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -685,13 +685,10 @@
"type": "string",
"enum": [
"OUTPUT_TYPE_SIMPLE",
"OUTPUT_TYPE_SPLIT_ROOT",
"OUTPUT_TYPE_PASSIVE_ASSETS_ONLY",
"OUTPUT_TYPE_PASSIVE_SPLIT_ROOT",
"OUTPUT_TYPE_SIMPLE_PASSIVE_ASSETS"
"OUTPUT_TYPE_SPLIT_ROOT"
],
"default": "OUTPUT_TYPE_SIMPLE",
"description": " - OUTPUT_TYPE_SIMPLE: OUTPUT_TYPE_SIMPLE is a plain full-value or split output that is not a\nsplit root and does not carry passive assets. In case of a split, the\nasset of this output has a split commitment.\n - OUTPUT_TYPE_SPLIT_ROOT: OUTPUT_TYPE_SPLIT_ROOT is a split root output that carries the change\nfrom a split or a tombstone from a non-interactive full value send\noutput. In either case, the asset of this output has a tx witness.\n - OUTPUT_TYPE_PASSIVE_ASSETS_ONLY: OUTPUT_TYPE_PASSIVE_ASSETS_ONLY indicates that this output only carries\npassive assets and therefore the asset in this output is nil. The passive\nassets themselves are signed in their own virtual transactions and\nare not present in this packet.\n - OUTPUT_TYPE_PASSIVE_SPLIT_ROOT: OUTPUT_TYPE_PASSIVE_SPLIT_ROOT is a split root output that carries the\nchange from a split or a tombstone from a non-interactive full value send\noutput, as well as passive assets.\n - OUTPUT_TYPE_SIMPLE_PASSIVE_ASSETS: OUTPUT_TYPE_SIMPLE_PASSIVE_ASSETS is a plain full-value interactive send\noutput that also carries passive assets. This is a special case where we\nsend the full value of a single asset in a commitment to a new script\nkey, but also carry passive assets in the same output. This is useful for\nkey rotation (send-to-self) scenarios or asset burns where we burn the\nfull supply of a single asset within a commitment."
"description": " - OUTPUT_TYPE_SIMPLE: OUTPUT_TYPE_SIMPLE is a plain full-value or split output that is not a\nsplit root and does not carry passive assets. In case of a split, the\nasset of this output has a split commitment.\n - OUTPUT_TYPE_SPLIT_ROOT: OUTPUT_TYPE_SPLIT_ROOT is a split root output that carries the change\nfrom a split or a tombstone from a non-interactive full value send\noutput. In either case, the asset of this output has a tx witness."
},
"taprpcScriptKey": {
"type": "object",
Expand Down
Loading

0 comments on commit c22283d

Please sign in to comment.