From 4ec30f961e438417f813fa3874ceb83542730207 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 7 Jul 2015 18:57:39 +0200 Subject: [PATCH 1/6] LocalisedTransaction && LocalisedTransactionReceipt --- libethereum/Client.cpp | 2 +- libethereum/ClientBase.cpp | 2 +- libethereum/Transaction.h | 24 ++++++++++++++++ libethereum/TransactionReceipt.h | 48 ++++++++++++++++++++++++++++++++ libevm/ExtVMFace.h | 19 +++++++------ 5 files changed, 84 insertions(+), 11 deletions(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index fba8d51fa..db4578285 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -429,7 +429,7 @@ void Client::appendFromNewBlock(h256 const& _block, h256Hash& io_changed) auto transactionHash = transaction(d.hash(), j).sha3(); // filter catches them for (LogEntry const& l: m) - i.second.changes.push_back(LocalisedLogEntry(l, d, transactionHash, j, logIndex)); + i.second.changes.push_back(LocalisedLogEntry(l, d.hash(), (BlockNumber)d.number, transactionHash, j, logIndex)); io_changed.insert(i.first); } } diff --git a/libethereum/ClientBase.cpp b/libethereum/ClientBase.cpp index 2cef62680..6483f6c0c 100644 --- a/libethereum/ClientBase.cpp +++ b/libethereum/ClientBase.cpp @@ -203,7 +203,7 @@ LocalisedLogEntries ClientBase::logs(LogFilter const& _f) const { total += le.size(); for (unsigned j = 0; j < le.size(); ++j) - ret.insert(ret.begin(), LocalisedLogEntry(le[j], info, th, i, logIndex)); + ret.insert(ret.begin(), LocalisedLogEntry(le[j], info.hash(), (BlockNumber)info.number, th, i, logIndex)); } } diff --git a/libethereum/Transaction.h b/libethereum/Transaction.h index 8ed0043c9..d29e9837e 100644 --- a/libethereum/Transaction.h +++ b/libethereum/Transaction.h @@ -130,5 +130,29 @@ private: /// Nice name for vector of Transaction. using Transactions = std::vector; +class LocalisedTransaction: public Transaction +{ +public: + LocalisedTransaction( + Transaction const& _t, + std::pair const& _location, + BlockNumber _blockNumber + ): + Transaction(_t), + m_blockHash(_location.first), + m_blockNumber(_blockNumber), + m_transactionIndex(_location.second) + {} + + h256 const& blockHash() const { return m_blockHash; } + BlockNumber blockNumber() const { return m_blockNumber; } + unsigned transactionIndex() const { return m_transactionIndex; } + +private: + h256 m_blockHash; + BlockNumber m_blockNumber; + unsigned m_transactionIndex; +}; + } } diff --git a/libethereum/TransactionReceipt.h b/libethereum/TransactionReceipt.h index 0a0b154f4..8c102611a 100644 --- a/libethereum/TransactionReceipt.h +++ b/libethereum/TransactionReceipt.h @@ -58,5 +58,53 @@ using TransactionReceipts = std::vector; std::ostream& operator<<(std::ostream& _out, eth::TransactionReceipt const& _r); +class LocalisedTransactionReceipt: public TransactionReceipt +{ +public: + LocalisedTransactionReceipt( + TransactionReceipt const& _t, + h256 const& _hash, + h256 const& _blockHash, + BlockNumber _blockNumber, + unsigned _transactionIndex, + Address const& _contractAddress = Address() + ): + TransactionReceipt(_t), + m_hash(_hash), + m_blockHash(_blockHash), + m_blockNumber(_blockNumber), + m_transactionIndex(_transactionIndex), + m_contractAddress(_contractAddress) + {} + + h256 const& hash() const { return m_hash; } + h256 const& blockHash() const { return m_blockHash; } + BlockNumber blockNumber() const { return m_blockNumber; } + unsigned transactionIndex() const { return m_transactionIndex; } + Address const& contractAddress() const { return m_contractAddress; } + + LocalisedLogEntries localisedLogs() const + { + LocalisedLogEntries localisedEntries; + LogEntries entries = log(); + for (unsigned i = 0; i < entries.size(); i++) + localisedEntries.push_back(LocalisedLogEntry( + entries[i], + m_blockHash, + m_blockNumber, + m_hash, + m_transactionIndex, + i)); + return localisedEntries; + }; + +private: + h256 m_hash; + h256 m_blockHash; + BlockNumber m_blockNumber; + unsigned m_transactionIndex; + Address m_contractAddress; +}; + } } diff --git a/libevm/ExtVMFace.h b/libevm/ExtVMFace.h index 94c8e2fef..6b40b4101 100644 --- a/libevm/ExtVMFace.h +++ b/libevm/ExtVMFace.h @@ -76,17 +76,18 @@ struct LocalisedLogEntry: public LogEntry explicit LocalisedLogEntry( LogEntry const& _le, - BlockInfo const& _bi, - h256 _th, - unsigned _ti, - unsigned _li + h256 const& _blockHash, + BlockNumber _blockNumber, + h256 const& _transactionHash, + unsigned _transactionIndex, + unsigned _logIndex ): LogEntry(_le), - blockHash(_bi.hash()), - blockNumber((BlockNumber)_bi.number), - transactionHash(_th), - transactionIndex(_ti), - logIndex(_li), + blockHash(_blockHash), + blockNumber(_blockNumber), + transactionHash(_transactionHash), + transactionIndex(_transactionIndex), + logIndex(_logIndex), mined(true) {} From e961867fdfa87ac78f1e69ad76768b5741a29f35 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Wed, 8 Jul 2015 10:09:29 +0200 Subject: [PATCH 2/6] LocalisedTransactionReceipt in ClientBase and WebThreeStubServerBase --- libethereum/BlockChain.h | 5 +++- libethereum/ClientBase.cpp | 14 ++++++++++ libethereum/ClientBase.h | 1 + libethereum/Interface.h | 1 + libethereum/TransactionReceipt.h | 28 ++++++++++---------- libweb3jsonrpc/JsonHelper.cpp | 31 +++++++---------------- libweb3jsonrpc/JsonHelper.h | 3 +-- libweb3jsonrpc/WebThreeStubServerBase.cpp | 3 +-- 8 files changed, 44 insertions(+), 42 deletions(-) diff --git a/libethereum/BlockChain.h b/libethereum/BlockChain.h index 4cffca2df..987d605ce 100644 --- a/libethereum/BlockChain.h +++ b/libethereum/BlockChain.h @@ -142,8 +142,11 @@ public: BlockReceipts receipts(h256 const& _hash) const { return queryExtras(_hash, m_receipts, x_receipts, NullBlockReceipts); } BlockReceipts receipts() const { return receipts(currentHash()); } + /// Get the transaction by block hash and index; + TransactionReceipt transactionReceipt(h256 const& _blockHash, unsigned _i) const {return receipts(_blockHash).receipts[_i]; } + /// Get the transaction receipt by transaction hash. Thread-safe. - TransactionReceipt transactionReceipt(h256 const& _transactionHash) const {TransactionAddress ta = queryExtras(_transactionHash, m_transactionAddresses, x_transactionAddresses, NullTransactionAddress); if (!ta) return bytesConstRef(); return receipts(ta.blockHash).receipts[ta.index]; } + TransactionReceipt transactionReceipt(h256 const& _transactionHash) const {TransactionAddress ta = queryExtras(_transactionHash, m_transactionAddresses, x_transactionAddresses, NullTransactionAddress); if (!ta) return bytesConstRef(); return transactionReceipt(ta.blockHash, ta.index); } /// Get a list of transaction hashes for a given block. Thread-safe. TransactionHashes transactionHashes(h256 const& _hash) const { auto b = block(_hash); RLP rlp(b); h256s ret; for (auto t: rlp[1]) ret.push_back(sha3(t.data())); return ret; } diff --git a/libethereum/ClientBase.cpp b/libethereum/ClientBase.cpp index 6483f6c0c..66ecfc2b4 100644 --- a/libethereum/ClientBase.cpp +++ b/libethereum/ClientBase.cpp @@ -332,6 +332,20 @@ TransactionReceipt ClientBase::transactionReceipt(h256 const& _transactionHash) return bc().transactionReceipt(_transactionHash); } +LocalisedTransactionReceipt ClientBase::localisedTransactionReceipt(h256 const& _transactionHash) const +{ + std::pair tl = bc().transactionLocation(_transactionHash); + Transaction t = Transaction(bc().transaction(tl.first, tl.second), CheckTransaction::Cheap); + TransactionReceipt tr = bc().transactionReceipt(tl.first, tl.second); + return LocalisedTransactionReceipt( + tr, + t.sha3(), + tl.first, + numberFromHash(tl.first), + tl.second, + toAddress(t.from(), t.nonce())); +} + pair ClientBase::transactionLocation(h256 const& _transactionHash) const { return bc().transactionLocation(_transactionHash); diff --git a/libethereum/ClientBase.h b/libethereum/ClientBase.h index 05766b3a1..e8795abd2 100644 --- a/libethereum/ClientBase.h +++ b/libethereum/ClientBase.h @@ -120,6 +120,7 @@ public: virtual Transaction transaction(h256 _transactionHash) const override; virtual Transaction transaction(h256 _blockHash, unsigned _i) const override; virtual TransactionReceipt transactionReceipt(h256 const& _transactionHash) const override; + virtual LocalisedTransactionReceipt localisedTransactionReceipt(h256 const& _transactionHash) const override; virtual std::pair transactionLocation(h256 const& _transactionHash) const override; virtual Transactions transactions(h256 _blockHash) const override; virtual TransactionHashes transactionHashes(h256 _blockHash) const override; diff --git a/libethereum/Interface.h b/libethereum/Interface.h index c65670a30..07758851c 100644 --- a/libethereum/Interface.h +++ b/libethereum/Interface.h @@ -136,6 +136,7 @@ public: virtual bool isKnownTransaction(h256 const& _transactionHash) const = 0; virtual Transaction transaction(h256 _transactionHash) const = 0; virtual TransactionReceipt transactionReceipt(h256 const& _transactionHash) const = 0; + virtual LocalisedTransactionReceipt localisedTransactionReceipt(h256 const& _transactionHash) const = 0; virtual std::pair transactionLocation(h256 const& _transactionHash) const = 0; virtual h256 hashFromNumber(BlockNumber _number) const = 0; virtual BlockNumber numberFromHash(h256 _blockHash) const = 0; diff --git a/libethereum/TransactionReceipt.h b/libethereum/TransactionReceipt.h index 8c102611a..ceb1123b5 100644 --- a/libethereum/TransactionReceipt.h +++ b/libethereum/TransactionReceipt.h @@ -75,35 +75,33 @@ public: m_blockNumber(_blockNumber), m_transactionIndex(_transactionIndex), m_contractAddress(_contractAddress) - {} - - h256 const& hash() const { return m_hash; } - h256 const& blockHash() const { return m_blockHash; } - BlockNumber blockNumber() const { return m_blockNumber; } - unsigned transactionIndex() const { return m_transactionIndex; } - Address const& contractAddress() const { return m_contractAddress; } - - LocalisedLogEntries localisedLogs() const { - LocalisedLogEntries localisedEntries; LogEntries entries = log(); for (unsigned i = 0; i < entries.size(); i++) - localisedEntries.push_back(LocalisedLogEntry( + m_localisedLogs.push_back(LocalisedLogEntry( entries[i], m_blockHash, m_blockNumber, m_hash, m_transactionIndex, - i)); - return localisedEntries; - }; + i + )); + } + + h256 const& hash() const { return m_hash; } + h256 const& blockHash() const { return m_blockHash; } + BlockNumber blockNumber() const { return m_blockNumber; } + unsigned transactionIndex() const { return m_transactionIndex; } + Address const& contractAddress() const { return m_contractAddress; } + LocalisedLogEntries const& localisedLogs() const { return m_localisedLogs; }; private: h256 m_hash; h256 m_blockHash; BlockNumber m_blockNumber; - unsigned m_transactionIndex; + unsigned m_transactionIndex = 0; Address m_contractAddress; + LocalisedLogEntries m_localisedLogs; }; } diff --git a/libweb3jsonrpc/JsonHelper.cpp b/libweb3jsonrpc/JsonHelper.cpp index 96312f625..34ab5ad7f 100644 --- a/libweb3jsonrpc/JsonHelper.cpp +++ b/libweb3jsonrpc/JsonHelper.cpp @@ -182,30 +182,17 @@ Json::Value toJson(dev::eth::TransactionReceipt const& _t) return res; } -Json::Value toJson(dev::eth::TransactionReceipt const& _tr, std::pair _location, BlockNumber _blockNumber, Transaction const& _t) +Json::Value toJson(dev::eth::LocalisedTransactionReceipt const& _t) { Json::Value res; - h256 h = _t.sha3(); - res["transactionHash"] = toJS(h); - res["transactionIndex"] = _location.second; - res["blockHash"] = toJS(_location.first); - res["blockNumber"] = _blockNumber; - res["cumulativeGasUsed"] = toJS(_tr.gasUsed()); // TODO: check if this is fine - res["gasUsed"] = toJS(_tr.gasUsed()); - res["contractAddress"] = toJS(toAddress(_t.from(), _t.nonce())); - res["logs"] = Json::Value(Json::arrayValue); - for (unsigned i = 0; i < _tr.log().size(); i++) - { - LogEntry e = _tr.log()[i]; - Json::Value l = toJson(e); - l["type"] = "mined"; - l["blockNumber"] = _blockNumber; - l["blockHash"] = toJS(_location.first); - l["logIndex"] = i; - l["transactionHash"] = toJS(h); - l["transactionIndex"] = _location.second; - res["logs"].append(l); - } + res["transactionHash"] = toJS(_t.hash()); + res["transactionIndex"] = _t.transactionIndex(); + res["blockHash"] = toJS(_t.blockHash()); + res["blockNumber"] = _t.blockNumber(); + res["cumulativeGasUsed"] = toJS(_t.gasUsed()); // TODO: check if this is fine + res["gasUsed"] = toJS(_t.gasUsed()); + res["contractAddress"] = toJS(_t.contractAddress()); + res["logs"] = dev::toJson(_t.localisedLogs()); return res; } diff --git a/libweb3jsonrpc/JsonHelper.h b/libweb3jsonrpc/JsonHelper.h index 421d11b78..8e42cf77a 100644 --- a/libweb3jsonrpc/JsonHelper.h +++ b/libweb3jsonrpc/JsonHelper.h @@ -57,8 +57,7 @@ Json::Value toJson(BlockInfo const& _bi, BlockDetails const& _bd, UncleHashes co Json::Value toJson(TransactionSkeleton const& _t); Json::Value toJson(Transaction const& _t); Json::Value toJson(TransactionReceipt const& _t); -//TODO: wrap these params into one structure eg. "LocalisedTransactionReceipt" -Json::Value toJson(TransactionReceipt const& _tr, std::pair _location, BlockNumber _blockNumber, Transaction const& _t); +Json::Value toJson(LocalisedTransactionReceipt const& _t); Json::Value toJson(LocalisedLogEntry const& _e); Json::Value toJson(LogEntry const& _e); TransactionSkeleton toTransactionSkeleton(Json::Value const& _json); diff --git a/libweb3jsonrpc/WebThreeStubServerBase.cpp b/libweb3jsonrpc/WebThreeStubServerBase.cpp index 166fbb1bb..fd1555161 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.cpp +++ b/libweb3jsonrpc/WebThreeStubServerBase.cpp @@ -427,8 +427,7 @@ Json::Value WebThreeStubServerBase::eth_getTransactionReceipt(string const& _tra if (!client()->isKnownTransaction(h)) return Json::Value(Json::nullValue); - auto l = client()->transactionLocation(h); - return toJson(client()->transactionReceipt(h), l, client()->numberFromHash(l.first), client()->transaction(h)); + return toJson(client()->localisedTransactionReceipt(h)); } catch (...) { From 7beb78413ce98c38f5d20984adca97f95a8a8b39 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Wed, 8 Jul 2015 10:40:54 +0200 Subject: [PATCH 3/6] LocalisedTransaction in ClientBase and WebThreeStubServerBase --- libethereum/ClientBase.cpp | 12 ++++++++++++ libethereum/ClientBase.h | 2 ++ libethereum/Interface.h | 2 ++ libethereum/Transaction.h | 9 +++++---- libweb3jsonrpc/JsonHelper.cpp | 20 ++++++++++++++++++++ libweb3jsonrpc/JsonHelper.h | 2 ++ libweb3jsonrpc/WebThreeStubServerBase.cpp | 9 +++------ 7 files changed, 46 insertions(+), 10 deletions(-) diff --git a/libethereum/ClientBase.cpp b/libethereum/ClientBase.cpp index 66ecfc2b4..141556411 100644 --- a/libethereum/ClientBase.cpp +++ b/libethereum/ClientBase.cpp @@ -317,6 +317,12 @@ Transaction ClientBase::transaction(h256 _transactionHash) const return Transaction(bc().transaction(_transactionHash), CheckTransaction::Cheap); } +LocalisedTransaction ClientBase::localisedTransaction(h256 _transactionHash) const +{ + std::pair tl = bc().transactionLocation(_transactionHash); + return localisedTransaction(tl.first, tl.second); +} + Transaction ClientBase::transaction(h256 _blockHash, unsigned _i) const { auto bl = bc().block(_blockHash); @@ -327,6 +333,12 @@ Transaction ClientBase::transaction(h256 _blockHash, unsigned _i) const return Transaction(); } +LocalisedTransaction ClientBase::localisedTransaction(h256 _blockHash, unsigned _i) const +{ + Transaction t = Transaction(bc().transaction(_blockHash, _i), CheckTransaction::Cheap); + return LocalisedTransaction(t, _blockHash, numberFromHash(_blockHash), _i); +} + TransactionReceipt ClientBase::transactionReceipt(h256 const& _transactionHash) const { return bc().transactionReceipt(_transactionHash); diff --git a/libethereum/ClientBase.h b/libethereum/ClientBase.h index e8795abd2..d0fbb4151 100644 --- a/libethereum/ClientBase.h +++ b/libethereum/ClientBase.h @@ -118,7 +118,9 @@ public: virtual BlockInfo blockInfo(h256 _hash) const override; virtual BlockDetails blockDetails(h256 _hash) const override; virtual Transaction transaction(h256 _transactionHash) const override; + virtual LocalisedTransaction localisedTransaction(h256 _transactionHash) const override; virtual Transaction transaction(h256 _blockHash, unsigned _i) const override; + virtual LocalisedTransaction localisedTransaction(h256 _blockHash, unsigned _i) const override; virtual TransactionReceipt transactionReceipt(h256 const& _transactionHash) const override; virtual LocalisedTransactionReceipt localisedTransactionReceipt(h256 const& _transactionHash) const override; virtual std::pair transactionLocation(h256 const& _transactionHash) const override; diff --git a/libethereum/Interface.h b/libethereum/Interface.h index 07758851c..0f1c5f2a3 100644 --- a/libethereum/Interface.h +++ b/libethereum/Interface.h @@ -135,6 +135,7 @@ public: virtual bool isKnownTransaction(h256 const& _transactionHash) const = 0; virtual Transaction transaction(h256 _transactionHash) const = 0; + virtual LocalisedTransaction localisedTransaction(h256 _transactionHash) const = 0; virtual TransactionReceipt transactionReceipt(h256 const& _transactionHash) const = 0; virtual LocalisedTransactionReceipt localisedTransactionReceipt(h256 const& _transactionHash) const = 0; virtual std::pair transactionLocation(h256 const& _transactionHash) const = 0; @@ -147,6 +148,7 @@ public: virtual BlockInfo blockInfo(h256 _hash) const = 0; virtual BlockDetails blockDetails(h256 _hash) const = 0; virtual Transaction transaction(h256 _blockHash, unsigned _i) const = 0; + virtual LocalisedTransaction localisedTransaction(h256 _blockHash, unsigned _i) const = 0; virtual BlockInfo uncle(h256 _blockHash, unsigned _i) const = 0; virtual UncleHashes uncleHashes(h256 _blockHash) const = 0; virtual unsigned transactionCount(h256 _blockHash) const = 0; diff --git a/libethereum/Transaction.h b/libethereum/Transaction.h index d29e9837e..2332a6fdb 100644 --- a/libethereum/Transaction.h +++ b/libethereum/Transaction.h @@ -135,13 +135,14 @@ class LocalisedTransaction: public Transaction public: LocalisedTransaction( Transaction const& _t, - std::pair const& _location, - BlockNumber _blockNumber + h256 const& _blockHash, + BlockNumber _blockNumber, + unsigned _transactionIndex ): Transaction(_t), - m_blockHash(_location.first), + m_blockHash(_blockHash), m_blockNumber(_blockNumber), - m_transactionIndex(_location.second) + m_transactionIndex(_transactionIndex) {} h256 const& blockHash() const { return m_blockHash; } diff --git a/libweb3jsonrpc/JsonHelper.cpp b/libweb3jsonrpc/JsonHelper.cpp index 34ab5ad7f..ab976eddd 100644 --- a/libweb3jsonrpc/JsonHelper.cpp +++ b/libweb3jsonrpc/JsonHelper.cpp @@ -214,6 +214,26 @@ Json::Value toJson(dev::eth::Transaction const& _t) return res; } +Json::Value toJson(dev::eth::LocalisedTransaction const& _t) +{ + Json::Value res; + if (_t) + { + res["hash"] = toJS(_t.sha3()); + res["input"] = toJS(_t.data()); + res["to"] = _t.isCreation() ? Json::Value() : toJS(_t.receiveAddress()); + res["from"] = toJS(_t.safeSender()); + res["gas"] = toJS(_t.gas()); + res["gasPrice"] = toJS(_t.gasPrice()); + res["nonce"] = toJS(_t.nonce()); + res["value"] = toJS(_t.value()); + res["blockHash"] = toJS(_t.blockHash()); + res["transactionIndex"] = toJS(_t.transactionIndex()); + res["blockNumber"] = toJS(_t.blockNumber()); + } + return res; +} + Json::Value toJson(dev::eth::LocalisedLogEntry const& _e) { Json::Value res; diff --git a/libweb3jsonrpc/JsonHelper.h b/libweb3jsonrpc/JsonHelper.h index 8e42cf77a..3c652db7a 100644 --- a/libweb3jsonrpc/JsonHelper.h +++ b/libweb3jsonrpc/JsonHelper.h @@ -43,6 +43,7 @@ namespace eth { class Transaction; +class LocalisedTransaction; struct BlockDetails; class Interface; using Transactions = std::vector; @@ -56,6 +57,7 @@ Json::Value toJson(BlockInfo const& _bi, BlockDetails const& _bd, UncleHashes co Json::Value toJson(BlockInfo const& _bi, BlockDetails const& _bd, UncleHashes const& _us, TransactionHashes const& _ts); Json::Value toJson(TransactionSkeleton const& _t); Json::Value toJson(Transaction const& _t); +Json::Value toJson(LocalisedTransaction const& _t); Json::Value toJson(TransactionReceipt const& _t); Json::Value toJson(LocalisedTransactionReceipt const& _t); Json::Value toJson(LocalisedLogEntry const& _e); diff --git a/libweb3jsonrpc/WebThreeStubServerBase.cpp b/libweb3jsonrpc/WebThreeStubServerBase.cpp index fd1555161..f91d29ea7 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.cpp +++ b/libweb3jsonrpc/WebThreeStubServerBase.cpp @@ -380,8 +380,7 @@ Json::Value WebThreeStubServerBase::eth_getTransactionByHash(string const& _tran if (!client()->isKnownTransaction(h)) return Json::Value(Json::nullValue); - auto l = client()->transactionLocation(h); - return toJson(client()->transaction(h), l, client()->numberFromHash(l.first)); + return toJson(client()->localisedTransaction(h)); } catch (...) { @@ -395,8 +394,7 @@ Json::Value WebThreeStubServerBase::eth_getTransactionByBlockHashAndIndex(string { h256 bh = jsToFixed<32>(_blockHash); unsigned ti = jsToInt(_transactionIndex); - Transaction t = client()->transaction(bh, ti); - return toJson(t, make_pair(bh, ti), client()->numberFromHash(bh)); + return toJson(client()->localisedTransaction(bh, ti)); } catch (...) { @@ -410,8 +408,7 @@ Json::Value WebThreeStubServerBase::eth_getTransactionByBlockNumberAndIndex(stri { BlockNumber bn = jsToBlockNumber(_blockNumber); unsigned ti = jsToInt(_transactionIndex); - Transaction t = client()->transaction(bn, ti); - return toJson(t, make_pair(client()->hashFromNumber(bn), ti), bn); + return toJson(client()->localisedTransaction(client()->hashFromNumber(bn), ti)); } catch (...) { From a5e31dc4e754a18784e27e4caba6c55db8318b3f Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Wed, 8 Jul 2015 10:45:41 +0200 Subject: [PATCH 4/6] style fixes --- libethereum/Transaction.h | 2 +- libethereum/TransactionReceipt.h | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libethereum/Transaction.h b/libethereum/Transaction.h index 2332a6fdb..b13630f6a 100644 --- a/libethereum/Transaction.h +++ b/libethereum/Transaction.h @@ -137,7 +137,7 @@ public: Transaction const& _t, h256 const& _blockHash, BlockNumber _blockNumber, - unsigned _transactionIndex + unsigned _transactionIndex ): Transaction(_t), m_blockHash(_blockHash), diff --git a/libethereum/TransactionReceipt.h b/libethereum/TransactionReceipt.h index ceb1123b5..6043cc5ee 100644 --- a/libethereum/TransactionReceipt.h +++ b/libethereum/TransactionReceipt.h @@ -63,11 +63,11 @@ class LocalisedTransactionReceipt: public TransactionReceipt public: LocalisedTransactionReceipt( TransactionReceipt const& _t, - h256 const& _hash, - h256 const& _blockHash, - BlockNumber _blockNumber, - unsigned _transactionIndex, - Address const& _contractAddress = Address() + h256 const& _hash, + h256 const& _blockHash, + BlockNumber _blockNumber, + unsigned _transactionIndex, + Address const& _contractAddress = Address() ): TransactionReceipt(_t), m_hash(_hash), From 596a2deaf6cfc1f293ae67ab39f1b09d77c5aada Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Thu, 9 Jul 2015 00:47:16 +0200 Subject: [PATCH 5/6] fixed style issues --- libethereum/BlockChain.h | 4 ++-- libethereum/ClientBase.cpp | 4 ++-- libethereum/ClientBase.h | 4 ++-- libethereum/Interface.h | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libethereum/BlockChain.h b/libethereum/BlockChain.h index 9956226f2..ecaaee4c0 100644 --- a/libethereum/BlockChain.h +++ b/libethereum/BlockChain.h @@ -143,10 +143,10 @@ public: BlockReceipts receipts() const { return receipts(currentHash()); } /// Get the transaction by block hash and index; - TransactionReceipt transactionReceipt(h256 const& _blockHash, unsigned _i) const {return receipts(_blockHash).receipts[_i]; } + TransactionReceipt transactionReceipt(h256 const& _blockHash, unsigned _i) const { return receipts(_blockHash).receipts[_i]; } /// Get the transaction receipt by transaction hash. Thread-safe. - TransactionReceipt transactionReceipt(h256 const& _transactionHash) const {TransactionAddress ta = queryExtras(_transactionHash, m_transactionAddresses, x_transactionAddresses, NullTransactionAddress); if (!ta) return bytesConstRef(); return transactionReceipt(ta.blockHash, ta.index); } + TransactionReceipt transactionReceipt(h256 const& _transactionHash) const { TransactionAddress ta = queryExtras(_transactionHash, m_transactionAddresses, x_transactionAddresses, NullTransactionAddress); if (!ta) return bytesConstRef(); return transactionReceipt(ta.blockHash, ta.index); } /// Get a list of transaction hashes for a given block. Thread-safe. TransactionHashes transactionHashes(h256 const& _hash) const { auto b = block(_hash); RLP rlp(b); h256s ret; for (auto t: rlp[1]) ret.push_back(sha3(t.data())); return ret; } diff --git a/libethereum/ClientBase.cpp b/libethereum/ClientBase.cpp index 5a5f89b72..5d5af7c6b 100644 --- a/libethereum/ClientBase.cpp +++ b/libethereum/ClientBase.cpp @@ -317,7 +317,7 @@ Transaction ClientBase::transaction(h256 _transactionHash) const return Transaction(bc().transaction(_transactionHash), CheckTransaction::Cheap); } -LocalisedTransaction ClientBase::localisedTransaction(h256 _transactionHash) const +LocalisedTransaction ClientBase::localisedTransaction(h256 const& _transactionHash) const { std::pair tl = bc().transactionLocation(_transactionHash); return localisedTransaction(tl.first, tl.second); @@ -333,7 +333,7 @@ Transaction ClientBase::transaction(h256 _blockHash, unsigned _i) const return Transaction(); } -LocalisedTransaction ClientBase::localisedTransaction(h256 _blockHash, unsigned _i) const +LocalisedTransaction ClientBase::localisedTransaction(h256 const& _blockHash, unsigned _i) const { Transaction t = Transaction(bc().transaction(_blockHash, _i), CheckTransaction::Cheap); return LocalisedTransaction(t, _blockHash, numberFromHash(_blockHash), _i); diff --git a/libethereum/ClientBase.h b/libethereum/ClientBase.h index 31a0f7499..91a9daf29 100644 --- a/libethereum/ClientBase.h +++ b/libethereum/ClientBase.h @@ -118,9 +118,9 @@ public: virtual BlockInfo blockInfo(h256 _hash) const override; virtual BlockDetails blockDetails(h256 _hash) const override; virtual Transaction transaction(h256 _transactionHash) const override; - virtual LocalisedTransaction localisedTransaction(h256 _transactionHash) const override; + virtual LocalisedTransaction localisedTransaction(h256 const& _transactionHash) const override; virtual Transaction transaction(h256 _blockHash, unsigned _i) const override; - virtual LocalisedTransaction localisedTransaction(h256 _blockHash, unsigned _i) const override; + virtual LocalisedTransaction localisedTransaction(h256 const& _blockHash, unsigned _i) const override; virtual TransactionReceipt transactionReceipt(h256 const& _transactionHash) const override; virtual LocalisedTransactionReceipt localisedTransactionReceipt(h256 const& _transactionHash) const override; virtual std::pair transactionLocation(h256 const& _transactionHash) const override; diff --git a/libethereum/Interface.h b/libethereum/Interface.h index d030e666f..418b8e0ff 100644 --- a/libethereum/Interface.h +++ b/libethereum/Interface.h @@ -135,7 +135,7 @@ public: virtual bool isKnownTransaction(h256 const& _transactionHash) const = 0; virtual Transaction transaction(h256 _transactionHash) const = 0; - virtual LocalisedTransaction localisedTransaction(h256 _transactionHash) const = 0; + virtual LocalisedTransaction localisedTransaction(h256 const& _transactionHash) const = 0; virtual TransactionReceipt transactionReceipt(h256 const& _transactionHash) const = 0; virtual LocalisedTransactionReceipt localisedTransactionReceipt(h256 const& _transactionHash) const = 0; virtual std::pair transactionLocation(h256 const& _transactionHash) const = 0; @@ -148,7 +148,7 @@ public: virtual BlockInfo blockInfo(h256 _hash) const = 0; virtual BlockDetails blockDetails(h256 _hash) const = 0; virtual Transaction transaction(h256 _blockHash, unsigned _i) const = 0; - virtual LocalisedTransaction localisedTransaction(h256 _blockHash, unsigned _i) const = 0; + virtual LocalisedTransaction localisedTransaction(h256 const& _blockHash, unsigned _i) const = 0; virtual BlockInfo uncle(h256 _blockHash, unsigned _i) const = 0; virtual UncleHashes uncleHashes(h256 _blockHash) const = 0; virtual unsigned transactionCount(h256 _blockHash) const = 0; From c6371bec4921b47009b95d93bac64554f7fce5fb Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Thu, 9 Jul 2015 00:59:32 +0200 Subject: [PATCH 6/6] blockNumber is optional for LocalisedTransaction --- libethereum/ClientBase.cpp | 2 +- libethereum/Transaction.h | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libethereum/ClientBase.cpp b/libethereum/ClientBase.cpp index 5d5af7c6b..b133e3731 100644 --- a/libethereum/ClientBase.cpp +++ b/libethereum/ClientBase.cpp @@ -336,7 +336,7 @@ Transaction ClientBase::transaction(h256 _blockHash, unsigned _i) const LocalisedTransaction ClientBase::localisedTransaction(h256 const& _blockHash, unsigned _i) const { Transaction t = Transaction(bc().transaction(_blockHash, _i), CheckTransaction::Cheap); - return LocalisedTransaction(t, _blockHash, numberFromHash(_blockHash), _i); + return LocalisedTransaction(t, _blockHash, _i, numberFromHash(_blockHash)); } TransactionReceipt ClientBase::transactionReceipt(h256 const& _transactionHash) const diff --git a/libethereum/Transaction.h b/libethereum/Transaction.h index b13630f6a..02373fe9e 100644 --- a/libethereum/Transaction.h +++ b/libethereum/Transaction.h @@ -136,23 +136,23 @@ public: LocalisedTransaction( Transaction const& _t, h256 const& _blockHash, - BlockNumber _blockNumber, - unsigned _transactionIndex + unsigned _transactionIndex, + BlockNumber _blockNumber = 0 ): Transaction(_t), m_blockHash(_blockHash), - m_blockNumber(_blockNumber), - m_transactionIndex(_transactionIndex) + m_transactionIndex(_transactionIndex), + m_blockNumber(_blockNumber) {} h256 const& blockHash() const { return m_blockHash; } - BlockNumber blockNumber() const { return m_blockNumber; } unsigned transactionIndex() const { return m_transactionIndex; } + BlockNumber blockNumber() const { return m_blockNumber; } private: h256 m_blockHash; - BlockNumber m_blockNumber; unsigned m_transactionIndex; + BlockNumber m_blockNumber; }; }