mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-27 03:58:06 +00:00
30836ca69b
The notion of NativeContractState shouldn't ever existed, native contract is a contract and its state is saved as regular contract state which is critical because we'll have MPT calculations over this state soon. Initial minting should be done in Neo.Native.Deploy because it generates notification that should have proper transaction context. RegisterNative() shouldn't exist as a public method, native contracts are only registered at block 0 and they can do it internally, no outside user should be able to mess with it. Move some structures from `native` package to `interop` also to avoid circular references as interop.Context has to have a list of native contracts (exposing them via Blockchainer is again too dangerous, it's too powerful tool).
24 lines
534 B
Go
24 lines
534 B
Go
package native
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
|
"github.com/nspcc-dev/neo-go/pkg/vm"
|
|
)
|
|
|
|
// Deploy deploys native contract.
|
|
func Deploy(ic *interop.Context, _ *vm.VM) error {
|
|
if ic.Block.Index != 0 {
|
|
return errors.New("native contracts can be deployed only at 0 block")
|
|
}
|
|
|
|
for _, native := range ic.Natives {
|
|
if err := native.Initialize(ic); err != nil {
|
|
md := native.Metadata()
|
|
return fmt.Errorf("initializing %s native contract: %v", md.ServiceName, err)
|
|
}
|
|
}
|
|
return nil
|
|
}
|