Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: add timeout height and support offline hash return #95

Merged
merged 1 commit into from
Sep 28, 2023
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
8 changes: 8 additions & 0 deletions client/tx/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type (
chainID string
memo string
password string
timeoutHeight uint64
accountNumber uint64
sequence uint64
gas uint64
Expand Down Expand Up @@ -168,6 +169,12 @@ func (f *Factory) WithQueryFunc(queryFunc QueryWithData) *Factory {
return f
}

// WithTimeout Timeout for accessing the blockchain (such as query transactions, broadcast transactions, etc.)
func (f *Factory) WithTimeout(height uint64) *Factory {
f.timeoutHeight = height
return f
}

func (f *Factory) BuildAndSign(name string, msgs []sdk.Msg, json bool) ([]byte, error) {
tx, err := f.BuildUnsignedTx(msgs)
if err != nil {
Expand Down Expand Up @@ -227,6 +234,7 @@ func (f *Factory) BuildUnsignedTx(msgs []sdk.Msg) (sdk.TxBuilder, error) {
tx.SetMemo(f.memo)
tx.SetFeeAmount(fees)
tx.SetGasLimit(f.gas)
tx.SetTimeoutHeight(f.timeoutHeight)
//f.txBuilder.SetTimeoutHeight(f.TimeoutHeight())

return tx, nil
Expand Down
12 changes: 9 additions & 3 deletions modules/base_client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Package modules is to warpped the API provided by each module of IRIS-Hub
//
//
package modules

import (
Expand Down Expand Up @@ -346,6 +344,10 @@ func (base *baseClient) prepare(baseTx sdk.BaseTx) (*clienttx.Factory, error) {
if len(baseTx.Memo) > 0 {
factory.WithMemo(baseTx.Memo)
}

if baseTx.TimeoutHeight > 0 {
factory.WithTimeout(baseTx.TimeoutHeight)
}
return factory, nil
}

Expand Down Expand Up @@ -390,6 +392,10 @@ func (base *baseClient) prepareTemp(addr string, accountNumber, sequence uint64,
if len(baseTx.Memo) > 0 {
factory.WithMemo(baseTx.Memo)
}

if baseTx.TimeoutHeight > 0 {
factory.WithTimeout(baseTx.TimeoutHeight)
}
return factory, nil
}

Expand Down Expand Up @@ -427,7 +433,7 @@ type locker struct {
size int
}

//NewLocker implement the function of lock, can lock resources according to conditions
// NewLocker implement the function of lock, can lock resources according to conditions
func NewLocker(size int) *locker {
shards := make([]chan int, size)
for i := 0; i < size; i++ {
Expand Down
6 changes: 6 additions & 0 deletions modules/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/hex"
"errors"
"github.com/tendermint/tendermint/crypto/tmhash"
"strings"
"time"

Expand Down Expand Up @@ -129,6 +130,11 @@ func (base *baseClient) buildTxWithAccount(addr string, accountNumber, sequence
}

func (base baseClient) broadcastTx(txBytes []byte, mode sdk.BroadcastMode, simulate bool) (res sdk.ResultTx, err sdk.Error) {
defer func() {
if res.Hash == "" {
res.Hash = strings.ToUpper(hex.EncodeToString(tmhash.Sum(txBytes)))
}
}()
if simulate {
estimateGas, err := base.EstimateTxGas(txBytes)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions types/stdtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func NewStdTx(msgs []Msg, fee StdFee, sigs []StdSignature, memo string) StdTx {
}
}

//nolint
// nolint
// GetMsgs returns the all the transaction's messages.
func (tx StdTx) GetMsgs() []Msg { return tx.Msgs }
func (tx StdTx) GetSignBytes() []string {
Expand Down Expand Up @@ -186,7 +186,7 @@ func (tx StdTx) GetSigners() []AccAddress {
return signers
}

//nolint
// nolint
func (tx StdTx) GetMemo() string { return tx.Memo }

// GetSignatures returns the signature of signers who signed the Msg.
Expand All @@ -208,6 +208,7 @@ type BaseTx struct {
Simulate bool `json:"simulate"`
AccountNumber uint64 `json:"account_number"`
Sequence uint64 `json:"sequence"`
TimeoutHeight uint64 `json:"timeout_height"`
}

// ResultTx encapsulates the return result of the transaction. When the transaction fails,
Expand Down
Loading