-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AND-5815 Add AptosApi #435
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
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 retrofit2.http.* | ||
|
||
/** | ||
* Aptos REST API | ||
* | ||
* @see <a href="https://fullnode.mainnet.aptoslabs.com/v1/spec#/">Aptos Node API</a> | ||
* | ||
* @author Andrew Khokhlov on 10/01/2024 | ||
*/ | ||
internal interface AptosApi { | ||
|
||
/** | ||
* Get account resources that contains information about account and balance | ||
* | ||
* @param address account address | ||
* | ||
* @see AptosResource 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> | ||
|
||
/** | ||
* Gives an estimate of the gas unit price required to get a transaction on chain in a reasonable amount of time. | ||
* The gas unit price is the amount that each transaction commits to pay for each unit of gas consumed | ||
* in executing the transaction. | ||
*/ | ||
@Headers("Content-Type: application/json") | ||
@GET("v1/estimate_gas_price") | ||
suspend fun estimateGasPrice(): EstimateGasPriceResponse | ||
|
||
/** | ||
* Simulate transaction's sending. Use it to estimate the maximum gas units for a submitted transaction. | ||
* Request queries: | ||
* - {estimate_gas_unit_price} - If set to true, the gas unit price in the transaction will be ignored and the | ||
* estimated value will be used | ||
* - {estimate_max_gas_amount} - If set to true, the max gas value in the transaction will be ignored and the | ||
* maximum possible gas will be used | ||
* - {estimate_prioritized_gas_unit_price} - If set to true, the transaction will use a higher price than the | ||
* original estimate | ||
* | ||
* @param body raw transaction data without signing transaction hash | ||
*/ | ||
@Headers("Content-Type: application/json") | ||
@POST( | ||
"v1/transactions/simulate?" + | ||
"estimate_gas_unit_price=false&" + | ||
"estimate_max_gas_amount=true&" + | ||
"estimate_prioritized_gas_unit_price=false", | ||
) | ||
suspend fun simulateTransaction(@Body body: TransactionBody): List<SimulateTransactionResponse> | ||
|
||
/** 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 | ||
|
||
/** Submit transaction [body] */ | ||
@Headers("Content-Type: application/json") | ||
@POST("v1/transactions") | ||
suspend fun submitTransaction(@Body body: TransactionBody): SubmitTransactionResponse | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.tangem.blockchain.blockchains.aptos.network.request | ||
|
||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
|
||
@JsonClass(generateAdapter = true) | ||
internal data class TransactionBody( | ||
@Json(name = "expiration_timestamp_secs") val expirationTimestamp: String, | ||
@Json(name = "gas_unit_price") val gasUnitPrice: String, | ||
@Json(name = "max_gas_amount") val maxGasAmount: String, | ||
@Json(name = "payload") val payload: Payload, | ||
@Json(name = "sender") val sender: String, | ||
@Json(name = "sequence_number") val sequenceNumber: String, | ||
@Json(name = "signature") val signature: Signature? = null, | ||
) { | ||
|
||
@JsonClass(generateAdapter = true) | ||
data class Payload( | ||
@Json(name = "type") val type: String, | ||
@Json(name = "function") val function: String, | ||
@Json(name = "type_arguments") val argumentTypes: List<String>, | ||
@Json(name = "arguments") val arguments: List<String>, | ||
) | ||
|
||
@JsonClass(generateAdapter = true) | ||
data class Signature( | ||
@Json(name = "type") val type: String, | ||
@Json(name = "public_key") val publicKey: String, | ||
@Json(name = "signature") val signature: String, | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.tangem.blockchain.blockchains.aptos.network.response | ||
|
||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory | ||
|
||
internal sealed class AptosResource { | ||
|
||
@JsonClass(generateAdapter = true) | ||
data class AccountResource( | ||
@Json(name = "data") val account: AccountData, | ||
) : AptosResource() { | ||
|
||
@JsonClass(generateAdapter = true) | ||
data class AccountData( | ||
@Json(name = "sequence_number") val sequenceNumber: String, | ||
) | ||
} | ||
|
||
@JsonClass(generateAdapter = true) | ||
data class CoinResource( | ||
@Json(name = "data") val coin: CoinData, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ключевые слова котлина нельзя использовать There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. точно! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. да, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Перезалил |
||
) : AptosResource() { | ||
|
||
@JsonClass(generateAdapter = true) | ||
data class CoinData( | ||
@Json(name = "coin") val coin: Coin, | ||
) { | ||
|
||
@JsonClass(generateAdapter = true) | ||
data class Coin( | ||
@Json(name = "value") val value: String, | ||
) | ||
} | ||
} | ||
|
||
object Unknown : AptosResource() | ||
|
||
companion object { | ||
|
||
fun createPolymorphicJsonAdapterFactory(): PolymorphicJsonAdapterFactory<AptosResource> { | ||
return PolymorphicJsonAdapterFactory | ||
.of(AptosResource::class.java, "type") | ||
.withSubtype(AccountResource::class.java, "0x1::account::Account") | ||
.withSubtype(CoinResource::class.java, "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>") | ||
.withDefaultValue(Unknown) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.tangem.blockchain.blockchains.aptos.network.response | ||
|
||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
|
||
@JsonClass(generateAdapter = true) | ||
internal data class EstimateGasPriceResponse( | ||
@Json(name = "deprioritized_gas_estimate") val minimalGasUnitPrice: Long, | ||
@Json(name = "gas_estimate") val normalGasUnitPrice: Long, | ||
@Json(name = "prioritized_gas_estimate") val priorityGasUnitPrice: Long, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.tangem.blockchain.blockchains.aptos.network.response | ||
|
||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
|
||
@JsonClass(generateAdapter = true) | ||
internal data class SimulateTransactionResponse( | ||
@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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.tangem.blockchain.blockchains.aptos.network.response | ||
|
||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
|
||
@JsonClass(generateAdapter = true) | ||
internal data class SubmitTransactionResponse( | ||
@Json(name = "hash") val hash: String, | ||
@Json(name = "sequence_number") val sequenceNumber: String, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
есть смысл такую же версию поставить, как и у остальных компонентов
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Готово