-
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 #114 from avianlabs/deprecated-blockhash-method
add getLatestBlockhash and deprecate getRecentBlockhash
- Loading branch information
Showing
3 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
solana-kotlin/src/commonMain/kotlin/net/avianlabs/solana/methods/getLatestBlockhash.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,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, | ||
) |
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