Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions scripts/ci/scenarios/steps/certificates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getDefaultBot } from "../../framework/botContext";
import { authenticateBot } from "../../framework/botAuth";
import { stringifyRedacted } from "../../framework/redact";
import { boolFromEnv } from "../../framework/env";
import { hashDrepAnchor } from "@meshsdk/core";

type ScriptUtxo = {
input: { txHash: string; outputIndex: number };
Expand Down Expand Up @@ -165,7 +166,7 @@ function createCertPhaseSteps(args: {
label: string;
runtime: { transactionId?: string; spentUtxoRefs?: { txHash: string; outputIndex: number }[] };
requireBroadcastSuccess: boolean;
buildExtraBody?: (ctx: CIBootstrapContext) => Record<string, unknown>;
buildExtraBody?: (ctx: CIBootstrapContext) => Promise<Record<string, unknown>> | Record<string, unknown>;
/** When true, each signing step uses the stake-cert flow (payment + stake witnesses). */
useStakeCertFlow?: boolean;
}): RouteStep[] {
Expand All @@ -192,13 +193,14 @@ function createCertPhaseSteps(args: {
fresh: true,
});

const extraBody = args.buildExtraBody ? await args.buildExtraBody(ctx) : {};
const body: Record<string, unknown> = {
walletId: wallet.walletId,
address: bot.paymentAddress,
action,
utxoRefs,
description: label,
...(args.buildExtraBody?.(ctx) ?? {}),
...extraBody,
};

const response = await requestJson<{ id?: string; error?: string }>({
Expand Down Expand Up @@ -504,12 +506,16 @@ export function createScenarioDRepCertificates(): Scenario {
const sdkReg: { transactionId?: string; spentUtxoRefs?: { txHash: string; outputIndex: number }[] } = {};
const sdkRetire: { transactionId?: string; spentUtxoRefs?: { txHash: string; outputIndex: number }[] } = {};

function buildDRepRegBody(): Record<string, unknown> {
async function buildDRepRegBody(): Promise<Record<string, unknown>> {
const anchorUrl = process.env.CI_DREP_ANCHOR_URL?.trim();
if (!anchorUrl) {
throw new Error("CI_DREP_ANCHOR_URL is required for DRep registration");
}
return { anchorUrl };
const res = await fetch(anchorUrl);
if (!res.ok) throw new Error(`Failed to fetch DRep anchor URL: HTTP ${res.status}`);
const json = await res.json() as object;
const anchorDataHash = hashDrepAnchor(json);
return { anchorUrl, anchorDataHash };
}

return {
Expand Down
20 changes: 5 additions & 15 deletions src/pages/api/v1/botDRepCertificate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { getTxBuilder } from "@/utils/get-tx-builder";
import { resolveWalletScriptAddress } from "@/lib/server/walletScriptAddress";
import { resolveUtxoRefsFromChain } from "@/lib/server/resolveUtxoRefsFromChain";
import { createPendingMultisigTransaction } from "@/lib/server/createPendingMultisigTransaction";
import { resolveDRepAnchorFromUrl } from "@/lib/server/resolveDRepAnchorFromUrl";
import type { DbWalletWithLegacy } from "@/types/wallet";
import type { Wallet as AppWallet } from "@/types/wallet";
import type { MultisigWallet } from "@/utils/multisigSDK";
Expand Down Expand Up @@ -177,19 +176,10 @@ export default async function handler(
if (!anchorUrl) {
return res.status(400).json({ error: "anchorUrl is required for register" });
}
let resolvedAnchorUrl: string;
let anchorDataHash: string;
try {
const r = await resolveDRepAnchorFromUrl(
anchorUrl,
typeof body.anchorDataHash === "string" ? body.anchorDataHash : undefined,
);
resolvedAnchorUrl = r.anchorUrl;
anchorDataHash = r.anchorDataHash;
} catch (e) {
return res.status(400).json({
error: e instanceof Error ? e.message : "Failed to resolve anchor",
});
const anchorDataHash =
typeof body.anchorDataHash === "string" ? body.anchorDataHash.trim() : "";
if (!anchorDataHash) {
return res.status(400).json({ error: "anchorDataHash is required for register — compute it from the anchor JSON before calling this endpoint" });
}

for (const utxo of utxos) {
Expand All @@ -204,7 +194,7 @@ export default async function handler(

txBuilder
.drepRegistrationCertificate(dRepId, {
anchorUrl: resolvedAnchorUrl,
anchorUrl,
anchorDataHash,
})
.certificateScript(drepCbor)
Expand Down
Loading