-
Notifications
You must be signed in to change notification settings - Fork 199
/
vmContainerFactory.go
76 lines (64 loc) · 2.22 KB
/
vmContainerFactory.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package shard
import (
arwen "github.com/ElrondNetwork/arwen-wasm-vm/arwen/context"
"github.com/ElrondNetwork/elrond-go/process"
"github.com/ElrondNetwork/elrond-go/process/factory"
"github.com/ElrondNetwork/elrond-go/process/factory/containers"
"github.com/ElrondNetwork/elrond-go/process/smartContract/hooks"
vmcommon "github.com/ElrondNetwork/elrond-vm-common"
)
type vmContainerFactory struct {
blockChainHookImpl *hooks.BlockChainHookImpl
cryptoHook vmcommon.CryptoHook
blockGasLimit uint64
gasSchedule map[string]map[string]uint64
}
// NewVMContainerFactory is responsible for creating a new virtual machine factory object
func NewVMContainerFactory(
blockGasLimit uint64,
gasSchedule map[string]map[string]uint64,
argBlockChainHook hooks.ArgBlockChainHook,
) (*vmContainerFactory, error) {
if gasSchedule == nil {
return nil, process.ErrNilGasSchedule
}
blockChainHookImpl, err := hooks.NewBlockChainHookImpl(argBlockChainHook)
if err != nil {
return nil, err
}
cryptoHook := hooks.NewVMCryptoHook()
return &vmContainerFactory{
blockChainHookImpl: blockChainHookImpl,
cryptoHook: cryptoHook,
blockGasLimit: blockGasLimit,
gasSchedule: gasSchedule,
}, nil
}
// Create sets up all the needed virtual machine returning a container of all the VMs
func (vmf *vmContainerFactory) Create() (process.VirtualMachinesContainer, error) {
container := containers.NewVirtualMachinesContainer()
currVm, err := vmf.createArwenVM()
if err != nil {
return nil, err
}
err = container.Add(factory.ArwenVirtualMachine, currVm)
if err != nil {
return nil, err
}
return container, nil
}
func (vmf *vmContainerFactory) createArwenVM() (vmcommon.VMExecutionHandler, error) {
arwenVM, err := arwen.NewArwenVM(vmf.blockChainHookImpl, vmf.cryptoHook, factory.ArwenVirtualMachine, vmf.blockGasLimit, vmf.gasSchedule)
return arwenVM, err
}
// BlockChainHookImpl returns the created blockChainHookImpl
func (vmf *vmContainerFactory) BlockChainHookImpl() process.BlockChainHookHandler {
return vmf.blockChainHookImpl
}
// IsInterfaceNil returns true if there is no value under the interface
func (vmf *vmContainerFactory) IsInterfaceNil() bool {
if vmf == nil {
return true
}
return false
}