-
Notifications
You must be signed in to change notification settings - Fork 0
/
Storage Number
83 lines (58 loc) · 2.09 KB
/
Storage Number
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// SPDX-License-Identifier: MIT
pragma solidity 0.8.7;
//First import method;
/*contract SimpleStorage {
uint256 ImHereStoreNumber;
mapping (string => uint256) public nameWhereStoreNumber;
struct People {
uint256 ImHereStoreNumber;
string name;
}
People[] public people;
function store (uint256 _ImHereStoreNumber) public {
ImHereStoreNumber = _ImHereStoreNumber;
}
function retrieve () public view returns (uint256){
return ImHereStoreNumber;
}
function addPerson(string memory _name, uint256 _ImHereStoreNumber) public {
people.push(People(_ImHereStoreNumber,_name));
nameWhereStoreNumber[_name] = _ImHereStoreNumber;
}
}
*/
//Second type importes method:
import "./SimpleStorage.sol";
// This Contract create storage
contract StorageFactory{
SimpleStorage[] public simpleStorageArray;
//This Function create storage
function createStorage() public {
SimpleStorage simpleStorage = new SimpleStorage();
// This simpleStorageArray is store Address when any one run this code the address show
simpleStorageArray.push(simpleStorage);
}
//This function Store the data on it Array
function sfStore(uint256 _simpleStorageIndex, uint256 _simpleStorageNumber) public {
/*
First Method is
SimpleStorage simpleStorage = SimpleStorage (simpleStorageArray[_simpleStorageIndex]);
*/
/*
Data store on Array index
First Method:
SimpleStorage simpleStorage = simpleStorageArray[_simpleStorageIndex];
simpleStorage.store(_simpleStorageNumber);
*/
//Second Method;
simpleStorageArray[_simpleStorageIndex].store(_simpleStorageNumber);
}
//This Function Read the data from Array by retrieve index
function sfGet(uint256 _simpleStorageIndex) public view returns (uint256){
/*First Method to Retrieve Data:
SimpleStorage simpleStorage = simpleStorageArray[_simpleStorageIndex];
*/
//Second Method;
return simpleStorageArray[_simpleStorageIndex].retrieve();
}
}