def __init__(self, transaction_type: TransactionType): from boa3.model.type.collection.sequence.uint256type import UInt256Type identifier = 'get_transaction' syscall = 'getTransaction' args: Dict[str, Variable] = {'hash_': Variable(UInt256Type.build())} super().__init__(identifier, syscall, args, return_type=transaction_type)
def __init__(self, block_type: BlockType): from boa3.model.type.collection.sequence.uint256type import UInt256Type from boa3.model.type.type import Type identifier = 'get_block' syscall = 'getBlock' args: Dict[str, Variable] = { 'index': Variable(Type.union.build([Type.int, UInt256Type.build()])) } super().__init__(identifier, syscall, args, return_type=block_type)
def __init__(self): super().__init__('Transaction') from boa3.model.type.type import Type from boa3.model.type.collection.sequence.uint160type import UInt160Type from boa3.model.type.collection.sequence.uint256type import UInt256Type self._variables: Dict[str, Variable] = { 'hash': Variable(UInt256Type.build()), 'version': Variable(Type.int), 'nonce': Variable(Type.int), 'sender': Variable(UInt160Type.build()), 'system_fee': Variable(Type.int), 'network_fee': Variable(Type.int), 'valid_until_block': Variable(Type.int), 'script': Variable(Type.bytes), } self._constructor: Method = None
def __init__(self): super().__init__('Block') from boa3.model.type.type import Type from boa3.model.type.collection.sequence.uint160type import UInt160Type from boa3.model.type.collection.sequence.uint256type import UInt256Type uint256 = UInt256Type.build() self._variables: Dict[str, Variable] = { 'hash': Variable(uint256), 'version': Variable(Type.int), 'previous_hash': Variable(uint256), 'merkle_root': Variable(uint256), 'timestamp': Variable(Type.int), 'index': Variable(Type.int), 'primary_index': Variable(Type.int), 'next_consensus': Variable(UInt160Type.build()), 'transaction_count': Variable(Type.int) } self._constructor: Method = None
class Builtin: @classmethod def get_symbol(cls, symbol_id: str) -> Optional[Callable]: for name, method in vars(cls).items(): if isinstance(method, IBuiltinCallable) and method.identifier == symbol_id: return method @classmethod def get_any_symbol(cls, symbol_id: str) -> Optional[ISymbol]: for name, method in vars(cls).items(): if isinstance(method, IdentifiedSymbol) and method.identifier == symbol_id: return method @classmethod def get_by_self(cls, symbol_id: str, self_type: IType) -> Optional[Callable]: for name, method in vars(cls).items(): if (isinstance(method, IBuiltinMethod) and method.identifier == symbol_id and method.validate_self(self_type)): return method # builtin method Abs = AbsMethod() Exit = ExitMethod() IsInstance = IsInstanceMethod() Len = LenMethod() NewEvent = CreateEventMethod() Max = MaxMethod() Min = MinMethod() Print = PrintMethod() ScriptHash = ScriptHashMethod() Sqrt = SqrtMethod() Sum = SumMethod() # python builtin class constructor ByteArray = ByteArrayMethod() Range = RangeMethod() Exception = ExceptionMethod() # python class method SequenceAppend = AppendMethod() SequenceClear = ClearMethod() SequenceExtend = ExtendMethod() SequenceInsert = InsertMethod() SequencePop = PopMethod() SequenceRemove = RemoveMethod() SequenceReverse = ReverseMethod() DictKeys = MapKeysMethod() DictValues = MapValuesMethod() # custom class methods ConvertToBytes = ToBytesMethod ConvertToInt = ToIntMethod ConvertToStr = ToStrMethod ConvertToBool = ToBoolMethod _python_builtins: List[IdentifiedSymbol] = [ Abs, ByteArray, ConvertToBool, ConvertToBytes, ConvertToInt, ConvertToStr, DictKeys, DictValues, Exit, IsInstance, Len, Max, Min, Print, ScriptHash, SequenceAppend, SequenceClear, SequenceExtend, SequenceInsert, SequencePop, SequenceRemove, SequenceReverse, Sqrt, Sum ] @classmethod def interop_symbols(cls, package: str = None) -> Dict[str, IdentifiedSymbol]: return { symbol.raw_identifier if hasattr(symbol, 'raw_identifier') else symbol.identifier: symbol for symbol in Interop.interop_symbols(package) } # builtin decorator Metadata = MetadataDecorator() Public = PublicDecorator() # boa builtin type Event = EventType UInt160 = UInt160Type.build() UInt256 = UInt256Type.build() # boa events Nep5Transfer = Nep5TransferEvent() Nep17Transfer = Nep17TransferEvent() # boa smart contract methods Abort = AbortMethod() _boa_builtins: List[IdentifiedSymbol] = [ Public, NewEvent, Event, Metadata, NeoMetadataType, ScriptHash ] metadata_fields: Dict[str, Union[type, Tuple[type]]] = { 'author': (str, type(None)), 'email': (str, type(None)), 'description': (str, type(None)), 'extras': dict } @classmethod def boa_symbols(cls) -> Dict[str, IdentifiedSymbol]: return {symbol.identifier: symbol for symbol in cls._boa_builtins} @classmethod def package_symbols(cls, package: str = None) -> Dict[str, IdentifiedSymbol]: if package in BoaPackage.__members__.values(): return { symbol.identifier: symbol for symbol in cls._boa_symbols[package] } return cls.boa_symbols() _boa_symbols: Dict[BoaPackage, List[IdentifiedSymbol]] = { BoaPackage.Contract: [ Abort, Nep17Transfer, Nep5Transfer, ], BoaPackage.Interop: Interop.package_symbols, BoaPackage.Type: [UInt160, UInt256] }
def __init__(self): from boa3.model.type.collection.sequence.uint256type import UInt256Type identifier = '-get_current_hash' syscall = 'currentHash' args: Dict[str, Variable] = {} super().__init__(identifier, syscall, args, return_type=UInt256Type.build())
class Builtin: @classmethod def get_symbol(cls, symbol_id: str) -> Optional[Callable]: for method in cls._python_builtins: if isinstance(method, IBuiltinCallable) and method.identifier == symbol_id: return method @classmethod def get_by_self(cls, symbol_id: str, self_type: IType) -> Optional[Callable]: for name, method in vars(cls).items(): if (isinstance(method, IBuiltinMethod) and method.identifier == symbol_id and method.validate_self(self_type)): return method # builtin method Abs = AbsMethod() Exit = ExitMethod() IsInstance = IsInstanceMethod() Len = LenMethod() NewEvent = CreateEventMethod() Max = MaxIntMethod() Min = MinIntMethod() Print = PrintMethod() ScriptHash = ScriptHashMethod() StrSplit = StrSplitMethod() Sum = SumMethod() # python builtin class constructor Bool = BoolMethod() ByteArray = ByteArrayMethod() Exception = ExceptionMethod() IntByteString = IntByteStringMethod() IntInt = IntIntMethod() Range = RangeMethod() Reversed = ReversedMethod() Super = SuperMethod() # python class method BytesStringIsDigit = IsDigitMethod() BytesStringJoin = JoinMethod() BytesStringLower = LowerMethod() BytesStringStartswith = StartsWithMethod() BytesStringStrip = StripMethod() BytesStringUpper = UpperMethod() CountSequence = CountSequenceMethod() CountStr = CountStrMethod() Copy = CopyListMethod() SequenceAppend = AppendMethod() SequenceClear = ClearMethod() SequenceExtend = ExtendMethod() SequenceIndex = IndexSequenceMethod() SequenceInsert = InsertMethod() SequencePop = PopSequenceMethod() SequenceRemove = RemoveMethod() SequenceReverse = ReverseMethod() StrIndex = IndexStrMethod() DictKeys = MapKeysMethod() DictPop = PopDictMethod() DictValues = MapValuesMethod() # custom class methods ConvertToBytes = ToBytesMethod ConvertToInt = ToIntMethod ConvertToStr = ToStrMethod ConvertToBool = ToBoolMethod # builtin decorator ClassMethodDecorator = ClassMethodDecorator() InstanceMethodDecorator = InstanceMethodDecorator() PropertyDecorator = PropertyDecorator() StaticMethodDecorator = StaticMethodDecorator() _python_builtins: List[IdentifiedSymbol] = [ Abs, ByteArray, BytesStringIsDigit, BytesStringJoin, BytesStringLower, BytesStringStartswith, BytesStringStrip, BytesStringUpper, ClassMethodDecorator, ConvertToBool, ConvertToBytes, ConvertToInt, ConvertToStr, Copy, CountSequence, CountStr, DictKeys, DictValues, Exception, Exit, IsInstance, Len, Max, Min, Print, PropertyDecorator, Range, Reversed, ScriptHash, SequenceAppend, SequenceClear, SequenceExtend, SequenceIndex, SequenceInsert, SequencePop, SequenceRemove, SequenceReverse, StaticMethodDecorator, StrIndex, StrSplit, Sum, Super, ] @classmethod def interop_symbols(cls, package: str = None) -> Dict[str, IdentifiedSymbol]: return { symbol.raw_identifier if hasattr(symbol, 'raw_identifier') else symbol.identifier: symbol for symbol in Interop.interop_symbols(package) } # boa builtin decorator ContractInterface = ContractDecorator() ContractMethodDisplayName = DisplayNameDecorator() Metadata = MetadataDecorator() Public = PublicDecorator() # boa builtin type ByteString = ByteStringType.build() Event = EventType UInt160 = UInt160Type.build() UInt256 = UInt256Type.build() ECPoint = ECPointType.build() NeoAccountState = NeoAccountStateType.build() # boa events Nep5Transfer = Nep5TransferEvent() Nep11Transfer = Nep11TransferEvent() Nep17Transfer = Nep17TransferEvent() # boa smart contract methods Abort = AbortMethod() # region boa builtin modules BuiltinMathCeil = DecimalCeilingMethod() BuiltinMathFloor = DecimalFloorMethod() MathModule = Package( identifier='math', methods=[Math.Sqrt, BuiltinMathCeil, BuiltinMathFloor]) _modules = [MathModule] # endregion boa_builtins: List[IdentifiedSymbol] = [ ContractInterface, ContractMethodDisplayName, Event, Metadata, NeoMetadataType, NewEvent, Public, ScriptHash ] + _modules metadata_fields: Dict[str, Union[type, Tuple[type]]] = { 'name': str, 'supported_standards': list, 'trusts': list, 'author': (str, type(None)), 'email': (str, type(None)), 'description': (str, type(None)), 'extras': dict } @classmethod def boa_symbols(cls) -> Dict[str, IdentifiedSymbol]: return {symbol.identifier: symbol for symbol in cls.boa_builtins} @classmethod def package_symbols(cls, package: str = None) -> Dict[str, IdentifiedSymbol]: if package in BoaPackage.__members__.values(): return { symbol.identifier: symbol for symbol in cls._boa_symbols[package] } return cls.boa_symbols() _boa_symbols: Dict[BoaPackage, List[IdentifiedSymbol]] = { BoaPackage.Contract: [ Abort, NeoAccountState, Nep11Transfer, Nep17Transfer, Nep5Transfer, ], BoaPackage.Interop: Interop.package_symbols, BoaPackage.Type: [ByteString, ECPoint, UInt160, UInt256] } _internal_methods = [InnerDeployMethod.instance()] internal_methods = { method.raw_identifier: method for method in _internal_methods }
def __init__(self, transaction_type: TransactionType): from boa3.model.type.collection.sequence.uint256type import UInt256Type from boa3.model.type.type import Type identifier = 'get_transaction_from_block' syscall = 'getTransactionFromBlock' args: Dict[str, Variable] = {'block_hash_or_height': Variable(Type.union.build([UInt256Type.build(), Type.int])), 'tx_index': Variable(Type.int)} super().__init__(identifier, syscall, args, return_type=transaction_type)