diff --git a/src/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.ts b/src/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.ts index 52d35628..d232103a 100644 --- a/src/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.ts +++ b/src/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.ts @@ -100,9 +100,9 @@ export class ClientCapability { private readonly chainSelector?: bigint, ) {} - async callContract( - input: CallContractRequest | CallContractRequestJson, - ): Promise { + callContract(input: CallContractRequest | CallContractRequestJson): { + result: () => Promise + } { // biome-ignore lint/suspicious/noExplicitAny: Needed for runtime type checking of protocol buffer messages const value = (input as any).$typeName ? (input as CallContractRequest) @@ -116,33 +116,41 @@ export class ClientCapability { ? `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.chainSelector}@${ClientCapability.CAPABILITY_VERSION}` : ClientCapability.CAPABILITY_ID - const capabilityResponse = await callCapability({ + const capabilityResponse = callCapability({ capabilityId, method: 'CallContract', mode: this.mode, payload, }) - if (capabilityResponse.response.case === 'error') { - throw new CapabilityError(capabilityResponse.response.value, { - capabilityId, - method: 'CallContract', - mode: this.mode, - }) + return { + result: async () => { + const { response } = await capabilityResponse.result() + + if (response.case === 'error') { + throw new CapabilityError(response.value, { + capabilityId, + method: 'CallContract', + mode: this.mode, + }) + } + + if (response.case !== 'payload') { + throw new CapabilityError('No payload in response', { + capabilityId, + method: 'CallContract', + mode: this.mode, + }) + } + + return fromBinary(CallContractReplySchema, response.value.value) + }, } - - if (capabilityResponse.response.case !== 'payload') { - throw new CapabilityError('No payload in response', { - capabilityId, - method: 'CallContract', - mode: this.mode, - }) - } - - return fromBinary(CallContractReplySchema, capabilityResponse.response.value.value) } - async filterLogs(input: FilterLogsRequest | FilterLogsRequestJson): Promise { + filterLogs(input: FilterLogsRequest | FilterLogsRequestJson): { + result: () => Promise + } { // biome-ignore lint/suspicious/noExplicitAny: Needed for runtime type checking of protocol buffer messages const value = (input as any).$typeName ? (input as FilterLogsRequest) @@ -156,33 +164,41 @@ export class ClientCapability { ? `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.chainSelector}@${ClientCapability.CAPABILITY_VERSION}` : ClientCapability.CAPABILITY_ID - const capabilityResponse = await callCapability({ + const capabilityResponse = callCapability({ capabilityId, method: 'FilterLogs', mode: this.mode, payload, }) - if (capabilityResponse.response.case === 'error') { - throw new CapabilityError(capabilityResponse.response.value, { - capabilityId, - method: 'FilterLogs', - mode: this.mode, - }) - } - - if (capabilityResponse.response.case !== 'payload') { - throw new CapabilityError('No payload in response', { - capabilityId, - method: 'FilterLogs', - mode: this.mode, - }) + return { + result: async () => { + const { response } = await capabilityResponse.result() + + if (response.case === 'error') { + throw new CapabilityError(response.value, { + capabilityId, + method: 'FilterLogs', + mode: this.mode, + }) + } + + if (response.case !== 'payload') { + throw new CapabilityError('No payload in response', { + capabilityId, + method: 'FilterLogs', + mode: this.mode, + }) + } + + return fromBinary(FilterLogsReplySchema, response.value.value) + }, } - - return fromBinary(FilterLogsReplySchema, capabilityResponse.response.value.value) } - async balanceAt(input: BalanceAtRequest | BalanceAtRequestJson): Promise { + balanceAt(input: BalanceAtRequest | BalanceAtRequestJson): { + result: () => Promise + } { // biome-ignore lint/suspicious/noExplicitAny: Needed for runtime type checking of protocol buffer messages const value = (input as any).$typeName ? (input as BalanceAtRequest) @@ -196,33 +212,41 @@ export class ClientCapability { ? `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.chainSelector}@${ClientCapability.CAPABILITY_VERSION}` : ClientCapability.CAPABILITY_ID - const capabilityResponse = await callCapability({ + const capabilityResponse = callCapability({ capabilityId, method: 'BalanceAt', mode: this.mode, payload, }) - if (capabilityResponse.response.case === 'error') { - throw new CapabilityError(capabilityResponse.response.value, { - capabilityId, - method: 'BalanceAt', - mode: this.mode, - }) - } - - if (capabilityResponse.response.case !== 'payload') { - throw new CapabilityError('No payload in response', { - capabilityId, - method: 'BalanceAt', - mode: this.mode, - }) + return { + result: async () => { + const { response } = await capabilityResponse.result() + + if (response.case === 'error') { + throw new CapabilityError(response.value, { + capabilityId, + method: 'BalanceAt', + mode: this.mode, + }) + } + + if (response.case !== 'payload') { + throw new CapabilityError('No payload in response', { + capabilityId, + method: 'BalanceAt', + mode: this.mode, + }) + } + + return fromBinary(BalanceAtReplySchema, response.value.value) + }, } - - return fromBinary(BalanceAtReplySchema, capabilityResponse.response.value.value) } - async estimateGas(input: EstimateGasRequest | EstimateGasRequestJson): Promise { + estimateGas(input: EstimateGasRequest | EstimateGasRequestJson): { + result: () => Promise + } { // biome-ignore lint/suspicious/noExplicitAny: Needed for runtime type checking of protocol buffer messages const value = (input as any).$typeName ? (input as EstimateGasRequest) @@ -236,35 +260,41 @@ export class ClientCapability { ? `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.chainSelector}@${ClientCapability.CAPABILITY_VERSION}` : ClientCapability.CAPABILITY_ID - const capabilityResponse = await callCapability({ + const capabilityResponse = callCapability({ capabilityId, method: 'EstimateGas', mode: this.mode, payload, }) - if (capabilityResponse.response.case === 'error') { - throw new CapabilityError(capabilityResponse.response.value, { - capabilityId, - method: 'EstimateGas', - mode: this.mode, - }) - } - - if (capabilityResponse.response.case !== 'payload') { - throw new CapabilityError('No payload in response', { - capabilityId, - method: 'EstimateGas', - mode: this.mode, - }) + return { + result: async () => { + const { response } = await capabilityResponse.result() + + if (response.case === 'error') { + throw new CapabilityError(response.value, { + capabilityId, + method: 'EstimateGas', + mode: this.mode, + }) + } + + if (response.case !== 'payload') { + throw new CapabilityError('No payload in response', { + capabilityId, + method: 'EstimateGas', + mode: this.mode, + }) + } + + return fromBinary(EstimateGasReplySchema, response.value.value) + }, } - - return fromBinary(EstimateGasReplySchema, capabilityResponse.response.value.value) } - async getTransactionByHash( - input: GetTransactionByHashRequest | GetTransactionByHashRequestJson, - ): Promise { + getTransactionByHash(input: GetTransactionByHashRequest | GetTransactionByHashRequestJson): { + result: () => Promise + } { // biome-ignore lint/suspicious/noExplicitAny: Needed for runtime type checking of protocol buffer messages const value = (input as any).$typeName ? (input as GetTransactionByHashRequest) @@ -278,35 +308,41 @@ export class ClientCapability { ? `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.chainSelector}@${ClientCapability.CAPABILITY_VERSION}` : ClientCapability.CAPABILITY_ID - const capabilityResponse = await callCapability({ + const capabilityResponse = callCapability({ capabilityId, method: 'GetTransactionByHash', mode: this.mode, payload, }) - if (capabilityResponse.response.case === 'error') { - throw new CapabilityError(capabilityResponse.response.value, { - capabilityId, - method: 'GetTransactionByHash', - mode: this.mode, - }) + return { + result: async () => { + const { response } = await capabilityResponse.result() + + if (response.case === 'error') { + throw new CapabilityError(response.value, { + capabilityId, + method: 'GetTransactionByHash', + mode: this.mode, + }) + } + + if (response.case !== 'payload') { + throw new CapabilityError('No payload in response', { + capabilityId, + method: 'GetTransactionByHash', + mode: this.mode, + }) + } + + return fromBinary(GetTransactionByHashReplySchema, response.value.value) + }, } - - if (capabilityResponse.response.case !== 'payload') { - throw new CapabilityError('No payload in response', { - capabilityId, - method: 'GetTransactionByHash', - mode: this.mode, - }) - } - - return fromBinary(GetTransactionByHashReplySchema, capabilityResponse.response.value.value) } - async getTransactionReceipt( - input: GetTransactionReceiptRequest | GetTransactionReceiptRequestJson, - ): Promise { + getTransactionReceipt(input: GetTransactionReceiptRequest | GetTransactionReceiptRequestJson): { + result: () => Promise + } { // biome-ignore lint/suspicious/noExplicitAny: Needed for runtime type checking of protocol buffer messages const value = (input as any).$typeName ? (input as GetTransactionReceiptRequest) @@ -320,35 +356,41 @@ export class ClientCapability { ? `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.chainSelector}@${ClientCapability.CAPABILITY_VERSION}` : ClientCapability.CAPABILITY_ID - const capabilityResponse = await callCapability({ + const capabilityResponse = callCapability({ capabilityId, method: 'GetTransactionReceipt', mode: this.mode, payload, }) - if (capabilityResponse.response.case === 'error') { - throw new CapabilityError(capabilityResponse.response.value, { - capabilityId, - method: 'GetTransactionReceipt', - mode: this.mode, - }) + return { + result: async () => { + const { response } = await capabilityResponse.result() + + if (response.case === 'error') { + throw new CapabilityError(response.value, { + capabilityId, + method: 'GetTransactionReceipt', + mode: this.mode, + }) + } + + if (response.case !== 'payload') { + throw new CapabilityError('No payload in response', { + capabilityId, + method: 'GetTransactionReceipt', + mode: this.mode, + }) + } + + return fromBinary(GetTransactionReceiptReplySchema, response.value.value) + }, } - - if (capabilityResponse.response.case !== 'payload') { - throw new CapabilityError('No payload in response', { - capabilityId, - method: 'GetTransactionReceipt', - mode: this.mode, - }) - } - - return fromBinary(GetTransactionReceiptReplySchema, capabilityResponse.response.value.value) } - async headerByNumber( - input: HeaderByNumberRequest | HeaderByNumberRequestJson, - ): Promise { + headerByNumber(input: HeaderByNumberRequest | HeaderByNumberRequestJson): { + result: () => Promise + } { // biome-ignore lint/suspicious/noExplicitAny: Needed for runtime type checking of protocol buffer messages const value = (input as any).$typeName ? (input as HeaderByNumberRequest) @@ -362,35 +404,41 @@ export class ClientCapability { ? `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.chainSelector}@${ClientCapability.CAPABILITY_VERSION}` : ClientCapability.CAPABILITY_ID - const capabilityResponse = await callCapability({ + const capabilityResponse = callCapability({ capabilityId, method: 'HeaderByNumber', mode: this.mode, payload, }) - if (capabilityResponse.response.case === 'error') { - throw new CapabilityError(capabilityResponse.response.value, { - capabilityId, - method: 'HeaderByNumber', - mode: this.mode, - }) - } - - if (capabilityResponse.response.case !== 'payload') { - throw new CapabilityError('No payload in response', { - capabilityId, - method: 'HeaderByNumber', - mode: this.mode, - }) + return { + result: async () => { + const { response } = await capabilityResponse.result() + + if (response.case === 'error') { + throw new CapabilityError(response.value, { + capabilityId, + method: 'HeaderByNumber', + mode: this.mode, + }) + } + + if (response.case !== 'payload') { + throw new CapabilityError('No payload in response', { + capabilityId, + method: 'HeaderByNumber', + mode: this.mode, + }) + } + + return fromBinary(HeaderByNumberReplySchema, response.value.value) + }, } - - return fromBinary(HeaderByNumberReplySchema, capabilityResponse.response.value.value) } - async registerLogTracking( - input: RegisterLogTrackingRequest | RegisterLogTrackingRequestJson, - ): Promise { + registerLogTracking(input: RegisterLogTrackingRequest | RegisterLogTrackingRequestJson): { + result: () => Promise + } { // biome-ignore lint/suspicious/noExplicitAny: Needed for runtime type checking of protocol buffer messages const value = (input as any).$typeName ? (input as RegisterLogTrackingRequest) @@ -404,35 +452,41 @@ export class ClientCapability { ? `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.chainSelector}@${ClientCapability.CAPABILITY_VERSION}` : ClientCapability.CAPABILITY_ID - const capabilityResponse = await callCapability({ + const capabilityResponse = callCapability({ capabilityId, method: 'RegisterLogTracking', mode: this.mode, payload, }) - if (capabilityResponse.response.case === 'error') { - throw new CapabilityError(capabilityResponse.response.value, { - capabilityId, - method: 'RegisterLogTracking', - mode: this.mode, - }) - } - - if (capabilityResponse.response.case !== 'payload') { - throw new CapabilityError('No payload in response', { - capabilityId, - method: 'RegisterLogTracking', - mode: this.mode, - }) + return { + result: async () => { + const { response } = await capabilityResponse.result() + + if (response.case === 'error') { + throw new CapabilityError(response.value, { + capabilityId, + method: 'RegisterLogTracking', + mode: this.mode, + }) + } + + if (response.case !== 'payload') { + throw new CapabilityError('No payload in response', { + capabilityId, + method: 'RegisterLogTracking', + mode: this.mode, + }) + } + + return fromBinary(EmptySchema, response.value.value) + }, } - - return fromBinary(EmptySchema, capabilityResponse.response.value.value) } - async unregisterLogTracking( - input: UnregisterLogTrackingRequest | UnregisterLogTrackingRequestJson, - ): Promise { + unregisterLogTracking(input: UnregisterLogTrackingRequest | UnregisterLogTrackingRequestJson): { + result: () => Promise + } { // biome-ignore lint/suspicious/noExplicitAny: Needed for runtime type checking of protocol buffer messages const value = (input as any).$typeName ? (input as UnregisterLogTrackingRequest) @@ -446,37 +500,45 @@ export class ClientCapability { ? `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.chainSelector}@${ClientCapability.CAPABILITY_VERSION}` : ClientCapability.CAPABILITY_ID - const capabilityResponse = await callCapability({ + const capabilityResponse = callCapability({ capabilityId, method: 'UnregisterLogTracking', mode: this.mode, payload, }) - if (capabilityResponse.response.case === 'error') { - throw new CapabilityError(capabilityResponse.response.value, { - capabilityId, - method: 'UnregisterLogTracking', - mode: this.mode, - }) - } - - if (capabilityResponse.response.case !== 'payload') { - throw new CapabilityError('No payload in response', { - capabilityId, - method: 'UnregisterLogTracking', - mode: this.mode, - }) + return { + result: async () => { + const { response } = await capabilityResponse.result() + + if (response.case === 'error') { + throw new CapabilityError(response.value, { + capabilityId, + method: 'UnregisterLogTracking', + mode: this.mode, + }) + } + + if (response.case !== 'payload') { + throw new CapabilityError('No payload in response', { + capabilityId, + method: 'UnregisterLogTracking', + mode: this.mode, + }) + } + + return fromBinary(EmptySchema, response.value.value) + }, } - - return fromBinary(EmptySchema, capabilityResponse.response.value.value) } logTrigger(config: FilterLogTriggerRequestJson): ClientLogTrigger { return new ClientLogTrigger(this.mode, config, ClientCapability.CAPABILITY_ID, 'LogTrigger') } - async writeReport(input: WriteReportRequest | WriteReportRequestJson): Promise { + writeReport(input: WriteReportRequest | WriteReportRequestJson): { + result: () => Promise + } { // biome-ignore lint/suspicious/noExplicitAny: Needed for runtime type checking of protocol buffer messages const value = (input as any).$typeName ? (input as WriteReportRequest) @@ -490,30 +552,36 @@ export class ClientCapability { ? `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.chainSelector}@${ClientCapability.CAPABILITY_VERSION}` : ClientCapability.CAPABILITY_ID - const capabilityResponse = await callCapability({ + const capabilityResponse = callCapability({ capabilityId, method: 'WriteReport', mode: this.mode, payload, }) - if (capabilityResponse.response.case === 'error') { - throw new CapabilityError(capabilityResponse.response.value, { - capabilityId, - method: 'WriteReport', - mode: this.mode, - }) + return { + result: async () => { + const { response } = await capabilityResponse.result() + + if (response.case === 'error') { + throw new CapabilityError(response.value, { + capabilityId, + method: 'WriteReport', + mode: this.mode, + }) + } + + if (response.case !== 'payload') { + throw new CapabilityError('No payload in response', { + capabilityId, + method: 'WriteReport', + mode: this.mode, + }) + } + + return fromBinary(WriteReportReplySchema, response.value.value) + }, } - - if (capabilityResponse.response.case !== 'payload') { - throw new CapabilityError('No payload in response', { - capabilityId, - method: 'WriteReport', - mode: this.mode, - }) - } - - return fromBinary(WriteReportReplySchema, capabilityResponse.response.value.value) } } diff --git a/src/generated-sdk/capabilities/internal/actionandtrigger/v1/basic_sdk_gen.ts b/src/generated-sdk/capabilities/internal/actionandtrigger/v1/basic_sdk_gen.ts index 59569511..6c3e2c1a 100644 --- a/src/generated-sdk/capabilities/internal/actionandtrigger/v1/basic_sdk_gen.ts +++ b/src/generated-sdk/capabilities/internal/actionandtrigger/v1/basic_sdk_gen.ts @@ -38,7 +38,7 @@ export class BasicCapability { constructor(private readonly mode: Mode = BasicCapability.DEFAULT_MODE) {} - async action(input: Input | InputJson): Promise { + action(input: Input | InputJson): { result: () => Promise } { // biome-ignore lint/suspicious/noExplicitAny: Needed for runtime type checking of protocol buffer messages const value = (input as any).$typeName ? (input as Input) @@ -49,30 +49,36 @@ export class BasicCapability { } const capabilityId = BasicCapability.CAPABILITY_ID - const capabilityResponse = await callCapability({ + const capabilityResponse = callCapability({ capabilityId, method: 'Action', mode: this.mode, payload, }) - if (capabilityResponse.response.case === 'error') { - throw new CapabilityError(capabilityResponse.response.value, { - capabilityId, - method: 'Action', - mode: this.mode, - }) + return { + result: async () => { + const { response } = await capabilityResponse.result() + + if (response.case === 'error') { + throw new CapabilityError(response.value, { + capabilityId, + method: 'Action', + mode: this.mode, + }) + } + + if (response.case !== 'payload') { + throw new CapabilityError('No payload in response', { + capabilityId, + method: 'Action', + mode: this.mode, + }) + } + + return fromBinary(OutputSchema, response.value.value) + }, } - - if (capabilityResponse.response.case !== 'payload') { - throw new CapabilityError('No payload in response', { - capabilityId, - method: 'Action', - mode: this.mode, - }) - } - - return fromBinary(OutputSchema, capabilityResponse.response.value.value) } trigger(config: ConfigJson): BasicTrigger { diff --git a/src/generated-sdk/capabilities/internal/basicaction/v1/basicaction_sdk_gen.ts b/src/generated-sdk/capabilities/internal/basicaction/v1/basicaction_sdk_gen.ts index a27fb360..199d8ae3 100644 --- a/src/generated-sdk/capabilities/internal/basicaction/v1/basicaction_sdk_gen.ts +++ b/src/generated-sdk/capabilities/internal/basicaction/v1/basicaction_sdk_gen.ts @@ -31,7 +31,7 @@ export class BasicActionCapability { constructor(private readonly mode: Mode = BasicActionCapability.DEFAULT_MODE) {} - async performAction(input: Inputs | InputsJson): Promise { + performAction(input: Inputs | InputsJson): { result: () => Promise } { // biome-ignore lint/suspicious/noExplicitAny: Needed for runtime type checking of protocol buffer messages const value = (input as any).$typeName ? (input as Inputs) @@ -42,29 +42,35 @@ export class BasicActionCapability { } const capabilityId = BasicActionCapability.CAPABILITY_ID - const capabilityResponse = await callCapability({ + const capabilityResponse = callCapability({ capabilityId, method: 'PerformAction', mode: this.mode, payload, }) - if (capabilityResponse.response.case === 'error') { - throw new CapabilityError(capabilityResponse.response.value, { - capabilityId, - method: 'PerformAction', - mode: this.mode, - }) - } + return { + result: async () => { + const { response } = await capabilityResponse.result() - if (capabilityResponse.response.case !== 'payload') { - throw new CapabilityError('No payload in response', { - capabilityId, - method: 'PerformAction', - mode: this.mode, - }) - } + if (response.case === 'error') { + throw new CapabilityError(response.value, { + capabilityId, + method: 'PerformAction', + mode: this.mode, + }) + } - return fromBinary(OutputsSchema, capabilityResponse.response.value.value) + if (response.case !== 'payload') { + throw new CapabilityError('No payload in response', { + capabilityId, + method: 'PerformAction', + mode: this.mode, + }) + } + + return fromBinary(OutputsSchema, response.value.value) + }, + } } } diff --git a/src/generated-sdk/capabilities/internal/consensus/v1alpha/consensus_sdk_gen.ts b/src/generated-sdk/capabilities/internal/consensus/v1alpha/consensus_sdk_gen.ts index 1d8b0c0a..1edf9eef 100644 --- a/src/generated-sdk/capabilities/internal/consensus/v1alpha/consensus_sdk_gen.ts +++ b/src/generated-sdk/capabilities/internal/consensus/v1alpha/consensus_sdk_gen.ts @@ -35,7 +35,9 @@ export class ConsensusCapability { constructor(private readonly mode: Mode = ConsensusCapability.DEFAULT_MODE) {} - async simple(input: SimpleConsensusInputs | SimpleConsensusInputsJson): Promise { + simple(input: SimpleConsensusInputs | SimpleConsensusInputsJson): { + result: () => Promise + } { // biome-ignore lint/suspicious/noExplicitAny: Needed for runtime type checking of protocol buffer messages const value = (input as any).$typeName ? (input as SimpleConsensusInputs) @@ -46,33 +48,39 @@ export class ConsensusCapability { } const capabilityId = ConsensusCapability.CAPABILITY_ID - const capabilityResponse = await callCapability({ + const capabilityResponse = callCapability({ capabilityId, method: 'Simple', mode: this.mode, payload, }) - if (capabilityResponse.response.case === 'error') { - throw new CapabilityError(capabilityResponse.response.value, { - capabilityId, - method: 'Simple', - mode: this.mode, - }) - } + return { + result: async () => { + const { response } = await capabilityResponse.result() - if (capabilityResponse.response.case !== 'payload') { - throw new CapabilityError('No payload in response', { - capabilityId, - method: 'Simple', - mode: this.mode, - }) - } + if (response.case === 'error') { + throw new CapabilityError(response.value, { + capabilityId, + method: 'Simple', + mode: this.mode, + }) + } - return fromBinary(ValueSchema, capabilityResponse.response.value.value) + if (response.case !== 'payload') { + throw new CapabilityError('No payload in response', { + capabilityId, + method: 'Simple', + mode: this.mode, + }) + } + + return fromBinary(ValueSchema, response.value.value) + }, + } } - async report(input: ReportRequest | ReportRequestJson): Promise { + report(input: ReportRequest | ReportRequestJson): { result: () => Promise } { // biome-ignore lint/suspicious/noExplicitAny: Needed for runtime type checking of protocol buffer messages const value = (input as any).$typeName ? (input as ReportRequest) @@ -83,29 +91,35 @@ export class ConsensusCapability { } const capabilityId = ConsensusCapability.CAPABILITY_ID - const capabilityResponse = await callCapability({ + const capabilityResponse = callCapability({ capabilityId, method: 'Report', mode: this.mode, payload, }) - if (capabilityResponse.response.case === 'error') { - throw new CapabilityError(capabilityResponse.response.value, { - capabilityId, - method: 'Report', - mode: this.mode, - }) - } + return { + result: async () => { + const { response } = await capabilityResponse.result() - if (capabilityResponse.response.case !== 'payload') { - throw new CapabilityError('No payload in response', { - capabilityId, - method: 'Report', - mode: this.mode, - }) - } + if (response.case === 'error') { + throw new CapabilityError(response.value, { + capabilityId, + method: 'Report', + mode: this.mode, + }) + } - return fromBinary(ReportResponseSchema, capabilityResponse.response.value.value) + if (response.case !== 'payload') { + throw new CapabilityError('No payload in response', { + capabilityId, + method: 'Report', + mode: this.mode, + }) + } + + return fromBinary(ReportResponseSchema, response.value.value) + }, + } } } diff --git a/src/generated-sdk/capabilities/internal/nodeaction/v1/basicaction_sdk_gen.ts b/src/generated-sdk/capabilities/internal/nodeaction/v1/basicaction_sdk_gen.ts index f752c7ae..25219a12 100644 --- a/src/generated-sdk/capabilities/internal/nodeaction/v1/basicaction_sdk_gen.ts +++ b/src/generated-sdk/capabilities/internal/nodeaction/v1/basicaction_sdk_gen.ts @@ -31,7 +31,7 @@ export class BasicActionCapability { constructor(private readonly mode: Mode = BasicActionCapability.DEFAULT_MODE) {} - async performAction(input: NodeInputs | NodeInputsJson): Promise { + performAction(input: NodeInputs | NodeInputsJson): { result: () => Promise } { // biome-ignore lint/suspicious/noExplicitAny: Needed for runtime type checking of protocol buffer messages const value = (input as any).$typeName ? (input as NodeInputs) @@ -42,29 +42,35 @@ export class BasicActionCapability { } const capabilityId = BasicActionCapability.CAPABILITY_ID - const capabilityResponse = await callCapability({ + const capabilityResponse = callCapability({ capabilityId, method: 'PerformAction', mode: this.mode, payload, }) - if (capabilityResponse.response.case === 'error') { - throw new CapabilityError(capabilityResponse.response.value, { - capabilityId, - method: 'PerformAction', - mode: this.mode, - }) - } + return { + result: async () => { + const { response } = await capabilityResponse.result() - if (capabilityResponse.response.case !== 'payload') { - throw new CapabilityError('No payload in response', { - capabilityId, - method: 'PerformAction', - mode: this.mode, - }) - } + if (response.case === 'error') { + throw new CapabilityError(response.value, { + capabilityId, + method: 'PerformAction', + mode: this.mode, + }) + } - return fromBinary(NodeOutputsSchema, capabilityResponse.response.value.value) + if (response.case !== 'payload') { + throw new CapabilityError('No payload in response', { + capabilityId, + method: 'PerformAction', + mode: this.mode, + }) + } + + return fromBinary(NodeOutputsSchema, response.value.value) + }, + } } } diff --git a/src/generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen.ts b/src/generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen.ts index 87f671ac..8d499aee 100644 --- a/src/generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen.ts +++ b/src/generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen.ts @@ -31,7 +31,7 @@ export class ClientCapability { constructor(private readonly mode: Mode = ClientCapability.DEFAULT_MODE) {} - async sendRequest(input: Request | RequestJson): Promise { + sendRequest(input: Request | RequestJson): { result: () => Promise } { // biome-ignore lint/suspicious/noExplicitAny: Needed for runtime type checking of protocol buffer messages const value = (input as any).$typeName ? (input as Request) @@ -42,29 +42,35 @@ export class ClientCapability { } const capabilityId = ClientCapability.CAPABILITY_ID - const capabilityResponse = await callCapability({ + const capabilityResponse = callCapability({ capabilityId, method: 'SendRequest', mode: this.mode, payload, }) - if (capabilityResponse.response.case === 'error') { - throw new CapabilityError(capabilityResponse.response.value, { - capabilityId, - method: 'SendRequest', - mode: this.mode, - }) - } + return { + result: async () => { + const { response } = await capabilityResponse.result() - if (capabilityResponse.response.case !== 'payload') { - throw new CapabilityError('No payload in response', { - capabilityId, - method: 'SendRequest', - mode: this.mode, - }) - } + if (response.case === 'error') { + throw new CapabilityError(response.value, { + capabilityId, + method: 'SendRequest', + mode: this.mode, + }) + } - return fromBinary(ResponseSchema, capabilityResponse.response.value.value) + if (response.case !== 'payload') { + throw new CapabilityError('No payload in response', { + capabilityId, + method: 'SendRequest', + mode: this.mode, + }) + } + + return fromBinary(ResponseSchema, response.value.value) + }, + } } } diff --git a/src/generator/generate-action.ts b/src/generator/generate-action.ts index cf306a41..82f418f8 100644 --- a/src/generator/generate-action.ts +++ b/src/generator/generate-action.ts @@ -25,7 +25,7 @@ export function generateActionMethod( const capabilityId = ${capabilityClassName}.CAPABILITY_ID;` return ` - async ${methodName}(input: ${method.input.name} | ${method.input.name}Json): Promise<${method.output.name}> { + ${methodName}(input: ${method.input.name} | ${method.input.name}Json): {result: () => Promise<${method.output.name}>} { // biome-ignore lint/suspicious/noExplicitAny: Needed for runtime type checking of protocol buffer messages const value = (input as any).$typeName ? input as ${method.input.name} : fromJson(${method.input.name}Schema, input as ${method.input.name}Json) const payload = { @@ -33,29 +33,35 @@ export function generateActionMethod( value: toBinary(${method.input.name}Schema, value), };${capabilityIdLogic} - const capabilityResponse = await callCapability({ + const capabilityResponse = callCapability({ capabilityId, method: "${method.name}", mode: this.mode, payload }); - if (capabilityResponse.response.case === 'error') { - throw new CapabilityError(capabilityResponse.response.value, { - capabilityId, - method: "${method.name}", - mode: this.mode, - }) - } + return { + result: async () => { + const {response} = await capabilityResponse.result(); - if (capabilityResponse.response.case !== 'payload') { - throw new CapabilityError('No payload in response', { - capabilityId, - method: "${method.name}", - mode: this.mode, - }) - } + if (response.case === 'error') { + throw new CapabilityError(response.value, { + capabilityId, + method: "${method.name}", + mode: this.mode, + }) + } - return fromBinary(${method.output.name}Schema, capabilityResponse.response.value.value) + if (response.case !== 'payload') { + throw new CapabilityError('No payload in response', { + capabilityId, + method: "${method.name}", + mode: this.mode, + }) + } + + return fromBinary(${method.output.name}Schema, response.value.value) + } + } }` } diff --git a/src/sdk/runtime/run-in-node-mode.test.ts b/src/sdk/runtime/run-in-node-mode.test.ts index a5f1cb44..947e5e66 100644 --- a/src/sdk/runtime/run-in-node-mode.test.ts +++ b/src/sdk/runtime/run-in-node-mode.test.ts @@ -37,7 +37,7 @@ describe('runInNodeMode', () => { // spy on consensus.simple const origSimple = ConsensusCapability.prototype.simple ConsensusCapability.prototype.simple = mock( - async (inputs: SimpleConsensusInputs | SimpleConsensusInputsJson) => { + (inputs: SimpleConsensusInputs | SimpleConsensusInputsJson) => { calls.push('CONSENSUS_SIMPLE') // biome-ignore lint/suspicious/noExplicitAny: Needed for runtime type checking of protocol buffer messages @@ -55,7 +55,7 @@ describe('runInNodeMode', () => { }) expect(castedInputs.descriptors).toEqual(expectedDescriptor) - return Value.from(anyResult).proto() + return { result: async () => Value.from(anyResult).proto() } }, ) @@ -81,7 +81,7 @@ describe('runInNodeMode', () => { // spy on consensus.simple const origSimple = ConsensusCapability.prototype.simple ConsensusCapability.prototype.simple = mock( - async (inputs: SimpleConsensusInputs | SimpleConsensusInputsJson) => { + (inputs: SimpleConsensusInputs | SimpleConsensusInputsJson) => { calls.push('CONSENSUS_SIMPLE') // biome-ignore lint/suspicious/noExplicitAny: Needed for runtime type checking of protocol buffer messages @@ -99,7 +99,7 @@ describe('runInNodeMode', () => { }) expect(castedInputs.descriptors).toEqual(expectedDescriptor) - return Value.from(anyResult).proto() + return { result: async () => Value.from(anyResult).proto() } }, ) @@ -123,7 +123,7 @@ describe('runInNodeMode', () => { // spy on consensus.simple const origSimple = ConsensusCapability.prototype.simple ConsensusCapability.prototype.simple = mock( - async (inputs: SimpleConsensusInputs | SimpleConsensusInputsJson) => { + (inputs: SimpleConsensusInputs | SimpleConsensusInputsJson) => { calls.push('CONSENSUS_SIMPLE') // biome-ignore lint/suspicious/noExplicitAny: Needed for runtime type checking of protocol buffer messages @@ -148,7 +148,7 @@ describe('runInNodeMode', () => { expect(async () => { await runInNodeMode(async (_: NodeRuntime) => { const ba = new BasicActionCapability() - const result = await ba.performAction({ inputThing: true }) + const result = await ba.performAction({ inputThing: true }).result() return result.adaptedThing }, consensusIdenticalAggregation())() }).toThrow(/.*cannot use Runtime inside RunInNodeMode.*/) diff --git a/src/sdk/runtime/run-in-node-mode.ts b/src/sdk/runtime/run-in-node-mode.ts index 97238cff..ea846613 100644 --- a/src/sdk/runtime/run-in-node-mode.ts +++ b/src/sdk/runtime/run-in-node-mode.ts @@ -1,4 +1,4 @@ -import { create, toJson } from '@bufbuild/protobuf' +import { create } from '@bufbuild/protobuf' import { Mode, SimpleConsensusInputsSchema } from '@cre/generated/sdk/v1alpha/sdk_pb' import { ConsensusCapability } from '@cre/generated-sdk/capabilities/internal/consensus/v1alpha/consensus_sdk_gen' import { runtime, type NodeRuntime } from '@cre/sdk/runtime/runtime' @@ -47,7 +47,7 @@ export function runInNodeMode( } const consensus = new ConsensusCapability() - const result = await consensus.simple(consensusInput) + const result = await consensus.simple(consensusInput).result() const wrappedValue = Value.wrap(result) return unwrapOptions diff --git a/src/sdk/utils/capabilities/call-capability.ts b/src/sdk/utils/capabilities/call-capability.ts index 353a9b20..4396ed1d 100644 --- a/src/sdk/utils/capabilities/call-capability.ts +++ b/src/sdk/utils/capabilities/call-capability.ts @@ -1,7 +1,6 @@ import { doRequestAsync } from '@cre/sdk/utils/do-request-async' import { awaitAsyncRequest } from '@cre/sdk/utils/await-async-request' import { Mode, type CapabilityResponse } from '@cre/generated/sdk/v1alpha/sdk_pb' -import { LazyPromise } from '@cre/sdk/utils/lazy-promise' import { runtimeGuards } from '@cre/sdk/runtime/runtime' export type CallCapabilityParams = { @@ -14,6 +13,10 @@ export type CallCapabilityParams = { } } +type CallCapabilityReturn = { + result: () => Promise +} + /** * Calls a capability asynchronously and returns a promise for the response. * The actual call is deferred until the promise is awaited (lazy execution). @@ -26,7 +29,7 @@ export function callCapability({ method, mode = Mode.DON, payload, -}: CallCapabilityParams): Promise { +}: CallCapabilityParams): CallCapabilityReturn { // Guards: // - Block DON-mode calls while currently in NODE mode // - Block NODE-mode calls while currently in DON mode @@ -40,11 +43,12 @@ export function callCapability({ payload, }) - return new LazyPromise(async () => { - return awaitAsyncRequest(callbackId, { - capabilityId, - method, - mode, - }) - }) + return { + result: async () => + awaitAsyncRequest(callbackId, { + capabilityId, + method, + mode, + }), + } } diff --git a/src/sdk/utils/capabilities/http/fetch.ts b/src/sdk/utils/capabilities/http/fetch.ts index ea50f61b..0b6dc782 100644 --- a/src/sdk/utils/capabilities/http/fetch.ts +++ b/src/sdk/utils/capabilities/http/fetch.ts @@ -71,7 +71,7 @@ export const creFetch = async (input: CreFetchRequest) => { const validatedInput = creFetchRequestSchema.parse(input) const httpClient = new cre.capabilities.HTTPClient() - const resp = await httpClient.sendRequest(validatedInput) + const resp = await httpClient.sendRequest(validatedInput).result() return { statusCode: resp.statusCode, diff --git a/src/workflows/on-chain-write/on-chain-write.ts b/src/workflows/on-chain-write/on-chain-write.ts index 4ef40b10..e201d29e 100644 --- a/src/workflows/on-chain-write/on-chain-write.ts +++ b/src/workflows/on-chain-write/on-chain-write.ts @@ -59,17 +59,19 @@ const onCronTrigger = async (config: Config, runtime: Runtime): Promise => functionName: 'get', }) - const contractCall = await evmClient.callContract({ - call: { - from: hexToBase64(zeroAddress), - to: hexToBase64(evmConfig.storageAddress), - data: hexToBase64(callData), - }, - blockNumber: { - absVal: Buffer.from([3]).toString('base64'), // 3 for finalized block - sign: '-1', // negative for finalized - }, - }) + const contractCall = await evmClient + .callContract({ + call: { + from: hexToBase64(zeroAddress), + to: hexToBase64(evmConfig.storageAddress), + data: hexToBase64(callData), + }, + blockNumber: { + absVal: Buffer.from([3]).toString('base64'), // 3 for finalized block + sign: '-1', // negative for finalized + }, + }) + .result() // Decode the result const onchainValue = decodeFunctionResult({ @@ -104,17 +106,19 @@ const onCronTrigger = async (config: Config, runtime: Runtime): Promise => runtime.logger.log('Dry running call to ensure the value is not anomalous...') // dry run the call to ensure the value is not anomalous - const dryRunCall = await evmClient.callContract({ - call: { - from: hexToBase64(zeroAddress), - to: hexToBase64(evmConfig.calculatorConsumerAddress), - data: hexToBase64(dryRunCallData), - }, - blockNumber: { - absVal: Buffer.from([3]).toString('base64'), // 3 for finalized block - sign: '-1', // negative for finalized - }, - }) + const dryRunCall = await evmClient + .callContract({ + call: { + from: hexToBase64(zeroAddress), + to: hexToBase64(evmConfig.calculatorConsumerAddress), + data: hexToBase64(dryRunCallData), + }, + blockNumber: { + absVal: Buffer.from([3]).toString('base64'), // 3 for finalized block + sign: '-1', // negative for finalized + }, + }) + .result() const dryRunResponse = decodeFunctionResult({ abi: CALCULATOR_CONSUMER_ABI, @@ -136,12 +140,14 @@ const onCronTrigger = async (config: Config, runtime: Runtime): Promise => args: [toHex('0x'), dryRunCallData], }) - const resp = await evmClient.writeReport({ - receiver: evmConfig.calculatorConsumerAddress, - report: { - rawReport: writeCallData, - }, - }) + const resp = await evmClient + .writeReport({ + receiver: evmConfig.calculatorConsumerAddress, + report: { + rawReport: writeCallData, + }, + }) + .result() const txHash = resp.txHash diff --git a/src/workflows/on-chain/on-chain.ts b/src/workflows/on-chain/on-chain.ts index c5d1ffb8..0b803992 100644 --- a/src/workflows/on-chain/on-chain.ts +++ b/src/workflows/on-chain/on-chain.ts @@ -59,17 +59,19 @@ const onCronTrigger = async (config: Config, runtime: Runtime): Promise => functionName: 'get', }) - const contractCall = await evmClient.callContract({ - call: { - from: hexToBase64(zeroAddress), - to: hexToBase64(evmConfig.storageAddress), - data: hexToBase64(callData), - }, - blockNumber: { - absVal: Buffer.from([3]).toString('base64'), // 3 for finalized block - sign: '-1', // negative for finalized - }, - }) + const contractCall = await evmClient + .callContract({ + call: { + from: hexToBase64(zeroAddress), + to: hexToBase64(evmConfig.storageAddress), + data: hexToBase64(callData), + }, + blockNumber: { + absVal: Buffer.from([3]).toString('base64'), // 3 for finalized block + sign: '-1', // negative for finalized + }, + }) + .result() // Decode the result const onchainValue = decodeFunctionResult({ diff --git a/src/workflows/standard_tests/capability_calls_are_async/test.ts b/src/workflows/standard_tests/capability_calls_are_async/test.ts index b74b2e7f..9c5c928a 100644 --- a/src/workflows/standard_tests/capability_calls_are_async/test.ts +++ b/src/workflows/standard_tests/capability_calls_are_async/test.ts @@ -13,9 +13,9 @@ const asyncCalls = async () => { const p1 = basicAction.performAction(input1) const p2 = basicAction.performAction(input2) - // We await them in the reverse order. - const r2 = await p2 - const r1 = await p1 + // We get results in the reverse order. + const r2 = await p2.result() + const r1 = await p1.result() cre.sendResponseValue(Value.from(`${r1.adaptedThing}${r2.adaptedThing}`)) } diff --git a/src/workflows/standard_tests/mode_switch/don_runtime_in_node_mode/test.ts b/src/workflows/standard_tests/mode_switch/don_runtime_in_node_mode/test.ts index a54fccc1..6b4ead06 100644 --- a/src/workflows/standard_tests/mode_switch/don_runtime_in_node_mode/test.ts +++ b/src/workflows/standard_tests/mode_switch/don_runtime_in_node_mode/test.ts @@ -11,7 +11,7 @@ const handler = async (_config: Config) => { try { await runInNodeMode(async () => { const basicCap = new BasicActionCapability() - return (await basicCap.performAction({ inputThing: true })).adaptedThing + return (await basicCap.performAction({ inputThing: true }).result()).adaptedThing }, consensusIdenticalAggregation())() } catch (e) { cre.sendError(e as Error) diff --git a/src/workflows/standard_tests/mode_switch/node_runtime_in_don_mode/test.ts b/src/workflows/standard_tests/mode_switch/node_runtime_in_don_mode/test.ts index b8ff42c3..9903f704 100644 --- a/src/workflows/standard_tests/mode_switch/node_runtime_in_don_mode/test.ts +++ b/src/workflows/standard_tests/mode_switch/node_runtime_in_don_mode/test.ts @@ -18,7 +18,7 @@ const handler = async () => { // We shoudl be using node runtime here in future... const _ = nrt const nodeActionCapability = new NodeActionCapability() - await nodeActionCapability.performAction({ inputThing: true }) + await nodeActionCapability.performAction({ inputThing: true }).result() } catch (e) { console.log('error', e) if (e instanceof NodeModeError) { diff --git a/src/workflows/standard_tests/mode_switch/successful_mode_switch/test.ts b/src/workflows/standard_tests/mode_switch/successful_mode_switch/test.ts index b2f7d61f..ea1d0ebd 100644 --- a/src/workflows/standard_tests/mode_switch/successful_mode_switch/test.ts +++ b/src/workflows/standard_tests/mode_switch/successful_mode_switch/test.ts @@ -15,16 +15,18 @@ class Output { const handler = async (_config: Config, runtime: Runtime) => { const donInput = { inputThing: true } const basicActionCapability = new BasicActionCapability() - const donResponse = await basicActionCapability.performAction(donInput) + const donResponse = await basicActionCapability.performAction(donInput).result() runtime.now() const consensusOutput = await cre.runInNodeMode( async (nodeRuntime: NodeRuntime): Promise => { nodeRuntime.now() const nodeActionCapability = new NodeActionCapability() - const nodeResponse = await nodeActionCapability.performAction({ - inputThing: true, - }) + const nodeResponse = await nodeActionCapability + .performAction({ + inputThing: true, + }) + .result() return new Output(new Int64(nodeResponse.outputThing)) }, diff --git a/src/workflows/standard_tests/random/test.ts b/src/workflows/standard_tests/random/test.ts index 787db652..9257efc9 100644 --- a/src/workflows/standard_tests/random/test.ts +++ b/src/workflows/standard_tests/random/test.ts @@ -20,9 +20,11 @@ const randHandler = async (_config: Config, runtime: Runtime) => { const nodeRandomNumber = nodeRuntime.getRand().Uint64() const nodeActionCapability = new NodeActionCapability() - const nodeResponse = await nodeActionCapability.performAction({ - inputThing: true, - }) + const nodeResponse = await nodeActionCapability + .performAction({ + inputThing: true, + }) + .result() if (nodeResponse.outputThing < 100) { log(`***${nodeRandomNumber.toString()}`)