@@ -94,9 +94,7 @@ contract Registry is RegistryInterface, MultiRole {
9494 // For all parties in the array add them to the contract's parties.
9595 financialContract.valid = Validity.Valid;
9696 for (uint i = 0 ; i < parties.length ; i = i.add (1 )) {
97- partyMap[parties[i]].contracts.push (contractAddress);
98- uint newLength = partyMap[parties[i]].contracts.length ;
99- partyMap[parties[i]].contractIndex[contractAddress] = newLength - 1 ;
97+ _addPartyToContract (parties[i], contractAddress);
10098 }
10199
102100 emit NewContractRegistered (contractAddress, msg .sender , parties);
@@ -113,14 +111,8 @@ contract Registry is RegistryInterface, MultiRole {
113111 address contractAddress = msg .sender ;
114112
115113 require (contractMap[contractAddress].valid == Validity.Valid, "Can only add to valid contract " );
116- require (! isPartyMemberOfContract (party, contractAddress), "Can only register a party once " );
117-
118- // Push the contract address and store the index.
119- uint contractIndex = partyMap[party].contracts.length ;
120- partyMap[party].contracts.push (contractAddress);
121- partyMap[party].contractIndex[contractAddress] = contractIndex;
122114
123- emit PartyAdded (contractAddress, party );
115+ _addPartyToContract (party, contractAddress );
124116 }
125117
126118 /**
@@ -207,4 +199,17 @@ contract Registry is RegistryInterface, MultiRole {
207199 uint index = partyMap[party].contractIndex[contractAddress];
208200 return partyMap[party].contracts.length > index && partyMap[party].contracts[index] == contractAddress;
209201 }
202+
203+ /****************************************
204+ * INTERNAL FUNCTIONS *
205+ ****************************************/
206+
207+ function _addPartyToContract (address party , address contractAddress ) internal {
208+ require (! isPartyMemberOfContract (party, contractAddress), "Can only register a party once " );
209+ uint contractIndex = partyMap[party].contracts.length ;
210+ partyMap[party].contracts.push (contractAddress);
211+ partyMap[party].contractIndex[contractAddress] = contractIndex;
212+
213+ emit PartyAdded (contractAddress, party);
214+ }
210215}
0 commit comments