diff options
Diffstat (limited to 'src/commonMain/kotlin/net/taler/wallet/kotlin/reserve/ReserveRecord.kt')
-rw-r--r-- | src/commonMain/kotlin/net/taler/wallet/kotlin/reserve/ReserveRecord.kt | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/src/commonMain/kotlin/net/taler/wallet/kotlin/reserve/ReserveRecord.kt b/src/commonMain/kotlin/net/taler/wallet/kotlin/reserve/ReserveRecord.kt new file mode 100644 index 0000000..b618719 --- /dev/null +++ b/src/commonMain/kotlin/net/taler/wallet/kotlin/reserve/ReserveRecord.kt @@ -0,0 +1,160 @@ +/* + * This file is part of GNU Taler + * (C) 2020 Taler Systems S.A. + * + * GNU Taler is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 3, or (at your option) any later version. + * + * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + +package net.taler.wallet.kotlin.reserve + +import net.taler.wallet.kotlin.Amount +import net.taler.wallet.kotlin.Timestamp +import net.taler.wallet.kotlin.exchange.DenominationSelectionInfo + +/** + * A reserve record as stored in the wallet's database. + */ +data class Reserve( + /** + * The reserve public key. + */ + val reservePub: String, + + /** + * The reserve private key. + */ + val reservePriv: String, + + /** + * The exchange base URL. + */ + val exchangeBaseUrl: String, + + /** + * Currency of the reserve. + */ + val currency: String, + + /** + * Time when the reserve was created. + */ + val timestampCreated: Timestamp, + + /** + * Time when the information about this reserve was posted to the bank. + * + * Only applies if bankWithdrawStatusUrl is not null. + * + * Set to 0 if that hasn't happened yet. + */ + val timestampReserveInfoPosted: Timestamp? = null, + + /** + * Time when the reserve was confirmed, either manually by the user or by the bank. + * + * Set to undefined if not confirmed yet. + */ + val timestampConfirmed: Timestamp? = null, + + /** + * Wire information (as payto URI) for the bank account that transferred funds for this reserve. + */ + val senderPaytoUri: String?, + + /** + * Wire information (as payto URI) for the exchange, + * specifically the account that was transferred to when creating the reserve. + */ + val exchangePaytoUri: String, + + /** + * Extra state for when this is a withdrawal involving a Taler-integrated bank. + */ + val bankInfo: ReserveBankInfo?, + + val reserveStatus: ReserveRecordStatus, + + /** + * Time of the last successful status query. + */ + val lastSuccessfulStatusQuery: Timestamp? = null, + + /** + * Retry info. This field is present even if no retry is scheduled, + * because we need it to be present for the index on the object store + * to work. + */ + val retryInfo: RetryInfo +) + +enum class ReserveRecordStatus(val value: String) { + /** + * Waiting for manual confirmation. + */ + UNCONFIRMED("unconfirmed"), + + /** + * Reserve must be registered with the bank. + */ + REGISTERING_BANK("registering-bank"), + + /** + * We've registered reserve's information with the bank + * and are now waiting for the user to confirm the withdraw + * with the bank (typically 2nd factor auth). + */ + WAIT_CONFIRM_BANK("wait-confirm-bank"), + + /** + * Querying reserve status with the exchange. + */ + QUERYING_STATUS("querying-status"), + + /** + * Status is queried, the wallet must now select coins + * and start withdrawing. + */ + WITHDRAWING("withdrawing"), + + /** + * The corresponding withdraw record has been created. + * No further processing is done, unless explicitly requested + * by the user. + */ + DORMANT("dormant") +} + +data class ReserveBankInfo( + val statusUrl: String, + val confirmUrl: String? = null, + val amount: Amount, + val bankWithdrawalGroupId: String, + val withdrawalStarted: Boolean, + val denomSel: DenominationSelectionInfo? = null // TODO do we really need this? nullable for now +) + +data class RetryInfo( + val firstTry: Timestamp, + val nextRetry: Timestamp, + val retryCounter: Int, + val active: Boolean +) { + // TODO implement retry policies and set proper nextRetry + companion object { + fun getInitial() = RetryInfo( + firstTry = Timestamp.now(), + nextRetry = Timestamp(0), + retryCounter = 0, + active = true + ) + } +} |