Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
55 lines (48 sloc) 1.83 KB
import { BaseCommand } from '../../base'
import { newCheckBuilder } from '../../utils/checks'
import { displaySendTx } from '../../utils/cli'
import { Flags } from '../../utils/command'
export default class Withdraw extends BaseCommand {
static description = 'Withdraw unlocked gold whose unlocking period has passed.'
static flags = {
...BaseCommand.flags,
from: Flags.address({ required: true }),
}
static examples = ['withdraw --from 0x47e172F6CfB6c7D01C1574fa3E2Be7CC73269D95']
async run() {
// tslint:disable-next-line
const { flags } = this.parse(Withdraw)
this.kit.defaultAccount = flags.from
const lockedgold = await this.kit.contracts.getLockedGold()
await newCheckBuilder(this)
.isAccount(flags.from)
.runChecks()
const currentTime = Math.round(new Date().getTime() / 1000)
while (true) {
let madeWithdrawal = false
const pendingWithdrawals = await lockedgold.getPendingWithdrawals(flags.from)
for (let i = 0; i < pendingWithdrawals.length; i++) {
const pendingWithdrawal = pendingWithdrawals[i]
if (pendingWithdrawal.time.isLessThan(currentTime)) {
console.log(
`Found available pending withdrawal of value ${pendingWithdrawal.value.toString()}, withdrawing`
)
await displaySendTx('withdraw', lockedgold.withdraw(i))
madeWithdrawal = true
break
}
}
if (!madeWithdrawal) {
break
}
}
const remainingPendingWithdrawals = await lockedgold.getPendingWithdrawals(flags.from)
for (const pendingWithdrawal of remainingPendingWithdrawals) {
console.log(
`Pending withdrawal of value ${pendingWithdrawal.value.toString()} available for withdrawal in ${pendingWithdrawal.time
.minus(currentTime)
.toString()} seconds.`
)
}
}
}
You can’t perform that action at this time.