Skip to content
module

neo3.contracts.manifest

NEP-15 contract manifest classes for describing smart contract access control.

Classes
  • ContractGroup Describes a set of mutually trusted contracts.
  • ContractManifest A description of a smart contract's abilities (callable methods & events) as well as a set of restrictionsdescribing what external contracts and methods are allowed to be called.
  • ContractPermission Describes a single set of outgoing call restrictions for a System.Contract.Call SYSCALL.It describes what other smart contracts the executing contract is allowed to call and what exact methods on the other contract are allowed to be called. This is enforced during runtime.
  • ContractPermissionDescriptor A restriction object that limits the smart contract's calling abilities. Enforced at runtime.
  • WildcardContainer An internal helper class for ContractManifest attributes.
class

neo3.contracts.manifest.ContractGroup(public_key, signature)

Bases
neo3.core.interfaces.IJson

Describes a set of mutually trusted contracts.

See Also

ContractManifest.

Methods
  • is_valid(contract_hash) (bool) Validate if the group has agreed on allowing the specific contract_hash.
  • to_json() (dict) Convert object into JSON representation.
  • from_json(json) (ContractGroup) Parse object out of JSON data.
classmethod

from_json(json) → ContractGroup

Parse object out of JSON data.

Parameters
  • json (dict) a dictionary.
Raises
  • KeyError if the data supplied does not contain the necessary keys.
  • ValueError if the signature length is not 64.
method

is_valid(contract_hash) → bool

Validate if the group has agreed on allowing the specific contract_hash.

method

to_json() → dict

Convert object into JSON representation.

class

neo3.contracts.manifest.ContractManifest(name=None)

Bases
neo3.core.serialization.ISerializable neo3.core.interfaces.IJson

A description of a smart contract's abilities (callable methods & events) as well as a set of restrictionsdescribing what external contracts and methods are allowed to be called.

For more information see: https://github.com/neo-project/proposals/blob/3e492ad05d9de97abb6524fb9a73714e2cdc5461/nep-15.mediawiki

Attributes
  • abi (ContractABI) https://github.com/neo-project/proposals/blob/d1f4e9e1a67d22a5755c45595121f80b0971ea64/nep-14.mediawiki
  • extra (Optional) Optional user defined data
  • groups (list) same group to invoke it.
  • name (str) Contract name
  • permissions (list) Permissions describe what external contract(s) and what method(s) on these are allowed to be invoked.
  • supported_standards (list) The list of NEP standards supported e.g. "NEP-3"
Methods
  • __len__() Return the length of the object in number of bytes.
  • can_call(target_contract_hash, target_manifest, target_method) (bool) Check if this contract is allowed to call target_method on target_contract.
  • contains_group(public_key) (bool) Check if group exists.
  • deserialize(reader) Deserialize the object from a binary stream.
  • is_valid(contract_hash) (bool) Validates the if any of the manifest groups signed the requesting contract_hash as permissive.
  • serialize(writer) Serialize the object into a binary stream.
  • to_array() (bytes) Serialize the object into a bytearray.
  • to_json() (dict) Convert object into JSON representation.
  • deserialize_from_bytes(data) (ISerializable_T) Parse data into an object instance.
  • from_file(path) Create object from a file.
  • from_json(json) Parse object out of JSON data.
method

__len__()

Return the length of the object in number of bytes.

method

can_call(target_contract_hash, target_manifest, target_method) → bool

Check if this contract is allowed to call target_method on target_contract.

method

contains_group(public_key)

Check if group exists.

Parameters
  • public_key (ECPoint) needle to search for.
Returns (bool)

True if found. False otherwise.

method

deserialize(reader)

Deserialize the object from a binary stream.

Parameters
  • reader (BinaryReader) instance.
classmethod

from_file(path)

Create object from a file.

Parameters
  • path (str) location of the file.
Raises
  • FileNotFoundError if the path is invalid.
  • ValueError if the file is not a valid ContractManifest.
classmethod

from_json(json)

Parse object out of JSON data.

Parameters
  • json (dict) a dictionary.

Raise: KeyError: if the data supplied does not contain the necessary keys. ValueError: if the manifest name property has an incorrect format. ValueError: if the manifest support standards contains an string.

method

is_valid(contract_hash) → bool

Validates the if any of the manifest groups signed the requesting contract_hash as permissive.

An example use-case is to allow creation and updating of smart contracts by a select group.

Parameters
  • contract_hash (UInt160) target contract hash.
method

serialize(writer)

Serialize the object into a binary stream.

Parameters
  • writer (BinaryWriter) instance.
method

to_json() → dict

Convert object into JSON representation.

classmethod

deserialize_from_bytes(data)

Parse data into an object instance.

Parameters
  • data (bytes | bytearray) hex escaped bytes.
Returns (ISerializable_T)

a deserialized instance of the class.

method

to_array() → bytes

Serialize the object into a bytearray.

class

neo3.contracts.manifest.ContractPermission(contract, methods)

Bases
neo3.core.interfaces.IJson

Describes a single set of outgoing call restrictions for a System.Contract.Call SYSCALL.It describes what other smart contracts the executing contract is allowed to call and what exact methods on the other contract are allowed to be called. This is enforced during runtime.

Example

Contract A (the executing contract) wants to call method x on Contract B. The runtime will query the manifestof Contract A and ask if this is allowed. The Manifest will search through its permissions (a list of ContractPermission objects) and ask if it is_allowed().

Methods
  • is_allowed(target_contract_hash, target_manifest, target_method) (bool) Return if it is allowed to call target_method on the target contract.
  • to_json() (dict) Convert object into JSON representation.
  • default_permissions() (ContractPermission) Construct a ContractPermission which allows any contract and any method to be called.
  • from_json(json) (ContractPermission) Parse object out of JSON data.
classmethod

default_permissions() → ContractPermission

Construct a ContractPermission which allows any contract and any method to be called.

classmethod

from_json(json) → ContractPermission

Parse object out of JSON data.

Parameters
  • json (dict) a dictionary.
Raises
  • KeyError if the data supplied does not contain the necessary keys.
  • ValueError if a method is zero length.
method

is_allowed(target_contract_hash, target_manifest, target_method) → bool

Return if it is allowed to call target_method on the target contract.

Parameters
  • target_contract_hash (UInt160) the contract hash of the contract to be called.
  • target_manifest (ContractManifest) the contract manifest of the contract to be called.
  • target_method (str) the method of the contract to be called.
method

to_json() → dict

Convert object into JSON representation.

class

neo3.contracts.manifest.ContractPermissionDescriptor(contract_hash=None, group=None)

Bases
neo3.core.interfaces.IJson

A restriction object that limits the smart contract's calling abilities. Enforced at runtime.

See Also: ContractManifest.

Attributes
  • is_group (bool) Indicates if the permission is limited to a specific group.
  • is_hash (bool) Indicates if the permission is limited to a specific contract hash.
  • is_wildcard (bool) Indicates if the permission is not limited to a specific contract or a specific group.
Methods
  • to_array() (bytes) Serialize the object.
  • to_json() (dict) Convert object into JSON representation.
  • from_json(json) (ContractPermissionDescriptor) Parse object out of JSON data.
classmethod

from_json(json) → ContractPermissionDescriptor

Parse object out of JSON data.

Parameters
  • json (dict) a dictionary.
Raises
  • KeyError if the data supplied does not contain the necessary key.
  • ValueError if the data supplied cannot recreate a valid object.
method

to_array() → bytes

Serialize the object.

method

to_json() → dict

Convert object into JSON representation.

class

neo3.contracts.manifest.WildcardContainer(data=None)

Bases
neo3.core.interfaces.IJson

An internal helper class for ContractManifest attributes.

Attributes
  • is_wildcard (bool) Indicates if the container is configured to allow all values.
Methods
  • to_json() (dict) Convert object into JSON representation.
  • create_wildcard() (WildcardContainer) Creates an instance that indicates any value is allowed.
  • from_json(json) Parse object out of JSON data.
  • from_json_as_type(json, conversion_func) Parse object out of JSON data.
classmethod

create_wildcard() → WildcardContainer

Creates an instance that indicates any value is allowed.

classmethod

from_json(json)

Parse object out of JSON data.

Note: if the value is not '*', and is a Python list, then it will assume that the list members are strings or convertible via str().

If the wildcard should contain other data types, use the alternative from_json_as_type() method.

Parameters
  • json (dict) a dictionary.
Raises
  • KeyError if the data supplied does not contain the necessary key.
  • ValueError if the data supplied cannot recreate a valid object.
classmethod

from_json_as_type(json, conversion_func)

Parse object out of JSON data.

Note: if the value is not '*', and is a Python list, then it will use conversion_func to parse the members into the expected types.

Parameters
  • json (dict) a dictionary.
  • conversion_func (Callable) a callable that takes 1 argument, which is the element in the value list.
  • Example with UInt160 {'wildcard': ['0xa400ff00ff00ff00ff00ff00ff00ff00ff00ff01', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa']}
    the first call has as argument '0xa400ff00ff00ff00ff00ff00ff00ff00ff00ff01'. to process this example call WildcardContainer.from_json_as_type(json_data, lambda f: types.UInt160.from_string(f))
Raises
  • KeyError if the data supplied does not contain the necessary key.
  • ValueError if the data supplied cannot recreate a valid object.
method

to_json() → dict

Convert object into JSON representation.