All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.provenance.client.grpc.PbClient.kt Maven / Gradle / Ivy

The newest version!
package io.provenance.client.grpc

import io.grpc.ManagedChannel
import io.grpc.netty.NettyChannelBuilder
import java.net.URI
import java.util.concurrent.TimeUnit


val SECURE_URL_SCHEMES = listOf("https", "grpcs", "tcp+tls")

fun createChannel(uri: URI, opts: ChannelOpts, config: NettyChannelBuilder.() -> Unit): ManagedChannel {
    return NettyChannelBuilder.forAddress(uri.host, uri.port)
        .apply {
            if (uri.scheme in SECURE_URL_SCHEMES) {
                useTransportSecurity()
            } else {
                usePlaintext()
            }
        }
        .executor(opts.executor)
        .maxInboundMessageSize(opts.inboundMessageSize)
        .idleTimeout(opts.idleTimeout.inWholeMilliseconds, TimeUnit.MILLISECONDS)
        .keepAliveTime(opts.keepAliveTime.inWholeMilliseconds, TimeUnit.MILLISECONDS)
        .keepAliveTimeout(opts.keepAliveTimeout.inWholeMilliseconds, TimeUnit.MILLISECONDS)
        .apply { config() }
        .build()
}

/**
 * Netty
 */
open class PbClient(
    override val chainId: String,
    override val channelUri: URI,
    override val gasEstimationMethod: GasEstimator,
    opts: ChannelOpts = ChannelOpts(),
    channelConfigLambda: (NettyChannelBuilder) -> Unit = { },
    channel: ManagedChannel = grpcChannel(channelUri, opts, NettyChannelBuilder::forAddress, channelConfigLambda),
) : AbstractPbClient(chainId, channelUri, gasEstimationMethod, NETTY_CHANNEL, channel)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy