Skip to content

Commit

Permalink
Merge pull request #30 from dataswap/enhance/Add-closeMatching-command
Browse files Browse the repository at this point in the history
feat: 🎸 Add matching related operations command
  • Loading branch information
siriusyim authored Mar 27, 2024
2 parents 20e6563 + cdc292b commit 9aa3bdd
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 9aa3bdd

Please sign in to comment.