diff --git a/client/tx/factory.go b/client/tx/factory.go index 7f539c1f..48aff5de 100644 --- a/client/tx/factory.go +++ b/client/tx/factory.go @@ -17,6 +17,7 @@ type ( chainID string memo string password string + timeoutHeight uint64 accountNumber uint64 sequence uint64 gas uint64 @@ -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 { @@ -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 diff --git a/modules/base_client.go b/modules/base_client.go index ebb59194..c5ad1180 100644 --- a/modules/base_client.go +++ b/modules/base_client.go @@ -1,6 +1,4 @@ // Package modules is to warpped the API provided by each module of IRIS-Hub -// -// package modules import ( @@ -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 } @@ -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 } @@ -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++ { diff --git a/modules/tx.go b/modules/tx.go index 7b0fa7dc..44edfb50 100644 --- a/modules/tx.go +++ b/modules/tx.go @@ -4,6 +4,7 @@ import ( "context" "encoding/hex" "errors" + "github.com/tendermint/tendermint/crypto/tmhash" "strings" "time" @@ -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 { diff --git a/types/stdtx.go b/types/stdtx.go index 29b83525..7310eb96 100644 --- a/types/stdtx.go +++ b/types/stdtx.go @@ -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 { @@ -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. @@ -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,