Showing 137 of 388 total issues
Function list
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
list (): SetLoanToken[] {
return [
{
symbol: 'DUSD',
name: 'Decentralized USD',
Function createVoc
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
Open
async createVoc (createVoc: CreateVoc, changeScript: Script): Promise<TransactionSegWit> {
if (!createVoc.nAmount.isEqualTo(new BigNumber(0))) {
throw new TxnBuilderError(TxnBuilderErrorType.INVALID_VOC_AMOUNT,
'CreateVoc amount should be 0'
)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function catchUp
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
private async catchUp (): Promise<void> {
const lastBlock = await this.getCrawledTip()
const nextBlockHeight = lastBlock === undefined ? 0 : lastBlock.data.height + 1
const nextBlock = await this.getBlock(nextBlockHeight)
Function createVoc
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
async createVoc (createVoc: CreateVoc, changeScript: Script): Promise<TransactionSegWit> {
if (!createVoc.nAmount.isEqualTo(new BigNumber(0))) {
throw new TxnBuilderError(TxnBuilderErrorType.INVALID_VOC_AMOUNT,
'CreateVoc amount should be 0'
)
Function list
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
list (): Array<Record<string, any>> {
return [
{
ATTRIBUTES: {
// dfi pay dtoken
Function dump
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
async dump (): Promise<boolean> {
let id = 0
const maxSize = 500_000
const dir = path.join(process.cwd(), 'dump')
if (!fs.existsSync(dir)) {
Function shouldQueryPartitionPagination
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
export async function shouldQueryPartitionPagination (database: Database): Promise<void> {
const window43 = await database.query(PartitionMapping.index.partition_a, {
limit: 2,
order: SortOrder.DESC
})
Function indexTransaction
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
async indexTransaction (block: RawBlock, transaction: DfTxTransaction<AppointOracle>): Promise<void> {
const data = transaction.dftx.data
const txn = transaction.txn
const oracleId = txn.txid
Function getMemberStats
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
async getMemberStats (memberId: string): Promise<MemberStatsInfo> {
const attrs: Record<string, any> = (await this.rpcClient.masternode.getGov('ATTRIBUTES')).ATTRIBUTES
const keys: string[] = Object.keys(attrs)
const membersKeyRegex = /^v0\/consortium\/\d+\/members$/
Function validate
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
async validate (hex: string): Promise<void> {
if (!hex.startsWith('040000000001')) {
return
}
Function computeReturnLessDexFeesInDestinationToken
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function computeReturnLessDexFeesInDestinationToken (path: SwapPathPoolPair[], fromTokenId: string): {
estimatedReturn: BigNumber
estimatedReturnLessDexFees: BigNumber
} {
let estimatedReturnLessDexFees = new BigNumber(1)
Function mapError
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function mapError (err: Error, url: string): ApiError {
if (err instanceof ApiException) {
return {
code: err.code,
type: err.type,
Function getTokenUSDValue
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
private async getTokenUSDValue (id: string): Promise<BigNumber | undefined> {
return await this.cache.get<BigNumber>(`PRICE_FOR_TOKEN_${id}`, async () => {
const tokenInfo = await this.deFiDCache.getTokenInfo(id)
const token = tokenInfo?.symbol
Function maxPriceAsBigNumber
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
static maxPriceAsBigNumber (getter: () => BigNumber, setter: (data: BigNumber) => void): BufferComposer {
return {
fromBuffer: (buffer: SmartBuffer): void => {
const integer = readBigNumberUInt64(buffer)
const fraction = readBigNumberUInt64(buffer)
Function pushToAssetBreakdownInfo
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
private pushToAssetBreakdownInfo (assetBreakdownInfo: AssetBreakdownInfo[], memberId: string, memberDetail: MemberDetail, tokenId: string, tokens: TokenInfoWithId[]): void {
const backingAddresses: string[] = memberDetail.backingId.length > 0 ? memberDetail.backingId.split(',').map(a => a.trim()) : []
const member: MemberWithTokenInfo = {
id: memberId,
Function readiness
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
async readiness (): Promise<HealthIndicatorResult> {
let highest: Block
let index: number | undefined
let defid: number | undefined
Function findSwap
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
private async findSwap (network: NetworkName, poolSwap: PoolSwap, transaction: Transaction): Promise<LegacySubgraphSwap | undefined> {
const fromAddress = fromScript(poolSwap.fromScript, network)?.address
const toAddress = fromScript(poolSwap.toScript, network)?.address
if (
Function from
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function from<T extends Address> (net: NetworkName, address: string): T {
const network = getNetwork(net)
const possible: Map<AddressTypeDeprecated, Address> = new Map()
possible.set('Unknown', new UnknownTypeAddress(network, address))
possible.set('P2PKH', Base58Address.fromAddress<P2PKH>(network, address, P2PKH))
Function getUSDVolume
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
public async getUSDVolume (id: string): Promise<PoolPairData['volume'] | undefined> {
return await this.cache.get<PoolPairData['volume']>(`POOLPAIR_VOLUME_${id}`, async () => {
const gatherAmount = async (interval: PoolSwapAggregatedInterval, count: number): Promise<number> => {
const aggregated: Record<string, number> = {}
const swaps = await this.poolSwapAggregatedMapper.query(`${id}-${interval as number}`, count)
Function indexSwap
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
async indexSwap (block: RawBlock, transaction: DfTxTransaction<any>, poolPairId: string, fromTokenId: number, fromAmount: BigNumber): Promise<void> {
await this.poolSwapMapper.put({
id: `${poolPairId}-${transaction.txn.txid}`,
txid: transaction.txn.txid,
txno: transaction.txnNo,