-
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 #40 from CityOfZion/convert-bytearray
Convert Bytes type
- Loading branch information
Showing
22 changed files
with
303 additions
and
45 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
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
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,60 @@ | ||
from typing import Any | ||
|
||
from boa3.model.type.itype import IType | ||
from boa3.model.type.sequence.sequencetype import SequenceType | ||
from boa3.neo.vm.type.AbiType import AbiType | ||
from boa3.neo.vm.type.StackItemType import StackItemType | ||
|
||
|
||
class BytesType(SequenceType): | ||
""" | ||
A class used to represent Python bytes type | ||
""" | ||
|
||
def __init__(self): | ||
identifier = 'bytes' | ||
from boa3.model.type.primitive.inttype import IntType | ||
values_type = [IntType()] | ||
super().__init__(identifier, values_type) | ||
|
||
@property | ||
def identifier(self) -> str: | ||
return self._identifier | ||
|
||
@property | ||
def abi_type(self) -> AbiType: | ||
return AbiType.ByteArray | ||
|
||
@property | ||
def stack_item(self) -> StackItemType: | ||
return StackItemType.Buffer | ||
|
||
@property | ||
def default_value(self) -> Any: | ||
return bytes() | ||
|
||
def is_valid_key(self, value_type: IType) -> bool: | ||
return value_type == self.valid_key | ||
|
||
@property | ||
def valid_key(self) -> IType: | ||
from boa3.model.type.type import Type | ||
return Type.int | ||
|
||
@classmethod | ||
def build(cls, value: Any): | ||
from boa3.model.type.type import Type | ||
return Type.bytes | ||
|
||
@classmethod | ||
def build_sequence(cls, value_type: IType): | ||
from boa3.model.type.type import Type | ||
return Type.bytes | ||
|
||
@classmethod | ||
def _is_type_of(cls, value: Any): | ||
return type(value) is bytes or isinstance(value, BytesType) | ||
|
||
@property | ||
def can_reassign_values(self) -> bool: | ||
return False |
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
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
Oops, something went wrong.