• Matthew Slipper's avatar
    Add broadcast API to Go forge scripts (#11826) · 219ebe00
    Matthew Slipper authored
    * Add broadcast API to Go forge scripts
    
    Adds a hooks-based API to collect transactions broadcasted via `vm.broadcast(*)` in the Go-based Forge scripts. Users pass an `OnBroadcast` hook to the host, which will be called with a `Broadcast` struct with the following fields whenever a transaction needs to be emitted:
    
    ```go
    type Broadcast struct {
    	From     common.Address
    	To       common.Address
    	Calldata []byte
    	Value    *big.Int
    }
    ```
    
    This API lets us layer on custom transaction management in the future which will be helpful for `op-deployer`.
    
    As part of this PR, I changed the internal `callStack` data structure to contain pointers to `CallFrame`s rather than passing by value. I discovered a bug where the pranked sender was not being cleared in subsequent calls due to an ineffectual assignment error. I took a look at the implementation and there are many places where assignments to call frames within the stack happen after converting the value to a reference, so converting the stack to store pointers in the first place both simplified the code and eliminated a class of errors in the future. I updated the public API methods to return copies of the internal structs to prevent accidental mutation.
    
    * Code review updates
    
    * moar review updates
    
    * fix bug with staticcall
    219ebe00
ScriptExample.json 161 KB