@lucid-evolution/utils 0.1.7 → 0.1.9
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 +37 -25
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +37 -25
- package/package.json +11 -7
package/dist/index.cjs
CHANGED
|
@@ -422,15 +422,21 @@ function getAddressDetails(address) {
|
|
|
422
422
|
function createCostModels(costModels) {
|
|
423
423
|
const costmdls = CML.CostModels.new();
|
|
424
424
|
const costmdlV1 = CML.IntList.new();
|
|
425
|
-
Object.values(costModels.PlutusV1)
|
|
426
|
-
|
|
427
|
-
|
|
425
|
+
for (const cost of Object.values(costModels.PlutusV1)) {
|
|
426
|
+
const int = CML.Int.from_str(cost.toString());
|
|
427
|
+
costmdlV1.add(int);
|
|
428
|
+
int.free();
|
|
429
|
+
}
|
|
428
430
|
costmdls.set_plutus_v1(costmdlV1);
|
|
431
|
+
costmdlV1.free();
|
|
429
432
|
const costmdlV2 = CML.IntList.new();
|
|
430
|
-
Object.values(costModels.PlutusV2)
|
|
431
|
-
|
|
432
|
-
|
|
433
|
+
for (const cost of Object.values(costModels.PlutusV2)) {
|
|
434
|
+
const int = CML.Int.from_str(cost.toString());
|
|
435
|
+
costmdlV2.add(int);
|
|
436
|
+
int.free();
|
|
437
|
+
}
|
|
433
438
|
costmdls.set_plutus_v2(costmdlV2);
|
|
439
|
+
costmdlV2.free();
|
|
434
440
|
return costmdls;
|
|
435
441
|
}
|
|
436
442
|
var PROTOCOL_PARAMETERS_DEFAULT = {
|
|
@@ -983,21 +989,24 @@ function addAssets(...assets) {
|
|
|
983
989
|
|
|
984
990
|
// src/utxo.ts
|
|
985
991
|
var utxoToTransactionOutput = (utxo) => {
|
|
986
|
-
const
|
|
992
|
+
const buildDatum = (utxo2, builder) => {
|
|
987
993
|
if (utxo2.datumHash)
|
|
988
|
-
return
|
|
994
|
+
return builder.with_data(
|
|
995
|
+
CML.DatumOption.new_hash(CML.DatumHash.from_hex(utxo2.datumHash))
|
|
996
|
+
);
|
|
989
997
|
if (utxo2.datum)
|
|
990
|
-
return
|
|
991
|
-
CML.PlutusData.from_cbor_hex(utxo2.datum)
|
|
998
|
+
return builder.with_data(
|
|
999
|
+
CML.DatumOption.new_datum(CML.PlutusData.from_cbor_hex(utxo2.datum))
|
|
992
1000
|
);
|
|
993
|
-
return
|
|
1001
|
+
return builder;
|
|
994
1002
|
};
|
|
995
|
-
|
|
996
|
-
CML.
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1003
|
+
const buildOutput = (utxo2) => {
|
|
1004
|
+
const builder = CML.TransactionOutputBuilder.new().with_address(
|
|
1005
|
+
CML.Address.from_bech32(utxo2.address)
|
|
1006
|
+
);
|
|
1007
|
+
return utxo2.scriptRef ? buildDatum(utxo2, builder).with_reference_script(toScriptRef(utxo2.scriptRef)).next() : buildDatum(utxo2, builder).next();
|
|
1008
|
+
};
|
|
1009
|
+
return buildOutput(utxo).with_value(assetsToValue(utxo.assets)).build().output();
|
|
1001
1010
|
};
|
|
1002
1011
|
var utxoToTransactionInput = (utxo) => {
|
|
1003
1012
|
return CML.TransactionInput.new(
|
|
@@ -1005,12 +1014,14 @@ var utxoToTransactionInput = (utxo) => {
|
|
|
1005
1014
|
BigInt(utxo.outputIndex)
|
|
1006
1015
|
);
|
|
1007
1016
|
};
|
|
1008
|
-
|
|
1009
|
-
|
|
1017
|
+
var utxoToCore = (utxo) => {
|
|
1018
|
+
const out = utxoToTransactionOutput(utxo);
|
|
1019
|
+
const utxoCore = CML.TransactionUnspentOutput.new(
|
|
1010
1020
|
utxoToTransactionInput(utxo),
|
|
1011
|
-
|
|
1021
|
+
out
|
|
1012
1022
|
);
|
|
1013
|
-
|
|
1023
|
+
return utxoCore;
|
|
1024
|
+
};
|
|
1014
1025
|
function utxosToCores(utxos) {
|
|
1015
1026
|
const result = [];
|
|
1016
1027
|
for (const utxo of utxos) {
|
|
@@ -1019,12 +1030,13 @@ function utxosToCores(utxos) {
|
|
|
1019
1030
|
return result;
|
|
1020
1031
|
}
|
|
1021
1032
|
function coreToUtxo(coreUtxo) {
|
|
1022
|
-
|
|
1033
|
+
const out = CML.TransactionOutput.from_cbor_hex(coreUtxo.to_cbor_hex());
|
|
1034
|
+
const utxo = {
|
|
1023
1035
|
...coreToOutRef(CML.TransactionInput.from_cbor_hex(coreUtxo.to_cbor_hex())),
|
|
1024
|
-
...coreToTxOutput(
|
|
1025
|
-
CML.TransactionOutput.from_cbor_hex(coreUtxo.to_cbor_hex())
|
|
1026
|
-
)
|
|
1036
|
+
...coreToTxOutput(out)
|
|
1027
1037
|
};
|
|
1038
|
+
out.free();
|
|
1039
|
+
return utxo;
|
|
1028
1040
|
}
|
|
1029
1041
|
function coresToUtxos(utxos) {
|
|
1030
1042
|
const result = [];
|
package/dist/index.d.cts
CHANGED
|
@@ -49,7 +49,7 @@ declare function slotToUnixTime(network: Network, slot: Slot): UnixTime;
|
|
|
49
49
|
|
|
50
50
|
declare const utxoToTransactionOutput: (utxo: UTxO) => CML.TransactionOutput;
|
|
51
51
|
declare const utxoToTransactionInput: (utxo: UTxO) => CML.TransactionInput;
|
|
52
|
-
declare
|
|
52
|
+
declare const utxoToCore: (utxo: UTxO) => CML.TransactionUnspentOutput;
|
|
53
53
|
declare function utxosToCores(utxos: UTxO[]): CML.TransactionUnspentOutput[];
|
|
54
54
|
declare function coreToUtxo(coreUtxo: CML.TransactionUnspentOutput): UTxO;
|
|
55
55
|
declare function coresToUtxos(utxos: CML.TransactionUnspentOutput[]): UTxO[];
|
package/dist/index.d.ts
CHANGED
|
@@ -49,7 +49,7 @@ declare function slotToUnixTime(network: Network, slot: Slot): UnixTime;
|
|
|
49
49
|
|
|
50
50
|
declare const utxoToTransactionOutput: (utxo: UTxO) => CML.TransactionOutput;
|
|
51
51
|
declare const utxoToTransactionInput: (utxo: UTxO) => CML.TransactionInput;
|
|
52
|
-
declare
|
|
52
|
+
declare const utxoToCore: (utxo: UTxO) => CML.TransactionUnspentOutput;
|
|
53
53
|
declare function utxosToCores(utxos: UTxO[]): CML.TransactionUnspentOutput[];
|
|
54
54
|
declare function coreToUtxo(coreUtxo: CML.TransactionUnspentOutput): UTxO;
|
|
55
55
|
declare function coresToUtxos(utxos: CML.TransactionUnspentOutput[]): UTxO[];
|
package/dist/index.js
CHANGED
|
@@ -342,15 +342,21 @@ function getAddressDetails(address) {
|
|
|
342
342
|
function createCostModels(costModels) {
|
|
343
343
|
const costmdls = CML.CostModels.new();
|
|
344
344
|
const costmdlV1 = CML.IntList.new();
|
|
345
|
-
Object.values(costModels.PlutusV1)
|
|
346
|
-
|
|
347
|
-
|
|
345
|
+
for (const cost of Object.values(costModels.PlutusV1)) {
|
|
346
|
+
const int = CML.Int.from_str(cost.toString());
|
|
347
|
+
costmdlV1.add(int);
|
|
348
|
+
int.free();
|
|
349
|
+
}
|
|
348
350
|
costmdls.set_plutus_v1(costmdlV1);
|
|
351
|
+
costmdlV1.free();
|
|
349
352
|
const costmdlV2 = CML.IntList.new();
|
|
350
|
-
Object.values(costModels.PlutusV2)
|
|
351
|
-
|
|
352
|
-
|
|
353
|
+
for (const cost of Object.values(costModels.PlutusV2)) {
|
|
354
|
+
const int = CML.Int.from_str(cost.toString());
|
|
355
|
+
costmdlV2.add(int);
|
|
356
|
+
int.free();
|
|
357
|
+
}
|
|
353
358
|
costmdls.set_plutus_v2(costmdlV2);
|
|
359
|
+
costmdlV2.free();
|
|
354
360
|
return costmdls;
|
|
355
361
|
}
|
|
356
362
|
var PROTOCOL_PARAMETERS_DEFAULT = {
|
|
@@ -907,21 +913,24 @@ function addAssets(...assets) {
|
|
|
907
913
|
|
|
908
914
|
// src/utxo.ts
|
|
909
915
|
var utxoToTransactionOutput = (utxo) => {
|
|
910
|
-
const
|
|
916
|
+
const buildDatum = (utxo2, builder) => {
|
|
911
917
|
if (utxo2.datumHash)
|
|
912
|
-
return
|
|
918
|
+
return builder.with_data(
|
|
919
|
+
CML.DatumOption.new_hash(CML.DatumHash.from_hex(utxo2.datumHash))
|
|
920
|
+
);
|
|
913
921
|
if (utxo2.datum)
|
|
914
|
-
return
|
|
915
|
-
CML.PlutusData.from_cbor_hex(utxo2.datum)
|
|
922
|
+
return builder.with_data(
|
|
923
|
+
CML.DatumOption.new_datum(CML.PlutusData.from_cbor_hex(utxo2.datum))
|
|
916
924
|
);
|
|
917
|
-
return
|
|
925
|
+
return builder;
|
|
918
926
|
};
|
|
919
|
-
|
|
920
|
-
CML.
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
927
|
+
const buildOutput = (utxo2) => {
|
|
928
|
+
const builder = CML.TransactionOutputBuilder.new().with_address(
|
|
929
|
+
CML.Address.from_bech32(utxo2.address)
|
|
930
|
+
);
|
|
931
|
+
return utxo2.scriptRef ? buildDatum(utxo2, builder).with_reference_script(toScriptRef(utxo2.scriptRef)).next() : buildDatum(utxo2, builder).next();
|
|
932
|
+
};
|
|
933
|
+
return buildOutput(utxo).with_value(assetsToValue(utxo.assets)).build().output();
|
|
925
934
|
};
|
|
926
935
|
var utxoToTransactionInput = (utxo) => {
|
|
927
936
|
return CML.TransactionInput.new(
|
|
@@ -929,12 +938,14 @@ var utxoToTransactionInput = (utxo) => {
|
|
|
929
938
|
BigInt(utxo.outputIndex)
|
|
930
939
|
);
|
|
931
940
|
};
|
|
932
|
-
|
|
933
|
-
|
|
941
|
+
var utxoToCore = (utxo) => {
|
|
942
|
+
const out = utxoToTransactionOutput(utxo);
|
|
943
|
+
const utxoCore = CML.TransactionUnspentOutput.new(
|
|
934
944
|
utxoToTransactionInput(utxo),
|
|
935
|
-
|
|
945
|
+
out
|
|
936
946
|
);
|
|
937
|
-
|
|
947
|
+
return utxoCore;
|
|
948
|
+
};
|
|
938
949
|
function utxosToCores(utxos) {
|
|
939
950
|
const result = [];
|
|
940
951
|
for (const utxo of utxos) {
|
|
@@ -943,12 +954,13 @@ function utxosToCores(utxos) {
|
|
|
943
954
|
return result;
|
|
944
955
|
}
|
|
945
956
|
function coreToUtxo(coreUtxo) {
|
|
946
|
-
|
|
957
|
+
const out = CML.TransactionOutput.from_cbor_hex(coreUtxo.to_cbor_hex());
|
|
958
|
+
const utxo = {
|
|
947
959
|
...coreToOutRef(CML.TransactionInput.from_cbor_hex(coreUtxo.to_cbor_hex())),
|
|
948
|
-
...coreToTxOutput(
|
|
949
|
-
CML.TransactionOutput.from_cbor_hex(coreUtxo.to_cbor_hex())
|
|
950
|
-
)
|
|
960
|
+
...coreToTxOutput(out)
|
|
951
961
|
};
|
|
962
|
+
out.free();
|
|
963
|
+
return utxo;
|
|
952
964
|
}
|
|
953
965
|
function coresToUtxos(utxos) {
|
|
954
966
|
const result = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lucid-evolution/utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -21,14 +21,18 @@
|
|
|
21
21
|
"keywords": [],
|
|
22
22
|
"author": "",
|
|
23
23
|
"license": "MIT",
|
|
24
|
+
"browser": {
|
|
25
|
+
"@dcspark/cardano-multiplatform-lib-nodejs": "@dcspark/cardano-multiplatform-lib-browser"
|
|
26
|
+
},
|
|
24
27
|
"dependencies": {
|
|
25
28
|
"@dcspark/cardano-multiplatform-lib-nodejs": "^5.3.0",
|
|
29
|
+
"@dcspark/cardano-multiplatform-lib-browser": "^5.3.0",
|
|
26
30
|
"cborg": "^4.2.0",
|
|
27
|
-
"@lucid-evolution/bip39": "0.2.
|
|
28
|
-
"@lucid-evolution/core-types": "0.1.
|
|
29
|
-
"@lucid-evolution/core-utils": "0.1.
|
|
30
|
-
"@lucid-evolution/crc8": "0.1.
|
|
31
|
-
"@lucid-evolution/plutus": "0.1.
|
|
31
|
+
"@lucid-evolution/bip39": "0.2.7",
|
|
32
|
+
"@lucid-evolution/core-types": "0.1.6",
|
|
33
|
+
"@lucid-evolution/core-utils": "0.1.6",
|
|
34
|
+
"@lucid-evolution/crc8": "0.1.6",
|
|
35
|
+
"@lucid-evolution/plutus": "0.1.9"
|
|
32
36
|
},
|
|
33
37
|
"devDependencies": {
|
|
34
38
|
"@types/node": "^20.12.8",
|
|
@@ -37,7 +41,7 @@
|
|
|
37
41
|
"vitest": "^1.6.0"
|
|
38
42
|
},
|
|
39
43
|
"scripts": {
|
|
40
|
-
"build": "tsup
|
|
44
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
41
45
|
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|
|
42
46
|
"test": "vitest run"
|
|
43
47
|
}
|