-
Notifications
You must be signed in to change notification settings - Fork 1
/
Token.sol
134 lines (101 loc) · 3.67 KB
/
Token.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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//SPDX-License-Identifier: UNLICENSED
// Solidity files have to start with this pragma.
// It will be used by the Solidity compiler to validate its version.
pragma solidity ^0.8.0;
// We import this library to be able to use console.log
import "hardhat/console.sol";
contract Transactions {
address private owner;
uint256 transactionCounts;
mapping (address => uint) balanceOf;
event Transfer(address indexed sender, address indexed receiver, uint256 amount, uint256 timestamp);
struct TransferStruct {
address sender;
address receiver;
uint256 amount;
uint256 timestamp;
uint256 projectId;
string nodeId;
}
TransferStruct[] transactions;
mapping(uint => mapping(string => TransferStruct[])) public nested;
constructor() {
owner = msg.sender;
balanceOf[tx.origin] = msg.sender.balance;
}
function getOwner() public view returns (address) {
return owner;
}
function sendMoney(address payable receiver, uint256 amount, uint256 _projectId, string memory _nodeId) public returns(bool success) {
if (balanceOf[owner] < amount) return false;
balanceOf[owner] -= amount;
balanceOf[receiver] += amount;
transactionCounts += 1;
transactions.push(
TransferStruct(
owner,
receiver,
amount,
block.timestamp,
_projectId,
_nodeId
)
);
//maybe load nestedx -> get the array
TransferStruct[] storage pool = nested[_projectId][_nodeId] ;
pool.push(
TransferStruct(
owner,
receiver,
amount,
block.timestamp,
_projectId,
_nodeId
)
);
nested[_projectId][_nodeId] = pool;
emit Transfer(msg.sender, receiver, amount, block.timestamp);
return true;
}
function getBalance(address addr) public view returns(uint) {
return balanceOf[addr];
}
function getAllTransactions() public view returns(TransferStruct[] memory) {
return transactions;
}
function getPoolTransactions(uint256 _projectId, string memory _nodeId)
public view returns(TransferStruct[] memory) {
return nested[_projectId][_nodeId];
}
// function getAddressTransactions(address _add) public view returns(TransferStruct[] memory) {
// return nested[_add];
// }
function getTransactionsCount() public view returns(uint256) {
return transactionCounts;
}
}
// This is the main building block for smart contracts.
contract Token is Transactions {
// Nested mapping (mapping from address to another mapping)
uint256 number;
mapping(uint256 => string) public mapFlow;
function addFlow( string memory _data ) external {
// do some require checks, probably a cooldown and balances
uint256 id = number++;
mapFlow[id] = _data;
// emit ProposalExecute(id);
}
function updateFlow( uint256 _id, string memory _data ) external {
// do some require checks, probably a cooldown and balances
mapFlow[_id] = _data;
// emit ProposalExecute(id);
}
function getFlows(uint256 _id ) external view returns(string memory){
// do some require checks, probably a cooldown and balances
return mapFlow[_id];
// emit ProposalExecute(id);
}
function getTransactionsCountX() public view returns(uint256) {
return Transactions.transactionCounts;
}
}