Repository navigation
Expand file tree
/
Copy pathOrgLib.sol
More file actions
145 lines (116 loc) · 5.4 KB
/
Copy pathOrgLib.sol
File metadata and controls
145 lines (116 loc) · 5.4 KB
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
135
136
137
138
139
140
141
142
143
144
145
/*
Trade Control Network
Org library (embedded)
Author IAM
github.com/tradecontrol/tc-network
Licence GNU General Public License v3.0
https://www.gnu.org/licenses/gpl-3.0.en.html
*/
pragma solidity >=0.4.21 <=0.5.12;
library OrgLib
{
struct Account {
address EOA;
bool IsAuthorised;
}
struct Consortium {
address OrgContract;
string AccountCode;
}
struct Invoice {
address OwnerContract;
address MirrorContract;
bool IsMirrored;
}
struct Orgs {
mapping (string => Account) Accounts;
mapping (address => Consortium) Consortiums;
mapping (address => mapping (string => string)) Activities;
mapping (address => mapping (string => string)) CashCodes;
mapping (string => address) Tasks;
mapping (string => mapping (string => Invoice)) Invoices;
}
// ** Consortium **
function NewMember(Orgs storage _self, address _eoa, address _orgContract, string memory _accountCode, bool _isAuthorised) internal {
_self.Consortiums[_eoa].AccountCode = _accountCode;
_self.Consortiums[_eoa].OrgContract = _orgContract;
_self.Accounts[_accountCode].IsAuthorised = _isAuthorised;
_self.Accounts[_accountCode].EOA = _eoa;
}
function Authorise (Orgs storage _self, string memory _accountCode, bool _isAuthorised) internal {
_self.Accounts[_accountCode].IsAuthorised = _isAuthorised;
}
function IsAuthorised(Orgs storage _self, address _eoa) internal view returns (bool _isAuthorised) {
return _self.Accounts[_self.Consortiums[_eoa].AccountCode].IsAuthorised;
}
function IsAuthorised(Orgs storage _self, string memory _accountCode) internal view returns (bool _isAuthorised) {
return _self.Accounts[_accountCode].IsAuthorised;
}
function GetAccountCode (Orgs storage _self, address _eoa) internal view returns (string memory _accountCode) {
return _self.Consortiums[_eoa].AccountCode;
}
function GetAccountCode (Orgs storage _self) internal view returns (string memory _accountCode) {
return _self.Consortiums[msg.sender].AccountCode;
}
function GetConsortium (Orgs storage _self, string memory _accountCode) internal view returns (address _consortium) {
return _self.Consortiums[_self.Accounts[_accountCode].EOA].OrgContract;
}
function GetEOA (Orgs storage _self, string memory _accountCode) internal view returns (address _eoa) {
return _self.Accounts[_accountCode].EOA;
}
// ** Activities **
function ActivityMirror(Orgs storage _self, address _eoa,
string memory _activityCode, string memory _allocationCode) internal
{
_self.Activities[_eoa][_activityCode] = _allocationCode;
}
function AllocationCode(Orgs storage _self, address _eoa,
string memory _activityCode) internal view returns (string memory allocationCode) {
allocationCode = _self.Activities[_eoa][_activityCode];
}
// ** Cash Codes **
function CashCodeMirror(Orgs storage _self, address _eoa,
string memory _cashCode, string memory _chargeCode) internal
{
_self.Activities[_eoa][_cashCode] = _chargeCode;
}
function ChargeCode(Orgs storage _self, address _eoa,
string memory _cashCode) internal view returns (string memory chargeCode) {
chargeCode = _self.CashCodes[_eoa][_cashCode];
}
// ** Tasks **
function TaskNew (Orgs storage _self, string memory _taskCode, address _taskContract) internal
{
_self.Tasks[_taskCode] = _taskContract;
}
function TaskContract(Orgs storage _self,
string memory _taskCode) internal view returns (address ownerContract) {
ownerContract = _self.Tasks[_taskCode];
}
// ** Invoices **
function InvoiceNew (Orgs storage _self, string memory _accountCode, string memory _invoiceNumber, address _invoiceContract) internal
{
_self.Invoices[_accountCode][_invoiceNumber] = Invoice(_invoiceContract, _invoiceContract, false);
}
function InvoiceMirror(Orgs storage _self, string memory _invoiceNumber, address _invoiceContract) internal
{
require (_self.Accounts[_self.Consortiums[msg.sender].AccountCode].IsAuthorised, "Un-authorised account");
string memory accountCode;
accountCode = _self.Consortiums[msg.sender].AccountCode;
require (!_self.Invoices[accountCode][_invoiceNumber].IsMirrored, "Invoice is already mirrored");
_self.Invoices[accountCode][_invoiceNumber].MirrorContract = _invoiceContract;
_self.Invoices[accountCode][_invoiceNumber].IsMirrored = true;
}
function InvoiceIsMirrored (Orgs storage _self, string memory _accountCode,
string memory _invoiceNumber) internal view returns (bool isMirrored) {
isMirrored = _self.Invoices[_accountCode][_invoiceNumber].IsMirrored;
}
function InvoiceOwnerContract(Orgs storage _self, string memory _accountCode,
string memory _invoiceNumber) internal view returns (address ownerContract) {
ownerContract = _self.Invoices[_accountCode][_invoiceNumber].OwnerContract;
}
function InvoiceMirrorContract(Orgs storage _self, string memory _accountCode,
string memory _invoiceNumber) internal view returns (address mirrorContract) {
mirrorContract = _self.Invoices[_accountCode][_invoiceNumber].MirrorContract;
}
}