Skip to content

Commit

Permalink
Merge pull request #166 from ilap/main
Browse files Browse the repository at this point in the history
Fix slotConfig inconsistency, update Kupmios example, and bump blaze-ogmios version for changeset release
  • Loading branch information
micahkendall authored Sep 11, 2024
2 parents 3653396 + bf2d952 commit 4cd001d
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 24 deletions.
31 changes: 18 additions & 13 deletions examples/kupmios/evaluate.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Unwrapped } from "../../packages/blaze-ogmios/dist/";
//import { Ogmios as OgmiosV1 } from '../../packages/blaze-ogmios/dist/';
import {
Bip32PrivateKey,
mnemonicToEntropy,
Expand All @@ -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<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
Expand All @@ -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";
Expand All @@ -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.`,
Expand All @@ -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);

Expand Down
10 changes: 5 additions & 5 deletions examples/kupmios/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<YOUR KUPO ENDPOINT>";
const kupoUrl = "http://localhost:1442";

// Tested with Ogmios v6.3.0
const ogmiosUrl = "<YOUR OGMIOS ENDPOINT>";
const ogmiosUrl = "http://localhost:1337";
const ogmios = await Unwrapped.Ogmios.new(ogmiosUrl);

const provider = new Kupmios(kupoUrl, ogmios);

const mnemonic = "<YOUR MNEMONIC THAT CONTAINS FUND TO SEND>";

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), "");

Expand Down
13 changes: 12 additions & 1 deletion packages/blaze-emulator/src/emulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/blaze-ogmios/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@blaze-cardano/ogmios",
"version": "0.0.5",
"version": "0.0.6",
"description": "Blaze cardano ogmios library",
"exports": {
".": {
Expand Down Expand Up @@ -30,7 +30,7 @@
"access": "public"
},
"dependencies": {
"@cardano-ogmios/schema": "^6.4.0",
"@cardano-ogmios/schema": "^6.6.1",
"isomorphic-ws": "^5.0.0"
}
}
4 changes: 2 additions & 2 deletions packages/blaze-tx/src/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4cd001d

Please sign in to comment.