Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fix for parsing plutus data #501

Merged
merged 3 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/mesh-common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@meshsdk/common",
"version": "1.9.0-beta.2",
"version": "1.9.0-beta.3",
"description": "Contains constants, types and interfaces used across the SDK and different serialization libraries",
"main": "./dist/index.cjs",
"browser": "./dist/index.js",
Expand Down
6 changes: 3 additions & 3 deletions packages/mesh-contract/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@meshsdk/contract",
"version": "1.9.0-beta.2",
"version": "1.9.0-beta.3",
"description": "List of open-source smart contracts, complete with documentation, live demos, and end-to-end source code. https://meshjs.dev/smart-contracts",
"main": "./dist/index.cjs",
"browser": "./dist/index.js",
Expand Down Expand Up @@ -34,8 +34,8 @@
"typescript": "^5.3.3"
},
"dependencies": {
"@meshsdk/common": "1.9.0-beta.2",
"@meshsdk/core": "1.9.0-beta.2"
"@meshsdk/common": "1.9.0-beta.3",
"@meshsdk/core": "1.9.0-beta.3"
},
"prettier": "@meshsdk/configs/prettier",
"publishConfig": {
Expand Down
6 changes: 3 additions & 3 deletions packages/mesh-core-csl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@meshsdk/core-csl",
"version": "1.9.0-beta.2",
"version": "1.9.0-beta.3",
"description": "Types and utilities functions between Mesh and cardano-serialization-lib",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
Expand Down Expand Up @@ -31,15 +31,15 @@
},
"devDependencies": {
"@meshsdk/configs": "*",
"@meshsdk/provider": "1.9.0-beta.2",
"@meshsdk/provider": "1.9.0-beta.3",
"@types/json-bigint": "^1.0.4",
"eslint": "^8.57.0",
"ts-jest": "^29.1.4",
"tsup": "^8.0.2",
"typescript": "^5.3.3"
},
"dependencies": {
"@meshsdk/common": "1.9.0-beta.2",
"@meshsdk/common": "1.9.0-beta.3",
"@sidan-lab/sidan-csl-rs-browser": "0.9.21",
"@sidan-lab/sidan-csl-rs-nodejs": "0.9.21",
"@types/base32-encoding": "^1.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ export class OfflineEvaluator implements IEvaluator {
foundUtxos.add(`${output.input.txHash}:${output.input.outputIndex}`);
}
}
const inputsToResolve = getTransactionInputs(tx).filter((input) =>
foundUtxos.has(`${input.txHash}:${input.outputIndex}`),
const inputsToResolve = getTransactionInputs(tx).filter(
(input) => !foundUtxos.has(`${input.txHash}:${input.outputIndex}`),
);
const txHashesSet = new Set(inputsToResolve.map((input) => input.txHash));
for (const txHash of txHashesSet) {
Expand Down
26 changes: 16 additions & 10 deletions packages/mesh-core-csl/test/offline-providers/evaluator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe("Offline Evaluator", () => {
};
fetcher.addUTxOs([utxo_1, utxo_2, utxo_3, utxo_4, utxo_5, utxo_6, utxo_7]);

const res = await evaluator.evaluateTx(txHex);
const res = await evaluator.evaluateTx(txHex, [], []);
expect(res).toStrictEqual([
{
index: 0,
Expand Down Expand Up @@ -177,6 +177,8 @@ describe("Offline Evaluator", () => {
const res = await evaluator
.evaluateTx(
"84a700d901028182582047ce1b14c0599bb377a3c73c20973e49adbd10e5090129879b068ca0aa4216c2000181825839003f1b5974f4f09f0974be655e4ce94f8a2d087df378b79ef3916c26b2b1f70b573b204c6695b8f66eb6e7c78c55ede9430024ebec6fd5f85d821b0000000252c63160a2581c0f6b02150cbcc7fedafa388abcc41635a9443afb860100099ba40f07a1446d65736801581cf1c9053e4e03414fc37092d0155682f96d20770afc13a07f00f057ffa14001021a000c6b250758207564366f82807a253ef1f25af3f04486ac49ecd7fb631da76a713b32580994d709a1581cf1c9053e4e03414fc37092d0155682f96d20770afc13a07f00f057ffa140010b582001208ac891cd1aefe984b233bb0f9c4ece236b172c279d14d4940a483d68ccb00dd90102818258206213898aa37d5e585721f4ebdd16da2ac6cd9cd0e81318906dfeea3ebdf9f15700a207d901028158a0589e01010032323232323225333002323232323253330073370e900018049baa00113253300949010f5468697320697320612074726163650016375c601660146ea800454cc02124010f5468697320697320612074726163650016300a300b003300900230080023008001300537540022930a99801a491856616c696461746f722072657475726e65642066616c736500136565734ae7155ceaab9e5742ae8905a182010082d8799f446d657368ff821a006acfc01ab2d05e00f5a11902d1a178386631633930353365346530333431346663333730393264303135353638326639366432303737306166633133613037663030663035376666a1646d657368a46b6465736372697074696f6e783254686973204e465420776173206d696e746564206279204d657368202868747470733a2f2f6d6573686a732e6465762f292e65696d6167657835697066733a2f2f516d527a6963705265757477436b4d36616f74754b6a4572464355443231334470775071364279757a4d4a617561696d656469615479706569696d6167652f6a7067646e616d656a4d65736820546f6b656e",
[],
[],
)
.catch((e) => {
return e;
Expand Down Expand Up @@ -239,6 +241,8 @@ describe("Offline Evaluator", () => {
const res = await preprodEvaluator
.evaluateTx(
"84a600d9010281825820ac853ef4408d0084b1c99737c883170c8976cb468b864881927444937a90d5a20001828258390096cbb27c96daf8cab890de6d7f87f5ffd025bf8ac80717cbc4fae7dad474272a44c561db7e051a61c625d4fd58f42d8d9f086dddfb816a8b1a000ecc168258390096cbb27c96daf8cab890de6d7f87f5ffd025bf8ac80717cbc4fae7dad474272a44c561db7e051a61c625d4fd58f42d8d9f086dddfb816a8b1a0030ae9d021a000cd08d081a04b75da50b58209999a37fb76920d7323340579d1281f17ad738473c8a69a76c1f155aba58ecb30dd90102818258206c9e579ed693ac8d01f2f2f3ef8230530020542ebe23687159c8518de66f0b0005a207d901028159042059041d010100323232323232323225333002323232323253330073370e900118049baa001132332232533300b3370e900018069baa00213232533300d3370e900118079baa0011323232323232325330153372c9210a74696d655f6e6f773a20003732660026ea001d22010015330153372c92010b6c6f616e5f7465726d3a20003732660026ea0025220100153330143371001200e294454cc05524011c74696d655f6e6f77203e206c6f616e5f7465726d203f2046616c73650014a06002002444a6664666603a0062646464646601400266e29221012800533301e0021337149101035b5d2900006133714911035b5f2000333300900233714911025d29000062233300a00a00230070012233300a00a0020015333019337100049007099b80483c80400854ccc064cdc40012410004266e00cdc0241002800490068b1bac301b002375a60320026466ec0dd4180c8009ba7301a0013754006264a666036002266e292201027b7d00003133714911037b5f200032323300100100322533301e0011003132533301f00113233300a00a301e001337149101023a200033300a00a301f001005302000213233300a00a301e001337149101023a200033300a00a301f0013007330040040023020002302000133714910102207d000033756006264a666036002266e29221025b5d00003133714911035b5f2000333300600133714911015d000032233300700700230040012233300700700200137580066e292201022c2000133005375a00400226466e2922010268270032333001001337006e34009200133714910101270000322253330193371000490000800899191919980300319b8000548004cdc599b80002533301c33710004900a0a40c02903719b8b33700002a66603866e2000520141481805206e0043370c004901019b8300148080cdc70020011bae0022222323300100100522533301b0011005132533301c001133004301d002006133005301d00233003003001301d0012232330010010032253330143370e0029000099b8a48901300000315333014337100029000099b8a489012d003300200233702900000089980299b8400148050cdc599b803370a002900a240c00066002002444a66602266e2400920001001133300300333708004900a19b8b3370066e14009201448180004dd6980918081baa00114a064600260206ea8c004c040dd5001918090009bad3010300e37546020601c6ea800854cc0312412a65787065637420536f6d65284d79446174756d207b206c6f616e5f7465726d207d29203d20646174756d0016300f3010301030103010301030103010300d375400c601a002601a601c00260146ea800458c02cc03000cc028008c024008c024004c014dd50008a4c2a660069211856616c696461746f722072657475726e65642066616c736500136565734ae7155ceaab9e5573eae855d12ba40105a182000082d87980821a006acfc01ab2d05e00f5f6",
[],
[],
)
.catch((e) => {
return e;
Expand Down Expand Up @@ -266,6 +270,8 @@ describe("Offline Evaluator", () => {
const res2 = await mainnetEvaluator
.evaluateTx(
"84a600d9010281825820ac853ef4408d0084b1c99737c883170c8976cb468b864881927444937a90d5a20001828258390096cbb27c96daf8cab890de6d7f87f5ffd025bf8ac80717cbc4fae7dad474272a44c561db7e051a61c625d4fd58f42d8d9f086dddfb816a8b1a000ecc168258390096cbb27c96daf8cab890de6d7f87f5ffd025bf8ac80717cbc4fae7dad474272a44c561db7e051a61c625d4fd58f42d8d9f086dddfb816a8b1a0030ae9d021a000cd08d081a04b75da50b58209999a37fb76920d7323340579d1281f17ad738473c8a69a76c1f155aba58ecb30dd90102818258206c9e579ed693ac8d01f2f2f3ef8230530020542ebe23687159c8518de66f0b0005a207d901028159042059041d010100323232323232323225333002323232323253330073370e900118049baa001132332232533300b3370e900018069baa00213232533300d3370e900118079baa0011323232323232325330153372c9210a74696d655f6e6f773a20003732660026ea001d22010015330153372c92010b6c6f616e5f7465726d3a20003732660026ea0025220100153330143371001200e294454cc05524011c74696d655f6e6f77203e206c6f616e5f7465726d203f2046616c73650014a06002002444a6664666603a0062646464646601400266e29221012800533301e0021337149101035b5d2900006133714911035b5f2000333300900233714911025d29000062233300a00a00230070012233300a00a0020015333019337100049007099b80483c80400854ccc064cdc40012410004266e00cdc0241002800490068b1bac301b002375a60320026466ec0dd4180c8009ba7301a0013754006264a666036002266e292201027b7d00003133714911037b5f200032323300100100322533301e0011003132533301f00113233300a00a301e001337149101023a200033300a00a301f001005302000213233300a00a301e001337149101023a200033300a00a301f0013007330040040023020002302000133714910102207d000033756006264a666036002266e29221025b5d00003133714911035b5f2000333300600133714911015d000032233300700700230040012233300700700200137580066e292201022c2000133005375a00400226466e2922010268270032333001001337006e34009200133714910101270000322253330193371000490000800899191919980300319b8000548004cdc599b80002533301c33710004900a0a40c02903719b8b33700002a66603866e2000520141481805206e0043370c004901019b8300148080cdc70020011bae0022222323300100100522533301b0011005132533301c001133004301d002006133005301d00233003003001301d0012232330010010032253330143370e0029000099b8a48901300000315333014337100029000099b8a489012d003300200233702900000089980299b8400148050cdc599b803370a002900a240c00066002002444a66602266e2400920001001133300300333708004900a19b8b3370066e14009201448180004dd6980918081baa00114a064600260206ea8c004c040dd5001918090009bad3010300e37546020601c6ea800854cc0312412a65787065637420536f6d65284d79446174756d207b206c6f616e5f7465726d207d29203d20646174756d0016300f3010301030103010301030103010300d375400c601a002601a601c00260146ea800458c02cc03000cc028008c024008c024004c014dd50008a4c2a660069211856616c696461746f722072657475726e65642066616c736500136565734ae7155ceaab9e5573eae855d12ba40105a182000082d87980821a006acfc01ab2d05e00f5f6",
[],
[],
)
.catch((e) => {
return e;
Expand Down Expand Up @@ -338,6 +344,8 @@ describe("Offline Evaluator", () => {
const res = await preprodEvaluator
.evaluateTx(
"84a600d9010281825820ac853ef4408d0084b1c99737c883170c8976cb468b864881927444937a90d5a20001828258390096cbb27c96daf8cab890de6d7f87f5ffd025bf8ac80717cbc4fae7dad474272a44c561db7e051a61c625d4fd58f42d8d9f086dddfb816a8b1a000ecc168258390096cbb27c96daf8cab890de6d7f87f5ffd025bf8ac80717cbc4fae7dad474272a44c561db7e051a61c625d4fd58f42d8d9f086dddfb816a8b1a0030ae9d021a000cd08d081a04b75da50b58209999a37fb76920d7323340579d1281f17ad738473c8a69a76c1f155aba58ecb30dd90102818258206c9e579ed693ac8d01f2f2f3ef8230530020542ebe23687159c8518de66f0b0005a207d901028159042059041d010100323232323232323225333002323232323253330073370e900118049baa001132332232533300b3370e900018069baa00213232533300d3370e900118079baa0011323232323232325330153372c9210a74696d655f6e6f773a20003732660026ea001d22010015330153372c92010b6c6f616e5f7465726d3a20003732660026ea0025220100153330143371001200e294454cc05524011c74696d655f6e6f77203e206c6f616e5f7465726d203f2046616c73650014a06002002444a6664666603a0062646464646601400266e29221012800533301e0021337149101035b5d2900006133714911035b5f2000333300900233714911025d29000062233300a00a00230070012233300a00a0020015333019337100049007099b80483c80400854ccc064cdc40012410004266e00cdc0241002800490068b1bac301b002375a60320026466ec0dd4180c8009ba7301a0013754006264a666036002266e292201027b7d00003133714911037b5f200032323300100100322533301e0011003132533301f00113233300a00a301e001337149101023a200033300a00a301f001005302000213233300a00a301e001337149101023a200033300a00a301f0013007330040040023020002302000133714910102207d000033756006264a666036002266e29221025b5d00003133714911035b5f2000333300600133714911015d000032233300700700230040012233300700700200137580066e292201022c2000133005375a00400226466e2922010268270032333001001337006e34009200133714910101270000322253330193371000490000800899191919980300319b8000548004cdc599b80002533301c33710004900a0a40c02903719b8b33700002a66603866e2000520141481805206e0043370c004901019b8300148080cdc70020011bae0022222323300100100522533301b0011005132533301c001133004301d002006133005301d00233003003001301d0012232330010010032253330143370e0029000099b8a48901300000315333014337100029000099b8a489012d003300200233702900000089980299b8400148050cdc599b803370a002900a240c00066002002444a66602266e2400920001001133300300333708004900a19b8b3370066e14009201448180004dd6980918081baa00114a064600260206ea8c004c040dd5001918090009bad3010300e37546020601c6ea800854cc0312412a65787065637420536f6d65284d79446174756d207b206c6f616e5f7465726d207d29203d20646174756d0016300f3010301030103010301030103010300d375400c601a002601a601c00260146ea800458c02cc03000cc028008c024008c024004c014dd50008a4c2a660069211856616c696461746f722072657475726e65642066616c736500136565734ae7155ceaab9e5573eae855d12ba40105a182000082d87980821a006acfc01ab2d05e00f5f6",
[],
[],
)
.catch((e) => {
return e;
Expand All @@ -360,19 +368,17 @@ describe("Offline Evaluator", () => {
]),
);

const mainnetEvaluator = new OfflineEvaluator(
fetcher,
"mainnet",
{
slotLength: SLOT_CONFIG_NETWORK.preprod.slotLength,
zeroSlot: SLOT_CONFIG_NETWORK.preprod.zeroSlot,
zeroTime: SLOT_CONFIG_NETWORK.preprod.zeroTime,
},
);
const mainnetEvaluator = new OfflineEvaluator(fetcher, "mainnet", {
slotLength: SLOT_CONFIG_NETWORK.preprod.slotLength,
zeroSlot: SLOT_CONFIG_NETWORK.preprod.zeroSlot,
zeroTime: SLOT_CONFIG_NETWORK.preprod.zeroTime,
});

const res2 = await mainnetEvaluator
.evaluateTx(
"84a600d9010281825820ac853ef4408d0084b1c99737c883170c8976cb468b864881927444937a90d5a20001828258390096cbb27c96daf8cab890de6d7f87f5ffd025bf8ac80717cbc4fae7dad474272a44c561db7e051a61c625d4fd58f42d8d9f086dddfb816a8b1a000ecc168258390096cbb27c96daf8cab890de6d7f87f5ffd025bf8ac80717cbc4fae7dad474272a44c561db7e051a61c625d4fd58f42d8d9f086dddfb816a8b1a0030ae9d021a000cd08d081a04b75da50b58209999a37fb76920d7323340579d1281f17ad738473c8a69a76c1f155aba58ecb30dd90102818258206c9e579ed693ac8d01f2f2f3ef8230530020542ebe23687159c8518de66f0b0005a207d901028159042059041d010100323232323232323225333002323232323253330073370e900118049baa001132332232533300b3370e900018069baa00213232533300d3370e900118079baa0011323232323232325330153372c9210a74696d655f6e6f773a20003732660026ea001d22010015330153372c92010b6c6f616e5f7465726d3a20003732660026ea0025220100153330143371001200e294454cc05524011c74696d655f6e6f77203e206c6f616e5f7465726d203f2046616c73650014a06002002444a6664666603a0062646464646601400266e29221012800533301e0021337149101035b5d2900006133714911035b5f2000333300900233714911025d29000062233300a00a00230070012233300a00a0020015333019337100049007099b80483c80400854ccc064cdc40012410004266e00cdc0241002800490068b1bac301b002375a60320026466ec0dd4180c8009ba7301a0013754006264a666036002266e292201027b7d00003133714911037b5f200032323300100100322533301e0011003132533301f00113233300a00a301e001337149101023a200033300a00a301f001005302000213233300a00a301e001337149101023a200033300a00a301f0013007330040040023020002302000133714910102207d000033756006264a666036002266e29221025b5d00003133714911035b5f2000333300600133714911015d000032233300700700230040012233300700700200137580066e292201022c2000133005375a00400226466e2922010268270032333001001337006e34009200133714910101270000322253330193371000490000800899191919980300319b8000548004cdc599b80002533301c33710004900a0a40c02903719b8b33700002a66603866e2000520141481805206e0043370c004901019b8300148080cdc70020011bae0022222323300100100522533301b0011005132533301c001133004301d002006133005301d00233003003001301d0012232330010010032253330143370e0029000099b8a48901300000315333014337100029000099b8a489012d003300200233702900000089980299b8400148050cdc599b803370a002900a240c00066002002444a66602266e2400920001001133300300333708004900a19b8b3370066e14009201448180004dd6980918081baa00114a064600260206ea8c004c040dd5001918090009bad3010300e37546020601c6ea800854cc0312412a65787065637420536f6d65284d79446174756d207b206c6f616e5f7465726d207d29203d20646174756d0016300f3010301030103010301030103010300d375400c601a002601a601c00260146ea800458c02cc03000cc028008c024008c024004c014dd50008a4c2a660069211856616c696461746f722072657475726e65642066616c736500136565734ae7155ceaab9e5573eae855d12ba40105a182000082d87980821a006acfc01ab2d05e00f5f6",
[],
[],
)
.catch((e) => {
return e;
Expand Down
4 changes: 2 additions & 2 deletions packages/mesh-core-cst/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@meshsdk/core-cst",
"version": "1.9.0-beta.2",
"version": "1.9.0-beta.3",
"description": "Types and utilities functions between Mesh and cardano-js-sdk",
"main": "./dist/index.cjs",
"browser": "./dist/index.js",
Expand Down Expand Up @@ -46,7 +46,7 @@
"@harmoniclabs/crypto": "0.2.4",
"@harmoniclabs/pair": "1.0.0",
"@harmoniclabs/bytestring": "1.0.0",
"@meshsdk/common": "1.9.0-beta.2",
"@meshsdk/common": "1.9.0-beta.3",
"@stricahq/bip32ed25519": "^1.1.0",
"@stricahq/cbors": "^1.0.0",
"@types/base32-encoding": "^1.0.2",
Expand Down
9 changes: 7 additions & 2 deletions packages/mesh-core-cst/src/utils/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,14 @@ export const fromPlutusDataToJson = (data: PlutusData): object => {
const plutusData = data.asConstrPlutusData();
if (plutusData) {
const fields = plutusData.getData();
const list: object[] = [];
for (let i = 0; i < fields.getLength(); i++) {
const element = fields.get(i);
list.push(fromPlutusDataToJson(element));
}
return {
constructor: plutusData.getAlternative(),
fields: fromPlutusDataToJson(PlutusData.newList(fields)),
fields: list,
};
} else {
throw new Error("Invalid constructor data found");
Expand Down Expand Up @@ -210,7 +215,7 @@ export const fromPlutusDataToJson = (data: PlutusData): object => {
const element = plutusList.get(i);
list.push(fromPlutusDataToJson(element));
}
return list;
return { list: list };
} else {
throw new Error("Invalid list data found");
}
Expand Down
57 changes: 57 additions & 0 deletions packages/mesh-core-cst/test/utils/serializer-utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import JSONBig from "json-bigint";

import { NativeScript } from "@meshsdk/common";
import { applyCborEncoding } from "@meshsdk/core-csl";
import { CardanoSDKSerializer } from "@meshsdk/core-cst";

import { parseDatumCbor } from "../../src";

describe("Serialization utils", () => {
const serializer = new CardanoSDKSerializer();

Expand Down Expand Up @@ -207,6 +211,59 @@ describe("Serialization utils", () => {
);
});

it("parse datum cbor", () => {
expect(
JSONBig.stringify(
parseDatumCbor(
"d8799f9f4040ff9f581c5066154a102ee037390c5236f78db23239b49c5748d3d349f3ccf04b4455534458ffd87a801a3c3360801a02faf0800a581c4ba6dd244255995969d2c05e323686bcbaba83b736e729941825d79bff",
),
),
).toEqual(
JSONBig.stringify({
constructor: 0,
fields: [
{
list: [
{
bytes: "",
},
{
bytes: "",
},
],
},
{
list: [
{
bytes:
"5066154a102ee037390c5236f78db23239b49c5748d3d349f3ccf04b",
},
{
bytes: "55534458",
},
],
},
{
constructor: 1,
fields: [],
},
{
int: 1010000000,
},
{
int: 50000000,
},
{
int: 10,
},
{
bytes: "4ba6dd244255995969d2c05e323686bcbaba83b736e729941825d79b",
},
],
}),
);
});

it("resolve private key", () => {
expect(
serializer.resolver.keys.resolvePrivateKey([
Expand Down
Loading