From 252ac6f5c98c78bb1a338daf4646ab44bf103593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Jas=CC=8Cko?= Date: Sun, 3 Dec 2023 14:30:44 +0100 Subject: [PATCH] impl --- .../src/api/cardano/cardanoCertificate.ts | 40 +++++++++++++++++++ .../connect/src/api/cardano/cardanoUtils.ts | 1 + .../src/api/cardano/cardanoWitnesses.ts | 5 ++- 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/packages/connect/src/api/cardano/cardanoCertificate.ts b/packages/connect/src/api/cardano/cardanoCertificate.ts index e24362ab268d..4b7c91723e49 100644 --- a/packages/connect/src/api/cardano/cardanoCertificate.ts +++ b/packages/connect/src/api/cardano/cardanoCertificate.ts @@ -10,6 +10,7 @@ import type { CardanoPoolOwner, CardanoPoolRelay, CardanoPoolMetadata, + CardanoDRep, } from '../../types/api/cardano'; const ipv4AddressToHex = (ipv4Address: string) => @@ -114,6 +115,16 @@ const validatePoolParameters = (poolParameters: CardanoPoolParameters) => { } }; +const validateDRep = (drep: CardanoDRep) => { + validateParams(drep, [{ name: 'type', type: 'number', required: true }]); + + if (drep.type === PROTO.CardanoDRepType.KEY_HASH) { + validateParams(drep, [{ name: 'keyHash', type: 'string', required: true }]); + } else if (drep.type === PROTO.CardanoDRepType.SCRIPT_HASH) { + validateParams(drep, [{ name: 'scriptHash', type: 'string', required: true }]); + } +}; + export type CertificateWithPoolOwnersAndRelays = { certificate: PROTO.CardanoTxCertificate; poolOwners: PROTO.CardanoPoolOwner[]; @@ -164,6 +175,20 @@ const transformPoolParameters = ( }; }; +const transformDRep = (drep?: CardanoDRep): PROTO.CardanoDRep | undefined => { + if (!drep) { + return undefined; + } + + validateDRep(drep); + + return { + type: drep.type, + key_hash: drep.keyHash, + script_hash: drep.scriptHash, + }; +}; + // transform incoming certificate object to protobuf messages format export const transformCertificate = ( certificate: CardanoCertificate, @@ -185,12 +210,25 @@ export const transformCertificate = ( paramsToValidate.push({ name: 'poolParameters', type: 'object', required: true }); } + if ( + certificate.type === PROTO.CardanoCertificateType.STAKE_REGISTRATION_CONWAY || + certificate.type === PROTO.CardanoCertificateType.STAKE_DEREGISTRATION_CONWAY + ) { + paramsToValidate.push({ name: 'deposit', type: 'string', required: true }); + } + + if (certificate.type === PROTO.CardanoCertificateType.VOTE_DELEGATION) { + paramsToValidate.push({ name: 'drep', type: 'object', required: true }); + } + validateParams(certificate, paramsToValidate); const { poolParameters, poolOwners, poolRelays } = transformPoolParameters( certificate.poolParameters, ); + const drep = transformDRep(certificate.drep); + return { certificate: { type: certificate.type, @@ -199,6 +237,8 @@ export const transformCertificate = ( key_hash: certificate.keyHash, pool: certificate.pool, pool_parameters: poolParameters, + deposit: certificate.deposit, + drep, }, poolOwners, poolRelays, diff --git a/packages/connect/src/api/cardano/cardanoUtils.ts b/packages/connect/src/api/cardano/cardanoUtils.ts index c6f1b29440ad..6d70fa25dcc9 100644 --- a/packages/connect/src/api/cardano/cardanoUtils.ts +++ b/packages/connect/src/api/cardano/cardanoUtils.ts @@ -47,6 +47,7 @@ export const prepareCertificates = (certs: CardanoCertificate[]) => { convertedCerts.push({ type: cert.type, }); + // conway certificates not supported by coin-selection lib yet break; // no default } diff --git a/packages/connect/src/api/cardano/cardanoWitnesses.ts b/packages/connect/src/api/cardano/cardanoWitnesses.ts index a1aaf41cddad..a57f65563986 100644 --- a/packages/connect/src/api/cardano/cardanoWitnesses.ts +++ b/packages/connect/src/api/cardano/cardanoWitnesses.ts @@ -29,7 +29,10 @@ export const gatherWitnessPaths = ( if ( certificate.path && (certificate.type === PROTO.CardanoCertificateType.STAKE_DELEGATION || - certificate.type === PROTO.CardanoCertificateType.STAKE_DEREGISTRATION) + certificate.type === PROTO.CardanoCertificateType.STAKE_DEREGISTRATION || + certificate.type === PROTO.CardanoCertificateType.STAKE_REGISTRATION_CONWAY || + certificate.type === PROTO.CardanoCertificateType.STAKE_DEREGISTRATION_CONWAY || + certificate.type === PROTO.CardanoCertificateType.VOTE_DELEGATION) ) { _insert(certificate.path); }