Skip to content

Commit

Permalink
feat: 🎸 Add matching related operations command
Browse files Browse the repository at this point in the history
✅ Closes: #29
  • Loading branch information
lovel8 committed Mar 27, 2024
1 parent bd5d882 commit 896a5c4
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down
80 changes: 80 additions & 0 deletions src/matching/repo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
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<boolean> {
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<boolean> {
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<boolean> {
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.
*
Expand Down

0 comments on commit 896a5c4

Please sign in to comment.