Skip to content

Commit

Permalink
v0.0.16
Browse files Browse the repository at this point in the history
  • Loading branch information
abrzezinski94 committed Apr 7, 2024
1 parent 2dd77ad commit 87a557d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@blockworks-foundation/mangolana",
"version": "0.0.15",
"version": "0.0.16",
"description": "",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
61 changes: 48 additions & 13 deletions src/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
TransactionSignature,
} from '@solana/web3.js';
import bs58 = require('bs58');
import { getUnixTs, Logger, MAXIMUM_NUMBER_OF_BLOCKS_FOR_TRANSACTION, sleep } from './tools';
import { getUnixTs, Logger, sleep } from './tools';
import {
BlockHeightStrategy,
BlockHeightStrategyClass,
Expand Down Expand Up @@ -311,6 +311,7 @@ export type sendAndConfirmSignedTransactionProps = {
logFlowInfo?: boolean;
skipPreflight?: boolean;
};
backupConnections?: Connection[];
};

/**
Expand Down Expand Up @@ -344,7 +345,13 @@ export const sendAndConfirmSignedTransaction = async ({
callbacks,
timeoutStrategy,
config,
backupConnections,
}: sendAndConfirmSignedTransactionProps) => {
const connections = [connection];
const abortController = new AbortController();
if (backupConnections && backupConnections.length) {
connections.push(...backupConnections);
}
const logger = new Logger({ ...config });
const timeoutConfig = getTimeoutConfig(timeoutStrategy);
let resendTimeout = 0;
Expand All @@ -359,9 +366,13 @@ export const sendAndConfirmSignedTransaction = async ({
const rawTransaction = signedTransaction.serialize();
let txid = bs58.encode(signedTransaction.signatures[0].signature!);
const startTime = getUnixTs();
txid = await connection.sendRawTransaction(rawTransaction, {
skipPreflight: config?.skipPreflight === undefined ? true : config.skipPreflight,
});
txid = await Promise.any(

Check failure on line 369 in src/transactions.ts

View workflow job for this annotation

GitHub Actions / Format

Property 'any' does not exist on type 'PromiseConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2021' or later.

Check failure on line 369 in src/transactions.ts

View workflow job for this annotation

GitHub Actions / Lint

Property 'any' does not exist on type 'PromiseConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2021' or later.

Check failure on line 369 in src/transactions.ts

View workflow job for this annotation

GitHub Actions / Format

Property 'any' does not exist on type 'PromiseConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2021' or later.

Check failure on line 369 in src/transactions.ts

View workflow job for this annotation

GitHub Actions / Lint

Property 'any' does not exist on type 'PromiseConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2021' or later.
connections.map((c) => {
return c.sendRawTransaction(rawTransaction, {
skipPreflight: config?.skipPreflight === undefined ? true : config.skipPreflight,
});
}),
);
if (callbacks?.postSendTxCallback) {
try {
callbacks.postSendTxCallback({ txid });
Expand All @@ -375,26 +386,44 @@ export const sendAndConfirmSignedTransaction = async ({
(async () => {
while (!done && getUnixTs() - startTime < resendTimeout!) {
await sleep(config?.resendPoolTimeMs || 2000);
connection.sendRawTransaction(rawTransaction, {
skipPreflight: config?.skipPreflight === undefined ? true : config.skipPreflight,
connections.map((c) => {
return c.sendRawTransaction(rawTransaction, {
skipPreflight: config?.skipPreflight === undefined ? true : config.skipPreflight,
});
});
}
})();
}

try {
await awaitTransactionSignatureConfirmation({
txid,
timeoutStrategy: timeoutStrategy,
confirmLevel,
connection,
config,
});
await Promise.any(

Check failure on line 399 in src/transactions.ts

View workflow job for this annotation

GitHub Actions / Format

Property 'any' does not exist on type 'PromiseConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2021' or later.

Check failure on line 399 in src/transactions.ts

View workflow job for this annotation

GitHub Actions / Lint

Property 'any' does not exist on type 'PromiseConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2021' or later.

Check failure on line 399 in src/transactions.ts

View workflow job for this annotation

GitHub Actions / Format

Property 'any' does not exist on type 'PromiseConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2021' or later.

Check failure on line 399 in src/transactions.ts

View workflow job for this annotation

GitHub Actions / Lint

Property 'any' does not exist on type 'PromiseConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2021' or later.
connections.map((c) =>
awaitTransactionSignatureConfirmation({
txid,
timeoutStrategy: timeoutStrategy,
confirmLevel,
connection: c,
config,
abortSignal: abortController.signal,
}),
),
);
abortController.abort();
if (callbacks?.afterTxConfirmation) {
callbacks.afterTxConfirmation();
}
} catch (err: any) {
logger.log(err);
abortController.abort();
if (err instanceof AggregateError) {

Check failure on line 418 in src/transactions.ts

View workflow job for this annotation

GitHub Actions / Format

Cannot find name 'AggregateError'.

Check failure on line 418 in src/transactions.ts

View workflow job for this annotation

GitHub Actions / Lint

Cannot find name 'AggregateError'.

Check failure on line 418 in src/transactions.ts

View workflow job for this annotation

GitHub Actions / Format

Cannot find name 'AggregateError'.

Check failure on line 418 in src/transactions.ts

View workflow job for this annotation

GitHub Actions / Lint

Cannot find name 'AggregateError'.
for (const individualError of err.errors) {
logger.log(individualError);
if (individualError === 'Timeout') {
throw { txid };
}
throw { message: 'Transaction failed', txid };
}
}
if (err === 'Timeout') {
throw { txid };
}
Expand Down Expand Up @@ -453,6 +482,7 @@ export type sendSignAndConfirmTransactionsProps = {
retried?: number;
logFlowInfo?: boolean;
};
backupConnections?: Connection[];
};
/**
* sign and send array of transactions in desired batches with different styles of send for each array
Expand Down Expand Up @@ -492,6 +522,7 @@ export const sendSignAndConfirmTransactions = async ({
retried: 0,
logFlowInfo: false,
},
backupConnections,
}: sendSignAndConfirmTransactionsProps) => {
const logger = new Logger({ ...config });
let block = timeoutStrategy?.block;
Expand Down Expand Up @@ -589,6 +620,7 @@ export const sendSignAndConfirmTransactions = async ({
afterTxConfirmation: callbacks?.afterEveryTxConfirmation,
},
config,
backupConnections,
});
resolve(resp);
} catch (e) {
Expand Down Expand Up @@ -623,6 +655,7 @@ export const sendSignAndConfirmTransactions = async ({
afterTxConfirmation: callbacks?.afterEveryTxConfirmation,
},
config,
backupConnections,
});
} catch (e) {
logger.log(e);
Expand Down Expand Up @@ -658,6 +691,7 @@ export const sendSignAndConfirmTransactions = async ({
onError: callbacks?.onError,
},
config,
backupConnections,
});
}
if (callbacks?.afterAllTxConfirmed) {
Expand Down Expand Up @@ -704,6 +738,7 @@ export const sendSignAndConfirmTransactions = async ({
transactionInstructions: txInstructionForRetry,
callbacks,
config,
backupConnections,
});
} else {
throw e;
Expand Down

0 comments on commit 87a557d

Please sign in to comment.