API endpoint for reading random numbers from the witness (#113)

This commit is contained in:
obucina 2020-05-17 23:09:15 +02:00 committed by GitHub
parent d8ca4d4625
commit be4869a64d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 2 deletions

View file

@ -184,6 +184,9 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
// gpos
gpos_info get_gpos_info(const account_id_type account) const;
// rng
int64_t get_random_number(uint64_t bound) const;
//private:
const account_object* get_account_from_string( const std::string& name_or_id,
bool throw_if_not_found = true ) const;
@ -2303,6 +2306,22 @@ graphene::app::gpos_info database_api_impl::get_gpos_info(const account_id_type
return result;
}
//////////////////////////////////////////////////////////////////////
// //
// Random numbers //
// //
//////////////////////////////////////////////////////////////////////
int64_t database_api::get_random_number(uint64_t bound) const
{
return my->get_random_number(bound);
}
int64_t database_api_impl::get_random_number(uint64_t bound) const {
int64_t result = _db.get_random_bits(bound);
return result;
}
//////////////////////////////////////////////////////////////////////
// //
// Private methods //

View file

@ -709,9 +709,17 @@ class database_api
*/
gpos_info get_gpos_info(const account_id_type account) const;
/////////////////////////////
// Random number generator //
/////////////////////////////
/**
* @brief Returns the random number
* @param bound Upper bound of segment containing random number
* @return Random number from segment [0, bound)
*/
int64_t get_random_number(uint64_t bound) const;
private:
private:
std::shared_ptr< database_api_impl > my;
};
@ -848,4 +856,7 @@ FC_API(graphene::app::database_api,
// gpos
(get_gpos_info)
// rngs
(get_random_number)
)