Skip to content

Commit 8f31ea9

Browse files
satyamakgecmaxsam4
authored andcommitted
remove the unneccessary code from partitionsOf() (#681)
1 parent 0ae44d0 commit 8f31ea9

File tree

4 files changed

+18
-75
lines changed

4 files changed

+18
-75
lines changed

contracts/interfaces/ITransferManager.sol

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,4 @@ interface ITransferManager {
2626
*/
2727
function getTokensByPartition(bytes32 _partition, address _tokenHolder, uint256 _additionalBalance) external view returns(uint256);
2828

29-
/**
30-
* @notice return the list of partitions for a tokenHolder
31-
* @param _tokenHolder Whom token amount need to query
32-
*/
33-
function getPartitions(address _tokenHolder) external view returns(bytes32[] memory);
34-
3529
}

contracts/modules/TransferManager/TransferManager.sol

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,4 @@ contract TransferManager is ITransferManager, Module {
2525
return 0;
2626
}
2727

28-
/**
29-
* @notice return the amount of tokens for a given user as per the partition
30-
*/
31-
function getPartitions(address /*_tokenHolder*/) external view returns(bytes32[] memory) {
32-
bytes32[] memory result = new bytes32[](2);
33-
result[0] = UNLOCKED;
34-
result[1] = LOCKED;
35-
return result;
36-
}
37-
3828
}

contracts/tokens/STGetter.sol

Lines changed: 8 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -228,63 +228,13 @@ contract STGetter is OZStorage, SecurityTokenStorage {
228228

229229
/**
230230
* @notice Return all partitions
231-
* @param _tokenHolder Whom balance need to queried
232231
* @return List of partitions
233232
*/
234-
function partitionsOf(address _tokenHolder) external view returns (bytes32[] memory) {
235-
address[] memory tms = modules[TRANSFER_KEY];
236-
/* uint256 count; */
237-
bytes32[] memory partitions;
238-
bytes32[] memory tmPartitions;
239-
// First determine the total number of non-distinct partitions
240-
for (uint256 i = 0; i < tms.length; i++) {
241-
tmPartitions = ITransferManager(tms[i]).getPartitions(_tokenHolder);
242-
for (uint256 j = 0 ; j < tmPartitions.length; j++) {
243-
partitions = _appendPartition(partitions, tmPartitions[j]);
244-
}
245-
}
246-
partitions = _appendPartition(partitions, "DEFAULT");
247-
/* bytes32[] memory partitions = new bytes32[](count + 1);
248-
count = 0;
249-
for (uint256 i = 0; i < tms.length; i++) {
250-
tmPartitions = ITransferManager(tms[i]).getPartitions(_tokenHolder);
251-
for (uint256 j = 0; j < tmPartitions.length; j++) {
252-
partitions[count + j] = tmPartitions[j];
253-
}
254-
count += tmPartitions.length;
255-
}
256-
partitions[count] = "DEFAULT";
257-
uint256[] memory index = new uint256[](count);
258-
count = 0;
259-
for (uint256 i = 0; i < partitions.length; i++) {
260-
for (uint256 j = 0; j < partitions.length; j++) {
261-
if (partitions[i] == partitions[j]) {
262-
index[i] = j;
263-
}
264-
}
265-
}
266-
// Create distinct list
267-
bytes32[] memory result */
268-
return partitions;
269-
}
270-
271-
function _appendPartition(bytes32[] memory partitions, bytes32 partition) internal pure returns (bytes32[] memory) {
272-
bool duplicate = false;
273-
for (uint256 i = 0; i < partitions.length; i++) {
274-
if (partition == partitions[i]) {
275-
duplicate = true;
276-
break;
277-
}
278-
}
279-
if (duplicate) {
280-
bytes32[] memory result = new bytes32[](1 + partitions.length);
281-
for (uint256 i = 0; i < partitions.length; i++) {
282-
result[i] = partitions[i];
283-
}
284-
result[partitions.length] = partition;
285-
return result;
286-
}
287-
return partitions;
233+
function partitionsOf(address /*_tokenHolder*/) external view returns (bytes32[] memory) {
234+
bytes32[] memory result = new bytes32[](2);
235+
result[0] = UNLOCKED;
236+
result[1] = LOCKED;
237+
return result;
288238
}
289239

290240
/**
@@ -307,9 +257,9 @@ contract STGetter is OZStorage, SecurityTokenStorage {
307257
*/
308258
function getDocument(bytes32 _name) external view returns (string memory, bytes32, uint256) {
309259
return (
310-
_documents[_name].uri,
311-
_documents[_name].docHash,
312-
_documents[_name].lastModified
260+
_documents[_name].uri,
261+
_documents[_name].docHash,
262+
_documents[_name].lastModified
313263
);
314264
}
315265

test/o_security_token.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1828,7 +1828,16 @@ contract("SecurityToken", async (accounts) => {
18281828

18291829
let afterTotalSupply = await I_SecurityToken.totalSupply.call();
18301830
assert.equal(web3.utils.fromWei(beforeTotalSupply.sub(afterTotalSupply)), 10);
1831-
})
1831+
});
1832+
1833+
it("Should get the partitions of the secuirtyToken", async() => {
1834+
let partitions = await I_STGetter.partitionsOf.call(account_investor1);
1835+
console.log(`Partitions of the investor 1: ${web3.utils.hexToUtf8(partitions[0])}`);
1836+
assert.equal("UNLOCKED", web3.utils.hexToUtf8(partitions[0]));
1837+
assert.equal("LOCKED", web3.utils.hexToUtf8(partitions[1]));
1838+
partitions = await I_STGetter.partitionsOf.call(account_investor2);
1839+
console.log(`Partitions of the investor 2: ${web3.utils.hexToUtf8(partitions[0])}`);
1840+
});
18321841
});
18331842

18341843
describe("Test cases for the storage", async() => {

0 commit comments

Comments
 (0)