@silvana-one/api 0.1.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.
Files changed (40) hide show
  1. package/README.md +1 -0
  2. package/dist/node/client/sdk.gen.d.ts +153 -0
  3. package/dist/node/client/sdk.gen.js +269 -0
  4. package/dist/node/client/sdk.gen.js.map +1 -0
  5. package/dist/node/client/types.gen.d.ts +1068 -0
  6. package/dist/node/client/types.gen.js +3 -0
  7. package/dist/node/client/types.gen.js.map +1 -0
  8. package/dist/node/config.d.ts +5 -0
  9. package/dist/node/config.js +15 -0
  10. package/dist/node/config.js.map +1 -0
  11. package/dist/node/index.cjs +286 -0
  12. package/dist/node/index.d.ts +4 -0
  13. package/dist/node/index.js +9 -0
  14. package/dist/node/index.js.map +1 -0
  15. package/dist/node/wait.d.ts +2 -0
  16. package/dist/node/wait.js +58 -0
  17. package/dist/node/wait.js.map +1 -0
  18. package/dist/tsconfig.tsbuildinfo +1 -0
  19. package/dist/tsconfig.web.tsbuildinfo +1 -0
  20. package/dist/web/client/sdk.gen.d.ts +153 -0
  21. package/dist/web/client/sdk.gen.js +269 -0
  22. package/dist/web/client/sdk.gen.js.map +1 -0
  23. package/dist/web/client/types.gen.d.ts +1068 -0
  24. package/dist/web/client/types.gen.js +3 -0
  25. package/dist/web/client/types.gen.js.map +1 -0
  26. package/dist/web/config.d.ts +5 -0
  27. package/dist/web/config.js +15 -0
  28. package/dist/web/config.js.map +1 -0
  29. package/dist/web/index.d.ts +4 -0
  30. package/dist/web/index.js +9 -0
  31. package/dist/web/index.js.map +1 -0
  32. package/dist/web/wait.d.ts +2 -0
  33. package/dist/web/wait.js +58 -0
  34. package/dist/web/wait.js.map +1 -0
  35. package/package.json +61 -0
  36. package/src/client/sdk.gen.ts +294 -0
  37. package/src/client/types.gen.ts +1211 -0
  38. package/src/config.ts +24 -0
  39. package/src/index.ts +8 -0
  40. package/src/wait.ts +73 -0
package/src/config.ts ADDED
@@ -0,0 +1,24 @@
1
+ import { client } from "./client/sdk.gen.js";
2
+
3
+ export function config({
4
+ apiKey,
5
+ chain,
6
+ throwOnError,
7
+ }: {
8
+ apiKey: string;
9
+ chain?: "mainnet" | "devnet" | "zeko";
10
+ throwOnError?: boolean;
11
+ }) {
12
+ client.setConfig({
13
+ headers: {
14
+ "x-api-key": apiKey,
15
+ },
16
+ baseUrl:
17
+ chain === "zeko"
18
+ ? "https://zekotokens.com/api/v1/"
19
+ : chain === "devnet"
20
+ ? "https://devnet.silvana-one.com/api/v1/"
21
+ : "https://silvana-one.com/api/v1/",
22
+ throwOnError: throwOnError ?? true,
23
+ });
24
+ }
package/src/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ // export * from "./api.js";
2
+ // export * from "./transaction.js";
3
+ // export * from "./token.js";
4
+ // export * from "./nft-v2.js";
5
+ export * from "./client/sdk.gen.js";
6
+ export * from "./client/types.gen.js";
7
+ export * from "./config.js";
8
+ export * from "./wait.js";
package/src/wait.ts ADDED
@@ -0,0 +1,73 @@
1
+ import { getProof, txStatus } from "./client/sdk.gen.js";
2
+
3
+ export async function waitForProofs(
4
+ jobId: string
5
+ ): Promise<(string | undefined)[] | undefined> {
6
+ console.log("Job ID:", jobId);
7
+ let errorCount = 0;
8
+ const startTime = Date.now();
9
+ console.log("Waiting for job result...");
10
+ while (errorCount < 100 && Date.now() - startTime < 1000 * 60 * 10) {
11
+ try {
12
+ const jobResults = (await getProof({ body: { jobId } })).data;
13
+ const jobStatus = jobResults?.jobStatus;
14
+
15
+ if (
16
+ jobResults?.success === true &&
17
+ (jobStatus === "finished" || jobStatus === "used")
18
+ ) {
19
+ return jobResults.results?.map((result) => result.hash ?? "") ?? [];
20
+ }
21
+
22
+ if (jobStatus === "failed") {
23
+ console.error(`Job ${jobId} failed`);
24
+ return undefined;
25
+ }
26
+ } catch (error) {
27
+ errorCount++;
28
+ console.error(error);
29
+ }
30
+ await sleep(10000);
31
+ }
32
+ return undefined;
33
+ }
34
+
35
+ export async function waitForTransaction(
36
+ hash: string,
37
+ timeout = 1000 * 60 * 60 * 5
38
+ ) {
39
+ console.log(`Waiting for transaction ${hash} to be included in a block...`);
40
+ const startTime = Date.now();
41
+ let status = "pending";
42
+ let errorCount = 0;
43
+ while (
44
+ status !== "applied" &&
45
+ errorCount < 100 &&
46
+ Date.now() - startTime < timeout
47
+ ) {
48
+ try {
49
+ const result = (await txStatus({ body: { hash } })).data;
50
+ status = result?.status ?? "pending";
51
+ if (status === "failed") {
52
+ throw new Error(
53
+ `Transaction ${hash} failed: ${JSON.stringify({ result })}`
54
+ );
55
+ } else if (status === "applied") {
56
+ console.log(`Transaction ${hash} included in a block`, result);
57
+ return;
58
+ }
59
+ } catch (error) {
60
+ errorCount++;
61
+ console.error(error);
62
+ }
63
+
64
+ await sleep(30000);
65
+ }
66
+ throw new Error(
67
+ `Transaction ${hash} not included in a block, timeout or too many errors`
68
+ );
69
+ }
70
+
71
+ async function sleep(ms: number) {
72
+ return new Promise((resolve) => setTimeout(resolve, ms));
73
+ }