예제 #1
0
    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_sell':
            MinterConvertor.decode_coin_name(kwargs['data']['coin_to_sell']),
            'value_to_sell':
            MinterConvertor.convert_value(value=MinterHelper.bin2int(
                kwargs['data']['value_to_sell']),
                                          to='bip'),
            'coin_to_buy':
            MinterConvertor.decode_coin_name(kwargs['data']['coin_to_buy']),
            'min_value_to_buy':
            MinterConvertor.convert_value(value=MinterHelper.bin2int(
                kwargs['data']['min_value_to_buy']),
                                          to='bip')
        })

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

        return kwargs
예제 #2
0
    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': MinterConvertor.decode_coin_name(kwargs['data']['symbol']),
            'initial_amount': MinterConvertor.convert_value(
                value=MinterHelper.bin2int(kwargs['data']['initial_amount']),
                to='bip'
            ),
            'initial_reserve': MinterConvertor.convert_value(
                value=MinterHelper.bin2int(kwargs['data']['initial_reserve']),
                to='bip'
            ),
            'crr': MinterHelper.bin2int(kwargs['data']['crr'])
        })

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

        return kwargs
예제 #3
0
    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':
            MinterPrefix.ADDRESS +
            MinterHelper.bin2hex(kwargs['data']['address']),
            'pub_key':
            MinterPrefix.PUBLIC_KEY +
            MinterHelper.bin2hex(kwargs['data']['pub_key']),
            'comission':
            MinterHelper.bin2int(kwargs['data']['comission']),
            'coin':
            MinterConvertor.decode_coin_name(kwargs['data']['coin']),
            'stake':
            MinterConvertor.convert_value(
                MinterHelper.bin2int(kwargs['data']['stake']), 'bip')
        })

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

        return kwargs
예제 #4
0
    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':
                MinterConvertor.decode_coin_name(item[0]),
                'to':
                MinterPrefix.ADDRESS + MinterHelper.bin2hex(item[1]),
                'value':
                MinterConvertor.convert_value(value=MinterHelper.bin2int(
                    item[2]),
                                              to='bip')
            }

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

        return kwargs
예제 #5
0
    def _structure_to_kwargs(cls, structure):
        """
        Works with already populated structure and prepare **kwargs for
        creating new instance of tx.
        """

        structure.update({
            'gas_coin': MinterConvertor.decode_coin_name(structure['gas_coin'])
        })

        return structure
예제 #6
0
파일: check.py 프로젝트: vrntsv/minter-sdk
    def from_raw(cls, rawcheck):
        """
        Create check instance from raw check
        Args:
            rawcheck (str)
        Returns:
            MinterCheck
        """

        # Remove check prefix and RLP decode it
        rawcheck = MinterPrefix.remove_prefix(
            string=rawcheck,
            prefix=MinterPrefix.CHECK
        )
        rawcheck = binascii.unhexlify(rawcheck)
        decoded = rlp.decode(rawcheck)

        # Create MinterCheck instance
        kwargs = {
            'nonce': int(decoded[0].decode()),
            'chain_id': MinterHelper.bin2int(decoded[1]),
            'due_block': MinterHelper.bin2int(decoded[2]),
            'coin': MinterConvertor.decode_coin_name(decoded[3]),
            'value': MinterConvertor.convert_value(
                value=MinterHelper.bin2int(decoded[4]),
                to='bip'
            ),
            'lock': binascii.hexlify(decoded[5]).decode(),
            'signature': {
                'v': MinterHelper.bin2int(decoded[6]),
                'r': MinterHelper.bin2hex(decoded[7]),
                's': MinterHelper.bin2hex(decoded[8])
            }
        }
        check = MinterCheck(**kwargs)

        # Recover owner address
        msg_hash = cls.__hash(data=[
            int(binascii.hexlify(str(check.nonce).encode()), 16),
            check.chain_id,
            check.due_block,
            MinterConvertor.encode_coin_name(check.coin),
            MinterConvertor.convert_value(value=check.value, to='pip'),
            MinterHelper.hex2bin(check.lock)
        ])
        public_key = ECDSA.recover(msg_hash, list(check.signature.values()))
        public_key = MinterPrefix.PUBLIC_KEY + public_key

        check.owner = MinterWallet.get_address_from_public_key(public_key)

        return check