259
.gitlab-ci.yml
259
.gitlab-ci.yml
@@ -1,112 +1,90 @@
|
||||
stages:
|
||||
- build
|
||||
- test
|
||||
- deploy
|
||||
########################################################################################################################
|
||||
####START#### PROJECT LEVEL VARIABLES ####START####
|
||||
########################################################################################################################
|
||||
variables:
|
||||
VERSION: 0.4.0c
|
||||
VERUS_CLI_LINUX: Verus-CLI-Linux-v${VERSION}.tar.gz
|
||||
VERUS_CLI_WINDOWS: Verus-CLI-Windows-v${VERSION}.zip
|
||||
VERUS_CLI_MACOS: Verus-CLI-MacOS-v${VERSION}.tar.gz
|
||||
DOWNSTREAM_AGAMA_BRANCH: ${CI_COMMIT_REF_NAME}
|
||||
POST_MESSAGE: "Source: ${CI_PROJECT_NAME}/${CI_COMMIT_REF_NAME}\n
|
||||
Pipeline Trigger: ${CI_PIPELINE_SOURCE}\n
|
||||
Commit: ${CI_COMMIT_SHA}$\n
|
||||
${CI_COMMIT_MESSAGE}"
|
||||
PACKAGE_DIR_LINUX: linux64
|
||||
PACKAGE_DIR_WINDOWS: win64
|
||||
PACKAGE_DIR_MACOS: macos
|
||||
AGAMA_ARTIFACTS_LINUX: ${PACKAGE_DIR_LINUX}.tar.gz
|
||||
AGAMA_ARTIFACTS_WINDOWS: ${PACKAGE_DIR_WINDOWS}.zip
|
||||
AGAMA_ARTIFACTS_MACOS: ${PACKAGE_DIR_MACOS}.tar.gz
|
||||
AGAMA_ARTIFACTS_LINUX_CHECKSUM: ${AGAMA_ARTIFACTS_LINUX}.md5
|
||||
AGAMA_ARTIFACTS_WINDOWS_CHECKSUM: ${AGAMA_ARTIFACTS_WINDOWS}.md5
|
||||
AGAMA_ARTIFACTS_MACOS_CHECKSUM: ${AGAMA_ARTIFACTS_MACOS}.md5
|
||||
ARTIFACT_EXPIRATION: 1 week
|
||||
|
||||
########################################################################################################################
|
||||
####END#### PROJECT LEVEL VARIABLES ####END####
|
||||
########################################################################################################################
|
||||
########################################################################################################################
|
||||
########################################################################################################################
|
||||
####START#### Build Stage: compile and package komodo binaries for Verus CLI ####START#####
|
||||
####START#### Build Stage: compile and package komodo binaries for the Agama Wallet. ####START#####
|
||||
########################################################################################################################
|
||||
########################################################################################################################
|
||||
####START#### LINUX ####START####
|
||||
########################################################################################################################
|
||||
build:linux:
|
||||
image: asherd/verus-builders:verus-ubuntu
|
||||
build:ubuntu:
|
||||
stage: build
|
||||
image: ca333/komodo-builders:komodo-ubuntu
|
||||
variables:
|
||||
DOCKER_DRIVER: overlay2
|
||||
stage: build
|
||||
cache:
|
||||
key: "${CI_JOB_NAME}${CI_COMMIT_REF_NAME}"
|
||||
paths:
|
||||
- depends/built
|
||||
script:
|
||||
- zcutil/build.sh -j$(nproc)
|
||||
- mkdir verus-cli
|
||||
- mkdir ${PACKAGE_DIR_LINUX}
|
||||
- cp src/komodod
|
||||
src/komodo-cli
|
||||
src/fiat/verus
|
||||
src/verusd
|
||||
doc/man/verus-cli/linux/README.txt
|
||||
zcutil/fetch-params.sh
|
||||
verus-cli
|
||||
- mv verus-cli/fetch-params.sh verus-cli/fetch-params
|
||||
- chmod +x verus-cli/komodod
|
||||
- chmod +x verus-cli/komodo-cli
|
||||
- chmod +x verus-cli/verus
|
||||
- chmod +x verus-cli/verusd
|
||||
- chmod +x verus-cli/fetch-params
|
||||
- if [ "${CI_COMMIT_REF_NAME}" = "master" ]; then strip -g verus-cli/komodod && strip -g verus-cli/komodod; fi
|
||||
- tar -czvf ${VERUS_CLI_LINUX} verus-cli
|
||||
- md5sum ${VERUS_CLI_LINUX} > ${VERUS_CLI_LINUX}.md5
|
||||
- curl -F file=@"${VERUS_CLI_LINUX}"
|
||||
-F channels="${CLI_POST_CHANNEL}"
|
||||
-F initial_comment="${POST_MESSAGE}"
|
||||
-H "${SLACK_BOT_AUTH}"
|
||||
"https://slack.com/api/files.upload"
|
||||
src/komodo-cli
|
||||
${PACKAGE_DIR_LINUX}
|
||||
- chmod +x ${PACKAGE_DIR_LINUX}/komodod
|
||||
- chmod +x ${PACKAGE_DIR_LINUX}/komodo-cli
|
||||
- tar -czvf ${AGAMA_ARTIFACTS_LINUX} ${PACKAGE_DIR_LINUX}
|
||||
- md5sum ${AGAMA_ARTIFACTS_LINUX} > ${AGAMA_ARTIFACTS_LINUX_CHECKSUM}
|
||||
artifacts:
|
||||
paths:
|
||||
- ${VERUS_CLI_LINUX}
|
||||
- ${VERUS_CLI_LINUX}.md5
|
||||
- ${AGAMA_ARTIFACTS_LINUX}
|
||||
- ${AGAMA_ARTIFACTS_LINUX_CHECKSUM}
|
||||
expire_in: 1 week
|
||||
|
||||
########################################################################################################################
|
||||
####END#### LINUX ####END####
|
||||
########################################################################################################################
|
||||
####START#### WINDOWS ####START####
|
||||
########################################################################################################################
|
||||
build:windows:
|
||||
image: asherd/verus-builders:verus-windows
|
||||
stage: build
|
||||
image: ca333/komodo-builders:komodo-windows
|
||||
variables:
|
||||
DOCKER_DRIVER: overlay2
|
||||
stage: build
|
||||
cache:
|
||||
key: "${CI_JOB_NAME}${CI_COMMIT_REF_NAME}"
|
||||
paths:
|
||||
- depends/built
|
||||
script:
|
||||
- zcutil/build-win.sh -j$(nproc)
|
||||
- mkdir verus-cli
|
||||
- mkdir ${PACKAGE_DIR_WINDOWS}
|
||||
- cp src/komodod.exe
|
||||
src/komodo-cli.exe
|
||||
src/komodo-tx.exe
|
||||
src/fiat/verus.bat
|
||||
src/verusd.bat
|
||||
doc/man/verus-cli/windows/README.txt
|
||||
zcutil/fetch-params.bat
|
||||
zcutil/wget64.exe
|
||||
verus-cli
|
||||
- zip -r ${VERUS_CLI_WINDOWS} verus-cli
|
||||
- md5sum ${VERUS_CLI_WINDOWS} > ${VERUS_CLI_WINDOWS}.md5
|
||||
- curl -F file=@"${VERUS_CLI_WINDOWS}"
|
||||
-F channels="${CLI_POST_CHANNEL}"
|
||||
-F initial_comment="${POST_MESSAGE}"
|
||||
-H "${SLACK_BOT_AUTH}"
|
||||
"https://slack.com/api/files.upload"
|
||||
src/komodo-cli.exe
|
||||
src/komodo-tx.exe
|
||||
${PACKAGE_DIR_WINDOWS}
|
||||
- zip -r ${PACKAGE_DIR_WINDOWS}.zip ${PACKAGE_DIR_WINDOWS}
|
||||
- md5sum ${AGAMA_ARTIFACTS_WINDOWS} > ${AGAMA_ARTIFACTS_WINDOWS_CHECKSUM}
|
||||
artifacts:
|
||||
paths:
|
||||
- ${VERUS_CLI_WINDOWS}
|
||||
- ${VERUS_CLI_WINDOWS}.md5
|
||||
- ${AGAMA_ARTIFACTS_WINDOWS}
|
||||
- ${AGAMA_ARTIFACTS_WINDOWS_CHECKSUM}
|
||||
expire_in: 1 week
|
||||
########################################################################################################################
|
||||
####END#### WINDOWS ####END####
|
||||
########################################################################################################################
|
||||
####START#### MACOS ####START####
|
||||
########################################################################################################################
|
||||
build:mac:
|
||||
build:macos:
|
||||
stage: build
|
||||
tags: ["High Sierra"]
|
||||
cache:
|
||||
@@ -115,18 +93,13 @@ build:mac:
|
||||
- depends/built
|
||||
script:
|
||||
- zcutil/build-mac.sh -j$(sysctl -n hw.physicalcpu)
|
||||
- ./makeReleaseMac.sh
|
||||
- tar -czvf ${VERUS_CLI_MACOS} verus-cli
|
||||
- md5sum ${VERUS_CLI_MACOS} > ${VERUS_CLI_MACOS}.md5
|
||||
- curl -F file=@"${VERUS_CLI_MACOS}"
|
||||
-F channels="${CLI_POST_CHANNEL}"
|
||||
-F initial_comment="${POST_MESSAGE}"
|
||||
-H "${SLACK_BOT_AUTH}"
|
||||
"https://slack.com/api/files.upload"
|
||||
- ./makeRelease.sh ${PACKAGE_DIR_MACOS}
|
||||
- tar -czvf ${AGAMA_ARTIFACTS_MACOS} ${PACKAGE_DIR_MACOS}
|
||||
- md5sum ${AGAMA_ARTIFACTS_MACOS} > ${AGAMA_ARTIFACTS_MACOS_CHECKSUM}
|
||||
artifacts:
|
||||
paths:
|
||||
- ${VERUS_CLI_MACOS}
|
||||
- ${VERUS_CLI_MACOS}.md5
|
||||
- ${AGAMA_ARTIFACTS_MACOS}
|
||||
- ${AGAMA_ARTIFACTS_MACOS_CHECKSUM}
|
||||
expire_in: 1 week
|
||||
########################################################################################################################
|
||||
####END#### MACOS ####END####
|
||||
@@ -137,13 +110,13 @@ build:mac:
|
||||
########################################################################################################################
|
||||
########################################################################################################################
|
||||
########################################################################################################################
|
||||
####START#### Test stage: Test functionality of komodo binaries. Produce code quality and SAST reports. ####START####
|
||||
####START#### Test stage: Produce code quality and static application security test reports. ####START####
|
||||
########################################################################################################################
|
||||
########################################################################################################################
|
||||
########################################################################################################################
|
||||
####START#### Code Quality ####START####
|
||||
########################################################################################################################
|
||||
.code_quality:
|
||||
code_quality:
|
||||
image: docker:stable
|
||||
variables:
|
||||
DOCKER_DRIVER: overlay2
|
||||
@@ -165,7 +138,7 @@ build:mac:
|
||||
########################################################################################################################
|
||||
####START#### Static Application Security Tests ####START####
|
||||
########################################################################################################################
|
||||
.sast:
|
||||
sast:
|
||||
image: docker:stable
|
||||
variables:
|
||||
DOCKER_DRIVER: overlay2
|
||||
@@ -185,149 +158,7 @@ build:mac:
|
||||
####END#### Static Application Security Tests ####END####
|
||||
########################################################################################################################
|
||||
########################################################################################################################
|
||||
####START#### Run Verus CLI on Ubuntu Xenial (16.04) ####START####
|
||||
########################################################################################################################
|
||||
.ubuntu:xenial:
|
||||
image: ubuntu:xenial
|
||||
variables:
|
||||
DOCKER_DRIVER: overlay2
|
||||
stage: test
|
||||
before_script:
|
||||
- apt update && apt install -y wget libgomp1 libcurl4-gnutls-dev python
|
||||
- rm -rf /root/.komodo || true
|
||||
- mv .komodo /root/ || true
|
||||
script:
|
||||
- tar -xzvf ${VERUS_CLI_LINUX}
|
||||
- export PATH=$PATH:$CI_PROJECT_DIR/verus-cli
|
||||
- python qa/verus-cli-tests/verus-cli-tester.py
|
||||
after_script:
|
||||
- mv /root/.komodo ./ || true
|
||||
cache:
|
||||
key: ${CI_JOB_NAME}
|
||||
paths: [.komodo]
|
||||
artifacts:
|
||||
paths: [log.txt]
|
||||
expire_in: 1 week
|
||||
dependencies:
|
||||
- build:linux
|
||||
########################################################################################################################
|
||||
####END#### Run Verus CLI on Ubuntu Xenial (16.04) ####END####
|
||||
####END#### Test stage ####END####
|
||||
########################################################################################################################
|
||||
########################################################################################################################
|
||||
####START#### Run Verus CLI on Ubuntu Bionic (18.04) ####START####
|
||||
########################################################################################################################
|
||||
.ubuntu:bionic:
|
||||
image: ubuntu:bionic
|
||||
variables:
|
||||
DOCKER_DRIVER: overlay2
|
||||
stage: test
|
||||
before_script:
|
||||
- apt update && apt install -y wget libgomp1 libcurl4-gnutls-dev python
|
||||
- rm -rf /root/.komodo || true
|
||||
- mv .komodo /root/ || true
|
||||
script:
|
||||
- tar -xzvf ${VERUS_CLI_LINUX}
|
||||
- export PATH=$PATH:$CI_PROJECT_DIR/verus-cli
|
||||
- python qa/verus-cli-tests/verus-cli-tester.py
|
||||
after_script:
|
||||
- mv /root/.komodo ./ || true
|
||||
cache:
|
||||
key: ${CI_JOB_NAME}
|
||||
paths: [.komodo]
|
||||
artifacts:
|
||||
paths: [log.txt]
|
||||
expire_in: 1 week
|
||||
dependencies:
|
||||
- build:linux
|
||||
########################################################################################################################
|
||||
####END#### Run Verus CLI on Ubuntu Bionic (18.04) ####END####
|
||||
########################################################################################################################
|
||||
########################################################################################################################
|
||||
####START#### Run Verus CLI on MacOS Sierra (10.12.6) ####START####
|
||||
########################################################################################################################
|
||||
.macos:sierra:
|
||||
stage: test
|
||||
tags: ["Sierra"]
|
||||
script:
|
||||
- tar -xzvf $VERUS_CLI_MACOS
|
||||
- export PATH=$PATH:$CI_PROJECT_DIR/verus-cli
|
||||
- python qa/verus-cli-tests/verus-cli-tester.py
|
||||
artifacts:
|
||||
paths: [log.txt]
|
||||
expire_in: 1 week
|
||||
dependencies:
|
||||
- build:mac
|
||||
########################################################################################################################
|
||||
####END#### Run Verus CLI on MacOS Sierra (10.12.6) ####END####
|
||||
########################################################################################################################
|
||||
########################################################################################################################
|
||||
####START#### Run Verus CLI on MacOS High Sierra (10.12.6) ####START####
|
||||
########################################################################################################################
|
||||
.macos:high-sierra:
|
||||
stage: test
|
||||
tags: ["High Sierra"]
|
||||
script:
|
||||
- tar -xzvf ${VERUS_CLI_MACOS}
|
||||
- export PATH=$PATH:$CI_PROJECT_DIR/verus-cli
|
||||
- python qa/verus-cli-tests/verus-cli-tester.py
|
||||
artifacts:
|
||||
paths: [log.txt]
|
||||
expire_in: 1 week
|
||||
dependencies:
|
||||
- build:mac
|
||||
########################################################################################################################
|
||||
####START#### Run Verus CLI on MacOS High Sierra (10.12.6) ####START####
|
||||
########################################################################################################################
|
||||
########################################################################################################################
|
||||
####START#### Run Verus CLI on Windows 10 ####START####
|
||||
########################################################################################################################
|
||||
.windows:10:
|
||||
stage: test
|
||||
tags: ["Windows 10"]
|
||||
script:
|
||||
- PowerShell Expand-Archive -Path %VERUS_CLI_WINDOWS% -DestinationPath %CI_PROJECT_DIR%
|
||||
- set PATH=%PATH%;%CI_PROJECT_DIR%\verus-cli
|
||||
- qa\verus-cli-tests\verus-cli-tester.py
|
||||
artifacts:
|
||||
paths: [log.txt]
|
||||
expire_in: 1 week
|
||||
dependencies:
|
||||
- build:windows
|
||||
########################################################################################################################
|
||||
####END#### Run Verus CLI on Windows 10 ####END####
|
||||
########################################################################################################################
|
||||
########################################################################################################################
|
||||
####END#### Test Stage ####END####
|
||||
########################################################################################################################
|
||||
########################################################################################################################
|
||||
####START#### Deploy ####START####
|
||||
########################################################################################################################
|
||||
deploy:
|
||||
stage: deploy
|
||||
image: google/cloud-sdk:alpine
|
||||
variables:
|
||||
DOCKER_DRIVER: overlay2
|
||||
dependencies:
|
||||
- build:linux
|
||||
- build:windows
|
||||
- build:mac
|
||||
script:
|
||||
- mkdir Windows && mkdir Linux && mkdir MacOS &&
|
||||
mv ${VERUS_CLI_WINDOWS} Windows &&
|
||||
mv ${VERUS_CLI_LINUX} Linux &&
|
||||
mv ${VERUS_CLI_MACOS} MacOS
|
||||
- echo "$AUTH_KEY" > AUTH_KEY.json &&
|
||||
gcloud auth activate-service-account
|
||||
--key-file AUTH_KEY.json
|
||||
- gsutil cp -r Windows Linux MacOS $STAGING/${CI_PROJECT_NAME}/${CI_COMMIT_REF_NAME}/
|
||||
- curl -X POST
|
||||
-F token="$CI_JOB_TOKEN"
|
||||
-F ref="$DOWNSTREAM_AGAMA_BRANCH"
|
||||
-F variables\[UPSTREAM_TRIGGER_INFO\]="${POST_MESSAGE}"
|
||||
-F variables\[VERUS_CLI_LINUX\]="${VERUS_CLI_LINUX}"
|
||||
-F variables\[VERUS_CLI_WINDOWS\]="${VERUS_CLI_WINDOWS}"
|
||||
-F variables\[VERUS_CLI_MACOS\]="${VERUS_CLI_MACOS}"
|
||||
"https://gitlab.com/api/v4/projects/8018592/trigger/pipeline"
|
||||
########################################################################################################################
|
||||
####END#### Deploy ####END####
|
||||
########################################################################################################################
|
||||
|
||||
188
README.md
188
README.md
@@ -1,16 +1,13 @@
|
||||
## VerusCoin version 0.4.0c
|
||||
|
||||
VerusCoin is a new, mineable and stakeable cryptocurrency. It is a live fork of Komodo that retains its Zcash lineage and improves it. VerusCoin will leverage the Komodo platform and dPoW notarization for enhanced security and cross-chain interoperability. We have added a variation of a zawy12, lwma difficulty algorithm, a new CPU-optimized hash algorithm and a new algorithm for fair proof of stake. We describe these changes and vision going forward in a [our Phase I white paper](http://185.25.51.16/papers/VerusPhaseI.pdf) and [our Vision](http://185.25.51.16/papers/VerusVision.pdf).
|
||||
- [VerusCoin web site https://veruscoin.io/ Wallets and CLI tools](https://veruscoin.io/)
|
||||
- [VerusCoin Explorer](https://explorer.veruscoin.io/)
|
||||
[](https://travis-ci.org/KomodoPlatform/komodo)
|
||||
---
|
||||

|
||||
|
||||
|
||||
## Komodo with Bitcore
|
||||
This version of Komodo contains Bitcore support for komodo and all its assetchains.
|
||||
## Komodo
|
||||
|
||||
## Komodod
|
||||
This software is the VerusCoin enhanced Komodo client. Generally, you will use this if you want to mine VRSC or setup a full node. When you run the wallet it launches komodod automatically. On first launch it downloads Zcash parameters, roughly 1GB, which is mildly slow.
|
||||
The wallet downloads and stores the block chain or asset chain of the coin you select. It downloads and stores the entire history of the coins 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.
|
||||
This is the official Komodo sourcecode repository based on https://github.com/jl777/komodo.
|
||||
|
||||
## Development Resources
|
||||
|
||||
- Komodo Website: [https://komodoplatform.com](https://komodoplatform.com/)
|
||||
- Komodo Blockexplorer: [https://kmdexplorer.io](https://kmdexplorer.io/)
|
||||
@@ -26,23 +23,23 @@ The wallet downloads and stores the block chain or asset chain of the coin you s
|
||||
|
||||
## List of Komodo Platform Technologies
|
||||
|
||||
- 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 - 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)
|
||||
- Also note you receive 5% APR on your holdings.
|
||||
[See this article for more details](https://komodoplatform.atlassian.net/wiki/spaces/KPSD/pages/20480015/Claim+KMD+Interest+in+Agama)
|
||||
- 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 - 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)
|
||||
- Also note you receive 5% Active User Reward on your balance.
|
||||
[See this article for more details](https://support.komodoplatform.com/en/support/solutions/articles/29000024515-how-to-claim-the-kmd-active-user-reward-in-agama)
|
||||
|
||||
## Tech Specification
|
||||
- Max Supply: 200 million KMD.
|
||||
- Block Time: 1M 2s
|
||||
- Block Reward: 3KMD
|
||||
- Max Supply: 200 million KMD
|
||||
- Block Time: 1m 2s
|
||||
- Block Reward: 3 KMD
|
||||
- Mining Algorithm: Equihash
|
||||
|
||||
## About this Project
|
||||
@@ -57,86 +54,121 @@ Komodo is based on Zcash and has been extended by our innovative consensus algor
|
||||
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-gnutls-dev bsdmainutils automake curl
|
||||
```
|
||||
|
||||
### Build Komodo
|
||||
|
||||
Building
|
||||
--------
|
||||
This software is based on zcash and considered experimental and is continously undergoing heavy development.
|
||||
|
||||
First time you'll need to get assorted startup values downloaded. This takes a moderate amount of time once but then does not need to be repeated unless you bring a new system up. The command is:
|
||||
```
|
||||
./zcutil/fetch-params.sh
|
||||
```
|
||||
Building for Ubunutu/Mint:
|
||||
```
|
||||
./zcutil/build.sh
|
||||
```
|
||||
Building for Mac OS/X (see README-MAC.md):
|
||||
```
|
||||
./zcutil/build-mac.sh
|
||||
```
|
||||
Building for Windows:
|
||||
```
|
||||
./zcutil/build-win.sh
|
||||
```
|
||||
VerusCoin
|
||||
------
|
||||
We develop on dev and some other branches and produce releases of of the master branch, using pull requests to manage what goes into master. The dev branch is considered the bleeding edge codebase, and may even be oncompatible from time to time, while the master-branch is considered tested (unit tests, runtime tests, functionality). At no point of time do the Komodo Platform developers or Verus Developers take any responsbility for any damage out of the usage of this software.
|
||||
|
||||
Verus builds for all operating systems out of the same codebase. Follow the OS specific instructions from below.
|
||||
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/VerusCoin/VerusCoin
|
||||
cd VerusCoin
|
||||
#you might want to: git checkout <branch>; git pull
|
||||
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.sh -j8
|
||||
#This can take some time.
|
||||
```
|
||||
|
||||
**The VerusCoin enhanced komodo is experimental and a work-in-progress.** Use at your own risk.
|
||||
#### 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
|
||||
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-gnutls-dev bsdmainutils automake curl cmake mingw-w64
|
||||
curl https://sh.rustup.rs -sSf | sh
|
||||
source $HOME/.cargo/env
|
||||
rustup target add x86_64-pc-windows-gnu
|
||||
git clone https://github.com/jl777/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.
|
||||
|
||||
#To view komodod output:
|
||||
tail -f ~/.komodo/debug.log
|
||||
#To view VRSC output:
|
||||
tail -f ~/.komodo/VRSC/debug.log
|
||||
Note that this directory is correct for Linux, not Mac or Windows
|
||||
#To view all command
|
||||
./src/komodo-cli help
|
||||
**Zcash is unfinished and highly experimental.** Use at your own risk.
|
||||
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`
|
||||
|
||||
#### :ledger: Deprecation Policy
|
||||
#### Create komodo.conf
|
||||
|
||||
This release is considered deprecated 16 weeks after the release day. There
|
||||
is an automatic deprecation shutdown feature which will halt the node some
|
||||
time after this 16 week time period. The automatic feature is based on block
|
||||
height.
|
||||
Create a komodo.conf file:
|
||||
|
||||
#Older Komodo Details
|
||||
The remaining text is from the komodo source we forked when creating VerusCoin/Veruscoin.
|
||||
```
|
||||
mkdir ~/.komodo
|
||||
cd ~/.komodo
|
||||
touch komodo.conf
|
||||
|
||||
#Add the following lines to the komodo.conf file:
|
||||
rpcuser=yourrpcusername
|
||||
rpcpassword=yoursecurerpcpassword
|
||||
rpcbind=127.0.0.1
|
||||
txindex=1
|
||||
addnode=5.9.102.210
|
||||
addnode=78.47.196.146
|
||||
addnode=178.63.69.164
|
||||
addnode=88.198.65.74
|
||||
addnode=5.9.122.241
|
||||
addnode=144.76.94.38
|
||||
addnode=89.248.166.91
|
||||
```
|
||||
### Create your own Blockchain based on Komodo
|
||||
|
||||
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
|
||||
./komodod -ac_name=name_of_your_chain -ac_supply=100000 -bind=ip_of_server_1 &
|
||||
```
|
||||
|
||||
#### On server 2 run:
|
||||
```shell
|
||||
./komodod -ac_name=name_of_your_chain -ac_supply=100000 -addnode=ip_of_server_1 -gen &
|
||||
```
|
||||
|
||||
**Komodo is based on Zcash which is unfinished and highly experimental.** Use at your own risk.
|
||||
|
||||
License
|
||||
-------
|
||||
For license information see the file [COPYING](COPYING).
|
||||
|
||||
**NOTE TO EXCHANGES:**
|
||||
https://bitcointalk.org/index.php?topic=1605144.msg17732151#msg17732151
|
||||
There is a small chance that an outbound transaction will give an error due to mismatched values in wallet calculations. There is a -exchange option that you can run komodod with, but make sure to have the entire transaction history under the same -exchange mode. Otherwise you will get wallet conflicts.
|
||||
|
||||
**To change modes:**
|
||||
|
||||
a) backup all privkeys (launch komodod with `-exportdir=<path>` 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
|
||||
a) backup all privkeys (launch komodod with `-exportdir=<path>` 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:
|
||||
```shell
|
||||
./verusd -exportdir=/tmp &
|
||||
./verus dumpwallet example
|
||||
./verus stop
|
||||
mv ~/.komodo/VRSC ~/.komodo/VRSC.old && mkdir ~/.komodo/VRSC && cp ~/.komodo/VRSC.old/VRSC.conf ~/.komodo/VRSC.old/peers.dat ~/.komodo/VRSC
|
||||
./verusd -exchange -exportdir=/tmp &
|
||||
./verus importwallet /tmp/example
|
||||
./komodod -exportdir=/tmp &
|
||||
./komodo-cli dumpwallet example
|
||||
./komodo-cli stop
|
||||
mv ~/.komodo ~/.komodo.old && mkdir ~/.komodo && cp ~/.komodo.old/komodo.conf ~/.komodo.old/peers.dat ~/.komodo
|
||||
./komodod -exchange -exportdir=/tmp &
|
||||
./komodo-cli importwallet /tmp/example
|
||||
```
|
||||
---
|
||||
|
||||
|
||||
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 notices and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
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.
|
||||
|
||||
@@ -1,29 +1,19 @@
|
||||
#!/bin/sh
|
||||
|
||||
KMD_DIR=verus-cli
|
||||
mkdir ${KMD_DIR}
|
||||
|
||||
cp src/fiat/verus \
|
||||
src/verusd \
|
||||
doc/man/verus-cli/mac/README.txt \
|
||||
zcutil/fetch-params.sh \
|
||||
verus-cli
|
||||
mv verus-cli/fetch-params.sh verus-cli/fetch-params
|
||||
chmod +x ${KMD_DIR}/fetch-params
|
||||
chmod +x ${KMD_DIR}/verus
|
||||
chmod +x ${KMD_DIR}/verusd
|
||||
PACKAGE_DIR="$@"
|
||||
mkdir ${PACKAGE_DIR}
|
||||
|
||||
binaries=("komodo-cli" "komodod")
|
||||
alllibs=()
|
||||
for binary in "${binaries[@]}";
|
||||
do
|
||||
# do the work in the destination directory
|
||||
cp src/${binary} ${KMD_DIR}
|
||||
cp src/${binary} ${PACKAGE_DIR}
|
||||
# find the dylibs to copy for komodod
|
||||
DYLIBS=`otool -L ${KMD_DIR}/${binary} | grep "/usr/local" | awk -F' ' '{ print $1 }'`
|
||||
echo "copying ${DYLIBS} to ${KMD_DIR}"
|
||||
DYLIBS=`otool -L ${PACKAGE_DIR}/${binary} | grep "/usr/local" | awk -F' ' '{ print $1 }'`
|
||||
echo "copying ${DYLIBS} to ${PACKAGE_DIR}"
|
||||
# copy the dylibs to the srcdir
|
||||
for dylib in ${DYLIBS}; do cp -rf ${dylib} ${KMD_DIR}; done
|
||||
for dylib in ${DYLIBS}; do cp -rf ${dylib} ${PACKAGE_DIR}; done
|
||||
done
|
||||
|
||||
libraries=("libgcc_s.1.dylib" "libgomp.1.dylib" "libidn2.0.dylib" "libstdc++.6.dylib")
|
||||
@@ -31,10 +21,10 @@ libraries=("libgcc_s.1.dylib" "libgomp.1.dylib" "libidn2.0.dylib" "libstdc++.6.d
|
||||
for binary in "${libraries[@]}";
|
||||
do
|
||||
# find the dylibs to copy for komodod
|
||||
DYLIBS=`otool -L ${KMD_DIR}/${binary} | grep "/usr/local" | awk -F' ' '{ print $1 }'`
|
||||
echo "copying ${DYLIBS} to ${KMD_DIR}"
|
||||
DYLIBS=`otool -L ${PACKAGE_DIR}/${binary} | grep "/usr/local" | awk -F' ' '{ print $1 }'`
|
||||
echo "copying ${DYLIBS} to ${PACKAGE_DIR}"
|
||||
# copy the dylibs to the srcdir
|
||||
for dylib in ${DYLIBS}; do cp -rf ${dylib} ${KMD_DIR}; alllibs+=(${dylib}); done
|
||||
for dylib in ${DYLIBS}; do cp -rf ${dylib} ${PACKAGE_DIR}; alllibs+=(${dylib}); done
|
||||
done
|
||||
|
||||
indirectlibraries=("libintl.8.dylib" "libunistring.2.dylib")
|
||||
@@ -44,10 +34,10 @@ do
|
||||
# Need to undo this for the dylibs when we are done
|
||||
chmod 755 src/${binary}
|
||||
# find the dylibs to copy for komodod
|
||||
DYLIBS=`otool -L ${KMD_DIR}/${binary} | grep "/usr/local" | awk -F' ' '{ print $1 }'`
|
||||
echo "copying indirect ${DYLIBS} to ${KMD_DIR}"
|
||||
DYLIBS=`otool -L ${PACKAGE_DIR}/${binary} | grep "/usr/local" | awk -F' ' '{ print $1 }'`
|
||||
echo "copying indirect ${DYLIBS} to ${PACKAGE_DIR}"
|
||||
# copy the dylibs to the dest dir
|
||||
for dylib in ${DYLIBS}; do cp -rf ${dylib} ${KMD_DIR}; alllibs+=(${dylib}); done
|
||||
for dylib in ${DYLIBS}; do cp -rf ${dylib} ${PACKAGE_DIR}; alllibs+=(${dylib}); done
|
||||
done
|
||||
|
||||
for binary in "${binaries[@]}";
|
||||
@@ -57,9 +47,9 @@ do
|
||||
for dylib in "${alllibs[@]}"
|
||||
do
|
||||
echo "Next lib is ${dylib} "
|
||||
install_name_tool -change ${dylib} @executable_path/`basename ${dylib}` ${KMD_DIR}/${binary}
|
||||
install_name_tool -change ${dylib} @executable_path/`basename ${dylib}` ${PACKAGE_DIR}/${binary}
|
||||
done
|
||||
chmod +x ${KMD_DIR}/${binary}
|
||||
chmod +x ${PACKAGE_DIR}/${binary}
|
||||
done
|
||||
|
||||
for binary in "${libraries[@]}";
|
||||
@@ -69,8 +59,6 @@ do
|
||||
for dylib in "${alllibs[@]}"
|
||||
do
|
||||
echo "Next lib is ${dylib} "
|
||||
install_name_tool -change ${dylib} @executable_path/`basename ${dylib}` ${KMD_DIR}/${binary}
|
||||
install_name_tool -change ${dylib} @executable_path/`basename ${dylib}` ${PACKAGE_DIR}/${binary}
|
||||
done
|
||||
done
|
||||
|
||||
|
||||
|
||||
@@ -14,6 +14,11 @@ testScripts=(
|
||||
'ac_private.py'
|
||||
'verushash.py'
|
||||
'cryptoconditions.py'
|
||||
'cryptoconditions_dice.py'
|
||||
'cryptoconditions_faucet.py'
|
||||
'cryptoconditions_oracles.py'
|
||||
'cryptoconditions_rewards.py'
|
||||
'cryptoconditions_token.py'
|
||||
'paymentdisclosure.py'
|
||||
'prioritisetransaction.py'
|
||||
'wallet_treestate.py'
|
||||
|
||||
259
qa/rpc-tests/cryptoconditions_dice.py
Executable file
259
qa/rpc-tests/cryptoconditions_dice.py
Executable file
@@ -0,0 +1,259 @@
|
||||
#!/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
|
||||
from cryptoconditions import assert_success, assert_error, generate_random_string
|
||||
|
||||
class CryptoconditionsDiceTest(BitcoinTestFramework):
|
||||
|
||||
def setup_chain(self):
|
||||
print("Initializing CC test directory "+self.options.tmpdir)
|
||||
self.num_nodes = 2
|
||||
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.addr1 = "RXEXoa1nRmKhMbuZovpcYwQMsicwzccZBp"
|
||||
self.pubkey1 = "024026d4ad4ecfc1f705a9b42ca64af6d2ad947509c085534a30b8861d756c6ff0"
|
||||
self.privkey1 = "UtdydP56pGTFmawHzHr1wDrc4oUwCNW1ttX8Pc3KrvH3MA8P49Wi"
|
||||
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir,
|
||||
extra_args=[[
|
||||
# always give -ac_name as first extra_arg and port as third
|
||||
'-ac_name=REGTEST',
|
||||
'-conf='+self.options.tmpdir+'/node0/REGTEST.conf',
|
||||
'-port=64367',
|
||||
'-rpcport=64368',
|
||||
'-regtest',
|
||||
'-addressindex=1',
|
||||
'-spentindex=1',
|
||||
'-ac_supply=5555555',
|
||||
'-ac_reward=10000000000000',
|
||||
'-pubkey=' + self.pubkey,
|
||||
'-ac_cc=2',
|
||||
'-whitelist=127.0.0.1',
|
||||
'-debug',
|
||||
'--daemon',
|
||||
'-rpcuser=rt',
|
||||
'-rpcpassword=rt'
|
||||
],
|
||||
['-ac_name=REGTEST',
|
||||
'-conf='+self.options.tmpdir+'/node1/REGTEST.conf',
|
||||
'-port=64365',
|
||||
'-rpcport=64366',
|
||||
'-regtest',
|
||||
'-addressindex=1',
|
||||
'-spentindex=1',
|
||||
'-ac_supply=5555555',
|
||||
'-ac_reward=10000000000000',
|
||||
'-pubkey=' + self.pubkey1,
|
||||
'-ac_cc=2',
|
||||
'-whitelist=127.0.0.1',
|
||||
'-debug',
|
||||
'-addnode=127.0.0.1:64367',
|
||||
'--daemon',
|
||||
'-rpcuser=rt',
|
||||
'-rpcpassword=rt']]
|
||||
)
|
||||
self.is_network_split = split
|
||||
self.rpc = self.nodes[0]
|
||||
self.rpc1 = self.nodes[1]
|
||||
self.sync_all()
|
||||
print("Done setting up network")
|
||||
|
||||
def send_and_mine(self, xtn, rpc_connection):
|
||||
txid = rpc_connection.sendrawtransaction(xtn)
|
||||
assert txid, 'got txid'
|
||||
# we need the tx above to be confirmed in the next block
|
||||
rpc_connection.generate(1)
|
||||
return txid
|
||||
|
||||
def run_dice_tests(self):
|
||||
rpc = self.nodes[0]
|
||||
rpc1 = self.nodes[1]
|
||||
self.sync_all()
|
||||
|
||||
# have to generate few blocks on second node to be able to place bets
|
||||
rpc1.generate(10)
|
||||
result = rpc1.getbalance()
|
||||
assert_greater_than(result, 100000)
|
||||
|
||||
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'], rpc)
|
||||
|
||||
# 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'], rpc)
|
||||
|
||||
# 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 = rpc1.dicebet(dicename,diceid,"0","2")
|
||||
assert_error(result)
|
||||
|
||||
# placing negative amount bet
|
||||
result = rpc1.dicebet(dicename,diceid,"-1","2")
|
||||
assert_error(result)
|
||||
|
||||
# placing bet more than maxbet
|
||||
result = rpc1.dicebet(dicename,diceid,"900","2")
|
||||
assert_error(result)
|
||||
|
||||
# placing bet with amount more than funding
|
||||
result = rpc1.dicebet(dicename,diceid,"3000","2")
|
||||
assert_error(result)
|
||||
|
||||
# placing bet with potential won more than funding
|
||||
result = rpc1.dicebet(dicename,diceid,"750","9")
|
||||
assert_error(result)
|
||||
|
||||
# placing 0 odds bet
|
||||
result = rpc1.dicebet(dicename,diceid,"1","0")
|
||||
assert_error(result)
|
||||
|
||||
# placing negative odds bet
|
||||
result = rpc1.dicebet(dicename,diceid,"1","-1")
|
||||
assert_error(result)
|
||||
|
||||
# placing bet with odds more than allowed
|
||||
result = rpc1.dicebet(dicename,diceid,"1","11")
|
||||
assert_error(result)
|
||||
|
||||
# placing bet with not correct dice name
|
||||
result = rpc1.dicebet("nope",diceid,"100","2")
|
||||
assert_error(result)
|
||||
|
||||
# placing bet with not correct dice id
|
||||
result = rpc1.dicebet(dicename,self.pubkey,"100","2")
|
||||
assert_error(result)
|
||||
|
||||
# have to make some entropy for the next test
|
||||
entropytx = 0
|
||||
fundingsum = 1
|
||||
while entropytx < 110:
|
||||
fundingsuminput = str(fundingsum)
|
||||
fundinghex = rpc.diceaddfunds(dicename,diceid,fundingsuminput)
|
||||
result = self.send_and_mine(fundinghex['hex'], rpc)
|
||||
entropytx = entropytx + 1
|
||||
fundingsum = fundingsum + 1
|
||||
|
||||
rpc.generate(2)
|
||||
self.sync_all()
|
||||
|
||||
# valid bet placing
|
||||
placebet = rpc1.dicebet(dicename,diceid,"100","2")
|
||||
betid = self.send_and_mine(placebet["hex"], rpc1)
|
||||
assert result, "bet placed"
|
||||
|
||||
# check bet status
|
||||
result = rpc1.dicestatus(dicename,diceid,betid)
|
||||
assert_success(result)
|
||||
|
||||
# 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:3, checking if balance changed correct
|
||||
# losscounter = 0
|
||||
# wincounter = 0
|
||||
# betcounter = 0
|
||||
#
|
||||
# while (betcounter < 10):
|
||||
# placebet = rpc1.dicebet(dicename,diceid,"1","2")
|
||||
# betid = self.send_and_mine(placebet["hex"], rpc1)
|
||||
# time.sleep(3)
|
||||
# self.sync_all()
|
||||
# finish = rpc.dicefinish(dicename,diceid,betid)
|
||||
# self.send_and_mine(finish["hex"], rpc1)
|
||||
# self.sync_all()
|
||||
# time.sleep(3)
|
||||
# betresult = rpc1.dicestatus(dicename,diceid,betid)
|
||||
# betcounter = betcounter + 1
|
||||
# if betresult["status"] == "loss":
|
||||
# losscounter = losscounter + 1
|
||||
# elif betresult["status"] == "win":
|
||||
# wincounter = wincounter + 1
|
||||
# else:
|
||||
# pass
|
||||
#
|
||||
# # funding balance should increase if player loss, decrease if player won
|
||||
# fundbalanceguess = funding + losscounter - wincounter * 2
|
||||
# fundinfoactual = rpc.diceinfo(diceid)
|
||||
# assert_equal(round(fundbalanceguess),round(float(fundinfoactual['funding'])))
|
||||
|
||||
def run_test(self):
|
||||
print("Mining blocks...")
|
||||
rpc = self.nodes[0]
|
||||
rpc1 = self.nodes[1]
|
||||
# utxos from block 1 become mature in block 101
|
||||
rpc.generate(101)
|
||||
self.sync_all()
|
||||
rpc.getinfo()
|
||||
rpc1.getinfo()
|
||||
# this corresponds to -pubkey above
|
||||
print("Importing privkeys")
|
||||
rpc.importprivkey(self.privkey)
|
||||
rpc1.importprivkey(self.privkey1)
|
||||
self.run_dice_tests()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
CryptoconditionsDiceTest ().main()
|
||||
173
qa/rpc-tests/cryptoconditions_faucet.py
Executable file
173
qa/rpc-tests/cryptoconditions_faucet.py
Executable file
@@ -0,0 +1,173 @@
|
||||
#!/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
|
||||
from cryptoconditions import assert_success, assert_error, generate_random_string
|
||||
|
||||
|
||||
class CryptoconditionsFaucetTest(BitcoinTestFramework):
|
||||
|
||||
def setup_chain(self):
|
||||
print("Initializing CC test directory "+self.options.tmpdir)
|
||||
self.num_nodes = 2
|
||||
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.addr1 = "RXEXoa1nRmKhMbuZovpcYwQMsicwzccZBp"
|
||||
self.pubkey1 = "024026d4ad4ecfc1f705a9b42ca64af6d2ad947509c085534a30b8861d756c6ff0"
|
||||
self.privkey1 = "UtdydP56pGTFmawHzHr1wDrc4oUwCNW1ttX8Pc3KrvH3MA8P49Wi"
|
||||
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir,
|
||||
extra_args=[[
|
||||
# always give -ac_name as first extra_arg and port as third
|
||||
'-ac_name=REGTEST',
|
||||
'-conf='+self.options.tmpdir+'/node0/REGTEST.conf',
|
||||
'-port=64367',
|
||||
'-rpcport=64368',
|
||||
'-regtest',
|
||||
'-addressindex=1',
|
||||
'-spentindex=1',
|
||||
'-ac_supply=5555555',
|
||||
'-ac_reward=10000000000000',
|
||||
'-pubkey=' + self.pubkey,
|
||||
'-ac_cc=2',
|
||||
'-whitelist=127.0.0.1',
|
||||
'-debug',
|
||||
'--daemon',
|
||||
'-rpcuser=rt',
|
||||
'-rpcpassword=rt'
|
||||
],
|
||||
['-ac_name=REGTEST',
|
||||
'-conf='+self.options.tmpdir+'/node1/REGTEST.conf',
|
||||
'-port=64365',
|
||||
'-rpcport=64366',
|
||||
'-regtest',
|
||||
'-addressindex=1',
|
||||
'-spentindex=1',
|
||||
'-ac_supply=5555555',
|
||||
'-ac_reward=10000000000000',
|
||||
'-pubkey=' + self.pubkey1,
|
||||
'-ac_cc=2',
|
||||
'-whitelist=127.0.0.1',
|
||||
'-debug',
|
||||
'-addnode=127.0.0.1:64367',
|
||||
'--daemon',
|
||||
'-rpcuser=rt',
|
||||
'-rpcpassword=rt']]
|
||||
)
|
||||
self.is_network_split = split
|
||||
self.rpc = self.nodes[0]
|
||||
self.rpc1 = self.nodes[1]
|
||||
self.sync_all()
|
||||
print("Done setting up network")
|
||||
|
||||
def send_and_mine(self, xtn, rpc_connection):
|
||||
txid = rpc_connection.sendrawtransaction(xtn)
|
||||
assert txid, 'got txid'
|
||||
# we need the tx above to be confirmed in the next block
|
||||
rpc_connection.generate(1)
|
||||
return txid
|
||||
|
||||
def run_faucet_tests(self):
|
||||
rpc = self.rpc
|
||||
rpc1 = self.rpc1
|
||||
|
||||
# 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)
|
||||
self.sync_all()
|
||||
|
||||
result = rpc.getwalletinfo()
|
||||
# minus one block reward
|
||||
balance2 = result['balance'] - 100000
|
||||
# make sure our balance is less now
|
||||
assert_greater_than(balance, balance2)
|
||||
|
||||
result = rpc.faucetinfo()
|
||||
assert_success(result)
|
||||
assert_greater_than( result['funding'], 0 )
|
||||
|
||||
# claiming faucet on second node
|
||||
faucetgethex = rpc1.faucetget()
|
||||
assert_success(faucetgethex)
|
||||
assert faucetgethex['hex'], "hex key found"
|
||||
|
||||
balance1 = rpc1.getwalletinfo()['balance']
|
||||
|
||||
# try to broadcast the faucetget transaction
|
||||
result = self.send_and_mine(faucetgethex['hex'], rpc1)
|
||||
assert txid, "transaction broadcasted"
|
||||
|
||||
balance2 = rpc1.getwalletinfo()['balance']
|
||||
assert_greater_than(balance2, balance1)
|
||||
|
||||
self.sync_all()
|
||||
|
||||
def run_test(self):
|
||||
print("Mining blocks...")
|
||||
rpc = self.nodes[0]
|
||||
rpc1 = self.nodes[1]
|
||||
# utxos from block 1 become mature in block 101
|
||||
rpc.generate(101)
|
||||
self.sync_all()
|
||||
rpc.getinfo()
|
||||
rpc1.getinfo()
|
||||
# this corresponds to -pubkey above
|
||||
print("Importing privkeys")
|
||||
rpc.importprivkey(self.privkey)
|
||||
rpc1.importprivkey(self.privkey1)
|
||||
self.run_faucet_tests()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
CryptoconditionsFaucetTest ().main()
|
||||
293
qa/rpc-tests/cryptoconditions_oracles.py
Executable file
293
qa/rpc-tests/cryptoconditions_oracles.py
Executable file
@@ -0,0 +1,293 @@
|
||||
#!/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
|
||||
from cryptoconditions import assert_success, assert_error, generate_random_string
|
||||
|
||||
|
||||
class CryptoconditionsOraclesTest(BitcoinTestFramework):
|
||||
|
||||
|
||||
def setup_chain(self):
|
||||
print("Initializing CC test directory "+self.options.tmpdir)
|
||||
self.num_nodes = 2
|
||||
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.addr1 = "RXEXoa1nRmKhMbuZovpcYwQMsicwzccZBp"
|
||||
self.pubkey1 = "024026d4ad4ecfc1f705a9b42ca64af6d2ad947509c085534a30b8861d756c6ff0"
|
||||
self.privkey1 = "UtdydP56pGTFmawHzHr1wDrc4oUwCNW1ttX8Pc3KrvH3MA8P49Wi"
|
||||
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir,
|
||||
extra_args=[[
|
||||
# always give -ac_name as first extra_arg and port as third
|
||||
'-ac_name=REGTEST',
|
||||
'-conf='+self.options.tmpdir+'/node0/REGTEST.conf',
|
||||
'-port=64367',
|
||||
'-rpcport=64368',
|
||||
'-regtest',
|
||||
'-addressindex=1',
|
||||
'-spentindex=1',
|
||||
'-ac_supply=5555555',
|
||||
'-ac_reward=10000000000000',
|
||||
'-pubkey=' + self.pubkey,
|
||||
'-ac_cc=2',
|
||||
'-whitelist=127.0.0.1',
|
||||
'-debug',
|
||||
'--daemon',
|
||||
'-rpcuser=rt',
|
||||
'-rpcpassword=rt'
|
||||
],
|
||||
['-ac_name=REGTEST',
|
||||
'-conf='+self.options.tmpdir+'/node1/REGTEST.conf',
|
||||
'-port=64365',
|
||||
'-rpcport=64366',
|
||||
'-regtest',
|
||||
'-addressindex=1',
|
||||
'-spentindex=1',
|
||||
'-ac_supply=5555555',
|
||||
'-ac_reward=10000000000000',
|
||||
'-pubkey=' + self.pubkey1,
|
||||
'-ac_cc=2',
|
||||
'-whitelist=127.0.0.1',
|
||||
'-debug',
|
||||
'-addnode=127.0.0.1:64367',
|
||||
'--daemon',
|
||||
'-rpcuser=rt',
|
||||
'-rpcpassword=rt']]
|
||||
)
|
||||
self.is_network_split = split
|
||||
self.rpc = self.nodes[0]
|
||||
self.rpc1 = self.nodes[1]
|
||||
self.sync_all()
|
||||
print("Done setting up network")
|
||||
|
||||
def send_and_mine(self, xtn, rpc_connection):
|
||||
txid = rpc_connection.sendrawtransaction(xtn)
|
||||
assert txid, 'got txid'
|
||||
# we need the tx above to be confirmed in the next block
|
||||
rpc_connection.generate(1)
|
||||
return txid
|
||||
|
||||
def run_oracles_tests(self):
|
||||
rpc = self.nodes[0]
|
||||
rpc1 = self.nodes[1]
|
||||
|
||||
result = rpc1.oraclesaddress()
|
||||
|
||||
result = rpc.oraclesaddress()
|
||||
assert_success(result)
|
||||
for x in ['OraclesCCaddress', 'Oraclesmarker', 'myCCaddress', 'myaddress']:
|
||||
assert_equal(result[x][0], 'R')
|
||||
|
||||
result = rpc.oraclesaddress(self.pubkey)
|
||||
assert_success(result)
|
||||
for x in ['OraclesCCaddress', 'Oraclesmarker', 'myCCaddress', 'myaddress']:
|
||||
assert_equal(result[x][0], 'R')
|
||||
|
||||
# there are no oracles created yet
|
||||
result = rpc.oracleslist()
|
||||
assert_equal(result, [])
|
||||
|
||||
# looking up non-existent oracle should return error.
|
||||
result = rpc.oraclesinfo("none")
|
||||
assert_error(result)
|
||||
|
||||
# attempt to create oracle with not valid data type should return error
|
||||
result = rpc.oraclescreate("Test", "Test", "Test")
|
||||
assert_error(result)
|
||||
|
||||
# attempt to create oracle with description > 32 symbols should return error
|
||||
too_long_name = generate_random_string(33)
|
||||
result = rpc.oraclescreate(too_long_name, "Test", "s")
|
||||
|
||||
# attempt to create oracle with description > 4096 symbols should return error
|
||||
too_long_description = generate_random_string(4100)
|
||||
result = rpc.oraclescreate("Test", too_long_description, "s")
|
||||
assert_error(result)
|
||||
# valid creating oracles of different types
|
||||
# using such naming to re-use it for data publishing / reading (e.g. oracle_s for s type)
|
||||
valid_formats = ["s", "S", "d", "D", "c", "C", "t", "T", "i", "I", "l", "L", "h", "Ihh"]
|
||||
for f in valid_formats:
|
||||
result = rpc.oraclescreate("Test", "Test", f)
|
||||
assert_success(result)
|
||||
globals()["oracle_{}".format(f)] = self.send_and_mine(result['hex'], rpc)
|
||||
|
||||
# trying to register with negative datafee
|
||||
for f in valid_formats:
|
||||
result = rpc.oraclesregister(globals()["oracle_{}".format(f)], "-100")
|
||||
assert_error(result)
|
||||
|
||||
# trying to register with zero datafee
|
||||
for f in valid_formats:
|
||||
result = rpc.oraclesregister(globals()["oracle_{}".format(f)], "0")
|
||||
assert_error(result)
|
||||
|
||||
# trying to register with datafee less than txfee
|
||||
for f in valid_formats:
|
||||
result = rpc.oraclesregister(globals()["oracle_{}".format(f)], "500")
|
||||
assert_error(result)
|
||||
|
||||
# trying to register valid
|
||||
for f in valid_formats:
|
||||
result = rpc.oraclesregister(globals()["oracle_{}".format(f)], "10000")
|
||||
assert_success(result)
|
||||
register_txid = self.send_and_mine(result["hex"], rpc)
|
||||
assert register_txid, "got txid"
|
||||
|
||||
# TODO: for most of the non valid oraclesregister and oraclessubscribe transactions generating and broadcasting now
|
||||
# so trying only valid oraclessubscribe atm
|
||||
for f in valid_formats:
|
||||
result = rpc.oraclessubscribe(globals()["oracle_{}".format(f)], self.pubkey, "1")
|
||||
assert_success(result)
|
||||
subscribe_txid = self.send_and_mine(result["hex"], rpc)
|
||||
assert register_txid, "got txid"
|
||||
|
||||
# now lets publish and read valid data for each oracle type
|
||||
|
||||
# s type
|
||||
result = rpc.oraclesdata(globals()["oracle_{}".format("s")], "05416e746f6e")
|
||||
assert_success(result)
|
||||
# baton
|
||||
oraclesdata_s = self.send_and_mine(result["hex"], rpc)
|
||||
result = rpc.oraclessamples(globals()["oracle_{}".format("s")], oraclesdata_s, "1")
|
||||
assert_equal("[u'Anton']", str(result["samples"][0]), "Data match")
|
||||
|
||||
# S type
|
||||
result = rpc.oraclesdata(globals()["oracle_{}".format("S")], "000161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161")
|
||||
assert_success(result)
|
||||
# baton
|
||||
oraclesdata_S = self.send_and_mine(result["hex"], rpc)
|
||||
result = rpc.oraclessamples(globals()["oracle_{}".format("S")], oraclesdata_S, "1")
|
||||
assert_equal("[u'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa']", str(result["samples"][0]), "Data match")
|
||||
|
||||
# d type
|
||||
result = rpc.oraclesdata(globals()["oracle_{}".format("d")], "0101")
|
||||
assert_success(result)
|
||||
# baton
|
||||
oraclesdata_d = self.send_and_mine(result["hex"], rpc)
|
||||
result = rpc.oraclessamples(globals()["oracle_{}".format("d")], oraclesdata_d, "1")
|
||||
# TODO: working not correct now!
|
||||
#assert_equal("[u'01']", str(result["samples"][0]), "Data match")
|
||||
|
||||
# D type
|
||||
result = rpc.oraclesdata(globals()["oracle_{}".format("D")], "0101")
|
||||
assert_success(result)
|
||||
# baton
|
||||
oraclesdata_D = self.send_and_mine(result["hex"], rpc)
|
||||
result = rpc.oraclessamples(globals()["oracle_{}".format("D")], oraclesdata_D, "1")
|
||||
# TODO: working not correct now!
|
||||
#assert_equal("[u'01']", str(result["samples"][0]), "Data match")
|
||||
|
||||
# c type
|
||||
result = rpc.oraclesdata(globals()["oracle_{}".format("c")], "ff")
|
||||
assert_success(result)
|
||||
# baton
|
||||
oraclesdata_c = self.send_and_mine(result["hex"], rpc)
|
||||
result = rpc.oraclessamples(globals()["oracle_{}".format("c")], oraclesdata_c, "1")
|
||||
assert_equal("[u'-1']", str(result["samples"][0]), "Data match")
|
||||
|
||||
# C type
|
||||
result = rpc.oraclesdata(globals()["oracle_{}".format("C")], "ff")
|
||||
assert_success(result)
|
||||
# baton
|
||||
oraclesdata_C = self.send_and_mine(result["hex"], rpc)
|
||||
result = rpc.oraclessamples(globals()["oracle_{}".format("C")], oraclesdata_C, "1")
|
||||
assert_equal("[u'255']", str(result["samples"][0]), "Data match")
|
||||
|
||||
# t type
|
||||
result = rpc.oraclesdata(globals()["oracle_{}".format("t")], "ffff")
|
||||
assert_success(result)
|
||||
# baton
|
||||
oraclesdata_t = self.send_and_mine(result["hex"], rpc)
|
||||
result = rpc.oraclessamples(globals()["oracle_{}".format("t")], oraclesdata_t, "1")
|
||||
assert_equal("[u'-1']", str(result["samples"][0]), "Data match")
|
||||
|
||||
# T type
|
||||
result = rpc.oraclesdata(globals()["oracle_{}".format("T")], "ffff")
|
||||
assert_success(result)
|
||||
# baton
|
||||
oraclesdata_T = self.send_and_mine(result["hex"], rpc)
|
||||
result = rpc.oraclessamples(globals()["oracle_{}".format("T")], oraclesdata_T, "1")
|
||||
assert_equal("[u'65535']", str(result["samples"][0]), "Data match")
|
||||
|
||||
# i type
|
||||
result = rpc.oraclesdata(globals()["oracle_{}".format("i")], "ffffffff")
|
||||
assert_success(result)
|
||||
# baton
|
||||
oraclesdata_i = self.send_and_mine(result["hex"], rpc)
|
||||
result = rpc.oraclessamples(globals()["oracle_{}".format("i")], oraclesdata_i, "1")
|
||||
assert_equal("[u'-1']", str(result["samples"][0]), "Data match")
|
||||
|
||||
# I type
|
||||
result = rpc.oraclesdata(globals()["oracle_{}".format("I")], "ffffffff")
|
||||
assert_success(result)
|
||||
# baton
|
||||
oraclesdata_I = self.send_and_mine(result["hex"], rpc)
|
||||
result = rpc.oraclessamples(globals()["oracle_{}".format("I")], oraclesdata_I, "1")
|
||||
assert_equal("[u'4294967295']", str(result["samples"][0]), "Data match")
|
||||
|
||||
# l type
|
||||
result = rpc.oraclesdata(globals()["oracle_{}".format("l")], "00000000ffffffff")
|
||||
assert_success(result)
|
||||
# baton
|
||||
oraclesdata_l = self.send_and_mine(result["hex"], rpc)
|
||||
result = rpc.oraclessamples(globals()["oracle_{}".format("l")], oraclesdata_l, "1")
|
||||
# TODO: working not correct now!
|
||||
#assert_equal("[u'-4294967296']", str(result["samples"][0]), "Data match")
|
||||
|
||||
# L type
|
||||
result = rpc.oraclesdata(globals()["oracle_{}".format("L")], "00000000ffffffff")
|
||||
assert_success(result)
|
||||
# baton
|
||||
oraclesdata_L = self.send_and_mine(result["hex"], rpc)
|
||||
result = rpc.oraclessamples(globals()["oracle_{}".format("L")], oraclesdata_L, "1")
|
||||
assert_equal("[u'18446744069414584320']", str(result["samples"][0]), "Data match")
|
||||
|
||||
# h type
|
||||
result = rpc.oraclesdata(globals()["oracle_{}".format("h")], "00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff")
|
||||
assert_success(result)
|
||||
# baton
|
||||
oraclesdata_h = self.send_and_mine(result["hex"], rpc)
|
||||
result = rpc.oraclessamples(globals()["oracle_{}".format("h")], oraclesdata_h, "1")
|
||||
assert_equal("[u'ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000']", str(result["samples"][0]), "Data match")
|
||||
|
||||
# Ihh type
|
||||
result = rpc.oraclesdata(globals()["oracle_{}".format("Ihh")], "00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff")
|
||||
assert_success(result)
|
||||
# baton
|
||||
oraclesdata_Ihh = self.send_and_mine(result["hex"], rpc)
|
||||
result = rpc.oraclessamples(globals()["oracle_{}".format("Ihh")], oraclesdata_Ihh, "1")
|
||||
assert_equal("[u'0']", str(result["samples"][0]), "Data match")
|
||||
assert_equal("[u'00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff']", str(result["samples"][1]), "Data match")
|
||||
assert_equal("[u'00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff']", str(result["samples"][2]), "Data match")
|
||||
|
||||
|
||||
def run_test(self):
|
||||
print("Mining blocks...")
|
||||
rpc = self.nodes[0]
|
||||
rpc1 = self.nodes[1]
|
||||
# utxos from block 1 become mature in block 101
|
||||
rpc.generate(101)
|
||||
self.sync_all()
|
||||
rpc.getinfo()
|
||||
rpc1.getinfo()
|
||||
# this corresponds to -pubkey above
|
||||
print("Importing privkeys")
|
||||
rpc.importprivkey(self.privkey)
|
||||
rpc1.importprivkey(self.privkey1)
|
||||
self.run_oracles_tests()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
CryptoconditionsOraclesTest().main()
|
||||
208
qa/rpc-tests/cryptoconditions_rewards.py
Executable file
208
qa/rpc-tests/cryptoconditions_rewards.py
Executable file
@@ -0,0 +1,208 @@
|
||||
#!/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
|
||||
from cryptoconditions import assert_success, assert_error, generate_random_string
|
||||
|
||||
|
||||
class CryptoconditionsRewardsTest(BitcoinTestFramework):
|
||||
|
||||
|
||||
def setup_chain(self):
|
||||
print("Initializing CC test directory "+self.options.tmpdir)
|
||||
self.num_nodes = 2
|
||||
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.addr1 = "RXEXoa1nRmKhMbuZovpcYwQMsicwzccZBp"
|
||||
self.pubkey1 = "024026d4ad4ecfc1f705a9b42ca64af6d2ad947509c085534a30b8861d756c6ff0"
|
||||
self.privkey1 = "UtdydP56pGTFmawHzHr1wDrc4oUwCNW1ttX8Pc3KrvH3MA8P49Wi"
|
||||
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir,
|
||||
extra_args=[[
|
||||
# always give -ac_name as first extra_arg and port as third
|
||||
'-ac_name=REGTEST',
|
||||
'-conf='+self.options.tmpdir+'/node0/REGTEST.conf',
|
||||
'-port=64367',
|
||||
'-rpcport=64368',
|
||||
'-regtest',
|
||||
'-addressindex=1',
|
||||
'-spentindex=1',
|
||||
'-ac_supply=5555555',
|
||||
'-ac_reward=10000000000000',
|
||||
'-pubkey=' + self.pubkey,
|
||||
'-ac_cc=2',
|
||||
'-whitelist=127.0.0.1',
|
||||
'-debug',
|
||||
'--daemon',
|
||||
'-rpcuser=rt',
|
||||
'-rpcpassword=rt'
|
||||
],
|
||||
['-ac_name=REGTEST',
|
||||
'-conf='+self.options.tmpdir+'/node1/REGTEST.conf',
|
||||
'-port=64365',
|
||||
'-rpcport=64366',
|
||||
'-regtest',
|
||||
'-addressindex=1',
|
||||
'-spentindex=1',
|
||||
'-ac_supply=5555555',
|
||||
'-ac_reward=10000000000000',
|
||||
'-pubkey=' + self.pubkey1,
|
||||
'-ac_cc=2',
|
||||
'-whitelist=127.0.0.1',
|
||||
'-debug',
|
||||
'-addnode=127.0.0.1:64367',
|
||||
'--daemon',
|
||||
'-rpcuser=rt',
|
||||
'-rpcpassword=rt']]
|
||||
)
|
||||
self.is_network_split = split
|
||||
self.rpc = self.nodes[0]
|
||||
self.rpc1 = self.nodes[1]
|
||||
self.sync_all()
|
||||
print("Done setting up network")
|
||||
|
||||
def send_and_mine(self, xtn, rpc_connection):
|
||||
txid = rpc_connection.sendrawtransaction(xtn)
|
||||
assert txid, 'got txid'
|
||||
# we need the tx above to be confirmed in the next block
|
||||
rpc_connection.generate(1)
|
||||
return txid
|
||||
|
||||
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'], rpc)
|
||||
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]
|
||||
rpc1 = self.nodes[1]
|
||||
# utxos from block 1 become mature in block 101
|
||||
rpc.generate(101)
|
||||
self.sync_all()
|
||||
rpc.getinfo()
|
||||
rpc1.getinfo()
|
||||
# this corresponds to -pubkey above
|
||||
print("Importing privkeys")
|
||||
rpc.importprivkey(self.privkey)
|
||||
rpc1.importprivkey(self.privkey1)
|
||||
self.run_rewards_tests()
|
||||
|
||||
if __name__ == '__main__':
|
||||
CryptoconditionsRewardsTest().main()
|
||||
288
qa/rpc-tests/cryptoconditions_token.py
Executable file
288
qa/rpc-tests/cryptoconditions_token.py
Executable file
@@ -0,0 +1,288 @@
|
||||
#!/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
|
||||
from cryptoconditions import assert_success, assert_error, generate_random_string
|
||||
|
||||
|
||||
class CryptoconditionsTokenTest(BitcoinTestFramework):
|
||||
|
||||
|
||||
def setup_chain(self):
|
||||
print("Initializing CC test directory "+self.options.tmpdir)
|
||||
self.num_nodes = 2
|
||||
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.addr1 = "RXEXoa1nRmKhMbuZovpcYwQMsicwzccZBp"
|
||||
self.pubkey1 = "024026d4ad4ecfc1f705a9b42ca64af6d2ad947509c085534a30b8861d756c6ff0"
|
||||
self.privkey1 = "UtdydP56pGTFmawHzHr1wDrc4oUwCNW1ttX8Pc3KrvH3MA8P49Wi"
|
||||
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir,
|
||||
extra_args=[[
|
||||
# always give -ac_name as first extra_arg and port as third
|
||||
'-ac_name=REGTEST',
|
||||
'-conf='+self.options.tmpdir+'/node0/REGTEST.conf',
|
||||
'-port=64367',
|
||||
'-rpcport=64368',
|
||||
'-regtest',
|
||||
'-addressindex=1',
|
||||
'-spentindex=1',
|
||||
'-ac_supply=5555555',
|
||||
'-ac_reward=10000000000000',
|
||||
'-pubkey=' + self.pubkey,
|
||||
'-ac_cc=2',
|
||||
'-whitelist=127.0.0.1',
|
||||
'-debug',
|
||||
'--daemon',
|
||||
'-rpcuser=rt',
|
||||
'-rpcpassword=rt'
|
||||
],
|
||||
['-ac_name=REGTEST',
|
||||
'-conf='+self.options.tmpdir+'/node1/REGTEST.conf',
|
||||
'-port=64365',
|
||||
'-rpcport=64366',
|
||||
'-regtest',
|
||||
'-addressindex=1',
|
||||
'-spentindex=1',
|
||||
'-ac_supply=5555555',
|
||||
'-ac_reward=10000000000000',
|
||||
'-pubkey=' + self.pubkey1,
|
||||
'-ac_cc=2',
|
||||
'-whitelist=127.0.0.1',
|
||||
'-debug',
|
||||
'-addnode=127.0.0.1:64367',
|
||||
'--daemon',
|
||||
'-rpcuser=rt',
|
||||
'-rpcpassword=rt']]
|
||||
)
|
||||
self.is_network_split = split
|
||||
self.rpc = self.nodes[0]
|
||||
self.rpc1 = self.nodes[1]
|
||||
self.sync_all()
|
||||
print("Done setting up network")
|
||||
|
||||
def send_and_mine(self, xtn, rpc_connection):
|
||||
txid = rpc_connection.sendrawtransaction(xtn)
|
||||
assert txid, 'got txid'
|
||||
# we need the tx above to be confirmed in the next block
|
||||
rpc_connection.generate(1)
|
||||
return txid
|
||||
|
||||
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'], rpc)
|
||||
|
||||
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'], rpc)
|
||||
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'], rpc)
|
||||
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'], rpc)
|
||||
cancel = rpc.tokencancelask(tokenid, testorderid)
|
||||
self.send_and_mine(cancel["hex"], rpc)
|
||||
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)
|
||||
|
||||
tokenbid = rpc.tokenbid("100", tokenid, "10")
|
||||
tokenbidhex = tokenbid['hex']
|
||||
tokenbidid = self.send_and_mine(tokenbid['hex'], rpc)
|
||||
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'], rpc)
|
||||
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'], rpc)
|
||||
cancel = rpc.tokencancelbid(tokenid, testorderid)
|
||||
self.send_and_mine(cancel["hex"], rpc)
|
||||
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"], rpc)
|
||||
result = rpc.tokenbalance(tokenid,randompubkey)
|
||||
assert_equal(result["balance"], 1)
|
||||
|
||||
def run_test(self):
|
||||
print("Mining blocks...")
|
||||
rpc = self.nodes[0]
|
||||
rpc1 = self.nodes[1]
|
||||
# utxos from block 1 become mature in block 101
|
||||
rpc.generate(101)
|
||||
self.sync_all()
|
||||
rpc.getinfo()
|
||||
rpc1.getinfo()
|
||||
# this corresponds to -pubkey above
|
||||
print("Importing privkeys")
|
||||
rpc.importprivkey(self.privkey)
|
||||
rpc1.importprivkey(self.privkey1)
|
||||
self.run_token_tests()
|
||||
|
||||
if __name__ == '__main__':
|
||||
CryptoconditionsTokenTest().main()
|
||||
@@ -28,7 +28,7 @@ class ListReceivedTest (BitcoinTestFramework):
|
||||
self.sync_all()
|
||||
assert_equal(new_height, self.nodes[0].getblockcount())
|
||||
|
||||
def run_test_release(self, release, expected_memo, height):
|
||||
def run_test_release(self, release, height):
|
||||
self.generate_and_sync(height+1)
|
||||
taddr = self.nodes[1].getnewaddress()
|
||||
zaddr1 = self.nodes[1].z_getnewaddress(release)
|
||||
@@ -61,7 +61,7 @@ class ListReceivedTest (BitcoinTestFramework):
|
||||
# Generate some change by sending part of zaddr1 to zaddr2
|
||||
zaddr2 = self.nodes[1].z_getnewaddress(release)
|
||||
opid = self.nodes[1].z_sendmany(zaddr1,
|
||||
[{'address': zaddr2, 'amount': 0.6, 'memo': my_memo}])
|
||||
[{'address': zaddr2, 'amount': 0.6}])
|
||||
txid = wait_and_assert_operationid_status(self.nodes[1], opid)
|
||||
self.sync_all()
|
||||
self.generate_and_sync(height+4)
|
||||
@@ -74,12 +74,12 @@ class ListReceivedTest (BitcoinTestFramework):
|
||||
assert_equal(txid, r[0]['txid'])
|
||||
assert_equal(Decimal('0.4')-fee, r[0]['amount'])
|
||||
assert_true(r[0]['change'], "Note valued at (0.4-fee) should be change")
|
||||
assert_equal(expected_memo, r[0]['memo'])
|
||||
assert_equal(no_memo, r[0]['memo'])
|
||||
|
||||
# The old note still exists (it's immutable), even though it is spent
|
||||
assert_equal(Decimal('1.0'), r[1]['amount'])
|
||||
assert_false(r[1]['change'], "Note valued at 1.0 should not be change")
|
||||
assert_equal(expected_memo, r[0]['memo'])
|
||||
assert_equal(my_memo, r[1]['memo'])
|
||||
|
||||
# zaddr2 should not have change
|
||||
r = self.nodes[1].z_listreceivedbyaddress(zaddr2, 0)
|
||||
@@ -88,11 +88,11 @@ class ListReceivedTest (BitcoinTestFramework):
|
||||
assert_equal(txid, r[0]['txid'])
|
||||
assert_equal(Decimal('0.6'), r[0]['amount'])
|
||||
assert_false(r[0]['change'], "Note valued at 0.6 should not be change")
|
||||
assert_equal(my_memo, r[0]['memo'])
|
||||
assert_equal(no_memo, r[0]['memo'])
|
||||
|
||||
def run_test(self):
|
||||
self.run_test_release('sprout', no_memo, 200)
|
||||
self.run_test_release('sapling', no_memo, 204)
|
||||
self.run_test_release('sprout', 200)
|
||||
self.run_test_release('sapling', 204)
|
||||
|
||||
if __name__ == '__main__':
|
||||
ListReceivedTest().main()
|
||||
|
||||
@@ -68,12 +68,22 @@ class WalletPersistenceTest (BitcoinTestFramework):
|
||||
|
||||
# Verify shielded balance
|
||||
assert_equal(self.nodes[0].z_getbalance(sapling_addr), Decimal('20'))
|
||||
|
||||
|
||||
# Verify size of shielded pools
|
||||
pools = self.nodes[0].getblockchaininfo()['valuePools']
|
||||
assert_equal(pools[0]['chainValue'], Decimal('0')) # Sprout
|
||||
assert_equal(pools[1]['chainValue'], Decimal('20')) # Sapling
|
||||
|
||||
# Restart the nodes
|
||||
stop_nodes(self.nodes)
|
||||
wait_bitcoinds()
|
||||
self.setup_network()
|
||||
|
||||
# Verify size of shielded pools
|
||||
pools = self.nodes[0].getblockchaininfo()['valuePools']
|
||||
assert_equal(pools[0]['chainValue'], Decimal('0')) # Sprout
|
||||
assert_equal(pools[1]['chainValue'], Decimal('20')) # Sapling
|
||||
|
||||
# Node 0 sends some shielded funds to Node 1
|
||||
dest_addr = self.nodes[1].z_getnewaddress('sapling')
|
||||
recipients = []
|
||||
@@ -128,4 +138,4 @@ class WalletPersistenceTest (BitcoinTestFramework):
|
||||
assert_equal(self.nodes[1].z_getbalance(dest_addr), Decimal('16'))
|
||||
|
||||
if __name__ == '__main__':
|
||||
WalletPersistenceTest().main()
|
||||
WalletPersistenceTest().main()
|
||||
|
||||
@@ -261,7 +261,6 @@ BITCOIN_CORE_H = \
|
||||
wallet/wallet.h \
|
||||
wallet/wallet_ismine.h \
|
||||
wallet/walletdb.h \
|
||||
veruslaunch.h \
|
||||
zmq/zmqabstractnotifier.h \
|
||||
zmq/zmqconfig.h\
|
||||
zmq/zmqnotificationinterface.h \
|
||||
@@ -483,7 +482,6 @@ libbitcoin_common_a_SOURCES = \
|
||||
script/script_error.cpp \
|
||||
script/sign.cpp \
|
||||
script/standard.cpp \
|
||||
veruslaunch.cpp \
|
||||
transaction_builder.cpp \
|
||||
$(BITCOIN_CORE_H) \
|
||||
$(LIBZCASH_H)
|
||||
|
||||
2
src/ac/zex
Executable file
2
src/ac/zex
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
./komodo-cli -ac_name=ZEX $1 $2 $3 $4 $5 $6
|
||||
@@ -118,7 +118,8 @@
|
||||
},
|
||||
{
|
||||
"ac_name": "EQL",
|
||||
"ac_supply": "500000000"
|
||||
"ac_supply": "500000000",
|
||||
"ac_ccactivate": "205000"
|
||||
},
|
||||
{
|
||||
"ac_name": "ZILLA",
|
||||
@@ -186,5 +187,28 @@
|
||||
"addnode": [
|
||||
"51.75.124.34"
|
||||
]
|
||||
},
|
||||
{
|
||||
"ac_name": "KMDICE",
|
||||
"ac_supply": "10500000",
|
||||
"ac_reward": "2500000000",
|
||||
"ac_halving": "210000",
|
||||
"ac_cc": "2",
|
||||
"addressindex": "1",
|
||||
"spentindex": "1",
|
||||
"addnode": [
|
||||
"144.76.217.232"
|
||||
]
|
||||
},
|
||||
{
|
||||
"ac_name": "ZEX",
|
||||
"ac_founders": "1",
|
||||
"ac_reward": "13000000000",
|
||||
"ac_halving": "525600",
|
||||
"ac_cc": "2",
|
||||
"ac_pubkey": "039d4a50cc70d1184e462a22edb3b66385da97cc8059196f8305c184a3e21440af",
|
||||
"addnode": [
|
||||
"5.9.102.210"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
@@ -33,7 +33,7 @@ echo $pubkey
|
||||
./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=10000000000 -addnode=13.230.224.15 &
|
||||
./komodod -pubkey=$pubkey -ac_name=EQL -ac_supply=500000000 -addnode=46.101.124.153 &
|
||||
./komodod -pubkey=$pubkey -ac_name=EQL -ac_supply=500000000 -ac_ccactivate=205000 -addnode=46.101.124.153 &
|
||||
./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 &
|
||||
@@ -44,3 +44,4 @@ echo $pubkey
|
||||
./komodod -pubkey=$pubkey -ac_name=PGT -ac_supply=10000000 -ac_end=1 -addnode=190.114.254.104 &
|
||||
./komodod -pubkey=$pubkey -ac_name=KMDICE -ac_supply=10500000 -ac_reward=2500000000 -ac_halving=210000 -ac_cc=2 -addressindex=1 -spentindex=1 -addnode=144.76.217.232 &
|
||||
./komodod -pubkey=$pubkey -ac_name=DION -ac_supply=3900000000 -ac_reward=22260000000 -ac_staked=100 -ac_cc=1 -ac_end=4300000000 -addnode=51.75.124.34 &
|
||||
./komodod -pubkey=$pubkey -ac_name=ZEX -ac_cc=2 -ac_founders=1 -ac_halving=525600 -ac_reward=13000000000 -ac_pubkey=039d4a50cc70d1184e462a22edb3b66385da97cc8059196f8305c184a3e21440af -addnode=5.9.102.210 &
|
||||
|
||||
@@ -178,6 +178,7 @@ std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTr
|
||||
void SetCCunspents(std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &unspentOutputs,char *coinaddr);
|
||||
void SetCCtxids(std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex,char *coinaddr);
|
||||
int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs);
|
||||
int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinputs);
|
||||
int64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout);
|
||||
|
||||
// curve25519 and sha256
|
||||
|
||||
@@ -431,3 +431,92 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3
|
||||
#endif
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinputs)
|
||||
{
|
||||
int32_t abovei,belowi,ind,vout,i,n = 0,maxutxos=64; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; struct CC_utxo *utxos,*up;
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||
utxos = (struct CC_utxo *)calloc(maxutxos,sizeof(*utxos));
|
||||
threshold = total/(maxinputs+1);
|
||||
if ( maxinputs > maxutxos )
|
||||
maxutxos = maxinputs;
|
||||
sum = 0;
|
||||
Getscriptaddress(coinaddr,CScript() << Mypubkey() << OP_CHECKSIG);
|
||||
SetCCunspents(unspentOutputs,coinaddr);
|
||||
for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++)
|
||||
{
|
||||
txid = it->first.txhash;
|
||||
vout = (int32_t)it->first.index;
|
||||
if ( it->second.satoshis < threshold )
|
||||
continue;
|
||||
if ( myGetTransaction(txid,tx,hashBlock) != 0 && tx.vout.size() > 0 && vout < tx.vout.size() && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() == 0 )
|
||||
{
|
||||
//fprintf(stderr,"check %.8f to vins array.%d of %d %s/v%d\n",(double)out.tx->vout[out.i].nValue/COIN,n,maxutxos,txid.GetHex().c_str(),(int32_t)vout);
|
||||
if ( mtx.vin.size() > 0 )
|
||||
{
|
||||
for (i=0; i<mtx.vin.size(); i++)
|
||||
if ( txid == mtx.vin[i].prevout.hash && vout == mtx.vin[i].prevout.n )
|
||||
break;
|
||||
if ( i != mtx.vin.size() )
|
||||
continue;
|
||||
}
|
||||
if ( n > 0 )
|
||||
{
|
||||
for (i=0; i<n; i++)
|
||||
if ( txid == utxos[i].txid && vout == utxos[i].vout )
|
||||
break;
|
||||
if ( i != n )
|
||||
continue;
|
||||
}
|
||||
if ( myIsutxo_spentinmempool(txid,vout) == 0 )
|
||||
{
|
||||
up = &utxos[n++];
|
||||
up->txid = txid;
|
||||
up->nValue = it->second.satoshis;
|
||||
up->vout = vout;
|
||||
sum += up->nValue;
|
||||
//fprintf(stderr,"add %.8f to vins array.%d of %d\n",(double)up->nValue/COIN,n,maxutxos);
|
||||
if ( n >= maxutxos || sum >= total )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
remains = total;
|
||||
for (i=0; i<maxinputs && n>0; i++)
|
||||
{
|
||||
below = above = 0;
|
||||
abovei = belowi = -1;
|
||||
if ( CC_vinselect(&abovei,&above,&belowi,&below,utxos,n,remains) < 0 )
|
||||
{
|
||||
printf("error finding unspent i.%d of %d, %.8f vs %.8f\n",i,n,(double)remains/COIN,(double)total/COIN);
|
||||
free(utxos);
|
||||
return(0);
|
||||
}
|
||||
if ( belowi < 0 || abovei >= 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];
|
||||
mtx.vin.push_back(CTxIn(up->txid,up->vout,CScript()));
|
||||
totalinputs += up->nValue;
|
||||
remains -= up->nValue;
|
||||
utxos[ind] = utxos[--n];
|
||||
memset(&utxos[n],0,sizeof(utxos[n]));
|
||||
//fprintf(stderr,"totalinputs %.8f vs total %.8f i.%d vs max.%d\n",(double)totalinputs/COIN,(double)total/COIN,i,maxinputs);
|
||||
if ( totalinputs >= total || (i+1) >= maxinputs )
|
||||
break;
|
||||
}
|
||||
free(utxos);
|
||||
if ( totalinputs >= total )
|
||||
{
|
||||
//fprintf(stderr,"return totalinputs %.8f\n",(double)totalinputs/COIN);
|
||||
return(totalinputs);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
@@ -1392,7 +1392,7 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6
|
||||
}
|
||||
if ( scriptPubKey == fundingPubKey )
|
||||
{
|
||||
if ( AddNormalinputs(mtx,mypk,amount+2*txfee,60) > 0 )
|
||||
if ( AddNormalinputs2(mtx,amount+2*txfee,60) > 0 )
|
||||
{
|
||||
hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash,mtx.vin[0].prevout.n,1);
|
||||
mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,dicepk));
|
||||
@@ -1505,7 +1505,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t &entropyv
|
||||
{
|
||||
if ( vin0txid == zeroid || vin0vout < 0 )
|
||||
{
|
||||
if ( AddNormalinputs(mtx,mypk,2*txfee,3) == 0 ) // must be a single vin!!
|
||||
if ( AddNormalinputs2(mtx,2*txfee,3) == 0 ) // must be a single vin!!
|
||||
{
|
||||
CCerror = "no txfee inputs for win/lose";
|
||||
fprintf(stderr,"%s\n", CCerror.c_str() );
|
||||
@@ -1652,22 +1652,32 @@ static uint256 dealer0_fundingtxid;
|
||||
void *dealer0_loop(void *_arg)
|
||||
{
|
||||
char *planstr = (char *)_arg;
|
||||
CTransaction tx; CPubKey mypk,dicepk; uint64_t entropyval; uint256 entropytxid; int32_t entropytxs,i,n,num; CScript fundingPubKey; struct CCcontract_info *cp,C; char coinaddr[64]; std::string res; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t refsbits,txfee = 10000;
|
||||
CTransaction tx,*entropytxs,entropytx; CPubKey mypk,dicepk; uint64_t entropyval; uint256 hashBlock,entropytxid,txid; int32_t height,lastht,numentropytxs,i,n,m,num; CScript fundingPubKey; struct CCcontract_info *cp,C; char coinaddr[64]; std::string res; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t refsbits,txfee = 10000;
|
||||
if ( (cp= Diceinit(fundingPubKey,dealer0_fundingtxid,&C,planstr,txfee,mypk,dicepk,refsbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 )
|
||||
{
|
||||
fprintf(stderr,"error initializing dealer0_loop\n");
|
||||
exit(-1);
|
||||
}
|
||||
fprintf(stderr,"dealer0 node running\n");
|
||||
height = lastht = 0;
|
||||
entropytxs = (CTransaction *)calloc(sizeof(*entropytxs),DICE_MINUTXOS);
|
||||
while ( 1 )
|
||||
{
|
||||
DicePlanFunds(entropyval,entropytxid,refsbits,cp,dicepk,dealer0_fundingtxid,entropytxs,false);
|
||||
if ( entropytxs < DICE_MINUTXOS )
|
||||
while ( KOMODO_INSYNC == 0 || (height= KOMODO_INSYNC) == lastht )
|
||||
{
|
||||
n = sqrt(DICE_MINUTXOS - entropytxs) + 10;
|
||||
for (i=0; i<DICE_MINUTXOS - entropytxs && i<n; i++)
|
||||
sleep(3);
|
||||
}
|
||||
lastht = height;
|
||||
fprintf(stderr,"New height.%d\n",height);
|
||||
DicePlanFunds(entropyval,entropytxid,refsbits,cp,dicepk,dealer0_fundingtxid,numentropytxs,false);
|
||||
if ( numentropytxs < DICE_MINUTXOS )
|
||||
{
|
||||
n = sqrt(DICE_MINUTXOS - numentropytxs);
|
||||
//if ( n > 10 )
|
||||
// n = 10;
|
||||
for (i=m=0; i<DICE_MINUTXOS - numentropytxs && i<n; i++)
|
||||
{
|
||||
res = DiceAddfunding(txfee,planstr,dealer0_fundingtxid,1000*COIN);///100);
|
||||
res = DiceAddfunding(txfee,planstr,dealer0_fundingtxid,COIN);
|
||||
if ( res.empty() == 0 && res.size() > 64 && is_hexstr((char *)res.c_str(),0) > 64 )
|
||||
{
|
||||
if ( DecodeHexTx(tx,res) != 0 )
|
||||
@@ -1675,12 +1685,37 @@ void *dealer0_loop(void *_arg)
|
||||
LOCK(cs_main);
|
||||
if ( myAddtomempool(tx) != 0 )
|
||||
{
|
||||
fprintf(stderr,"ENTROPY %s: %d of %d, %d\n",tx.GetHash().GetHex().c_str(),i,n,DICE_MINUTXOS - entropytxs);
|
||||
fprintf(stderr,"ENTROPY %s: %d of %d, %d\n",tx.GetHash().GetHex().c_str(),i,n,DICE_MINUTXOS - numentropytxs);
|
||||
RelayTransaction(tx);
|
||||
entropytxs[m++] = tx;
|
||||
} else break;
|
||||
} else break;
|
||||
} else break;
|
||||
}
|
||||
for (i=0; i<m; i++)
|
||||
{
|
||||
tx = entropytxs[i];
|
||||
txid = tx.GetHash();
|
||||
fprintf(stderr,"check %d of %d: %s\n",i,m,txid.GetHex().c_str());
|
||||
while ( 1 )
|
||||
{
|
||||
if ( myGetTransaction(txid,entropytx,hashBlock) == 0 || hashBlock == zeroid )
|
||||
{
|
||||
LOCK(cs_main);
|
||||
if ( myAddtomempool(tx) != 0 )
|
||||
{
|
||||
fprintf(stderr,"resend ENTROPY %s: %d of %d\n",txid.GetHex().c_str(),i,m);
|
||||
RelayTransaction(tx);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr,"found %s in %s\n",txid.GetHex().c_str(),hashBlock.GetHex().c_str());
|
||||
break;
|
||||
}
|
||||
sleep(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
pubkey2addr(coinaddr,Mypubkey().data());
|
||||
dicefinish_utxosget(num,0,0,coinaddr);
|
||||
|
||||
@@ -74,11 +74,11 @@ bool Eval::Dispatch(const CC *cond, const CTransaction &txTo, unsigned int nIn)
|
||||
switch ( ecode )
|
||||
{
|
||||
case EVAL_IMPORTPAYOUT:
|
||||
//return ImportPayout(vparams, txTo, nIn);
|
||||
return ImportPayout(vparams, txTo, nIn);
|
||||
break;
|
||||
|
||||
case EVAL_IMPORTCOIN:
|
||||
//return ImportCoin(vparams, txTo, nIn);
|
||||
return ImportCoin(vparams, txTo, nIn);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -557,7 +557,7 @@ extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
|
||||
const CScript &CCoinsViewCache::GetSpendFor(const CCoins *coins, const CTxIn& input)
|
||||
{
|
||||
assert(coins);
|
||||
if (coins->nHeight < 6400 && !strcmp(ASSETCHAINS_SYMBOL, "VRSC"))
|
||||
/*if (coins->nHeight < 6400 && !strcmp(ASSETCHAINS_SYMBOL, "VRSC"))
|
||||
{
|
||||
std::string hc = input.prevout.hash.ToString();
|
||||
if (LaunchMap().lmap.count(hc))
|
||||
@@ -568,7 +568,7 @@ const CScript &CCoinsViewCache::GetSpendFor(const CCoins *coins, const CTxIn& in
|
||||
return txData.scriptPubKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
return coins->vout[input.prevout.n].scriptPubKey;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/unordered_map.hpp>
|
||||
#include "zcash/IncrementalMerkleTree.hpp"
|
||||
#include "veruslaunch.h"
|
||||
//#include "veruslaunch.h"
|
||||
|
||||
/**
|
||||
* Pruned version of CTransaction: only retains metadata and unspent transaction outputs
|
||||
@@ -456,7 +456,7 @@ class CTransactionExceptionData
|
||||
CTransactionExceptionData() : scriptPubKey(), voutMask() {}
|
||||
};
|
||||
|
||||
class CLaunchMap
|
||||
/*class CLaunchMap
|
||||
{
|
||||
public:
|
||||
std::unordered_map<std::string, CTransactionExceptionData> lmap;
|
||||
@@ -477,7 +477,7 @@ class CLaunchMap
|
||||
}
|
||||
}
|
||||
};
|
||||
static CLaunchMap launchMap = CLaunchMap();
|
||||
static CLaunchMap launchMap = CLaunchMap();*/
|
||||
|
||||
/** CCoinsView that adds a memory cache for transactions to another CCoinsView */
|
||||
class CCoinsViewCache : public CCoinsViewBacked
|
||||
@@ -507,7 +507,7 @@ public:
|
||||
~CCoinsViewCache();
|
||||
|
||||
// Standard CCoinsView methods
|
||||
static CLaunchMap &LaunchMap() { return launchMap; }
|
||||
//static CLaunchMap &LaunchMap() { return launchMap; }
|
||||
bool GetSproutAnchorAt(const uint256 &rt, SproutMerkleTree &tree) const;
|
||||
bool GetSaplingAnchorAt(const uint256 &rt, SaplingMerkleTree &tree) const;
|
||||
bool GetNullifier(const uint256 &nullifier, ShieldedType type) const;
|
||||
|
||||
2
src/fiat/zex
Executable file
2
src/fiat/zex
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
./komodo-cli -ac_name=ZEX $1 $2 $3 $4 $5 $6
|
||||
@@ -291,7 +291,7 @@ TEST_F(ContextualCheckBlockTest, BlockOverwinterRulesRejectOtherTx) {
|
||||
|
||||
{
|
||||
SCOPED_TRACE("BlockOverwinterRulesRejectSaplingTx");
|
||||
ExpectInvalidBlockFromTx(CTransaction(mtx), 100, "bad-overwinter-tx-version-group-id");
|
||||
ExpectInvalidBlockFromTx(CTransaction(mtx), 0, "bad-overwinter-tx-version-group-id");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,6 +319,6 @@ TEST_F(ContextualCheckBlockTest, BlockSaplingRulesRejectOtherTx) {
|
||||
|
||||
{
|
||||
SCOPED_TRACE("BlockSaplingRulesRejectOverwinterTx");
|
||||
ExpectInvalidBlockFromTx(CTransaction(mtx), 100, "bad-sapling-tx-version-group-id");
|
||||
ExpectInvalidBlockFromTx(CTransaction(mtx), 0, "bad-sapling-tx-version-group-id");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -844,7 +844,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
const CChainParams& chainparams = Params();
|
||||
|
||||
// Set this early so that experimental features are correctly enabled/disabled
|
||||
fExperimentalMode = GetBoolArg("-experimentalfeatures", false);
|
||||
fExperimentalMode = GetBoolArg("-experimentalfeatures", true);
|
||||
|
||||
// Fail early if user has set experimental options without the global flag
|
||||
if (!fExperimentalMode) {
|
||||
|
||||
@@ -1771,12 +1771,12 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height)
|
||||
{
|
||||
if ( (is_PoSblock= komodo_is_PoSblock(slowflag,height,pblock,bnTarget,bhash)) == 0 )
|
||||
{
|
||||
if ( slowflag == 0 ) // need all past 100 blocks to calculate PoW target
|
||||
return(0);
|
||||
if ( ASSETCHAINS_STAKED == 100 && height > 100 ) // only PoS allowed! POSTEST64
|
||||
return(-1);
|
||||
else
|
||||
{
|
||||
if ( slowflag == 0 ) // need all past 100 blocks to calculate PoW target
|
||||
return(0);
|
||||
if ( slowflag != 0 )
|
||||
bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED);
|
||||
if ( bhash > bnTarget )
|
||||
@@ -1796,6 +1796,8 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height)
|
||||
fprintf(stderr,"unexpected negative is_PoSblock.%d\n",is_PoSblock);
|
||||
return(-1);
|
||||
}
|
||||
else if ( ASSETCHAINS_STAKED != 0 )
|
||||
failed = 0;
|
||||
}
|
||||
if ( failed == 0 && ASSETCHAINS_COMMISSION != 0 ) //ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 )
|
||||
{
|
||||
@@ -1824,12 +1826,28 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height)
|
||||
return(-1);
|
||||
}
|
||||
}
|
||||
//fprintf(stderr,"komodo_checkPOW possible.%d slowflag.%d ht.%d notaryid.%d failed.%d\n",possible,slowflag,height,notaryid,failed);
|
||||
//fprintf(stderr,"komodo_checkPOW possible.%d slowflag.%d ht.%d notaryid.%d failed.%d\n",possible,slowflag,height,notaryid,failed);
|
||||
if ( failed != 0 && possible == 0 && notaryid < 0 )
|
||||
return(-1);
|
||||
else return(0);
|
||||
}
|
||||
|
||||
int32_t komodo_acpublic(uint32_t tiptime)
|
||||
{
|
||||
int32_t acpublic = ASSETCHAINS_PUBLIC; CBlockIndex *pindex;
|
||||
if ( acpublic == 0 )
|
||||
{
|
||||
if ( tiptime == 0 )
|
||||
{
|
||||
if ( (pindex= chainActive.LastTip()) != 0 )
|
||||
tiptime = pindex->nTime;
|
||||
}
|
||||
if ( (ASSETCHAINS_SYMBOL[0] == 0 || strcmp(ASSETCHAINS_SYMBOL,"ZEX") == 0) && tiptime >= KOMODO_SAPLING_DEADLINE )
|
||||
acpublic = 1;
|
||||
}
|
||||
return(acpublic);
|
||||
}
|
||||
|
||||
int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock)
|
||||
{
|
||||
CTxDestination address; int32_t i,j,m,n,vout; uint8_t *script; uint256 txid,hashBlock; int64_t zfunds=0,vinsum=0,voutsum=0;
|
||||
|
||||
31
src/main.cpp
31
src/main.cpp
@@ -77,7 +77,7 @@ static int64_t nTimeBestReceived = 0;
|
||||
CWaitableCriticalSection csBestBlock;
|
||||
CConditionVariable cvBlockChange;
|
||||
int nScriptCheckThreads = 0;
|
||||
bool fExperimentalMode = false;
|
||||
bool fExperimentalMode = true;
|
||||
bool fImporting = false;
|
||||
bool fReindex = false;
|
||||
bool fTxIndex = false;
|
||||
@@ -1034,9 +1034,12 @@ bool ContextualCheckTransaction(
|
||||
}
|
||||
|
||||
// Reject transactions with non-Sapling version group ID
|
||||
if (tx.fOverwintered && tx.nVersionGroupId != SAPLING_VERSION_GROUP_ID) {
|
||||
return state.DoS(dosLevel, error("CheckTransaction(): invalid Sapling tx version"),
|
||||
REJECT_INVALID, "bad-sapling-tx-version-group-id");
|
||||
if (tx.fOverwintered && tx.nVersionGroupId != SAPLING_VERSION_GROUP_ID)
|
||||
{
|
||||
//return state.DoS(dosLevel, error("CheckTransaction(): invalid Sapling tx version"),REJECT_INVALID, "bad-sapling-tx-version-group-id");
|
||||
return state.DoS(isInitBlockDownload() ? 0 : dosLevel,
|
||||
error("CheckTransaction(): invalid Sapling tx version"),
|
||||
REJECT_INVALID, "bad-sapling-tx-version-group-id");
|
||||
}
|
||||
|
||||
// Reject transactions with invalid version
|
||||
@@ -1058,9 +1061,12 @@ bool ContextualCheckTransaction(
|
||||
}
|
||||
|
||||
// Reject transactions with non-Overwinter version group ID
|
||||
if (tx.fOverwintered && tx.nVersionGroupId != OVERWINTER_VERSION_GROUP_ID) {
|
||||
return state.DoS(dosLevel, error("CheckTransaction(): invalid Overwinter tx version"),
|
||||
REJECT_INVALID, "bad-overwinter-tx-version-group-id");
|
||||
if (tx.fOverwintered && tx.nVersionGroupId != OVERWINTER_VERSION_GROUP_ID)
|
||||
{
|
||||
//return state.DoS(dosLevel, error("CheckTransaction(): invalid Overwinter tx version"),REJECT_INVALID, "bad-overwinter-tx-version-group-id");
|
||||
return state.DoS(isInitBlockDownload() ? 0 : dosLevel,
|
||||
error("CheckTransaction(): invalid Overwinter tx version"),
|
||||
REJECT_INVALID, "bad-overwinter-tx-version-group-id");
|
||||
}
|
||||
|
||||
// Reject transactions with invalid version
|
||||
@@ -1253,10 +1259,12 @@ int32_t komodo_isnotaryvout(char *coinaddr) // from ac_private chains only
|
||||
return(0);
|
||||
}
|
||||
|
||||
int32_t komodo_acpublic(uint32_t tiptime);
|
||||
|
||||
bool CheckTransactionWithoutProofVerification(uint32_t tiptime,const CTransaction& tx, CValidationState &state)
|
||||
{
|
||||
// Basic checks that don't depend on any context
|
||||
int32_t invalid_private_taddr=0,z_z=0,z_t=0,t_z=0,acpublic = ASSETCHAINS_PUBLIC;
|
||||
int32_t invalid_private_taddr=0,z_z=0,z_t=0,t_z=0,acpublic = komodo_acpublic(tiptime);
|
||||
/**
|
||||
* Previously:
|
||||
* 1. The consensus rule below was:
|
||||
@@ -1359,8 +1367,6 @@ bool CheckTransactionWithoutProofVerification(uint32_t tiptime,const CTransactio
|
||||
return state.DoS(100, error("CheckTransaction(): tx.valueBalance has no sources or sinks"),
|
||||
REJECT_INVALID, "bad-txns-valuebalance-nonzero");
|
||||
}
|
||||
if ( (ASSETCHAINS_SYMBOL[0] == 0 || strcmp(ASSETCHAINS_SYMBOL,"ZEX") == 0) && tiptime >= KOMODO_SAPLING_DEADLINE )
|
||||
acpublic = 1;
|
||||
if ( acpublic != 0 && (tx.vShieldedSpend.empty() == 0 || tx.vShieldedOutput.empty() == 0) )
|
||||
{
|
||||
return state.DoS(100, error("CheckTransaction(): this is a public chain, no sapling allowed"),
|
||||
@@ -1725,7 +1731,8 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
|
||||
if (pfMissingInputs)
|
||||
*pfMissingInputs = true;
|
||||
//fprintf(stderr,"missing inputs\n");
|
||||
return state.DoS(0, error("AcceptToMemoryPool: tx inputs not found"),REJECT_INVALID, "bad-txns-inputs-missing");
|
||||
//return state.DoS(0, error("AcceptToMemoryPool: tx inputs not found"),REJECT_INVALID, "bad-txns-inputs-missing");
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1979,6 +1986,7 @@ bool myAddtomempool(CTransaction &tx, CValidationState *pstate)
|
||||
|
||||
bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock)
|
||||
{
|
||||
memset(&hashBlock,0,sizeof(hashBlock));
|
||||
// need a GetTransaction without lock so the validation code for assets can run without deadlock
|
||||
{
|
||||
//fprintf(stderr,"check mempool\n");
|
||||
@@ -2022,6 +2030,7 @@ bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlo
|
||||
bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock, bool fAllowSlow)
|
||||
{
|
||||
CBlockIndex *pindexSlow = NULL;
|
||||
memset(&hashBlock,0,sizeof(hashBlock));
|
||||
|
||||
LOCK(cs_main);
|
||||
|
||||
|
||||
@@ -463,8 +463,6 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount,
|
||||
uint64_t txfees,utxovalue; uint32_t txtime; uint256 utxotxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[128],*ptr;
|
||||
CMutableTransaction txStaked = CreateNewContextualCMutableTransaction(Params().GetConsensus(), stakeHeight);
|
||||
|
||||
//if ( blocktime > pindexPrev->GetMedianTimePast()+60 )
|
||||
// blocktime = pindexPrev->GetMedianTimePast() + 60;
|
||||
if (ASSETCHAINS_LWMAPOS != 0)
|
||||
{
|
||||
uint32_t nBitsPOS;
|
||||
@@ -479,6 +477,9 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount,
|
||||
}
|
||||
else
|
||||
{
|
||||
blocktime = GetAdjustedTime();
|
||||
//if ( blocktime > pindexPrev->GetMedianTimePast()+60 )
|
||||
// blocktime = pindexPrev->GetMedianTimePast() + 60;
|
||||
siglen = komodo_staked(txStaked, pblock->nBits, &blocktime, &txtime, &utxotxid, &utxovout, &utxovalue, utxosig);
|
||||
}
|
||||
|
||||
@@ -736,7 +737,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight,
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!isStake)
|
||||
//if ( !isStake || ASSETCHAINS_STAKED != 0 )
|
||||
{
|
||||
if (!reservekey.GetReservedKey(pubkey))
|
||||
{
|
||||
|
||||
@@ -136,7 +136,6 @@ static const CRPCConvertParam vRPCConvertParams[] =
|
||||
{ "z_shieldcoinbase", 3},
|
||||
{ "z_getoperationstatus", 0},
|
||||
{ "z_getoperationresult", 0},
|
||||
{ "z_importkey", 1 },
|
||||
{ "paxprice", 4 },
|
||||
{ "paxprices", 3 },
|
||||
{ "paxpending", 0 },
|
||||
|
||||
@@ -670,7 +670,8 @@ bool CBlockTreeDB::LoadBlockIndexGuts()
|
||||
pindexNew->nCachedBranchId = diskindex.nCachedBranchId;
|
||||
pindexNew->nTx = diskindex.nTx;
|
||||
pindexNew->nSproutValue = diskindex.nSproutValue;
|
||||
|
||||
pindexNew->nSaplingValue = diskindex.nSaplingValue;
|
||||
|
||||
// Consistency checks
|
||||
auto header = pindexNew->GetBlockHeader();
|
||||
if (header.GetHash() != pindexNew->GetBlockHash())
|
||||
|
||||
1424
src/veruslaunch.cpp
1424
src/veruslaunch.cpp
File diff suppressed because it is too large
Load Diff
@@ -1,17 +0,0 @@
|
||||
|
||||
// Copyright (c) 2018 The Verus developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef VERUS_LAUNCH_H
|
||||
#define VERUS_LAUNCH_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#define WHITELIST_COUNT 704
|
||||
|
||||
extern const char *whitelist_ids[WHITELIST_COUNT];
|
||||
extern const char *whitelist_address;
|
||||
extern uint64_t whitelist_masks[WHITELIST_COUNT];
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -9,6 +9,7 @@
|
||||
#include "asyncrpcoperation.h"
|
||||
#include "paymentdisclosure.h"
|
||||
#include "primitives/transaction.h"
|
||||
#include "transaction_builder.h"
|
||||
#include "wallet.h"
|
||||
#include "zcash/Address.hpp"
|
||||
#include "zcash/JoinSplit.hpp"
|
||||
@@ -24,11 +25,13 @@
|
||||
|
||||
using namespace libzcash;
|
||||
|
||||
// Input UTXO is a tuple of txid, vout, amount
|
||||
typedef std::tuple<COutPoint, CAmount> MergeToAddressInputUTXO;
|
||||
// Input UTXO is a tuple of txid, vout, amount, script
|
||||
typedef std::tuple<COutPoint, CAmount, CScript> MergeToAddressInputUTXO;
|
||||
|
||||
// Input JSOP is a tuple of JSOutpoint, note, amount, spending key
|
||||
typedef std::tuple<JSOutPoint, SproutNote, CAmount, SpendingKey> MergeToAddressInputNote;
|
||||
typedef std::tuple<JSOutPoint, SproutNote, CAmount, SproutSpendingKey> MergeToAddressInputSproutNote;
|
||||
|
||||
typedef std::tuple<SaplingOutPoint, SaplingNote, CAmount, SaplingExpandedSpendingKey> MergeToAddressInputSaplingNote;
|
||||
|
||||
// A recipient is a tuple of address, memo (optional if zaddr)
|
||||
typedef std::tuple<std::string, std::string> MergeToAddressRecipient;
|
||||
@@ -53,33 +56,36 @@ class AsyncRPCOperation_mergetoaddress : public AsyncRPCOperation
|
||||
{
|
||||
public:
|
||||
AsyncRPCOperation_mergetoaddress(
|
||||
CMutableTransaction contextualTx,
|
||||
std::vector<MergeToAddressInputUTXO> utxoInputs,
|
||||
std::vector<MergeToAddressInputNote> noteInputs,
|
||||
MergeToAddressRecipient recipient,
|
||||
CAmount fee = MERGE_TO_ADDRESS_OPERATION_DEFAULT_MINERS_FEE,
|
||||
UniValue contextInfo = NullUniValue);
|
||||
boost::optional<TransactionBuilder> builder,
|
||||
CMutableTransaction contextualTx,
|
||||
std::vector<MergeToAddressInputUTXO> utxoInputs,
|
||||
std::vector<MergeToAddressInputSproutNote> sproutNoteInputs,
|
||||
std::vector<MergeToAddressInputSaplingNote> saplingNoteInputs,
|
||||
MergeToAddressRecipient recipient,
|
||||
CAmount fee = MERGE_TO_ADDRESS_OPERATION_DEFAULT_MINERS_FEE,
|
||||
UniValue contextInfo = NullUniValue);
|
||||
virtual ~AsyncRPCOperation_mergetoaddress();
|
||||
|
||||
|
||||
// We don't want to be copied or moved around
|
||||
AsyncRPCOperation_mergetoaddress(AsyncRPCOperation_mergetoaddress const&) = delete; // Copy construct
|
||||
AsyncRPCOperation_mergetoaddress(AsyncRPCOperation_mergetoaddress&&) = delete; // Move construct
|
||||
AsyncRPCOperation_mergetoaddress& operator=(AsyncRPCOperation_mergetoaddress const&) = delete; // Copy assign
|
||||
AsyncRPCOperation_mergetoaddress& operator=(AsyncRPCOperation_mergetoaddress&&) = delete; // Move assign
|
||||
|
||||
|
||||
virtual void main();
|
||||
|
||||
|
||||
virtual UniValue getStatus() const;
|
||||
|
||||
|
||||
bool testmode = false; // Set to true to disable sending txs and generating proofs
|
||||
|
||||
bool paymentDisclosureMode = false; // Set to true to save esk for encrypted notes in payment disclosure database.
|
||||
|
||||
|
||||
bool paymentDisclosureMode = true; // Set to true to save esk for encrypted notes in payment disclosure database.
|
||||
|
||||
private:
|
||||
friend class TEST_FRIEND_AsyncRPCOperation_mergetoaddress; // class for unit testing
|
||||
|
||||
|
||||
UniValue contextinfo_; // optional data to include in return value from getStatus()
|
||||
|
||||
|
||||
bool isUsingBuilder_; // Indicates that no Sprout addresses are involved
|
||||
uint32_t consensusBranchId_;
|
||||
CAmount fee_;
|
||||
int mindepth_;
|
||||
@@ -88,43 +94,45 @@ private:
|
||||
bool isToZaddr_;
|
||||
CTxDestination toTaddr_;
|
||||
PaymentAddress toPaymentAddress_;
|
||||
|
||||
|
||||
uint256 joinSplitPubKey_;
|
||||
unsigned char joinSplitPrivKey_[crypto_sign_SECRETKEYBYTES];
|
||||
|
||||
|
||||
// The key is the result string from calling JSOutPoint::ToString()
|
||||
std::unordered_map<std::string, MergeToAddressWitnessAnchorData> jsopWitnessAnchorMap;
|
||||
|
||||
|
||||
std::vector<MergeToAddressInputUTXO> utxoInputs_;
|
||||
std::vector<MergeToAddressInputNote> noteInputs_;
|
||||
|
||||
std::vector<MergeToAddressInputSproutNote> sproutNoteInputs_;
|
||||
std::vector<MergeToAddressInputSaplingNote> saplingNoteInputs_;
|
||||
|
||||
TransactionBuilder builder_;
|
||||
CTransaction tx_;
|
||||
|
||||
|
||||
std::array<unsigned char, ZC_MEMO_SIZE> get_memo_from_hex_string(std::string s);
|
||||
bool main_impl();
|
||||
|
||||
|
||||
// JoinSplit without any input notes to spend
|
||||
UniValue perform_joinsplit(MergeToAddressJSInfo&);
|
||||
|
||||
|
||||
// JoinSplit with input notes to spend (JSOutPoints))
|
||||
UniValue perform_joinsplit(MergeToAddressJSInfo&, std::vector<JSOutPoint>&);
|
||||
|
||||
|
||||
// JoinSplit where you have the witnesses and anchor
|
||||
UniValue perform_joinsplit(
|
||||
MergeToAddressJSInfo& info,
|
||||
std::vector<boost::optional<SproutWitness>> witnesses,
|
||||
uint256 anchor);
|
||||
|
||||
MergeToAddressJSInfo& info,
|
||||
std::vector<boost::optional<SproutWitness>> witnesses,
|
||||
uint256 anchor);
|
||||
|
||||
void sign_send_raw_transaction(UniValue obj); // throws exception if there was an error
|
||||
|
||||
|
||||
void lock_utxos();
|
||||
|
||||
|
||||
void unlock_utxos();
|
||||
|
||||
|
||||
void lock_notes();
|
||||
|
||||
|
||||
void unlock_notes();
|
||||
|
||||
|
||||
// payment disclosure!
|
||||
std::vector<PaymentDisclosureKeyInfo> paymentDisclosureData_;
|
||||
};
|
||||
@@ -135,54 +143,54 @@ class TEST_FRIEND_AsyncRPCOperation_mergetoaddress
|
||||
{
|
||||
public:
|
||||
std::shared_ptr<AsyncRPCOperation_mergetoaddress> delegate;
|
||||
|
||||
|
||||
TEST_FRIEND_AsyncRPCOperation_mergetoaddress(std::shared_ptr<AsyncRPCOperation_mergetoaddress> ptr) : delegate(ptr) {}
|
||||
|
||||
|
||||
CTransaction getTx()
|
||||
{
|
||||
return delegate->tx_;
|
||||
}
|
||||
|
||||
|
||||
void setTx(CTransaction tx)
|
||||
{
|
||||
delegate->tx_ = tx;
|
||||
}
|
||||
|
||||
|
||||
// Delegated methods
|
||||
|
||||
|
||||
std::array<unsigned char, ZC_MEMO_SIZE> get_memo_from_hex_string(std::string s)
|
||||
{
|
||||
return delegate->get_memo_from_hex_string(s);
|
||||
}
|
||||
|
||||
|
||||
bool main_impl()
|
||||
{
|
||||
return delegate->main_impl();
|
||||
}
|
||||
|
||||
|
||||
UniValue perform_joinsplit(MergeToAddressJSInfo& info)
|
||||
{
|
||||
return delegate->perform_joinsplit(info);
|
||||
}
|
||||
|
||||
|
||||
UniValue perform_joinsplit(MergeToAddressJSInfo& info, std::vector<JSOutPoint>& v)
|
||||
{
|
||||
return delegate->perform_joinsplit(info, v);
|
||||
}
|
||||
|
||||
|
||||
UniValue perform_joinsplit(
|
||||
MergeToAddressJSInfo& info,
|
||||
std::vector<boost::optional<SproutWitness>> witnesses,
|
||||
uint256 anchor)
|
||||
MergeToAddressJSInfo& info,
|
||||
std::vector<boost::optional<SproutWitness>> witnesses,
|
||||
uint256 anchor)
|
||||
{
|
||||
return delegate->perform_joinsplit(info, witnesses, anchor);
|
||||
}
|
||||
|
||||
|
||||
void sign_send_raw_transaction(UniValue obj)
|
||||
{
|
||||
delegate->sign_send_raw_transaction(obj);
|
||||
}
|
||||
|
||||
|
||||
void set_state(OperationStatus state)
|
||||
{
|
||||
delegate->state_.store(state);
|
||||
|
||||
@@ -123,7 +123,7 @@ AsyncRPCOperation_sendmany::AsyncRPCOperation_sendmany(
|
||||
|
||||
|
||||
// Enable payment disclosure if requested
|
||||
paymentDisclosureMode = fExperimentalMode && GetBoolArg("-paymentdisclosure", false);
|
||||
paymentDisclosureMode = fExperimentalMode && GetBoolArg("-paymentdisclosure", true);
|
||||
}
|
||||
|
||||
AsyncRPCOperation_sendmany::~AsyncRPCOperation_sendmany() {
|
||||
@@ -1366,7 +1366,8 @@ void AsyncRPCOperation_sendmany::add_taddr_change_output_to_tx(CBitcoinAddress *
|
||||
}
|
||||
|
||||
std::array<unsigned char, ZC_MEMO_SIZE> AsyncRPCOperation_sendmany::get_memo_from_hex_string(std::string s) {
|
||||
std::array<unsigned char, ZC_MEMO_SIZE> memo = {{0x00}};
|
||||
// initialize to default memo (no_memo), see section 5.5 of the protocol spec
|
||||
std::array<unsigned char, ZC_MEMO_SIZE> memo = {{0xF6}};
|
||||
|
||||
std::vector<unsigned char> rawMemo = ParseHex(s.c_str());
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ public:
|
||||
|
||||
bool testmode = false; // Set to true to disable sending txs and generating proofs
|
||||
|
||||
bool paymentDisclosureMode = false; // Set to true to save esk for encrypted notes in payment disclosure database.
|
||||
bool paymentDisclosureMode = true; // Set to true to save esk for encrypted notes in payment disclosure database.
|
||||
|
||||
private:
|
||||
friend class TEST_FRIEND_AsyncRPCOperation_sendmany; // class for unit testing
|
||||
|
||||
@@ -93,7 +93,7 @@ AsyncRPCOperation_shieldcoinbase::AsyncRPCOperation_shieldcoinbase(
|
||||
lock_utxos();
|
||||
|
||||
// Enable payment disclosure if requested
|
||||
paymentDisclosureMode = fExperimentalMode && GetBoolArg("-paymentdisclosure", false);
|
||||
paymentDisclosureMode = fExperimentalMode && GetBoolArg("-paymentdisclosure", true);
|
||||
}
|
||||
|
||||
AsyncRPCOperation_shieldcoinbase::~AsyncRPCOperation_shieldcoinbase() {
|
||||
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
bool testmode = false; // Set to true to disable sending txs and generating proofs
|
||||
bool cheatSpend = false; // set when this is shielding a cheating coinbase
|
||||
|
||||
bool paymentDisclosureMode = false; // Set to true to save esk for encrypted notes in payment disclosure database.
|
||||
bool paymentDisclosureMode = true; // Set to true to save esk for encrypted notes in payment disclosure database.
|
||||
|
||||
private:
|
||||
friend class ShieldToAddress;
|
||||
|
||||
@@ -42,7 +42,7 @@ UniValue z_getpaymentdisclosure(const UniValue& params, bool fHelp)
|
||||
return NullUniValue;
|
||||
|
||||
string enableArg = "paymentdisclosure";
|
||||
auto fEnablePaymentDisclosure = fExperimentalMode && GetBoolArg("-" + enableArg, false);
|
||||
auto fEnablePaymentDisclosure = fExperimentalMode && GetBoolArg("-" + enableArg, true);
|
||||
string strPaymentDisclosureDisabledMsg = "";
|
||||
if (!fEnablePaymentDisclosure) {
|
||||
strPaymentDisclosureDisabledMsg = experimentalDisabledHelpMsg("z_getpaymentdisclosure", enableArg);
|
||||
@@ -149,7 +149,7 @@ UniValue z_validatepaymentdisclosure(const UniValue& params, bool fHelp)
|
||||
return NullUniValue;
|
||||
|
||||
string enableArg = "paymentdisclosure";
|
||||
auto fEnablePaymentDisclosure = fExperimentalMode && GetBoolArg("-" + enableArg, false);
|
||||
auto fEnablePaymentDisclosure = fExperimentalMode && GetBoolArg("-" + enableArg, true);
|
||||
string strPaymentDisclosureDisabledMsg = "";
|
||||
if (!fEnablePaymentDisclosure) {
|
||||
strPaymentDisclosureDisabledMsg = experimentalDisabledHelpMsg("z_validatepaymentdisclosure", enableArg);
|
||||
|
||||
@@ -2342,6 +2342,7 @@ UniValue walletlock(const UniValue& params, bool fHelp)
|
||||
return NullUniValue;
|
||||
}
|
||||
|
||||
int32_t komodo_acpublic(uint32_t tiptime);
|
||||
|
||||
UniValue encryptwallet(const UniValue& params, bool fHelp)
|
||||
{
|
||||
@@ -2349,7 +2350,8 @@ UniValue encryptwallet(const UniValue& params, bool fHelp)
|
||||
return NullUniValue;
|
||||
|
||||
string enableArg = "developerencryptwallet";
|
||||
auto fEnableWalletEncryption = fExperimentalMode && GetBoolArg("-" + enableArg, false);
|
||||
int32_t flag = (komodo_acpublic(0) || ASSETCHAINS_SYMBOL[0] == 0);
|
||||
auto fEnableWalletEncryption = fExperimentalMode && GetBoolArg("-" + enableArg, flag);
|
||||
|
||||
std::string strWalletEncryptionDisabledMsg = "";
|
||||
if (!fEnableWalletEncryption) {
|
||||
@@ -2849,8 +2851,8 @@ UniValue z_listunspent(const UniValue& params, bool fHelp)
|
||||
|
||||
"\nExamples\n"
|
||||
+ HelpExampleCli("z_listunspent", "")
|
||||
+ HelpExampleCli("z_listunspent", "6 9999999 false \"[\\\"ztbx5DLDxa5ZLFTchHhoPNkKs57QzSyib6UqXpEdy76T1aUdFxJt1w9318Z8DJ73XzbnWHKEZP9Yjg712N5kMmP4QzS9iC9\\\",\\\"ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf\\\"]\"")
|
||||
+ HelpExampleRpc("z_listunspent", "6 9999999 false \"[\\\"ztbx5DLDxa5ZLFTchHhoPNkKs57QzSyib6UqXpEdy76T1aUdFxJt1w9318Z8DJ73XzbnWHKEZP9Yjg712N5kMmP4QzS9iC9\\\",\\\"ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf\\\"]\"")
|
||||
+ HelpExampleCli("z_listunspent", "6 9999999 false \"[\\\"zs14d8tc0hl9q0vg5l28uec5vk6sk34fkj2n8s7jalvw5fxpy6v39yn4s2ga082lymrkjk0x2nqg37\\\",\\\"zs14d8tc0hl9q0vg5l28uec5vk6sk34fkj2n8s7jalvw5fxpy6v39yn4s2ga082lymrkjk0x2nqg37\\\"]\"")
|
||||
+ HelpExampleRpc("z_listunspent", "6 9999999 false \"[\\\"zs14d8tc0hl9q0vg5l28uec5vk6sk34fkj2n8s7jalvw5fxpy6v39yn4s2ga082lymrkjk0x2nqg37\\\",\\\"zs14d8tc0hl9q0vg5l28uec5vk6sk34fkj2n8s7jalvw5fxpy6v39yn4s2ga082lymrkjk0x2nqg37\\\"]\"")
|
||||
);
|
||||
|
||||
RPCTypeCheck(params, boost::assign::list_of(UniValue::VNUM)(UniValue::VNUM)(UniValue::VBOOL)(UniValue::VARR));
|
||||
@@ -3686,8 +3688,8 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp)
|
||||
" \"change\": true|false, (boolean) true if the address that received the note is also one of the sending addresses\n"
|
||||
"}\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("z_listreceivedbyaddress", "\"ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf\"")
|
||||
+ HelpExampleRpc("z_listreceivedbyaddress", "\"ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf\"")
|
||||
+ HelpExampleCli("z_listreceivedbyaddress", "\"zs14d8tc0hl9q0vg5l28uec5vk6sk34fkj2n8s7jalvw5fxpy6v39yn4s2ga082lymrkjk0x2nqg37\"")
|
||||
+ HelpExampleRpc("z_listreceivedbyaddress", "\"zs14d8tc0hl9q0vg5l28uec5vk6sk34fkj2n8s7jalvw5fxpy6v39yn4s2ga082lymrkjk0x2nqg37\"")
|
||||
);
|
||||
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
@@ -4019,8 +4021,8 @@ UniValue z_sendmany(const UniValue& params, bool fHelp)
|
||||
"\nResult:\n"
|
||||
"\"operationid\" (string) An operationid to pass to z_getoperationstatus to get the result of the operation.\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("z_sendmany", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" '[{\"address\": \"ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf\" ,\"amount\": 5.0}]'")
|
||||
+ HelpExampleRpc("z_sendmany", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", [{\"address\": \"ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf\" ,\"amount\": 5.0}]")
|
||||
+ HelpExampleCli("z_sendmany", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" '[{\"address\": \"zs14d8tc0hl9q0vg5l28uec5vk6sk34fkj2n8s7jalvw5fxpy6v39yn4s2ga082lymrkjk0x2nqg37\" ,\"amount\": 5.0}]'")
|
||||
+ HelpExampleRpc("z_sendmany", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", [{\"address\": \"zs14d8tc0hl9q0vg5l28uec5vk6sk34fkj2n8s7jalvw5fxpy6v39yn4s2ga082lymrkjk0x2nqg37\" ,\"amount\": 5.0}]")
|
||||
);
|
||||
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
@@ -4110,15 +4112,10 @@ UniValue z_sendmany(const UniValue& params, bool fHelp)
|
||||
}
|
||||
// If we are sending from a shielded address, all recipient
|
||||
// shielded addresses must be of the same type.
|
||||
if (fromSprout && toSapling) {
|
||||
if ((fromSprout && toSapling) || (fromSapling && toSprout)) {
|
||||
throw JSONRPCError(
|
||||
RPC_INVALID_PARAMETER,
|
||||
"Cannot send from a Sprout address to a Sapling address using z_sendmany");
|
||||
}
|
||||
if (fromSapling && toSprout) {
|
||||
throw JSONRPCError(
|
||||
RPC_INVALID_PARAMETER,
|
||||
"Cannot send from a Sapling address to a Sprout address using z_sendmany");
|
||||
"Cannot send between Sprout and Sapling addresses using z_sendmany");
|
||||
}
|
||||
} else {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, unknown address format: ")+address );
|
||||
@@ -4330,8 +4327,8 @@ UniValue z_shieldcoinbase(const UniValue& params, bool fHelp)
|
||||
" \"opid\": xxx (string) An operationid to pass to z_getoperationstatus to get the result of the operation.\n"
|
||||
"}\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("z_shieldcoinbase", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" \"ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf\"")
|
||||
+ HelpExampleRpc("z_shieldcoinbase", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", \"ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf\"")
|
||||
+ HelpExampleCli("z_shieldcoinbase", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" \"zs14d8tc0hl9q0vg5l28uec5vk6sk34fkj2n8s7jalvw5fxpy6v39yn4s2ga082lymrkjk0x2nqg37\"")
|
||||
+ HelpExampleRpc("z_shieldcoinbase", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", \"zs14d8tc0hl9q0vg5l28uec5vk6sk34fkj2n8s7jalvw5fxpy6v39yn4s2ga082lymrkjk0x2nqg37\"")
|
||||
);
|
||||
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
@@ -4519,160 +4516,159 @@ UniValue z_shieldcoinbase(const UniValue& params, bool fHelp)
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
#define MERGE_TO_ADDRESS_DEFAULT_TRANSPARENT_LIMIT 50
|
||||
#define MERGE_TO_ADDRESS_DEFAULT_SHIELDED_LIMIT 10
|
||||
#define MERGE_TO_ADDRESS_DEFAULT_SPROUT_LIMIT 10
|
||||
#define MERGE_TO_ADDRESS_DEFAULT_SAPLING_LIMIT 90
|
||||
|
||||
#define JOINSPLIT_SIZE GetSerializeSize(JSDescription(), SER_NETWORK, PROTOCOL_VERSION)
|
||||
#define OUTPUTDESCRIPTION_SIZE GetSerializeSize(OutputDescription(), SER_NETWORK, PROTOCOL_VERSION)
|
||||
#define SPENDDESCRIPTION_SIZE GetSerializeSize(SpendDescription(), SER_NETWORK, PROTOCOL_VERSION)
|
||||
|
||||
UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return NullUniValue;
|
||||
|
||||
|
||||
string enableArg = "zmergetoaddress";
|
||||
auto fEnableMergeToAddress = fExperimentalMode && GetBoolArg("-" + enableArg, false);
|
||||
auto fEnableMergeToAddress = fExperimentalMode && GetBoolArg("-" + enableArg, true);
|
||||
std::string strDisabledMsg = "";
|
||||
if (!fEnableMergeToAddress) {
|
||||
strDisabledMsg = experimentalDisabledHelpMsg("z_mergetoaddress", enableArg);
|
||||
}
|
||||
|
||||
|
||||
if (fHelp || params.size() < 2 || params.size() > 6)
|
||||
throw runtime_error(
|
||||
"z_mergetoaddress [\"fromaddress\", ... ] \"toaddress\" ( fee ) ( transparent_limit ) ( shielded_limit ) ( memo )\n"
|
||||
+ strDisabledMsg +
|
||||
"\nMerge multiple UTXOs and notes into a single UTXO or note. Coinbase UTXOs are ignored; use `z_shieldcoinbase`"
|
||||
"\nto combine those into a single note."
|
||||
"\n\nThis is an asynchronous operation, and UTXOs selected for merging will be locked. If there is an error, they"
|
||||
"\nare unlocked. The RPC call `listlockunspent` can be used to return a list of locked UTXOs."
|
||||
"\n\nThe number of UTXOs and notes selected for merging can be limited by the caller. If the transparent limit"
|
||||
"\nparameter is set to zero, and Overwinter is not yet active, the -mempooltxinputlimit option will determine the"
|
||||
"\nnumber of UTXOs. Any limit is constrained by the consensus rule defining a maximum transaction size of"
|
||||
+ strprintf("\n%d bytes before Sapling, and %d bytes once Sapling activates.", MAX_TX_SIZE_BEFORE_SAPLING, MAX_TX_SIZE_AFTER_SAPLING)
|
||||
+ HelpRequiringPassphrase() + "\n"
|
||||
"\nArguments:\n"
|
||||
"1. fromaddresses (string, required) A JSON array with addresses.\n"
|
||||
" The following special strings are accepted inside the array:\n"
|
||||
" - \"*\": Merge both UTXOs and notes from all addresses belonging to the wallet.\n"
|
||||
" - \"ANY_TADDR\": Merge UTXOs from all t-addrs belonging to the wallet.\n"
|
||||
" - \"ANY_ZADDR\": Merge notes from all z-addrs belonging to the wallet.\n"
|
||||
" If a special string is given, any given addresses of that type will be ignored.\n"
|
||||
" [\n"
|
||||
" \"address\" (string) Can be a t-addr or a z-addr\n"
|
||||
" ,...\n"
|
||||
" ]\n"
|
||||
"2. \"toaddress\" (string, required) The t-addr or z-addr to send the funds to.\n"
|
||||
"3. fee (numeric, optional, default="
|
||||
+ strprintf("%s", FormatMoney(MERGE_TO_ADDRESS_OPERATION_DEFAULT_MINERS_FEE)) + ") The fee amount to attach to this transaction.\n"
|
||||
"4. transparent_limit (numeric, optional, default="
|
||||
+ strprintf("%d", MERGE_TO_ADDRESS_DEFAULT_TRANSPARENT_LIMIT) + ") Limit on the maximum number of UTXOs to merge. Set to 0 to use node option -mempooltxinputlimit (before Overwinter), or as many as will fit in the transaction (after Overwinter).\n"
|
||||
"4. shielded_limit (numeric, optional, default="
|
||||
+ strprintf("%d", MERGE_TO_ADDRESS_DEFAULT_SHIELDED_LIMIT) + ") Limit on the maximum number of notes to merge. Set to 0 to merge as many as will fit in the transaction.\n"
|
||||
"5. \"memo\" (string, optional) Encoded as hex. When toaddress is a z-addr, this will be stored in the memo field of the new note.\n"
|
||||
"\nResult:\n"
|
||||
"{\n"
|
||||
" \"remainingUTXOs\": xxx (numeric) Number of UTXOs still available for merging.\n"
|
||||
" \"remainingTransparentValue\": xxx (numeric) Value of UTXOs still available for merging.\n"
|
||||
" \"remainingNotes\": xxx (numeric) Number of notes still available for merging.\n"
|
||||
" \"remainingShieldedValue\": xxx (numeric) Value of notes still available for merging.\n"
|
||||
" \"mergingUTXOs\": xxx (numeric) Number of UTXOs being merged.\n"
|
||||
" \"mergingTransparentValue\": xxx (numeric) Value of UTXOs being merged.\n"
|
||||
" \"mergingNotes\": xxx (numeric) Number of notes being merged.\n"
|
||||
" \"mergingShieldedValue\": xxx (numeric) Value of notes being merged.\n"
|
||||
" \"opid\": xxx (string) An operationid to pass to z_getoperationstatus to get the result of the operation.\n"
|
||||
"}\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("z_mergetoaddress", "'[\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\"]' ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf")
|
||||
+ HelpExampleRpc("z_mergetoaddress", "[\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\"], \"ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf\"")
|
||||
);
|
||||
|
||||
"z_mergetoaddress [\"fromaddress\", ... ] \"toaddress\" ( fee ) ( transparent_limit ) ( shielded_limit ) ( memo )\n"
|
||||
+ strDisabledMsg +
|
||||
"\nMerge multiple UTXOs and notes into a single UTXO or note. Coinbase UTXOs are ignored; use `z_shieldcoinbase`"
|
||||
"\nto combine those into a single note."
|
||||
"\n\nThis is an asynchronous operation, and UTXOs selected for merging will be locked. If there is an error, they"
|
||||
"\nare unlocked. The RPC call `listlockunspent` can be used to return a list of locked UTXOs."
|
||||
"\n\nThe number of UTXOs and notes selected for merging can be limited by the caller. If the transparent limit"
|
||||
"\nparameter is set to zero, and Overwinter is not yet active, the -mempooltxinputlimit option will determine the"
|
||||
"\nnumber of UTXOs. Any limit is constrained by the consensus rule defining a maximum transaction size of"
|
||||
+ strprintf("\n%d bytes before Sapling, and %d bytes once Sapling activates.", MAX_TX_SIZE_BEFORE_SAPLING, MAX_TX_SIZE_AFTER_SAPLING)
|
||||
+ HelpRequiringPassphrase() + "\n"
|
||||
"\nArguments:\n"
|
||||
"1. fromaddresses (string, required) A JSON array with addresses.\n"
|
||||
" The following special strings are accepted inside the array:\n"
|
||||
" - \"ANY_TADDR\": Merge UTXOs from any t-addrs belonging to the wallet.\n"
|
||||
" - \"ANY_SPROUT\": Merge notes from any Sprout z-addrs belonging to the wallet.\n"
|
||||
" - \"ANY_SAPLING\": Merge notes from any Sapling z-addrs belonging to the wallet.\n"
|
||||
" If a special string is given, any given addresses of that type will be ignored.\n"
|
||||
" [\n"
|
||||
" \"address\" (string) Can be a t-addr or a z-addr\n"
|
||||
" ,...\n"
|
||||
" ]\n"
|
||||
"2. \"toaddress\" (string, required) The t-addr or z-addr to send the funds to.\n"
|
||||
"3. fee (numeric, optional, default="
|
||||
+ strprintf("%s", FormatMoney(MERGE_TO_ADDRESS_OPERATION_DEFAULT_MINERS_FEE)) + ") The fee amount to attach to this transaction.\n"
|
||||
"4. transparent_limit (numeric, optional, default="
|
||||
+ strprintf("%d", MERGE_TO_ADDRESS_DEFAULT_TRANSPARENT_LIMIT) + ") Limit on the maximum number of UTXOs to merge. Set to 0 to use node option -mempooltxinputlimit (before Overwinter), or as many as will fit in the transaction (after Overwinter).\n"
|
||||
"4. shielded_limit (numeric, optional, default="
|
||||
+ strprintf("%d Sprout or %d Sapling Notes", MERGE_TO_ADDRESS_DEFAULT_SPROUT_LIMIT, MERGE_TO_ADDRESS_DEFAULT_SAPLING_LIMIT) + ") Limit on the maximum number of notes to merge. Set to 0 to merge as many as will fit in the transaction.\n"
|
||||
"5. \"memo\" (string, optional) Encoded as hex. When toaddress is a z-addr, this will be stored in the memo field of the new note.\n"
|
||||
"\nResult:\n"
|
||||
"{\n"
|
||||
" \"remainingUTXOs\": xxx (numeric) Number of UTXOs still available for merging.\n"
|
||||
" \"remainingTransparentValue\": xxx (numeric) Value of UTXOs still available for merging.\n"
|
||||
" \"remainingNotes\": xxx (numeric) Number of notes still available for merging.\n"
|
||||
" \"remainingShieldedValue\": xxx (numeric) Value of notes still available for merging.\n"
|
||||
" \"mergingUTXOs\": xxx (numeric) Number of UTXOs being merged.\n"
|
||||
" \"mergingTransparentValue\": xxx (numeric) Value of UTXOs being merged.\n"
|
||||
" \"mergingNotes\": xxx (numeric) Number of notes being merged.\n"
|
||||
" \"mergingShieldedValue\": xxx (numeric) Value of notes being merged.\n"
|
||||
" \"opid\": xxx (string) An operationid to pass to z_getoperationstatus to get the result of the operation.\n"
|
||||
"}\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("z_mergetoaddress", "'[\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\"]' ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf")
|
||||
+ HelpExampleRpc("z_mergetoaddress", "[\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\"], \"zs14d8tc0hl9q0vg5l28uec5vk6sk34fkj2n8s7jalvw5fxpy6v39yn4s2ga082lymrkjk0x2nqg37\"")
|
||||
);
|
||||
|
||||
if (!fEnableMergeToAddress) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Error: z_mergetoaddress is disabled.");
|
||||
}
|
||||
|
||||
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
|
||||
bool useAny = false;
|
||||
|
||||
bool useAnyUTXO = false;
|
||||
bool useAnyNote = false;
|
||||
bool useAnySprout = false;
|
||||
bool useAnySapling = false;
|
||||
std::set<CTxDestination> taddrs = {};
|
||||
std::set<libzcash::PaymentAddress> zaddrs = {};
|
||||
|
||||
uint32_t branchId = CurrentEpochBranchId(chainActive.Height(), Params().GetConsensus());
|
||||
|
||||
|
||||
UniValue addresses = params[0].get_array();
|
||||
if (addresses.size()==0)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, fromaddresses array is empty.");
|
||||
|
||||
|
||||
// Keep track of addresses to spot duplicates
|
||||
std::set<std::string> setAddress;
|
||||
|
||||
|
||||
// Sources
|
||||
bool containsSaplingZaddrSource = false;
|
||||
for (const UniValue& o : addresses.getValues()) {
|
||||
if (!o.isStr())
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected string");
|
||||
|
||||
|
||||
std::string address = o.get_str();
|
||||
if (address == "*") {
|
||||
useAny = true;
|
||||
} else if (address == "ANY_TADDR") {
|
||||
|
||||
if (address == "ANY_TADDR") {
|
||||
useAnyUTXO = true;
|
||||
} else if (address == "ANY_ZADDR") {
|
||||
useAnyNote = true;
|
||||
} else if (address == "ANY_SPROUT") {
|
||||
useAnySprout = true;
|
||||
} else if (address == "ANY_SAPLING") {
|
||||
useAnySapling = true;
|
||||
} else {
|
||||
CTxDestination taddr = DecodeDestination(address);
|
||||
if (IsValidDestination(taddr)) {
|
||||
// Ignore any listed t-addrs if we are using all of them
|
||||
if (!(useAny || useAnyUTXO)) {
|
||||
taddrs.insert(taddr);
|
||||
}
|
||||
taddrs.insert(taddr);
|
||||
} else {
|
||||
auto zaddr = DecodePaymentAddress(address);
|
||||
if (IsValidPaymentAddress(zaddr, branchId)) {
|
||||
// Ignore listed z-addrs if we are using all of them
|
||||
if (!(useAny || useAnyNote)) {
|
||||
zaddrs.insert(zaddr);
|
||||
}
|
||||
// Check if z-addr is Sapling
|
||||
bool isSapling = boost::get<libzcash::SaplingPaymentAddress>(&zaddr) != nullptr;
|
||||
containsSaplingZaddrSource |= isSapling;
|
||||
if (IsValidPaymentAddress(zaddr)) {
|
||||
zaddrs.insert(zaddr);
|
||||
} else {
|
||||
throw JSONRPCError(
|
||||
RPC_INVALID_PARAMETER,
|
||||
string("Invalid parameter, unknown address format: ") + address);
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Unknown address format: ") + address);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (setAddress.count(address))
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ") + address);
|
||||
setAddress.insert(address);
|
||||
}
|
||||
|
||||
|
||||
if (useAnyUTXO && taddrs.size() > 0) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot specify specific t-addrs when using \"ANY_TADDR\"");
|
||||
}
|
||||
if ((useAnySprout || useAnySapling) && zaddrs.size() > 0) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot specify specific z-addrs when using \"ANY_SPROUT\" or \"ANY_SAPLING\"");
|
||||
}
|
||||
|
||||
const int nextBlockHeight = chainActive.Height() + 1;
|
||||
const bool overwinterActive = NetworkUpgradeActive(nextBlockHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER);
|
||||
const bool saplingActive = NetworkUpgradeActive(nextBlockHeight, Params().GetConsensus(), Consensus::UPGRADE_SAPLING);
|
||||
|
||||
// Validate the destination address
|
||||
auto destaddress = params[1].get_str();
|
||||
bool isToZaddr = false;
|
||||
bool isToSproutZaddr = false;
|
||||
bool isToSaplingZaddr = false;
|
||||
CTxDestination taddr = DecodeDestination(destaddress);
|
||||
if (!IsValidDestination(taddr)) {
|
||||
if (IsValidPaymentAddressString(destaddress, branchId)) {
|
||||
isToZaddr = true;
|
||||
|
||||
// Is this a Sapling address?
|
||||
auto res = DecodePaymentAddress(destaddress);
|
||||
if (IsValidPaymentAddress(res)) {
|
||||
isToSaplingZaddr = boost::get<libzcash::SaplingPaymentAddress>(&res) != nullptr;
|
||||
auto decodeAddr = DecodePaymentAddress(destaddress);
|
||||
if (IsValidPaymentAddress(decodeAddr)) {
|
||||
if (boost::get<libzcash::SaplingPaymentAddress>(&decodeAddr) != nullptr) {
|
||||
isToSaplingZaddr = true;
|
||||
// If Sapling is not active, do not allow sending to a sapling addresses.
|
||||
if (!saplingActive) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, Sapling has not activated");
|
||||
}
|
||||
} else {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, unknown address format: ") + destaddress );
|
||||
isToSproutZaddr = true;
|
||||
}
|
||||
} else {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, unknown address format: ") + destaddress );
|
||||
}
|
||||
}
|
||||
else if ( ASSETCHAINS_PRIVATE != 0 )
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "cant use transparent addresses in private chain");
|
||||
|
||||
|
||||
// Convert fee from currency format to zatoshis
|
||||
CAmount nFee = SHIELD_COINBASE_DEFAULT_MINERS_FEE;
|
||||
if (params.size() > 2) {
|
||||
@@ -4682,7 +4678,7 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
|
||||
nFee = AmountFromValue( params[2] );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int nUTXOLimit = MERGE_TO_ADDRESS_DEFAULT_TRANSPARENT_LIMIT;
|
||||
if (params.size() > 3) {
|
||||
nUTXOLimit = params[3].get_int();
|
||||
@@ -4690,19 +4686,22 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Limit on maximum number of UTXOs cannot be negative");
|
||||
}
|
||||
}
|
||||
|
||||
int nNoteLimit = MERGE_TO_ADDRESS_DEFAULT_SHIELDED_LIMIT;
|
||||
|
||||
int sproutNoteLimit = MERGE_TO_ADDRESS_DEFAULT_SPROUT_LIMIT;
|
||||
int saplingNoteLimit = MERGE_TO_ADDRESS_DEFAULT_SAPLING_LIMIT;
|
||||
if (params.size() > 4) {
|
||||
nNoteLimit = params[4].get_int();
|
||||
int nNoteLimit = params[4].get_int();
|
||||
if (nNoteLimit < 0) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Limit on maximum number of notes cannot be negative");
|
||||
}
|
||||
sproutNoteLimit = nNoteLimit;
|
||||
saplingNoteLimit = nNoteLimit;
|
||||
}
|
||||
|
||||
|
||||
std::string memo;
|
||||
if (params.size() > 5) {
|
||||
memo = params[5].get_str();
|
||||
if (!isToZaddr) {
|
||||
if (!(isToSproutZaddr || isToSaplingZaddr)) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Memo can not be used with a taddr. It can only be used with a zaddr.");
|
||||
} else if (!IsHex(memo)) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected memo data in hexadecimal format.");
|
||||
@@ -4711,75 +4710,56 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid parameter, size of memo is larger than maximum allowed %d", ZC_MEMO_SIZE ));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MergeToAddressRecipient recipient(destaddress, memo);
|
||||
|
||||
int nextBlockHeight = chainActive.Height() + 1;
|
||||
bool overwinterActive = NetworkUpgradeActive(nextBlockHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER);
|
||||
unsigned int max_tx_size = MAX_TX_SIZE_AFTER_SAPLING;
|
||||
if (!NetworkUpgradeActive(nextBlockHeight, Params().GetConsensus(), Consensus::UPGRADE_SAPLING)) {
|
||||
max_tx_size = MAX_TX_SIZE_BEFORE_SAPLING;
|
||||
}
|
||||
|
||||
// This RPC does not support Sapling yet.
|
||||
if (isToSaplingZaddr || containsSaplingZaddrSource) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, Sapling is not supported yet by z_mergetoadress");
|
||||
}
|
||||
|
||||
// If this RPC does support Sapling...
|
||||
// If Sapling is not active, do not allow sending from or sending to Sapling addresses.
|
||||
if (!NetworkUpgradeActive(nextBlockHeight, Params().GetConsensus(), Consensus::UPGRADE_SAPLING)) {
|
||||
if (isToSaplingZaddr || containsSaplingZaddrSource) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, Sapling has not activated");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Prepare to get UTXOs and notes
|
||||
std::vector<MergeToAddressInputUTXO> utxoInputs;
|
||||
std::vector<MergeToAddressInputNote> noteInputs;
|
||||
std::vector<MergeToAddressInputSproutNote> sproutNoteInputs;
|
||||
std::vector<MergeToAddressInputSaplingNote> saplingNoteInputs;
|
||||
CAmount mergedUTXOValue = 0;
|
||||
CAmount mergedNoteValue = 0;
|
||||
CAmount remainingUTXOValue = 0;
|
||||
CAmount remainingNoteValue = 0;
|
||||
#ifdef __LP64__
|
||||
uint64_t utxoCounter = 0;
|
||||
uint64_t noteCounter = 0;
|
||||
#else
|
||||
size_t utxoCounter = 0;
|
||||
size_t noteCounter = 0;
|
||||
#endif
|
||||
bool maxedOutUTXOsFlag = false;
|
||||
bool maxedOutNotesFlag = false;
|
||||
size_t mempoolLimit = (nUTXOLimit != 0) ? nUTXOLimit : (overwinterActive ? 0 : (size_t)GetArg("-mempooltxinputlimit", 0));
|
||||
|
||||
|
||||
unsigned int max_tx_size = saplingActive ? MAX_TX_SIZE_AFTER_SAPLING : MAX_TX_SIZE_BEFORE_SAPLING;
|
||||
size_t estimatedTxSize = 200; // tx overhead + wiggle room
|
||||
if (isToZaddr) {
|
||||
if (isToSproutZaddr) {
|
||||
estimatedTxSize += JOINSPLIT_SIZE;
|
||||
} else if (isToSaplingZaddr) {
|
||||
estimatedTxSize += OUTPUTDESCRIPTION_SIZE;
|
||||
}
|
||||
|
||||
if (useAny || useAnyUTXO || taddrs.size() > 0) {
|
||||
|
||||
if (useAnyUTXO || taddrs.size() > 0) {
|
||||
// Get available utxos
|
||||
vector<COutput> vecOutputs;
|
||||
pwalletMain->AvailableCoins(vecOutputs, true, NULL, false, false);
|
||||
|
||||
|
||||
// Find unspent utxos and update estimated size
|
||||
for (const COutput& out : vecOutputs) {
|
||||
if (!out.fSpendable) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
CScript scriptPubKey = out.tx->vout[out.i].scriptPubKey;
|
||||
|
||||
CTxDestination address;
|
||||
if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) {
|
||||
if (!ExtractDestination(scriptPubKey, address)) {
|
||||
continue;
|
||||
}
|
||||
// If taddr is not wildcard "*", filter utxos
|
||||
if (taddrs.size() > 0 && !taddrs.count(address)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
utxoCounter++;
|
||||
CAmount nValue = out.tx->vout[out.i].nValue;
|
||||
|
||||
|
||||
if (!maxedOutUTXOsFlag) {
|
||||
size_t increase = (boost::get<CScriptID>(&address) != nullptr) ? CTXIN_SPEND_P2SH_SIZE : CTXIN_SPEND_DUST_SIZE;
|
||||
if (estimatedTxSize + increase >= max_tx_size ||
|
||||
@@ -4789,34 +4769,51 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
|
||||
} else {
|
||||
estimatedTxSize += increase;
|
||||
COutPoint utxo(out.tx->GetHash(), out.i);
|
||||
utxoInputs.emplace_back(utxo, nValue);
|
||||
utxoInputs.emplace_back(utxo, nValue, scriptPubKey);
|
||||
mergedUTXOValue += nValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (maxedOutUTXOsFlag) {
|
||||
remainingUTXOValue += nValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (useAny || useAnyNote || zaddrs.size() > 0) {
|
||||
|
||||
if (useAnySprout || useAnySapling || zaddrs.size() > 0) {
|
||||
// Get available notes
|
||||
std::vector<CSproutNotePlaintextEntry> sproutEntries;
|
||||
std::vector<SaplingNoteEntry> saplingEntries;
|
||||
pwalletMain->GetFilteredNotes(sproutEntries, saplingEntries, zaddrs);
|
||||
|
||||
|
||||
// If Sapling is not active, do not allow sending from a sapling addresses.
|
||||
if (!saplingActive && saplingEntries.size() > 0) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, Sapling has not activated");
|
||||
}
|
||||
// Sending from both Sprout and Sapling is currently unsupported using z_mergetoaddress
|
||||
if (sproutEntries.size() > 0 && saplingEntries.size() > 0) {
|
||||
throw JSONRPCError(
|
||||
RPC_INVALID_PARAMETER,
|
||||
"Cannot send from both Sprout and Sapling addresses using z_mergetoaddress");
|
||||
}
|
||||
// If sending between shielded addresses, they must be the same type
|
||||
if ((saplingEntries.size() > 0 && isToSproutZaddr) || (sproutEntries.size() > 0 && isToSaplingZaddr)) {
|
||||
throw JSONRPCError(
|
||||
RPC_INVALID_PARAMETER,
|
||||
"Cannot send between Sprout and Sapling addresses using z_mergetoaddress");
|
||||
}
|
||||
|
||||
// Find unspent notes and update estimated size
|
||||
for (CSproutNotePlaintextEntry& entry : sproutEntries) {
|
||||
for (const CSproutNotePlaintextEntry& entry : sproutEntries) {
|
||||
noteCounter++;
|
||||
CAmount nValue = entry.plaintext.value();
|
||||
|
||||
|
||||
if (!maxedOutNotesFlag) {
|
||||
// If we haven't added any notes yet and the merge is to a
|
||||
// z-address, we have already accounted for the first JoinSplit.
|
||||
size_t increase = (noteInputs.empty() && !isToZaddr) || (noteInputs.size() % 2 == 0) ? JOINSPLIT_SIZE : 0;
|
||||
size_t increase = (sproutNoteInputs.empty() && !isToSproutZaddr) || (sproutNoteInputs.size() % 2 == 0) ? JOINSPLIT_SIZE : 0;
|
||||
if (estimatedTxSize + increase >= max_tx_size ||
|
||||
(nNoteLimit > 0 && noteCounter > nNoteLimit))
|
||||
(sproutNoteLimit > 0 && noteCounter > sproutNoteLimit))
|
||||
{
|
||||
maxedOutNotesFlag = true;
|
||||
} else {
|
||||
@@ -4824,31 +4821,49 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
|
||||
auto zaddr = entry.address;
|
||||
SproutSpendingKey zkey;
|
||||
pwalletMain->GetSproutSpendingKey(zaddr, zkey);
|
||||
noteInputs.emplace_back(entry.jsop, entry.plaintext.note(zaddr), nValue, zkey);
|
||||
sproutNoteInputs.emplace_back(entry.jsop, entry.plaintext.note(zaddr), nValue, zkey);
|
||||
mergedNoteValue += nValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (maxedOutNotesFlag) {
|
||||
remainingNoteValue += nValue;
|
||||
}
|
||||
}
|
||||
|
||||
for (const SaplingNoteEntry& entry : saplingEntries) {
|
||||
noteCounter++;
|
||||
CAmount nValue = entry.note.value();
|
||||
if (!maxedOutNotesFlag) {
|
||||
size_t increase = SPENDDESCRIPTION_SIZE;
|
||||
if (estimatedTxSize + increase >= max_tx_size ||
|
||||
(saplingNoteLimit > 0 && noteCounter > saplingNoteLimit))
|
||||
{
|
||||
maxedOutNotesFlag = true;
|
||||
} else {
|
||||
estimatedTxSize += increase;
|
||||
libzcash::SaplingExtendedSpendingKey extsk;
|
||||
if (!pwalletMain->GetSaplingExtendedSpendingKey(entry.address, extsk)) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Could not find spending key for payment address.");
|
||||
}
|
||||
saplingNoteInputs.emplace_back(entry.op, entry.note, nValue, extsk.expsk);
|
||||
mergedNoteValue += nValue;
|
||||
}
|
||||
}
|
||||
|
||||
if (maxedOutNotesFlag) {
|
||||
remainingNoteValue += nValue;
|
||||
}
|
||||
}
|
||||
// TODO: Add Sapling support
|
||||
}
|
||||
|
||||
#ifdef __LP64__
|
||||
uint64_t numUtxos = utxoInputs.size(); //ca333
|
||||
uint64_t numNotes = noteInputs.size();
|
||||
#else
|
||||
|
||||
size_t numUtxos = utxoInputs.size();
|
||||
size_t numNotes = noteInputs.size();
|
||||
#endif
|
||||
|
||||
|
||||
size_t numNotes = sproutNoteInputs.size() + saplingNoteInputs.size();
|
||||
|
||||
if (numUtxos == 0 && numNotes == 0) {
|
||||
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Could not find any funds to merge.");
|
||||
}
|
||||
|
||||
|
||||
// Sanity check: Don't do anything if:
|
||||
// - We only have one from address
|
||||
// - It's equal to toaddress
|
||||
@@ -4856,42 +4871,47 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
|
||||
if (setAddress.size() == 1 && setAddress.count(destaddress) && (numUtxos + numNotes) == 1) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Destination address is also the only source address, and all its funds are already merged.");
|
||||
}
|
||||
|
||||
|
||||
CAmount mergedValue = mergedUTXOValue + mergedNoteValue;
|
||||
if (mergedValue < nFee) {
|
||||
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS,
|
||||
strprintf("Insufficient funds, have %s, which is less than miners fee %s",
|
||||
FormatMoney(mergedValue), FormatMoney(nFee)));
|
||||
strprintf("Insufficient funds, have %s, which is less than miners fee %s",
|
||||
FormatMoney(mergedValue), FormatMoney(nFee)));
|
||||
}
|
||||
|
||||
|
||||
// Check that the user specified fee is sane (if too high, it can result in error -25 absurd fee)
|
||||
CAmount netAmount = mergedValue - nFee;
|
||||
if (nFee > netAmount) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Fee %s is greater than the net amount to be shielded %s", FormatMoney(nFee), FormatMoney(netAmount)));
|
||||
}
|
||||
|
||||
|
||||
// Keep record of parameters in context object
|
||||
UniValue contextInfo(UniValue::VOBJ);
|
||||
contextInfo.push_back(Pair("fromaddresses", params[0]));
|
||||
contextInfo.push_back(Pair("toaddress", params[1]));
|
||||
contextInfo.push_back(Pair("fee", ValueFromAmount(nFee)));
|
||||
|
||||
|
||||
// Contextual transaction we will build on
|
||||
CMutableTransaction contextualTx = CreateNewContextualCMutableTransaction(
|
||||
Params().GetConsensus(),
|
||||
nextBlockHeight);
|
||||
bool isShielded = numNotes > 0 || isToZaddr;
|
||||
if (contextualTx.nVersion == 1 && isShielded) {
|
||||
Params().GetConsensus(),
|
||||
nextBlockHeight);
|
||||
bool isSproutShielded = sproutNoteInputs.size() > 0 || isToSproutZaddr;
|
||||
if (contextualTx.nVersion == 1 && isSproutShielded) {
|
||||
contextualTx.nVersion = 2; // Tx format should support vjoinsplit
|
||||
}
|
||||
|
||||
|
||||
// Builder (used if Sapling addresses are involved)
|
||||
boost::optional<TransactionBuilder> builder;
|
||||
if (isToSaplingZaddr || saplingNoteInputs.size() > 0) {
|
||||
builder = TransactionBuilder(Params().GetConsensus(), nextBlockHeight, pwalletMain);
|
||||
}
|
||||
// Create operation and add to global queue
|
||||
std::shared_ptr<AsyncRPCQueue> q = getAsyncRPCQueue();
|
||||
std::shared_ptr<AsyncRPCOperation> operation(
|
||||
new AsyncRPCOperation_mergetoaddress(contextualTx, utxoInputs, noteInputs, recipient, nFee, contextInfo) );
|
||||
new AsyncRPCOperation_mergetoaddress(builder, contextualTx, utxoInputs, sproutNoteInputs, saplingNoteInputs, recipient, nFee, contextInfo) );
|
||||
q->addOperation(operation);
|
||||
AsyncRPCOperationId operationId = operation->getId();
|
||||
|
||||
|
||||
// Return continuation information
|
||||
UniValue o(UniValue::VOBJ);
|
||||
o.push_back(Pair("remainingUTXOs", static_cast<uint64_t>(utxoCounter - numUtxos)));
|
||||
@@ -5059,8 +5079,10 @@ struct komodo_staking *komodo_addutxo(struct komodo_staking *array,int32_t *numk
|
||||
{
|
||||
*maxkp += 1000;
|
||||
array = (struct komodo_staking *)realloc(array,sizeof(*array) * (*maxkp));
|
||||
//fprintf(stderr,"realloc max.%d array.%p\n",*maxkp,array);
|
||||
}
|
||||
kp = &array[(*numkp)++];
|
||||
//fprintf(stderr,"kp.%p num.%d\n",kp,*numkp);
|
||||
memset(kp,0,sizeof(*kp));
|
||||
strcpy(kp->address,address);
|
||||
kp->txid = txid;
|
||||
@@ -5083,15 +5105,11 @@ arith_uint256 _komodo_eligible(struct komodo_staking *kp,arith_uint256 ratio,uin
|
||||
diff = 3600*24*30;
|
||||
if ( iter > 0 )
|
||||
diff += segid*2;
|
||||
coinage = ((uint64_t)kp->nValue/COIN * diff);
|
||||
coinage = ((uint64_t)kp->nValue * diff);
|
||||
if ( blocktime+iter+segid*2 > prevtime+480 )
|
||||
coinage *= ((blocktime+iter+segid*2) - (prevtime+400));
|
||||
//if ( nHeight >= 2500 && blocktime+iter+segid*2 > prevtime+180 )
|
||||
// coinage *= ((blocktime+iter+segid*2) - (prevtime+60));
|
||||
coinage256 = arith_uint256(coinage+1);
|
||||
hashval = ratio * (kp->hashval / coinage256);
|
||||
//if ( nHeight >= 900 && nHeight < 916 )
|
||||
// hashval = (hashval / coinage256);
|
||||
return(hashval);
|
||||
}
|
||||
|
||||
@@ -5121,7 +5139,7 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod
|
||||
return(blocktime);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else fprintf(stderr,"maxiters is not good enough\n");
|
||||
return(0);
|
||||
}
|
||||
|
||||
@@ -5148,10 +5166,10 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
|
||||
if ( (minage= nHeight*3) > 6000 ) // about 100 blocks
|
||||
minage = 6000;
|
||||
komodo_segids(hashbuf,nHeight-101,100);
|
||||
if ( *blocktimep > tipindex->nTime+60 )
|
||||
if ( *blocktimep < tipindex->nTime+60 )
|
||||
*blocktimep = tipindex->nTime+60;
|
||||
//fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight);
|
||||
if ( time(NULL) > lasttime+600 )
|
||||
if ( time(NULL) > lasttime+600 || array == 0 )
|
||||
{
|
||||
if ( array != 0 )
|
||||
{
|
||||
@@ -5170,7 +5188,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
|
||||
counter++;
|
||||
if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth )
|
||||
{
|
||||
//fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth);
|
||||
fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth);
|
||||
continue;
|
||||
}
|
||||
CAmount nValue = out.tx->vout[out.i].nValue;
|
||||
@@ -5184,12 +5202,14 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
|
||||
if ( GetTransaction(out.tx->GetHash(),tx,hashBlock,true) != 0 && (pindex= komodo_getblockindex(hashBlock)) != 0 )
|
||||
{
|
||||
array = komodo_addutxo(array,&numkp,&maxkp,(uint32_t)pindex->nTime,(uint64_t)nValue,out.tx->GetHash(),out.i,(char *)CBitcoinAddress(address).ToString().c_str(),hashbuf,(CScript)pk);
|
||||
//fprintf(stderr,"addutxo numkp.%d vs max.%d\n",numkp,maxkp);
|
||||
}
|
||||
}
|
||||
}
|
||||
lasttime = (uint32_t)time(NULL);
|
||||
//fprintf(stderr,"finished kp data of utxo for staking %u ht.%d numkp.%d maxkp.%d\n",(uint32_t)time(NULL),nHeight,numkp,maxkp);
|
||||
//fprintf(stderr,"finished kp data of utxo for staking %u ht.%d numkp.%d maxkp.%d\n",(uint32_t)time(NULL),nHeight,numkp,maxkp);
|
||||
}
|
||||
//fprintf(stderr,"numkp.%d blocktime.%u\n",numkp,*blocktimep);
|
||||
block_from_future_rejecttime = (uint32_t)GetAdjustedTime() + 57;
|
||||
for (i=winners=0; i<numkp; i++)
|
||||
{
|
||||
@@ -5202,7 +5222,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
|
||||
if ( (eligible2= komodo_eligible(bnTarget,ratio,kp,nHeight,*blocktimep,(uint32_t)tipindex->nTime+27,minage,hashbuf)) == 0 )
|
||||
continue;
|
||||
eligible = komodo_stake(0,bnTarget,nHeight,kp->txid,kp->vout,0,(uint32_t)tipindex->nTime+27,kp->address);
|
||||
//fprintf(stderr,"i.%d %u vs %u\n",i,eligible2,eligible);
|
||||
//fprintf(stderr,"i.%d %u vs %u\n",i,eligible2,eligible);
|
||||
if ( eligible > 0 )
|
||||
{
|
||||
besttime = m = 0;
|
||||
@@ -5215,7 +5235,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
|
||||
if ( eligible < block_from_future_rejecttime ) // nothing gained by going earlier
|
||||
break;
|
||||
m++;
|
||||
//fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible);
|
||||
//fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -5225,7 +5245,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
|
||||
}
|
||||
eligible = besttime;
|
||||
winners++;
|
||||
//fprintf(stderr,"ht.%d validated winning [%d] -> %.8f eligible.%u test prior\n",nHeight,(int32_t)(eligible - tipindex->nTime),(double)kp->nValue/COIN,eligible);
|
||||
//fprintf(stderr,"ht.%d validated winning [%d] -> %.8f eligible.%u test prior\n",nHeight,(int32_t)(eligible - tipindex->nTime),(double)kp->nValue/COIN,eligible);
|
||||
if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || kp->nValue < *utxovaluep)) )
|
||||
{
|
||||
earliest = eligible;
|
||||
@@ -5238,7 +5258,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
|
||||
fprintf(stderr,"ht.%d earliest.%u [%d].%d (%s) nValue %.8f locktime.%u counter.%d winners.%d\n",nHeight,earliest,(int32_t)(earliest - tipindex->nTime),m,kp->address,(double)kp->nValue/COIN,*txtimep,counter,winners);
|
||||
}
|
||||
} //else fprintf(stderr,"utxo not eligible\n");
|
||||
} //else fprintf(stderr,"no tipindex\n");
|
||||
}
|
||||
if ( numkp < 10000 && array != 0 )
|
||||
{
|
||||
free(array);
|
||||
@@ -5273,7 +5293,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
|
||||
for (i=0; i<siglen; i++)
|
||||
utxosig[i] = ptr[i];//, fprintf(stderr,"%02x",ptr[i]);
|
||||
//fprintf(stderr," siglen.%d\n",siglen);
|
||||
//fprintf(stderr,"best %u from %u, gap %d lag.%d\n",earliest,*blocktimep,(int32_t)(earliest - *blocktimep),(int32_t)(time(NULL) - *blocktimep));
|
||||
//fprintf(stderr,"best %u from %u, gap %d lag.%d\n",earliest,*blocktimep,(int32_t)(earliest - *blocktimep),(int32_t)(time(NULL) - *blocktimep));
|
||||
*blocktimep = earliest;
|
||||
}
|
||||
} //else fprintf(stderr,"no earliest utxo for staking\n");
|
||||
|
||||
@@ -4960,10 +4960,10 @@ void CWallet::GetFilteredNotes(
|
||||
}
|
||||
|
||||
// skip locked notes
|
||||
// TODO: Add locking for Sapling notes
|
||||
// if (ignoreLocked && IsLockedNote(op)) {
|
||||
// continue;
|
||||
// }
|
||||
// TODO: Add locking for Sapling notes -> done
|
||||
if (ignoreLocked && IsLockedNote(op)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto note = notePt.note(nd.ivk).get();
|
||||
saplingEntries.push_back(SaplingNoteEntry {
|
||||
|
||||
Reference in New Issue
Block a user