abrhsn1998

contract.sol

Nov 22nd, 2020 (edited)
250
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. pragma solidity >=0.4.22 <0.7.0;
  2.  
  3. // "SPDX-License-Identifier: UNLICENSED"
  4.  
  5. contract MainContract{
  6.  
  7. address owner;
  8. uint256 public dataCounter;
  9. mapping(uint256=>uint256[]) public dataList; // dataId -> Data
  10. mapping(string=>uint256) public timeToData; // time in string format -> Data
  11.  
  12. constructor() public payable{
  13. owner = msg.sender;
  14. dataCounter = 0;
  15. }
  16.  
  17. function createData(string memory _time, uint256[] memory _datas) public payable returns(uint256) {
  18. timeToData[_time] = dataCounter;
  19. dataList[dataCounter] = _datas;
  20. dataCounter++;
  21. return dataCounter-1;
  22. }
  23.  
  24. function getData(uint256 _dataId) public view returns(uint256[] memory){
  25. return dataList[_dataId];
  26. }
  27.  
  28. function getLatestData() public view returns(uint256[] memory){
  29. return dataList[dataCounter-1];
  30. }
  31.  
  32. function getDataId(string memory _time) public view returns (uint256){
  33. return timeToData[_time];
  34. }
  35.  
  36. }
RAW Paste Data