Browse Source

LocalisedTransaction in ClientBase and WebThreeStubServerBase

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
7beb78413c
  1. 12
      libethereum/ClientBase.cpp
  2. 2
      libethereum/ClientBase.h
  3. 2
      libethereum/Interface.h
  4. 9
      libethereum/Transaction.h
  5. 20
      libweb3jsonrpc/JsonHelper.cpp
  6. 2
      libweb3jsonrpc/JsonHelper.h
  7. 9
      libweb3jsonrpc/WebThreeStubServerBase.cpp

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

2
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<h256, unsigned> transactionLocation(h256 const& _transactionHash) const override;

2
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<h256, unsigned> 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;

9
libethereum/Transaction.h

@ -135,13 +135,14 @@ class LocalisedTransaction: public Transaction
public:
LocalisedTransaction(
Transaction const& _t,
std::pair<h256, unsigned> 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; }

20
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;

2
libweb3jsonrpc/JsonHelper.h

@ -43,6 +43,7 @@ namespace eth
{
class Transaction;
class LocalisedTransaction;
struct BlockDetails;
class Interface;
using Transactions = std::vector<Transaction>;
@ -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);

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

Loading…
Cancel
Save