diff --git a/examples/verity_oracle_example/Move.toml b/examples/verity_oracle_example/Move.toml index f66b6e8455..874b2b94ea 100644 --- a/examples/verity_oracle_example/Move.toml +++ b/examples/verity_oracle_example/Move.toml @@ -6,7 +6,7 @@ version = "0.0.1" MoveStdlib = { git = "https://github.com/rooch-network/rooch.git", subdir = "frameworks/move-stdlib", rev = "main" } MoveosStdlib = { git = "https://github.com/rooch-network/rooch.git", subdir = "frameworks/moveos-stdlib", rev = "main" } RoochFramework = { git = "https://github.com/rooch-network/rooch.git", subdir = "frameworks/rooch-framework", rev = "main" } -VerityMoveOracles = { git = "https://github.com/usherlabs/verity-move-oracles.git", subdir = "rooch", rev = "feature/open-ai" } # change feature/open-ai to main once PR#15 is merged +VerityMoveOracles = { git = "https://github.com/usherlabs/verity-move-oracles.git", subdir = "rooch", rev = "main" } [addresses] diff --git a/examples/verity_oracle_example/sources/example.move b/examples/verity_oracle_example/sources/example.move index cf6e27fd16..83fc5cbeeb 100644 --- a/examples/verity_oracle_example/sources/example.move +++ b/examples/verity_oracle_example/sources/example.move @@ -9,12 +9,10 @@ module verity_oracle_example::example_caller { use moveos_std::object::{ObjectID}; use std::option::{Self, Option}; use std::vector; - use std::string::String; + use std::string::{Self,String}; use verity::oracles::{Self as Oracles}; use rooch_framework::gas_coin::RGas; use rooch_framework::account_coin_store; - #[test_only] - use verity::oracles; struct GlobalParams has key { pending_requests: vector, @@ -22,7 +20,7 @@ module verity_oracle_example::example_caller { #[test_only] public fun init_for_test(){ - oracles::init_for_test(); + Oracles::init_for_test(); init(); } @@ -39,7 +37,7 @@ module verity_oracle_example::example_caller { // Initiate the module with an empty vector of pending requests // Requests are managed in the caller to prevent other modules from impersonating the calling module, and spoofing new data. fun init(){ - // let params = account::borrow_mut_resource(@verity_test_foreign_module); // account::borrow_mut_resource in init throws an error on deployment + // let params = account::borrow_mut_resource(@verity_oracle_example); // account::borrow_mut_resource in init throws an error on deployment // params.pending_requests = vector::empty(); let signer = moveos_std::signer::module_signer(); account::move_resource_to(&signer, GlobalParams { pending_requests: vector::empty() }); @@ -60,16 +58,16 @@ module verity_oracle_example::example_caller { // We're passing the address and function identifier of the recipient address. in this from :: // If you do not want to pay for the Oracle to notify your contract, you can pass in option::none() as the argument. let payment = account_coin_store::withdraw(from, amount); - let request_id = Oracles::new_request_with_payment(http_request, pick, oracle, Oracles::with_notify(@verity_test_foreign_module, b"example_caller::receive_data"),payment); + let request_id = Oracles::new_request_with_payment(http_request, pick, oracle, Oracles::with_notify(@verity_oracle_example, string::utf8(b"example_caller::receive_data")),payment); // let no_notify_request_id = Oracles::new_request(http_request, pick, oracle, Oracles::without_notify()); - let params = account::borrow_mut_resource(@verity_test_foreign_module); + let params = account::borrow_mut_resource(@verity_oracle_example); vector::push_back(&mut params.pending_requests, request_id); } // This notify function is called by the Oracle. // ! It must not include parameters, or return arguments. public entry fun receive_data() { - let params = account::borrow_mut_resource(@verity_test_foreign_module); + let params = account::borrow_mut_resource(@verity_oracle_example); let pending_requests = params.pending_requests; let i = 0; @@ -78,22 +76,20 @@ module verity_oracle_example::example_caller { // Remove the fulfilled request from the pending_requests vector // This ensures unfulfilled requests are retained in the vector if (option::is_some(&Oracles::get_response(request_id))) { - vector::remove(&mut params.pending_requests, i); - // Decrement i to account for the removed element - if (i > 0) { - i = i - 1; + let (found, index) = vector::index_of(&mut params.pending_requests, request_id); + if (found){ + vector::remove(&mut params.pending_requests, index); + // ? ------ OPTIONAL ------ + let request_url = Oracles::get_request_params_url(request_id); + let request_method = Oracles::get_request_params_method(request_id); + let response = Oracles::get_response(request_id); + // For each fulfilment, emit an event + event::emit(RequestFulfilledEvent { + request_url, + request_method, + response, + }); }; - - // ? ------ OPTIONAL ------ - let request_url = Oracles::get_request_params_url(request_id); - let request_method = Oracles::get_request_params_method(request_id); - let response = Oracles::get_response(request_id); - // For each fulfilment, emit an event - event::emit(RequestFulfilledEvent { - request_url, - request_method, - response, - }); // \ ------ OPTIONAL ------ }; @@ -103,7 +99,7 @@ module verity_oracle_example::example_caller { #[view] public fun pending_requests_count(): u64 { - let params = account::borrow_resource(@verity_test_foreign_module); + let params = account::borrow_resource(@verity_oracle_example); vector::length(¶ms.pending_requests) } } @@ -111,7 +107,7 @@ module verity_oracle_example::example_caller { #[test_only] module verity_oracle_example::test_foreign_module { use moveos_std::signer; - use verity_test_foreign_module::example_caller::{Self, request_data, pending_requests_count}; + use verity_oracle_example::example_caller::{Self, request_data, pending_requests_count}; use rooch_framework::gas_coin; use verity::registry; use std::vector;