Skip to content

Commit

Permalink
Merge pull request #56 from avianlabs/header-provider-constructor
Browse files Browse the repository at this point in the history
ios friendly ctor
  • Loading branch information
wiyarmir authored Mar 18, 2024
2 parents 58e41d5 + 0c0e395 commit e0b64ce
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,32 @@ import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonArray
import net.avianlabs.solana.client.RpcInvocation
import net.avianlabs.solana.client.RpcKtorClient
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine

public class SolanaClient(
private val client: RpcKtorClient,
private val headerProviders: Map<String, suspend () -> String?> = mapOf(),
) {

// iOS friendly constructor
public constructor(
url: String,
authorizationHeaderProvider: suspend () -> String?,
authorizationHeaderProvider: (completion: (String?) -> Unit) -> Unit,
) : this(
client = RpcKtorClient(
url = url,
httpClient = HttpClient(),
),
headerProviders = mapOf(
HttpHeaders.Authorization to authorizationHeaderProvider,
)
HttpHeaders.Authorization to {
suspendCoroutine { continuation ->
authorizationHeaderProvider { header ->
continuation.resume(header)
}
}
},
),
)

@OptIn(ExperimentalSerializationApi::class)
Expand Down

0 comments on commit e0b64ce

Please sign in to comment.