Exemplo n.º 1
0
MyMoneyObject const * TransactionMatcher::findMatch(const MyMoneyTransaction& ti, const MyMoneySplit& si, MyMoneySplit& sm, autoMatchResultE& result)
{
  result = notMatched;
  sm = MyMoneySplit();

  MyMoneyTransactionFilter filter(si.accountId());
  filter.setReportAllSplits(false);
  filter.setDateFilter(ti.postDate().addDays(-m_days), ti.postDate().addDays(m_days));
  filter.setAmountFilter(si.shares(), si.shares());

  QValueList<QPair<MyMoneyTransaction, MyMoneySplit> > list;
  MyMoneyFile::instance()->transactionList(list, filter);

  // parse list
  QValueList<QPair<MyMoneyTransaction, MyMoneySplit> >::iterator it_l;
  QPair<MyMoneyTransaction, MyMoneySplit> lastMatch;

  for(it_l = list.begin(); (result != matchedDuplicate) && (it_l != list.end()); ++it_l) {
    // just skip myself
    if((*it_l).first.id() == ti.id()) {
      continue;
    }

    checkTransaction((*it_l).first, ti, si, lastMatch, result);
  }

  MyMoneyObject* rc = 0;
  if(result != notMatched) {
    sm = lastMatch.second;
    rc = new MyMoneyTransaction(lastMatch.first);

  } else {
    // if we did not find anything, we need to scan for scheduled transactions
    QValueList<MyMoneySchedule> list;
    QValueList<MyMoneySchedule>::iterator it_sch;
    // find all schedules that have a reference to the current account
    list = MyMoneyFile::instance()->scheduleList(m_account.id());
    for(it_sch = list.begin(); (result != matched && result != matchedExact) && (it_sch != list.end()); ++it_sch) {
      // get the next due date adjusted by the weekend switch
      QDate nextDueDate = (*it_sch).nextDueDate();
      if((*it_sch).isOverdue() ||
         (nextDueDate >= ti.postDate().addDays(-m_days)
         && nextDueDate <= ti.postDate().addDays(m_days))) {
        MyMoneyTransaction st = KMyMoneyUtils::scheduledTransaction(*it_sch);
        checkTransaction(st, ti, si, lastMatch, result, (*it_sch).variation());
        if(result == matched || result == matchedExact) {
          sm = lastMatch.second;
          rc = new MyMoneySchedule(*it_sch);
        }
      }
    }
  }

  return rc;
}
Exemplo n.º 2
0
void
applyAllowTrust(Application& app, SecretKey& from, SecretKey& trustor,
                SequenceNumber seq, std::string const& currencyCode,
                bool authorize, AllowTrustResultCode result)
{
    TransactionFramePtr txFrame;
    txFrame = createAllowTrust(from, trustor, seq, currencyCode, authorize);

    LedgerDelta delta(app.getLedgerManager().getCurrentLedgerHeader());
    txFrame->apply(delta, app);

    checkTransaction(*txFrame);
    REQUIRE(AllowTrustOpFrame::getInnerCode(
                txFrame->getResult().result.results()[0]) == result);
}
Exemplo n.º 3
0
void
applyChangeTrust(Application& app, SecretKey& from, SecretKey& to,
                 SequenceNumber seq, std::string const& currencyCode,
                 int64_t limit, ChangeTrustResultCode result)
{
    TransactionFramePtr txFrame;

    txFrame = createChangeTrust(from, to, seq, currencyCode, limit);

    LedgerDelta delta(app.getLedgerManager().getCurrentLedgerHeader());
    txFrame->apply(delta, app);

    checkTransaction(*txFrame);
    REQUIRE(ChangeTrustOpFrame::getInnerCode(
                txFrame->getResult().result.results()[0]) == result);
}
Exemplo n.º 4
0
void
applySetOptions(Application& app, SecretKey& source, AccountID* inflationDest,
                uint32_t* setFlags, uint32_t* clearFlags, Thresholds* thrs,
                Signer* signer, SequenceNumber seq, SetOptionsResultCode result)
{
    TransactionFramePtr txFrame;

    txFrame = createSetOptions(source, inflationDest, setFlags, clearFlags,
                               thrs, signer, seq);

    LedgerDelta delta(app.getLedgerManager().getCurrentLedgerHeader());
    txFrame->apply(delta, app);

    checkTransaction(*txFrame);
    REQUIRE(SetOptionsOpFrame::getInnerCode(
                txFrame->getResult().result.results()[0]) == result);
}
Exemplo n.º 5
0
void
applyPaymentTx(Application& app, SecretKey& from, SecretKey& to,
               SequenceNumber seq, int64_t amount, PaymentResultCode result)
{
    TransactionFramePtr txFrame;

    AccountFrame fromAccount;
    AccountFrame toAccount;
    bool beforeToExists = AccountFrame::loadAccount(
        to.getPublicKey(), toAccount, app.getDatabase());

    REQUIRE(AccountFrame::loadAccount(from.getPublicKey(), fromAccount,
                                      app.getDatabase()));

    txFrame = createPaymentTx(from, to, seq, amount);

    LedgerDelta delta(app.getLedgerManager().getCurrentLedgerHeader());
    txFrame->apply(delta, app);

    checkTransaction(*txFrame);
    auto txResult = txFrame->getResult();
    auto innerCode = PaymentOpFrame::getInnerCode(txResult.result.results()[0]);
    REQUIRE(innerCode == result);

    REQUIRE(txResult.feeCharged == app.getLedgerManager().getTxFee());

    AccountFrame toAccountAfter;
    bool afterToExists = AccountFrame::loadAccount(
        to.getPublicKey(), toAccountAfter, app.getDatabase());

    if (!(innerCode == PAYMENT_SUCCESS || innerCode == PAYMENT_SUCCESS_MULTI))
    {
        // check that the target account didn't change
        REQUIRE(beforeToExists == afterToExists);
        if (beforeToExists && afterToExists)
        {
            REQUIRE(memcmp(&toAccount.getAccount(),
                           &toAccountAfter.getAccount(),
                           sizeof(AccountEntry)) == 0);
        }
    }
    else
    {
        REQUIRE(afterToExists);
    }
}
Exemplo n.º 6
0
OperationResult
applyInflation(Application& app, SecretKey& from, SequenceNumber seq,
               InflationResultCode result)
{
    TransactionFramePtr txFrame = createInflation(from, seq);

    LedgerDelta delta(app.getLedgerManager().getCurrentLedgerHeader());
    bool res = txFrame->apply(delta, app);

    checkTransaction(*txFrame);
    REQUIRE(InflationOpFrame::getInnerCode(
                txFrame->getResult().result.results()[0]) == result);
    if (res)
    {
        delta.commit();
    }
    return getFirstResult(*txFrame);
}
Exemplo n.º 7
0
PaymentResult
applyCreditPaymentTx(Application& app, SecretKey& from, SecretKey& to,
                     Currency& ci, SequenceNumber seq, int64_t amount,
                     PaymentResultCode result, std::vector<Currency>* path)
{
    TransactionFramePtr txFrame;

    txFrame = createCreditPaymentTx(from, to, ci, seq, amount, path);

    LedgerDelta delta(app.getLedgerManager().getCurrentLedgerHeader());
    txFrame->apply(delta, app);

    checkTransaction(*txFrame);

    auto& firstResult = getFirstResult(*txFrame);

    PaymentResult res = firstResult.tr().paymentResult();
    auto resCode = res.code();
    REQUIRE(resCode == result);
    return res;
}
Exemplo n.º 8
0
void LLFloaterBuyLandUI::draw()
{
	LLFloater::draw();
	
	bool needsUpdate = false;
	needsUpdate |= checkTransaction();
	needsUpdate |= mCurrency.process();
	
	if (mBought)
	{
		closeFloater();
	}
	else if (needsUpdate)
	{
		if (mCanBuy && mCurrency.hasError())
		{
			tellUserError(mCurrency.errorMessage(), mCurrency.errorURI());
		}
		
		refreshUI();
	}
}
Exemplo n.º 9
0
static CreateOfferResult
applyCreateOfferHelper(Application& app, LedgerDelta& delta, uint64 offerId,
                       SecretKey& source, Currency& takerGets,
                       Currency& takerPays, Price const& price, int64_t amount,
                       SequenceNumber seq)
{
    uint64_t expectedOfferID = delta.getHeaderFrame().getLastGeneratedID() + 1;
    if (offerId != 0)
    {
        expectedOfferID = offerId;
    }

    TransactionFramePtr txFrame;

    txFrame = createOfferOp(offerId, source, takerGets, takerPays, price,
                            amount, seq);

    txFrame->apply(delta, app);

    checkTransaction(*txFrame);

    auto& results = txFrame->getResult().result.results();

    REQUIRE(results.size() == 1);

    auto& createOfferResult = results[0].tr().createOfferResult();

    if (createOfferResult.code() == CREATE_OFFER_SUCCESS)
    {
        OfferFrame offer;

        auto& offerResult = createOfferResult.success().offer;
        auto& offerEntry = offer.getOffer();

        switch (offerResult.effect())
        {
        case CREATE_OFFER_CREATED:
        case CREATE_OFFER_UPDATED:
            REQUIRE(OfferFrame::loadOffer(source.getPublicKey(),
                                          expectedOfferID, offer,
                                          app.getDatabase()));
            REQUIRE(memcmp(&offerEntry, &offerResult.offer(),
                           sizeof(OfferEntry)) == 0);
            REQUIRE(offerEntry.price == price);
            REQUIRE(memcmp(&offerEntry.takerGets, &takerGets,
                           sizeof(Currency)) == 0);
            REQUIRE(memcmp(&offerEntry.takerPays, &takerPays,
                           sizeof(Currency)) == 0);
            break;
        case CREATE_OFFER_DELETED:
            REQUIRE(!OfferFrame::loadOffer(source.getPublicKey(),
                                           expectedOfferID, offer,
                                           app.getDatabase()));
            break;
        default:
            abort();
        }
    }

    return createOfferResult;
}
Exemplo n.º 10
0
int ProcessingRestrictions::CheckUsageControl()
{
    DataObject dob_auc; // Application Usage Control
    int res;

    if (InitStatus == EMV_DATA_ERROR)
        return initError;
    if (InitStatus == EMV_DATA_NOT_INITIALIZED)
    {
        if (initData() != SUCCESS)
            return initError;
    }

    res = EnvContext.getTagValue (0x9f07, &dob_auc, true);
    if (res == SUCCESS && dob_auc.len > 0)
    {
        // DO checking according to section 6.4.2, EMV book 3 -
        //  Application Usage Control)

        // Get Terminal Type and additional terminal capabilities
        DataObject dob_termType;
        DataObject dob_addTermCap;
        if ((res = EnvContext.getTagValue (0x9f35, &dob_termType, false))
                != SUCCESS)
            return EMV_MISSING_MANDATORY_DATA;

        if ((res = EnvContext.getTagValue (0x9f40, &dob_addTermCap, false))
                != SUCCESS)
            return EMV_MISSING_MANDATORY_DATA;

        // Check condition 1 (section 6.4.2, EMV book 3)
        if (IsATM(&dob_termType, &dob_addTermCap))
        {
            // Terminal type is ATM
            if (!check_bit(dob_auc.Data[0], 0x02))
            {
                //Appl Usage Control doesn't have 'Valid for ATMs' bit set
                updateDataObject (0x95, &dob_TVR, 2, 0x10);
            }
        }
        else
        {
            // Terminal is not an ATM
            // Check condition 2 (section 6.4.2, EMV book 3)
            if (!check_bit(dob_auc.Data[0], 0x01))
            {
                // Appl Usage Control doesn't have 'Valid for terminals
                // other than ATMs' bit set
                updateDataObject (0x95, &dob_TVR, 2, 0x10);
            }
        }

        // Get Issuer Country Code
        DataObject dob_issCntryCode;
        if ((res = EnvContext.getTagValue (0x5f28, &dob_issCntryCode, true))
                != SUCCESS)
        {
            // Issuer Country code is conditional if Application Usage Control is
            // present. Since it is not found, do not continue with additional
            // checking
            return SUCCESS;
            //return EMV_MISSING_MANDATORY_DATA;
        }

        // Get Transaction Info (tag '60000001' in TransactionTypes). This data type
        // must be initialized during TransactionType initialization
        DataObject dob_transInfo;
        if ((res = EnvContext.getTagValue (0x60000001, &dob_transInfo, true))
                != SUCCESS)
        {
            // Transaction Info is mandatory.
            //Since it is not found, exit the transaction
            return EMV_MISSING_MANDATORY_DATA;
        }

        byte cash = 0x20;
        byte goods = 0x04;
        byte services = 0x08;
        byte cashback = 0x02;

        byte dom_cash = 0x80;
        byte int_cash = 0x40;
        byte dom_goods = 0x20;
        byte int_goods = 0x10;
        byte dom_serv = 0x08;
        byte int_serv = 0x04;
        byte dom_csh_back = 0x80;
        byte int_csh_back = 0x40;

        bool IsCountryCodeMatch = CompareByteArr (dob_issCntryCode.Data,
                                  dob_issCntryCode.len,
                                  dob_TermCountryCode.Data,
                                  dob_TermCountryCode.len);

        if (checkTransaction (dob_transInfo.Data [0],
                              cash, dom_cash, int_cash,
                              dob_auc.Data[0], IsCountryCodeMatch) != SUCCESS)
            return updateDataObject (0x95, &dob_TVR, 2, 0x10);
        if (checkTransaction (dob_transInfo.Data [0],
                              goods, dom_goods, int_goods,
                              dob_auc.Data[0], IsCountryCodeMatch) != SUCCESS)
            return updateDataObject (0x95, &dob_TVR, 2, 0x10);
        if (checkTransaction (dob_transInfo.Data [0],
                              services, dom_serv, int_serv,
                              dob_auc.Data[0], IsCountryCodeMatch) != SUCCESS)
            return updateDataObject (0x95, &dob_TVR, 2, 0x10);
        // Check if cashback amount (Amount Other, tag '9F03') is present
        DataObject dob_cashBack;
        if ((res = EnvContext.getTagValue (0x9f03, &dob_cashBack, true))
                == SUCCESS)
        {
            if (checkTransaction (dob_transInfo.Data [0],
                                  cashback, dom_csh_back,
                                  int_csh_back, dob_auc.Data[1],
                                  IsCountryCodeMatch) != SUCCESS)
                return updateDataObject (0x95, &dob_TVR, 2, 0x10);
        }
    }
    return SUCCESS;

}