Skip to content

Commit cd6ff0c

Browse files
authored
Merge pull request #495 from input-output-hk/chore/adp-1858-upgrade-from-csl-to-cml
ADP-1858-upgrade-from-csl-to-cml
2 parents cbd23d4 + 5c0c5f4 commit cd6ff0c

File tree

67 files changed

+3983
-4895
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+3983
-4895
lines changed

packages/cardano-services/src/TxSubmit/rabbitmq/RabbitMqTxSubmitProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
ProviderFailure,
66
SubmitTxArgs,
77
TxSubmitProvider,
8-
cslUtil
8+
cmlUtil
99
} from '@cardano-sdk/core';
1010
import { Channel, Connection, connect } from 'amqplib';
1111
import { Logger } from 'ts-log';
@@ -171,7 +171,7 @@ export class RabbitMqTxSubmitProvider implements TxSubmitProvider {
171171
};
172172

173173
try {
174-
txId = cslUtil.deserializeTx(signedTransaction).id.toString();
174+
txId = cmlUtil.deserializeTx(signedTransaction).id.toString();
175175

176176
this.#dependencies.logger.info(`${moduleName}: queuing tx id: ${txId}`);
177177

packages/cardano-services/src/TxSubmit/rabbitmq/TxSubmitWorker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { CONNECTION_ERROR_EVENT, TX_SUBMISSION_QUEUE, serializeError, waitForPen
33
import { Channel, Connection, Message, connect } from 'amqplib';
44
import { EventEmitter } from 'events';
55
import { Logger } from 'ts-log';
6-
import { ProviderError, ProviderFailure, TxSubmitProvider, cslUtil } from '@cardano-sdk/core';
6+
import { ProviderError, ProviderFailure, TxSubmitProvider, cmlUtil } from '@cardano-sdk/core';
77
import { bufferToHexString } from '@cardano-sdk/util';
88

99
const moduleName = 'TxSubmitWorker';
@@ -281,7 +281,7 @@ export class TxSubmitWorker extends EventEmitter {
281281
const txBody = new Uint8Array(content);
282282

283283
// Register the handling of current transaction
284-
txId = cslUtil.deserializeTx(txBody).id.toString();
284+
txId = cmlUtil.deserializeTx(txBody).id.toString();
285285

286286
this.#dependencies.logger.info(`${moduleName}: submitting tx #${counter} id: ${txId}`);
287287
this.#dependencies.logger.debug(`${moduleName}: tx #${counter} dump:`, [content.toString('hex')]);

packages/core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
"dependencies": {
6464
"@cardano-ogmios/client": "5.5.5",
6565
"@cardano-sdk/util": "^0.5.0",
66-
"@emurgo/cardano-serialization-lib-browser": "11.0.5",
67-
"@emurgo/cardano-serialization-lib-nodejs": "11.0.5",
66+
"@dcspark/cardano-multiplatform-lib-browser": "^3.1.0",
67+
"@dcspark/cardano-multiplatform-lib-nodejs": "^3.1.0",
6868
"@emurgo/cip14-js": "^3.0.1",
6969
"bech32": "^2.0.0",
7070
"lodash": "^4.17.21",

packages/core/src/Asset/util/assetId.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AssetId, AssetName, PolicyId } from '../../Cardano/types';
2-
import { CSL } from '../../CSL/CSL';
2+
import { CML } from '../../CML/CML';
33
import { bytesToHex } from '../../util/misc/bytesToHex';
44

55
export const policyIdFromAssetId = (assetId: AssetId): PolicyId => PolicyId(assetId.slice(0, 56));
@@ -8,7 +8,7 @@ export const assetNameFromAssetId = (assetId: AssetId): AssetName => AssetName(a
88
/**
99
* @returns {string} concatenated hex-encoded policy id and asset name
1010
*/
11-
export const createAssetId = (scriptHash: CSL.ScriptHash, assetName: CSL.AssetName): AssetId =>
11+
export const createAssetId = (scriptHash: CML.ScriptHash, assetName: CML.AssetName): AssetId =>
1212
AssetId(bytesToHex(scriptHash.to_bytes()) + bytesToHex(assetName.name()).toString());
1313

1414
/**
@@ -21,7 +21,7 @@ export const parseAssetId = (assetId: AssetId) => {
2121
const policyId = policyIdFromAssetId(assetId);
2222
const assetName = assetNameFromAssetId(assetId);
2323
return {
24-
assetName: CSL.AssetName.new(Buffer.from(assetName, 'hex')),
25-
scriptHash: CSL.ScriptHash.from_bytes(Buffer.from(policyId, 'hex'))
24+
assetName: CML.AssetName.new(Buffer.from(assetName, 'hex')),
25+
scriptHash: CML.ScriptHash.from_bytes(Buffer.from(policyId, 'hex'))
2626
};
2727
};

packages/core/src/CML/CML.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import * as CML from '@dcspark/cardano-multiplatform-lib-nodejs';
2+
export * as CML from '@dcspark/cardano-multiplatform-lib-nodejs';
3+
export type CardanoMultiplatformLib = typeof CML;

packages/core/src/CSL/cslToCore/certificate.ts renamed to packages/core/src/CML/cmlToCore/certificate.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CSL } from '../CSL';
1+
import { CML } from '../CML';
22
import {
33
Certificate,
44
CertificateType,
@@ -19,23 +19,23 @@ import { NetworkId } from '../../Cardano/NetworkId';
1919
import { NotImplementedError, SerializationError, SerializationFailure } from '../../errors';
2020
import { usingAutoFree } from '@cardano-sdk/util';
2121

22-
const stakeRegistration = (certificate: CSL.StakeRegistration): StakeAddressCertificate =>
22+
const stakeRegistration = (certificate: CML.StakeRegistration): StakeAddressCertificate =>
2323
usingAutoFree((scope) => ({
2424
__typename: CertificateType.StakeKeyRegistration,
2525
stakeKeyHash: Ed25519KeyHash(
2626
Buffer.from(scope.manage(scope.manage(certificate.stake_credential()).to_keyhash())!.to_bytes()).toString('hex')
2727
)
2828
}));
2929

30-
const stakeDeregistration = (certificate: CSL.StakeDeregistration): StakeAddressCertificate =>
30+
const stakeDeregistration = (certificate: CML.StakeDeregistration): StakeAddressCertificate =>
3131
usingAutoFree((scope) => ({
3232
__typename: CertificateType.StakeKeyDeregistration,
3333
stakeKeyHash: Ed25519KeyHash(
3434
Buffer.from(scope.manage(scope.manage(certificate.stake_credential()).to_keyhash())!.to_bytes()).toString('hex')
3535
)
3636
}));
3737

38-
const stakeDelegation = (certificate: CSL.StakeDelegation): StakeDelegationCertificate =>
38+
const stakeDelegation = (certificate: CML.StakeDelegation): StakeDelegationCertificate =>
3939
usingAutoFree((scope) => ({
4040
__typename: CertificateType.StakeDelegation,
4141
poolId: PoolId(scope.manage(certificate.pool_keyhash()).to_bech32('pool')),
@@ -44,7 +44,7 @@ const stakeDelegation = (certificate: CSL.StakeDelegation): StakeDelegationCerti
4444
)
4545
}));
4646

47-
const createCardanoRelays = (relays: CSL.Relays): Relay[] =>
47+
const createCardanoRelays = (relays: CML.Relays): Relay[] =>
4848
usingAutoFree((scope) => {
4949
const result: Relay[] = [];
5050
for (let i = 0; i < relays.len(); i++) {
@@ -81,19 +81,19 @@ const createCardanoRelays = (relays: CSL.Relays): Relay[] =>
8181
return result;
8282
});
8383

84-
const createCardanoOwners = (owners: CSL.Ed25519KeyHashes, networkId: NetworkId): RewardAccount[] =>
84+
const createCardanoOwners = (owners: CML.Ed25519KeyHashes, networkId: NetworkId): RewardAccount[] =>
8585
usingAutoFree((scope) => {
8686
const result: RewardAccount[] = [];
8787
for (let i = 0; i < owners.len(); i++) {
8888
const keyHash = scope.manage(owners.get(i));
89-
const stakeCredential = scope.manage(CSL.StakeCredential.from_keyhash(keyHash));
90-
const rewardAccount = scope.manage(CSL.RewardAddress.new(networkId, stakeCredential));
89+
const stakeCredential = scope.manage(CML.StakeCredential.from_keyhash(keyHash));
90+
const rewardAccount = scope.manage(CML.RewardAddress.new(networkId, stakeCredential));
9191
result.push(RewardAccount(scope.manage(rewardAccount.to_address()).to_bech32()));
9292
}
9393
return result;
9494
});
9595

96-
const jsonMetadata = (poolMetadata?: CSL.PoolMetadata): PoolMetadataJson | undefined =>
96+
const jsonMetadata = (poolMetadata?: CML.PoolMetadata): PoolMetadataJson | undefined =>
9797
usingAutoFree((scope) => {
9898
if (!poolMetadata) return;
9999
return {
@@ -102,7 +102,7 @@ const jsonMetadata = (poolMetadata?: CSL.PoolMetadata): PoolMetadataJson | undef
102102
};
103103
});
104104

105-
export const poolRegistration = (certificate: CSL.PoolRegistration): PoolRegistrationCertificate =>
105+
export const poolRegistration = (certificate: CML.PoolRegistration): PoolRegistrationCertificate =>
106106
usingAutoFree((scope) => {
107107
const poolParams = scope.manage(certificate.pool_params());
108108
const rewardAccountAddress = scope.manage(scope.manage(poolParams.reward_account()).to_address());
@@ -125,14 +125,14 @@ export const poolRegistration = (certificate: CSL.PoolRegistration): PoolRegistr
125125
} as PoolRegistrationCertificate;
126126
});
127127

128-
const poolRetirement = (certificate: CSL.PoolRetirement): PoolRetirementCertificate =>
128+
const poolRetirement = (certificate: CML.PoolRetirement): PoolRetirementCertificate =>
129129
usingAutoFree((scope) => ({
130130
__typename: CertificateType.PoolRetirement,
131131
epoch: certificate.epoch(),
132132
poolId: PoolId(scope.manage(certificate.pool_keyhash()).to_bech32('pool'))
133133
}));
134134

135-
const genesisKeyDelegaation = (certificate: CSL.GenesisKeyDelegation): GenesisKeyDelegationCertificate =>
135+
const genesisKeyDelegaation = (certificate: CML.GenesisKeyDelegation): GenesisKeyDelegationCertificate =>
136136
usingAutoFree((scope) => ({
137137
__typename: CertificateType.GenesisKeyDelegation,
138138
genesisDelegateHash: Hash32ByteBase16(
@@ -142,22 +142,22 @@ const genesisKeyDelegaation = (certificate: CSL.GenesisKeyDelegation): GenesisKe
142142
vrfKeyHash: Hash32ByteBase16(Buffer.from(scope.manage(certificate.vrf_keyhash()).to_bytes()).toString())
143143
}));
144144

145-
export const createCertificate = (cslCertificate: CSL.Certificate): Certificate =>
145+
export const createCertificate = (cmlCertificate: CML.Certificate): Certificate =>
146146
usingAutoFree((scope) => {
147-
switch (cslCertificate.kind()) {
148-
case CSL.CertificateKind.StakeRegistration:
149-
return stakeRegistration(scope.manage(cslCertificate.as_stake_registration()!));
150-
case CSL.CertificateKind.StakeDeregistration:
151-
return stakeDeregistration(scope.manage(cslCertificate.as_stake_deregistration()!));
152-
case CSL.CertificateKind.StakeDelegation:
153-
return stakeDelegation(scope.manage(cslCertificate.as_stake_delegation()!));
154-
case CSL.CertificateKind.PoolRegistration:
155-
return poolRegistration(scope.manage(cslCertificate.as_pool_registration()!));
156-
case CSL.CertificateKind.PoolRetirement:
157-
return poolRetirement(scope.manage(cslCertificate.as_pool_retirement()!));
158-
case CSL.CertificateKind.GenesisKeyDelegation:
159-
return genesisKeyDelegaation(scope.manage(cslCertificate.as_genesis_key_delegation()!));
160-
case CSL.CertificateKind.MoveInstantaneousRewardsCert:
147+
switch (cmlCertificate.kind()) {
148+
case CML.CertificateKind.StakeRegistration:
149+
return stakeRegistration(scope.manage(cmlCertificate.as_stake_registration()!));
150+
case CML.CertificateKind.StakeDeregistration:
151+
return stakeDeregistration(scope.manage(cmlCertificate.as_stake_deregistration()!));
152+
case CML.CertificateKind.StakeDelegation:
153+
return stakeDelegation(scope.manage(cmlCertificate.as_stake_delegation()!));
154+
case CML.CertificateKind.PoolRegistration:
155+
return poolRegistration(scope.manage(cmlCertificate.as_pool_registration()!));
156+
case CML.CertificateKind.PoolRetirement:
157+
return poolRetirement(scope.manage(cmlCertificate.as_pool_retirement()!));
158+
case CML.CertificateKind.GenesisKeyDelegation:
159+
return genesisKeyDelegaation(scope.manage(cmlCertificate.as_genesis_key_delegation()!));
160+
case CML.CertificateKind.MoveInstantaneousRewardsCert:
161161
throw new NotImplementedError('MIR certificate conversion'); // TODO: support this certificate type
162162
default:
163163
throw new SerializationError(SerializationFailure.InvalidType);

0 commit comments

Comments
 (0)