Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
micahkendall committed Aug 13, 2024
1 parent 5a4d4e4 commit a421f6f
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 27 deletions.
7 changes: 7 additions & 0 deletions .changeset/twelve-actors-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@blaze-cardano/ogmios": patch
"@blaze-cardano/query": patch
"@blaze-cardano/tx": patch
---

patch: @microproofs bug x2 (ogmios bigints, data.to lists), @calvin bug (lockAssets)
2 changes: 1 addition & 1 deletion packages/blaze-ogmios/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"devDependencies": {
"@blaze-cardano/eslint-config": "workspace:*",
"@blaze-cardano/tsconfig": "workspace:*",
"@cardano-ogmios/schema": "^6.4.0",
"eslint": "^8.57.0",
"ts-node": "^10.9.2",
"tsup": "^8.0.2",
Expand All @@ -27,6 +26,7 @@
"access": "public"
},
"dependencies": {
"@cardano-ogmios/schema": "^6.4.0",
"isomorphic-ws": "^5.0.0"
}
}
16 changes: 13 additions & 3 deletions packages/blaze-ogmios/src/unwrapped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,17 @@ export class Ogmios {
}
const id = Ogmios.generateId();
return new Promise<Extract<R, "result">>((resolve, reject) => {
this.ws.send(JSON.stringify({ jsonrpc: "2.0", method, params, id }));
this.ws.send(
JSON.stringify(
{ jsonrpc: "2.0", method, params, id },
(_key, value) => {
if (value instanceof BigInt) {
return Number(value);
}
return value;
},
),
);
this.requests[id] = { resolve, reject };
});
}
Expand Down Expand Up @@ -126,12 +136,12 @@ export class Ogmios {
// Transaction Evaluation API
async evaluateTransaction(
transaction: { cbor: string },
additionalUtxo?: schema.Utxo,
additionalUtxos?: schema.Utxo,
): Promise<schema.EvaluateTransactionSuccess["result"]> {
return this.request<
schema.EvaluateTransaction,
schema.Ogmios["EvaluateTransactionResponse"]
>("evaluateTransaction", { transaction, additionalUtxo });
>("evaluateTransaction", { transaction, additionalUtxo: additionalUtxos });
}

// State Query API
Expand Down
1 change: 1 addition & 0 deletions packages/blaze-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"access": "public"
},
"dependencies": {
"@cardano-ogmios/schema": "^6.4.0",
"@blaze-cardano/core": "workspace:*",
"@blaze-cardano/ogmios": "workspace:*",
"@blaze-cardano/jest-config": "workspace:*",
Expand Down
11 changes: 7 additions & 4 deletions packages/blaze-query/src/kupmios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
} from "@blaze-cardano/core";
import { purposeToTag, type Provider } from "./types";
import type { Unwrapped } from "@blaze-cardano/ogmios";
import type * as Schema from "@cardano-ogmios/schema";

export class Kupmios implements Provider {
kupoUrl: string;
Expand Down Expand Up @@ -410,22 +411,24 @@ export class Kupmios implements Provider {
* @param unspentOutputs - Unspent outputs to serialize.
* @returns the serialized unspent outputs.
*/
static serializeUtxos(unspentOutputs: TransactionUnspentOutput[]): any[] {
static serializeUtxos(
unspentOutputs: TransactionUnspentOutput[],
): Schema.Utxo {
return unspentOutputs.map((output) => {
const out = output.output();
const address = out.address().toBech32();

// Output parameters
const ada = out.amount().coin().valueOf();

const value: { [key: string]: any } = { ada: { lovelace: ada } };
const value: Schema.Value = { ada: { lovelace: ada } };
const multiAsset = out.amount().multiasset?.();
multiAsset?.forEach((assets, assetId) => {
const policyID = AssetId.getPolicyId(assetId);
const assetName = AssetId.getAssetName(assetId);

value[policyID] ??= {};
value[policyID][assetName] = assets;
value[policyID]![assetName] = assets;
});

// Handle optional datum and datumHash
Expand Down Expand Up @@ -464,7 +467,7 @@ export class Kupmios implements Provider {
datumHash,
datum,
script,
};
} as Schema.Utxo[number];
});
}
}
2 changes: 1 addition & 1 deletion packages/blaze-tx/src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ function to<T extends TSchema>(
if (data instanceof Array) {
const list = new PlutusList();
for (let i = 0; i < data.length; i++) {
list.add(to(data[i], type[0]));
list.add(to(data[i]));
}
return PlutusData.newList(list);
} else if (data instanceof Map) {
Expand Down
25 changes: 10 additions & 15 deletions packages/blaze-tx/src/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,18 +614,12 @@ export class TxBuilder {
datum: Datum,
scriptReference?: Script,
) {
assertLockAddress(address);
const paymentAddress = getPaymentAddress(address);
this.addOutput(
TransactionOutput.fromCore({
address: paymentAddress,
value: { coins: lovelace },
datum: !("__opaqueString" in datum) ? datum.toCore() : undefined,
datumHash: "__opaqueString" in datum ? datum : undefined,
scriptReference: scriptReference?.toCore(),
}),
return this.lockAssets(
address,
new Value(lovelace),
datum,
scriptReference,
);
return this;
}

/**
Expand All @@ -646,18 +640,19 @@ export class TxBuilder {
datum: Datum,
scriptReference?: Script,
) {
const datumData = typeof datum == "object" ? datum.toCore() : undefined;
const datumHash = typeof datum == "string" ? datum : undefined;
assertLockAddress(address);
const paymentAddress = getPaymentAddress(address);
this.addOutput(
return this.addOutput(
TransactionOutput.fromCore({
address: paymentAddress,
value: value.toCore(),
datum: !("__opaqueString" in datum) ? datum.toCore() : undefined,
datumHash: "__opaqueString" in datum ? datum : undefined,
datum: datumData,
datumHash,
scriptReference: scriptReference?.toCore(),
}),
);
return this;
}

/**
Expand Down
9 changes: 6 additions & 3 deletions pnpm-lock.yaml

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

0 comments on commit a421f6f

Please sign in to comment.