Skip to content

Commit

Permalink
[WAL-1123/WAL-816/WAL-870]: Bump SDK version and remove deprecated cl…
Browse files Browse the repository at this point in the history
…asses (#117)

* WAL-1123: Bump SDK version

* Remove deprecated classes

* Fix version declaration
  • Loading branch information
Ifropc authored Sep 20, 2023
1 parent ac2a0f1 commit a97b5d2
Show file tree
Hide file tree
Showing 24 changed files with 70 additions and 1,026 deletions.
5 changes: 3 additions & 2 deletions docs/WalletGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ Once the Wallet is configured, you can use the following:

<!--- INCLUDE .*account.*
import org.stellar.sdk.responses.operations.OperationResponse
import org.stellar.sdk.responses.AccountResponse
import org.stellar.walletsdk.*
-->
<!--- SUFFIX .*account.*
Expand All @@ -150,15 +151,15 @@ val accountKeyPair = account.createKeyPair()
Get account information from the Stellar network (assets, liquidity pools, and reserved native balance).

```kotlin
suspend fun getAccountInfo(): AccountInfo {
suspend fun getAccountInfo(): AccountResponse {
return account.getInfo(accountKeyPair.address)
}
```

Get account history (all operations) from the Stellar network.

```kotlin
suspend fun getAccountHistory(): List<WalletOperation<OperationResponse>> {
suspend fun getAccountHistory(): List<OperationResponse> {
return account.getHistory(accountKeyPair.address)
}
```
Expand Down
5 changes: 3 additions & 2 deletions examples/documentation/src/example-account-01.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
package org.stellar.example.exampleAccount01

import org.stellar.sdk.responses.operations.OperationResponse
import org.stellar.sdk.responses.AccountResponse
import org.stellar.walletsdk.*

val wallet = Wallet(StellarConfiguration.Testnet)

val account = wallet.stellar().account()
val accountKeyPair = account.createKeyPair()

suspend fun getAccountInfo(): AccountInfo {
suspend fun getAccountInfo(): AccountResponse {
return account.getInfo(accountKeyPair.address)
}

suspend fun getAccountHistory(): List<WalletOperation<OperationResponse>> {
suspend fun getAccountHistory(): List<OperationResponse> {
return account.getHistory(accountKeyPair.address)
}
suspend fun main() {
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
coroutines = "1.6.4"
google-gson = "2.8.9"
hoplite = "2.7.0"
java-stellar-sdk = "0.40.0"
java-stellar-sdk = "0.41.0"
dokka = "1.6.10"
kotlin = "1.8.20"
kotlinx-json = "1.5.0"
Expand Down
2 changes: 1 addition & 1 deletion wallet-sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ configurations {

dependencies {
api(libs.coroutines.core)
api(libs.java.stellar.sdk)
api(variantOf(libs.java.stellar.sdk) { classifier("uber") })
api(libs.kotlin.datetime)
api(libs.bundles.ktor.client)
implementation(libs.kotlin.serialization.json)
Expand Down
11 changes: 0 additions & 11 deletions wallet-sdk/src/main/kotlin/org/stellar/walletsdk/Constant.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,6 @@ package org.stellar.walletsdk
const val BASE_RESERVE_MIN_COUNT = 2
const val BASE_RESERVE = 0.5

val XLM_ASSET_DEFAULT =
NativeAssetDefault(
id = "XLM:native",
homeDomain = "Native",
name = "XLM",
// TODO: add XLM image
imageUrl = null,
assetCode = "XLM",
assetIssuer = "Native",
)

const val XLM_PRECISION = 1e7
const val DECIMAL_POINT_PRECISION = 7
const val STRING_TRIM_LENGTH = 8
Expand Down
108 changes: 0 additions & 108 deletions wallet-sdk/src/main/kotlin/org/stellar/walletsdk/Data.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ package org.stellar.walletsdk

import kotlinx.serialization.Serializable
import org.stellar.sdk.requests.RequestBuilder
import org.stellar.walletsdk.asset.AssetId

@Deprecated("Formatted classes are to be removed")
data class AccountInfo(
val publicKey: String,
val assets: List<FormattedAsset>,
val liquidityPools: List<FormattedLiquidityPool>,
val reservedNativeBalance: String,
)

/**
* Account weights threshold
Expand All @@ -21,52 +12,6 @@ data class AccountInfo(
*/
data class AccountThreshold(val low: Int, val medium: Int, val high: Int)

@Deprecated("Formatted classes are to be removed")
enum class AssetType(val type: String) {
NATIVE("native"),
ALPHANUM_4("credit_alphanum4"),
ALPHANUM_12("credit_alphanum12"),
LIQUIDITY_POOL("liquidity_pool_shares")
}

@Deprecated("Formatted classes are to be removed")
data class CachedAsset(
val id: String,
val homeDomain: String?,
val name: String?,
val imageUrl: String?,
val amount: String?
)

@Deprecated("Formatted classes are to be removed")
data class FormattedAsset(
val id: String,
val homeDomain: String?,
val name: String?,
val imageUrl: String?,
val assetCode: String,
val assetIssuer: String,
val balance: String,
val availableBalance: String,
val buyingLiabilities: String,
val sellingLiabilities: String
)

@Deprecated("Formatted classes are to be removed")
data class FormattedBalances(
val assets: MutableList<FormattedAsset>,
val liquidityPools: MutableList<FormattedLiquidityPool>
)

@Deprecated("Formatted classes are to be removed")
data class FormattedLiquidityPool(
val id: String,
val balance: String,
val totalTrustlines: Long,
val totalShares: String,
val reserves: List<LiquidityPoolReserve>
)

@Serializable
data class InteractiveFlowResponse(
val id: String,
Expand All @@ -78,56 +23,3 @@ enum class Order(internal val builderEnum: RequestBuilder.Order) {
ASC(RequestBuilder.Order.ASC),
DESC(RequestBuilder.Order.DESC)
}

@Deprecated("Formatted classes are to be removed")
data class LiquidityPoolInfo(
val totalTrustlines: Long,
val totalShares: String,
val reserves: MutableList<LiquidityPoolReserve>
)

@Deprecated("Formatted classes are to be removed")
data class LiquidityPoolReserve(
val id: String,
val assetCode: String,
val assetIssuer: String,
val homeDomain: String?,
val name: String?,
val imageUrl: String?,
val amount: String,
)

@Deprecated("Formatted classes are to be removed")
data class NativeAssetDefault(
val id: String,
val homeDomain: String?,
val name: String?,
val imageUrl: String?,
val assetCode: String,
val assetIssuer: String,
)

@Deprecated(
"Formatted classes are to be removed. Use rawOperation instead",
replaceWith = ReplaceWith("this.rawOperation")
)
data class WalletOperation<T>(
val id: String,
val date: String,
val amount: String,
val account: String,
val asset: List<AssetId>,
val type: WalletOperationType,
val rawOperation: T,
)

@Deprecated("Formatted classes are to be removed")
enum class WalletOperationType {
SEND,
RECEIVE,
DEPOSIT,
WITHDRAW,
SWAP,
OTHER,
ERROR
}
4 changes: 2 additions & 2 deletions wallet-sdk/src/main/kotlin/org/stellar/walletsdk/Wallet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import io.ktor.serialization.kotlinx.json.*
import io.ktor.utils.io.core.*
import java.time.Duration
import java.util.*
import okhttp3.OkHttpClient
import org.stellar.sdk.Network
import org.stellar.sdk.Server
import org.stellar.walletsdk.anchor.Anchor
Expand All @@ -19,7 +20,6 @@ import org.stellar.walletsdk.json.defaultJson
import org.stellar.walletsdk.recovery.Recovery
import org.stellar.walletsdk.recovery.RecoveryServer
import org.stellar.walletsdk.recovery.RecoveryServerKey
import shadow.okhttp3.OkHttpClient

/**
* Wallet SDK main entry point. It provides methods to build wallet applications on the Stellar
Expand Down Expand Up @@ -92,7 +92,7 @@ data class StellarConfiguration(
* [Default base fee]
* (https://developers.stellar.org/docs/encyclopedia/fees-surge-pricing-fee-strategies#network-fees-on-stellar)
*/
val baseFee: UInt = 100u,
val baseFee: ULong = 100u,
val defaultTimeout: Duration = Duration.ofMinutes(3),
val horizonClient: OkHttpClient? = null,
val submitClient: OkHttpClient? = null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package org.stellar.walletsdk.extension

import org.stellar.sdk.LiquidityPoolID
import org.stellar.sdk.Server
import org.stellar.sdk.requests.ErrorResponse
import org.stellar.sdk.responses.AccountResponse
import org.stellar.sdk.responses.LiquidityPoolResponse
import org.stellar.sdk.responses.operations.OperationResponse
import org.stellar.walletsdk.*
import org.stellar.walletsdk.exception.HorizonRequestFailedException
import org.stellar.walletsdk.exception.OperationsLimitExceededException
import org.stellar.walletsdk.util.formatAmount

@Suppress("TooGenericExceptionCaught", "RethrowCaughtException")
private fun <T> safeHorizonCall(body: () -> T): T {
Expand Down Expand Up @@ -45,68 +42,6 @@ suspend fun Server.accountOrNull(accountAddress: String): AccountResponse? {
}
}

/**
* Fetch liquidity pool information from the Stellar network.
*
* @param liquidityPoolId Liquidity pool ID
* @param cachedAssetInfo Previously cached asset information to use for liquidity pool assets
* @return liquidity pool data object
* @throws [HorizonRequestFailedException] for Horizon exceptions
*/
@Deprecated("Formatted classes are to be removed")
suspend fun Server.liquidityPoolInfo(
liquidityPoolId: LiquidityPoolID,
cachedAssetInfo: MutableMap<String, CachedAsset>
): LiquidityPoolInfo {
val response: LiquidityPoolResponse = safeHorizonCall {
liquidityPools().liquidityPool(liquidityPoolId)
}

val responseReserves = response.reserves
val totalTrustlines = response.totalTrustlines
val totalShares = response.totalShares

val reserves: MutableList<LiquidityPoolReserve> = mutableListOf()

responseReserves.forEach { item ->
if (item.asset.type == AssetType.NATIVE.type) {
val nativeReserve =
LiquidityPoolReserve(
id = XLM_ASSET_DEFAULT.id,
homeDomain = XLM_ASSET_DEFAULT.homeDomain,
name = XLM_ASSET_DEFAULT.name,
imageUrl = XLM_ASSET_DEFAULT.imageUrl,
assetCode = XLM_ASSET_DEFAULT.assetCode,
assetIssuer = XLM_ASSET_DEFAULT.assetIssuer,
amount = formatAmount(item.amount),
)

reserves.add(nativeReserve)
} else {
val assetArr = item.asset.toString().split(":")
val assetCode = assetArr[0]
val assetIssuer = assetArr[1]

val cachedItem = cachedAssetInfo[item.asset.toString()]
// TODO: if there is no cached info, fetch toml file to get homeDomain, name, and imageURL
val lpAsset =
LiquidityPoolReserve(
id = item.asset.toString(),
assetCode = assetCode,
assetIssuer = assetIssuer,
homeDomain = cachedItem?.homeDomain,
name = cachedItem?.name,
imageUrl = cachedItem?.imageUrl,
amount = formatAmount(item.amount),
)

reserves.add(lpAsset)
}
}

return LiquidityPoolInfo(totalTrustlines, totalShares, reserves)
}

/**
* Fetch account operations from Stellar network.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.stellar.walletsdk.horizon

import mu.KotlinLogging
import org.stellar.sdk.*
import org.stellar.sdk.responses.AccountResponse
import org.stellar.sdk.responses.operations.OperationResponse
import org.stellar.walletsdk.*
import org.stellar.walletsdk.exception.*
Expand Down Expand Up @@ -41,20 +42,8 @@ internal constructor(
* @return formatted account information
* @throws [HorizonRequestFailedException] for Horizon exceptions
*/
suspend fun getInfo(accountAddress: String, serverInstance: Server = server): AccountInfo {
val account = serverInstance.accountByAddress(accountAddress)
val balances = formatAccountBalances(account, serverInstance)

log.debug { "Account info: accountAddress = $accountAddress" }

// TODO: add accountDetails

return AccountInfo(
publicKey = account.accountId,
assets = balances.assets,
liquidityPools = balances.liquidityPools,
reservedNativeBalance = account.reservedBalance()
)
suspend fun getInfo(accountAddress: String, serverInstance: Server = server): AccountResponse {
return serverInstance.accountByAddress(accountAddress)
}

/**
Expand All @@ -75,14 +64,12 @@ internal constructor(
order: Order? = Order.DESC,
cursor: String? = null,
includeFailed: Boolean? = null
): List<WalletOperation<OperationResponse>> {
): List<OperationResponse> {
log.debug {
"Account history: accountAddress = $accountAddress, limit = $limit, order" +
" = $order, cursor = $cursor, includeFailed = $includeFailed"
}

return server.accountOperations(accountAddress, limit, order, cursor, includeFailed).map {
formatStellarOperation(accountAddress, it)
}
return server.accountOperations(accountAddress, limit, order, cursor, includeFailed)
}
}
Loading

0 comments on commit a97b5d2

Please sign in to comment.