forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5df0cb2
commit 40acb44
Showing
3 changed files
with
54 additions
and
58 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
|
||
pragma solidity >=0.7.0 <=0.8.9; | ||
|
||
/** | ||
* @title Storage | ||
* @dev Store & retrieve value in a variable | ||
*/ | ||
contract Storage { | ||
|
||
uint256 number; | ||
|
||
/** | ||
* @dev Store value in variable | ||
* @param num value to store | ||
*/ | ||
function store(uint256 num) public { | ||
number = num; | ||
} | ||
|
||
/** | ||
* @dev Return value | ||
* @return value of 'number' | ||
*/ | ||
function retrieve() public view returns (uint256){ | ||
return number; | ||
} | ||
} | ||
|
||
contract StorageManager { | ||
// track storage contracts we've created | ||
|
||
address[] public storageAddrs; | ||
|
||
function create() public { | ||
Storage strContract = new Storage(); | ||
storageAddrs.push(address(strContract)); | ||
} | ||
|
||
function store(uint256 index, uint256 num) public { | ||
require(index < storageAddrs.length, "invalid index"); | ||
Storage strContract = Storage(storageAddrs[index]); | ||
strContract.store(num); | ||
} | ||
|
||
function retrieve(uint256 index) public view returns (uint256) { | ||
require(index < storageAddrs.length, "invalid index"); | ||
Storage strContract = Storage(storageAddrs[index]); | ||
return strContract.retrieve(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters