Browse Source

LocalisedTransactionReceipt in ClientBase and WebThreeStubServerBase

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
e961867fdf
  1. 5
      libethereum/BlockChain.h
  2. 14
      libethereum/ClientBase.cpp
  3. 1
      libethereum/ClientBase.h
  4. 1
      libethereum/Interface.h
  5. 28
      libethereum/TransactionReceipt.h
  6. 31
      libweb3jsonrpc/JsonHelper.cpp
  7. 3
      libweb3jsonrpc/JsonHelper.h
  8. 3
      libweb3jsonrpc/WebThreeStubServerBase.cpp

5
libethereum/BlockChain.h

@ -142,8 +142,11 @@ public:
BlockReceipts receipts(h256 const& _hash) const { return queryExtras<BlockReceipts, ExtraReceipts>(_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<TransactionAddress, ExtraTransactionAddress>(_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<TransactionAddress, ExtraTransactionAddress>(_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; }

14
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<h256, unsigned> 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<h256, unsigned> ClientBase::transactionLocation(h256 const& _transactionHash) const
{
return bc().transactionLocation(_transactionHash);

1
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<h256, unsigned> transactionLocation(h256 const& _transactionHash) const override;
virtual Transactions transactions(h256 _blockHash) const override;
virtual TransactionHashes transactionHashes(h256 _blockHash) const override;

1
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<h256, unsigned> transactionLocation(h256 const& _transactionHash) const = 0;
virtual h256 hashFromNumber(BlockNumber _number) const = 0;
virtual BlockNumber numberFromHash(h256 _blockHash) const = 0;

28
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;
};
}

31
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<h256, unsigned> _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;
}

3
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<h256, unsigned> _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);

3
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 (...)
{

Loading…
Cancel
Save