Skip to content

Commit 2c3b072

Browse files
committed
tapfreighter: add method ShouldDeliverProof to struct TransferOutput
ShouldDeliverProof returns true if a proof corresponding to the subject transfer output should be delivered to a peer.
1 parent 6162e05 commit 2c3b072

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tapfreighter/interface.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,48 @@ type TransferOutput struct {
248248
ProofCourierAddr []byte
249249
}
250250

251+
// ShouldDeliverProof returns true if a proof corresponding to the subject
252+
// transfer output should be delivered to a peer.
253+
func (out *TransferOutput) ShouldDeliverProof() (bool, error) {
254+
// If the proof courier address is unspecified, we don't need to deliver
255+
// a proof.
256+
if len(out.ProofCourierAddr) == 0 {
257+
return false, nil
258+
}
259+
260+
// The proof courier address may have been specified in error, in which
261+
// case we will conduct further checks to determine if a proof should be
262+
// delivered.
263+
//
264+
// If the script key is un-spendable, we don't need to deliver a proof.
265+
unSpendable, err := out.ScriptKey.IsUnSpendable()
266+
if err != nil {
267+
return false, fmt.Errorf("error checking if script key is "+
268+
"unspendable: %w", err)
269+
}
270+
271+
if unSpendable {
272+
return false, nil
273+
}
274+
275+
// If this is an output that is going to our own node/wallet, we don't
276+
// need to deliver a proof.
277+
if out.ScriptKey.TweakedScriptKey != nil && out.ScriptKeyLocal {
278+
return false, nil
279+
}
280+
281+
// If the script key is a burn key, we don't need to deliver a proof.
282+
if len(out.WitnessData) > 0 && asset.IsBurnKey(
283+
out.ScriptKey.PubKey, out.WitnessData[0],
284+
) {
285+
286+
return false, nil
287+
}
288+
289+
// At this point, we should deliver a proof.
290+
return true, nil
291+
}
292+
251293
// OutboundParcel represents the database level delta of an outbound Taproot
252294
// Asset parcel (outbound spend). A spend will destroy a series of assets listed
253295
// as inputs, and re-create them as new outputs. Along the way some assets may

0 commit comments

Comments
 (0)