diff --git a/README.md b/README.md index a30c197..8b251db 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,7 @@ p8e { chainId = "pio-mainnet-1" mainNet = true txFeeAdjustment = "2.0" + fixedGasLimit = 60_000_000 txBatchSize = "5" provenanceQueryTimeoutSeconds = "20" osHeaders = mapOf( diff --git a/src/main/kotlin/com/figure/p8e/plugin/Bootstrapper.kt b/src/main/kotlin/com/figure/p8e/plugin/Bootstrapper.kt index b1de11e..92ef94d 100644 --- a/src/main/kotlin/com/figure/p8e/plugin/Bootstrapper.kt +++ b/src/main/kotlin/com/figure/p8e/plugin/Bootstrapper.kt @@ -2,7 +2,6 @@ package com.figure.p8e.plugin import com.google.protobuf.ByteString import com.google.protobuf.Message -import io.grpc.ManagedChannelBuilder import io.provenance.client.grpc.BaseReqSigner import io.provenance.client.grpc.ChannelOpts import io.provenance.client.grpc.createChannel @@ -127,7 +126,7 @@ internal class Bootstrapper( var errored = false - extension.locations.forEach { name, location -> + extension.locations.forEach { (name, location) -> project.logger.info("Publishing contracts - location: $name object-store url: ${location.osUrl} provenance url: ${location.provenanceUrl}") val config = ClientConfig( diff --git a/src/main/kotlin/com/figure/p8e/plugin/Dsl.kt b/src/main/kotlin/com/figure/p8e/plugin/Dsl.kt index a0ecb1f..b2af5b7 100644 --- a/src/main/kotlin/com/figure/p8e/plugin/Dsl.kt +++ b/src/main/kotlin/com/figure/p8e/plugin/Dsl.kt @@ -17,6 +17,7 @@ open class P8eLocationExtension { var mainNet: Boolean = chainId == "pio-mainnet-1" var txBatchSize: String = "10" var txFeeAdjustment: String = "1.25" + var fixedGasLimit: Long = 0 var osHeaders: Map = emptyMap() } diff --git a/src/main/kotlin/com/figure/p8e/plugin/ProvenanceClient.kt b/src/main/kotlin/com/figure/p8e/plugin/ProvenanceClient.kt index 7dc197a..2bd2af1 100644 --- a/src/main/kotlin/com/figure/p8e/plugin/ProvenanceClient.kt +++ b/src/main/kotlin/com/figure/p8e/plugin/ProvenanceClient.kt @@ -3,15 +3,18 @@ package com.figure.p8e.plugin import com.google.protobuf.Any import com.google.protobuf.Message import cosmos.tx.v1beta1.ServiceOuterClass.BroadcastMode +import cosmos.tx.v1beta1.TxOuterClass import cosmos.tx.v1beta1.TxOuterClass.TxBody import io.grpc.ManagedChannel +import io.provenance.client.common.gas.GasEstimate import io.provenance.client.grpc.BaseReqSigner -import io.provenance.client.grpc.GasEstimationMethod +import io.provenance.client.grpc.GasEstimator import io.provenance.client.grpc.PbClient import io.provenance.metadata.v1.ContractSpecificationRequest import io.provenance.metadata.v1.ContractSpecificationResponse import io.provenance.metadata.v1.ScopeSpecificationRequest import io.provenance.metadata.v1.ScopeSpecificationResponse +import io.provenance.msgfees.v1.CalculateTxFeesRequest import org.slf4j.Logger import java.net.URI import java.util.concurrent.TimeUnit @@ -21,11 +24,30 @@ fun Collection.toTxBody(): TxBody = TxBody.newBuilder() .build() fun Message.toAny(typeUrlPrefix: String = "") = Any.pack(this, typeUrlPrefix) +fun fixedLimitTransactionGasEstimator(location: P8eLocationExtension): GasEstimator = + { tx: TxOuterClass.Tx, adjustment: Double -> + val estimate = msgFeeClient.calculateTxFees( + CalculateTxFeesRequest.newBuilder() + .setTxBytes(tx.toByteString()) + .setGasAdjustment(adjustment.toFloat()) + .build() + ) + GasEstimate( + limit = if (location.fixedGasLimit > 0) { + location.fixedGasLimit + } else { + estimate.estimatedGas + }, + feesCalculated = estimate.totalFeesList, + msgFees = estimate.additionalFeesList + ) + } + class ProvenanceClient(channel: ManagedChannel, val logger: Logger, val location: P8eLocationExtension) { private val inner = PbClient( location.chainId!!, URI(location.provenanceUrl!!), - GasEstimationMethod.MSG_FEE_CALCULATION, + fixedLimitTransactionGasEstimator(location), channel = channel ) private val queryTimeoutSeconds = location.provenanceQueryTimeoutSeconds.toLong()