Skip to content

Commit e9d725b

Browse files
authored
feat: TxSubmission MsgDone callback support (#1072)
Fixes #1071 Signed-off-by: Aurora Gaffney <[email protected]>
1 parent 68c9953 commit e9d725b

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

protocol/txsubmission/server.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ func (s *Server) handleDone() error {
207207
"role", "server",
208208
"connection_id", s.callbackContext.ConnectionId.String(),
209209
)
210+
// Call the user callback function
211+
if s.config != nil && s.config.DoneFunc != nil {
212+
if err := s.config.DoneFunc(s.callbackContext); err != nil {
213+
return err
214+
}
215+
}
210216
// Restart protocol
211217
s.Stop()
212218
s.initProtocol()

protocol/txsubmission/txsubmission.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ type Config struct {
122122
RequestTxIdsFunc RequestTxIdsFunc
123123
RequestTxsFunc RequestTxsFunc
124124
InitFunc InitFunc
125+
DoneFunc DoneFunc
125126
IdleTimeout time.Duration
126127
}
127128

@@ -137,6 +138,7 @@ type (
137138
RequestTxIdsFunc func(CallbackContext, bool, uint16, uint16) ([]TxIdAndSize, error)
138139
RequestTxsFunc func(CallbackContext, []TxId) ([]TxBody, error)
139140
InitFunc func(CallbackContext) error
141+
DoneFunc func(CallbackContext) error
140142
)
141143

142144
// New returns a new TxSubmission object
@@ -186,6 +188,13 @@ func WithInitFunc(initFunc InitFunc) TxSubmissionOptionFunc {
186188
}
187189
}
188190

191+
// WithDoneFunc specifies the Done callback function
192+
func WithDoneFunc(doneFunc DoneFunc) TxSubmissionOptionFunc {
193+
return func(c *Config) {
194+
c.DoneFunc = doneFunc
195+
}
196+
}
197+
189198
// WithIdleTimeout specifies the timeout for waiting for new transactions from the remote node's mempool
190199
func WithIdleTimeout(timeout time.Duration) TxSubmissionOptionFunc {
191200
return func(c *Config) {

0 commit comments

Comments
 (0)