-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add isMalicious field to balances * default to setting all balances to isMalicious: false * rm comment * update test name * fix formatting
- Loading branch information
1 parent
5ea726d
commit 26bd893
Showing
4 changed files
with
252 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Logger } from "pino"; | ||
import { BlockAidService } from ".."; | ||
import { NetworkNames } from "../../../helper/validate"; | ||
|
||
export const addScannedStatus = async ( | ||
balances: { [key: string]: {} }, | ||
blockaidService: BlockAidService, | ||
network: NetworkNames, | ||
logger: Logger | ||
) => { | ||
const scannedBalances = {} as { [key: string]: { isMalicious: boolean } }; | ||
const entries = Object.entries(balances); | ||
|
||
for (let i = 0; i < entries.length; i++) { | ||
const [key, balanceInfo] = entries[i]; | ||
let data; | ||
if (key !== "native" && network === "PUBLIC") { | ||
// we only scan non-native assets on the public network | ||
try { | ||
const splitKey = key.split(":"); | ||
const blockaidKey = `${splitKey[0]}-${splitKey[1]}`; | ||
const res = await blockaidService.scanAsset(blockaidKey); | ||
|
||
data = res.data; | ||
} catch (e) { | ||
logger.error(e); | ||
} | ||
} | ||
|
||
scannedBalances[key] = { | ||
...balanceInfo, | ||
isMalicious: Boolean(Number(data?.malicious_score)) ?? false, | ||
}; | ||
} | ||
|
||
return scannedBalances; | ||
}; |