@@ -39,6 +39,9 @@ type Client struct {
3939 clientCtx client.Context
4040}
4141
42+ func (c Client ) TxConfig () client.TxConfig {
43+ return c .clientCtx .TxConfig
44+ }
4245func (c Client ) GetNumberSequence (address string ) (uint64 , uint64 , error ) {
4346 addr , err := sdk .AccAddressFromBech32 (address )
4447 orPanic (err )
@@ -72,6 +75,19 @@ func (c Client) BuildAndSignTx(
7275 )
7376}
7477
78+ func (c Client ) SignTx (
79+ signerAccount Account ,
80+ txBuilder client.TxBuilder ,
81+ ) (signedTx authsigning.Tx , err error ) {
82+ return signTx (
83+ c .clientCtx ,
84+ signerAccount .Key ,
85+ signerAccount .Number ,
86+ signerAccount .Sequence ,
87+ txBuilder ,
88+ )
89+ }
90+
7591func (c Client ) Encode (signedTx authsigning.Tx ) []byte {
7692 return bytesOrPanic (c .clientCtx .TxConfig .TxEncoder ()(signedTx ))
7793}
@@ -181,10 +197,6 @@ func buildAndSignTx(
181197 gasLimit uint64 ,
182198 msgs ... sdk.Msg ,
183199) (signedTx authsigning.Tx , err error ) {
184- privKey := & ethsecp256k1.PrivKey {
185- Key : signerKey ,
186- }
187-
188200 txBuilder := clientCtx .TxConfig .NewTxBuilder ()
189201 txBuilder .SetGasLimit (gasLimit )
190202 txBuilder .SetFeeAmount (fee )
@@ -193,6 +205,22 @@ func buildAndSignTx(
193205 return nil , err
194206 }
195207
208+ return signTx (
209+ clientCtx ,
210+ signerKey ,
211+ accNum ,
212+ accSeq ,
213+ txBuilder ,
214+ )
215+ }
216+
217+ func signTx (
218+ clientCtx client.Context ,
219+ signerKey Secp256k1PrivateKey ,
220+ accNum , accSeq uint64 ,
221+ txBuilder client.TxBuilder ,
222+ ) (signedTx authsigning.Tx , err error ) {
223+
196224 signerData := authsigning.SignerData {
197225 ChainID : clientCtx .ChainID ,
198226 AccountNumber : accNum ,
@@ -204,6 +232,10 @@ func buildAndSignTx(
204232 Signature : nil ,
205233 }
206234
235+ privKey := & ethsecp256k1.PrivKey {
236+ Key : signerKey ,
237+ }
238+
207239 sig := signing.SignatureV2 {
208240 PubKey : privKey .PubKey (),
209241 Data : sigData ,
0 commit comments