Skip to content
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ p8e {
chainId = "pio-mainnet-1"
mainNet = true
txFeeAdjustment = "2.0"
fixedGasLimit = 60_000_000
txBatchSize = "5"
provenanceQueryTimeoutSeconds = "20"
osHeaders = mapOf(
Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/com/figure/p8e/plugin/Bootstrapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/com/figure/p8e/plugin/Dsl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> = emptyMap()
}

Expand Down
26 changes: 24 additions & 2 deletions src/main/kotlin/com/figure/p8e/plugin/ProvenanceClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,11 +24,30 @@ fun Collection<Message>.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()
Expand Down
Loading