Skip to content

Commit

Permalink
Do gas estimate before tx
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperschwartz committed Feb 3, 2022
1 parent 2c9b77b commit 38cd0fb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import cosmwasm.wasm.v1.Tx
import io.provenance.client.PbClient
import io.provenance.client.grpc.BaseReq
import io.provenance.client.grpc.BaseReqSigner
import io.provenance.client.grpc.GasEstimate
import io.provenance.invoice.AssetProtos.Asset
import io.provenance.invoice.config.provenance.ObjectStore
import io.provenance.invoice.config.provenance.ProvenanceProperties
Expand Down Expand Up @@ -98,29 +97,31 @@ class EventHandlerService(
// TODO: Resolve this somehow
val oracleAddress = "tp15e6l9dv8s2rdshjfn34k8a2nju55tr4z42phrt"
val accountInfo = pbClient.getBaseAccount(oracleAddress)
val baseReq = BaseReq(
signers = BaseReqSigner(
signer = KeySigner(
address = oracleAddress,
privateKey = provenanceProperties.oraclePrivateKey,
),
sequenceOffset = 0,
account = accountInfo,
).wrapList(),
body = TxOuterClass.TxBody.newBuilder().addMessages(
Tx.MsgExecuteContract.newBuilder()
.setMsg(OracleApproval.forUuid(invoiceUuid).toBase64Msg())
.setContract(contractInfo.address)
.setSender(oracleAddress)
.build()
.toProtoAny()
).setMemo("Oracle signature").build(),
chainId = provenanceProperties.chainId,
gasAdjustment = 2.0,
)
val gasEstimate = pbClient.estimateTx(baseReq)
val response = try {
pbClient.broadcastTx(
baseReq = BaseReq(
signers = BaseReqSigner(
signer = KeySigner(
address = oracleAddress,
privateKey = provenanceProperties.oraclePrivateKey,
),
sequenceOffset = 0,
account = accountInfo,
).wrapList(),
body = TxOuterClass.TxBody.newBuilder().addMessages(
Tx.MsgExecuteContract.newBuilder()
.setMsg(OracleApproval.forUuid(invoiceUuid).toBase64Msg())
.setContract(contractInfo.address)
.setSender(oracleAddress)
.build()
.toProtoAny()
).setMemo("Oracle signature").build(),
chainId = provenanceProperties.chainId,
gasAdjustment = 2.0,
),
gasEstimate = GasEstimate(1905),
baseReq = baseReq,
gasEstimate = gasEstimate,
mode = BroadcastMode.BROADCAST_MODE_BLOCK
)
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ import io.provenance.hdwallet.signer.BCECSigner
import io.provenance.scope.util.sha256
import java.security.PrivateKey


class KeySigner(
private val address: String,
privateKey: PrivateKey
): Signer {
class KeySigner(private val address: String, privateKey: PrivateKey): Signer {
private val keyPair = privateKey.toECPrivateKey().toECKeyPair()

override fun address(): String = address
Expand Down

0 comments on commit 38cd0fb

Please sign in to comment.