Skip to content

Commit 764126b

Browse files
authored
solana sdk: Fix getIsApproved to check inbox item (#550)
* solana sdk: Fix getIsApproved to check inbox item getIsApproved() was returning true when the VAA was posted, causing track() to set the receipt state to DestinationInitiated prematurely. It should check if the inbox item is initialized instead. Fixes an issue that caused calls to NttManualRoute.complete() to return early and never actually complete the transfer in rare cases (receipt.DestinationInitiated === true and inbox item not created). * throw instead of return false
1 parent 6b4ea16 commit 764126b

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

solana/ts/sdk/ntt.ts

+16-8
Original file line numberDiff line numberDiff line change
@@ -800,14 +800,22 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
800800
}
801801

802802
async getIsApproved(attestation: Ntt.Attestation): Promise<boolean> {
803-
const digest = (attestation as WormholeNttTransceiver.VAA).hash;
804-
const vaaAddress = utils.derivePostedVaaKey(
805-
this.core.address,
806-
Buffer.from(digest)
807-
);
808-
809-
const info = await this.connection.getAccountInfo(vaaAddress);
810-
return info !== null;
803+
if (attestation.payloadName !== "WormholeTransfer") {
804+
throw new Error(`Invalid payload: ${attestation.payloadName}`);
805+
}
806+
const payload = attestation.payload["nttManagerPayload"];
807+
try {
808+
// check that the inbox item was initialized
809+
const inboxItem = await this.program.account.inboxItem.fetch(
810+
this.pdas.inboxItemAccount(attestation.emitterChain, payload)
811+
);
812+
return inboxItem.init;
813+
} catch (e: any) {
814+
if (e.message?.includes("Account does not exist")) {
815+
return false;
816+
}
817+
throw e;
818+
}
811819
}
812820

813821
async *completeInboundQueuedTransfer(

0 commit comments

Comments
 (0)