Browse Source

Transaction now supports data/init.

cl-refactor
Gav Wood 11 years ago
parent
commit
85acf4b7b6
  1. 31
      libethereum/Transaction.cpp
  2. 25
      libethereum/Transaction.h

31
libethereum/Transaction.cpp

@ -37,24 +37,17 @@ Transaction::Transaction(bytesConstRef _rlpData)
{
nonce = rlp[field = 0].toInt<u256>();
value = rlp[field = 1].toInt<u256>();
gasPrice = rlp[field = 2].toInt<u256>();
isCreation = rlp[field = 3].isList();
if (isCreation)
receiveAddress = rlp[field = 2].toHash<Address>();
gasPrice = rlp[field = 3].toInt<u256>();
gas = rlp[field = 4].toInt<u256>();
data = rlp[field = 5].toBytes();
if (isCreation())
{
storage.reserve(rlp[field = 3].itemCountStrict());
for (auto const& i: rlp[3])
storage.push_back(i.toInt<u256>());
vrs = Signature{ rlp[field = 4].toInt<byte>(), rlp[field = 5].toInt<u256>(), rlp[field = 6].toInt<u256>() };
init = rlp[field = 6].toBytes();
vrs = Signature{ rlp[field = 7].toInt<byte>(), rlp[field = 8].toInt<u256>(), rlp[field = 9].toInt<u256>() };
}
else
{
receiveAddress = rlp[3].toHash<Address>();
gas = rlp[field = 4].toInt<u256>();
data.reserve(rlp[field = 5].itemCountStrict());
for (auto const& i: rlp[5])
data.push_back(i.toInt<byte>());
vrs = Signature{ rlp[field = 6].toInt<byte>(), rlp[field = 7].toInt<u256>(), rlp[field = 8].toInt<u256>() };
}
}
catch (RLPException const&)
{
@ -126,12 +119,10 @@ void Transaction::sign(Secret _priv)
void Transaction::fillStream(RLPStream& _s, bool _sig) const
{
_s.appendList((_sig ? 3 : 0) + (isCreation ? 4 : 6));
_s << nonce << value << gasPrice;
if (isCreation)
_s << storage;
else
(_s << receiveAddress << gas).appendVector(data);
_s.appendList((_sig ? 3 : 0) + (isCreation() ? 6 : 7));
_s << nonce << value << receiveAddress << gasPrice << gas << data;
if (isCreation())
_s << init;
if (_sig)
_s << vrs.v << vrs.r << vrs.s;
}

25
libethereum/Transaction.h

@ -34,9 +34,9 @@ struct Signature
u256 s;
};
// [ nonce, value, baseFee, receiving_address, gas_deposit, [ data byte 0, data byte 1, ... ], v, r, s ]
// [ nonce, value, receiveAddress, gasPrice, gasDeposit, data, v, r, s ]
// or
// [ nonce, endowment, baseFee, [ storage code 1, storage code 2, ... ], v, r, s ]
// [ nonce, endowment, 0, gasPrice, gasDeposit (for init), body, init, v, r, s ]
struct Transaction
{
Transaction() {}
@ -47,23 +47,22 @@ struct Transaction
bool operator!=(Transaction const& _c) const { return !operator==(_c); }
u256 nonce; ///< The transaction-count of the sender.
bool isCreation; ///< Is this a contract-creation transaction?
u256 value; ///< The amount of ETH to be transferred by this transaction. Called 'endowment' for contract-creation transactions.
Address receiveAddress; ///< The receiving address of the transaction.
u256 gasPrice; ///< The base fee and thus the implied exchange rate of ETH to GAS.
Signature vrs; ///< The signature of the transaction. Encodes the sender.
u256 gas; ///< The total gas to convert, paid for from sender's account. Any unused gas gets refunded once the contract is ended.
// if isCreation:
u256s storage; ///< The initial storage of the contract.
bytes data; ///< The data associated with the transaction, or the main body if it's a creation transaction.
bytes init; ///< The initialisation associated with the transaction.
// if !isCreation:
u256 gas; ///< The total gas to convert, paid for from sender's account. Any unused gas gets refunded once the contract is ended.
Address receiveAddress; ///< The receiving address of the transaction.
bytes data; ///< The data associated with the transaction.
Signature vrs; ///< The signature of the transaction. Encodes the sender.
Address safeSender() const noexcept; ///< Like sender() but will never throw.
Address sender() const; ///< Determine the sender of the transaction from the signature (and hash).
void sign(Secret _priv); ///< Sign the transaction.
bool isCreation() const { return !receiveAddress; }
static h256 kFromMessage(h256 _msg, h256 _priv);
void fillStream(RLPStream& _s, bool _sig = true) const;
@ -78,10 +77,10 @@ using Transactions = std::vector<Transaction>;
inline std::ostream& operator<<(std::ostream& _out, Transaction const& _t)
{
_out << "{";
if (_t.isCreation)
_out << "[CREATE]";
else
if (_t.receiveAddress)
_out << _t.receiveAddress.abridged();
else
_out << "[CREATE]";
_out << "/" << _t.nonce << "$" << _t.value << "+" << _t.gas << "@" << _t.gasPrice;
Address s;

Loading…
Cancel
Save