Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Witness rules #138

Merged
merged 2 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 3 additions & 19 deletions neo3/contracts/applicationengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,26 +124,10 @@ def checkwitness(self, hash_: types.UInt160) -> bool:
else:
return False

if signer.scope == payloads.WitnessScope.GLOBAL:
return True

if payloads.WitnessScope.CALLED_BY_ENTRY in signer.scope:
if self.calling_scripthash == self.entry_scripthash:
return True

if payloads.WitnessScope.CUSTOM_CONTRACTS in signer.scope:
if self.current_scripthash in signer.allowed_contracts:
return True

if payloads.WitnessScope.CUSTOM_GROUPS in signer.scope:
self._validate_callflags(contracts.CallFlags.READ_STATES)
for rule in signer.get_all_rules():
if rule.condition.match(self):
return rule.action == payloads.WitnessRuleAction.ALLOW

contract = contracts.ManagementContract().get_contract(self.snapshot, self.current_scripthash)
if contract is None:
return False
group_keys = set(map(lambda g: g.public_key, contract.manifest.groups))
if any(group_keys.intersection(signer.allowed_groups)):
return True
return False

self._validate_callflags(contracts.CallFlags.READ_STATES)
Expand Down
6 changes: 6 additions & 0 deletions neo3/contracts/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,12 @@ def can_call(self, target_contract: contracts.ContractState, target_method: str)
results = list(map(lambda p: p.is_allowed(target_contract, target_method), self.permissions))
return any(results)

def contains_group(self, public_key: cryptography.ECPoint) -> bool:
for g in self.groups:
if public_key == g.public_key:
return True
return False

@classmethod
def _serializable_init(cls):
return cls()
18 changes: 17 additions & 1 deletion neo3/network/payloads/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,23 @@
from .version import VersionPayload
from .address import NetworkAddress, AddrPayload, AddressState, DisconnectReason
from .ping import PingPayload
from .verification import Witness, WitnessScope, Signer, IVerifiable
from .verification import (Witness,
WitnessScope,
Signer,
IVerifiable,
WitnessRuleAction,
WitnessRule,
ConditionAnd,
ConditionBool,
ConditionCalledByContract,
ConditionCalledByEntry,
ConditionCalledByGroup,
ConditionGroup,
ConditionNot,
ConditionOr,
ConditionScriptHash,
WitnessConditionType)

from .transaction import Transaction, TransactionAttribute, TransactionAttributeType, HighPriorityAttribute
from .block import (Header,
Block,
Expand Down
Loading