Skip to content

Commit 2dc4fb9

Browse files
committed
protofsm: add option to allow conf resp to return full back
In this commit, we add an option to allow a conf req caller to receive the full block. This is useful if the caller wants to be able to create an SPV proof.
1 parent 234949c commit 2dc4fb9

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

protofsm/daemon_events.go

+5
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ type RegisterConf[Event any] struct {
116116
// transaction needs to dispatch an event.
117117
NumConfs fn.Option[uint32]
118118

119+
// FullBlock is a boolean that indicates whether we want the full block
120+
// in the returned response. This is useful if callers want to create an
121+
// SPV proof for the transaction post conf.
122+
FullBlock bool
123+
119124
// PostConfMapper is a special conf mapper, that if present, will be
120125
// used to map the protofsm confirmation event to a custom event.
121126
PostConfMapper fn.Option[ConfMapper[Event]]

protofsm/state_machine.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ type DaemonAdapters interface {
104104
// TODO(roasbeef): could abstract further?
105105
RegisterConfirmationsNtfn(txid *chainhash.Hash, pkScript []byte,
106106
numConfs, heightHint uint32,
107-
opts ...chainntnfs.NotifierOption,
108-
) (*chainntnfs.ConfirmationEvent, error)
107+
opts ...chainntnfs.NotifierOption) (*chainntnfs.ConfirmationEvent, error)
109108

110109
// RegisterSpendNtfn registers an intent to be notified once the target
111110
// outpoint is successfully spent within a transaction. The script that
@@ -494,10 +493,15 @@ func (s *StateMachine[Event, Env]) executeDaemonEvent(ctx context.Context,
494493
s.log.DebugS(ctx, "Registering conf",
495494
"txid", daemonEvent.Txid)
496495

496+
var opts []chainntnfs.NotifierOption
497+
if daemonEvent.FullBlock {
498+
opts = append(opts, chainntnfs.WithIncludeBlock())
499+
}
500+
497501
numConfs := daemonEvent.NumConfs.UnwrapOr(1)
498502
confEvent, err := s.cfg.Daemon.RegisterConfirmationsNtfn(
499503
&daemonEvent.Txid, daemonEvent.PkScript,
500-
numConfs, daemonEvent.HeightHint,
504+
numConfs, daemonEvent.HeightHint, opts...,
501505
)
502506
if err != nil {
503507
return fmt.Errorf("unable to register conf: %w", err)

0 commit comments

Comments
 (0)