コード例 #1
0
ファイル: test_address.py プロジェクト: ulamlabs/aioxrpy
def test_address_validation():
    with pytest.raises(ValueError):
        # Valid string but not account ID
        address.decode_address('snoPBrXtMeMyMHUVTgbuqAfg1SUTb')

    with pytest.raises(ValueError):
        address.decode_address('shitcoin1234')
コード例 #2
0
ファイル: rpc.py プロジェクト: ulamlabs/aioxrpy
    async def multisign_and_submit(self, tx: Dict,
                                   keys: List[RippleKey]) -> dict:
        """
        Signs, serializes and submits the transaction using multiple
        keys
        """
        tx = deepcopy(tx)
        assert 'Account' in tx

        if 'Sequence' not in tx:
            info = await self.account_info(tx['Account'],
                                           ledger_index='current')
            tx['Sequence'] = info['account_data']['Sequence']

        # sort keys by account ID
        tx['SigningPubKey'] = b''
        tx['Signers'] = [{
            'Signer': {
                'Account': key.to_account(),
                'TxnSignature': key.sign_tx(tx, multi_sign=True),
                'SigningPubKey': key.to_public(),
            }
        } for key in sorted(
            keys, key=lambda key: address.decode_address(key.to_account()))]
        tx_blob = binascii.hexlify(serializer.serialize(tx)).decode()
        return await self.submit(tx_blob)
コード例 #3
0
    def serialize(self, value):
        # XRP is passed as int, Issued Currency as dict
        if isinstance(value, int):
            amount = value
            if amount >= 0:
                amount |= 0x4000000000000000
            else:
                amount = -amount
            return BasicTypeSerializer('>Q').serialize(amount)
        elif isinstance(value, dict):
            # Issued Currency
            amount = D(value.get('value'))
            currency = value.get('code')
            issuer = value.get('issuer')

            serialized_amount = 0x8000000000000000
            sign, mantissa, exp = self.scale_to_xrp_amount(amount)

            # When mantissa == 0, it means we're rounding to 0
            if mantissa != 0:
                # set "Is positive" bit
                if sign == 0:
                    serialized_amount |= 0x4000000000000000

                # next 8 bits are exponent
                serialized_amount |= ((exp + 97) << 54)
                # last 54 bits are mantissa
                serialized_amount |= mantissa

            return b''.join(
                (BasicTypeSerializer('>Q').serialize(serialized_amount),
                 CurrencySerializer().serialize(currency),
                 decode_address(issuer)))
        raise ValueError('Unsupported type, expected dict or int')
コード例 #4
0
 def serialize(self, value):
     ccy_serializer = CurrencySerializer()
     results = []
     for path in value:
         path_data = []
         for step in path:
             type_byte = 0
             data = []
             if "account" in step.keys():
                 type_byte |= 0x01
                 data.append(decode_address(step['account']))
             if "currency" in step.keys():
                 type_byte |= 0x10
                 data.append(ccy_serializer.serialize(step['currency']))
             if "issuer" in step.keys():
                 type_byte |= 0x20
                 data.append(decode_address(step['issuer']))
             path_data.append(b''.join(
                 (BasicTypeSerializer('>B').serialize(type_byte), *data)))
         results.append(b''.join(path_data))
     return b''.join((b'\xFF'.join(results), b'\x00'))
コード例 #5
0
ファイル: keys.py プロジェクト: ulamlabs/aioxrpy
 def _tx_suffix(self, multi_sign: bool) -> bytes:
     return b'' if not multi_sign else decode_address(self.to_account())
コード例 #6
0
ファイル: test_address.py プロジェクト: ulamlabs/aioxrpy
def test_decode_address():
    binary = (
        b'\xb5\xf7by\x8aS\xd5C\xa0\x14\xca\xf8\xb2\x97\xcf\xf8\xf2\xf97\xe8')
    base58 = 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'
    assert address.decode_address(base58) == binary
コード例 #7
0
 def serialize(self, value: str) -> bytes:
     return BlobSerializer().serialize(decode_address(value))