Skip to content

Commit

Permalink
AND-5815 Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Mama1emon committed Jan 16, 2024
1 parent cfe93da commit 192df95
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 26 deletions.
2 changes: 1 addition & 1 deletion blockchain/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ dependencies {
implementation 'com.squareup.retrofit2:converter-moshi:2.6.0'
implementation 'com.squareup.moshi:moshi:1.13.0'
implementation "com.squareup.moshi:moshi-kotlin:1.13.0"
implementation 'com.squareup.moshi:moshi-adapters:1.9.1'
implementation 'com.squareup.moshi:moshi-adapters:1.13.0'
kapt("com.squareup.moshi:moshi-kotlin-codegen:1.13.0")
implementation 'com.squareup.okhttp3:logging-interceptor:4.9.3'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.tangem.blockchain.blockchains.aptos.network

import com.tangem.blockchain.blockchains.aptos.network.request.TransactionBody
import com.tangem.blockchain.blockchains.aptos.network.response.AptosResource
import com.tangem.blockchain.blockchains.aptos.network.response.EstimateGasPriceResponse
import com.tangem.blockchain.blockchains.aptos.network.response.SimulateTransactionResponse
import com.tangem.blockchain.blockchains.aptos.network.response.SubmitTransactionResponse
import com.tangem.blockchain.blockchains.aptos.network.request.AptosTransactionBody
import com.tangem.blockchain.blockchains.aptos.network.response.AptosEstimateGasPriceResponse
import com.tangem.blockchain.blockchains.aptos.network.response.AptosResourceBody
import com.tangem.blockchain.blockchains.aptos.network.response.AptosSimulateTransactionBody
import com.tangem.blockchain.blockchains.aptos.network.response.AptosSubmitTransactionResponse
import retrofit2.http.*

/**
Expand All @@ -21,11 +21,11 @@ internal interface AptosApi {
*
* @param address account address
*
* @see AptosResource to know more details about kind of resources
* @see AptosResourceBody to know more details about kind of resources
*/
@Headers("Content-Type: application/json")
@GET("v1/accounts/{address}/resources")
suspend fun getAccountResources(@Path("address") address: String): List<AptosResource>
suspend fun getAccountResources(@Path("address") address: String): List<AptosResourceBody>

/**
* Gives an estimate of the gas unit price required to get a transaction on chain in a reasonable amount of time.
Expand All @@ -34,7 +34,7 @@ internal interface AptosApi {
*/
@Headers("Content-Type: application/json")
@GET("v1/estimate_gas_price")
suspend fun estimateGasPrice(): EstimateGasPriceResponse
suspend fun estimateGasPrice(): AptosEstimateGasPriceResponse

/**
* Simulate transaction's sending. Use it to estimate the maximum gas units for a submitted transaction.
Expand All @@ -55,15 +55,15 @@ internal interface AptosApi {
"estimate_max_gas_amount=true&" +
"estimate_prioritized_gas_unit_price=false",
)
suspend fun simulateTransaction(@Body body: TransactionBody): List<SimulateTransactionResponse>
suspend fun simulateTransaction(@Body body: AptosTransactionBody): List<AptosSimulateTransactionBody>

/** Build raw transaction data [body] and encode in BCS */
@Headers("Content-Type: application/json")
@POST("v1/transactions/encode_submission")
suspend fun encodeSubmission(@Body body: TransactionBody): String
suspend fun encodeSubmission(@Body body: AptosTransactionBody): String

/** Submit transaction [body] */
@Headers("Content-Type: application/json")
@POST("v1/transactions")
suspend fun submitTransaction(@Body body: TransactionBody): SubmitTransactionResponse
suspend fun submitTransaction(@Body body: AptosTransactionBody): AptosSubmitTransactionResponse
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
internal data class TransactionBody(
internal data class AptosTransactionBody(
@Json(name = "expiration_timestamp_secs") val expirationTimestamp: String,
@Json(name = "gas_unit_price") val gasUnitPrice: String,
@Json(name = "max_gas_amount") val maxGasAmount: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
internal data class EstimateGasPriceResponse(
internal data class AptosEstimateGasPriceResponse(
@Json(name = "deprioritized_gas_estimate") val minimalGasUnitPrice: Long,
@Json(name = "gas_estimate") val normalGasUnitPrice: Long,
@Json(name = "prioritized_gas_estimate") val priorityGasUnitPrice: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory

internal sealed class AptosResource {
internal sealed class AptosResourceBody {

@JsonClass(generateAdapter = true)
data class AccountResource(
@Json(name = "data") val account: AccountData,
) : AptosResource() {
) : AptosResourceBody() {

@JsonClass(generateAdapter = true)
data class AccountData(
Expand All @@ -19,8 +19,8 @@ internal sealed class AptosResource {

@JsonClass(generateAdapter = true)
data class CoinResource(
@Json(name = "data") val coin: CoinData,
) : AptosResource() {
@Json(name = "data") val coinData: CoinData,
) : AptosResourceBody() {

@JsonClass(generateAdapter = true)
data class CoinData(
Expand All @@ -34,13 +34,13 @@ internal sealed class AptosResource {
}
}

object Unknown : AptosResource()
object Unknown : AptosResourceBody()

companion object {

fun createPolymorphicJsonAdapterFactory(): PolymorphicJsonAdapterFactory<AptosResource> {
fun createPolymorphicJsonAdapterFactory(): PolymorphicJsonAdapterFactory<AptosResourceBody> {
return PolymorphicJsonAdapterFactory
.of(AptosResource::class.java, "type")
.of(AptosResourceBody::class.java, "type")
.withSubtype(AccountResource::class.java, "0x1::account::Account")
.withSubtype(CoinResource::class.java, "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>")
.withDefaultValue(Unknown)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
internal data class SimulateTransactionResponse(
internal data class AptosSimulateTransactionBody(
@Json(name = "gas_used") val usedGasUnit: String,
@Json(name = "sequence_number") val sequenceNumber: String,
@Json(name = "success") val isSuccess: Boolean,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
internal data class SubmitTransactionResponse(
internal data class AptosSubmitTransactionResponse(
@Json(name = "hash") val hash: String,
@Json(name = "sequence_number") val sequenceNumber: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.tangem.blockchain.network

import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import com.tangem.blockchain.blockchains.aptos.network.response.AptosResource
import com.tangem.blockchain.blockchains.aptos.network.response.AptosResourceBody
import okhttp3.Interceptor
import okhttp3.OkHttpClient
import retrofit2.Retrofit
Expand Down Expand Up @@ -63,7 +63,7 @@ data class Timeout(
internal val moshi: Moshi by lazy {
Moshi.Builder()
.add(BigDecimal::class.java, BigDecimalAdapter)
.add(AptosResource.createPolymorphicJsonAdapterFactory())
.add(AptosResourceBody.createPolymorphicJsonAdapterFactory())
.add(KotlinJsonAdapterFactory())
.build()
}
Expand Down

0 comments on commit 192df95

Please sign in to comment.