Пример #1
0
def __make_params(user_address, to, amount, fee, method, private_key_bytes):
    """Make params for jsonrpc format.

    :param user_address: Address of user's wallet.
    :param to: Address of wallet to receive the asset.
    :param amount: Amount of money.
    :param fee: Transaction fee.
    :param method: Method type. type(str)
    :param private_key_bytes: Private key of user's wallet.
    :return:
    type(dict)
    """
    params = {
        'from': user_address,
        'to': to,
        'value': hex(amount),
        'fee': hex(fee),
        'timestamp': str(get_timestamp_us())
    }
    tx_hash_bytes = get_tx_hash(method, params)
    signature_bytes = sign(private_key_bytes, tx_hash_bytes)
    params['tx_hash'] = tx_hash_bytes.hex()
    params['signature'] = signature_bytes.decode()

    return params
    def test_get_tx(self):
        """Test for get_tx_hash function.
        """
        # Given
        method = "method"
        params = {"param1": 1}

        # When
        expect = b'\xc0\x84\x19o\xd3\xe6<\x9e%\xd9\x05\xd4\x8di\x17\xd3\x02<a\xc6\xa2\xb2\xec I-\x12\xe1n\xd5\xac:'
        tx_hash = get_tx_hash(method, params)

        # Then
        self.assertEqual(expect, tx_hash)