Herder::TransactionSubmitStatus
LoadGenerator::TxInfo::execute(Application& app, bool isCreate,
                               TransactionResultCode& code, int32_t batchSize)
{
    auto seqNum = mFrom->getLastSequenceNumber();
    mFrom->setSequenceNumber(seqNum + 1);

    TransactionFramePtr txf =
        transactionFromOperations(app, mFrom->getSecretKey(), seqNum + 1, mOps);
    TxMetrics txm(app.getMetrics());

    // Record tx metrics.
    if (isCreate)
    {
        while (batchSize--)
        {
            txm.mAccountCreated.Mark();
        }
    }
    else
    {
        txm.mPayment.Mark();
        txm.mNativePayment.Mark();
    }
    txm.mTxnAttempted.Mark();

    StellarMessage msg;
    msg.type(TRANSACTION);
    msg.transaction() = txf->getEnvelope();
    txm.mTxnBytes.Mark(xdr::xdr_argpack_size(msg));

    auto status = app.getHerder().recvTransaction(txf);
    if (status != Herder::TX_STATUS_PENDING)
    {
        CLOG(INFO, "LoadGen")
            << "tx rejected '" << Herder::TX_STATUS_STRING[status]
            << "': " << xdr::xdr_to_string(txf->getEnvelope()) << " ===> "
            << xdr::xdr_to_string(txf->getResult());
        if (status == Herder::TX_STATUS_ERROR)
        {
            code = txf->getResultCode();
        }
        txm.mTxnRejected.Mark();
    }
    else
    {
        app.getOverlayManager().broadcastMessage(msg);
    }

    return status;
}
Exemple #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);
}
Exemple #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);
}
Exemple #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);
}
Exemple #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);
    }
}
Exemple #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);
}
void
CommandHandler::testTx(std::string const& params, std::string& retStr)
{
    std::map<std::string, std::string> retMap;
    http::server::server::parseParams(params, retMap);

    auto to = retMap.find("to");
    auto from = retMap.find("from");
    auto amount = retMap.find("amount");
    auto create = retMap.find("create");

    Json::Value root;

    if (to != retMap.end() && from != retMap.end() && amount != retMap.end())
    {
        Hash const& networkID = mApp.getNetworkID();

        SecretKey toKey, fromKey;
        if (to->second == "root")
        {
            toKey = getRoot(networkID);
        }
        else
        {
            toKey = getAccount(to->second.c_str());
        }

        if (from->second == "root")
        {
            fromKey = getRoot(networkID);
        }
        else
        {
            fromKey = getAccount(from->second.c_str());
        }

        uint64_t paymentAmount = 0;
        std::istringstream iss(amount->second);
        iss >> paymentAmount;

        root["from_name"] = from->second;
        root["to_name"] = to->second;
        root["from_id"] = PubKeyUtils::toStrKey(fromKey.getPublicKey());
        root["to_id"] = PubKeyUtils::toStrKey(toKey.getPublicKey());
        ;
        root["amount"] = (Json::UInt64)paymentAmount;

        SequenceNumber fromSeq = getSeq(fromKey, mApp) + 1;

        TransactionFramePtr txFrame;
        if (create != retMap.end() && create->second == "true")
        {
            txFrame = createCreateAccountTx(networkID, fromKey, toKey, fromSeq,
                                            paymentAmount);
        }
        else
        {
            txFrame = createPaymentTx(networkID, fromKey, toKey, fromSeq,
                                      paymentAmount);
        }

        switch (mApp.getHerder().recvTransaction(txFrame))
        {
        case Herder::TX_STATUS_PENDING:
            root["status"] = "pending";
            break;
        case Herder::TX_STATUS_DUPLICATE:
            root["status"] = "duplicate";
            break;
        case Herder::TX_STATUS_ERROR:
            root["status"] = "error";
            root["detail"] =
                xdr::xdr_to_string(txFrame->getResult().result.code());
            break;
        default:
            assert(false);
        }
    }
Exemple #8
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;
}