Press n or j to go to the next uncovered block, b, p or k for the previous block.
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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | 2x 75x 6x 2x 7x 2x 20x 2x 16x 16x 16x 16x 75x | import { AccountUpdate, Bool, Experimental, Field, ProvablePure, PublicKey, Signature, SmartContract, State, UInt64, method, provablePure, state, } from 'o1js'; import { BasicRequestClient } from './BasicRequestClient.js'; export interface IOracleData { sender: string; req0: string; req1: string; req2: string; req3: string; } /** * Abstract class representing an Oracle client. */ export abstract class IOracleClient { oracleAddress = State<PublicKey>(); // State variable storing the Oracle's address tokenAddress = State<PublicKey>(); // State variable storing the Token's address data0 = State<Field>(); /** * Sets the Oracle contract address. * * @param oracleAddress - The public key of the Oracle contract. * @returns A boolean indicating success. */ abstract setOracleContract(oracleAddress: PublicKey): Promise<void>; /** * Updates the stored ERC-677 token address associated with this oracle contract. * * @param tokenAddress - The new PublicKey of the ERC-677 token. * @returns True to indicate successful execution. */ abstract setErc677Token(tokenAddress: PublicKey): Promise<void>; /** * Sends an Oracle request with Address. * * @param oracleAddress - The public key of the Oracle contract. * @param req0 - The first field of the request data. * @param req1 - The second field of the request data. * @param req2 - The third field of the request data. * @param req3 - The fourth field of the request data. * @returns A boolean indicating success. */ abstract sendOracleRequestWithAddr( oracleAddress: PublicKey, req0: Field, req1: Field, req2: Field, req3: Field ): Promise<void>; /** * Sends an Oracle request. * * @param req0 - The first field of the request data. * @param req1 - The second field of the request data. * @param req2 - The third field of the request data. * @param req3 - The fourth field of the request data. * @returns A boolean indicating success. */ abstract sendOracleRequest( req0: Field, req1: Field, req2: Field, req3: Field ): Promise<void>; /** * Sends an Erc677 TransferAndCall request. * * @param req0 - The first field of the request data. * @param req1 - The second field of the request data. * @param req2 - The third field of the request data. * @param req3 - The fourth field of the request data. * @returns A boolean indicating success. */ abstract sendErc677RequestTo( req0: Field, req1: Field, req2: Field, req3: Field ): Promise<void>; /** * Handles the fulfillment of an Oracle request. * * @param data0 - The data0 data from the Oracle. * @returns A boolean indicating success. */ abstract onFulfillRequest(data0: Field): Promise<void>; } /** * Represents the data structure for an Oracle request. */ export interface IOracleData { /** * The public key of the sender who initiated the Oracle request. */ sender: string; // Consider using PublicKey type if available /** * The first field of the request data (converted to string). */ req0: string; /** * The second field of the request data (converted to string). */ req1: string; /** * The third field of the request data (converted to string). */ req2: string; /** * The fourth field of the request data (converted to string). */ req3: string; } /** * Abstract class representing an Oracle contract. */ export abstract class IOracleContract { tokenAddress = State<PublicKey>(); // State variable storing the Token's address /** * Makes an Oracle request. * * @param req0 - The first field of the request data. * @param req1 - The second field of the request data. * @param req2 - The third field of the request data. * @param req3 - The fourth field of the request data. * @returns A boolean indicating success. */ abstract oracleRequest( req0: Field, req1: Field, req2: Field, req3: Field ): Promise<void>; /** * Fulfills an Oracle request, verifies a signature, and potentially sends a callback to the specified address. * * @param callbackAddress - The public key of the contract to send the callback to (optional). * @param data0 - The first field of the data to be sent in the callback (optional). * @param signature - The signature to be verified (associated with the request or data). * @returns A boolean indicating success (always true in this implementation, potentially modify based on requirements). */ abstract fulfillOracleRequest( callbackAddress: PublicKey, data0: Field, signature: Signature ): Promise<void>; /** * Events emitted by the Oracle contract. */ events: IOracleEvents; } /** * Type representing the events emitted by an Oracle contract. */ export type IOracleEvents = { /** * Event emitted when an Oracle request is made. */ OracleRequest: ProvablePure<{ /** * Event emitted when an Oracle request is made. */ sender: PublicKey; /** * The first field of the request data. */ req0: Field; /** * The second field of the request data. */ req1: Field; /** * The third field of the request data. */ req2: Field; /** * The fourth field of the request data. */ req3: Field; }>; }; /** * Represents events emitted by the Oracle contract. */ export const OracleEvents: IOracleEvents = { /** * Event emitted when an Oracle request is made. */ OracleRequest: provablePure({ /** * The public key of the sender. */ sender: PublicKey, /** * The first field of the request data. */ req0: Field, /** * The second field of the request data. */ req1: Field, /** * The third field of the request data. */ req2: Field, /** * The fourth field of the request data. */ req3: Field, }), }; /** * An Oracle contract implementing the `IOracleContract` interface. */ export class OracleContract extends SmartContract implements IOracleContract { /** * Stores the address of a token associated with the oracle contract. This * token might be used for payment of oracle services or other interactions. */ @state(PublicKey) tokenAddress = State<PublicKey>(); init() { super.init(); } /** * Updates the stored ERC-677 token address associated with this oracle contract. * * @param tokenAddress - The new PublicKey of the ERC-677 token. * @returns True to indicate successful execution. */ @method async setErc677Token(tokenAddress: PublicKey) { this.tokenAddress.set(tokenAddress); } /** * Makes an Oracle request based on provided data. * * @param req0 - The first field of the request data. * @param req1 - The second field of the request data. * @param req2 - The third field of the request data. * @param req3 - The fourth field of the request data. * @returns A boolean indicating success (always true in this implementation). */ @method async oracleRequest(req0: Field, req1: Field, req2: Field, req3: Field) { // Publish Event for Operator // Assert Erc677Token from Sender // ? CallbackAddr // const validSignature = signature.verify(tokenAddress, [roundId]); this.emitEvent('OracleRequest', { sender: this.sender.getAndRequireSignature(), req0, req1, req2, req3, }); } /** * Fulfills an Oracle request, verifies a signature, and potentially sends a callback to the specified address. * * @param callbackAddress - The public key of the contract to send the callback to (optional). * @param data0 - The first field of the data to be sent in the callback (optional). * @param signature - The signature to be verified (associated with the request or data). * @returns A boolean indicating success (always true in this implementation, potentially modify based on requirements). */ @method async fulfillOracleRequest( callbackAddress: PublicKey, data0: Field, signature: Signature ) { const validSignature = signature.verify(this.address, [data0]); validSignature.assertTrue(); const callbackContract = new BasicRequestClient(callbackAddress); await callbackContract.onFulfillRequest(data0); } // ⬜ cancelOracleRequest - Allows requesters to cancel requests. // ⬜ setFulfillmentPermission() - Sets the fulfillment permission for a given operator. // function setFulfillmentPermission(address _node, bool _allowed) // ⬜ getAuthorizationStatus() - Use this to check if an operator is authorized for fulfilling requests. // function getAuthorizationStatus(address _node) // ⬜ withdraw() - Allows the operator to withdraw earned. // function withdraw(address _recipient, uint256 _amount) /** * Events emitted by this Oracle contract. */ events = OracleEvents; } |