Skip to content

Commit

Permalink
Code review completed
Browse files Browse the repository at this point in the history
  • Loading branch information
bokkypoobah committed Dec 10, 2017
1 parent 06c15ed commit 715369e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -682,12 +682,12 @@ contract BTTSToken is ERC20Token, BTTSInterface {
## Code Review
* [ ] [code-review/BTTSTokenFactory.md](code-review/BTTSTokenFactory.md)
* [x] [code-review/BTTSTokenFactory.md](code-review/BTTSTokenFactory.md)
* [x] contract ERC20Interface
* [x] contract ApproveAndCallFallBack
* [x] contract BTTSTokenInterface is ERC20Interface
* [ ] library BTTSLib
* [ ] contract BTTSToken is BTTSTokenInterface
* [x] library BTTSLib
* [x] contract BTTSToken is BTTSTokenInterface
* [x] contract Owned
* [x] contract BTTSTokenFactory is Owned
Expand Down
55 changes: 51 additions & 4 deletions code-review/BTTSTokenFactory.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,14 @@ library BTTSLib {
// ------------------------------------------------------------------------
// Minting and management
// ------------------------------------------------------------------------
// BK Next function Ok - Only owner can execute
// BK Next function Ok - Only owner can execute when mintable
function setMinter(Data storage self, address minter) public {
require(msg.sender == self.owner);
require(self.mintable);
MinterUpdated(self.minter, minter);
self.minter = minter;
}
// BK Next function Ok - Only owner or minter can execute
// BK Next function Ok - Only owner or minter can execute when mintable
function mint(Data storage self, address tokenOwner, uint tokens, bool lockAccount) public returns (bool success) {
require(self.mintable);
require(msg.sender == self.minter || msg.sender == self.owner);
Expand Down Expand Up @@ -418,7 +418,7 @@ library BTTSLib {
// ------------------------------------------------------------------------
// Signed function
// ------------------------------------------------------------------------
// BK NOTE - Token owner signs [functionSig, tokenContractAddress, tokenOwner, toAccount, fees, nonce]
// BK NOTE - Token owner signs [functionSig, tokenContractAddress, tokenOwner, to, tokens, fee, nonce]
// BK Next function Ok - Pure function
function signedTransferHash(Data storage /*self*/, address tokenContract, address tokenOwner, address to, uint tokens, uint fee, uint nonce) public pure returns (bytes32 hash) {
hash = keccak256(signedTransferSig, tokenContract, tokenOwner, to, tokens, fee, nonce);
Expand All @@ -437,6 +437,7 @@ library BTTSLib {
if (self.balances[feeAccount] + fee < self.balances[feeAccount]) return BTTSTokenInterface.CheckResult.OverflowError;
return BTTSTokenInterface.CheckResult.Success;
}
// BK Next function Ok
function signedTransfer(Data storage self, address tokenContract, address tokenOwner, address to, uint tokens, uint fee, uint nonce, bytes sig, address feeAccount) public returns (bool success) {
require(self.transferable);
bytes32 hash = signedTransferHash(self, tokenContract, tokenOwner, to, tokens, fee, nonce);
Expand All @@ -452,7 +453,7 @@ library BTTSLib {
Transfer(tokenOwner, feeAccount, fee);
return true;
}
// BK NOTE - Token owner signs [functionSig, tokenContractAddress, tokenOwner, spender, toAccount, fees, nonce]
// BK NOTE - Token owner signs [functionSig, tokenContractAddress, tokenOwner, spender, tokens, fee, nonce]
// BK Next function Ok - Pure function
function signedApproveHash(Data storage /*self*/, address tokenContract, address tokenOwner, address spender, uint tokens, uint fee, uint nonce) public pure returns (bytes32 hash) {
hash = keccak256(signedApproveSig, tokenContract, tokenOwner, spender, tokens, fee, nonce);
Expand All @@ -468,6 +469,7 @@ library BTTSLib {
if (self.balances[feeAccount] + fee < self.balances[feeAccount]) return BTTSTokenInterface.CheckResult.OverflowError;
return BTTSTokenInterface.CheckResult.Success;
}
// BK Next function Ok
function signedApprove(Data storage self, address tokenContract, address tokenOwner, address spender, uint tokens, uint fee, uint nonce, bytes sig, address feeAccount) public returns (bool success) {
require(self.transferable);
bytes32 hash = signedApproveHash(self, tokenContract, tokenOwner, spender, tokens, fee, nonce);
Expand All @@ -482,6 +484,7 @@ library BTTSLib {
Transfer(tokenOwner, feeAccount, fee);
return true;
}
// BK NOTE - Token owner signs [functionSig, tokenContractAddress, spender, from, to, tokens, fee, nonce]
// BK Next function Ok - Pure function
function signedTransferFromHash(Data storage /*self*/, address tokenContract, address spender, address from, address to, uint tokens, uint fee, uint nonce) public pure returns (bytes32 hash) {
hash = keccak256(signedTransferFromSig, tokenContract, spender, from, to, tokens, fee, nonce);
Expand All @@ -502,6 +505,7 @@ library BTTSLib {
if (self.balances[feeAccount] + fee < self.balances[feeAccount]) return BTTSTokenInterface.CheckResult.OverflowError;
return BTTSTokenInterface.CheckResult.Success;
}
// BK Next function Ok
function signedTransferFrom(Data storage self, address tokenContract, address spender, address from, address to, uint tokens, uint fee, uint nonce, bytes sig, address feeAccount) public returns (bool success) {
require(self.transferable);
bytes32 hash = signedTransferFromHash(self, tokenContract, spender, from, to, tokens, fee, nonce);
Expand All @@ -519,6 +523,7 @@ library BTTSLib {
Transfer(from, feeAccount, fee);
return true;
}
// BK NOTE - Spender signs [functionSig, tokenContractAddress, tokenOwner, spender, tokens, data, fee, nonce]
// BK Next function Ok - Pure function
function signedApproveAndCallHash(Data storage /*self*/, address tokenContract, address tokenOwner, address spender, uint tokens, bytes data, uint fee, uint nonce) public pure returns (bytes32 hash) {
hash = keccak256(signedApproveAndCallSig, tokenContract, tokenOwner, spender, tokens, data, fee, nonce);
Expand All @@ -534,6 +539,7 @@ library BTTSLib {
if (self.balances[feeAccount] + fee < self.balances[feeAccount]) return BTTSTokenInterface.CheckResult.OverflowError;
return BTTSTokenInterface.CheckResult.Success;
}
// BK Next function Ok
function signedApproveAndCall(Data storage self, address tokenContract, address tokenOwner, address spender, uint tokens, bytes data, uint fee, uint nonce, bytes sig, address feeAccount) public returns (bool success) {
require(self.transferable);
bytes32 hash = signedApproveAndCallHash(self, tokenContract, tokenOwner, spender, tokens, data, fee, nonce);
Expand All @@ -557,153 +563,194 @@ library BTTSLib {
//
// Enjoy. (c) BokkyPooBah / Bok Consulting Pty Ltd 2017. The MIT Licence.
// ----------------------------------------------------------------------------
// BK Ok
contract BTTSToken is BTTSTokenInterface {
// BK Ok
using BTTSLib for BTTSLib.Data;

// BK Ok
BTTSLib.Data data;

// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
// BK Next function Ok - Constructor calling the library init
function BTTSToken(address owner, string symbol, string name, uint8 decimals, uint initialSupply, bool mintable, bool transferable) public {
data.init(owner, symbol, name, decimals, initialSupply, mintable, transferable);
}

// ------------------------------------------------------------------------
// Ownership
// ------------------------------------------------------------------------
// BK Next function Ok - View function
function owner() public view returns (address) {
return data.owner;
}
// BK Next function Ok - View function
function newOwner() public view returns (address) {
return data.newOwner;
}
// BK Next function Ok - Only owner can execute
function transferOwnership(address _newOwner) public {
data.transferOwnership(_newOwner);
}
// BK Next function Ok - Only new owner can execute
function acceptOwnership() public {
data.acceptOwnership();
}
// BK Next function Ok - Only owner can execute
function transferOwnershipImmediately(address _newOwner) public {
data.transferOwnershipImmediately(_newOwner);
}

// ------------------------------------------------------------------------
// Token
// ------------------------------------------------------------------------
// BK Next function Ok - View function
function symbol() public view returns (string) {
return data.symbol;
}
// BK Next function Ok - View function
function name() public view returns (string) {
return data.name;
}
// BK Next function Ok - View function
function decimals() public view returns (uint8) {
return data.decimals;
}

// ------------------------------------------------------------------------
// Minting and management
// ------------------------------------------------------------------------
// BK Next function Ok - View function
function minter() public view returns (address) {
return data.minter;
}
// BK Next function Ok - Only owner can execute when mintable
function setMinter(address _minter) public {
data.setMinter(_minter);
}
// BK Next function Ok - Only owner or minter can execute when mintable
function mint(address tokenOwner, uint tokens, bool lockAccount) public returns (bool success) {
return data.mint(tokenOwner, tokens, lockAccount);
}
// BK Next function Ok - Only owner can execute
function unlockAccount(address tokenOwner) public {
return data.unlockAccount(tokenOwner);
}
// BK Next function Ok - View function
function mintable() public view returns (bool) {
return data.mintable;
}
// BK Next function Ok - View function
function transferable() public view returns (bool) {
return data.transferable;
}
// BK Next function Ok - Only owner or minter can execute
function disableMinting() public {
data.disableMinting();
}
// BK Next function Ok - Only owner can execute
function enableTransfers() public {
data.enableTransfers();
}

// ------------------------------------------------------------------------
// Other functions
// ------------------------------------------------------------------------
// BK Next function Ok - Only owner can execute
function transferAnyERC20Token(address tokenAddress, uint tokens) public returns (bool success) {
return data.transferAnyERC20Token(tokenAddress, tokens);
}

// ------------------------------------------------------------------------
// Don't accept ethers
// ------------------------------------------------------------------------
// BK Next function Ok
function () public payable {
revert();
}

// ------------------------------------------------------------------------
// Token functions
// ------------------------------------------------------------------------
// BK Next function Ok - Constant function
function totalSupply() public constant returns (uint) {
return data.totalSupply - data.balances[address(0)];
}
// BK Next function Ok - Constant function
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return data.balances[tokenOwner];
}
// BK Next function Ok - Constant function
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return data.allowed[tokenOwner][spender];
}
// BK Next function Ok
function transfer(address to, uint tokens) public returns (bool success) {
return data.transfer(to, tokens);
}
// BK Next function Ok
function approve(address spender, uint tokens) public returns (bool success) {
return data.approve(spender, tokens);
}
// BK Next function Ok
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
return data.transferFrom(from, to, tokens);
}
// BK Next function Ok
function approveAndCall(address spender, uint tokens, bytes _data) public returns (bool success) {
success = data.approveAndCall(this, spender, tokens, _data);
}

// ------------------------------------------------------------------------
// Signed function
// ------------------------------------------------------------------------
// BK Next function Ok
function signedTransferHash(address tokenOwner, address to, uint tokens, uint fee, uint nonce) public view returns (bytes32 hash) {
return data.signedTransferHash(address(this), tokenOwner, to, tokens, fee, nonce);
}
// BK Next function Ok
function signedTransferCheck(address tokenOwner, address to, uint tokens, uint fee, uint nonce, bytes sig, address feeAccount) public view returns (CheckResult result) {
return data.signedTransferCheck(address(this), tokenOwner, to, tokens, fee, nonce, sig, feeAccount);
}
// BK Next function Ok
function signedTransfer(address tokenOwner, address to, uint tokens, uint fee, uint nonce, bytes sig, address feeAccount) public returns (bool success) {
return data.signedTransfer(address(this), tokenOwner, to, tokens, fee, nonce, sig, feeAccount);
}
// BK Next function Ok
function signedApproveHash(address tokenOwner, address spender, uint tokens, uint fee, uint nonce) public view returns (bytes32 hash) {
return data.signedApproveHash(address(this), tokenOwner, spender, tokens, fee, nonce);
}
// BK Next function Ok
function signedApproveCheck(address tokenOwner, address spender, uint tokens, uint fee, uint nonce, bytes sig, address feeAccount) public view returns (CheckResult result) {
return data.signedApproveCheck(address(this), tokenOwner, spender, tokens, fee, nonce, sig, feeAccount);
}
// BK Next function Ok
function signedApprove(address tokenOwner, address spender, uint tokens, uint fee, uint nonce, bytes sig, address feeAccount) public returns (bool success) {
return data.signedApprove(address(this), tokenOwner, spender, tokens, fee, nonce, sig, feeAccount);
}
// BK Next function Ok
function signedTransferFromHash(address spender, address from, address to, uint tokens, uint fee, uint nonce) public view returns (bytes32 hash) {
return data.signedTransferFromHash(address(this), spender, from, to, tokens, fee, nonce);
}
// BK Next function Ok
function signedTransferFromCheck(address spender, address from, address to, uint tokens, uint fee, uint nonce, bytes sig, address feeAccount) public view returns (CheckResult result) {
return data.signedTransferFromCheck(address(this), spender, from, to, tokens, fee, nonce, sig, feeAccount);
}
// BK Next function Ok
function signedTransferFrom(address spender, address from, address to, uint tokens, uint fee, uint nonce, bytes sig, address feeAccount) public returns (bool success) {
return data.signedTransferFrom(address(this), spender, from, to, tokens, fee, nonce, sig, feeAccount);
}
// BK Next function Ok
function signedApproveAndCallHash(address tokenOwner, address spender, uint tokens, bytes _data, uint fee, uint nonce) public view returns (bytes32 hash) {
return data.signedApproveAndCallHash(address(this), tokenOwner, spender, tokens, _data, fee, nonce);
}
// BK Next function Ok
function signedApproveAndCallCheck(address tokenOwner, address spender, uint tokens, bytes _data, uint fee, uint nonce, bytes sig, address feeAccount) public view returns (CheckResult result) {
return data.signedApproveAndCallCheck(address(this), tokenOwner, spender, tokens, _data, fee, nonce, sig, feeAccount);
}
// BK Next function Ok
function signedApproveAndCall(address tokenOwner, address spender, uint tokens, bytes _data, uint fee, uint nonce, bytes sig, address feeAccount) public returns (bool success) {
return data.signedApproveAndCall(address(this), tokenOwner, spender, tokens, _data, fee, nonce, sig, feeAccount);
}
Expand Down

0 comments on commit 715369e

Please sign in to comment.