-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add in-transit XCM msgs in blocks endpoint #1412
Changes from 2 commits
f6e401e
9f5500d
cf8ea13
a4952b3
25b3a52
f5effc9
f8f260d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -21,13 +21,16 @@ import type { | |||||
IDownwardMessage, | ||||||
IExtrinsic, | ||||||
IFrameMethod, | ||||||
IHorizontalMessage, | ||||||
IHorizontalMessageInParachain, | ||||||
IHorizontalMessageInRelayChain, | ||||||
IMessages, | ||||||
IUpwardMessage, | ||||||
} from '../../types/responses'; | ||||||
import type { ISanitizedBackedCandidate } from '../../types/responses/SanitizedBackedCandidate'; | ||||||
import type { ISanitizedBackedCandidateHorizontalMessage } from '../../types/responses/SanitizedBackedCandidatesHorizontalMessage'; | ||||||
import type { ISanitizedParachainInherentData } from '../../types/responses/SanitizedParachainInherentData'; | ||||||
import type { ISanitizedParentInherentData } from '../../types/responses/SanitizedParentInherentData'; | ||||||
import { IOption } from '../../types/util'; | ||||||
|
||||||
enum ChainType { | ||||||
Relay = 'Relay', | ||||||
|
@@ -63,23 +66,28 @@ export class XcmDecoder { | |||||
const frame = extrinsic.method as IFrameMethod; | ||||||
if (frame.pallet === 'paraInherent' && frame.method === 'enter') { | ||||||
const data = extrinsic.args.data as ISanitizedParentInherentData; | ||||||
if (paraId !== undefined) { | ||||||
data.backedCandidates.forEach((candidate) => { | ||||||
if (candidate.candidate.descriptor.paraId.toString() === paraId.toString()) { | ||||||
const msg_decoded = this.checkUpwardMsg(api, candidate); | ||||||
if (msg_decoded != undefined && Object.keys(msg_decoded).length > 0) { | ||||||
xcmMessages.upwardMessages?.push(msg_decoded); | ||||||
} | ||||||
data.backedCandidates.forEach((candidate) => { | ||||||
if (paraId === undefined || candidate.candidate.descriptor.paraId.toString() === paraId.toString()) { | ||||||
const horizontalMsgs: IHorizontalMessageInRelayChain[] = this.checkMessagesInRelay( | ||||||
api, | ||||||
candidate, | ||||||
'horizontal', | ||||||
paraId, | ||||||
) as IHorizontalMessageInRelayChain[]; | ||||||
if (horizontalMsgs != null && horizontalMsgs.length > 0) { | ||||||
horizontalMsgs.forEach((msg: IHorizontalMessageInRelayChain) => { | ||||||
xcmMessages.horizontalMessages?.push(msg); | ||||||
}); | ||||||
} | ||||||
}); | ||||||
} else { | ||||||
data.backedCandidates.forEach((candidate) => { | ||||||
const msg_decoded = this.checkUpwardMsg(api, candidate); | ||||||
if (msg_decoded != undefined && Object.keys(msg_decoded).length > 0) { | ||||||
xcmMessages.upwardMessages?.push(msg_decoded); | ||||||
|
||||||
const upwardMsgs = this.checkMessagesInRelay(api, candidate, 'upward', paraId) as IUpwardMessage[]; | ||||||
if (upwardMsgs != null && upwardMsgs.length > 0) { | ||||||
upwardMsgs.forEach((msg: IUpwardMessage) => { | ||||||
xcmMessages.upwardMessages?.push(msg); | ||||||
}); | ||||||
} | ||||||
}); | ||||||
} | ||||||
} | ||||||
}); | ||||||
} | ||||||
}); | ||||||
} else if (this.curChainType === ChainType.Parachain) { | ||||||
|
@@ -100,44 +108,67 @@ export class XcmDecoder { | |||||
} | ||||||
}); | ||||||
data.horizontalMessages.forEach((msgs, index) => { | ||||||
msgs.forEach((msg) => { | ||||||
const xcmMessageDecoded = this.decodeMsg(api, msg.data.slice(1)); | ||||||
let horizontalMessage: IHorizontalMessage; | ||||||
if (paraId !== undefined && index.toString() === paraId.toString()) { | ||||||
horizontalMessage = { | ||||||
if (paraId === undefined || index.toString() === paraId.toString()) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
msgs.forEach((msg) => { | ||||||
const xcmMessageDecoded = this.decodeMsg(api, msg.data.slice(1)); | ||||||
const horizontalMessage: IHorizontalMessageInParachain = { | ||||||
sentAt: msg.sentAt, | ||||||
paraId: index, | ||||||
originParaId: index, | ||||||
data: xcmMessageDecoded, | ||||||
}; | ||||||
xcmMessages.horizontalMessages?.push(horizontalMessage); | ||||||
} else if (paraId === undefined) { | ||||||
horizontalMessage = { | ||||||
sentAt: msg.sentAt, | ||||||
paraId: index, | ||||||
data: xcmMessageDecoded, | ||||||
}; | ||||||
xcmMessages.horizontalMessages?.push(horizontalMessage); | ||||||
} | ||||||
}); | ||||||
}); | ||||||
} | ||||||
}); | ||||||
} | ||||||
}); | ||||||
} | ||||||
return xcmMessages; | ||||||
} | ||||||
|
||||||
private checkUpwardMsg(api: ApiPromise, candidate: ISanitizedBackedCandidate): IUpwardMessage | undefined { | ||||||
if (candidate.candidate.commitments.upwardMessages.length > 0) { | ||||||
const xcmMessage = candidate.candidate.commitments.upwardMessages; | ||||||
const paraId: string = candidate.candidate.descriptor.paraId; | ||||||
const xcmMessageDecoded: string = this.decodeMsg(api, xcmMessage[0]); | ||||||
const upwardMessage = { | ||||||
paraId: paraId, | ||||||
data: xcmMessageDecoded[0], | ||||||
}; | ||||||
return upwardMessage; | ||||||
private checkMessagesInRelay( | ||||||
api: ApiPromise, | ||||||
candidate: ISanitizedBackedCandidate, | ||||||
messageType: 'upward' | 'horizontal', | ||||||
paraId?: number, | ||||||
): IOption<IUpwardMessage[] | IHorizontalMessageInRelayChain[]> { | ||||||
const messages: IUpwardMessage[] | IHorizontalMessageInRelayChain[] = []; | ||||||
const xcmMessages = | ||||||
messageType === 'upward' | ||||||
? candidate.candidate.commitments.upwardMessages | ||||||
: candidate.candidate.commitments.horizontalMessages; | ||||||
|
||||||
if (xcmMessages.length > 0) { | ||||||
const paraIdCandidate: string = candidate.candidate.descriptor.paraId.toString(); | ||||||
|
||||||
xcmMessages.forEach((msg: string | ISanitizedBackedCandidateHorizontalMessage) => { | ||||||
const msgData: string = | ||||||
messageType === 'upward' | ||||||
? (msg as string) | ||||||
: (msg as ISanitizedBackedCandidateHorizontalMessage).data.slice(1); | ||||||
const xcmMessageDecoded: string = this.decodeMsg(api, msgData); | ||||||
|
||||||
if (paraId === undefined || paraIdCandidate === paraId.toString()) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if (messageType === 'upward') { | ||||||
const upwardMessage: IUpwardMessage = { | ||||||
originParaId: paraIdCandidate, | ||||||
data: xcmMessageDecoded, | ||||||
}; | ||||||
(messages as IUpwardMessage[]).push(upwardMessage); | ||||||
} else { | ||||||
const horizontalMessage: IHorizontalMessageInRelayChain = { | ||||||
originParaId: paraIdCandidate, | ||||||
destinationParaId: (msg as ISanitizedBackedCandidateHorizontalMessage).recipient.toString(), | ||||||
data: xcmMessageDecoded, | ||||||
}; | ||||||
(messages as IHorizontalMessageInRelayChain[]).push(horizontalMessage); | ||||||
} | ||||||
} | ||||||
}); | ||||||
|
||||||
return messages; | ||||||
} else { | ||||||
return undefined; | ||||||
return null; | ||||||
} | ||||||
} | ||||||
|
||||||
|
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
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.