Skip to content

Commit e8f3f0b

Browse files
authored
Merge pull request #1485 from input-output-hk/fix/LW-11572-V10-protocol-fixes
LW-11572 V10 protocol fixes
2 parents bf1c222 + 0b86722 commit e8f3f0b

File tree

3 files changed

+16
-48
lines changed

3 files changed

+16
-48
lines changed

packages/cardano-services/src/Utxo/DbSyncUtxoProvider/mappers.ts

+12
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ const parseReferenceScript = (model: UtxoModel): Cardano.Script => {
5353
version: Cardano.PlutusLanguageVersion.V2
5454
};
5555
break;
56+
case ReferenceScriptType.PlutusV3:
57+
if (!isNotNil(model.reference_script_bytes))
58+
throw new SerializationError(
59+
SerializationFailure.InvalidScript,
60+
'Unexpected error deserializing PlutusV2 script. Data is null'
61+
);
62+
script = {
63+
__type: Cardano.ScriptType.Plutus,
64+
bytes: model.reference_script_bytes as unknown as HexBlob,
65+
version: Cardano.PlutusLanguageVersion.V3
66+
};
67+
break;
5668
default:
5769
throw new SerializationError(
5870
SerializationFailure.InvalidScriptType,

packages/cardano-services/src/Utxo/DbSyncUtxoProvider/types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ export enum ReferenceScriptType {
2828
Multisig = 'multisig',
2929
Timelock = 'timelock',
3030
PlutusV1 = 'plutusV1',
31-
PlutusV2 = 'plutusV2'
31+
PlutusV2 = 'plutusV2',
32+
PlutusV3 = 'plutusV3'
3233
}

packages/core/src/Serialization/Update/Costmdls/CostModel.ts

+2-47
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import { InvalidArgumentError, InvalidStateError } from '@cardano-sdk/util';
1+
import { InvalidArgumentError } from '@cardano-sdk/util';
22
import { PlutusLanguageVersion } from '../../../Cardano/types/Script';
33

4-
const PLUTUS_V1_COST_MODEL_OP_COUNT = 166;
5-
const PLUTUS_V2_COST_MODEL_OP_COUNT = 175;
6-
const PLUTUS_V3_COST_MODEL_OP_COUNT = 179;
7-
84
/**
95
* The execution of plutus scripts consumes resources. To make sure that these
106
* scripts don't run indefinitely or consume excessive resources (which would be
@@ -28,32 +24,6 @@ export class CostModel {
2824
constructor(language: PlutusLanguageVersion, costs: Array<number>) {
2925
this.#language = language;
3026
this.#costs = costs;
31-
32-
switch (this.#language) {
33-
case PlutusLanguageVersion.V1:
34-
if (costs.length !== PLUTUS_V1_COST_MODEL_OP_COUNT)
35-
throw new InvalidArgumentError(
36-
'costs',
37-
`Cost model for PlutusV2 language should have ${PLUTUS_V2_COST_MODEL_OP_COUNT} operations, but got ${costs.length}.`
38-
);
39-
break;
40-
case PlutusLanguageVersion.V2:
41-
if (costs.length !== PLUTUS_V2_COST_MODEL_OP_COUNT)
42-
throw new InvalidArgumentError(
43-
'costs',
44-
`Cost model for PlutusV2 language should have ${PLUTUS_V2_COST_MODEL_OP_COUNT} operations, but got ${costs.length}.`
45-
);
46-
break;
47-
case PlutusLanguageVersion.V3:
48-
if (costs.length !== PLUTUS_V3_COST_MODEL_OP_COUNT)
49-
throw new InvalidArgumentError(
50-
'costs',
51-
`Cost model for PlutusV3 language should have ${PLUTUS_V3_COST_MODEL_OP_COUNT} operations, but got ${costs.length}.`
52-
);
53-
break;
54-
default:
55-
throw new InvalidStateError('Invalid plutus language version.');
56-
}
5727
}
5828

5929
/**
@@ -141,21 +111,6 @@ export class CostModel {
141111
* @returns true if is a valid operation; otherwise; false.
142112
*/
143113
#isOperationValid(operation: number): boolean {
144-
let isValid = false;
145-
switch (this.#language) {
146-
case PlutusLanguageVersion.V1:
147-
isValid = operation >= 0 && operation < PLUTUS_V1_COST_MODEL_OP_COUNT;
148-
break;
149-
case PlutusLanguageVersion.V2:
150-
isValid = operation >= 0 && operation < PLUTUS_V2_COST_MODEL_OP_COUNT;
151-
break;
152-
case PlutusLanguageVersion.V3:
153-
isValid = operation >= 0 && operation < PLUTUS_V3_COST_MODEL_OP_COUNT;
154-
break;
155-
default:
156-
throw new InvalidStateError('Invalid plutus language version.');
157-
}
158-
159-
return isValid;
114+
return operation >= 0;
160115
}
161116
}

0 commit comments

Comments
 (0)