forked from PatrickAlphaC/storage_factory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StorageFactory.sol
33 lines (24 loc) · 1.38 KB
/
StorageFactory.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
import "./SimpleStorage.sol";
contract StorageFactory is SimpleStorage {
SimpleStorage[] public simpleStorageArray;
function createSimpleStorageContract() public {
SimpleStorage simpleStorage = new SimpleStorage();
simpleStorageArray.push(simpleStorage);
}
function sfStore(uint256 _simpleStorageIndex, uint256 _simpleStorageNumber) public {
// Address
// ABI
//this line has an explicit cast to the address type and initializes a new SimpleStorage object from the address
SimpleStorage(address(simpleStorageArray[_simpleStorageIndex])).store(_simpleStorageNumber);
//this line simply gets the SimpleStorage object at the index _simpleStorageIndex in the array simpleStorageArray
//simpleStorageArray[_simpleStorageIndex].store(_simpleStorageNumber);
}
function sfGet(uint256 _simpleStorageIndex) public view returns (uint256) {
//this line has an explicit cast to the address type and initializes a new SimpleStorage object from the address
return SimpleStorage(address(simpleStorageArray[_simpleStorageIndex])).retrieve();
//this line simply gets the SimpleStorage object at the index _simpleStorageIndex in the array simpleStorageArray
//return simpleStorageArray[_simpleStorageIndex].retrieve();
}
}