Skip to content

Commit fa8847b

Browse files
Prepare report sugar (#126)
* Prepare report sugar * Make sure file naming follows common convention
1 parent 19186d8 commit fa8847b

File tree

8 files changed

+36
-21
lines changed

8 files changed

+36
-21
lines changed
File renamed without changes.
File renamed without changes.

packages/cre-http-trigger/src/trigger-workflow.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { v4 as uuidv4 } from 'uuid'
22
import { privateKeyToAccount } from 'viem/accounts'
3-
import { createJWT, type JSONRPCRequest } from './createJWT'
4-
import { getConfig } from './getConfig'
3+
import { createJWT, type JSONRPCRequest } from './create-jwt'
4+
import { getConfig } from './get-config'
55
import type { TriggerInput, WorkflowSelector } from './schemas'
66

77
export async function triggerWorkflow(workflowSelector: WorkflowSelector, payload: TriggerInput) {
@@ -38,6 +38,8 @@ export async function triggerWorkflow(workflowSelector: WorkflowSelector, payloa
3838
body: JSON.stringify(jsonrpcRequest),
3939
})
4040

41+
console.log(' Response:', response)
42+
4143
const result = await response.json()
4244

4345
return result

packages/cre-sdk-examples/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@chainlink/cre-sdk-examples",
33
"private": true,
4-
"version": "0.0.8-alpha",
4+
"version": "0.0.9-alpha",
55
"type": "module",
66
"author": "Ernest Nowacki",
77
"license": "BUSL-1.1",

packages/cre-sdk-examples/src/workflows/on-chain-write/index.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
hexToBase64,
99
LAST_FINALIZED_BLOCK_NUMBER,
1010
ok,
11+
prepareReportRequest,
1112
Runner,
1213
type Runtime,
1314
TxStatus,
@@ -153,19 +154,12 @@ const onCronTrigger = (runtime: Runtime<Config>) => {
153154
args: [toHex('0x'), dryRunCallData],
154155
})
155156

156-
const report = runtime
157-
.report({
158-
encodedPayload: hexToBase64(writeCallData),
159-
encoderName: 'evm',
160-
signingAlgo: 'ecdsa',
161-
hashingAlgo: 'keccak256',
162-
})
163-
.result()
157+
const report = runtime.report(prepareReportRequest(writeCallData)).result()
164158

165159
const resp = evmClient
166160
.writeReport(runtime, {
167161
receiver: evmConfig.calculatorConsumerAddress,
168-
report: report,
162+
report,
169163
})
170164
.result()
171165

packages/cre-sdk-examples/src/workflows/proof-of-reserve/index.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
hexToBase64,
1212
LAST_FINALIZED_BLOCK_NUMBER,
1313
median,
14+
prepareReportRequest,
1415
Runner,
1516
type Runtime,
1617
TxStatus,
@@ -205,14 +206,7 @@ const updateReserves = (
205206
})
206207

207208
// Step 1: Generate report using consensus capability
208-
const reportResponse = runtime
209-
.report({
210-
encodedPayload: hexToBase64(callData),
211-
encoderName: 'evm',
212-
signingAlgo: 'ecdsa',
213-
hashingAlgo: 'keccak256',
214-
})
215-
.result()
209+
const reportResponse = runtime.report(prepareReportRequest(callData)).result()
216210

217211
const resp = evmClient
218212
.writeReport(runtime, {

packages/cre-sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@chainlink/cre-sdk",
3-
"version": "0.0.8-alpha",
3+
"version": "0.0.9-alpha",
44
"type": "module",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

packages/cre-sdk/src/sdk/utils/capabilities/blockchain/blockchain-helpers.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { CallMsgJson } from '@cre/generated/capabilities/blockchain/evm/v1alpha/client_pb'
2+
import type { ReportRequestJson } from '@cre/generated/sdk/v1alpha/sdk_pb'
23
import { hexToBase64 } from '@cre/sdk/utils/hex-utils'
34
import type { Address, Hex } from 'viem'
45

@@ -57,3 +58,27 @@ export const encodeCallMsg = (payload: EncodeCallMsgPayload): CallMsgJson => ({
5758
to: hexToBase64(payload.to),
5859
data: hexToBase64(payload.data),
5960
})
61+
62+
/**
63+
* Default values expected by the EVM capability for report encoding.
64+
*/
65+
export const EVM_DEFAULT_REPORT_ENCODER = {
66+
encoderName: 'evm',
67+
signingAlgo: 'ecdsa',
68+
hashingAlgo: 'keccak256',
69+
}
70+
71+
/**
72+
* Prepares a report request for the EVM capability to pass to `.report()` function.
73+
*
74+
* @param hexEncodedPayload - The hex encoded payload to be signed.
75+
* @param reportEncoder - The report encoder to be used. Defaults to EVM_DEFAULT_REPORT_ENCODER.
76+
* @returns The prepared report request.
77+
*/
78+
export const prepareReportRequest = (
79+
hexEncodedPayload: Hex,
80+
reportEncoder: Exclude<ReportRequestJson, 'encodedPayload'> = EVM_DEFAULT_REPORT_ENCODER,
81+
): ReportRequestJson => ({
82+
encodedPayload: hexToBase64(hexEncodedPayload),
83+
...reportEncoder,
84+
})

0 commit comments

Comments
 (0)