diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index a025e66ac..d73d84b67 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,10 +1,8 @@ -This issue tracker is only for technical issues related to zcashd. +This issue tracker is only for technical issues related to komodod -General Zcash questions and/or support requests and are best directed to the [Zcash Forums](https://forum.z.cash) or [Community Rocket.Chat](https://chat.zcashcommunity.com). - -For reporting security vulnerabilities or for sensitive discussions with our security team, please contact [security@z.cash](mailto:security@z.cash). You can use the [GPG key](https://z.cash/gpg-pubkeys/security.asc) (fingerprint: `AF85 0445 546C 18B7 86F9 2C62 88FB 8B86 D8B5 A68C`) to send an encrypted message. The key and fingerprint are duplicated on our [Public Keys page](https://z.cash/support/pubkeys.html). +General Komodo questions and/or support requests and are best directed to [Discord](https://komodoplatform.com/discord) ### Describe the issue Please provide a general summary of the issue you're experiencing @@ -21,8 +19,8 @@ Tell us what should happen ### Actual behaviour + errors Tell us what happens instead including any noticable error output (any messages displayed on-screen when e.g. a crash occurred) -### The version of Zcash you were using: -Run `zcashd --version` to find out +### The version of Komodo you were using: +Run `komodod --version` to find out ### Machine specs: - OS name + version: @@ -34,9 +32,9 @@ Run `zcashd --version` to find out - Compiler version (gcc -version): ### Any extra information that might be useful in the debugging process. -This includes the relevant contents of `~/.zcash/debug.log`. You can paste raw text, attach the file directly in the issue or link to the text via a pastebin type site. +This includes the relevant contents of `~/.komodo/debug.log`. You can paste raw text, attach the file directly in the issue or link to the text via a pastebin type site. Please also include any non-standard things you did during compilation (extra flags, dependency version changes etc.) if applicable. -### Do you have a backup of `~/.zcash` directory and/or take a VM snapshot? -- Backing up / making a copy of the `~/.zcash` directory might help make the problem reproducible. Please redact appropriately. +### Do you have a backup of `~/.komodo` directory and/or take a VM snapshot? +- Backing up / making a copy of the `~/.komodo` directory might help make the problem reproducible. Please redact appropriately. - Taking a VM snapshot is really helpful for interactively testing fixes diff --git a/.gitignore b/.gitignore index bebcef932..3916d4e87 100644 --- a/.gitignore +++ b/.gitignore @@ -120,3 +120,4 @@ src/komodo-cli src/komodod src/komodo-tx src/komodo-test +src/wallet-utility diff --git a/.travis.yml b/.travis.yml index ac331dcf9..d9237a104 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,105 +1,46 @@ -<<<<<<< HEAD language: cpp +matrix: + include: + - os: linux + dist: xenial + sudo: required + - os: osx + osx_image: xcode8 compiler: - - gcc - +- gcc before_install: - - sudo add-apt-repository --yes ppa:ubuntu-sdk-team/ppa - - sudo apt-get update -qq - - sudo apt-get install build-essential pkg-config libcurl3-gnutls-dev libc6-dev libevent-dev m4 g++-multilib autoconf libtool ncurses-dev unzip git python zlib1g-dev wget bsdmainutils automake libssl-dev libprotobuf-dev protobuf-compiler libdb++-dev ntp ntpdate -#install: - -script: - - ./zcutil/build.sh -j 5 - +- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo add-apt-repository --yes ppa:ubuntu-sdk-team/ppa; fi +- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get update -qq; fi +- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install libgnutls28-dev; fi +- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install build-essential pkg-config libcurl3-gnutls-dev libc6-dev libevent-dev m4 g++-multilib autoconf libtool ncurses-dev unzip git python zlib1g-dev wget bsdmainutils automake libssl-dev libprotobuf-dev protobuf-compiler libdb++-dev ntp ntpdate; fi +- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then rm '/usr/local/include/c++'; fi +- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi +- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install gcc@6; fi +- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew link --overwrite gcc@6; fi +script: +- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ./zcutil/build.sh -j 5; fi +- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./zcutil/build-mac.sh -j 5; fi notifications: irc: channels: - - "chat.freenode.net#komodoplatform" + - chat.freenode.net#komodoplatform template: - - "%{repository}/%{branch} (%{commit} - %{author}): %{message}" - - "Alt Message : %{repository_slug} - (%{commit} - %{author}): %{message}, Build Time: %{duration}" - - "Change view : %{compare_url}" - - "Build details : %{build_url}" -======= -# errata: -# - A travis bug causes caches to trample eachother when using the same -# compiler key (which we don't use anyway). This is worked around for now by -# replacing the "compilers" with a build name prefixed by the no-op ":" -# command. See: https://github.com/travis-ci/travis-ci/issues/4393 -# - sudo/dist/group are set so as to get Blue Box VMs, necessary for [loopback] -# IPv6 support - -sudo: required -dist: precise -group: legacy - -os: linux -language: cpp -compiler: gcc -env: - global: - - MAKEJOBS=-j3 - - RUN_TESTS=false - - BOOST_TEST_RANDOM=1$TRAVIS_BUILD_ID - - CCACHE_SIZE=100M - - CCACHE_TEMPDIR=/tmp/.ccache-temp - - CCACHE_COMPRESS=1 - - BASE_OUTDIR=$TRAVIS_BUILD_DIR/out - - SDK_URL=https://bitcoincore.org/depends-sources/sdks - - PYTHON_DEBUG=1 - - WINEDEBUG=fixme-all -cache: - apt: true - directories: - - depends/built - - depends/sdk-sources - - $HOME/.ccache -matrix: - fast_finish: true - include: - - compiler: ": ARM" - env: HOST=arm-linux-gnueabihf PACKAGES="g++-arm-linux-gnueabihf" DEP_OPTS="" GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat --enable-reduce-exports" - - compiler: ": Win32" - env: HOST=i686-w64-mingw32 PACKAGES="nsis gcc-mingw-w64-i686 g++-mingw-w64-i686 binutils-mingw-w64-i686 mingw-w64-dev wine bc" RUN_TESTS=true GOAL="deploy" BITCOIN_CONFIG="--enable-reduce-exports" MAKEJOBS="-j2" - - compiler: ": 32-bit + dash" - env: HOST=i686-pc-linux-gnu PACKAGES="g++-multilib bc python-zmq" PPA="ppa:chris-lea/zeromq" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-zmq --enable-glibc-back-compat --enable-reduce-exports LDFLAGS=-static-libstdc++" USE_SHELL="/bin/dash" - - compiler: ": Win64" - env: HOST=x86_64-w64-mingw32 PACKAGES="nsis gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 binutils-mingw-w64-x86-64 mingw-w64-dev wine bc" RUN_TESTS=true GOAL="deploy" BITCOIN_CONFIG="--enable-reduce-exports" MAKEJOBS="-j2" - - compiler: ": bitcoind" - env: HOST=x86_64-unknown-linux-gnu PACKAGES="bc python-zmq" PPA="ppa:chris-lea/zeromq" DEP_OPTS="DEBUG=1" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-zmq --enable-glibc-back-compat --enable-reduce-exports CPPFLAGS=-DDEBUG_LOCKORDER" - - compiler: ": No wallet" - env: HOST=x86_64-unknown-linux-gnu DEP_OPTS="NO_WALLET=1" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat --enable-reduce-exports" - - compiler: ": Cross-Mac" - env: HOST=x86_64-apple-darwin11 PACKAGES="cmake libcap-dev libz-dev libbz2-dev" BITCOIN_CONFIG="--enable-reduce-exports" OSX_SDK=10.9 GOAL="deploy" - exclude: - - compiler: gcc -install: - - if [ -n "$PACKAGES" ]; then sudo rm -f /etc/apt/sources.list.d/travis_ci_zeromq3-source.list; fi - - if [ -n "$PACKAGES" ]; then travis_retry sudo apt-get update; fi - - if [ -n "$PACKAGES" ]; then travis_retry sudo apt-get install --no-install-recommends --no-upgrade -qq $PACKAGES; fi -before_script: - - unset CC; unset CXX - - mkdir -p depends/SDKs depends/sdk-sources - - if [ -n "$OSX_SDK" -a ! -f depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz ]; then curl --location --fail $SDK_URL/MacOSX${OSX_SDK}.sdk.tar.gz -o depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz; fi - - if [ -n "$OSX_SDK" -a -f depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz ]; then tar -C depends/SDKs -xf depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz; fi - - make $MAKEJOBS -C depends HOST=$HOST $DEP_OPTS -script: - - if [ -n "$USE_SHELL" ]; then export CONFIG_SHELL="$USE_SHELL"; fi - - OUTDIR=$BASE_OUTDIR/$TRAVIS_PULL_REQUEST/$TRAVIS_JOB_NUMBER-$HOST - - BITCOIN_CONFIG_ALL="--disable-dependency-tracking --prefix=$TRAVIS_BUILD_DIR/depends/$HOST --bindir=$OUTDIR/bin --libdir=$OUTDIR/lib" - - depends/$HOST/native/bin/ccache --max-size=$CCACHE_SIZE - - if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then export CCACHE_READONLY=1; fi - - test -n "$USE_SHELL" && eval '"$USE_SHELL" -c "./autogen.sh"' || ./autogen.sh - - ./configure --cache-file=config.cache $BITCOIN_CONFIG_ALL $BITCOIN_CONFIG || ( cat config.log && false) - - make distdir PACKAGE=bitcoin VERSION=$HOST - - cd bitcoin-$HOST - - ./configure --cache-file=../config.cache $BITCOIN_CONFIG_ALL $BITCOIN_CONFIG || ( cat config.log && false) - - make $MAKEJOBS $GOAL || ( echo "Build failure. Verbose build follows." && make $GOAL V=1 ; false ) - - export LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/depends/$HOST/lib - - if [ "$RUN_TESTS" = "true" ]; then make check; fi - - if [ "$RUN_TESTS" = "true" ]; then qa/pull-tester/rpc-tests.sh; fi -after_script: - - if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then (echo "Upload goes here. Something like: scp -r $BASE_OUTDIR server" || echo "upload failed"); fi ->>>>>>> zcash/master + - "%{repository}/%{branch} (%{commit} - %{author}): %{message}" + - 'Alt Message : %{repository_slug} - (%{commit} - %{author}): %{message}, Build + Time: %{duration}' + - 'Change view : %{compare_url}' + - 'Build details : %{build_url}' +before_deploy: + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then git tag "linux-$(date +'%Y%m%d%H%M')-$(git log --format=%h -1)"; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then git tag "osx-$(date +'%Y%m%d%H%M')-$(git log --format=%h -1)"; fi +deploy: + provider: releases + api_key: + secure: Jms7dz5GMZmuXUCHl5u6iZUtAybv86oW3x36DCJfdzbDiO4B9EWB04z7zA0qvoomefyujHTmQUHxyOKfd4h9/rVMFFv9hgmUxWkrcg7KyLNisOQRaovVOuNtu2lRNXTOSF16Cy+xFGkVh1ObBRhAoMsVKPhMl6PCDiKhNWIekRR9pBtjafKsClQ2ieknUYfqhuvgj7zmqCedeyVaVQyt2W/J65leD0BkfCUESTpANSprHs4bQB65VuQIKKMi+URKx2VgpDdUcWJySt9jAHVPIbI5cT5maAT6RUMnE4oha7Ca1Ox8StBqjQ/hkkMyDbN0keIlN7RjZlwdZQf/qUnT/dPQhsyUCdPXOxmEJ2jekezEK/LGr4Fb+v+vjd9dhLNkD5nVn9zp36biGSCjiMpffQ3fjMeM0YGmVEVRP9kZXLWVRYQoVKrzjyzg5dY8iChbiQEfYpTeBuU+e2rqj4mns+Jvy0zjUbMy6Tyva+iqdZ/PdsBDbiB7c+FIgB1IUTVOD+GgKx6dhCtBZEccn5EyWFwZF9IdQJHZCYV4PA7nuzfm1Ol9SDdZkGHd2OgRCqK/sTwyfTHv8exNqZ1k+epGJp2a0q4IOEknc9aPCAF+m9pHahk7s7VO5gmhO6pvbvuKoeEtEXRZHRzCkGkXfzJlBk+23X5gBexKb6inRdBlj6M= + file: + - src/komodod + - src/komodo-cli + skip_cleanup: true + on: + repo: KomodoPlatform/komodo diff --git a/COPYING b/COPYING index c84bfb7aa..eecf5ccc8 100644 --- a/COPYING +++ b/COPYING @@ -1,3 +1,4 @@ +Copyright (c) 2016-2018 The Komodo developers Copyright (c) 2016-2017 The Zcash developers Copyright (c) 2009-2017 The Bitcoin Core developers diff --git a/README.md b/README.md index 5d85d013d..e8ed8c3cb 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,34 @@ -## Komodo with Bitcore -This version of Komodo contains Bitcore support for komodo and all its assetchains. +[![Build Status](https://travis-ci.org/KomodoPlatform/komodo.svg?branch=dev)](https://travis-ci.org/KomodoPlatform/komodo) +--- +![Komodo Logo](https://i.imgur.com/vIwVtqv.png "Komodo Logo") -## Komodod -This software is Komodo client, generally you will use this if you want to mine KMD or setup a full node. -It downloads and stores the entire history of Komodo transactions; depending on the speed of your computer and network connection, the synchronization process could take a day or more once the blockchain has reached a significant size. + +## Komodo + +This is the official Komodo sourcecode repository based on https://github.com/jl777/komodo. ## Development Resources -- Komodo Web: [https://komodoplatform.com/](https://komodoplatform.com/) -- Organization web: [https://komodoplatform.com/](https://komodoplatform.com/) + +- Komodo Website: [https://komodoplatform.com/](https://komodoplatform.com/) +- Komodo Blockexplorer: [https://kmdexplorer.io//](https://https://kmdexplorer.io/) - Forum: [https://forum.komodoplatform.com/](https://forum.komodoplatform.com/) - Mail: [info@komodoplatform.com](mailto:info@komodoplatform.com) - Support: [https://support.komodoplatform.com/support/home](https://support.komodoplatform.com/support/home) - Knowledgebase & How-to: [https://komodoplatform.atlassian.net/wiki/spaces/KPSD/pages](https://komodoplatform.atlassian.net/wiki/spaces/KPSD/pages) -- API references: [http://docs.supernet.org/](http://docs.supernet.org/) #Not up to date. +- API references: [http://docs.komodoplatform.com/](http://docs.komodoplatform.com/) +- Blog: [http://blog.komodoplatform.com/](http://blog.komodoplatform.com/) - Whitepaper: [Komodo Whitepaper](https://komodoplatform.com/wp-content/uploads/2018/03/2018-03-12-Komodo-White-Paper-Full.pdf) - Komodo Platform public material: [Komodo Platform public material](https://docs.google.com/document/d/1AbhWrtagu4vYdkl-vsWz-HSNyNvK-W-ZasHCqe7CZy0) ## List of Komodo Platform Technologies -- Delayed Proof of Work (dPoW) - Additional security layer. -- zk-SNARKs - Komodo Platform's privacy technology + +- Delayed Proof of Work (dPoW) - Additional security layer and Komodos own consensus algorithm. +- zk-SNARKs - Komodo Platform's privacy technology for shielded transactions +- Tokens/Assets Technology - create "colored coins" on the Komodo Platform and use them as a layer for securites +- Reward API - Komodo CC technology for securities +- CC - Crypto Conditions to realize "smart contract" logic on top of the Komodo Platform - Jumblr - Decentralized tumbler for KMD and other cryptocurrencies -- Assetchains - Easy way to fork Komodo coin +- Assetchains - Create your own Blockchain that inherits all Komodo Platform functionalities and blockchain interoperability - Pegged Assets - Chains that maintain a peg to fiat currencies - Peerchains - Scalability solution where sibling chains form a network of blockchains - More in depth covered [here](https://docs.google.com/document/d/1AbhWrtagu4vYdkl-vsWz-HSNyNvK-W-ZasHCqe7CZy0) @@ -31,77 +39,76 @@ It downloads and stores the entire history of Komodo transactions; depending on - Max Supply: 200 million KMD. - Block Time: 1M 2s - Block Reward: 3KMD -- Mining Algorithm: Equihash +- Mining Algorithm: Equihash ## About this Project -Komodo is based on Zcash and has been by our innovative consensus algorithm called dPoW which utilizes Bitcoin's hashrate to store Komodo blockchain information into the Bitcoin blockchain. Other new and native Komodo features are the privacy technology called JUMBLR or our assetchain capabilities (one click plug and play blockchain solutions). More details are available under https://komodoplatform.com/. +Komodo is based on Zcash and has been extended by our innovative consensus algorithm called dPoW which utilizes Bitcoin's hashrate to store Komodo blockchain information into the Bitcoin blockchain. Other new and native Komodo features are the privacy technology called JUMBLR, our assetchain capabilities (one click plug and play blockchain solutions) and a set of financial decentralization and interoperability technologies. More details are available under https://komodoplatform.com/ and https://blog.komodoplatform.com. ## Getting started -Dependencies ------------- + +### Dependencies ```shell #The following packages are needed: sudo apt-get install build-essential pkg-config libc6-dev m4 g++-multilib autoconf libtool ncurses-dev unzip git python python-zmq zlib1g-dev wget libcurl4-openssl-dev bsdmainutils automake curl ``` -Komodo ------- -We have a release process that goes through several stages before it reaches master. This allows the most conservative users just use the master branch, which is only updated after the other branches have signed off on a release. +### Build Komodo -99% of the activity is in the dev branch, this is where I am testing each change one by one and there are literally thousands of updates. Only use this branch if you really want to be on the bleeding edge. I try to keep things stable, but there are times where necessarily there are bugs in the dev branch, since I am actively developing and debugging here. A good rule is to wait for at least 4 hours from the last update before using the dev branch (unless you know what you are doing) +This software is based on zcash and considered experimental and is continously undergoing heavy development. -After things look good in the dev branch, it is propagated to the beta branch, this is the version the notary nodes use. They are knowledegable command line server guys and so they have a keen eye for anything that wasnt caught during the dev cycle. - -After the notary nodes verify things are working and the latest release is deemed stable, it is propagated to the dPoW branch. From here an automated Jenkins process builds it for all OS, and since the notary nodes are all unix, it is possible for some issues to be caught at this stage. The dPoW branch is what goes into the GUI installers. - -After the GUI are updated and released and it is verified that no significant support issues were created, the master branch is finally updated. - -Master branch: exchanges and users that build from the repo without changing branches -dPoW branch: autobuild into GUI installers, unix, osx, windows -beta branch: notary nodes, command line unix -dev branch: bleeding edge, possibly wont even compile, multiple updates per hour +The dev branch is considered the bleeding edge codebase while the master-branch is considered tested (unit tests, runtime tests, functionality). At no point of time do the Komodo Platform developers take any responsbility for any damage out of the usage of this software. +Komodo builds for all operating systems out of the same codebase. Follow the OS specific instructions from below. +#### Linux ```shell -git clone https://github.com/jl777/komodo +git clone https://github.com/komodoplatform/komodo --branch master --single-branch cd komodo -#you might want to: git checkout ; git pull ./zcutil/fetch-params.sh -# -j8 uses 8 threads - replace 8 with number of threads you want to use +# -j8 = using 8 threads for the compilation - replace 8 with number of threads you want to use ./zcutil/build.sh -j8 #This can take some time. ``` +#### OSX +Ensure you have [brew](https://brew.sh) and the command line tools installed (comes automatically with XCode) and run: +```shell +brew update && brew install gcc@6 +git clone https://github.com/komodoplatform/komodo --branch master --single-branch +cd komodo +./zcutil/fetch-params.sh +# -j8 = using 8 threads for the compilation - replace 8 with number of threads you want to use +./zcutil/build-mac.sh -j8 +#This can take some time. +``` + +#### Windows +Use a debian cross-compilation setup with mingw for windows and run: +```shell +git clone https://github.com/komodoplatform/komodo --branch master --single-branch +cd komodo +./zcutil/fetch-params.sh +# -j8 = using 8 threads for the compilation - replace 8 with number of threads you want to use +./zcutil/build-win.sh -j8 +#This can take some time. +``` **komodo is experimental and a work-in-progress.** Use at your own risk. -Deprecation Policy ------------------- +To reset the Komodo blockchain change into the *~/.komodo* data directory and delete the corresponding files by running `rm -rf blocks chainstate debug.log komodostate db.log` -This release is considered deprecated one year after the release day. There -is an automatic deprecation shutdown feature which will halt the node some -time after this one year period. The automatic feature is based on block -height and can be explicitly disabled. +#### Create komodo.conf - -# to update an existing version, `git checkout dPoW` if not on that branch already -```shell -git pull -./zcutil/fetch-params.sh -./zcutil/build.sh -j8 -``` -To reset the blockchain, from *~/.komodo* `rm -rf blocks chainstate debug.log komodostate db.log` - -Create komodo.conf ------------------- +Create a komodo.conf file: ``` -cd ~ -mkdir .komodo -cd .komodo -pico komodo.conf +mkdir ~/.komodo +cd ~/.komodo +touch komodo.conf + #Add the following lines to the komodo.conf file: -rpcuser=bitcoinrpc -rpcpassword=password +rpcuser=yourrpcusername +rpcpassword=yoursecurerpcpassword +rpcbind=127.0.0.1 txindex=1 addnode=5.9.102.210 addnode=78.47.196.146 @@ -111,58 +118,22 @@ addnode=5.9.122.241 addnode=144.76.94.38 addnode=89.248.166.91 ``` +### Create your own Blockchain based on Komodo -Start mining ------------- +Komodo allows anyone to create a runtime fork which represents an independent Blockchain. Below are the detailed instructions: +Setup two independent servers with at least 1 server having a static IP and build komodod on those servers. +#### On server 1 (with static IP) run: ```shell -#iguana documentation shows how to get the btcpubkey and wifstrs that need to be used -#bitcoin also need to be installed with txindex=1 and with rpc enabled -cd ~ -cd komodo -#This will return your pubkey eg. "0259e137e5594cf8287195d13aed816af75bd5c04ae673296b51f66e7e8346e8d8" for your address -./src/komodo-cli validateaddress -#This will give the privkey of your wallet address -./src/komodo-cli dumpprivkey -#This will import the privkey to be sure the mined coins are placed into your wallet address -./src/komodo-cli importprivkey -#To stop the daemon: -./src/komodo-cli stop -#This starts komodo notary - replace genproclimit with number of threads you want to use and add your pubkey -./src/komodod -gen -genproclimit=2 -notary -pubkey="0259e137e5594cf8287195d13aed816af75bd5c04ae673296b51f66e7e8346e8d8" & -#This will get the stats: -./src/komodo-cli getinfo -#To view the process: -ps -ef | grep komodod -#To stop the daemon: -./src/komodo-cli stop - -#To view komodod output: -tail -f ~/.komodo/debug.log -#To view all command -./src/komodo-cli help -ASSETCHAINS: -ac_name=name -ac_supply=nnnnn -Both komodod and komodo-cli recognize -ac_name=option so you can create fork from the commandline +./komodod -ac_name=name_of_your_chain -ac_supply=100000 -bind=ip_of_server_1 & ``` -======= -**Zcash is unfinished and highly experimental.** Use at your own risk. -Where do I begin? ------------------ -We have a guide for joining the main Zcash network: -https://github.com/zcash/zcash/wiki/1.0-User-Guide +#### On server 2 run: +```shell +./komodod -ac_name=name_of_your_chain -ac_supply=100000 -addnode=ip_of_server_1 -gen & +``` -### Need Help? -* See the documentation at the [Zcash Wiki](https://github.com/zcash/zcash/wiki) -for help and more information. -* Ask for help on the [Zcash](https://forum.z.cash/) forum. -Participation in the Zcash project is subject to a -[Code of Conduct](code_of_conduct.md). - -Building --------- -Build Zcash along with most dependencies from source by running -`./zcutil/build.sh`. Currently only Linux is officially supported. +**Komodo is based on Zcash which is unfinished and highly experimental.** Use at your own risk. License ------- @@ -175,11 +146,8 @@ There is a small chance that an outbound transaction will give an error due to m **To change modes:** a) backup all privkeys (launch komodod with `-exportdir=` and `dumpwallet`) - b) start a totally new sync including `wallet.dat`, launch with same `exportdir` - c) stop it before it gets too far and import all the privkeys from a) using `komodo-cli importwallet filename` - d) resume sync till it gets to chaintip For example: @@ -191,44 +159,11 @@ mv ~/.komodo ~/.komodo.old && mkdir ~/.komodo && cp ~/.komodo.old/komodo.conf ~/ ./komodod -exchange -exportdir=/tmp & ./komodo-cli importwallet /tmp/example ``` - -## JUMBLR -komodod now has `jumblr_deposit` and `jumblr_secret` RPC calls. - -Jumblr works like described previously where all the nodes with jumblr active synchronize their tx activity during the same block to maximize the mixing effect. However, unlike all other mixers/tumblers, you never give up control of your coins to anybody else. JUMBLR uses a one to many allocation of funds, ie. one deposit address and many secret addresses. You can always run multiple komodod daemons to get multiple active deposit addresses. - -JUMBLR implements t -> z, z -> z and z -> t transactions to maximize privacy of the destination t (transparent) address. So while it is transparent, its first activity is funds coming from an untracable z address. - -Which of the three stages is done is randomly selected at each turn. Also when there is more than one possible transaction at the selected stage, a random one is selected. This randomization prevents analyzing incoming z ->t transactions by its size to correlate it to the originating address. - -`jumblr_deposit ` designates the deposit address as the jumblr deposit address for that session. You can select an address that already has funds in it and it will immediately start jumblr process. If there are no funds, it will wait until you send funds to it. - -There are three sizes of a jumblr transaction: 10 KMD, 100 KMD and 1000 KMD. There is also a fixed interval of blocks where all jumblr nodes are active. Currently it is set to be 10, but this is subject to change. Only during every 10*10 blocks are the largest 1000 KMD transactions processed, so this concentrates all the large transactions every N*N blocks. - -`jumblr_secret ` notifies JUMBLR where to send the final z -> t transactions. In order to allow larger accounts to obtain privacy, up to 777 secret addresses are supported. Whenever a z -> t stage is activated, a random secret address from the list of the then active secret addresses is selected. - -#### Practical Advice: -Obtaining privacy used to be very difficult. JUMBLR makes it as simple as issuing two command line calls. Higher level layers can be added to help manage the addresses, ie. linking them at the passphrase level. Such matters are left to each implementation. - -Once obtained, it is very easy to lose all the privacy. With a single errant transaction that combines some previously used address and the secretaddress, well, the secretaddress is no longer so private. - -The advice is to setup a totally separate node! - -This might seem a bit drastic, but if you want to maintain privacy, it is best to make it look like all the transactions are coming from a different node. The easiest way for most people to do this is to actually have a different node. - -It can be a dedicated laptop (recommended) or a VPS (for smaller amounts) with a totally fresh komodod wallet. Generate an address on this wallet and use that as the jumblr_secret address on your main node. As the JUMBLR operates funds will teleport into your secret node's address. If you are careful and never use the same IP address for both your nodes, you will be able to maintain very good privacy. - -Of course, don't send emails that link the two accounts together! Dont use secret address funds for home delivery purchases! Etc. There are many ways to lose the privacy, just think about what linkages can be dont at the IP and blockchain level and that should be a useful preparation. - -What if you have 100,000 KMD and you dont want others to know you are such a whale? -Instead of generating 1 secret address, generate 100 and make a script file with: -```shell -./komodo-cli jumblr_secret -./komodo-cli jumblr_secret -... -./komodo-cli jumblr_secret -``` -And make sure to delete all traces of this when the JUMBLR is finished. You will end up with 100 addresses that have an average of 1000 KMD each. So as long as you are careful and dont do a 10,000 KMD transaction (that will link 10 of your secret addresses together), you can appear as 100 different people each with 1000 KMD. +--- +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/contrib/debian/examples/komodo.conf b/contrib/debian/examples/komodo.conf new file mode 100644 index 000000000..656a43533 --- /dev/null +++ b/contrib/debian/examples/komodo.conf @@ -0,0 +1,140 @@ +## +## komodo.conf configuration file. Lines beginning with # are comments. +## + +# Network-related settings: + +# Run a regression test network +#regtest=0 + +# Connect via a SOCKS5 proxy +#proxy=127.0.0.1:9050 + +# Bind to given address and always listen on it. Use [host]:port notation for IPv6 +#bind= + +# Bind to given address and whitelist peers connecting to it. Use [host]:port notation for IPv6 +#whitebind= + +############################################################## +## Quick Primer on addnode vs connect ## +## Let's say for instance you use addnode=4.2.2.4 ## +## addnode will connect you to and tell you about the ## +## nodes connected to 4.2.2.4. In addition it will tell ## +## the other nodes connected to it that you exist so ## +## they can connect to you. ## +## connect will not do the above when you 'connect' to it. ## +## It will *only* connect you to 4.2.2.4 and no one else.## +## ## +## So if you're behind a firewall, or have other problems ## +## finding nodes, add some using 'addnode'. ## +## ## +## If you want to stay private, use 'connect' to only ## +## connect to "trusted" nodes. ## +## ## +## If you run multiple nodes on a LAN, there's no need for ## +## all of them to open lots of connections. Instead ## +## 'connect' them all to one node that is port forwarded ## +## and has lots of connections. ## +## Thanks goes to [Noodle] on Freenode. ## +############################################################## + +# Use as many addnode= settings as you like to connect to specific peers +#addnode=69.164.218.197 +#addnode=10.0.0.2:8233 + +# Alternatively use as many connect= settings as you like to connect ONLY to specific peers +#connect=69.164.218.197 +#connect=10.0.0.1:8233 + +# Listening mode, enabled by default except when 'connect' is being used +#listen=1 + +# Maximum number of inbound+outbound connections. +#maxconnections= + +# +# JSON-RPC options (for controlling a running Komodo/komodod process) +# + +# server=1 tells komodod to accept JSON-RPC commands (set as default if not specified) +#server=1 + +# Bind to given address to listen for JSON-RPC connections. Use [host]:port notation for IPv6. +# This option can be specified multiple times (default: bind to all interfaces) +#rpcbind= + +# You must set rpcuser and rpcpassword to secure the JSON-RPC api +#rpcuser=Ulysses +#rpcpassword=YourSuperGreatPasswordNumber_DO_NOT_USE_THIS_OR_YOU_WILL_GET_ROBBED_385593 + +# How many seconds komodo will wait for a complete RPC HTTP request. +# after the HTTP connection is established. +#rpcclienttimeout=30 + +# By default, only RPC connections from localhost are allowed. +# Specify as many rpcallowip= settings as you like to allow connections from other hosts, +# either as a single IPv4/IPv6 or with a subnet specification. + +# NOTE: opening up the RPC port to hosts outside your local trusted network is NOT RECOMMENDED, +# because the rpcpassword is transmitted over the network unencrypted and also because anyone +# that can authenticate on the RPC port can steal your keys + take over the account running komodod +# For more information see https://github.com/zcash/zcash/issues/1497 + +#rpcallowip=10.1.1.34/255.255.255.0 +#rpcallowip=1.2.3.4/24 +#rpcallowip=2001:db8:85a3:0:0:8a2e:370:7334/96 + +# Listen for RPC connections on this TCP port: +#rpcport=8232 + +# You can use Komodo or komodod to send commands to Komodo/komodod +# running on another host using this option: +#rpcconnect=127.0.0.1 + +# Transaction Fee + +# Send transactions as zero-fee transactions if possible (default: 0) +#sendfreetransactions=0 + +# Create transactions that have enough fees (or priority) so they are likely to # begin confirmation within n blocks (default: 1). +# This setting is overridden by the -paytxfee option. +#txconfirmtarget=n + +# Miscellaneous options + +# Enable attempt to mine komodo. +#gen=0 + +# Set the number of threads to be used for mining komodo (-1 = all cores). +#genproclimit=1 + +# Specify a different Equihash solver (e.g. "tromp") to try to mine komodo +# faster when gen=1. +#equihashsolver=default + +# Pre-generate this many public/private key pairs, so wallet backups will be valid for +# both prior transactions and several dozen future transactions. +#keypool=100 + +# Pay an optional transaction fee every time you send komodo. Transactions with fees +# are more likely than free transactions to be included in generated blocks, so may +# be validated sooner. This setting does not affect private transactions created with +# 'z_sendmany'. +#paytxfee=0.00 + +#Rewind the chain to specific block height. This is useful for creating snapshots at a given block height. +#rewind=777777 + +#Stop the chain a specific block height. This is useful for creating snapshots at a given block height. +#stopat=1000000 + +#Set an address to use as change address for all transactions. This value must be set to a 33 byte pubkey. All mined coins will also be sent to this address. +#pubkey=027dc7b5cfb5efca96674b45e9fda18df069d040b9fd9ff32c35df56005e330392 + +#Forfeit all user rewards to miners. Set this to explicitly not claim user rewards. +#exchange=1 + +#Donate all user rewards to a a specific address. This value must be set to a 33 byte pubkey. +#donation=027dc7b5cfb5efca96674b45e9fda18df069d040b9fd9ff32c35df56005e330392 + diff --git a/depends/packages/googletest.mk b/depends/packages/googletest.mk index 1275593f5..409c83a1b 100644 --- a/depends/packages/googletest.mk +++ b/depends/packages/googletest.mk @@ -1,6 +1,6 @@ package=googletest $(package)_version=1.8.0 -$(package)_download_path=https://github.com/google/$(package)/archive/ +$(package)_download_path=https://github.com/google/$(package)/archive $(package)_file_name=$(package)-$($(package)_version).tar.gz $(package)_download_file=release-$($(package)_version).tar.gz $(package)_sha256_hash=58a6f4277ca2bc8565222b3bbd58a177609e9c488e8a72649359ba51450db7d8 diff --git a/depends/packages/libevent.mk b/depends/packages/libevent.mk index 2a1125fda..ffe6f7e79 100644 --- a/depends/packages/libevent.mk +++ b/depends/packages/libevent.mk @@ -1,6 +1,6 @@ package=libevent $(package)_version=2.1.8 -$(package)_download_path=https://github.com/libevent/libevent/archive/ +$(package)_download_path=https://github.com/libevent/libevent/archive $(package)_file_name=$(package)-$($(package)_version).tar.gz $(package)_download_file=release-$($(package)_version)-stable.tar.gz $(package)_sha256_hash=316ddb401745ac5d222d7c529ef1eada12f58f6376a66c1118eee803cb70f83d diff --git a/depends/packages/libgmp.mk b/depends/packages/libgmp.mk index d8e41573a..c62fa18ed 100644 --- a/depends/packages/libgmp.mk +++ b/depends/packages/libgmp.mk @@ -1,7 +1,7 @@ package=libgmp ifeq ($(host_os),mingw32) -$(package)_download_path=https://github.com/joshuayabut/$(package)/archive/ +$(package)_download_path=https://github.com/joshuayabut/$(package)/archive $(package)_file_name=$(package)-$($(package)_git_commit).tar.gz $(package)_download_file=$($(package)_git_commit).tar.gz $(package)_sha256_hash=193836c1acc9dc00fe2521205d7bbe1ba13263f6cbef6f02584bf6f8b34b108f @@ -9,7 +9,7 @@ $(package)_git_commit=053c03b1cab347671d936f43ef66b48ab5e380ee $(package)_dependencies= $(package)_config_opts=--enable-cxx --disable-shared else ifeq ($(build_os),darwin) -$(package)_download_path=https://github.com/ca333/$(package)/archive/ +$(package)_download_path=https://github.com/ca333/$(package)/archive $(package)_file_name=$(package)-$($(package)_git_commit).tar.gz $(package)_download_file=$($(package)_git_commit).tar.gz $(package)_sha256_hash=59b2c2b5d58fdf5943bfde1fa709e9eb53e7e072c9699d28dc1c2cbb3c8cc32c diff --git a/depends/packages/librustzcash.mk b/depends/packages/librustzcash.mk index 20126776a..689082f8f 100644 --- a/depends/packages/librustzcash.mk +++ b/depends/packages/librustzcash.mk @@ -1,6 +1,6 @@ package=librustzcash $(package)_version=0.1 -$(package)_download_path=https://github.com/zcash/$(package)/archive/ +$(package)_download_path=https://github.com/zcash/$(package)/archive $(package)_file_name=$(package)-$($(package)_git_commit).tar.gz $(package)_download_file=$($(package)_git_commit).tar.gz $(package)_sha256_hash=a5760a90d4a1045c8944204f29fa2a3cf2f800afee400f88bf89bbfe2cce1279 diff --git a/depends/packages/libsodium.mk b/depends/packages/libsodium.mk index efa5d90de..67e096fae 100644 --- a/depends/packages/libsodium.mk +++ b/depends/packages/libsodium.mk @@ -9,7 +9,7 @@ $(package)_config_opts= else package=libsodium $(package)_version=1.0.15 -$(package)_download_path=https://download.libsodium.org/libsodium/releases/ +$(package)_download_path=https://download.libsodium.org/libsodium/releases $(package)_file_name=$(package)-$($(package)_version).tar.gz $(package)_sha256_hash=fb6a9e879a2f674592e4328c5d9f79f082405ee4bb05cb6e679b90afe9e178f4 $(package)_dependencies= diff --git a/depends/packages/zeromq.mk b/depends/packages/zeromq.mk index 850cce778..66e491ffb 100644 --- a/depends/packages/zeromq.mk +++ b/depends/packages/zeromq.mk @@ -1,6 +1,6 @@ ifeq ($(host_os),mingw32) $(package)_version=4.2.2-1 -$(package)_download_path=https://github.com/ca333/libzmq/archive/ +$(package)_download_path=https://github.com/ca333/libzmq/archive $(package)_download_file=v$($(package)_version).tar.gz $(package)_file_name=libzmq-$($(package)_version).tar.gz $(package)_sha256_hash=0e225b85ce11be23bf7eb7d3f25c6686728bf30d5c31f61c12d37bb646c69962 diff --git a/migratecoin.sh b/migratecoin.sh new file mode 100644 index 000000000..6cd09ba04 --- /dev/null +++ b/migratecoin.sh @@ -0,0 +1,43 @@ +#!/usr/bin/bash + +# This script makes the neccesary transactions to migrate +# coin between 2 assetchains on the same -ac_cc id + +set -e + +source=TXSCL +target=TXSCL000 +address="RFw7byY4xZpZCrtkMk3nFuuG1NTs9rSGgQ" +amount=1 + +# Alias for running cli on source chain +cli_source="komodo-cli -ac_name=$source" + +# Raw tx that we will work with +txraw=`$cli_source createrawtransaction "[]" "{\"$address\":$amount}"` + +# Convert to an export tx +exportData=`$cli_source migrate_converttoexport $txraw $target $amount` +exportRaw=`echo $exportData | jq -r .exportTx` +exportPayouts=`echo $exportData | jq -r .payouts` + +# Fund +exportFundedData=`$cli_source fundrawtransaction $exportRaw` +exportFundedTx=`echo $exportFundedData | jq -r .hex` + +# Sign +exportSignedData=`$cli_source signrawtransaction $exportFundedTx` +exportSignedTx=`echo $exportSignedData | jq -r .hex` + +# Send +echo "Sending export tx" +$cli_source sendrawtransaction $exportSignedTx + +read -p "Wait for a notarisation to KMD, and then two more notarisations from the target chain, and then press enter to continue" + +# Create import +importTx=`$cli_source migrate_createimporttransaction $exportSignedTx $payouts` +importTx=`komodo-cli migrate_completeimporttransaction $importTx` + +# Send import +komodo-cli -ac_name=$target sendrawtransaction $importTx diff --git a/qa/pull-tester/rpc-tests.sh b/qa/pull-tester/rpc-tests.sh index 50de39f64..fb4ff99a7 100755 --- a/qa/pull-tester/rpc-tests.sh +++ b/qa/pull-tester/rpc-tests.sh @@ -11,6 +11,7 @@ export BITCOIND=${REAL_BITCOIND} #Run the tests testScripts=( + 'cryptoconditions.py' 'paymentdisclosure.py' 'prioritisetransaction.py' 'wallet_treestate.py' diff --git a/qa/pull-tester/tests-config.sh.in b/qa/pull-tester/tests-config.sh.in index cc76e8ad8..8d9467f3f 100755 --- a/qa/pull-tester/tests-config.sh.in +++ b/qa/pull-tester/tests-config.sh.in @@ -13,6 +13,6 @@ EXEEXT="@EXEEXT@" @ENABLE_ZMQ_TRUE@ENABLE_ZMQ=1 @ENABLE_PROTON_TRUE@ENABLE_PROTON=1 -REAL_BITCOIND="$BUILDDIR/src/zcashd${EXEEXT}" -REAL_BITCOINCLI="$BUILDDIR/src/zcash-cli${EXEEXT}" +REAL_BITCOIND="$BUILDDIR/src/komodod${EXEEXT}" +REAL_BITCOINCLI="$BUILDDIR/src/komodo-cli${EXEEXT}" diff --git a/qa/rpc-tests/README.md b/qa/rpc-tests/README.md index a0229b56d..17aee1967 100644 --- a/qa/rpc-tests/README.md +++ b/qa/rpc-tests/README.md @@ -18,9 +18,9 @@ Possible options: ``` -h, --help show this help message and exit - --nocleanup Leave bitcoinds and test.* datadir on exit or error - --noshutdown Don't stop bitcoinds after the test execution - --srcdir=SRCDIR Source directory containing bitcoind/bitcoin-cli (default: + --nocleanup Leave komodods and test.* datadir on exit or error + --noshutdown Don't stop komodods after the test execution + --srcdir=SRCDIR Source directory containing komodod/komodo-cli (default: ../../src) --tmpdir=TMPDIR Root directory for datadirs --tracerpc Print out all RPC calls as they are made @@ -31,7 +31,7 @@ If you set the environment variable `PYTHON_DEBUG=1` you will get some debug out A 200-block -regtest blockchain and wallets for four nodes is created the first time a regression test is run and is stored in the cache/ directory. Each node has the miner -subsidy from 25 mature blocks (25*10=250 ZEC) in its wallet. +subsidy from 25 mature blocks (25*10=250 KMD) in its wallet. After the first run, the cache/ blockchain and wallets are copied into a temporary directory and used as the initial @@ -42,5 +42,5 @@ to recover with: ```bash rm -rf cache -killall zcashd +killall komodod ``` diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py new file mode 100755 index 000000000..fbd650a8e --- /dev/null +++ b/qa/rpc-tests/cryptoconditions.py @@ -0,0 +1,605 @@ +#!/usr/bin/env python2 +# Copyright (c) 2018 SuperNET developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +from test_framework.test_framework import BitcoinTestFramework +from test_framework.authproxy import JSONRPCException +from test_framework.util import assert_equal, assert_greater_than, \ + initialize_chain_clean, initialize_chain, start_nodes, start_node, connect_nodes_bi, \ + stop_nodes, sync_blocks, sync_mempools, wait_bitcoinds, rpc_port, assert_raises + +import time +from decimal import Decimal + +def assert_success(result): + assert_equal(result['result'], 'success') + +def assert_error(result): + assert_equal(result['result'], 'error') + +class CryptoConditionsTest (BitcoinTestFramework): + + def setup_chain(self): + print("Initializing CC test directory "+self.options.tmpdir) + self.num_nodes = 1 + initialize_chain_clean(self.options.tmpdir, self.num_nodes) + + def setup_network(self, split = False): + print("Setting up network...") + self.addr = "RWPg8B91kfK5UtUN7z6s6TeV9cHSGtVY8D" + self.pubkey = "02676d00110c2cd14ae24f95969e8598f7ccfaa675498b82654a5b5bd57fc1d8cf" + self.privkey = "UqMgxk7ySPNQ4r9nKAFPjkXy6r5t898yhuNCjSZJLg3RAM4WW1m9" + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, + extra_args=[[ + # always give -ac_name as first extra_arg + '-ac_name=REGTEST', + '-conf='+self.options.tmpdir+'/node0/REGTEST.conf', + '-port=64367', + '-rpcport=64368', + '-regtest', + '-addressindex=1', + '-spentindex=1', + '-ac_supply=5555555', + '-ac_reward=10000000', + '-pubkey=' + self.pubkey, + '-ac_cc=2', + '-whitelist=127.0.0.1', + '-debug', + '-daemon', + '-rpcuser=rt', + '-rpcpassword=rt' + ]] + ) + self.is_network_split = split + self.rpc = self.nodes[0] + self.sync_all() + print("Done setting up network") + + def send_and_mine(self, xtn): + txid = self.rpc.sendrawtransaction(xtn) + assert txid, 'got txid' + # we need the tx above to be confirmed in the next block + self.rpc.generate(1) + return txid + + def run_faucet_tests(self): + rpc = self.rpc + + # basic sanity tests + result = rpc.getwalletinfo() + assert_greater_than(result['txcount'], 100) + assert_greater_than(result['balance'], 0.0) + balance = result['balance'] + + faucet = rpc.faucetaddress() + assert_equal(faucet['result'], 'success') + # verify all keys look like valid AC addrs, could be better + for x in ['myCCaddress', 'FaucetCCaddress', 'Faucetmarker', 'myaddress']: + assert_equal(faucet[x][0], 'R') + + result = rpc.faucetaddress(self.pubkey) + assert_success(result) + # test that additional CCaddress key is returned + for x in ['myCCaddress', 'FaucetCCaddress', 'Faucetmarker', 'myaddress', 'CCaddress']: + assert_equal(result[x][0], 'R') + + # no funds in the faucet yet + result = rpc.faucetget() + assert_error(result) + + result = rpc.faucetinfo() + assert_success(result) + + result = rpc.faucetfund("0") + assert_error(result) + + result = rpc.faucetfund("-1") + assert_error(result) + + # we need at least 1 + txfee to get + result = rpc.faucetfund("2") + assert_success(result) + assert result['hex'], "hex key found" + + # broadcast the xtn + result = rpc.sendrawtransaction(result['hex']) + txid = result[0] + assert txid, "found txid" + + # we need the tx above to be confirmed in the next block + rpc.generate(1) + + result = rpc.getwalletinfo() + balance2 = result['balance'] + # make sure our balance is less now + assert_greater_than(balance, balance2) + + result = rpc.faucetinfo() + assert_success(result) + assert_greater_than( result['funding'], 0 ) + + result = rpc.faucetget() + assert_success(result) + assert result['hex'], "hex key found" + + # try to broadcast the xtn, but we will get 'faucet is only for brand new addresses' + assert_raises(JSONRPCException, rpc.sendrawtransaction, [ result['hex'] ]) + + newaddr = rpc.getnewaddress() + assert newaddr, "got a new address" + result = rpc.validateaddress(newaddr) + newpubkey = result['pubkey'] + assert newpubkey, "got a pubkey for new address" + + def run_dice_tests(self): + rpc = self.nodes[0] + + dice = rpc.diceaddress() + assert_equal(dice['result'], 'success') + for x in ['myCCaddress', 'DiceCCaddress', 'Dicemarker', 'myaddress']: + assert_equal(dice[x][0], 'R') + + dice = rpc.diceaddress(self.pubkey) + assert_equal(dice['result'], 'success') + for x in ['myCCaddress', 'DiceCCaddress', 'Dicemarker', 'myaddress', 'CCaddress']: + assert_equal(dice[x][0], 'R') + + # no dice created yet + result = rpc.dicelist() + assert_equal(result, []) + + # creating dice plan with too long name (>8 chars) + result = rpc.dicefund("THISISTOOLONG", "10000", "10", "10000", "10", "5") + assert_error(result) + + # creating dice plan with < 100 funding + result = rpc.dicefund("LUCKY","10","1","10000","10","5") + assert_error(result) + + # creating dice plan with 0 blocks timeout + result = rpc.dicefund("LUCKY","10","1","10000","10","0") + assert_error(result) + + # creating dice plan + dicefundtx = rpc.dicefund("LUCKY","1000","1","800","10","5") + diceid = self.send_and_mine(dicefundtx['hex']) + + # checking if it in plans list now + result = rpc.dicelist() + assert_equal(result[0], diceid) + + # set dice name for futher usage + dicename = "LUCKY" + + # adding zero funds to plan + result = rpc.diceaddfunds(dicename,diceid,"0") + assert_error(result) + + # adding negative funds to plan + result = rpc.diceaddfunds(dicename,diceid,"-1") + assert_error(result) + + # adding funds to plan + addfundstx = rpc.diceaddfunds(dicename,diceid,"1100") + result = self.send_and_mine(addfundstx['hex']) + + # checking if funds added to plan + result = rpc.diceinfo(diceid) + assert_equal(result["funding"], "2100.00000000") + + # not valid dice info checking + result = rpc.diceinfo("invalid") + assert_error(result) + + # placing 0 amount bet + result = rpc.dicebet(dicename,diceid,"0","1") + assert_error(result) + + # placing negative amount bet + result = rpc.dicebet(dicename,diceid,"-1","1") + assert_error(result) + + # placing bet more than maxbet + result = rpc.dicebet(dicename,diceid,"900","1") + assert_error(result) + + # placing bet with amount more than funding + result = rpc.dicebet(dicename,diceid,"3000","1") + assert_error(result) + + # placing bet with potential won more than funding + result = rpc.dicebet(dicename,diceid,"750","9") + assert_error(result) + + # placing 0 odds bet + result = rpc.dicebet(dicename,diceid,"1","0") + assert_error(result) + + # placing negative odds bet + result = rpc.dicebet(dicename,diceid,"1","-1") + assert_error(result) + + # placing bet with odds more than allowed + result = rpc.dicebet(dicename,diceid,"1","11") + assert_error(result) + + # placing bet with not correct dice name + result = rpc.dicebet("nope",diceid,"100","1") + assert_error(result) + + # placing bet with not correct dice id + result = rpc.dicebet(dicename,self.pubkey,"100","1") + assert_error(result) + + # valid bet placing + placebet = rpc.dicebet(dicename,diceid,"100","1") + betid = self.send_and_mine(placebet["hex"]) + assert result, "bet placed" + + # check bet status + result = rpc.dicestatus(dicename,diceid,betid) + assert_success(result) + + # have to make some entropy for the next test + entropytx = 0 + fundingsum = 1 + while entropytx < 10: + fundingsuminput = str(fundingsum) + fundinghex = rpc.diceaddfunds(dicename,diceid,fundingsuminput) + result = self.send_and_mine(fundinghex['hex']) + entropytx = entropytx + 1 + fundingsum = fundingsum + 1 + + rpc.generate(2) + + # note initial dice funding state at this point. + # TODO: track player balance somehow (hard to do because of mining and fees) + diceinfo = rpc.diceinfo(diceid) + funding = float(diceinfo['funding']) + + # placing same amount bets with amount 1 and odds 1:2, checking if balance changed correct + losscounter = 0 + wincounter = 0 + betcounter = 0 + + while (betcounter < 10): + placebet = rpc.dicebet(dicename,diceid,"1","1") + betid = self.send_and_mine(placebet["hex"]) + finish = rpc.dicefinish(dicename,diceid,betid) + self.send_and_mine(finish["hex"]) + betresult = rpc.dicestatus(dicename,diceid,betid) + betcounter = betcounter + 1 + if betresult["status"] == "loss": + losscounter = losscounter + 1 + elif betresult["status"] == "win": + wincounter = wincounter + 1 + + # funding balance should increase if player loss, decrease if player won + fundbalanceguess = funding + losscounter - wincounter + fundinfoactual = rpc.diceinfo(diceid) + assert_equal(round(fundbalanceguess),round(float(fundinfoactual['funding']))) + + def run_token_tests(self): + rpc = self.nodes[0] + result = rpc.tokenaddress() + assert_success(result) + for x in ['AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress']: + assert_equal(result[x][0], 'R') + + result = rpc.tokenaddress(self.pubkey) + assert_success(result) + for x in ['AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress', 'CCaddress']: + assert_equal(result[x][0], 'R') + # there are no tokens created yet + result = rpc.tokenlist() + assert_equal(result, []) + + # trying to create token with negaive supply + result = rpc.tokencreate("NUKE", "-1987420", "no bueno supply") + assert_error(result) + + # creating token with name more than 32 chars + result = rpc.tokencreate("NUKE123456789012345678901234567890", "1987420", "name too long") + assert_error(result) + + # creating valid token + result = rpc.tokencreate("DUKE", "1987.420", "Duke's custom token") + assert_success(result) + + tokenid = self.send_and_mine(result['hex']) + + result = rpc.tokenlist() + assert_equal(result[0], tokenid) + + # there are no token orders yet + result = rpc.tokenorders() + assert_equal(result, []) + + # getting token balance for pubkey + result = rpc.tokenbalance(self.pubkey) + assert_success(result) + assert_equal(result['balance'], 0) + assert_equal(result['CCaddress'], 'RCRsm3VBXz8kKTsYaXKpy7pSEzrtNNQGJC') + assert_equal(result['tokenid'], self.pubkey) + + # get token balance for token with pubkey + result = rpc.tokenbalance(tokenid, self.pubkey) + assert_success(result) + assert_equal(result['balance'], 198742000000) + assert_equal(result['tokenid'], tokenid) + + # get token balance for token without pubkey + result = rpc.tokenbalance(tokenid) + assert_success(result) + assert_equal(result['balance'], 198742000000) + assert_equal(result['tokenid'], tokenid) + + # this is not a valid assetid + result = rpc.tokeninfo(self.pubkey) + assert_error(result) + + # check tokeninfo for valid token + result = rpc.tokeninfo(tokenid) + assert_success(result) + assert_equal(result['tokenid'], tokenid) + assert_equal(result['owner'], self.pubkey) + assert_equal(result['name'], "DUKE") + assert_equal(result['supply'], 198742000000) + assert_equal(result['description'], "Duke's custom token") + + # invalid numtokens ask + result = rpc.tokenask("-1", tokenid, "1") + assert_error(result) + + # invalid numtokens ask + result = rpc.tokenask("0", tokenid, "1") + assert_error(result) + + # invalid price ask + result = rpc.tokenask("1", tokenid, "-1") + assert_error(result) + + # invalid price ask + result = rpc.tokenask("1", tokenid, "0") + assert_error(result) + + # invalid tokenid ask + result = rpc.tokenask("100", "deadbeef", "1") + assert_error(result) + + # valid ask + tokenask = rpc.tokenask("100", tokenid, "7.77") + tokenaskhex = tokenask['hex'] + tokenaskid = self.send_and_mine(tokenask['hex']) + result = rpc.tokenorders() + order = result[0] + assert order, "found order" + + # invalid ask fillunits + result = rpc.tokenfillask(tokenid, tokenaskid, "0") + assert_error(result) + + # invalid ask fillunits + result = rpc.tokenfillask(tokenid, tokenaskid, "-777") + assert_error(result) + + # valid ask fillunits + fillask = rpc.tokenfillask(tokenid, tokenaskid, "777") + result = self.send_and_mine(fillask['hex']) + txid = result[0] + assert txid, "found txid" + + # should be no token orders + result = rpc.tokenorders() + assert_equal(result, []) + + # checking ask cancellation + testorder = rpc.tokenask("100", tokenid, "7.77") + testorderid = self.send_and_mine(testorder['hex']) + cancel = rpc.tokencancelask(tokenid, testorderid) + self.send_and_mine(cancel["hex"]) + result = rpc.tokenorders() + assert_equal(result, []) + + # invalid numtokens bid + result = rpc.tokenbid("-1", tokenid, "1") + assert_error(result) + + # invalid numtokens bid + result = rpc.tokenbid("0", tokenid, "1") + assert_error(result) + + # invalid price bid + result = rpc.tokenbid("1", tokenid, "-1") + assert_error(result) + + # invalid price bid + result = rpc.tokenbid("1", tokenid, "0") + assert_error(result) + + # invalid tokenid bid + result = rpc.tokenbid("100", "deadbeef", "1") + assert_error(result) + + # valid bid + tokenbid = rpc.tokenbid("100", tokenid, "10") + tokenbidhex = tokenbid['hex'] + tokenbidid = self.send_and_mine(tokenbid['hex']) + result = rpc.tokenorders() + order = result[0] + assert order, "found order" + + # invalid bid fillunits + result = rpc.tokenfillbid(tokenid, tokenbidid, "0") + assert_error(result) + + # invalid bid fillunits + result = rpc.tokenfillbid(tokenid, tokenbidid, "-777") + assert_error(result) + + # valid bid fillunits + fillbid = rpc.tokenfillbid(tokenid, tokenbidid, "1000") + result = self.send_and_mine(fillbid['hex']) + txid = result[0] + assert txid, "found txid" + + # should be no token orders + result = rpc.tokenorders() + assert_equal(result, []) + + # checking bid cancellation + testorder = rpc.tokenbid("100", tokenid, "7.77") + testorderid = self.send_and_mine(testorder['hex']) + cancel = rpc.tokencancelbid(tokenid, testorderid) + self.send_and_mine(cancel["hex"]) + result = rpc.tokenorders() + assert_equal(result, []) + + # invalid token transfer amount (have to add status to CC code!) + randompubkey = "021a559101e355c907d9c553671044d619769a6e71d624f68bfec7d0afa6bd6a96" + result = rpc.tokentransfer(tokenid,randompubkey,"0") + assert_error(result) + + # invalid token transfer amount (have to add status to CC code!) + result = rpc.tokentransfer(tokenid,randompubkey,"-1") + assert_error(result) + + # valid token transfer + sendtokens = rpc.tokentransfer(tokenid,randompubkey,"1") + self.send_and_mine(sendtokens["hex"]) + result = rpc.tokenbalance(tokenid,randompubkey) + assert_equal(result["balance"], 1) + + + def run_rewards_tests(self): + rpc = self.nodes[0] + result = rpc.rewardsaddress() + for x in ['RewardsCCaddress', 'myCCaddress', 'Rewardsmarker', 'myaddress']: + assert_equal(result[x][0], 'R') + + result = rpc.rewardsaddress(self.pubkey) + for x in ['RewardsCCaddress', 'myCCaddress', 'Rewardsmarker', 'myaddress', 'CCaddress']: + assert_equal(result[x][0], 'R') + + # no rewards yet + result = rpc.rewardslist() + assert_equal(result, []) + + # looking up non-existent reward should return error + result = rpc.rewardsinfo("none") + assert_error(result) + + # creating rewards plan with name > 8 chars, should return error + result = rpc.rewardscreatefunding("STUFFSTUFF", "7777", "25", "0", "10", "10") + assert_error(result) + + # creating rewards plan with 0 funding + result = rpc.rewardscreatefunding("STUFF", "0", "25", "0", "10", "10") + assert_error(result) + + # creating rewards plan with 0 maxdays + result = rpc.rewardscreatefunding("STUFF", "7777", "25", "0", "10", "0") + assert_error(result) + + # creating rewards plan with > 25% APR + result = rpc.rewardscreatefunding("STUFF", "7777", "30", "0", "10", "10") + assert_error(result) + + # creating valid rewards plan + result = rpc.rewardscreatefunding("STUFF", "7777", "25", "0", "10", "10") + assert result['hex'], 'got raw xtn' + fundingtxid = rpc.sendrawtransaction(result['hex']) + assert fundingtxid, 'got txid' + + # confirm the above xtn + rpc.generate(1) + result = rpc.rewardsinfo(fundingtxid) + assert_success(result) + assert_equal(result['name'], 'STUFF') + assert_equal(result['APR'], "25.00000000") + assert_equal(result['minseconds'], 0) + assert_equal(result['maxseconds'], 864000) + assert_equal(result['funding'], "7777.00000000") + assert_equal(result['mindeposit'], "10.00000000") + assert_equal(result['fundingtxid'], fundingtxid) + + # checking if new plan in rewardslist + result = rpc.rewardslist() + assert_equal(result[0], fundingtxid) + + # creating reward plan with already existing name, should return error + result = rpc.rewardscreatefunding("STUFF", "7777", "25", "0", "10", "10") + assert_error(result) + + # add funding amount must be positive + result = rpc.rewardsaddfunding("STUFF", fundingtxid, "-1") + assert_error(result) + + # add funding amount must be positive + result = rpc.rewardsaddfunding("STUFF", fundingtxid, "0") + assert_error(result) + + # adding valid funding + result = rpc.rewardsaddfunding("STUFF", fundingtxid, "555") + addfundingtxid = self.send_and_mine(result['hex']) + assert addfundingtxid, 'got funding txid' + + # checking if funding added to rewardsplan + result = rpc.rewardsinfo(fundingtxid) + assert_equal(result['funding'], "8332.00000000") + + # trying to lock funds, locking funds amount must be positive + result = rpc.rewardslock("STUFF", fundingtxid, "-5") + assert_error(result) + + # trying to lock funds, locking funds amount must be positive + result = rpc.rewardslock("STUFF", fundingtxid, "0") + assert_error(result) + + # trying to lock less than the min amount is an error + result = rpc.rewardslock("STUFF", fundingtxid, "7") + assert_error(result) + + # locking funds in rewards plan + result = rpc.rewardslock("STUFF", fundingtxid, "10") + assert_success(result) + locktxid = result['hex'] + assert locktxid, "got lock txid" + + # locktxid has not been broadcast yet + result = rpc.rewardsunlock("STUFF", fundingtxid, locktxid) + assert_error(result) + + # broadcast xtn + txid = rpc.sendrawtransaction(locktxid) + assert txid, 'got txid from sendrawtransaction' + + # confirm the xtn above + rpc.generate(1) + + # will not unlock since reward amount is less than tx fee + result = rpc.rewardsunlock("STUFF", fundingtxid, locktxid) + assert_error(result) + + + def run_test (self): + print("Mining blocks...") + rpc = self.nodes[0] + + # utxos from block 1 become mature in block 101 + rpc.generate(101) + self.sync_all() + + # this corresponds to -pubkey above + print("Importing privkey") + rpc.importprivkey(self.privkey) + + self.run_rewards_tests() + self.run_dice_tests() + self.run_token_tests() + self.run_faucet_tests() + + +if __name__ == '__main__': + CryptoConditionsTest ().main () diff --git a/qa/rpc-tests/test_framework/test_framework.py b/qa/rpc-tests/test_framework/test_framework.py index 56151bb3e..f545b4246 100755 --- a/qa/rpc-tests/test_framework/test_framework.py +++ b/qa/rpc-tests/test_framework/test_framework.py @@ -90,11 +90,11 @@ class BitcoinTestFramework(object): parser = optparse.OptionParser(usage="%prog [options]") parser.add_option("--nocleanup", dest="nocleanup", default=False, action="store_true", - help="Leave bitcoinds and test.* datadir on exit or error") + help="Leave komodods and test.* datadir on exit or error") parser.add_option("--noshutdown", dest="noshutdown", default=False, action="store_true", - help="Don't stop bitcoinds after the test execution") + help="Don't stop komodods after the test execution") parser.add_option("--srcdir", dest="srcdir", default="../../src", - help="Source directory containing bitcoind/bitcoin-cli (default: %default)") + help="Source directory containing komodod/komodo-cli (default: %default)") parser.add_option("--tmpdir", dest="tmpdir", default=tempfile.mkdtemp(prefix="test"), help="Root directory for datadirs") parser.add_option("--tracerpc", dest="trace_rpc", default=False, action="store_true", @@ -137,7 +137,7 @@ class BitcoinTestFramework(object): stop_nodes(self.nodes) wait_bitcoinds() else: - print("Note: bitcoinds were not stopped and may still be running") + print("Note: komodods were not stopped and may still be running") if not self.options.nocleanup and not self.options.noshutdown: print("Cleaning up") @@ -151,7 +151,7 @@ class BitcoinTestFramework(object): sys.exit(1) -# Test framework for doing p2p comparison testing, which sets up some bitcoind +# Test framework for doing p2p comparison testing, which sets up some komodod # binaries: # 1 binary: test binary # 2 binaries: 1 test binary, 1 ref binary @@ -165,10 +165,10 @@ class ComparisonTestFramework(BitcoinTestFramework): def add_options(self, parser): parser.add_option("--testbinary", dest="testbinary", - default=os.getenv("BITCOIND", "bitcoind"), + default=os.getenv("BITCOIND", "komodod"), help="bitcoind binary to test") parser.add_option("--refbinary", dest="refbinary", - default=os.getenv("BITCOIND", "bitcoind"), + default=os.getenv("BITCOIND", "komodod"), help="bitcoind binary to use for reference nodes (if any)") def setup_chain(self): diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index f3ea481ee..5cb0d1b10 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -1,4 +1,5 @@ # Copyright (c) 2014 The Bitcoin Core developers +# Copyright (c) 2018 The SuperNET developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -75,38 +76,55 @@ def initialize_datadir(dirname, n): datadir = os.path.join(dirname, "node"+str(n)) if not os.path.isdir(datadir): os.makedirs(datadir) - with open(os.path.join(datadir, "zcash.conf"), 'w') as f: + # kmd AC's don't use this, they use the conf auto-created when the AC is created + # plus CLI arguments. This is for komodod tests + print("Writing to " + os.path.join(datadir,"komodo.conf")) + with open(os.path.join(datadir, "komodo.conf"), 'w') as f: f.write("regtest=1\n"); + f.write("txindex=1\n"); + f.write("server=1\n"); f.write("showmetrics=0\n"); f.write("rpcuser=rt\n"); f.write("rpcpassword=rt\n"); - f.write("port="+str(p2p_port(n))+"\n"); - f.write("rpcport="+str(rpc_port(n))+"\n"); + #f.write("port="+str(p2p_port(n))+"\n"); + #rpcport = str(rpc_port(n)) + #f.write("rpcport="+rpcport+"\n"); + #print "RPC port=" + rpcport f.write("listenonion=0\n"); + # TODO: maybe make these optional, defaulted to on for now + f.write("addressindex=1\n"); + f.write("spentindex=1\n"); + f.write("timestampindex=1\n"); return datadir def initialize_chain(test_dir): """ Create (or copy from cache) a 200-block-long chain and 4 wallets. - bitcoind and bitcoin-cli must be in search path. + komodod and komodo-cli must be in search path. """ + print("initialize_chain") if not os.path.isdir(os.path.join("cache", "node0")): devnull = open("/dev/null", "w+") - # Create cache directories, run bitcoinds: + # Create cache directories, run komodods: for i in range(4): datadir=initialize_datadir("cache", i) - args = [ os.getenv("BITCOIND", "bitcoind"), "-keypool=1", "-datadir="+datadir, "-discover=0" ] + args = [ os.getenv("BITCOIND", "komodod"), "-keypool=1", "-datadir="+datadir, "-discover=0" ] if i > 0: args.append("-connect=127.0.0.1:"+str(p2p_port(0))) bitcoind_processes[i] = subprocess.Popen(args) + cmd = os.getenv("BITCOINCLI", "komodo-cli") + cmd_args = cmd + " -datadir="+datadir + " -rpcwait getblockcount" if os.getenv("PYTHON_DEBUG", ""): - print "initialize_chain: bitcoind started, calling bitcoin-cli -rpcwait getblockcount" - subprocess.check_call([ os.getenv("BITCOINCLI", "bitcoin-cli"), "-datadir="+datadir, - "-rpcwait", "getblockcount"], stdout=devnull) + print "initialize_chain: komodod started, calling: " + cmd_args + strcmd = cmd + " " + "-datadir="+datadir + " -rpcwait getblockcount" + + print("Running " + strcmd) + subprocess.check_call(strcmd, shell=True); + #subprocess.check_call([ cmd, "-rpcwait", "getblockcount"], stdout=devnull) if os.getenv("PYTHON_DEBUG", ""): - print "initialize_chain: bitcoin-cli -rpcwait getblockcount completed" + print "initialize_chain: komodo-cli -rpcwait getblockcount completed" devnull.close() rpcs = [] for i in range(4): @@ -144,7 +162,7 @@ def initialize_chain(test_dir): from_dir = os.path.join("cache", "node"+str(i)) to_dir = os.path.join(test_dir, "node"+str(i)) shutil.copytree(from_dir, to_dir) - initialize_datadir(test_dir, i) # Overwrite port/rpcport in zcash.conf + initialize_datadir(test_dir, i) # Overwrite port/rpcport in komodo.conf def initialize_chain_clean(test_dir, num_nodes): """ @@ -177,34 +195,50 @@ def _rpchost_to_args(rpchost): def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=None): """ - Start a bitcoind and return RPC connection to it + Start a komodod and return RPC connection to it """ datadir = os.path.join(dirname, "node"+str(i)) if binary is None: - binary = os.getenv("BITCOIND", "bitcoind") + binary = os.getenv("BITCOIND", "komodod") args = [ binary, "-datadir="+datadir, "-keypool=1", "-discover=0", "-rest" ] if extra_args is not None: args.extend(extra_args) + #print("args=" + ' '.join(args)) bitcoind_processes[i] = subprocess.Popen(args) devnull = open("/dev/null", "w+") + + cmd = os.getenv("BITCOINCLI", "komodo-cli") + print("cmd=" + cmd) + cmd_args = ' '.join(extra_args) + " -rpcwait getblockcount " if os.getenv("PYTHON_DEBUG", ""): - print "start_node: bitcoind started, calling bitcoin-cli -rpcwait getblockcount" - subprocess.check_call([ os.getenv("BITCOINCLI", "bitcoin-cli"), "-datadir="+datadir] + - _rpchost_to_args(rpchost) + - ["-rpcwait", "getblockcount"], stdout=devnull) + print "start_node: komodod started, calling : " + cmd + " " + cmd_args + strcmd = cmd + " " + cmd_args + + print("Running " + strcmd) + import time + time.sleep(2) + subprocess.check_call(strcmd, shell=True); + #subprocess.check_call([ os.getenv("BITCOINCLI", "komodo-cli"), "-datadir="+datadir] + + # _rpchost_to_args(rpchost) + + # ["-rpcwait", "-rpcport=6438", "getblockcount"], stdout=devnull) if os.getenv("PYTHON_DEBUG", ""): - print "start_node: calling bitcoin-cli -rpcwait getblockcount returned" + print "start_node: calling komodo-cli -rpcwait getblockcount returned" devnull.close() - url = "http://rt:rt@%s:%d" % (rpchost or '127.0.0.1', rpc_port(i)) + if extra_args[0] == '-ac_name=REGTEST': + url = "http://rt:rt@%s:%d" % (rpchost or '127.0.0.1', 64368) + else: + url = "http://rt:rt@%s:%d" % (rpchost or '127.0.0.1', rpc_port(i)) + print("connecting to " + url) if timewait is not None: proxy = AuthServiceProxy(url, timeout=timewait) else: proxy = AuthServiceProxy(url) + print("created proxy") proxy.url = url # store URL on proxy for info return proxy def start_nodes(num_nodes, dirname, extra_args=None, rpchost=None, binary=None): """ - Start multiple bitcoinds, return RPC connections to them + Start multiple komodods, return RPC connections to them """ if extra_args is None: extra_args = [ None for i in range(num_nodes) ] if binary is None: binary = [ None for i in range(num_nodes) ] diff --git a/src/Makefile.am b/src/Makefile.am index a1232968d..8b10c06e0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -256,11 +256,22 @@ libbitcoin_server_a_SOURCES = \ asyncrpcqueue.cpp \ bloom.cpp \ cc/eval.cpp \ - cc/importpayout.cpp \ - cc/disputepayout.cpp \ + cc/import.cpp \ + cc/CCassetsCore.cpp \ + cc/CCcustom.cpp \ + cc/CCtx.cpp \ + cc/CCutils.cpp \ + cc/assets.cpp \ + cc/faucet.cpp \ + cc/rewards.cpp \ + cc/dice.cpp \ + cc/lotto.cpp \ + cc/fsm.cpp \ + cc/auction.cpp \ cc/betprotocol.cpp \ chain.cpp \ checkpoints.cpp \ + crosschain.cpp \ deprecation.cpp \ httprpc.cpp \ httpserver.cpp \ @@ -272,12 +283,14 @@ libbitcoin_server_a_SOURCES = \ miner.cpp \ net.cpp \ noui.cpp \ + notarisationdb.cpp \ paymentdisclosure.cpp \ paymentdisclosuredb.cpp \ policy/fees.cpp \ pow.cpp \ rest.cpp \ rpcblockchain.cpp \ + rpccrosschain.cpp \ rpcmining.cpp \ rpcmisc.cpp \ rpcnet.cpp \ @@ -331,6 +344,8 @@ libbitcoin_wallet_a_SOURCES = \ paymentdisclosuredb.cpp \ wallet/rpcdisclosure.cpp \ wallet/rpcdump.cpp \ + cc/CCassetstx.cpp \ + cc/CCtx.cpp \ wallet/rpcwallet.cpp \ wallet/wallet.cpp \ wallet/wallet_ismine.cpp \ @@ -385,6 +400,7 @@ libbitcoin_common_a_SOURCES = \ core_read.cpp \ core_write.cpp \ hash.cpp \ + importcoin.cpp \ key.cpp \ keystore.cpp \ netbase.cpp \ @@ -605,7 +621,7 @@ endif libzcashconsensus_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS) libzcashconsensus_la_LIBADD = $(LIBSECP256K1) -libzcashconsensus_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -DBUILD_BITCOIN_INTERNAL +libzcashconsensus_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -I$(srcdir)/cryptoconditions/include -DBUILD_BITCOIN_INTERNAL libzcashconsensus_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) endif diff --git a/src/Makefile.ktest.include b/src/Makefile.ktest.include index 06aab54dc..07c64caa0 100644 --- a/src/Makefile.ktest.include +++ b/src/Makefile.ktest.include @@ -5,9 +5,13 @@ bin_PROGRAMS += komodo-test # tool for generating our public parameters komodo_test_SOURCES = \ test-komodo/main.cpp \ + test-komodo/testutils.cpp \ test-komodo/test_cryptoconditions.cpp \ + test-komodo/test_coinimport.cpp \ test-komodo/test_eval_bet.cpp \ - test-komodo/test_eval_notarisation.cpp + test-komodo/test_eval_notarisation.cpp \ + test-komodo/test_crosschain.cpp \ + test-komodo/test_parse_notarisation.cpp komodo_test_CPPFLAGS = $(komodod_CPPFLAGS) diff --git a/src/Makefile.test.include b/src/Makefile.test.include index ff270bd6a..a52b66335 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -45,7 +45,6 @@ BITCOIN_TESTS =\ test/arith_uint256_tests.cpp \ test/bignum.h \ test/addrman_tests.cpp \ - test/alert_tests.cpp \ test/allocator_tests.cpp \ test/base32_tests.cpp \ test/base58_tests.cpp \ diff --git a/src/ac/ccl b/src/ac/ccl new file mode 100755 index 000000000..c3d03a0a4 --- /dev/null +++ b/src/ac/ccl @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=CCL $1 $2 $3 $4 $5 $6 diff --git a/src/assetchains b/src/assetchains index ec77fba28..57e705d5c 100755 --- a/src/assetchains +++ b/src/assetchains @@ -1,59 +1,19 @@ #!/bin/bash +set -eo pipefail + +# You can now add delay line to pubkey.txt file source pubkey.txt -args=("$@") +overide_args="$@" seed_ip=`getent hosts zero.kolo.supernet.org | awk '{ print $1 }'` -komodo_binary='./komodod' -delay=20 -function komodo_asset () -{ - if [ $[RANDOM % 10] == 1 ] - then - gen=" -gen" - else - gen="" - fi +if [ -z "$delay" ]; then delay=20; fi - if [ -n "$2" ] - then - supply=" -ac_supply=$2" - else - supply=" " - fi +./listassetchainparams | while read args; do + gen="" + if [ $[RANDOM % 10] == 1 ]; then + gen=" -gen" + fi - $komodo_binary -ac_name=$1 $gen $supply $args -pubkey=$pubkey -addnode=$seed_ip & - sleep $delay -} - -#set -x - -komodo_asset REVS 1300000 -komodo_asset SUPERNET 816061 -komodo_asset DEX 999999 -komodo_asset PANGEA 999999 -komodo_asset JUMBLR 999999 -komodo_asset BET 999999 -komodo_asset CRYPTO 999999 -komodo_asset HODL 9999999 -komodo_asset MSHARK 1400000 -komodo_asset BOTS 999999 -komodo_asset MGW 999999 -komodo_asset COQUI 72000000 -komodo_asset WLC 210000000 -komodo_asset KV 1000000 -komodo_asset CEAL 366666666 -komodo_asset MESH 1000007 -komodo_asset MNZ 257142858 -komodo_asset AXO 200000000 -komodo_asset ETOMIC 100000000 -komodo_asset BTCH 20998641 -komodo_asset PIZZA 100000000 -komodo_asset BEER 100000000 -komodo_asset NINJA 100000000 -komodo_asset OOT 216000000 -komodo_asset BNTN 500000000 -komodo_asset CHAIN 999999 -komodo_asset PRLPAY 500000000 -komodo_asset DSEC 7000000 -komodo_asset GLXT 100000000 -komodo_asset EQL 500000000 + ./komodod $gen $args $overide_args -pubkey=$pubkey -addnode=$seed_ip & + sleep $delay +done diff --git a/src/assetchains.json b/src/assetchains.json new file mode 100644 index 000000000..b74d953a0 --- /dev/null +++ b/src/assetchains.json @@ -0,0 +1,146 @@ +[ + { + "ac_name": "REVS", + "ac_supply": "1300000" + }, + { + "ac_name": "SUPERNET", + "ac_supply": "816061" + }, + { + "ac_name": "DEX", + "ac_supply": "999999" + }, + { + "ac_name": "PANGEA", + "ac_supply": "999999" + }, + { + "ac_name": "JUMBLR", + "ac_supply": "999999" + }, + { + "ac_name": "BET", + "ac_supply": "999999" + }, + { + "ac_name": "CRYPTO", + "ac_supply": "999999" + }, + { + "ac_name": "HODL", + "ac_supply": "9999999" + }, + { + "ac_name": "MSHARK", + "ac_supply": "1400000" + }, + { + "ac_name": "BOTS", + "ac_supply": "999999" + }, + { + "ac_name": "MGW", + "ac_supply": "999999" + }, + { + "ac_name": "COQUI", + "ac_supply": "72000000" + }, + { + "ac_name": "WLC", + "ac_supply": "210000000" + }, + { + "ac_name": "KV", + "ac_supply": "1000000" + }, + { + "ac_name": "CEAL", + "ac_supply": "366666666" + }, + { + "ac_name": "MESH", + "ac_supply": "1000007" + }, + { + "ac_name": "MNZ", + "ac_supply": "257142858" + }, + { + "ac_name": "AXO", + "ac_supply": "200000000" + }, + { + "ac_name": "ETOMIC", + "ac_supply": "100000000" + }, + { + "ac_name": "BTCH", + "ac_supply": "20998641" + }, + { + "ac_name": "PIZZA", + "ac_supply": "100000000" + }, + { + "ac_name": "BEER", + "ac_supply": "100000000" + }, + { + "ac_name": "NINJA", + "ac_supply": "100000000" + }, + { + "ac_name": "OOT", + "ac_supply": "216000000" + }, + { + "ac_name": "BNTN", + "ac_supply": "500000000" + }, + { + "ac_name": "CHAIN", + "ac_supply": "999999" + }, + { + "ac_name": "PRLPAY", + "ac_supply": "500000000" + }, + { + "ac_name": "DSEC", + "ac_supply": "7000000" + }, + { + "ac_name": "GLXT", + "ac_supply": "10000000000" + }, + { + "ac_name": "EQL", + "ac_supply": "500000000" + }, + { + "ac_name": "ZILLA", + "ac_supply": "11000000" + }, + { + "ac_name": "RFOX", + "ac_supply": "1000000000", + "ac_reward": "100000000" + }, + { + "ac_name": "SEC", + "ac_supply": "1000000000", + "ac_cc": "333" + }, + { + "ac_name": "CCL", + "ac_supply": "200000000", + "ac_end": "1", + "ac_cc": "2", + "addressindex": "1", + "spentindex": "1", + "addnode": "142.93.136.89", + "addnode": "195.201.22.89" + } +] diff --git a/src/assetchains.old b/src/assetchains.old index af9361746..d7a18811d 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -32,7 +32,10 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=CHAIN -ac_supply=999999 -addnode=78.47.146.222 & ./komodod -pubkey=$pubkey -ac_name=PRLPAY -ac_supply=500000000 -addnode=13.250.226.125 & ./komodod -pubkey=$pubkey -ac_name=DSEC -ac_supply=7000000 -addnode=185.148.147.30 & -./komodod -pubkey=$pubkey -ac_name=GLXT -ac_supply=100000000 -addnode=13.230.224.15 & +./komodod -pubkey=$pubkey -ac_name=GLXT -ac_supply=10000000000 -addnode=13.230.224.15 & ./komodod -pubkey=$pubkey -ac_name=EQL -ac_supply=500000000 -addnode=46.101.124.153 & -~/VerusCoin/src/komodod -ac_name=VRSC -ac_algo=verushash -ac_cc=1 -ac_veruspos=50 -ac_supply=0 -ac_eras=3 -ac_reward=0,38400000000,2400000000 -ac_halving=1,43200,1051920 -ac_decay=100000000,0,0 -ac_end=10080,226080,0 -ac_timelockgte=19200000000 -ac_timeunlockfrom=129600 -ac_timeunlockto=1180800 -addnode=185.25.48.236 -addnode=185.64.105.111 & - +./komodod -pubkey=$pubkey -ac_name=ZILLA -ac_supply=11000000 -addnode=54.39.23.248 & +./komodod -pubkey=$pubkey -ac_name=RFOX -ac_supply=1000000000 -ac_reward=100000000 -addnode=78.47.196.146 & +~/VerusCoin/src/komodod -pubkey=$pubkey -ac_name=VRSC -ac_algo=verushash -ac_cc=1 -ac_veruspos=50 -ac_supply=0 -ac_eras=3 -ac_reward=0,38400000000,2400000000 -ac_halving=1,43200,1051920 -ac_decay=100000000,0,0 -ac_end=10080,226080,0 -ac_timelockgte=19200000000 -ac_timeunlockfrom=129600 -ac_timeunlockto=1180800 -addnode=185.25.48.236 -addnode=185.64.105.111 & +./komodod -pubkey=$pubkey -ac_name=SEC -ac_cc=333 -ac_supply=1000000000 -addnode=185.148.145.43 & +./komodod -pubkey=$pubkey -ac_name=CCL -ac_supply=200000000 -ac_end=1 -ac_cc=2 -addressindex=1 -spentindex=1 -addnode=142.93.136.89 -addnode=195.201.22.89 & diff --git a/src/assetchains_stop b/src/assetchains_stop index e55231b1a..60549dc20 100755 --- a/src/assetchains_stop +++ b/src/assetchains_stop @@ -1,40 +1,6 @@ #!/bin/bash -args=("$@") -komodo_cli='./komodo-cli' -delay=20 +set -eo pipefail -function komodo_stop () -{ - $komodo_cli --ac_name=$1 stop -} - -#set -x - -komodo_stop REVS -komodo_stop SUPERNET -komodo_stop DEX -komodo_stop PANGEA -komodo_stop JUMBLR -komodo_stop BET -komodo_stop CRYPTO -komodo_stop HODL -komodo_stop MSHARK -komodo_stop BOTS -komodo_stop MGW -komodo_stop COQUI -komodo_stop WLC -komodo_stop KV -komodo_stop CEAL -komodo_stop MESH -komodo_stop MNZ -komodo_stop AXO -komodo_stop ETOMIC -komodo_stop BTCH -komodo_stop PIZZA -komodo_stop BEER -komodo_stop NINJA -komodo_stop OOT -komodo_stop BNTN -komodo_stop CHAIN -komodo_stop PRLPAY -komodo_stop DSEC +./listassetchains | while read chain; do + ./komodo-cli --ac_name=$chain stop +done diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 5c12cfa2f..36fea57bf 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -144,21 +144,21 @@ bool AppInit(int argc, char* argv[]) ReadConfigFile(mapArgs, mapMultiArgs); } catch (const missing_zcash_conf& e) { fprintf(stderr, - (_("Before starting zcashd, you need to create a configuration file:\n" + (_("Before starting komodod, you need to create a configuration file:\n" "%s\n" "It can be completely empty! That indicates you are happy with the default\n" - "configuration of zcashd. But requiring a configuration file to start ensures\n" - "that zcashd won't accidentally compromise your privacy if there was a default\n" + "configuration of komodod. But requiring a configuration file to start ensures\n" + "that komodod won't accidentally compromise your privacy if there was a default\n" "option you needed to change.\n" "\n" "You can look at the example configuration file for suggestions of default\n" "options that you may want to change. It should be in one of these locations,\n" - "depending on how you installed Zcash:\n") + + "depending on how you installed Komodo:\n") + _("- Source code: %s\n" "- .deb package: %s\n")).c_str(), GetConfigFile().string().c_str(), - "contrib/debian/examples/zcash.conf", - "/usr/share/doc/zcash/examples/zcash.conf"); + "contrib/debian/examples/komodo.conf", + "/usr/share/doc/komodo/examples/komodo.conf"); return false; } catch (const std::exception& e) { fprintf(stderr,"Error reading configuration file: %s\n", e.what()); diff --git a/src/cc/CCassets.h b/src/cc/CCassets.h new file mode 100644 index 000000000..9a0f2a0ea --- /dev/null +++ b/src/cc/CCassets.h @@ -0,0 +1,65 @@ +/****************************************************************************** + * Copyright © 2014-2018 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + + +/* + CCassetstx has the functions that create the EVAL_ASSETS transactions. It is expected that rpc calls would call these functions. For EVAL_ASSETS, the rpc functions are in rpcwallet.cpp + + CCassetsCore has functions that are used in two contexts, both during rpc transaction create time and also during the blockchain validation. Using the identical functions is a good way to prevent them from being mismatched. The must match or the transaction will get rejected. + */ + +#ifndef CC_ASSETS_H +#define CC_ASSETS_H + +#include "CCinclude.h" + +// CCcustom +bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); + +// CCassetsCore +//CTxOut MakeAssetsVout(CAmount nValue,CPubKey pk); +CScript EncodeAssetCreateOpRet(uint8_t funcid,std::vector origpubkey,std::string name,std::string description); +CScript EncodeAssetOpRet(uint8_t funcid,uint256 assetid,uint256 assetid2,int64_t price,std::vector origpubkey); +bool DecodeAssetCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description); +uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey); +bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CTransaction &tx); +int64_t IsAssetvout(int64_t &price,std::vector &origpubkey,const CTransaction& tx,int32_t v,uint256 refassetid); +bool ValidateBidRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); +bool ValidateAskRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); +bool ValidateSwapRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); +bool SetBidFillamounts(int64_t &paid,int64_t &remaining_price,int64_t orig_nValue,int64_t &received,int64_t totalprice); +bool SetAskFillamounts(int64_t &paid,int64_t &remaining_price,int64_t orig_nValue,int64_t &received,int64_t totalprice); +bool SetSwapFillamounts(int64_t &paid,int64_t &remaining_price,int64_t orig_nValue,int64_t &received,int64_t totalprice); +int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 refassetid); +int64_t AssetValidateSellvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 assetid); +bool AssetExactAmounts(struct CCcontract_info *cp,int64_t &inputs,int32_t starti,int64_t &outputs,Eval* eval,const CTransaction &tx,uint256 assetid); + +// CCassetstx +int64_t GetAssetBalance(CPubKey pk,uint256 tokenid); +int64_t AddAssetInputs(CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs); +UniValue AssetOrders(uint256 tokenid); +UniValue AssetInfo(uint256 tokenid); +UniValue AssetList(); +std::string CreateAsset(int64_t txfee,int64_t assetsupply,std::string name,std::string description); +std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total); +std::string CreateBuyOffer(int64_t txfee,int64_t bidamount,uint256 assetid,int64_t pricetotal); +std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid); +std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t fillamount); +std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t pricetotal); +std::string CreateSwap(int64_t txfee,int64_t askamount,uint256 assetid,uint256 assetid2,int64_t pricetotal); +std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid); +std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 asktxid,int64_t fillamount); + +#endif diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp new file mode 100644 index 000000000..9ef08348e --- /dev/null +++ b/src/cc/CCassetsCore.cpp @@ -0,0 +1,484 @@ +/****************************************************************************** + * Copyright © 2014-2018 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#include "CCassets.h" + +/* + The SetAssetFillamounts() and ValidateAssetRemainder() work in tandem to calculate the vouts for a fill and to validate the vouts, respectively. + + This pair of functions are critical to make sure the trading is correct and is the trickiest part of the assets contract. + + //vin.0: normal input + //vin.1: unspendable.(vout.0 from buyoffer) buyTx.vout[0] + //vin.2+: valid CC output satisfies buyoffer (*tx.vin[2])->nValue + //vout.0: remaining amount of bid to unspendable + //vout.1: vin.1 value to signer of vin.2 + //vout.2: vin.2 assetoshis to original pubkey + //vout.3: CC output for assetoshis change (if any) + //vout.4: normal output for change (if any) + //vout.n-1: opreturn [EVAL_ASSETS] ['B'] [assetid] [remaining asset required] [origpubkey] + ValidateAssetRemainder(remaining_price,tx.vout[0].nValue,nValue,tx.vout[1].nValue,tx.vout[2].nValue,totalunits); + + Yes, this is quite confusing... + + In ValudateAssetRemainder the naming convention is nValue is the coin/asset with the offer on the books and "units" is what it is being paid in. The high level check is to make sure we didnt lose any coins or assets, the harder to validate is the actual price paid as the "orderbook" is in terms of the combined nValue for the combined totalunits. + + We assume that the effective unit cost in the orderbook is valid and that that amount was paid and also that any remainder will be close enough in effective unit cost to not matter. At the edge cases, this will probably be not true and maybe some orders wont be practically fillable when reduced to fractional state. However, the original pubkey that created the offer can always reclaim it. +*/ + +bool ValidateBidRemainder(int64_t remaining_units,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidunits,int64_t totalunits) +{ + int64_t unitprice,recvunitprice,newunitprice=0; + if ( orig_nValue == 0 || received_nValue == 0 || paidunits == 0 || totalunits == 0 ) + { + fprintf(stderr,"ValidateAssetRemainder: orig_nValue == %llu || received_nValue == %llu || paidunits == %llu || totalunits == %llu\n",(long long)orig_nValue,(long long)received_nValue,(long long)paidunits,(long long)totalunits); + return(false); + } + else if ( totalunits != (remaining_units + paidunits) ) + { + fprintf(stderr,"ValidateAssetRemainder: totalunits %llu != %llu (remaining_units %llu + %llu paidunits)\n",(long long)totalunits,(long long)(remaining_units + paidunits),(long long)remaining_units,(long long)paidunits); + return(false); + } + else if ( orig_nValue != (remaining_nValue + received_nValue) ) + { + fprintf(stderr,"ValidateAssetRemainder: orig_nValue %llu != %llu (remaining_nValue %llu + %llu received_nValue)\n",(long long)orig_nValue,(long long)(remaining_nValue - received_nValue),(long long)remaining_nValue,(long long)received_nValue); + return(false); + } + else + { + //unitprice = (orig_nValue * COIN) / totalunits; + //recvunitprice = (received_nValue * COIN) / paidunits; + //if ( remaining_units != 0 ) + // newunitprice = (remaining_nValue * COIN) / remaining_units; + unitprice = (orig_nValue / totalunits); + recvunitprice = (received_nValue / paidunits); + if ( remaining_units != 0 ) + newunitprice = (remaining_nValue / remaining_units); + if ( recvunitprice < unitprice ) + { + fprintf(stderr,"error recvunitprice %.16f < %.16f unitprice, new unitprice %.16f\n",(double)recvunitprice/(COIN),(double)unitprice/(COIN),(double)newunitprice/(COIN)); + return(false); + } + fprintf(stderr,"orig %llu total %llu, recv %llu paid %llu,recvunitprice %.16f >= %.16f unitprice, new unitprice %.16f\n",(long long)orig_nValue,(long long)totalunits,(long long)received_nValue,(long long)paidunits,(double)recvunitprice/(COIN),(double)unitprice/(COIN),(double)newunitprice/(COIN)); + } + return(true); +} + +bool SetBidFillamounts(int64_t &received_nValue,int64_t &remaining_units,int64_t orig_nValue,int64_t &paidunits,int64_t totalunits) +{ + int64_t remaining_nValue,unitprice; double dprice; + if ( totalunits == 0 ) + { + received_nValue = remaining_units = paidunits = 0; + return(false); + } + if ( paidunits >= totalunits ) + { + paidunits = totalunits; + received_nValue = orig_nValue; + remaining_units = 0; + fprintf(stderr,"totally filled!\n"); + return(true); + } + remaining_units = (totalunits - paidunits); + //unitprice = (orig_nValue * COIN) / totalunits; + //received_nValue = (paidunits * unitprice) / COIN; + unitprice = (orig_nValue / totalunits); + received_nValue = (paidunits * unitprice); + if ( unitprice > 0 && received_nValue > 0 && received_nValue <= orig_nValue ) + { + remaining_nValue = (orig_nValue - received_nValue); + printf("total.%llu - paid.%llu, remaining %llu <- %llu (%llu - %llu)\n",(long long)totalunits,(long long)paidunits,(long long)remaining_nValue,(long long)(orig_nValue - received_nValue),(long long)orig_nValue,(long long)received_nValue); + return(ValidateBidRemainder(remaining_units,remaining_nValue,orig_nValue,received_nValue,paidunits,totalunits)); + } else return(false); +} + +bool SetAskFillamounts(int64_t &received_assetoshis,int64_t &remaining_nValue,int64_t orig_assetoshis,int64_t &paid_nValue,int64_t total_nValue) +{ + int64_t remaining_assetoshis; double dunitprice; + if ( total_nValue == 0 ) + { + received_assetoshis = remaining_nValue = paid_nValue = 0; + return(false); + } + if ( paid_nValue >= total_nValue ) + { + paid_nValue = total_nValue; + received_assetoshis = orig_assetoshis; + remaining_nValue = 0; + fprintf(stderr,"totally filled!\n"); + return(true); + } + remaining_nValue = (total_nValue - paid_nValue); + dunitprice = ((double)total_nValue / orig_assetoshis); + received_assetoshis = (paid_nValue / dunitprice); + fprintf(stderr,"remaining_nValue %.8f (%.8f - %.8f)\n",(double)remaining_nValue/COIN,(double)total_nValue/COIN,(double)paid_nValue/COIN); + fprintf(stderr,"unitprice %.8f received_assetoshis %llu orig %llu\n",dunitprice/COIN,(long long)received_assetoshis,(long long)orig_assetoshis); + if ( fabs(dunitprice) > SMALLVAL && received_assetoshis > 0 && received_assetoshis <= orig_assetoshis ) + { + remaining_assetoshis = (orig_assetoshis - received_assetoshis); + return(ValidateAskRemainder(remaining_nValue,remaining_assetoshis,orig_assetoshis,received_assetoshis,paid_nValue,total_nValue)); + } else return(false); +} + +bool ValidateAskRemainder(int64_t remaining_nValue,int64_t remaining_assetoshis,int64_t orig_assetoshis,int64_t received_assetoshis,int64_t paid_nValue,int64_t total_nValue) +{ + int64_t unitprice,recvunitprice,newunitprice=0; + if ( orig_assetoshis == 0 || received_assetoshis == 0 || paid_nValue == 0 || total_nValue == 0 ) + { + fprintf(stderr,"ValidateAssetRemainder: orig_assetoshis == %llu || received_assetoshis == %llu || paid_nValue == %llu || total_nValue == %llu\n",(long long)orig_assetoshis,(long long)received_assetoshis,(long long)paid_nValue,(long long)total_nValue); + return(false); + } + else if ( total_nValue != (remaining_nValue + paid_nValue) ) + { + fprintf(stderr,"ValidateAssetRemainder: total_nValue %llu != %llu (remaining_nValue %llu + %llu paid_nValue)\n",(long long)total_nValue,(long long)(remaining_nValue + paid_nValue),(long long)remaining_nValue,(long long)paid_nValue); + return(false); + } + else if ( orig_assetoshis != (remaining_assetoshis + received_assetoshis) ) + { + fprintf(stderr,"ValidateAssetRemainder: orig_assetoshis %llu != %llu (remaining_nValue %llu + %llu received_nValue)\n",(long long)orig_assetoshis,(long long)(remaining_assetoshis - received_assetoshis),(long long)remaining_assetoshis,(long long)received_assetoshis); + return(false); + } + else + { + unitprice = (total_nValue / orig_assetoshis); + recvunitprice = (paid_nValue / received_assetoshis); + if ( remaining_nValue != 0 ) + newunitprice = (remaining_nValue / remaining_assetoshis); + if ( recvunitprice < unitprice ) + { + fprintf(stderr,"error recvunitprice %.8f < %.8f unitprice, new unitprice %.8f\n",(double)recvunitprice/COIN,(double)unitprice/COIN,(double)newunitprice/COIN); + return(false); + } + fprintf(stderr,"got recvunitprice %.8f >= %.8f unitprice, new unitprice %.8f\n",(double)recvunitprice/COIN,(double)unitprice/COIN,(double)newunitprice/COIN); + } + return(true); +} + +bool SetSwapFillamounts(int64_t &received_assetoshis,int64_t &remaining_assetoshis2,int64_t orig_assetoshis,int64_t &paid_assetoshis2,int64_t total_assetoshis2) +{ + int64_t remaining_assetoshis; double dunitprice; + if ( total_assetoshis2 == 0 ) + { + fprintf(stderr,"total_assetoshis2.0 origsatoshis.%llu paid_assetoshis2.%llu\n",(long long)orig_assetoshis,(long long)paid_assetoshis2); + received_assetoshis = remaining_assetoshis2 = paid_assetoshis2 = 0; + return(false); + } + if ( paid_assetoshis2 >= total_assetoshis2 ) + { + paid_assetoshis2 = total_assetoshis2; + received_assetoshis = orig_assetoshis; + remaining_assetoshis2 = 0; + fprintf(stderr,"totally filled!\n"); + return(true); + } + remaining_assetoshis2 = (total_assetoshis2 - paid_assetoshis2); + dunitprice = ((double)total_assetoshis2 / orig_assetoshis); + received_assetoshis = (paid_assetoshis2 / dunitprice); + fprintf(stderr,"remaining_assetoshis2 %llu (%llu - %llu)\n",(long long)remaining_assetoshis2/COIN,(long long)total_assetoshis2/COIN,(long long)paid_assetoshis2/COIN); + fprintf(stderr,"unitprice %.8f received_assetoshis %llu orig %llu\n",dunitprice/COIN,(long long)received_assetoshis,(long long)orig_assetoshis); + if ( fabs(dunitprice) > SMALLVAL && received_assetoshis > 0 && received_assetoshis <= orig_assetoshis ) + { + remaining_assetoshis = (orig_assetoshis - received_assetoshis); + return(ValidateAskRemainder(remaining_assetoshis2,remaining_assetoshis,orig_assetoshis,received_assetoshis,paid_assetoshis2,total_assetoshis2)); + } else return(false); +} + +bool ValidateSwapRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidunits,int64_t totalunits) +{ + int64_t unitprice,recvunitprice,newunitprice=0; + if ( orig_nValue == 0 || received_nValue == 0 || paidunits == 0 || totalunits == 0 ) + { + fprintf(stderr,"ValidateAssetRemainder: orig_nValue == %llu || received_nValue == %llu || paidunits == %llu || totalunits == %llu\n",(long long)orig_nValue,(long long)received_nValue,(long long)paidunits,(long long)totalunits); + return(false); + } + else if ( totalunits != (remaining_price + paidunits) ) + { + fprintf(stderr,"ValidateAssetRemainder: totalunits %llu != %llu (remaining_price %llu + %llu paidunits)\n",(long long)totalunits,(long long)(remaining_price + paidunits),(long long)remaining_price,(long long)paidunits); + return(false); + } + else if ( orig_nValue != (remaining_nValue + received_nValue) ) + { + fprintf(stderr,"ValidateAssetRemainder: orig_nValue %llu != %llu (remaining_nValue %llu + %llu received_nValue)\n",(long long)orig_nValue,(long long)(remaining_nValue - received_nValue),(long long)remaining_nValue,(long long)received_nValue); + return(false); + } + else + { + unitprice = (orig_nValue * COIN) / totalunits; + recvunitprice = (received_nValue * COIN) / paidunits; + if ( remaining_price != 0 ) + newunitprice = (remaining_nValue * COIN) / remaining_price; + if ( recvunitprice < unitprice ) + { + fprintf(stderr,"error recvunitprice %.16f < %.16f unitprice, new unitprice %.16f\n",(double)recvunitprice/(COIN*COIN),(double)unitprice/(COIN*COIN),(double)newunitprice/(COIN*COIN)); + return(false); + } + fprintf(stderr,"recvunitprice %.16f >= %.16f unitprice, new unitprice %.16f\n",(double)recvunitprice/(COIN*COIN),(double)unitprice/(COIN*COIN),(double)newunitprice/(COIN*COIN)); + } + return(true); +} + +CScript EncodeAssetCreateOpRet(uint8_t funcid,std::vector origpubkey,std::string name,std::string description) +{ + CScript opret; uint8_t evalcode = EVAL_ASSETS; + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << origpubkey << name << description); + return(opret); +} + +CScript EncodeAssetOpRet(uint8_t funcid,uint256 assetid,uint256 assetid2,int64_t price,std::vector origpubkey) +{ + CScript opret; uint8_t evalcode = EVAL_ASSETS; + assetid = revuint256(assetid); + switch ( funcid ) + { + case 't': case 'x': case 'o': + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << assetid); + break; + case 's': case 'b': case 'S': case 'B': + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << assetid << price << origpubkey); + break; + case 'E': case 'e': + assetid2 = revuint256(assetid2); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << assetid << assetid2 << price << origpubkey); + break; + default: + fprintf(stderr,"EncodeOpRet: illegal funcid.%02x\n",funcid); + opret << OP_RETURN; + break; + } + return(opret); +} + +bool DecodeAssetCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description) +{ + std::vector vopret; uint8_t evalcode,funcid,*script; + GetOpReturnData(scriptPubKey, vopret); + script = (uint8_t *)vopret.data(); + if ( script != 0 && vopret.size() > 2 && script[0] == EVAL_ASSETS && script[1] == 'c' ) + { + if ( E_UNMARSHAL(vopret,ss >> evalcode; ss >> funcid; ss >> origpubkey; ss >> name; ss >> description) != 0 ) + return(true); + } + return(0); +} + +uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey) +{ + std::vector vopret; uint8_t funcid=0,*script,e,f; + GetOpReturnData(scriptPubKey, vopret); + script = (uint8_t *)vopret.data(); + memset(&assetid,0,sizeof(assetid)); + memset(&assetid2,0,sizeof(assetid2)); + price = 0; + if ( script != 0 && script[0] == EVAL_ASSETS ) + { + funcid = script[1]; + //fprintf(stderr,"decode.[%c]\n",funcid); + switch ( funcid ) + { + case 'c': return(funcid); + break; + case 't': case 'x': case 'o': + if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> assetid) != 0 ) + { + assetid = revuint256(assetid); + return(funcid); + } + break; + case 's': case 'b': case 'S': case 'B': + if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> assetid; ss >> price; ss >> origpubkey) != 0 ) + { + assetid = revuint256(assetid); + //fprintf(stderr,"got price %llu\n",(long long)price); + return(funcid); + } + break; + case 'E': case 'e': + if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> assetid; ss >> assetid2; ss >> price; ss >> origpubkey) != 0 ) + { + //fprintf(stderr,"got price %llu\n",(long long)price); + assetid = revuint256(assetid); + assetid2 = revuint256(assetid2); + return(funcid); + } + break; + default: + fprintf(stderr,"DecodeAssetOpRet: illegal funcid.%02x\n",funcid); + funcid = 0; + break; + } + } + return(funcid); +} + +bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CTransaction &tx) +{ + uint256 assetid,assetid2; + if ( tx.vout.size() > 0 && DecodeAssetOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,assetid,assetid2,price,origpubkey) != 0 ) + return(true); + else return(false); +} + +bool GetAssetorigaddrs(struct CCcontract_info *cp,char *CCaddr,char *destaddr,const CTransaction& tx) +{ + uint256 assetid,assetid2; int64_t price,nValue=0; int32_t n; uint8_t funcid; std::vector origpubkey; CScript script; + n = tx.vout.size(); + if ( n == 0 || (funcid= DecodeAssetOpRet(tx.vout[n-1].scriptPubKey,assetid,assetid2,price,origpubkey)) == 0 ) + return(false); + if ( GetCCaddress(cp,CCaddr,pubkey2pk(origpubkey)) != 0 && Getscriptaddress(destaddr,CScript() << origpubkey << OP_CHECKSIG) != 0 ) + return(true); + else return(false); +} + +int64_t IsAssetvout(int64_t &price,std::vector &origpubkey,const CTransaction& tx,int32_t v,uint256 refassetid) +{ + uint256 assetid,assetid2; int64_t nValue=0; int32_t n; uint8_t funcid; + if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) // maybe check address too? + { + n = tx.vout.size(); + nValue = tx.vout[v].nValue; + //fprintf(stderr,"CC vout v.%d of n.%d %.8f\n",v,n,(double)nValue/COIN); + if ( v >= n-1 ) + return(0); + if ( (funcid= DecodeAssetOpRet(tx.vout[n-1].scriptPubKey,assetid,assetid2,price,origpubkey)) == 0 ) + { + fprintf(stderr,"null decodeopret\n"); + return(0); + } + else if ( funcid == 'c' ) + { + if ( refassetid == tx.GetHash() && v == 0 ) + return(nValue); + } + else if ( (funcid == 'b' || funcid == 'B') && v == 0 ) // critical! 'b'/'B' vout0 is NOT asset + return(0); + else if ( funcid != 'E' ) + { + if ( assetid == refassetid ) + return(nValue); + } + else if ( funcid == 'E' ) + { + if ( v < 2 && assetid == refassetid ) + return(nValue); + else if ( v == 2 && assetid2 == refassetid ) + return(nValue); + } + } + //fprintf(stderr,"Isassetvout: normal output v.%d %.8f\n",v,(double)tx.vout[v].nValue/COIN); + return(0); +} + +int64_t AssetValidateCCvin(struct CCcontract_info *cp,Eval* eval,char *CCaddr,char *origaddr,const CTransaction &tx,int32_t vini,CTransaction &vinTx) +{ + uint256 hashBlock; char destaddr[64]; + origaddr[0] = destaddr[0] = CCaddr[0] = 0; + if ( tx.vin.size() < 2 ) + return eval->Invalid("not enough for CC vins"); + else if ( tx.vin[vini].prevout.n != 0 ) + return eval->Invalid("vin1 needs to be buyvin.vout[0]"); + else if ( eval->GetTxUnconfirmed(tx.vin[vini].prevout.hash,vinTx,hashBlock) == 0 ) + { + int32_t z; + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&tx.vin[vini].prevout.hash)[z]); + fprintf(stderr," vini.%d\n",vini); + return eval->Invalid("always should find CCvin, but didnt"); + } + else if ( Getscriptaddress(destaddr,vinTx.vout[tx.vin[vini].prevout.n].scriptPubKey) == 0 || strcmp(destaddr,(char *)cp->unspendableCCaddr) != 0 ) + { + fprintf(stderr,"%s vs %s\n",destaddr,(char *)cp->unspendableCCaddr); + return eval->Invalid("invalid vin AssetsCCaddr"); + } + //else if ( vinTx.vout[0].nValue < 10000 ) + // return eval->Invalid("invalid dust for buyvin"); + else if ( GetAssetorigaddrs(cp,CCaddr,origaddr,vinTx) == 0 ) + return eval->Invalid("couldnt get origaddr for buyvin"); + fprintf(stderr,"Got %.8f to origaddr.(%s)\n",(double)vinTx.vout[tx.vin[vini].prevout.n].nValue/COIN,origaddr); + if ( vinTx.vout[0].nValue == 0 ) + return eval->Invalid("null value CCvin"); + return(vinTx.vout[0].nValue); +} + +int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 refassetid) +{ + CTransaction vinTx; int64_t nValue; uint256 assetid,assetid2; uint8_t funcid; + CCaddr[0] = origaddr[0] = 0; + if ( (nValue= AssetValidateCCvin(cp,eval,CCaddr,origaddr,tx,1,vinTx)) == 0 ) + return(0); + else if ( vinTx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) + return eval->Invalid("invalid normal vout0 for buyvin"); + else + { + //fprintf(stderr,"have %.8f checking assetid origaddr.(%s)\n",(double)nValue/COIN,origaddr); + if ( vinTx.vout.size() > 0 && (funcid= DecodeAssetOpRet(vinTx.vout[vinTx.vout.size()-1].scriptPubKey,assetid,assetid2,tmpprice,tmporigpubkey)) != 'b' && funcid != 'B' ) + return eval->Invalid("invalid opreturn for buyvin"); + else if ( refassetid != assetid ) + return eval->Invalid("invalid assetid for buyvin"); + //int32_t i; for (i=31; i>=0; i--) + // fprintf(stderr,"%02x",((uint8_t *)&assetid)[i]); + //fprintf(stderr," AssetValidateBuyvin assetid for %s\n",origaddr); + } + return(nValue); +} + +int64_t AssetValidateSellvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 assetid) +{ + CTransaction vinTx; int64_t nValue,assetoshis; + fprintf(stderr,"AssetValidateSellvin\n"); + if ( (nValue= AssetValidateCCvin(cp,eval,CCaddr,origaddr,tx,1,vinTx)) == 0 ) + return(0); + if ( (assetoshis= IsAssetvout(tmpprice,tmporigpubkey,vinTx,0,assetid)) == 0 ) + return eval->Invalid("invalid missing CC vout0 for sellvin"); + else return(assetoshis); +} + +bool AssetExactAmounts(struct CCcontract_info *cp,int64_t &inputs,int32_t starti,int64_t &outputs,Eval* eval,const CTransaction &tx,uint256 assetid) +{ + CTransaction vinTx; uint256 hashBlock; int32_t i,numvins,numvouts; int64_t assetoshis; std::vector tmporigpubkey; int64_t tmpprice; + numvins = tx.vin.size(); + numvouts = tx.vout.size(); + inputs = outputs = 0; + for (i=starti; iismyvin)(tx.vin[i].scriptSig) != 0 ) + { + if ( eval->GetTxUnconfirmed(tx.vin[i].prevout.hash,vinTx,hashBlock) == 0 ) + { + fprintf(stderr,"i.%d starti.%d numvins.%d\n",i,starti,numvins); + return eval->Invalid("always should find vin, but didnt"); + } + else if ( (assetoshis= IsAssetvout(tmpprice,tmporigpubkey,vinTx,tx.vin[i].prevout.n,assetid)) != 0 ) + { + fprintf(stderr,"vin%d %llu, ",i,(long long)assetoshis); + inputs += assetoshis; + } + } + } + for (i=0; i origpubkey; CTransaction vintx; int32_t j,vout,n = 0; + std::vector > unspentOutputs; + GetCCaddress(cp,coinaddr,pk); + SetCCunspents(unspentOutputs,coinaddr); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + txid = it->first.txhash; + vout = (int32_t)it->first.index; + for (j=0; j 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + { + if ( total != 0 && maxinputs != 0 ) + mtx.vin.push_back(CTxIn(txid,vout,CScript())); + nValue = it->second.satoshis; + totalinputs += nValue; + n++; + if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) + break; + } + } + } + return(totalinputs); +} + +int64_t GetAssetBalance(CPubKey pk,uint256 tokenid) +{ + CMutableTransaction mtx; struct CCcontract_info *cp,C; + cp = CCinit(&C,EVAL_ASSETS); + return(AddAssetInputs(cp,mtx,pk,tokenid,0,0)); +} + +UniValue AssetInfo(uint256 assetid) +{ + UniValue result(UniValue::VOBJ); uint256 hashBlock; CTransaction vintx; std::vector origpubkey; std::string name,description; char str[67],numstr[65]; + if ( GetTransaction(assetid,vintx,hashBlock,false) == 0 ) + { + fprintf(stderr,"cant find assetid\n"); + result.push_back(Pair("result","error")); + result.push_back(Pair("error","cant find assetid")); + return(result); + } + if ( vintx.vout.size() > 0 && DecodeAssetCreateOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,origpubkey,name,description) == 0 ) + { + fprintf(stderr,"assetid isnt assetcreation txid\n"); + result.push_back(Pair("result","error")); + result.push_back(Pair("error","assetid isnt assetcreation txid")); + } + result.push_back(Pair("result","success")); + result.push_back(Pair("tokenid",uint256_str(str,assetid))); + result.push_back(Pair("owner",pubkey33_str(str,origpubkey.data()))); + result.push_back(Pair("name",name)); + result.push_back(Pair("supply",vintx.vout[0].nValue)); + result.push_back(Pair("description",description)); + return(result); +} + +UniValue AssetList() +{ + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock; CTransaction vintx; std::vector origpubkey; std::string name,description; char str[65]; + cp = CCinit(&C,EVAL_ASSETS); + SetCCtxids(addressIndex,cp->normaladdr); + for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) + { + txid = it->first.txhash; + if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + { + if ( vintx.vout.size() > 0 && DecodeAssetCreateOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,origpubkey,name,description) != 0 ) + { + result.push_back(uint256_str(str,txid)); + } + } + } + return(result); +} + +UniValue AssetOrders(uint256 refassetid) +{ + static uint256 zero; + int64_t price; uint256 txid,hashBlock,assetid,assetid2; std::vector origpubkey; CTransaction vintx; UniValue result(UniValue::VARR); std::vector > unspentOutputs; uint8_t funcid; char numstr[32],funcidstr[16],origaddr[64],assetidstr[65]; struct CCcontract_info *cp,C; + cp = CCinit(&C,EVAL_ASSETS); + SetCCunspents(unspentOutputs,(char *)cp->unspendableCCaddr); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + txid = it->first.txhash; + if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + { + if ( vintx.vout.size() > 0 && (funcid= DecodeAssetOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,assetid,assetid2,price,origpubkey)) != 0 ) + { + if ( refassetid != zero && assetid != refassetid ) + { + //int32_t z; + //for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&txid)[z]); + //fprintf(stderr," txid\n"); + //for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&assetid)[z]); + //fprintf(stderr," assetid\n"); + //for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&refassetid)[z]); + //fprintf(stderr," refassetid\n"); + continue; + } + if ( vintx.vout[it->first.index].nValue == 0 ) + continue; + UniValue item(UniValue::VOBJ); + funcidstr[0] = funcid; + funcidstr[1] = 0; + item.push_back(Pair("funcid", funcidstr)); + item.push_back(Pair("txid", uint256_str(assetidstr,txid))); + item.push_back(Pair("vout", (int64_t)it->first.index)); + if ( funcid == 'b' || funcid == 'B' ) + { + sprintf(numstr,"%.8f",(double)vintx.vout[it->first.index].nValue/COIN); + item.push_back(Pair("amount",numstr)); + sprintf(numstr,"%.8f",(double)vintx.vout[0].nValue/COIN); + item.push_back(Pair("bidamount",numstr)); + } + else + { + sprintf(numstr,"%llu",(long long)vintx.vout[it->first.index].nValue); + item.push_back(Pair("amount",numstr)); + sprintf(numstr,"%llu",(long long)vintx.vout[0].nValue); + item.push_back(Pair("askamount",numstr)); + } + if ( origpubkey.size() == 33 ) + { + GetCCaddress(cp,origaddr,pubkey2pk(origpubkey)); + item.push_back(Pair("origaddress",origaddr)); + } + if ( assetid != zeroid ) + item.push_back(Pair("tokenid",uint256_str(assetidstr,assetid))); + if ( assetid2 != zeroid ) + item.push_back(Pair("otherid",uint256_str(assetidstr,assetid2))); + if ( price > 0 ) + { + if ( funcid == 's' || funcid == 'S' || funcid == 'e' || funcid == 'e' ) + { + sprintf(numstr,"%.8f",(double)price / COIN); + item.push_back(Pair("totalrequired", numstr)); + sprintf(numstr,"%.8f",(double)price / (COIN * vintx.vout[0].nValue)); + item.push_back(Pair("price", numstr)); + } + else + { + item.push_back(Pair("totalrequired", (int64_t)price)); + sprintf(numstr,"%.8f",(double)vintx.vout[0].nValue / (price * COIN)); + item.push_back(Pair("price",numstr)); + } + } + result.push_back(item); + //fprintf(stderr,"func.(%c) %s/v%d %.8f\n",funcid,uint256_str(assetidstr,txid),(int32_t)it->first.index,(double)vintx.vout[it->first.index].nValue/COIN); + } + } + } + return(result); +} + +std::string CreateAsset(int64_t txfee,int64_t assetsupply,std::string name,std::string description) +{ + CMutableTransaction mtx; CPubKey mypk; struct CCcontract_info *cp,C; + if ( assetsupply < 0 ) + { + fprintf(stderr,"negative assetsupply %lld\n",(long long)assetsupply); + return(""); + } + cp = CCinit(&C,EVAL_ASSETS); + if ( name.size() > 32 || description.size() > 4096 ) + { + fprintf(stderr,"name.%d or description.%d is too big\n",(int32_t)name.size(),(int32_t)description.size()); + return(""); + } + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + if ( AddNormalinputs(mtx,mypk,assetsupply+2*txfee,64) > 0 ) + { + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,assetsupply,mypk)); + mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(cp->CChexstr) << OP_CHECKSIG)); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetCreateOpRet('c',Mypubkey(),name,description))); + } + return(""); +} + +std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total) +{ + CMutableTransaction mtx; CPubKey mypk; uint64_t mask; int64_t CCchange=0,inputs=0; struct CCcontract_info *cp,C; + if ( total < 0 ) + { + fprintf(stderr,"negative total %lld\n",(long long)total); + return(""); + } + cp = CCinit(&C,EVAL_ASSETS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 ) + { + /*n = outputs.size(); + if ( n == amounts.size() ) + { + for (i=0; i 0 ) + { + if ( inputs > total ) + CCchange = (inputs - total); + //for (i=0; i origpubkey; std::string name,description; + if ( bidamount < 0 || pricetotal < 0 ) + { + fprintf(stderr,"negative bidamount %lld, pricetotal %lld\n",(long long)bidamount,(long long)pricetotal); + return(""); + } + if ( GetTransaction(assetid,vintx,hashBlock,false) == 0 ) + { + fprintf(stderr,"cant find assetid\n"); + return(""); + } + if ( vintx.vout.size() > 0 && DecodeAssetCreateOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,origpubkey,name,description) == 0 ) + { + fprintf(stderr,"assetid isnt assetcreation txid\n"); + return(""); + } + cp = CCinit(&C,EVAL_ASSETS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + if ( AddNormalinputs(mtx,mypk,bidamount+txfee,64) > 0 ) + { + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,bidamount,GetUnspendable(cp,0))); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('b',assetid,zeroid,pricetotal,Mypubkey()))); + } + return(""); +} + +std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t pricetotal) +{ + CMutableTransaction mtx; CPubKey mypk; uint64_t mask; int64_t inputs,CCchange; CScript opret; struct CCcontract_info *cp,C; + if ( askamount < 0 || pricetotal < 0 ) + { + fprintf(stderr,"negative askamount %lld, askamount %lld\n",(long long)pricetotal,(long long)askamount); + return(""); + } + cp = CCinit(&C,EVAL_ASSETS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 ) + { + mask = ~((1LL << mtx.vin.size()) - 1); + if ( (inputs= AddAssetInputs(cp,mtx,mypk,assetid,askamount,60)) > 0 ) + { + if ( inputs < askamount ) + askamount = inputs; + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,askamount,GetUnspendable(cp,0))); + if ( inputs > askamount ) + CCchange = (inputs - askamount); + if ( CCchange != 0 ) + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk)); + opret = EncodeAssetOpRet('s',assetid,zeroid,pricetotal,Mypubkey()); + return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,opret)); + } else fprintf(stderr,"need some assets to place ask\n"); + } + fprintf(stderr,"need some native coins to place ask\n"); + return(""); +} + +std::string CreateSwap(int64_t txfee,int64_t askamount,uint256 assetid,uint256 assetid2,int64_t pricetotal) +{ + CMutableTransaction mtx; CPubKey mypk; uint64_t mask; int64_t inputs,CCchange; CScript opret; struct CCcontract_info *cp,C; + fprintf(stderr,"asset swaps disabled\n"); + return(""); + if ( askamount < 0 || pricetotal < 0 ) + { + fprintf(stderr,"negative askamount %lld, askamount %lld\n",(long long)pricetotal,(long long)askamount); + return(""); + } + cp = CCinit(&C,EVAL_ASSETS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 ) + { + mask = ~((1LL << mtx.vin.size()) - 1); + if ( (inputs= AddAssetInputs(cp,mtx,mypk,assetid,askamount,60)) > 0 ) + { + if ( inputs < askamount ) + askamount = inputs; + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,askamount,GetUnspendable(cp,0))); + if ( inputs > askamount ) + CCchange = (inputs - askamount); + if ( CCchange != 0 ) + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk)); + if ( assetid2 == zeroid ) + opret = EncodeAssetOpRet('s',assetid,zeroid,pricetotal,Mypubkey()); + else + { + opret = EncodeAssetOpRet('e',assetid,assetid2,pricetotal,Mypubkey()); + } + return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,opret)); + } else fprintf(stderr,"need some assets to place ask\n"); + } + fprintf(stderr,"need some native coins to place ask\n"); + return(""); +} + +std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid) +{ + CMutableTransaction mtx; CTransaction vintx; uint64_t mask; uint256 hashBlock; int64_t bidamount; CPubKey mypk; struct CCcontract_info *cp,C; + cp = CCinit(&C,EVAL_ASSETS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 ) + { + mask = ~((1LL << mtx.vin.size()) - 1); + if ( GetTransaction(bidtxid,vintx,hashBlock,false) != 0 ) + { + bidamount = vintx.vout[0].nValue; + mtx.vin.push_back(CTxIn(bidtxid,0,CScript())); + mtx.vout.push_back(CTxOut(bidamount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,EncodeAssetOpRet('o',assetid,zeroid,0,Mypubkey()))); + } + } + return(""); +} + +std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) +{ + CMutableTransaction mtx; CTransaction vintx; uint64_t mask; uint256 hashBlock; int64_t askamount; CPubKey mypk; struct CCcontract_info *cp,C; + cp = CCinit(&C,EVAL_ASSETS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 ) + { + mask = ~((1LL << mtx.vin.size()) - 1); + if ( GetTransaction(asktxid,vintx,hashBlock,false) != 0 ) + { + askamount = vintx.vout[0].nValue; + mtx.vin.push_back(CTxIn(asktxid,0,CScript())); + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,askamount,mypk)); + return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,EncodeAssetOpRet('x',assetid,zeroid,0,Mypubkey()))); + } + } + return(""); +} + +std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t fillamount) +{ + CTransaction vintx; uint256 hashBlock; CMutableTransaction mtx; CPubKey mypk; std::vector origpubkey; int32_t bidvout=0; uint64_t mask; int64_t origprice,bidamount,paid_amount,remaining_required,inputs,CCchange=0; struct CCcontract_info *cp,C; + if ( fillamount < 0 ) + { + fprintf(stderr,"negative fillamount %lld\n",(long long)fillamount); + return(""); + } + cp = CCinit(&C,EVAL_ASSETS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 ) + { + mask = ~((1LL << mtx.vin.size()) - 1); + if ( GetTransaction(bidtxid,vintx,hashBlock,false) != 0 ) + { + bidamount = vintx.vout[bidvout].nValue; + SetAssetOrigpubkey(origpubkey,origprice,vintx); + mtx.vin.push_back(CTxIn(bidtxid,bidvout,CScript())); + if ( (inputs= AddAssetInputs(cp,mtx,mypk,assetid,fillamount,60)) > 0 ) + { + if ( inputs < fillamount ) + fillamount = inputs; + SetBidFillamounts(paid_amount,remaining_required,bidamount,fillamount,origprice); + if ( inputs > fillamount ) + CCchange = (inputs - fillamount); + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,bidamount - paid_amount,GetUnspendable(cp,0))); + mtx.vout.push_back(CTxOut(paid_amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,fillamount,pubkey2pk(origpubkey))); + if ( CCchange != 0 ) + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk)); + fprintf(stderr,"remaining %llu -> origpubkey\n",(long long)remaining_required); + return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,EncodeAssetOpRet('B',assetid,zeroid,remaining_required,origpubkey))); + } else return("dont have any assets to fill bid\n"); + } + } + return("no normal coins left"); +} + +std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 asktxid,int64_t fillunits) +{ + CTransaction vintx,filltx; uint256 hashBlock; CMutableTransaction mtx; CPubKey mypk; std::vector origpubkey; double dprice; uint64_t mask; int32_t askvout=0; int64_t received_assetoshis,total_nValue,orig_assetoshis,paid_nValue,remaining_nValue,inputs,CCchange=0; struct CCcontract_info *cp,C; + if ( fillunits < 0 ) + { + CCerror = strprintf("negative fillunits %lld\n",(long long)fillunits); + fprintf(stderr,"%s\n",CCerror.c_str()); + return(""); + } + if ( assetid2 != zeroid ) + { + CCerror = "asset swaps disabled"; + fprintf(stderr,"%s\n",CCerror.c_str()); + return(""); + } + + cp = CCinit(&C,EVAL_ASSETS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 ) + { + mask = ~((1LL << mtx.vin.size()) - 1); + if ( GetTransaction(asktxid,vintx,hashBlock,false) != 0 ) + { + orig_assetoshis = vintx.vout[askvout].nValue; + SetAssetOrigpubkey(origpubkey,total_nValue,vintx); + dprice = (double)total_nValue / orig_assetoshis; + paid_nValue = dprice * fillunits; + mtx.vin.push_back(CTxIn(asktxid,askvout,CScript())); + if ( assetid2 != zeroid ) + inputs = AddAssetInputs(cp,mtx,mypk,assetid2,paid_nValue,60); + else + { + inputs = AddNormalinputs(mtx,mypk,paid_nValue,60); + mask = ~((1LL << mtx.vin.size()) - 1); + } + if ( inputs > 0 ) + { + if ( inputs < paid_nValue ) + paid_nValue = inputs; + if ( assetid2 != zeroid ) + SetSwapFillamounts(received_assetoshis,remaining_nValue,orig_assetoshis,paid_nValue,total_nValue); + else SetAskFillamounts(received_assetoshis,remaining_nValue,orig_assetoshis,paid_nValue,total_nValue); + if ( assetid2 != zeroid && inputs > paid_nValue ) + CCchange = (inputs - paid_nValue); + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,orig_assetoshis - received_assetoshis,GetUnspendable(cp,0))); + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,received_assetoshis,mypk)); + if ( assetid2 != zeroid ) + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,paid_nValue,origpubkey)); + else mtx.vout.push_back(CTxOut(paid_nValue,CScript() << origpubkey << OP_CHECKSIG)); + if ( CCchange != 0 ) + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk)); + return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,EncodeAssetOpRet(assetid2!=zeroid?'E':'S',assetid,assetid2,remaining_nValue,origpubkey))); + } else { + CCerror = strprintf("filltx not enough utxos"); + fprintf(stderr,"%s\n", CCerror.c_str()); + } + } + } + return(""); +} diff --git a/src/cc/CCauction.h b/src/cc/CCauction.h new file mode 100644 index 000000000..855cdf72e --- /dev/null +++ b/src/cc/CCauction.h @@ -0,0 +1,30 @@ +/****************************************************************************** + * Copyright © 2014-2018 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + + +#ifndef CC_AUCTION_H +#define CC_AUCTION_H + +#include "CCinclude.h" + +#define EVAL_AUCTION 0xe8 + +bool AuctionValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); + +std::string AuctionPost(uint64_t txfee,uint256 itemhash,int64_t minbid,char *title,char *description); +std::string AuctionBid(uint64_t txfee,uint256 itemhash,int64_t amount); +std::string AuctionDeliver(uint64_t txfee,uint256 itemhash,uint256 bidtxid); + +#endif diff --git a/src/cc/CCcustom.cpp b/src/cc/CCcustom.cpp new file mode 100644 index 000000000..9bf1d5449 --- /dev/null +++ b/src/cc/CCcustom.cpp @@ -0,0 +1,195 @@ +/****************************************************************************** + * Copyright © 2014-2018 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#include "CCinclude.h" +#include "CCassets.h" +#include "CCfaucet.h" +#include "CCrewards.h" +#include "CCdice.h" +#include "CCauction.h" +#include "CClotto.h" +#include "CCfsm.h" + +/* + CCcustom has most of the functions that need to be extended to create a new CC contract. + + A CC scriptPubKey can only be spent if it is properly signed and validated. By constraining the vins and vouts, it is possible to implement a variety of functionality. CC vouts have an otherwise non-standard form, but it is properly supported by the enhanced bitcoin protocol code as a "cryptoconditions" output and the same pubkey will create a different address. + + This allows creation of a special address(es) for each contract type, which has the privkey public. That allows anybody to properly sign and spend it, but with the constraints on what is allowed in the validation code, the contract functionality can be implemented. + + what needs to be done to add a new contract: + 1. add EVAL_CODE to eval.h + 2. initialize the variables in the CCinit function below + 3. write a Validate function to reject any unsanctioned usage of vin/vout + 4. make helper functions to create rawtx for RPC functions + 5. add rpc calls to rpcserver.cpp and rpcserver.h and in one of the rpc.cpp files + 6. add the new .cpp files to src/Makefile.am + + IMPORTANT: make sure that all CC inputs and CC outputs are properly accounted for and reconcile to the satoshi. The built in utxo management will enforce overall vin/vout constraints but it wont know anything about the CC constraints. That is what your Validate function needs to do. + + Generally speaking, there will be normal coins that change into CC outputs, CC outputs that go back to being normal coins, CC outputs that are spent to new CC outputs. + + Make sure both the CC coins and normal coins are preserved and follow the rules that make sense. It is a good idea to define specific roles for specific vins and vouts to reduce the complexity of validation. + */ + +//BTCD Address: RAssetsAtGnvwgK9gVHBbAU4sVTah1hAm5 +//BTCD Privkey: UvtvQVgVScXEYm4J3r4nE4nbFuGXSVM5pKec8VWXwgG9dmpWBuDh +//BTCD Address: RSavingsEYcivt2DFsxsKeCjqArV6oVtVZ +//BTCD Privkey: Ux6XQekTxokko6gZHz24B7PUsmUQtWFzG2W9nUA8jba7UoVbPBF4 + +// Assets, aka Tokens +#define FUNCNAME IsAssetsInput +#define EVALCODE EVAL_ASSETS +const char *AssetsCCaddr = "RGKRjeTBw4LYFotSDLT6RWzMHbhXri6BG6"; +const char *AssetsNormaladdr = "RFYE2yL3KknWdHK6uNhvWacYsCUtwzjY3u"; +char AssetsCChexstr[67] = { "02adf84e0e075cf90868bd4e3d34a03420e034719649c41f371fc70d8e33aa2702" }; +uint8_t AssetsCCpriv[32] = { 0x9b, 0x17, 0x66, 0xe5, 0x82, 0x66, 0xac, 0xb6, 0xba, 0x43, 0x83, 0x74, 0xf7, 0x63, 0x11, 0x3b, 0xf0, 0xf3, 0x50, 0x6f, 0xd9, 0x6b, 0x67, 0x85, 0xf9, 0x7a, 0xf0, 0x54, 0x4d, 0xb1, 0x30, 0x77 }; + +#include "CCcustom.inc" +#undef FUNCNAME +#undef EVALCODE + +// Faucet +#define FUNCNAME IsFaucetInput +#define EVALCODE EVAL_FAUCET +const char *FaucetCCaddr = "R9zHrofhRbub7ER77B7NrVch3A63R39GuC"; +const char *FaucetNormaladdr = "RKQV4oYs4rvxAWx1J43VnT73rSTVtUeckk"; +char FaucetCChexstr[67] = { "03682b255c40d0cde8faee381a1a50bbb89980ff24539cb8518e294d3a63cefe12" }; +uint8_t FaucetCCpriv[32] = { 0xd4, 0x4f, 0xf2, 0x31, 0x71, 0x7d, 0x28, 0x02, 0x4b, 0xc7, 0xdd, 0x71, 0xa0, 0x39, 0xc4, 0xbe, 0x1a, 0xfe, 0xeb, 0xc2, 0x46, 0xda, 0x76, 0xf8, 0x07, 0x53, 0x3d, 0x96, 0xb4, 0xca, 0xa0, 0xe9 }; + +#include "CCcustom.inc" +#undef FUNCNAME +#undef EVALCODE + +// Rewards +#define FUNCNAME IsRewardsInput +#define EVALCODE EVAL_REWARDS +const char *RewardsCCaddr = "RTsRBYL1HSvMoE3qtBJkyiswdVaWkm8YTK"; +const char *RewardsNormaladdr = "RMgye9jeczNjQx9Uzq8no8pTLiCSwuHwkz"; +char RewardsCChexstr[67] = { "03da60379d924c2c30ac290d2a86c2ead128cb7bd571f69211cb95356e2dcc5eb9" }; +uint8_t RewardsCCpriv[32] = { 0x82, 0xf5, 0xd2, 0xe7, 0xd6, 0x99, 0x33, 0x77, 0xfb, 0x80, 0x00, 0x97, 0x23, 0x3d, 0x1e, 0x6f, 0x61, 0xa9, 0xb5, 0x2e, 0x5e, 0xb4, 0x96, 0x6f, 0xbc, 0xed, 0x6b, 0xe2, 0xbb, 0x7b, 0x4b, 0xb3 }; +#include "CCcustom.inc" +#undef FUNCNAME +#undef EVALCODE + +// Dice +#define FUNCNAME IsDiceInput +#define EVALCODE EVAL_DICE +const char *DiceCCaddr = "REabWB7KjFN5C3LFMZ5odExHPenYzHLtVw"; +const char *DiceNormaladdr = "RLEe8f7Eg3TDuXii9BmNiiiaVGraHUt25c"; +char DiceCChexstr[67] = { "039d966927cfdadab3ee6c56da63c21f17ea753dde4b3dfd41487103e24b27e94e" }; +uint8_t DiceCCpriv[32] = { 0x0e, 0xe8, 0xf5, 0xb4, 0x3d, 0x25, 0xcc, 0x35, 0xd1, 0xf1, 0x2f, 0x04, 0x5f, 0x01, 0x26, 0xb8, 0xd1, 0xac, 0x3a, 0x5a, 0xea, 0xe0, 0x25, 0xa2, 0x8f, 0x2a, 0x8e, 0x0e, 0xf9, 0x34, 0xfa, 0x77 }; +#include "CCcustom.inc" +#undef FUNCNAME +#undef EVALCODE + +// Lotto +#define FUNCNAME IsLottoInput +#define EVALCODE EVAL_LOTTO +const char *LottoCCaddr = "RNXZxgyWSAE6XS3qGnTaf5dVNCxnYzhPrg"; +const char *LottoNormaladdr = "RLW6hhRqBZZMBndnyPv29Yg3krh6iBYCyg"; +char LottoCChexstr[67] = { "03f72d2c4db440df1e706502b09ca5fec73ffe954ea1883e4049e98da68690d98f" }; +uint8_t LottoCCpriv[32] = { 0xb4, 0xac, 0xc2, 0xd9, 0x67, 0x34, 0xd7, 0x58, 0x80, 0x4e, 0x25, 0x55, 0xc0, 0x50, 0x66, 0x84, 0xbb, 0xa2, 0xe7, 0xc0, 0x39, 0x17, 0xb4, 0xc5, 0x07, 0xb7, 0x3f, 0xca, 0x07, 0xb0, 0x9a, 0xeb }; +#include "CCcustom.inc" +#undef FUNCNAME +#undef EVALCODE + +// Finite State Machine +#define FUNCNAME IsFSMInput +#define EVALCODE EVAL_FSM +const char *FSMCCaddr = "RUKTbLBeKgHkm3Ss4hKZP3ikuLW1xx7B2x"; +const char *FSMNormaladdr = "RWSHRbxnJYLvDjpcQ2i8MekgP6h2ctTKaj"; +char FSMCChexstr[67] = { "039b52d294b413b07f3643c1a28c5467901a76562d8b39a785910ae0a0f3043810" }; +uint8_t FSMCCpriv[32] = { 0x11, 0xe1, 0xea, 0x3e, 0xdb, 0x36, 0xf0, 0xa8, 0xc6, 0x34, 0xe1, 0x21, 0xb8, 0x02, 0xb9, 0x4b, 0x12, 0x37, 0x8f, 0xa0, 0x86, 0x23, 0x50, 0xb2, 0x5f, 0xe4, 0xe7, 0x36, 0x0f, 0xda, 0xae, 0xfc }; +#include "CCcustom.inc" +#undef FUNCNAME +#undef EVALCODE + +// Auction +#define FUNCNAME IsAuctionInput +#define EVALCODE EVAL_AUCTION +const char *AuctionCCaddr = "RL4YPX7JYG3FnvoPqWF2pn3nQknH5NWEwx"; +const char *AuctionNormaladdr = "RFtVDNmdTZBTNZdmFRbfBgJ6LitgTghikL"; +char AuctionCChexstr[67] = { "037eefe050c14cb60ae65d5b2f69eaa1c9006826d729bc0957bdc3024e3ca1dbe6" }; +uint8_t AuctionCCpriv[32] = { 0x8c, 0x1b, 0xb7, 0x8c, 0x02, 0xa3, 0x9d, 0x21, 0x28, 0x59, 0xf5, 0xea, 0xda, 0xec, 0x0d, 0x11, 0xcd, 0x38, 0x47, 0xac, 0x0b, 0x6f, 0x19, 0xc0, 0x24, 0x36, 0xbf, 0x1c, 0x0a, 0x06, 0x31, 0xfb }; +#include "CCcustom.inc" +#undef FUNCNAME +#undef EVALCODE + +struct CCcontract_info *CCinit(struct CCcontract_info *cp,uint8_t evalcode) +{ + cp->evalcode = evalcode; + switch ( evalcode ) + { + case EVAL_ASSETS: + strcpy(cp->unspendableCCaddr,AssetsCCaddr); + strcpy(cp->normaladdr,AssetsNormaladdr); + strcpy(cp->CChexstr,AssetsCChexstr); + memcpy(cp->CCpriv,AssetsCCpriv,32); + cp->validate = AssetsValidate; + cp->ismyvin = IsAssetsInput; + break; + case EVAL_FAUCET: + strcpy(cp->unspendableCCaddr,FaucetCCaddr); + strcpy(cp->normaladdr,FaucetNormaladdr); + strcpy(cp->CChexstr,FaucetCChexstr); + memcpy(cp->CCpriv,FaucetCCpriv,32); + cp->validate = FaucetValidate; + cp->ismyvin = IsFaucetInput; + break; + case EVAL_REWARDS: + strcpy(cp->unspendableCCaddr,RewardsCCaddr); + strcpy(cp->normaladdr,RewardsNormaladdr); + strcpy(cp->CChexstr,RewardsCChexstr); + memcpy(cp->CCpriv,RewardsCCpriv,32); + cp->validate = RewardsValidate; + cp->ismyvin = IsRewardsInput; + break; + case EVAL_DICE: + strcpy(cp->unspendableCCaddr,DiceCCaddr); + strcpy(cp->normaladdr,DiceNormaladdr); + strcpy(cp->CChexstr,DiceCChexstr); + memcpy(cp->CCpriv,DiceCCpriv,32); + cp->validate = DiceValidate; + cp->ismyvin = IsDiceInput; + break; + case EVAL_LOTTO: + strcpy(cp->unspendableCCaddr,LottoCCaddr); + strcpy(cp->normaladdr,LottoNormaladdr); + strcpy(cp->CChexstr,LottoCChexstr); + memcpy(cp->CCpriv,LottoCCpriv,32); + cp->validate = LottoValidate; + cp->ismyvin = IsLottoInput; + break; + case EVAL_FSM: + strcpy(cp->unspendableCCaddr,FSMCCaddr); + strcpy(cp->normaladdr,FSMNormaladdr); + strcpy(cp->CChexstr,FSMCChexstr); + memcpy(cp->CCpriv,FSMCCpriv,32); + cp->validate = FSMValidate; + cp->ismyvin = IsFSMInput; + break; + case EVAL_AUCTION: + strcpy(cp->unspendableCCaddr,AuctionCCaddr); + strcpy(cp->normaladdr,AuctionNormaladdr); + strcpy(cp->CChexstr,AuctionCChexstr); + memcpy(cp->CCpriv,AuctionCCpriv,32); + cp->validate = AuctionValidate; + cp->ismyvin = IsAuctionInput; + break; + } + return(cp); +} + diff --git a/src/cc/CCcustom.inc b/src/cc/CCcustom.inc new file mode 100644 index 000000000..c33ca4f5b --- /dev/null +++ b/src/cc/CCcustom.inc @@ -0,0 +1,17 @@ + +bool FUNCNAME(CScript const& scriptSig) +{ + CC *cond; + if (!(cond = GetCryptoCondition(scriptSig))) + return false; + // Recurse the CC tree to find asset condition + auto findEval = [] (CC *cond, struct CCVisitor _) { + bool r = cc_typeId(cond) == CC_Eval && cond->codeLength == 1 && cond->code[0] == EVALCODE; + // false for a match, true for continue + return r ? 0 : 1; + }; + CCVisitor visitor = {findEval, (uint8_t*)"", 0, NULL}; + bool out =! cc_visit(cond, visitor); + cc_free(cond); + return out; +} diff --git a/src/cc/CCdice.h b/src/cc/CCdice.h new file mode 100644 index 000000000..16b2f6136 --- /dev/null +++ b/src/cc/CCdice.h @@ -0,0 +1,34 @@ +/****************************************************************************** + * Copyright © 2014-2018 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + + +#ifndef CC_DICE_H +#define CC_DICE_H + +#include "CCinclude.h" + +#define EVAL_DICE 0xe6 + +bool DiceValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); + +std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds); +std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout); +double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid); +std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks); +std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount); +UniValue DiceInfo(uint256 diceid); +UniValue DiceList(); + +#endif diff --git a/src/cc/CCfaucet.h b/src/cc/CCfaucet.h new file mode 100644 index 000000000..39930cb20 --- /dev/null +++ b/src/cc/CCfaucet.h @@ -0,0 +1,32 @@ +/****************************************************************************** + * Copyright © 2014-2018 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + + +#ifndef CC_FAUCET_H +#define CC_FAUCET_H + +#include "CCinclude.h" + +#define EVAL_FAUCET 0xe4 +#define FAUCETSIZE (COIN / 10) + +bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); + +// CCcustom +std::string FaucetFund(uint64_t txfee,int64_t funds); +std::string FaucetGet(uint64_t txfee); +UniValue FaucetInfo(); + +#endif diff --git a/src/cc/CCfsm.h b/src/cc/CCfsm.h new file mode 100644 index 000000000..c6ea17024 --- /dev/null +++ b/src/cc/CCfsm.h @@ -0,0 +1,30 @@ +/****************************************************************************** + * Copyright © 2014-2018 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + + +#ifndef CC_FSM_H +#define CC_FSM_H + +#include "CCinclude.h" + +#define EVAL_FSM 0xe7 + +bool FSMValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); + +std::string FSMList(); +std::string FSMInfo(uint256 fsmtxid); +std::string FSMCreate(uint64_t txfee,std::string name,std::string states); + +#endif diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h new file mode 100644 index 000000000..4795ead3c --- /dev/null +++ b/src/cc/CCinclude.h @@ -0,0 +1,107 @@ +/****************************************************************************** + * Copyright © 2014-2018 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#ifndef CC_INCLUDE_H +#define CC_INCLUDE_H + +#include +#include