API endpoint for reading random numbers from the witness
Test cmd:
curl --data '{"method": "call", "params": ["database", "get_random_number", [1000]], "jsonrpc": "2.0", "id": 1}' http://127.0.0.1:8090/ws
curl --data '{"method": "call", "params": ["database", "get_random_number", [5000]], "jsonrpc": "2.0", "id": 1}' http://127.0.0.1:8090/ws
curl --data '{"method": "call", "params": ["database", "get_random_number", [1000000]], "jsonrpc": "2.0", "id": 1}' http://127.0.0.1:8090/ws
This commit is contained in:
parent
38f560f861
commit
654e998d89
2 changed files with 21 additions and 0 deletions
|
|
@ -163,6 +163,7 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
|
||||||
|
|
||||||
// gpos
|
// gpos
|
||||||
gpos_info get_gpos_info(const account_id_type account) const;
|
gpos_info get_gpos_info(const account_id_type account) const;
|
||||||
|
int64_t get_random_number(uint64_t bound) const;
|
||||||
|
|
||||||
//private:
|
//private:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
@ -2072,6 +2073,16 @@ graphene::app::gpos_info database_api_impl::get_gpos_info(const account_id_type
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 //
|
// Private methods //
|
||||||
|
|
|
||||||
|
|
@ -659,6 +659,13 @@ class database_api
|
||||||
*/
|
*/
|
||||||
gpos_info get_gpos_info(const account_id_type account) const;
|
gpos_info get_gpos_info(const account_id_type account) const;
|
||||||
|
|
||||||
|
//////////
|
||||||
|
// RNG //
|
||||||
|
//////////
|
||||||
|
/**
|
||||||
|
* @return Current Random number
|
||||||
|
*/
|
||||||
|
int64_t get_random_number(uint64_t bound) const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -786,4 +793,7 @@ FC_API(graphene::app::database_api,
|
||||||
|
|
||||||
// gpos
|
// gpos
|
||||||
(get_gpos_info)
|
(get_gpos_info)
|
||||||
|
|
||||||
|
// rngs
|
||||||
|
(get_random_number)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue