neo-go/pkg/core/native/interop.go

35 lines
778 B
Go
Raw Normal View History

2020-03-19 15:52:37 +00:00
package native
import (
"errors"
"fmt"
2020-03-19 15:52:37 +00:00
"github.com/nspcc-dev/neo-go/pkg/core/interop"
"github.com/nspcc-dev/neo-go/pkg/core/state"
2020-03-19 15:52:37 +00:00
"github.com/nspcc-dev/neo-go/pkg/vm"
)
// Deploy deploys native contract.
func Deploy(ic *interop.Context, _ *vm.VM) error {
if ic.Block == nil || ic.Block.Index != 0 {
2020-03-19 15:52:37 +00:00
return errors.New("native contracts can be deployed only at 0 block")
}
for _, native := range ic.Natives {
md := native.Metadata()
cs := &state.Contract{
2020-06-09 09:12:56 +00:00
ID: md.ContractID,
Script: md.Script,
Manifest: md.Manifest,
}
if err := ic.DAO.PutContractState(cs); err != nil {
return err
}
if err := native.Initialize(ic); err != nil {
return fmt.Errorf("initializing %s native contract: %v", md.ServiceName, err)
}
}
2020-03-19 15:52:37 +00:00
return nil
}