Exemplo n.º 1
0
SerializedTransaction::SerializedTransaction (SerializerIterator& sit) : STObject (sfTransaction),
    mSigGood (false), mSigBad (false)
{
    int length = sit.getBytesLeft ();

    if ((length < Protocol::txMinSizeBytes) || (length > Protocol::txMaxSizeBytes))
    {
        Log (lsERROR) << "Transaction has invalid length: " << length;
        throw std::runtime_error ("Transaction length invalid");
    }

    set (sit);
    mType = static_cast<TxType> (getFieldU16 (sfTransactionType));

    mFormat = TxFormats::getInstance()->findByType (mType);

    if (!mFormat)
    {
        WriteLog (lsWARNING, SerializedTransaction) << "Transaction type: " << mType;
        throw std::runtime_error ("invalid transaction type");
    }

    if (!setType (mFormat->elements))
    {
        WriteLog (lsWARNING, SerializedTransaction) << "Transaction not legal for format";
        throw std::runtime_error ("transaction not valid");
    }
}
Exemplo n.º 2
0
STTx::STTx (SerialIter& sit)
    : STObject (sfTransaction)
    , sig_state_ (boost::indeterminate)
{
    int length = sit.getBytesLeft ();

    if ((length < Protocol::txMinSizeBytes) || (length > Protocol::txMaxSizeBytes))
    {
        WriteLog (lsERROR, STTx) <<
            "Transaction has invalid length: " << length;
        throw std::runtime_error ("Transaction length invalid");
    }

    set (sit);
    tx_type_ = static_cast<TxType> (getFieldU16 (sfTransactionType));

    auto format = TxFormats::getInstance().findByType (tx_type_);

    if (!format)
    {
        WriteLog (lsWARNING, STTx) <<
            "Invalid transaction type: " << tx_type_;
        throw std::runtime_error ("invalid transaction type");
    }

    if (!setType (format->elements))
    {
        WriteLog (lsWARNING, STTx) <<
            "Transaction not legal for format";
        throw std::runtime_error ("transaction not valid");
    }
}
Exemplo n.º 3
0
STTx::STTx (STObject&& object)
    : STObject (std::move (object))
{
    tx_type_ = static_cast <TxType> (getFieldU16 (sfTransactionType));

    if (!setType (getTxFormat (tx_type_)->elements))
        Throw<std::runtime_error> ("transaction not valid");

    tid_ = getHash(HashPrefix::transactionID);
}
Exemplo n.º 4
0
STTx::STTx (SerialIter& sit)
    : STObject (sfTransaction)
{
    int length = sit.getBytesLeft ();

    if ((length < txMinSizeBytes) || (length > txMaxSizeBytes))
        Throw<std::runtime_error> ("Transaction length invalid");

    set (sit);
    tx_type_ = static_cast<TxType> (getFieldU16 (sfTransactionType));

    if (!setType (getTxFormat (tx_type_)->elements))
        Throw<std::runtime_error> ("transaction not valid");

    tid_ = getHash(HashPrefix::transactionID);
}
Exemplo n.º 5
0
void STLedgerEntry::setSLEType ()
{
    mFormat = LedgerFormats::getInstance().findByType (
        static_cast <LedgerEntryType> (getFieldU16 (sfLedgerEntryType)));

    if (mFormat == nullptr)
        throw std::runtime_error ("invalid ledger entry type");

    type_ = mFormat->getType ();
    if (!setType (mFormat->elements))
    {
        WriteLog (lsWARNING, SerializedLedger)
            << "Ledger entry not valid for type " << mFormat->getName ();
        WriteLog (lsWARNING, SerializedLedger) << getJson (0);
        throw std::runtime_error ("ledger entry not valid for type");
    }
}
Exemplo n.º 6
0
SerializedLedgerEntry::SerializedLedgerEntry (SerializerIterator& sit, uint256 const& index)
    : STObject (sfLedgerEntry), mIndex (index), mMutable (true)
{
    set (sit);
    uint16 type = getFieldU16 (sfLedgerEntryType);
    
    LedgerFormats::Item const* const item =
        LedgerFormats::getInstance()->findByType (static_cast <LedgerEntryType> (type));
    
    if (item == nullptr)
        throw std::runtime_error ("invalid ledger entry type");

    mType = item->getType ();

    if (!setType (item->elements))
        throw std::runtime_error ("ledger entry not valid for type");
}
Exemplo n.º 7
0
STTx::STTx (
        TxType type,
        std::function<void(STObject&)> assembler)
    : STObject (sfTransaction)
{
    auto format = getTxFormat (type);

    set (format->elements);
    setFieldU16 (sfTransactionType, format->getType ());

    assembler (*this);

    tx_type_ = static_cast<TxType>(getFieldU16 (sfTransactionType));

    if (tx_type_ != type)
        LogicError ("Transaction type was mutated during assembly");

    tid_ = getHash(HashPrefix::transactionID);
}
Exemplo n.º 8
0
SerializedTransaction::SerializedTransaction (STObject const& object)
    : STObject (object)
    , mSigGood (false)
    , mSigBad (false)
{
    mType = static_cast <TxType> (getFieldU16 (sfTransactionType));

    mFormat = TxFormats::getInstance()->findByType (mType);

    if (!mFormat)
    {
        WriteLog (lsWARNING, SerializedTransaction) << "Transaction type: " << mType;
        throw std::runtime_error ("invalid transaction type");
    }

    if (!setType (mFormat->elements))
    {
        throw std::runtime_error ("transaction not valid");
    }
}
Exemplo n.º 9
0
void STLedgerEntry::setSLEType ()
{
    mFormat = LedgerFormats::getInstance().findByType (
        static_cast <LedgerEntryType> (getFieldU16 (sfLedgerEntryType)));

    if (mFormat == nullptr)
        Throw<std::runtime_error> ("invalid ledger entry type");

    type_ = mFormat->getType ();
    if (!setType (mFormat->elements))
    {
        if (auto j = debugLog().error())
        {
            j << "Ledger entry not valid for type " << mFormat->getName ();
            j << "Object: " << getJson (0);
        }

        Throw<std::runtime_error> ("ledger entry not valid for type");
    }
}
Exemplo n.º 10
0
STTx::STTx (STObject&& object)
    : STObject (std::move (object))
{
    tx_type_ = static_cast <TxType> (getFieldU16 (sfTransactionType));

    auto format = TxFormats::getInstance().findByType (tx_type_);

    if (!format)
    {
        WriteLog (lsWARNING, STTx) <<
            "Transaction type: " << tx_type_;
        throw std::runtime_error ("invalid transaction type");
    }

    if (!setType (format->elements))
    {
        WriteLog (lsWARNING, STTx) <<
            "Transaction not legal for format";
        throw std::runtime_error ("transaction not valid");
    }
}
Exemplo n.º 11
0
SerializedLedgerEntry::SerializedLedgerEntry (const Serializer& s, uint256 const& index)
    : STObject (sfLedgerEntry), mIndex (index), mMutable (true)
{
    SerializerIterator sit (const_cast<Serializer&> (s)); // we know 's' isn't going away
    set (sit);

    uint16 type = getFieldU16 (sfLedgerEntryType);

    LedgerFormats::Item const* const item =
        LedgerFormats::getInstance()->findByType (static_cast <LedgerEntryType> (type));

    if (item == nullptr)
        throw std::runtime_error ("invalid ledger entry type");

    mType = item->getType ();

    if (!setType (item->elements))
    {
        WriteLog (lsWARNING, SerializedLedgerLog) << "Ledger entry not valid for type " << mFormat->getName ();
        WriteLog (lsWARNING, SerializedLedgerLog) << getJson (0);
        throw std::runtime_error ("ledger entry not valid for type");
    }
}