From 2264d3d0ac836bc7f713f441b80cb86353c49192 Mon Sep 17 00:00:00 2001 From: Kyle Peacock Date: Tue, 23 Jul 2024 14:05:33 -0700 Subject: [PATCH] feat: handling for "accepted" but not replied sync call --- packages/agent/src/actor.ts | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/agent/src/actor.ts b/packages/agent/src/actor.ts index d0f4ced1..b7963a9f 100644 --- a/packages/agent/src/actor.ts +++ b/packages/agent/src/actor.ts @@ -541,12 +541,24 @@ function _createActorMethod( blsVerify, }); const path = [new TextEncoder().encode('request_status'), requestId]; - reply = lookupResultToBuffer(certificate.lookup([...path, 'reply'])); - } else { - // if (!response.ok || response.body /* IC-1462 */) { - // throw new UpdateCallRejectedError(cid, methodName, requestId, response); - // } - + const status = new TextDecoder().decode( + lookupResultToBuffer(certificate.lookup([...path, 'status'])), + ); + + switch (status) { + case 'replied': + reply = lookupResultToBuffer(certificate.lookup([...path, 'reply'])); + break; + case 'rejected': + throw new UpdateCallRejectedError(cid, methodName, requestId, response); + case 'accepted': + // The certificate is not yet ready, so we need to poll for the response + break; + case 'default': + throw new ActorCallError(cid, methodName, 'update', { requestId: toHex(requestId) }); + } + } + if (reply === undefined) { const pollStrategy = pollingStrategyFactory(); // Contains the certificate and the reply from the boundary node const response = await pollForResponse(agent, ecid, requestId, pollStrategy, blsVerify);