fix(wallet): avoid saving read-only snapshots

This commit is contained in:
Ricardo Guilherme Schmidt 2026-07-17 20:06:15 -03:00
parent 7a09449371
commit 7d1bef9795
No known key found for this signature in database
GPG Key ID: 1396EA17DE132FFE
2 changed files with 8 additions and 14 deletions

View File

@ -499,8 +499,6 @@ WalletSnapshot LogosWalletProvider::loadSnapshot()
result.accounts.append(account); result.accounts.append(account);
} }
if (!save())
result.failure = WalletFailure::SaveFailed;
return result; return result;
} }
@ -590,18 +588,11 @@ void LogosWalletProvider::loadSnapshotAsync(quint64 generation, SnapshotCallback
state->snapshot.publicAccountReads.append( state->snapshot.publicAccountReads.append(
state->publicReads.at(index)); state->publicReads.at(index));
} }
m_impl->logos->logos_execution_zone.saveAsync( if (state->snapshot.ok()) {
[this, generation, state](int result) mutable { m_snapshot = state->snapshot;
if (generation != m_generation) m_snapshotReady = true;
return; }
if (result != WALLET_FFI_SUCCESS) state->callback(std::move(state->snapshot));
state->snapshot.failure = WalletFailure::SaveFailed;
if (state->snapshot.ok()) {
m_snapshot = state->snapshot;
m_snapshotReady = true;
}
state->callback(std::move(state->snapshot));
});
}; };
if (entries.isEmpty()) { if (entries.isEmpty()) {

View File

@ -100,6 +100,7 @@ void LogosWalletProviderTest::adoptsOpenWalletAndCachesSnapshots()
const int listCalls = modules.logos_execution_zone.listCalls; const int listCalls = modules.logos_execution_zone.listCalls;
const int readCalls = modules.logos_execution_zone.publicReadCalls; const int readCalls = modules.logos_execution_zone.publicReadCalls;
const int saveCalls = modules.logos_execution_zone.saveCalls;
QVERIFY(provider.snapshot().ok()); QVERIFY(provider.snapshot().ok());
QCOMPARE(modules.logos_execution_zone.listCalls, listCalls); QCOMPARE(modules.logos_execution_zone.listCalls, listCalls);
QCOMPARE(modules.logos_execution_zone.publicReadCalls, readCalls); QCOMPARE(modules.logos_execution_zone.publicReadCalls, readCalls);
@ -107,6 +108,7 @@ void LogosWalletProviderTest::adoptsOpenWalletAndCachesSnapshots()
QVERIFY(provider.snapshot(true).ok()); QVERIFY(provider.snapshot(true).ok());
QVERIFY(modules.logos_execution_zone.listCalls > listCalls); QVERIFY(modules.logos_execution_zone.listCalls > listCalls);
QVERIFY(modules.logos_execution_zone.publicReadCalls > readCalls); QVERIFY(modules.logos_execution_zone.publicReadCalls > readCalls);
QCOMPARE(modules.logos_execution_zone.saveCalls, saveCalls);
modules.logos_execution_zone.publicAccounts[ACCOUNT_A] = publicAccountJson( modules.logos_execution_zone.publicAccounts[ACCOUNT_A] = publicAccountJson(
PROGRAM_ID, QString(32, QLatin1Char('f'))); PROGRAM_ID, QString(32, QLatin1Char('f')));
@ -511,6 +513,7 @@ void LogosWalletProviderTest::completedAsyncSnapshotReleasesCallback()
QVERIFY(completed); QVERIFY(completed);
QVERIFY(callbackLifetime.expired()); QVERIFY(callbackLifetime.expired());
QCOMPARE(modules.logos_execution_zone.saveCalls, 0);
} }
void LogosWalletProviderTest::deferredCallbacksIgnoreDestroyedController() void LogosWalletProviderTest::deferredCallbacksIgnoreDestroyedController()