1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use super::*;
impl ExecutionContext {
pub(crate) fn invoke_native_oracle(&mut self, method: &str, params: StackItem) -> StackItem {
match method {
"request" => {
// Extract parameters: url, filter, callback_contract, callback_method, user_data, gas_for_response
let (url, filter, cb_contract, cb_method, user_data, gas_for_response) =
if let StackItem::Array(args) = ¶ms {
let borrowed = args.borrow();
let url = Self::stack_item_to_bytes(
borrowed.first().cloned().unwrap_or(StackItem::Null),
);
let filter = Self::stack_item_to_bytes(
borrowed.get(1).cloned().unwrap_or(StackItem::Null),
);
let cb_contract = Self::stack_item_to_bytes(
borrowed.get(2).cloned().unwrap_or(StackItem::Null),
);
let cb_method = Self::stack_item_to_bytes(
borrowed.get(3).cloned().unwrap_or(StackItem::Null),
);
let user_data = Self::stack_item_to_bytes(
borrowed.get(4).cloned().unwrap_or(StackItem::Null),
);
let gas = Self::extract_first_int(
&borrowed
.get(5)
.cloned()
.unwrap_or(StackItem::UnsignedInteger(0)),
);
(url, filter, cb_contract, cb_method, user_data, gas)
} else {
(
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
0,
)
};
let id = self.oracle_next_request_id;
self.oracle_next_request_id += 1;
let request = OracleRequest {
id,
original_tx_hash: vec![0u8; 32],
url: String::from_utf8_lossy(&url).to_string(),
filter: String::from_utf8_lossy(&filter).to_string(),
callback_contract: cb_contract,
callback_method: String::from_utf8_lossy(&cb_method).to_string(),
user_data,
gas_for_response,
};
self.oracle_requests.insert(id, request);
// Return 4-byte request id (matching original behavior)
let id_bytes = (id as u32).to_le_bytes();
StackItem::byte_array(id_bytes.to_vec())
}
"getprice" => StackItem::UnsignedInteger(self.oracle_price),
"setprice" => {
self.oracle_price = Self::extract_first_int(¶ms);
StackItem::Null
}
"finish" => {
// No-op in embedded runtime
StackItem::Null
}
"verify" => StackItem::Boolean(true),
_ => StackItem::Null,
}
}
}