-
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.
Merge pull request #1 from avianlabs/add-commitment
Add commitment to the calls
- Loading branch information
Showing
11 changed files
with
198 additions
and
72 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"), | ||
} |
24 changes: 20 additions & 4 deletions
24
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,34 @@ | ||
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 | ||
|
||
/** | ||
* @return The balance of the account of provided [PublicKey] | ||
* | ||
* @param account Pubkey of account to query | ||
* @param commitment Optional [Commitment] level | ||
*/ | ||
public suspend fun SolanaClient.getBalance( | ||
account: PublicKey, | ||
commitment: Commitment? = null, | ||
): Long { | ||
val result = invoke<RPC<Long>>("getBalance", params(account)) | ||
val result = invoke<RPC<Long>>( | ||
method = "getBalance", | ||
params = JsonArray(buildList { | ||
add(json.encodeToJsonElement<PublicKey>(account)) | ||
commitment?.let { add(json.encodeToJsonElement(BalanceParams(it.value))) } | ||
}) | ||
) | ||
return result!!.value!! | ||
} | ||
|
||
private fun SolanaClient.params( | ||
account: PublicKey, | ||
) = JsonArray(listOf(json.encodeToJsonElement(account))) | ||
@Serializable | ||
internal data class BalanceParams( | ||
val commitment: String? = null, | ||
) |
31 changes: 25 additions & 6 deletions
31
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,35 @@ | ||
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)) | ||
/** | ||
* Get the fee the network will charge for a particular Message | ||
* | ||
* @param message Base-64 encoded Message | ||
* @param commitment Optional [Commitment] level | ||
* | ||
*/ | ||
public suspend fun SolanaClient.getFeeForMessage( | ||
message: ByteArray, | ||
commitment: Commitment? = null | ||
): Long { | ||
val result = invoke<RPC<Long>>( | ||
method = "getFeeForMessage", | ||
params = JsonArray(buildList { | ||
add(json.encodeToJsonElement<String>(message.encodeBase64())) | ||
commitment?.let { add(json.encodeToJsonElement(FeeForMessageParams(it.value))) } | ||
}) | ||
) | ||
return result!!.value!! | ||
} | ||
|
||
private fun SolanaClient.params( | ||
message: ByteArray, | ||
) = JsonArray(listOf(json.encodeToJsonElement(message.encodeBase64()))) | ||
@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
Oops, something went wrong.