-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
124 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
solana-kotlin/src/commonMain/kotlin/net/avianlabs/solana/domain/core/Commitment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package net.avianlabs.solana.domain.core | ||
|
||
|
||
/** | ||
* [Commitment.Finalized] - the node will query the most recent block confirmed by supermajority of the cluster as having reached maximum lockout, meaning the cluster has recognized this block as finalized | ||
* [Commitment.Confirmed] - the node will query the most recent block that has been voted on by supermajority of the cluster. | ||
* It incorporates votes from gossip and replay. | ||
* It does not count votes on descendants of a block, only direct votes on that block. | ||
* This confirmation level also upholds "optimistic confirmation" guarantees in release 1.3 and onwards. | ||
* [Commitment.Processed] - the node will query its most recent block. Note that the block may still be skipped by the cluster. | ||
* | ||
* @see <a href="https://docs.solana.com/api/http#configuring-state-commitment">Configuring state commitment</a> | ||
*/ | ||
public enum class Commitment(public val value: String) { | ||
Finalized("finalized"), | ||
Confirmed("confirmed"), | ||
Processed("processed"), | ||
} |
16 changes: 14 additions & 2 deletions
16
solana-kotlin/src/commonMain/kotlin/net/avianlabs/solana/methods/getBalance.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,30 @@ | ||
package net.avianlabs.solana.methods | ||
|
||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.json.JsonArray | ||
import kotlinx.serialization.json.encodeToJsonElement | ||
import net.avianlabs.solana.SolanaClient | ||
import net.avianlabs.solana.client.RpcResponse.RPC | ||
import net.avianlabs.solana.domain.core.Commitment | ||
import net.avianlabs.solana.domain.core.PublicKey | ||
|
||
public suspend fun SolanaClient.getBalance( | ||
account: PublicKey, | ||
commitment: Commitment? = null, | ||
): Long { | ||
val result = invoke<RPC<Long>>("getBalance", params(account)) | ||
val result = invoke<RPC<Long>>("getBalance", params(account, commitment)) | ||
return result!!.value!! | ||
} | ||
|
||
private fun SolanaClient.params( | ||
account: PublicKey, | ||
) = JsonArray(listOf(json.encodeToJsonElement(account))) | ||
commitment: Commitment? | ||
) = JsonArray(buildList { | ||
add(json.encodeToJsonElement(account)) | ||
commitment?.let { add(json.encodeToJsonElement(BalanceParams(it.value))) } | ||
}) | ||
|
||
@Serializable | ||
internal data class BalanceParams( | ||
val commitment: String? = null, | ||
) |
22 changes: 18 additions & 4 deletions
22
solana-kotlin/src/commonMain/kotlin/net/avianlabs/solana/methods/getFeeForMessage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,30 @@ | ||
package net.avianlabs.solana.methods | ||
|
||
import io.ktor.util.* | ||
import io.ktor.util.encodeBase64 | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.json.JsonArray | ||
import kotlinx.serialization.json.encodeToJsonElement | ||
import net.avianlabs.solana.SolanaClient | ||
import net.avianlabs.solana.client.RpcResponse.RPC | ||
import net.avianlabs.solana.domain.core.Commitment | ||
|
||
public suspend fun SolanaClient.getFeeForMessage(message: ByteArray): Long { | ||
val result = invoke<RPC<Long>>("getFeeForMessage", params(message)) | ||
public suspend fun SolanaClient.getFeeForMessage( | ||
message: ByteArray, | ||
commitment: Commitment? = null | ||
): Long { | ||
val result = invoke<RPC<Long>>("getFeeForMessage", params(message, commitment)) | ||
return result!!.value!! | ||
} | ||
|
||
private fun SolanaClient.params( | ||
message: ByteArray, | ||
) = JsonArray(listOf(json.encodeToJsonElement(message.encodeBase64()))) | ||
commitment: Commitment?, | ||
) = JsonArray(buildList { | ||
add(json.encodeToJsonElement(message.encodeBase64())) | ||
commitment?.let { add(json.encodeToJsonElement(FeeForMessageParams(it.value))) } | ||
}) | ||
|
||
@Serializable | ||
internal data class FeeForMessageParams( | ||
val commitment: String? = null, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 15 additions & 2 deletions
17
solana-kotlin/src/commonMain/kotlin/net/avianlabs/solana/methods/requestAirdrop.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,32 @@ | ||
package net.avianlabs.solana.methods | ||
|
||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.json.JsonArray | ||
import kotlinx.serialization.json.encodeToJsonElement | ||
import net.avianlabs.solana.SolanaClient | ||
import net.avianlabs.solana.domain.core.Commitment | ||
import net.avianlabs.solana.domain.core.PublicKey | ||
|
||
public suspend fun SolanaClient.requestAirdrop( | ||
publicKey: PublicKey, | ||
lamports: Long, | ||
commitment: Commitment? = null | ||
): String { | ||
val result = invoke<String>("requestAirdrop", params(publicKey, lamports)) | ||
val result = invoke<String>("requestAirdrop", params(publicKey, lamports, commitment)) | ||
return result!! | ||
} | ||
|
||
private fun SolanaClient.params( | ||
publicKey: PublicKey, | ||
lamports: Long, | ||
) = JsonArray(listOf(json.encodeToJsonElement(publicKey), json.encodeToJsonElement(lamports))) | ||
commitment: Commitment? | ||
) = JsonArray(buildList { | ||
add(json.encodeToJsonElement(publicKey)) | ||
add(json.encodeToJsonElement(lamports)) | ||
commitment?.let { json.encodeToJsonElement(RequestAirdropParams(it.value)) } | ||
}) | ||
|
||
@Serializable | ||
internal data class RequestAirdropParams( | ||
val commitment: String? = null, | ||
) |