Random number wallet api with number storing

This commit is contained in:
Srdjan Obucina 2020-05-25 03:04:32 +02:00
parent d5eac3f1a7
commit 29d6d7b1f9
7 changed files with 205 additions and 132 deletions

View file

@ -186,7 +186,7 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
// rng // rng
vector<uint64_t> get_random_number_ex(uint64_t minimum, uint64_t maximum, uint64_t selections, bool duplicates) const; vector<uint64_t> get_random_number_ex(uint64_t minimum, uint64_t maximum, uint64_t selections, bool duplicates) const;
int64_t get_random_number(uint64_t bound) const; uint64_t get_random_number(uint64_t bound) const;
//private: //private:
const account_object* get_account_from_string( const std::string& name_or_id, const account_object* get_account_from_string( const std::string& name_or_id,
@ -2350,12 +2350,12 @@ vector<uint64_t> database_api_impl::get_random_number_ex(uint64_t minimum, uint6
return v; return v;
} }
int64_t database_api::get_random_number(uint64_t bound) const uint64_t database_api::get_random_number(uint64_t bound) const
{ {
return my->get_random_number(bound); return my->get_random_number(bound);
} }
int64_t database_api_impl::get_random_number(uint64_t bound) const { uint64_t database_api_impl::get_random_number(uint64_t bound) const {
vector<uint64_t> v = get_random_number_ex(0, bound, 1, false); vector<uint64_t> v = get_random_number_ex(0, bound, 1, false);
return v.at(0); return v.at(0);
} }

View file

@ -727,7 +727,7 @@ class database_api
* @param bound Upper bound of segment containing random number * @param bound Upper bound of segment containing random number
* @return Random number from segment [0, bound) * @return Random number from segment [0, bound)
*/ */
int64_t get_random_number(uint64_t bound) const; uint64_t get_random_number(uint64_t bound) const;
private: private:
std::shared_ptr< database_api_impl > my; std::shared_ptr< database_api_impl > my;

View file

@ -9,8 +9,7 @@ namespace graphene { namespace chain {
asset fee; asset fee;
account_id_type account; account_id_type account;
time_point_sec timestamp; vector<uint64_t> random_number;
uint64_t random_number;
std::string data; std::string data;
account_id_type fee_payer()const { return account; } account_id_type fee_payer()const { return account; }
@ -21,7 +20,6 @@ namespace graphene { namespace chain {
FC_REFLECT( graphene::chain::random_number_store_operation::fee_parameters_type, (fee) ) FC_REFLECT( graphene::chain::random_number_store_operation::fee_parameters_type, (fee) )
FC_REFLECT( graphene::chain::random_number_store_operation, (fee) FC_REFLECT( graphene::chain::random_number_store_operation, (fee)
(account) (account)
(timestamp)
(random_number) (random_number)
(data) ) (data) )

View file

@ -11,7 +11,7 @@ namespace graphene { namespace chain {
account_id_type account; /* account who requested random number */ account_id_type account; /* account who requested random number */
time_point_sec timestamp; /* date and time when the number is read */ time_point_sec timestamp; /* date and time when the number is read */
uint64_t random_number; /* random number */ vector<uint64_t> random_number; /* random number(s) */
std::string data; /* custom data in json format */ std::string data; /* custom data in json format */
}; };

View file

@ -12,10 +12,10 @@ void_result random_number_store_evaluator::do_evaluate( const random_number_stor
object_id_type random_number_store_evaluator::do_apply( const random_number_store_operation& op ) object_id_type random_number_store_evaluator::do_apply( const random_number_store_operation& op )
{ try { { try {
const auto& new_random_number_object = db().create<random_number_object>( [&]( random_number_object& obj ) { const auto& new_random_number_object = db().create<random_number_object>( [&]( random_number_object& obj ) {
//obj.account = op.account; obj.account = op.account;
//obj.timestamp = op.timestamp; obj.timestamp = db().head_block_time();
//obj.random_number = op.random_number; obj.random_number = op.random_number;
//obj.data = op.data; obj.data = op.data;
}); });
return new_random_number_object.id; return new_random_number_object.id;
} FC_CAPTURE_AND_RETHROW( (op) ) } } FC_CAPTURE_AND_RETHROW( (op) ) }

View file

@ -1654,6 +1654,32 @@ class wallet_api
bool broadcast /* = false */ bool broadcast /* = false */
); );
/** Get random numbers
* @brief Returns the random number
* @param minimum Lower bound of segment containing random number
* @param maximum Upper bound of segment containing random number
* @param selections Number of random numbers to return
* @param duplicates Allow duplicated numbers
* @param broadcast true if you wish to broadcast the transaction
* @return the signed version of the transaction
* @return Vector containing random numbers from segment [minimum, maximum)
*/
vector<uint64_t> get_random_number_ex(string account,
uint64_t minimum,
uint64_t maximum,
uint64_t selections,
bool duplicates,
bool broadcast);
/** Get random number
* @brief Returns the random number
* @param bound Upper bound of segment containing random number
* @return Random number from segment [0, bound)
*/
uint64_t get_random_number(string account,
uint64_t bound,
bool broadcast);
order_book get_order_book( const string& base, const string& quote, unsigned limit = 50); order_book get_order_book( const string& base, const string& quote, unsigned limit = 50);
asset get_total_matched_bet_amount_for_betting_market_group(betting_market_group_id_type group_id); asset get_total_matched_bet_amount_for_betting_market_group(betting_market_group_id_type group_id);
@ -2094,6 +2120,8 @@ FC_API( graphene::wallet::wallet_api,
(propose_fee_change) (propose_fee_change)
(propose_dividend_asset_update) (propose_dividend_asset_update)
(approve_proposal) (approve_proposal)
(get_random_number_ex)
(get_random_number)
(dbg_make_uia) (dbg_make_uia)
(dbg_make_mia) (dbg_make_mia)
(dbg_push_blocks) (dbg_push_blocks)

View file

@ -3242,6 +3242,38 @@ public:
return sign_transaction(tx, broadcast); return sign_transaction(tx, broadcast);
} }
vector<uint64_t> get_random_number_ex(string account,
uint64_t minimum,
uint64_t maximum,
uint64_t selections,
bool duplicates,
bool broadcast)
{
vector<uint64_t> v = _remote_db->get_random_number_ex(minimum, maximum, selections, duplicates);
random_number_store_operation op;
op.account = get_account(account).id;
op.random_number = v;
op.data = "";
signed_transaction trx;
trx.operations.push_back(op);
set_operation_fees( trx, _remote_db->get_global_properties().parameters.current_fees );
trx.validate();
sign_transaction( trx, broadcast );
return v;
}
uint64_t get_random_number(string account,
uint64_t bound,
bool broadcast)
{
vector<uint64_t> v = get_random_number_ex(account, 0, bound, 1, false, broadcast);
return v.at(0);
}
void dbg_make_uia(string creator, string symbol) void dbg_make_uia(string creator, string symbol)
{ {
asset_options opts; asset_options opts;
@ -4541,7 +4573,22 @@ signed_transaction wallet_api::approve_proposal(
return my->approve_proposal( fee_paying_account, proposal_id, delta, broadcast ); return my->approve_proposal( fee_paying_account, proposal_id, delta, broadcast );
} }
vector<uint64_t> wallet_api::get_random_number_ex(string account,
uint64_t minimum,
uint64_t maximum,
uint64_t selections,
bool duplicates,
bool broadcast)
{
return my->get_random_number_ex( account, minimum, maximum, selections, duplicates, broadcast );
}
uint64_t wallet_api::get_random_number(string account,
uint64_t bound,
bool broadcast)
{
return my->get_random_number( account, bound, broadcast );
}
global_property_object wallet_api::get_global_properties() const global_property_object wallet_api::get_global_properties() const