2021-12-06 14:58:53 +00:00
|
|
|
package vm
|
|
|
|
|
|
|
|
import (
|
2022-01-18 10:20:35 +00:00
|
|
|
"fmt"
|
|
|
|
|
2021-12-06 14:58:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/common"
|
2022-01-18 10:20:35 +00:00
|
|
|
"github.com/ledgerwatch/erigon/crypto"
|
2021-12-06 14:58:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func NewCVM(state IntraBlockState) *CVM {
|
|
|
|
cvm := &CVM{
|
|
|
|
intraBlockState: state,
|
|
|
|
}
|
|
|
|
|
|
|
|
return cvm
|
|
|
|
}
|
|
|
|
|
|
|
|
type CVM struct {
|
|
|
|
config Config
|
|
|
|
intraBlockState IntraBlockState
|
|
|
|
}
|
|
|
|
|
2022-01-18 10:20:35 +00:00
|
|
|
func (cvm *CVM) Create(caller ContractRef, code []byte) ([]byte, common.Address, error) {
|
|
|
|
address := crypto.CreateAddress(caller.Address(), cvm.intraBlockState.GetNonce(caller.Address()))
|
2021-12-06 14:58:53 +00:00
|
|
|
cvm.intraBlockState.SetCode(address, code)
|
2022-01-18 10:20:35 +00:00
|
|
|
fmt.Println(">>>> Create Starknet Contract", address.Hex())
|
2021-12-06 14:58:53 +00:00
|
|
|
return code, common.Address{}, nil
|
|
|
|
|
|
|
|
//TODO:: execute cairo construct
|
|
|
|
//ret, err := cvm.run(code)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cvm *CVM) Config() Config {
|
|
|
|
return cvm.config
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cvm *CVM) IntraBlockState() IntraBlockState {
|
|
|
|
return cvm.intraBlockState
|
|
|
|
}
|
|
|
|
|
|
|
|
//func (cvm *CVM) run(code []byte) ([]byte, error) {
|
|
|
|
// // TODO:: call grpc cairo
|
|
|
|
// return code, nil
|
|
|
|
//}
|