Skip to content

Commit 8e171d4

Browse files
committed
feat: Added Response status
1 parent 888b9db commit 8e171d4

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

orchestrator/src/indexer/rooch.ts

+14-18
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default class RoochIndexer {
3131
private oracleAddress: string,
3232
) {
3333
this.keyPair = Secp256k1Keypair.fromSecretKey(this.privateKey);
34-
this.orchestrator = `0x${this.keyPair.getSchnorrPublicKey()}`.toLowerCase();
34+
this.orchestrator = this.keyPair.getRoochAddress().toHexAddress();
3535
log.info(`Rooch Indexer initialized`);
3636
log.info(`Chain ID: ${this.chainId}`);
3737
log.info(`Oracle Address: ${this.oracleAddress}`);
@@ -77,19 +77,10 @@ export default class RoochIndexer {
7777
}
7878
}
7979

80-
async sendFulfillment(data: IRequestAdded, result: string) {
80+
async sendFulfillment(data: IRequestAdded, status: number, result: string) {
8181
const client = new RoochClient({
8282
url: getRoochNodeUrl(this.chainId),
8383
});
84-
const session = await client.createSession({
85-
sessionArgs: {
86-
appName: "your app name",
87-
appUrl: "your app url",
88-
scopes: [`${this.oracleAddress}::oracles::fulfil_request`],
89-
},
90-
signer: this.keyPair,
91-
});
92-
9384
const tx = new Transaction();
9485
tx.callFunction({
9586
target: `${this.oracleAddress}::oracles::fulfil_request`,
@@ -98,7 +89,7 @@ export default class RoochIndexer {
9889

9990
const receipt = await client.signAndExecuteTransaction({
10091
transaction: tx,
101-
signer: session,
92+
signer: this.keyPair,
10293
});
10394

10495
log.debug(receipt);
@@ -109,9 +100,9 @@ export default class RoochIndexer {
109100
log.debug("processing:", data.request_id);
110101
const token = xInstance.getAccessToken();
111102

112-
if (data.oracle.toLowerCase() !== this.orchestrator) {
113-
return null;
114-
}
103+
// if (data.oracle.toLowerCase() !== this.orchestrator) {
104+
// return null;
105+
// }
115106
const url = data.params.value.url?.includes("http") ? data.params.value.url : `https://${data.params.value.url}`;
116107
try {
117108
const _url = new URL(url);
@@ -151,9 +142,9 @@ export default class RoochIndexer {
151142
try {
152143
const result = await run(data.pick, JSON.stringify(request.data), { input: "string" });
153144
log.debug({ result });
154-
return result;
145+
return { status: request.status, message: result };
155146
} catch {
156-
return { status: 406, message: "`Pick` value provided could not be resolved on the returned response" };
147+
return { status: 409, message: "`Pick` value provided could not be resolved on the returned response" };
157148
}
158149
// return { status: request.status, message: result };
159150
} catch (error: any) {
@@ -201,7 +192,11 @@ export default class RoochIndexer {
201192
const data = await this.processRequestAddedEvent(event.decoded_event_data.value);
202193
if (data) {
203194
try {
204-
const temp = await this.sendFulfillment(event.decoded_event_data.value, JSON.stringify(data));
195+
const temp = await this.sendFulfillment(
196+
event.decoded_event_data.value,
197+
data.status,
198+
JSON.stringify(data.message),
199+
);
205200
await prismaClient.events.create({
206201
data: {
207202
eventHandleId: event.event_id.event_handle_id,
@@ -216,6 +211,7 @@ export default class RoochIndexer {
216211
},
217212
});
218213
} catch (err) {
214+
log.error(err);
219215
await prismaClient.events.create({
220216
data: {
221217
eventHandleId: event.event_id.event_handle_id,

rooch/sources/oracles.move

+5-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ module verity::oracles {
3535
params: HTTPRequest,
3636
pick: String, // An optional JQ string to pick the value from the response JSON data structure.
3737
oracle: address,
38+
status: u8,
3839
response: Option<String>
39-
// recommendation include a optional Int field for status to contain errors_code/statuscode
4040
}
4141

4242
// Global params for the oracle system
@@ -127,7 +127,8 @@ module verity::oracles {
127127
params,
128128
pick,
129129
oracle,
130-
response: option::none()
130+
status: 0,
131+
response: option::none(),
131132
});
132133
let request_id = object::id(&request);
133134
object::transfer(request, oracle); // transfer to oracle to ensure permission
@@ -152,6 +153,7 @@ module verity::oracles {
152153
public entry fun fulfil_request(
153154
sender: &signer,
154155
id: ObjectID,
156+
status:u8,
155157
result: String
156158
// proof: String
157159
) {
@@ -168,6 +170,7 @@ module verity::oracles {
168170

169171
// Fulfil the request
170172
request.response = option::some(result);
173+
request.status = status;
171174

172175
// TODO: Move gas from module escrow to Oracle
173176

0 commit comments

Comments
 (0)