Merge branch 'master' of git+ssh://taler.net/var/git/mint

This commit is contained in:
Christian Grothoff 2015-06-22 15:23:23 +02:00
commit 214bcf54c7
2 changed files with 281 additions and 60 deletions

View File

@ -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 static void
interpret_save_array (struct PERF_TALER_MINTDB_interpreter_state *state) 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. * Main interpreter loop.
* *
@ -344,6 +395,7 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
int start_index, stop_index; int start_index, stop_index;
struct timespec start, stop; struct timespec start, stop;
unsigned long elapsed_ms; unsigned long elapsed_ms;
start_index = cmd_find (state->cmd, start_index = cmd_find (state->cmd,
state->cmd[state->i].details.gauger.label_start); state->cmd[state->i].details.gauger.label_start);
stop_index = cmd_find (state->cmd, stop_index = cmd_find (state->cmd,
@ -380,35 +432,7 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
break; break;
case PERF_TALER_MINTDB_CMD_LOAD_ARRAY: case PERF_TALER_MINTDB_CMD_LOAD_ARRAY:
{ interpret_load_array (state);
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;
}
}
break; break;
case PERF_TALER_MINTDB_CMD_INSERT_DEPOSIT: case PERF_TALER_MINTDB_CMD_INSERT_DEPOSIT:
@ -431,8 +455,98 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
state->cmd[state->i] state->cmd[state->i]
.details.get_deposit.label_source)] .details.get_deposit.label_source)]
.exposed.deposit; // Get the deposit from the source .exposed.deposit; // Get the deposit from the source
state->plugin->have_deposit (state->plugin->cls, 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; break;

View File

@ -118,28 +118,6 @@
.exposed_type = PERF_TALER_MINTDB_NONE, \ .exposed_type = PERF_TALER_MINTDB_NONE, \
} }
/**
* Insert a deposit into the database
*/
#define PERF_TALER_MINTDB_INIT_CMD_INSERT_DEPOSIT(_label) \
{ \
.command = PERF_TALER_MINTDB_CMD_INSERT_DEPOSIT,\
.label = _label, \
.exposed_type = PERF_TALER_MINTDB_DEPOSIT, \
}
/**
* Check if a deposit is in the database
* @param _label_deposit Label of the deposit to use
*/
#define PERF_TALER_MINTDB_INIT_CMD_GET_DEPOSIT(_label, _label_deposit) \
{ \
.command = PERF_TALER_MINTDB_CMD_GET_DEPOSIT, \
.label = _label, \
.exposed_type = PERF_TALER_MINTDB_NONE, \
.details.get_deposit.label_source = _label_deposit \
}
/** /**
* Extracts @a _nb_saved items of type @a _save_type * Extracts @a _nb_saved items of type @a _save_type
* from the command @a _label_save during the loop @a _label_loop * from the command @a _label_save during the loop @a _label_loop
@ -171,7 +149,94 @@
.label_save = _label_save \ .label_save = _label_save \
} \ } \
} }
/**
* Insert a deposit into the database
*/
#define PERF_TALER_MINTDB_INIT_CMD_INSERT_DEPOSIT(_label) \
{ \
.command = PERF_TALER_MINTDB_CMD_INSERT_DEPOSIT,\
.label = _label, \
.exposed_type = PERF_TALER_MINTDB_DEPOSIT, \
}
/**
* Check if a deposit is in the database
* @param _label_deposit Label of the deposit to use
*/
#define PERF_TALER_MINTDB_INIT_CMD_GET_DEPOSIT(_label, _label_deposit) \
{ \
.command = PERF_TALER_MINTDB_CMD_GET_DEPOSIT, \
.label = _label, \
.exposed_type = PERF_TALER_MINTDB_NONE, \
.details.get_deposit.label_source = _label_deposit \
}
/**
* Creates a new reserve in the database
*/
#define PERF_TALER_MINTDB_INIT_CMD_INSERT_RESERVE(_label) \
{ \
.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.get_reserve.label_source = _label_source \
}
/**
* Inserts informations about a withdrawal in the database
*/
#define PERF_TALER_MINTDB_INIT_CMD_INSERT_WITHDRAW(_label) \
{ \
.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.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_TIME,
PERF_TALER_MINTDB_DEPOSIT, PERF_TALER_MINTDB_DEPOSIT,
PERF_TALER_MINTDB_BLINDCOIN, PERF_TALER_MINTDB_BLINDCOIN,
PERF_TALER_MINTDB_RESERVE_KEY,
PERF_TALER_MINTDB_RESERVE, PERF_TALER_MINTDB_RESERVE,
PERF_TALER_MINTDB_DENOMINATION_KEY,
PERF_TALER_MINTDB_DENOMINATION_INFO, PERF_TALER_MINTDB_DENOMINATION_INFO,
PERF_TALER_MINTDB_COIN_INFO, PERF_TALER_MINTDB_COIN_INFO,
}; };
@ -195,10 +262,11 @@ enum PERF_TALER_MINTDB_Type
*/ */
union PERF_TALER_MINTDB_Data union PERF_TALER_MINTDB_Data
{ {
struct TALER_MINTDB_Deposit *deposit;
struct timespec time; struct timespec time;
struct TALER_MINTDB_Deposit *deposit;
struct TALER_MINTDB_CollectableBlindcoin *blindcoin; struct TALER_MINTDB_CollectableBlindcoin *blindcoin;
struct TALER_MINTDB_Reserve *reserve; struct TALER_MINTDB_Reserve *reserve;
struct TALER_DenominationPublicKey *dpk;
struct TALER_MINTDB_DenominationKeyIssueInformation *dki; struct TALER_MINTDB_DenominationKeyIssueInformation *dki;
struct TALER_CoinPublicInfo *cpi; struct TALER_CoinPublicInfo *cpi;
}; };
@ -239,19 +307,36 @@ enum PERF_TALER_MINTDB_CMD_Name
// Abort a transaction // Abort a transaction
PERF_TALER_MINTDB_CMD_ABORT_TRANSACTION, PERF_TALER_MINTDB_CMD_ABORT_TRANSACTION,
// 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 // Saves random deposits from a loop
PERF_TALER_MINTDB_CMD_SAVE_ARRAY, PERF_TALER_MINTDB_CMD_SAVE_ARRAY,
// Load deposits saved earlier // Load deposits saved earlier
PERF_TALER_MINTDB_CMD_LOAD_ARRAY, PERF_TALER_MINTDB_CMD_LOAD_ARRAY,
} command; // 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,
// Insert currency in a reserve / Create a reserve
PERF_TALER_MINTDB_CMD_INSERT_RESERVE,
// 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,
// 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
};
/** /**
@ -365,6 +450,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 * Contains extra data required for any command
*/ */
@ -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_save_array_details save_array;
struct PERF_TALER_MINTDB_CMD_load_array_details load_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_deposit_details get_deposit;
struct PERF_TALER_MINTDB_CMD_get_reserve_details get_reserve;
struct PERF_TALER_MINTDB_CMD_get_denomination_details get_denomination;
}; };