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/.travis.yml b/.travis.yml index de6f6a538..d9237a104 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,26 @@ -dist: xenial language: cpp + +matrix: + include: + - os: linux + dist: xenial + sudo: required + - os: osx + osx_image: xcode8 compiler: - gcc before_install: -- sudo add-apt-repository --yes ppa:ubuntu-sdk-team/ppa -- sudo apt-get update -qq -- sudo apt-get install libgnutls28-dev -- 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 +- 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: -- "./zcutil/build.sh -j 5" +- 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: @@ -21,3 +31,16 @@ notifications: 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/README.md b/README.md index 788635536..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. -- Whitepaper: [Komodo Whitepaper](https://komodoplatform.com/wp-content/uploads/2018/06/Komodo-Whitepaper-June-3.pdf) +- 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/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 51668eda8..7d55b85ff 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -15,9 +15,6 @@ #include "CCassets.h" -// need allassets -// find asset - int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs) { char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t j,vout,n = 0; @@ -35,7 +32,7 @@ int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK continue; if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - if ( (nValue= IsAssetvout(price,origpubkey,vintx,vout,assetid)) > 0 ) + if ( (nValue= IsAssetvout(price,origpubkey,vintx,vout,assetid)) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( total != 0 && maxinputs != 0 ) mtx.vin.push_back(CTxIn(txid,vout,CScript())); diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 0ab0bf874..a59a2325c 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -33,6 +33,13 @@ union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; typedef union _bits256 bits256; +struct CC_utxo +{ + uint256 txid; + int64_t nValue; + int32_t vout; +}; + struct CCcontract_info { uint256 prevtxid; diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index bea26e4a2..666132590 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -201,36 +201,124 @@ uint64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout) return(0); } +int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t *belowp,struct CC_utxo utxos[],int32_t numunspents,uint64_t value) +{ + int32_t i,abovei,belowi; int64_t above,below,gap,atx_value; + abovei = belowi = -1; + for (above=below=i=0; i value ) + { + gap = (atx_value - value); + if ( above == 0 || gap < above ) + { + above = gap; + abovei = i; + } + } + else + { + gap = (value - atx_value); + if ( below == 0 || gap < below ) + { + below = gap; + belowi = i; + } + } + //printf("value %.8f gap %.8f abovei.%d %.8f belowi.%d %.8f\n",dstr(value),dstr(gap),abovei,dstr(above),belowi,dstr(below)); + } + *aboveip = abovei; + *abovep = above; + *belowip = belowi; + *belowp = below; + //printf("above.%d below.%d\n",abovei,belowi); + if ( abovei >= 0 && belowi >= 0 ) + { + if ( above < (below >> 1) ) + return(abovei); + else return(belowi); + } + else if ( abovei >= 0 ) + return(abovei); + else return(belowi); + //return(abovei >= 0 && above < (below>>1) ? abovei : belowi); +} + uint64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,uint64_t total,int32_t maxinputs) { - int32_t vout,j,n = 0; uint64_t nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; + int32_t abovei,belowi,ind,vout,i,n = 0,maxutxos=1024; int64_t above,below; uint64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; #ifdef ENABLE_WALLET const CKeyStore& keystore = *pwalletMain; assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); + utxos = (struct CC_utxo *)calloc(maxutxos,sizeof(*utxos)); BOOST_FOREACH(const COutput& out, vecOutputs) { if ( out.fSpendable != 0 ) { txid = out.tx->GetHash(); vout = out.i; - for (j=0; jtxid = txid; + up->nValue = out.tx->vout[out.i].nValue; + up->vout = vout; + /*mtx.vin.push_back(CTxIn(txid,vout,CScript())); nValue = out.tx->vout[out.i].nValue; totalinputs += nValue; n++; if ( totalinputs >= total || n >= maxinputs ) + break;*/ + if ( n >= maxutxos ) break; } } } + remains = total; + for (i=0; i= 0 ) + ind = abovei; + else ind = belowi; + if ( ind < 0 ) + { + printf("error finding unspent i.%d of %d, %.8f vs %.8f, abovei.%d belowi.%d ind.%d\n",i,n,(double)remains/COIN,(double)total/COIN,abovei,belowi,ind); + free(utxos); + return(0); + } + up = &utxos[ind]; + utxos[ind] = utxos[--n]; + memset(&utxos[n],0,sizeof(utxos[n])); + mtx.vin.push_back(CTxIn(up->txid,up->vout,CScript())); + totalinputs += up->nValue; + remains -= up->nValue; + if ( totalinputs >= total || (i+1) >= maxinputs ) + break; + } + free(utxos); if ( totalinputs >= total ) return(totalinputs); #endif diff --git a/src/cc/auction.cpp b/src/cc/auction.cpp index cf3ae601a..7d8512ede 100644 --- a/src/cc/auction.cpp +++ b/src/cc/auction.cpp @@ -73,6 +73,7 @@ bool AuctionExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransactio bool AuctionValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; + return(false); // reject any auction CC for now numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 51d7f2f6f..b8b3b62cb 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -126,20 +126,21 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx uint64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs) { - char coinaddr[64]; uint64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t n = 0; + char coinaddr[64]; uint64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t 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; - // prevent dup + vout = (int32_t)it->first.index; + // no need to prevent dup if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - if ( (nValue= IsFaucetvout(cp,vintx,(int32_t)it->first.index)) > 1000000 ) + if ( (nValue= IsFaucetvout(cp,vintx,vout)) > 1000000 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( total != 0 && maxinputs != 0 ) - mtx.vin.push_back(CTxIn(txid,(int32_t)it->first.index,CScript())); + mtx.vin.push_back(CTxIn(txid,vout,CScript())); nValue = it->second.satoshis; totalinputs += nValue; n++; diff --git a/src/cc/fsm.cpp b/src/cc/fsm.cpp index 201535992..e3e112bf6 100644 --- a/src/cc/fsm.cpp +++ b/src/cc/fsm.cpp @@ -73,6 +73,7 @@ bool FSMExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &t bool FSMValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; + return(false); // reject any FSM CC for now numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; diff --git a/src/cc/lotto.cpp b/src/cc/lotto.cpp index 43367ab70..0ed223c25 100644 --- a/src/cc/lotto.cpp +++ b/src/cc/lotto.cpp @@ -73,6 +73,7 @@ bool LottoExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction bool LottoValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; + return(false); // reject any lotto CC for now numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index a0f07aba1..afa025851 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -282,7 +282,7 @@ uint64_t AddRewardsInputs(CScript &scriptPubKey,int32_t fundsflag,struct CCcontr break; if ( j != mtx.vin.size() ) continue; - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) + if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( (funcid= DecodeRewardsOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid)) != 0 ) { diff --git a/src/chainparams.cpp b/src/chainparams.cpp index d48d32c93..6903fe54e 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -568,9 +568,12 @@ public: 0 }; // These prefixes are the same as the testnet prefixes - base58Prefixes[PUBKEY_ADDRESS] = {0x1D,0x25}; - base58Prefixes[SCRIPT_ADDRESS] = {0x1C,0xBA}; - base58Prefixes[SECRET_KEY] = {0xEF}; + base58Prefixes[PUBKEY_ADDRESS] = std::vector(1,60); + base58Prefixes[SCRIPT_ADDRESS] = std::vector(1,85); + base58Prefixes[SECRET_KEY] = std::vector(1,188); + //base58Prefixes[PUBKEY_ADDRESS] = {0x1D,0x25}; + //base58Prefixes[SCRIPT_ADDRESS] = {0x1C,0xBA}; + //base58Prefixes[SECRET_KEY] = {0xEF}; // do not rely on these BIP32 prefixes; they are not specified and may change base58Prefixes[EXT_PUBLIC_KEY] = {0x04,0x35,0x87,0xCF}; base58Prefixes[EXT_SECRET_KEY] = {0x04,0x35,0x83,0x94}; diff --git a/src/komodo_kv.h b/src/komodo_kv.h index ee0496aae..2f4eadea4 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -88,7 +88,7 @@ int32_t komodo_kvsearch(uint256 *pubkeyp,int32_t current_height,uint32_t *flagsp if ( (retval= ptr->valuesize) > 0 ) memcpy(value,ptr->value,retval); } - } else fprintf(stderr,"couldnt find (%s)\n",(char *)key); + } //else fprintf(stderr,"couldnt find (%s)\n",(char *)key); portable_mutex_unlock(&KOMODO_KV_mutex); if ( retval < 0 ) { @@ -172,7 +172,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) memcpy(ptr->key,key,keylen); newflag = 1; HASH_ADD_KEYPTR(hh,KOMODO_KV,ptr->key,ptr->keylen,ptr); - fprintf(stderr,"KV add.(%s) (%s)\n",ptr->key,valueptr); + //fprintf(stderr,"KV add.(%s) (%s)\n",ptr->key,valueptr); } if ( newflag != 0 || (ptr->flags & KOMODO_KVPROTECTED) == 0 ) { diff --git a/src/main.h b/src/main.h index 56b439fc0..dfea318cb 100644 --- a/src/main.h +++ b/src/main.h @@ -103,9 +103,10 @@ static const unsigned int DATABASE_FLUSH_INTERVAL = 24 * 60 * 60; static const unsigned int MAX_REJECT_MESSAGE_LENGTH = 111; //static const bool DEFAULT_ADDRESSINDEX = false; +//static const bool DEFAULT_SPENTINDEX = false; #define DEFAULT_ADDRESSINDEX (GetArg("-ac_cc",0) != 0) +#define DEFAULT_SPENTINDEX (GetArg("-ac_cc",0) != 0) static const bool DEFAULT_TIMESTAMPINDEX = false; -static const bool DEFAULT_SPENTINDEX = false; static const unsigned int DEFAULT_DB_MAX_OPEN_FILES = 1000; static const bool DEFAULT_DB_COMPRESSION = true; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 295460618..c2e486a05 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4837,6 +4837,8 @@ int32_t ensure_CCrequirements() return(-1); else if ( GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX) == 0 ) return(-1); + else if ( GetBoolArg("-spentindex", DEFAULT_SPENTINDEX) == 0 ) + return(-1); else return(0); }