Skip to content

Instantly share code, notes, and snippets.

@idimitrov07
Created September 28, 2018 11:18
Show Gist options
  • Select an option

  • Save idimitrov07/6a593d6002e306d1ff0afd1468a34dfe to your computer and use it in GitHub Desktop.

Select an option

Save idimitrov07/6a593d6002e306d1ff0afd1468a34dfe to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.24;
contract AssetTracker {
// define new Asset object
struct Asset {
uint256 uuid;
string name;
string manufacturer;
uint256 timestamp;
}
// create a new asset mapping
mapping (uint256 => Asset) assets;
mapping (uint256 => bytes32[]) assetToCheckpoint;
// create new asset
function createAsset(uint uuid, string name, string manufacturer) {
assets[uuid] = Asset(uuid, name, manufacturer, now);
}
// get asset, view function
function getAsset(uint256 uuid) view returns(uint256, string, string, uint256) {
return (assets[uuid].uuid, assets[uuid].name, assets[uuid].manufacturer, assets[uuid].timestamp);
}
// add to checkpount
function addCheckpoint(uint256 uuid, bytes32 message) {
assetToCheckpoint[uuid].push(message);
}
function getCheckpoints(uint256 uuid) view returns (bytes32[]) {
return assetToCheckpoint[uuid];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment