diff --git a/README.md b/README.md index cafe475..21889da 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,18 @@ +# ZSL on Quorum Example + +This repository contains a modified 7nodes example to demonstrate [ZSL on Quroum](https://github.com/jpmorganchase/zsl-q/blob/master/README.md) + +The following changes have been made: + +* ZSL precompiles added to `genesis.json` between address 0x8801 - 0x8804 +* Node 2 is unlocked in `raft-start.sh` +* Symbolic links added for accessing ZSL parameters (proving and verification keys) when the example is run inside Vagrant. These symbolic links can be replaced with actual parameter files if running from the local host machine, and not inside Vagrant. +* New file `tracker.js` contains note tracking and other helper functions. + +There are examples of using ZSL on 7nodes documented in [ZSL on Quorum](https://github.com/jpmorganchase/zsl-q/tree/master/README.md) + +Original README follows. + # Quorum Examples This repository contains setup examples for Quorum. diff --git a/Vagrantfile b/Vagrantfile index 89c7c4c..13cc0b3 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -9,6 +9,6 @@ Vagrant.configure(2) do |config| config.vm.network "forwarded_port", guest: 22005, host: 22005 config.vm.network "forwarded_port", guest: 22006, host: 22006 config.vm.provider "virtualbox" do |v| - v.memory = 4096 + v.memory = 16384 end end diff --git a/examples/7nodes/genesis.json b/examples/7nodes/genesis.json index 925d615..30c98ec 100644 --- a/examples/7nodes/genesis.json +++ b/examples/7nodes/genesis.json @@ -1,5 +1,21 @@ { "alloc": { + "0x0000000000000000000000000000000000008801": { + "balance": "1000000000000000000000000000", + "code": "0x00" + }, + "0x0000000000000000000000000000000000008802": { + "balance": "1000000000000000000000000000", + "code": "0x00" + }, + "0x0000000000000000000000000000000000008803": { + "balance": "1000000000000000000000000000", + "code": "0x00" + }, + "0x0000000000000000000000000000000000008804": { + "balance": "1000000000000000000000000000", + "code": "0x00" + }, "0x0000000000000000000000000000000000000020": { "code": "0x606060405236156100c45760e060020a60003504631290948581146100c9578063284d163c146100f957806342169e4814610130578063488099a6146101395780634fe437d514610154578063559c390c1461015d57806368bb8bb61461025d57806372a571fc146102c857806386c1ff681461036957806398ba676d146103a0578063a7771ee31461040b578063adfaa72e14610433578063cf5289851461044e578063de8fa43114610457578063e814d1c71461046d578063f4ab9adf14610494575b610002565b610548600435600160a060020a03331660009081526003602052604090205460ff16156100c45760018190555b50565b610548600435600160a060020a03331660009081526005602052604090205460ff16156100c4576004546001141561055e57610002565b61045b60025481565b61054a60043560056020526000908152604090205460ff1681565b61045b60015481565b61045b60043560006000600060006000600050600186038154811015610002579080526002027f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5630192505b60018301548110156105d75760018301805484916000918490811015610002576000918252602080832090910154835282810193909352604091820181205485825292869052205410801561023257506001805490840180548591600091859081101561000257906000526020600020900160005054815260208101919091526040016000205410155b156102555760018301805482908110156100025760009182526020909120015491505b6001016101a8565b610548600435602435600160a060020a03331660009081526003602052604081205460ff16156100c4578054839010156105e45780548084038101808355908290829080158290116105df576002028160020283600052602060002091820191016105df919061066b565b610548600435600160a060020a03331660009081526005602052604090205460ff16156100c457600160a060020a0381166000908152604090205460ff1615156100f65760406000819020805460ff191660019081179091556004805490910190558051600160a060020a038316815290517f1a4ce6942f7aa91856332e618fc90159f13a340611a308f5d7327ba0707e56859181900360200190a16100f6565b610548600435600160a060020a03331660009081526003602052604090205460ff16156100c4576002546001141561071457610002565b61045b600435602435600060006000600050600185038154811015610002579080526002027f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5630181509050806001016000508381548110156100025750825250602090200154919050565b61054a600435600160a060020a03811660009081526003602052604090205460ff165b919050565b61054a60043560036020526000908152604090205460ff1681565b61045b60045481565b6000545b60408051918252519081900360200190f35b61054a600435600160a060020a03811660009081526005602052604090205460ff1661042e565b610548600435600160a060020a03331660009081526003602052604090205460ff16156100c457600160a060020a03811660009081526003602052604090205460ff1615156100f65760406000818120600160a060020a0384169182905260036020908152815460ff1916600190811790925560028054909201909155825191825291517f0ad2eca75347acd5160276fe4b5dad46987e4ff4af9e574195e3e9bc15d7e0ff929181900390910190a16100f6565b005b604080519115158252519081900360200190f35b600160a060020a03811660009081526005602052604090205460ff16156100f65760406000819020805460ff19169055600480546000190190558051600160a060020a038316815290517f8cee3054364d6799f1c8962580ad61273d9d38ca1ff26516bd1ad23c099a60229181900360200190a16100f6565b509392505050565b505050505b60008054600019850190811015610002578382526002027f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563016020819052604082205490925014156106b8578060010160005080548060010182818154818355818115116106a5578183600052602060002091820191016106a5919061068d565b50506002015b808211156106a157600181018054600080835591825260208220610665918101905b808211156106a1576000815560010161068d565b5090565b5050506000928352506020909120018290555b600082815260208281526040918290208054600101905581514381529081018490528151600160a060020a033316927f3d03ba7f4b5227cdb385f2610906e5bcee147171603ec40005b30915ad20e258928290030190a2505050565b600160a060020a03811660009081526003602052604090205460ff16156100f65760406000819020805460ff19169055600280546000190190558051600160a060020a038316815290517f183393fc5cffbfc7d03d623966b85f76b9430f42d3aada2ac3f3deabc78899e89181900360200190a16100f656", "storage": { diff --git a/examples/7nodes/raft-start.sh b/examples/7nodes/raft-start.sh index 0785203..ac66c2c 100755 --- a/examples/7nodes/raft-start.sh +++ b/examples/7nodes/raft-start.sh @@ -20,7 +20,7 @@ echo "[*] Starting node 1" PRIVATE_CONFIG=tm1.conf nohup geth --datadir qdata/dd1 $GLOBAL_ARGS --raftport 50401 --rpcport 22000 --port 21000 --unlock 0 --password passwords.txt 2>>qdata/logs/1.log & echo "[*] Starting node 2" -PRIVATE_CONFIG=tm2.conf nohup geth --datadir qdata/dd2 $GLOBAL_ARGS --raftport 50402 --rpcport 22001 --port 21001 2>>qdata/logs/2.log & +PRIVATE_CONFIG=tm2.conf nohup geth --datadir qdata/dd2 $GLOBAL_ARGS --raftport 50402 --rpcport 22001 --port 21001 --unlock 0 --password passwords.txt 2>>qdata/logs/2.log & echo "[*] Starting node 3" PRIVATE_CONFIG=tm3.conf nohup geth --datadir qdata/dd3 $GLOBAL_ARGS --raftport 50403 --rpcport 22002 --port 21002 2>>qdata/logs/3.log & diff --git a/examples/7nodes/shielding.pk b/examples/7nodes/shielding.pk new file mode 120000 index 0000000..ddf9b76 --- /dev/null +++ b/examples/7nodes/shielding.pk @@ -0,0 +1 @@ +/vagrant/shielding.pk \ No newline at end of file diff --git a/examples/7nodes/shielding.vk b/examples/7nodes/shielding.vk new file mode 120000 index 0000000..56582f4 --- /dev/null +++ b/examples/7nodes/shielding.vk @@ -0,0 +1 @@ +/vagrant/shielding.vk \ No newline at end of file diff --git a/examples/7nodes/transfer.pk b/examples/7nodes/transfer.pk new file mode 120000 index 0000000..97c456c --- /dev/null +++ b/examples/7nodes/transfer.pk @@ -0,0 +1 @@ +/vagrant/transfer.pk \ No newline at end of file diff --git a/examples/7nodes/transfer.vk b/examples/7nodes/transfer.vk new file mode 120000 index 0000000..1962f0b --- /dev/null +++ b/examples/7nodes/transfer.vk @@ -0,0 +1 @@ +/vagrant/transfer.vk \ No newline at end of file diff --git a/examples/7nodes/unshielding.pk b/examples/7nodes/unshielding.pk new file mode 120000 index 0000000..6fc3a17 --- /dev/null +++ b/examples/7nodes/unshielding.pk @@ -0,0 +1 @@ +/vagrant/unshielding.pk \ No newline at end of file diff --git a/examples/7nodes/unshielding.vk b/examples/7nodes/unshielding.vk new file mode 120000 index 0000000..cdf7505 --- /dev/null +++ b/examples/7nodes/unshielding.vk @@ -0,0 +1 @@ +/vagrant/unshielding.vk \ No newline at end of file diff --git a/examples/7nodes/zdemo.js b/examples/7nodes/zdemo.js new file mode 100644 index 0000000..459eba4 --- /dev/null +++ b/examples/7nodes/zdemo.js @@ -0,0 +1,5 @@ +var alice = "0xed9d02e382b34818e88b88a309c7fe71e65f419d"; +var bob = "0xca843569e3427144cead5e4d5999a3d0ccf92b8e"; +var alice_constellation = "BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo="; +var bob_constellation = "QfeDAys9MPDs2XHExtc84jKGHxZg/aj52DTh0vtA3Xc="; +loadScript("ztracker.js"); diff --git a/examples/7nodes/ztracker.js b/examples/7nodes/ztracker.js new file mode 100644 index 0000000..163d25e --- /dev/null +++ b/examples/7nodes/ztracker.js @@ -0,0 +1,466 @@ +// Copyright 2017 Zerocoin Electric Coin Company LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// ================================= +// START: Web3 deploy code +// ================================= + +var ztoken_abi = web3.eth.contract([{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"type":"function","payable":true},{"constant":false,"inputs":[{"name":"v","type":"uint256"},{"name":"n","type":"uint256"}],"name":"rightShift","outputs":[{"name":"","type":"uint256"}],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"type":"function","payable":true},{"constant":true,"inputs":[{"name":"left","type":"bytes32"},{"name":"right","type":"bytes32"}],"name":"combine","outputs":[{"name":"","type":"bytes32"}],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"shieldedTxCapacity","outputs":[{"name":"","type":"uint256"}],"type":"function","payable":true},{"constant":false,"inputs":[{"name":"target","type":"address"},{"name":"amount","type":"uint256"}],"name":"mint","outputs":[],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"shieldedTransferCount","outputs":[{"name":"","type":"uint256"}],"type":"function","payable":true},{"constant":true,"inputs":[{"name":"cm","type":"bytes32"}],"name":"getWitness","outputs":[{"name":"","type":"uint256"},{"name":"","type":"bytes32[]"}],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"available","outputs":[{"name":"","type":"uint256"}],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"unshieldingCount","outputs":[{"name":"","type":"uint256"}],"type":"function","payable":true},{"constant":false,"inputs":[{"name":"proof","type":"bytes"},{"name":"send_nf","type":"bytes32"},{"name":"cm","type":"bytes32"},{"name":"value","type":"uint64"}],"name":"shield","outputs":[],"type":"function","payable":true},{"constant":false,"inputs":[{"name":"v","type":"uint256"},{"name":"n","type":"uint256"}],"name":"leftShift","outputs":[{"name":"","type":"uint256"}],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"capacity","outputs":[{"name":"","type":"uint256"}],"type":"function","payable":true},{"constant":false,"inputs":[{"name":"proof","type":"bytes"},{"name":"anchor","type":"bytes32"},{"name":"spend_nf_1","type":"bytes32"},{"name":"spend_nf_2","type":"bytes32"},{"name":"send_nf_1","type":"bytes32"},{"name":"send_nf_2","type":"bytes32"},{"name":"cm_1","type":"bytes32"},{"name":"cm_2","type":"bytes32"}],"name":"shieldedTransfer","outputs":[],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"shieldedTxAvailable","outputs":[{"name":"","type":"uint256"}],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"depth","outputs":[{"name":"","type":"uint256"}],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"getEmptyRoots","outputs":[{"name":"","type":"bytes32[]"}],"type":"function","payable":true},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"shieldingCount","outputs":[{"name":"","type":"uint256"}],"type":"function","payable":true},{"constant":false,"inputs":[{"name":"proof","type":"bytes"},{"name":"spend_nf","type":"bytes32"},{"name":"cm","type":"bytes32"},{"name":"rt","type":"bytes32"},{"name":"value","type":"uint64"}],"name":"unshield","outputs":[],"type":"function","payable":true},{"constant":true,"inputs":[{"name":"cm","type":"bytes32"}],"name":"commitmentExists","outputs":[{"name":"","type":"bool"}],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"size","outputs":[{"name":"","type":"uint256"}],"type":"function","payable":true},{"constant":false,"inputs":[{"name":"cm","type":"bytes32"}],"name":"addCommitment","outputs":[],"type":"function","payable":true},{"constant":true,"inputs":[{"name":"depth","type":"uint256"}],"name":"getEmptyRoot","outputs":[{"name":"","type":"bytes32"}],"type":"function","payable":true},{"constant":false,"inputs":[{"name":"recipient","type":"address"},{"name":"value","type":"uint256"}],"name":"transfer","outputs":[],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"balance","outputs":[{"name":"","type":"uint256"}],"type":"function","payable":true},{"constant":true,"inputs":[{"name":"cm","type":"bytes32"}],"name":"getLeafIndex","outputs":[{"name":"","type":"uint256"}],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"ZTOKEN_TREE_DEPTH","outputs":[{"name":"","type":"uint256"}],"type":"function","payable":true},{"constant":true,"inputs":[{"name":"index","type":"uint256"}],"name":"getCommitmentAtLeafIndex","outputs":[{"name":"","type":"bytes32"}],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"root","outputs":[{"name":"","type":"bytes32"}],"type":"function","payable":true},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"type":"function","payable":true},{"inputs":[{"name":"initialSupply","type":"uint256"},{"name":"tokenName","type":"string"}],"type":"constructor","payable":true},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"LogTransfer","type":"event","payable":true},{"anonymous":false,"inputs":[{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"LogMint","type":"event","payable":true},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":false,"name":"value","type":"uint256"},{"indexed":false,"name":"uuid","type":"bytes32"}],"name":"LogShielding","type":"event","payable":true},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":false,"name":"value","type":"uint256"},{"indexed":false,"name":"uuid","type":"bytes32"}],"name":"LogUnshielding","type":"event","payable":true},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":false,"name":"uuid_1","type":"bytes32"},{"indexed":false,"name":"uuid_2","type":"bytes32"}],"name":"LogShieldedTransfer","type":"event","payable":true},{"type":"fallback","payable":true}]); + +var zprivatecontract_abi = web3.eth.contract([{"constant":true,"inputs":[],"name":"paymentReceivedByAsker","outputs":[{"name":"","type":"bytes32"}],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"bidderConstellationAddress","outputs":[{"name":"","type":"string"}],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"randomness","outputs":[{"name":"","type":"bytes32"}],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"paymentReceivedByBidder","outputs":[{"name":"","type":"bytes32"}],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"bidderApk","outputs":[{"name":"","type":"bytes32"}],"type":"function","payable":true},{"constant":false,"inputs":[{"name":"rho","type":"bytes32"}],"name":"submitPaymentDetails","outputs":[],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"askAmount","outputs":[{"name":"","type":"uint64"}],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"type":"function","payable":true},{"constant":false,"inputs":[{"name":"apk","type":"bytes32"},{"name":"r","type":"bytes32"}],"name":"acceptBid","outputs":[{"name":"result","type":"bool"}],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"bidAmount","outputs":[{"name":"","type":"uint64"}],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"state","outputs":[{"name":"","type":"uint8"}],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"asker","outputs":[{"name":"","type":"address"}],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"askerConstellationAddress","outputs":[{"name":"","type":"string"}],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"bidTokenAddress","outputs":[{"name":"","type":"address"}],"type":"function","payable":true},{"constant":false,"inputs":[{"name":"rho","type":"bytes32"}],"name":"submitSettlementDetails","outputs":[],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"askerApk","outputs":[{"name":"","type":"bytes32"}],"type":"function","payable":true},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"bidder","outputs":[{"name":"","type":"address"}],"type":"function","payable":true},{"constant":true,"inputs":[],"name":"askTokenAddress","outputs":[{"name":"","type":"address"}],"type":"function","payable":true},{"inputs":[{"name":"apk","type":"bytes32"},{"name":"r","type":"bytes32"},{"name":"bid_constellation","type":"string"},{"name":"bid_address","type":"address"},{"name":"bid_amount","type":"uint64"},{"name":"ask_constellation","type":"string"},{"name":"ask_address","type":"address"},{"name":"ask_amount","type":"uint64"}],"type":"constructor","payable":true},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"},{"indexed":false,"name":"_amount","type":"uint256"}],"name":"LogBidEvent","type":"event","payable":true},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"}],"name":"LogDoneEvent","type":"event","payable":true},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"}],"name":"LogPaymentEvent","type":"event","payable":true},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"}],"name":"LogSettlementEvent","type":"event","payable":true},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"}],"name":"LogPaymentFailedEvent","type":"event","payable":true},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"}],"name":"LogSettlementFailedEvent","type":"event","payable":true},{"type":"fallback","payable":true}]); + +// ================================= +// END: Web3 deploy code +// ================================= + +function _zdemo_create_ztoken(tokenName, initialSupply) { + // ================================= + // START: Web3 deploy code + // ================================= + var ztoken = ztoken_abi.new( + initialSupply, + tokenName, + { + from: web3.eth.accounts[0], + data: '0x60606040526000600560005055604051613556380380613556833981016040528080519060200190919080518201919060200150505b601d5b5b33600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908302179055505b60405161093f806105bd833901809050604051809103906000f0600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff02191690830217905550806002600050819055508060020a6003600050819055506100c981610258565b5b5081600a60005060003373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005081905550816009600050819055508060086000509080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015857805160ff1916838001178555610189565b82800160010185558215610189579182015b8281111561018857825182600050559160200191906001019061016a565b5b5090506101b49190610196565b808211156101b05760008181506000905550600101610196565b5090565b505060405161093f80610efc833901809050604051809103906000f0600e60006101000a81548173ffffffffffffffffffffffffffffffffffffffff02191690830217905550600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16600f60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908302179055505b5050611d1b8061183b6000396000f35b6000600060006001029150600460005080548060010182818154818355818115116102b5578183600052602060002091820191016102b49190610296565b808211156102b05760008181506000905550600101610296565b5090565b5b5050509190906000526020600020900160005b8490919091505550600090505b60018303811015610369576102ea828361036f565b91508150600460005080548060010182818154818355818115116103405781836000526020600020918201910161033f9190610321565b8082111561033b5760008181506000905550600101610321565b5090565b5b5050509190906000526020600020900160005b84909190915055505b80806001019150506102d5565b5b505050565b60006020604051908101604052806000815260200150600060406040518059106103965750595b9080825280602002602001820160405280156103ad575b5091506000905080505b60208110156104375784816020811015610002571a7f01000000000000000000000000000000000000000000000000000000000000000282828151811015610002579060200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053505b80806001019150506103b7565b6000905080505b60208110156104c15783816020811015610002571a7f01000000000000000000000000000000000000000000000000000000000000000282602083018151811015610002579060200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053505b808060010191505061043e565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16633319f70b83604051827c010000000000000000000000000000000000000000000000000000000002815260040180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600302600f01f150905090810190601f1680156105855780820380516001836020036101000a031916815260200191505b50925050506020604051808303816000876161da5a03f115610002575050506040518051906020015092506105b5565b5050929150505660606040525b618801600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff02191690830217905550618802600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff02191690830217905550618803600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff02191690830217905550618804600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908302179055505b610877806100c86000396000f36060604052361561005e576000357c0100000000000000000000000000000000000000000000000000000000900480633319f70b1461006f578063794f69e3146100aa578063dafca47a14610122578063e088659e146101765761005e565b61006d5b61006a6101ca565b5b565b005b610090600480803590602001908201803590602001919091929050506101d1565b604051808260001916815260200191505060405180910390f35b61010a6004808035906020019082018035906020019190919290803590602001909190803590602001909190803590602001909190803590602001909190803590602001909190803590602001909190803590602001909190505061029e565b60405180821515815260200191505060405180910390f35b61015e600480803590602001908201803590602001919091929080359060200190919080359060200190919080359060200190919050506104a5565b60405180821515815260200191505060405180910390f35b6101b26004808035906020019082018035906020019190919290803590602001909190803590602001909190803590602001909190505061067e565b60405180821515815260200191505060405180910390f35b610002565b565b60006101e260408484905014610857565b600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16633a2765238484604051837c010000000000000000000000000000000000000000000000000000000002815260040180806020018281038252848482818152602001925080828437820191505093505050506020604051808303816000876161da5a03f11561000257505050604051805190602001509050610298565b92915050565b600060006000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16635286a75b8d8d8d8d8d8d8d8d8d6040518a7c010000000000000000000000000000000000000000000000000000000002815260040180806020018960001916815260200188600019168152602001876000191681526020018660001916815260200185600019168152602001846000191681526020018360001916815260200182810382528b8b8281815260200192508082843782019150509a50505050505050505050506020604051808303816000876161da5a03f115610002575050506040518051906020015091508160006020811015610002571a7f010000000000000000000000000000000000000000000000000000000000000002905060007f010000000000000000000000000000000000000000000000000000000000000002817effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916141561043457600092506104965661048b565b60017f010000000000000000000000000000000000000000000000000000000000000002817effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916141561048a5760019250610496565b5b6104956000610867565b5b50509998505050505050505050565b600060006000600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16634e3202638989898989604051867c0100000000000000000000000000000000000000000000000000000000028152600401808060200185600019168152602001846000191681526020018367ffffffffffffffff1681526020018281038252878782818152602001925080828437820191505096505050505050506020604051808303816000876161da5a03f115610002575050506040518051906020015091508160006020811015610002571a7f010000000000000000000000000000000000000000000000000000000000000002905060007f010000000000000000000000000000000000000000000000000000000000000002817effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff19161415610611576000925061067356610668565b60017f010000000000000000000000000000000000000000000000000000000000000002817effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614156106675760019250610673565b5b6106726000610867565b5b505095945050505050565b600060006000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16634e3202638989898989604051867c0100000000000000000000000000000000000000000000000000000000028152600401808060200185600019168152602001846000191681526020018367ffffffffffffffff1681526020018281038252878782818152602001925080828437820191505096505050505050506020604051808303816000876161da5a03f115610002575050506040518051906020015091508160006020811015610002571a7f010000000000000000000000000000000000000000000000000000000000000002905060007f010000000000000000000000000000000000000000000000000000000000000002817effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614156107ea576000925061084c56610841565b60017f010000000000000000000000000000000000000000000000000000000000000002817effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff19161415610840576001925061084c565b5b61084b6000610867565b5b505095945050505050565b80151561086357610002565b5b50565b80151561087357610002565b5b505660606040525b618801600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff02191690830217905550618802600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff02191690830217905550618803600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff02191690830217905550618804600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908302179055505b610877806100c86000396000f36060604052361561005e576000357c0100000000000000000000000000000000000000000000000000000000900480633319f70b1461006f578063794f69e3146100aa578063dafca47a14610122578063e088659e146101765761005e565b61006d5b61006a6101ca565b5b565b005b610090600480803590602001908201803590602001919091929050506101d1565b604051808260001916815260200191505060405180910390f35b61010a6004808035906020019082018035906020019190919290803590602001909190803590602001909190803590602001909190803590602001909190803590602001909190803590602001909190803590602001909190505061029e565b60405180821515815260200191505060405180910390f35b61015e600480803590602001908201803590602001919091929080359060200190919080359060200190919080359060200190919050506104a5565b60405180821515815260200191505060405180910390f35b6101b26004808035906020019082018035906020019190919290803590602001909190803590602001909190803590602001909190505061067e565b60405180821515815260200191505060405180910390f35b610002565b565b60006101e260408484905014610857565b600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16633a2765238484604051837c010000000000000000000000000000000000000000000000000000000002815260040180806020018281038252848482818152602001925080828437820191505093505050506020604051808303816000876161da5a03f11561000257505050604051805190602001509050610298565b92915050565b600060006000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16635286a75b8d8d8d8d8d8d8d8d8d6040518a7c010000000000000000000000000000000000000000000000000000000002815260040180806020018960001916815260200188600019168152602001876000191681526020018660001916815260200185600019168152602001846000191681526020018360001916815260200182810382528b8b8281815260200192508082843782019150509a50505050505050505050506020604051808303816000876161da5a03f115610002575050506040518051906020015091508160006020811015610002571a7f010000000000000000000000000000000000000000000000000000000000000002905060007f010000000000000000000000000000000000000000000000000000000000000002817effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916141561043457600092506104965661048b565b60017f010000000000000000000000000000000000000000000000000000000000000002817effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916141561048a5760019250610496565b5b6104956000610867565b5b50509998505050505050505050565b600060006000600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16634e3202638989898989604051867c0100000000000000000000000000000000000000000000000000000000028152600401808060200185600019168152602001846000191681526020018367ffffffffffffffff1681526020018281038252878782818152602001925080828437820191505096505050505050506020604051808303816000876161da5a03f115610002575050506040518051906020015091508160006020811015610002571a7f010000000000000000000000000000000000000000000000000000000000000002905060007f010000000000000000000000000000000000000000000000000000000000000002817effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff19161415610611576000925061067356610668565b60017f010000000000000000000000000000000000000000000000000000000000000002817effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614156106675760019250610673565b5b6106726000610867565b5b505095945050505050565b600060006000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16634e3202638989898989604051867c0100000000000000000000000000000000000000000000000000000000028152600401808060200185600019168152602001846000191681526020018367ffffffffffffffff1681526020018281038252878782818152602001925080828437820191505096505050505050506020604051808303816000876161da5a03f115610002575050506040518051906020015091508160006020811015610002571a7f010000000000000000000000000000000000000000000000000000000000000002905060007f010000000000000000000000000000000000000000000000000000000000000002817effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614156107ea576000925061084c56610841565b60017f010000000000000000000000000000000000000000000000000000000000000002817effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff19161415610840576001925061084c565b5b61084b6000610867565b5b505095945050505050565b80151561086357610002565b5b50565b80151561087357610002565b5b505660606040523615610192576000357c01000000000000000000000000000000000000000000000000000000009004806306fdde03146101a35780630af0b1321461021e57806318160ddd146102535780631d48f5e91461027657806334298c21146102af57806340c10f19146102d257806341a42bea146102f357806347e722461461031657806348a0d7541461037d5780634e3cb2e9146103a05780635967caa2146103c35780635ae60499146104345780635cfc1a51146104695780635e2aca561461048c5780635f95f1d414610521578063631c56ef146105445780636def0cbe1461056757806370a08231146105be5780637a14db16146105ea578063835278b71461060d57806386307865146106875780638da5cb5b146106b5578063949d225d146106ee5780639f7ad1d114610711578063a06f097714610729578063a9059cbb14610759578063b69ef8a81461077a578063c8c505151461079d578063ce0a8572146107c9578063d0316c50146107ec578063ebf0c7171461081c578063f2fde38b1461084357610192565b6101a15b61019e61085b565b5b565b005b6101b06004805050610862565b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600302600f01f150905090810190601f1680156102105780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b61023d6004808035906020019091908035906020019091905050610903565b6040518082815260200191505060405180910390f35b6102606004805050610918565b6040518082815260200191505060405180910390f35b6102956004808035906020019091908035906020019091905050610921565b604051808260001916815260200191505060405180910390f35b6102bc6004805050610b6f565b6040518082815260200191505060405180910390f35b6102f16004808035906020019091908035906020019091905050610b86565b005b6103006004805050610cb9565b6040518082815260200191505060405180910390f35b61032c6004808035906020019091905050610cc2565b60405180838152602001806020018281038252838181518152602001915080519060200190602002808383829060006004602084601f0104600302600f01f150905001935050505060405180910390f35b61038a6004805050610dd3565b6040518082815260200191505060405180910390f35b6103ad6004805050610dec565b6040518082815260200191505060405180910390f35b6104326004808035906020019082018035906020019191908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050909091908035906020019091908035906020019091908035906020019091905050610df5565b005b61045360048080359060200190919080359060200190919050506110ce565b6040518082815260200191505060405180910390f35b61047660048050506110e3565b6040518082815260200191505060405180910390f35b61051f6004808035906020019082018035906020019191908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509090919080359060200190919080359060200190919080359060200190919080359060200190919080359060200190919080359060200190919080359060200190919050506110f5565b005b61052e600480505061140d565b6040518082815260200191505060405180910390f35b6105516004805050611428565b6040518082815260200191505060405180910390f35b610574600480505061143a565b60405180806020018281038252838181518152602001915080519060200190602002808383829060006004602084601f0104600302600f01f1509050019250505060405180910390f35b6105d460048080359060200190919050506114af565b6040518082815260200191505060405180910390f35b6105f760048050506114ca565b6040518082815260200191505060405180910390f35b6106856004808035906020019082018035906020019191908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509090919080359060200190919080359060200190919080359060200190919080359060200190919050506114d3565b005b61069d600480803590602001909190505061175e565b60405180821515815260200191505060405180910390f35b6106c2600480505061178e565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6106fb60048050506117b4565b6040518082815260200191505060405180910390f35b61072760048080359060200190919050506117c6565b005b61073f600480803590602001909190505061185e565b604051808260001916815260200191505060405180910390f35b610778600480803590602001909190803590602001909190505061189e565b005b6107876004805050611a1b565b6040518082815260200191505060405180910390f35b6107b36004808035906020019091905050611ab0565b6040518082815260200191505060405180910390f35b6107d66004805050611af1565b6040518082815260200191505060405180910390f35b6108026004808035906020019091905050611af6565b604051808260001916815260200191505060405180910390f35b6108296004805050611b37565b604051808260001916815260200191505060405180910390f35b6108596004808035906020019091905050611b53565b005b610002565b565b60086000508054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156108fb5780601f106108d0576101008083540402835291602001916108fb565b820191906000526020600020905b8154815290600101906020018083116108de57829003601f168201915b505050505081565b60008160020a83049050610912565b92915050565b60096000505481565b60006020604051908101604052806000815260200150600060406040518059106109485750595b90808252806020026020018201604052801561095f575b5091506000905080505b60208110156109e95784816020811015610002571a7f01000000000000000000000000000000000000000000000000000000000000000282828151811015610002579060200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053505b8080600101915050610969565b6000905080505b6020811015610a735783816020811015610002571a7f01000000000000000000000000000000000000000000000000000000000000000282602083018151811015610002579060200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053505b80806001019150506109f0565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16633319f70b83604051827c010000000000000000000000000000000000000000000000000000000002815260040180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600302600f01f150905090810190601f168015610b375780820380516001836020036101000a031916815260200191505b50925050506020604051808303816000876161da5a03f11561000257505050604051805190602001509250610b67565b505092915050565b60006002610b7b6110e3565b049050610b83565b90565b600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610be257610002565b610c1b600a60005060008473ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000505482611bde565b600a60005060008473ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005081905550610c5d60096000505482611bde565b6009600050819055508173ffffffffffffffffffffffffffffffffffffffff167f9f494565851dbcb31fb5198ca217cda6833282fadb96ba9431bd19c82afc1dd3826040518082815260200191505060405180910390a25b5050565b600d6000505481565b60006020604051908101604052806000815260200150600060006020604051908101604052806000815260200150600060006000600660005060008a600019168152602001908152602001600020600050549550610d2260008711611c0e565b600186039450600260005054604051805910610d3b5750595b908082528060200260200182016040528015610d52575b50935060009250849150600090505b600260005054831015610dbd57610d816001831884806001019550611c1e565b84828060010193508151811015610002579060200190602002019060001916908181526020015050610db4826001610903565b91508150610d61565b848497509750610dc8565b505050505050915091565b6000600560005054600360005054039050610de9565b90565b600c6000505481565b610e3a8167ffffffffffffffff16600a60005060003373ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050541015611c0e565b610e63600060106000506000866000191681526020019081526020016000206000505414611c0e565b610e75610e6f8361175e565b15611c0e565b610f94600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663e088659e86868686604051857c0100000000000000000000000000000000000000000000000000000000028152600401808060200185600019168152602001846000191681526020018367ffffffffffffffff1681526020018281038252868181518152602001915080519060200190808383829060006004602084601f0104600302600f01f150905090810190601f168015610f635780820380516001836020036101000a031916815260200191505b50955050505050506020604051808303816000876161da5a03f1156100025750505060405180519060200150611ce7565b610f9d826117c6565b6001601060005060008560001916815260200190815260200160002060005081905550611003600a60005060003373ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050548267ffffffffffffffff16611cf7565b600a60005060003373ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050819055503373ffffffffffffffffffffffffffffffffffffffff167fe98b540e92df7848084ffd671d0e51f24307beb49f2ab01e35bb695ceb8aba67828460405180826000191681526020019150506040518091039020604051808367ffffffffffffffff168152602001826000191681526020019250505060405180910390a2600b6000818150548092919060010191905055505b50505050565b60008160020a830290506110dd565b92915050565b600060036000505490506110f2565b90565b61111e600060106000506000876000191681526020019081526020016000206000505414611c0e565b611147600060106000506000866000191681526020019081526020016000206000505414611c0e565b611170600060106000506000896000191681526020019081526020016000206000505414611c0e565b611199600060106000506000886000191681526020019081526020016000206000505414611c0e565b6111ab6111a58361175e565b15611c0e565b6111bd6111b78261175e565b15611c0e565b611306600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663794f69e38a8a8a8a8a8a8a8a604051897c010000000000000000000000000000000000000000000000000000000002815260040180806020018960001916815260200188600019168152602001876000191681526020018660001916815260200185600019168152602001846000191681526020018360001916815260200182810382528a8181518152602001915080519060200190808383829060006004602084601f0104600302600f01f150905090810190601f1680156112d15780820380516001836020036101000a031916815260200191505b5099505050505050505050506020604051808303816000876161da5a03f1156100025750505060405180519060200150611ce7565b61130f826117c6565b611318816117c6565b600160106000506000866000191681526020019081526020016000206000508190555060016010600050600085600019168152602001908152602001600020600050819055503373ffffffffffffffffffffffffffffffffffffffff167f0d3211cecea8fbffc05221205fa1aefe539b636c658a996a6cbc8729fe1ad001836040518082600019168152602001915050604051809103902083604051808260001916815260200191505060405180910390206040518083600019168152602001826000191681526020019250505060405180910390a2600d6000818150548092919060010191905055505b5050505050505050565b6000600d6000505461141d610b6f565b039050611425565b90565b60006002600050549050611437565b90565b602060405190810160405280600081526020015060046000508054806020026020016040519081016040528092919081815260200182805480156114a057602002820191906000526020600020905b816000505481526020019060010190808311611489575b505050505090506114ac565b90565b600a6000506020528060005260406000206000915090505481565b600b6000505481565b6114fc600060106000506000876000191681526020019081526020016000206000505414611c0e565b61150d6115088461175e565b611c0e565b61162c600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663dafca47a87878686604051857c0100000000000000000000000000000000000000000000000000000000028152600401808060200185600019168152602001846000191681526020018367ffffffffffffffff1681526020018281038252868181518152602001915080519060200190808383829060006004602084601f0104600302600f01f150905090810190601f1680156115fb5780820380516001836020036101000a031916815260200191505b50955050505050506020604051808303816000876161da5a03f1156100025750505060405180519060200150611ce7565b6001601060005060008660001916815260200190815260200160002060005081905550611692600a60005060003373ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050548267ffffffffffffffff16611bde565b600a60005060003373ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050819055503373ffffffffffffffffffffffffffffffffffffffff167f77c10afc47cf7753a7d1b501cd07d1720103713089bf4f7ba501bebda81cd4b7828560405180826000191681526020019150506040518091039020604051808367ffffffffffffffff168152602001826000191681526020019250505060405180910390a2600c6000818150548092919060010191905055505b5050505050565b6000600060066000506000846000191681526020019081526020016000206000505414159050611789565b919050565b600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600060056000505490506117c3565b90565b60006117f1600060066000506000856000191681526020019081526020016000206000505414611c0e565b61180660036000505460056000505410611c0e565b60056000818150546001019190508190559050806006600050600084600019168152602001908152602001600020600050819055508160076000506000838152602001908152602001600020600050819055505b5050565b60006118736004600050805490508310611c0e565b600460005082815481101561000257906000526020600020900160005b50549050611899565b919050565b6118d981600a60005060003373ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050541015611c0e565b611912600a60005060003373ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000505482611cf7565b600a60005060003373ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000508190555061197e600a60005060008473ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000505482611bde565b600a60005060008473ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050819055508173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f0a85107a334eae0d22d21cdf13af0f8e8125039ec60baaa843d2c4c5b0680174836040518082815260200191505060405180910390a35b5050565b60003073ffffffffffffffffffffffffffffffffffffffff166370a0823133604051827c0100000000000000000000000000000000000000000000000000000000028152600401808273ffffffffffffffffffffffffffffffffffffffff1681526020019150506020604051808303816000876161da5a03f11561000257505050604051805190602001509050611aad565b90565b600060006006600050600084600019168152602001908152602001600020600050549050611ae060008211611c0e565b600181019150611aeb565b50919050565b601d81565b60006000611b0a6005600050548410611c0e565b60018301905060076000506000828152602001908152602001600020600050549150611b31565b50919050565b6000611b496000600260005054611c1e565b9050611b50565b90565b600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515611baf57610002565b80600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908302179055505b50565b600060008284019050611bff848210158015611bfa5750838210155b611ce7565b809150611c07565b5092915050565b801515611c1a57610002565b5b50565b6000600060006000611c3086866110ce565b600560005054111515611c6357600460005085815481101561000257906000526020600020900160005b50549350611cde565b6000851415611c975760018601925060076000506000848152602001908152602001600020600050549350611cde56611cdd565b611cae611ca58760016110ce565b60018703611c1e565b9150611cca6001611cc08860016110ce565b0160018703611c1e565b9050611cd68282610921565b9350611cde565b5b50505092915050565b801515611cf357610002565b5b50565b60006000611d0783851015611ce7565b8284039050809150611d14565b509291505056', + gas: '54700000' // changed + }, function (e, contract) { + console.log(e, contract); + if (typeof contract.address !== 'undefined') { + console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash); + } + }) + // ================================= + // END: Web3 deploy code + // ================================= + return ztoken; +} + +function _zdemo_get_ztoken(a) { + return ztoken_abi.at(a) +} + +function _zdemo_create_zprivatecontract(tracker, bid_constellation, bid_token, bid_amount, ask_constellation, ask_token, ask_amount) { + var apk = tracker.keypair.a_pk; + var r = zsl.getRandomness(); + var bid_address = bid_token.address; + var ask_address = ask_token.address; + + // ================================= + // START: Web3 deploy code + // ================================= + var zprivatecontract = zprivatecontract_abi.new( + apk, + r, + bid_constellation, + bid_address, + bid_amount, + ask_constellation, + ask_address, + ask_amount, + { + privateFor: [ask_constellation], // changed + from: web3.eth.accounts[0], + data: '0x60606040526040516112fe3803806112fe833981016040528080519060200190919080519060200190919080518201919060200180519060200190919080519060200190919080518201919060200180519060200190919080519060200190919050505b5b33600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908302179055505b87600b6000508190555086600e6000508190555033600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff0219169083021790555084600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff0219169083021790555084600660006101000a81548173ffffffffffffffffffffffffffffffffffffffff0219169083021790555083600160146101000a81548167ffffffffffffffff021916908302179055508560076000509080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061019357805160ff19168380011785556101c4565b828001600101855582156101c4579182015b828111156101c35782518260005055916020019190600101906101a5565b5b5090506101ef91906101d1565b808211156101eb57600081815060009055506001016101d1565b5090565b505081600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff0219169083021790555081600560006101000a81548173ffffffffffffffffffffffffffffffffffffffff0219169083021790555080600360146101000a81548167ffffffffffffffff021916908302179055508260086000509080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106102b557805160ff19168380011785556102e6565b828001600101855582156102e6579182015b828111156102e55782518260005055916020019190600101906102c7565b5b50905061031191906102f3565b8082111561030d57600081815060009055506001016102f3565b5090565b50506000600060146101000a81548160ff021916908302179055503373ffffffffffffffffffffffffffffffffffffffff167fff2fc9682dd82e89e7e02de136eac388f69e7458384298b0936d259a829af6a485604051808267ffffffffffffffff16815260200191505060405180910390a25b5050505050505050610f638061039b6000396000f360606040523615610103576000357c010000000000000000000000000000000000000000000000000000000090048063091007a6146101055780633042b76e1461012c57806336013189146101a75780634717f698146101ce5780635dec6f70146101f55780636a1abd511461021c5780636ba5ceeb146102345780638da5cb5b146102615780639527f9be1461029a578063aec2393b146102d1578063c19d93fb146102fe578063c7a66eb314610321578063cc4f8c141461035a578063d05afbad146103d5578063dbab221b1461040e578063ef03dd1e14610426578063f2fde38b1461044d578063f496d88214610465578063fabe9f361461049e57610103565b005b61011260048050506104d7565b604051808260001916815260200191505060405180910390f35b61013960048050506104e0565b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600302600f01f150905090810190601f1680156101995780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101b46004805050610581565b604051808260001916815260200191505060405180910390f35b6101db600480505061058a565b604051808260001916815260200191505060405180910390f35b6102026004805050610593565b604051808260001916815260200191505060405180910390f35b610232600480803590602001909190505061059c565b005b6102416004805050610819565b604051808267ffffffffffffffff16815260200191505060405180910390f35b61026e6004805050610833565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6102b96004808035906020019091908035906020019091905050610859565b60405180821515815260200191505060405180910390f35b6102de60048050506109d3565b604051808267ffffffffffffffff16815260200191505060405180910390f35b61030b60048050506109ed565b6040518082815260200191505060405180910390f35b61032e6004805050610a00565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6103676004805050610a26565b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600302600f01f150905090810190601f1680156103c75780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6103e26004805050610ac7565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6104246004808035906020019091905050610aed565b005b6104336004805050610d68565b604051808260001916815260200191505060405180910390f35b6104636004808035906020019091905050610d71565b005b6104726004805050610dfc565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6104ab6004805050610e22565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b600a6000505481565b60076000508054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156105795780601f1061054e57610100808354040283529160200191610579565b820191906000526020600020905b81548152906001019060200180831161055c57829003601f168201915b505050505081565b600d6000505481565b60096000505481565b600b6000505481565b60006000600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156105fc57610002565b6106176001600060149054906101000a900460ff1614610e48565b600283600c6000505461063f600160149054906101000a900467ffffffffffffffff16610e58565b6040518084600019168152602001836000191681526020018280519060200190808383829060006004602084601f0104600302600f01f15090500193505050506020604051808303816000866161da5a03f115610002575050604051805190602001509150600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16638630786583604051827c010000000000000000000000000000000000000000000000000000000002815260040180826000191681526020019150506020604051808303816000876161da5a03f1156100025750505060405180519060200150905080156107b35782600a600050819055506002600060146101000a81548160ff021916908302179055503373ffffffffffffffffffffffffffffffffffffffff167f6c1576fb076bed036cd08dac98156e394fab225838376081753020857084ddea60405180905060405180910390a2610813565b6004600060146101000a81548160ff021916908302179055503373ffffffffffffffffffffffffffffffffffffffff167f336cc5227bd5defbf32bddcc8249a2259895087ef005a131b57e9af0f94343ed60405180905060405180910390a25b5b505050565b600360149054906101000a900467ffffffffffffffff1681565b600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60006108b5600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415610e48565b6108d06000600060149054906101000a900460ff1614610e48565b82600c6000508190555081600f600050819055506002600e60005054600f60005054604051808360001916815260200182600019168152602001925050506020604051808303816000866161da5a03f11561000257505060405180519060200150600d6000508190555033600460006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908302179055506001600060146101000a81548160ff021916908302179055503373ffffffffffffffffffffffffffffffffffffffff167f6a2175dc1fe200a7edb14cc691d97f643198113419adb9233a1b4c5cb8aa53d360405180905060405180910390a2600190506109cd565b92915050565b600160149054906101000a900467ffffffffffffffff1681565b600060149054906101000a900460ff1681565b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60086000508054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610abf5780601f10610a9457610100808354040283529160200191610abf565b820191906000526020600020905b815481529060010190602001808311610aa257829003601f168201915b505050505081565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60006000610b4b600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415610e48565b610b666002600060149054906101000a900460ff1614610e48565b600283600b60005054610b8e600360149054906101000a900467ffffffffffffffff16610e58565b6040518084600019168152602001836000191681526020018280519060200190808383829060006004602084601f0104600302600f01f15090500193505050506020604051808303816000866161da5a03f115610002575050604051805190602001509150600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16638630786583604051827c010000000000000000000000000000000000000000000000000000000002815260040180826000191681526020019150506020604051808303816000876161da5a03f115610002575050506040518051906020015090508015610d0257826009600050819055506003600060146101000a81548160ff021916908302179055503373ffffffffffffffffffffffffffffffffffffffff167f3e67459cc1f023920040097861ffd0b6de230e415fe2415e7dafb515a3005ae960405180905060405180910390a2610d62565b6005600060146101000a81548160ff021916908302179055503373ffffffffffffffffffffffffffffffffffffffff167fc00fac96dee2f35b8fec0d57bf0887d7a2c82034746a0b3328994d2e9bac97c760405180905060405180910390a25b5b505050565b600c6000505481565b600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610dcd57610002565b80600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908302179055505b50565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b801515610e5457610002565b5b50565b60206040519081016040528060008152602001506000602060405190810160405280600081526020015060008478010000000000000000000000000000000000000000000000000292506008604051805910610eb15750595b908082528060200260200182016040528015610ec8575b509150600090505b6008811015610f535782816007036008811015610002571a7f01000000000000000000000000000000000000000000000000000000000000000282828151811015610002579060200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053505b8080600101915050610ed0565b819350610f5b565b50505091905056', + gas: '54700000' // changed + }, function (e, contract) { + console.log(e, contract); + if (typeof contract.address !== 'undefined') { + console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash); + } + }) + // ================================= + // END: Web3 deploy code + // ================================= + + return zprivatecontract; +} + + +function _zdemo_get_zprivatecontract(a) { + return zprivatecontract_abi.at(a); +} + +function _zdemo_accept_bid(tracker, zprivatecontract) { + var counterparty = zprivatecontract.bidderConstellationAddress(); + zprivatecontract.acceptBid(tracker.keypair.a_pk, zsl.getRandomness(), { from: eth.accounts[0], gas: 54700000, privateFor: [counterparty] }); +} + +function _zdemo_add_payment_received_by_asker(tracker, zprivatecontract) { + var rho = zprivatecontract.paymentReceivedByAsker(); + var pk = tracker.keypair.a_pk; + var value = parseInt(zprivatecontract.bidAmount()); + var cm = zsl.getCommitment(rho, pk, value); + var note = {}; + note.rho = rho; + note.value = value; + note.ztoken = zprivatecontract.bidTokenAddress(); + note.uuid = web3.toHex(web3.sha3(cm, { encoding: 'hex' })); + tracker.notes[note.uuid] = note; + return note; +} + +function _zdemo_add_payment_received_by_bidder(tracker, zprivatecontract) { + var rho = zprivatecontract.paymentReceivedByBidder(); + var pk = tracker.keypair.a_pk; + var value = parseInt(zprivatecontract.askAmount()); + var cm = zsl.getCommitment(rho, pk, value); + var note = {}; + note.rho = rho; + note.value = value; + note.ztoken = zprivatecontract.askTokenAddress(); + note.uuid = web3.toHex(web3.sha3(cm, { encoding: 'hex' })); + tracker.notes[note.uuid] = note; + return note; +} + +// Send a single note as shielded transfer, with change going back to the sender. +function _zdemo_submit_funds_to_contract(tracker, ztoken, zprivatecontract, noteId, amount, recipient_apk, recipient) { + + var empty_uncles = ["0x8000000000000000000000000000000000000000000000000000000000000100", "0x8000000000000000000000000000000000000000000000000000000000000100", "0x8000000000000000000000000000000000000000000000000000000000000100", "0x8000000000000000000000000000000000000000000000000000000000000100", "0x8000000000000000000000000000000000000000000000000000000000000100", "0x8000000000000000000000000000000000000000000000000000000000000100", "0x8000000000000000000000000000000000000000000000000000000000000100", "0x8000000000000000000000000000000000000000000000000000000000000100", "0x8000000000000000000000000000000000000000000000000000000000000100", "0x8000000000000000000000000000000000000000000000000000000000000100", "0x8000000000000000000000000000000000000000000000000000000000000100", "0x8000000000000000000000000000000000000000000000000000000000000100", "0x8000000000000000000000000000000000000000000000000000000000000100", "0x8000000000000000000000000000000000000000000000000000000000000100", "0x8000000000000000000000000000000000000000000000000000000000000100", "0x8000000000000000000000000000000000000000000000000000000000000100", "0x8000000000000000000000000000000000000000000000000000000000000100", "0x8000000000000000000000000000000000000000000000000000000000000100", "0x8000000000000000000000000000000000000000000000000000000000000100", "0x8000000000000000000000000000000000000000000000000000000000000100", "0x8000000000000000000000000000000000000000000000000000000000000100", "0x8000000000000000000000000000000000000000000000000000000000000100", "0x8000000000000000000000000000000000000000000000000000000000000100", "0x8000000000000000000000000000000000000000000000000000000000000100", "0x8000000000000000000000000000000000000000000000000000000000000100", "0x8000000000000000000000000000000000000000000000000000000000000100", "0x8000000000000000000000000000000000000000000000000000000000000100", "0x8000000000000000000000000000000000000000000000000000000000000100", "0x8000000000000000000000000000000000000000000000000000000000000100"]; + var note = tracker.notes[noteId]; + + if (note.value < amount) { + console.log("Cannot transfer " + amount + " as note value of " + note.value + " is too small."); + return; + } + + var change = note.value - amount; + var cm = zsl.getCommitment(note.rho, tracker.keypair.a_pk, note.value); + var witnesses = ztoken.getWitness(cm); + var treeIndex = parseInt(witnesses[0]); + var authPath = witnesses[1]; + var tmpKeypair = zsl.getNewAddress(); + var out_rho_1 = zsl.getRandomness(); + var out_rho_2 = zsl.getRandomness(); + + console.log("***************************************************************"); + console.log("[*] Generating proof for shielded transfer"); + var start = new Date(); + var result = zsl.createShieldedTransfer( + note.rho, tracker.keypair.a_sk, note.value, treeIndex, authPath, + zsl.getRandomness(), tmpKeypair.a_sk, 0, 0, empty_uncles, + out_rho_1, recipient_apk, amount, + out_rho_2, tracker.keypair.a_pk, change); + var elapsed = new Date() - start; + console.log("[*] Generated in " + elapsed / 1000 + " secs"); + + var n1 = {}; + n1.value = amount; + n1.rho = out_rho_1; + n1.uuid = web3.toHex(web3.sha3(result.out_cm_1, { encoding: 'hex' })); + n1.ztoken = ztoken.address; + console.log("[*] Recipient receives note of " + amount + " " + ztoken.name()) + + var n2 = {}; + n2.value = change; + n2.rho = out_rho_2; + n2.uuid = web3.toHex(web3.sha3(result.out_cm_2, { encoding: 'hex' })); + n2.ztoken = ztoken.address; + console.log("[*] Sender receives change of " + change + " " + ztoken.name()) + + var events = ztoken.allEvents(); + events.watch(function (error, event) { + if (error) { + console.log("Error: " + error); + } else { + var s = JSON.stringify(event.args); + console.log(event.event + " : " + s); + if (event.event == 'LogShieldedTransfer' && event.args['uuid_1'] == n1.uuid && event.args['uuid_2'] == n2.uuid) { + console.log("[*] Shielded transfer added to z-contract."); + events.stopWatching(); + + // This note belongs to the recipient. In this POC, it will be another node, so we don't track it here. + // tracker.notes[n1.uuid] = n1; + + // This note is the change note which should be tracked. + tracker.notes[n2.uuid] = n2; + + // Input note is spent. + tracker.spent[noteId] = note; + delete (tracker.notes[noteId]); + + // Notify private contract about payment + if (recipient == zprivatecontract.askerConstellationAddress()) { + console.log("[*] Submitting payment details to private contract"); + zprivatecontract.submitPaymentDetails( + n1.rho, + { from: eth.accounts[0], gas: 54700000, privateFor: [recipient] }); + } else { + console.log("[*] Submitting settlement details to private contract"); + zprivatecontract.submitSettlementDetails( + n1.rho, + { from: eth.accounts[0], gas: 54700000, privateFor: [recipient] }); + } + console.log("***************************************************************"); + } + } + }); + + console.log("[*] Submit shielded transfer to z-contract..."); + var anchor = ztoken.root(); + ztoken.shieldedTransfer( + result.proof, anchor, + result.in_spend_nf_1, result.in_spend_nf_2, + result.out_send_nf_1, result.out_send_nf_2, + result.out_cm_1, result.out_cm_2, + { from: eth.accounts[0], gas: 5470000 }); + return "Waiting for log event..."; +} + + +function _zdemo_submit_payment(tracker, ztoken, zprivatecontract, noteId) { + return _zdemo_submit_funds_to_contract(tracker, ztoken, zprivatecontract, noteId, + parseInt(zprivatecontract.bidAmount()), + zprivatecontract.askerApk(), + zprivatecontract.askerConstellationAddress()); +} + + +function _zdemo_submit_settlement(tracker, ztoken, zprivatecontract, noteId) { + return _zdemo_submit_funds_to_contract(tracker, ztoken, zprivatecontract, noteId, + parseInt(zprivatecontract.askAmount()), + zprivatecontract.bidderApk(), + zprivatecontract.bidderConstellationAddress()); +} + + +function _zdemo_watch_events(zprivatecontract) { + var events = zprivatecontract.allEvents(); + events.watch(function (error, event) { + if (error) { + console.log("Error: " + error); + } else { + var s = JSON.stringify(event.args) + console.log(event.event + " : " + s); + // take action + if (event.event == 'LogDoneEvent') { + console.log("***************************************************************"); + console.log("* TRADE AGREED"); + if (zprivatecontract.bidder() == web3.eth.accounts[0]) { + var tmp = _zdemo_get_ztoken(zprivatecontract.bidTokenAddress()) + console.log + console.log("* Please send payment of " + zprivatecontract.bidAmount() + " " + tmp.name() + " to private contract."); + console.log("* Counterparty's constellation address: " + zprivatecontract.askerConstellationAddress()); + console.log("***************************************************************"); + } else { + console.log("* Waiting for payment from counterparty."); + console.log("***************************************************************"); + } + } + else if (event.event == 'LogPaymentEvent') { + console.log("***************************************************************"); + console.log("* PAYMENT RECEIVED"); + if (zprivatecontract.asker() == web3.eth.accounts[0]) { + var tmp = _zdemo_get_ztoken(zprivatecontract.askTokenAddress()) + console.log("* Please send settlement of " + zprivatecontract.askAmount() + " " + tmp.name() + " to private contract."); + console.log("* Counterparty's constellation address: " + zprivatecontract.bidderConstellationAddress()); + console.log("***************************************************************"); + } else { + console.log("* Waiting for settlement from counterparty."); + console.log("***************************************************************"); + } + } else if (event.event == 'LogSettlementEvent') { + console.log("***************************************************************"); + console.log("* TRADE FINISHED"); + var note; + if (zprivatecontract.asker() == web3.eth.accounts[0]) { + note = _zdemo_add_payment_received_by_asker(tracker, zprivatecontract); + // for (var key in note){ + // console.log( "* " + key + ": " + note[key] ); + // } + //console.log(JSON.stringify(note, null, 4)) + } else { + var note = _zdemo_add_payment_received_by_bidder(tracker, zprivatecontract); + } + console.log("* Tracker received shielded note with uuid: " + note.uuid) + console.log("***************************************************************"); + } + } + }); + return events; +} + + +// Namespace for zdemo, using module pattern. + +var zdemo = (function() { + return { + create_ztoken: function(tokenName, initialSupply) { + return _zdemo_create_ztoken(tokenName, initialSupply); + }, + get_ztoken: function(a) { + return _zdemo_get_ztoken(a); + }, + create_zprivatecontract: function(tracker, bid_constellation, bid_token, bid_amount, ask_constellation, ask_token, ask_amount) { + return _zdemo_create_zprivatecontract(tracker, bid_constellation, bid_token, bid_amount, ask_constellation, ask_token, ask_amount); + }, + get_zprivatecontract: function(a) { + return _zdemo_get_zprivatecontract(a); + }, + accept_bid: function(tracker, zprivatecontract) { + return _zdemo_accept_bid(tracker, zprivatecontract); + }, + submit_payment: function(tracker, ztoken, zprivatecontract, noteId) { + return _zdemo_submit_payment(tracker, ztoken, zprivatecontract, noteId); + }, + submit_settlement: function(tracker, ztoken, zprivatecontract, noteId) { + return _zdemo_submit_settlement(tracker, ztoken, zprivatecontract, noteId); + }, + watch_events: function(zprivatecontract) { + return _zdemo_watch_events(zprivatecontract); + } + }; +})(); + + +// Note tracker + +function ztracker() { + this.keypair = zsl.getNewAddress(); + this.notes = {}; + this.spent = {}; +} + +ztracker.prototype.shield = function (ztoken, value) { + var rho = zsl.getRandomness(); + var pk = this.keypair.a_pk; + console.log("***************************************************************"); + console.log("[*] Generating proof for shielding"); + var start = new Date(); + var result = zsl.createShielding(rho, pk, value); + var elapsed = new Date() - start; + console.log("[*] Generated in " + elapsed / 1000 + " secs"); + + var uuid = web3.toHex(web3.sha3(result.cm, { encoding: 'hex' })); + + var that = this; + var events = ztoken.allEvents(); + events.watch(function (error, event) { + if (error) { + console.log("Error: " + error); + } else { + var s = JSON.stringify(event.args); + console.log(event.event + " : " + s); + if (event.event == 'LogShielding' && event.args['uuid'] == uuid) { + console.log("[*] Shielding added to z-contract."); + console.log("***************************************************************"); + events.stopWatching(); + var note = {}; + note.rho = rho; + note.value = value; + note.uuid = uuid; + note.ztoken = ztoken.address; + that.notes[uuid] = note; + } + } + }); + + ztoken.shield(result.proof, result.send_nf, result.cm, value, { from: eth.accounts[0], gas: 5470000 }); + return "Waiting for log event..."; +} + + +ztracker.prototype.unshield = function (uuid) { + var note = this.notes[uuid]; + + var a = note.ztoken; + var ztoken = ztoken_abi.at(a); + + var cm = zsl.getCommitment(note.rho, this.keypair.a_pk, note.value); + var witnesses = ztoken.getWitness(cm) + var treeIndex = parseInt(witnesses[0]) + var authPath = witnesses[1] + + console.log("***************************************************************"); + console.log("[*] Generating proof for unshielding"); + var start = new Date(); + var result = zsl.createUnshielding(note.rho, this.keypair.a_sk, note.value, treeIndex, authPath) + var elapsed = new Date() - start; + console.log("[*] Generated in " + elapsed / 1000 + " secs"); + + var that = this; + + var events = ztoken.allEvents(); + events.watch(function (error, event) { + if (error) { + console.log("Error: " + error); + } else { + var s = JSON.stringify(event.args); + console.log(event.event + " : " + s); + if (event.event == 'LogUnshielding' && event.args['uuid'] == uuid) { + console.log("[*] Unshielding added to z-contract."); + console.log("***************************************************************"); + events.stopWatching(); + that.spent[uuid] = note; + delete (that.notes[uuid]); + } + } + }); + + var rt = ztoken.root(); + ztoken.unshield(result.proof, result.spend_nf, cm, rt, note.value, { from: eth.accounts[0], gas: 54700000 }) + return "Waiting for log event..."; +} + + +ztracker.prototype.list = function (ztoken, amount) { + var result = []; + var name = ztoken.name(); + var addr = ztoken.address; + if (amount == undefined) { + amount = 0; + } + for (var uuid in this.notes) { + var note = this.notes[uuid]; + if (addr == note.ztoken && (note.value >= amount)) { + result.push(note); + } + } + + console.log("***************************************************************"); + console.log("Found " + result.length + " " + name + " notes >= " + amount) + console.log(JSON.stringify(result, null, 4)) + console.log("***************************************************************"); +} + + +ztracker.prototype.balance = function (ztoken) { + var result = 0; + var name = ztoken.name(); + var addr = ztoken.address; + for (var uuid in this.notes) { + var note = this.notes[uuid]; + if (addr == note.ztoken) { + result += note.value; + } + } + console.log("***************************************************************"); + console.log("Shielded balance of " + name + " = " + result); + console.log("***************************************************************"); +} + +// Basic persistence of tracker for demo purposes. +ztracker.prototype.load = function (filename) { + var x = JSON.parse(zsl.loadTracker(filename)); + this.keypair = x.keypair; + this.notes = x.notes; + this.spent = x.spent; + return true; +} + +// TODO: Post-demo, filename should be sanitized. +ztracker.prototype.save = function (filename) { + return zsl.saveTracker(filename, JSON.stringify(this)) +} diff --git a/vagrant/bootstrap.sh b/vagrant/bootstrap.sh index 4a2ddd6..369021b 100755 --- a/vagrant/bootstrap.sh +++ b/vagrant/bootstrap.sh @@ -23,14 +23,25 @@ rm -f $GOREL PATH=$PATH:/usr/local/go/bin echo 'PATH=$PATH:/usr/local/go/bin' >> /home/ubuntu/.bashrc +# ZSL START +# During the development phase, there is no public access to the repository +# so we compile geth and bootnode locally and place them in the /vagrant +# shared folder which the VM can access. + # make/install quorum -git clone https://github.com/getamis/quorum.git -pushd quorum >/dev/null -git checkout feature/istanbul -make all -cp build/bin/geth /usr/local/bin -cp build/bin/bootnode /usr/local/bin -popd >/dev/null +# git clone https://github.com/getamis/quorum.git +# pushd quorum >/dev/null +# git checkout feature/istanbul +# make all +# cp build/bin/geth /usr/local/bin +# cp build/bin/bootnode /usr/local/bin +# popd >/dev/null + +echo 'Copying geth and bootnode from /vagrant/zsl-tmp into the VM /usr/local/bin' +cp /vagrant/zsl-tmp/geth /usr/local/bin +cp /vagrant/zsl-tmp/bootnode /usr/local/bin +mkdir /home/ubuntu/quorum +#ZSL END # install Porosity wget -q https://github.com/jpmorganchase/quorum/releases/download/v1.2.0/porosity