Intro to Nexus
How-to Guides
- Fetch Price Data
- Generate Randomness
- Migrate to DIA
- Fund the Oracle
- Build a Scraper
- Request a Custom Oracle
Reference
- Architecture
- Pricing Methodologies
- Data Sources
- Smart Contracts
- Randomness Protocol
Resources
Smart Contracts
DIAOracleV2.sol
Copy
Ask AI
pragma solidity 0.7.4;
contract DIAOracleV2 {
mapping (string => uint256) public values;
address oracleUpdater;
event OracleUpdate(string key, uint128 value, uint128 timestamp);
event UpdaterAddressChange(address newUpdater);
constructor() {
oracleUpdater = msg.sender;
}
function setValue(string memory key, uint128 value, uint128 timestamp) public {
require(msg.sender == oracleUpdater);
uint256 cValue = (((uint256)(value)) << 128) + timestamp;
values[key] = cValue;
emit OracleUpdate(key, value, timestamp);
}
function getValue(string memory key) external view returns (uint128, uint128) {
uint256 cValue = values[key];
uint128 timestamp = (uint128)(cValue % 2**128);
uint128 value = (uint128)(cValue >> 128);
return (value, timestamp);
}
function updateOracleUpdaterAddress(address newOracleUpdaterAddress) public {
require(msg.sender == oracleUpdater);
oracleUpdater = newOracleUpdaterAddress;
emit UpdaterAddressChange(newOracleUpdaterAddress);
}
}
Assistant
Responses are generated using AI and may contain mistakes.