Skip to content

Commit

Permalink
inline yielding
Browse files Browse the repository at this point in the history
  • Loading branch information
artursapek committed Jan 3, 2024
1 parent b7b4006 commit 5b317ba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
12 changes: 4 additions & 8 deletions connect/src/protocols/cctpTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,12 +553,11 @@ export class CircleTransfer<N extends Network = Network>

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<CircleTransferProtocol, SC, DC>;
yield receipt;
}

if (isSourceFinalized(receipt)) {
Expand All @@ -575,12 +574,11 @@ export class CircleTransfer<N extends Network = Network>
receipt.attestation.id as WormholeMessageId,
leftover(start, timeout),
);
receipt = {
yield {
...receipt,
attestation: { id: receipt.attestation.id, attestation: vaa },
state: TransferState.Attested,
} as AttestedTransferReceipt<CircleTransferProtocol, SC, DC>;
yield receipt;
}
}
}
Expand All @@ -598,18 +596,17 @@ export class CircleTransfer<N extends Network = Network>

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<CircleTransferProtocol, SC, DC>;
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,
Expand All @@ -618,7 +615,6 @@ export class CircleTransfer<N extends Network = Network>
? TransferState.DestinationFinalized
: TransferState.Attested,
} as AttestedTransferReceipt<CircleTransferProtocol, SC, DC>;
yield receipt;
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions connect/src/protocols/tokenTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,7 @@ export class TokenTransfer<N extends Network = Network>
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
Expand All @@ -606,8 +605,7 @@ export class TokenTransfer<N extends Network = Network>
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
Expand Down

0 comments on commit 5b317ba

Please sign in to comment.