@ghostspeak/sdk 1.3.1 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -21582,10 +21582,11 @@ var BaseInstructions = class {
21582
21582
  */
21583
21583
  getSendAndConfirmTransaction() {
21584
21584
  if (!this._sendAndConfirmTransaction) {
21585
- this._sendAndConfirmTransaction = sendAndConfirmTransactionFactory({
21586
- rpc: this.rpc,
21587
- rpcSubscriptions: this.rpcSubscriptions
21588
- });
21585
+ const factoryConfig = { rpc: this.rpc };
21586
+ if (this.rpcSubscriptions) {
21587
+ factoryConfig.rpcSubscriptions = this.rpcSubscriptions;
21588
+ }
21589
+ this._sendAndConfirmTransaction = sendAndConfirmTransactionFactory(factoryConfig);
21589
21590
  }
21590
21591
  return this._sendAndConfirmTransaction;
21591
21592
  }
@@ -21605,6 +21606,22 @@ var BaseInstructions = class {
21605
21606
  console.log(`\u{1F510} Using ${signers.length} signers`);
21606
21607
  console.log(`\u{1F4CD} Program ID: ${this.programId}`);
21607
21608
  console.log(`\u{1F310} Commitment: ${this.commitment}`);
21609
+ for (let i = 0; i < instructions.length; i++) {
21610
+ const instruction = instructions[i];
21611
+ if (!instruction) {
21612
+ throw new Error(`Instruction at index ${i} is undefined`);
21613
+ }
21614
+ if (!instruction.programAddress) {
21615
+ throw new Error(`Instruction at index ${i} has no programAddress`);
21616
+ }
21617
+ if (!instruction.accounts) {
21618
+ throw new Error(`Instruction at index ${i} has no accounts array`);
21619
+ }
21620
+ if (!Array.isArray(instruction.accounts)) {
21621
+ throw new Error(`Instruction at index ${i} accounts is not an array`);
21622
+ }
21623
+ console.log(`\u2705 Instruction ${i}: ${instruction.accounts.length} accounts, program: ${instruction.programAddress}`);
21624
+ }
21608
21625
  console.log("\u{1F517} Fetching latest blockhash...");
21609
21626
  const { value: latestBlockhash } = await this.rpc.getLatestBlockhash().send();
21610
21627
  console.log(`\u2705 Got blockhash: ${latestBlockhash.blockhash}`);
@@ -21620,12 +21637,41 @@ var BaseInstructions = class {
21620
21637
  const signedTransaction = await signTransactionMessageWithSigners(transactionMessage);
21621
21638
  console.log("\u2705 Transaction signed");
21622
21639
  console.log("\u{1F4E1} Sending transaction to blockchain...");
21623
- const sendAndConfirmTransaction = this.getSendAndConfirmTransaction();
21624
- const result = await sendAndConfirmTransaction(signedTransaction, {
21625
- commitment: this.commitment,
21626
- skipPreflight: false
21627
- });
21628
- const signature = result?.signature || Object.values(signedTransaction.signatures || {})[0] || "unknown_signature";
21640
+ let result;
21641
+ let signature;
21642
+ if (!this.rpcSubscriptions) {
21643
+ console.log("\u26A0\uFE0F No RPC subscriptions available, using polling for confirmation...");
21644
+ const transactionSignature = await this.rpc.sendTransaction(signedTransaction, {
21645
+ skipPreflight: false,
21646
+ preflightCommitment: this.commitment
21647
+ }).send();
21648
+ console.log(`\u{1F4E4} Transaction sent: ${transactionSignature}`);
21649
+ let confirmed = false;
21650
+ let attempts = 0;
21651
+ const maxAttempts = 30;
21652
+ while (!confirmed && attempts < maxAttempts) {
21653
+ const status = await this.rpc.getSignatureStatuses([transactionSignature]).send();
21654
+ if (status.value[0] && status.value[0].confirmationStatus === this.commitment) {
21655
+ confirmed = true;
21656
+ console.log("\u2705 Transaction confirmed!");
21657
+ } else {
21658
+ attempts++;
21659
+ console.log(`\u23F3 Waiting for confirmation... (${attempts}/${maxAttempts})`);
21660
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
21661
+ }
21662
+ }
21663
+ if (!confirmed) {
21664
+ throw new Error("Transaction confirmation timeout");
21665
+ }
21666
+ signature = transactionSignature;
21667
+ } else {
21668
+ const sendAndConfirmTransaction = this.getSendAndConfirmTransaction();
21669
+ result = await sendAndConfirmTransaction(signedTransaction, {
21670
+ commitment: this.commitment,
21671
+ skipPreflight: false
21672
+ });
21673
+ signature = result?.signature || Object.values(signedTransaction.signatures || {})[0] || "unknown_signature";
21674
+ }
21629
21675
  const rpcEndpoint = this.config.rpc?.toString() || "mainnet-beta";
21630
21676
  const cluster = detectClusterFromEndpoint(rpcEndpoint);
21631
21677
  const transactionResult = createTransactionResult(
@@ -21738,6 +21784,11 @@ var BaseInstructions = class {
21738
21784
  console.log(` Program: ${instruction.programAddress}`);
21739
21785
  console.log(` Accounts: ${instruction.accounts?.length || 0}`);
21740
21786
  console.log(` Data size: ${instruction.data?.length || 0} bytes`);
21787
+ if (instruction.accounts) {
21788
+ instruction.accounts.forEach((account, index) => {
21789
+ console.log(` Account ${index}: ${JSON.stringify(account)}`);
21790
+ });
21791
+ }
21741
21792
  }
21742
21793
  };
21743
21794
 
@@ -21756,17 +21807,30 @@ var AgentInstructions = class extends BaseInstructions {
21756
21807
  metadataUri: params.metadataUri,
21757
21808
  agentId: params.agentId,
21758
21809
  agentAddress: agentAddress.toString(),
21759
- userRegistry: userRegistryAddress.toString()
21760
- });
21761
- const instruction = getRegisterAgentInstruction({
21762
- agentAccount: agentAddress,
21763
- userRegistry: userRegistryAddress,
21764
- signer,
21765
- agentType,
21766
- metadataUri: params.metadataUri,
21767
- agentId: params.agentId
21810
+ userRegistry: userRegistryAddress.toString(),
21811
+ signer: signer.address ? signer.address.toString() : "NO_ADDRESS"
21768
21812
  });
21769
- return this.sendTransaction([instruction], [signer]);
21813
+ try {
21814
+ const instruction = getRegisterAgentInstruction({
21815
+ agentAccount: agentAddress,
21816
+ userRegistry: userRegistryAddress,
21817
+ signer,
21818
+ agentType,
21819
+ metadataUri: params.metadataUri,
21820
+ agentId: params.agentId
21821
+ });
21822
+ console.log("\u{1F4E6} Instruction created:", {
21823
+ programAddress: instruction.programAddress,
21824
+ accountsLength: instruction.accounts?.length,
21825
+ dataLength: instruction.data?.length,
21826
+ accounts: instruction.accounts
21827
+ });
21828
+ this.logInstructionDetails(instruction);
21829
+ return this.sendTransaction([instruction], [signer]);
21830
+ } catch (error) {
21831
+ console.error("\u274C Failed to create register instruction:", error);
21832
+ throw error;
21833
+ }
21770
21834
  }
21771
21835
  /**
21772
21836
  * Update an existing agent