@xyo-network/xl1-rpc 1.7.2 → 1.7.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.
@@ -209,204 +209,6 @@ var MemoryXyoProvider = class {
209
209
  }
210
210
  };
211
211
 
212
- // src/provider/runner/JsonRpcXyoRunner.ts
213
- var JsonRpcXyoRunner = class {
214
- static {
215
- __name(this, "JsonRpcXyoRunner");
216
- }
217
- transport;
218
- constructor(transport) {
219
- this.transport = transport;
220
- }
221
- async broadcastTransaction(transaction) {
222
- return await this.transport.sendRequest("xyoRunner_broadcastTransaction", [
223
- transaction
224
- ]);
225
- }
226
- };
227
-
228
- // src/provider/runner/MemoryXyoRunner.ts
229
- import { MemoryArchivist } from "@xyo-network/archivist-memory";
230
- import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
231
- import { flattenHydratedTransaction } from "@xyo-network/xl1-protocol-sdk";
232
- var MemoryXyoRunner = class {
233
- static {
234
- __name(this, "MemoryXyoRunner");
235
- }
236
- _archivist;
237
- async broadcastTransaction(transaction) {
238
- const archivist = await this.getArchivist();
239
- await archivist.insert(flattenHydratedTransaction(transaction));
240
- return await PayloadBuilder2.hash(transaction[0]);
241
- }
242
- async getArchivist() {
243
- if (!this._archivist) {
244
- this._archivist = await MemoryArchivist.create({
245
- account: "random"
246
- });
247
- }
248
- return this._archivist;
249
- }
250
- };
251
-
252
- // src/provider/runner/NodeXyoRunner.ts
253
- import { assertEx as assertEx2 } from "@xylabs/assert";
254
- import { asArchivistInstance } from "@xyo-network/archivist-model";
255
- import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/payload-builder";
256
- import { PayloadBundleSchema } from "@xyo-network/payload-model";
257
- import { flattenHydratedTransaction as flattenHydratedTransaction2 } from "@xyo-network/xl1-protocol-sdk";
258
- var NodeXyoRunner = class {
259
- static {
260
- __name(this, "NodeXyoRunner");
261
- }
262
- // TODO: Make configurable with defaults
263
- node;
264
- pendingArchivistPath = "XYOChain:Pending:PendingTransactions";
265
- _pendingArchivist;
266
- constructor(node) {
267
- this.node = node;
268
- }
269
- async broadcastTransaction(transaction) {
270
- const flattened = flattenHydratedTransaction2(transaction);
271
- const pendingArchivist = await this.getPendingArchivist();
272
- const txHash = await PayloadBuilder3.hash(transaction[0]);
273
- const payloadBundle = {
274
- schema: PayloadBundleSchema,
275
- payloads: flattened,
276
- root: txHash
277
- };
278
- await pendingArchivist.insert([
279
- payloadBundle
280
- ]);
281
- return txHash;
282
- }
283
- getArchivist = /* @__PURE__ */ __name(async (identifier) => {
284
- const archivist = await this.node.resolve(identifier);
285
- return assertEx2(asArchivistInstance(archivist), () => `Error: Could not resolve ${identifier} to an archivist instance`);
286
- }, "getArchivist");
287
- getPendingArchivist = /* @__PURE__ */ __name(async () => {
288
- if (this._pendingArchivist) return this._pendingArchivist;
289
- this._pendingArchivist = await this.getArchivist(this.pendingArchivistPath);
290
- return assertEx2(this._pendingArchivist, () => `Error: Could not resolve pending archivist at ${this.pendingArchivistPath}`);
291
- }, "getPendingArchivist");
292
- };
293
-
294
- // src/provider/signer/JsonRpcXyoSigner.ts
295
- var JsonRpcXyoSigner = class {
296
- static {
297
- __name(this, "JsonRpcXyoSigner");
298
- }
299
- transport;
300
- constructor(transport) {
301
- this.transport = transport;
302
- }
303
- async address() {
304
- return await this.transport.sendRequest("xyoSigner_address");
305
- }
306
- async createSignedTransaction(chain, elevatedPayloads, additionalPayloads, nbf, exp, fees, from) {
307
- return await this.transport.sendRequest("xyoSigner_createSignedTransaction", [
308
- chain,
309
- elevatedPayloads,
310
- additionalPayloads,
311
- nbf,
312
- exp,
313
- fees,
314
- from
315
- ]);
316
- }
317
- };
318
-
319
- // src/provider/signer/MemoryXyoSigner.ts
320
- import { buildTransaction } from "@xyo-network/xl1-protocol-sdk";
321
- var MemoryXyoSigner = class {
322
- static {
323
- __name(this, "MemoryXyoSigner");
324
- }
325
- _account;
326
- constructor(account) {
327
- this._account = account;
328
- }
329
- address() {
330
- return this._account.address;
331
- }
332
- async createSignedTransaction(chain, elevatedPayloads, additionalPayloads, nbf, exp, fees, from) {
333
- const fromAddress = from ?? this._account.address;
334
- const transaction = await buildTransaction(chain, elevatedPayloads, additionalPayloads, this._account, nbf, exp, fromAddress, fees);
335
- return transaction[0];
336
- }
337
- };
338
-
339
- // src/provider/viewer/JsonRpcXyoViewer.ts
340
- var JsonRpcXyoViewer = class {
341
- static {
342
- __name(this, "JsonRpcXyoViewer");
343
- }
344
- transport;
345
- constructor(transport) {
346
- this.transport = transport;
347
- }
348
- async accountBalance(address) {
349
- return await this.transport.sendRequest("xyoViewer_accountBalance", [
350
- address
351
- ]);
352
- }
353
- async accountHistory(address) {
354
- return await this.transport.sendRequest("xyoViewer_accountBalance", [
355
- address
356
- ]);
357
- }
358
- async blockByHash(hash) {
359
- return await this.transport.sendRequest("xyoViewer_blockByHash", [
360
- hash
361
- ]);
362
- }
363
- async blockByNumber(blockNumber) {
364
- return await this.transport.sendRequest("xyoViewer_blockByNumber", [
365
- blockNumber
366
- ]);
367
- }
368
- async blocksByHash(hash, limit) {
369
- return await this.transport.sendRequest("xyoViewer_blocksByHash", [
370
- hash,
371
- limit
372
- ]);
373
- }
374
- async chainId() {
375
- return await this.transport.sendRequest("xyoViewer_chainId");
376
- }
377
- async currentBlock() {
378
- return await this.transport.sendRequest("xyoViewer_currentBlock");
379
- }
380
- async currentBlockHash() {
381
- return await this.transport.sendRequest("xyoViewer_currentBlockHash");
382
- }
383
- async currentBlockNumber() {
384
- return await this.transport.sendRequest("xyoViewer_currentBlockNumber");
385
- }
386
- async transactionByBlockHashAndIndex(blockHash, transactionIndex) {
387
- return await this.transport.sendRequest("xyoViewer_transactionByBlockHashAndIndex", [
388
- blockHash,
389
- transactionIndex
390
- ]);
391
- }
392
- async transactionByBlockNumberAndIndex(blockNumber, transactionIndex) {
393
- return await this.transport.sendRequest("xyoViewer_transactionByBlockNumberAndIndex", [
394
- blockNumber,
395
- transactionIndex
396
- ]);
397
- }
398
- async transactionByHash(transactionHash) {
399
- return await this.transport.sendRequest("xyoViewer_transactionByHash", [
400
- transactionHash
401
- ]);
402
- }
403
- };
404
-
405
- // src/transport/HttpRpcTransport.ts
406
- import { AxiosJson } from "@xylabs/axios";
407
- import { isUndefinedOrNull } from "@xylabs/typeof";
408
- import { v4 } from "uuid";
409
-
410
212
  // src/types/ErrorCodes.ts
411
213
  var JsonRpcErrorCodes = {
412
214
  InternalError: {
@@ -1059,6 +861,9 @@ var XyoGatewayRpcSchemas = {
1059
861
  };
1060
862
 
1061
863
  // src/transport/HttpRpcTransport.ts
864
+ import { AxiosJson } from "@xylabs/axios";
865
+ import { isUndefinedOrNull } from "@xylabs/typeof";
866
+ import { v4 } from "uuid";
1062
867
  var HttpRpcTransport = class {
1063
868
  static {
1064
869
  __name(this, "HttpRpcTransport");
@@ -1188,6 +993,253 @@ var PostMessageRpcTransport = class {
1188
993
  });
1189
994
  }
1190
995
  };
996
+
997
+ // src/provider/runner/JsonRpcXyoRunner.ts
998
+ var JsonRpcXyoRunner = class {
999
+ static {
1000
+ __name(this, "JsonRpcXyoRunner");
1001
+ }
1002
+ transport;
1003
+ constructor(transport) {
1004
+ this.transport = transport;
1005
+ }
1006
+ async broadcastTransaction(transaction) {
1007
+ return await this.transport.sendRequest("xyoRunner_broadcastTransaction", [
1008
+ transaction
1009
+ ]);
1010
+ }
1011
+ };
1012
+
1013
+ // src/provider/runner/MemoryXyoRunner.ts
1014
+ import { MemoryArchivist } from "@xyo-network/archivist-memory";
1015
+ import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
1016
+ import { flattenHydratedTransaction } from "@xyo-network/xl1-protocol-sdk";
1017
+ var MemoryXyoRunner = class {
1018
+ static {
1019
+ __name(this, "MemoryXyoRunner");
1020
+ }
1021
+ _archivist;
1022
+ async broadcastTransaction(transaction) {
1023
+ const archivist = await this.getArchivist();
1024
+ await archivist.insert(flattenHydratedTransaction(transaction));
1025
+ return await PayloadBuilder2.hash(transaction[0]);
1026
+ }
1027
+ async getArchivist() {
1028
+ if (!this._archivist) {
1029
+ this._archivist = await MemoryArchivist.create({
1030
+ account: "random"
1031
+ });
1032
+ }
1033
+ return this._archivist;
1034
+ }
1035
+ };
1036
+
1037
+ // src/provider/runner/NodeXyoRunner.ts
1038
+ import { assertEx as assertEx2 } from "@xylabs/assert";
1039
+ import { asArchivistInstance } from "@xyo-network/archivist-model";
1040
+ import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/payload-builder";
1041
+ import { PayloadBundleSchema } from "@xyo-network/payload-model";
1042
+ import { flattenHydratedTransaction as flattenHydratedTransaction2 } from "@xyo-network/xl1-protocol-sdk";
1043
+ var NodeXyoRunner = class {
1044
+ static {
1045
+ __name(this, "NodeXyoRunner");
1046
+ }
1047
+ // TODO: Make configurable with defaults
1048
+ node;
1049
+ pendingArchivistPath = "XYOChain:Pending:PendingTransactions";
1050
+ _pendingArchivist;
1051
+ constructor(node) {
1052
+ this.node = node;
1053
+ }
1054
+ async broadcastTransaction(transaction) {
1055
+ const flattened = flattenHydratedTransaction2(transaction);
1056
+ const pendingArchivist = await this.getPendingArchivist();
1057
+ const txHash = await PayloadBuilder3.hash(transaction[0]);
1058
+ const payloadBundle = {
1059
+ schema: PayloadBundleSchema,
1060
+ payloads: flattened,
1061
+ root: txHash
1062
+ };
1063
+ await pendingArchivist.insert([
1064
+ payloadBundle
1065
+ ]);
1066
+ return txHash;
1067
+ }
1068
+ getArchivist = /* @__PURE__ */ __name(async (identifier) => {
1069
+ const archivist = await this.node.resolve(identifier);
1070
+ return assertEx2(asArchivistInstance(archivist), () => `Error: Could not resolve ${identifier} to an archivist instance`);
1071
+ }, "getArchivist");
1072
+ getPendingArchivist = /* @__PURE__ */ __name(async () => {
1073
+ if (this._pendingArchivist) return this._pendingArchivist;
1074
+ this._pendingArchivist = await this.getArchivist(this.pendingArchivistPath);
1075
+ return assertEx2(this._pendingArchivist, () => `Error: Could not resolve pending archivist at ${this.pendingArchivistPath}`);
1076
+ }, "getPendingArchivist");
1077
+ };
1078
+
1079
+ // src/provider/signer/JsonRpcXyoSigner.ts
1080
+ var JsonRpcXyoSigner = class {
1081
+ static {
1082
+ __name(this, "JsonRpcXyoSigner");
1083
+ }
1084
+ transport;
1085
+ constructor(transport) {
1086
+ this.transport = transport;
1087
+ }
1088
+ async address() {
1089
+ return await this.transport.sendRequest("xyoSigner_address");
1090
+ }
1091
+ async createSignedTransaction(chain, elevatedPayloads, additionalPayloads, nbf, exp, fees, from) {
1092
+ return await this.transport.sendRequest("xyoSigner_createSignedTransaction", [
1093
+ chain,
1094
+ elevatedPayloads,
1095
+ additionalPayloads,
1096
+ nbf,
1097
+ exp,
1098
+ fees,
1099
+ from
1100
+ ]);
1101
+ }
1102
+ };
1103
+
1104
+ // src/provider/signer/MemoryXyoSigner.ts
1105
+ import { buildTransaction } from "@xyo-network/xl1-protocol-sdk";
1106
+ var MemoryXyoSigner = class {
1107
+ static {
1108
+ __name(this, "MemoryXyoSigner");
1109
+ }
1110
+ _account;
1111
+ constructor(account) {
1112
+ this._account = account;
1113
+ }
1114
+ address() {
1115
+ return this._account.address;
1116
+ }
1117
+ async createSignedTransaction(chain, elevatedPayloads, additionalPayloads, nbf, exp, fees, from) {
1118
+ const fromAddress = from ?? this._account.address;
1119
+ const transaction = await buildTransaction(chain, elevatedPayloads, additionalPayloads, this._account, nbf, exp, fromAddress, fees);
1120
+ return transaction[0];
1121
+ }
1122
+ };
1123
+
1124
+ // src/provider/viewer/JsonRpcXyoViewer.ts
1125
+ var JsonRpcXyoViewer = class {
1126
+ static {
1127
+ __name(this, "JsonRpcXyoViewer");
1128
+ }
1129
+ transport;
1130
+ constructor(transport) {
1131
+ this.transport = transport;
1132
+ }
1133
+ async accountBalance(address) {
1134
+ return await this.transport.sendRequest("xyoViewer_accountBalance", [
1135
+ address
1136
+ ]);
1137
+ }
1138
+ async accountHistory(address) {
1139
+ return await this.transport.sendRequest("xyoViewer_accountBalance", [
1140
+ address
1141
+ ]);
1142
+ }
1143
+ async blockByHash(hash) {
1144
+ return await this.transport.sendRequest("xyoViewer_blockByHash", [
1145
+ hash
1146
+ ]);
1147
+ }
1148
+ async blockByNumber(blockNumber) {
1149
+ return await this.transport.sendRequest("xyoViewer_blockByNumber", [
1150
+ blockNumber
1151
+ ]);
1152
+ }
1153
+ async blocksByHash(hash, limit) {
1154
+ return await this.transport.sendRequest("xyoViewer_blocksByHash", [
1155
+ hash,
1156
+ limit
1157
+ ]);
1158
+ }
1159
+ async chainId() {
1160
+ return await this.transport.sendRequest("xyoViewer_chainId");
1161
+ }
1162
+ async currentBlock() {
1163
+ return await this.transport.sendRequest("xyoViewer_currentBlock");
1164
+ }
1165
+ async currentBlockHash() {
1166
+ return await this.transport.sendRequest("xyoViewer_currentBlockHash");
1167
+ }
1168
+ async currentBlockNumber() {
1169
+ return await this.transport.sendRequest("xyoViewer_currentBlockNumber");
1170
+ }
1171
+ async transactionByBlockHashAndIndex(blockHash, transactionIndex) {
1172
+ return await this.transport.sendRequest("xyoViewer_transactionByBlockHashAndIndex", [
1173
+ blockHash,
1174
+ transactionIndex
1175
+ ]);
1176
+ }
1177
+ async transactionByBlockNumberAndIndex(blockNumber, transactionIndex) {
1178
+ return await this.transport.sendRequest("xyoViewer_transactionByBlockNumberAndIndex", [
1179
+ blockNumber,
1180
+ transactionIndex
1181
+ ]);
1182
+ }
1183
+ async transactionByHash(transactionHash) {
1184
+ return await this.transport.sendRequest("xyoViewer_transactionByHash", [
1185
+ transactionHash
1186
+ ]);
1187
+ }
1188
+ };
1189
+
1190
+ // src/provider/provider/confirmTransaction.ts
1191
+ import { delay } from "@xylabs/delay";
1192
+ import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
1193
+ var CONFIRMATION_ATTEMPTS = 20;
1194
+ var DELAY_BETWEEN_ATTEMPTS = 1e3;
1195
+ var confirmTransaction = /* @__PURE__ */ __name(async (provider, txBW, onConfirm, onTimeout) => {
1196
+ const txBWHash = await PayloadBuilder4.hash(txBW);
1197
+ console.log("\u2705 confirming transaction:", txBWHash, "\n");
1198
+ let confirmed = false;
1199
+ let attempts = 0;
1200
+ while (!confirmed) {
1201
+ const tx = await provider.viewer?.transactionByHash(txBWHash);
1202
+ if (tx) {
1203
+ confirmed = true;
1204
+ console.log("\u{1F37B} Transaction confirmed:", txBWHash, "\n");
1205
+ onConfirm?.(txBWHash);
1206
+ } else {
1207
+ attempts++;
1208
+ if (attempts > CONFIRMATION_ATTEMPTS) {
1209
+ console.error(`\u26A0\uFE0F Transaction not confirmed after ${CONFIRMATION_ATTEMPTS} attempts`);
1210
+ onTimeout?.();
1211
+ return;
1212
+ } else {
1213
+ console.log(`\u{1F504} Transaction not confirmed yet, attempt ${attempts}. Retrying...`, "\n");
1214
+ await delay(DELAY_BETWEEN_ATTEMPTS);
1215
+ }
1216
+ }
1217
+ }
1218
+ }, "confirmTransaction");
1219
+
1220
+ // src/provider/provider/RpcXyoProvider.ts
1221
+ var RpcXyoProvider = class extends MemoryXyoProvider {
1222
+ static {
1223
+ __name(this, "RpcXyoProvider");
1224
+ }
1225
+ constructor(params) {
1226
+ const transport = new HttpRpcTransport(params.endpoint, {
1227
+ ...XyoRunnerRpcSchemas,
1228
+ ...XyoViewerRpcSchemas
1229
+ });
1230
+ const signer = params.account ? new MemoryXyoSigner(params.account) : void 0;
1231
+ const runner = new JsonRpcXyoRunner(transport);
1232
+ const viewer = new JsonRpcXyoViewer(transport);
1233
+ super({
1234
+ signer,
1235
+ runner,
1236
+ viewer
1237
+ });
1238
+ }
1239
+ async confirm(tx, onConfirm, onTimeout) {
1240
+ return await confirmTransaction(this, tx, onConfirm, onTimeout);
1241
+ }
1242
+ };
1191
1243
  export {
1192
1244
  AllRpcSchemas,
1193
1245
  CaveatTypesSchema,
@@ -1208,6 +1260,7 @@ export {
1208
1260
  NodeXyoRunner,
1209
1261
  PermissionSchema,
1210
1262
  PostMessageRpcTransport,
1263
+ RpcXyoProvider,
1211
1264
  XyoGatewayRpcSchemas,
1212
1265
  XyoProviderRpcSchemas,
1213
1266
  XyoRunnerRpcSchemas,