-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from CityOfZion/fix-notify
Change Notify implementation
- Loading branch information
Showing
9 changed files
with
128 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from abc import ABC | ||
from typing import Dict, List, Tuple | ||
|
||
from boa3.model.callable import Callable | ||
from boa3.model.identifiedsymbol import IdentifiedSymbol | ||
from boa3.model.type.itype import IType | ||
from boa3.model.variable import Variable | ||
from boa3.neo.vm.opcode.Opcode import Opcode | ||
|
||
|
||
class IBuiltinCallable(Callable, IdentifiedSymbol, ABC): | ||
def __init__(self, identifier: str, args: Dict[str, Variable] = None, return_type: IType = None): | ||
super().__init__(args, return_type) | ||
self._identifier = identifier | ||
|
||
@property | ||
def opcode(self) -> List[Tuple[Opcode, bytes]]: | ||
""" | ||
Gets the opcode for the method. | ||
:return: the opcode and its data if exists. None otherwise. | ||
""" | ||
return [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from abc import ABC | ||
from typing import Dict, List, Tuple | ||
|
||
from boa3.model.builtin.method.builtinevent import IBuiltinEvent | ||
from boa3.model.variable import Variable | ||
from boa3.neo.vm.opcode.Opcode import Opcode | ||
|
||
|
||
class InteropEvent(IBuiltinEvent, ABC): | ||
|
||
def __init__(self, identifier: str, sys_call: str, args: Dict[str, Variable] = None): | ||
self._sys_call: str = sys_call | ||
super().__init__(identifier, args) | ||
|
||
@property | ||
def interop_method_hash(self) -> bytes: | ||
return self._method_hash(self._sys_call) | ||
|
||
def _method_hash(self, method_name: str) -> bytes: | ||
from boa3.constants import SIZE_OF_INT32 | ||
from boa3.neo import cryptography | ||
from boa3.neo.vm.type.String import String | ||
|
||
return cryptography.sha256(String(method_name).to_bytes())[:SIZE_OF_INT32] | ||
|
||
@property | ||
def opcode(self) -> List[Tuple[Opcode, bytes]]: | ||
return [(Opcode.SYSCALL, self.interop_method_hash)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
from typing import Dict | ||
|
||
from boa3.model.builtin.interop.interopmethod import InteropMethod | ||
from boa3.model.builtin.interop.interopevent import InteropEvent | ||
from boa3.model.variable import Variable | ||
|
||
|
||
class NotifyMethod(InteropMethod): | ||
class NotifyMethod(InteropEvent): | ||
|
||
def __init__(self): | ||
from boa3.model.type.type import Type | ||
identifier = 'notify' | ||
syscall = 'System.Runtime.Notify' | ||
args: Dict[str, Variable] = {'state': Variable(Type.any)} | ||
super().__init__(identifier, syscall, args, Type.none) | ||
super().__init__(identifier, syscall, args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from abc import ABC | ||
from typing import Dict | ||
|
||
from boa3.model.builtin.builtincallable import IBuiltinCallable | ||
from boa3.model.event import Event | ||
from boa3.model.variable import Variable | ||
|
||
|
||
class IBuiltinEvent(IBuiltinCallable, Event, ABC): | ||
def __init__(self, identifier: str, args: Dict[str, Variable] = None): | ||
from boa3.model.type.type import Type | ||
super().__init__(identifier, args, Type.none) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters