Skip to content

Commit

Permalink
added some basic functionality to Ownable contract
Browse files Browse the repository at this point in the history
  • Loading branch information
jensendarren committed Jun 16, 2020
1 parent 2711433 commit b6c570b
Show file tree
Hide file tree
Showing 9 changed files with 3,447 additions and 129 deletions.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
eth-contracts/build

node_modules

zokrates/code/square/proof.json
zokrates/code/square/out
zokrates/code/square/out.code
zokrates/code/square/proving.key
zokrates/code/square/verification.key
zokrates/code/square/witness

.secret

TODO.txt
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ This project uses ZoKrates for implementing zkSNARKS. To run ZoKrates in a Docke
docker run -v $(pwd)/zokrates/code:/home/zokrates/code -ti zokrates/zokrates:0.4.6 /bin/bash
```

In the running container bash session run the following to confirm ZoKrates is configured correctly:

```
~/zokrates compile -i ./code/zokrates/code/square/
~/zokrates setup
~/zokrates compute-witness -a 2 4
~/zokrates generate-proof
~/zokrates export-verifier
```

# Project Resources

* [Remix - Solidity IDE](https://remix.ethereum.org/)
Expand Down
39 changes: 24 additions & 15 deletions eth-contracts/contracts/ERC721Mintable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,35 @@ import 'openzeppelin-solidity/contracts/token/ERC721/IERC721Receiver.sol';
import "./Oraclize.sol";

contract Ownable {
// TODO's
// 1) create a private '_owner' variable of type address with a public getter function
// 2) create an internal constructor that sets the _owner var to the creater of the contract
// 3) create an 'onlyOwner' modifier that throws if called by any account other than the owner.
// 4) fill out the transferOwnership function
address private _owner;
constructor() internal {
_owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == _owner, 'Caller is not the contract owner.');
_;
}
// 5) create an event that emits anytime ownerShip is transfered (including in the constructor)
event ContractOwnershipTransferEvent(address newOwner);

function transferOwnership(address newOwner) public onlyOwner {
// TODO add functionality to transfer control of the contract to a newOwner.
// make sure the new owner is a real address

require(address(newOwner) != address(0x0), 'New owner must be a valid address');
_owner = newOwner;
emit ContractOwnershipTransferEvent(newOwner);
}
}

// TODO's: Create a Pausable contract that inherits from the Ownable contract
// 1) create a private '_paused' variable of type bool
// 2) create a public setter using the inherited onlyOwner modifier
// 2) create a public setter using the inherited onlyOwner modifier
// 3) create an internal constructor that sets the _paused variable to false
// 4) create 'whenNotPaused' & 'paused' modifier that throws in the appropriate situation
// 5) create a Paused & Unpaused event that emits the address that triggered the event

contract Pausable is Ownable {

}

contract ERC165 {
bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;
/*
Expand Down Expand Up @@ -71,7 +79,7 @@ contract ERC721 is Pausable, ERC165 {
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

using SafeMath for uint256;
using Address for address;
using Counters for Counters.Counter;
Expand Down Expand Up @@ -113,7 +121,7 @@ contract ERC721 is Pausable, ERC165 {

// @dev Approves another address to transfer the given token ID
function approve(address to, uint256 tokenId) public {

// TODO require the given address to not be the owner of the tokenId

// TODO require the msg sender to be the owner of the contract or isApprovedForAll() to be true
Expand Down Expand Up @@ -192,7 +200,7 @@ contract ERC721 is Pausable, ERC165 {
function _mint(address to, uint256 tokenId) internal {

// TODO revert if given tokenId already exists or given address is invalid

// TODO mint tokenId to given address & increase token count of owner

// TODO emit Transfer event
Expand All @@ -205,10 +213,10 @@ contract ERC721 is Pausable, ERC165 {
// TODO: require from address is the owner of the given token

// TODO: require token is being transfered to valid address

// TODO: clear approval

// TODO: update token counts & transfer ownership of the token ID
// TODO: update token counts & transfer ownership of the token ID

// TODO: emit correct event
}
Expand Down Expand Up @@ -414,10 +422,11 @@ contract ERC721Enumerable is ERC165, ERC721 {
}

contract ERC721Metadata is ERC721Enumerable, usingOraclize {

// TODO: Create private vars for token _name, _symbol, and _baseTokenURI (string)

// TODO: create private mapping of tokenId's to token uri's called '_tokenURIs'
mapping(uint256 => string) private _tokenURIs;

bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f;
/*
Expand Down
29 changes: 7 additions & 22 deletions eth-contracts/test/TestERC721Mintable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,27 @@ contract('TestERC721Mintable', accounts => {
const account_two = accounts[1];

describe('match erc721 spec', function () {
beforeEach(async function () {
beforeEach(async function () {
this.contract = await ERC721MintableComplete.new({from: account_one});

// TODO: mint multiple tokens
})

it('should return total supply', async function () {

})
it('should return total supply', async function () {

it('should get token balance', async function () {

})

// token uri should be complete i.e: https://s3-us-west-2.amazonaws.com/udacity-blockchain/capstone/1
it('should return token uri', async function () {

})
it('should get token balance', async function () {

it('should transfer token from one owner to another', async function () {

})
});

describe('have ownership properties', function () {
beforeEach(async function () {
this.contract = await ERC721MintableComplete.new({from: account_one});
})
// token uri should be complete i.e: https://s3-us-west-2.amazonaws.com/udacity-blockchain/capstone/1
it('should return token uri', async function () {

it('should fail when minting when address is not contract owner', async function () {

})

it('should return contract owner', async function () {

})
it('should transfer token from one owner to another', async function () {

})
});
})
22 changes: 22 additions & 0 deletions eth-contracts/test/ownableSpecs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var ERC721MintableComplete = artifacts.require('ERC721MintableComplete');

contract('TestERC721Mintable', accounts => {

const account_one = accounts[0];
const account_two = accounts[1];

describe('have ownership properties', function () {
beforeEach(async function () {
this.contract = await ERC721MintableComplete.new({from: account_one});
})

it.only('should return contract owner', async function () {

})

it('should fail when minting when address is not contract owner', async function () {

})

});
})
Loading

0 comments on commit b6c570b

Please sign in to comment.