Skip to content

Commit ed0a8a1

Browse files
committed
tapfreighter: set type for burn/tombstone keys correctly
In order for burn/tombstone keys to be stored with the correct type, we need to detect them before storing the transfer outputs to the database. We can't set the script key type before, because we're carrying around the script key in a virtual packet, where that information isn't available.
1 parent 83ffab4 commit ed0a8a1

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

tapfreighter/chain_porter.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,6 +1723,46 @@ func (p *ChainPorter) publishSubscriberEvent(event fn.Event) {
17231723
}
17241724
}
17251725

1726+
// detectUnSpendableKeys checks if the script key in the virtual output is a
1727+
// burn or tombstone key and sets the appropriate type on the output script key.
1728+
func detectUnSpendableKeys(vOut *tappsbt.VOutput) {
1729+
setScriptKeyType := func(vOut *tappsbt.VOutput,
1730+
scriptKeyType asset.ScriptKeyType) {
1731+
1732+
if vOut.Asset.ScriptKey.TweakedScriptKey == nil {
1733+
vOut.Asset.ScriptKey.TweakedScriptKey = new(
1734+
asset.TweakedScriptKey,
1735+
)
1736+
vOut.Asset.ScriptKey.RawKey.PubKey =
1737+
vOut.Asset.ScriptKey.PubKey
1738+
}
1739+
if vOut.ScriptKey.TweakedScriptKey == nil {
1740+
vOut.ScriptKey.TweakedScriptKey = new(
1741+
asset.TweakedScriptKey,
1742+
)
1743+
vOut.ScriptKey.RawKey.PubKey = vOut.ScriptKey.PubKey
1744+
}
1745+
1746+
vOut.Asset.ScriptKey.Type = scriptKeyType
1747+
vOut.ScriptKey.Type = scriptKeyType
1748+
}
1749+
1750+
if vOut.Asset == nil {
1751+
return
1752+
}
1753+
1754+
witness := vOut.Asset.PrevWitnesses
1755+
scriptKey := vOut.ScriptKey
1756+
if len(witness) > 0 && asset.IsBurnKey(scriptKey.PubKey, witness[0]) {
1757+
setScriptKeyType(vOut, asset.ScriptKeyBurn)
1758+
}
1759+
1760+
unSpendable, _ := scriptKey.IsUnSpendable()
1761+
if unSpendable {
1762+
setScriptKeyType(vOut, asset.ScriptKeyTombstone)
1763+
}
1764+
}
1765+
17261766
// A compile-time assertion to make sure ChainPorter satisfies the
17271767
// fn.EventPublisher interface.
17281768
var _ fn.EventPublisher[fn.Event, bool] = (*ChainPorter)(nil)

tapfreighter/parcel.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,13 @@ func ConvertToTransfer(currentHeight uint32, activeTransfers []*tappsbt.VPacket,
589589
vPkt := activeTransfers[pIdx]
590590

591591
for vPktOutputIdx := range vPkt.Outputs {
592+
// Burn and tombstone keys are the only keys that we
593+
// don't explicitly store in the DB before this point.
594+
// But we'll want them to have the correct type when
595+
// creating the transfer, as they'll be inserted into
596+
// the DB, assigned to this transfer.
597+
detectUnSpendableKeys(vPkt.Outputs[vPktOutputIdx])
598+
592599
tOut, err := transferOutput(
593600
vPkt, vPktOutputIdx, outputPosition, anchorTx,
594601
passiveAssets, isLocalKey,

0 commit comments

Comments
 (0)