Esempio n. 1
0
    def __init__(self):
        super().__init__('ContractGroup')
        from boa3.model.type.collection.sequence.ecpointtype import ECPointType
        from boa3.model.type.type import Type

        self._variables: Dict[str, Variable] = {
            'pubkey': Variable(ECPointType.build()),
            'signature': Variable(Type.bytes)
        }
        self._constructor: Method = None
    def __init__(self):
        from boa3.model.type.collection.sequence.uint160type import UInt160Type
        from boa3.model.type.collection.sequence.ecpointtype import ECPointType

        identifier = 'create_standard_account'
        syscall = 'System.Contract.CreateStandardAccount'
        args: Dict[str, Variable] = {
            'pub_key': Variable(ECPointType.build())
        }
        super().__init__(identifier, syscall, args, return_type=UInt160Type.build())
    def __init__(self):
        from boa3.model.type.type import Type
        from boa3.model.type.collection.sequence.ecpointtype import ECPointType

        identifier = 'unregister_candidate'
        native_identifier = 'unregisterCandidate'
        args: Dict[str, Variable] = {
            'pubkey': Variable(ECPointType.build())
        }
        super().__init__(identifier, native_identifier, args, return_type=Type.bool)
Esempio n. 4
0
    def __init__(self):
        super().__init__('NeoAccountState')
        from boa3.model.type.type import Type
        from boa3.model.type.collection.sequence.ecpointtype import ECPointType

        self._variables: Dict[str, Variable] = {
            'balance': Variable(Type.int),
            'height': Variable(Type.int),
            'vote_to': Variable(ECPointType.build()),
        }
        self._constructor: Optional[Method] = None
Esempio n. 5
0
    def __init__(self):
        from boa3.model.type.type import Type
        from boa3.model.type.collection.sequence.ecpointtype import ECPointType

        identifier = 'get_next_block_validators'
        native_identifier = 'getNextBlockValidators'
        args: Dict[str, Variable] = {}
        super().__init__(identifier,
                         native_identifier,
                         args,
                         return_type=Type.list.build([ECPointType.build()]))
Esempio n. 6
0
    def __init__(self):
        super().__init__('ContractPermissionDescriptor')
        from boa3.model.type.collection.sequence.uint160type import UInt160Type
        from boa3.model.type.collection.sequence.ecpointtype import ECPointType
        from boa3.model.type.type import Type

        self._variables: Dict[str, Variable] = {
            'hash': Variable(Type.optional.build(UInt160Type.build())),
            'group': Variable(Type.optional.build(ECPointType.build()))
        }
        self._constructor: Method = None
Esempio n. 7
0
    def __init__(self):
        from boa3.model.type.type import Type
        from boa3.model.type.collection.sequence.ecpointtype import ECPointType

        identifier = 'check_multisig'
        syscall = 'System.Crypto.CheckMultisig'
        args: Dict[str, Variable] = {
            'pubkeys': Variable(Type.list.build_collection([ECPointType.build()])),
            'signatures': Variable(Type.list.build_collection([Type.bytes]))
        }
        super().__init__(identifier, syscall, args, return_type=Type.bool)
Esempio n. 8
0
    def __init__(self):
        from boa3.model.type.type import Type
        from boa3.model.type.collection.sequence.ecpointtype import ECPointType
        from boa3.model.type.collection.sequence.uint160type import UInt160Type

        identifier = 'vote'
        native_identifier = 'vote'
        args: Dict[str, Variable] = {
            'account': Variable(UInt160Type.build()),
            'vote_to': Variable(ECPointType.build())
        }
        super().__init__(identifier, native_identifier, args, return_type=Type.bool)
Esempio n. 9
0
    def __init__(self):
        from boa3.model.type.type import Type
        from boa3.model.builtin.interop.role.roletype import RoleType
        from boa3.model.type.collection.sequence.ecpointtype import ECPointType

        identifier = 'get_designated_by_role'
        native_identifier = 'getDesignatedByRole'

        role_type = RoleType.build()
        args: Dict[str, Variable] = {
            'role': Variable(role_type),
            'index': Variable(Type.int)
        }
        super().__init__(identifier, native_identifier, args, return_type=ECPointType.build())
Esempio n. 10
0
    def __init__(self):
        from boa3.model.type.type import Type
        from boa3.model.type.collection.sequence.ecpointtype import ECPointType

        identifier = 'get_candidates'
        native_identifier = 'getCandidates'
        args: Dict[str, Variable] = {}
        super().__init__(
            identifier,
            native_identifier,
            args,
            return_type=Type.list.build_collection(
                [Type.tuple.build_collection([ECPointType.build(),
                                              Type.int])]))
Esempio n. 11
0
    def __init__(self):
        from boa3.model.type.type import Type
        from boa3.model.type.collection.sequence.ecpointtype import ECPointType
        from boa3.model.type.collection.sequence.uint160type import UInt160Type

        identifier = 'check_witness'
        syscall = 'System.Runtime.CheckWitness'
        args: Dict[str, Variable] = {
            'hash_or_pubkey':
            Variable(
                Type.union.build([ECPointType.build(),
                                  UInt160Type.build()]))
        }
        super().__init__(identifier, syscall, args, return_type=Type.bool)
Esempio n. 12
0
    def __init__(self):
        from boa3.model.type.collection.sequence.uint160type import UInt160Type
        from boa3.model.type.collection.sequence.ecpointtype import ECPointType
        from boa3.model.type.type import Type

        identifier = 'create_multisig_account'
        syscall = 'System.Contract.CreateMultisigAccount'
        args: Dict[str, Variable] = {
            'm': Variable(Type.int),
            'pub_keys':
            Variable(Type.list.build_collection([ECPointType.build()]))
        }
        super().__init__(identifier,
                         syscall,
                         args,
                         return_type=UInt160Type.build())
Esempio n. 13
0
    def __init__(self):
        from boa3.model.type.type import Type
        from boa3.model.type.collection.sequence.ecpointtype import ECPointType
        from boa3.model.type.primitive.bytestringtype import ByteStringType
        from boa3.model.builtin.interop.crypto.namedcurvetype import NamedCurveType

        identifier = 'verify_with_ecdsa'
        native_identifier = 'verifyWithECDsa'
        args: Dict[str, Variable] = {
            'data': Variable(Type.any),
            'pubkey': Variable(ECPointType.build()),
            'signature': Variable(ByteStringType.build()),
            'curve': Variable(NamedCurveType.build())
        }
        super().__init__(identifier,
                         native_identifier,
                         args,
                         return_type=Type.bool)
Esempio n. 14
0
    def __init__(self):
        from boa3.model.type.type import Type
        from boa3.model.type.collection.sequence.ecpointtype import ECPointType

        identifier = 'get_committee'
        native_identifier = 'getCommittee'
        args: Dict[str, Variable] = {}
        super().__init__(identifier, native_identifier, args, return_type=Type.list.build([ECPointType.build()]))
Esempio n. 15
0
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, data_type: IType = None):
        ec_point = ECPointType.build()
        if not ec_point.is_type_of(data_type):
            data_type = ec_point

        super().__init__(data_type)