Commit ab7f1b9 1 parent 24b6d50 commit ab7f1b9 Copy full SHA for ab7f1b9
File tree 4 files changed +14
-19
lines changed
zcash_client_sqlite/src/wallet
4 files changed +14
-19
lines changed Original file line number Diff line number Diff line change @@ -116,13 +116,14 @@ pub(super) const TABLE_EPHEMERAL_ADDRESSES: &str = r#"
116
116
CREATE TABLE ephemeral_addresses (
117
117
account_id INTEGER NOT NULL,
118
118
address_index INTEGER NOT NULL,
119
- address TEXT,
119
+ address TEXT NOT NULL ,
120
120
used_in_tx INTEGER,
121
121
seen_in_tx INTEGER,
122
122
FOREIGN KEY (account_id) REFERENCES accounts(id),
123
123
FOREIGN KEY (used_in_tx) REFERENCES transactions(id_tx),
124
124
FOREIGN KEY (seen_in_tx) REFERENCES transactions(id_tx),
125
125
PRIMARY KEY (account_id, address_index),
126
+ CONSTRAINT ephemeral_addr_uniq UNIQUE (address),
126
127
CONSTRAINT used_implies_seen CHECK (
127
128
used_in_tx IS NULL OR seen_in_tx IS NOT NULL
128
129
),
@@ -135,10 +136,6 @@ CREATE TABLE ephemeral_addresses (
135
136
// libsqlite3-sys requires at least version 3.14.0.
136
137
// "WITHOUT ROWID" tells SQLite to use a clustered index on the (composite) primary key.
137
138
const_assert_eq ! ( GAP_LIMIT , 20 ) ;
138
- pub ( super ) const INDEX_EPHEMERAL_ADDRESSES_ADDRESS : & str = r#"
139
- CREATE INDEX ephemeral_addresses_address ON ephemeral_addresses (
140
- address ASC
141
- )"# ;
142
139
143
140
/// Stores information about every block that the wallet has scanned.
144
141
///
Original file line number Diff line number Diff line change @@ -422,7 +422,6 @@ mod tests {
422
422
db:: INDEX_ACCOUNTS_UIVK ,
423
423
db:: INDEX_HD_ACCOUNT ,
424
424
db:: INDEX_ADDRESSES_ACCOUNTS ,
425
- db:: INDEX_EPHEMERAL_ADDRESSES_ADDRESS ,
426
425
db:: INDEX_NF_MAP_LOCATOR_IDX ,
427
426
db:: INDEX_ORCHARD_RECEIVED_NOTES_ACCOUNT ,
428
427
db:: INDEX_ORCHARD_RECEIVED_NOTES_TX ,
Original file line number Diff line number Diff line change @@ -45,24 +45,22 @@ impl<P: consensus::Parameters> RusqliteMigration for Migration<P> {
45
45
"CREATE TABLE ephemeral_addresses (
46
46
account_id INTEGER NOT NULL,
47
47
address_index INTEGER NOT NULL,
48
- address TEXT,
48
+ address TEXT NOT NULL ,
49
49
used_in_tx INTEGER,
50
50
seen_in_tx INTEGER,
51
51
FOREIGN KEY (account_id) REFERENCES accounts(id),
52
52
FOREIGN KEY (used_in_tx) REFERENCES transactions(id_tx),
53
53
FOREIGN KEY (seen_in_tx) REFERENCES transactions(id_tx),
54
54
PRIMARY KEY (account_id, address_index),
55
+ CONSTRAINT ephemeral_addr_uniq UNIQUE (address),
55
56
CONSTRAINT used_implies_seen CHECK (
56
57
used_in_tx IS NULL OR seen_in_tx IS NOT NULL
57
58
),
58
59
CONSTRAINT index_range_and_address_nullity CHECK (
59
60
(address_index BETWEEN 0 AND 0x7FFFFFFF AND address IS NOT NULL) OR
60
61
(address_index BETWEEN 0x80000000 AND 0x7FFFFFFF + 20 AND address IS NULL AND used_in_tx IS NULL AND seen_in_tx IS NULL)
61
62
)
62
- ) WITHOUT ROWID;
63
- CREATE INDEX ephemeral_addresses_address ON ephemeral_addresses (
64
- address ASC
65
- );" ,
63
+ ) WITHOUT ROWID;"
66
64
) ?;
67
65
68
66
// Make sure that at least `GAP_LIMIT` ephemeral transparent addresses are
Original file line number Diff line number Diff line change @@ -282,18 +282,19 @@ fn reserve_until<P: consensus::Parameters>(
282
282
) ?;
283
283
284
284
for raw_index in range_to_store {
285
- let address_str_opt = match NonHardenedChildIndex :: from_index ( raw_index) {
286
- Some ( address_index) => Some (
285
+ let address_str = NonHardenedChildIndex :: from_index ( raw_index)
286
+ . map ( | address_index| {
287
287
ephemeral_ivk
288
- . derive_ephemeral_address ( address_index) ?
289
- . encode ( params) ,
290
- ) ,
291
- None => None ,
292
- } ;
288
+ . derive_ephemeral_address ( address_index)
289
+ . map ( |addr| addr. encode ( params) )
290
+ } )
291
+ . transpose ( ) ?
292
+ . expect ( "we do not attempt to generate addresses outside the non-hardened index range" ) ;
293
+
293
294
stmt_insert_ephemeral_address. execute ( named_params ! [
294
295
":account_id" : account_id. 0 ,
295
296
":address_index" : raw_index,
296
- ":address" : address_str_opt ,
297
+ ":address" : address_str ,
297
298
] ) ?;
298
299
}
299
300
Ok ( ( ) )
You can’t perform that action at this time.
0 commit comments