Skip to content

Commit cfe99f2

Browse files
authored
feat(core): ink! message origin (#781)
1 parent 89efebe commit cfe99f2

5 files changed

Lines changed: 20 additions & 5 deletions

File tree

.changeset/long-knives-send.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@reactive-dot/core": minor
3+
---
4+
5+
Added support for specifying an `origin` (caller) when invoking a read-message on an Ink! contract.

packages/core/src/ink/query-builder.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ describe("message", () => {
146146
"body": undefined,
147147
"instruction": "send-message",
148148
"name": "test-message",
149+
"origin": undefined,
149150
},
150151
]
151152
`);
@@ -162,6 +163,7 @@ describe("message", () => {
162163
},
163164
"instruction": "send-message",
164165
"name": "test-message",
166+
"origin": undefined,
165167
},
166168
]
167169
`);
@@ -182,6 +184,7 @@ describe("message", () => {
182184
},
183185
"instruction": "send-message",
184186
"name": "test-message",
187+
"origin": undefined,
185188
},
186189
]
187190
`);
@@ -212,6 +215,7 @@ describe("messages", () => {
212215
"instruction": "send-message",
213216
"multi": true,
214217
"name": "test-message",
218+
"origin": undefined,
215219
},
216220
]
217221
`);
@@ -241,6 +245,7 @@ describe("messages", () => {
241245
"instruction": "send-message",
242246
"multi": true,
243247
"name": "test-message",
248+
"origin": undefined,
244249
},
245250
]
246251
`);

packages/core/src/ink/query-builder.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88
StringKeyOf,
99
} from "../types.js";
1010
import type { UnwrapResult } from "./result.js";
11-
import type { GenericInkDescriptors } from "./types.js";
11+
import type { ContractAddress, GenericInkDescriptors } from "./types.js";
1212

1313
type StorageReadInstruction = BaseInstruction<"read-storage"> & {
1414
path: string;
@@ -36,6 +36,7 @@ type MessageSendInstruction = BaseInstruction<"send-message"> & {
3636
[Str: string]: unknown;
3737
}
3838
| undefined;
39+
origin: ContractAddress | undefined;
3940
at: Finality | undefined;
4041
};
4142

@@ -196,18 +197,19 @@ export class InkQuery<
196197
> extends never
197198
? [
198199
body: TDescriptor["__types"]["messages"][TName]["message"],
199-
options?: { at?: Finality },
200+
options?: { origin?: ContractAddress; at?: Finality },
200201
]
201202
: [
202203
body?: TDescriptor["__types"]["messages"][TName]["message"],
203-
options?: { at?: Finality },
204+
options?: { origin?: ContractAddress; at?: Finality },
204205
]
205206
) {
206207
return this.#append({
207208
instruction: "send-message",
208209
// TODO: this is needed for some reason
209210
name: name as typeof name,
210211
body: bodyAndOptions[0] as any,
212+
origin: bodyAndOptions[1]?.origin,
211213
at: bodyAndOptions[1]?.at,
212214
} satisfies MessageSendInstruction);
213215
}
@@ -221,7 +223,7 @@ export class InkQuery<
221223
>(
222224
name: TName,
223225
bodies: Array<TDescriptor["__types"]["messages"][TName]["message"]>,
224-
options?: { at?: Finality; stream?: TStream },
226+
options?: { origin?: ContractAddress; at?: Finality; stream?: TStream },
225227
) {
226228
return this.#append({
227229
instruction: "send-message",
@@ -232,6 +234,7 @@ export class InkQuery<
232234
// TODO: this is needed for some reason
233235
name: name as typeof name,
234236
bodies,
237+
origin: options?.origin,
235238
at: options?.at,
236239
} satisfies MultiMessageSendInstruction);
237240
}

packages/core/src/ink/query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export async function queryInk<
6363
}
6464

6565
const response = await api.apis.ReviveApi.call(
66-
toSs58Address(address, undefined, 238),
66+
toSs58Address(instruction.origin ?? address, undefined, 238),
6767
toH160Bytes(address),
6868
0n,
6969
undefined,

packages/core/src/query-builder.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ it("should append a read-contract instruction", () => {
175175
"body": {},
176176
"instruction": "send-message",
177177
"name": "testMessage",
178+
"origin": undefined,
178179
},
179180
],
180181
}
@@ -208,6 +209,7 @@ it("should append a multi read-contract instruction using contracts", () => {
208209
"body": {},
209210
"instruction": "send-message",
210211
"name": "testMessage",
212+
"origin": undefined,
211213
},
212214
],
213215
"multi": true,

0 commit comments

Comments
 (0)