From c1d7da3250e5783f73edf8621baaf36cd6903d05 Mon Sep 17 00:00:00 2001 From: Pal Dorogi Date: Wed, 11 Sep 2024 10:20:02 +0200 Subject: [PATCH 1/4] fix(blaze-emulator): ensure slotConfig consistency between LedgerTimer and makeUplcEvaluator with fallback logic --- packages/blaze-emulator/src/emulator.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/blaze-emulator/src/emulator.ts b/packages/blaze-emulator/src/emulator.ts index 2e947128..b75c190b 100644 --- a/packages/blaze-emulator/src/emulator.ts +++ b/packages/blaze-emulator/src/emulator.ts @@ -137,7 +137,18 @@ export class Emulator { } this.clock = new LedgerTimer(slotConfig); this.params = params; - this.evaluator = evaluator ?? makeUplcEvaluator(params, 1, 1, slotConfig); + this.evaluator = + evaluator ?? + makeUplcEvaluator( + params, + 1, + 1, + slotConfig ?? { + zeroSlot: this.clock.slot, + zeroTime: this.clock.time, + slotLength: this.clock.slotLength, + }, + ); this.addUtxo = this.addUtxo.bind(this); this.removeUtxo = this.removeUtxo.bind(this); } From 665c3338f69b5c99ff479ed9c666c01f02a040ee Mon Sep 17 00:00:00 2001 From: Pal Dorogi Date: Wed, 11 Sep 2024 10:21:57 +0200 Subject: [PATCH 2/4] fix(examples): update and fix Kupmios example to work properly again --- examples/kupmios/evaluate.ts | 31 ++++++++++++++++++------------- examples/kupmios/index.js | 10 +++++----- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/examples/kupmios/evaluate.ts b/examples/kupmios/evaluate.ts index f2f02aae..9212f353 100644 --- a/examples/kupmios/evaluate.ts +++ b/examples/kupmios/evaluate.ts @@ -1,3 +1,5 @@ +import { Unwrapped } from "../../packages/blaze-ogmios/dist/"; +//import { Ogmios as OgmiosV1 } from '../../packages/blaze-ogmios/dist/'; import { Bip32PrivateKey, mnemonicToEntropy, @@ -8,10 +10,10 @@ import { NetworkId, PlutusV2Script, PlutusData, -} from "../../packages/blaze-core/dist/index.js"; -import { Kupmios } from "../../packages/blaze-query/dist/index.js"; -import { Blaze, makeValue } from "../../packages/blaze-sdk/dist/index.js"; -import { HotWallet } from "../../packages/blaze-wallet/dist/index.js"; +} from "../../packages/blaze-core/dist/index.mjs"; +import { Kupmios } from "../../packages/blaze-query/dist/index.mjs"; +import { Blaze } from "../../packages/blaze-sdk/dist/index.mjs"; +import { HotWallet } from "../../packages/blaze-wallet/dist/index.mjs"; function sleep(ms: number): Promise { return new Promise((resolve) => setTimeout(resolve, ms)); @@ -25,8 +27,9 @@ const kupoUrl = "http://localhost:1442"; // Tested with Ogmios v6.3.0 const ogmiosUrl = "ws://localhost:1337"; +const ogmios = await Unwrapped.Ogmios.new(ogmiosUrl); -const provider = new Kupmios(kupoUrl, ogmiosUrl); +const provider = new Kupmios(kupoUrl, ogmios as any); const mnemonic = "test test test test test test test test test test test test test test test test test test test test test test test sauce"; @@ -46,12 +49,13 @@ const alwaysTrueScript: Script = Script.newPlutusV2Script( const scriptAddress = addressFromValidator(NetworkId.Testnet, alwaysTrueScript); -const txId = await blaze +const tx = await blaze .newTransaction() .lockLovelace(scriptAddress, 50_000_000n, PlutusData.fromCbor(HexBlob("01"))) - .complete() - .then(blaze.signTransaction) - .then(blaze.submitTransaction); + .complete(); + +const signed = await blaze.signTransaction(tx); +const txId = await blaze.provider.postTransactionToChain(signed); console.log( `Transaction with ID ${txId} has been successfully submitted to the blockchain.`, @@ -67,13 +71,14 @@ await sleep(sleeptime); const scriptUtxos = await blaze.provider.getUnspentOutputs(scriptAddress); -const txId1 = await blaze +const tx1 = await blaze .newTransaction() .addInput(scriptUtxos[0], PlutusData.fromCbor(HexBlob("00"))) .provideScript(alwaysTrueScript) - .complete() - .then(blaze.signTransaction) - .then(blaze.submitTransaction); + .complete(); + +const signed1 = await blaze.signTransaction(tx1); +const txId1 = await blaze.provider.postTransactionToChain(signed1); const confirmed1 = await blaze.provider.awaitTransactionConfirmation(txId1); diff --git a/examples/kupmios/index.js b/examples/kupmios/index.js index cf9b586c..d87d5732 100644 --- a/examples/kupmios/index.js +++ b/examples/kupmios/index.js @@ -4,21 +4,21 @@ import { wordlist, } from "../../packages/blaze-core/dist/index.js"; import { Kupmios } from "../../packages/blaze-query/dist/index.js"; -import { Unwrapped } from "../../packages/blaze-ogmios"; +import { Unwrapped } from "../../packages/blaze-ogmios/dist/index.js"; import { Blaze } from "../../packages/blaze-sdk/dist/index.js"; import { HotWallet } from "../../packages/blaze-wallet/dist/index.js"; // Tested with Kupo v2.8.0 -const kupoUrl = ""; +const kupoUrl = "http://localhost:1442"; // Tested with Ogmios v6.3.0 -const ogmiosUrl = ""; +const ogmiosUrl = "http://localhost:1337"; const ogmios = await Unwrapped.Ogmios.new(ogmiosUrl); const provider = new Kupmios(kupoUrl, ogmios); -const mnemonic = ""; - +const mnemonic = + "test test test test test test test test test test test test test test test test test test test test test test test sauce"; const entropy = mnemonicToEntropy(mnemonic, wordlist); const masterkey = Bip32PrivateKey.fromBip39Entropy(Buffer.from(entropy), ""); From 988505279e336626d28ab0685177b85194ba3323 Mon Sep 17 00:00:00 2001 From: Pal Dorogi Date: Wed, 11 Sep 2024 10:23:37 +0200 Subject: [PATCH 3/4] chore(blaze-ogmios): bump version for missed changeset release --- packages/blaze-ogmios/package.json | 4 ++-- pnpm-lock.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/blaze-ogmios/package.json b/packages/blaze-ogmios/package.json index 1cc39fda..c11cee83 100644 --- a/packages/blaze-ogmios/package.json +++ b/packages/blaze-ogmios/package.json @@ -1,6 +1,6 @@ { "name": "@blaze-cardano/ogmios", - "version": "0.0.5", + "version": "0.0.6", "description": "Blaze cardano ogmios library", "exports": { ".": { @@ -30,7 +30,7 @@ "access": "public" }, "dependencies": { - "@cardano-ogmios/schema": "^6.4.0", + "@cardano-ogmios/schema": "^6.6.1", "isomorphic-ws": "^5.0.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 350e5f65..7e2d90fa 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -209,7 +209,7 @@ importers: packages/blaze-ogmios: dependencies: '@cardano-ogmios/schema': - specifier: ^6.4.0 + specifier: ^6.6.1 version: 6.6.1 isomorphic-ws: specifier: ^5.0.0 From bf2d9527d7d74e8c1a78663bd9bed6eb49502bd1 Mon Sep 17 00:00:00 2001 From: Pal Dorogi Date: Wed, 11 Sep 2024 14:34:35 +0200 Subject: [PATCH 4/4] fix(blaze-tx): convert insertIdx to BigInt for redeemer index comparison in TxBuilder --- packages/blaze-tx/src/tx.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/blaze-tx/src/tx.ts b/packages/blaze-tx/src/tx.ts index 31657c47..3a4e1684 100644 --- a/packages/blaze-tx/src/tx.ts +++ b/packages/blaze-tx/src/tx.ts @@ -489,7 +489,7 @@ export class TxBuilder { for (const redeemer of redeemers) { if ( redeemer.tag() == RedeemerTag.Mint && - redeemer.index() >= insertIdx + redeemer.index() >= BigInt(insertIdx) ) { redeemer.setIndex(redeemer.index() + 1n); } @@ -1792,7 +1792,7 @@ export class TxBuilder { for (const redeemer of redeemers) { if ( redeemer.tag() == RedeemerTag.Reward && - redeemer.index() >= insertIdx + redeemer.index() >= BigInt(insertIdx) ) { redeemer.setIndex(redeemer.index() + 1n); }