un-expose hooks copy

This commit is contained in:
Sina Mahmoodi 2024-12-10 18:12:50 +01:00
parent de48d559ea
commit 9cae376df4
3 changed files with 6 additions and 4 deletions

View File

@ -207,8 +207,10 @@ type Hooks struct {
OnBlockHashRead BlockHashReadHook OnBlockHashRead BlockHashReadHook
} }
// Copy creates a new Hooks instance with all implemented hooks copied from the original. // copy creates a new Hooks instance with all implemented hooks copied from the original.
func (h *Hooks) Copy() *Hooks { // Note: it is not a deep copy. If a hook has been implemented as a closure and acts on
// a mutable state, the copied hook will still act on the same state.
func (h *Hooks) copy() *Hooks {
copied := &Hooks{} copied := &Hooks{}
srcValue := reflect.ValueOf(h).Elem() srcValue := reflect.ValueOf(h).Elem()
dstValue := reflect.ValueOf(copied).Elem() dstValue := reflect.ValueOf(copied).Elem()

View File

@ -62,7 +62,7 @@ func WrapWithJournal(hooks *Hooks) (*Hooks, error) {
} }
// Create a new Hooks instance and copy all hooks // Create a new Hooks instance and copy all hooks
wrapped := hooks.Copy() wrapped := hooks.copy()
// Create journal // Create journal
j := &journal{entries: make([]entry, 0), hooks: hooks} j := &journal{entries: make([]entry, 0), hooks: hooks}
// Scope hooks need to be re-implemented. // Scope hooks need to be re-implemented.

View File

@ -179,7 +179,7 @@ func TestAllHooksCalled(t *testing.T) {
continue continue
} }
// Skip non-hooks, i.e. Copy // Skip non-hooks, i.e. Copy
if field.Name == "Copy" { if field.Name == "copy" {
continue continue
} }