-
Notifications
You must be signed in to change notification settings - Fork 0
/
CollabXLogo.sol
82 lines (68 loc) · 2.6 KB
/
CollabXLogo.sol
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
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
// Uncomment this line to use console.log
// import "hardhat/console.sol";
import "./interfaces/IOracle.sol";
// @title Quickstart
// @notice This contract interacts with teeML oracle to initiate calls for image generation using DALL-E.
contract Quickstart {
// @notice Address of the contract owner
address private owner;
// @notice Address of the oracle contract
address public oracleAddress;
// @notice Last response received from the oracle
string public lastResponse;
// @notice Counter for the number of calls made
uint private callsCount;
// @notice Event emitted when the oracle address is updated
event OracleAddressUpdated(address indexed newOracleAddress);
// @param initialOracleAddress Initial address of the oracle contract
constructor(address initialOracleAddress) {
owner = msg.sender;
oracleAddress = initialOracleAddress;
}
// @notice Ensures the caller is the contract owner
modifier onlyOwner() {
require(msg.sender == owner, "Caller is not owner");
_;
}
// @notice Ensures the caller is the oracle contract
modifier onlyOracle() {
require(msg.sender == oracleAddress, "Caller is not oracle");
_;
}
// @notice Updates the oracle address
// @param newOracleAddress The new oracle address to set
function setOracleAddress(address newOracleAddress) public onlyOwner {
oracleAddress = newOracleAddress;
emit OracleAddressUpdated(newOracleAddress);
}
// @notice Initializes a call to the oracle for image generation
// @param message The message or prompt for image generation
// @return The ID of the initiated call
function initializeDalleCall(string memory message) public returns (uint) {
uint currentId = callsCount;
callsCount = currentId + 1;
IOracle(oracleAddress).createFunctionCall(
currentId,
"image_generation",
message
);
return currentId;
}
// @notice Handles the response from the oracle for the function call
// @param response The response from the oracle
// @param errorMessage Any error message
// @dev Called by teeML oracle
function onOracleFunctionResponse(
uint /*runId*/,
string memory response,
string memory errorMessage
) public onlyOracle {
if (keccak256(abi.encodePacked(errorMessage)) != keccak256(abi.encodePacked(""))) {
lastResponse = errorMessage;
} else {
lastResponse = response;
}
}
}