@@ -15,7 +15,7 @@ use near_jsonrpc_primitives::types::query::QueryResponseKind;
15
15
use near_jsonrpc_primitives:: types:: transactions:: RpcTransactionError ;
16
16
use near_primitives:: errors:: { ActionError , ActionErrorKind , InvalidTxError , TxExecutionError } ;
17
17
use near_primitives:: hash:: CryptoHash ;
18
- use near_primitives:: transaction:: { Action , Transaction } ;
18
+ use near_primitives:: transaction:: { Action , SignedTransaction , Transaction } ;
19
19
use near_primitives:: types:: { BlockHeight , Finality , Nonce } ;
20
20
use near_primitives:: views:: {
21
21
AccessKeyView , ExecutionStatusView , FinalExecutionOutcomeView , FinalExecutionOutcomeViewEnum ,
@@ -95,6 +95,28 @@ impl Client {
95
95
}
96
96
}
97
97
98
+ pub ( crate ) async fn sign_tx (
99
+ & self ,
100
+ signer : & dyn SignerExt ,
101
+ receiver_id : & AccountId ,
102
+ actions : Vec < Action > ,
103
+ ) -> Result < SignedTransaction > {
104
+ let pk = signer. public_key ( ) ;
105
+ let ( nonce, block_hash, _) = self . fetch_nonce ( signer. account_id ( ) , & pk) . await ?;
106
+
107
+ let tx = Transaction :: V0 ( near_primitives:: transaction:: TransactionV0 {
108
+ nonce,
109
+ signer_id : signer. account_id ( ) . clone ( ) ,
110
+ public_key : pk,
111
+ receiver_id : receiver_id. clone ( ) ,
112
+ block_hash,
113
+ actions,
114
+ } ) ;
115
+
116
+ let signature = signer. sign ( tx. get_hash_and_size ( ) . 0 . as_ref ( ) ) ;
117
+ Ok ( SignedTransaction :: new ( signature, tx) )
118
+ }
119
+
98
120
/// Send the transaction only once. No retrying involved.
99
121
pub ( crate ) async fn send_tx_once (
100
122
& self ,
@@ -104,20 +126,12 @@ impl Client {
104
126
wait_until : TxExecutionStatus ,
105
127
) -> Result < FinalExecutionOutcomeView > {
106
128
let cache_key = ( signer. account_id ( ) . clone ( ) , signer. public_key ( ) ) ;
107
- let ( nonce , block_hash , _ ) = self . fetch_nonce ( & cache_key . 0 , & cache_key . 1 ) . await ?;
129
+ let signed_transaction = self . sign_tx ( signer , receiver_id , actions ) . await ?;
108
130
109
131
let result = self
110
132
. rpc_client
111
133
. call ( & methods:: send_tx:: RpcSendTransactionRequest {
112
- signed_transaction : Transaction {
113
- nonce,
114
- block_hash,
115
- signer_id : signer. account_id ( ) . clone ( ) ,
116
- public_key : signer. public_key ( ) ,
117
- receiver_id : receiver_id. clone ( ) ,
118
- actions : actions. clone ( ) ,
119
- }
120
- . sign ( signer. as_signer ( ) ) ,
134
+ signed_transaction,
121
135
wait_until,
122
136
} )
123
137
. await ;
@@ -143,17 +157,7 @@ impl Client {
143
157
// Note, the cache key's public-key part can be different per retry loop. For instance,
144
158
// KeyRotatingSigner rotates secret_key and public_key after each `Signer::sign` call.
145
159
let cache_key = ( signer. account_id ( ) . clone ( ) , signer. public_key ( ) ) ;
146
-
147
- let ( nonce, block_hash, _) = self . fetch_nonce ( & cache_key. 0 , & cache_key. 1 ) . await ?;
148
- let signed_transaction = Transaction {
149
- nonce,
150
- block_hash,
151
- signer_id : signer. account_id ( ) . clone ( ) ,
152
- public_key : signer. public_key ( ) ,
153
- receiver_id : receiver_id. clone ( ) ,
154
- actions : actions. clone ( ) ,
155
- }
156
- . sign ( signer. as_signer ( ) ) ;
160
+ let signed_transaction = self . sign_tx ( signer, receiver_id, actions) . await ?;
157
161
let tx_hash = signed_transaction. get_hash ( ) ;
158
162
159
163
let result = self
0 commit comments