neo3.contracts.manifest
NEP-15 contract manifest classes for describing smart contract access control.
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 aSystem.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.
neo3.contracts.manifest.
ContractGroup
(
public_key
, signature
)
Describes a set of mutually trusted contracts.
ContractManifest.
from_json
(
json
)
→ ContractGroup
Parse object out of JSON data.
json
(dict) — a dictionary.
KeyError
— if the data supplied does not contain the necessary keys.ValueError
— if the signature length is not 64.
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.
neo3.contracts.manifest.
ContractManifest
(
name=None
)
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
abi
(ContractABI) — https://github.com/neo-project/proposals/blob/d1f4e9e1a67d22a5755c45595121f80b0971ea64/nep-14.mediawikiextra
(Optional) — Optional user defined datagroups
(list) — same group to invoke it.name
(str) — Contract namepermissions
(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"
__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 calltarget_method
ontarget_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 requestingcontract_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.
__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
)
Check if group exists.
public_key
(ECPoint) — needle to search for.
True
if found. False
otherwise.
deserialize
(
reader
)
Deserialize the object from a binary stream.
reader
(BinaryReader) — instance.
from_file
(
path
)
Create object from a file.
path
(str) — location of the file.
FileNotFoundError
— if the path is invalid.ValueError
— if the file is not a valid ContractManifest.
from_json
(
json
)
Parse object out of JSON data.
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.
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.
contract_hash
(UInt160) — target contract hash.
serialize
(
writer
)
Serialize the object into a binary stream.
writer
(BinaryWriter) — instance.
to_json
(
)
→ dict
Convert object into JSON representation.
deserialize_from_bytes
(
data
)
Parse data into an object instance.
data
(bytes | bytearray) — hex escaped bytes.
a deserialized instance of the class.
to_array
(
)
→ bytes
Serialize the object into a bytearray.
neo3.contracts.manifest.
ContractPermission
(
contract
, methods
)
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.
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()
.
is_allowed
(
target_contract_hash
,target_manifest
,target_method
)
(bool) — Return if it is allowed to calltarget_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.
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.
json
(dict) — a dictionary.
KeyError
— if the data supplied does not contain the necessary keys.ValueError
— if a method is zero length.
is_allowed
(
target_contract_hash
, target_manifest
, target_method
)
→ bool
Return if it is allowed to call target_method
on the target contract.
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.
to_json
(
)
→ dict
Convert object into JSON representation.
neo3.contracts.manifest.
ContractPermissionDescriptor
(
contract_hash=None
, group=None
)
A restriction object that limits the smart contract's calling abilities. Enforced at runtime.
See Also: ContractManifest.
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.
from_json
(
json
)
→ ContractPermissionDescriptor
Parse object out of JSON data.
json
(dict) — a dictionary.
KeyError
— if the data supplied does not contain the necessary key.ValueError
— if the data supplied cannot recreate a valid object.
to_array
(
)
→ bytes
Serialize the object.
to_json
(
)
→ dict
Convert object into JSON representation.
neo3.contracts.manifest.
WildcardContainer
(
data=None
)
An internal helper class for ContractManifest attributes.
is_wildcard
(bool) — Indicates if the container is configured to allow all values.
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.
create_wildcard
(
)
→ WildcardContainer
Creates an instance that indicates any value is allowed.
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.
json
(dict) — a dictionary.
KeyError
— if the data supplied does not contain the necessary key.ValueError
— if the data supplied cannot recreate a valid object.
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.
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))
KeyError
— if the data supplied does not contain the necessary key.ValueError
— if the data supplied cannot recreate a valid object.
to_json
(
)
→ dict
Convert object into JSON representation.