@@ -31,7 +31,8 @@ import {
3131import { applyCommonTransactionParams } from "../params/common-tx-params" ;
3232import { TransferCryptoParams } from "../params/transfer" ;
3333
34- export const createAccount = async ( {
34+ // buildCreateAccount builds an AccountCreateTransaction from parameters
35+ export const buildCreateAccount = ( {
3536 key,
3637 initialBalance,
3738 receiverSignatureRequired,
@@ -43,7 +44,7 @@ export const createAccount = async ({
4344 memo,
4445 autoRenewPeriod,
4546 alias,
46- } : CreateAccountParams ) : Promise < AccountResponse > => {
47+ } : CreateAccountParams ) : AccountCreateTransaction => {
4748 let transaction = new AccountCreateTransaction ( ) . setGrpcDeadline (
4849 DEFAULT_GRPC_DEADLINE ,
4950 ) ;
@@ -98,16 +99,25 @@ export const createAccount = async ({
9899 ) ;
99100 }
100101
102+ return transaction ;
103+ } ;
104+
105+ export const createAccount = async (
106+ params : CreateAccountParams ,
107+ ) : Promise < AccountResponse > => {
108+ const transaction = buildCreateAccount ( params ) ;
109+
101110 const txResponse = await transaction . execute ( sdk . getClient ( ) ) ;
102111 const receipt = await txResponse . getReceipt ( sdk . getClient ( ) ) ;
103112
104113 return {
105- accountId : receipt . accountId . toString ( ) ,
114+ accountId : receipt . accountId ? .toString ( ) ,
106115 status : receipt . status . toString ( ) ,
107116 } ;
108117} ;
109118
110- export const updateAccount = async ( {
119+ // buildUpdateAccount builds an AccountUpdateTransaction from parameters
120+ const buildUpdateAccount = ( {
111121 accountId,
112122 key,
113123 autoRenewPeriod,
@@ -119,7 +129,7 @@ export const updateAccount = async ({
119129 stakedNodeId,
120130 declineStakingReward,
121131 commonTransactionParams,
122- } : UpdateAccountParams ) : Promise < AccountResponse > => {
132+ } : UpdateAccountParams ) : AccountUpdateTransaction => {
123133 let transaction = new AccountUpdateTransaction ( ) . setGrpcDeadline (
124134 DEFAULT_GRPC_DEADLINE ,
125135 ) ;
@@ -176,6 +186,14 @@ export const updateAccount = async ({
176186 ) ;
177187 }
178188
189+ return transaction ;
190+ } ;
191+
192+ export const updateAccount = async (
193+ params : UpdateAccountParams ,
194+ ) : Promise < AccountResponse > => {
195+ const transaction = buildUpdateAccount ( params ) ;
196+
179197 const txResponse = await transaction . execute ( sdk . getClient ( ) ) ;
180198 const receipt = await txResponse . getReceipt ( sdk . getClient ( ) ) ;
181199
@@ -184,11 +202,12 @@ export const updateAccount = async ({
184202 } ;
185203} ;
186204
187- export const deleteAccount = async ( {
205+ // buildDeleteAccount builds an AccountDeleteTransaction from parameters
206+ const buildDeleteAccount = ( {
188207 deleteAccountId,
189208 transferAccountId,
190209 commonTransactionParams,
191- } : DeleteAccountParams ) : Promise < AccountResponse > => {
210+ } : DeleteAccountParams ) : AccountDeleteTransaction => {
192211 let transaction = new AccountDeleteTransaction ( ) . setGrpcDeadline (
193212 DEFAULT_GRPC_DEADLINE ,
194213 ) ;
@@ -211,6 +230,14 @@ export const deleteAccount = async ({
211230 ) ;
212231 }
213232
233+ return transaction ;
234+ } ;
235+
236+ export const deleteAccount = async (
237+ params : DeleteAccountParams ,
238+ ) : Promise < AccountResponse > => {
239+ const transaction = buildDeleteAccount ( params ) ;
240+
214241 const txResponse = await transaction . execute ( sdk . getClient ( ) ) ;
215242 const receipt = await txResponse . getReceipt ( sdk . getClient ( ) ) ;
216243
@@ -219,10 +246,11 @@ export const deleteAccount = async ({
219246 } ;
220247} ;
221248
222- export const approveAllowance = async ( {
249+ // buildApproveAllowance builds an AccountAllowanceApproveTransaction from parameters
250+ export const buildApproveAllowance = ( {
223251 allowances,
224252 commonTransactionParams,
225- } : AccountAllowanceApproveParams ) : Promise < AccountResponse > => {
253+ } : AccountAllowanceApproveParams ) : AccountAllowanceApproveTransaction => {
226254 const transaction = new AccountAllowanceApproveTransaction ( ) ;
227255 transaction . setGrpcDeadline ( DEFAULT_GRPC_DEADLINE ) ;
228256
@@ -252,8 +280,6 @@ export const approveAllowance = async ({
252280 }
253281 }
254282
255- transaction . freezeWith ( sdk . getClient ( ) ) ;
256-
257283 if ( commonTransactionParams ) {
258284 applyCommonTransactionParams (
259285 commonTransactionParams ,
@@ -262,6 +288,14 @@ export const approveAllowance = async ({
262288 ) ;
263289 }
264290
291+ return transaction ;
292+ } ;
293+
294+ export const approveAllowance = async (
295+ params : AccountAllowanceApproveParams ,
296+ ) : Promise < AccountResponse > => {
297+ const transaction = buildApproveAllowance ( params ) ;
298+
265299 const txResponse = await transaction . execute ( sdk . getClient ( ) ) ;
266300 const receipt = await txResponse . getReceipt ( sdk . getClient ( ) ) ;
267301
@@ -270,23 +304,21 @@ export const approveAllowance = async ({
270304 } ;
271305} ;
272306
273- export const deleteAllowance = async ( {
307+ // buildDeleteAllowance builds an AccountAllowanceDeleteTransaction from parameters
308+ const buildDeleteAllowance = ( {
274309 allowances,
275310 commonTransactionParams,
276- } : DeleteAllowanceParams ) : Promise < AccountResponse > => {
311+ } : DeleteAllowanceParams ) : AccountAllowanceDeleteTransaction => {
277312 let transaction = new AccountAllowanceDeleteTransaction ( ) . setGrpcDeadline (
278313 DEFAULT_GRPC_DEADLINE ,
279314 ) ;
280315
281316 for ( const allowance of allowances ) {
282317 const owner = AccountId . fromString ( allowance . ownerAccountId ) ;
283- const tokenId = AccountId . fromString ( allowance . tokenId ) ;
318+ const tokenId = TokenId . fromString ( allowance . tokenId ) ;
284319
285320 for ( const serialNumber of allowance . serialNumbers ) {
286- const nftId = new NftId (
287- new TokenId ( tokenId ) ,
288- Long . fromString ( serialNumber ) ,
289- ) ;
321+ const nftId = new NftId ( tokenId , Long . fromString ( serialNumber ) ) ;
290322
291323 transaction . deleteAllTokenNftAllowances ( nftId , owner ) ;
292324 }
@@ -300,6 +332,14 @@ export const deleteAllowance = async ({
300332 ) ;
301333 }
302334
335+ return transaction ;
336+ } ;
337+
338+ export const deleteAllowance = async (
339+ params : DeleteAllowanceParams ,
340+ ) : Promise < AccountResponse > => {
341+ const transaction = buildDeleteAllowance ( params ) ;
342+
303343 const txResponse = await transaction . execute ( sdk . getClient ( ) ) ;
304344 const receipt = await txResponse . getReceipt ( sdk . getClient ( ) ) ;
305345
@@ -308,10 +348,11 @@ export const deleteAllowance = async ({
308348 } ;
309349} ;
310350
311- export const transferCrypto = async ( {
351+ // buildTransferCrypto builds a TransferTransaction from parameters
352+ export const buildTransferCrypto = ( {
312353 transfers,
313354 commonTransactionParams,
314- } : TransferCryptoParams ) : Promise < AccountResponse > => {
355+ } : TransferCryptoParams ) : TransferTransaction => {
315356 if ( ! transfers . length ) {
316357 throw new Error ( "No transfers provided." ) ;
317358 }
@@ -403,6 +444,14 @@ export const transferCrypto = async ({
403444 ) ;
404445 }
405446
447+ return transaction ;
448+ } ;
449+
450+ export const transferCrypto = async (
451+ params : TransferCryptoParams ,
452+ ) : Promise < AccountResponse > => {
453+ const transaction = buildTransferCrypto ( params ) ;
454+
406455 const txResponse = await transaction . execute ( sdk . getClient ( ) ) ;
407456 const receipt = await txResponse . getReceipt ( sdk . getClient ( ) ) ;
408457
0 commit comments