Random number wallet api with number storing
This commit is contained in:
parent
d5eac3f1a7
commit
29d6d7b1f9
7 changed files with 205 additions and 132 deletions
|
|
@ -186,7 +186,7 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
|
|||
|
||||
// rng
|
||||
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:
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
return v.at(0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -727,7 +727,7 @@ class database_api
|
|||
* @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;
|
||||
uint64_t get_random_number(uint64_t bound) const;
|
||||
|
||||
private:
|
||||
std::shared_ptr< database_api_impl > my;
|
||||
|
|
|
|||
|
|
@ -9,8 +9,7 @@ namespace graphene { namespace chain {
|
|||
asset fee;
|
||||
|
||||
account_id_type account;
|
||||
time_point_sec timestamp;
|
||||
uint64_t random_number;
|
||||
vector<uint64_t> random_number;
|
||||
std::string data;
|
||||
|
||||
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)
|
||||
(account)
|
||||
(timestamp)
|
||||
(random_number)
|
||||
(data) )
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace graphene { namespace chain {
|
|||
|
||||
account_id_type account; /* account who requested random number */
|
||||
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 */
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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 )
|
||||
{ try {
|
||||
const auto& new_random_number_object = db().create<random_number_object>( [&]( random_number_object& obj ) {
|
||||
//obj.account = op.account;
|
||||
//obj.timestamp = op.timestamp;
|
||||
//obj.random_number = op.random_number;
|
||||
//obj.data = op.data;
|
||||
obj.account = op.account;
|
||||
obj.timestamp = db().head_block_time();
|
||||
obj.random_number = op.random_number;
|
||||
obj.data = op.data;
|
||||
});
|
||||
return new_random_number_object.id;
|
||||
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||
|
|
|
|||
|
|
@ -1654,6 +1654,32 @@ class wallet_api
|
|||
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);
|
||||
|
||||
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_dividend_asset_update)
|
||||
(approve_proposal)
|
||||
(get_random_number_ex)
|
||||
(get_random_number)
|
||||
(dbg_make_uia)
|
||||
(dbg_make_mia)
|
||||
(dbg_push_blocks)
|
||||
|
|
|
|||
|
|
@ -3242,6 +3242,38 @@ public:
|
|||
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)
|
||||
{
|
||||
asset_options opts;
|
||||
|
|
@ -4541,7 +4573,22 @@ signed_transaction wallet_api::approve_proposal(
|
|||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue