diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 32a24e03d..315b8ed29 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -724,6 +724,11 @@ bytes Client::codeAt(Address _a, int _block) const return asOf(_block).code(_a); } +Transaction Client::transaction(h256 _transactionHash) const +{ + return Transaction(m_bc.transaction(_transactionHash), CheckSignature::Range); +} + Transaction Client::transaction(h256 _blockHash, unsigned _i) const { auto bl = m_bc.block(_blockHash); @@ -768,6 +773,11 @@ Transactions Client::transactions(h256 _blockHash) const return res; } +TransactionHashes Client::transactionHashes(h256 _blockHash) const +{ + return m_bc.transactionHashes(_blockHash); +} + LocalisedLogEntries Client::logs(unsigned _watchId) const { try { diff --git a/libethereum/Client.h b/libethereum/Client.h index 66a2e5e4d..6217b1d16 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -236,11 +236,13 @@ public: virtual h256 hashFromNumber(unsigned _number) const { return m_bc.numberHash(_number); } virtual BlockInfo blockInfo(h256 _hash) const { return BlockInfo(m_bc.block(_hash)); } virtual BlockDetails blockDetails(h256 _hash) const { return m_bc.details(_hash); } + virtual Transaction transaction(h256 _transactionHash) const; virtual Transaction transaction(h256 _blockHash, unsigned _i) const; virtual BlockInfo uncle(h256 _blockHash, unsigned _i) const; virtual unsigned transactionCount(h256 _blockHash) const; virtual unsigned uncleCount(h256 _blockHash) const; virtual Transactions transactions(h256 _blockHash) const; + virtual TransactionHashes transactionHashes(h256 _blockHash) const; /// Differences between transactions. using Interface::diff; diff --git a/libethereum/Interface.h b/libethereum/Interface.h index 36c222bba..56d24116d 100644 --- a/libethereum/Interface.h +++ b/libethereum/Interface.h @@ -37,6 +37,8 @@ namespace dev namespace eth { +using TransactionHashes = h256s; + /** * @brief Main API hub for interfacing with Ethereum. */ @@ -101,11 +103,13 @@ public: virtual h256 hashFromNumber(unsigned _number) const = 0; virtual BlockInfo blockInfo(h256 _hash) const = 0; virtual BlockDetails blockDetails(h256 _hash) const = 0; + virtual Transaction transaction(h256 _transactionHash) const = 0; virtual Transaction transaction(h256 _blockHash, unsigned _i) const = 0; virtual BlockInfo uncle(h256 _blockHash, unsigned _i) const = 0; virtual unsigned transactionCount(h256 _blockHash) const = 0; virtual unsigned uncleCount(h256 _blockHash) const = 0; virtual Transactions transactions(h256 _blockHash) const = 0; + virtual TransactionHashes transactionHashes(h256 _blockHash) const = 0; // [EXTRA API]: diff --git a/libweb3jsonrpc/WebThreeStubServerBase.cpp b/libweb3jsonrpc/WebThreeStubServerBase.cpp index f27c89c6d..68058047e 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.cpp +++ b/libweb3jsonrpc/WebThreeStubServerBase.cpp @@ -88,6 +88,15 @@ static Json::Value toJson(dev::eth::BlockInfo const& _bi, Transactions const& _t return res; } +static Json::Value toJson(dev::eth::BlockInfo const& _bi, TransactionHashes const& _ts) +{ + Json::Value res = toJson(_bi); + res["transactions"] = Json::Value(Json::arrayValue); + for (h256 const& t: _ts) + res["transactions"].append(toJS(t)); + return res; +} + static Json::Value toJson(dev::eth::TransactionSkeleton const& _t) { Json::Value res; @@ -565,7 +574,7 @@ Json::Value WebThreeStubServerBase::eth_getBlockByHash(string const& _blockHash, return toJson(client()->blockInfo(hash), client()->transactions(hash)); } - return toJson(client()->blockInfo(hash)); + return toJson(client()->blockInfo(hash), client()->transactionHashes(hash)); } Json::Value WebThreeStubServerBase::eth_getBlockByNumber(string const& _blockNumber, bool _includeTransactions) @@ -603,9 +612,7 @@ Json::Value WebThreeStubServerBase::eth_getTransactionByHash(string const& _tran throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS); } -// return toJson(client()->transaction(hash, index)); - // TODO: - return ""; + return toJson(client()->transaction(hash)); } Json::Value WebThreeStubServerBase::eth_getTransactionByBlockHashAndIndex(string const& _blockHash, string const& _transactionIndex) diff --git a/mix/MixClient.cpp b/mix/MixClient.cpp index 53d5b75a7..2e0270849 100644 --- a/mix/MixClient.cpp +++ b/mix/MixClient.cpp @@ -462,6 +462,11 @@ eth::BlockDetails MixClient::blockDetails(h256 _hash) const return bc().details(_hash); } +Transaction MixClient::transaction(h256 _transactionHash) const +{ + return Transaction(bc().transaction(_transactionHash), CheckSignature::Range); +} + eth::Transaction MixClient::transaction(h256 _blockHash, unsigned _i) const { auto bl = bc().block(_blockHash); @@ -506,6 +511,11 @@ Transactions MixClient::transactions(h256 _blockHash) const return res; } +TransactionHashes MixClient::transactionHashes(h256 _blockHash) const +{ + return bc().transactionHashes(_blockHash); +} + unsigned MixClient::number() const { return bc().number(); diff --git a/mix/MixClient.h b/mix/MixClient.h index 8b565f365..770424a93 100644 --- a/mix/MixClient.h +++ b/mix/MixClient.h @@ -68,11 +68,13 @@ public: h256 hashFromNumber(unsigned _number) const override; eth::BlockInfo blockInfo(h256 _hash) const override; eth::BlockDetails blockDetails(h256 _hash) const override; + eth::Transaction transaction(h256 _transactionHash) const override; eth::Transaction transaction(h256 _blockHash, unsigned _i) const override; eth::BlockInfo uncle(h256 _blockHash, unsigned _i) const override; unsigned transactionCount(h256 _blockHash) const override; unsigned uncleCount(h256 _blockHash) const override; eth::Transactions transactions(h256 _blockHash) const override; + eth::TransactionHashes transactionHashes(h256 _blockHash) const override; unsigned number() const override; eth::Transactions pending() const override; eth::StateDiff diff(unsigned _txi, h256 _block) const override;