Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@saberhq/solana-contrib

Package Overview
Dependencies
Maintainers
2
Versions
181
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@saberhq/solana-contrib - npm Package Compare versions

Comparing version 1.12.62 to 1.12.63

153

dist/cjs/broadcaster.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MultipleConnectionBroadcaster = exports.SingleConnectionBroadcaster = void 0;
const tslib_1 = require("tslib");
const error_1 = require("./error");

@@ -21,9 +20,7 @@ const provider_1 = require("./provider");

*/
getRecentBlockhash(commitment) {
async getRecentBlockhash(commitment) {
var _a;
if (commitment === void 0) { commitment = (_a = this.opts.commitment) !== null && _a !== void 0 ? _a : "confirmed"; }
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const result = yield this.sendConnection.getLatestBlockhash(commitment);
return result.blockhash;
});
const result = await this.sendConnection.getLatestBlockhash(commitment);
return result.blockhash;
}

@@ -33,16 +30,13 @@ /**

*/
broadcast(tx, _a = this.opts) {
var { printLogs = true } = _a, opts = tslib_1.__rest(_a, ["printLogs"]);
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (tx.signatures.length === 0) {
throw new Error("Transaction must be signed before broadcasting.");
}
const rawTx = tx.serialize();
if (printLogs) {
return new transaction_1.PendingTransaction(this.sendConnection, yield this.sendConnection.sendRawTransaction(rawTx, opts));
}
return yield (0, utils_1.suppressConsoleErrorAsync)(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
// hide the logs of TX errors if printLogs = false
return new transaction_1.PendingTransaction(this.sendConnection, yield this.sendConnection.sendRawTransaction(rawTx, opts));
}));
async broadcast(tx, { printLogs = true, ...opts } = this.opts) {
if (tx.signatures.length === 0) {
throw new Error("Transaction must be signed before broadcasting.");
}
const rawTx = tx.serialize();
if (printLogs) {
return new transaction_1.PendingTransaction(this.sendConnection, await this.sendConnection.sendRawTransaction(rawTx, opts));
}
return await (0, utils_1.suppressConsoleErrorAsync)(async () => {
// hide the logs of TX errors if printLogs = false
return new transaction_1.PendingTransaction(this.sendConnection, await this.sendConnection.sendRawTransaction(rawTx, opts));
});

@@ -53,3 +47,3 @@ }

*/
simulate(tx, _a) {
async simulate(tx, _a) {
var _b, _c;

@@ -60,8 +54,6 @@ var { commitment = (_b = this.opts.preflightCommitment) !== null && _b !== void 0 ? _b : "confirmed", verifySigners = true, } = _a === void 0 ? {

} : _a;
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (verifySigners && tx.signatures.length === 0) {
throw new Error("Transaction must be signed before simulating.");
}
return yield (0, simulateTransactionWithCommitment_1.simulateTransactionWithCommitment)(this.sendConnection, tx, commitment);
});
if (verifySigners && tx.signatures.length === 0) {
throw new Error("Transaction must be signed before simulating.");
}
return await (0, simulateTransactionWithCommitment_1.simulateTransactionWithCommitment)(this.sendConnection, tx, commitment);
}

@@ -78,36 +70,32 @@ }

}
getRecentBlockhash(commitment) {
async getRecentBlockhash(commitment) {
var _a;
if (commitment === void 0) { commitment = (_a = this.opts.preflightCommitment) !== null && _a !== void 0 ? _a : "confirmed"; }
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
const result = yield Promise.any(this.connections.map((conn) => conn.getLatestBlockhash(commitment)));
return result.blockhash;
try {
const result = await Promise.any(this.connections.map((conn) => conn.getLatestBlockhash(commitment)));
return result.blockhash;
}
catch (e) {
if (e instanceof AggregateError) {
throw (0, error_1.firstAggregateError)(e);
}
catch (e) {
if (e instanceof AggregateError) {
throw (0, error_1.firstAggregateError)(e);
}
else {
throw e;
}
else {
throw e;
}
});
}
}
_sendRawTransaction(encoded, options) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
return yield Promise.any(this.connections.map((connection) => tslib_1.__awaiter(this, void 0, void 0, function* () {
return new transaction_1.PendingTransaction(connection, yield connection.sendRawTransaction(encoded, options));
})));
async _sendRawTransaction(encoded, options) {
try {
return await Promise.any(this.connections.map(async (connection) => {
return new transaction_1.PendingTransaction(connection, await connection.sendRawTransaction(encoded, options));
}));
}
catch (e) {
if (e instanceof AggregateError) {
throw (0, error_1.firstAggregateError)(e);
}
catch (e) {
if (e instanceof AggregateError) {
throw (0, error_1.firstAggregateError)(e);
}
else {
throw e;
}
else {
throw e;
}
});
}
}

@@ -122,16 +110,13 @@ /**

*/
broadcast(tx, _a = this.opts) {
var { printLogs = true } = _a, opts = tslib_1.__rest(_a, ["printLogs"]);
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (tx.signatures.length === 0) {
throw new Error("Transaction must be signed before broadcasting.");
}
const rawTx = tx.serialize();
if (printLogs) {
return yield this._sendRawTransaction(rawTx, opts);
}
return yield (0, utils_1.suppressConsoleErrorAsync)(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
// hide the logs of TX errors if printLogs = false
return yield this._sendRawTransaction(rawTx, opts);
}));
async broadcast(tx, { printLogs = true, ...opts } = this.opts) {
if (tx.signatures.length === 0) {
throw new Error("Transaction must be signed before broadcasting.");
}
const rawTx = tx.serialize();
if (printLogs) {
return await this._sendRawTransaction(rawTx, opts);
}
return await (0, utils_1.suppressConsoleErrorAsync)(async () => {
// hide the logs of TX errors if printLogs = false
return await this._sendRawTransaction(rawTx, opts);
});

@@ -145,3 +130,3 @@ }

*/
simulate(tx, _a) {
async simulate(tx, _a) {
var _b, _c;

@@ -152,20 +137,18 @@ var { commitment = (_b = this.opts.preflightCommitment) !== null && _b !== void 0 ? _b : "confirmed", verifySigners = true, } = _a === void 0 ? {

} : _a;
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (verifySigners && tx.signatures.length === 0) {
throw new Error("Transaction must be signed before simulating.");
if (verifySigners && tx.signatures.length === 0) {
throw new Error("Transaction must be signed before simulating.");
}
try {
return await Promise.any(this.connections.map(async (connection) => {
return await (0, simulateTransactionWithCommitment_1.simulateTransactionWithCommitment)(connection, tx, commitment);
}));
}
catch (e) {
if (e instanceof AggregateError) {
throw (0, error_1.firstAggregateError)(e);
}
try {
return yield Promise.any(this.connections.map((connection) => tslib_1.__awaiter(this, void 0, void 0, function* () {
return yield (0, simulateTransactionWithCommitment_1.simulateTransactionWithCommitment)(connection, tx, commitment);
})));
else {
throw e;
}
catch (e) {
if (e instanceof AggregateError) {
throw (0, error_1.firstAggregateError)(e);
}
else {
throw e;
}
}
});
}
}

@@ -172,0 +155,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SolanaAugmentedProvider = exports.SolanaProvider = exports.SolanaTransactionSigner = exports.SolanaReadonlyProvider = exports.DEFAULT_READONLY_PUBLIC_KEY = exports.DEFAULT_PROVIDER_OPTIONS = void 0;
const tslib_1 = require("tslib");
const web3_js_1 = require("@solana/web3.js");

@@ -32,3 +31,6 @@ const _1 = require(".");

};
this.wallet = Object.assign(Object.assign({}, this.wallet), { publicKey });
this.wallet = {
...this.wallet,
publicKey,
};
}

@@ -40,13 +42,11 @@ /**

*/
getAccountInfo(accountId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const accountInfo = yield this.connection.getAccountInfo(accountId, this.opts.commitment);
if (!accountInfo) {
return null;
}
return {
accountId,
accountInfo,
};
});
async getAccountInfo(accountId) {
const accountInfo = await this.connection.getAccountInfo(accountId, this.opts.commitment);
if (!accountInfo) {
return null;
}
return {
accountId,
accountInfo,
};
}

@@ -75,16 +75,14 @@ }

*/
sign(tx, signers = [], opts = {
async sign(tx, signers = [], opts = {
preflightCommitment: this.preflightCommitment,
}) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
tx.feePayer = this.wallet.publicKey;
tx.recentBlockhash = yield this.broadcaster.getRecentBlockhash(opts.preflightCommitment);
yield this.wallet.signTransaction(tx);
signers
.filter((s) => s !== undefined)
.forEach((kp) => {
tx.partialSign(kp);
});
return tx;
tx.feePayer = this.wallet.publicKey;
tx.recentBlockhash = await this.broadcaster.getRecentBlockhash(opts.preflightCommitment);
await this.wallet.signTransaction(tx);
signers
.filter((s) => s !== undefined)
.forEach((kp) => {
tx.partialSign(kp);
});
return tx;
}

@@ -94,25 +92,23 @@ /**

*/
signAll(reqs, opts = {
async signAll(reqs, opts = {
preflightCommitment: this.preflightCommitment,
}) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const blockhash = yield this.broadcaster.getRecentBlockhash(opts.preflightCommitment);
const txs = reqs.map((r) => {
const tx = r.tx;
let signers = r.signers;
if (signers === undefined) {
signers = [];
}
tx.feePayer = this.wallet.publicKey;
tx.recentBlockhash = blockhash;
signers
.filter((s) => s !== undefined)
.forEach((kp) => {
tx.partialSign(kp);
});
return tx;
const blockhash = await this.broadcaster.getRecentBlockhash(opts.preflightCommitment);
const txs = reqs.map((r) => {
const tx = r.tx;
let signers = r.signers;
if (signers === undefined) {
signers = [];
}
tx.feePayer = this.wallet.publicKey;
tx.recentBlockhash = blockhash;
signers
.filter((s) => s !== undefined)
.forEach((kp) => {
tx.partialSign(kp);
});
const signedTxs = yield this.wallet.signAllTransactions(txs);
return signedTxs;
return tx;
});
const signedTxs = await this.wallet.signAllTransactions(txs);
return signedTxs;
}

@@ -163,9 +159,7 @@ }

*/
send(tx, signers = [], opts = this.opts) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const theTx = yield this.signer.sign(tx, signers, opts);
const pending = yield this.broadcaster.broadcast(theTx, opts);
yield pending.wait();
return pending;
});
async send(tx, signers = [], opts = this.opts) {
const theTx = await this.signer.sign(tx, signers, opts);
const pending = await this.broadcaster.broadcast(theTx, opts);
await pending.wait();
return pending;
}

@@ -175,11 +169,9 @@ /**

*/
sendAll(reqs, opts = this.opts) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const txs = yield this.signer.signAll(reqs, opts);
return yield Promise.all(txs.map((tx) => tslib_1.__awaiter(this, void 0, void 0, function* () {
const pending = yield this.broadcaster.broadcast(tx, opts);
yield pending.wait();
return pending;
})));
});
async sendAll(reqs, opts = this.opts) {
const txs = await this.signer.signAll(reqs, opts);
return await Promise.all(txs.map(async (tx) => {
const pending = await this.broadcaster.broadcast(tx, opts);
await pending.wait();
return pending;
}));
}

@@ -195,12 +187,10 @@ /**

*/
simulate(tx, signers, opts = this.opts) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
let simTX = tx;
if (signers !== undefined) {
simTX = yield this.signer.sign(tx, signers, opts);
}
return yield this.broadcaster.simulate(simTX, {
verifySigners: signers !== undefined,
commitment: opts.commitment,
});
async simulate(tx, signers, opts = this.opts) {
let simTX = tx;
if (signers !== undefined) {
simTX = await this.signer.sign(tx, signers, opts);
}
return await this.broadcaster.simulate(simTX, {
verifySigners: signers !== undefined,
commitment: opts.commitment,
});

@@ -261,6 +251,4 @@ }

*/
requestAirdrop(lamports, to = this.wallet.publicKey) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return new _1.PendingTransaction(this.connection, yield this.connection.requestAirdrop(to, lamports));
});
async requestAirdrop(lamports, to = this.wallet.publicKey) {
return new _1.PendingTransaction(this.connection, await this.connection.requestAirdrop(to, lamports));
}

@@ -267,0 +255,0 @@ /**

@@ -28,14 +28,11 @@ "use strict";

*/
wait(_a = {}) {
var { commitment = "confirmed", useWebsocket = false } = _a, retryOpts = tslib_1.__rest(_a, ["commitment", "useWebsocket"]);
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (this._receipt) {
return this._receipt;
}
if (useWebsocket) {
yield this.awaitSignatureConfirmation(commitment);
return yield this.pollForReceipt({ commitment });
}
return yield this.pollForReceipt(Object.assign({ commitment }, retryOpts));
});
async wait({ commitment = "confirmed", useWebsocket = false, ...retryOpts } = {}) {
if (this._receipt) {
return this._receipt;
}
if (useWebsocket) {
await this.awaitSignatureConfirmation(commitment);
return await this.pollForReceipt({ commitment });
}
return await this.pollForReceipt({ commitment, ...retryOpts });
}

@@ -46,21 +43,22 @@ /**

*/
pollForReceipt(_a = {}) {
var { commitment = "confirmed" } = _a, retryOpts = tslib_1.__rest(_a, ["commitment"]);
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const receipt = yield (0, promise_retry_1.default)((retry) => tslib_1.__awaiter(this, void 0, void 0, function* () {
const result = yield this.connection.getTransaction(this.signature, {
commitment,
});
if (!result) {
retry(new Error("Error fetching transaction"));
return;
}
return new transaction_1.TransactionReceipt(this.signature, result);
}), Object.assign({ retries: 5, minTimeout: 500 }, retryOpts));
if (!receipt) {
throw new Error("transaction could not be confirmed");
async pollForReceipt({ commitment = "confirmed", ...retryOpts } = {}) {
const receipt = await (0, promise_retry_1.default)(async (retry) => {
const result = await this.connection.getTransaction(this.signature, {
commitment,
});
if (!result) {
retry(new Error("Error fetching transaction"));
return;
}
this._receipt = receipt;
return receipt;
return new transaction_1.TransactionReceipt(this.signature, result);
}, {
retries: 5,
minTimeout: 500,
...retryOpts,
});
if (!receipt) {
throw new Error("transaction could not be confirmed");
}
this._receipt = receipt;
return receipt;
}

@@ -71,10 +69,8 @@ /**

*/
awaitSignatureConfirmation(commitment = "confirmed") {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const { value } = yield this.connection.confirmTransaction(this.signature, commitment);
if (value.err) {
throw value.err;
}
return this.signature;
});
async awaitSignatureConfirmation(commitment = "confirmed") {
const { value } = await this.connection.confirmTransaction(this.signature, commitment);
if (value.err) {
throw value.err;
}
return this.signature;
}

@@ -81,0 +77,0 @@ /**

@@ -217,3 +217,3 @@ "use strict";

simulateUnchecked(opts) {
return this.simulate(Object.assign(Object.assign({}, opts), { verifySigners: false }));
return this.simulate({ ...opts, verifySigners: false });
}

@@ -258,7 +258,5 @@ /**

*/
send(opts) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const signed = yield this.provider.signer.sign(this.build(), this.signers, opts);
return this.provider.broadcaster.broadcast(signed, opts);
});
async send(opts) {
const signed = await this.provider.signer.sign(this.build(), this.signers, opts);
return this.provider.broadcaster.broadcast(signed, opts);
}

@@ -269,6 +267,4 @@ /**

*/
confirm(opts) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return (yield this.send(opts)).wait();
});
async confirm(opts) {
return (await this.send(opts)).wait();
}

@@ -395,10 +391,8 @@ /**

*/
static combineAllAsync(firstTX, ...txs) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
let acc = yield firstTX;
for (const tx of txs) {
acc = acc.combine(yield tx);
}
return acc;
});
static async combineAllAsync(firstTX, ...txs) {
let acc = await firstTX;
for (const tx of txs) {
acc = acc.combine(await tx);
}
return acc;
}

@@ -409,11 +403,9 @@ /**

*/
static sendAll(txs, opts) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const firstTX = txs[0];
if (!firstTX) {
return [];
}
const provider = firstTX.provider;
return yield provider.sendAll(txs.map((tx) => ({ tx: tx.build(), signers: tx.signers })), opts);
});
static async sendAll(txs, opts) {
const firstTX = txs[0];
if (!firstTX) {
return [];
}
const provider = firstTX.provider;
return await provider.sendAll(txs.map((tx) => ({ tx: tx.build(), signers: tx.signers })), opts);
}

@@ -420,0 +412,0 @@ /**

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.exists = exports.isNotUndefined = exports.isNotNull = exports.suppressConsoleError = exports.suppressConsoleErrorAsync = void 0;
const tslib_1 = require("tslib");
const noop = () => {

@@ -12,7 +11,7 @@ // noop

*/
const suppressConsoleErrorAsync = (fn) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const suppressConsoleErrorAsync = async (fn) => {
const oldConsoleError = console.error;
console.error = noop;
try {
const result = yield fn();
const result = await fn();
console.error = oldConsoleError;

@@ -25,3 +24,3 @@ return result;

}
});
};
exports.suppressConsoleErrorAsync = suppressConsoleErrorAsync;

@@ -28,0 +27,0 @@ /**

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.printAccountOwners = void 0;
const tslib_1 = require("tslib");
const web3_js_1 = require("@solana/web3.js");

@@ -39,51 +38,49 @@ /**

*/
function printAccountOwners(connection, plainObj) {
async function printAccountOwners(connection, plainObj) {
var _a, _b;
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
if (typeof plainObj !== "object") {
throw new Error("printAccountOwners only works on objects");
}
else {
let relativePath;
const callStack = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n");
if (callStack) {
let expectIndex = callStack.findIndex((l) => l.includes(`at ${printAccountOwners.name}`));
// debugAccountOwners in chai-solana wraps printAccountOwners
// We need to get the caller of debugAccountOwners instead
const debugAccountOwnersIndex = callStack.findIndex((l) => l.includes(`at debugAccountOwners`));
if (debugAccountOwnersIndex > expectIndex) {
expectIndex = debugAccountOwnersIndex;
}
// Only log the line number in Node.js
if (expectIndex > 0 &&
typeof process !== "undefined" &&
typeof window === "undefined") {
const maybeProcess = process;
const targetLine = callStack[expectIndex + 1];
if (targetLine) {
const cwd = ((_b = maybeProcess.cwd) === null || _b === void 0 ? void 0 : _b.call(maybeProcess)) || "/";
// get the part of targetLine after cwd
const targetLineAfterCwd = targetLine.substring(targetLine.indexOf(cwd) + cwd.length);
if (targetLineAfterCwd.length > 0) {
relativePath = targetLineAfterCwd.substring(1).replace(/\)$/, "");
}
try {
if (typeof plainObj !== "object") {
throw new Error("printAccountOwners only works on objects");
}
else {
let relativePath;
const callStack = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n");
if (callStack) {
let expectIndex = callStack.findIndex((l) => l.includes(`at ${printAccountOwners.name}`));
// debugAccountOwners in chai-solana wraps printAccountOwners
// We need to get the caller of debugAccountOwners instead
const debugAccountOwnersIndex = callStack.findIndex((l) => l.includes(`at debugAccountOwners`));
if (debugAccountOwnersIndex > expectIndex) {
expectIndex = debugAccountOwnersIndex;
}
// Only log the line number in Node.js
if (expectIndex > 0 &&
typeof process !== "undefined" &&
typeof window === "undefined") {
const maybeProcess = process;
const targetLine = callStack[expectIndex + 1];
if (targetLine) {
const cwd = ((_b = maybeProcess.cwd) === null || _b === void 0 ? void 0 : _b.call(maybeProcess)) || "/";
// get the part of targetLine after cwd
const targetLineAfterCwd = targetLine.substring(targetLine.indexOf(cwd) + cwd.length);
if (targetLineAfterCwd.length > 0) {
relativePath = targetLineAfterCwd.substring(1).replace(/\)$/, "");
}
}
}
if (!connection) {
return;
}
if (relativePath) {
console.log(relativePath, yield _transformAccountOwners(plainObj, connection));
}
else {
console.log(yield _transformAccountOwners(plainObj, connection));
}
}
if (!connection) {
return;
}
if (relativePath) {
console.log(relativePath, await _transformAccountOwners(plainObj, connection));
}
else {
console.log(await _transformAccountOwners(plainObj, connection));
}
}
catch (e) {
console.error("Error in printAccountOwners:", e);
}
});
}
catch (e) {
console.error("Error in printAccountOwners:", e);
}
}

@@ -100,29 +97,27 @@ exports.printAccountOwners = printAccountOwners;

*/
function gracefulGetMultipleAccountsInfo(connection, publicKeys) {
async function gracefulGetMultipleAccountsInfo(connection, publicKeys) {
var _a;
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
// To be honest, the web3 internals aren't going to change that much. And if
// they do, it'll be rare.
const unknownConection = connection;
const rpcRequest = unknownConection._rpcRequest;
if (typeof rpcRequest !== "function") {
console.error("_rpcRequest is not a function. Maybe web3 changed?");
return [];
}
const unsafeRes = yield rpcRequest("getMultipleAccounts", [
publicKeys.map((key) => key.toBase58()),
{ encoding: "base64", commitment: "confirmed" },
]);
const value = (_a = unsafeRes === null || unsafeRes === void 0 ? void 0 : unsafeRes.result) === null || _a === void 0 ? void 0 : _a.value;
if (value) {
return value;
}
try {
// To be honest, the web3 internals aren't going to change that much. And if
// they do, it'll be rare.
const unknownConection = connection;
const rpcRequest = unknownConection._rpcRequest;
if (typeof rpcRequest !== "function") {
console.error("_rpcRequest is not a function. Maybe web3 changed?");
return [];
}
catch (e) {
console.error("Error in gracefulGetMultipleAccountsInfo:", e);
return [];
const unsafeRes = await rpcRequest("getMultipleAccounts", [
publicKeys.map((key) => key.toBase58()),
{ encoding: "base64", commitment: "confirmed" },
]);
const value = (_a = unsafeRes === null || unsafeRes === void 0 ? void 0 : unsafeRes.result) === null || _a === void 0 ? void 0 : _a.value;
if (value) {
return value;
}
});
return [];
}
catch (e) {
console.error("Error in gracefulGetMultipleAccountsInfo:", e);
return [];
}
}

@@ -134,3 +129,3 @@ /**

*/
const _transformAccountOwners = (plainObjWithAddressesAndBignums, connection) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const _transformAccountOwners = async (plainObjWithAddressesAndBignums, connection) => {
/* eslint-disable */

@@ -169,3 +164,3 @@ const result = {};

if (Object.keys(base58ToResultKey).length > 0) {
const accountInfos = yield gracefulGetMultipleAccountsInfo(connection, base58ToLookup);
const accountInfos = await gracefulGetMultipleAccountsInfo(connection, base58ToLookup);
for (const [base58, resultKey] of Object.entries(base58ToResultKey)) {

@@ -201,3 +196,3 @@ const lookupIndex = base58ToLookup.findIndex((p) => p.toBase58() === base58);

}
const asyncValues = yield Promise.all(asyncPromises);
const asyncValues = await Promise.all(asyncPromises);
for (let i = 0; i < asyncKeys.length; i++) {

@@ -207,3 +202,3 @@ result[asyncKeys[i]] = asyncValues[i];

return result;
});
};
function isPlainObject(obj) {

@@ -210,0 +205,0 @@ /* eslint-disable */

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.simulateTransactionWithCommitment = void 0;
const tslib_1 = require("tslib");
const web3_js_1 = require("@solana/web3.js");

@@ -9,23 +8,21 @@ /**

*/
function simulateTransactionWithCommitment(connection, transaction, commitment = "confirmed") {
async function simulateTransactionWithCommitment(connection, transaction, commitment = "confirmed") {
var _a;
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const connectionInner = connection;
const transactionTyped = transaction;
transaction.recentBlockhash = yield connectionInner._recentBlockhash(connectionInner._disableBlockhashCaching);
const signData = transaction.serializeMessage();
const wireTransaction = transactionTyped._serialize(signData);
const encodedTransaction = wireTransaction.toString("base64");
const config = { encoding: "base64", commitment };
const res = yield connectionInner._rpcRequest("simulateTransaction", [
encodedTransaction,
config,
]);
if (res.error) {
throw new web3_js_1.SendTransactionError("failed to simulate transaction: " + res.error.message, (_a = res.result.value.logs) !== null && _a !== void 0 ? _a : undefined);
}
return res.result;
});
const connectionInner = connection;
const transactionTyped = transaction;
transaction.recentBlockhash = await connectionInner._recentBlockhash(connectionInner._disableBlockhashCaching);
const signData = transaction.serializeMessage();
const wireTransaction = transactionTyped._serialize(signData);
const encodedTransaction = wireTransaction.toString("base64");
const config = { encoding: "base64", commitment };
const res = await connectionInner._rpcRequest("simulateTransaction", [
encodedTransaction,
config,
]);
if (res.error) {
throw new web3_js_1.SendTransactionError("failed to simulate transaction: " + res.error.message, (_a = res.result.value.logs) !== null && _a !== void 0 ? _a : undefined);
}
return res.result;
}
exports.simulateTransactionWithCommitment = simulateTransactionWithCommitment;
//# sourceMappingURL=simulateTransactionWithCommitment.js.map

@@ -1,2 +0,1 @@

import { __awaiter, __rest } from "tslib";
import { firstAggregateError } from "./error";

@@ -18,9 +17,7 @@ import { DEFAULT_PROVIDER_OPTIONS } from "./provider";

*/
getRecentBlockhash(commitment) {
async getRecentBlockhash(commitment) {
var _a;
if (commitment === void 0) { commitment = (_a = this.opts.commitment) !== null && _a !== void 0 ? _a : "confirmed"; }
return __awaiter(this, void 0, void 0, function* () {
const result = yield this.sendConnection.getLatestBlockhash(commitment);
return result.blockhash;
});
const result = await this.sendConnection.getLatestBlockhash(commitment);
return result.blockhash;
}

@@ -30,16 +27,13 @@ /**

*/
broadcast(tx, _a = this.opts) {
var { printLogs = true } = _a, opts = __rest(_a, ["printLogs"]);
return __awaiter(this, void 0, void 0, function* () {
if (tx.signatures.length === 0) {
throw new Error("Transaction must be signed before broadcasting.");
}
const rawTx = tx.serialize();
if (printLogs) {
return new PendingTransaction(this.sendConnection, yield this.sendConnection.sendRawTransaction(rawTx, opts));
}
return yield suppressConsoleErrorAsync(() => __awaiter(this, void 0, void 0, function* () {
// hide the logs of TX errors if printLogs = false
return new PendingTransaction(this.sendConnection, yield this.sendConnection.sendRawTransaction(rawTx, opts));
}));
async broadcast(tx, { printLogs = true, ...opts } = this.opts) {
if (tx.signatures.length === 0) {
throw new Error("Transaction must be signed before broadcasting.");
}
const rawTx = tx.serialize();
if (printLogs) {
return new PendingTransaction(this.sendConnection, await this.sendConnection.sendRawTransaction(rawTx, opts));
}
return await suppressConsoleErrorAsync(async () => {
// hide the logs of TX errors if printLogs = false
return new PendingTransaction(this.sendConnection, await this.sendConnection.sendRawTransaction(rawTx, opts));
});

@@ -50,3 +44,3 @@ }

*/
simulate(tx, _a) {
async simulate(tx, _a) {
var _b, _c;

@@ -57,8 +51,6 @@ var { commitment = (_b = this.opts.preflightCommitment) !== null && _b !== void 0 ? _b : "confirmed", verifySigners = true, } = _a === void 0 ? {

} : _a;
return __awaiter(this, void 0, void 0, function* () {
if (verifySigners && tx.signatures.length === 0) {
throw new Error("Transaction must be signed before simulating.");
}
return yield simulateTransactionWithCommitment(this.sendConnection, tx, commitment);
});
if (verifySigners && tx.signatures.length === 0) {
throw new Error("Transaction must be signed before simulating.");
}
return await simulateTransactionWithCommitment(this.sendConnection, tx, commitment);
}

@@ -74,36 +66,32 @@ }

}
getRecentBlockhash(commitment) {
async getRecentBlockhash(commitment) {
var _a;
if (commitment === void 0) { commitment = (_a = this.opts.preflightCommitment) !== null && _a !== void 0 ? _a : "confirmed"; }
return __awaiter(this, void 0, void 0, function* () {
try {
const result = yield Promise.any(this.connections.map((conn) => conn.getLatestBlockhash(commitment)));
return result.blockhash;
try {
const result = await Promise.any(this.connections.map((conn) => conn.getLatestBlockhash(commitment)));
return result.blockhash;
}
catch (e) {
if (e instanceof AggregateError) {
throw firstAggregateError(e);
}
catch (e) {
if (e instanceof AggregateError) {
throw firstAggregateError(e);
}
else {
throw e;
}
else {
throw e;
}
});
}
}
_sendRawTransaction(encoded, options) {
return __awaiter(this, void 0, void 0, function* () {
try {
return yield Promise.any(this.connections.map((connection) => __awaiter(this, void 0, void 0, function* () {
return new PendingTransaction(connection, yield connection.sendRawTransaction(encoded, options));
})));
async _sendRawTransaction(encoded, options) {
try {
return await Promise.any(this.connections.map(async (connection) => {
return new PendingTransaction(connection, await connection.sendRawTransaction(encoded, options));
}));
}
catch (e) {
if (e instanceof AggregateError) {
throw firstAggregateError(e);
}
catch (e) {
if (e instanceof AggregateError) {
throw firstAggregateError(e);
}
else {
throw e;
}
else {
throw e;
}
});
}
}

@@ -118,16 +106,13 @@ /**

*/
broadcast(tx, _a = this.opts) {
var { printLogs = true } = _a, opts = __rest(_a, ["printLogs"]);
return __awaiter(this, void 0, void 0, function* () {
if (tx.signatures.length === 0) {
throw new Error("Transaction must be signed before broadcasting.");
}
const rawTx = tx.serialize();
if (printLogs) {
return yield this._sendRawTransaction(rawTx, opts);
}
return yield suppressConsoleErrorAsync(() => __awaiter(this, void 0, void 0, function* () {
// hide the logs of TX errors if printLogs = false
return yield this._sendRawTransaction(rawTx, opts);
}));
async broadcast(tx, { printLogs = true, ...opts } = this.opts) {
if (tx.signatures.length === 0) {
throw new Error("Transaction must be signed before broadcasting.");
}
const rawTx = tx.serialize();
if (printLogs) {
return await this._sendRawTransaction(rawTx, opts);
}
return await suppressConsoleErrorAsync(async () => {
// hide the logs of TX errors if printLogs = false
return await this._sendRawTransaction(rawTx, opts);
});

@@ -141,3 +126,3 @@ }

*/
simulate(tx, _a) {
async simulate(tx, _a) {
var _b, _c;

@@ -148,22 +133,20 @@ var { commitment = (_b = this.opts.preflightCommitment) !== null && _b !== void 0 ? _b : "confirmed", verifySigners = true, } = _a === void 0 ? {

} : _a;
return __awaiter(this, void 0, void 0, function* () {
if (verifySigners && tx.signatures.length === 0) {
throw new Error("Transaction must be signed before simulating.");
if (verifySigners && tx.signatures.length === 0) {
throw new Error("Transaction must be signed before simulating.");
}
try {
return await Promise.any(this.connections.map(async (connection) => {
return await simulateTransactionWithCommitment(connection, tx, commitment);
}));
}
catch (e) {
if (e instanceof AggregateError) {
throw firstAggregateError(e);
}
try {
return yield Promise.any(this.connections.map((connection) => __awaiter(this, void 0, void 0, function* () {
return yield simulateTransactionWithCommitment(connection, tx, commitment);
})));
else {
throw e;
}
catch (e) {
if (e instanceof AggregateError) {
throw firstAggregateError(e);
}
else {
throw e;
}
}
});
}
}
}
//# sourceMappingURL=broadcaster.js.map

@@ -1,2 +0,1 @@

import { __awaiter } from "tslib";
import { SystemProgram } from "@solana/web3.js";

@@ -29,3 +28,6 @@ import { MultipleConnectionBroadcaster, PendingTransaction, SignerWallet, } from ".";

};
this.wallet = Object.assign(Object.assign({}, this.wallet), { publicKey });
this.wallet = {
...this.wallet,
publicKey,
};
}

@@ -37,13 +39,11 @@ /**

*/
getAccountInfo(accountId) {
return __awaiter(this, void 0, void 0, function* () {
const accountInfo = yield this.connection.getAccountInfo(accountId, this.opts.commitment);
if (!accountInfo) {
return null;
}
return {
accountId,
accountInfo,
};
});
async getAccountInfo(accountId) {
const accountInfo = await this.connection.getAccountInfo(accountId, this.opts.commitment);
if (!accountInfo) {
return null;
}
return {
accountId,
accountInfo,
};
}

@@ -71,16 +71,14 @@ }

*/
sign(tx, signers = [], opts = {
async sign(tx, signers = [], opts = {
preflightCommitment: this.preflightCommitment,
}) {
return __awaiter(this, void 0, void 0, function* () {
tx.feePayer = this.wallet.publicKey;
tx.recentBlockhash = yield this.broadcaster.getRecentBlockhash(opts.preflightCommitment);
yield this.wallet.signTransaction(tx);
signers
.filter((s) => s !== undefined)
.forEach((kp) => {
tx.partialSign(kp);
});
return tx;
tx.feePayer = this.wallet.publicKey;
tx.recentBlockhash = await this.broadcaster.getRecentBlockhash(opts.preflightCommitment);
await this.wallet.signTransaction(tx);
signers
.filter((s) => s !== undefined)
.forEach((kp) => {
tx.partialSign(kp);
});
return tx;
}

@@ -90,25 +88,23 @@ /**

*/
signAll(reqs, opts = {
async signAll(reqs, opts = {
preflightCommitment: this.preflightCommitment,
}) {
return __awaiter(this, void 0, void 0, function* () {
const blockhash = yield this.broadcaster.getRecentBlockhash(opts.preflightCommitment);
const txs = reqs.map((r) => {
const tx = r.tx;
let signers = r.signers;
if (signers === undefined) {
signers = [];
}
tx.feePayer = this.wallet.publicKey;
tx.recentBlockhash = blockhash;
signers
.filter((s) => s !== undefined)
.forEach((kp) => {
tx.partialSign(kp);
});
return tx;
const blockhash = await this.broadcaster.getRecentBlockhash(opts.preflightCommitment);
const txs = reqs.map((r) => {
const tx = r.tx;
let signers = r.signers;
if (signers === undefined) {
signers = [];
}
tx.feePayer = this.wallet.publicKey;
tx.recentBlockhash = blockhash;
signers
.filter((s) => s !== undefined)
.forEach((kp) => {
tx.partialSign(kp);
});
const signedTxs = yield this.wallet.signAllTransactions(txs);
return signedTxs;
return tx;
});
const signedTxs = await this.wallet.signAllTransactions(txs);
return signedTxs;
}

@@ -158,9 +154,7 @@ }

*/
send(tx, signers = [], opts = this.opts) {
return __awaiter(this, void 0, void 0, function* () {
const theTx = yield this.signer.sign(tx, signers, opts);
const pending = yield this.broadcaster.broadcast(theTx, opts);
yield pending.wait();
return pending;
});
async send(tx, signers = [], opts = this.opts) {
const theTx = await this.signer.sign(tx, signers, opts);
const pending = await this.broadcaster.broadcast(theTx, opts);
await pending.wait();
return pending;
}

@@ -170,11 +164,9 @@ /**

*/
sendAll(reqs, opts = this.opts) {
return __awaiter(this, void 0, void 0, function* () {
const txs = yield this.signer.signAll(reqs, opts);
return yield Promise.all(txs.map((tx) => __awaiter(this, void 0, void 0, function* () {
const pending = yield this.broadcaster.broadcast(tx, opts);
yield pending.wait();
return pending;
})));
});
async sendAll(reqs, opts = this.opts) {
const txs = await this.signer.signAll(reqs, opts);
return await Promise.all(txs.map(async (tx) => {
const pending = await this.broadcaster.broadcast(tx, opts);
await pending.wait();
return pending;
}));
}

@@ -190,12 +182,10 @@ /**

*/
simulate(tx, signers, opts = this.opts) {
return __awaiter(this, void 0, void 0, function* () {
let simTX = tx;
if (signers !== undefined) {
simTX = yield this.signer.sign(tx, signers, opts);
}
return yield this.broadcaster.simulate(simTX, {
verifySigners: signers !== undefined,
commitment: opts.commitment,
});
async simulate(tx, signers, opts = this.opts) {
let simTX = tx;
if (signers !== undefined) {
simTX = await this.signer.sign(tx, signers, opts);
}
return await this.broadcaster.simulate(simTX, {
verifySigners: signers !== undefined,
commitment: opts.commitment,
});

@@ -255,6 +245,4 @@ }

*/
requestAirdrop(lamports, to = this.wallet.publicKey) {
return __awaiter(this, void 0, void 0, function* () {
return new PendingTransaction(this.connection, yield this.connection.requestAirdrop(to, lamports));
});
async requestAirdrop(lamports, to = this.wallet.publicKey) {
return new PendingTransaction(this.connection, await this.connection.requestAirdrop(to, lamports));
}

@@ -261,0 +249,0 @@ /**

@@ -1,2 +0,1 @@

import { __awaiter, __rest } from "tslib";
import promiseRetry from "promise-retry";

@@ -25,14 +24,11 @@ import { TransactionReceipt } from "../transaction";

*/
wait(_a = {}) {
var { commitment = "confirmed", useWebsocket = false } = _a, retryOpts = __rest(_a, ["commitment", "useWebsocket"]);
return __awaiter(this, void 0, void 0, function* () {
if (this._receipt) {
return this._receipt;
}
if (useWebsocket) {
yield this.awaitSignatureConfirmation(commitment);
return yield this.pollForReceipt({ commitment });
}
return yield this.pollForReceipt(Object.assign({ commitment }, retryOpts));
});
async wait({ commitment = "confirmed", useWebsocket = false, ...retryOpts } = {}) {
if (this._receipt) {
return this._receipt;
}
if (useWebsocket) {
await this.awaitSignatureConfirmation(commitment);
return await this.pollForReceipt({ commitment });
}
return await this.pollForReceipt({ commitment, ...retryOpts });
}

@@ -43,21 +39,22 @@ /**

*/
pollForReceipt(_a = {}) {
var { commitment = "confirmed" } = _a, retryOpts = __rest(_a, ["commitment"]);
return __awaiter(this, void 0, void 0, function* () {
const receipt = yield promiseRetry((retry) => __awaiter(this, void 0, void 0, function* () {
const result = yield this.connection.getTransaction(this.signature, {
commitment,
});
if (!result) {
retry(new Error("Error fetching transaction"));
return;
}
return new TransactionReceipt(this.signature, result);
}), Object.assign({ retries: 5, minTimeout: 500 }, retryOpts));
if (!receipt) {
throw new Error("transaction could not be confirmed");
async pollForReceipt({ commitment = "confirmed", ...retryOpts } = {}) {
const receipt = await promiseRetry(async (retry) => {
const result = await this.connection.getTransaction(this.signature, {
commitment,
});
if (!result) {
retry(new Error("Error fetching transaction"));
return;
}
this._receipt = receipt;
return receipt;
return new TransactionReceipt(this.signature, result);
}, {
retries: 5,
minTimeout: 500,
...retryOpts,
});
if (!receipt) {
throw new Error("transaction could not be confirmed");
}
this._receipt = receipt;
return receipt;
}

@@ -68,10 +65,8 @@ /**

*/
awaitSignatureConfirmation(commitment = "confirmed") {
return __awaiter(this, void 0, void 0, function* () {
const { value } = yield this.connection.confirmTransaction(this.signature, commitment);
if (value.err) {
throw value.err;
}
return this.signature;
});
async awaitSignatureConfirmation(commitment = "confirmed") {
const { value } = await this.connection.confirmTransaction(this.signature, commitment);
if (value.err) {
throw value.err;
}
return this.signature;
}

@@ -78,0 +73,0 @@ /**

@@ -1,2 +0,1 @@

import { __awaiter } from "tslib";
import { PACKET_DATA_SIZE, PublicKey, Transaction } from "@solana/web3.js";

@@ -214,3 +213,3 @@ import invariant from "tiny-invariant";

simulateUnchecked(opts) {
return this.simulate(Object.assign(Object.assign({}, opts), { verifySigners: false }));
return this.simulate({ ...opts, verifySigners: false });
}

@@ -255,7 +254,5 @@ /**

*/
send(opts) {
return __awaiter(this, void 0, void 0, function* () {
const signed = yield this.provider.signer.sign(this.build(), this.signers, opts);
return this.provider.broadcaster.broadcast(signed, opts);
});
async send(opts) {
const signed = await this.provider.signer.sign(this.build(), this.signers, opts);
return this.provider.broadcaster.broadcast(signed, opts);
}

@@ -266,6 +263,4 @@ /**

*/
confirm(opts) {
return __awaiter(this, void 0, void 0, function* () {
return (yield this.send(opts)).wait();
});
async confirm(opts) {
return (await this.send(opts)).wait();
}

@@ -392,10 +387,8 @@ /**

*/
static combineAllAsync(firstTX, ...txs) {
return __awaiter(this, void 0, void 0, function* () {
let acc = yield firstTX;
for (const tx of txs) {
acc = acc.combine(yield tx);
}
return acc;
});
static async combineAllAsync(firstTX, ...txs) {
let acc = await firstTX;
for (const tx of txs) {
acc = acc.combine(await tx);
}
return acc;
}

@@ -406,11 +399,9 @@ /**

*/
static sendAll(txs, opts) {
return __awaiter(this, void 0, void 0, function* () {
const firstTX = txs[0];
if (!firstTX) {
return [];
}
const provider = firstTX.provider;
return yield provider.sendAll(txs.map((tx) => ({ tx: tx.build(), signers: tx.signers })), opts);
});
static async sendAll(txs, opts) {
const firstTX = txs[0];
if (!firstTX) {
return [];
}
const provider = firstTX.provider;
return await provider.sendAll(txs.map((tx) => ({ tx: tx.build(), signers: tx.signers })), opts);
}

@@ -417,0 +408,0 @@ /**

@@ -1,2 +0,1 @@

import { __awaiter } from "tslib";
const noop = () => {

@@ -9,7 +8,7 @@ // noop

*/
export const suppressConsoleErrorAsync = (fn) => __awaiter(void 0, void 0, void 0, function* () {
export const suppressConsoleErrorAsync = async (fn) => {
const oldConsoleError = console.error;
console.error = noop;
try {
const result = yield fn();
const result = await fn();
console.error = oldConsoleError;

@@ -22,3 +21,3 @@ return result;

}
});
};
/**

@@ -25,0 +24,0 @@ * Hide the console.error because @solana/web3.js often emits noisy errors as a

@@ -1,2 +0,1 @@

import { __awaiter } from "tslib";
import { PublicKey } from "@solana/web3.js";

@@ -36,51 +35,49 @@ /**

*/
export function printAccountOwners(connection, plainObj) {
export async function printAccountOwners(connection, plainObj) {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
try {
if (typeof plainObj !== "object") {
throw new Error("printAccountOwners only works on objects");
}
else {
let relativePath;
const callStack = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n");
if (callStack) {
let expectIndex = callStack.findIndex((l) => l.includes(`at ${printAccountOwners.name}`));
// debugAccountOwners in chai-solana wraps printAccountOwners
// We need to get the caller of debugAccountOwners instead
const debugAccountOwnersIndex = callStack.findIndex((l) => l.includes(`at debugAccountOwners`));
if (debugAccountOwnersIndex > expectIndex) {
expectIndex = debugAccountOwnersIndex;
}
// Only log the line number in Node.js
if (expectIndex > 0 &&
typeof process !== "undefined" &&
typeof window === "undefined") {
const maybeProcess = process;
const targetLine = callStack[expectIndex + 1];
if (targetLine) {
const cwd = ((_b = maybeProcess.cwd) === null || _b === void 0 ? void 0 : _b.call(maybeProcess)) || "/";
// get the part of targetLine after cwd
const targetLineAfterCwd = targetLine.substring(targetLine.indexOf(cwd) + cwd.length);
if (targetLineAfterCwd.length > 0) {
relativePath = targetLineAfterCwd.substring(1).replace(/\)$/, "");
}
try {
if (typeof plainObj !== "object") {
throw new Error("printAccountOwners only works on objects");
}
else {
let relativePath;
const callStack = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n");
if (callStack) {
let expectIndex = callStack.findIndex((l) => l.includes(`at ${printAccountOwners.name}`));
// debugAccountOwners in chai-solana wraps printAccountOwners
// We need to get the caller of debugAccountOwners instead
const debugAccountOwnersIndex = callStack.findIndex((l) => l.includes(`at debugAccountOwners`));
if (debugAccountOwnersIndex > expectIndex) {
expectIndex = debugAccountOwnersIndex;
}
// Only log the line number in Node.js
if (expectIndex > 0 &&
typeof process !== "undefined" &&
typeof window === "undefined") {
const maybeProcess = process;
const targetLine = callStack[expectIndex + 1];
if (targetLine) {
const cwd = ((_b = maybeProcess.cwd) === null || _b === void 0 ? void 0 : _b.call(maybeProcess)) || "/";
// get the part of targetLine after cwd
const targetLineAfterCwd = targetLine.substring(targetLine.indexOf(cwd) + cwd.length);
if (targetLineAfterCwd.length > 0) {
relativePath = targetLineAfterCwd.substring(1).replace(/\)$/, "");
}
}
}
if (!connection) {
return;
}
if (relativePath) {
console.log(relativePath, yield _transformAccountOwners(plainObj, connection));
}
else {
console.log(yield _transformAccountOwners(plainObj, connection));
}
}
if (!connection) {
return;
}
if (relativePath) {
console.log(relativePath, await _transformAccountOwners(plainObj, connection));
}
else {
console.log(await _transformAccountOwners(plainObj, connection));
}
}
catch (e) {
console.error("Error in printAccountOwners:", e);
}
});
}
catch (e) {
console.error("Error in printAccountOwners:", e);
}
}

@@ -96,29 +93,27 @@ /**

*/
function gracefulGetMultipleAccountsInfo(connection, publicKeys) {
async function gracefulGetMultipleAccountsInfo(connection, publicKeys) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
try {
// To be honest, the web3 internals aren't going to change that much. And if
// they do, it'll be rare.
const unknownConection = connection;
const rpcRequest = unknownConection._rpcRequest;
if (typeof rpcRequest !== "function") {
console.error("_rpcRequest is not a function. Maybe web3 changed?");
return [];
}
const unsafeRes = yield rpcRequest("getMultipleAccounts", [
publicKeys.map((key) => key.toBase58()),
{ encoding: "base64", commitment: "confirmed" },
]);
const value = (_a = unsafeRes === null || unsafeRes === void 0 ? void 0 : unsafeRes.result) === null || _a === void 0 ? void 0 : _a.value;
if (value) {
return value;
}
try {
// To be honest, the web3 internals aren't going to change that much. And if
// they do, it'll be rare.
const unknownConection = connection;
const rpcRequest = unknownConection._rpcRequest;
if (typeof rpcRequest !== "function") {
console.error("_rpcRequest is not a function. Maybe web3 changed?");
return [];
}
catch (e) {
console.error("Error in gracefulGetMultipleAccountsInfo:", e);
return [];
const unsafeRes = await rpcRequest("getMultipleAccounts", [
publicKeys.map((key) => key.toBase58()),
{ encoding: "base64", commitment: "confirmed" },
]);
const value = (_a = unsafeRes === null || unsafeRes === void 0 ? void 0 : unsafeRes.result) === null || _a === void 0 ? void 0 : _a.value;
if (value) {
return value;
}
});
return [];
}
catch (e) {
console.error("Error in gracefulGetMultipleAccountsInfo:", e);
return [];
}
}

@@ -130,3 +125,3 @@ /**

*/
const _transformAccountOwners = (plainObjWithAddressesAndBignums, connection) => __awaiter(void 0, void 0, void 0, function* () {
const _transformAccountOwners = async (plainObjWithAddressesAndBignums, connection) => {
/* eslint-disable */

@@ -165,3 +160,3 @@ const result = {};

if (Object.keys(base58ToResultKey).length > 0) {
const accountInfos = yield gracefulGetMultipleAccountsInfo(connection, base58ToLookup);
const accountInfos = await gracefulGetMultipleAccountsInfo(connection, base58ToLookup);
for (const [base58, resultKey] of Object.entries(base58ToResultKey)) {

@@ -197,3 +192,3 @@ const lookupIndex = base58ToLookup.findIndex((p) => p.toBase58() === base58);

}
const asyncValues = yield Promise.all(asyncPromises);
const asyncValues = await Promise.all(asyncPromises);
for (let i = 0; i < asyncKeys.length; i++) {

@@ -203,3 +198,3 @@ result[asyncKeys[i]] = asyncValues[i];

return result;
});
};
function isPlainObject(obj) {

@@ -206,0 +201,0 @@ /* eslint-disable */

@@ -1,2 +0,1 @@

import { __awaiter } from "tslib";
import { SendTransactionError } from "@solana/web3.js";

@@ -6,22 +5,20 @@ /**

*/
export function simulateTransactionWithCommitment(connection, transaction, commitment = "confirmed") {
export async function simulateTransactionWithCommitment(connection, transaction, commitment = "confirmed") {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const connectionInner = connection;
const transactionTyped = transaction;
transaction.recentBlockhash = yield connectionInner._recentBlockhash(connectionInner._disableBlockhashCaching);
const signData = transaction.serializeMessage();
const wireTransaction = transactionTyped._serialize(signData);
const encodedTransaction = wireTransaction.toString("base64");
const config = { encoding: "base64", commitment };
const res = yield connectionInner._rpcRequest("simulateTransaction", [
encodedTransaction,
config,
]);
if (res.error) {
throw new SendTransactionError("failed to simulate transaction: " + res.error.message, (_a = res.result.value.logs) !== null && _a !== void 0 ? _a : undefined);
}
return res.result;
});
const connectionInner = connection;
const transactionTyped = transaction;
transaction.recentBlockhash = await connectionInner._recentBlockhash(connectionInner._disableBlockhashCaching);
const signData = transaction.serializeMessage();
const wireTransaction = transactionTyped._serialize(signData);
const encodedTransaction = wireTransaction.toString("base64");
const config = { encoding: "base64", commitment };
const res = await connectionInner._rpcRequest("simulateTransaction", [
encodedTransaction,
config,
]);
if (res.error) {
throw new SendTransactionError("failed to simulate transaction: " + res.error.message, (_a = res.result.value.logs) !== null && _a !== void 0 ? _a : undefined);
}
return res.result;
}
//# sourceMappingURL=simulateTransactionWithCommitment.js.map
{
"name": "@saberhq/solana-contrib",
"version": "1.12.62",
"version": "1.12.63",
"description": "Common types and libraries for Solana",

@@ -46,3 +46,3 @@ "author": "Ian Macalinao <ian@saber.so>",

},
"gitHead": "02ba28d061f06bdb3ff4672cced985c9f853e9ba",
"gitHead": "458b20ec0afb87644f172538e2ce5a0c728c3a4f",
"publishConfig": {

@@ -49,0 +49,0 @@ "access": "public"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc