コード例 #1
0
ファイル: transactions.py プロジェクト: hitfm00/minter-guard
    def _structure_to_kwargs(cls, structure):
        """ Prepare decoded structure data to instance kwargs. """

        kwargs = super()._structure_to_kwargs(structure)

        # Convert data values to verbose.
        # Data will be passed as additional kwarg
        kwargs['data'].update({
            'name':
            kwargs['data']['name'].decode(),
            'symbol':
            MinterHelper.decode_coin_name(kwargs['data']['symbol']),
            'initial_amount':
            MinterHelper.to_bip(
                int.from_bytes(kwargs['data']['initial_amount'], 'big')),
            'initial_reserve':
            MinterHelper.to_bip(
                int.from_bytes(kwargs['data']['initial_reserve'], 'big')),
            'crr':
            int.from_bytes(kwargs['data']['crr'], 'big'),
            'max_supply':
            MinterHelper.to_bip(
                int.from_bytes(kwargs['data']['max_supply'], 'big'))
        })

        # Populate data key values as kwargs
        kwargs.update(kwargs['data'])

        return kwargs
コード例 #2
0
ファイル: transactions.py プロジェクト: hitfm00/minter-guard
    def _structure_to_kwargs(cls, structure):
        """ Prepare decoded structure data to instance kwargs. """

        kwargs = super()._structure_to_kwargs(structure)

        # Convert data values to verbose.
        # Data will be passed as additional kwarg
        kwargs['data'].update({
            'address':
            MinterHelper.prefix_add(kwargs['data']['address'].hex(),
                                    PREFIX_ADDR),
            'pub_key':
            MinterHelper.prefix_add(kwargs['data']['pub_key'].hex(),
                                    PREFIX_PUBKEY),
            'commission':
            int.from_bytes(kwargs['data']['commission'], 'big'),
            'coin':
            kwargs['data']['coin'],
            'stake':
            MinterHelper.to_bip(int.from_bytes(kwargs['data']['stake'], 'big'))
        })

        # Populate data key values as kwargs
        kwargs.update(kwargs['data'])

        return kwargs
コード例 #3
0
ファイル: transactions.py プロジェクト: hitfm00/minter-guard
    def _structure_to_kwargs(cls, structure):
        """ Prepare decoded structure data to instance kwargs. """

        kwargs = super()._structure_to_kwargs(structure)

        # Convert data values to verbose.
        # Data will be passed as additional kwarg
        kwargs['data'].update({
            'coin_to_buy':
            kwargs['data']['coin_to_buy'],
            'value_to_buy':
            MinterHelper.to_bip(
                int.from_bytes(kwargs['data']['value_to_buy'], 'big')),
            'coin_to_sell':
            kwargs['data']['coin_to_sell'],
            'max_value_to_sell':
            MinterHelper.to_bip(
                int.from_bytes(kwargs['data']['max_value_to_sell'], 'big'))
        })

        # Populate data key values as kwargs
        kwargs.update(kwargs['data'])

        return kwargs
コード例 #4
0
    def from_raw(cls, rawcheck):
        """
        Create check instance from raw check
        Args:
            rawcheck (str)
        Returns:
            MinterCheck
        """

        # Remove check prefix and RLP decode it
        rawcheck = MinterHelper.prefix_remove(rawcheck)
        rawcheck = bytes.fromhex(rawcheck)
        decoded = rlp.decode(rawcheck)

        # Create MinterCheck instance
        kwargs = {
            'nonce': int(decoded[0].decode()),
            'chain_id': int.from_bytes(decoded[1], 'big'),
            'due_block': int.from_bytes(decoded[2], 'big'),
            'coin': MinterHelper.decode_coin_name(decoded[3]),
            'value': MinterHelper.to_bip(int.from_bytes(decoded[4], 'big')),
            'gas_coin': MinterHelper.decode_coin_name(decoded[5]),
            'lock': decoded[6].hex(),
            'signature': {
                'v': int.from_bytes(decoded[7], 'big'),
                'r': decoded[8].hex(),
                's': decoded[9].hex()
            }
        }
        check = MinterCheck(**kwargs)

        # Recover owner address
        msg_hash = cls.__hash(data=[
            int(str(check.nonce).encode().hex(), 16), check.chain_id,
            check.due_block,
            MinterHelper.encode_coin_name(check.coin),
            MinterHelper.to_pip(check.value),
            MinterHelper.encode_coin_name(check.gas_coin),
            bytes.fromhex(check.lock)
        ])
        public_key = ECDSA.recover(msg_hash, tuple(check.signature.values()))
        public_key = MinterHelper.prefix_add(public_key, PREFIX_PUBKEY)

        check.owner = MinterWallet.get_address_from_public_key(public_key)

        return check
コード例 #5
0
ファイル: transactions.py プロジェクト: hitfm00/minter-guard
    def _structure_to_kwargs(cls, structure):
        """ Prepare decoded structure data to instance kwargs. """

        kwargs = super()._structure_to_kwargs(structure)

        # Convert data values to verbose.
        # Data will be passed as additional kwarg
        for index, item in enumerate(kwargs['data']['txs']):
            kwargs['data']['txs'][index] = {
                'coin': item[0],
                'to': MinterHelper.prefix_add(item[1].hex(), PREFIX_ADDR),
                'value': MinterHelper.to_bip(int.from_bytes(item[2], 'big'))
            }

        # Populate data key values as kwargs
        kwargs.update(kwargs['data'])

        return kwargs
コード例 #6
0
ファイル: transactions.py プロジェクト: megamcloud/minter-sdk
    def _structure_to_kwargs(cls, structure):
        """ Prepare decoded structure data to instance kwargs. """

        kwargs = super()._structure_to_kwargs(structure)

        # Convert data values to verbose.
        # Data will be passed as additional kwarg
        kwargs['data'].update({
            'coin':
            MinterHelper.decode_coin_name(kwargs['data']['coin']),
            'to':
            MinterHelper.prefix_add(kwargs['data']['to'].hex(), PREFIX_ADDR),
            'value':
            MinterHelper.to_bip(int.from_bytes(kwargs['data']['value'], 'big'))
        })

        # Populate data key values as kwargs
        kwargs.update(kwargs['data'])

        return kwargs
コード例 #7
0
ファイル: minterapi.py プロジェクト: alvisx/minter-sdk
    def __pip_to_bip(value, key, exclude=None):
        """
        Convert coin amounts integers from PIP to BIP.
        Used as processor function for '__response_processor()'
        Args:
            exclude ([str]): Keys excluded from conversion
        Returns:
            Decimal|int
        """
        # Keys with coin values. Keys' values should be converted
        # from PIP to BIP
        include_keys = [
            'total_stake', 'value', 'bip_value', 'value_to_buy', 'volume',
            'maximum_value_to_sell', 'initial_amount', 'initial_reserve',
            'max_supply', 'stake', 'value_to_sell', 'tx.sell_amount',
            'minimum_value_to_buy', 'tx.return', 'block_reward', 'amount',
            'reserve_balance', 'will_get', 'commission', 'total_bip_stake',
            'will_pay', 'accum_reward', 'total_slashed'
        ]

        # Combine default exclude list with argument
        exclude_keys = []
        if type(exclude) is list:
            exclude_keys += exclude

        # Convert value.
        # Key should be present in 'include_keys' and should be missing
        # in 'exclude_keys' or key is coin symbol.
        # DANGEROUS! We determine if key is coin symbol by checking
        # if key is uppercase or not (should think more about it).
        if type(value) is int and \
                (
                    (key in include_keys and key not in exclude_keys) or
                    key.isupper()
                ):
            return MinterHelper.to_bip(value)

        return value
コード例 #8
0
ファイル: shortcuts.py プロジェクト: hitfm00/minter-guard
def to_bip(value):
    return MinterHelper.to_bip(value)