@wormhole-foundation/connect-sdk-solana
Advanced tools
Comparing version 0.3.0-beta.10 to 0.3.0-beta.11
import { Balances, Chain, ChainsConfig, Network, PlatformContext, SignedTx, TokenId, TxHash } from '@wormhole-foundation/connect-sdk'; | ||
import { SolanaChain } from './chain'; | ||
import { Commitment, Connection, SendOptions } from '@solana/web3.js'; | ||
import { Commitment, Connection, ConnectionConfig, SendOptions } from '@solana/web3.js'; | ||
import { AnySolanaAddress, SolanaChains, SolanaPlatformType } from './types'; | ||
@@ -11,3 +11,3 @@ /** | ||
constructor(network: N, config?: ChainsConfig<N, SolanaPlatformType>); | ||
getRpc<C extends SolanaChains>(chain: C, commitment?: Commitment): Connection; | ||
getRpc<C extends SolanaChains>(chain: C, config?: ConnectionConfig): Connection; | ||
getChain<C extends SolanaChains>(chain: C, rpc?: Connection): SolanaChain<N, C>; | ||
@@ -14,0 +14,0 @@ static nativeTokenId<N extends Network, C extends SolanaChains>(network: N, chain: C): TokenId<C>; |
@@ -18,5 +18,8 @@ "use strict"; | ||
} | ||
getRpc(chain, commitment = 'confirmed') { | ||
getRpc(chain, config = { | ||
commitment: 'confirmed', | ||
disableRetryOnRateLimit: true, | ||
}) { | ||
if (chain in this.config) | ||
return new web3_js_1.Connection(this.config[chain].rpc, commitment); | ||
return new web3_js_1.Connection(this.config[chain].rpc, config); | ||
throw new Error('No configuration available for chain: ' + chain); | ||
@@ -87,10 +90,7 @@ } | ||
const { blockhash, lastValidBlockHeight } = await this.latestBlock(rpc); | ||
const txhashes = await Promise.all(stxns.map((stxn) => rpc.sendRawTransaction(stxn, | ||
// Set the commitment level to match the rpc commitment level | ||
// otherwise, it defaults to finalized | ||
if (!opts) | ||
opts = { preflightCommitment: rpc.commitment }; | ||
const txhashes = await Promise.all(stxns.map((stxn) => { | ||
return rpc.sendRawTransaction(stxn, opts); | ||
})); | ||
await Promise.all(txhashes.map((signature) => { | ||
opts ?? { preflightCommitment: rpc.commitment }))); | ||
const results = await Promise.all(txhashes.map((signature) => { | ||
return rpc.confirmTransaction({ | ||
@@ -102,6 +102,11 @@ signature, | ||
})); | ||
const erroredTxs = results | ||
.filter((result) => result.value.err) | ||
.map((result) => result.value.err); | ||
if (erroredTxs.length > 0) | ||
throw new Error(`Failed to confirm transaction: ${erroredTxs}`); | ||
return txhashes; | ||
} | ||
static async latestBlock(rpc, commitment) { | ||
return rpc.getLatestBlockhash(commitment ?? 'finalized'); | ||
return rpc.getLatestBlockhash(commitment ?? rpc.commitment); | ||
} | ||
@@ -108,0 +113,0 @@ static async getLatestBlock(rpc) { |
@@ -26,3 +26,3 @@ "use strict"; | ||
const [_, chain] = await platform_1.SolanaPlatform.chainFromRpc(rpc); | ||
return new signer_1.SolanaSigner(chain, web3_js_1.Keypair.fromSecretKey(connect_sdk_1.encoding.b58.decode(privateKey))); | ||
return new signer_1.SolanaSigner(chain, web3_js_1.Keypair.fromSecretKey(connect_sdk_1.encoding.b58.decode(privateKey)), rpc); | ||
} | ||
@@ -29,0 +29,0 @@ exports.getSolanaSigner = getSolanaSigner; |
@@ -1,2 +0,2 @@ | ||
import { Connection, Keypair } from '@solana/web3.js'; | ||
import { Connection, Keypair, SendOptions } from '@solana/web3.js'; | ||
import { SignAndSendSigner, UnsignedTransaction } from '@wormhole-foundation/connect-sdk'; | ||
@@ -10,7 +10,10 @@ import { Network } from '@wormhole-foundation/sdk-base/src'; | ||
private _debug; | ||
constructor(_rpc: Connection, _chain: C, _keypair: Keypair, _debug?: boolean); | ||
private _sendOpts?; | ||
private _priotifyFeeAmount?; | ||
constructor(_rpc: Connection, _chain: C, _keypair: Keypair, _debug?: boolean, _sendOpts?: SendOptions, _priotifyFeeAmount?: bigint); | ||
chain(): C; | ||
address(): string; | ||
private retryable; | ||
signAndSend(tx: UnsignedTransaction[]): Promise<any[]>; | ||
} | ||
//# sourceMappingURL=sendSigner.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SolanaSendSigner = void 0; | ||
const web3_js_1 = require("@solana/web3.js"); | ||
const platform_1 = require("../platform"); | ||
const debug_1 = require("./debug"); | ||
// Number of blocks to wait before considering a transaction expired | ||
const SOLANA_EXPIRED_BLOCKHEIGHT = 150; | ||
class SolanaSendSigner { | ||
@@ -10,3 +14,5 @@ _rpc; | ||
_debug; | ||
constructor(_rpc, _chain, _keypair, _debug = false) { | ||
_sendOpts; | ||
_priotifyFeeAmount; | ||
constructor(_rpc, _chain, _keypair, _debug = false, _sendOpts, _priotifyFeeAmount) { | ||
this._rpc = _rpc; | ||
@@ -16,2 +22,7 @@ this._chain = _chain; | ||
this._debug = _debug; | ||
this._sendOpts = _sendOpts; | ||
this._priotifyFeeAmount = _priotifyFeeAmount; | ||
this._sendOpts = this._sendOpts ?? { | ||
preflightCommitment: this._rpc.commitment, | ||
}; | ||
} | ||
@@ -24,31 +35,84 @@ chain() { | ||
} | ||
// Handles retrying a Transaction if the error is deemed to be | ||
// recoverable. Currently handles: | ||
// - Transaction expired | ||
// - Blockhash not found | ||
// - Not enough bytes (storage account not seen yet) | ||
retryable(e) { | ||
// Tx expired, set a new block hash and retry | ||
if (e instanceof web3_js_1.TransactionExpiredBlockheightExceededError) | ||
return true; | ||
// Besides tx expiry, only handle SendTransactionError | ||
if (!(e instanceof web3_js_1.SendTransactionError)) | ||
return false; | ||
// Only handle simulation errors | ||
if (!e.message.includes('Transaction simulation failed')) | ||
return false; | ||
// Blockhash not found, similar to expired, resend with new blockhash | ||
if (e.message.includes('Blockhash not found')) | ||
return true; | ||
// Find the log message with the error details | ||
const loggedErr = e.logs.find((log) => log.startsWith('Program log: Error: ')); | ||
// who knows | ||
if (!loggedErr) | ||
return false; | ||
// Probably caused by storage account not seen yet | ||
if (loggedErr.includes('Not enough bytes')) | ||
return true; | ||
if (loggedErr.includes('Unexpected length of input')) | ||
return true; | ||
return false; | ||
} | ||
async signAndSend(tx) { | ||
const { blockhash, lastValidBlockHeight } = await platform_1.SolanaPlatform.latestBlock(this._rpc, 'finalized'); | ||
const txPromises = []; | ||
let { blockhash, lastValidBlockHeight } = await platform_1.SolanaPlatform.latestBlock(this._rpc); | ||
const txids = []; | ||
for (const txn of tx) { | ||
const { description, transaction } = txn; | ||
const { description, transaction: { transaction, signers: extraSigners }, } = txn; | ||
console.log(`Signing: ${description} for ${this.address()}`); | ||
if (this._debug) { | ||
console.log(transaction.signatures); | ||
console.log(transaction.feePayer); | ||
transaction.instructions.forEach((ix) => { | ||
console.log('Program', ix.programId.toBase58()); | ||
console.log('Data: ', ix.data.toString('hex')); | ||
console.log('Keys: ', ix.keys.map((k) => [k, k.pubkey.toBase58()])); | ||
}); | ||
if (this._priotifyFeeAmount) | ||
transaction.add(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ | ||
microLamports: this._priotifyFeeAmount, | ||
})); | ||
if (this._debug) | ||
(0, debug_1.logTxDetails)(transaction); | ||
// Try to send the transaction up to 5 times | ||
const maxRetries = 5; | ||
for (let i = 0; i < maxRetries; i++) { | ||
try { | ||
transaction.recentBlockhash = blockhash; | ||
transaction.partialSign(this._keypair, ...(extraSigners ?? [])); | ||
const txid = await this._rpc.sendRawTransaction(transaction.serialize(), this._sendOpts); | ||
txids.push(txid); | ||
break; | ||
} | ||
catch (e) { | ||
// No point checking if retryable if we're on the last retry | ||
if (i === maxRetries - 1) | ||
throw e; | ||
// If it's not retryable, throw | ||
if (!this.retryable(e)) | ||
throw e; | ||
// If it is retryable, we need to grab a new block hash | ||
const { blockhash: newBlockhash, lastValidBlockHeight: newBlockHeight, } = await platform_1.SolanaPlatform.latestBlock(this._rpc); | ||
// But we should _not_ submit if the blockhash hasnt expired | ||
if (newBlockHeight - lastValidBlockHeight < | ||
SOLANA_EXPIRED_BLOCKHEIGHT) { | ||
throw e; | ||
} | ||
lastValidBlockHeight = newBlockHeight; | ||
blockhash = newBlockhash; | ||
} | ||
} | ||
transaction.partialSign(this._keypair); | ||
txPromises.push(this._rpc.sendRawTransaction(transaction.serialize(), { | ||
preflightCommitment: this._rpc.commitment, | ||
})); | ||
} | ||
const txids = await Promise.all(txPromises); | ||
// Wait for finalization | ||
for (const signature of txids) { | ||
await this._rpc.confirmTransaction({ | ||
signature, | ||
blockhash, | ||
lastValidBlockHeight, | ||
}); | ||
} | ||
const results = await Promise.all(txids.map((signature) => this._rpc.confirmTransaction({ | ||
signature, | ||
blockhash, | ||
lastValidBlockHeight, | ||
}, this._rpc.commitment))); | ||
const erroredTxs = results | ||
.filter((result) => result.value.err) | ||
.map((result) => result.value.err); | ||
if (erroredTxs.length > 0) | ||
throw new Error(`Failed to confirm transaction: ${erroredTxs}`); | ||
return txids; | ||
@@ -55,0 +119,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { Keypair } from '@solana/web3.js'; | ||
import { Connection, Keypair } from '@solana/web3.js'; | ||
import { SignOnlySigner, UnsignedTransaction } from '@wormhole-foundation/connect-sdk'; | ||
@@ -8,4 +8,5 @@ import { Network } from '@wormhole-foundation/sdk-base/src'; | ||
private _keypair; | ||
private _rpc; | ||
private _debug; | ||
constructor(_chain: C, _keypair: Keypair, _debug?: boolean); | ||
constructor(_chain: C, _keypair: Keypair, _rpc: Connection, _debug?: boolean); | ||
chain(): C; | ||
@@ -12,0 +13,0 @@ address(): string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SolanaSigner = void 0; | ||
const platform_1 = require("../platform"); | ||
const debug_1 = require("./debug"); | ||
class SolanaSigner { | ||
_chain; | ||
_keypair; | ||
_rpc; | ||
_debug; | ||
constructor(_chain, _keypair, _debug = false) { | ||
constructor(_chain, _keypair, _rpc, _debug = false) { | ||
this._chain = _chain; | ||
this._keypair = _keypair; | ||
this._rpc = _rpc; | ||
this._debug = _debug; | ||
@@ -20,19 +24,11 @@ } | ||
async sign(tx) { | ||
const { blockhash } = await platform_1.SolanaPlatform.latestBlock(this._rpc); | ||
const signed = []; | ||
for (const txn of tx) { | ||
const { description, transaction } = txn; | ||
const { description, transaction: { transaction, signers: extraSigners }, } = txn; | ||
console.log(`Signing: ${description} for ${this.address()}`); | ||
if (this._debug) { | ||
const st = transaction; | ||
console.log(st.signatures); | ||
console.log(st.feePayer); | ||
st.instructions.forEach((ix) => { | ||
console.log('Program', ix.programId.toBase58()); | ||
console.log('Data: ', ix.data.toString('hex')); | ||
ix.keys.forEach((k) => { | ||
console.log(k, k.pubkey.toBase58()); | ||
}); | ||
}); | ||
} | ||
transaction.partialSign(this._keypair); | ||
if (this._debug) | ||
(0, debug_1.logTxDetails)(transaction); | ||
transaction.recentBlockhash = blockhash; | ||
transaction.partialSign(this._keypair, ...(extraSigners ?? [])); | ||
signed.push(transaction.serialize()); | ||
@@ -39,0 +35,0 @@ } |
@@ -1,6 +0,10 @@ | ||
import { Transaction } from '@solana/web3.js'; | ||
import { Keypair, Transaction } from '@solana/web3.js'; | ||
import { Network, UnsignedTransaction } from '@wormhole-foundation/connect-sdk'; | ||
import { SolanaChains } from './types'; | ||
export type SolanaTransaction = { | ||
transaction: Transaction; | ||
signers?: Keypair[]; | ||
}; | ||
export declare class SolanaUnsignedTransaction<N extends Network, C extends SolanaChains = SolanaChains> implements UnsignedTransaction { | ||
readonly transaction: Transaction; | ||
readonly transaction: SolanaTransaction; | ||
readonly network: N; | ||
@@ -10,4 +14,4 @@ readonly chain: C; | ||
readonly parallelizable: boolean; | ||
constructor(transaction: Transaction, network: N, chain: C, description: string, parallelizable?: boolean); | ||
constructor(transaction: SolanaTransaction, network: N, chain: C, description: string, parallelizable?: boolean); | ||
} | ||
//# sourceMappingURL=unsignedTransaction.d.ts.map |
import { Balances, Chain, ChainsConfig, Network, PlatformContext, SignedTx, TokenId, TxHash } from '@wormhole-foundation/connect-sdk'; | ||
import { SolanaChain } from './chain'; | ||
import { Commitment, Connection, SendOptions } from '@solana/web3.js'; | ||
import { Commitment, Connection, ConnectionConfig, SendOptions } from '@solana/web3.js'; | ||
import { AnySolanaAddress, SolanaChains, SolanaPlatformType } from './types'; | ||
@@ -11,3 +11,3 @@ /** | ||
constructor(network: N, config?: ChainsConfig<N, SolanaPlatformType>); | ||
getRpc<C extends SolanaChains>(chain: C, commitment?: Commitment): Connection; | ||
getRpc<C extends SolanaChains>(chain: C, config?: ConnectionConfig): Connection; | ||
getChain<C extends SolanaChains>(chain: C, rpc?: Connection): SolanaChain<N, C>; | ||
@@ -14,0 +14,0 @@ static nativeTokenId<N extends Network, C extends SolanaChains>(network: N, chain: C): TokenId<C>; |
@@ -15,5 +15,8 @@ import { PlatformContext, Wormhole, chainToPlatform, decimals, nativeChainIds, networkPlatformConfigs, } from '@wormhole-foundation/connect-sdk'; | ||
} | ||
getRpc(chain, commitment = 'confirmed') { | ||
getRpc(chain, config = { | ||
commitment: 'confirmed', | ||
disableRetryOnRateLimit: true, | ||
}) { | ||
if (chain in this.config) | ||
return new Connection(this.config[chain].rpc, commitment); | ||
return new Connection(this.config[chain].rpc, config); | ||
throw new Error('No configuration available for chain: ' + chain); | ||
@@ -84,10 +87,7 @@ } | ||
const { blockhash, lastValidBlockHeight } = await this.latestBlock(rpc); | ||
const txhashes = await Promise.all(stxns.map((stxn) => rpc.sendRawTransaction(stxn, | ||
// Set the commitment level to match the rpc commitment level | ||
// otherwise, it defaults to finalized | ||
if (!opts) | ||
opts = { preflightCommitment: rpc.commitment }; | ||
const txhashes = await Promise.all(stxns.map((stxn) => { | ||
return rpc.sendRawTransaction(stxn, opts); | ||
})); | ||
await Promise.all(txhashes.map((signature) => { | ||
opts ?? { preflightCommitment: rpc.commitment }))); | ||
const results = await Promise.all(txhashes.map((signature) => { | ||
return rpc.confirmTransaction({ | ||
@@ -99,6 +99,11 @@ signature, | ||
})); | ||
const erroredTxs = results | ||
.filter((result) => result.value.err) | ||
.map((result) => result.value.err); | ||
if (erroredTxs.length > 0) | ||
throw new Error(`Failed to confirm transaction: ${erroredTxs}`); | ||
return txhashes; | ||
} | ||
static async latestBlock(rpc, commitment) { | ||
return rpc.getLatestBlockhash(commitment ?? 'finalized'); | ||
return rpc.getLatestBlockhash(commitment ?? rpc.commitment); | ||
} | ||
@@ -105,0 +110,0 @@ static async getLatestBlock(rpc) { |
@@ -9,3 +9,3 @@ import { Keypair } from '@solana/web3.js'; | ||
const [_, chain] = await SolanaPlatform.chainFromRpc(rpc); | ||
return new SolanaSigner(chain, Keypair.fromSecretKey(encoding.b58.decode(privateKey))); | ||
return new SolanaSigner(chain, Keypair.fromSecretKey(encoding.b58.decode(privateKey)), rpc); | ||
} | ||
@@ -12,0 +12,0 @@ // returns a SignAndSendSigner for the Solana platform |
@@ -1,2 +0,2 @@ | ||
import { Connection, Keypair } from '@solana/web3.js'; | ||
import { Connection, Keypair, SendOptions } from '@solana/web3.js'; | ||
import { SignAndSendSigner, UnsignedTransaction } from '@wormhole-foundation/connect-sdk'; | ||
@@ -10,7 +10,10 @@ import { Network } from '@wormhole-foundation/sdk-base/src'; | ||
private _debug; | ||
constructor(_rpc: Connection, _chain: C, _keypair: Keypair, _debug?: boolean); | ||
private _sendOpts?; | ||
private _priotifyFeeAmount?; | ||
constructor(_rpc: Connection, _chain: C, _keypair: Keypair, _debug?: boolean, _sendOpts?: SendOptions, _priotifyFeeAmount?: bigint); | ||
chain(): C; | ||
address(): string; | ||
private retryable; | ||
signAndSend(tx: UnsignedTransaction[]): Promise<any[]>; | ||
} | ||
//# sourceMappingURL=sendSigner.d.ts.map |
@@ -0,2 +1,6 @@ | ||
import { ComputeBudgetProgram, SendTransactionError, TransactionExpiredBlockheightExceededError, } from '@solana/web3.js'; | ||
import { SolanaPlatform } from '../platform'; | ||
import { logTxDetails } from './debug'; | ||
// Number of blocks to wait before considering a transaction expired | ||
const SOLANA_EXPIRED_BLOCKHEIGHT = 150; | ||
export class SolanaSendSigner { | ||
@@ -7,3 +11,5 @@ _rpc; | ||
_debug; | ||
constructor(_rpc, _chain, _keypair, _debug = false) { | ||
_sendOpts; | ||
_priotifyFeeAmount; | ||
constructor(_rpc, _chain, _keypair, _debug = false, _sendOpts, _priotifyFeeAmount) { | ||
this._rpc = _rpc; | ||
@@ -13,2 +19,7 @@ this._chain = _chain; | ||
this._debug = _debug; | ||
this._sendOpts = _sendOpts; | ||
this._priotifyFeeAmount = _priotifyFeeAmount; | ||
this._sendOpts = this._sendOpts ?? { | ||
preflightCommitment: this._rpc.commitment, | ||
}; | ||
} | ||
@@ -21,31 +32,84 @@ chain() { | ||
} | ||
// Handles retrying a Transaction if the error is deemed to be | ||
// recoverable. Currently handles: | ||
// - Transaction expired | ||
// - Blockhash not found | ||
// - Not enough bytes (storage account not seen yet) | ||
retryable(e) { | ||
// Tx expired, set a new block hash and retry | ||
if (e instanceof TransactionExpiredBlockheightExceededError) | ||
return true; | ||
// Besides tx expiry, only handle SendTransactionError | ||
if (!(e instanceof SendTransactionError)) | ||
return false; | ||
// Only handle simulation errors | ||
if (!e.message.includes('Transaction simulation failed')) | ||
return false; | ||
// Blockhash not found, similar to expired, resend with new blockhash | ||
if (e.message.includes('Blockhash not found')) | ||
return true; | ||
// Find the log message with the error details | ||
const loggedErr = e.logs.find((log) => log.startsWith('Program log: Error: ')); | ||
// who knows | ||
if (!loggedErr) | ||
return false; | ||
// Probably caused by storage account not seen yet | ||
if (loggedErr.includes('Not enough bytes')) | ||
return true; | ||
if (loggedErr.includes('Unexpected length of input')) | ||
return true; | ||
return false; | ||
} | ||
async signAndSend(tx) { | ||
const { blockhash, lastValidBlockHeight } = await SolanaPlatform.latestBlock(this._rpc, 'finalized'); | ||
const txPromises = []; | ||
let { blockhash, lastValidBlockHeight } = await SolanaPlatform.latestBlock(this._rpc); | ||
const txids = []; | ||
for (const txn of tx) { | ||
const { description, transaction } = txn; | ||
const { description, transaction: { transaction, signers: extraSigners }, } = txn; | ||
console.log(`Signing: ${description} for ${this.address()}`); | ||
if (this._debug) { | ||
console.log(transaction.signatures); | ||
console.log(transaction.feePayer); | ||
transaction.instructions.forEach((ix) => { | ||
console.log('Program', ix.programId.toBase58()); | ||
console.log('Data: ', ix.data.toString('hex')); | ||
console.log('Keys: ', ix.keys.map((k) => [k, k.pubkey.toBase58()])); | ||
}); | ||
if (this._priotifyFeeAmount) | ||
transaction.add(ComputeBudgetProgram.setComputeUnitPrice({ | ||
microLamports: this._priotifyFeeAmount, | ||
})); | ||
if (this._debug) | ||
logTxDetails(transaction); | ||
// Try to send the transaction up to 5 times | ||
const maxRetries = 5; | ||
for (let i = 0; i < maxRetries; i++) { | ||
try { | ||
transaction.recentBlockhash = blockhash; | ||
transaction.partialSign(this._keypair, ...(extraSigners ?? [])); | ||
const txid = await this._rpc.sendRawTransaction(transaction.serialize(), this._sendOpts); | ||
txids.push(txid); | ||
break; | ||
} | ||
catch (e) { | ||
// No point checking if retryable if we're on the last retry | ||
if (i === maxRetries - 1) | ||
throw e; | ||
// If it's not retryable, throw | ||
if (!this.retryable(e)) | ||
throw e; | ||
// If it is retryable, we need to grab a new block hash | ||
const { blockhash: newBlockhash, lastValidBlockHeight: newBlockHeight, } = await SolanaPlatform.latestBlock(this._rpc); | ||
// But we should _not_ submit if the blockhash hasnt expired | ||
if (newBlockHeight - lastValidBlockHeight < | ||
SOLANA_EXPIRED_BLOCKHEIGHT) { | ||
throw e; | ||
} | ||
lastValidBlockHeight = newBlockHeight; | ||
blockhash = newBlockhash; | ||
} | ||
} | ||
transaction.partialSign(this._keypair); | ||
txPromises.push(this._rpc.sendRawTransaction(transaction.serialize(), { | ||
preflightCommitment: this._rpc.commitment, | ||
})); | ||
} | ||
const txids = await Promise.all(txPromises); | ||
// Wait for finalization | ||
for (const signature of txids) { | ||
await this._rpc.confirmTransaction({ | ||
signature, | ||
blockhash, | ||
lastValidBlockHeight, | ||
}); | ||
} | ||
const results = await Promise.all(txids.map((signature) => this._rpc.confirmTransaction({ | ||
signature, | ||
blockhash, | ||
lastValidBlockHeight, | ||
}, this._rpc.commitment))); | ||
const erroredTxs = results | ||
.filter((result) => result.value.err) | ||
.map((result) => result.value.err); | ||
if (erroredTxs.length > 0) | ||
throw new Error(`Failed to confirm transaction: ${erroredTxs}`); | ||
return txids; | ||
@@ -52,0 +116,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { Keypair } from '@solana/web3.js'; | ||
import { Connection, Keypair } from '@solana/web3.js'; | ||
import { SignOnlySigner, UnsignedTransaction } from '@wormhole-foundation/connect-sdk'; | ||
@@ -8,4 +8,5 @@ import { Network } from '@wormhole-foundation/sdk-base/src'; | ||
private _keypair; | ||
private _rpc; | ||
private _debug; | ||
constructor(_chain: C, _keypair: Keypair, _debug?: boolean); | ||
constructor(_chain: C, _keypair: Keypair, _rpc: Connection, _debug?: boolean); | ||
chain(): C; | ||
@@ -12,0 +13,0 @@ address(): string; |
@@ -0,8 +1,12 @@ | ||
import { SolanaPlatform } from '../platform'; | ||
import { logTxDetails } from './debug'; | ||
export class SolanaSigner { | ||
_chain; | ||
_keypair; | ||
_rpc; | ||
_debug; | ||
constructor(_chain, _keypair, _debug = false) { | ||
constructor(_chain, _keypair, _rpc, _debug = false) { | ||
this._chain = _chain; | ||
this._keypair = _keypair; | ||
this._rpc = _rpc; | ||
this._debug = _debug; | ||
@@ -17,19 +21,11 @@ } | ||
async sign(tx) { | ||
const { blockhash } = await SolanaPlatform.latestBlock(this._rpc); | ||
const signed = []; | ||
for (const txn of tx) { | ||
const { description, transaction } = txn; | ||
const { description, transaction: { transaction, signers: extraSigners }, } = txn; | ||
console.log(`Signing: ${description} for ${this.address()}`); | ||
if (this._debug) { | ||
const st = transaction; | ||
console.log(st.signatures); | ||
console.log(st.feePayer); | ||
st.instructions.forEach((ix) => { | ||
console.log('Program', ix.programId.toBase58()); | ||
console.log('Data: ', ix.data.toString('hex')); | ||
ix.keys.forEach((k) => { | ||
console.log(k, k.pubkey.toBase58()); | ||
}); | ||
}); | ||
} | ||
transaction.partialSign(this._keypair); | ||
if (this._debug) | ||
logTxDetails(transaction); | ||
transaction.recentBlockhash = blockhash; | ||
transaction.partialSign(this._keypair, ...(extraSigners ?? [])); | ||
signed.push(transaction.serialize()); | ||
@@ -36,0 +32,0 @@ } |
@@ -1,6 +0,10 @@ | ||
import { Transaction } from '@solana/web3.js'; | ||
import { Keypair, Transaction } from '@solana/web3.js'; | ||
import { Network, UnsignedTransaction } from '@wormhole-foundation/connect-sdk'; | ||
import { SolanaChains } from './types'; | ||
export type SolanaTransaction = { | ||
transaction: Transaction; | ||
signers?: Keypair[]; | ||
}; | ||
export declare class SolanaUnsignedTransaction<N extends Network, C extends SolanaChains = SolanaChains> implements UnsignedTransaction { | ||
readonly transaction: Transaction; | ||
readonly transaction: SolanaTransaction; | ||
readonly network: N; | ||
@@ -10,4 +14,4 @@ readonly chain: C; | ||
readonly parallelizable: boolean; | ||
constructor(transaction: Transaction, network: N, chain: C, description: string, parallelizable?: boolean); | ||
constructor(transaction: SolanaTransaction, network: N, chain: C, description: string, parallelizable?: boolean); | ||
} | ||
//# sourceMappingURL=unsignedTransaction.d.ts.map |
{ | ||
"name": "@wormhole-foundation/connect-sdk-solana", | ||
"version": "0.3.0-beta.10", | ||
"version": "0.3.0-beta.11", | ||
"repository": { | ||
@@ -49,3 +49,3 @@ "type": "git", | ||
"dependencies": { | ||
"@wormhole-foundation/connect-sdk": "^0.3.0-beta.10", | ||
"@wormhole-foundation/connect-sdk": "^0.3.0-beta.11", | ||
"@coral-xyz/borsh": "0.2.6", | ||
@@ -52,0 +52,0 @@ "@project-serum/anchor": "0.25.0", |
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
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
387370
180
3170