@lucid-evolution/provider 0.1.97 → 0.2.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.
package/dist/index.cjs CHANGED
@@ -37,11 +37,103 @@ __export(index_exports, {
37
37
  Kupmios: () => Kupmios,
38
38
  KupmiosError: () => KupmiosError,
39
39
  Maestro: () => Maestro,
40
+ OgmiosJsonRpcError: () => OgmiosJsonRpcError,
40
41
  generateEmulatorAccount: () => generateEmulatorAccount,
41
- generateEmulatorAccountFromPrivateKey: () => generateEmulatorAccountFromPrivateKey
42
+ generateEmulatorAccountFromPrivateKey: () => generateEmulatorAccountFromPrivateKey,
43
+ isEmulatorProvider: () => isEmulatorProvider
42
44
  });
43
45
  module.exports = __toCommonJS(index_exports);
44
46
 
47
+ // src/errors.ts
48
+ var asRecord = (value) => typeof value === "object" && value !== null ? value : void 0;
49
+ var responseStatus = (cause) => {
50
+ const response = asRecord(asRecord(cause)?.response);
51
+ return typeof response?.status === "number" ? response.status : void 0;
52
+ };
53
+ var retryAfterHeaderToMs = (value) => {
54
+ if (value === void 0) return void 0;
55
+ const seconds = Number(value);
56
+ if (Number.isFinite(seconds)) return Math.max(0, seconds * 1e3);
57
+ const timestamp = Date.parse(value);
58
+ return Number.isNaN(timestamp) ? void 0 : Math.max(0, timestamp - Date.now());
59
+ };
60
+ var retryAfter = (cause) => {
61
+ const response = asRecord(asRecord(cause)?.response);
62
+ const headers = asRecord(response?.headers);
63
+ const value = headers?.["retry-after"];
64
+ return retryAfterHeaderToMs(typeof value === "string" ? value : void 0);
65
+ };
66
+ var errorTag = (cause) => {
67
+ const record = asRecord(cause);
68
+ return [record?._tag, record?.name, record?.reason].filter((value) => typeof value === "string").join(" ").toLowerCase();
69
+ };
70
+ var inferKind = (cause, status) => {
71
+ const tag = errorTag(cause);
72
+ if (tag.includes("timeout")) return "timeout";
73
+ if (tag.includes("parse") || tag.includes("decode")) return "decode";
74
+ if (status !== void 0) return "http";
75
+ if (tag.includes("request") || tag.includes("transport")) return "transport";
76
+ return "unknown";
77
+ };
78
+ var inferRetryable = (kind, status) => kind === "timeout" || kind === "transport" || status === 408 || status === 425 || status === 429 || status !== void 0 && status >= 500;
79
+ var KupmiosError = class extends Error {
80
+ _tag = "KupmiosError";
81
+ provider = "Kupmios";
82
+ protocol;
83
+ operation;
84
+ kind;
85
+ status;
86
+ retryable;
87
+ retryAfterMs;
88
+ cause;
89
+ constructor(options) {
90
+ const status = options.status ?? responseStatus(options.cause);
91
+ const kind = options.kind ?? inferKind(options.cause, status);
92
+ const retryable = options.retryable ?? inferRetryable(kind, status);
93
+ const operation = options.operation ?? "unknown";
94
+ const statusSuffix = status === void 0 ? "" : ` (HTTP ${status})`;
95
+ super(
96
+ options.message ?? `${options.protocol ?? "provider"} ${operation} failed${statusSuffix}`,
97
+ {
98
+ cause: options.cause
99
+ }
100
+ );
101
+ this.name = "KupmiosError";
102
+ this.protocol = options.protocol;
103
+ this.operation = operation;
104
+ this.kind = kind;
105
+ this.status = status;
106
+ this.retryable = retryable;
107
+ this.retryAfterMs = options.retryAfterMs ?? retryAfter(options.cause);
108
+ this.cause = options.cause;
109
+ }
110
+ };
111
+ var OgmiosJsonRpcError = class extends KupmiosError {
112
+ _tag = "OgmiosJsonRpcError";
113
+ code;
114
+ data;
115
+ method;
116
+ id;
117
+ constructor(options) {
118
+ const dataSuffix = options.data === void 0 ? "" : `: ${JSON.stringify(options.data)}`;
119
+ super({
120
+ protocol: "ogmios",
121
+ operation: options.operation ?? options.method ?? "unknown",
122
+ kind: "json_rpc",
123
+ status: options.status,
124
+ retryAfterMs: options.retryAfterMs,
125
+ cause: options.cause,
126
+ message: `Ogmios JSON-RPC error ${options.code}: ${options.message}${dataSuffix}`
127
+ });
128
+ this.name = "OgmiosJsonRpcError";
129
+ this.code = options.code;
130
+ this.data = options.data;
131
+ this.method = options.method;
132
+ this.id = options.id;
133
+ }
134
+ };
135
+ var toKupmiosError = (cause, protocol, operation) => cause instanceof KupmiosError ? cause : new KupmiosError({ cause, protocol, operation });
136
+
45
137
  // src/core.ts
46
138
  var CML = __toESM(require("@anastasia-labs/cardano-multiplatform-lib-nodejs"), 1);
47
139
 
@@ -52,7 +144,7 @@ var import_utils2 = require("@lucid-evolution/utils");
52
144
  // package.json
53
145
  var package_default = {
54
146
  name: "@lucid-evolution/provider",
55
- version: "0.1.97",
147
+ version: "0.2.0",
56
148
  description: "",
57
149
  main: "./dist/index.js",
58
150
  types: "./dist/index.d.ts",
@@ -295,18 +387,29 @@ var Blockfrost = class {
295
387
  )
296
388
  );
297
389
  }
298
- async getDelegation(rewardAddress) {
299
- const result = await fetch(`${this.url}/accounts/${rewardAddress}`, {
390
+ async getRewardAccount(rewardAddress) {
391
+ const response = await fetch(`${this.url}/accounts/${rewardAddress}`, {
300
392
  headers: { project_id: this.projectId, lucid }
301
- }).then((res) => res.json());
302
- if (!result || result.error) {
303
- return { poolId: null, rewards: 0n };
393
+ });
394
+ if (response.status === 404) {
395
+ return { registered: false, poolId: null, rewards: 0n };
304
396
  }
397
+ if (!response.ok) {
398
+ throw new Error(
399
+ `Could not fetch reward account from Blockfrost. Received status code: ${response.status}`
400
+ );
401
+ }
402
+ const result = await response.json();
305
403
  return {
404
+ registered: result.active,
306
405
  poolId: result.pool_id || null,
307
406
  rewards: BigInt(result.withdrawable_amount)
308
407
  };
309
408
  }
409
+ async getDelegation(rewardAddress) {
410
+ const { poolId, rewards } = await this.getRewardAccount(rewardAddress);
411
+ return { poolId, rewards };
412
+ }
310
413
  async getDatum(datumHash) {
311
414
  const datum = await fetch(`${this.url}/scripts/datum/${datumHash}/cbor`, {
312
415
  headers: { project_id: this.projectId, lucid }
@@ -330,6 +433,29 @@ var Blockfrost = class {
330
433
  }, checkInterval);
331
434
  });
332
435
  }
436
+ async getTransactionStatus(txHash, options = {}) {
437
+ const response = await fetch(`${this.url}/txs/${txHash}`, {
438
+ headers: { project_id: this.projectId, lucid },
439
+ signal: options.signal
440
+ });
441
+ if (response.status === 404) return { status: "not_found", txHash };
442
+ if (!response.ok) {
443
+ throw new Error(
444
+ `Could not fetch transaction status from Blockfrost. Received status code: ${response.status}`
445
+ );
446
+ }
447
+ const result = await response.json();
448
+ return {
449
+ status: "confirmed",
450
+ txHash,
451
+ confirmation: {
452
+ txHash,
453
+ blockHash: result.block,
454
+ blockHeight: result.block_height,
455
+ slot: result.slot
456
+ }
457
+ };
458
+ }
333
459
  async submitTx(tx) {
334
460
  const result = await fetch(`${this.url}/tx/submit`, {
335
461
  method: "POST",
@@ -488,12 +614,28 @@ var JSONRPCErrorResponseSchema = import_effect2.Schema.Struct({
488
614
  var JSONRPCResponseSchema = (schema) => import_effect2.Schema.Union(JSONRPCSchema(schema), JSONRPCErrorResponseSchema).annotations({
489
615
  identifier: "JSONRPCResponseSchema"
490
616
  });
491
- var getJSONRPCResult = (response) => {
617
+ var getJSONRPCResult = (response, operation, transport) => {
492
618
  if ("error" in response) {
493
- const data = response.error.data === void 0 ? "" : `: ${JSON.stringify(response.error.data)}`;
494
- throw new Error(
495
- `Ogmios JSON-RPC error ${response.error.code}: ${response.error.message}${data}`
496
- );
619
+ throw new OgmiosJsonRpcError({
620
+ code: response.error.code,
621
+ message: response.error.message,
622
+ data: response.error.data,
623
+ method: response.method,
624
+ id: response.id,
625
+ operation,
626
+ status: transport?.status,
627
+ retryAfterMs: retryAfterHeaderToMs(transport?.headers["retry-after"]),
628
+ cause: transport
629
+ });
630
+ }
631
+ if (transport && (transport.status < 200 || transport.status >= 300)) {
632
+ throw new KupmiosError({
633
+ protocol: "ogmios",
634
+ operation: operation ?? response.method ?? "unknown",
635
+ status: transport.status,
636
+ retryAfterMs: retryAfterHeaderToMs(transport.headers["retry-after"]),
637
+ cause: transport
638
+ });
497
639
  }
498
640
  return response.result;
499
641
  };
@@ -636,7 +778,7 @@ var LegacyDelegationSummarySchema = import_effect2.Schema.Struct({
636
778
  deposit: RewardAccountAdaSchema
637
779
  });
638
780
  var RewardAccountSummarySchema = import_effect2.Schema.Struct({
639
- from: import_effect2.Schema.optional(import_effect2.Schema.Literal("key", "script")),
781
+ from: import_effect2.Schema.optional(import_effect2.Schema.Literal("key", "verificationKey", "script")),
640
782
  credential: import_effect2.Schema.optional(import_effect2.Schema.String),
641
783
  stakePool: import_effect2.Schema.optional(import_effect2.Schema.NullOr(import_effect2.Schema.Struct({ id: import_effect2.Schema.String }))),
642
784
  rewards: RewardAccountAdaSchema,
@@ -827,6 +969,33 @@ var makePostAsJson = (url, data, schema, headers) => (0, import_effect4.pipe)(
827
969
  // Prevents resource leaks and ensures clean request termination
828
970
  import_effect4.Effect.scoped
829
971
  );
972
+ var makePostAsJsonResponse = (url, data, schema, headers) => (0, import_effect4.pipe)(
973
+ import_platform.HttpClientRequest.post(url),
974
+ headers ? import_platform.HttpClientRequest.setHeaders(headers) : import_effect4.identity,
975
+ import_platform.HttpClientRequest.bodyJson(data),
976
+ import_effect4.Effect.flatMap(import_platform.HttpClient.execute),
977
+ import_effect4.Effect.flatMap(
978
+ (response) => (0, import_effect4.pipe)(
979
+ import_platform.HttpClientResponse.schemaBodyJson(schema)(response),
980
+ import_effect4.Effect.map((body) => ({
981
+ body,
982
+ status: response.status,
983
+ headers: response.headers
984
+ })),
985
+ import_effect4.Effect.catchAll(
986
+ (cause) => response.status >= 200 && response.status < 300 ? import_effect4.Effect.fail(cause) : import_effect4.Effect.fail(
987
+ new import_platform.HttpClientError.ResponseError({
988
+ response,
989
+ request: response.request,
990
+ reason: "StatusCode",
991
+ description: "non 2xx status code with an invalid JSON response"
992
+ })
993
+ )
994
+ )
995
+ )
996
+ ),
997
+ import_effect4.Effect.scoped
998
+ );
830
999
  var makePostAsUint8Array = (url, data, schema, headers) => (0, import_effect4.pipe)(
831
1000
  // Initiate a POST request to the specified URL
832
1001
  import_platform.HttpClientRequest.post(url),
@@ -848,10 +1017,23 @@ var makePostAsUint8Array = (url, data, schema, headers) => (0, import_effect4.pi
848
1017
 
849
1018
  // src/kupmios.ts
850
1019
  var import_platform2 = require("@effect/platform");
851
- var KupmiosError = class extends import_effect6.Data.TaggedError("KupmiosError") {
852
- get message() {
853
- return `${this.cause}`;
1020
+ var catchProviderError = (protocol, operation) => (effect) => import_effect6.Effect.catchAll(
1021
+ effect,
1022
+ (cause) => import_effect6.Effect.fail(toKupmiosError(cause, protocol, operation))
1023
+ );
1024
+ var runProviderEffect = async (effect, protocol, operation, signal) => {
1025
+ const exit = await import_effect6.Effect.runPromiseExit(effect, { signal });
1026
+ if (import_effect6.Exit.isSuccess(exit)) return exit.value;
1027
+ if (signal?.aborted) {
1028
+ throw new KupmiosError({
1029
+ protocol,
1030
+ operation,
1031
+ kind: "aborted",
1032
+ retryable: false,
1033
+ cause: signal.reason ?? import_effect6.Cause.squash(exit.cause)
1034
+ });
854
1035
  }
1036
+ throw toKupmiosError(import_effect6.Cause.squash(exit.cause), protocol, operation);
855
1037
  };
856
1038
  var Kupmios = class {
857
1039
  kupoUrl;
@@ -872,19 +1054,26 @@ var Kupmios = class {
872
1054
  const schema = JSONRPCResponseSchema(
873
1055
  import_effect5.Schema.Record({ key: import_effect5.Schema.String, value: import_effect5.Schema.Unknown })
874
1056
  );
875
- const response = await (0, import_effect6.pipe)(
876
- makePostAsJson(
877
- this.ogmiosUrl,
878
- data,
879
- schema,
880
- this.headers?.ogmiosHeader
1057
+ const response = await runProviderEffect(
1058
+ (0, import_effect6.pipe)(
1059
+ makePostAsJsonResponse(
1060
+ this.ogmiosUrl,
1061
+ data,
1062
+ schema,
1063
+ this.headers?.ogmiosHeader
1064
+ ),
1065
+ import_effect6.Effect.timeout(1e4),
1066
+ catchProviderError("ogmios", "queryLedgerState/protocolParameters"),
1067
+ import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer)
881
1068
  ),
882
- import_effect6.Effect.timeout(1e4),
883
- import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause })),
884
- import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
885
- import_effect6.Effect.runPromise
1069
+ "ogmios",
1070
+ "queryLedgerState/protocolParameters"
1071
+ );
1072
+ const result = getJSONRPCResult(
1073
+ response.body,
1074
+ data.method,
1075
+ response
886
1076
  );
887
- const result = getJSONRPCResult(response);
888
1077
  const protocolParameters = import_effect5.Schema.decodeUnknownSync(
889
1078
  ProtocolParametersSchema
890
1079
  )(normalizeProtocolParameters(result));
@@ -900,19 +1089,26 @@ var Kupmios = class {
900
1089
  const schema = JSONRPCResponseSchema(
901
1090
  TreasuryAndReservesSchema
902
1091
  );
903
- const response = await (0, import_effect6.pipe)(
904
- makePostAsJson(
905
- this.ogmiosUrl,
906
- data,
907
- schema,
908
- this.headers?.ogmiosHeader
1092
+ const response = await runProviderEffect(
1093
+ (0, import_effect6.pipe)(
1094
+ makePostAsJsonResponse(
1095
+ this.ogmiosUrl,
1096
+ data,
1097
+ schema,
1098
+ this.headers?.ogmiosHeader
1099
+ ),
1100
+ import_effect6.Effect.timeout(1e4),
1101
+ catchProviderError("ogmios", "queryLedgerState/treasuryAndReserves"),
1102
+ import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer)
909
1103
  ),
910
- import_effect6.Effect.timeout(1e4),
911
- import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause })),
912
- import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
913
- import_effect6.Effect.runPromise
1104
+ "ogmios",
1105
+ "queryLedgerState/treasuryAndReserves"
1106
+ );
1107
+ const result = getJSONRPCResult(
1108
+ response.body,
1109
+ data.method,
1110
+ response
914
1111
  );
915
- const result = getJSONRPCResult(response);
916
1112
  return lovelaceAmountToBigInt(result.treasury.ada.lovelace);
917
1113
  }
918
1114
  async getUtxos(addressOrCredential) {
@@ -920,15 +1116,18 @@ var Kupmios = class {
920
1116
  const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
921
1117
  const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent`;
922
1118
  const schema = import_effect5.Schema.Array(UTxOSchema);
923
- const utxos = await (0, import_effect6.pipe)(
924
- makeGet(pattern, schema, this.headers?.kupoHeader),
925
- import_effect6.Effect.flatMap(
926
- (u) => kupmiosUtxosToUtxos(this.kupoUrl, u, this.headers?.kupoHeader)
1119
+ const utxos = await runProviderEffect(
1120
+ (0, import_effect6.pipe)(
1121
+ makeGet(pattern, schema, this.headers?.kupoHeader),
1122
+ import_effect6.Effect.flatMap(
1123
+ (u) => kupmiosUtxosToUtxos(this.kupoUrl, u, this.headers?.kupoHeader)
1124
+ ),
1125
+ import_effect6.Effect.timeout(1e4),
1126
+ catchProviderError("kupo", "getUtxos"),
1127
+ import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer)
927
1128
  ),
928
- import_effect6.Effect.timeout(1e4),
929
- import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause })),
930
- import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
931
- import_effect6.Effect.runPromise
1129
+ "kupo",
1130
+ "getUtxos"
932
1131
  );
933
1132
  return utxos;
934
1133
  }
@@ -938,31 +1137,62 @@ var Kupmios = class {
938
1137
  const { policyId, assetName } = (0, import_utils4.fromUnit)(unit);
939
1138
  const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent&policy_id=${policyId}${assetName ? `&asset_name=${assetName}` : ""}`;
940
1139
  const schema = import_effect5.Schema.Array(UTxOSchema);
941
- const utxos = await (0, import_effect6.pipe)(
942
- makeGet(pattern, schema, this.headers?.kupoHeader),
943
- import_effect6.Effect.flatMap(
944
- (u) => kupmiosUtxosToUtxos(this.kupoUrl, u, this.headers?.kupoHeader)
1140
+ const utxos = await runProviderEffect(
1141
+ (0, import_effect6.pipe)(
1142
+ makeGet(pattern, schema, this.headers?.kupoHeader),
1143
+ import_effect6.Effect.flatMap(
1144
+ (u) => kupmiosUtxosToUtxos(this.kupoUrl, u, this.headers?.kupoHeader)
1145
+ ),
1146
+ import_effect6.Effect.timeout(1e4),
1147
+ catchProviderError("kupo", "getUtxosWithUnit"),
1148
+ import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer)
945
1149
  ),
946
- import_effect6.Effect.timeout(1e4),
947
- import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause })),
948
- import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
949
- import_effect6.Effect.runPromise
1150
+ "kupo",
1151
+ "getUtxosWithUnit"
1152
+ );
1153
+ return utxos.filter((utxo) => (utxo.assets[unit] ?? 0n) > 0n);
1154
+ }
1155
+ async getUtxosWithPolicy(addressOrCredential, policyId) {
1156
+ if (!/^[0-9a-f]{56}$/i.test(policyId)) {
1157
+ throw new TypeError(
1158
+ "policyId must be a 56-character hexadecimal string."
1159
+ );
1160
+ }
1161
+ const normalizedPolicyId = policyId.toLowerCase();
1162
+ const isAddress = typeof addressOrCredential === "string";
1163
+ const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
1164
+ const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent&policy_id=${normalizedPolicyId}`;
1165
+ const schema = import_effect5.Schema.Array(UTxOSchema);
1166
+ return runProviderEffect(
1167
+ (0, import_effect6.pipe)(
1168
+ makeGet(pattern, schema, this.headers?.kupoHeader),
1169
+ import_effect6.Effect.flatMap(
1170
+ (utxos) => kupmiosUtxosToUtxos(this.kupoUrl, utxos, this.headers?.kupoHeader)
1171
+ ),
1172
+ import_effect6.Effect.timeout(1e4),
1173
+ catchProviderError("kupo", "getUtxosWithPolicy"),
1174
+ import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer)
1175
+ ),
1176
+ "kupo",
1177
+ "getUtxosWithPolicy"
950
1178
  );
951
- return utxos;
952
1179
  }
953
1180
  async getUtxoByUnit(unit) {
954
1181
  const { policyId, assetName } = (0, import_utils4.fromUnit)(unit);
955
- const pattern = `${this.kupoUrl}/matches/${policyId}.${assetName ? `${assetName}` : "*"}?unspent`;
1182
+ const pattern = `${this.kupoUrl}/matches/${policyId}.${assetName ?? ""}?unspent`;
956
1183
  const schema = import_effect5.Schema.Array(UTxOSchema);
957
- const utxos = await (0, import_effect6.pipe)(
958
- makeGet(pattern, schema, this.headers?.kupoHeader),
959
- import_effect6.Effect.flatMap(
960
- (u) => kupmiosUtxosToUtxos(this.kupoUrl, u, this.headers?.kupoHeader)
1184
+ const utxos = await runProviderEffect(
1185
+ (0, import_effect6.pipe)(
1186
+ makeGet(pattern, schema, this.headers?.kupoHeader),
1187
+ import_effect6.Effect.flatMap(
1188
+ (u) => kupmiosUtxosToUtxos(this.kupoUrl, u, this.headers?.kupoHeader)
1189
+ ),
1190
+ import_effect6.Effect.timeout(1e4),
1191
+ catchProviderError("kupo", "getUtxoByUnit"),
1192
+ import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer)
961
1193
  ),
962
- import_effect6.Effect.timeout(1e4),
963
- import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause })),
964
- import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
965
- import_effect6.Effect.runPromise
1194
+ "kupo",
1195
+ "getUtxoByUnit"
966
1196
  );
967
1197
  if (utxos.length === 0) {
968
1198
  throw new Error("Unit not found.");
@@ -986,11 +1216,13 @@ var Kupmios = class {
986
1216
  (u) => kupmiosUtxosToUtxos(this.kupoUrl, u, this.headers?.kupoHeader)
987
1217
  ),
988
1218
  import_effect6.Effect.timeout(1e4),
989
- import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause }))
1219
+ catchProviderError("kupo", "getUtxosByOutRef")
990
1220
  )
991
1221
  );
992
- const utxos = await import_effect6.Effect.runPromise(
993
- (0, import_effect6.pipe)(program, import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer))
1222
+ const utxos = await runProviderEffect(
1223
+ (0, import_effect6.pipe)(program, import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer)),
1224
+ "kupo",
1225
+ "getUtxosByOutRef"
994
1226
  );
995
1227
  return import_effect6.Array.flatten(utxos).filter(
996
1228
  (utxo) => outRefs.some(
@@ -998,7 +1230,7 @@ var Kupmios = class {
998
1230
  )
999
1231
  );
1000
1232
  }
1001
- async getDelegation(rewardAddress) {
1233
+ async getRewardAccount(rewardAddress) {
1002
1234
  const data = {
1003
1235
  jsonrpc: "2.0",
1004
1236
  method: "queryLedgerState/rewardAccountSummaries",
@@ -1006,50 +1238,95 @@ var Kupmios = class {
1006
1238
  id: null
1007
1239
  };
1008
1240
  const schema = JSONRPCResponseSchema(Delegation);
1009
- const response = await (0, import_effect6.pipe)(
1010
- makePostAsJson(
1011
- this.ogmiosUrl,
1012
- data,
1013
- schema,
1014
- this.headers?.ogmiosHeader
1241
+ const response = await runProviderEffect(
1242
+ (0, import_effect6.pipe)(
1243
+ makePostAsJsonResponse(
1244
+ this.ogmiosUrl,
1245
+ data,
1246
+ schema,
1247
+ this.headers?.ogmiosHeader
1248
+ ),
1249
+ import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
1250
+ import_effect6.Effect.timeout(1e4),
1251
+ catchProviderError("ogmios", "queryLedgerState/rewardAccountSummaries")
1015
1252
  ),
1016
- import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
1017
- import_effect6.Effect.timeout(1e4),
1018
- import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause })),
1019
- import_effect6.Effect.runPromise
1253
+ "ogmios",
1254
+ "queryLedgerState/rewardAccountSummaries"
1255
+ );
1256
+ const result = getJSONRPCResult(
1257
+ response.body,
1258
+ data.method,
1259
+ response
1020
1260
  );
1021
- const result = getJSONRPCResult(response);
1022
- return toDelegation(result);
1261
+ return toRewardAccountState(result);
1262
+ }
1263
+ async getDelegation(rewardAddress) {
1264
+ const { poolId, rewards } = await this.getRewardAccount(rewardAddress);
1265
+ return { poolId, rewards };
1023
1266
  }
1024
1267
  async getDatum(datumHash) {
1025
1268
  const pattern = `${this.kupoUrl}/datums/${datumHash}`;
1026
1269
  const schema = DatumSchema;
1027
- const result = await (0, import_effect6.pipe)(
1028
- makeGet(pattern, schema, this.headers?.kupoHeader),
1029
- import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
1030
- import_effect6.Effect.timeout(1e4),
1031
- import_effect6.Effect.flatMap(import_effect6.Effect.fromNullable),
1032
- import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause })),
1033
- import_effect6.Effect.runPromise
1270
+ const result = await runProviderEffect(
1271
+ (0, import_effect6.pipe)(
1272
+ makeGet(pattern, schema, this.headers?.kupoHeader),
1273
+ import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
1274
+ import_effect6.Effect.timeout(1e4),
1275
+ import_effect6.Effect.flatMap(import_effect6.Effect.fromNullable),
1276
+ catchProviderError("kupo", "getDatum")
1277
+ ),
1278
+ "kupo",
1279
+ "getDatum"
1034
1280
  );
1035
1281
  return result.datum;
1036
1282
  }
1283
+ async getTransactionStatus(txHash, options = {}) {
1284
+ const pattern = `${this.kupoUrl}/matches/*@${txHash}`;
1285
+ const schema = import_effect5.Schema.Array(UTxOSchema).annotations({
1286
+ identifier: "Array<KupmiosSchema.KupoUTxO>"
1287
+ });
1288
+ const matches = await runProviderEffect(
1289
+ (0, import_effect6.pipe)(
1290
+ makeGet(pattern, schema, this.headers?.kupoHeader),
1291
+ import_effect6.Effect.timeout(1e4),
1292
+ catchProviderError("kupo", "getTransactionStatus"),
1293
+ import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer)
1294
+ ),
1295
+ "kupo",
1296
+ "getTransactionStatus",
1297
+ options.signal
1298
+ );
1299
+ if (matches.length === 0) return { status: "not_found", txHash };
1300
+ const createdAt = matches[0].created_at;
1301
+ return {
1302
+ status: "confirmed",
1303
+ txHash,
1304
+ confirmation: {
1305
+ txHash,
1306
+ blockHash: createdAt.header_hash,
1307
+ slot: createdAt.slot_no
1308
+ }
1309
+ };
1310
+ }
1037
1311
  async awaitTx(txHash, checkInterval = 2e4) {
1038
- const pattern = `${this.kupoUrl}/matches/*@${txHash}?unspent`;
1312
+ const pattern = `${this.kupoUrl}/matches/*@${txHash}`;
1039
1313
  const schema = import_effect5.Schema.Array(UTxOSchema).annotations({
1040
1314
  identifier: "Array<KupmiosSchema.KupoUTxO>"
1041
1315
  });
1042
- const result = await (0, import_effect6.pipe)(
1043
- makeGet(pattern, schema, this.headers?.kupoHeader),
1044
- import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
1045
- import_effect6.Effect.repeat({
1046
- schedule: import_effect6.Schedule.exponential(checkInterval),
1047
- until: (result2) => result2.length > 0
1048
- }),
1049
- import_effect6.Effect.timeout(16e4),
1050
- import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause })),
1051
- import_effect6.Effect.as(true),
1052
- import_effect6.Effect.runPromise
1316
+ const result = await runProviderEffect(
1317
+ (0, import_effect6.pipe)(
1318
+ makeGet(pattern, schema, this.headers?.kupoHeader),
1319
+ import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
1320
+ import_effect6.Effect.repeat({
1321
+ schedule: import_effect6.Schedule.exponential(checkInterval),
1322
+ until: (result2) => result2.length > 0
1323
+ }),
1324
+ import_effect6.Effect.timeout(16e4),
1325
+ catchProviderError("kupo", "awaitTx"),
1326
+ import_effect6.Effect.as(true)
1327
+ ),
1328
+ "kupo",
1329
+ "awaitTx"
1053
1330
  );
1054
1331
  return result;
1055
1332
  }
@@ -1069,19 +1346,26 @@ var Kupmios = class {
1069
1346
  })
1070
1347
  })
1071
1348
  );
1072
- const response = await (0, import_effect6.pipe)(
1073
- makePostAsJson(
1074
- this.ogmiosUrl,
1075
- data,
1076
- schema,
1077
- this.headers?.ogmiosHeader
1349
+ const response = await runProviderEffect(
1350
+ (0, import_effect6.pipe)(
1351
+ makePostAsJsonResponse(
1352
+ this.ogmiosUrl,
1353
+ data,
1354
+ schema,
1355
+ this.headers?.ogmiosHeader
1356
+ ),
1357
+ import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
1358
+ import_effect6.Effect.timeout(1e4),
1359
+ catchProviderError("ogmios", "submitTransaction")
1078
1360
  ),
1079
- import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
1080
- import_effect6.Effect.timeout(1e4),
1081
- import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause })),
1082
- import_effect6.Effect.runPromise
1361
+ "ogmios",
1362
+ "submitTransaction"
1363
+ );
1364
+ const result = getJSONRPCResult(
1365
+ response.body,
1366
+ data.method,
1367
+ response
1083
1368
  );
1084
- const result = getJSONRPCResult(response);
1085
1369
  return result.transaction.id;
1086
1370
  }
1087
1371
  async evaluateTx(tx, additionalUTxOs) {
@@ -1095,19 +1379,26 @@ var Kupmios = class {
1095
1379
  id: null
1096
1380
  };
1097
1381
  const schema = JSONRPCResponseSchema(import_effect5.Schema.Array(RedeemerSchema));
1098
- const response = await (0, import_effect6.pipe)(
1099
- makePostAsJson(
1100
- this.ogmiosUrl,
1101
- data,
1102
- schema,
1103
- this.headers?.ogmiosHeader
1382
+ const response = await runProviderEffect(
1383
+ (0, import_effect6.pipe)(
1384
+ makePostAsJsonResponse(
1385
+ this.ogmiosUrl,
1386
+ data,
1387
+ schema,
1388
+ this.headers?.ogmiosHeader
1389
+ ),
1390
+ import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
1391
+ import_effect6.Effect.timeout(1e4),
1392
+ catchProviderError("ogmios", "evaluateTransaction")
1104
1393
  ),
1105
- import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
1106
- import_effect6.Effect.timeout(1e4),
1107
- import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause })),
1108
- import_effect6.Effect.runPromise
1394
+ "ogmios",
1395
+ "evaluateTransaction"
1396
+ );
1397
+ const result = getJSONRPCResult(
1398
+ response.body,
1399
+ data.method,
1400
+ response
1109
1401
  );
1110
- const result = getJSONRPCResult(response);
1111
1402
  const evalRedeemers = result.map((item) => ({
1112
1403
  ex_units: {
1113
1404
  mem: item.budget.memory,
@@ -1209,15 +1500,13 @@ var toProtocolParameters = (result) => {
1209
1500
  }
1210
1501
  };
1211
1502
  };
1212
- var toDelegation = (result) => {
1213
- if (!result) {
1214
- return { poolId: null, rewards: 0n };
1215
- }
1216
- const delegation = Array.isArray(result) ? result[0] : Object.values(result)[0];
1503
+ var toRewardAccountState = (result) => {
1504
+ const delegation = result ? Array.isArray(result) ? result[0] : Object.values(result)[0] : void 0;
1217
1505
  if (!delegation) {
1218
- return { poolId: null, rewards: 0n };
1506
+ return { registered: false, poolId: null, rewards: 0n };
1219
1507
  }
1220
1508
  return {
1509
+ registered: true,
1221
1510
  poolId: "stakePool" in delegation ? delegation.stakePool?.id || null : delegation.delegate?.id || null,
1222
1511
  rewards: BigInt(delegation.rewards.ada.lovelace)
1223
1512
  };
@@ -1251,6 +1540,12 @@ var import_utils5 = require("@lucid-evolution/utils");
1251
1540
  var import_utils6 = require("@lucid-evolution/utils");
1252
1541
  var import_core_utils2 = require("@lucid-evolution/core-utils");
1253
1542
  var import_wallet = require("@lucid-evolution/wallet");
1543
+ var EMULATOR_PROVIDER_BRAND = Symbol.for(
1544
+ "@lucid-evolution/provider/Emulator"
1545
+ );
1546
+ var isEmulatorProvider = (provider) => Boolean(
1547
+ provider && provider[EMULATOR_PROVIDER_BRAND]
1548
+ );
1254
1549
  function generateEmulatorAccountFromPrivateKey(assets) {
1255
1550
  const privateKey = CML.PrivateKey.generate_ed25519().to_bech32();
1256
1551
  const priv = CML.PrivateKey.from_bech32(privateKey);
@@ -1280,6 +1575,7 @@ function generateEmulatorAccount(assets) {
1280
1575
  };
1281
1576
  }
1282
1577
  var Emulator = class {
1578
+ [EMULATOR_PROVIDER_BRAND] = true;
1283
1579
  ledger;
1284
1580
  mempool = {};
1285
1581
  /**
@@ -1293,6 +1589,7 @@ var Emulator = class {
1293
1589
  protocolParameters;
1294
1590
  datumTable = {};
1295
1591
  treasury;
1592
+ transactionHistory = {};
1296
1593
  constructor(accounts, protocolParameters = import_utils5.PROTOCOL_PARAMETERS_DEFAULT, treasury = 0n) {
1297
1594
  const GENESIS_HASH = "00".repeat(32);
1298
1595
  this.blockHeight = 0;
@@ -1328,12 +1625,27 @@ var Emulator = class {
1328
1625
  now() {
1329
1626
  return this.time;
1330
1627
  }
1628
+ confirmPendingTransactions(blockHeight, slot) {
1629
+ for (const [txHash, status] of Object.entries(this.transactionHistory)) {
1630
+ if (status.status === "pending") {
1631
+ this.transactionHistory[txHash] = {
1632
+ status: "confirmed",
1633
+ blockHeight,
1634
+ slot
1635
+ };
1636
+ }
1637
+ }
1638
+ }
1331
1639
  awaitSlot(length = 1) {
1332
1640
  this.slot += length;
1333
1641
  this.time += length * 1e3;
1334
1642
  const currentHeight = this.blockHeight;
1335
1643
  this.blockHeight = Math.floor(this.slot / 20);
1336
1644
  if (this.blockHeight > currentHeight) {
1645
+ this.confirmPendingTransactions(
1646
+ currentHeight + 1,
1647
+ (currentHeight + 1) * 20
1648
+ );
1337
1649
  for (const [outRef, { utxo, spent }] of Object.entries(this.mempool)) {
1338
1650
  this.ledger[outRef] = { utxo, spent };
1339
1651
  }
@@ -1344,9 +1656,14 @@ var Emulator = class {
1344
1656
  }
1345
1657
  }
1346
1658
  awaitBlock(height = 1) {
1659
+ const previousHeight = this.blockHeight;
1660
+ const previousSlot = this.slot;
1347
1661
  this.blockHeight += height;
1348
1662
  this.slot += height * 20;
1349
1663
  this.time += height * 20 * 1e3;
1664
+ if (height > 0) {
1665
+ this.confirmPendingTransactions(previousHeight + 1, previousSlot + 20);
1666
+ }
1350
1667
  for (const [outRef, { utxo, spent }] of Object.entries(this.mempool)) {
1351
1668
  this.ledger[outRef] = { utxo, spent };
1352
1669
  }
@@ -1356,14 +1673,17 @@ var Emulator = class {
1356
1673
  this.mempool = {};
1357
1674
  }
1358
1675
  getUtxos(addressOrCredential) {
1359
- const utxos = Object.values(this.ledger).flatMap(({ utxo }) => {
1360
- if (typeof addressOrCredential === "string") {
1361
- return addressOrCredential === utxo.address ? utxo : [];
1362
- } else {
1363
- const { paymentCredential } = (0, import_utils6.getAddressDetails)(utxo.address);
1364
- return paymentCredential?.hash === addressOrCredential.hash ? utxo : [];
1676
+ const utxos = Object.values(this.ledger).flatMap(
1677
+ ({ utxo, spent }) => {
1678
+ if (spent) return [];
1679
+ if (typeof addressOrCredential === "string") {
1680
+ return addressOrCredential === utxo.address ? utxo : [];
1681
+ } else {
1682
+ const { paymentCredential } = (0, import_utils6.getAddressDetails)(utxo.address);
1683
+ return paymentCredential?.hash === addressOrCredential.hash ? utxo : [];
1684
+ }
1365
1685
  }
1366
- });
1686
+ );
1367
1687
  return Promise.resolve(utxos);
1368
1688
  }
1369
1689
  getProtocolParameters() {
@@ -1376,32 +1696,44 @@ var Emulator = class {
1376
1696
  return Promise.resolve(this.datumTable[datumHash]);
1377
1697
  }
1378
1698
  getUtxosWithUnit(addressOrCredential, unit) {
1379
- const utxos = Object.values(this.ledger).flatMap(({ utxo }) => {
1380
- if (typeof addressOrCredential === "string") {
1381
- return addressOrCredential === utxo.address && utxo.assets[unit] > 0n ? utxo : [];
1382
- } else {
1383
- const { paymentCredential } = (0, import_utils6.getAddressDetails)(utxo.address);
1384
- return paymentCredential?.hash === addressOrCredential.hash && utxo.assets[unit] > 0n ? utxo : [];
1699
+ const utxos = Object.values(this.ledger).flatMap(
1700
+ ({ utxo, spent }) => {
1701
+ if (spent) return [];
1702
+ if (typeof addressOrCredential === "string") {
1703
+ return addressOrCredential === utxo.address && utxo.assets[unit] > 0n ? utxo : [];
1704
+ } else {
1705
+ const { paymentCredential } = (0, import_utils6.getAddressDetails)(utxo.address);
1706
+ return paymentCredential?.hash === addressOrCredential.hash && utxo.assets[unit] > 0n ? utxo : [];
1707
+ }
1385
1708
  }
1386
- });
1709
+ );
1387
1710
  return Promise.resolve(utxos);
1388
1711
  }
1389
1712
  getUtxosByOutRef(outRefs) {
1390
1713
  return Promise.resolve(
1391
- outRefs.flatMap(
1392
- (outRef) => this.ledger[outRef.txHash + outRef.outputIndex]?.utxo || []
1393
- )
1714
+ outRefs.flatMap((outRef) => {
1715
+ const entry = this.ledger[outRef.txHash + outRef.outputIndex];
1716
+ return entry && !entry.spent ? entry.utxo : [];
1717
+ })
1394
1718
  );
1395
1719
  }
1396
1720
  getUtxoByUnit(unit) {
1397
1721
  const utxos = Object.values(this.ledger).flatMap(
1398
- ({ utxo }) => utxo.assets[unit] > 0n ? utxo : []
1722
+ ({ utxo, spent }) => !spent && utxo.assets[unit] > 0n ? utxo : []
1399
1723
  );
1400
1724
  if (utxos.length > 1) {
1401
1725
  throw new Error("Unit needs to be an NFT or only held by one address.");
1402
1726
  }
1403
1727
  return Promise.resolve(utxos[0]);
1404
1728
  }
1729
+ getRewardAccount(rewardAddress) {
1730
+ const account = this.chain[rewardAddress];
1731
+ return Promise.resolve({
1732
+ registered: account?.registeredStake ?? false,
1733
+ poolId: account?.delegation.poolId ?? null,
1734
+ rewards: account?.delegation.rewards ?? 0n
1735
+ });
1736
+ }
1405
1737
  getDelegation(rewardAddress) {
1406
1738
  return Promise.resolve({
1407
1739
  poolId: this.chain[rewardAddress]?.delegation?.poolId || null,
@@ -1409,12 +1741,34 @@ var Emulator = class {
1409
1741
  });
1410
1742
  }
1411
1743
  awaitTx(txHash) {
1412
- if (this.mempool[txHash + 0]) {
1744
+ if (this.transactionHistory[txHash]?.status === "pending") {
1413
1745
  this.awaitBlock();
1414
1746
  return Promise.resolve(true);
1415
1747
  }
1416
1748
  return Promise.resolve(true);
1417
1749
  }
1750
+ getTransactionStatus(txHash, options = {}) {
1751
+ if (options.signal?.aborted) {
1752
+ return Promise.reject(
1753
+ options.signal.reason instanceof Error ? options.signal.reason : new DOMException("The operation was aborted.", "AbortError")
1754
+ );
1755
+ }
1756
+ const status = this.transactionHistory[txHash];
1757
+ if (!status) return Promise.resolve({ status: "not_found", txHash });
1758
+ if (status.status === "pending") {
1759
+ return Promise.resolve({ status: "pending", txHash });
1760
+ }
1761
+ return Promise.resolve({
1762
+ status: "confirmed",
1763
+ txHash,
1764
+ confirmation: {
1765
+ txHash,
1766
+ blockHeight: status.blockHeight,
1767
+ slot: status.slot,
1768
+ confirmations: this.blockHeight - status.blockHeight + 1
1769
+ }
1770
+ });
1771
+ }
1418
1772
  /**
1419
1773
  * Emulates the behaviour of the reward distribution at epoch boundaries.
1420
1774
  * Stake keys need to be registered and delegated like on a real chain in order to receive rewards.
@@ -2095,6 +2449,7 @@ It does not exist or was already spent.`
2095
2449
  for (const [datumHash, datum] of Object.entries(datumTable)) {
2096
2450
  this.datumTable[datumHash] = datum;
2097
2451
  }
2452
+ this.transactionHistory[txHash] = { status: "pending" };
2098
2453
  return Promise.resolve(txHash);
2099
2454
  }
2100
2455
  async evaluateTx(tx, additionalUTxOs) {
@@ -2346,21 +2701,30 @@ var Maestro = class {
2346
2701
  );
2347
2702
  return utxos.map(this.maestroUtxoToUtxo);
2348
2703
  }
2349
- async getDelegation(rewardAddress) {
2350
- const timestampedResultResponse = await fetch(
2351
- `${this.url}/accounts/${rewardAddress}`,
2352
- { headers: this.commonHeaders() }
2353
- );
2354
- if (!timestampedResultResponse.ok) {
2355
- return { poolId: null, rewards: 0n };
2704
+ async getRewardAccount(rewardAddress) {
2705
+ const response = await fetch(`${this.url}/accounts/${rewardAddress}`, {
2706
+ headers: this.requireAmountsAsStrings(this.commonHeaders())
2707
+ });
2708
+ if (response.status === 404) {
2709
+ return { registered: false, poolId: null, rewards: 0n };
2356
2710
  }
2357
- const timestampedResult = await timestampedResultResponse.json();
2711
+ if (!response.ok) {
2712
+ throw new Error(
2713
+ `Could not fetch reward account from Maestro. Received status code: ${response.status}`
2714
+ );
2715
+ }
2716
+ const timestampedResult = await response.json();
2358
2717
  const result = timestampedResult.data;
2359
2718
  return {
2719
+ registered: result.registered,
2360
2720
  poolId: result.delegated_pool || null,
2361
2721
  rewards: BigInt(result.rewards_available)
2362
2722
  };
2363
2723
  }
2724
+ async getDelegation(rewardAddress) {
2725
+ const { poolId, rewards } = await this.getRewardAccount(rewardAddress);
2726
+ return { poolId, rewards };
2727
+ }
2364
2728
  async getDatum(datumHash) {
2365
2729
  const timestampedResultResponse = await fetch(
2366
2730
  `${this.url}/datums/${datumHash}`,
@@ -2398,6 +2762,42 @@ var Maestro = class {
2398
2762
  }, checkInterval);
2399
2763
  });
2400
2764
  }
2765
+ async getTransactionStatus(txHash, options = {}) {
2766
+ const response = await fetch(`${this.url}/txmanager/${txHash}/state`, {
2767
+ headers: this.commonHeaders(),
2768
+ signal: options.signal
2769
+ });
2770
+ if (response.status === 404) return { status: "not_found", txHash };
2771
+ if (!response.ok) {
2772
+ throw new Error(
2773
+ `Could not fetch transaction status from Maestro. Received status code: ${response.status}`
2774
+ );
2775
+ }
2776
+ const result = await response.json();
2777
+ switch (result.status) {
2778
+ case "pending":
2779
+ return { status: "pending", txHash };
2780
+ case "confirmed":
2781
+ return {
2782
+ status: "confirmed",
2783
+ txHash,
2784
+ confirmation: {
2785
+ txHash,
2786
+ confirmations: result.confirmations
2787
+ }
2788
+ };
2789
+ case "failed":
2790
+ return {
2791
+ status: "failed",
2792
+ txHash,
2793
+ reason: result.reason ?? result.error
2794
+ };
2795
+ default:
2796
+ throw new Error(
2797
+ `Maestro returned an unknown transaction status: ${String(result.status)}`
2798
+ );
2799
+ }
2800
+ }
2401
2801
  async submitTx(tx) {
2402
2802
  let queryUrl = `${this.url}/txmanager`;
2403
2803
  queryUrl += this.turboSubmit ? "/turbosubmit" : "";
@@ -2747,8 +3147,13 @@ var AssetAddressSchema = import_effect7.Schema.Struct({
2747
3147
  quantity: import_effect7.Schema.String
2748
3148
  });
2749
3149
  var AccountInfoSchema = import_effect7.Schema.Struct({
3150
+ status: import_effect7.Schema.Literal("registered", "not registered"),
2750
3151
  delegated_pool: import_effect7.Schema.NullOr(import_effect7.Schema.String),
2751
- rewards_available: import_effect7.Schema.NumberFromString
3152
+ rewards_available: import_effect7.Schema.String
3153
+ });
3154
+ var TxStatusSchema = import_effect7.Schema.Struct({
3155
+ tx_hash: import_effect7.Schema.String,
3156
+ num_confirmations: import_effect7.Schema.NullOr(import_effect7.Schema.Number)
2752
3157
  });
2753
3158
  var DatumInfo = import_effect7.Schema.Struct({
2754
3159
  bytes: import_effect7.Schema.String
@@ -2985,7 +3390,7 @@ var Koios = class {
2985
3390
  return [];
2986
3391
  }
2987
3392
  }
2988
- async getDelegation(rewardAddress) {
3393
+ async getRewardAccount(rewardAddress) {
2989
3394
  const body = {
2990
3395
  _stake_addresses: [rewardAddress]
2991
3396
  };
@@ -3000,18 +3405,24 @@ var Koios = class {
3000
3405
  ),
3001
3406
  // Allows for dependency injection and easier testing
3002
3407
  import_effect8.Effect.provide(import_platform4.FetchHttpClient.layer),
3003
- import_effect8.Effect.flatMap(
3004
- (result2) => result2.length === 0 ? import_effect8.Effect.fail("No Delegation Found by Reward Address") : import_effect8.Effect.succeed(result2[0])
3005
- ),
3006
3408
  import_effect8.Effect.timeout(1e4),
3007
3409
  import_effect8.Effect.catchAllCause((cause) => new KoiosError({ cause })),
3008
3410
  import_effect8.Effect.runPromise
3009
3411
  );
3412
+ const account = result[0];
3413
+ if (!account) {
3414
+ return { registered: false, poolId: null, rewards: 0n };
3415
+ }
3010
3416
  return {
3011
- poolId: result.delegated_pool || null,
3012
- rewards: BigInt(result.rewards_available)
3417
+ registered: account.status === "registered",
3418
+ poolId: account.delegated_pool || null,
3419
+ rewards: BigInt(account.rewards_available)
3013
3420
  };
3014
3421
  }
3422
+ async getDelegation(rewardAddress) {
3423
+ const { poolId, rewards } = await this.getRewardAccount(rewardAddress);
3424
+ return { poolId, rewards };
3425
+ }
3015
3426
  async getDatum(datumHash) {
3016
3427
  const url = `${this.baseUrl}/datum_info`;
3017
3428
  const body = {
@@ -3058,6 +3469,38 @@ var Koios = class {
3058
3469
  );
3059
3470
  return result;
3060
3471
  }
3472
+ async getTransactionStatus(txHash, options = {}) {
3473
+ const url = `${this.baseUrl}/tx_status`;
3474
+ const body = { _tx_hashes: [txHash] };
3475
+ const bearerToken = this.token ? { Authorization: `Bearer ${this.token}` } : void 0;
3476
+ const response = await fetch(url, {
3477
+ method: "POST",
3478
+ headers: { "Content-Type": "application/json", ...bearerToken },
3479
+ body: JSON.stringify(body),
3480
+ signal: options.signal
3481
+ });
3482
+ if (response.status === 404) return { status: "not_found", txHash };
3483
+ if (!response.ok) {
3484
+ throw new Error(
3485
+ `Could not fetch transaction status from Koios. Received status code: ${response.status}`
3486
+ );
3487
+ }
3488
+ const result = import_effect8.Schema.decodeUnknownSync(import_effect8.Schema.Array(TxStatusSchema))(
3489
+ await response.json()
3490
+ );
3491
+ const status = result[0];
3492
+ if (!status || status.num_confirmations === null) {
3493
+ return { status: "not_found", txHash };
3494
+ }
3495
+ return {
3496
+ status: "confirmed",
3497
+ txHash,
3498
+ confirmation: {
3499
+ txHash,
3500
+ confirmations: status.num_confirmations
3501
+ }
3502
+ };
3503
+ }
3061
3504
  async submitTx(tx) {
3062
3505
  const url = `${this.baseUrl}/submittx`;
3063
3506
  const body = (0, import_core_utils4.fromHex)(tx);
@@ -3114,6 +3557,8 @@ var Koios = class {
3114
3557
  Kupmios,
3115
3558
  KupmiosError,
3116
3559
  Maestro,
3560
+ OgmiosJsonRpcError,
3117
3561
  generateEmulatorAccount,
3118
- generateEmulatorAccountFromPrivateKey
3562
+ generateEmulatorAccountFromPrivateKey,
3563
+ isEmulatorProvider
3119
3564
  });