clients/js: Dump payload in case of parse failure
This commit is contained in:
parent
3b6292af29
commit
e8620ccea9
|
@ -452,9 +452,7 @@ yargs(hideBin(process.argv))
|
||||||
const buf = Buffer.from(vaa_hex, "hex");
|
const buf = Buffer.from(vaa_hex, "hex");
|
||||||
const parsed_vaa = vaa.parse(buf);
|
const parsed_vaa = vaa.parse(buf);
|
||||||
|
|
||||||
if (!vaa.hasPayload(parsed_vaa)) {
|
vaa.assertKnownPayload(parsed_vaa);
|
||||||
throw Error("Couldn't parse VAA payload");
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(parsed_vaa.payload);
|
console.log(parsed_vaa.payload);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
{
|
||||||
|
version: 1,
|
||||||
|
guardianSetIndex: 0,
|
||||||
|
signatures: [
|
||||||
|
{
|
||||||
|
guardianSetIndex: 0,
|
||||||
|
signature: 'e29d3ad180b153d68c3f445d75eaa62fcc99690945baaf4ad0463e9ce44f27f75da3d49f79722920aac81ba2be80f688895f174942fedc403bc4e5ce3555b77b00'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
timestamp: 1656354705,
|
||||||
|
nonce: 0,
|
||||||
|
emitterChain: 2,
|
||||||
|
emitterAddress: '0x000000000000000000000000f19a2a01b70519f67adb309a994ec8c69a967e8b',
|
||||||
|
sequence: 0n,
|
||||||
|
consistencyLevel: 1,
|
||||||
|
payload: {
|
||||||
|
type: 'Other',
|
||||||
|
hex: '46726f6d3a2065766d305c6e4d73673a2048656c6c6f20576f726c6421',
|
||||||
|
ascii: 'From: evm0\\nMsg: Hello World!'
|
||||||
|
},
|
||||||
|
digest: '0x8b7781f662ff1eed4827b770c0e735288948f0b56611f8cd73bf65e6b2a7a8ad'
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
AQAAAAABAOKdOtGAsVPWjD9EXXXqpi/MmWkJRbqvStBGPpzkTyf3XaPUn3lyKSCqyBuivoD2iIlfF0lC/txAO8TlzjVVt3sAYrn3kQAAAAAAAgAAAAAAAAAAAAAAAPGaKgG3BRn2etswmplOyMaaln6LAAAAAAAAAAABRnJvbTogZXZtMFxuTXNnOiBIZWxsbyBXb3JsZCE=
|
|
@ -52,6 +52,12 @@ class P<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface Other {
|
||||||
|
type: "Other",
|
||||||
|
hex: string,
|
||||||
|
ascii?: string
|
||||||
|
}
|
||||||
|
|
||||||
// All the different types of payloads
|
// All the different types of payloads
|
||||||
export type Payload =
|
export type Payload =
|
||||||
GuardianSetUpgrade
|
GuardianSetUpgrade
|
||||||
|
@ -70,7 +76,7 @@ export type ContractUpgrade =
|
||||||
| PortalContractUpgrade<"TokenBridge">
|
| PortalContractUpgrade<"TokenBridge">
|
||||||
| PortalContractUpgrade<"NFTBridge">
|
| PortalContractUpgrade<"NFTBridge">
|
||||||
|
|
||||||
export function parse(buffer: Buffer): VAA<Payload | null> {
|
export function parse(buffer: Buffer): VAA<Payload | Other> {
|
||||||
const vaa = parseEnvelope(buffer)
|
const vaa = parseEnvelope(buffer)
|
||||||
const parser = guardianSetUpgradeParser
|
const parser = guardianSetUpgradeParser
|
||||||
.or(coreContractUpgradeParser)
|
.or(coreContractUpgradeParser)
|
||||||
|
@ -82,15 +88,21 @@ export function parse(buffer: Buffer): VAA<Payload | null> {
|
||||||
.or(tokenBridgeTransferWithPayloadParser())
|
.or(tokenBridgeTransferWithPayloadParser())
|
||||||
.or(tokenBridgeAttestMetaParser())
|
.or(tokenBridgeAttestMetaParser())
|
||||||
.or(nftBridgeTransferParser())
|
.or(nftBridgeTransferParser())
|
||||||
const payload = parser.parse(vaa.payload)
|
let payload : Payload | Other | null = parser.parse(vaa.payload)
|
||||||
delete payload['tokenURILength']
|
if (payload === null) {
|
||||||
|
payload = {type: "Other", hex: Buffer.from(vaa.payload).toString("hex"), ascii: Buffer.from(vaa.payload).toString('utf8')}
|
||||||
|
} else {
|
||||||
|
delete payload['tokenURILength']
|
||||||
|
}
|
||||||
var myVAA = { ...vaa, payload }
|
var myVAA = { ...vaa, payload }
|
||||||
|
|
||||||
return myVAA
|
return myVAA
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hasPayload(vaa: VAA<Payload | null>): vaa is VAA<Payload> {
|
export function assertKnownPayload(vaa: VAA<Payload | Other>): asserts vaa is VAA<Payload> {
|
||||||
return vaa.payload !== null
|
if (vaa.payload.type === "Other") {
|
||||||
|
throw Error(`Couldn't parse VAA payload: ${vaa.payload.hex}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the VAA envelope without looking into the payload.
|
// Parse the VAA envelope without looking into the payload.
|
||||||
|
@ -161,68 +173,72 @@ export function serialiseVAA(vaa: VAA<Payload>) {
|
||||||
return body.join("")
|
return body.join("")
|
||||||
}
|
}
|
||||||
|
|
||||||
export function vaaDigest(vaa: VAA<Payload>) {
|
export function vaaDigest(vaa: VAA<Payload | Other>) {
|
||||||
return solidityKeccak256(["bytes"], [solidityKeccak256(["bytes"], ["0x" + vaaBody(vaa)])])
|
return solidityKeccak256(["bytes"], [solidityKeccak256(["bytes"], ["0x" + vaaBody(vaa)])])
|
||||||
}
|
}
|
||||||
|
|
||||||
function vaaBody(vaa: VAA<Payload>) {
|
function vaaBody(vaa: VAA<Payload | Other>) {
|
||||||
let payload = vaa.payload
|
|
||||||
let payload_str: string
|
let payload_str: string
|
||||||
switch (payload.module) {
|
if (vaa.payload.type === "Other") {
|
||||||
case "Core":
|
payload_str = vaa.payload.hex
|
||||||
switch (payload.type) {
|
} else {
|
||||||
case "GuardianSetUpgrade":
|
let payload = vaa.payload;
|
||||||
payload_str = serialiseGuardianSetUpgrade(payload)
|
switch (payload.module) {
|
||||||
break
|
case "Core":
|
||||||
case "ContractUpgrade":
|
switch (payload.type) {
|
||||||
payload_str = serialiseCoreContractUpgrade(payload)
|
case "GuardianSetUpgrade":
|
||||||
break
|
payload_str = serialiseGuardianSetUpgrade(payload)
|
||||||
default:
|
break
|
||||||
impossible(payload)
|
case "ContractUpgrade":
|
||||||
break
|
payload_str = serialiseCoreContractUpgrade(payload)
|
||||||
}
|
break
|
||||||
break
|
default:
|
||||||
case "NFTBridge":
|
impossible(payload)
|
||||||
switch (payload.type) {
|
break
|
||||||
case "ContractUpgrade":
|
}
|
||||||
payload_str = serialisePortalContractUpgrade(payload)
|
break
|
||||||
break
|
case "NFTBridge":
|
||||||
case "RegisterChain":
|
switch (payload.type) {
|
||||||
payload_str = serialisePortalRegisterChain(payload)
|
case "ContractUpgrade":
|
||||||
break
|
payload_str = serialisePortalContractUpgrade(payload)
|
||||||
case "Transfer":
|
break
|
||||||
payload_str = serialiseNFTBridgeTransfer(payload)
|
case "RegisterChain":
|
||||||
break
|
payload_str = serialisePortalRegisterChain(payload)
|
||||||
default:
|
break
|
||||||
impossible(payload)
|
case "Transfer":
|
||||||
break
|
payload_str = serialiseNFTBridgeTransfer(payload)
|
||||||
}
|
break
|
||||||
break
|
default:
|
||||||
case "TokenBridge":
|
impossible(payload)
|
||||||
switch (payload.type) {
|
break
|
||||||
case "ContractUpgrade":
|
}
|
||||||
payload_str = serialisePortalContractUpgrade(payload)
|
break
|
||||||
break
|
case "TokenBridge":
|
||||||
case "RegisterChain":
|
switch (payload.type) {
|
||||||
payload_str = serialisePortalRegisterChain(payload)
|
case "ContractUpgrade":
|
||||||
break
|
payload_str = serialisePortalContractUpgrade(payload)
|
||||||
case "Transfer":
|
break
|
||||||
payload_str = serialiseTokenBridgeTransfer(payload)
|
case "RegisterChain":
|
||||||
break
|
payload_str = serialisePortalRegisterChain(payload)
|
||||||
case "TransferWithPayload":
|
break
|
||||||
payload_str = serialiseTokenBridgeTransferWithPayload(payload)
|
case "Transfer":
|
||||||
break
|
payload_str = serialiseTokenBridgeTransfer(payload)
|
||||||
case "AttestMeta":
|
break
|
||||||
payload_str = serialiseTokenBridgeAttestMeta(payload)
|
case "TransferWithPayload":
|
||||||
break
|
payload_str = serialiseTokenBridgeTransferWithPayload(payload)
|
||||||
default:
|
break
|
||||||
impossible(payload)
|
case "AttestMeta":
|
||||||
break
|
payload_str = serialiseTokenBridgeAttestMeta(payload)
|
||||||
}
|
break
|
||||||
break
|
default:
|
||||||
default:
|
impossible(payload)
|
||||||
impossible(payload)
|
break
|
||||||
break
|
}
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
impossible(payload)
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const body = [
|
const body = [
|
||||||
encode("uint32", vaa.timestamp),
|
encode("uint32", vaa.timestamp),
|
||||||
|
|
Loading…
Reference in New Issue