Esempio n. 1
0
def analyze_transaction(txstr):
    txdata = json.loads(txstr)
    if 'transaction' in txdata:
        tx = TransactionSubscriptionMessage(txdata).transaction
    elif 'result' in txdata:
        tx = Transaction(txdata['result'])
    else:
        tx = Transaction(txdata)

    data = [tx.type.__name__]
    if not tx.successful:
        data.append('unsuccessful')
    else:
        if tx.type == PaymentTransaction:
            data.append(tx.hash)
            data.append('{0} {1}/{2}'.format(*tx.amount_received))
            data.append('to: %s' % tx.Destination)
        if not tx.is_xrp_received:
            data.append('new balance: %s' % tx.recipient_balance)
            data.append('of limit: %s' % tx.recipient_trust_limit)
            data.append('path: intermediaries={intermediaries}, offers={offers}'.format(
                **tx.analyze_path()
            ))
        else:
            data.append('TODO: parse')

    # Print the collected info
    print(data[0])
    for line in data[1:]:
        print('    %s' % line)
def test_payment_with_intermediary_traders():
    msg = open_transaction('payment_with_intermediary_traders.json')
    tx = TransactionSubscriptionMessage(msg).transaction

    # We identify the correct recipient data
    assert tx.currencies_received == ('USD', ['rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q'])
    assert tx.recipient_balances == [
        ('rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q', Decimal('369.1796199999879'))]
    assert tx.recipient_trust_limits == [
        ('rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q', Decimal('4000'))]

    assert tx.analyze_path() == {'offers': 2, 'intermediaries': 2}
Esempio n. 3
0
def test_payment_with_intermediary_traders():
    msg = open_transaction('payment_with_intermediary_traders.json')
    tx = TransactionSubscriptionMessage(msg).transaction

    # We identify the correct recipient data
    assert tx.currencies_received == ('USD',
                                      ['rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q'])
    assert tx.recipient_balances == [('rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
                                      Decimal('369.1796199999879'))]
    assert tx.recipient_trust_limits == [('rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
                                          Decimal('4000'))]

    assert tx.analyze_path() == {'offers': 2, 'intermediaries': 2}