Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bounty module CLI commands #3102

Open
wants to merge 16 commits into
base: rhodes
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
implemented withdraw funding commands
  • Loading branch information
zeeshanakram3 committed Jan 28, 2022
commit a39e43be3ca8ccb15ffec62e73d94515c8b90693
65 changes: 65 additions & 0 deletions cli/src/commands/bounty/withdrawFunding.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import chalk from 'chalk'
import BountyCommandBase from '../../base/BountyCommandBase'
import ExitCodes from '../../ExitCodes'

export default class WithdrawFundingCommand extends BountyCommandBase {
static description = 'Withdraw funding from the bounty.'
static args = [
{
name: 'bountyId',
required: true,
description: 'ID of the Bounty',
},
]

static flags = {
funderContext: BountyCommandBase.bountyActorContextFlag,
}

async run() {
let { funderContext } = this.parse(WithdrawFundingCommand).flags
const { bountyId } = this.parse(WithdrawFundingCommand).args

// Context
if (!funderContext) {
funderContext = await this.promptForCreatorContext()
}

const [funder, funderAddress] = await this.getBountyActor(funderContext)
const bounty = await this.getApi().bountyById(bountyId)

const isFundingStage = await this.isFundingStage(bounty)
const isFundingExpiredStage = await this.isFundingExpiredStage(bounty)
const isWorkSubmissionStage = await this.isWorkSubmissionStage(bounty)
const isJudgmentStage = await this.isJudgmentStage(bounty)
const isSuccessfulBountyWithdrawlStage = await this.isSuccessfulBountyWithdrawalStage(bounty)

// if bounty is in any of the following stages funds cannot be withdrawn
if (
isFundingStage ||
isFundingExpiredStage ||
isWorkSubmissionStage ||
isJudgmentStage ||
isSuccessfulBountyWithdrawlStage
) {
this.error('Funds cannot be withdrawn in this stage', { exit: ExitCodes.AccessDenied })
}

this.jsonPrettyPrint(JSON.stringify({ bountyId }))

await this.requireConfirmation('Do you confirm to withdraw funding from bounty?', true)

const result = await this.sendAndFollowNamedTx(
await this.getDecodedPair(funderAddress),
'bounty',
'withdrawFunding',
[funder, bountyId]
)
if (result) {
const event = this.findEvent(result, 'bounty', 'BountyFundingWithdrawal')
this.log(
chalk.green(`Amount successfully refunded from bounty with id ${chalk.cyanBright(event?.data[1].toString())} !`)
)
}
}
}
57 changes: 57 additions & 0 deletions cli/src/commands/bounty/withdrawWorkEntrantFunds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import chalk from 'chalk'
import BountyCommandBase from '../../base/BountyCommandBase'
import ExitCodes from '../../ExitCodes'

export default class WithdrawWorkEntrantCommand extends BountyCommandBase {
static description = 'Cashout work entrant funds.'
static args = [
{
name: 'bountyId',
required: true,
description: 'Identifier for bounty to which work entry corresponds.',
},
{
name: 'entryId',
required: true,
description: 'Identifier for work entry.',
},
]

async run() {
const { bountyId, entryId } = this.parse(WithdrawWorkEntrantCommand).args

const bounty = await this.getApi().bountyById(bountyId)
await this.getApi().entryById(entryId)
// Get member context
const memberContext = await this.getRequiredMemberContext()

const isFundingStage = await this.isFundingStage(bounty)
const isFundingExpiredStage = await this.isFundingExpiredStage(bounty)
const isWorkSubmissionStage = await this.isWorkSubmissionStage(bounty)
const isJudgmentStage = await this.isJudgmentStage(bounty)

// if bounty is in any of the following stages work entrant funds cannot be withdrawn
if (isFundingStage || isFundingExpiredStage || isWorkSubmissionStage || isJudgmentStage) {
this.error('Work entrant funds cannot be withdrawn in this stage', { exit: ExitCodes.AccessDenied })
}

this.jsonPrettyPrint(JSON.stringify({ memberId: memberContext.id, bountyId, entryId }))

await this.requireConfirmation('Do you confirm the the input?', true)

const result = await this.sendAndFollowNamedTx(
await this.getDecodedPair(memberContext.membership.controller_account.toString()),
'bounty',
'withdrawWorkEntrantFunds',
[memberContext.id, bountyId, entryId]
)
if (result) {
const event = this.findEvent(result, 'bounty', 'WorkEntrantFundsWithdrawn')
this.log(
chalk.green(
`Work entrant funds successfully cashed out for bounty with id ${chalk.cyanBright(event?.data[0].toString())}`
)
)
}
}
}