github.com/ethereum/go-ethereum@v1.16.1/accounts/abi/bind/v2/internal/contracts/db/contract.sol (about)

     1  // SPDX-License-Identifier: GPL-3.0
     2  pragma solidity >=0.7.0 <0.9.0;
     3  
     4  contract DB {
     5      uint balance = 0;
     6      mapping(uint => uint) private _store;
     7      uint[] private _keys;
     8      struct Stats {
     9          uint gets;
    10          uint inserts;
    11          uint mods; // modifications
    12      }
    13      Stats _stats;
    14  
    15      event KeyedInsert(uint indexed key, uint value);
    16      event Insert(uint key, uint value, uint length);
    17  
    18      constructor() {
    19          _stats = Stats(0, 0, 0);
    20      }
    21  
    22      // insert adds a key value to the store, returning the new length of the store.
    23      function insert(uint k, uint v) external returns (uint) {
    24          // No need to store 0 values
    25          if (v == 0) {
    26              return _keys.length;
    27          }
    28          // Check if a key is being overriden
    29          if (_store[k] == 0) {
    30              _keys.push(k);
    31              _stats.inserts++;
    32          } else {
    33              _stats.mods++;
    34          }
    35          _store[k] = v;
    36          emit Insert(k, v, _keys.length);
    37          emit KeyedInsert(k, v);
    38  
    39          return _keys.length;
    40      }
    41  
    42      function get(uint k) public returns (uint) {
    43          _stats.gets++;
    44          return _store[k];
    45      }
    46  
    47      function getStatParams() public view returns (uint, uint, uint) {
    48          return (_stats.gets, _stats.inserts, _stats.mods);
    49      }
    50  
    51      function getNamedStatParams() public view returns (uint gets, uint inserts, uint mods) {
    52          return (_stats.gets, _stats.inserts, _stats.mods);
    53      }
    54  
    55      function getStatsStruct() public view returns (Stats memory) {
    56          return _stats;
    57      }
    58  
    59      receive() external payable {
    60          balance += msg.value;
    61      }
    62  
    63      fallback(bytes calldata _input) external returns (bytes memory _output) {
    64          _output = _input;
    65      }
    66  }