Skip to content

Commit

Permalink
Merge pull request #114 from avianlabs/deprecated-blockhash-method
Browse files Browse the repository at this point in the history
add getLatestBlockhash and deprecate getRecentBlockhash
  • Loading branch information
wiyarmir authored Aug 26, 2024
2 parents ba7db9c + 2597ffc commit 6da1611
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package net.avianlabs.solana.methods

import kotlinx.serialization.Serializable
import kotlinx.serialization.json.addJsonObject
import kotlinx.serialization.json.buildJsonArray
import kotlinx.serialization.json.put
import net.avianlabs.solana.SolanaClient
import net.avianlabs.solana.client.RpcResponse
import net.avianlabs.solana.domain.core.Commitment

/**
* Returns the latest blockhash
*
* @param commitment Optional [Commitment] level
*/
public suspend fun SolanaClient.getLatestBlockhash(
commitment: Commitment? = null,
): LatestBlockHash {
val result = invoke<RpcResponse.RPC<LatestBlockHash>>(
method = "getLatestBlockhash",
params = buildJsonArray {
commitment?.let {
addJsonObject {
put("commitment", it.value)
}
}
}
)
return result!!.value!!
}

@Serializable
public data class LatestBlockHash(
val blockhash: String,
val lastValidBlockHeight: Long,
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ import net.avianlabs.solana.domain.core.FeeCalculator
* Returns the latest blockhash
*
* @param commitment Optional [Commitment] level
*
* @deprecated Use [getLatestBlockhash] instead
*/
@Deprecated(
"No longer a part of solana-core after 2.0. Use getLatestBlockhash instead",
ReplaceWith("getLatestBlockhash"),
DeprecationLevel.ERROR,
)
public suspend fun SolanaClient.getRecentBlockhash(
commitment: Commitment? = null,
): RecentBlockHash {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SystemProgramTest {

val rentExempt = client.getMinimumBalanceForRentExemption(SystemProgram.NONCE_ACCOUNT_LENGTH)

val blockhash = client.getRecentBlockhash()
val blockhash = client.getLatestBlockhash()

val initTransaction = Transaction()
.addInstruction(
Expand Down

0 comments on commit 6da1611

Please sign in to comment.