Skip to content

Commit 4bbc964

Browse files
committed
electrum: login_user: prevent AccountGapsDisallowed
Subaccounts created at login come from the cache/store so in theory they can't have gaps. But if for any reason we see a gap here, we should not error and prevent login since it might lock a user out of its wallet. GA_create_subaccount will still error if there is a gap.
1 parent 6afe08c commit 4bbc964

File tree

5 files changed

+10
-2
lines changed

5 files changed

+10
-2
lines changed

src/ga_auth_handlers.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,8 @@ namespace sdk {
530530
// Fall through to create the subaccount
531531
}
532532

533+
// This is an actual subaccount creation, do not allow the caller to set this flag
534+
m_details.erase("is_already_created");
533535
// Create the subaccount
534536
m_result = m_session->create_subaccount(m_details, m_subaccount, m_subaccount_xpub);
535537
// Ensure the server created the subaccount number we expected

src/ga_rust.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ namespace sdk {
108108
const std::vector<uint32_t>& pointers, const std::vector<std::string>& bip32_xpubs)
109109
{
110110
// Note we only register each loaded subaccount once.
111-
const nlohmann::json details({ { "name", std::string() } });
111+
// Subaccount to register has already been created, so we
112+
// set a flag to avoid the checks on the (sub)account gaps.
113+
const nlohmann::json details({ { "name", std::string() }, { "is_already_created", true } });
112114
for (size_t i = 0; i < pointers.size(); ++i) {
113115
const auto pointer = pointers.at(i);
114116
if (!m_user_pubkeys->have_subaccount(pointer)) {

subprojects/gdk_rust/gdk_common/src/model.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ pub struct CreateAccountOpt {
206206
pub xpub: Option<ExtendedPubKey>,
207207
#[serde(default)]
208208
pub discovered: bool,
209+
#[serde(default)]
210+
pub is_already_created: bool,
209211
}
210212

211213
#[derive(Serialize, Deserialize, Debug, Clone)]

subprojects/gdk_rust/gdk_electrum/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ impl ElectrumSession {
418418
name: "".to_string(),
419419
xpub: Some(xpub),
420420
discovered: false,
421+
is_already_created: true,
421422
})?;
422423
}
423424

@@ -818,7 +819,7 @@ impl ElectrumSession {
818819
let account = accounts
819820
.get(&last_account)
820821
.ok_or_else(|| Error::InvalidSubaccount(last_account))?;
821-
if !account.has_transactions()? {
822+
if !opt.is_already_created && !account.has_transactions()? {
822823
bail!(Error::AccountGapsDisallowed);
823824
}
824825
}

subprojects/gdk_rust/gdk_test/src/electrum_session_ext.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ impl ElectrumSessionExt for ElectrumSession {
5858
name: "".to_string(),
5959
xpub: Some(xpub),
6060
discovered: false,
61+
is_already_created: true,
6162
};
6263
self.create_subaccount(opt).unwrap();
6364
}

0 commit comments

Comments
 (0)