/* This file is part of cpp-ethereum. cpp-ethereum is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. cpp-ethereum is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with cpp-ethereum. If not, see . */ /** @file Transaction.h * @author Gav Wood * @date 2014 */ #pragma once #include "CommonEth.h" #include "RLP.h" namespace eth { struct Signature { byte v; u256 r; u256 s; }; // [ nonce, value, baseFee, receiving_address, gas_deposit, [ data byte 0, data byte 1, ... ], v, r, s ] // or // [ nonce, endowment, baseFee, [ storage code 1, storage code 2, ... ], v, r, s ] struct Transaction { Transaction() {} Transaction(bytesConstRef _rlp); Transaction(bytes const& _rlp): Transaction(&_rlp) {} bool operator==(Transaction const& _c) const { return receiveAddress == _c.receiveAddress && value == _c.value && data == _c.data; } 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. 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. // if isCreation: u256s storage; ///< The initial storage of the contract. // 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. 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. static h256 kFromMessage(h256 _msg, h256 _priv); void fillStream(RLPStream& _s, bool _sig = true) const; bytes rlp(bool _sig = true) const { RLPStream s; fillStream(s, _sig); return s.out(); } std::string rlpString(bool _sig = true) const { return asString(rlp(_sig)); } h256 sha3(bool _sig = true) const { RLPStream s; fillStream(s, _sig); return eth::sha3(s.out()); } bytes sha3Bytes(bool _sig = true) const { RLPStream s; fillStream(s, _sig); return eth::sha3Bytes(s.out()); } }; using Transactions = std::vector; inline std::ostream& operator<<(std::ostream& _out, Transaction const& _t) { _out << "{"; if (_t.isCreation) _out << "[CREATE]"; else _out << _t.receiveAddress.abridged(); _out << "/" << _t.nonce << "$" << _t.value << "+" << _t.gas << "@" << _t.gasPrice; Address s; try { _out << "<-" << _t.sender().abridged(); } catch (...) {} _out << "}"; return _out; } }