Add blockNumber and blockTimestamp to ExecutionFramework

This commit is contained in:
Alex Beregszaszi 2017-02-07 16:20:05 +00:00
parent af8e31b023
commit 3128ec2ca5
4 changed files with 12 additions and 0 deletions

View File

@ -82,6 +82,8 @@ void ExecutionFramework::sendMessage(bytes const& _data, bool _isCreation, u256
m_rpc.test_mineBlocks(1);
RPCSession::TransactionReceipt receipt(m_rpc.eth_getTransactionReceipt(txHash));
m_blockNumber = u256(receipt.blockNumber);
if (_isCreation)
{
m_contractAddress = Address(receipt.contractAddress);
@ -129,6 +131,12 @@ size_t ExecutionFramework::currentTimestamp()
return size_t(u256(latestBlock.get("timestamp", "invalid").asString()));
}
size_t ExecutionFramework::blockTimestamp(u256 _number)
{
auto latestBlock = m_rpc.rpcCall("eth_getBlockByNumber", {toString(_number), "false"});
return size_t(u256(latestBlock.get("timestamp", "invalid").asString()));
}
Address ExecutionFramework::account(size_t _i)
{
return Address(m_rpc.accountCreateIfNotExists(_i));

View File

@ -262,6 +262,7 @@ protected:
void sendMessage(bytes const& _data, bool _isCreation, u256 const& _value = 0);
void sendEther(Address const& _to, u256 const& _value);
size_t currentTimestamp();
size_t blockTimestamp(u256 number);
/// @returns the (potentially newly created) _ith address.
Address account(size_t _i);
@ -284,6 +285,7 @@ protected:
bool m_showMessages = false;
Address m_sender;
Address m_contractAddress;
u256 m_blockNumber;
u256 const m_gasPrice = 100 * szabo;
u256 const m_gas = 100000000;
bytes m_output;

View File

@ -138,6 +138,7 @@ RPCSession::TransactionReceipt RPCSession::eth_getTransactionReceipt(string cons
BOOST_REQUIRE(!result.isNull());
receipt.gasUsed = result["gasUsed"].asString();
receipt.contractAddress = result["contractAddress"].asString();
receipt.blockNumber = result["blockNumber"].asString();
for (auto const& log: result["logs"])
{
LogEntry entry;

View File

@ -92,6 +92,7 @@ public:
std::string gasUsed;
std::string contractAddress;
std::vector<LogEntry> logEntries;
std::string blockNumber;
};
static RPCSession& instance(std::string const& _path);