@xandeum/web3.js 1.12.0 → 1.13.0

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.
@@ -0,0 +1,15 @@
1
+ import { Connection } from "@solana/web3.js";
2
+ /**
3
+ * Sends a JSON-RPC request to the Xandeum-compatible endpoint to retrieve
4
+ * the result of a transaction previously submitted with a specific signature.
5
+ *
6
+ * This function calls the custom RPC method `getXandeumResult`, which returns
7
+ * the result associated with the given transaction signature.
8
+ *
9
+ * @param connection - The Solana web3 connection object pointing to a Xandeum-compatible RPC endpoint.
10
+ * @param signature - The transaction signature string whose result should be queried.
11
+ *
12
+ * @returns A `Promise<any>` resolving to the parsed JSON response from the RPC server,
13
+ * which includes the result of the transaction if available.
14
+ */
15
+ export declare function getXandeumResult(connection: Connection, signature: string): Promise<any>;
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.getXandeumResult = getXandeumResult;
40
+ function sleep(ms) {
41
+ return new Promise(function (resolve) { return setTimeout(resolve, ms); });
42
+ }
43
+ /**
44
+ * Sends a JSON-RPC request to the Xandeum-compatible endpoint to retrieve
45
+ * the result of a transaction previously submitted with a specific signature.
46
+ *
47
+ * This function calls the custom RPC method `getXandeumResult`, which returns
48
+ * the result associated with the given transaction signature.
49
+ *
50
+ * @param connection - The Solana web3 connection object pointing to a Xandeum-compatible RPC endpoint.
51
+ * @param signature - The transaction signature string whose result should be queried.
52
+ *
53
+ * @returns A `Promise<any>` resolving to the parsed JSON response from the RPC server,
54
+ * which includes the result of the transaction if available.
55
+ */
56
+ function getXandeumResult(connection, signature) {
57
+ return __awaiter(this, void 0, void 0, function () {
58
+ var url, requestBody, response, errorText, data;
59
+ return __generator(this, function (_a) {
60
+ switch (_a.label) {
61
+ case 0:
62
+ url = connection.rpcEndpoint;
63
+ requestBody = {
64
+ jsonrpc: '2.0',
65
+ id: 1,
66
+ method: 'getXandeumResult',
67
+ params: [signature]
68
+ };
69
+ // sleeping To let the transaction process
70
+ return [4 /*yield*/, sleep(5000)];
71
+ case 1:
72
+ // sleeping To let the transaction process
73
+ _a.sent();
74
+ return [4 /*yield*/, fetch(url, {
75
+ method: 'POST',
76
+ headers: {
77
+ 'Content-Type': 'application/json'
78
+ },
79
+ body: JSON.stringify(requestBody)
80
+ })];
81
+ case 2:
82
+ response = _a.sent();
83
+ if (!!response.ok) return [3 /*break*/, 4];
84
+ return [4 /*yield*/, response.text()];
85
+ case 3:
86
+ errorText = _a.sent();
87
+ return [2 /*return*/, new Error("Error! status: ".concat(response.status, ", message: ").concat(errorText))];
88
+ case 4: return [4 /*yield*/, response.json()];
89
+ case 5:
90
+ data = _a.sent();
91
+ return [2 /*return*/, data];
92
+ }
93
+ });
94
+ });
95
+ }
package/dist/index.d.ts CHANGED
@@ -10,6 +10,7 @@ export * from "./poke";
10
10
  export * from "./removeDirectory";
11
11
  export * from "./copyPath";
12
12
  export * from "./move";
13
+ export * from "./getXandeumResult";
13
14
  export { exists } from "./exists";
14
15
  export { listDirectoryEntry } from "./listDirectoryEntery";
15
16
  export { getMetadata } from "./getMetadata";
package/dist/index.js CHANGED
@@ -28,6 +28,7 @@ __exportStar(require("./poke"), exports);
28
28
  __exportStar(require("./removeDirectory"), exports);
29
29
  __exportStar(require("./copyPath"), exports);
30
30
  __exportStar(require("./move"), exports);
31
+ __exportStar(require("./getXandeumResult"), exports);
31
32
  var exists_1 = require("./exists");
32
33
  Object.defineProperty(exports, "exists", { enumerable: true, get: function () { return exists_1.exists; } });
33
34
  var listDirectoryEntery_1 = require("./listDirectoryEntery");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xandeum/web3.js",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
4
  "description": "Xandeum javascript api",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -0,0 +1,48 @@
1
+
2
+ import { Connection } from "@solana/web3.js"
3
+
4
+ function sleep(ms: number) {
5
+ return new Promise(resolve => setTimeout(resolve, ms));
6
+ }
7
+
8
+ /**
9
+ * Sends a JSON-RPC request to the Xandeum-compatible endpoint to retrieve
10
+ * the result of a transaction previously submitted with a specific signature.
11
+ *
12
+ * This function calls the custom RPC method `getXandeumResult`, which returns
13
+ * the result associated with the given transaction signature.
14
+ *
15
+ * @param connection - The Solana web3 connection object pointing to a Xandeum-compatible RPC endpoint.
16
+ * @param signature - The transaction signature string whose result should be queried.
17
+ *
18
+ * @returns A `Promise<any>` resolving to the parsed JSON response from the RPC server,
19
+ * which includes the result of the transaction if available.
20
+ */
21
+ export async function getXandeumResult( connection: Connection, signature: string): Promise<any> {
22
+ const url = connection.rpcEndpoint;
23
+ const requestBody = {
24
+ jsonrpc: '2.0',
25
+ id: 1,
26
+ method: 'getXandeumResult',
27
+ params: [signature]
28
+ }
29
+
30
+ // sleeping To let the transaction process
31
+ await sleep(5000);
32
+
33
+ const response = await fetch(url, {
34
+ method: 'POST',
35
+ headers: {
36
+ 'Content-Type': 'application/json'
37
+ },
38
+ body: JSON.stringify(requestBody)
39
+ })
40
+
41
+ if (!response.ok) {
42
+ const errorText = await response.text();
43
+ return new Error(`Error! status: ${response.status}, message: ${errorText}`);
44
+ }
45
+
46
+ const data = await response.json()
47
+ return data
48
+ }
package/src/index.ts CHANGED
@@ -10,7 +10,7 @@ export * from "./poke";
10
10
  export * from "./removeDirectory";
11
11
  export * from "./copyPath";
12
12
  export * from "./move";
13
-
13
+ export * from "./getXandeumResult";
14
14
  export {exists } from "./exists";
15
15
  export {listDirectoryEntry} from "./listDirectoryEntery";
16
16
  export {getMetadata} from "./getMetadata";