github.com/koko1123/flow-go-1@v0.29.6/fvm/environment/runtime.go (about)

     1  package environment
     2  
     3  import (
     4  	cadenceRuntime "github.com/onflow/cadence/runtime"
     5  
     6  	"github.com/koko1123/flow-go-1/fvm/runtime"
     7  )
     8  
     9  type RuntimeParams struct {
    10  	runtime.ReusableCadenceRuntimePool
    11  }
    12  
    13  func DefaultRuntimeParams() RuntimeParams {
    14  	return RuntimeParams{
    15  		ReusableCadenceRuntimePool: runtime.NewReusableCadenceRuntimePool(
    16  			0,
    17  			cadenceRuntime.Config{}),
    18  	}
    19  }
    20  
    21  // Runtime expose the cadence runtime to the rest of the envionment package.
    22  type Runtime struct {
    23  	RuntimeParams
    24  
    25  	env Environment
    26  }
    27  
    28  func NewRuntime(params RuntimeParams) *Runtime {
    29  	return &Runtime{
    30  		RuntimeParams: params,
    31  	}
    32  }
    33  
    34  func (runtime *Runtime) SetEnvironment(env Environment) {
    35  	runtime.env = env
    36  }
    37  
    38  func (runtime *Runtime) BorrowCadenceRuntime() *runtime.ReusableCadenceRuntime {
    39  	return runtime.ReusableCadenceRuntimePool.Borrow(runtime.env)
    40  }
    41  
    42  func (runtime *Runtime) ReturnCadenceRuntime(
    43  	reusable *runtime.ReusableCadenceRuntime,
    44  ) {
    45  	runtime.ReusableCadenceRuntimePool.Return(reusable)
    46  }