@harmoniclabs/plu-ts-offchain
Advanced tools
Comparing version 0.1.13-dev7 to 0.1.13-dev8
@@ -8,3 +8,5 @@ import { UTxO, Script, IUTxO, NativeScript, ScriptType } from "@harmoniclabs/cardano-ledger-ts"; | ||
referenceScriptV2?: ITxBuildInputRefScript; | ||
/** can have undefined datum only if plutus script is v3 or higher */ | ||
referenceScript?: ITxBuildInputRefScript; | ||
/** can have undefined datum only if plutus script is v3 or higher */ | ||
inputScript?: ITxBuildInputInlineScript; | ||
@@ -11,0 +13,0 @@ nativeScript?: NativeScript | Script; |
@@ -16,3 +16,2 @@ "use strict"; | ||
var cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts"); | ||
var CanBeData_1 = require("../../utils/CanBeData.js"); | ||
var ITxBuildInputRefScript_1 = require("./ITxBuildInputRefScript.js"); | ||
@@ -62,13 +61,5 @@ var ITxBuildInputInlineScript_1 = require("./ITxBuildInputInlineScript.js"); | ||
var referenceScript = ref === undefined ? undefined : | ||
{ | ||
refUtxo: new cardano_ledger_ts_1.UTxO(ref.refUtxo), | ||
datum: ref.datum === "inline" ? "inline" : (0, CanBeData_1.cloneCanBeData)(ref.datum), | ||
redeemer: (0, CanBeData_1.cloneCanBeData)(ref.redeemer) | ||
}; | ||
(0, ITxBuildInputRefScript_1.normalizeITxBuildInputRefScript)(ref); | ||
var inputScript = inScript === undefined ? undefined : | ||
{ | ||
script: inScript.script.clone(), | ||
datum: inScript.datum === "inline" ? "inline" : (0, CanBeData_1.cloneCanBeData)(inScript.datum), | ||
redeemer: (0, CanBeData_1.cloneCanBeData)(inScript.redeemer) | ||
}; | ||
(0, ITxBuildInputInlineScript_1.normalizeITxBuildInputInlineScript)(inScript); | ||
return { | ||
@@ -75,0 +66,0 @@ utxo: new cardano_ledger_ts_1.UTxO(utxo), |
@@ -6,3 +6,3 @@ import { Script } from "@harmoniclabs/cardano-ledger-ts"; | ||
script: Script; | ||
datum: CanBeData | "inline"; | ||
datum?: CanBeData | "inline" | undefined; | ||
redeemer: CanBeData; | ||
@@ -12,5 +12,5 @@ } | ||
script: Script; | ||
datum: Data | "inline"; | ||
datum: Data | "inline" | undefined; | ||
redeemer: Data; | ||
} | ||
export declare function normalizeITxBuildInputInlineScript(input: ITxBuildInputInlineScript): NormalizedITxBuildInputInlineScript; |
@@ -8,3 +8,5 @@ "use strict"; | ||
result.script = input.script.clone(); | ||
result.datum = input.datum === "inline" ? "inline" : (0, CanBeData_1.forceData)(input.datum); | ||
result.datum = (input.datum === "inline" ? "inline" : | ||
((0, CanBeData_1.canBeData)(input.datum) ? (0, CanBeData_1.forceData)(input.datum) : | ||
undefined)); | ||
result.redeemer = (0, CanBeData_1.forceData)(input.redeemer); | ||
@@ -11,0 +13,0 @@ return result; |
@@ -6,3 +6,3 @@ import { IUTxO, UTxO } from "@harmoniclabs/cardano-ledger-ts"; | ||
refUtxo: IUTxO; | ||
datum: CanBeData | "inline"; | ||
datum?: CanBeData | "inline"; | ||
redeemer: CanBeData; | ||
@@ -12,5 +12,5 @@ } | ||
refUtxo: UTxO; | ||
datum: Data | "inline"; | ||
datum: Data | "inline" | undefined; | ||
redeemer: Data; | ||
} | ||
export declare function normalizeITxBuildInputRefScript(input: ITxBuildInputRefScript): NormalizedITxBuildInputRefScript; |
@@ -9,3 +9,5 @@ "use strict"; | ||
result.refUtxo = new cardano_ledger_ts_1.UTxO(input.refUtxo); | ||
result.datum = input.datum === "inline" ? "inline" : (0, CanBeData_1.forceData)(input.datum); | ||
result.datum = (input.datum === "inline" ? "inline" : | ||
((0, CanBeData_1.canBeData)(input.datum) ? (0, CanBeData_1.forceData)(input.datum) : | ||
undefined)); | ||
result.redeemer = (0, CanBeData_1.forceData)(input.redeemer); | ||
@@ -12,0 +14,0 @@ return result; |
@@ -554,10 +554,33 @@ "use strict"; | ||
*/ | ||
function pushWitDatum(datum, inlineDatum) { | ||
if (datum === "inline") { | ||
if (!(0, CanBeData_1.canBeData)(inlineDatum)) | ||
throw new Error("datum was specified to be inline; but inline datum is missing"); | ||
// no need to push to witnesses | ||
return (0, CanBeData_1.forceData)(inlineDatum); | ||
function pushWitDatum(datum, inlineDatum, scriptType) { | ||
if (scriptType === cardano_ledger_ts_1.ScriptType.NativeScript) | ||
return undef; | ||
if (datum === "inline") | ||
datum = undef; | ||
if (scriptType === cardano_ledger_ts_1.ScriptType.PlutusV1 || | ||
scriptType === cardano_ledger_ts_1.ScriptType.PlutusV2) { | ||
if (datum === undef) { | ||
if (!(0, CanBeData_1.canBeData)(inlineDatum)) | ||
throw new Error("datum was specified to be inline; but inline datum is missing"); | ||
// no need to push to witnesses | ||
return (0, CanBeData_1.forceData)(inlineDatum); | ||
} | ||
else { | ||
var dat = (0, CanBeData_1.forceData)(datum); | ||
// add datum to witnesses | ||
// the node finds it trough the datum hash (on the utxo) | ||
datums.push(dat); | ||
return dat; | ||
} | ||
} | ||
else { | ||
if (datum === undef) { | ||
if ((0, CanBeData_1.canBeData)(inlineDatum)) { | ||
// no need to push to witnesses | ||
return (0, CanBeData_1.forceData)(inlineDatum); | ||
} | ||
if (inlineDatum instanceof cardano_ledger_ts_1.Hash32) | ||
throw new Error("datum hash specified on spending utxo, but resolved datum is missing"); | ||
return undef; | ||
} | ||
else if (inlineDatum instanceof cardano_ledger_ts_1.Hash32) { | ||
var dat = (0, CanBeData_1.forceData)(datum); | ||
@@ -569,2 +592,3 @@ // add datum to witnesses | ||
} | ||
return undef; | ||
} | ||
@@ -601,3 +625,3 @@ var isScriptValid = true; | ||
} | ||
var dat = pushWitDatum(datum, utxo.resolved.datum); | ||
var dat = pushWitDatum(datum, utxo.resolved.datum, refScript.type); | ||
var i_1 = sortedIns.indexOf(input); | ||
@@ -619,3 +643,3 @@ if (i_1 < 0) | ||
pushWitScript(script); | ||
var dat = pushWitDatum(datum, utxo.resolved.datum); | ||
var dat = pushWitDatum(datum, utxo.resolved.datum, script.type); | ||
var i_2 = sortedIns.indexOf(input); | ||
@@ -622,0 +646,0 @@ if (i_2 < 0) |
{ | ||
"name": "@harmoniclabs/plu-ts-offchain", | ||
"version": "0.1.13-dev7", | ||
"version": "0.1.13-dev8", | ||
"description": "An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
257222
4778