From 18b7584cb49363447075d4486eb6dd64ec0aa0ae Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Mon, 8 Feb 2021 13:09:28 +0300 Subject: [PATCH] compiler/interop: add Manifest to Contract struct --- pkg/compiler/native_test.go | 16 +++++ pkg/interop/native/management/contract.go | 71 +++++++++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/pkg/compiler/native_test.go b/pkg/compiler/native_test.go index 5aafd6208..d964ecfc0 100644 --- a/pkg/compiler/native_test.go +++ b/pkg/compiler/native_test.go @@ -48,6 +48,22 @@ func testPrintHash(u util.Uint160) { fmt.Println(`"`) } +func TestContractParameterTypes(t *testing.T) { + require.EqualValues(t, management.AnyType, smartcontract.AnyType) + require.EqualValues(t, management.BoolType, smartcontract.BoolType) + require.EqualValues(t, management.IntegerType, smartcontract.IntegerType) + require.EqualValues(t, management.ByteArrayType, smartcontract.ByteArrayType) + require.EqualValues(t, management.StringType, smartcontract.StringType) + require.EqualValues(t, management.Hash160Type, smartcontract.Hash160Type) + require.EqualValues(t, management.Hash256Type, smartcontract.Hash256Type) + require.EqualValues(t, management.PublicKeyType, smartcontract.PublicKeyType) + require.EqualValues(t, management.SignatureType, smartcontract.SignatureType) + require.EqualValues(t, management.ArrayType, smartcontract.ArrayType) + require.EqualValues(t, management.MapType, smartcontract.MapType) + require.EqualValues(t, management.InteropInterfaceType, smartcontract.InteropInterfaceType) + require.EqualValues(t, management.VoidType, smartcontract.VoidType) +} + func TestRoleManagementRole(t *testing.T) { require.EqualValues(t, native.RoleOracle, roles.Oracle) require.EqualValues(t, native.RoleStateValidator, roles.StateValidator) diff --git a/pkg/interop/native/management/contract.go b/pkg/interop/native/management/contract.go index 01aae529e..415cf3984 100644 --- a/pkg/interop/native/management/contract.go +++ b/pkg/interop/native/management/contract.go @@ -8,4 +8,75 @@ type Contract struct { UpdateCounter int Hash interop.Hash160 NEF []byte + Manifest Manifest +} + +// ParameterType represents smartcontract parameter type. +type ParameterType byte + +// Various parameter types. +const ( + AnyType ParameterType = 0x00 + BoolType ParameterType = 0x10 + IntegerType ParameterType = 0x11 + ByteArrayType ParameterType = 0x12 + StringType ParameterType = 0x13 + Hash160Type ParameterType = 0x14 + Hash256Type ParameterType = 0x15 + PublicKeyType ParameterType = 0x16 + SignatureType ParameterType = 0x17 + ArrayType ParameterType = 0x20 + MapType ParameterType = 0x22 + InteropInterfaceType ParameterType = 0x30 + VoidType ParameterType = 0xff +) + +// Manifest represents contract's manifest. +type Manifest struct { + Name string + Groups []Group + SupportedStandards []string + ABI ABI + Permissions []Permission + Trusts []interop.Hash160 + Extra interface{} +} + +// ABI represents contract's ABI. +type ABI struct { + Methods []Method + Events []Event +} + +// Method represents contract method. +type Method struct { + Name string + Params []Parameter + ReturnType ParameterType + Offset int + Safe bool +} + +// Event represents contract event. +type Event struct { + Name string + Params []Parameter +} + +// Parameter represents method parameter. +type Parameter struct { + Name string + Type ParameterType +} + +// Permission represents contract permission. +type Permission struct { + Contract interop.Hash160 + Methods []string +} + +// Group represents manifest group. +type Group struct { + PublicKey interop.PublicKey + Signature interop.Signature }