diff --git a/src/cmd.ts b/src/cmd.ts index 9ba8521..4d7bab4 100644 --- a/src/cmd.ts +++ b/src/cmd.ts @@ -314,6 +314,38 @@ function matchingCommand(yargs: yargs.Argv<{}>): { type: "string", }, }) + .command("closeMatching", "Close matching", { + matchingId: { + description: "Matching Id", + alias: "m", + demandOption: true, + type: "number", + }, + }) + .command("cancelMatching", "Cancel matching", { + matchingId: { + description: "Matching Id", + alias: "m", + demandOption: true, + type: "number", + }, + }) + .command("pauseMatching", "Pause matching", { + matchingId: { + description: "Matching Id", + alias: "m", + demandOption: true, + type: "number", + }, + }) + .command("resumeMatching", "Resume matching", { + matchingId: { + description: "Matching Id", + alias: "m", + demandOption: true, + type: "number", + }, + }) .command("getMatchingState", "Get matching state", { matchingId: { description: @@ -624,6 +656,30 @@ async function matching( amount: BigInt(String(argv.amount)), }) break + case "closeMatching": + await new Matching().closeMatching({ + context, + matchingId: Number(argv.matchingId), + }) + break + case "cancelMatching": + await new Matching().cancelMatching({ + context, + matchingId: Number(argv.matchingId), + }) + break + case "pauseMatching": + await new Matching().pauseMatching({ + context, + matchingId: Number(argv.matchingId), + }) + break + case "resumeMatching": + await new Matching().resumeMatching({ + context, + matchingId: Number(argv.matchingId), + }) + break case "getMatchingState": await new Matching().getMatchingState({ context, diff --git a/src/matching/repo/index.ts b/src/matching/repo/index.ts index 5f4ef9e..a5e2022 100644 --- a/src/matching/repo/index.ts +++ b/src/matching/repo/index.ts @@ -132,6 +132,86 @@ export class Matching { return true } + /** + * Closes a matching with the specified matching ID. + * @param options - An object containing the context and matching ID. + * @returns A Promise that resolves to true if the matching is closed successfully. + */ + @logMethodCall(["context"]) + async closeMatching(options: { + context: Context + matchingId: number + }): Promise { + options.context.evm.matchingBids + .getWallet() + .add(process.env.privateKey!) + await handleEvmError( + options.context.evm.matchingBids.closeMatching(options.matchingId) + ) + return true + } + + /** + * Cancels a matching with the specified matching ID. + * @param options - An object containing the context and matching ID. + * @returns A Promise that resolves to true if the matching is canceled successfully. + */ + @logMethodCall(["context"]) + async cancelMatching(options: { + context: Context + matchingId: number + }): Promise { + options.context.evm.matchingBids + .getWallet() + .add(process.env.datasetPreparerPrivateKey!) + await handleEvmError( + options.context.evm.matchingBids.cancelMatching(options.matchingId) + ) + return true + } + + /** + * Pauses a matching with the specified matching ID. + * @param options - An object containing the context and matching ID. + * @returns A Promise that resolves to true if the matching is paused successfully. + */ + @logMethodCall(["context"]) + async pauseMatching(options: { + context: Context + matchingId: number + }): Promise { + options.context.evm.matchingMetadata + .getWallet() + .add(process.env.datasetPreparerPrivateKey!) + await handleEvmError( + options.context.evm.matchingMetadata.pauseMatching( + options.matchingId + ) + ) + return true + } + + /** + * Resumes a matching with the specified matching ID. + * @param options - An object containing the context and matching ID. + * @returns A Promise that resolves to true if the matching is resumed successfully. + */ + @logMethodCall(["context"]) + async resumeMatching(options: { + context: Context + matchingId: number + }): Promise { + options.context.evm.matchingMetadata + .getWallet() + .add(process.env.datasetPreparerPrivateKey!) + await handleEvmError( + options.context.evm.matchingMetadata.resumeMatching( + options.matchingId + ) + ) + return true + } + /** * Retrieves the IDs of cars based on the provided JSON file path. *