Skip to content

Commit

Permalink
feat: Added notify
Browse files Browse the repository at this point in the history
  • Loading branch information
xlassix committed Sep 17, 2024
1 parent aabec05 commit 7be5810
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
22 changes: 21 additions & 1 deletion orchestrator/src/indexer/rooch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ function isValidJson(jsonString: string): boolean {
}
}

function decodeNotifyValue(hex: string): string {
return `${hex.slice(0, 66)}${Buffer.from(hex.slice(66), "hex").toString()}`;
}

export default class RoochIndexer {
private keyPair: Secp256k1Keypair;
private orchestrator: string;
Expand Down Expand Up @@ -82,6 +86,8 @@ export default class RoochIndexer {
const client = new RoochClient({
url: getRoochNodeUrl(this.chainId),
});
log.debug(JSON.stringify({ notify: data.notify }));

const tx = new Transaction();
tx.callFunction({
target: `${this.oracleAddress}::oracles::fulfil_request`,
Expand All @@ -93,7 +99,21 @@ export default class RoochIndexer {
signer: this.keyPair,
});

log.debug(receipt.execution_info);
log.debug(JSON.stringify({ execution_info: receipt.execution_info }));

if ((data.notify?.value?.vec?.at(0)?.length ?? 0) > 66) {

This comment has been minimized.

Copy link
@rsoury

rsoury Sep 18, 2024

Member

Could be wise to wrap this in try/catch no?

This comment has been minimized.

Copy link
@xlassix

xlassix Sep 18, 2024

Author Collaborator

I agree

const tx = new Transaction();
tx.callFunction({
target: decodeNotifyValue(data.notify?.value?.vec?.at(0) ?? ""),
});

const receipt = await client.signAndExecuteTransaction({
transaction: tx,
signer: this.keyPair,
});

// log.debug(receipt.execution_info);
}
return receipt;
}

Expand Down
2 changes: 1 addition & 1 deletion orchestrator/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ interface VecValue {
}

export interface IRequestAdded {
notify: NotifyValue;
notify?: NotifyValue;
oracle: string;
params: ParamsValue;
pick: string;
Expand Down
4 changes: 2 additions & 2 deletions rooch/Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ MoveosStdlib = { git = "https://github.com/rooch-network/rooch.git", subdir = "f
# RoochFramework = { git = "https://github.com/rooch-network/rooch.git", subdir = "frameworks/rooch-framework", rev = "main" }

[addresses]
verity = "_"
verity_test_foreign_module = "_"
verity = "0x9a759932a6640790b3e2a5fefdf23917c8830dcd8998fe8af3f3b49b0ab5ca35"
verity_test_foreign_module = "0x9a759932a6640790b3e2a5fefdf23917c8830dcd8998fe8af3f3b49b0ab5ca35"
std = "0x1"
moveos_std = "0x2"
# rooch_framework = "0x3"
Expand Down
4 changes: 2 additions & 2 deletions rooch/sources/example_caller.move
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ module verity_test_foreign_module::example_caller {
) {
let http_request = Oracles::build_request(url, method, headers, body);

// We're passing the address and function name of the module as the recipient.
// We're passing the address and function identifier of the recipient address. in this from <module_name>::<function_name>
// If you do not want to pay for the Oracle to notify your contract, you can pass in option::none() as the argument.
let request_id = Oracles::new_request(http_request, pick, oracle, Oracles::with_notify(@verity_test_foreign_module, b"receive_data"));
let request_id = Oracles::new_request(http_request, pick, oracle, Oracles::with_notify(@verity_test_foreign_module, b"example_caller::receive_data"));
// let no_notify_request_id = Oracles::new_request(http_request, pick, oracle, Oracles::without_notify());
let params = account::borrow_mut_resource<GlobalParams>(@verity_test_foreign_module);
vector::push_back(&mut params.pending_requests, request_id);
Expand Down
10 changes: 5 additions & 5 deletions rooch/sources/oracles.move
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module verity::oracles {
params: HTTPRequest,
pick: String, // An optional JQ string to pick the value from the response JSON data structure.
oracle: address,
response_status: u8,
response_status: u16,

This comment has been minimized.

Copy link
@rsoury

rsoury Sep 18, 2024

Member

Why the need to change from u8 to u16?

This comment has been minimized.

Copy link
@xlassix

xlassix Sep 18, 2024

Author Collaborator

u8 range is 0-255
we would have error added status above (429 and so on )

response: Option<String>
}

Expand Down Expand Up @@ -153,7 +153,7 @@ module verity::oracles {
public entry fun fulfil_request(
sender: &signer,
id: ObjectID,
response_status: u8,
response_status: u16,
result: String
// proof: String
) {
Expand Down Expand Up @@ -184,7 +184,7 @@ module verity::oracles {
public entry fun test_fulfil_request(
sender: &signer,
id: ObjectID,
response_status: u8,
response_status: u16,
result: String
// proof: String
) {
Expand Down Expand Up @@ -265,7 +265,7 @@ module verity::oracles {
}

#[view]
public fun get_response_status(id: &ObjectID): u8 {
public fun get_response_status(id: &ObjectID): u16 {
let request = borrow_request(id);
request.response_status
}
Expand Down Expand Up @@ -324,7 +324,7 @@ module verity::test_oracles {
assert!(oracles::get_request_params_url(&id) == string::utf8(b"https://api.example.com/data"), 99952);
assert!(oracles::get_request_params_method(&id) == string::utf8(b"GET"), 99953);
assert!(oracles::get_request_params_body(&id) == string::utf8(b""), 99954);
assert!(oracles::get_response_status(&id) ==(0 as u8), 99955);
assert!(oracles::get_response_status(&id) ==(0 as u16), 99955);
}

#[test]
Expand Down

0 comments on commit 7be5810

Please sign in to comment.