Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store transfer output proof delivery status #1035

Merged
merged 7 commits into from
Jul 29, 2024
42 changes: 42 additions & 0 deletions tapfreighter/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,48 @@ type TransferOutput struct {
ProofCourierAddr []byte
}

// ShouldDeliverProof returns true if a proof corresponding to the subject
// transfer output should be delivered to a peer.
func (out *TransferOutput) ShouldDeliverProof() (bool, error) {
// If the proof courier address is unspecified, we don't need to deliver
// a proof.
if len(out.ProofCourierAddr) == 0 {
return false, nil
}

// The proof courier address may have been specified in error, in which
// case we will conduct further checks to determine if a proof should be
// delivered.
//
// If the script key is un-spendable, we don't need to deliver a proof.
unSpendable, err := out.ScriptKey.IsUnSpendable()
if err != nil {
return false, fmt.Errorf("error checking if script key is "+
"unspendable: %w", err)
}

if unSpendable {
return false, nil
}

// If this is an output that is going to our own node/wallet, we don't
// need to deliver a proof.
if out.ScriptKey.TweakedScriptKey != nil && out.ScriptKeyLocal {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should double check this with some of the litd itests we have for channels. At times, we verify that a proof was uploaded even if it was a local script key.

return false, nil
}

// If the script key is a burn key, we don't need to deliver a proof.
if len(out.WitnessData) > 0 && asset.IsBurnKey(
out.ScriptKey.PubKey, out.WitnessData[0],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't burns still relevant? So to proof to someone that you've burnt an asset.

) {

return false, nil
}

// At this point, we should deliver a proof.
return true, nil
}

// OutboundParcel represents the database level delta of an outbound Taproot
// Asset parcel (outbound spend). A spend will destroy a series of assets listed
// as inputs, and re-create them as new outputs. Along the way some assets may
Expand Down