Skip to content

Commit 2597ffc

Browse files
committed
add getLatestBlockhash and deprecate getRecentBlockhash
1 parent 6afbe1c commit 2597ffc

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package net.avianlabs.solana.methods
2+
3+
import kotlinx.serialization.Serializable
4+
import kotlinx.serialization.json.addJsonObject
5+
import kotlinx.serialization.json.buildJsonArray
6+
import kotlinx.serialization.json.put
7+
import net.avianlabs.solana.SolanaClient
8+
import net.avianlabs.solana.client.RpcResponse
9+
import net.avianlabs.solana.domain.core.Commitment
10+
11+
/**
12+
* Returns the latest blockhash
13+
*
14+
* @param commitment Optional [Commitment] level
15+
*/
16+
public suspend fun SolanaClient.getLatestBlockhash(
17+
commitment: Commitment? = null,
18+
): LatestBlockHash {
19+
val result = invoke<RpcResponse.RPC<LatestBlockHash>>(
20+
method = "getLatestBlockhash",
21+
params = buildJsonArray {
22+
commitment?.let {
23+
addJsonObject {
24+
put("commitment", it.value)
25+
}
26+
}
27+
}
28+
)
29+
return result!!.value!!
30+
}
31+
32+
@Serializable
33+
public data class LatestBlockHash(
34+
val blockhash: String,
35+
val lastValidBlockHeight: Long,
36+
)

solana-kotlin/src/commonMain/kotlin/net/avianlabs/solana/methods/getRecentBlockhash.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@ import net.avianlabs.solana.domain.core.FeeCalculator
1313
* Returns the latest blockhash
1414
*
1515
* @param commitment Optional [Commitment] level
16+
*
17+
* @deprecated Use [getLatestBlockhash] instead
1618
*/
19+
@Deprecated(
20+
"No longer a part of solana-core after 2.0. Use getLatestBlockhash instead",
21+
ReplaceWith("getLatestBlockhash"),
22+
DeprecationLevel.ERROR,
23+
)
1724
public suspend fun SolanaClient.getRecentBlockhash(
1825
commitment: Commitment? = null,
1926
): RecentBlockHash {

solana-kotlin/src/commonTest/kotlin/net/avianlabs/solana/domain/program/SystemProgramTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class SystemProgramTest {
3434

3535
val rentExempt = client.getMinimumBalanceForRentExemption(SystemProgram.NONCE_ACCOUNT_LENGTH)
3636

37-
val blockhash = client.getRecentBlockhash()
37+
val blockhash = client.getLatestBlockhash()
3838

3939
val initTransaction = Transaction()
4040
.addInstruction(

0 commit comments

Comments
 (0)