From 192f4e633ec12417f13704f8103549a3db3a0411 Mon Sep 17 00:00:00 2001 From: trungnb-viigstar Date: Sat, 19 Mar 2022 21:45:29 +0700 Subject: [PATCH 1/2] ft(export-unsigned-transaction): comment code and sample about how to return an uninitialized instructions --- .../utility/createExternalPriceAccount.ts | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/actions/utility/createExternalPriceAccount.ts b/src/actions/utility/createExternalPriceAccount.ts index a75e384..410aec7 100644 --- a/src/actions/utility/createExternalPriceAccount.ts +++ b/src/actions/utility/createExternalPriceAccount.ts @@ -23,18 +23,27 @@ import { TransactionsBatch } from '../../utils/transactions-batch'; interface CreateExternalPriceAccountParams { connection: Connection; wallet: Wallet; + isUninitialized?: boolean; } interface CreateExternalPriceAccountResponse { txId: TransactionSignature; externalPriceAccount: PublicKey; priceMint: PublicKey; + transactionBatch?: Array } -// This command creates the external pricing oracle +/*** + * This command creates the external pricing oracle + * @param connection + * @param wallet + * @param isUninitialized {boolean} optional + * Indicate that transaction should be immediately signed by owner or just get instructions to merge into bigger transaction + */ export const createExternalPriceAccount = async ({ connection, wallet, + isUninitialized, }: CreateExternalPriceAccountParams): Promise => { const txBatch = new TransactionsBatch({ transactions: [] }); const txOptions: TransactionCtorFields = { feePayer: wallet.publicKey }; @@ -68,6 +77,16 @@ export const createExternalPriceAccount = async ({ externalPriceAccountData, }); txBatch.addTransaction(updateEPA); + const externalPriceAccountResponse = { + externalPriceAccount: externalPriceAccount.publicKey, + priceMint: NATIVE_MINT, + } as CreateExternalPriceAccountResponse + + if (isUninitialized) { + return Object.assign(externalPriceAccountResponse, { + transactionBatch: [txBatch] + } as CreateExternalPriceAccountResponse) + } const txId = await sendTransaction({ connection, From 84356a9fa19ab9e8c6ede046b0411469160b4702 Mon Sep 17 00:00:00 2001 From: trungnb-viigstar Date: Sat, 19 Mar 2022 21:56:51 +0700 Subject: [PATCH 2/2] ft(export-unsigned-transaction): refactor response createExternalPriceAccount --- src/actions/utility/createExternalPriceAccount.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/actions/utility/createExternalPriceAccount.ts b/src/actions/utility/createExternalPriceAccount.ts index 410aec7..cab09b5 100644 --- a/src/actions/utility/createExternalPriceAccount.ts +++ b/src/actions/utility/createExternalPriceAccount.ts @@ -77,15 +77,15 @@ export const createExternalPriceAccount = async ({ externalPriceAccountData, }); txBatch.addTransaction(updateEPA); + const externalPriceAccountResponse = { externalPriceAccount: externalPriceAccount.publicKey, priceMint: NATIVE_MINT, + transactionBatch: [txBatch] } as CreateExternalPriceAccountResponse if (isUninitialized) { - return Object.assign(externalPriceAccountResponse, { - transactionBatch: [txBatch] - } as CreateExternalPriceAccountResponse) + return externalPriceAccountResponse } const txId = await sendTransaction({ @@ -97,7 +97,6 @@ export const createExternalPriceAccount = async ({ return { txId, - externalPriceAccount: externalPriceAccount.publicKey, - priceMint: NATIVE_MINT, + ...externalPriceAccountResponse, }; };