Skip to content

Commit

Permalink
AND-5746 Moved extensions for 'Result' model to other file
Browse files Browse the repository at this point in the history
  • Loading branch information
iiiburnyiii committed Jan 16, 2024
1 parent fdeff1c commit 29e77e6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 31 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@ class VechainTransactionBuilder(blockchain: Blockchain, private val publicKey: W
minimum = Fee.Vechain(
amount = Amount(
token = VechainWalletManager.VTHO_TOKEN,
value = gas.toBigDecimal().movePointLeft(GAS_TO_VET_DECIMAL)
value = gas.toBigDecimal().movePointLeft(GAS_TO_VET_DECIMAL),
),
gasPriceCoef = 0,
),
normal = Fee.Vechain(
amount = Amount(
token = VechainWalletManager.VTHO_TOKEN,
value = (gas * 1.5).toBigDecimal().movePointLeft(GAS_TO_VET_DECIMAL)
value = (gas * 1.5).toBigDecimal().movePointLeft(GAS_TO_VET_DECIMAL),
),
gasPriceCoef = 127,
),
priority = Fee.Vechain(
amount = Amount(
token = VechainWalletManager.VTHO_TOKEN,
value = (gas * 2).toBigDecimal().movePointLeft(GAS_TO_VET_DECIMAL)
value = (gas * 2).toBigDecimal().movePointLeft(GAS_TO_VET_DECIMAL),
),
gasPriceCoef = 255,
),
Expand Down Expand Up @@ -85,7 +85,7 @@ class VechainTransactionBuilder(blockchain: Blockchain, private val publicKey: W
fee,
transactionData.destinationAddress,
blockInfo,
nonce
nonce,
)

val publicKeys = DataVector()
Expand All @@ -95,7 +95,10 @@ class VechainTransactionBuilder(blockchain: Blockchain, private val publicKey: W
signatures.add(unmarshalSignature(signature, hash, publicKey))

val compileWithSignatures = TransactionCompiler.compileWithSignatures(
coinType, inputData.toByteArray(), signatures, publicKeys
coinType,
inputData.toByteArray(),
signatures,
publicKeys,
)

val output = VeChain.SigningOutput.parseFrom(compileWithSignatures)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal class VechainNetworkService(
accountResponse = accountInfoDeferred.await().extractResult(),
pendingTxsInfo = pendingTxsDeferred.awaitAll().map { it.extractResult() },
tokenBalances = tokenBalances,
)
),
)
}
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal object VechainWalletManagerAssembly : WalletManagerAssembly<VechainWall
override fun make(input: WalletManagerAssemblyInput): VechainWalletManager {
return VechainWalletManager(
wallet = input.wallet,
networkProviders = VechainNetworkProvidersBuilder().build(input.wallet.blockchain.isTestnet(), input.config)
networkProviders = VechainNetworkProvidersBuilder().build(input.wallet.blockchain.isTestnet(), input.config),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package com.tangem.blockchain.extensions

import com.tangem.blockchain.common.BlockchainError
import com.tangem.blockchain.common.BlockchainSdkError
import com.tangem.common.CompletionResult
import com.tangem.common.core.TangemError
import kotlinx.coroutines.delay
import java.io.IOException

suspend fun <T> retryIO(
internal suspend fun <T> retryIO(
times: Int = 3,
initialDelay: Long = 100,
maxDelay: Long = 1000,
Expand Down Expand Up @@ -36,24 +37,31 @@ sealed class Result<out T> {
}
}

inline fun <T> Result<T>.successOr(failureClause: (Result.Failure) -> T): T {
internal inline fun <T> Result<T>.successOr(failureClause: (Result.Failure) -> T): T {
return when (this) {
is Result.Success -> this.data
is Result.Failure -> failureClause(this)
}
}

inline fun <A, B> Result<A>.map(block: (A) -> B): Result<B> {
internal inline fun <A, B> Result<A>.map(block: (A) -> B): Result<B> {
return when (this) {
is Result.Success -> Result.Success(block(this.data))
is Result.Failure -> this
}
}

fun Result.Failure.toSimpleFailure(): SimpleResult.Failure {
internal fun Result.Failure.toSimpleFailure(): SimpleResult.Failure {
return SimpleResult.Failure(error)
}

internal fun <T> Result<T>.toSimpleResult(): SimpleResult {
return when (this) {
is Result.Success -> SimpleResult.Success
is Result.Failure -> SimpleResult.Failure(this.error)
}
}

sealed class SimpleResult {
object Success : SimpleResult()
data class Failure(val error: BlockchainError) : SimpleResult()
Expand All @@ -65,9 +73,16 @@ sealed class SimpleResult {
}
}

inline fun SimpleResult.successOr(failureClause: (SimpleResult.Failure) -> Nothing): SimpleResult.Success {
internal inline fun SimpleResult.successOr(failureClause: (SimpleResult.Failure) -> Nothing): SimpleResult.Success {
return when (this) {
is SimpleResult.Success -> this
is SimpleResult.Failure -> failureClause(this)
}
}

internal inline fun <T> CompletionResult<T>.successOr(failureClause: (CompletionResult.Failure<T>) -> Nothing): T {
return when (this) {
is CompletionResult.Success -> this.data
is CompletionResult.Failure -> failureClause(this)
}
}

0 comments on commit 29e77e6

Please sign in to comment.