@chainlink/cre-sdk 0.0.3-alpha → 0.0.5-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +78 -59
- package/dist/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.d.ts +18 -3
- package/dist/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.js +149 -41
- package/dist/generated-sdk/capabilities/internal/consensus/v1alpha/consensus_sdk_gen.d.ts +4 -3
- package/dist/generated-sdk/capabilities/internal/consensus/v1alpha/consensus_sdk_gen.js +27 -8
- package/dist/generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen.d.ts +1 -1
- package/dist/generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen.js +14 -4
- package/dist/generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen.js +3 -0
- package/dist/generated-sdk/capabilities/scheduler/cron/v1/cron_sdk_gen.js +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/sdk/cre/index.d.ts +1 -1
- package/dist/sdk/cre/index.js +1 -0
- package/dist/sdk/impl/runtime-impl.d.ts +5 -1
- package/dist/sdk/impl/runtime-impl.js +13 -2
- package/dist/sdk/index.d.ts +1 -0
- package/dist/sdk/index.js +1 -0
- package/dist/sdk/report.d.ts +6 -0
- package/dist/sdk/report.js +14 -0
- package/dist/sdk/runtime.d.ts +6 -0
- package/dist/sdk/utils/capabilities/blockchain/blockchain-helpers.d.ts +50 -0
- package/dist/sdk/utils/capabilities/blockchain/blockchain-helpers.js +48 -0
- package/dist/sdk/utils/capabilities/http/http-helpers.d.ts +112 -0
- package/dist/sdk/utils/capabilities/http/http-helpers.js +44 -0
- package/dist/sdk/utils/index.d.ts +2 -0
- package/dist/sdk/utils/index.js +2 -0
- package/dist/workflows/standard_tests/Makefile +19 -0
- package/dist/workflows/standard_tests/capability_calls_are_async/test.ts +39 -0
- package/dist/workflows/standard_tests/config/test.ts +23 -0
- package/dist/workflows/standard_tests/errors/test.ts +24 -0
- package/dist/workflows/standard_tests/logging/test.ts +25 -0
- package/dist/workflows/standard_tests/mode_switch/don_runtime_in_node_mode/test.ts +33 -0
- package/dist/workflows/standard_tests/mode_switch/node_runtime_in_don_mode/test.ts +41 -0
- package/dist/workflows/standard_tests/mode_switch/successful_mode_switch/test.ts +58 -0
- package/dist/workflows/standard_tests/multiple_triggers/test.ts +40 -0
- package/dist/workflows/standard_tests/random/test.ts +64 -0
- package/dist/workflows/standard_tests/secrets/test.ts +30 -0
- package/dist/workflows/standard_tests/secrets_fail_in_node_mode/test.ts +29 -0
- package/package.json +70 -69
- package/scripts/run-standard-tests.sh +0 -3
- package/scripts/src/cre-setup.ts +9 -0
- package/dist/sdk/utils/safeJsonStringify.d.ts +0 -6
- package/dist/sdk/utils/safeJsonStringify.js +0 -6
package/README.md
CHANGED
|
@@ -1,19 +1,77 @@
|
|
|
1
1
|
# @chainlink/cre-sdk
|
|
2
2
|
|
|
3
|
-
The Chainlink Runtime Environment (CRE) SDK for TypeScript enables developers to
|
|
3
|
+
The Chainlink Runtime Environment (CRE) SDK for TypeScript enables developers to write decentralized [Chainlink Runtime Environment Workflows](https://docs.chain.link/cre/) in Typescript.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [How to use this SDK](#how-to-use-this-sdk)
|
|
8
|
+
- [Examples](#examples)
|
|
9
|
+
- [Simulate locally with CRE CLI](#simulate-locally-with-cre-cli)
|
|
10
|
+
- [Installation](#installation)
|
|
11
|
+
- [Core Concepts](#core-concepts)
|
|
12
|
+
- [Workflows](#workflows)
|
|
13
|
+
- [Runtime Modes](#runtime-modes)
|
|
14
|
+
- [Available Capabilities](#available-capabilities)
|
|
15
|
+
- [Scheduling](#scheduling)
|
|
16
|
+
- [HTTP Operations](#http-operations)
|
|
17
|
+
- [Blockchain Interactions](#blockchain-interactions)
|
|
18
|
+
- [Configuration & Type Safety](#configuration--type-safety)
|
|
19
|
+
- [Consensus & Aggregation](#consensus--aggregation)
|
|
20
|
+
- [Utility Functions](#utility-functions)
|
|
21
|
+
- [Hex Utilities](#hex-utilities)
|
|
22
|
+
- [Chain Selectors](#chain-selectors)
|
|
23
|
+
- [Example Workflows](#example-workflows)
|
|
24
|
+
- [1. Simple Scheduled Task](#1-simple-scheduled-task)
|
|
25
|
+
- [2. API Data Aggregation](#2-api-data-aggregation)
|
|
26
|
+
- [3. On-Chain Data Integration](#3-on-chain-data-integration)
|
|
27
|
+
- [API Reference](#api-reference)
|
|
28
|
+
- [Core Functions](#core-functions)
|
|
29
|
+
- [Capabilities](#capabilities)
|
|
30
|
+
- [Utilities](#utilities)
|
|
31
|
+
- [Building from Source](#building-from-source)
|
|
32
|
+
- [Protobuf Generation](#protobuf-generation)
|
|
33
|
+
- [Chain Selectors Generation](#chain-selectors-generation)
|
|
34
|
+
- [Requirements](#requirements)
|
|
35
|
+
- [License](#license)
|
|
36
|
+
|
|
37
|
+
## How to use this SDK
|
|
38
|
+
|
|
39
|
+
This package exposes the APIs you use to write CRE Workflows in TypeScript, and then compile them to WASM.
|
|
40
|
+
|
|
41
|
+
This package must be used along with the [CRE CLI tool](https://github.com/smartcontractkit/cre-cli) to deploy your WASM-compiled workflows.
|
|
42
|
+
|
|
43
|
+
## Prerequisites
|
|
44
|
+
|
|
45
|
+
1. the [bun runtime](https://bun.com/). The wasm compilation currently is only supported by the bun runtime which has near-complete NodeJS compatibility.
|
|
46
|
+
|
|
47
|
+
2. the [CRE CLI tool](https://github.com/smartcontractkit/cre-cli) installed.
|
|
48
|
+
|
|
49
|
+
## Getting Started
|
|
50
|
+
|
|
51
|
+
We recommend you consult the [getting started docs](https://docs.chain.link/cre/getting-started/cli-installation) and install the CRE CLI.
|
|
52
|
+
|
|
53
|
+
Then run `cre init`, name your project and choose TypeScript as the language to define your workflows in.
|
|
4
54
|
|
|
5
55
|
## Examples
|
|
6
56
|
|
|
7
|
-
|
|
57
|
+
This TypeScript CRE SDK also includes some reference examples - [cre-sdk-examples](https://github.com/smartcontractkit/cre-sdk-typescript/tree/main/packages/cre-sdk-examples). These can be copied and pasted into your project as needed.
|
|
58
|
+
|
|
59
|
+
⚠️ Note however that these are refence TypeScript workflows and may require some additional steps (having the CRE CLI installed, running `bunx cre-setup` from inside a workflow example directory, etc) to get them to work within this repo.
|
|
60
|
+
|
|
61
|
+
**We recommend you setup your project using the CRE CLI and then copy and paste these examples into your project**
|
|
8
62
|
|
|
9
63
|
## Simulate locally with CRE CLI
|
|
10
64
|
|
|
11
|
-
You can run and debug your TypeScript workflows locally using the CRE CLI simulation
|
|
65
|
+
You can run and debug your TypeScript workflows locally using [the CRE CLI's](https://github.com/smartcontractkit/cre-cli) simulation functionality.
|
|
66
|
+
|
|
67
|
+
Make sure you `cd` into the directory that contain's your workflow's TypeScript file and the associated `config.json`. Then:
|
|
12
68
|
|
|
13
69
|
```bash
|
|
14
|
-
cre workflow simulate --target local-simulation --config config.json
|
|
70
|
+
cre workflow simulate --target local-simulation --config config.json index.ts
|
|
15
71
|
```
|
|
16
72
|
|
|
73
|
+
When simulating workflows that write to the blockchain, remember to pass extra flag `--broadcast` to broadcast the transactions to the blockchain.
|
|
74
|
+
|
|
17
75
|
See the CLI docs for additional flags (e.g. config file, secrets, HTTP payloads, EVM log params).
|
|
18
76
|
|
|
19
77
|
## Installation
|
|
@@ -22,33 +80,6 @@ See the CLI docs for additional flags (e.g. config file, secrets, HTTP payloads,
|
|
|
22
80
|
bun add @chainlink/cre-sdk
|
|
23
81
|
```
|
|
24
82
|
|
|
25
|
-
## Quick Start
|
|
26
|
-
|
|
27
|
-
```typescript
|
|
28
|
-
import { cre, Runner, type Runtime } from "@chainlink/cre-sdk";
|
|
29
|
-
|
|
30
|
-
type Config = { schedule: string };
|
|
31
|
-
|
|
32
|
-
const onCronTrigger = (runtime: Runtime<Config>) => {
|
|
33
|
-
runtime.log("Hello, CRE!");
|
|
34
|
-
return "Hello, CRE!";
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const initWorkflow = (config: Config) => {
|
|
38
|
-
const cron = new cre.capabilities.CronCapability();
|
|
39
|
-
return [
|
|
40
|
-
cre.handler(cron.trigger({ schedule: config.schedule }), onCronTrigger),
|
|
41
|
-
];
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export async function main() {
|
|
45
|
-
const runner = await Runner.newRunner<Config>();
|
|
46
|
-
await runner.run(initWorkflow);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
main();
|
|
50
|
-
```
|
|
51
|
-
|
|
52
83
|
## Core Concepts
|
|
53
84
|
|
|
54
85
|
### Workflows
|
|
@@ -56,7 +87,7 @@ main();
|
|
|
56
87
|
Workflows are the fundamental building blocks of CRE applications. They define how your application responds to triggers and what actions to take. Each workflow consists of:
|
|
57
88
|
|
|
58
89
|
- **Triggers**: Events that initiate workflow execution (cron schedules, HTTP requests, etc.)
|
|
59
|
-
- **Handlers**: Functions that process trigger events and execute your business logic
|
|
90
|
+
- **Handlers**: Functions that process trigger events and execute your business logic as provided in a callback function.
|
|
60
91
|
- **Capabilities**: Built-in services for interacting with external systems
|
|
61
92
|
|
|
62
93
|
### Runtime Modes
|
|
@@ -183,7 +214,11 @@ const onCronTrigger = async (runtime: Runtime<Config>) => {
|
|
|
183
214
|
|
|
184
215
|
## Configuration & Type Safety
|
|
185
216
|
|
|
186
|
-
|
|
217
|
+
You, the developer, must declare config files in config.json files, co-located with your TypeScript workflow definition.
|
|
218
|
+
|
|
219
|
+
Use Zod schemas for type-safe configuration.
|
|
220
|
+
|
|
221
|
+
Here's an example of zod usage for the config specified in `../cre-sdk-examples/src/workflows/on-chain/config.json`
|
|
187
222
|
|
|
188
223
|
```typescript
|
|
189
224
|
import { z } from "zod";
|
|
@@ -231,10 +266,17 @@ const aggregatedValue = await runtime.runInNodeMode(
|
|
|
231
266
|
|
|
232
267
|
### Hex Utilities
|
|
233
268
|
|
|
269
|
+
CRE capabilities (like EVM client) expect data in base64 format for serialization. You may need to convert a hex string to base64 format for CRE protocol communication.
|
|
270
|
+
|
|
271
|
+
Or you may need to convert binary data back to hex format for blockchain operations. This can be Useful for decoding responses from CRE capabilities and transforming data for libraries like viem (which expect hex format)
|
|
272
|
+
|
|
234
273
|
```typescript
|
|
235
274
|
import { hexToBase64, bytesToHex } from "@chainlink/cre-sdk";
|
|
236
275
|
|
|
276
|
+
// Example: "0x1234567890abcdef" → "EjRWeJCrze8="
|
|
237
277
|
const base64Data = hexToBase64("0x1234567890abcdef");
|
|
278
|
+
|
|
279
|
+
// Example: Uint8Array([18, 52, 86...]) → "0x1234567890abcdef"
|
|
238
280
|
const hexData = bytesToHex(buffer);
|
|
239
281
|
```
|
|
240
282
|
|
|
@@ -253,36 +295,13 @@ const ethereumSepolia = getNetwork({
|
|
|
253
295
|
|
|
254
296
|
## Example Workflows
|
|
255
297
|
|
|
256
|
-
### 1. Simple
|
|
257
|
-
|
|
258
|
-
```typescript
|
|
259
|
-
import { cre, Runner, type Runtime } from "@chainlink/cre-sdk";
|
|
260
|
-
|
|
261
|
-
type Config = { schedule: string };
|
|
262
|
-
|
|
263
|
-
const onCronTrigger = (runtime: Runtime<Config>) => {
|
|
264
|
-
runtime.log("Workflow executed!");
|
|
265
|
-
return "Task completed";
|
|
266
|
-
};
|
|
298
|
+
### 1. Simple Cron-scheduled task
|
|
267
299
|
|
|
268
|
-
|
|
269
|
-
const cron = new cre.capabilities.CronCapability();
|
|
270
|
-
return [
|
|
271
|
-
cre.handler(cron.trigger({ schedule: config.schedule }), onCronTrigger),
|
|
272
|
-
];
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
export async function main() {
|
|
276
|
-
const runner = await Runner.newRunner<Config>();
|
|
277
|
-
await runner.run(initWorkflow);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
main();
|
|
281
|
-
```
|
|
300
|
+
See the [hello-world](https://github.com/smartcontractkit/cre-sdk-typescript/tree/main/packages/cre-sdk-examples/src/hello-world) example for a simple example that runs a cron-based operation on CRE at intervals you define in the `config.js` file.
|
|
282
301
|
|
|
283
302
|
### 2. API Data Aggregation
|
|
284
303
|
|
|
285
|
-
See the [http-fetch example](https://github.com/smartcontractkit/cre-sdk-typescript/tree/main/packages/cre-sdk-examples/src/workflows/http-fetch) for a complete implementation that fetches data from external APIs with consensus aggregation.
|
|
304
|
+
See the [http-fetch example](https://github.com/smartcontractkit/cre-sdk-typescript/tree/main/packages/cre-sdk-examples/src/workflows/http-fetch) for a complete implementation that fetches data from external APIs, with Chainlink CRE consensus aggregation applied.
|
|
286
305
|
|
|
287
306
|
### 3. On-Chain Data Integration
|
|
288
307
|
|
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
import { type Any, type Empty } from '@bufbuild/protobuf/wkt';
|
|
2
|
-
import { type BalanceAtReply, type BalanceAtRequest, type BalanceAtRequestJson, type CallContractReply, type CallContractRequest, type CallContractRequestJson, type EstimateGasReply, type EstimateGasRequest, type EstimateGasRequestJson, type FilterLogsReply, type FilterLogsRequest, type FilterLogsRequestJson, type FilterLogTriggerRequest, type FilterLogTriggerRequestJson, type GetTransactionByHashReply, type GetTransactionByHashRequest, type GetTransactionByHashRequestJson, type GetTransactionReceiptReply, type GetTransactionReceiptRequest, type GetTransactionReceiptRequestJson, type HeaderByNumberReply, type HeaderByNumberRequest, type HeaderByNumberRequestJson, type Log, type RegisterLogTrackingRequest, type RegisterLogTrackingRequestJson, type UnregisterLogTrackingRequest, type UnregisterLogTrackingRequestJson, type WriteReportReply, type WriteReportRequest
|
|
3
|
-
import type
|
|
2
|
+
import { type BalanceAtReply, type BalanceAtRequest, type BalanceAtRequestJson, type CallContractReply, type CallContractRequest, type CallContractRequestJson, type EstimateGasReply, type EstimateGasRequest, type EstimateGasRequestJson, type FilterLogsReply, type FilterLogsRequest, type FilterLogsRequestJson, type FilterLogTriggerRequest, type FilterLogTriggerRequestJson, type GasConfig, type GasConfigJson, type GetTransactionByHashReply, type GetTransactionByHashRequest, type GetTransactionByHashRequestJson, type GetTransactionReceiptReply, type GetTransactionReceiptRequest, type GetTransactionReceiptRequestJson, type HeaderByNumberReply, type HeaderByNumberRequest, type HeaderByNumberRequestJson, type Log, type RegisterLogTrackingRequest, type RegisterLogTrackingRequestJson, type UnregisterLogTrackingRequest, type UnregisterLogTrackingRequestJson, type WriteReportReply, type WriteReportRequest } from '../../../../../generated/capabilities/blockchain/evm/v1alpha/client_pb';
|
|
3
|
+
import { type Runtime } from '../../../../../sdk';
|
|
4
|
+
import { Report } from '../../../../../sdk/report';
|
|
4
5
|
import { type Trigger } from '../../../../../sdk/utils/triggers/trigger-interface';
|
|
6
|
+
export type WriteCreReportRequest = {
|
|
7
|
+
receiver: Uint8Array;
|
|
8
|
+
report?: Report;
|
|
9
|
+
gasConfig?: GasConfig;
|
|
10
|
+
$report: true;
|
|
11
|
+
};
|
|
12
|
+
export type WriteCreReportRequestJson = {
|
|
13
|
+
receiver: string;
|
|
14
|
+
report?: Report;
|
|
15
|
+
gasConfig?: GasConfigJson;
|
|
16
|
+
};
|
|
17
|
+
export declare function x_generatedCodeOnly_wrap_WriteCreReportRequest(input: WriteReportRequest): WriteCreReportRequest;
|
|
18
|
+
export declare function createWriteCreReportRequest(input: WriteCreReportRequestJson): WriteCreReportRequest;
|
|
19
|
+
export declare function x_generatedCodeOnly_unwrap_WriteCreReportRequest(input: WriteCreReportRequest): WriteReportRequest;
|
|
5
20
|
/**
|
|
6
21
|
* Client Capability
|
|
7
22
|
*
|
|
@@ -60,7 +75,7 @@ export declare class ClientCapability {
|
|
|
60
75
|
result: () => Empty;
|
|
61
76
|
};
|
|
62
77
|
logTrigger(config: FilterLogTriggerRequestJson): ClientLogTrigger;
|
|
63
|
-
writeReport(runtime: Runtime<unknown>, input:
|
|
78
|
+
writeReport(runtime: Runtime<unknown>, input: WriteCreReportRequest | WriteCreReportRequestJson): {
|
|
64
79
|
result: () => WriteReportReply;
|
|
65
80
|
};
|
|
66
81
|
}
|
|
@@ -1,7 +1,34 @@
|
|
|
1
1
|
import { create, fromJson } from '@bufbuild/protobuf';
|
|
2
2
|
import { AnySchema, anyPack, EmptySchema } from '@bufbuild/protobuf/wkt';
|
|
3
|
-
import { BalanceAtReplySchema, BalanceAtRequestSchema, CallContractReplySchema, CallContractRequestSchema, EstimateGasReplySchema, EstimateGasRequestSchema, FilterLogsReplySchema, FilterLogsRequestSchema, FilterLogTriggerRequestSchema, GetTransactionByHashReplySchema, GetTransactionByHashRequestSchema, GetTransactionReceiptReplySchema, GetTransactionReceiptRequestSchema, HeaderByNumberReplySchema, HeaderByNumberRequestSchema, LogSchema, RegisterLogTrackingRequestSchema, UnregisterLogTrackingRequestSchema, WriteReportReplySchema, WriteReportRequestSchema, } from '../../../../../generated/capabilities/blockchain/evm/v1alpha/client_pb';
|
|
3
|
+
import { BalanceAtReplySchema, BalanceAtRequestSchema, CallContractReplySchema, CallContractRequestSchema, EstimateGasReplySchema, EstimateGasRequestSchema, FilterLogsReplySchema, FilterLogsRequestSchema, FilterLogTriggerRequestSchema, GasConfigSchema, GetTransactionByHashReplySchema, GetTransactionByHashRequestSchema, GetTransactionReceiptReplySchema, GetTransactionReceiptRequestSchema, HeaderByNumberReplySchema, HeaderByNumberRequestSchema, LogSchema, RegisterLogTrackingRequestSchema, UnregisterLogTrackingRequestSchema, WriteReportReplySchema, WriteReportRequestSchema, } from '../../../../../generated/capabilities/blockchain/evm/v1alpha/client_pb';
|
|
4
|
+
import { ReportResponseSchema, } from '../../../../../generated/sdk/v1alpha/sdk_pb';
|
|
5
|
+
import {} from '../../../../../sdk';
|
|
6
|
+
import { Report } from '../../../../../sdk/report';
|
|
7
|
+
import { hexToBytes } from '../../../../../sdk/utils/hex-utils';
|
|
4
8
|
import {} from '../../../../../sdk/utils/triggers/trigger-interface';
|
|
9
|
+
export function x_generatedCodeOnly_wrap_WriteCreReportRequest(input) {
|
|
10
|
+
return {
|
|
11
|
+
receiver: input.receiver,
|
|
12
|
+
report: input.report !== undefined ? new Report(input.report) : undefined,
|
|
13
|
+
gasConfig: input.gasConfig,
|
|
14
|
+
$report: true,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export function createWriteCreReportRequest(input) {
|
|
18
|
+
return {
|
|
19
|
+
receiver: hexToBytes(input.receiver),
|
|
20
|
+
report: input.report,
|
|
21
|
+
gasConfig: input.gasConfig !== undefined ? fromJson(GasConfigSchema, input.gasConfig) : undefined,
|
|
22
|
+
$report: true,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export function x_generatedCodeOnly_unwrap_WriteCreReportRequest(input) {
|
|
26
|
+
return create(WriteReportRequestSchema, {
|
|
27
|
+
receiver: input.receiver,
|
|
28
|
+
report: input.report !== undefined ? input.report.x_generatedCodeOnly_unwrap() : undefined,
|
|
29
|
+
gasConfig: input.gasConfig,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
5
32
|
/**
|
|
6
33
|
* Client Capability
|
|
7
34
|
*
|
|
@@ -35,9 +62,16 @@ export class ClientCapability {
|
|
|
35
62
|
this.chainSelector = chainSelector;
|
|
36
63
|
}
|
|
37
64
|
callContract(runtime, input) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
65
|
+
// Handle input conversion - unwrap if it's a wrapped type, convert from JSON if needed
|
|
66
|
+
let payload;
|
|
67
|
+
if (input.$typeName) {
|
|
68
|
+
// It's the original protobuf type
|
|
69
|
+
payload = input;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
// It's regular JSON, convert using fromJson
|
|
73
|
+
payload = fromJson(CallContractRequestSchema, input);
|
|
74
|
+
}
|
|
41
75
|
// Include chainSelector in capability ID for routing when specified
|
|
42
76
|
const capabilityId = this.chainSelector
|
|
43
77
|
? `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.chainSelector}@${ClientCapability.CAPABILITY_VERSION}`
|
|
@@ -51,14 +85,22 @@ export class ClientCapability {
|
|
|
51
85
|
});
|
|
52
86
|
return {
|
|
53
87
|
result: () => {
|
|
54
|
-
|
|
88
|
+
const result = capabilityResponse.result();
|
|
89
|
+
return result;
|
|
55
90
|
},
|
|
56
91
|
};
|
|
57
92
|
}
|
|
58
93
|
filterLogs(runtime, input) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
94
|
+
// Handle input conversion - unwrap if it's a wrapped type, convert from JSON if needed
|
|
95
|
+
let payload;
|
|
96
|
+
if (input.$typeName) {
|
|
97
|
+
// It's the original protobuf type
|
|
98
|
+
payload = input;
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
// It's regular JSON, convert using fromJson
|
|
102
|
+
payload = fromJson(FilterLogsRequestSchema, input);
|
|
103
|
+
}
|
|
62
104
|
// Include chainSelector in capability ID for routing when specified
|
|
63
105
|
const capabilityId = this.chainSelector
|
|
64
106
|
? `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.chainSelector}@${ClientCapability.CAPABILITY_VERSION}`
|
|
@@ -72,14 +114,22 @@ export class ClientCapability {
|
|
|
72
114
|
});
|
|
73
115
|
return {
|
|
74
116
|
result: () => {
|
|
75
|
-
|
|
117
|
+
const result = capabilityResponse.result();
|
|
118
|
+
return result;
|
|
76
119
|
},
|
|
77
120
|
};
|
|
78
121
|
}
|
|
79
122
|
balanceAt(runtime, input) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
123
|
+
// Handle input conversion - unwrap if it's a wrapped type, convert from JSON if needed
|
|
124
|
+
let payload;
|
|
125
|
+
if (input.$typeName) {
|
|
126
|
+
// It's the original protobuf type
|
|
127
|
+
payload = input;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
// It's regular JSON, convert using fromJson
|
|
131
|
+
payload = fromJson(BalanceAtRequestSchema, input);
|
|
132
|
+
}
|
|
83
133
|
// Include chainSelector in capability ID for routing when specified
|
|
84
134
|
const capabilityId = this.chainSelector
|
|
85
135
|
? `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.chainSelector}@${ClientCapability.CAPABILITY_VERSION}`
|
|
@@ -93,14 +143,22 @@ export class ClientCapability {
|
|
|
93
143
|
});
|
|
94
144
|
return {
|
|
95
145
|
result: () => {
|
|
96
|
-
|
|
146
|
+
const result = capabilityResponse.result();
|
|
147
|
+
return result;
|
|
97
148
|
},
|
|
98
149
|
};
|
|
99
150
|
}
|
|
100
151
|
estimateGas(runtime, input) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
152
|
+
// Handle input conversion - unwrap if it's a wrapped type, convert from JSON if needed
|
|
153
|
+
let payload;
|
|
154
|
+
if (input.$typeName) {
|
|
155
|
+
// It's the original protobuf type
|
|
156
|
+
payload = input;
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
// It's regular JSON, convert using fromJson
|
|
160
|
+
payload = fromJson(EstimateGasRequestSchema, input);
|
|
161
|
+
}
|
|
104
162
|
// Include chainSelector in capability ID for routing when specified
|
|
105
163
|
const capabilityId = this.chainSelector
|
|
106
164
|
? `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.chainSelector}@${ClientCapability.CAPABILITY_VERSION}`
|
|
@@ -114,14 +172,22 @@ export class ClientCapability {
|
|
|
114
172
|
});
|
|
115
173
|
return {
|
|
116
174
|
result: () => {
|
|
117
|
-
|
|
175
|
+
const result = capabilityResponse.result();
|
|
176
|
+
return result;
|
|
118
177
|
},
|
|
119
178
|
};
|
|
120
179
|
}
|
|
121
180
|
getTransactionByHash(runtime, input) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
181
|
+
// Handle input conversion - unwrap if it's a wrapped type, convert from JSON if needed
|
|
182
|
+
let payload;
|
|
183
|
+
if (input.$typeName) {
|
|
184
|
+
// It's the original protobuf type
|
|
185
|
+
payload = input;
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
// It's regular JSON, convert using fromJson
|
|
189
|
+
payload = fromJson(GetTransactionByHashRequestSchema, input);
|
|
190
|
+
}
|
|
125
191
|
// Include chainSelector in capability ID for routing when specified
|
|
126
192
|
const capabilityId = this.chainSelector
|
|
127
193
|
? `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.chainSelector}@${ClientCapability.CAPABILITY_VERSION}`
|
|
@@ -135,14 +201,22 @@ export class ClientCapability {
|
|
|
135
201
|
});
|
|
136
202
|
return {
|
|
137
203
|
result: () => {
|
|
138
|
-
|
|
204
|
+
const result = capabilityResponse.result();
|
|
205
|
+
return result;
|
|
139
206
|
},
|
|
140
207
|
};
|
|
141
208
|
}
|
|
142
209
|
getTransactionReceipt(runtime, input) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
210
|
+
// Handle input conversion - unwrap if it's a wrapped type, convert from JSON if needed
|
|
211
|
+
let payload;
|
|
212
|
+
if (input.$typeName) {
|
|
213
|
+
// It's the original protobuf type
|
|
214
|
+
payload = input;
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
// It's regular JSON, convert using fromJson
|
|
218
|
+
payload = fromJson(GetTransactionReceiptRequestSchema, input);
|
|
219
|
+
}
|
|
146
220
|
// Include chainSelector in capability ID for routing when specified
|
|
147
221
|
const capabilityId = this.chainSelector
|
|
148
222
|
? `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.chainSelector}@${ClientCapability.CAPABILITY_VERSION}`
|
|
@@ -156,14 +230,22 @@ export class ClientCapability {
|
|
|
156
230
|
});
|
|
157
231
|
return {
|
|
158
232
|
result: () => {
|
|
159
|
-
|
|
233
|
+
const result = capabilityResponse.result();
|
|
234
|
+
return result;
|
|
160
235
|
},
|
|
161
236
|
};
|
|
162
237
|
}
|
|
163
238
|
headerByNumber(runtime, input) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
239
|
+
// Handle input conversion - unwrap if it's a wrapped type, convert from JSON if needed
|
|
240
|
+
let payload;
|
|
241
|
+
if (input.$typeName) {
|
|
242
|
+
// It's the original protobuf type
|
|
243
|
+
payload = input;
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
// It's regular JSON, convert using fromJson
|
|
247
|
+
payload = fromJson(HeaderByNumberRequestSchema, input);
|
|
248
|
+
}
|
|
167
249
|
// Include chainSelector in capability ID for routing when specified
|
|
168
250
|
const capabilityId = this.chainSelector
|
|
169
251
|
? `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.chainSelector}@${ClientCapability.CAPABILITY_VERSION}`
|
|
@@ -177,14 +259,22 @@ export class ClientCapability {
|
|
|
177
259
|
});
|
|
178
260
|
return {
|
|
179
261
|
result: () => {
|
|
180
|
-
|
|
262
|
+
const result = capabilityResponse.result();
|
|
263
|
+
return result;
|
|
181
264
|
},
|
|
182
265
|
};
|
|
183
266
|
}
|
|
184
267
|
registerLogTracking(runtime, input) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
268
|
+
// Handle input conversion - unwrap if it's a wrapped type, convert from JSON if needed
|
|
269
|
+
let payload;
|
|
270
|
+
if (input.$typeName) {
|
|
271
|
+
// It's the original protobuf type
|
|
272
|
+
payload = input;
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
// It's regular JSON, convert using fromJson
|
|
276
|
+
payload = fromJson(RegisterLogTrackingRequestSchema, input);
|
|
277
|
+
}
|
|
188
278
|
// Include chainSelector in capability ID for routing when specified
|
|
189
279
|
const capabilityId = this.chainSelector
|
|
190
280
|
? `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.chainSelector}@${ClientCapability.CAPABILITY_VERSION}`
|
|
@@ -198,14 +288,22 @@ export class ClientCapability {
|
|
|
198
288
|
});
|
|
199
289
|
return {
|
|
200
290
|
result: () => {
|
|
201
|
-
|
|
291
|
+
const result = capabilityResponse.result();
|
|
292
|
+
return result;
|
|
202
293
|
},
|
|
203
294
|
};
|
|
204
295
|
}
|
|
205
296
|
unregisterLogTracking(runtime, input) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
297
|
+
// Handle input conversion - unwrap if it's a wrapped type, convert from JSON if needed
|
|
298
|
+
let payload;
|
|
299
|
+
if (input.$typeName) {
|
|
300
|
+
// It's the original protobuf type
|
|
301
|
+
payload = input;
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
// It's regular JSON, convert using fromJson
|
|
305
|
+
payload = fromJson(UnregisterLogTrackingRequestSchema, input);
|
|
306
|
+
}
|
|
209
307
|
// Include chainSelector in capability ID for routing when specified
|
|
210
308
|
const capabilityId = this.chainSelector
|
|
211
309
|
? `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.chainSelector}@${ClientCapability.CAPABILITY_VERSION}`
|
|
@@ -219,7 +317,8 @@ export class ClientCapability {
|
|
|
219
317
|
});
|
|
220
318
|
return {
|
|
221
319
|
result: () => {
|
|
222
|
-
|
|
320
|
+
const result = capabilityResponse.result();
|
|
321
|
+
return result;
|
|
223
322
|
},
|
|
224
323
|
};
|
|
225
324
|
}
|
|
@@ -231,9 +330,17 @@ export class ClientCapability {
|
|
|
231
330
|
return new ClientLogTrigger(config, capabilityId, 'LogTrigger');
|
|
232
331
|
}
|
|
233
332
|
writeReport(runtime, input) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
333
|
+
// Handle input conversion - unwrap if it's a wrapped type, convert from JSON if needed
|
|
334
|
+
let payload;
|
|
335
|
+
// Check if it's a wrapped type by looking for the $report property
|
|
336
|
+
if (input.$report) {
|
|
337
|
+
// It's a wrapped type, unwrap it
|
|
338
|
+
payload = x_generatedCodeOnly_unwrap_WriteCreReportRequest(input);
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
// It's wrapped JSON, convert using create function
|
|
342
|
+
payload = x_generatedCodeOnly_unwrap_WriteCreReportRequest(createWriteCreReportRequest(input));
|
|
343
|
+
}
|
|
237
344
|
// Include chainSelector in capability ID for routing when specified
|
|
238
345
|
const capabilityId = this.chainSelector
|
|
239
346
|
? `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.chainSelector}@${ClientCapability.CAPABILITY_VERSION}`
|
|
@@ -247,7 +354,8 @@ export class ClientCapability {
|
|
|
247
354
|
});
|
|
248
355
|
return {
|
|
249
356
|
result: () => {
|
|
250
|
-
|
|
357
|
+
const result = capabilityResponse.result();
|
|
358
|
+
return result;
|
|
251
359
|
},
|
|
252
360
|
};
|
|
253
361
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { type ReportRequest, type ReportRequestJson, type
|
|
1
|
+
import { type ReportRequest, type ReportRequestJson, type SimpleConsensusInputs, type SimpleConsensusInputsJson } from '../../../../../generated/sdk/v1alpha/sdk_pb';
|
|
2
2
|
import { type Value } from '../../../../../generated/values/v1/values_pb';
|
|
3
|
-
import type
|
|
3
|
+
import { type Runtime } from '../../../../../sdk';
|
|
4
|
+
import { Report } from '../../../../../sdk/report';
|
|
4
5
|
/**
|
|
5
6
|
* Consensus Capability
|
|
6
7
|
*
|
|
@@ -17,6 +18,6 @@ export declare class ConsensusCapability {
|
|
|
17
18
|
result: () => Value;
|
|
18
19
|
};
|
|
19
20
|
report(runtime: Runtime<unknown>, input: ReportRequest | ReportRequestJson): {
|
|
20
|
-
result: () =>
|
|
21
|
+
result: () => Report;
|
|
21
22
|
};
|
|
22
23
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { fromJson } from '@bufbuild/protobuf';
|
|
2
2
|
import { ReportRequestSchema, ReportResponseSchema, SimpleConsensusInputsSchema, } from '../../../../../generated/sdk/v1alpha/sdk_pb';
|
|
3
3
|
import { ValueSchema } from '../../../../../generated/values/v1/values_pb';
|
|
4
|
+
import {} from '../../../../../sdk';
|
|
5
|
+
import { Report } from '../../../../../sdk/report';
|
|
6
|
+
import { hexToBytes } from '../../../../../sdk/utils/hex-utils';
|
|
4
7
|
/**
|
|
5
8
|
* Consensus Capability
|
|
6
9
|
*
|
|
@@ -14,9 +17,16 @@ export class ConsensusCapability {
|
|
|
14
17
|
static CAPABILITY_NAME = 'consensus';
|
|
15
18
|
static CAPABILITY_VERSION = '1.0.0-alpha';
|
|
16
19
|
simple(runtime, input) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
// Handle input conversion - unwrap if it's a wrapped type, convert from JSON if needed
|
|
21
|
+
let payload;
|
|
22
|
+
if (input.$typeName) {
|
|
23
|
+
// It's the original protobuf type
|
|
24
|
+
payload = input;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
// It's regular JSON, convert using fromJson
|
|
28
|
+
payload = fromJson(SimpleConsensusInputsSchema, input);
|
|
29
|
+
}
|
|
20
30
|
const capabilityId = ConsensusCapability.CAPABILITY_ID;
|
|
21
31
|
const capabilityResponse = runtime.callCapability({
|
|
22
32
|
capabilityId,
|
|
@@ -27,14 +37,22 @@ export class ConsensusCapability {
|
|
|
27
37
|
});
|
|
28
38
|
return {
|
|
29
39
|
result: () => {
|
|
30
|
-
|
|
40
|
+
const result = capabilityResponse.result();
|
|
41
|
+
return result;
|
|
31
42
|
},
|
|
32
43
|
};
|
|
33
44
|
}
|
|
34
45
|
report(runtime, input) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
46
|
+
// Handle input conversion - unwrap if it's a wrapped type, convert from JSON if needed
|
|
47
|
+
let payload;
|
|
48
|
+
if (input.$typeName) {
|
|
49
|
+
// It's the original protobuf type
|
|
50
|
+
payload = input;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
// It's regular JSON, convert using fromJson
|
|
54
|
+
payload = fromJson(ReportRequestSchema, input);
|
|
55
|
+
}
|
|
38
56
|
const capabilityId = ConsensusCapability.CAPABILITY_ID;
|
|
39
57
|
const capabilityResponse = runtime.callCapability({
|
|
40
58
|
capabilityId,
|
|
@@ -45,7 +63,8 @@ export class ConsensusCapability {
|
|
|
45
63
|
});
|
|
46
64
|
return {
|
|
47
65
|
result: () => {
|
|
48
|
-
|
|
66
|
+
const result = capabilityResponse.result();
|
|
67
|
+
return new Report(result);
|
|
49
68
|
},
|
|
50
69
|
};
|
|
51
70
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Request, type RequestJson, type Response } from '../../../../../generated/capabilities/networking/http/v1alpha/client_pb';
|
|
2
|
-
import type
|
|
2
|
+
import { type NodeRuntime, type Runtime } from '../../../../../sdk';
|
|
3
3
|
import type { ConsensusAggregation, PrimitiveTypes, UnwrapOptions } from '../../../../../sdk/utils';
|
|
4
4
|
export declare class SendRequester {
|
|
5
5
|
private readonly runtime;
|