From ace2218e59c05b0949b9a8c9823a3e5b6cf119ab Mon Sep 17 00:00:00 2001 From: Artur Sapek Date: Wed, 3 Jan 2024 17:53:02 -0500 Subject: [PATCH] inline yielding --- connect/src/protocols/cctpTransfer.ts | 12 ++++-------- connect/src/protocols/tokenTransfer.ts | 6 ++---- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/connect/src/protocols/cctpTransfer.ts b/connect/src/protocols/cctpTransfer.ts index b3fe6c1288..64da812e5d 100644 --- a/connect/src/protocols/cctpTransfer.ts +++ b/connect/src/protocols/cctpTransfer.ts @@ -543,12 +543,11 @@ export class CircleTransfer const initTx = receipt.originTxs[receipt.originTxs.length - 1]!; const xfermsg = await CircleTransfer.getTransferMessage(_fromChain, initTx.txid); - receipt = { + yield { ...receipt, attestation: { id: xfermsg }, state: TransferState.SourceFinalized, } as SourceFinalizedTransferReceipt; - yield receipt; } if (isSourceFinalized(receipt)) { @@ -565,12 +564,11 @@ export class CircleTransfer receipt.attestation.id as WormholeMessageId, leftover(start, timeout), ); - receipt = { + yield { ...receipt, attestation: { id: receipt.attestation.id, attestation: vaa }, state: TransferState.Attested, } as AttestedTransferReceipt; - yield receipt; } } } @@ -588,18 +586,17 @@ export class CircleTransfer if (txStatus && txStatus.globalTx?.destinationTx?.txHash) { const { chainId, txHash } = txStatus.globalTx.destinationTx; - receipt = { + yield { ...receipt, destinationTxs: [{ chain: toChain(chainId) as DC, txid: txHash }], state: TransferState.DestinationFinalized, } as CompletedTransferReceipt; - yield receipt; } // Fall back to asking the destination chain if this VAA has been redeemed // assuming we have the full attestation if (isAttested(receipt)) { - receipt = { + yield { ...receipt, state: (await CircleTransfer.isTransferComplete( _toChain, @@ -608,7 +605,6 @@ export class CircleTransfer ? TransferState.DestinationFinalized : TransferState.Attested, } as AttestedTransferReceipt; - yield receipt; } } } diff --git a/connect/src/protocols/tokenTransfer.ts b/connect/src/protocols/tokenTransfer.ts index b83ce24c7f..875b6afc4c 100644 --- a/connect/src/protocols/tokenTransfer.ts +++ b/connect/src/protocols/tokenTransfer.ts @@ -595,8 +595,7 @@ export class TokenTransfer txid, leftover(start, timeout), ); - receipt = { ...receipt, state: TransferState.SourceFinalized, attestation: { id: msg } }; - yield receipt; + yield { ...receipt, state: TransferState.SourceFinalized, attestation: { id: msg } }; } // If the source is finalized, we need to fetch the signed attestation @@ -606,8 +605,7 @@ export class TokenTransfer if (!receipt.attestation.id) throw "Attestation id required to fetch attestation"; const { id } = receipt.attestation; const attestation = await TokenTransfer.getTransferVaa(wh, id, leftover(start, timeout)); - receipt = { ...receipt, attestation: { id, attestation }, state: TransferState.Attested }; - yield receipt; + yield { ...receipt, attestation: { id, attestation }, state: TransferState.Attested }; } // First try to grab the tx status from the API