Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the unnecessary code from partitionsOf() #681

Merged
merged 1 commit into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions contracts/interfaces/ITransferManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,4 @@ interface ITransferManager {
*/
function getTokensByPartition(bytes32 _partition, address _tokenHolder, uint256 _additionalBalance) external view returns(uint256);

/**
* @notice return the list of partitions for a tokenHolder
* @param _tokenHolder Whom token amount need to query
*/
function getPartitions(address _tokenHolder) external view returns(bytes32[] memory);

}
10 changes: 0 additions & 10 deletions contracts/modules/TransferManager/TransferManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,4 @@ contract TransferManager is ITransferManager, Module {
return 0;
}

/**
* @notice return the amount of tokens for a given user as per the partition
*/
function getPartitions(address /*_tokenHolder*/) external view returns(bytes32[] memory) {
bytes32[] memory result = new bytes32[](2);
result[0] = UNLOCKED;
result[1] = LOCKED;
return result;
}

}
66 changes: 8 additions & 58 deletions contracts/tokens/STGetter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -228,63 +228,13 @@ contract STGetter is OZStorage, SecurityTokenStorage {

/**
* @notice Return all partitions
* @param _tokenHolder Whom balance need to queried
* @return List of partitions
*/
function partitionsOf(address _tokenHolder) external view returns (bytes32[] memory) {
address[] memory tms = modules[TRANSFER_KEY];
/* uint256 count; */
bytes32[] memory partitions;
bytes32[] memory tmPartitions;
// First determine the total number of non-distinct partitions
for (uint256 i = 0; i < tms.length; i++) {
tmPartitions = ITransferManager(tms[i]).getPartitions(_tokenHolder);
for (uint256 j = 0 ; j < tmPartitions.length; j++) {
partitions = _appendPartition(partitions, tmPartitions[j]);
}
}
partitions = _appendPartition(partitions, "DEFAULT");
/* bytes32[] memory partitions = new bytes32[](count + 1);
count = 0;
for (uint256 i = 0; i < tms.length; i++) {
tmPartitions = ITransferManager(tms[i]).getPartitions(_tokenHolder);
for (uint256 j = 0; j < tmPartitions.length; j++) {
partitions[count + j] = tmPartitions[j];
}
count += tmPartitions.length;
}
partitions[count] = "DEFAULT";
uint256[] memory index = new uint256[](count);
count = 0;
for (uint256 i = 0; i < partitions.length; i++) {
for (uint256 j = 0; j < partitions.length; j++) {
if (partitions[i] == partitions[j]) {
index[i] = j;
}
}
}
// Create distinct list
bytes32[] memory result */
return partitions;
}

function _appendPartition(bytes32[] memory partitions, bytes32 partition) internal pure returns (bytes32[] memory) {
bool duplicate = false;
for (uint256 i = 0; i < partitions.length; i++) {
if (partition == partitions[i]) {
duplicate = true;
break;
}
}
if (duplicate) {
bytes32[] memory result = new bytes32[](1 + partitions.length);
for (uint256 i = 0; i < partitions.length; i++) {
result[i] = partitions[i];
}
result[partitions.length] = partition;
return result;
}
return partitions;
function partitionsOf(address /*_tokenHolder*/) external view returns (bytes32[] memory) {
bytes32[] memory result = new bytes32[](2);
result[0] = UNLOCKED;
result[1] = LOCKED;
return result;
}

/**
Expand All @@ -307,9 +257,9 @@ contract STGetter is OZStorage, SecurityTokenStorage {
*/
function getDocument(bytes32 _name) external view returns (string memory, bytes32, uint256) {
return (
_documents[_name].uri,
_documents[_name].docHash,
_documents[_name].lastModified
_documents[_name].uri,
_documents[_name].docHash,
_documents[_name].lastModified
);
}

Expand Down
11 changes: 10 additions & 1 deletion test/o_security_token.js
Original file line number Diff line number Diff line change
Expand Up @@ -1735,7 +1735,16 @@ contract("SecurityToken", async (accounts) => {

let afterTotalSupply = await I_SecurityToken.totalSupply.call();
assert.equal(web3.utils.fromWei(beforeTotalSupply.sub(afterTotalSupply)), 10);
})
});

it("Should get the partitions of the secuirtyToken", async() => {
let partitions = await I_STGetter.partitionsOf.call(account_investor1);
console.log(`Partitions of the investor 1: ${web3.utils.hexToUtf8(partitions[0])}`);
assert.equal("UNLOCKED", web3.utils.hexToUtf8(partitions[0]));
assert.equal("LOCKED", web3.utils.hexToUtf8(partitions[1]));
partitions = await I_STGetter.partitionsOf.call(account_investor2);
console.log(`Partitions of the investor 2: ${web3.utils.hexToUtf8(partitions[0])}`);
});
});

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