@flashbacktech/flashbackclient 0.1.35 → 0.1.37

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.
@@ -8,6 +8,12 @@ BigInt.prototype.toJSON = function () {
8
8
  };
9
9
  const stellar_sdk_1 = require("@stellar/stellar-sdk");
10
10
  const stellar_sdk_2 = require("@stellar/stellar-sdk");
11
+ // Set global configuration for Stellar SDK to allow HTTP connections
12
+ // This is sometimes needed for newer versions of the SDK
13
+ if (typeof window !== 'undefined') {
14
+ // Browser environment
15
+ window.__STELLAR_SDK_ALLOW_HTTP__ = true;
16
+ }
11
17
  const getNetwork = (network) => {
12
18
  let networkPassphrase = "";
13
19
  switch (network) {
@@ -30,23 +36,92 @@ const getServer = (network) => {
30
36
  let serverUrl = "";
31
37
  switch (network.network) {
32
38
  case "TESTNET":
33
- serverUrl = "https://soroban-testnet.stellar.org:443";
39
+ serverUrl = "https://soroban-testnet.stellar.org";
34
40
  break;
35
41
  case "PUBLIC":
36
- serverUrl = "https://rpc.stellar.org:443";
42
+ serverUrl = "https://rpc.stellar.org";
37
43
  break;
38
44
  }
39
- const server = new stellar_sdk_2.rpc.Server(serverUrl);
40
- return server;
45
+ console.log(`Creating Soroban RPC server for network: ${network.network}, URL: ${serverUrl}`);
46
+ // For Stellar SDK v13+, we need to handle the allowHttp issue
47
+ // Try different approaches to create the server
48
+ let server;
49
+ // Approach 1: Try with allowHttp option
50
+ try {
51
+ console.log(`Attempting to create server with allowHttp: true`);
52
+ server = new stellar_sdk_2.rpc.Server(serverUrl, { allowHttp: true });
53
+ console.log(`Soroban RPC server created successfully with allowHttp: true`);
54
+ return server;
55
+ }
56
+ catch (error) {
57
+ console.log(`Failed with allowHttp: true:`, error instanceof Error ? error.message : String(error));
58
+ }
59
+ // Approach 1.5: Try with allowHttp as a boolean string
60
+ try {
61
+ console.log(`Attempting to create server with allowHttp: "true"`);
62
+ server = new stellar_sdk_2.rpc.Server(serverUrl, { allowHttp: "true" });
63
+ console.log(`Soroban RPC server created successfully with allowHttp: "true"`);
64
+ return server;
65
+ }
66
+ catch (error) {
67
+ console.log(`Failed with allowHttp: "true":`, error instanceof Error ? error.message : String(error));
68
+ }
69
+ // Approach 1.6: Try with allowHttp as a number
70
+ try {
71
+ console.log(`Attempting to create server with allowHttp: 1`);
72
+ server = new stellar_sdk_2.rpc.Server(serverUrl, { allowHttp: 1 });
73
+ console.log(`Soroban RPC server created successfully with allowHttp: 1`);
74
+ return server;
75
+ }
76
+ catch (error) {
77
+ console.log(`Failed with allowHttp: 1:`, error instanceof Error ? error.message : String(error));
78
+ }
79
+ // Approach 3: Try without any options
80
+ try {
81
+ console.log(`Attempting to create server without options`);
82
+ server = new stellar_sdk_2.rpc.Server(serverUrl);
83
+ console.log(`Soroban RPC server created successfully without options`);
84
+ return server;
85
+ }
86
+ catch (error) {
87
+ console.log(`Failed without options:`, error instanceof Error ? error.message : String(error));
88
+ }
89
+ // Approach 4: Try with empty options
90
+ try {
91
+ console.log(`Attempting to create server with empty options`);
92
+ server = new stellar_sdk_2.rpc.Server(serverUrl, {});
93
+ console.log(`Soroban RPC server created successfully with empty options`);
94
+ return server;
95
+ }
96
+ catch (error) {
97
+ console.log(`Failed with empty options:`, error instanceof Error ? error.message : String(error));
98
+ }
99
+ // Approach 5: Try with a different URL format (without protocol)
100
+ try {
101
+ console.log(`Attempting to create server with URL without protocol`);
102
+ const urlWithoutProtocol = serverUrl.replace('https://', '');
103
+ server = new stellar_sdk_2.rpc.Server(urlWithoutProtocol, { allowHttp: true });
104
+ console.log(`Soroban RPC server created successfully with URL without protocol`);
105
+ return server;
106
+ }
107
+ catch (error) {
108
+ console.log(`Failed with URL without protocol:`, error instanceof Error ? error.message : String(error));
109
+ }
110
+ // If all approaches fail, throw a comprehensive error
111
+ throw new Error(`Failed to create Soroban RPC server for ${network.network} at ${serverUrl}. All configuration attempts failed.`);
41
112
  };
42
113
  exports.getServer = getServer;
43
114
  const TIMEOUT_TRANSACTION = 60;
44
115
  const getHorizonServer = (network) => {
45
116
  if (network === "TESTNET") {
46
- return new stellar_sdk_1.Horizon.Server("https://horizon-testnet.stellar.org");
117
+ return new stellar_sdk_1.Horizon.Server("https://horizon-testnet.stellar.org", {
118
+ allowHttp: true
119
+ });
47
120
  }
48
121
  else {
49
- return new stellar_sdk_1.Horizon.Server("https://horizon.stellar.org");
122
+ return new stellar_sdk_1.Horizon.Server("https://horizon.stellar.org", {
123
+ allowHttp: true
124
+ });
50
125
  }
51
126
  };
52
127
  exports.getHorizonServer = getHorizonServer;
@@ -146,7 +221,17 @@ const prepareTransaction = async (context, address, contractCalls) => {
146
221
  const builtTransaction = transactionBuilder
147
222
  .setTimeout(TIMEOUT_TRANSACTION)
148
223
  .build();
149
- const sim = await server.simulateTransaction(builtTransaction);
224
+ console.log(`About to simulate transaction for method: ${calls[0]?.method || 'unknown'}`);
225
+ console.log(`Network: ${context.network.network}, Passphrase: ${context.network.networkPassphrase}`);
226
+ let sim;
227
+ try {
228
+ sim = await server.simulateTransaction(builtTransaction);
229
+ console.log(`Transaction simulation successful`);
230
+ }
231
+ catch (error) {
232
+ console.error(`Transaction simulation failed:`, error);
233
+ throw error;
234
+ }
150
235
  if (stellar_sdk_2.rpc.Api.isSimulationSuccess(sim)) {
151
236
  response.isSuccess = true;
152
237
  const result = sim.result && sim.result.retval
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flashbacktech/flashbackclient",
3
- "version": "0.1.35",
3
+ "version": "0.1.37",
4
4
  "type": "commonjs",
5
5
  "publishConfig": {
6
6
  "access": "public"