github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/vent/test/EventsTest.sol (about)

     1  pragma solidity >=0.4.20;
     2  
     3  contract EventsTest {
     4  
     5      event UpdateTestEvents(
     6          bytes32 indexed name,
     7          bytes32 indexed key,
     8          bytes32 indexed description);
     9  
    10      event DeleteTestEvents(
    11          bytes32 indexed name,
    12          bytes32 indexed key,
    13          int __DELETE__);
    14  
    15      bytes32 constant TABLE_EVENTS_TEST = "TEST_EVENTS";
    16  
    17      struct Thing {
    18          string name;
    19          string description;
    20          bool exists;
    21      }
    22  
    23      int length;
    24      mapping(string => Thing) things;
    25  
    26      function addThing(string calldata _name, string calldata _description) external {
    27          Thing storage thing = things[_name];
    28          if (!thing.exists) {
    29              length++;
    30          }
    31          thing.name = _name;
    32          thing.description = _description;
    33          thing.exists = true;
    34          emit UpdateTestEvents(prefix32(_name), TABLE_EVENTS_TEST, prefix32(_description));
    35      }
    36  
    37      function addThings(string calldata _name, string calldata _description) external {
    38          Thing storage thing = things[_name];
    39          if (!thing.exists) {
    40              length++;
    41          }
    42          thing.name = _name;
    43          thing.description = _description;
    44          thing.exists = true;
    45          emit UpdateTestEvents(prefix32(_name), TABLE_EVENTS_TEST, prefix32(_description));
    46          emit UpdateTestEvents(prefix32(_name), TABLE_EVENTS_TEST, prefix32(_description));
    47      }
    48  
    49      function removeThing(string calldata _name) external {
    50          Thing storage thing = things[_name];
    51          if (thing.exists) {
    52              length--;
    53              delete things[_name];
    54              emit DeleteTestEvents(prefix32(_name), TABLE_EVENTS_TEST, 0);
    55          }
    56      }
    57  
    58      function removeThings(string calldata _name) external {
    59          Thing storage thing = things[_name];
    60          if (thing.exists) {
    61              length--;
    62              delete things[_name];
    63              emit DeleteTestEvents(prefix32(_name), TABLE_EVENTS_TEST, 0);
    64              emit DeleteTestEvents(prefix32(_name), TABLE_EVENTS_TEST, 0);
    65          }
    66      }
    67  
    68      function count() external view returns (int size) {
    69          return length;
    70      }
    71  
    72      function description(string calldata _name) external view returns (string memory _description) {
    73          return things[_name].description;
    74      }
    75  
    76      function prefix32(string memory _str) private pure returns (bytes32 str32) {
    77          assembly {
    78          // We load one word256 after the start address of _str so that we get the first 32 bytes. Note: strings
    79          // with length less than 32 bytes are padded to a multiple of 32 bytes so we are not eating consecutive
    80          // memory here.
    81              str32 := mload(add(_str, 32))
    82          }
    83      }
    84  }