shared: fix OgmiosLucidProvider scriptRef extraction (Ogmios v6 shape)
ogmiosUtxoToLucidUtxo expected `o.script` to be a hex string, but
Ogmios v6 returns it as `{ language: "plutus:v3", cbor: "<hex>" }`
(or "native"). The typeof === "string" guard never matched, so
scriptRef was always null on returned UTxOs — making
.readFrom([refUtxo]) silently produce a tx with no script witness
and the supplier reject the resulting Claim with 503.
Wired ogmiosScriptToLucidScript() to translate the Ogmios shape into
the lucid-evolution shape across all four script languages.
Verified end-to-end: tmp-repro now reports
"scriptRef: present type=PlutusV3 cborlen=6884" against the published
ref UTxO (250928de…#0).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -370,12 +370,27 @@ function ogmiosUtxoToLucidUtxo(o: OgmiosUtxo): UTxO {
|
||||
assets,
|
||||
datumHash: o.datumHash ?? null,
|
||||
datum: typeof o.datum === "string" ? o.datum : null,
|
||||
scriptRef: typeof o.script === "string"
|
||||
? { type: "PlutusV3", script: o.script }
|
||||
: null,
|
||||
scriptRef: ogmiosScriptToLucidScript(o.script),
|
||||
};
|
||||
}
|
||||
|
||||
/** Ogmios v6 returns the script as `{ language: "plutus:v3", cbor: "<hex>" }`
|
||||
* (or `"native"` for native scripts). lucid-evolution wants
|
||||
* `{ type: "PlutusV1"|"PlutusV2"|"PlutusV3"|"Native", script: "<cbor-hex>" }`.
|
||||
* Returns null if the field is missing or unrecognised. */
|
||||
function ogmiosScriptToLucidScript(s: unknown): UTxO["scriptRef"] {
|
||||
if (!s || typeof s !== "object") return null;
|
||||
const obj = s as { language?: string; cbor?: string };
|
||||
if (typeof obj.cbor !== "string") return null;
|
||||
switch (obj.language) {
|
||||
case "plutus:v1": return { type: "PlutusV1", script: obj.cbor };
|
||||
case "plutus:v2": return { type: "PlutusV2", script: obj.cbor };
|
||||
case "plutus:v3": return { type: "PlutusV3", script: obj.cbor };
|
||||
case "native": return { type: "Native", script: obj.cbor };
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
function fractionToNumber(value: string | number | undefined, fallback: number): number {
|
||||
if (typeof value === "number" && Number.isFinite(value)) return value;
|
||||
if (typeof value !== "string") return fallback;
|
||||
|
||||
Reference in New Issue
Block a user