Skip to content

Commit

Permalink
chore: add calculateDaoMaximumWithdraw
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Nov 7, 2019
1 parent 2460b0b commit c0dbdb9
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions packages/neuron-wallet/src/services/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ export default class WalletService {

public withdrawFormDao = async (
walletID: string,
_depositOutPoint: OutPoint,
depositOutPoint: OutPoint,
withdrawingOutPoint: OutPoint,
fee: string = '0',
feeRate: string = '0'
Expand Down Expand Up @@ -654,7 +654,7 @@ export default class WalletService {
const minimalSince = this.epochSince(minimalSinceEpochLength, minimalSinceEpochIndex, minimalSinceEpochNumber)

// TODO: calculate_dao_maximum_withdraw rpc
const outputCapacity = '1000'
const outputCapacity: bigint = await this.calculateDaoMaximumWithdraw(depositOutPoint, withdrawBlock.hash)

const { codeHash, outPoint: secpOutPoint, hashType } = await LockUtils.systemScript()
const daoScriptInfo = await DaoUtils.daoScript()
Expand Down Expand Up @@ -707,6 +707,23 @@ export default class WalletService {
}
}

public calculateDaoMaximumWithdraw = async (depositOutPoint: OutPoint, withdrawBlockHash: string): bigint => {
const calculateDaoMaximumWithdrawMethod = {
name: 'calculateDaoMaximumWithdraw',
method: 'calculate_dao_maximum_withdraw',
paramsFormatters: [core.rpc.paramsFormatter.toOutPoint, core.rpc.paramsFormatter.toHash],
}

core.rpc.addMethod(calculateDaoMaximumWithdrawMethod)

const result = await (core.rpc as any).calculateDaoMaximumWithdraw(
ConvertTo.toSdkOutPoint(depositOutPoint),
withdrawBlockHash,
)

return BigInt(result)
}

public parseEpoch = (epoch: bigint) => {
return {
length: (epoch >> BigInt(40)) & BigInt(0xFFFF),
Expand Down

0 comments on commit c0dbdb9

Please sign in to comment.