Skip to content

Commit

Permalink
temp commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kyonRay committed Sep 18, 2024
1 parent ce7c03e commit 5aff3c8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
17 changes: 10 additions & 7 deletions bcos-rpc/bcos-rpc/web3jsonrpc/endpoints/EthEndpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ using namespace bcos::rpc;

task::Task<void> EthEndpoint::protocolVersion(const Json::Value&, Json::Value&)
{
// TODO: impl this
// TODO: impl this, this returns eth p2p protocol version
BOOST_THROW_EXCEPTION(
JsonRpcException(MethodNotFound, "This API has not been implemented yet!"));
co_return;
Expand All @@ -68,10 +68,12 @@ task::Task<void> EthEndpoint::syncing(const Json::Value&, Json::Value& response)
buildJsonContent(result, response);
co_return;
}
task::Task<void> EthEndpoint::coinbase(const Json::Value&, Json::Value&)
task::Task<void> EthEndpoint::coinbase(const Json::Value&, Json::Value& response)
{
BOOST_THROW_EXCEPTION(
JsonRpcException(MethodNotFound, "This API has not been implemented yet!"));
auto const nodeId = m_nodeService->consensus()->consensusConfig()->nodeID();
auto const address = right160(crypto::keccak256Hash(ref(nodeId->data())));
Json::Value result = address.hexPrefixed();
buildJsonContent(result, response);
co_return;
}
task::Task<void> EthEndpoint::chainId(const Json::Value&, Json::Value& response)
Expand Down Expand Up @@ -114,6 +116,7 @@ task::Task<void> EthEndpoint::gasPrice(const Json::Value&, Json::Value& response
{
// result: gasPrice(QTY)
auto const ledger = m_nodeService->ledger();
// TODO)): gas price can wrap in a class
auto config = co_await ledger::getSystemConfig(*ledger, ledger::SYSTEM_KEY_TX_GAS_PRICE);
Json::Value result;
if (config.has_value())
Expand Down Expand Up @@ -245,12 +248,12 @@ task::Task<void> EthEndpoint::getTransactionCount(const Json::Value& request, Js
<< LOG_KV("blockTag", blockTag) << LOG_KV("blockNumber", blockNumber);
}
auto const ledger = m_nodeService->ledger();
uint64_t nonce = 0;
u256 nonce = 0;
if (auto const entry = co_await ledger::getStorageAt(
*ledger, addressStr, bcos::ledger::ACCOUNT_TABLE_FIELDS::NONCE, /*blockNumber*/ 0);
entry.has_value())
{
nonce = std::stoull(std::string(entry.value().get()));
nonce = u256(entry.value().get());
}
// else
// {
Expand Down Expand Up @@ -715,7 +718,7 @@ task::Task<void> EthEndpoint::getTransactionReceipt(
JsonRpcException(InvalidParams, "Invalid transaction hash: " + hash.hexPrefixed()));
}
auto block = co_await ledger::getBlockData(*ledger, receipt->blockNumber(),
bcos::ledger::HEADER | bcos::ledger::TRANSACTIONS_HASH);
bcos::ledger::HEADER | bcos::ledger::TRANSACTIONS_HASH | bcos::ledger::RECEIPTS);
combineReceiptResponse(result, std::move(receipt), txs->at(0), std::move(block));
}
catch (...)
Expand Down
3 changes: 2 additions & 1 deletion bcos-rpc/bcos-rpc/web3jsonrpc/model/BlockResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ namespace bcos::rpc
result["parentHash"] = info.blockHash.hexPrefixed();
}
result["nonce"] = "0x0000000000000000";
// result["sha3Uncles"] = "0x";
// empty uncle hash: keccak256(RLP([]))
result["sha3Uncles"] = "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347";
result["logsBloom"] = "0x";
result["transactionsRoot"] = block->blockHeader()->txsRoot().hexPrefixed();
result["stateRoot"] = block->blockHeader()->stateRoot().hexPrefixed();
Expand Down
9 changes: 7 additions & 2 deletions bcos-rpc/bcos-rpc/web3jsonrpc/model/ReceiptResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace bcos::rpc
size_t transactionIndex = 0;
crypto::HashType blockHash;
uint64_t blockNumber = 0;
u256 cumulativeGasUsed = 0;
if (block)
{
blockHash = block->blockHeader()->hash();
Expand All @@ -58,6 +59,10 @@ namespace bcos::rpc
{
break;
}
if (transactionIndex <= block->receiptsSize())
{
cumulativeGasUsed += block->receipt(transactionIndex)->gasUsed();
}
}
}
result["transactionIndex"] = toQuantity(transactionIndex);
Expand All @@ -77,10 +82,10 @@ namespace bcos::rpc
toChecksumAddress(to, bcos::crypto::keccak256Hash(bcos::bytesConstRef(to)).hex());
result["to"] = "0x" + std::move(to);
}
result["cumulativeGasUsed"] = "0x0";
result["cumulativeGasUsed"] = toQuantity(cumulativeGasUsed);
result["effectiveGasPrice"] =
receipt->effectiveGasPrice().empty() ? "0x0" : std::string(receipt->effectiveGasPrice());
result["gasUsed"] = toQuantity((uint64_t)receipt->gasUsed());
result["gasUsed"] = toQuantity(receipt->gasUsed());
if (receipt->contractAddress().empty())
{
result["contractAddress"] = Json::nullValue;
Expand Down
3 changes: 2 additions & 1 deletion bcos-rpc/bcos-rpc/web3jsonrpc/utils/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
namespace bcos::rpc
{
constexpr const uint64_t LowestGasPrice{21000};
constexpr const uint64_t LowestGasUsed{21000};
enum Web3JsonRpcError : int32_t
{
Web3DefautError = -32000,
Web3DefaultError = -32000,
};
} // namespace bcos::rpc

0 comments on commit 5aff3c8

Please sign in to comment.