github.com/diadata-org/diadata@v1.4.593/pkg/dia/scraper/blockchain-scrapers/blockchains/ethereum/diaOracleV2MultiupdateService/DIAOracleV2Multiupdate.sol (about)

     1  // compiled using solidity 0.8.19
     2  pragma solidity 0.8.19;
     3  
     4  contract DIAOracleV2 {
     5      mapping (string => uint256) public values;
     6      address oracleUpdater;
     7      
     8      event OracleUpdate(string key, uint128 value, uint128 timestamp);
     9      event UpdaterAddressChange(address newUpdater);
    10      
    11      constructor() {
    12          oracleUpdater = msg.sender;
    13      }
    14      
    15      function setValue(string memory key, uint128 value, uint128 timestamp) public {
    16          require(msg.sender == oracleUpdater);
    17          uint256 cValue = (((uint256)(value)) << 128) + timestamp;
    18          values[key] = cValue;
    19          emit OracleUpdate(key, value, timestamp);
    20      }
    21  
    22      function setMultipleValues(string[] memory keys, uint256[] memory compressedValues) public {
    23          require(msg.sender == oracleUpdater);
    24          require(keys.length == compressedValues.length);
    25          
    26          for (uint128 i = 0; i < keys.length; i++) {
    27              string memory currentKey = keys[i];
    28              uint256 currentCvalue = compressedValues[i];
    29              uint128 value = (uint128)(currentCvalue >> 128);
    30              uint128 timestamp = (uint128)(currentCvalue % 2**128);
    31  
    32              values[currentKey] = currentCvalue;
    33              emit OracleUpdate(currentKey, value, timestamp);
    34          }
    35      }
    36      
    37      function getValue(string memory key) external view returns (uint128, uint128) {
    38          uint256 cValue = values[key];
    39          uint128 timestamp = (uint128)(cValue % 2**128);
    40          uint128 value = (uint128)(cValue >> 128);
    41          return (value, timestamp);
    42      }
    43      
    44      function updateOracleUpdaterAddress(address newOracleUpdaterAddress) public {
    45          require(msg.sender == oracleUpdater);
    46          oracleUpdater = newOracleUpdaterAddress;
    47          emit UpdaterAddressChange(newOracleUpdaterAddress);
    48      }
    49  }
    50