@lucid-evolution/provider 0.2.0 → 0.2.2

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
@@ -144,7 +144,7 @@ var import_utils2 = require("@lucid-evolution/utils");
144
144
  // package.json
145
145
  var package_default = {
146
146
  name: "@lucid-evolution/provider",
147
- version: "0.2.0",
147
+ version: "0.2.2",
148
148
  description: "",
149
149
  main: "./dist/index.js",
150
150
  types: "./dist/index.d.ts",
@@ -882,7 +882,17 @@ var ValueSchema = import_effect3.Schema.Struct({
882
882
  coins: QuantitySchema,
883
883
  assets: import_effect3.Schema.Record({ key: import_effect3.Schema.String, value: QuantitySchema })
884
884
  });
885
- var UTxOSchema = import_effect3.Schema.Struct({
885
+ var PointSchema = import_effect3.Schema.Struct({
886
+ slot_no: import_effect3.Schema.Number,
887
+ header_hash: import_effect3.Schema.String
888
+ });
889
+ var ScriptSchema = import_effect3.Schema.NullOr(
890
+ import_effect3.Schema.Struct({
891
+ language: import_effect3.Schema.Literal("native", "plutus:v1", "plutus:v2", "plutus:v3"),
892
+ script: import_effect3.Schema.String
893
+ })
894
+ );
895
+ var UTxOFields = {
886
896
  transaction_index: import_effect3.Schema.Number,
887
897
  transaction_id: import_effect3.Schema.String,
888
898
  output_index: import_effect3.Schema.Number,
@@ -891,23 +901,15 @@ var UTxOSchema = import_effect3.Schema.Struct({
891
901
  datum_hash: import_effect3.Schema.NullOr(import_effect3.Schema.String),
892
902
  datum_type: import_effect3.Schema.optional(import_effect3.Schema.Literal("hash", "inline")),
893
903
  script_hash: import_effect3.Schema.NullOr(import_effect3.Schema.String),
894
- created_at: import_effect3.Schema.Struct({
895
- slot_no: import_effect3.Schema.Number,
896
- header_hash: import_effect3.Schema.String
897
- }),
898
- spent_at: import_effect3.Schema.NullOr(
899
- import_effect3.Schema.Struct({
900
- slot_no: import_effect3.Schema.Number,
901
- header_hash: import_effect3.Schema.String
902
- })
903
- )
904
+ created_at: PointSchema,
905
+ spent_at: import_effect3.Schema.NullOr(PointSchema)
906
+ };
907
+ var UTxOSchema = import_effect3.Schema.Struct(UTxOFields);
908
+ var ResolvedUTxOSchema = import_effect3.Schema.Struct({
909
+ ...UTxOFields,
910
+ datum: import_effect3.Schema.NullOr(import_effect3.Schema.String),
911
+ script: ScriptSchema
904
912
  });
905
- var ScriptSchema = import_effect3.Schema.NullOr(
906
- import_effect3.Schema.Struct({
907
- language: import_effect3.Schema.Literal("native", "plutus:v1", "plutus:v2", "plutus:v3"),
908
- script: import_effect3.Schema.String
909
- })
910
- );
911
913
  var DatumSchema = import_effect3.Schema.NullOr(import_effect3.Schema.Struct({ datum: import_effect3.Schema.String }));
912
914
  var DelegationSchema = import_effect3.Schema.NullOr(
913
915
  import_effect3.Schema.Record({
@@ -1017,6 +1019,14 @@ var makePostAsUint8Array = (url, data, schema, headers) => (0, import_effect4.pi
1017
1019
 
1018
1020
  // src/kupmios.ts
1019
1021
  var import_platform2 = require("@effect/platform");
1022
+ var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
1023
+ var DEFAULT_AWAIT_TX_TIMEOUT_MS = 16e4;
1024
+ var validateTimeout = (name, timeout) => {
1025
+ if (!Number.isFinite(timeout) || timeout <= 0) {
1026
+ throw new TypeError(`${name} must be a positive finite number.`);
1027
+ }
1028
+ return timeout;
1029
+ };
1020
1030
  var catchProviderError = (protocol, operation) => (effect) => import_effect6.Effect.catchAll(
1021
1031
  effect,
1022
1032
  (cause) => import_effect6.Effect.fail(toKupmiosError(cause, protocol, operation))
@@ -1038,11 +1048,21 @@ var runProviderEffect = async (effect, protocol, operation, signal) => {
1038
1048
  var Kupmios = class {
1039
1049
  kupoUrl;
1040
1050
  ogmiosUrl;
1041
- headers;
1042
- constructor(kupoUrl, ogmiosUrl, headers) {
1051
+ options;
1052
+ requestTimeoutMs;
1053
+ awaitTxTimeoutMs;
1054
+ constructor(kupoUrl, ogmiosUrl, options = {}) {
1043
1055
  this.kupoUrl = kupoUrl;
1044
1056
  this.ogmiosUrl = ogmiosUrl;
1045
- this.headers = headers;
1057
+ this.options = options;
1058
+ this.requestTimeoutMs = validateTimeout(
1059
+ "requestTimeoutMs",
1060
+ options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS
1061
+ );
1062
+ this.awaitTxTimeoutMs = validateTimeout(
1063
+ "awaitTxTimeoutMs",
1064
+ options.awaitTxTimeoutMs ?? DEFAULT_AWAIT_TX_TIMEOUT_MS
1065
+ );
1046
1066
  }
1047
1067
  async getProtocolParameters() {
1048
1068
  const data = {
@@ -1060,9 +1080,9 @@ var Kupmios = class {
1060
1080
  this.ogmiosUrl,
1061
1081
  data,
1062
1082
  schema,
1063
- this.headers?.ogmiosHeader
1083
+ this.options.ogmiosHeader
1064
1084
  ),
1065
- import_effect6.Effect.timeout(1e4),
1085
+ import_effect6.Effect.timeout(this.requestTimeoutMs),
1066
1086
  catchProviderError("ogmios", "queryLedgerState/protocolParameters"),
1067
1087
  import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer)
1068
1088
  ),
@@ -1095,9 +1115,9 @@ var Kupmios = class {
1095
1115
  this.ogmiosUrl,
1096
1116
  data,
1097
1117
  schema,
1098
- this.headers?.ogmiosHeader
1118
+ this.options.ogmiosHeader
1099
1119
  ),
1100
- import_effect6.Effect.timeout(1e4),
1120
+ import_effect6.Effect.timeout(this.requestTimeoutMs),
1101
1121
  catchProviderError("ogmios", "queryLedgerState/treasuryAndReserves"),
1102
1122
  import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer)
1103
1123
  ),
@@ -1114,15 +1134,13 @@ var Kupmios = class {
1114
1134
  async getUtxos(addressOrCredential) {
1115
1135
  const isAddress = typeof addressOrCredential === "string";
1116
1136
  const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
1117
- const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent`;
1118
- const schema = import_effect5.Schema.Array(UTxOSchema);
1137
+ const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent&resolve_hashes`;
1138
+ const schema = import_effect5.Schema.Array(ResolvedUTxOSchema);
1119
1139
  const utxos = await runProviderEffect(
1120
1140
  (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),
1141
+ makeGet(pattern, schema, this.options.kupoHeader),
1142
+ import_effect6.Effect.map(kupmiosUtxosToUtxos),
1143
+ import_effect6.Effect.timeout(this.requestTimeoutMs),
1126
1144
  catchProviderError("kupo", "getUtxos"),
1127
1145
  import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer)
1128
1146
  ),
@@ -1135,15 +1153,13 @@ var Kupmios = class {
1135
1153
  const isAddress = typeof addressOrCredential === "string";
1136
1154
  const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
1137
1155
  const { policyId, assetName } = (0, import_utils4.fromUnit)(unit);
1138
- const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent&policy_id=${policyId}${assetName ? `&asset_name=${assetName}` : ""}`;
1139
- const schema = import_effect5.Schema.Array(UTxOSchema);
1156
+ const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent&resolve_hashes&policy_id=${policyId}${assetName ? `&asset_name=${assetName}` : ""}`;
1157
+ const schema = import_effect5.Schema.Array(ResolvedUTxOSchema);
1140
1158
  const utxos = await runProviderEffect(
1141
1159
  (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),
1160
+ makeGet(pattern, schema, this.options.kupoHeader),
1161
+ import_effect6.Effect.map(kupmiosUtxosToUtxos),
1162
+ import_effect6.Effect.timeout(this.requestTimeoutMs),
1147
1163
  catchProviderError("kupo", "getUtxosWithUnit"),
1148
1164
  import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer)
1149
1165
  ),
@@ -1161,15 +1177,13 @@ var Kupmios = class {
1161
1177
  const normalizedPolicyId = policyId.toLowerCase();
1162
1178
  const isAddress = typeof addressOrCredential === "string";
1163
1179
  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);
1180
+ const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent&resolve_hashes&policy_id=${normalizedPolicyId}`;
1181
+ const schema = import_effect5.Schema.Array(ResolvedUTxOSchema);
1166
1182
  return runProviderEffect(
1167
1183
  (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),
1184
+ makeGet(pattern, schema, this.options.kupoHeader),
1185
+ import_effect6.Effect.map(kupmiosUtxosToUtxos),
1186
+ import_effect6.Effect.timeout(this.requestTimeoutMs),
1173
1187
  catchProviderError("kupo", "getUtxosWithPolicy"),
1174
1188
  import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer)
1175
1189
  ),
@@ -1179,15 +1193,13 @@ var Kupmios = class {
1179
1193
  }
1180
1194
  async getUtxoByUnit(unit) {
1181
1195
  const { policyId, assetName } = (0, import_utils4.fromUnit)(unit);
1182
- const pattern = `${this.kupoUrl}/matches/${policyId}.${assetName ?? ""}?unspent`;
1183
- const schema = import_effect5.Schema.Array(UTxOSchema);
1196
+ const pattern = `${this.kupoUrl}/matches/${policyId}.${assetName ?? ""}?unspent&resolve_hashes`;
1197
+ const schema = import_effect5.Schema.Array(ResolvedUTxOSchema);
1184
1198
  const utxos = await runProviderEffect(
1185
1199
  (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),
1200
+ makeGet(pattern, schema, this.options.kupoHeader),
1201
+ import_effect6.Effect.map(kupmiosUtxosToUtxos),
1202
+ import_effect6.Effect.timeout(this.requestTimeoutMs),
1191
1203
  catchProviderError("kupo", "getUtxoByUnit"),
1192
1204
  import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer)
1193
1205
  ),
@@ -1206,16 +1218,14 @@ var Kupmios = class {
1206
1218
  const queryHashes = [
1207
1219
  ...new Set(outRefs.map((outRef) => outRef.txHash))
1208
1220
  ];
1209
- const mkPattern = (txHash) => `${this.kupoUrl}/matches/*@${txHash}?unspent`;
1210
- const schema = import_effect5.Schema.Array(UTxOSchema);
1221
+ const mkPattern = (txHash) => `${this.kupoUrl}/matches/*@${txHash}?unspent&resolve_hashes`;
1222
+ const schema = import_effect5.Schema.Array(ResolvedUTxOSchema);
1211
1223
  const program = import_effect6.Effect.forEach(
1212
1224
  queryHashes,
1213
1225
  (txHash) => (0, import_effect6.pipe)(
1214
- makeGet(mkPattern(txHash), schema, this.headers?.kupoHeader),
1215
- import_effect6.Effect.flatMap(
1216
- (u) => kupmiosUtxosToUtxos(this.kupoUrl, u, this.headers?.kupoHeader)
1217
- ),
1218
- import_effect6.Effect.timeout(1e4),
1226
+ makeGet(mkPattern(txHash), schema, this.options.kupoHeader),
1227
+ import_effect6.Effect.map(kupmiosUtxosToUtxos),
1228
+ import_effect6.Effect.timeout(this.requestTimeoutMs),
1219
1229
  catchProviderError("kupo", "getUtxosByOutRef")
1220
1230
  )
1221
1231
  );
@@ -1244,10 +1254,10 @@ var Kupmios = class {
1244
1254
  this.ogmiosUrl,
1245
1255
  data,
1246
1256
  schema,
1247
- this.headers?.ogmiosHeader
1257
+ this.options.ogmiosHeader
1248
1258
  ),
1249
1259
  import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
1250
- import_effect6.Effect.timeout(1e4),
1260
+ import_effect6.Effect.timeout(this.requestTimeoutMs),
1251
1261
  catchProviderError("ogmios", "queryLedgerState/rewardAccountSummaries")
1252
1262
  ),
1253
1263
  "ogmios",
@@ -1269,9 +1279,9 @@ var Kupmios = class {
1269
1279
  const schema = DatumSchema;
1270
1280
  const result = await runProviderEffect(
1271
1281
  (0, import_effect6.pipe)(
1272
- makeGet(pattern, schema, this.headers?.kupoHeader),
1282
+ makeGet(pattern, schema, this.options.kupoHeader),
1273
1283
  import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
1274
- import_effect6.Effect.timeout(1e4),
1284
+ import_effect6.Effect.timeout(this.requestTimeoutMs),
1275
1285
  import_effect6.Effect.flatMap(import_effect6.Effect.fromNullable),
1276
1286
  catchProviderError("kupo", "getDatum")
1277
1287
  ),
@@ -1287,8 +1297,8 @@ var Kupmios = class {
1287
1297
  });
1288
1298
  const matches = await runProviderEffect(
1289
1299
  (0, import_effect6.pipe)(
1290
- makeGet(pattern, schema, this.headers?.kupoHeader),
1291
- import_effect6.Effect.timeout(1e4),
1300
+ makeGet(pattern, schema, this.options.kupoHeader),
1301
+ import_effect6.Effect.timeout(this.requestTimeoutMs),
1292
1302
  catchProviderError("kupo", "getTransactionStatus"),
1293
1303
  import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer)
1294
1304
  ),
@@ -1315,13 +1325,13 @@ var Kupmios = class {
1315
1325
  });
1316
1326
  const result = await runProviderEffect(
1317
1327
  (0, import_effect6.pipe)(
1318
- makeGet(pattern, schema, this.headers?.kupoHeader),
1328
+ makeGet(pattern, schema, this.options.kupoHeader),
1319
1329
  import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
1320
1330
  import_effect6.Effect.repeat({
1321
1331
  schedule: import_effect6.Schedule.exponential(checkInterval),
1322
1332
  until: (result2) => result2.length > 0
1323
1333
  }),
1324
- import_effect6.Effect.timeout(16e4),
1334
+ import_effect6.Effect.timeout(this.awaitTxTimeoutMs),
1325
1335
  catchProviderError("kupo", "awaitTx"),
1326
1336
  import_effect6.Effect.as(true)
1327
1337
  ),
@@ -1352,10 +1362,10 @@ var Kupmios = class {
1352
1362
  this.ogmiosUrl,
1353
1363
  data,
1354
1364
  schema,
1355
- this.headers?.ogmiosHeader
1365
+ this.options.ogmiosHeader
1356
1366
  ),
1357
1367
  import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
1358
- import_effect6.Effect.timeout(1e4),
1368
+ import_effect6.Effect.timeout(this.requestTimeoutMs),
1359
1369
  catchProviderError("ogmios", "submitTransaction")
1360
1370
  ),
1361
1371
  "ogmios",
@@ -1385,10 +1395,10 @@ var Kupmios = class {
1385
1395
  this.ogmiosUrl,
1386
1396
  data,
1387
1397
  schema,
1388
- this.headers?.ogmiosHeader
1398
+ this.options.ogmiosHeader
1389
1399
  ),
1390
1400
  import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
1391
- import_effect6.Effect.timeout(1e4),
1401
+ import_effect6.Effect.timeout(this.requestTimeoutMs),
1392
1402
  catchProviderError("ogmios", "evaluateTransaction")
1393
1403
  ),
1394
1404
  "ogmios",
@@ -1410,59 +1420,6 @@ var Kupmios = class {
1410
1420
  return evalRedeemers;
1411
1421
  }
1412
1422
  };
1413
- var getDatumEffect = (kupoUrl, datum_type, datum_hash, kupoHeader) => import_effect6.Effect.gen(function* () {
1414
- if (datum_type === "inline" && datum_hash) {
1415
- const pattern = `${kupoUrl}/datums/${datum_hash}`;
1416
- const schema = DatumSchema;
1417
- return yield* (0, import_effect6.pipe)(
1418
- makeGet(pattern, schema, kupoHeader),
1419
- import_effect6.Effect.flatMap(import_effect6.Effect.fromNullable),
1420
- import_effect6.Effect.map((result) => result.datum),
1421
- import_effect6.Effect.retry(
1422
- import_effect6.Schedule.compose(import_effect6.Schedule.exponential(50), import_effect6.Schedule.recurs(5))
1423
- ),
1424
- import_effect6.Effect.timeout(5e3)
1425
- );
1426
- } else return void 0;
1427
- });
1428
- var getScriptEffect = (kupoUrl, script_hash, kupoHeader) => import_effect6.Effect.gen(function* () {
1429
- if (script_hash) {
1430
- const pattern = `${kupoUrl}/scripts/${script_hash}`;
1431
- const schema = ScriptSchema;
1432
- return yield* (0, import_effect6.pipe)(
1433
- makeGet(pattern, schema, kupoHeader),
1434
- import_effect6.Effect.flatMap(import_effect6.Effect.fromNullable),
1435
- import_effect6.Effect.retry(
1436
- import_effect6.Schedule.compose(import_effect6.Schedule.exponential(50), import_effect6.Schedule.recurs(5))
1437
- ),
1438
- import_effect6.Effect.timeout(5e3),
1439
- import_effect6.Effect.map(({ language, script }) => {
1440
- switch (language) {
1441
- case "native":
1442
- return {
1443
- type: "Native",
1444
- script
1445
- };
1446
- case "plutus:v1":
1447
- return {
1448
- type: "PlutusV1",
1449
- script: (0, import_utils4.applyDoubleCborEncoding)(script)
1450
- };
1451
- case "plutus:v2":
1452
- return {
1453
- type: "PlutusV2",
1454
- script: (0, import_utils4.applyDoubleCborEncoding)(script)
1455
- };
1456
- case "plutus:v3":
1457
- return {
1458
- type: "PlutusV3",
1459
- script: (0, import_utils4.applyDoubleCborEncoding)(script)
1460
- };
1461
- }
1462
- })
1463
- );
1464
- } else return void 0;
1465
- });
1466
1423
  var toAssets = (value) => {
1467
1424
  const assets = { lovelace: BigInt(value.coins) };
1468
1425
  for (const unit of Object.keys(value.assets)) {
@@ -1511,29 +1468,37 @@ var toRewardAccountState = (result) => {
1511
1468
  rewards: BigInt(delegation.rewards.ada.lovelace)
1512
1469
  };
1513
1470
  };
1514
- var kupmiosUtxosToUtxos = (kupoURL, utxos, kupoHeader) => import_effect6.Effect.forEach(
1515
- utxos,
1516
- (utxo) => {
1517
- return (0, import_effect6.pipe)(
1518
- import_effect6.Effect.all([
1519
- getDatumEffect(kupoURL, utxo.datum_type, utxo.datum_hash, kupoHeader),
1520
- getScriptEffect(kupoURL, utxo.script_hash, kupoHeader)
1521
- ]),
1522
- import_effect6.Effect.map(
1523
- ([datum, script]) => ({
1524
- txHash: utxo.transaction_id,
1525
- outputIndex: utxo.output_index,
1526
- address: utxo.address,
1527
- assets: toAssets(utxo.value),
1528
- datumHash: utxo.datum_type === "hash" ? utxo.datum_hash : void 0,
1529
- datum,
1530
- scriptRef: script
1531
- })
1532
- )
1533
- );
1534
- },
1535
- { concurrency: "unbounded" }
1536
- );
1471
+ var toScriptRef = (script) => {
1472
+ if (!script) return void 0;
1473
+ switch (script.language) {
1474
+ case "native":
1475
+ return { type: "Native", script: script.script };
1476
+ case "plutus:v1":
1477
+ return {
1478
+ type: "PlutusV1",
1479
+ script: (0, import_utils4.applyDoubleCborEncoding)(script.script)
1480
+ };
1481
+ case "plutus:v2":
1482
+ return {
1483
+ type: "PlutusV2",
1484
+ script: (0, import_utils4.applyDoubleCborEncoding)(script.script)
1485
+ };
1486
+ case "plutus:v3":
1487
+ return {
1488
+ type: "PlutusV3",
1489
+ script: (0, import_utils4.applyDoubleCborEncoding)(script.script)
1490
+ };
1491
+ }
1492
+ };
1493
+ var kupmiosUtxosToUtxos = (utxos) => utxos.map((utxo) => ({
1494
+ txHash: utxo.transaction_id,
1495
+ outputIndex: utxo.output_index,
1496
+ address: utxo.address,
1497
+ assets: toAssets(utxo.value),
1498
+ datumHash: utxo.datum_type === "hash" ? utxo.datum_hash : void 0,
1499
+ datum: utxo.datum_type === "inline" ? utxo.datum : void 0,
1500
+ scriptRef: toScriptRef(utxo.script)
1501
+ }));
1537
1502
 
1538
1503
  // src/emulator.ts
1539
1504
  var import_utils5 = require("@lucid-evolution/utils");
@@ -2841,7 +2806,7 @@ var Maestro = class {
2841
2806
  address: result.address,
2842
2807
  datumHash: result.datum ? result.datum.type == "inline" ? void 0 : result.datum.hash : void 0,
2843
2808
  datum: result.datum?.bytes,
2844
- scriptRef: toScriptRef(result.reference_script)
2809
+ scriptRef: toScriptRef2(result.reference_script)
2845
2810
  };
2846
2811
  }
2847
2812
  async getAllPagesData(getResponse, qry, paramsGiven, errorMsg) {
@@ -2892,7 +2857,7 @@ var Maestro = class {
2892
2857
  return result;
2893
2858
  }
2894
2859
  };
2895
- var toScriptRef = (reference_script) => {
2860
+ var toScriptRef2 = (reference_script) => {
2896
2861
  if (reference_script && reference_script.bytes) {
2897
2862
  switch (reference_script.type) {
2898
2863
  case "native":
@@ -3174,9 +3139,9 @@ var toUTxO = (koiosUTxO, address) => ({
3174
3139
  address,
3175
3140
  datumHash: koiosUTxO.inline_datum ? void 0 : koiosUTxO.datum_hash || void 0,
3176
3141
  datum: koiosUTxO.inline_datum ? koiosUTxO.inline_datum.bytes : void 0,
3177
- scriptRef: toScriptRef2(koiosUTxO.reference_script)
3142
+ scriptRef: toScriptRef3(koiosUTxO.reference_script)
3178
3143
  });
3179
- var toScriptRef2 = (reference_script) => {
3144
+ var toScriptRef3 = (reference_script) => {
3180
3145
  if (reference_script && reference_script.bytes && reference_script.type) {
3181
3146
  switch (reference_script.type) {
3182
3147
  case "plutusV1":
package/dist/index.d.cts CHANGED
@@ -68,9 +68,19 @@ declare class Blockfrost implements Provider {
68
68
  evaluateTx(tx: Transaction, additionalUTxOs?: UTxO[]): Promise<EvalRedeemer[]>;
69
69
  }
70
70
 
71
+ interface KupmiosOptions {
72
+ readonly ogmiosHeader?: Record<string, string>;
73
+ readonly kupoHeader?: Record<string, string>;
74
+ /** One-shot Kupo and Ogmios request deadline in milliseconds. @default 30000 */
75
+ readonly requestTimeoutMs?: number;
76
+ /** Overall transaction confirmation deadline in milliseconds. @default 160000 */
77
+ readonly awaitTxTimeoutMs?: number;
78
+ }
71
79
  /**
72
80
  * Provides support for interacting with both Kupo and Ogmios APIs.
73
81
  *
82
+ * Requires Kupo v2.10.0 or later.
83
+ *
74
84
  * @example Using Local URLs (No Authentication):
75
85
  * ```typescript
76
86
  * const kupmios = new Kupmios(
@@ -101,11 +111,10 @@ declare class Blockfrost implements Provider {
101
111
  declare class Kupmios implements Provider {
102
112
  private readonly kupoUrl;
103
113
  private readonly ogmiosUrl;
104
- private readonly headers?;
105
- constructor(kupoUrl: string, ogmiosUrl: string, headers?: {
106
- ogmiosHeader?: Record<string, string>;
107
- kupoHeader?: Record<string, string>;
108
- });
114
+ private readonly options;
115
+ private readonly requestTimeoutMs;
116
+ private readonly awaitTxTimeoutMs;
117
+ constructor(kupoUrl: string, ogmiosUrl: string, options?: KupmiosOptions);
109
118
  getProtocolParameters(): Promise<ProtocolParameters>;
110
119
  getTreasury(): Promise<bigint>;
111
120
  getUtxos(addressOrCredential: Address | Credential): Promise<UTxO[]>;
@@ -278,4 +287,4 @@ declare class Koios implements Provider {
278
287
  evaluateTx(tx: Transaction, additionalUTxOs?: UTxO[]): Promise<EvalRedeemer[]>;
279
288
  }
280
289
 
281
- export { Blockfrost, Emulator, type EmulatorAccount, Koios, KoiosError, Kupmios, KupmiosError, type KupmiosErrorOptions, Maestro, type MaestroConfig, type MaestroSupportedNetworks, OgmiosJsonRpcError, type OgmiosJsonRpcErrorOptions, type ProviderErrorKind, type ProviderTransportProtocol, generateEmulatorAccount, generateEmulatorAccountFromPrivateKey, isEmulatorProvider };
290
+ export { Blockfrost, Emulator, type EmulatorAccount, Koios, KoiosError, Kupmios, KupmiosError, type KupmiosErrorOptions, type KupmiosOptions, Maestro, type MaestroConfig, type MaestroSupportedNetworks, OgmiosJsonRpcError, type OgmiosJsonRpcErrorOptions, type ProviderErrorKind, type ProviderTransportProtocol, generateEmulatorAccount, generateEmulatorAccountFromPrivateKey, isEmulatorProvider };
package/dist/index.d.ts CHANGED
@@ -68,9 +68,19 @@ declare class Blockfrost implements Provider {
68
68
  evaluateTx(tx: Transaction, additionalUTxOs?: UTxO[]): Promise<EvalRedeemer[]>;
69
69
  }
70
70
 
71
+ interface KupmiosOptions {
72
+ readonly ogmiosHeader?: Record<string, string>;
73
+ readonly kupoHeader?: Record<string, string>;
74
+ /** One-shot Kupo and Ogmios request deadline in milliseconds. @default 30000 */
75
+ readonly requestTimeoutMs?: number;
76
+ /** Overall transaction confirmation deadline in milliseconds. @default 160000 */
77
+ readonly awaitTxTimeoutMs?: number;
78
+ }
71
79
  /**
72
80
  * Provides support for interacting with both Kupo and Ogmios APIs.
73
81
  *
82
+ * Requires Kupo v2.10.0 or later.
83
+ *
74
84
  * @example Using Local URLs (No Authentication):
75
85
  * ```typescript
76
86
  * const kupmios = new Kupmios(
@@ -101,11 +111,10 @@ declare class Blockfrost implements Provider {
101
111
  declare class Kupmios implements Provider {
102
112
  private readonly kupoUrl;
103
113
  private readonly ogmiosUrl;
104
- private readonly headers?;
105
- constructor(kupoUrl: string, ogmiosUrl: string, headers?: {
106
- ogmiosHeader?: Record<string, string>;
107
- kupoHeader?: Record<string, string>;
108
- });
114
+ private readonly options;
115
+ private readonly requestTimeoutMs;
116
+ private readonly awaitTxTimeoutMs;
117
+ constructor(kupoUrl: string, ogmiosUrl: string, options?: KupmiosOptions);
109
118
  getProtocolParameters(): Promise<ProtocolParameters>;
110
119
  getTreasury(): Promise<bigint>;
111
120
  getUtxos(addressOrCredential: Address | Credential): Promise<UTxO[]>;
@@ -278,4 +287,4 @@ declare class Koios implements Provider {
278
287
  evaluateTx(tx: Transaction, additionalUTxOs?: UTxO[]): Promise<EvalRedeemer[]>;
279
288
  }
280
289
 
281
- export { Blockfrost, Emulator, type EmulatorAccount, Koios, KoiosError, Kupmios, KupmiosError, type KupmiosErrorOptions, Maestro, type MaestroConfig, type MaestroSupportedNetworks, OgmiosJsonRpcError, type OgmiosJsonRpcErrorOptions, type ProviderErrorKind, type ProviderTransportProtocol, generateEmulatorAccount, generateEmulatorAccountFromPrivateKey, isEmulatorProvider };
290
+ export { Blockfrost, Emulator, type EmulatorAccount, Koios, KoiosError, Kupmios, KupmiosError, type KupmiosErrorOptions, type KupmiosOptions, Maestro, type MaestroConfig, type MaestroSupportedNetworks, OgmiosJsonRpcError, type OgmiosJsonRpcErrorOptions, type ProviderErrorKind, type ProviderTransportProtocol, generateEmulatorAccount, generateEmulatorAccountFromPrivateKey, isEmulatorProvider };
package/dist/index.js CHANGED
@@ -101,7 +101,7 @@ import {
101
101
  // package.json
102
102
  var package_default = {
103
103
  name: "@lucid-evolution/provider",
104
- version: "0.2.0",
104
+ version: "0.2.2",
105
105
  description: "",
106
106
  main: "./dist/index.js",
107
107
  types: "./dist/index.d.ts",
@@ -839,7 +839,17 @@ var ValueSchema = S2.Struct({
839
839
  coins: QuantitySchema,
840
840
  assets: S2.Record({ key: S2.String, value: QuantitySchema })
841
841
  });
842
- var UTxOSchema = S2.Struct({
842
+ var PointSchema = S2.Struct({
843
+ slot_no: S2.Number,
844
+ header_hash: S2.String
845
+ });
846
+ var ScriptSchema = S2.NullOr(
847
+ S2.Struct({
848
+ language: S2.Literal("native", "plutus:v1", "plutus:v2", "plutus:v3"),
849
+ script: S2.String
850
+ })
851
+ );
852
+ var UTxOFields = {
843
853
  transaction_index: S2.Number,
844
854
  transaction_id: S2.String,
845
855
  output_index: S2.Number,
@@ -848,23 +858,15 @@ var UTxOSchema = S2.Struct({
848
858
  datum_hash: S2.NullOr(S2.String),
849
859
  datum_type: S2.optional(S2.Literal("hash", "inline")),
850
860
  script_hash: S2.NullOr(S2.String),
851
- created_at: S2.Struct({
852
- slot_no: S2.Number,
853
- header_hash: S2.String
854
- }),
855
- spent_at: S2.NullOr(
856
- S2.Struct({
857
- slot_no: S2.Number,
858
- header_hash: S2.String
859
- })
860
- )
861
+ created_at: PointSchema,
862
+ spent_at: S2.NullOr(PointSchema)
863
+ };
864
+ var UTxOSchema = S2.Struct(UTxOFields);
865
+ var ResolvedUTxOSchema = S2.Struct({
866
+ ...UTxOFields,
867
+ datum: S2.NullOr(S2.String),
868
+ script: ScriptSchema
861
869
  });
862
- var ScriptSchema = S2.NullOr(
863
- S2.Struct({
864
- language: S2.Literal("native", "plutus:v1", "plutus:v2", "plutus:v3"),
865
- script: S2.String
866
- })
867
- );
868
870
  var DatumSchema = S2.NullOr(S2.Struct({ datum: S2.String }));
869
871
  var DelegationSchema = S2.NullOr(
870
872
  S2.Record({
@@ -979,6 +981,14 @@ var makePostAsUint8Array = (url, data, schema, headers) => pipe2(
979
981
 
980
982
  // src/kupmios.ts
981
983
  import { FetchHttpClient } from "@effect/platform";
984
+ var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
985
+ var DEFAULT_AWAIT_TX_TIMEOUT_MS = 16e4;
986
+ var validateTimeout = (name, timeout) => {
987
+ if (!Number.isFinite(timeout) || timeout <= 0) {
988
+ throw new TypeError(`${name} must be a positive finite number.`);
989
+ }
990
+ return timeout;
991
+ };
982
992
  var catchProviderError = (protocol, operation) => (effect) => Effect2.catchAll(
983
993
  effect,
984
994
  (cause) => Effect2.fail(toKupmiosError(cause, protocol, operation))
@@ -1000,11 +1010,21 @@ var runProviderEffect = async (effect, protocol, operation, signal) => {
1000
1010
  var Kupmios = class {
1001
1011
  kupoUrl;
1002
1012
  ogmiosUrl;
1003
- headers;
1004
- constructor(kupoUrl, ogmiosUrl, headers) {
1013
+ options;
1014
+ requestTimeoutMs;
1015
+ awaitTxTimeoutMs;
1016
+ constructor(kupoUrl, ogmiosUrl, options = {}) {
1005
1017
  this.kupoUrl = kupoUrl;
1006
1018
  this.ogmiosUrl = ogmiosUrl;
1007
- this.headers = headers;
1019
+ this.options = options;
1020
+ this.requestTimeoutMs = validateTimeout(
1021
+ "requestTimeoutMs",
1022
+ options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS
1023
+ );
1024
+ this.awaitTxTimeoutMs = validateTimeout(
1025
+ "awaitTxTimeoutMs",
1026
+ options.awaitTxTimeoutMs ?? DEFAULT_AWAIT_TX_TIMEOUT_MS
1027
+ );
1008
1028
  }
1009
1029
  async getProtocolParameters() {
1010
1030
  const data = {
@@ -1022,9 +1042,9 @@ var Kupmios = class {
1022
1042
  this.ogmiosUrl,
1023
1043
  data,
1024
1044
  schema,
1025
- this.headers?.ogmiosHeader
1045
+ this.options.ogmiosHeader
1026
1046
  ),
1027
- Effect2.timeout(1e4),
1047
+ Effect2.timeout(this.requestTimeoutMs),
1028
1048
  catchProviderError("ogmios", "queryLedgerState/protocolParameters"),
1029
1049
  Effect2.provide(FetchHttpClient.layer)
1030
1050
  ),
@@ -1057,9 +1077,9 @@ var Kupmios = class {
1057
1077
  this.ogmiosUrl,
1058
1078
  data,
1059
1079
  schema,
1060
- this.headers?.ogmiosHeader
1080
+ this.options.ogmiosHeader
1061
1081
  ),
1062
- Effect2.timeout(1e4),
1082
+ Effect2.timeout(this.requestTimeoutMs),
1063
1083
  catchProviderError("ogmios", "queryLedgerState/treasuryAndReserves"),
1064
1084
  Effect2.provide(FetchHttpClient.layer)
1065
1085
  ),
@@ -1076,15 +1096,13 @@ var Kupmios = class {
1076
1096
  async getUtxos(addressOrCredential) {
1077
1097
  const isAddress = typeof addressOrCredential === "string";
1078
1098
  const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
1079
- const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent`;
1080
- const schema = S3.Array(UTxOSchema);
1099
+ const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent&resolve_hashes`;
1100
+ const schema = S3.Array(ResolvedUTxOSchema);
1081
1101
  const utxos = await runProviderEffect(
1082
1102
  pipe3(
1083
- makeGet(pattern, schema, this.headers?.kupoHeader),
1084
- Effect2.flatMap(
1085
- (u) => kupmiosUtxosToUtxos(this.kupoUrl, u, this.headers?.kupoHeader)
1086
- ),
1087
- Effect2.timeout(1e4),
1103
+ makeGet(pattern, schema, this.options.kupoHeader),
1104
+ Effect2.map(kupmiosUtxosToUtxos),
1105
+ Effect2.timeout(this.requestTimeoutMs),
1088
1106
  catchProviderError("kupo", "getUtxos"),
1089
1107
  Effect2.provide(FetchHttpClient.layer)
1090
1108
  ),
@@ -1097,15 +1115,13 @@ var Kupmios = class {
1097
1115
  const isAddress = typeof addressOrCredential === "string";
1098
1116
  const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
1099
1117
  const { policyId, assetName } = fromUnit2(unit);
1100
- const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent&policy_id=${policyId}${assetName ? `&asset_name=${assetName}` : ""}`;
1101
- const schema = S3.Array(UTxOSchema);
1118
+ const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent&resolve_hashes&policy_id=${policyId}${assetName ? `&asset_name=${assetName}` : ""}`;
1119
+ const schema = S3.Array(ResolvedUTxOSchema);
1102
1120
  const utxos = await runProviderEffect(
1103
1121
  pipe3(
1104
- makeGet(pattern, schema, this.headers?.kupoHeader),
1105
- Effect2.flatMap(
1106
- (u) => kupmiosUtxosToUtxos(this.kupoUrl, u, this.headers?.kupoHeader)
1107
- ),
1108
- Effect2.timeout(1e4),
1122
+ makeGet(pattern, schema, this.options.kupoHeader),
1123
+ Effect2.map(kupmiosUtxosToUtxos),
1124
+ Effect2.timeout(this.requestTimeoutMs),
1109
1125
  catchProviderError("kupo", "getUtxosWithUnit"),
1110
1126
  Effect2.provide(FetchHttpClient.layer)
1111
1127
  ),
@@ -1123,15 +1139,13 @@ var Kupmios = class {
1123
1139
  const normalizedPolicyId = policyId.toLowerCase();
1124
1140
  const isAddress = typeof addressOrCredential === "string";
1125
1141
  const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
1126
- const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent&policy_id=${normalizedPolicyId}`;
1127
- const schema = S3.Array(UTxOSchema);
1142
+ const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent&resolve_hashes&policy_id=${normalizedPolicyId}`;
1143
+ const schema = S3.Array(ResolvedUTxOSchema);
1128
1144
  return runProviderEffect(
1129
1145
  pipe3(
1130
- makeGet(pattern, schema, this.headers?.kupoHeader),
1131
- Effect2.flatMap(
1132
- (utxos) => kupmiosUtxosToUtxos(this.kupoUrl, utxos, this.headers?.kupoHeader)
1133
- ),
1134
- Effect2.timeout(1e4),
1146
+ makeGet(pattern, schema, this.options.kupoHeader),
1147
+ Effect2.map(kupmiosUtxosToUtxos),
1148
+ Effect2.timeout(this.requestTimeoutMs),
1135
1149
  catchProviderError("kupo", "getUtxosWithPolicy"),
1136
1150
  Effect2.provide(FetchHttpClient.layer)
1137
1151
  ),
@@ -1141,15 +1155,13 @@ var Kupmios = class {
1141
1155
  }
1142
1156
  async getUtxoByUnit(unit) {
1143
1157
  const { policyId, assetName } = fromUnit2(unit);
1144
- const pattern = `${this.kupoUrl}/matches/${policyId}.${assetName ?? ""}?unspent`;
1145
- const schema = S3.Array(UTxOSchema);
1158
+ const pattern = `${this.kupoUrl}/matches/${policyId}.${assetName ?? ""}?unspent&resolve_hashes`;
1159
+ const schema = S3.Array(ResolvedUTxOSchema);
1146
1160
  const utxos = await runProviderEffect(
1147
1161
  pipe3(
1148
- makeGet(pattern, schema, this.headers?.kupoHeader),
1149
- Effect2.flatMap(
1150
- (u) => kupmiosUtxosToUtxos(this.kupoUrl, u, this.headers?.kupoHeader)
1151
- ),
1152
- Effect2.timeout(1e4),
1162
+ makeGet(pattern, schema, this.options.kupoHeader),
1163
+ Effect2.map(kupmiosUtxosToUtxos),
1164
+ Effect2.timeout(this.requestTimeoutMs),
1153
1165
  catchProviderError("kupo", "getUtxoByUnit"),
1154
1166
  Effect2.provide(FetchHttpClient.layer)
1155
1167
  ),
@@ -1168,16 +1180,14 @@ var Kupmios = class {
1168
1180
  const queryHashes = [
1169
1181
  ...new Set(outRefs.map((outRef) => outRef.txHash))
1170
1182
  ];
1171
- const mkPattern = (txHash) => `${this.kupoUrl}/matches/*@${txHash}?unspent`;
1172
- const schema = S3.Array(UTxOSchema);
1183
+ const mkPattern = (txHash) => `${this.kupoUrl}/matches/*@${txHash}?unspent&resolve_hashes`;
1184
+ const schema = S3.Array(ResolvedUTxOSchema);
1173
1185
  const program = Effect2.forEach(
1174
1186
  queryHashes,
1175
1187
  (txHash) => pipe3(
1176
- makeGet(mkPattern(txHash), schema, this.headers?.kupoHeader),
1177
- Effect2.flatMap(
1178
- (u) => kupmiosUtxosToUtxos(this.kupoUrl, u, this.headers?.kupoHeader)
1179
- ),
1180
- Effect2.timeout(1e4),
1188
+ makeGet(mkPattern(txHash), schema, this.options.kupoHeader),
1189
+ Effect2.map(kupmiosUtxosToUtxos),
1190
+ Effect2.timeout(this.requestTimeoutMs),
1181
1191
  catchProviderError("kupo", "getUtxosByOutRef")
1182
1192
  )
1183
1193
  );
@@ -1206,10 +1216,10 @@ var Kupmios = class {
1206
1216
  this.ogmiosUrl,
1207
1217
  data,
1208
1218
  schema,
1209
- this.headers?.ogmiosHeader
1219
+ this.options.ogmiosHeader
1210
1220
  ),
1211
1221
  Effect2.provide(FetchHttpClient.layer),
1212
- Effect2.timeout(1e4),
1222
+ Effect2.timeout(this.requestTimeoutMs),
1213
1223
  catchProviderError("ogmios", "queryLedgerState/rewardAccountSummaries")
1214
1224
  ),
1215
1225
  "ogmios",
@@ -1231,9 +1241,9 @@ var Kupmios = class {
1231
1241
  const schema = DatumSchema;
1232
1242
  const result = await runProviderEffect(
1233
1243
  pipe3(
1234
- makeGet(pattern, schema, this.headers?.kupoHeader),
1244
+ makeGet(pattern, schema, this.options.kupoHeader),
1235
1245
  Effect2.provide(FetchHttpClient.layer),
1236
- Effect2.timeout(1e4),
1246
+ Effect2.timeout(this.requestTimeoutMs),
1237
1247
  Effect2.flatMap(Effect2.fromNullable),
1238
1248
  catchProviderError("kupo", "getDatum")
1239
1249
  ),
@@ -1249,8 +1259,8 @@ var Kupmios = class {
1249
1259
  });
1250
1260
  const matches = await runProviderEffect(
1251
1261
  pipe3(
1252
- makeGet(pattern, schema, this.headers?.kupoHeader),
1253
- Effect2.timeout(1e4),
1262
+ makeGet(pattern, schema, this.options.kupoHeader),
1263
+ Effect2.timeout(this.requestTimeoutMs),
1254
1264
  catchProviderError("kupo", "getTransactionStatus"),
1255
1265
  Effect2.provide(FetchHttpClient.layer)
1256
1266
  ),
@@ -1277,13 +1287,13 @@ var Kupmios = class {
1277
1287
  });
1278
1288
  const result = await runProviderEffect(
1279
1289
  pipe3(
1280
- makeGet(pattern, schema, this.headers?.kupoHeader),
1290
+ makeGet(pattern, schema, this.options.kupoHeader),
1281
1291
  Effect2.provide(FetchHttpClient.layer),
1282
1292
  Effect2.repeat({
1283
1293
  schedule: Schedule.exponential(checkInterval),
1284
1294
  until: (result2) => result2.length > 0
1285
1295
  }),
1286
- Effect2.timeout(16e4),
1296
+ Effect2.timeout(this.awaitTxTimeoutMs),
1287
1297
  catchProviderError("kupo", "awaitTx"),
1288
1298
  Effect2.as(true)
1289
1299
  ),
@@ -1314,10 +1324,10 @@ var Kupmios = class {
1314
1324
  this.ogmiosUrl,
1315
1325
  data,
1316
1326
  schema,
1317
- this.headers?.ogmiosHeader
1327
+ this.options.ogmiosHeader
1318
1328
  ),
1319
1329
  Effect2.provide(FetchHttpClient.layer),
1320
- Effect2.timeout(1e4),
1330
+ Effect2.timeout(this.requestTimeoutMs),
1321
1331
  catchProviderError("ogmios", "submitTransaction")
1322
1332
  ),
1323
1333
  "ogmios",
@@ -1347,10 +1357,10 @@ var Kupmios = class {
1347
1357
  this.ogmiosUrl,
1348
1358
  data,
1349
1359
  schema,
1350
- this.headers?.ogmiosHeader
1360
+ this.options.ogmiosHeader
1351
1361
  ),
1352
1362
  Effect2.provide(FetchHttpClient.layer),
1353
- Effect2.timeout(1e4),
1363
+ Effect2.timeout(this.requestTimeoutMs),
1354
1364
  catchProviderError("ogmios", "evaluateTransaction")
1355
1365
  ),
1356
1366
  "ogmios",
@@ -1372,59 +1382,6 @@ var Kupmios = class {
1372
1382
  return evalRedeemers;
1373
1383
  }
1374
1384
  };
1375
- var getDatumEffect = (kupoUrl, datum_type, datum_hash, kupoHeader) => Effect2.gen(function* () {
1376
- if (datum_type === "inline" && datum_hash) {
1377
- const pattern = `${kupoUrl}/datums/${datum_hash}`;
1378
- const schema = DatumSchema;
1379
- return yield* pipe3(
1380
- makeGet(pattern, schema, kupoHeader),
1381
- Effect2.flatMap(Effect2.fromNullable),
1382
- Effect2.map((result) => result.datum),
1383
- Effect2.retry(
1384
- Schedule.compose(Schedule.exponential(50), Schedule.recurs(5))
1385
- ),
1386
- Effect2.timeout(5e3)
1387
- );
1388
- } else return void 0;
1389
- });
1390
- var getScriptEffect = (kupoUrl, script_hash, kupoHeader) => Effect2.gen(function* () {
1391
- if (script_hash) {
1392
- const pattern = `${kupoUrl}/scripts/${script_hash}`;
1393
- const schema = ScriptSchema;
1394
- return yield* pipe3(
1395
- makeGet(pattern, schema, kupoHeader),
1396
- Effect2.flatMap(Effect2.fromNullable),
1397
- Effect2.retry(
1398
- Schedule.compose(Schedule.exponential(50), Schedule.recurs(5))
1399
- ),
1400
- Effect2.timeout(5e3),
1401
- Effect2.map(({ language, script }) => {
1402
- switch (language) {
1403
- case "native":
1404
- return {
1405
- type: "Native",
1406
- script
1407
- };
1408
- case "plutus:v1":
1409
- return {
1410
- type: "PlutusV1",
1411
- script: applyDoubleCborEncoding2(script)
1412
- };
1413
- case "plutus:v2":
1414
- return {
1415
- type: "PlutusV2",
1416
- script: applyDoubleCborEncoding2(script)
1417
- };
1418
- case "plutus:v3":
1419
- return {
1420
- type: "PlutusV3",
1421
- script: applyDoubleCborEncoding2(script)
1422
- };
1423
- }
1424
- })
1425
- );
1426
- } else return void 0;
1427
- });
1428
1385
  var toAssets = (value) => {
1429
1386
  const assets = { lovelace: BigInt(value.coins) };
1430
1387
  for (const unit of Object.keys(value.assets)) {
@@ -1473,29 +1430,37 @@ var toRewardAccountState = (result) => {
1473
1430
  rewards: BigInt(delegation.rewards.ada.lovelace)
1474
1431
  };
1475
1432
  };
1476
- var kupmiosUtxosToUtxos = (kupoURL, utxos, kupoHeader) => Effect2.forEach(
1477
- utxos,
1478
- (utxo) => {
1479
- return pipe3(
1480
- Effect2.all([
1481
- getDatumEffect(kupoURL, utxo.datum_type, utxo.datum_hash, kupoHeader),
1482
- getScriptEffect(kupoURL, utxo.script_hash, kupoHeader)
1483
- ]),
1484
- Effect2.map(
1485
- ([datum, script]) => ({
1486
- txHash: utxo.transaction_id,
1487
- outputIndex: utxo.output_index,
1488
- address: utxo.address,
1489
- assets: toAssets(utxo.value),
1490
- datumHash: utxo.datum_type === "hash" ? utxo.datum_hash : void 0,
1491
- datum,
1492
- scriptRef: script
1493
- })
1494
- )
1495
- );
1496
- },
1497
- { concurrency: "unbounded" }
1498
- );
1433
+ var toScriptRef = (script) => {
1434
+ if (!script) return void 0;
1435
+ switch (script.language) {
1436
+ case "native":
1437
+ return { type: "Native", script: script.script };
1438
+ case "plutus:v1":
1439
+ return {
1440
+ type: "PlutusV1",
1441
+ script: applyDoubleCborEncoding2(script.script)
1442
+ };
1443
+ case "plutus:v2":
1444
+ return {
1445
+ type: "PlutusV2",
1446
+ script: applyDoubleCborEncoding2(script.script)
1447
+ };
1448
+ case "plutus:v3":
1449
+ return {
1450
+ type: "PlutusV3",
1451
+ script: applyDoubleCborEncoding2(script.script)
1452
+ };
1453
+ }
1454
+ };
1455
+ var kupmiosUtxosToUtxos = (utxos) => utxos.map((utxo) => ({
1456
+ txHash: utxo.transaction_id,
1457
+ outputIndex: utxo.output_index,
1458
+ address: utxo.address,
1459
+ assets: toAssets(utxo.value),
1460
+ datumHash: utxo.datum_type === "hash" ? utxo.datum_hash : void 0,
1461
+ datum: utxo.datum_type === "inline" ? utxo.datum : void 0,
1462
+ scriptRef: toScriptRef(utxo.script)
1463
+ }));
1499
1464
 
1500
1465
  // src/emulator.ts
1501
1466
  import {
@@ -2811,7 +2776,7 @@ var Maestro = class {
2811
2776
  address: result.address,
2812
2777
  datumHash: result.datum ? result.datum.type == "inline" ? void 0 : result.datum.hash : void 0,
2813
2778
  datum: result.datum?.bytes,
2814
- scriptRef: toScriptRef(result.reference_script)
2779
+ scriptRef: toScriptRef2(result.reference_script)
2815
2780
  };
2816
2781
  }
2817
2782
  async getAllPagesData(getResponse, qry, paramsGiven, errorMsg) {
@@ -2862,7 +2827,7 @@ var Maestro = class {
2862
2827
  return result;
2863
2828
  }
2864
2829
  };
2865
- var toScriptRef = (reference_script) => {
2830
+ var toScriptRef2 = (reference_script) => {
2866
2831
  if (reference_script && reference_script.bytes) {
2867
2832
  switch (reference_script.type) {
2868
2833
  case "native":
@@ -3144,9 +3109,9 @@ var toUTxO = (koiosUTxO, address) => ({
3144
3109
  address,
3145
3110
  datumHash: koiosUTxO.inline_datum ? void 0 : koiosUTxO.datum_hash || void 0,
3146
3111
  datum: koiosUTxO.inline_datum ? koiosUTxO.inline_datum.bytes : void 0,
3147
- scriptRef: toScriptRef2(koiosUTxO.reference_script)
3112
+ scriptRef: toScriptRef3(koiosUTxO.reference_script)
3148
3113
  });
3149
- var toScriptRef2 = (reference_script) => {
3114
+ var toScriptRef3 = (reference_script) => {
3150
3115
  if (reference_script && reference_script.bytes && reference_script.type) {
3151
3116
  switch (reference_script.type) {
3152
3117
  case "plutusV1":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lucid-evolution/provider",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -32,8 +32,8 @@
32
32
  "effect": "^3.11.7",
33
33
  "@lucid-evolution/core-types": "0.3.0",
34
34
  "@lucid-evolution/core-utils": "0.1.16",
35
- "@lucid-evolution/utils": "0.1.72",
36
- "@lucid-evolution/wallet": "0.2.0"
35
+ "@lucid-evolution/utils": "0.1.73",
36
+ "@lucid-evolution/wallet": "0.2.1"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/node": "^20.12.8",