Ejemplo n.º 1
0
bool MTRecord::DiscardOutgoingCash()
{
    if (!this->CanDiscardOutgoingCash())
        return false;
    // -----------------------------
    return OTAPI_Wrap::Nym_RemoveOutpaymentsByIndex(m_str_nym_id, GetBoxIndex());
}
Ejemplo n.º 2
0
void GetCellPossibilities(int X, int Y, int PuzzleMatrix[9][9], std::vector<int> &CellInfo)
{
    if (PuzzleMatrix[X][Y] != 0) return;

    std::vector<int> Data;
    int BoxMatrix[3][3] = {{0}};
    int RowLineMatrix[9] = {0};
    int ColumnLineMatrix[9] = {0};
    int RowBoxIndex = 0, ColumnBoxIndex = 0;
    GetBoxIndex(X, Y, RowBoxIndex, ColumnBoxIndex);

    ReadRowLine(Y, PuzzleMatrix, RowLineMatrix);
    ReadColumnLine(X, PuzzleMatrix, ColumnLineMatrix);
    ReadBox(RowBoxIndex, ColumnBoxIndex, PuzzleMatrix, BoxMatrix);

    for (int I = 0; I < 9; ++I)
    {
        if (BoxMatrix[I / 3][I % 3] != 0) Data.push_back(BoxMatrix[I / 3][I % 3]);
        if (RowLineMatrix[I] != 0) Data.push_back(RowLineMatrix[I]);
        if (ColumnLineMatrix[I] != 0) Data.push_back(ColumnLineMatrix[I]);
    }

    std::sort(Data.begin(), Data.end());
    Data.erase(std::unique(Data.begin(), Data.end()), Data.end());

    for (int I = 1, J = 0; I < 10; ++I, ++J)
    {
        if (std::find(Data.begin(), Data.end(), I) == Data.end())
        {
            CellInfo.push_back(I);
        }
    }
}
Ejemplo n.º 3
0
// ---------------------------------------
bool MTRecord::CanDiscardOutgoingCash() const  // For OUTgoing cash. (No way to see if it's been accepted, so this lets you erase the record of sending it.)
{
    if (false == this->IsOutgoing())
        return false;

    if (false == this->IsPending())
        return false;

    if (false == this->IsCash())
        return false;

    if (!(GetBoxIndex() >= 0))
        return false;

    return true;
}
Ejemplo n.º 4
0
// ---------------------------------------
// For outgoing, pending (not-yet-accepted) instruments.
//
bool MTRecord::CancelOutgoing(const std::string str_via_acct) // This can be blank if it's a cheque.
{
    if (!this->CanCancelOutgoing())
        return false;

    switch (this->GetRecordType())
    {
        case MTRecord::Instrument:
        {
            if (m_str_nym_id.empty())
            {
                OTLog::vError("%s: Error: missing nym id (%s)\n",
                              __FUNCTION__, m_str_nym_id.c_str());
                return false;
            }

            const OTIdentifier theNymID(m_str_nym_id);
            // ------------------------------
            std::string str_using_acct;

            if (this->IsCheque())
            {
                str_using_acct = m_str_account_id;
            }
            else
            {
                str_using_acct = str_via_acct;
            }
            // ---------------------------------------
            if (str_using_acct.empty())
            {
                OTLog::vError("%s: Error: Missing account ID (FAILURE)\n", __FUNCTION__);
                return false;
            }
            // ------------------------------
            if (0 == m_lTransactionNum)
            {
                if (IsCash())
                {
                    // Maybe it's cash...
                    std::string strOutpayment(OTAPI_Wrap::GetNym_OutpaymentsContentsByIndex(m_str_nym_id, GetBoxIndex()));

                    if (strOutpayment.empty())
                    {
                        long lIndex = static_cast<long>(GetBoxIndex());
                        OTLog::vError("%s: Error: Blank outpayment at index %ld\n", __FUNCTION__, lIndex);
                        return false;
                    }
                    // ------------------------
                    OTString  strPayment(strOutpayment);
                    OTPayment thePayment(strPayment);

                    if (!thePayment.IsValid() || !thePayment.SetTempValues())
                    {
                        long lIndex = static_cast<long>(GetBoxIndex());
                        OTLog::vError("%s: Error: Invalid outpayment at index %ld\n", __FUNCTION__, lIndex);
                        return false;
                    }
                    // ------------------------
                    long lTransNum = 0;
                    thePayment.GetOpeningNum(lTransNum, theNymID);
                    // ------------------------
                    if (0 == lTransNum) // Found it.
                    {
                        long lIndex = static_cast<long>(GetBoxIndex());
                        OTString strIndices;
                        strIndices.Format("%ld", lIndex);
                        const std::string str_indices(strIndices.Get());
                        // ---------------------------------
                        OT_ME madeEasy;

                        return madeEasy.cancel_outgoing_payments(m_str_nym_id, str_using_acct, str_indices);
                    }
                    else
                    {
                        OTLog::vError("%s: Error: Transaction number is non-zero (%ld), for cash outgoing payment for nym id (%s)\n",
                                      __FUNCTION__, lTransNum, m_str_nym_id.c_str());
                        return false;
                    }
                } // IsCash()
                else
                {
                    OTLog::vError("%s: Error: Transaction number is 0, for non-cash outgoing payment for nym id (%s)\n",
                                  __FUNCTION__, m_str_nym_id.c_str());
                    return false;
                }
            }
            // ---------------------------------------
            // Find the payment in the Nym's outpayments box that correlates to this MTRecord.
            //
            int32_t nCount = OTAPI_Wrap::GetNym_OutpaymentsCount(m_str_nym_id);

            for (int32_t nIndex = 0; nIndex < nCount; ++nIndex)
            {
                std::string strOutpayment(OTAPI_Wrap::GetNym_OutpaymentsContentsByIndex(m_str_nym_id, nIndex));

                if (strOutpayment.empty())
                {
                    long lIndex = nIndex;
                    OTLog::vError("%s: Error: Blank outpayment at index %ld\n", __FUNCTION__, lIndex);
                    return false;
                }
                // ------------------------
                OTString  strPayment(strOutpayment);
                OTPayment thePayment(strPayment);

                if (!thePayment.IsValid() || !thePayment.SetTempValues())
                {
                    long lIndex = nIndex;
                    OTLog::vError("%s: Error: Invalid outpayment at index %ld\n", __FUNCTION__, lIndex);
                    return false;
                }
                // ------------------------
                long lTransNum = 0;
                thePayment.GetOpeningNum(lTransNum, theNymID);
                // ------------------------
                if (lTransNum == m_lTransactionNum) // Found it.
                {
                    long lIndex = nIndex;
                    OTString strIndices;
                    strIndices.Format("%ld", lIndex);
                    const std::string str_indices(strIndices.Get());
                    // ---------------------------------
                    OT_ME madeEasy;

                    return madeEasy.cancel_outgoing_payments(m_str_nym_id, str_using_acct, str_indices);
                }
            } // for
            // ---------------------------------------------------
        }
            break;
        // -----------------------------
        default:
            OTLog::vError("%s: Unexpected type: %s\n",
                          __FUNCTION__, this->GetInstrumentType().c_str());
            return false;
    }

    return true;
}