Skip to content

Commit

Permalink
feat: add gracefull recovery from errors
Browse files Browse the repository at this point in the history
- this feature enables toggling btn throwing errors and returning Option.None'
- it defaults to false
  • Loading branch information
astinz committed Jul 15, 2024
1 parent 2529f60 commit 7dd64d7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
22 changes: 20 additions & 2 deletions lib/src/commonMain/kotlin/xyz/mcxross/kaptos/Aptos.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package xyz.mcxross.kaptos

import xyz.mcxross.kaptos.core.Application
import xyz.mcxross.kaptos.model.*
import xyz.mcxross.kaptos.protocol.*

Expand All @@ -24,12 +25,29 @@ import xyz.mcxross.kaptos.protocol.*
*
* @param config [AptosConfig] to optionally configure the SDK.
*/
class Aptos(override val config: AptosConfig = AptosConfig()) :
class Aptos(
override val config: AptosConfig = AptosConfig(),
graceFull: Boolean = Application.graceFull,
) :
Account by xyz.mcxross.kaptos.api.Account(config),
Coin by xyz.mcxross.kaptos.api.Coin(config),
General by xyz.mcxross.kaptos.api.General(config),
Transaction by xyz.mcxross.kaptos.api.Transaction(config),
Staking by xyz.mcxross.kaptos.api.Staking(config),
DigitalAsset by xyz.mcxross.kaptos.api.DigitalAsset(config),
Faucet by xyz.mcxross.kaptos.api.Faucet(config),
Ans by xyz.mcxross.kaptos.api.Ans(config)
Ans by xyz.mcxross.kaptos.api.Ans(config) {

init {
Application.graceFull = graceFull
}

/**
* Returns the current graceFull setting.
*
* @return [Boolean] indicating if the SDK is in graceFull mode.
*/
fun isGraceFull(): Boolean {
return Application.graceFull
}
}
28 changes: 28 additions & 0 deletions lib/src/commonMain/kotlin/xyz/mcxross/kaptos/core/Application.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2024 McXross
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package xyz.mcxross.kaptos.core

import xyz.mcxross.kaptos.model.Option

/**
* The [Application] object is used to store global state for the SDK.
*
* @property graceFull [Boolean] indicating if the SDK is in graceFull mode. This is used to
* determine if the SDK should throw exceptions or return [Option.None].
*/
internal object Application {
var graceFull: Boolean = false
}

0 comments on commit 7dd64d7

Please sign in to comment.