fix(service-party-android): 导出钱包时自动从后端获取空的 partyId
旧版本钱包(MIGRATION_2_3 之前创建的)partyId 为空,导出时会导致备份文件 中 partyId 字段为空。现在导出时检测到 partyId 为空会自动从后端 session 状态 API 获取正确的 partyId,并同时更新本地数据库。 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
b4afc4615c
commit
6be4775506
|
|
@ -2089,8 +2089,39 @@ class TssRepository @Inject constructor(
|
|||
android.util.Log.d("TssRepository", "[EXPORT] - publicKey length: ${share.publicKey.length}")
|
||||
android.util.Log.d("TssRepository", "[EXPORT] - encryptedShare length: ${share.encryptedShare.length}")
|
||||
|
||||
android.util.Log.d("TssRepository", "[EXPORT] Converting to ShareBackup...")
|
||||
val backup = ShareBackup.fromShareRecord(share.toShareRecord())
|
||||
// If partyId is empty (legacy data from before MIGRATION_2_3), fetch it from backend
|
||||
var effectivePartyId = share.partyId
|
||||
if (effectivePartyId.isEmpty()) {
|
||||
android.util.Log.w("TssRepository", "[EXPORT] partyId is empty (legacy data), fetching from backend...")
|
||||
try {
|
||||
val sessionStatusResult = getSessionStatus(share.sessionId)
|
||||
if (sessionStatusResult.isSuccess) {
|
||||
val sessionStatus = sessionStatusResult.getOrThrow()
|
||||
// Find participant by partyIndex
|
||||
val participant = sessionStatus.participants.find { it.partyIndex == share.partyIndex }
|
||||
if (participant != null && participant.partyId.isNotEmpty()) {
|
||||
effectivePartyId = participant.partyId
|
||||
android.util.Log.d("TssRepository", "[EXPORT] Retrieved partyId from backend: $effectivePartyId")
|
||||
|
||||
// Also update the database for future exports
|
||||
val updatedShare = share.copy(partyId = effectivePartyId)
|
||||
shareRecordDao.insertShare(updatedShare)
|
||||
android.util.Log.d("TssRepository", "[EXPORT] Updated partyId in database")
|
||||
} else {
|
||||
android.util.Log.w("TssRepository", "[EXPORT] Could not find participant with partyIndex=${share.partyIndex} in session")
|
||||
}
|
||||
} else {
|
||||
android.util.Log.w("TssRepository", "[EXPORT] Failed to get session status: ${sessionStatusResult.exceptionOrNull()?.message}")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.w("TssRepository", "[EXPORT] Error fetching partyId from backend: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
android.util.Log.d("TssRepository", "[EXPORT] Converting to ShareBackup with partyId: $effectivePartyId")
|
||||
// Create ShareRecord with effective partyId (may be fetched from backend)
|
||||
val shareRecord = share.toShareRecord().copy(partyId = effectivePartyId)
|
||||
val backup = ShareBackup.fromShareRecord(shareRecord)
|
||||
android.util.Log.d("TssRepository", "[EXPORT] ShareBackup created, version: ${backup.version}")
|
||||
|
||||
android.util.Log.d("TssRepository", "[EXPORT] Serializing to JSON...")
|
||||
|
|
|
|||
Loading…
Reference in New Issue