Skip to content
This repository has been archived by the owner on Feb 21, 2019. It is now read-only.

Modified get_block API command to call find_block_num when handed a time... #1409

Merged
merged 1 commit into from Feb 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions libraries/api/blockchain_api.json
Expand Up @@ -234,14 +234,14 @@
},
{
"method_name": "blockchain_get_block",
"description": "Retrieves the block record for the given block number or ID",
"description": "Retrieves the block record for the given block number, ID or timestamp",
"cached" : true,
"return_type": "oblock_record",
"parameters" : [
{
"name" : "block",
"type" : "string",
"description" : "block number or ID to retrieve"
"description" : "timestamp, number or ID of the block to retrieve"
}
],
"is_const" : true,
Expand Down
10 changes: 8 additions & 2 deletions libraries/client/blockchain_api.cpp
Expand Up @@ -290,8 +290,14 @@ oblock_record detail::client_impl::blockchain_get_block( const string& block )co
ASSERT_TASK_NOT_PREEMPTED(); // make sure no cancel gets swallowed by catch(...)
if( block.size() == string( block_id_type() ).size() )
return _chain_db->get_block_record( block_id_type( block ) );
else
return _chain_db->get_block_record( std::stoi( block ) );
uint32_t num;
try {
fc::time_point_sec time(fc::time_point_sec::from_iso_string( block ));
num = _chain_db->find_block_num( time );
} catch( ... ) {
num = std::stoi( block );
}
return _chain_db->get_block_record( num );
}
catch( ... )
{
Expand Down