From a9c54f50b97a188f24cd1249a0cc047ad8344539 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Tue, 31 Jul 2018 20:38:43 -0400 Subject: [PATCH] Finally running plasma_cash with Embark --- .gitignore | 1 + config/contracts.json | 44 +++++++++++++++----------------- contracts/plasma/Cards.sol | 40 +++++++++++++++++++++++++++++ plasma_cash/README.md | 34 ++++++++++++++++++++++++ plasma_cash/config.py | 6 +++-- plasma_cash/dependency_config.py | 2 +- 6 files changed, 101 insertions(+), 26 deletions(-) create mode 100644 contracts/plasma/Cards.sol diff --git a/.gitignore b/.gitignore index 5c20c22..b0b7be0 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ dist/ # pyenv .python-version +erc721plasma/ # dotenv .env diff --git a/config/contracts.json b/config/contracts.json index 01d0db3..98136cd 100644 --- a/config/contracts.json +++ b/config/contracts.json @@ -26,12 +26,25 @@ "DelegationProxyKernel": { "deploy": false }, "ProposalCuration": { "deploy": false }, "Democracy": { "deploy": false }, - "TestToken": { + "TestToken": { "deploy": false }, + "AddressUtils": { "deploy": false }, + "PollManager": { "deploy": false }, + "ERC721BasicToken": { "deploy": false }, + "ERC721Token": { "deploy": false }, + "RLP": { "deploy": false }, + "SparseMerkleTree": { "deploy": false }, + "ECVerify": { "deploy": false }, + "Transaction": { "deploy": false }, + "ValidatorManagerContract": {}, + "RootChain": { + "args": ["$ValidatorManagerContract"] + }, + "CryptoCards":{ + "args": ["$RootChain"] }, "MiniMeTokenFactory": { }, - "PollManager": { "deploy": false }, "SNT": { "instanceOf": "MiniMeToken", "args": [ @@ -44,31 +57,16 @@ true ] }, - - - - "AddressUtils": { "deploy": false }, - "SupportsInterfaceWithLookup": { "deploy": false }, - "ERC721BasicToken": { "deploy": false }, - "ERC721Token": { "deploy": false }, - "RLP": { "deploy": false }, - "SparseMerkleTree": { "deploy": false }, - "ECVerify": { "deploy": false }, - "Transaction": { "deploy": false }, - "ValidatorManagerContract": {}, - "RootChain": { - "args": ["$ValidatorManagerContract"] - }, "PlasmaERC20":{ "deploy": false }, "PlasmaSNT": { "instanceOf": "PlasmaERC20", - "args": ["$RootChain", "$SNT", "PlasmaSNT", "PSNT"], - "onDeploy": [ - "ValidatorManagerContract.methods.toggleToken($PlasmaSNT).send()", - "PlasmaSNT.methods.setExchangeRate(0, 5000000000000000000).send()" - ] + "args": ["$RootChain", "$SNT", "PlasmaSNT", "PSNT"] } - } + }, + "afterDeploy": [ + "ValidatorManagerContract.methods.toggleToken('$CryptoCards').send()", + "PlasmaSNT.methods.setExchangeRate(0, 5000000000000000000).send()" + ] }, diff --git a/contracts/plasma/Cards.sol b/contracts/plasma/Cards.sol new file mode 100644 index 0000000..5769f03 --- /dev/null +++ b/contracts/plasma/Cards.sol @@ -0,0 +1,40 @@ +pragma solidity ^0.4.24; + +import "openzeppelin-solidity/contracts/token/ERC721/ERC721Token.sol"; + + +contract CryptoCards is ERC721Token("CryptoCards", "CCC") { + + address plasma; + + constructor (address _plasma) public { + plasma = _plasma; + } + + function register() external { + // Give each new player 5 cards + for (int j = 0; j < 5; j++) { + create(); + } + } + + function depositToPlasmaWithData(uint tokenId, bytes _data) public { + require(plasma != address(0)); + safeTransferFrom( + msg.sender, + plasma, + tokenId, + _data); + } + + function depositToPlasma(uint tokenId) public { + require(plasma != address(0)); + safeTransferFrom(msg.sender, plasma, tokenId); + } + + function create() private { + uint256 tokenId = allTokens.length + 1; + _mint(msg.sender, tokenId); + } + +} diff --git a/plasma_cash/README.md b/plasma_cash/README.md index adf02ec..ee1de4b 100644 --- a/plasma_cash/README.md +++ b/plasma_cash/README.md @@ -1,3 +1,37 @@ + +# @rramos notes +I configured the project to run with Embark (Only demo.py was tested). To run this project in Ubuntu, the following steps need to be executed + +1. `npm install` +2. Open at least 4 terminals (you can use `tmux` for this) +3. In Terminal-1, execute `embark simulator` +4. In Terminal-2, execute `embark run` +5. In Terminal-3: +``` +cd plasma_cash +virtualenv erc721plasma -p python3.6 +source erc721plasma/bin/activate +pip install -r requirements.txt +FLASK_APP=./child_chain FLASK_ENV=development flask run --port=8546 +``` +6. In Terminal-4: +``` +cd plasma_cash +source erc721plasma/bin/activate +python demo.py +``` + + Most of the previous instructions are covered here, I just wrote them here for quick reference. + +If installing the server from scratch: + 1. Install Nodejs with `nvm` + 2. Follow the instructions from Embark for its installation, + 3. `sudo apt install virtualenv python3 python3-dev libssl-dev build-essential` + + _NOTE_: `nvm` and Embark must be installed with a normal user. Don't use `root`! + + + # Development Dependencies A patched version of web3.py is used because otherwise it does not work with Ganache due to issue #674. In addition, in order to be able to monitor events, PR #827, which is not merged yet. Pyethereum dependencies broke recently so we need to manually install a slightly older version of rlp encoding. Flask is used for server purposes. diff --git a/plasma_cash/config.py b/plasma_cash/config.py index 4e85e89..b7150cf 100644 --- a/plasma_cash/config.py +++ b/plasma_cash/config.py @@ -1,7 +1,8 @@ plasma_config = dict( - validator_manager='0x494748735312D87C54Ff36E9dc71f90fb800D7Df', - root_chain='0xe5731c3df7a510fba6c5b2766251ce631C6B1d78', + validator_manager='0xd8a512EBD6fd82f44dFFD968EEB0835265497d20', + root_chain='0x494748735312D87C54Ff36E9dc71f90fb800D7Df', token_contract='0x6427A6200Bed37FC1e512BdeA49D25Aa9089CF47', + authority='0xf942d5d524ec07158df4354402bfba8d928c99d0ab34d0799a6158d56156d986', alice='0x88f37cfbaed8c0c515c62a17a3a1ce2f397d08bbf20dcc788b69f11b5a5c9791', bob='0xf4ebc8adae40bfc741b0982c206061878bffed3ad1f34d67c94fa32c3d33eac8', @@ -10,6 +11,7 @@ plasma_config = dict( mallory='0x130137aa9a7fbc7cadc98c079cda47a999ff41931d9feaab621855beceed71f7', eve='0xead83d04f741d2b3ab50be1299c18aa1a82c241606861a9a6d3122443496522d', trudy='0xe6e893ac9f1c1db066a8a83a376554084b0a786e4cdcd91559d68bd4a1dac396', + players=[ '0x56901d80abc6953d1dc01de2f077b75260f49a3304f665b57ed13514a7e2a2bc', '0xedc63d0e14b29aaa26c7585e962f93abb59bd7d8b01b585e073dc03d052a000b', diff --git a/plasma_cash/dependency_config.py b/plasma_cash/dependency_config.py index dc1998c..490963d 100644 --- a/plasma_cash/dependency_config.py +++ b/plasma_cash/dependency_config.py @@ -8,7 +8,7 @@ class DependencyContainer(object): def __init__(self): self._child_chain = None self.root_chain_abi = '../dist/contracts/RootChain.json' - self.token_contract_abi = '../dist/contracts/PlasmaERC20.json' + self.token_contract_abi = '../dist/contracts/CryptoCards.json' self.endpoint = 'http://localhost:8545' self.root_chain = PlasmaCash( plasma_config['authority'],