Skip to content

Commit c431c33

Browse files
committed
tapfreighter: set type for burn keys correctly
In order for burn 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 13eddb8 commit c431c33

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tapfreighter/chain_porter.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,12 @@ func (p *ChainPorter) stateStep(currentPkg sendPackage) (*sendPackage, error) {
12961296
"%w", err)
12971297
}
12981298

1299+
// Burn keys are the only keys that we don't explicitly store
1300+
// in the DB before this point. But we'll want them to have the
1301+
// correct type when creating the transfer, so we'll set that
1302+
// now.
1303+
detectBurnKeys(currentPkg.VirtualPackets)
1304+
12991305
// We now need to find out if this is a transfer to ourselves
13001306
// (e.g. a change output) or an outbound transfer. A key being
13011307
// local means the lnd node connected to this daemon knows how
@@ -1567,6 +1573,26 @@ func (p *ChainPorter) publishSubscriberEvent(event fn.Event) {
15671573
}
15681574
}
15691575

1576+
// detectBurnKeys checks if any of the outputs in the virtual packets are burn
1577+
// keys and sets the appropriate type on the output script key.
1578+
func detectBurnKeys(activeTransfers []*tappsbt.VPacket) {
1579+
for _, vPkt := range activeTransfers {
1580+
for _, vOut := range vPkt.Outputs {
1581+
if vOut.Asset == nil {
1582+
continue
1583+
}
1584+
1585+
witness := vOut.Asset.PrevWitnesses
1586+
if len(witness) > 0 && asset.IsBurnKey(
1587+
vOut.ScriptKey.PubKey, witness[0],
1588+
) {
1589+
vOut.Asset.ScriptKey.Type = asset.ScriptKeyBurn
1590+
vOut.ScriptKey.Type = asset.ScriptKeyBurn
1591+
}
1592+
}
1593+
}
1594+
}
1595+
15701596
// A compile-time assertion to make sure ChainPorter satisfies the
15711597
// fn.EventPublisher interface.
15721598
var _ fn.EventPublisher[fn.Event, bool] = (*ChainPorter)(nil)

0 commit comments

Comments
 (0)