Verified contractPartial
TemperatureMeasurement
Address0x6ada465151d32aa4dd3cea5206bfa47934b2f61a
- Balance
0 ETH
- Transactions
4
- Compiler
solc 0.3.5
- Same code
95 more contracts
Details
- Compiler
- solc 0.3.5+commit.5f97274a
- Language
- solidity
- Optimization
- Yes, 200 runs
- License
- Not stated
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 2,397,370
- Creation transaction
- 0x693cbee1d2…c3daf6f27d
TemperatureMeasurement.sol
// Recovered by EthereumHistory (ethereumhistory.com) -sw
contract TemperatureMeasurement {
address owner;
address device;
string description;
int8 minTemperature;
int8 maxTemperature;
uint32[] failedTimestampSeconds;
int8[] failedTemperatures;
uint16 maxFailureReports;
uint32 m_nrMeasurements = 0;
uint32 m_nrFailures = 0;
uint32 m_timestampFirst = 0;
uint32 m_timestampLast = 0;
bytes32[] hash;
function TemperatureMeasurement(address _device, int8 _minTemperature, int8 _maxTemperature, uint16 _maxFailureReports, string _description) {
owner = msg.sender;
device = _device;
minTemperature = _minTemperature;
maxTemperature = _maxTemperature;
if (_maxFailureReports < 1) throw;
maxFailureReports = _maxFailureReports;
description = _description;
}
function reportTemperature(int8[] _temperatures, uint32[] _timestamps) {
if (msg.sender != device) throw;
if (_temperatures.length != _timestamps.length) throw;
bytes memory data = new bytes(_temperatures.length * 5);
for (uint16 i = 0; i < _temperatures.length; i++) {
data[i * 5 + 0] = byte(_timestamps[i]);
data[i * 5 + 1] = byte(shr(_timestamps[i], 8));
data[i * 5 + 2] = byte(shr(_timestamps[i], 16));
data[i * 5 + 3] = byte(shr(_timestamps[i], 24));
data[i * 5 + 4] = byte(_temperatures[i]);
}
hash.push(sha256(data));
uint32 nrMeasurements = m_nrMeasurements;
uint32 nrFailures = m_nrFailures;
uint32 timestampFirst = m_timestampFirst;
uint32 timestampLast = m_timestampLast;
int8 maxT = maxTemperature;
int8 minT = minTemperature;
uint16 maxReports = maxFailureReports;
uint failedLen = failedTimestampSeconds.length;
if (timestampFirst == 0 && _timestamps.length > 0) timestampFirst = _timestamps[0];
if (_timestamps.length > 0 && _timestamps[_timestamps.length - 1] > timestampLast) timestampLast = _timestamps[_timestamps.length - 1];
for (uint32 j = 0; j < _temperatures.length; j++) {
nrMeasurements++;
if (_temperatures[j] > maxT || _temperatures[j] < minT) {
nrFailures++;
if (failedLen < maxReports) {
failedLen++;
failedTimestampSeconds.push(_timestamps[j]);
failedTemperatures.push(_temperatures[j]);
}
}
}
if (m_nrMeasurements != nrMeasurements) m_nrMeasurements = nrMeasurements;
if (m_nrFailures != nrFailures) m_nrFailures = nrFailures;
if (m_timestampFirst != timestampFirst) m_timestampFirst = timestampFirst;
if (m_timestampLast != timestampLast) m_timestampLast = timestampLast;
}
function shr(uint32 value, uint8 bits) constant returns (uint32) {
return value / 2 ** uint32(bits);
}
function nrFailures() constant returns (uint32) {
return m_nrFailures;
}
function timestampLast() constant returns (uint32) {
return m_timestampLast;
}
function timestampFirst() constant returns (uint32) {
return m_timestampFirst;
}
function nrMeasurements() constant returns (uint32) {
return m_nrMeasurements;
}
function success() constant returns (bool) {
return failedTimestampSeconds.length == 0 && m_nrMeasurements > 0;
}
function failed() constant returns (bool) {
return failedTimestampSeconds.length > 0 && m_nrMeasurements > 0;
}
function temperatureMin() constant returns (int8) {
return minTemperature;
}
function temperatureMax() constant returns (int8) {
return maxTemperature;
}
function failedTimestampLength() constant returns (uint16) {
return uint16(failedTimestampSeconds.length);
}
function failedTimestampSecondsAt(uint16 index) constant returns (uint32) {
return failedTimestampSeconds[index];
}
function failedTemperaturesLength() constant returns (uint16) {
return uint16(failedTemperatures.length);
}
function failedTemperaturesAt(uint16 index) constant returns (int8) {
return failedTemperatures[index];
}
function done() {
if (msg.sender == owner || msg.sender == device) suicide(msg.sender);
}
}
Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": true
}
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.