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

commonMain.kr.jadekim.chameleon.injective.Injective.kt Maven / Gradle / Ivy

There is a newer version: 0.4.4
Show newest version
package kr.jadekim.chameleon.injective

import cosmos.tx.v1beta1.Tx
import kr.jadekim.chameleon.core.tool.SemaphoreProvider
import kr.jadekim.chameleon.core.type.BigDecimal
import kr.jadekim.chameleon.cosmos.tool.*
import kr.jadekim.chameleon.cosmos.tool.broadcaster.CosmosBroadcaster
import kr.jadekim.chameleon.cosmos.tool.broadcaster.SyncBroadcaster
import kr.jadekim.chameleon.injective.wallet.InjectiveWallet
import kr.jadekim.protobuf.type.ProtobufServiceClientOption

data class InjectiveOptions(
    val chainId: String,
    val client: CosmosClient,
    val accountInfoProvider: AccountInfoProvider? = client.accountInfoProvider(),
    val gasPriceProvider: CosmosGasPriceProvider? = StaticGasPriceProvider(mapOf("inj" to BigDecimal("160000000"))),
    val feeEstimator: CosmosFeeEstimator? = gasPriceProvider?.let {
        CosmosNodeFeeEstimator(client.transactionApi(), it)
    },
    val semaphoreProvider: SemaphoreProvider? = null,
    val broadcaster: CosmosBroadcaster = SyncBroadcaster(
        chainId,
        client.transactionApi(),
        feeEstimator,
        accountInfoProvider?.let { CosmosTransactionDirectSigner(it) },
        semaphoreProvider?.let {
            accountInfoProvider?.let {
                CosmosBroadcastEventHandler(semaphoreProvider, accountInfoProvider)
            }
        }
    ),
)

class Injective(
    val chainId: String,
    val broadcaster: CosmosBroadcaster,
    val client: CosmosClient,
) {

    constructor(options: InjectiveOptions) : this(options.chainId, options.broadcaster, options.client)

    fun broadcast(transaction: Tx, sender: InjectiveWallet) = broadcaster.broadcast(transaction, sender)

    fun broadcast(
        sender: InjectiveWallet,
        buildTransaction: InjectiveTransactionBuilder.() -> Unit,
    ) = broadcast(InjectiveTransactionBuilder().apply(buildTransaction).build(), sender)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy