-
Notifications
You must be signed in to change notification settings - Fork 0
/
StorageFactory.sol
29 lines (21 loc) · 1.01 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
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0;
import "./SimpleStorage.sol";
contract StorageFactory {
SimpleStorage[] public simpleStorageArray;
function createSimpleStorageContract() public {
SimpleStorage simpleStorage = new SimpleStorage();
simpleStorageArray.push(simpleStorage);
}
function sfStore(uint256 _simpleStorageIndex, uint256 _simpleStorageNumber) public {
require(simpleStorageArray.length > _simpleStorageIndex, "There is no contract at that index.");
SimpleStorage simpleStorage = SimpleStorage(address(simpleStorageArray[_simpleStorageIndex]));
simpleStorage.store(_simpleStorageNumber);
}
function retrieveFavoriteNumberFromContractAtIndex(uint256 index) public view returns(uint256){
require(simpleStorageArray.length > index, "There is no contract at that index.");
SimpleStorage _contract = simpleStorageArray[index];
uint256 favoriteNumber = _contract.retrieve();
return favoriteNumber;
}
}