-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a548f6
commit 3e81350
Showing
6 changed files
with
44 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { CKBToShannonFormatter } from 'utils/formatters' | ||
import { CapacityTooSmallException } from 'exceptions' | ||
import { bytes as byteUtils } from '@ckb-lumos/codec' | ||
import { ckbCore } from 'services/chain' | ||
|
||
export const validateCapacity = (item: State.Output, isSendMax?: boolean, isLast?: boolean) => { | ||
const { amount, unit, address } = item | ||
const capacity = CKBToShannonFormatter(amount, unit) | ||
const script = ckbCore.utils.addressToScript(address as string) | ||
|
||
const size = 1 + byteUtils.concat(script.args, script.codeHash).byteLength | ||
const outputSize = 8 + byteUtils.bytify('0x').byteLength + size | ||
|
||
const judgement = isSendMax ? !isLast : true | ||
|
||
if (BigInt(capacity) < BigInt(outputSize) * BigInt(10 ** 8) && judgement) { | ||
throw new CapacityTooSmallException(outputSize.toString()) | ||
} | ||
|
||
return true | ||
} | ||
export default validateCapacity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3e81350
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Packaging for test is done in 7000538827