@lucid-evolution/utils 0.1.16 → 0.1.18
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 +23 -10
- package/dist/index.d.cts +16 -5
- package/dist/index.d.ts +16 -5
- package/dist/index.js +23 -10
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -1115,16 +1115,29 @@ var selectUTxOs = (utxos, totalAssets) => {
|
|
|
1115
1115
|
return [];
|
|
1116
1116
|
return selectedUtxos;
|
|
1117
1117
|
};
|
|
1118
|
-
var sortUTxOs = (utxos, order = "
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
return
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1118
|
+
var sortUTxOs = (utxos, order = "LargestFirst") => {
|
|
1119
|
+
switch (order) {
|
|
1120
|
+
case "LargestFirst":
|
|
1121
|
+
return [...utxos].sort(largestFirst);
|
|
1122
|
+
case "SmallestFirst":
|
|
1123
|
+
return [...utxos].sort(smallestFirst);
|
|
1124
|
+
}
|
|
1125
|
+
};
|
|
1126
|
+
var largestFirst = (a, b) => {
|
|
1127
|
+
const lovelaceA = Number(a.assets["lovelace"]);
|
|
1128
|
+
const lovelaceB = Number(b.assets["lovelace"]);
|
|
1129
|
+
if (lovelaceA === lovelaceB) {
|
|
1130
|
+
return Object.keys(a.assets).length - Object.keys(b.assets).length;
|
|
1131
|
+
}
|
|
1132
|
+
return -1 * (lovelaceA - lovelaceB);
|
|
1133
|
+
};
|
|
1134
|
+
var smallestFirst = (a, b) => {
|
|
1135
|
+
const lovelaceA = Number(a.assets["lovelace"]);
|
|
1136
|
+
const lovelaceB = Number(b.assets["lovelace"]);
|
|
1137
|
+
if (lovelaceA == lovelaceB) {
|
|
1138
|
+
return Object.keys(a.assets).length - Object.keys(b.assets).length;
|
|
1139
|
+
}
|
|
1140
|
+
return lovelaceA - lovelaceB;
|
|
1128
1141
|
};
|
|
1129
1142
|
var isEqualUTxO = (self, that) => self.txHash === that.txHash && self.outputIndex === that.outputIndex;
|
|
1130
1143
|
|
package/dist/index.d.cts
CHANGED
|
@@ -61,15 +61,26 @@ declare function coreToTxOutput(output: CML.TransactionOutput): TxOutput;
|
|
|
61
61
|
declare function coresToTxOutputs(outputs: CML.TransactionOutput[]): TxOutput[];
|
|
62
62
|
declare const selectUTxOs: (utxos: UTxO[], totalAssets: Assets) => UTxO[];
|
|
63
63
|
/**
|
|
64
|
-
*
|
|
64
|
+
* Union type for specifying sorting order in function "sortUTxOs"
|
|
65
|
+
*/
|
|
66
|
+
type SortOrder =
|
|
67
|
+
/**
|
|
68
|
+
* Largest amount of "lovelace" with least number of unique assets first
|
|
69
|
+
*/
|
|
70
|
+
"LargestFirst"
|
|
71
|
+
/**
|
|
72
|
+
* Smallest amount of "lovelace" with least number of unique assets first
|
|
73
|
+
*/
|
|
74
|
+
| "SmallestFirst";
|
|
75
|
+
/**
|
|
76
|
+
* Sorts an array of UTXOs according to specified sort order ("LargestFirst" by default).
|
|
65
77
|
*
|
|
66
78
|
* @param {UTxO[]} utxos - The array of UTXO objects to be sorted.
|
|
67
|
-
* @param {
|
|
68
|
-
* Use "ascending" for ascending order and "descending" for descending order.
|
|
79
|
+
* @param {SortOrder} [order="LargestFirst"] - The order in which to sort the UTXOs.
|
|
69
80
|
* @returns {UTxO[]} - The sorted array of UTXOs.
|
|
70
81
|
*
|
|
71
82
|
*/
|
|
72
|
-
declare const sortUTxOs: (utxos: UTxO[], order?:
|
|
83
|
+
declare const sortUTxOs: (utxos: UTxO[], order?: SortOrder) => UTxO[];
|
|
73
84
|
declare const isEqualUTxO: (self: UTxO, that: UTxO) => boolean;
|
|
74
85
|
|
|
75
86
|
declare function valueToAssets(value: CML.Value): Assets;
|
|
@@ -92,4 +103,4 @@ declare function addAssets(...assets: Assets[]): Assets;
|
|
|
92
103
|
|
|
93
104
|
declare const stringify: (data: any) => string;
|
|
94
105
|
|
|
95
|
-
export { PROTOCOL_PARAMETERS_DEFAULT, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, applyParamsToScript, assetsToValue, coreToOutRef, coreToTxOutput, coreToUtxo, coresToOutRefs, coresToTxOutputs, coresToUtxos, createCostModels, credentialToAddress, credentialToRewardAddress, datumToHash, fromLabel, fromScriptRef, fromUnit, generatePrivateKey, generateSeedPhrase, getAddressDetails, isEqualUTxO, keyHashToCredential, mintingPolicyToId, nativeFromJson, nativeJSFromJson, nativeScriptFromJson, networkToId, paymentCredentialOf, scriptHashToCredential, selectUTxOs, slotToUnixTime, sortUTxOs, stakeCredentialOf, stringify, toLabel, toNativeScript, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
|
|
106
|
+
export { PROTOCOL_PARAMETERS_DEFAULT, type SortOrder, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, applyParamsToScript, assetsToValue, coreToOutRef, coreToTxOutput, coreToUtxo, coresToOutRefs, coresToTxOutputs, coresToUtxos, createCostModels, credentialToAddress, credentialToRewardAddress, datumToHash, fromLabel, fromScriptRef, fromUnit, generatePrivateKey, generateSeedPhrase, getAddressDetails, isEqualUTxO, keyHashToCredential, mintingPolicyToId, nativeFromJson, nativeJSFromJson, nativeScriptFromJson, networkToId, paymentCredentialOf, scriptHashToCredential, selectUTxOs, slotToUnixTime, sortUTxOs, stakeCredentialOf, stringify, toLabel, toNativeScript, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
|
package/dist/index.d.ts
CHANGED
|
@@ -61,15 +61,26 @@ declare function coreToTxOutput(output: CML.TransactionOutput): TxOutput;
|
|
|
61
61
|
declare function coresToTxOutputs(outputs: CML.TransactionOutput[]): TxOutput[];
|
|
62
62
|
declare const selectUTxOs: (utxos: UTxO[], totalAssets: Assets) => UTxO[];
|
|
63
63
|
/**
|
|
64
|
-
*
|
|
64
|
+
* Union type for specifying sorting order in function "sortUTxOs"
|
|
65
|
+
*/
|
|
66
|
+
type SortOrder =
|
|
67
|
+
/**
|
|
68
|
+
* Largest amount of "lovelace" with least number of unique assets first
|
|
69
|
+
*/
|
|
70
|
+
"LargestFirst"
|
|
71
|
+
/**
|
|
72
|
+
* Smallest amount of "lovelace" with least number of unique assets first
|
|
73
|
+
*/
|
|
74
|
+
| "SmallestFirst";
|
|
75
|
+
/**
|
|
76
|
+
* Sorts an array of UTXOs according to specified sort order ("LargestFirst" by default).
|
|
65
77
|
*
|
|
66
78
|
* @param {UTxO[]} utxos - The array of UTXO objects to be sorted.
|
|
67
|
-
* @param {
|
|
68
|
-
* Use "ascending" for ascending order and "descending" for descending order.
|
|
79
|
+
* @param {SortOrder} [order="LargestFirst"] - The order in which to sort the UTXOs.
|
|
69
80
|
* @returns {UTxO[]} - The sorted array of UTXOs.
|
|
70
81
|
*
|
|
71
82
|
*/
|
|
72
|
-
declare const sortUTxOs: (utxos: UTxO[], order?:
|
|
83
|
+
declare const sortUTxOs: (utxos: UTxO[], order?: SortOrder) => UTxO[];
|
|
73
84
|
declare const isEqualUTxO: (self: UTxO, that: UTxO) => boolean;
|
|
74
85
|
|
|
75
86
|
declare function valueToAssets(value: CML.Value): Assets;
|
|
@@ -92,4 +103,4 @@ declare function addAssets(...assets: Assets[]): Assets;
|
|
|
92
103
|
|
|
93
104
|
declare const stringify: (data: any) => string;
|
|
94
105
|
|
|
95
|
-
export { PROTOCOL_PARAMETERS_DEFAULT, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, applyParamsToScript, assetsToValue, coreToOutRef, coreToTxOutput, coreToUtxo, coresToOutRefs, coresToTxOutputs, coresToUtxos, createCostModels, credentialToAddress, credentialToRewardAddress, datumToHash, fromLabel, fromScriptRef, fromUnit, generatePrivateKey, generateSeedPhrase, getAddressDetails, isEqualUTxO, keyHashToCredential, mintingPolicyToId, nativeFromJson, nativeJSFromJson, nativeScriptFromJson, networkToId, paymentCredentialOf, scriptHashToCredential, selectUTxOs, slotToUnixTime, sortUTxOs, stakeCredentialOf, stringify, toLabel, toNativeScript, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
|
|
106
|
+
export { PROTOCOL_PARAMETERS_DEFAULT, type SortOrder, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, applyParamsToScript, assetsToValue, coreToOutRef, coreToTxOutput, coreToUtxo, coresToOutRefs, coresToTxOutputs, coresToUtxos, createCostModels, credentialToAddress, credentialToRewardAddress, datumToHash, fromLabel, fromScriptRef, fromUnit, generatePrivateKey, generateSeedPhrase, getAddressDetails, isEqualUTxO, keyHashToCredential, mintingPolicyToId, nativeFromJson, nativeJSFromJson, nativeScriptFromJson, networkToId, paymentCredentialOf, scriptHashToCredential, selectUTxOs, slotToUnixTime, sortUTxOs, stakeCredentialOf, stringify, toLabel, toNativeScript, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
|
package/dist/index.js
CHANGED
|
@@ -1034,16 +1034,29 @@ var selectUTxOs = (utxos, totalAssets) => {
|
|
|
1034
1034
|
return [];
|
|
1035
1035
|
return selectedUtxos;
|
|
1036
1036
|
};
|
|
1037
|
-
var sortUTxOs = (utxos, order = "
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
return
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1037
|
+
var sortUTxOs = (utxos, order = "LargestFirst") => {
|
|
1038
|
+
switch (order) {
|
|
1039
|
+
case "LargestFirst":
|
|
1040
|
+
return [...utxos].sort(largestFirst);
|
|
1041
|
+
case "SmallestFirst":
|
|
1042
|
+
return [...utxos].sort(smallestFirst);
|
|
1043
|
+
}
|
|
1044
|
+
};
|
|
1045
|
+
var largestFirst = (a, b) => {
|
|
1046
|
+
const lovelaceA = Number(a.assets["lovelace"]);
|
|
1047
|
+
const lovelaceB = Number(b.assets["lovelace"]);
|
|
1048
|
+
if (lovelaceA === lovelaceB) {
|
|
1049
|
+
return Object.keys(a.assets).length - Object.keys(b.assets).length;
|
|
1050
|
+
}
|
|
1051
|
+
return -1 * (lovelaceA - lovelaceB);
|
|
1052
|
+
};
|
|
1053
|
+
var smallestFirst = (a, b) => {
|
|
1054
|
+
const lovelaceA = Number(a.assets["lovelace"]);
|
|
1055
|
+
const lovelaceB = Number(b.assets["lovelace"]);
|
|
1056
|
+
if (lovelaceA == lovelaceB) {
|
|
1057
|
+
return Object.keys(a.assets).length - Object.keys(b.assets).length;
|
|
1058
|
+
}
|
|
1059
|
+
return lovelaceA - lovelaceB;
|
|
1047
1060
|
};
|
|
1048
1061
|
var isEqualUTxO = (self, that) => self.txHash === that.txHash && self.outputIndex === that.outputIndex;
|
|
1049
1062
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lucid-evolution/utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"@dcspark/cardano-multiplatform-lib-browser": "^5.3.0",
|
|
30
30
|
"cborg": "^4.2.0",
|
|
31
31
|
"@lucid-evolution/bip39": "0.2.7",
|
|
32
|
-
"@lucid-evolution/core-types": "0.1.
|
|
32
|
+
"@lucid-evolution/core-types": "0.1.7",
|
|
33
33
|
"@lucid-evolution/core-utils": "0.1.6",
|
|
34
34
|
"@lucid-evolution/crc8": "0.1.6",
|
|
35
|
-
"@lucid-evolution/plutus": "0.1.
|
|
36
|
-
"@lucid-evolution/uplc": "0.2.
|
|
35
|
+
"@lucid-evolution/plutus": "0.1.10",
|
|
36
|
+
"@lucid-evolution/uplc": "0.2.6"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^20.12.8",
|