remarks on #3814/3815
This commit is contained in:
parent
ca8eb3ec5c
commit
1f8291a024
@ -321,28 +321,46 @@ postgres_create_tables (void *cls,
|
|||||||
", PRIMARY KEY (session, oldcoin_index)" /* a coin can be used only
|
", PRIMARY KEY (session, oldcoin_index)" /* a coin can be used only
|
||||||
once in a refresh session */
|
once in a refresh session */
|
||||||
") ");
|
") ");
|
||||||
|
/* Table with information about the desired denominations to be created
|
||||||
|
during a refresh operation; contains the denomination key for each
|
||||||
|
of the coins (for a given refresh session) */
|
||||||
SQLEXEC("CREATE TABLE IF NOT EXISTS refresh_order "
|
SQLEXEC("CREATE TABLE IF NOT EXISTS refresh_order "
|
||||||
"(session_hash BYTEA NOT NULL CHECK (LENGTH(session_hash)=64) REFERENCES refresh_sessions (session_hash)"
|
"(session_hash BYTEA NOT NULL CHECK (LENGTH(session_hash)=64) REFERENCES refresh_sessions (session_hash)"
|
||||||
",newcoin_index INT2 NOT NULL "
|
",newcoin_index INT2 NOT NULL "
|
||||||
",denom_pub BYTEA NOT NULL "
|
",denom_pub BYTEA NOT NULL "
|
||||||
",PRIMARY KEY (session_hash, newcoin_index)"
|
",PRIMARY KEY (session_hash, newcoin_index)"
|
||||||
")");
|
")");
|
||||||
|
|
||||||
|
/* Table with the commitments for a refresh operation; includes
|
||||||
|
the session_hash for which this is the link information, the
|
||||||
|
oldcoin index and the cut-and-choose index (from 0 to #TALER_CNC_KAPPA-1),
|
||||||
|
as well as the actual link data (the transfer public key and the encrypted
|
||||||
|
link secret).
|
||||||
|
NOTE: We might want to simplify this and not have the oldcoin_index
|
||||||
|
and instead store all link secrets, one after the other, in one big BYTEA.
|
||||||
|
(#3814) */
|
||||||
SQLEXEC("CREATE TABLE IF NOT EXISTS refresh_commit_link"
|
SQLEXEC("CREATE TABLE IF NOT EXISTS refresh_commit_link"
|
||||||
"(session_hash BYTEA NOT NULL REFERENCES refresh_sessions (session_hash)"
|
"(session_hash BYTEA NOT NULL REFERENCES refresh_sessions (session_hash)"
|
||||||
",transfer_pub BYTEA NOT NULL CHECK(LENGTH(transfer_pub)=32)"
|
",transfer_pub BYTEA NOT NULL CHECK(LENGTH(transfer_pub)=32)"
|
||||||
",link_secret_enc BYTEA NOT NULL"
|
",link_secret_enc BYTEA NOT NULL"
|
||||||
// index of the old coin in the customer's request
|
|
||||||
",oldcoin_index INT2 NOT NULL"
|
",oldcoin_index INT2 NOT NULL"
|
||||||
// index for cut and choose,
|
|
||||||
// ranges from 0 to #TALER_CNC_KAPPA-1
|
|
||||||
",cnc_index INT2 NOT NULL"
|
",cnc_index INT2 NOT NULL"
|
||||||
")");
|
")");
|
||||||
|
/* Table with the commitments for the new coins that are to be created
|
||||||
|
during a melting session. Includes the session, the cut-and-choose
|
||||||
|
index and the index of the new coin, and the envelope of the new
|
||||||
|
coin to be signed, as well as the encrypted information about the
|
||||||
|
private key and the blinding factor for the coin (for verification
|
||||||
|
in case this cnc_index is chosen to be revealed)
|
||||||
|
|
||||||
|
NOTE: We might want to simplify this and not have the
|
||||||
|
newcoin_index and instead store all coin_evs and
|
||||||
|
link_vector_encs, one after the other, in two big BYTEAs.
|
||||||
|
(#3815) */
|
||||||
SQLEXEC("CREATE TABLE IF NOT EXISTS refresh_commit_coin"
|
SQLEXEC("CREATE TABLE IF NOT EXISTS refresh_commit_coin"
|
||||||
"(session_hash BYTEA NOT NULL REFERENCES refresh_sessions (session_hash) "
|
"(session_hash BYTEA NOT NULL REFERENCES refresh_sessions (session_hash) "
|
||||||
",link_vector_enc BYTEA NOT NULL"
|
",link_vector_enc BYTEA NOT NULL"
|
||||||
// index of the new coin in the customer's request
|
|
||||||
",newcoin_index INT2 NOT NULL"
|
",newcoin_index INT2 NOT NULL"
|
||||||
// index for cut and choose,
|
|
||||||
",cnc_index INT2 NOT NULL"
|
",cnc_index INT2 NOT NULL"
|
||||||
",coin_ev BYTEA NOT NULL"
|
",coin_ev BYTEA NOT NULL"
|
||||||
")");
|
")");
|
||||||
@ -410,8 +428,8 @@ postgres_prepare (PGconn *db_conn)
|
|||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
PREPARE ("insert_denomination",
|
PREPARE ("insert_denomination",
|
||||||
"INSERT INTO denominations ("
|
"INSERT INTO denominations "
|
||||||
" pub"
|
"(pub"
|
||||||
",valid_from"
|
",valid_from"
|
||||||
",expire_withdraw"
|
",expire_withdraw"
|
||||||
",expire_spend"
|
",expire_spend"
|
||||||
@ -433,8 +451,8 @@ postgres_prepare (PGconn *db_conn)
|
|||||||
"$7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17);",
|
"$7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17);",
|
||||||
14, NULL);
|
14, NULL);
|
||||||
PREPARE ("get_reserve",
|
PREPARE ("get_reserve",
|
||||||
"SELECT "
|
"SELECT"
|
||||||
"current_balance_val"
|
" current_balance_val"
|
||||||
",current_balance_frac"
|
",current_balance_frac"
|
||||||
",current_balance_curr"
|
",current_balance_curr"
|
||||||
",expiration_date "
|
",expiration_date "
|
||||||
@ -453,8 +471,8 @@ postgres_prepare (PGconn *db_conn)
|
|||||||
"($1, $2, $3, $4, $5);",
|
"($1, $2, $3, $4, $5);",
|
||||||
5, NULL);
|
5, NULL);
|
||||||
PREPARE ("update_reserve",
|
PREPARE ("update_reserve",
|
||||||
"UPDATE reserves "
|
"UPDATE reserves"
|
||||||
"SET"
|
" SET"
|
||||||
" expiration_date=$1 "
|
" expiration_date=$1 "
|
||||||
",current_balance_val=$2 "
|
",current_balance_val=$2 "
|
||||||
",current_balance_frac=$3 "
|
",current_balance_frac=$3 "
|
||||||
@ -492,7 +510,7 @@ postgres_prepare (PGconn *db_conn)
|
|||||||
"($1, $2, $3, $4, $5);",
|
"($1, $2, $3, $4, $5);",
|
||||||
5, NULL);
|
5, NULL);
|
||||||
PREPARE ("get_collectable_blindcoin",
|
PREPARE ("get_collectable_blindcoin",
|
||||||
"SELECT "
|
"SELECT"
|
||||||
" denom_pub"
|
" denom_pub"
|
||||||
",denom_sig"
|
",denom_sig"
|
||||||
",reserve_sig"
|
",reserve_sig"
|
||||||
@ -511,7 +529,7 @@ postgres_prepare (PGconn *db_conn)
|
|||||||
1, NULL);
|
1, NULL);
|
||||||
/* refreshing */
|
/* refreshing */
|
||||||
PREPARE ("get_refresh_session",
|
PREPARE ("get_refresh_session",
|
||||||
"SELECT "
|
"SELECT"
|
||||||
" num_oldcoins"
|
" num_oldcoins"
|
||||||
",num_newcoins"
|
",num_newcoins"
|
||||||
",noreveal_index"
|
",noreveal_index"
|
||||||
@ -519,13 +537,13 @@ postgres_prepare (PGconn *db_conn)
|
|||||||
" WHERE session_hash=$1 ",
|
" WHERE session_hash=$1 ",
|
||||||
1, NULL);
|
1, NULL);
|
||||||
PREPARE ("insert_refresh_session",
|
PREPARE ("insert_refresh_session",
|
||||||
"INSERT INTO refresh_sessions ( "
|
"INSERT INTO refresh_sessions "
|
||||||
" session_hash "
|
"(session_hash "
|
||||||
",num_oldcoins "
|
",num_oldcoins "
|
||||||
",num_newcoins "
|
",num_newcoins "
|
||||||
",noreveal_index "
|
",noreveal_index "
|
||||||
") "
|
") VALUES "
|
||||||
"VALUES ($1, $2, $3, $4) ",
|
"($1, $2, $3, $4);",
|
||||||
4, NULL);
|
4, NULL);
|
||||||
PREPARE ("get_known_coin",
|
PREPARE ("get_known_coin",
|
||||||
"SELECT"
|
"SELECT"
|
||||||
@ -535,26 +553,26 @@ postgres_prepare (PGconn *db_conn)
|
|||||||
" WHERE coin_pub=$1",
|
" WHERE coin_pub=$1",
|
||||||
1, NULL);
|
1, NULL);
|
||||||
PREPARE ("insert_known_coin",
|
PREPARE ("insert_known_coin",
|
||||||
"INSERT INTO known_coins ("
|
"INSERT INTO known_coins "
|
||||||
" coin_pub"
|
"(coin_pub"
|
||||||
",denom_pub"
|
",denom_pub"
|
||||||
",denom_sig"
|
",denom_sig"
|
||||||
")"
|
") VALUES "
|
||||||
"VALUES ($1,$2,$3)",
|
"($1,$2,$3)",
|
||||||
3, NULL);
|
3, NULL);
|
||||||
PREPARE ("get_refresh_commit_link",
|
PREPARE ("get_refresh_commit_link",
|
||||||
"SELECT"
|
"SELECT"
|
||||||
" transfer_pub "
|
" transfer_pub"
|
||||||
",link_secret_enc "
|
",link_secret_enc"
|
||||||
"FROM refresh_commit_link "
|
" FROM refresh_commit_link"
|
||||||
"WHERE session_hash=$1 AND cnc_index=$2 AND oldcoin_index=$3",
|
" WHERE session_hash=$1 AND cnc_index=$2 AND oldcoin_index=$3",
|
||||||
3, NULL);
|
3, NULL);
|
||||||
PREPARE ("get_refresh_commit_coin",
|
PREPARE ("get_refresh_commit_coin",
|
||||||
"SELECT"
|
"SELECT"
|
||||||
" link_vector_enc "
|
" link_vector_enc"
|
||||||
",coin_ev "
|
",coin_ev"
|
||||||
"FROM refresh_commit_coin "
|
" FROM refresh_commit_coin"
|
||||||
"WHERE session_hash=$1 AND cnc_index=$2 AND newcoin_index=$3",
|
" WHERE session_hash=$1 AND cnc_index=$2 AND newcoin_index=$3",
|
||||||
3, NULL);
|
3, NULL);
|
||||||
PREPARE ("insert_refresh_order",
|
PREPARE ("insert_refresh_order",
|
||||||
"INSERT INTO refresh_order "
|
"INSERT INTO refresh_order "
|
||||||
@ -591,41 +609,41 @@ postgres_prepare (PGconn *db_conn)
|
|||||||
PREPARE ("get_refresh_order",
|
PREPARE ("get_refresh_order",
|
||||||
"SELECT denom_pub "
|
"SELECT denom_pub "
|
||||||
"FROM refresh_order "
|
"FROM refresh_order "
|
||||||
"WHERE session_hash = $1 AND newcoin_index = $2",
|
"WHERE session_hash=$1 AND newcoin_index=$2",
|
||||||
2, NULL);
|
2, NULL);
|
||||||
PREPARE ("get_refresh_collectable",
|
PREPARE ("get_refresh_collectable",
|
||||||
"SELECT ev_sig "
|
"SELECT ev_sig "
|
||||||
"FROM refresh_collectable "
|
"FROM refresh_collectable "
|
||||||
"WHERE session_hash = $1 AND newcoin_index = $2",
|
"WHERE session_hash = $1 AND newcoin_index = $2",
|
||||||
2, NULL);
|
2, NULL);
|
||||||
#if 0 /* FIXME: not complete yet */
|
|
||||||
PREPARE ("insert_refresh_commit_link",
|
PREPARE ("insert_refresh_commit_link",
|
||||||
"INSERT INTO refresh_commit_link ("
|
"INSERT INTO refresh_commit_link "
|
||||||
" session_hash "
|
"(session_hash"
|
||||||
",transfer_pub "
|
",transfer_pub"
|
||||||
",cnc_index "
|
",cnc_index"
|
||||||
",oldcoin_index "
|
",oldcoin_index"
|
||||||
",link_secret_enc "
|
",link_secret_enc"
|
||||||
") "
|
") VALUES "
|
||||||
"VALUES ($1, $2, $3, $4, $5) ",
|
"($1, $2, $3, $4, $5);",
|
||||||
5, NULL);
|
5, NULL);
|
||||||
|
#if 0 /* FIXME: not complete yet */
|
||||||
PREPARE ("insert_refresh_commit_coin",
|
PREPARE ("insert_refresh_commit_coin",
|
||||||
"INSERT INTO refresh_commit_coin ("
|
"INSERT INTO refresh_commit_coin "
|
||||||
" session_hash "
|
"(session_hash"
|
||||||
",coin_ev "
|
",coin_ev"
|
||||||
",cnc_index "
|
",cnc_index"
|
||||||
",newcoin_index "
|
",newcoin_index"
|
||||||
",link_vector_enc "
|
",link_vector_enc"
|
||||||
") "
|
") VALUES "
|
||||||
"VALUES ($1, $2, $3, $4, $5)",
|
"($1, $2, $3, $4, $5);",
|
||||||
5, NULL);
|
5, NULL);
|
||||||
PREPARE ("insert_refresh_collectable",
|
PREPARE ("insert_refresh_collectable",
|
||||||
"INSERT INTO refresh_collectable ("
|
"INSERT INTO refresh_collectable "
|
||||||
" session_hash "
|
"(session_hash"
|
||||||
",newcoin_index "
|
",newcoin_index"
|
||||||
",ev_sig "
|
",ev_sig"
|
||||||
") "
|
") VALUES "
|
||||||
"VALUES ($1, $2, $3)",
|
"($1, $2, $3)",
|
||||||
3, NULL);
|
3, NULL);
|
||||||
PREPARE ("get_link",
|
PREPARE ("get_link",
|
||||||
"SELECT link_vector_enc, ro.denom_pub, ev_sig "
|
"SELECT link_vector_enc, ro.denom_pub, ev_sig "
|
||||||
@ -634,12 +652,13 @@ postgres_prepare (PGconn *db_conn)
|
|||||||
" JOIN refresh_commit_coin rcc USING (session_hash) "
|
" JOIN refresh_commit_coin rcc USING (session_hash) "
|
||||||
" JOIN refresh_sessions rs USING (session_hash) "
|
" JOIN refresh_sessions rs USING (session_hash) "
|
||||||
" JOIN refresh_collectable rc USING (session_hash) "
|
" JOIN refresh_collectable rc USING (session_hash) "
|
||||||
"WHERE rm.coin_pub = $1 "
|
"WHERE rm.coin_pub=$1"
|
||||||
"AND ro.newcoin_index = rcc.newcoin_index "
|
" AND ro.newcoin_index=rcc.newcoin_index"
|
||||||
"AND ro.newcoin_index = rc.newcoin_index "
|
" AND ro.newcoin_index=rc.newcoin_index"
|
||||||
"AND rcc.cnc_index = rs.noreveal_index % ( "
|
" AND rcc.cnc_index=rs.noreveal_index % ("
|
||||||
" SELECT count(*) FROM refresh_commit_coin rcc2 "
|
" SELECT count(*) FROM refresh_commit_coin rcc2"
|
||||||
" WHERE rcc2.newcoin_index = 0 AND rcc2.session_hash = rs.session_hash "
|
" WHERE rcc2.newcoin_index=0"
|
||||||
|
" AND rcc2.session_hash=rs.session_hash"
|
||||||
" ) ",
|
" ) ",
|
||||||
1, NULL);
|
1, NULL);
|
||||||
PREPARE ("get_transfer",
|
PREPARE ("get_transfer",
|
||||||
@ -647,65 +666,66 @@ postgres_prepare (PGconn *db_conn)
|
|||||||
"FROM refresh_melt rm "
|
"FROM refresh_melt rm "
|
||||||
" JOIN refresh_commit_link rcl USING (session_hash) "
|
" JOIN refresh_commit_link rcl USING (session_hash) "
|
||||||
" JOIN refresh_sessions rs USING (session_hash) "
|
" JOIN refresh_sessions rs USING (session_hash) "
|
||||||
"WHERE rm.coin_pub = $1 "
|
"WHERE rm.coin_pub=$1"
|
||||||
"AND rm.oldcoin_index = rcl.oldcoin_index "
|
" AND rm.oldcoin_index = rcl.oldcoin_index"
|
||||||
"AND rcl.cnc_index = rs.noreveal_index % ( "
|
" AND rcl.cnc_index=rs.noreveal_index % ("
|
||||||
" SELECT count(*) FROM refresh_commit_coin rcc2 "
|
" SELECT count(*) FROM refresh_commit_coin rcc2"
|
||||||
" WHERE newcoin_index = 0 AND rcc2.session_hash = rm.session_hash "
|
" WHERE newcoin_index=0"
|
||||||
|
" AND rcc2.session_hash=rm.session_hash"
|
||||||
" ) ",
|
" ) ",
|
||||||
1, NULL);
|
1, NULL);
|
||||||
#endif
|
#endif
|
||||||
PREPARE ("insert_deposit",
|
PREPARE ("insert_deposit",
|
||||||
"INSERT INTO deposits ("
|
"INSERT INTO deposits "
|
||||||
"coin_pub,"
|
"(coin_pub"
|
||||||
"denom_pub,"
|
",denom_pub"
|
||||||
"denom_sig,"
|
",denom_sig"
|
||||||
"transaction_id,"
|
",transaction_id"
|
||||||
"amount_val,"
|
",amount_val"
|
||||||
"amount_frac,"
|
",amount_frac"
|
||||||
"amount_curr,"
|
",amount_curr"
|
||||||
"merchant_pub,"
|
",merchant_pub"
|
||||||
"h_contract,"
|
",h_contract"
|
||||||
"h_wire,"
|
",h_wire"
|
||||||
"coin_sig,"
|
",coin_sig"
|
||||||
"wire"
|
",wire"
|
||||||
") VALUES ("
|
") VALUES "
|
||||||
"$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12"
|
"($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)",
|
||||||
")",
|
|
||||||
12, NULL);
|
12, NULL);
|
||||||
PREPARE ("get_deposit",
|
PREPARE ("get_deposit",
|
||||||
"SELECT "
|
"SELECT"
|
||||||
"coin_pub,"
|
" coin_pub"
|
||||||
"denom_pub,"
|
",denom_pub"
|
||||||
"transaction_id,"
|
",transaction_id"
|
||||||
"amount_val,"
|
",amount_val"
|
||||||
"amount_frac,"
|
",amount_frac"
|
||||||
"amount_curr,"
|
",amount_curr"
|
||||||
"merchant_pub,"
|
",merchant_pub"
|
||||||
"h_contract,"
|
",h_contract"
|
||||||
"h_wire,"
|
",h_wire"
|
||||||
"coin_sig"
|
",coin_sig"
|
||||||
" FROM deposits WHERE ("
|
" FROM deposits"
|
||||||
"(coin_pub = $1) AND"
|
"WHERE ("
|
||||||
"(transaction_id = $2) AND"
|
" (coin_pub = $1) AND"
|
||||||
"(merchant_pub = $3)"
|
" (transaction_id = $2) AND"
|
||||||
")",
|
" (merchant_pub = $3)"
|
||||||
|
" )",
|
||||||
3, NULL);
|
3, NULL);
|
||||||
PREPARE ("get_deposit_with_coin_pub",
|
PREPARE ("get_deposit_with_coin_pub",
|
||||||
"SELECT "
|
"SELECT"
|
||||||
"coin_pub,"
|
" coin_pub"
|
||||||
"denom_pub,"
|
",denom_pub"
|
||||||
"transaction_id,"
|
",transaction_id"
|
||||||
"amount_val,"
|
",amount_val"
|
||||||
"amount_frac,"
|
",amount_frac"
|
||||||
"amount_curr,"
|
",amount_curr"
|
||||||
"merchant_pub,"
|
",merchant_pub"
|
||||||
"h_contract,"
|
",h_contract"
|
||||||
"h_wire,"
|
",h_wire"
|
||||||
"wire,"
|
",wire"
|
||||||
"coin_sig"
|
",coin_sig"
|
||||||
" FROM deposits WHERE "
|
" FROM deposits"
|
||||||
" coin_pub = $1",
|
" WHERE coin_pub=$1",
|
||||||
1, NULL);
|
1, NULL);
|
||||||
|
|
||||||
return GNUNET_OK;
|
return GNUNET_OK;
|
||||||
|
Loading…
Reference in New Issue
Block a user