Skip to content

Commit

Permalink
Merge pull request #252 from w3f/bug-fix/xcm-getLocation
Browse files Browse the repository at this point in the history
fix null pointer access
  • Loading branch information
ironoa authored Oct 28, 2024
2 parents bd0c76c + df5bea8 commit d66c93c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions charts/polkadot-watcher-transaction/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
description: Polkadot Watcher
name: polkadot-watcher-transaction
version: v1.4.1
appVersion: v1.4.1
version: v1.4.2
appVersion: v1.4.2
apiVersion: v2
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "polkadot-watcher-transaction",
"version": "1.4.1",
"version": "1.4.2",
"description": "Monitor events on Polkadot networks, specifically transactions",
"repository": "git@github.com:w3f/polkadot-watcher-csv-exporter.git",
"author": "W3F Infrastructure Team <devops@web3.foundation>",
Expand Down
20 changes: 16 additions & 4 deletions src/transfers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ export const extractTransferInfoFromEvent = (event: Event, chainInfo: ChainInfo,
function extractTransferInfoFromXcmEvent(event: XcmSentEvent, chainInfo: ChainInfo, blockNumber: number): TransferInfo {
const { origin, message } = event
let { destination } = event

// TODO: Validate if the message includes a supported command.
// Categorize commands as:
// - Supported.
// - Unsupported (custom XCM): commands that include one or more instructions not yet supported and may require custom handling.
// - Non-asset-transfer: commands that do not involve asset transfers and should be skipped during processing.
// Example: Some commands, such as those including only a `Transact` instruction, do not involve asset transfers.
// Reference: https://polkadot.subscan.io/block/23164873?tab=event&event=23164873-57

// 1. Get origin from the MultiLocation (X1.AccountId32)
const originAddress = getLocation(origin, chainInfo, blockNumber)
// 2. Get beneficiary
Expand Down Expand Up @@ -109,8 +118,11 @@ function extractTransferInfoFromXcmEvent(event: XcmSentEvent, chainInfo: ChainIn
}

function getLocation(location: StagingXcmV4Location, chainInfo: ChainInfo, blockNumber: number): string {
if (!(location.interior.isX1)) {
log.error(`XCM. Junctions not supported: ${location.interior.type}. Block ${blockNumber}`)
if (!location || !location.interior) {
log.info(`XCM. Instruction not supported or doesn't include asset transfer. Block ${blockNumber}`)
return 'Unknown'
} else if (!(location.interior.isX1)) {
log.info(`XCM. Junctions not supported: ${location?.interior.type}. Block ${blockNumber}`)
return 'Unknown'
}
const x1 = location.interior.asX1[0]
Expand All @@ -123,7 +135,7 @@ function getLocation(location: StagingXcmV4Location, chainInfo: ChainInfo, block
const chainIndex = x1.asParachain.toString()
return parachainNames[chainInfo.id][chainIndex] || `Parachain ${chainIndex}`;
} else {
log.error(`XCM. Junctions not supported: ${x1.type}. Block ${blockNumber}`)
log.info(`XCM. Junctions not supported: ${x1.type}. Block ${blockNumber}`)
}
return 'Unknown'
}
Expand All @@ -146,7 +158,7 @@ function getTokenAmountFromAsset(assets: StagingXcmV4Asset[], chainInfo: ChainIn
// TODO: AssetHub monitoring. The token address should be processed.
continue
} else {
log.error(`Asset Junctions not supported: ${interior.type}. Block ${blockNumber}`)
log.info(`Asset Junctions not supported: ${interior.type}. Block ${blockNumber}`)
continue
}
result.push([token, amount])
Expand Down

0 comments on commit d66c93c

Please sign in to comment.