mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-19 01:24:21 +01:00
accounts: make fallback pk non optional
Note: this commit alone is *incorrect* and will cause crashes. It is part of a greater plan to upgrade accounts. It was done this way to break commits to smaller, more digestable chunks Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -20,11 +20,15 @@ pub struct Accounts {
|
|||||||
account_data: BTreeMap<[u8; 32], AccountData>,
|
account_data: BTreeMap<[u8; 32], AccountData>,
|
||||||
relay_defaults: RelayDefaults,
|
relay_defaults: RelayDefaults,
|
||||||
needs_relay_config: bool,
|
needs_relay_config: bool,
|
||||||
fallback: Option<Pubkey>,
|
fallback: Pubkey,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Accounts {
|
impl Accounts {
|
||||||
pub fn new(key_store: Option<AccountStorage>, forced_relays: Vec<String>) -> Self {
|
pub fn new(
|
||||||
|
key_store: Option<AccountStorage>,
|
||||||
|
forced_relays: Vec<String>,
|
||||||
|
fallback: Pubkey,
|
||||||
|
) -> Self {
|
||||||
let accounts = match &key_store {
|
let accounts = match &key_store {
|
||||||
Some(keystore) => match keystore.get_accounts() {
|
Some(keystore) => match keystore.get_accounts() {
|
||||||
Ok(k) => k,
|
Ok(k) => k,
|
||||||
@@ -53,7 +57,7 @@ impl Accounts {
|
|||||||
account_data,
|
account_data,
|
||||||
relay_defaults,
|
relay_defaults,
|
||||||
needs_relay_config: true,
|
needs_relay_config: true,
|
||||||
fallback: None,
|
fallback,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +86,7 @@ impl Accounts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_fallback(&mut self, fallback: Pubkey) {
|
pub fn with_fallback(&mut self, fallback: Pubkey) {
|
||||||
self.fallback = Some(fallback);
|
self.fallback = fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_account(&mut self, index: usize) {
|
pub fn remove_account(&mut self, index: usize) {
|
||||||
@@ -359,11 +363,9 @@ impl Accounts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn handle_no_accounts(&mut self, unknown_ids: &mut UnknownIds, ndb: &Ndb, txn: &Transaction) {
|
fn handle_no_accounts(&mut self, unknown_ids: &mut UnknownIds, ndb: &Ndb, txn: &Transaction) {
|
||||||
if let Some(fallback) = self.fallback {
|
self.add_account(Keypair::new(self.fallback, None))
|
||||||
self.add_account(Keypair::new(fallback, None))
|
.process_action(unknown_ids, ndb, txn);
|
||||||
.process_action(unknown_ids, ndb, txn);
|
self.select_account(self.num_accounts() - 1);
|
||||||
self.select_account(self.num_accounts() - 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poll_for_updates(&mut self, ndb: &Ndb) -> bool {
|
fn poll_for_updates(&mut self, ndb: &Ndb) -> bool {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::account::FALLBACK_PUBKEY;
|
||||||
use crate::persist::{AppSizeHandler, ZoomHandler};
|
use crate::persist::{AppSizeHandler, ZoomHandler};
|
||||||
use crate::wallet::GlobalWallet;
|
use crate::wallet::GlobalWallet;
|
||||||
use crate::zaps::Zaps;
|
use crate::zaps::Zaps;
|
||||||
@@ -176,7 +177,7 @@ impl Notedeck {
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut accounts = Accounts::new(keystore, parsed_args.relays.clone());
|
let mut accounts = Accounts::new(keystore, parsed_args.relays.clone(), FALLBACK_PUBKEY());
|
||||||
|
|
||||||
let num_keys = parsed_args.keys.len();
|
let num_keys = parsed_args.keys.len();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user