diff --git a/libraries/api/blockchain_api.json b/libraries/api/blockchain_api.json index 478e22157..4a8ef7aba 100644 --- a/libraries/api/blockchain_api.json +++ b/libraries/api/blockchain_api.json @@ -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, diff --git a/libraries/client/blockchain_api.cpp b/libraries/client/blockchain_api.cpp index c87418b59..919d9ed4c 100644 --- a/libraries/client/blockchain_api.cpp +++ b/libraries/client/blockchain_api.cpp @@ -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( ... ) {