Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge 5.17 to 5.18 #832

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,10 @@ internal class SolanaNetworkService(
}
}

suspend fun getRecentBlockhash(commitment: Commitment = Commitment.CONFIRMED): Result<String> {
suspend fun getLatestBlockhash(commitment: Commitment = Commitment.CONFIRMED): Result<String> {
return withContext(Dispatchers.IO) {
try {
Result.Success(provider.api.getRecentBlockhash(commitment))
Result.Success(provider.api.getLatestBlockhash(commitment))
} catch (ex: Exception) {
Result.Failure(Solana.Api(ex))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ internal class SolanaTransactionBuilder(
amount: BigDecimal,
): Result<SolanaTransaction> {
val recentBlockHash = multiNetworkProvider.performRequest {
getRecentBlockhash()
getLatestBlockhash()
}.successOr { return Result.Failure(it.error) }
val destinationAccount = PublicKey(destinationAddress)
val lamports = SolanaValueConverter.toLamports(amount)
Expand Down Expand Up @@ -112,7 +112,7 @@ internal class SolanaTransactionBuilder(
).successOr { return Result.Failure(it.error) }

val recentBlockHash = multiNetworkProvider.performRequest {
getRecentBlockhash()
getLatestBlockhash()
}.successOr { return it }
setRecentBlockHash(recentBlockHash)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.p2p.solanaj.core.Transaction
import org.p2p.solanaj.rpc.RpcApi
import org.p2p.solanaj.rpc.RpcClient
import org.p2p.solanaj.rpc.RpcException
import org.p2p.solanaj.rpc.types.RecentBlockhash
import org.p2p.solanaj.rpc.types.config.Commitment
import org.p2p.solanaj.ws.listeners.NotificationEventListener

Expand Down Expand Up @@ -192,4 +193,12 @@ internal class SolanaRpcApi(rpcClient: RpcClient) : RpcApi(rpcClient) {
)
}
}

fun getLatestBlockhash(commitment: Commitment): String {
val params = buildList {
add(mapOf("commitment" to commitment.value))
}

return client.call("getLatestBlockhash", params, RecentBlockhash::class.java).value.blockhash
}
}
Loading