Skip to content

Commit

Permalink
dev2
Browse files Browse the repository at this point in the history
  • Loading branch information
michele-nuzzi committed Jul 3, 2024
1 parent 5d4cc6c commit f6ef0a0
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 51 deletions.
32 changes: 16 additions & 16 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@harmoniclabs/plu-ts",
"version": "0.8.0-dev0",
"version": "0.8.0-dev2",
"description": "An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -79,7 +79,7 @@
"@harmoniclabs/plutus-machine": "^2.0.0-dev2",
"@harmoniclabs/uplc": "^1.2.3",
"@harmoniclabs/cardano-ledger-ts": "^0.2.0-dev5",
"@harmoniclabs/plu-ts-offchain": "0.1.13-dev2",
"@harmoniclabs/plu-ts-offchain": "0.1.13-dev4",
"@harmoniclabs/plu-ts-onchain": "^0.3.0-dev2"
},
"devDependencies": {
Expand Down
24 changes: 12 additions & 12 deletions packages/offchain/package-lock.json

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

2 changes: 1 addition & 1 deletion packages/offchain/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@harmoniclabs/plu-ts-offchain",
"version": "0.1.13-dev2",
"version": "0.1.13-dev4",
"description": "An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
19 changes: 12 additions & 7 deletions packages/offchain/src/TxBuilder/TxBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { fromHex, fromUtf8, isUint8Array, lexCompare, toHex } from "@harmoniclabs/uint8array-utils";
import { fromHex, isUint8Array, lexCompare, toHex } from "@harmoniclabs/uint8array-utils";
import { keepRelevant } from "./keepRelevant";
import { GenesisInfos, NormalizedGenesisInfos, defaultMainnetGenesisInfos, defaultPreprodGenesisInfos, isGenesisInfos, isNormalizedGenesisInfos, normalizedGenesisInfos } from "./GenesisInfos";
import { isCostModelsV2, isCostModelsV1, defaultV2Costs, defaultV1Costs, costModelsToLanguageViewCbor, isCostModelsV3, defaultV3Costs } from "@harmoniclabs/cardano-costmodels-ts";
import { NetworkT, ProtocolParameters, isPartialProtocolParameters, Tx, Value, ValueUnits, TxOut, TxRedeemerTag, txRdmrTagToString, ScriptType, UTxO, VKeyWitness, Script, BootstrapWitness, TxRedeemer, Hash32, TxIn, Hash28, AuxiliaryData, TxWitnessSet, getNSignersNeeded, txRedeemerTagToString, ScriptDataHash, Address, AddressStr, TxBody, CredentialType, canBeHash32, VotingProcedures, ProposalProcedure } from "@harmoniclabs/cardano-ledger-ts";
import { CborString, CborPositiveRational, Cbor, CborArray, CanBeCborString } from "@harmoniclabs/cbor";
import { isCostModelsV2, isCostModelsV1, costModelsToLanguageViewCbor, isCostModelsV3, defaultV3Costs } from "@harmoniclabs/cardano-costmodels-ts";
import { Tx, Value, ValueUnits, TxOut, TxRedeemerTag, ScriptType, UTxO, VKeyWitness, Script, BootstrapWitness, TxRedeemer, Hash32, TxIn, Hash28, AuxiliaryData, TxWitnessSet, getNSignersNeeded, txRedeemerTagToString, ScriptDataHash, TxBody, CredentialType, canBeHash32, VotingProcedures, ProposalProcedure } from "@harmoniclabs/cardano-ledger-ts";
import { CborString, Cbor, CborArray, CanBeCborString, CborPositiveRational } from "@harmoniclabs/cbor";
import { byte, blake2b_256 } from "@harmoniclabs/crypto";
import { Data, dataToCborObj, DataConstr, dataToCbor } from "@harmoniclabs/plutus-data";
import { Machine, ExBudget } from "@harmoniclabs/plutus-machine";
Expand All @@ -12,7 +12,6 @@ import { POSIXToSlot, getTxInfos, slotToPOSIX } from "../toOnChain";
import { ITxBuildArgs, ITxBuildOptions, ITxBuildInput, ITxBuildSyncOptions, txBuildOutToTxOut, normalizeITxBuildArgs, NormalizedITxBuildInput } from "../txBuild";
import { CanBeUInteger, forceBigUInt, canBeUInteger, unsafeForceUInt } from "../utils/ints";
import { freezeAll, defineReadOnlyProperty, definePropertyIfNotPresent, hasOwn, isObject } from "@harmoniclabs/obj-utils";
import { assert } from "../utils/assert";
import { TxBuilderRunner } from "./TxBuilderRunner/TxBuilderRunner";
import { ITxRunnerProvider } from "./IProvider";
import { CanBeData, canBeData, forceData } from "../utils/CanBeData";
Expand Down Expand Up @@ -308,8 +307,14 @@ export class TxBuilder
"if the protocol params are missing the script evaluation costs"
)

const executionUnitPrices = this.protocolParamters.executionUnitPrices;
const [ memRational, cpuRational ] = executionUnitPrices;
let executionUnitPrices = this.protocolParamters.executionUnitPrices;
executionUnitPrices = Array.isArray( executionUnitPrices ) ? executionUnitPrices : [
(executionUnitPrices as any).priceMemory,
(executionUnitPrices as any).priceSteps,
]
let [ memRational, cpuRational ] = executionUnitPrices;
memRational = typeof memRational === "number" ? CborPositiveRational.fromNumber( memRational ) : memRational;
cpuRational = typeof cpuRational === "number" ? CborPositiveRational.fromNumber( cpuRational ) : cpuRational;

// group by purpose so we can use the redeemer index to find the script
const spendScriptsToExec = scriptsToExec.filter( elem => elem.rdmrTag === TxRedeemerTag.Spend );
Expand Down
28 changes: 15 additions & 13 deletions packages/offchain/src/TxBuilder/TxBuilderProtocolParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CanBeUInteger, canBeUInteger } from "../utils/ints";
import { CborPositiveRational } from "@harmoniclabs/cbor";
import { ExBudget, ExBudgetJson } from "@harmoniclabs/plutus-machine";
import { Rational, cborFromRational, isRational } from "../utils/Rational";
import { CostModels, isCostModels } from "@harmoniclabs/cardano-costmodels-ts";
import { CostModels, defaultV1Costs, defaultV2Costs, defaultV3Costs, isCostModels } from "@harmoniclabs/cardano-costmodels-ts";
import { isObject } from "@harmoniclabs/obj-utils";

export interface ValidatedTxBuilderProtocolParams {
Expand Down Expand Up @@ -59,18 +59,20 @@ export interface TxBuilderProtocolParams {
}

export const defaultTxBuilderProtocolParameters = Object.freeze({
txFeePerByte: BigInt( defaultProtocolParameters.txFeePerByte ),
txFeeFixed: BigInt( defaultProtocolParameters.txFeeFixed ),
utxoCostPerByte: BigInt( defaultProtocolParameters.utxoCostPerByte ),

maxTxSize: BigInt( defaultProtocolParameters.maxTxSize ),
maxTxExecutionUnits: forceExBudget( defaultProtocolParameters.maxTxExecutionUnits ),
maxCollateralInputs: BigInt( defaultProtocolParameters.maxCollateralInputs ),
collateralPercentage: BigInt( defaultProtocolParameters.collateralPercentage ),
minfeeRefScriptCostPerByte: cborFromRational( defaultProtocolParameters.minfeeRefScriptCostPerByte ),

executionUnitPrices: forceExecUnitPricesArray( defaultProtocolParameters.executionUnitPrices ),
costModels: defaultProtocolParameters.costModels
txFeePerByte: BigInt( defaultProtocolParameters.txFeePerByte ?? 0 ),
txFeeFixed: BigInt( defaultProtocolParameters.txFeeFixed ?? 0 ),
utxoCostPerByte: BigInt( defaultProtocolParameters.utxoCostPerByte ?? 0 ),
maxTxSize: BigInt( defaultProtocolParameters.maxTxSize ?? 0 ),
maxTxExecutionUnits: forceExBudget( defaultProtocolParameters.maxTxExecutionUnits ?? { steps: 0, memory: 0 }),
maxCollateralInputs: BigInt( defaultProtocolParameters.maxCollateralInputs ?? 0 ),
collateralPercentage: BigInt( defaultProtocolParameters.collateralPercentage ?? 0 ),
minfeeRefScriptCostPerByte: cborFromRational( defaultProtocolParameters.minfeeRefScriptCostPerByte ?? 0 ),
executionUnitPrices: forceExecUnitPricesArray( defaultProtocolParameters.executionUnitPrices ?? [ 0, 0 ]),
costModels: defaultProtocolParameters.costModels ?? {
PlutusScriptV1: defaultV1Costs,
PlutusScriptV2: defaultV2Costs,
PlutusScriptV3: defaultV3Costs
}
} as ValidatedTxBuilderProtocolParams);

function forceExBudget( ex: ExBudget | ExBudgetJson ): ExBudget
Expand Down

0 comments on commit f6ef0a0

Please sign in to comment.