diff options
-rw-r--r-- | src/mintdb/perf_taler_mintdb_interpreter.c | 178 | ||||
-rw-r--r-- | src/mintdb/perf_taler_mintdb_interpreter.h | 155 |
2 files changed, 277 insertions, 56 deletions
diff --git a/src/mintdb/perf_taler_mintdb_interpreter.c b/src/mintdb/perf_taler_mintdb_interpreter.c index 73c0669ea..d7d3a6d00 100644 --- a/src/mintdb/perf_taler_mintdb_interpreter.c +++ b/src/mintdb/perf_taler_mintdb_interpreter.c @@ -227,6 +227,10 @@ interpret_end_loop (struct PERF_TALER_MINTDB_interpreter_state *state) } +/** + * Saves the data exposed by another command into + * an array in the command specific struct. + */ static void interpret_save_array (struct PERF_TALER_MINTDB_interpreter_state *state) { @@ -309,6 +313,53 @@ interpret_save_array (struct PERF_TALER_MINTDB_interpreter_state *state) } +static void +interpret_load_array (struct PERF_TALER_MINTDB_interpreter_state *state) +{ + int loop_index, save_index; + union PERF_TALER_MINTDB_Data zero = {0}; + union PERF_TALER_MINTDB_Data *loaded_data; + + loop_index = cmd_find (state->cmd, + state->cmd[state->i].details.load_array.label_loop); + save_index = cmd_find (state->cmd, + state->cmd[state->i].details.load_array.label_save); + /* Extracting the data from the loop_indexth indice in save_index + * array. + */ + loaded_data = &state->cmd[save_index].details.save_array.data_saved[ + state->cmd[state->i].details.load_array.permutation[ + state->cmd[loop_index].details.loop.curr_iteration]]; + + switch (state->cmd[state->i].exposed_type) + { + case PERF_TALER_MINTDB_TIME: + state->cmd[state->i].exposed.time = loaded_data->time; + break; + + case PERF_TALER_MINTDB_DEPOSIT: + state->cmd[state->i].exposed.deposit = loaded_data->deposit; + break; + + case PERF_TALER_MINTDB_BLINDCOIN: + state->cmd[state->i].exposed.blindcoin = loaded_data->blindcoin; + break; + + case PERF_TALER_MINTDB_RESERVE: + state->cmd[state->i].exposed.reserve = loaded_data->reserve; + break; + + case PERF_TALER_MINTDB_DENOMINATION_INFO: + state->cmd[state->i].exposed.dki = loaded_data->dki; + + case PERF_TALER_MINTDB_COIN_INFO: + state->cmd[state->i].exposed.cpi = loaded_data->cpi; + default: + break; + } + *loaded_data = zero; +} + /** * Main interpreter loop. * @@ -344,12 +395,13 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state) int start_index, stop_index; struct timespec start, stop; unsigned long elapsed_ms; + start_index = cmd_find (state->cmd, state->cmd[state->i].details.gauger.label_start); stop_index = cmd_find (state->cmd, state->cmd[state->i].details.gauger.label_stop); - start = state->cmd [start_index].exposed.time; - stop = state->cmd [stop_index].exposed.time; + start = state->cmd[start_index].exposed.time; + stop = state->cmd[stop_index].exposed.time; elapsed_ms = (start.tv_sec - stop.tv_sec) * 1000 + (start.tv_nsec - stop.tv_nsec) / 1000000; @@ -380,35 +432,7 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state) break; case PERF_TALER_MINTDB_CMD_LOAD_ARRAY: - { - int loop_index, save_index; - union PERF_TALER_MINTDB_Data *loaded_data; - loop_index = cmd_find (state->cmd, - state->cmd[state->i].details.load_array.label_loop); - save_index = cmd_find (state->cmd, - state->cmd[state->i].details.load_array.label_save); - /* Extracting the data from the loop_indexth indice in save_index - * array. - */ - loaded_data = &state->cmd[save_index].details.save_array.data_saved[ - state->cmd[state->i].details.load_array.permutation[ - state->cmd[loop_index].details.loop.curr_iteration]]; - - switch (state->cmd[state->i].exposed_type) - { - case PERF_TALER_MINTDB_TIME: - state->cmd[state->i].exposed.time = loaded_data->time; - break; - - case PERF_TALER_MINTDB_DEPOSIT: - state->cmd[state->i].exposed.deposit = loaded_data->deposit; - loaded_data->deposit = NULL; - break; - - default: - break; - } - } + interpret_load_array (state); break; case PERF_TALER_MINTDB_CMD_INSERT_DEPOSIT: @@ -431,8 +455,98 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state) state->cmd[state->i] .details.get_deposit.label_source)] .exposed.deposit; // Get the deposit from the source + state->plugin->have_deposit (state->plugin->cls, - state->session, deposit); + state->session, + deposit); + } + break; + + case PERF_TALER_MINTDB_CMD_INSERT_RESERVE: + { + struct TALER_MINTDB_Reserve *reserve; + json_t *details = json_pack ("si","justification", + GNUNET_CRYPTO_random_u32 ( + GNUNET_CRYPTO_QUALITY_WEAK, + UINT32_MAX)); + reserve = PERF_TALER_MINTDB_reserve_init (); + state->plugin->reserves_in_insert ( + state->plugin->cls, + state->session, + &reserve->pub, + &reserve->balance, + details + ); + json_decref (details); + state->cmd[state->i].exposed.reserve = reserve; + } + break; + + case PERF_TALER_MINTDB_CMD_GET_RESERVE: + { + struct TALER_MINTDB_Reserve *reserve = + state->cmd[cmd_find (state->cmd, + state->cmd[state->i] + .details.get_reserve.label_source)] + .exposed.reserve; // Get the deposit from the source + + state->plugin->reserve_get (state->plugin->cls, + state->session, + reserve); + } + break; + + case PERF_TALER_MINTDB_CMD_INSERT_DENOMINATION: + { + struct TALER_MINTDB_DenominationKeyIssueInformation *dki = + PERF_TALER_MINTDB_denomination_init (); + + state->plugin->insert_denomination_info (state->plugin->cls, + state->session, + &dki->denom_pub, + &dki->issue); + state->cmd[state->i].exposed.dki = dki; + } + break; + + case PERF_TALER_MINTDB_CMD_GET_DENOMINATION: + { + struct TALER_MINTDB_DenominationKeyIssueInformation *dki = + state->cmd[cmd_find (state->cmd, + state->cmd[state->i] + .details.get_denomination.label_source)] + .exposed.dki; + state->plugin->get_denomination_info (state->plugin->cls, + state->session, + &dki->denom_pub, + &dki->issue); + } + break; + + case PERF_TALER_MINTDB_CMD_INSERT_WITHDRAW: + { + struct TALER_MINTDB_CollectableBlindcoin *blindcoin = + PERF_TALER_MINTDB_collectable_blindcoin_init (); + + state->plugin->insert_withdraw_info (state->plugin->cls, + state->session, + blindcoin); + state->cmd[state->i].exposed.blindcoin = blindcoin; + } + break; + + case PERF_TALER_MINTDB_CMD_GET_WITHDRAW: + { + struct TALER_MINTDB_CollectableBlindcoin *blindcoin = + state->cmd[cmd_find (state->cmd, + state->cmd[state->i] + .details.get_denomination.label_source)] + .exposed.blindcoin; + + state->plugin->get_withdraw_info (state->plugin->cls, + state->session, + &blindcoin->h_coin_envelope, + blindcoin); } break; diff --git a/src/mintdb/perf_taler_mintdb_interpreter.h b/src/mintdb/perf_taler_mintdb_interpreter.h index 367aaf295..798660313 100644 --- a/src/mintdb/perf_taler_mintdb_interpreter.h +++ b/src/mintdb/perf_taler_mintdb_interpreter.h @@ -119,6 +119,37 @@ } /** + * Extracts @a _nb_saved items of type @a _save_type + * from the command @a _label_save during the loop @a _label_loop + */ +#define PERF_TALER_MINTDB_INIT_CMD_SAVE_ARRAY(_label, _label_loop, _label_save, _nb_saved, _save_type) \ +{ \ + .command = PERF_TALER_MINTDB_CMD_SAVE_ARRAY, \ + .label = _label, \ + .exposed_type = PERF_TALER_MINTDB_NONE, \ + .details.save_array = { \ + .label_loop = _label_loop, \ + .label_save = _label_save, \ + .nb_saved = _nb_saved, \ + .type_saved = _save_type \ + } \ +} + +/** + * Loads @a _nb_saved previously sampled data of type @a _saved_type + * from @a _label_save during the loop @a _label_loop + */ +#define PERF_TALER_MINTDB_INIT_CMD_LOAD_ARRAY(_label, _label_loop, _label_save) \ +{ \ + .command = PERF_TALER_MINTDB_CMD_LOAD_ARRAY, \ + .label = _label, \ + .exposed_type = PERF_TALER_MINTDB_NONE, \ + .details.load_array = { \ + .label_loop = _label_loop, \ + .label_save = _label_save \ + } \ +} +/** * Insert a deposit into the database */ #define PERF_TALER_MINTDB_INIT_CMD_INSERT_DEPOSIT(_label) \ @@ -141,37 +172,71 @@ } /** - * Extracts @a _nb_saved items of type @a _save_type - * from the command @a _label_save during the loop @a _label_loop + * Creates a new reserve in the database */ -#define PERF_TALER_MINTDB_INIT_CMD_SAVE_ARRAY(_label, _label_loop, _label_save, _nb_saved, _save_type) \ +#define PERF_TALER_MINTDB_INIT_CMD_INSERT_RESERVE(_label) \ { \ - .command = PERF_TALER_MINTDB_CMD_SAVE_ARRAY, \ + .command = PERF_TALER_MINTDB_CMD_INSERT_RESERVE \ + .label = _label \ + .exposed_type = PERF_TALER_MINTDB_RESERVE \ +} + + +/** + * Polls the database for a secific reserve's details + * @param _label_source Source for the reserve to poll + */ +#define PERF_TALER_MINTDB_INIT_CMD_GET_RESERVE(_label, _label_source) \ +{ \ + .command = PERF_TALER_MINTDB_CMD_GET_RESERVE \ .label = _label, \ .exposed_type = PERF_TALER_MINTDB_NONE, \ - .details.save_array = { \ - .label_loop = _label_loop, \ - .label_save = _label_save, \ - .nb_saved = _nb_saved, \ - .type_saved = _save_type \ - } \ + .details.get_reserve.label_source = _label_source \ } + /** - * Loads @a _nb_saved previously sampled data of type @a _saved_type - * from @a _label_save during the loop @a _label_loop + * Inserts informations about a withdrawal in the database */ -#define PERF_TALER_MINTDB_INIT_CMD_LOAD_ARRAY(_label, _label_loop, _label_save) \ +#define PERF_TALER_MINTDB_INIT_CMD_INSERT_WITHDRAW(_label) \ { \ - .command = PERF_TALER_MINTDB_CMD_LOAD_ARRAY, \ + .command = PERF_TALER_MINTDB_CMD_INSERT_WITHDRAW, \ + .label = _label, \ + .exposed_type = PERF_TALER_MINTDB_BLINDCOIN, \ +}\ + + +/** + * Polls the database about informations regarding a secific withdrawal + */ +#define PERF_TALER_MINTDB_INIT_CMD_GET_WITHDRAW(_label, _label_source) \ +{ \ + .command = PERF_TALER_MINTDB_CMD_GET_WITHDRAW, \ .label = _label, \ .exposed_type = PERF_TALER_MINTDB_NONE, \ - .details.load_array = { \ - .label_loop = _label_loop, \ - .label_save = _label_save \ - } \ + .details.get_withdraw.label_source = _label_source, \ } +/** + * Inserts informations about a denomination key in the database + */ +#define PERF_TALER_MINTDB_INIT_CMD_INSERT_DENOMINATION(_label) \ +{ \ + .command = PERF_TALER_MINTDB_CMD_INSERT_WITHDRAW, \ + .label = _label, \ + .exposed_type = PERF_TALER_MINTDB_DENOMINATION_KEY, \ +} + +/** + * Polls the database about informations regarding a specific denomination key + */ +#define PERF_TALER_MINTDB_INIT_CMD_GET_DENOMINATION(_label, _label_source) \ +{ \ + .command = PERF_TALER_MINTDB_CMD_GET_DENOMINATION, \ + .label = _label, \ + .exposed_type = PERF_TALER_MINTDB_NONE, \ + .details.get_denomination.label_source = _label_source, \ +} /** @@ -184,7 +249,9 @@ enum PERF_TALER_MINTDB_Type PERF_TALER_MINTDB_TIME, PERF_TALER_MINTDB_DEPOSIT, PERF_TALER_MINTDB_BLINDCOIN, + PERF_TALER_MINTDB_RESERVE_KEY, PERF_TALER_MINTDB_RESERVE, + PERF_TALER_MINTDB_DENOMINATION_KEY, PERF_TALER_MINTDB_DENOMINATION_INFO, PERF_TALER_MINTDB_COIN_INFO, }; @@ -195,10 +262,11 @@ enum PERF_TALER_MINTDB_Type */ union PERF_TALER_MINTDB_Data { - struct TALER_MINTDB_Deposit *deposit; struct timespec time; + struct TALER_MINTDB_Deposit *deposit; struct TALER_MINTDB_CollectableBlindcoin *blindcoin; struct TALER_MINTDB_Reserve *reserve; + struct TALER_DenominationPublicKey *dpk; struct TALER_MINTDB_DenominationKeyIssueInformation *dki; struct TALER_CoinPublicInfo *cpi; }; @@ -239,19 +307,36 @@ enum PERF_TALER_MINTDB_CMD_Name // Abort a transaction PERF_TALER_MINTDB_CMD_ABORT_TRANSACTION, + // Saves random deposits from a loop + PERF_TALER_MINTDB_CMD_SAVE_ARRAY, + + // Load deposits saved earlier + PERF_TALER_MINTDB_CMD_LOAD_ARRAY, + // Insert a deposit into the database PERF_TALER_MINTDB_CMD_INSERT_DEPOSIT, // Check if a deposit is in the database PERF_TALER_MINTDB_CMD_GET_DEPOSIT, - // Saves random deposits from a loop - PERF_TALER_MINTDB_CMD_SAVE_ARRAY, + // Insert currency in a reserve / Create a reserve + PERF_TALER_MINTDB_CMD_INSERT_RESERVE, - // Load deposits saved earlier - PERF_TALER_MINTDB_CMD_LOAD_ARRAY, + // Get Informations about a reserve + PERF_TALER_MINTDB_CMD_GET_RESERVE, + + // Insert informations about a withdrawal in the database + PERF_TALER_MINTDB_CMD_INSERT_WITHDRAW, -} command; + // Pulls informations about a withdrawal from the database + PERF_TALER_MINTDB_CMD_GET_WITHDRAW, + + // Insert informations about a denomination key in the database + PERF_TALER_MINTDB_CMD_INSERT_DENOMINATION, + + // polls the database for informations about a specific denomination key + PERF_TALER_MINTDB_CMD_GET_DENOMINATION +}; /** @@ -366,6 +451,26 @@ struct PERF_TALER_MINTDB_CMD_get_deposit_details /** + * Extra data requiered for the GET_DEPOSIT command + */ +struct PERF_TALER_MINTDB_CMD_get_reserve_details +{ + /** + * The label of the source of the reserve to check + */ + const char *label_source; +}; + + +struct PERF_TALER_MINTDB_CMD_get_denomination_details +{ + /** + * The label of the source of the denomination to check + */ + const char *label_source; +}; + +/** * Contains extra data required for any command */ union PERF_TALER_MINTDB_CMD_Details @@ -376,6 +481,8 @@ union PERF_TALER_MINTDB_CMD_Details struct PERF_TALER_MINTDB_CMD_save_array_details save_array; struct PERF_TALER_MINTDB_CMD_load_array_details load_array; struct PERF_TALER_MINTDB_CMD_get_deposit_details get_deposit; + struct PERF_TALER_MINTDB_CMD_get_reserve_details get_reserve; + struct PERF_TALER_MINTDB_CMD_get_denomination_details get_denomination; }; |