From 951d0abada71519e371f5e714ede06282c15448f Mon Sep 17 00:00:00 2001 From: ca333 Date: Thu, 9 Aug 2018 23:13:17 +0200 Subject: [PATCH 001/643] update travis --- .travis.yml | 91 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 68 insertions(+), 23 deletions(-) diff --git a/.travis.yml b/.travis.yml index d9237a104..6792e41bb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,22 +5,32 @@ matrix: - os: linux dist: xenial sudo: required + env: LINUX_DEPLOY="true" OSX_DEPLOY="false" - os: osx - osx_image: xcode8 + osx_image: xcode8 + env: OSX_DEPLOY="true" LINUX_DEPLOY="false" +branches: + only: + - master + - dev + - cctests compiler: -- gcc + - gcc before_install: -- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo add-apt-repository --yes ppa:ubuntu-sdk-team/ppa; fi -- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get update -qq; fi -- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install libgnutls28-dev; fi -- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install build-essential pkg-config libcurl3-gnutls-dev libc6-dev libevent-dev m4 g++-multilib autoconf libtool ncurses-dev unzip git python zlib1g-dev wget bsdmainutils automake libssl-dev libprotobuf-dev protobuf-compiler libdb++-dev ntp ntpdate; fi -- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then rm '/usr/local/include/c++'; fi -- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi -- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install gcc@6; fi -- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew link --overwrite gcc@6; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo add-apt-repository --yes ppa:ubuntu-sdk-team/ppa; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get update -qq; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install libgnutls28-dev; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install build-essential pkg-config libcurl3-gnutls-dev libc6-dev libevent-dev m4 g++-multilib autoconf libtool ncurses-dev unzip git python zlib1g-dev wget bsdmainutils automake libssl-dev libprotobuf-dev protobuf-compiler libdb++-dev ntp ntpdate; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then rm '/usr/local/include/c++'; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install gcc@6; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew link --overwrite gcc@6; fi script: -- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ./zcutil/build.sh -j 5; fi -- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./zcutil/build-mac.sh -j 5; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ./zcutil/build.sh -j 5; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then tar cvfz komodo_linux.tar.gz src/komodod src/komodo-cli; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./zcutil/build-mac.sh -j 5; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./makeRelease.sh; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then tar cvfz komodo_osx.tar.gz src/komodod src/komodo-cli src/libgcc_s.1.dylib src/libgomp.1.dylib src/libstdc++.6.dylib; fi notifications: irc: channels: @@ -32,15 +42,50 @@ notifications: - 'Change view : %{compare_url}' - 'Build details : %{build_url}' before_deploy: - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then git tag "linux-$(date +'%Y%m%d%H%M')-$(git log --format=%h -1)"; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then git tag "osx-$(date +'%Y%m%d%H%M')-$(git log --format=%h -1)"; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then git tag "$TRAVIS_BRANCH-linux-$(date +'%Y%m%d%H%M')-$(git log --format=%h -1)"; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then git tag "$TRAVIS_BRANCH-osx-$(date +'%Y%m%d%H%M')-$(git log --format=%h -1)"; fi deploy: - provider: releases - api_key: - secure: Jms7dz5GMZmuXUCHl5u6iZUtAybv86oW3x36DCJfdzbDiO4B9EWB04z7zA0qvoomefyujHTmQUHxyOKfd4h9/rVMFFv9hgmUxWkrcg7KyLNisOQRaovVOuNtu2lRNXTOSF16Cy+xFGkVh1ObBRhAoMsVKPhMl6PCDiKhNWIekRR9pBtjafKsClQ2ieknUYfqhuvgj7zmqCedeyVaVQyt2W/J65leD0BkfCUESTpANSprHs4bQB65VuQIKKMi+URKx2VgpDdUcWJySt9jAHVPIbI5cT5maAT6RUMnE4oha7Ca1Ox8StBqjQ/hkkMyDbN0keIlN7RjZlwdZQf/qUnT/dPQhsyUCdPXOxmEJ2jekezEK/LGr4Fb+v+vjd9dhLNkD5nVn9zp36biGSCjiMpffQ3fjMeM0YGmVEVRP9kZXLWVRYQoVKrzjyzg5dY8iChbiQEfYpTeBuU+e2rqj4mns+Jvy0zjUbMy6Tyva+iqdZ/PdsBDbiB7c+FIgB1IUTVOD+GgKx6dhCtBZEccn5EyWFwZF9IdQJHZCYV4PA7nuzfm1Ol9SDdZkGHd2OgRCqK/sTwyfTHv8exNqZ1k+epGJp2a0q4IOEknc9aPCAF+m9pHahk7s7VO5gmhO6pvbvuKoeEtEXRZHRzCkGkXfzJlBk+23X5gBexKb6inRdBlj6M= - file: - - src/komodod - - src/komodo-cli - skip_cleanup: true - on: - repo: KomodoPlatform/komodo + - provider: releases + api_key: + secure: Jms7dz5GMZmuXUCHl5u6iZUtAybv86oW3x36DCJfdzbDiO4B9EWB04z7zA0qvoomefyujHTmQUHxyOKfd4h9/rVMFFv9hgmUxWkrcg7KyLNisOQRaovVOuNtu2lRNXTOSF16Cy+xFGkVh1ObBRhAoMsVKPhMl6PCDiKhNWIekRR9pBtjafKsClQ2ieknUYfqhuvgj7zmqCedeyVaVQyt2W/J65leD0BkfCUESTpANSprHs4bQB65VuQIKKMi+URKx2VgpDdUcWJySt9jAHVPIbI5cT5maAT6RUMnE4oha7Ca1Ox8StBqjQ/hkkMyDbN0keIlN7RjZlwdZQf/qUnT/dPQhsyUCdPXOxmEJ2jekezEK/LGr4Fb+v+vjd9dhLNkD5nVn9zp36biGSCjiMpffQ3fjMeM0YGmVEVRP9kZXLWVRYQoVKrzjyzg5dY8iChbiQEfYpTeBuU+e2rqj4mns+Jvy0zjUbMy6Tyva+iqdZ/PdsBDbiB7c+FIgB1IUTVOD+GgKx6dhCtBZEccn5EyWFwZF9IdQJHZCYV4PA7nuzfm1Ol9SDdZkGHd2OgRCqK/sTwyfTHv8exNqZ1k+epGJp2a0q4IOEknc9aPCAF+m9pHahk7s7VO5gmhO6pvbvuKoeEtEXRZHRzCkGkXfzJlBk+23X5gBexKb6inRdBlj6M= + name: komodo_linux-$TRAVIS_BRANCH + prerelease: true + file: komodo_linux.tar.gz + skip_cleanup: true + on: + repo: KomodoPlatform/komodo + branch: master + condition: $LINUX_DEPLOY = "true" + - provider: releases + api_key: + secure: Jms7dz5GMZmuXUCHl5u6iZUtAybv86oW3x36DCJfdzbDiO4B9EWB04z7zA0qvoomefyujHTmQUHxyOKfd4h9/rVMFFv9hgmUxWkrcg7KyLNisOQRaovVOuNtu2lRNXTOSF16Cy+xFGkVh1ObBRhAoMsVKPhMl6PCDiKhNWIekRR9pBtjafKsClQ2ieknUYfqhuvgj7zmqCedeyVaVQyt2W/J65leD0BkfCUESTpANSprHs4bQB65VuQIKKMi+URKx2VgpDdUcWJySt9jAHVPIbI5cT5maAT6RUMnE4oha7Ca1Ox8StBqjQ/hkkMyDbN0keIlN7RjZlwdZQf/qUnT/dPQhsyUCdPXOxmEJ2jekezEK/LGr4Fb+v+vjd9dhLNkD5nVn9zp36biGSCjiMpffQ3fjMeM0YGmVEVRP9kZXLWVRYQoVKrzjyzg5dY8iChbiQEfYpTeBuU+e2rqj4mns+Jvy0zjUbMy6Tyva+iqdZ/PdsBDbiB7c+FIgB1IUTVOD+GgKx6dhCtBZEccn5EyWFwZF9IdQJHZCYV4PA7nuzfm1Ol9SDdZkGHd2OgRCqK/sTwyfTHv8exNqZ1k+epGJp2a0q4IOEknc9aPCAF+m9pHahk7s7VO5gmhO6pvbvuKoeEtEXRZHRzCkGkXfzJlBk+23X5gBexKb6inRdBlj6M= + name: komodo_linux-$TRAVIS_BRANCH + prerelease: true + file: komodo_linux.tar.gz + skip_cleanup: true + on: + repo: KomodoPlatform/komodo + branch: dev + condition: $LINUX_DEPLOY = "true" + - provider: releases + api_key: + secure: Jms7dz5GMZmuXUCHl5u6iZUtAybv86oW3x36DCJfdzbDiO4B9EWB04z7zA0qvoomefyujHTmQUHxyOKfd4h9/rVMFFv9hgmUxWkrcg7KyLNisOQRaovVOuNtu2lRNXTOSF16Cy+xFGkVh1ObBRhAoMsVKPhMl6PCDiKhNWIekRR9pBtjafKsClQ2ieknUYfqhuvgj7zmqCedeyVaVQyt2W/J65leD0BkfCUESTpANSprHs4bQB65VuQIKKMi+URKx2VgpDdUcWJySt9jAHVPIbI5cT5maAT6RUMnE4oha7Ca1Ox8StBqjQ/hkkMyDbN0keIlN7RjZlwdZQf/qUnT/dPQhsyUCdPXOxmEJ2jekezEK/LGr4Fb+v+vjd9dhLNkD5nVn9zp36biGSCjiMpffQ3fjMeM0YGmVEVRP9kZXLWVRYQoVKrzjyzg5dY8iChbiQEfYpTeBuU+e2rqj4mns+Jvy0zjUbMy6Tyva+iqdZ/PdsBDbiB7c+FIgB1IUTVOD+GgKx6dhCtBZEccn5EyWFwZF9IdQJHZCYV4PA7nuzfm1Ol9SDdZkGHd2OgRCqK/sTwyfTHv8exNqZ1k+epGJp2a0q4IOEknc9aPCAF+m9pHahk7s7VO5gmhO6pvbvuKoeEtEXRZHRzCkGkXfzJlBk+23X5gBexKb6inRdBlj6M= + name: komodo_osx-$TRAVIS_BRANCH + prerelease: true + file: komodo_osx.tar.gz + skip_cleanup: true + on: + repo: KomodoPlatform/komodo + branch: master + condition: $OSX_DEPLOY = "true" + - provider: releases + api_key: + secure: Jms7dz5GMZmuXUCHl5u6iZUtAybv86oW3x36DCJfdzbDiO4B9EWB04z7zA0qvoomefyujHTmQUHxyOKfd4h9/rVMFFv9hgmUxWkrcg7KyLNisOQRaovVOuNtu2lRNXTOSF16Cy+xFGkVh1ObBRhAoMsVKPhMl6PCDiKhNWIekRR9pBtjafKsClQ2ieknUYfqhuvgj7zmqCedeyVaVQyt2W/J65leD0BkfCUESTpANSprHs4bQB65VuQIKKMi+URKx2VgpDdUcWJySt9jAHVPIbI5cT5maAT6RUMnE4oha7Ca1Ox8StBqjQ/hkkMyDbN0keIlN7RjZlwdZQf/qUnT/dPQhsyUCdPXOxmEJ2jekezEK/LGr4Fb+v+vjd9dhLNkD5nVn9zp36biGSCjiMpffQ3fjMeM0YGmVEVRP9kZXLWVRYQoVKrzjyzg5dY8iChbiQEfYpTeBuU+e2rqj4mns+Jvy0zjUbMy6Tyva+iqdZ/PdsBDbiB7c+FIgB1IUTVOD+GgKx6dhCtBZEccn5EyWFwZF9IdQJHZCYV4PA7nuzfm1Ol9SDdZkGHd2OgRCqK/sTwyfTHv8exNqZ1k+epGJp2a0q4IOEknc9aPCAF+m9pHahk7s7VO5gmhO6pvbvuKoeEtEXRZHRzCkGkXfzJlBk+23X5gBexKb6inRdBlj6M= + name: komodo_osx-$TRAVIS_BRANCH + prerelease: true + file: komodo_osx.tar.gz + skip_cleanup: true + on: + repo: KomodoPlatform/komodo + branch: dev + condition: $OSX_DEPLOY = "true" From 53bcb42e5853844a1d23b9c9f1267241618e6591 Mon Sep 17 00:00:00 2001 From: ca333 Date: Fri, 10 Aug 2018 00:11:20 +0200 Subject: [PATCH 002/643] update deployment keys --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6792e41bb..93307b3a5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -47,7 +47,7 @@ before_deploy: deploy: - provider: releases api_key: - secure: Jms7dz5GMZmuXUCHl5u6iZUtAybv86oW3x36DCJfdzbDiO4B9EWB04z7zA0qvoomefyujHTmQUHxyOKfd4h9/rVMFFv9hgmUxWkrcg7KyLNisOQRaovVOuNtu2lRNXTOSF16Cy+xFGkVh1ObBRhAoMsVKPhMl6PCDiKhNWIekRR9pBtjafKsClQ2ieknUYfqhuvgj7zmqCedeyVaVQyt2W/J65leD0BkfCUESTpANSprHs4bQB65VuQIKKMi+URKx2VgpDdUcWJySt9jAHVPIbI5cT5maAT6RUMnE4oha7Ca1Ox8StBqjQ/hkkMyDbN0keIlN7RjZlwdZQf/qUnT/dPQhsyUCdPXOxmEJ2jekezEK/LGr4Fb+v+vjd9dhLNkD5nVn9zp36biGSCjiMpffQ3fjMeM0YGmVEVRP9kZXLWVRYQoVKrzjyzg5dY8iChbiQEfYpTeBuU+e2rqj4mns+Jvy0zjUbMy6Tyva+iqdZ/PdsBDbiB7c+FIgB1IUTVOD+GgKx6dhCtBZEccn5EyWFwZF9IdQJHZCYV4PA7nuzfm1Ol9SDdZkGHd2OgRCqK/sTwyfTHv8exNqZ1k+epGJp2a0q4IOEknc9aPCAF+m9pHahk7s7VO5gmhO6pvbvuKoeEtEXRZHRzCkGkXfzJlBk+23X5gBexKb6inRdBlj6M= + secure: id69KBVsY0p41WFlqd5cGrAIksJAkUempmdrQwHtfqIbB6es7MVfXuxfmTxk7lZNEItSvLGilYtqhBMNVAVjRRPvk90hveGDMkbpjFz3XBbFEFqtrAr2GdIcpGtII2T3T/TG7j11TMtJ6GvBVt4OcatHFVsKBCFDIx0fB0fd1oLrEAwgRdBO2Jq7bMzoLdzGx3mVtdW5dSRBQzG/Z0yvx+R9mQHSvyPGh6oNPD6mvXPzEaCeRW6Y8g8y1SW/6zDJR6sSdOKA0jsHkr/hM8st3Qkr5Cu3roEbL8598uvfBahjxVHVT8+lu/nJnQyrvtWZKu/uUefybqgZl7UpGvZVFxbNwAB/ZNn0pBKIpZlX/kh6rdGF0XrAG7g+Ths6iklh7wDefYP2JeGwHWJ38YcdF8T/VcSdOXz7EiWwEeZO5sGcTRSl5Ql8mcU3YyyB7BTdViYNTHf5VFFJ/baLZG+shZ/0tb1Ntx5mLDbV8vcYXJpUNTJcXbhcUDSF3QuSz04ftkzgpcsODzcTzD6+2sezV1vlOAlxK04C+zzxG96Md/TegvZYYns78RSgrP/UH1qwEbgxTo3xpErGllzntzZfHJ887Goez+DeB9ga7pUBc5AXGpfRhYqJP66wR10zqfWuWYvjAwRBRNySjr3pUvaA3T1iSZ5HLrpKBfcHXJOTg8M= name: komodo_linux-$TRAVIS_BRANCH prerelease: true file: komodo_linux.tar.gz @@ -58,7 +58,7 @@ deploy: condition: $LINUX_DEPLOY = "true" - provider: releases api_key: - secure: Jms7dz5GMZmuXUCHl5u6iZUtAybv86oW3x36DCJfdzbDiO4B9EWB04z7zA0qvoomefyujHTmQUHxyOKfd4h9/rVMFFv9hgmUxWkrcg7KyLNisOQRaovVOuNtu2lRNXTOSF16Cy+xFGkVh1ObBRhAoMsVKPhMl6PCDiKhNWIekRR9pBtjafKsClQ2ieknUYfqhuvgj7zmqCedeyVaVQyt2W/J65leD0BkfCUESTpANSprHs4bQB65VuQIKKMi+URKx2VgpDdUcWJySt9jAHVPIbI5cT5maAT6RUMnE4oha7Ca1Ox8StBqjQ/hkkMyDbN0keIlN7RjZlwdZQf/qUnT/dPQhsyUCdPXOxmEJ2jekezEK/LGr4Fb+v+vjd9dhLNkD5nVn9zp36biGSCjiMpffQ3fjMeM0YGmVEVRP9kZXLWVRYQoVKrzjyzg5dY8iChbiQEfYpTeBuU+e2rqj4mns+Jvy0zjUbMy6Tyva+iqdZ/PdsBDbiB7c+FIgB1IUTVOD+GgKx6dhCtBZEccn5EyWFwZF9IdQJHZCYV4PA7nuzfm1Ol9SDdZkGHd2OgRCqK/sTwyfTHv8exNqZ1k+epGJp2a0q4IOEknc9aPCAF+m9pHahk7s7VO5gmhO6pvbvuKoeEtEXRZHRzCkGkXfzJlBk+23X5gBexKb6inRdBlj6M= + secure: id69KBVsY0p41WFlqd5cGrAIksJAkUempmdrQwHtfqIbB6es7MVfXuxfmTxk7lZNEItSvLGilYtqhBMNVAVjRRPvk90hveGDMkbpjFz3XBbFEFqtrAr2GdIcpGtII2T3T/TG7j11TMtJ6GvBVt4OcatHFVsKBCFDIx0fB0fd1oLrEAwgRdBO2Jq7bMzoLdzGx3mVtdW5dSRBQzG/Z0yvx+R9mQHSvyPGh6oNPD6mvXPzEaCeRW6Y8g8y1SW/6zDJR6sSdOKA0jsHkr/hM8st3Qkr5Cu3roEbL8598uvfBahjxVHVT8+lu/nJnQyrvtWZKu/uUefybqgZl7UpGvZVFxbNwAB/ZNn0pBKIpZlX/kh6rdGF0XrAG7g+Ths6iklh7wDefYP2JeGwHWJ38YcdF8T/VcSdOXz7EiWwEeZO5sGcTRSl5Ql8mcU3YyyB7BTdViYNTHf5VFFJ/baLZG+shZ/0tb1Ntx5mLDbV8vcYXJpUNTJcXbhcUDSF3QuSz04ftkzgpcsODzcTzD6+2sezV1vlOAlxK04C+zzxG96Md/TegvZYYns78RSgrP/UH1qwEbgxTo3xpErGllzntzZfHJ887Goez+DeB9ga7pUBc5AXGpfRhYqJP66wR10zqfWuWYvjAwRBRNySjr3pUvaA3T1iSZ5HLrpKBfcHXJOTg8M= name: komodo_linux-$TRAVIS_BRANCH prerelease: true file: komodo_linux.tar.gz @@ -69,7 +69,7 @@ deploy: condition: $LINUX_DEPLOY = "true" - provider: releases api_key: - secure: Jms7dz5GMZmuXUCHl5u6iZUtAybv86oW3x36DCJfdzbDiO4B9EWB04z7zA0qvoomefyujHTmQUHxyOKfd4h9/rVMFFv9hgmUxWkrcg7KyLNisOQRaovVOuNtu2lRNXTOSF16Cy+xFGkVh1ObBRhAoMsVKPhMl6PCDiKhNWIekRR9pBtjafKsClQ2ieknUYfqhuvgj7zmqCedeyVaVQyt2W/J65leD0BkfCUESTpANSprHs4bQB65VuQIKKMi+URKx2VgpDdUcWJySt9jAHVPIbI5cT5maAT6RUMnE4oha7Ca1Ox8StBqjQ/hkkMyDbN0keIlN7RjZlwdZQf/qUnT/dPQhsyUCdPXOxmEJ2jekezEK/LGr4Fb+v+vjd9dhLNkD5nVn9zp36biGSCjiMpffQ3fjMeM0YGmVEVRP9kZXLWVRYQoVKrzjyzg5dY8iChbiQEfYpTeBuU+e2rqj4mns+Jvy0zjUbMy6Tyva+iqdZ/PdsBDbiB7c+FIgB1IUTVOD+GgKx6dhCtBZEccn5EyWFwZF9IdQJHZCYV4PA7nuzfm1Ol9SDdZkGHd2OgRCqK/sTwyfTHv8exNqZ1k+epGJp2a0q4IOEknc9aPCAF+m9pHahk7s7VO5gmhO6pvbvuKoeEtEXRZHRzCkGkXfzJlBk+23X5gBexKb6inRdBlj6M= + secure: id69KBVsY0p41WFlqd5cGrAIksJAkUempmdrQwHtfqIbB6es7MVfXuxfmTxk7lZNEItSvLGilYtqhBMNVAVjRRPvk90hveGDMkbpjFz3XBbFEFqtrAr2GdIcpGtII2T3T/TG7j11TMtJ6GvBVt4OcatHFVsKBCFDIx0fB0fd1oLrEAwgRdBO2Jq7bMzoLdzGx3mVtdW5dSRBQzG/Z0yvx+R9mQHSvyPGh6oNPD6mvXPzEaCeRW6Y8g8y1SW/6zDJR6sSdOKA0jsHkr/hM8st3Qkr5Cu3roEbL8598uvfBahjxVHVT8+lu/nJnQyrvtWZKu/uUefybqgZl7UpGvZVFxbNwAB/ZNn0pBKIpZlX/kh6rdGF0XrAG7g+Ths6iklh7wDefYP2JeGwHWJ38YcdF8T/VcSdOXz7EiWwEeZO5sGcTRSl5Ql8mcU3YyyB7BTdViYNTHf5VFFJ/baLZG+shZ/0tb1Ntx5mLDbV8vcYXJpUNTJcXbhcUDSF3QuSz04ftkzgpcsODzcTzD6+2sezV1vlOAlxK04C+zzxG96Md/TegvZYYns78RSgrP/UH1qwEbgxTo3xpErGllzntzZfHJ887Goez+DeB9ga7pUBc5AXGpfRhYqJP66wR10zqfWuWYvjAwRBRNySjr3pUvaA3T1iSZ5HLrpKBfcHXJOTg8M= name: komodo_osx-$TRAVIS_BRANCH prerelease: true file: komodo_osx.tar.gz @@ -80,7 +80,7 @@ deploy: condition: $OSX_DEPLOY = "true" - provider: releases api_key: - secure: Jms7dz5GMZmuXUCHl5u6iZUtAybv86oW3x36DCJfdzbDiO4B9EWB04z7zA0qvoomefyujHTmQUHxyOKfd4h9/rVMFFv9hgmUxWkrcg7KyLNisOQRaovVOuNtu2lRNXTOSF16Cy+xFGkVh1ObBRhAoMsVKPhMl6PCDiKhNWIekRR9pBtjafKsClQ2ieknUYfqhuvgj7zmqCedeyVaVQyt2W/J65leD0BkfCUESTpANSprHs4bQB65VuQIKKMi+URKx2VgpDdUcWJySt9jAHVPIbI5cT5maAT6RUMnE4oha7Ca1Ox8StBqjQ/hkkMyDbN0keIlN7RjZlwdZQf/qUnT/dPQhsyUCdPXOxmEJ2jekezEK/LGr4Fb+v+vjd9dhLNkD5nVn9zp36biGSCjiMpffQ3fjMeM0YGmVEVRP9kZXLWVRYQoVKrzjyzg5dY8iChbiQEfYpTeBuU+e2rqj4mns+Jvy0zjUbMy6Tyva+iqdZ/PdsBDbiB7c+FIgB1IUTVOD+GgKx6dhCtBZEccn5EyWFwZF9IdQJHZCYV4PA7nuzfm1Ol9SDdZkGHd2OgRCqK/sTwyfTHv8exNqZ1k+epGJp2a0q4IOEknc9aPCAF+m9pHahk7s7VO5gmhO6pvbvuKoeEtEXRZHRzCkGkXfzJlBk+23X5gBexKb6inRdBlj6M= + secure: id69KBVsY0p41WFlqd5cGrAIksJAkUempmdrQwHtfqIbB6es7MVfXuxfmTxk7lZNEItSvLGilYtqhBMNVAVjRRPvk90hveGDMkbpjFz3XBbFEFqtrAr2GdIcpGtII2T3T/TG7j11TMtJ6GvBVt4OcatHFVsKBCFDIx0fB0fd1oLrEAwgRdBO2Jq7bMzoLdzGx3mVtdW5dSRBQzG/Z0yvx+R9mQHSvyPGh6oNPD6mvXPzEaCeRW6Y8g8y1SW/6zDJR6sSdOKA0jsHkr/hM8st3Qkr5Cu3roEbL8598uvfBahjxVHVT8+lu/nJnQyrvtWZKu/uUefybqgZl7UpGvZVFxbNwAB/ZNn0pBKIpZlX/kh6rdGF0XrAG7g+Ths6iklh7wDefYP2JeGwHWJ38YcdF8T/VcSdOXz7EiWwEeZO5sGcTRSl5Ql8mcU3YyyB7BTdViYNTHf5VFFJ/baLZG+shZ/0tb1Ntx5mLDbV8vcYXJpUNTJcXbhcUDSF3QuSz04ftkzgpcsODzcTzD6+2sezV1vlOAlxK04C+zzxG96Md/TegvZYYns78RSgrP/UH1qwEbgxTo3xpErGllzntzZfHJ887Goez+DeB9ga7pUBc5AXGpfRhYqJP66wR10zqfWuWYvjAwRBRNySjr3pUvaA3T1iSZ5HLrpKBfcHXJOTg8M= name: komodo_osx-$TRAVIS_BRANCH prerelease: true file: komodo_osx.tar.gz From d3c2d1ac34c67459845d897ac6bc576310cb4075 Mon Sep 17 00:00:00 2001 From: ca333 Date: Fri, 10 Aug 2018 09:43:22 +0200 Subject: [PATCH 003/643] test --- .travis.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 93307b3a5..5490f0f08 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,10 +5,10 @@ matrix: - os: linux dist: xenial sudo: required - env: LINUX_DEPLOY="true" OSX_DEPLOY="false" + env: LINUX_DEPLOY="true" OSX_DEPLOY="false" $TRAVIS_OS_NAME="linux" - os: osx osx_image: xcode8 - env: OSX_DEPLOY="true" LINUX_DEPLOY="false" + env: OSX_DEPLOY="true" LINUX_DEPLOY="false" $TRAVIS_OS_NAME="osx" branches: only: - master @@ -27,10 +27,10 @@ before_install: - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew link --overwrite gcc@6; fi script: - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ./zcutil/build.sh -j 5; fi - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then tar cvfz komodo_linux.tar.gz src/komodod src/komodo-cli; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then tar cvfz komodo_linux_$TRAVIS_BRANCH.tar.gz src/komodod src/komodo-cli; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./zcutil/build-mac.sh -j 5; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./makeRelease.sh; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then tar cvfz komodo_osx.tar.gz src/komodod src/komodo-cli src/libgcc_s.1.dylib src/libgomp.1.dylib src/libstdc++.6.dylib; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then tar cvfz komodo_osx_$TRAVIS_BRANCH.tar.gz src/komodod src/komodo-cli src/libgcc_s.1.dylib src/libgomp.1.dylib src/libstdc++.6.dylib; fi notifications: irc: channels: @@ -50,7 +50,7 @@ deploy: secure: id69KBVsY0p41WFlqd5cGrAIksJAkUempmdrQwHtfqIbB6es7MVfXuxfmTxk7lZNEItSvLGilYtqhBMNVAVjRRPvk90hveGDMkbpjFz3XBbFEFqtrAr2GdIcpGtII2T3T/TG7j11TMtJ6GvBVt4OcatHFVsKBCFDIx0fB0fd1oLrEAwgRdBO2Jq7bMzoLdzGx3mVtdW5dSRBQzG/Z0yvx+R9mQHSvyPGh6oNPD6mvXPzEaCeRW6Y8g8y1SW/6zDJR6sSdOKA0jsHkr/hM8st3Qkr5Cu3roEbL8598uvfBahjxVHVT8+lu/nJnQyrvtWZKu/uUefybqgZl7UpGvZVFxbNwAB/ZNn0pBKIpZlX/kh6rdGF0XrAG7g+Ths6iklh7wDefYP2JeGwHWJ38YcdF8T/VcSdOXz7EiWwEeZO5sGcTRSl5Ql8mcU3YyyB7BTdViYNTHf5VFFJ/baLZG+shZ/0tb1Ntx5mLDbV8vcYXJpUNTJcXbhcUDSF3QuSz04ftkzgpcsODzcTzD6+2sezV1vlOAlxK04C+zzxG96Md/TegvZYYns78RSgrP/UH1qwEbgxTo3xpErGllzntzZfHJ887Goez+DeB9ga7pUBc5AXGpfRhYqJP66wR10zqfWuWYvjAwRBRNySjr3pUvaA3T1iSZ5HLrpKBfcHXJOTg8M= name: komodo_linux-$TRAVIS_BRANCH prerelease: true - file: komodo_linux.tar.gz + file: komodo_linux_$TRAVIS_BRANCH.tar.gz.tar.gz skip_cleanup: true on: repo: KomodoPlatform/komodo @@ -61,7 +61,7 @@ deploy: secure: id69KBVsY0p41WFlqd5cGrAIksJAkUempmdrQwHtfqIbB6es7MVfXuxfmTxk7lZNEItSvLGilYtqhBMNVAVjRRPvk90hveGDMkbpjFz3XBbFEFqtrAr2GdIcpGtII2T3T/TG7j11TMtJ6GvBVt4OcatHFVsKBCFDIx0fB0fd1oLrEAwgRdBO2Jq7bMzoLdzGx3mVtdW5dSRBQzG/Z0yvx+R9mQHSvyPGh6oNPD6mvXPzEaCeRW6Y8g8y1SW/6zDJR6sSdOKA0jsHkr/hM8st3Qkr5Cu3roEbL8598uvfBahjxVHVT8+lu/nJnQyrvtWZKu/uUefybqgZl7UpGvZVFxbNwAB/ZNn0pBKIpZlX/kh6rdGF0XrAG7g+Ths6iklh7wDefYP2JeGwHWJ38YcdF8T/VcSdOXz7EiWwEeZO5sGcTRSl5Ql8mcU3YyyB7BTdViYNTHf5VFFJ/baLZG+shZ/0tb1Ntx5mLDbV8vcYXJpUNTJcXbhcUDSF3QuSz04ftkzgpcsODzcTzD6+2sezV1vlOAlxK04C+zzxG96Md/TegvZYYns78RSgrP/UH1qwEbgxTo3xpErGllzntzZfHJ887Goez+DeB9ga7pUBc5AXGpfRhYqJP66wR10zqfWuWYvjAwRBRNySjr3pUvaA3T1iSZ5HLrpKBfcHXJOTg8M= name: komodo_linux-$TRAVIS_BRANCH prerelease: true - file: komodo_linux.tar.gz + file: komodo_linux_$TRAVIS_BRANCH.tar.gz.tar.gz skip_cleanup: true on: repo: KomodoPlatform/komodo @@ -72,7 +72,7 @@ deploy: secure: id69KBVsY0p41WFlqd5cGrAIksJAkUempmdrQwHtfqIbB6es7MVfXuxfmTxk7lZNEItSvLGilYtqhBMNVAVjRRPvk90hveGDMkbpjFz3XBbFEFqtrAr2GdIcpGtII2T3T/TG7j11TMtJ6GvBVt4OcatHFVsKBCFDIx0fB0fd1oLrEAwgRdBO2Jq7bMzoLdzGx3mVtdW5dSRBQzG/Z0yvx+R9mQHSvyPGh6oNPD6mvXPzEaCeRW6Y8g8y1SW/6zDJR6sSdOKA0jsHkr/hM8st3Qkr5Cu3roEbL8598uvfBahjxVHVT8+lu/nJnQyrvtWZKu/uUefybqgZl7UpGvZVFxbNwAB/ZNn0pBKIpZlX/kh6rdGF0XrAG7g+Ths6iklh7wDefYP2JeGwHWJ38YcdF8T/VcSdOXz7EiWwEeZO5sGcTRSl5Ql8mcU3YyyB7BTdViYNTHf5VFFJ/baLZG+shZ/0tb1Ntx5mLDbV8vcYXJpUNTJcXbhcUDSF3QuSz04ftkzgpcsODzcTzD6+2sezV1vlOAlxK04C+zzxG96Md/TegvZYYns78RSgrP/UH1qwEbgxTo3xpErGllzntzZfHJ887Goez+DeB9ga7pUBc5AXGpfRhYqJP66wR10zqfWuWYvjAwRBRNySjr3pUvaA3T1iSZ5HLrpKBfcHXJOTg8M= name: komodo_osx-$TRAVIS_BRANCH prerelease: true - file: komodo_osx.tar.gz + file: komodo_osx_$TRAVIS_BRANCH.tar.gz.tar.gz skip_cleanup: true on: repo: KomodoPlatform/komodo @@ -83,7 +83,7 @@ deploy: secure: id69KBVsY0p41WFlqd5cGrAIksJAkUempmdrQwHtfqIbB6es7MVfXuxfmTxk7lZNEItSvLGilYtqhBMNVAVjRRPvk90hveGDMkbpjFz3XBbFEFqtrAr2GdIcpGtII2T3T/TG7j11TMtJ6GvBVt4OcatHFVsKBCFDIx0fB0fd1oLrEAwgRdBO2Jq7bMzoLdzGx3mVtdW5dSRBQzG/Z0yvx+R9mQHSvyPGh6oNPD6mvXPzEaCeRW6Y8g8y1SW/6zDJR6sSdOKA0jsHkr/hM8st3Qkr5Cu3roEbL8598uvfBahjxVHVT8+lu/nJnQyrvtWZKu/uUefybqgZl7UpGvZVFxbNwAB/ZNn0pBKIpZlX/kh6rdGF0XrAG7g+Ths6iklh7wDefYP2JeGwHWJ38YcdF8T/VcSdOXz7EiWwEeZO5sGcTRSl5Ql8mcU3YyyB7BTdViYNTHf5VFFJ/baLZG+shZ/0tb1Ntx5mLDbV8vcYXJpUNTJcXbhcUDSF3QuSz04ftkzgpcsODzcTzD6+2sezV1vlOAlxK04C+zzxG96Md/TegvZYYns78RSgrP/UH1qwEbgxTo3xpErGllzntzZfHJ887Goez+DeB9ga7pUBc5AXGpfRhYqJP66wR10zqfWuWYvjAwRBRNySjr3pUvaA3T1iSZ5HLrpKBfcHXJOTg8M= name: komodo_osx-$TRAVIS_BRANCH prerelease: true - file: komodo_osx.tar.gz + file: komodo_osx_$TRAVIS_BRANCH.tar.gz.tar.gz skip_cleanup: true on: repo: KomodoPlatform/komodo From 49c6cb313a5ea94bb385aa89ca420b3bce607b9c Mon Sep 17 00:00:00 2001 From: ca333 Date: Fri, 10 Aug 2018 10:32:20 +0200 Subject: [PATCH 004/643] test --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5490f0f08..bfc8b8b4a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,7 +50,7 @@ deploy: secure: id69KBVsY0p41WFlqd5cGrAIksJAkUempmdrQwHtfqIbB6es7MVfXuxfmTxk7lZNEItSvLGilYtqhBMNVAVjRRPvk90hveGDMkbpjFz3XBbFEFqtrAr2GdIcpGtII2T3T/TG7j11TMtJ6GvBVt4OcatHFVsKBCFDIx0fB0fd1oLrEAwgRdBO2Jq7bMzoLdzGx3mVtdW5dSRBQzG/Z0yvx+R9mQHSvyPGh6oNPD6mvXPzEaCeRW6Y8g8y1SW/6zDJR6sSdOKA0jsHkr/hM8st3Qkr5Cu3roEbL8598uvfBahjxVHVT8+lu/nJnQyrvtWZKu/uUefybqgZl7UpGvZVFxbNwAB/ZNn0pBKIpZlX/kh6rdGF0XrAG7g+Ths6iklh7wDefYP2JeGwHWJ38YcdF8T/VcSdOXz7EiWwEeZO5sGcTRSl5Ql8mcU3YyyB7BTdViYNTHf5VFFJ/baLZG+shZ/0tb1Ntx5mLDbV8vcYXJpUNTJcXbhcUDSF3QuSz04ftkzgpcsODzcTzD6+2sezV1vlOAlxK04C+zzxG96Md/TegvZYYns78RSgrP/UH1qwEbgxTo3xpErGllzntzZfHJ887Goez+DeB9ga7pUBc5AXGpfRhYqJP66wR10zqfWuWYvjAwRBRNySjr3pUvaA3T1iSZ5HLrpKBfcHXJOTg8M= name: komodo_linux-$TRAVIS_BRANCH prerelease: true - file: komodo_linux_$TRAVIS_BRANCH.tar.gz.tar.gz + file: komodo_linux_$TRAVIS_BRANCH.tar.gz skip_cleanup: true on: repo: KomodoPlatform/komodo @@ -61,7 +61,7 @@ deploy: secure: id69KBVsY0p41WFlqd5cGrAIksJAkUempmdrQwHtfqIbB6es7MVfXuxfmTxk7lZNEItSvLGilYtqhBMNVAVjRRPvk90hveGDMkbpjFz3XBbFEFqtrAr2GdIcpGtII2T3T/TG7j11TMtJ6GvBVt4OcatHFVsKBCFDIx0fB0fd1oLrEAwgRdBO2Jq7bMzoLdzGx3mVtdW5dSRBQzG/Z0yvx+R9mQHSvyPGh6oNPD6mvXPzEaCeRW6Y8g8y1SW/6zDJR6sSdOKA0jsHkr/hM8st3Qkr5Cu3roEbL8598uvfBahjxVHVT8+lu/nJnQyrvtWZKu/uUefybqgZl7UpGvZVFxbNwAB/ZNn0pBKIpZlX/kh6rdGF0XrAG7g+Ths6iklh7wDefYP2JeGwHWJ38YcdF8T/VcSdOXz7EiWwEeZO5sGcTRSl5Ql8mcU3YyyB7BTdViYNTHf5VFFJ/baLZG+shZ/0tb1Ntx5mLDbV8vcYXJpUNTJcXbhcUDSF3QuSz04ftkzgpcsODzcTzD6+2sezV1vlOAlxK04C+zzxG96Md/TegvZYYns78RSgrP/UH1qwEbgxTo3xpErGllzntzZfHJ887Goez+DeB9ga7pUBc5AXGpfRhYqJP66wR10zqfWuWYvjAwRBRNySjr3pUvaA3T1iSZ5HLrpKBfcHXJOTg8M= name: komodo_linux-$TRAVIS_BRANCH prerelease: true - file: komodo_linux_$TRAVIS_BRANCH.tar.gz.tar.gz + file: komodo_linux_$TRAVIS_BRANCH.tar.gz skip_cleanup: true on: repo: KomodoPlatform/komodo @@ -72,7 +72,7 @@ deploy: secure: id69KBVsY0p41WFlqd5cGrAIksJAkUempmdrQwHtfqIbB6es7MVfXuxfmTxk7lZNEItSvLGilYtqhBMNVAVjRRPvk90hveGDMkbpjFz3XBbFEFqtrAr2GdIcpGtII2T3T/TG7j11TMtJ6GvBVt4OcatHFVsKBCFDIx0fB0fd1oLrEAwgRdBO2Jq7bMzoLdzGx3mVtdW5dSRBQzG/Z0yvx+R9mQHSvyPGh6oNPD6mvXPzEaCeRW6Y8g8y1SW/6zDJR6sSdOKA0jsHkr/hM8st3Qkr5Cu3roEbL8598uvfBahjxVHVT8+lu/nJnQyrvtWZKu/uUefybqgZl7UpGvZVFxbNwAB/ZNn0pBKIpZlX/kh6rdGF0XrAG7g+Ths6iklh7wDefYP2JeGwHWJ38YcdF8T/VcSdOXz7EiWwEeZO5sGcTRSl5Ql8mcU3YyyB7BTdViYNTHf5VFFJ/baLZG+shZ/0tb1Ntx5mLDbV8vcYXJpUNTJcXbhcUDSF3QuSz04ftkzgpcsODzcTzD6+2sezV1vlOAlxK04C+zzxG96Md/TegvZYYns78RSgrP/UH1qwEbgxTo3xpErGllzntzZfHJ887Goez+DeB9ga7pUBc5AXGpfRhYqJP66wR10zqfWuWYvjAwRBRNySjr3pUvaA3T1iSZ5HLrpKBfcHXJOTg8M= name: komodo_osx-$TRAVIS_BRANCH prerelease: true - file: komodo_osx_$TRAVIS_BRANCH.tar.gz.tar.gz + file: komodo_osx_$TRAVIS_BRANCH.tar.gz skip_cleanup: true on: repo: KomodoPlatform/komodo @@ -83,7 +83,7 @@ deploy: secure: id69KBVsY0p41WFlqd5cGrAIksJAkUempmdrQwHtfqIbB6es7MVfXuxfmTxk7lZNEItSvLGilYtqhBMNVAVjRRPvk90hveGDMkbpjFz3XBbFEFqtrAr2GdIcpGtII2T3T/TG7j11TMtJ6GvBVt4OcatHFVsKBCFDIx0fB0fd1oLrEAwgRdBO2Jq7bMzoLdzGx3mVtdW5dSRBQzG/Z0yvx+R9mQHSvyPGh6oNPD6mvXPzEaCeRW6Y8g8y1SW/6zDJR6sSdOKA0jsHkr/hM8st3Qkr5Cu3roEbL8598uvfBahjxVHVT8+lu/nJnQyrvtWZKu/uUefybqgZl7UpGvZVFxbNwAB/ZNn0pBKIpZlX/kh6rdGF0XrAG7g+Ths6iklh7wDefYP2JeGwHWJ38YcdF8T/VcSdOXz7EiWwEeZO5sGcTRSl5Ql8mcU3YyyB7BTdViYNTHf5VFFJ/baLZG+shZ/0tb1Ntx5mLDbV8vcYXJpUNTJcXbhcUDSF3QuSz04ftkzgpcsODzcTzD6+2sezV1vlOAlxK04C+zzxG96Md/TegvZYYns78RSgrP/UH1qwEbgxTo3xpErGllzntzZfHJ887Goez+DeB9ga7pUBc5AXGpfRhYqJP66wR10zqfWuWYvjAwRBRNySjr3pUvaA3T1iSZ5HLrpKBfcHXJOTg8M= name: komodo_osx-$TRAVIS_BRANCH prerelease: true - file: komodo_osx_$TRAVIS_BRANCH.tar.gz.tar.gz + file: komodo_osx_$TRAVIS_BRANCH.tar.gz skip_cleanup: true on: repo: KomodoPlatform/komodo From 71fc062672b1e6d1e419fc35652a89c6dfd2f1a1 Mon Sep 17 00:00:00 2001 From: SHossain Date: Mon, 1 Oct 2018 10:53:44 +0100 Subject: [PATCH 005/643] Update README.md --- README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e8ed8c3cb..92a7014f4 100644 --- a/README.md +++ b/README.md @@ -9,15 +9,16 @@ This is the official Komodo sourcecode repository based on https://github.com/jl ## Development Resources -- Komodo Website: [https://komodoplatform.com/](https://komodoplatform.com/) -- Komodo Blockexplorer: [https://kmdexplorer.io//](https://https://kmdexplorer.io/) -- Forum: [https://forum.komodoplatform.com/](https://forum.komodoplatform.com/) +- Komodo Website: [https://komodoplatform.com](https://komodoplatform.com/) +- Komodo Blockexplorer: [https://kmdexplorer.io](https://kmdexplorer.io/) +- Komodo Discord: [https://komodoplatform.com/discord](https://komodoplatform.com/discord) +- Forum: [https://forum.komodoplatform.com](https://forum.komodoplatform.com/) - Mail: [info@komodoplatform.com](mailto:info@komodoplatform.com) - Support: [https://support.komodoplatform.com/support/home](https://support.komodoplatform.com/support/home) -- Knowledgebase & How-to: [https://komodoplatform.atlassian.net/wiki/spaces/KPSD/pages](https://komodoplatform.atlassian.net/wiki/spaces/KPSD/pages) -- API references: [http://docs.komodoplatform.com/](http://docs.komodoplatform.com/) -- Blog: [http://blog.komodoplatform.com/](http://blog.komodoplatform.com/) -- Whitepaper: [Komodo Whitepaper](https://komodoplatform.com/wp-content/uploads/2018/03/2018-03-12-Komodo-White-Paper-Full.pdf) +- Knowledgebase & How-to: [https://support.komodoplatform.com/en/support/solutions](https://support.komodoplatform.com/en/support/solutions) +- API references & Dev Documentation: [https://docs.komodoplatform.com](https://docs.komodoplatform.com/) +- Blog: [https://blog.komodoplatform.com](https://blog.komodoplatform.com/) +- Whitepaper: [Komodo Whitepaper](https://komodoplatform.com/whitepaper) - Komodo Platform public material: [Komodo Platform public material](https://docs.google.com/document/d/1AbhWrtagu4vYdkl-vsWz-HSNyNvK-W-ZasHCqe7CZy0) ## List of Komodo Platform Technologies From 167047c7d975c17bf8913aae0572d3913e7ce7e3 Mon Sep 17 00:00:00 2001 From: Asher Dawes Date: Thu, 18 Oct 2018 01:09:03 -0700 Subject: [PATCH 006/643] Introducing gitlab-ci configuration for komodo builds. Modifying makeRelease.sh to add additional dynamic libraries to the mac artifact package to support MacOS Sierra systems. --- .gitlab-ci.yml | 162 +++++++++++++++++++++++++++++++++++++++++++++++++ makeRelease.sh | 65 +++++++++++++++++--- 2 files changed, 218 insertions(+), 9 deletions(-) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 000000000..6f867ad6b --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,162 @@ +stages: +- build +- test +######################################################################################################################## +####START#### PROJECT LEVEL VARIABLES ####START#### +######################################################################################################################## +variables: + 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 the Agama Wallet. ####START##### +######################################################################################################################## +######################################################################################################################## +####START#### LINUX ####START#### +######################################################################################################################## +build:ubuntu: + stage: build + image: asherd/komodo-builders:komodo-ubuntu + variables: + DOCKER_DRIVER: overlay2 + cache: + key: "${CI_JOB_NAME}${CI_COMMIT_REF_NAME}" + paths: + - depends/built + script: + - zcutil/build.sh -j$(nproc) + - mkdir ${PACKAGE_DIR_LINUX} + - cp src/komodod + 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: + - ${AGAMA_ARTIFACTS_LINUX} + - ${AGAMA_ARTIFACTS_LINUX_CHECKSUM} + expire_in: ${ARTIFACT_EXPIRATION} +######################################################################################################################## +####END#### LINUX ####END#### +######################################################################################################################## +####START#### WINDOWS ####START#### +######################################################################################################################## +build:windows: + stage: build + image: asherd/komodo-builders:komodo-windows + variables: + DOCKER_DRIVER: overlay2 + cache: + key: "${CI_JOB_NAME}${CI_COMMIT_REF_NAME}" + paths: + - depends/built + script: + - zcutil/build-win.sh -j$(nproc) + - mkdir ${PACKAGE_DIR_WINDOWS}. + - cp src/komodod.exe + src/komodo-cli.exe + src/komodo-tx.exe + ${PACKAGE_DIR_WINDOWS} + - zip -r ${PACKAGE_DIR_WINDOWS} + - md5sum ${AGAMA_ARTIFACTS_WINDOWS} > ${AGAMA_ARTIFACTS_WINDOWS_CHECKSUM} + artifacts: + paths: + - ${AGAMA_ARTIFACTS_WINDOWS} + - ${AGAMA_ARTIFACTS_WINDOWS_CHECKSUM} + expire_in: ${ARTIFACT_EXPIRATION} +######################################################################################################################## +####END#### WINDOWS ####END#### +######################################################################################################################## +####START#### MACOS ####START#### +######################################################################################################################## +build:macos: + stage: build + tags: ["High Sierra"] + cache: + key: "${CI_JOB_NAME}${CI_COMMIT_REF_NAME}" + paths: + - depends/built + script: + - zcutil/build-mac.sh -j$(sysctl -n hw.physicalcpu) + - ./makeRelease.sh ${PACKAGE_DIR_MACOS} + - tar -czvf ${AGAMA_ARTIFACTS_MACOS} ${PACKAGE_DIR_MACOS} + - md5sum ${AGAMA_ARTIFACTS_MACOS} > ${AGAMA_ARTIFACTS_MACOS_CHECKSUM} + artifacts: + paths: + - ${AGAMA_ARTIFACTS_MACOS} + - ${AGAMA_ARTIFACTS_MACOS_CHECKSUM} + expire_in: ${ARTIFACT_EXPIRATION} +######################################################################################################################## +####END#### MACOS ####END#### +######################################################################################################################## +######################################################################################################################## +####END#### Build Stage ####END#### +######################################################################################################################## +######################################################################################################################## +######################################################################################################################## +######################################################################################################################## +####START#### Test stage: Produce code quality and static application security test reports. ####START#### +######################################################################################################################## +######################################################################################################################## +######################################################################################################################## +####START#### Code Quality ####START#### +######################################################################################################################## +code_quality: + image: docker:stable + variables: + DOCKER_DRIVER: overlay2 + allow_failure: true + services: + - docker:stable-dind + script: + - export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/') + - docker run + --env SOURCE_CODE="$PWD" + --volume "$PWD":/code + --volume /var/run/docker.sock:/var/run/docker.sock + "registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code + artifacts: + paths: [gl-code-quality-report.json] +######################################################################################################################## +####END#### Code Quality ####END#### +######################################################################################################################## +######################################################################################################################## +####START#### Static Application Security Tests ####START#### +######################################################################################################################## +sast: + image: docker:stable + variables: + DOCKER_DRIVER: overlay2 + allow_failure: true + services: + - docker:stable-dind + script: + - export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/') + - docker run + --env SAST_CONFIDENCE_LEVEL="${SAST_CONFIDENCE_LEVEL:-3}" + --volume "$PWD:/code" + --volume /var/run/docker.sock:/var/run/docker.sock + "registry.gitlab.com/gitlab-org/security-products/sast:$SP_VERSION" /app/bin/run /code + artifacts: + paths: [gl-sast-report.json] +######################################################################################################################## +####END#### Static Application Security Tests ####END#### +######################################################################################################################## +######################################################################################################################## +######################################################################################################################## +####END#### Test stage ####END#### +######################################################################################################################## +######################################################################################################################## \ No newline at end of file diff --git a/makeRelease.sh b/makeRelease.sh index 5d68f0b03..e20df75aa 100755 --- a/makeRelease.sh +++ b/makeRelease.sh @@ -1,17 +1,64 @@ #!/bin/sh +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} ${PACKAGE_DIR} + # find the dylibs to copy for komodod + 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} ${PACKAGE_DIR}; done +done + +libraries=("libgcc_s.1.dylib" "libgomp.1.dylib" "libidn2.0.dylib" "libstdc++.6.dylib") + +for binary in "${libraries[@]}"; +do + # find the dylibs to copy for komodod + 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} ${PACKAGE_DIR}; alllibs+=(${dylib}); done +done + +indirectlibraries=("libintl.8.dylib" "libunistring.2.dylib") + +for binary in "${indirectlibraries[@]}"; +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 ${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} ${PACKAGE_DIR}; alllibs+=(${dylib}); done +done for binary in "${binaries[@]}"; do - # find the dylibs to copy for komodod - DYLIBS=`otool -L src/$binary | grep "/usr/local" | awk -F' ' '{ print $1 }'` - echo "copying $DYLIBS to $src" - # copy the dylibs to the srcdir - for dylib in $DYLIBS; do cp -rf $dylib src/; done - # modify komodod to point to dylibs - echo "modifying $binary to use local libraries" - for dylib in $DYLIBS; do install_name_tool -change $dylib @executable_path/`basename $dylib` src/$binary; done; - chmod +x src/$binary + echo "modifying ${binary} to use local libraries" + for dylib in "${alllibs[@]}" + do + echo "Next lib is ${dylib} " + install_name_tool -change ${dylib} @executable_path/`basename ${dylib}` ${PACKAGE_DIR}/${binary} + done + chmod +x ${PACKAGE_DIR}/${binary} +done + +for binary in "${libraries[@]}"; +do + # modify libraries to point to dylibs + echo "modifying ${binary} to use local libraries" + for dylib in "${alllibs[@]}" + do + echo "Next lib is ${dylib} " + install_name_tool -change ${dylib} @executable_path/`basename ${dylib}` ${PACKAGE_DIR}/${binary} + done done From 73e64aa79c9c1b9d2c8b53a7e1505f1216a2bff3 Mon Sep 17 00:00:00 2001 From: ca333 Date: Sun, 25 Nov 2018 17:00:01 +0100 Subject: [PATCH 007/643] update gitlab CI conf --- .gitlab-ci.yml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6f867ad6b..3ace05cb9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -15,6 +15,7 @@ variables: 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#### ######################################################################################################################## @@ -27,7 +28,7 @@ variables: ######################################################################################################################## build:ubuntu: stage: build - image: asherd/komodo-builders:komodo-ubuntu + image: ca333/komodo-builders:komodo-ubuntu variables: DOCKER_DRIVER: overlay2 cache: @@ -48,7 +49,8 @@ build:ubuntu: paths: - ${AGAMA_ARTIFACTS_LINUX} - ${AGAMA_ARTIFACTS_LINUX_CHECKSUM} - expire_in: ${ARTIFACT_EXPIRATION} + expire_in: 1 week + ######################################################################################################################## ####END#### LINUX ####END#### ######################################################################################################################## @@ -56,7 +58,7 @@ build:ubuntu: ######################################################################################################################## build:windows: stage: build - image: asherd/komodo-builders:komodo-windows + image: ca333/komodo-builders:komodo-windows variables: DOCKER_DRIVER: overlay2 cache: @@ -65,18 +67,18 @@ build:windows: - depends/built script: - zcutil/build-win.sh -j$(nproc) - - mkdir ${PACKAGE_DIR_WINDOWS}. + - mkdir ${PACKAGE_DIR_WINDOWS} - cp src/komodod.exe src/komodo-cli.exe src/komodo-tx.exe ${PACKAGE_DIR_WINDOWS} - - zip -r ${PACKAGE_DIR_WINDOWS} + - zip -r ${PACKAGE_DIR_WINDOWS}.zip ${PACKAGE_DIR_WINDOWS} - md5sum ${AGAMA_ARTIFACTS_WINDOWS} > ${AGAMA_ARTIFACTS_WINDOWS_CHECKSUM} artifacts: paths: - ${AGAMA_ARTIFACTS_WINDOWS} - ${AGAMA_ARTIFACTS_WINDOWS_CHECKSUM} - expire_in: ${ARTIFACT_EXPIRATION} + expire_in: 1 week ######################################################################################################################## ####END#### WINDOWS ####END#### ######################################################################################################################## @@ -98,7 +100,7 @@ build:macos: paths: - ${AGAMA_ARTIFACTS_MACOS} - ${AGAMA_ARTIFACTS_MACOS_CHECKSUM} - expire_in: ${ARTIFACT_EXPIRATION} + expire_in: 1 week ######################################################################################################################## ####END#### MACOS ####END#### ######################################################################################################################## @@ -159,4 +161,4 @@ sast: ######################################################################################################################## ####END#### Test stage ####END#### ######################################################################################################################## -######################################################################################################################## \ No newline at end of file +######################################################################################################################## From 8a8fb052bde226f05007dbb9ab5fc109577c5175 Mon Sep 17 00:00:00 2001 From: ca333 Date: Sun, 25 Nov 2018 17:04:54 +0100 Subject: [PATCH 008/643] rename makeRelease.sh --- makeRelease.sh => makeReleaseMac.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename makeRelease.sh => makeReleaseMac.sh (100%) diff --git a/makeRelease.sh b/makeReleaseMac.sh similarity index 100% rename from makeRelease.sh rename to makeReleaseMac.sh From 2d725d91fc4855fa19813b49ad22fd89d66dd378 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 17 Dec 2018 00:18:15 +0800 Subject: [PATCH 009/643] Fix setgenerate and genproclimit --- src/init.cpp | 6 +-- src/komodo_utils.h | 11 +++-- src/miner.cpp | 117 +++++++++++++++++++++++---------------------- src/rpc/mining.cpp | 5 +- 4 files changed, 75 insertions(+), 64 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index a87eb6170..1fcd87be7 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1501,7 +1501,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) fReindex = true; } } - + bool clearWitnessCaches = false; bool fLoaded = false; @@ -1874,9 +1874,9 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) VERUS_MINTBLOCKS = GetBoolArg("-mint", false); if (pwalletMain || !GetArg("-mineraddress", "").empty()) - GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", 0)); + GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", -1)); #else - GenerateBitcoins(GetBoolArg("-gen", false), GetArg("-genproclimit", 0)); + GenerateBitcoins(GetBoolArg("-gen", false), GetArg("-genproclimit", -1)); #endif #endif diff --git a/src/komodo_utils.h b/src/komodo_utils.h index e6600fa65..73be6c02c 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1657,11 +1657,9 @@ void komodo_args(char *argv0) std::string name,addn; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[8192],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,baseid,len,n,extralen = 0; IS_KOMODO_NOTARY = GetBoolArg("-notary", false); - if ( GetBoolArg("-gen", false) != 0 )\ + if ( GetBoolArg("-gen", false) != 0 ) { KOMODO_MININGTHREADS = GetArg("-genproclimit",-1); - if (KOMODO_MININGTHREADS == 0) - mapArgs["-gen"] = "0"; } else KOMODO_MININGTHREADS = 0; @@ -1679,6 +1677,8 @@ void komodo_args(char *argv0) if ( strcmp(NOTARY_PUBKEY.c_str(),Notaries_elected1[i][1]) == 0 ) { IS_KOMODO_NOTARY = 1; + KOMODO_MININGTHREADS = 1; + mapArgs ["-genproclimit"] = itostr(KOMODO_MININGTHREADS); fprintf(stderr,"running as notary.%d %s\n",i,Notaries_elected1[i][0]); break; } @@ -1781,8 +1781,11 @@ void komodo_args(char *argv0) // for now, we only support 50% PoS due to other parts of the algorithm needing adjustment for // other values if ( (ASSETCHAINS_LWMAPOS = GetArg("-ac_veruspos",0)) != 0 ) + { ASSETCHAINS_LWMAPOS = 50; - + if ( GetBoolArg("-gen", false) != 0 ) + VERUS_MINTBLOCKS = true; + } ASSETCHAINS_SAPLING = GetArg("-ac_sapling", -1); if (ASSETCHAINS_SAPLING == -1) { diff --git a/src/miner.cpp b/src/miner.cpp index e94ed0b03..01ee92234 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -68,7 +68,7 @@ public: set setDependsOn; CFeeRate feeRate; double dPriority; - + COrphan(const CTransaction* ptxIn) : ptx(ptxIn), feeRate(0), dPriority(0) { } @@ -82,10 +82,10 @@ typedef boost::tuple TxPriority; class TxPriorityCompare { bool byFee; - + public: TxPriorityCompare(bool _byFee) : byFee(_byFee) { } - + bool operator()(const TxPriority& a, const TxPriority& b) { if (byFee) @@ -170,27 +170,27 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, // -blockversion=N to test forking scenarios if (Params().MineBlocksOnDemand()) pblock->nVersion = GetArg("-blockversion", pblock->nVersion); - + // Add dummy coinbase tx as first transaction pblock->vtx.push_back(CTransaction()); pblocktemplate->vTxFees.push_back(-1); // updated at end pblocktemplate->vTxSigOps.push_back(-1); // updated at end - + // Largest block you're willing to create: unsigned int nBlockMaxSize = GetArg("-blockmaxsize", MAX_BLOCK_SIZE(chainActive.LastTip()->GetHeight()+1)); // Limit to betweeen 1K and MAX_BLOCK_SIZE-1K for sanity: nBlockMaxSize = std::max((unsigned int)1000, std::min((unsigned int)(MAX_BLOCK_SIZE(chainActive.LastTip()->GetHeight()+1)-1000), nBlockMaxSize)); - + // How much of the block should be dedicated to high-priority transactions, // included regardless of the fees they pay unsigned int nBlockPrioritySize = GetArg("-blockprioritysize", DEFAULT_BLOCK_PRIORITY_SIZE); nBlockPrioritySize = std::min(nBlockMaxSize, nBlockPrioritySize); - + // Minimum block size you want to create; block will be filled with free transactions // until there are no more or the block reaches this size: unsigned int nBlockMinSize = GetArg("-blockminsize", DEFAULT_BLOCK_MIN_SIZE); nBlockMinSize = std::min(nBlockMaxSize, nBlockMinSize); - + // Collect memory pool transactions into the block CAmount nFees = 0; @@ -225,7 +225,7 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, CCoinsViewCache view(pcoinsTip); uint32_t expired; uint64_t commission; - + SaplingMerkleTree sapling_tree; assert(view.GetSaplingAnchorAt(view.GetBestAnchor(SAPLING), sapling_tree)); @@ -233,7 +233,7 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, list vOrphan; // list memory doesn't move map > mapDependers; bool fPrintPriority = GetBoolArg("-printpriority", false); - + // This vector will be sorted into a priority queue: vector vecPriority; vecPriority.reserve(mempool.mapTx.size() + 1); @@ -243,7 +243,7 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, mi != mempool.mapTx.end(); ++mi) { const CTransaction& tx = mi->GetTx(); - + int64_t nLockTimeCutoff = (STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST) ? nMedianTimePast : pblock->GetBlockTime(); @@ -314,16 +314,16 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, } if (fMissingInputs) continue; - + // Priority is sum(valuein * age) / modified_txsize unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); dPriority = tx.ComputePriority(dPriority, nTxSize); - + uint256 hash = tx.GetHash(); mempool.ApplyDeltas(hash, dPriority, nTotalIn); - + CFeeRate feeRate(nTotalIn-tx.GetValueOut(), nTxSize); - + if (porphan) { porphan->dPriority = dPriority; @@ -339,20 +339,20 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, int64_t interest; int nBlockSigOps = 100; bool fSortedByFee = (nBlockPrioritySize <= 0); - + TxPriorityCompare comparer(fSortedByFee); std::make_heap(vecPriority.begin(), vecPriority.end(), comparer); - + while (!vecPriority.empty()) { // Take highest priority transaction off the priority queue: double dPriority = vecPriority.front().get<0>(); CFeeRate feeRate = vecPriority.front().get<1>(); const CTransaction& tx = *(vecPriority.front().get<2>()); - + std::pop_heap(vecPriority.begin(), vecPriority.end(), comparer); vecPriority.pop_back(); - + // Size limits unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); if (nBlockSize + nTxSize >= nBlockMaxSize-512) // room for extra autotx @@ -360,7 +360,7 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, //fprintf(stderr,"nBlockSize %d + %d nTxSize >= %d nBlockMaxSize\n",(int32_t)nBlockSize,(int32_t)nTxSize,(int32_t)nBlockMaxSize); continue; } - + // Legacy limits on sigOps: unsigned int nTxSigOps = GetLegacySigOpCount(tx); if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1) @@ -387,14 +387,14 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, comparer = TxPriorityCompare(fSortedByFee); std::make_heap(vecPriority.begin(), vecPriority.end(), comparer); } - + if (!view.HaveInputs(tx)) { //fprintf(stderr,"dont have inputs\n"); continue; } CAmount nTxFees = view.GetValueIn(chainActive.LastTip()->GetHeight(),&interest,tx,chainActive.LastTip()->nTime)-tx.GetValueOut(); - + nTxSigOps += GetP2SHSigOpCount(tx, view); if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1) { @@ -425,12 +425,12 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, ++nBlockTx; nBlockSigOps += nTxSigOps; nFees += nTxFees; - + if (fPrintPriority) { LogPrintf("priority %.1f fee %s txid %s\n",dPriority, feeRate.ToString(), tx.GetHash().ToString()); } - + // Add transactions that depend on this one to the priority queue if (mapDependers.count(hash)) { @@ -448,7 +448,7 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, } } } - + nLastBlockTx = nBlockTx; nLastBlockSize = nBlockSize; blocktime = 1 + std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); @@ -497,7 +497,7 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, //printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.LastTip()->GetHeight()+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13))); } else return(0); //fprintf(stderr,"no utxos eligible for staking\n"); } - + // Create coinbase tx CMutableTransaction txNew = CreateNewContextualCMutableTransaction(consensusParams, nHeight); txNew.vin.resize(1); @@ -531,7 +531,7 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, fprintf(stderr,"CreateNewBlock: attempt to add timelock to pay2sh or pay2cc\n"); return 0; } - + opretScript += scriptPubKeyIn; txNew.vout[0].scriptPubKey = CScriptExt().PayToScriptHash(CScriptID(opretScript)); @@ -578,7 +578,7 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, nonce >>= 16; pblock->nNonce = ArithToUint256(nonce); } - + // Fill in header pblock->hashPrevBlock = pindexPrev->GetBlockHash(); pblock->hashFinalSaplingRoot = sapling_tree.root(); @@ -638,7 +638,7 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, //fprintf(stderr,"done new block\n"); return pblocktemplate.release(); } - + /* #ifdef ENABLE_WALLET boost::optional GetMinerScriptPubKey(CReserveKey& reservekey) @@ -661,11 +661,11 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, return boost::optional(); #endif } - + CScript scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG; return scriptPubKey; } - + #ifdef ENABLE_WALLET CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey) { @@ -675,7 +675,7 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, { boost::optional scriptPubKey = GetMinerScriptPubKey(); #endif - + if (!scriptPubKey) { return NULL; } @@ -703,7 +703,7 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& CMutableTransaction txCoinbase(pblock->vtx[0]); txCoinbase.vin[0].scriptSig = (CScript() << nHeight << CScriptNum(nExtraNonce)) + COINBASE_FLAGS; assert(txCoinbase.vin[0].scriptSig.size() <= 100); - + pblock->vtx[0] = txCoinbase; pblock->hashMerkleRoot = pblock->BuildMerkleTree(); } @@ -783,7 +783,7 @@ static bool ProcessBlockFound(CBlock* pblock) { LogPrintf("%s\n", pblock->ToString()); LogPrintf("generated %s height.%d\n", FormatMoney(pblock->vtx[0].vout[0].nValue),chainActive.LastTip()->GetHeight()+1); - + // Found a solution { if (pblock->hashPrevBlock != chainActive.LastTip()->GetBlockHash()) @@ -797,11 +797,11 @@ static bool ProcessBlockFound(CBlock* pblock) for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); fprintf(stderr," <- chainTip (stale)\n"); - + return error("KomodoMiner: generated block is stale"); } } - + #ifdef ENABLE_WALLET // Remove key from key pool if ( IS_KOMODO_NOTARY == 0 ) @@ -825,7 +825,7 @@ static bool ProcessBlockFound(CBlock* pblock) CValidationState state; if (!ProcessNewBlock(1,chainActive.LastTip()->GetHeight()+1,state, NULL, pblock, true, NULL)) return error("KomodoMiner: ProcessNewBlock, block not accepted"); - + TrackMinedBlock(pblock->GetHash()); komodo_broadcast(pblock,16); return true; @@ -853,7 +853,7 @@ int32_t waitForPeers(const CChainParams &chainparams) if (fvNodesEmpty || IsNotInSync()) { int loops = 0, blockDiff = 0, newDiff = 0; - + do { if (fvNodesEmpty) { @@ -1036,7 +1036,7 @@ void static VerusStaker(CWallet *pwallet) post.SetCompact(pblock->GetVerusPOSTarget()); pindexPrev = get_chainactive(Mining_height - 100); CTransaction &sTx = pblock->vtx[pblock->vtx.size()-1]; - printf("POS hash: %s \ntarget: %s\n", + printf("POS hash: %s \ntarget: %s\n", CTransaction::_GetVerusPOSHash(&(pblock->nNonce), sTx.vin[0].prevout.hash, sTx.vin[0].prevout.n, Mining_height, pindexPrev->GetBlockHeader().GetVerusEntropyHash(Mining_height - 100), sTx.vout[0].nValue).GetHex().c_str(), ArithToUint256(post).GetHex().c_str()); if (unlockTime > Mining_height && subsidy >= ASSETCHAINS_TIMELOCKGTE) printf("- timelocked until block %i\n", unlockTime); @@ -1356,15 +1356,15 @@ void static BitcoinMiner() SetThreadPriority(THREAD_PRIORITY_LOWEST); RenameThread("komodo-miner"); const CChainParams& chainparams = Params(); - + #ifdef ENABLE_WALLET // Each thread has its own key CReserveKey reservekey(pwallet); #endif - + // Each thread has its own counter unsigned int nExtraNonce = 0; - + unsigned int n = chainparams.EquihashN(); unsigned int k = chainparams.EquihashK(); uint8_t *script; uint64_t total; int32_t i,j,gpucount=KOMODO_MAXGPUCOUNT,notaryid = -1; @@ -1395,7 +1395,7 @@ void static BitcoinMiner() } ); miningTimer.start(); - + try { if ( ASSETCHAINS_SYMBOL[0] != 0 ) fprintf(stderr,"try %s Mining with %s\n",ASSETCHAINS_SYMBOL,solver.c_str()); @@ -1418,7 +1418,7 @@ void static BitcoinMiner() break; MilliSleep(15000); //fprintf(stderr,"fvNodesEmpty %d IsInitialBlockDownload(%s) %d\n",(int32_t)fvNodesEmpty,ASSETCHAINS_SYMBOL,(int32_t)IsInitialBlockDownload()); - + } while (true); //fprintf(stderr,"%s Found peers\n",ASSETCHAINS_SYMBOL); miningTimer.start(); @@ -1567,7 +1567,7 @@ void static BitcoinMiner() komodo_longestchain(); // Hash state KOMODO_CHOSEN_ONE = 0; - + crypto_generichash_blake2b_state state; EhInitialiseState(n, k, state); // I = the block header minus nonce and solution. @@ -1687,13 +1687,13 @@ void static BitcoinMiner() std::lock_guard lock{m_cs}; return cancelSolver; }; - + // TODO: factor this out into a function with the same API for each solver. if (solver == "tromp" ) { //&& notaryid >= 0 ) { // Create solver and initialize it. equi eq(1); eq.setstate(&curr_state); - + // Initialization done, start algo driver. eq.digit0(0); eq.xfull = eq.bfull = eq.hfull = 0; @@ -1705,7 +1705,7 @@ void static BitcoinMiner() } eq.digitK(0); ehSolverRuns.increment(); - + // Convert solution indices to byte array (decompress) and pass it to validBlock method. for (size_t s = 0; s < eq.nsols; s++) { LogPrint("pow", "Checking solution %d\n", s+1); @@ -1714,7 +1714,7 @@ void static BitcoinMiner() index_vector[i] = eq.sols[s][i]; } std::vector sol_char = GetMinimalFromIndices(index_vector, DIGITBITS); - + if (validBlock(sol_char)) { // If we find a POW solution, do not try other solutions // because they become invalid as we created a new block in blockchain. @@ -1741,7 +1741,7 @@ void static BitcoinMiner() cancelSolver = false; } } - + // Check for stop or if block needs to be rebuilt boost::this_thread::interruption_point(); // Regtest mode doesn't require peers @@ -1811,7 +1811,7 @@ void static BitcoinMiner() miningTimer.stop(); c.disconnect(); } - + #ifdef ENABLE_WALLET void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads) #else @@ -1819,10 +1819,10 @@ void static BitcoinMiner() #endif { static boost::thread_group* minerThreads = NULL; - + if (nThreads < 0) nThreads = GetNumCores(); - + if (minerThreads != NULL) { minerThreads->interrupt_all(); @@ -1831,8 +1831,13 @@ void static BitcoinMiner() } //fprintf(stderr,"nThreads.%d fGenerate.%d\n",(int32_t)nThreads,fGenerate); - if ( nThreads == 0 && ASSETCHAINS_STAKED ) - nThreads = 1; + if ( ASSETCHAINS_STAKED > 0 && nThreads == 0 ) + { + if ( pwallet != NULL ) + nThreads = 1; + else + return; + } if ((nThreads == 0 || !fGenerate) && (VERUS_MINTBLOCKS == 0 || pwallet == NULL)) return; @@ -1861,5 +1866,5 @@ void static BitcoinMiner() #endif } } - + #endif // ENABLE_MINING diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 25b75c301..5ed1de14c 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -344,7 +344,10 @@ UniValue setgenerate(const UniValue& params, bool fHelp) { VERUS_MINTBLOCKS = 1; fGenerate = GetBoolArg("-gen", false); - nGenProcLimit = KOMODO_MININGTHREADS; + if ( ASSETCHAINS_STAKED == 0 ) + nGenProcLimit = KOMODO_MININGTHREADS; + else + KOMODO_MININGTHREADS = nGenProcLimit; } else if (!fGenerate) { From 92c9ee71c17f3e5d595bd280c888f4041294c821 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 17 Dec 2018 00:22:14 +0800 Subject: [PATCH 010/643] fix --- src/komodo_utils.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 73be6c02c..1f0ea1ca1 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1676,11 +1676,11 @@ void komodo_args(char *argv0) for (i=0; i<64; i++) if ( strcmp(NOTARY_PUBKEY.c_str(),Notaries_elected1[i][1]) == 0 ) { - IS_KOMODO_NOTARY = 1; + IS_KOMODO_NOTARY = 1; KOMODO_MININGTHREADS = 1; mapArgs ["-genproclimit"] = itostr(KOMODO_MININGTHREADS); - fprintf(stderr,"running as notary.%d %s\n",i,Notaries_elected1[i][0]); - break; + fprintf(stderr,"running as notary.%d %s\n",i,Notaries_elected1[i][0]); + break; } } //KOMODO_PAX = 1; @@ -1784,7 +1784,7 @@ void komodo_args(char *argv0) { ASSETCHAINS_LWMAPOS = 50; if ( GetBoolArg("-gen", false) != 0 ) - VERUS_MINTBLOCKS = true; + VERUS_MINTBLOCKS = true; } ASSETCHAINS_SAPLING = GetArg("-ac_sapling", -1); if (ASSETCHAINS_SAPLING == -1) From c17728c00c4ca7057aec14120246df4dddb67307 Mon Sep 17 00:00:00 2001 From: blackjok3rtt <30971146+blackjok3rtt@users.noreply.github.com> Date: Mon, 17 Dec 2018 00:26:10 +0800 Subject: [PATCH 011/643] fix format --- src/komodo_utils.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 1f0ea1ca1..309dae3b4 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1676,11 +1676,11 @@ void komodo_args(char *argv0) for (i=0; i<64; i++) if ( strcmp(NOTARY_PUBKEY.c_str(),Notaries_elected1[i][1]) == 0 ) { - IS_KOMODO_NOTARY = 1; - KOMODO_MININGTHREADS = 1; - mapArgs ["-genproclimit"] = itostr(KOMODO_MININGTHREADS); - fprintf(stderr,"running as notary.%d %s\n",i,Notaries_elected1[i][0]); - break; + IS_KOMODO_NOTARY = 1; + KOMODO_MININGTHREADS = 1; + mapArgs ["-genproclimit"] = itostr(KOMODO_MININGTHREADS); + fprintf(stderr,"running as notary.%d %s\n",i,Notaries_elected1[i][0]); + break; } } //KOMODO_PAX = 1; @@ -1781,11 +1781,11 @@ void komodo_args(char *argv0) // for now, we only support 50% PoS due to other parts of the algorithm needing adjustment for // other values if ( (ASSETCHAINS_LWMAPOS = GetArg("-ac_veruspos",0)) != 0 ) - { + { ASSETCHAINS_LWMAPOS = 50; - if ( GetBoolArg("-gen", false) != 0 ) - VERUS_MINTBLOCKS = true; - } + if ( GetBoolArg("-gen", false) != 0 ) + VERUS_MINTBLOCKS = true; + } ASSETCHAINS_SAPLING = GetArg("-ac_sapling", -1); if (ASSETCHAINS_SAPLING == -1) { From f9260ac43ff2e788d2359052f70e5ae30547e2e8 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 17 Dec 2018 00:57:23 +0800 Subject: [PATCH 012/643] fix --- src/komodo_utils.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 309dae3b4..335d9a8cf 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1676,11 +1676,11 @@ void komodo_args(char *argv0) for (i=0; i<64; i++) if ( strcmp(NOTARY_PUBKEY.c_str(),Notaries_elected1[i][1]) == 0 ) { - IS_KOMODO_NOTARY = 1; - KOMODO_MININGTHREADS = 1; - mapArgs ["-genproclimit"] = itostr(KOMODO_MININGTHREADS); - fprintf(stderr,"running as notary.%d %s\n",i,Notaries_elected1[i][0]); - break; + IS_KOMODO_NOTARY = 1; + KOMODO_MININGTHREADS = 1; + mapArgs ["-genproclimit"] = itostr(KOMODO_MININGTHREADS); + fprintf(stderr,"running as notary.%d %s\n",i,Notaries_elected1[i][0]); + break; } } //KOMODO_PAX = 1; @@ -1781,11 +1781,9 @@ void komodo_args(char *argv0) // for now, we only support 50% PoS due to other parts of the algorithm needing adjustment for // other values if ( (ASSETCHAINS_LWMAPOS = GetArg("-ac_veruspos",0)) != 0 ) - { + { ASSETCHAINS_LWMAPOS = 50; - if ( GetBoolArg("-gen", false) != 0 ) - VERUS_MINTBLOCKS = true; - } + } ASSETCHAINS_SAPLING = GetArg("-ac_sapling", -1); if (ASSETCHAINS_SAPLING == -1) { From a2d19feeba952a8f1f1da1715a41434d9e9dff2b Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 17 Dec 2018 12:25:53 +0800 Subject: [PATCH 013/643] fir mining properly. Revert all proclimits to 1 or -1, as they are in zcash. also on shutdown, the pos64 was starting a new thread and then seg faulting, this stops that. --- src/miner.cpp | 4 +- src/rpc/mining.cpp | 25 +- .../asyncrpcoperation_mergetoaddress.cpp | 266 +++++++++--------- src/wallet/asyncrpcoperation_sendmany.cpp | 16 +- .../asyncrpcoperation_shieldcoinbase.cpp | 4 +- src/zcbenchmarks.cpp | 4 +- 6 files changed, 161 insertions(+), 158 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 01ee92234..5c8109f40 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1441,7 +1441,7 @@ void static BitcoinMiner() #ifdef ENABLE_WALLET // notaries always default to staking - CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, pindexPrev->GetHeight()+1, gpucount, ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", 0) == 0); + CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, pindexPrev->GetHeight()+1, gpucount, ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", -1) == 0); #else CBlockTemplate *ptr = CreateNewBlockWithKey(); #endif @@ -1831,7 +1831,7 @@ void static BitcoinMiner() } //fprintf(stderr,"nThreads.%d fGenerate.%d\n",(int32_t)nThreads,fGenerate); - if ( ASSETCHAINS_STAKED > 0 && nThreads == 0 ) + if ( ASSETCHAINS_STAKED > 0 && nThreads == 0 && fGenerate ) { if ( pwallet != NULL ) nThreads = 1; diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 5ed1de14c..042dd9b00 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -339,22 +339,25 @@ UniValue setgenerate(const UniValue& params, bool fHelp) //if (nGenProcLimit == 0) // fGenerate = false; } - - if (fGenerate && !nGenProcLimit) + if ( ASSETCHAINS_LWMAPOS != 0 ) { - VERUS_MINTBLOCKS = 1; - fGenerate = GetBoolArg("-gen", false); - if ( ASSETCHAINS_STAKED == 0 ) - nGenProcLimit = KOMODO_MININGTHREADS; - else + if (fGenerate && !nGenProcLimit) + { + VERUS_MINTBLOCKS = 1; + fGenerate = GetBoolArg("-gen", false); KOMODO_MININGTHREADS = nGenProcLimit; + } + else if (!fGenerate) + { + VERUS_MINTBLOCKS = 0; + KOMODO_MININGTHREADS = 0; + } + else KOMODO_MININGTHREADS = (int32_t)nGenProcLimit; } - else if (!fGenerate) + else { - VERUS_MINTBLOCKS = 0; - KOMODO_MININGTHREADS = 0; + KOMODO_MININGTHREADS = (int32_t)nGenProcLimit; } - else KOMODO_MININGTHREADS = (int32_t)nGenProcLimit; mapArgs["-gen"] = (fGenerate ? "1" : "0"); mapArgs ["-genproclimit"] = itostr(KOMODO_MININGTHREADS); diff --git a/src/wallet/asyncrpcoperation_mergetoaddress.cpp b/src/wallet/asyncrpcoperation_mergetoaddress.cpp index c77489381..c97999efd 100644 --- a/src/wallet/asyncrpcoperation_mergetoaddress.cpp +++ b/src/wallet/asyncrpcoperation_mergetoaddress.cpp @@ -42,7 +42,7 @@ int mta_find_output(UniValue obj, int n) if (!outputMapValue.isArray()) { throw JSONRPCError(RPC_WALLET_ERROR, "Missing outputmap for JoinSplit operation"); } - + UniValue outputMap = outputMapValue.get_array(); assert(outputMap.size() == ZC_NUM_JS_OUTPUTS); for (size_t i = 0; i < outputMap.size(); i++) { @@ -50,7 +50,7 @@ int mta_find_output(UniValue obj, int n) return i; } } - + throw std::logic_error("n is not present in outputmap"); } @@ -69,33 +69,33 @@ saplingNoteInputs_(saplingNoteInputs), recipient_(recipient), fee_(fee), context if (fee < 0 || fee > MAX_MONEY) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Fee is out of range"); } - + if (utxoInputs.empty() && sproutNoteInputs.empty() && saplingNoteInputs.empty()) { throw JSONRPCError(RPC_INVALID_PARAMETER, "No inputs"); } - + if (std::get<0>(recipient).size() == 0) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Recipient parameter missing"); } - + if (sproutNoteInputs.size() > 0 && saplingNoteInputs.size() > 0) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot send from both Sprout and Sapling addresses using z_mergetoaddress"); } - + if (sproutNoteInputs.size() > 0 && builder) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Sprout notes are not supported by the TransactionBuilder"); } - + isUsingBuilder_ = false; if (builder) { isUsingBuilder_ = true; builder_ = builder.get(); } - + toTaddr_ = DecodeDestination(std::get<0>(recipient)); isToTaddr_ = IsValidDestination(toTaddr_); isToZaddr_ = false; - + if (!isToTaddr_) { auto address = DecodePaymentAddress(std::get<0>(recipient)); if (IsValidPaymentAddress(address)) { @@ -105,18 +105,18 @@ saplingNoteInputs_(saplingNoteInputs), recipient_(recipient), fee_(fee), context throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid recipient address"); } } - + // Log the context info i.e. the call parameters to z_mergetoaddress if (LogAcceptCategory("zrpcunsafe")) { LogPrint("zrpcunsafe", "%s: z_mergetoaddress initialized (params=%s)\n", getId(), contextInfo.write()); } else { LogPrint("zrpc", "%s: z_mergetoaddress initialized\n", getId()); } - + // Lock UTXOs lock_utxos(); lock_notes(); - + // Enable payment disclosure if requested paymentDisclosureMode = fExperimentalMode && GetBoolArg("-paymentdisclosure", true); } @@ -132,12 +132,12 @@ void AsyncRPCOperation_mergetoaddress::main() unlock_notes(); return; } - + set_state(OperationStatus::EXECUTING); start_execution_clock(); - + bool success = false; - + #ifdef ENABLE_MINING #ifdef ENABLE_WALLET GenerateBitcoins(false, NULL, 0); @@ -145,7 +145,7 @@ void AsyncRPCOperation_mergetoaddress::main() GenerateBitcoins(false, 0); #endif #endif - + try { success = main_impl(); } catch (const UniValue& objError) { @@ -166,7 +166,7 @@ void AsyncRPCOperation_mergetoaddress::main() set_error_code(-2); set_error_message("unknown error"); } - + #ifdef ENABLE_MINING #ifdef ENABLE_WALLET GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", 1)); @@ -174,15 +174,15 @@ void AsyncRPCOperation_mergetoaddress::main() GenerateBitcoins(GetBoolArg("-gen", false), GetArg("-genproclimit", 1)); #endif #endif - + stop_execution_clock(); - + if (success) { set_state(OperationStatus::SUCCESS); } else { set_state(OperationStatus::FAILED); } - + std::string s = strprintf("%s: z_mergetoaddress finished (status=%s", getId(), getStateAsString()); if (success) { s += strprintf(", txid=%s)\n", tx_.GetHash().ToString()); @@ -190,10 +190,10 @@ void AsyncRPCOperation_mergetoaddress::main() s += strprintf(", error=%s)\n", getErrorMessage()); } LogPrintf("%s", s); - + unlock_utxos(); // clean up unlock_notes(); // clean up - + // !!! Payment disclosure START if (success && paymentDisclosureMode && paymentDisclosureData_.size() > 0) { uint256 txidhash = tx_.GetHash(); @@ -216,12 +216,12 @@ void AsyncRPCOperation_mergetoaddress::main() bool AsyncRPCOperation_mergetoaddress::main_impl() { assert(isToTaddr_ != isToZaddr_); - + bool isPureTaddrOnlyTx = (sproutNoteInputs_.empty() && saplingNoteInputs_.empty() && isToTaddr_); CAmount minersFee = fee_; - + size_t numInputs = utxoInputs_.size(); - + // Check mempooltxinputlimit to avoid creating a transaction which the local mempool rejects size_t limit = (size_t)GetArg("-mempooltxinputlimit", 0); { @@ -235,31 +235,31 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() strprintf("Number of transparent inputs %d is greater than mempooltxinputlimit of %d", numInputs, limit)); } - + CAmount t_inputs_total = 0; for (MergeToAddressInputUTXO& t : utxoInputs_) { t_inputs_total += std::get<1>(t); } - + CAmount z_inputs_total = 0; for (const MergeToAddressInputSproutNote& t : sproutNoteInputs_) { z_inputs_total += std::get<2>(t); } - + for (const MergeToAddressInputSaplingNote& t : saplingNoteInputs_) { z_inputs_total += std::get<2>(t); } - + CAmount targetAmount = z_inputs_total + t_inputs_total; - + if (targetAmount <= minersFee) { throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, strprintf("Insufficient funds, have %s and miners fee is %s", FormatMoney(targetAmount), FormatMoney(minersFee))); } - + CAmount sendAmount = targetAmount - minersFee; - + // update the transaction with the UTXO inputs and output (if any) if (!isUsingBuilder_) { CMutableTransaction rawTx(tx_); @@ -274,7 +274,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() } tx_ = CTransaction(rawTx); } - + LogPrint(isPureTaddrOnlyTx ? "zrpc" : "zrpcunsafe", "%s: spending %s to send %s with fee %s\n", getId(), FormatMoney(targetAmount), FormatMoney(sendAmount), FormatMoney(minersFee)); LogPrint("zrpc", "%s: transparent input: %s\n", getId(), FormatMoney(t_inputs_total)); @@ -285,13 +285,13 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() LogPrint("zrpcunsafe", "%s: private output: %s\n", getId(), FormatMoney(sendAmount)); } LogPrint("zrpc", "%s: fee: %s\n", getId(), FormatMoney(minersFee)); - + // Grab the current consensus branch ID { LOCK(cs_main); consensusBranchId_ = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); } - + /** * SCENARIO #0 * @@ -301,15 +301,15 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() */ if (isUsingBuilder_) { builder_.SetFee(minersFee); - - + + for (const MergeToAddressInputUTXO& t : utxoInputs_) { COutPoint outPoint = std::get<0>(t); CAmount amount = std::get<1>(t); CScript scriptPubKey = std::get<2>(t); builder_.AddTransparentInput(outPoint, scriptPubKey, amount); } - + boost::optional ovk; // Select Sapling notes std::vector saplingOPs; @@ -324,7 +324,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() ovk = expsk.full_viewing_key().ovk; } } - + // Fetch Sapling anchor and witnesses uint256 anchor; std::vector> witnesses; @@ -332,7 +332,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() LOCK2(cs_main, pwalletMain->cs_wallet); pwalletMain->GetSaplingNoteWitnesses(saplingOPs, witnesses, anchor); } - + // Add Sapling spends for (size_t i = 0; i < saplingNotes.size(); i++) { if (!witnesses[i]) { @@ -340,7 +340,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() } assert(builder_.AddSaplingSpend(expsks[i], saplingNotes[i], anchor, witnesses[i].get())); } - + if (isToTaddr_) { if (!builder_.AddTransparentOutput(toTaddr_, sendAmount)) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid output address, not a valid taddr."); @@ -372,15 +372,15 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() } builder_.AddSaplingOutput(ovk.get(), *saplingPaymentAddress, sendAmount, hexMemo); } - - + + // Build the transaction auto maybe_tx = builder_.Build(); if (!maybe_tx) { throw JSONRPCError(RPC_WALLET_ERROR, "Failed to build transaction."); } tx_ = maybe_tx.get(); - + // Send the transaction // TODO: Use CWallet::CommitTransaction instead of sendrawtransaction auto signedtxn = EncodeHexTx(tx_); @@ -391,9 +391,9 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() if (sendResultValue.isNull()) { throw JSONRPCError(RPC_WALLET_ERROR, "sendrawtransaction did not return an error or a txid."); } - + auto txid = sendResultValue.get_str(); - + UniValue o(UniValue::VOBJ); o.push_back(Pair("txid", txid)); set_result(o); @@ -405,14 +405,14 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() o.push_back(Pair("hex", signedtxn)); set_result(o); } - + return true; } /** * END SCENARIO #0 */ - - + + /** * SCENARIO #1 * @@ -429,16 +429,16 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() /** * END SCENARIO #1 */ - - + + // Prepare raw transaction to handle JoinSplits CMutableTransaction mtx(tx_); crypto_sign_keypair(joinSplitPubKey_.begin(), joinSplitPrivKey_); mtx.joinSplitPubKey = joinSplitPubKey_; tx_ = CTransaction(mtx); std::string hexMemo = std::get<1>(recipient_); - - + + /** * SCENARIO #2 * @@ -451,13 +451,13 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() MergeToAddressJSInfo info; info.vpub_old = sendAmount; info.vpub_new = 0; - + JSOutput jso = JSOutput(boost::get(toPaymentAddress_), sendAmount); if (hexMemo.size() > 0) { jso.memo = get_memo_from_hex_string(hexMemo); } info.vjsout.push_back(jso); - + UniValue obj(UniValue::VOBJ); obj = perform_joinsplit(info); sign_send_raw_transaction(obj); @@ -466,14 +466,14 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() /** * END SCENARIO #2 */ - - + + // Copy zinputs to more flexible containers std::deque zInputsDeque; for (const auto& o : sproutNoteInputs_) { zInputsDeque.push_back(o); } - + // When spending notes, take a snapshot of note witnesses and anchors as the treestate will // change upon arrival of new blocks which contain joinsplit transactions. This is likely // to happen as creating a chained joinsplit transaction can take longer than the block interval. @@ -488,7 +488,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() jsopWitnessAnchorMap[jso.ToString()] = MergeToAddressWitnessAnchorData{vInputWitnesses[0], inputAnchor}; } } - + /** * SCENARIO #3 * @@ -507,12 +507,12 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() int changeOutputIndex = -1; // this is updated after each joinsplit if jsChange > 0 bool vpubOldProcessed = false; // updated when vpub_old for taddr inputs is set in first joinsplit bool vpubNewProcessed = false; // updated when vpub_new for miner fee and taddr outputs is set in last joinsplit - + // At this point, we are guaranteed to have at least one input note. // Use address of first input note as the temporary change address. SproutSpendingKey changeKey = std::get<3>(zInputsDeque.front()); SproutPaymentAddress changeAddress = changeKey.address(); - + CAmount vpubOldTarget = 0; CAmount vpubNewTarget = 0; if (isToTaddr_) { @@ -524,16 +524,16 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() vpubOldTarget = t_inputs_total - minersFee; } } - + // Keep track of treestate within this transaction boost::unordered_map intermediates; std::vector previousCommitments; - + while (!vpubNewProcessed) { MergeToAddressJSInfo info; info.vpub_old = 0; info.vpub_new = 0; - + // Set vpub_old in the first joinsplit if (!vpubOldProcessed) { if (t_inputs_total < vpubOldTarget) { @@ -544,30 +544,30 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() info.vpub_old += vpubOldTarget; // funds flowing from public pool vpubOldProcessed = true; } - + CAmount jsInputValue = 0; uint256 jsAnchor; std::vector> witnesses; - + JSDescription prevJoinSplit; - + // Keep track of previous JoinSplit and its commitments if (tx_.vjoinsplit.size() > 0) { prevJoinSplit = tx_.vjoinsplit.back(); } - + // If there is no change, the chain has terminated so we can reset the tracked treestate. if (jsChange == 0 && tx_.vjoinsplit.size() > 0) { intermediates.clear(); previousCommitments.clear(); } - + // // Consume change as the first input of the JoinSplit. // if (jsChange > 0) { LOCK2(cs_main, pwalletMain->cs_wallet); - + // Update tree state with previous joinsplit SproutMerkleTree tree; auto it = intermediates.find(prevJoinSplit.anchor); @@ -576,7 +576,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() } else if (!pcoinsTip->GetSproutAnchorAt(prevJoinSplit.anchor, tree)) { throw JSONRPCError(RPC_WALLET_ERROR, "Could not find previous JoinSplit anchor"); } - + assert(changeOutputIndex != -1); boost::optional changeWitness; int n = 0; @@ -594,7 +594,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() } jsAnchor = tree.root(); intermediates.insert(std::make_pair(tree.root(), tree)); // chained js are interstitial (found in between block boundaries) - + // Decrypt the change note's ciphertext to retrieve some data we need ZCNoteDecryption decryptor(changeKey.receiving_key()); auto hSig = prevJoinSplit.h_sig(*pzcashParams, tx_.joinSplitPubKey); @@ -605,23 +605,23 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() prevJoinSplit.ephemeralKey, hSig, (unsigned char)changeOutputIndex); - + SproutNote note = plaintext.note(changeAddress); info.notes.push_back(note); info.zkeys.push_back(changeKey); - + jsInputValue += plaintext.value(); - + LogPrint("zrpcunsafe", "%s: spending change (amount=%s)\n", getId(), FormatMoney(plaintext.value())); - + } catch (const std::exception& e) { throw JSONRPCError(RPC_WALLET_ERROR, strprintf("Error decrypting output note of previous JoinSplit: %s", e.what())); } } - - + + // // Consume spendable non-change notes // @@ -638,7 +638,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() CAmount noteFunds = std::get<2>(t); SproutSpendingKey zkey = std::get<3>(t); zInputsDeque.pop_front(); - + MergeToAddressWitnessAnchorData wad = jsopWitnessAnchorMap[jso.ToString()]; vInputWitnesses.push_back(wad.witness); if (inputAnchor.IsNull()) { @@ -646,13 +646,13 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() } else if (inputAnchor != wad.anchor) { throw JSONRPCError(RPC_WALLET_ERROR, "Selected input notes do not share the same anchor"); } - + vOutPoints.push_back(jso); vInputNotes.push_back(note); vInputZKeys.push_back(zkey); - + jsInputValue += noteFunds; - + int wtxHeight = -1; int wtxDepth = -1; { @@ -674,13 +674,13 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() wtxHeight, wtxDepth); } - + // Add history of previous commitments to witness if (vInputNotes.size() > 0) { if (vInputWitnesses.size() == 0) { throw JSONRPCError(RPC_WALLET_ERROR, "Could not find witness for note commitment"); } - + for (auto& optionalWitness : vInputWitnesses) { if (!optionalWitness) { throw JSONRPCError(RPC_WALLET_ERROR, "Witness for note commitment is null"); @@ -696,20 +696,20 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() } witnesses.push_back(w); } - + // The jsAnchor is null if this JoinSplit is at the start of a new chain if (jsAnchor.IsNull()) { jsAnchor = inputAnchor; } - + // Add spendable notes as inputs std::copy(vInputNotes.begin(), vInputNotes.end(), std::back_inserter(info.notes)); std::copy(vInputZKeys.begin(), vInputZKeys.end(), std::back_inserter(info.zkeys)); } - + // Accumulate change jsChange = jsInputValue + info.vpub_old; - + // Set vpub_new in the last joinsplit (when there are no more notes to spend) if (zInputsDeque.empty()) { assert(!vpubNewProcessed); @@ -724,10 +724,10 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() // If we are merging to a t-addr, there should be no change if (isToTaddr_) assert(jsChange == 0); } - + // create dummy output info.vjsout.push_back(JSOutput()); // dummy output while we accumulate funds into a change note for vpub_new - + // create output for any change if (jsChange > 0) { std::string outputType = "change"; @@ -741,24 +741,24 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() } } info.vjsout.push_back(jso); - + LogPrint("zrpcunsafe", "%s: generating note for %s (amount=%s)\n", getId(), outputType, FormatMoney(jsChange)); } - + obj = perform_joinsplit(info, witnesses, jsAnchor); - + if (jsChange > 0) { changeOutputIndex = mta_find_output(obj, 1); } } - + // Sanity check in case changes to code block above exits loop by invoking 'break' assert(zInputsDeque.size() == 0); assert(vpubNewProcessed); - + sign_send_raw_transaction(obj); return true; } @@ -778,7 +778,7 @@ void AsyncRPCOperation_mergetoaddress::sign_send_raw_transaction(UniValue obj) throw JSONRPCError(RPC_WALLET_ERROR, "Missing hex data for raw transaction"); } std::string rawtxn = rawtxnValue.get_str(); - + UniValue params = UniValue(UniValue::VARR); params.push_back(rawtxn); UniValue signResultValue = signrawtransaction(params, false); @@ -789,13 +789,13 @@ void AsyncRPCOperation_mergetoaddress::sign_send_raw_transaction(UniValue obj) // TODO: #1366 Maybe get "errors" and print array vErrors into a string throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, "Failed to sign transaction"); } - + UniValue hexValue = find_value(signResultObject, "hex"); if (hexValue.isNull()) { throw JSONRPCError(RPC_WALLET_ERROR, "Missing hex data for signed transaction"); } std::string signedtxn = hexValue.get_str(); - + // Send the signed transaction if (!testmode) { params.clear(); @@ -805,26 +805,26 @@ void AsyncRPCOperation_mergetoaddress::sign_send_raw_transaction(UniValue obj) if (sendResultValue.isNull()) { throw JSONRPCError(RPC_WALLET_ERROR, "Send raw transaction did not return an error or a txid."); } - + std::string txid = sendResultValue.get_str(); - + UniValue o(UniValue::VOBJ); o.push_back(Pair("txid", txid)); set_result(o); } else { // Test mode does not send the transaction to the network. - + CDataStream stream(ParseHex(signedtxn), SER_NETWORK, PROTOCOL_VERSION); CTransaction tx; stream >> tx; - + UniValue o(UniValue::VOBJ); o.push_back(Pair("test", 1)); o.push_back(Pair("txid", tx.GetHash().ToString())); o.push_back(Pair("hex", signedtxn)); set_result(o); } - + // Keep the signed transaction so we can hash to the same txid CDataStream stream(ParseHex(signedtxn), SER_NETWORK, PROTOCOL_VERSION); CTransaction tx; @@ -864,52 +864,52 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit( if (anchor.IsNull()) { throw std::runtime_error("anchor is null"); } - + if (witnesses.size() != info.notes.size()) { throw runtime_error("number of notes and witnesses do not match"); } - + if (info.notes.size() != info.zkeys.size()) { throw runtime_error("number of notes and spending keys do not match"); } - + for (size_t i = 0; i < witnesses.size(); i++) { if (!witnesses[i]) { throw runtime_error("joinsplit input could not be found in tree"); } info.vjsin.push_back(JSInput(*witnesses[i], info.notes[i], info.zkeys[i])); } - + // Make sure there are two inputs and two outputs while (info.vjsin.size() < ZC_NUM_JS_INPUTS) { info.vjsin.push_back(JSInput()); } - + while (info.vjsout.size() < ZC_NUM_JS_OUTPUTS) { info.vjsout.push_back(JSOutput()); } - + if (info.vjsout.size() != ZC_NUM_JS_INPUTS || info.vjsin.size() != ZC_NUM_JS_OUTPUTS) { throw runtime_error("unsupported joinsplit input/output counts"); } - + CMutableTransaction mtx(tx_); - + LogPrint("zrpcunsafe", "%s: creating joinsplit at index %d (vpub_old=%s, vpub_new=%s, in[0]=%s, in[1]=%s, out[0]=%s, out[1]=%s)\n", getId(), tx_.vjoinsplit.size(), FormatMoney(info.vpub_old), FormatMoney(info.vpub_new), FormatMoney(info.vjsin[0].note.value()), FormatMoney(info.vjsin[1].note.value()), FormatMoney(info.vjsout[0].value), FormatMoney(info.vjsout[1].value)); - + // Generate the proof, this can take over a minute. std::array inputs{info.vjsin[0], info.vjsin[1]}; std::array outputs{info.vjsout[0], info.vjsout[1]}; std::array inputMap; std::array outputMap; - + uint256 esk; // payment disclosure - secret - + JSDescription jsdesc = JSDescription::Randomized( mtx.fOverwintered && (mtx.nVersion >= SAPLING_TX_VERSION), *pzcashParams, @@ -929,34 +929,34 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit( throw std::runtime_error("error verifying joinsplit"); } } - + mtx.vjoinsplit.push_back(jsdesc); - + // Empty output script. CScript scriptCode; CTransaction signTx(mtx); uint256 dataToBeSigned = SignatureHash(scriptCode, signTx, NOT_AN_INPUT, SIGHASH_ALL, 0, consensusBranchId_); - + // Add the signature if (!(crypto_sign_detached(&mtx.joinSplitSig[0], NULL, dataToBeSigned.begin(), 32, joinSplitPrivKey_) == 0)) { throw std::runtime_error("crypto_sign_detached failed"); } - + // Sanity check if (!(crypto_sign_verify_detached(&mtx.joinSplitSig[0], dataToBeSigned.begin(), 32, mtx.joinSplitPubKey.begin()) == 0)) { throw std::runtime_error("crypto_sign_verify_detached failed"); } - + CTransaction rawTx(mtx); tx_ = rawTx; - + CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); ss << rawTx; - + std::string encryptedNote1; std::string encryptedNote2; { @@ -965,7 +965,7 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit( ss2 << jsdesc.ephemeralKey; ss2 << jsdesc.ciphertexts[0]; ss2 << jsdesc.h_sig(*pzcashParams, joinSplitPubKey_); - + encryptedNote1 = HexStr(ss2.begin(), ss2.end()); } { @@ -974,10 +974,10 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit( ss2 << jsdesc.ephemeralKey; ss2 << jsdesc.ciphertexts[1]; ss2 << jsdesc.h_sig(*pzcashParams, joinSplitPubKey_); - + encryptedNote2 = HexStr(ss2.begin(), ss2.end()); } - + UniValue arrInputMap(UniValue::VARR); UniValue arrOutputMap(UniValue::VARR); for (size_t i = 0; i < ZC_NUM_JS_INPUTS; i++) { @@ -986,8 +986,8 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit( for (size_t i = 0; i < ZC_NUM_JS_OUTPUTS; i++) { arrOutputMap.push_back(static_cast(outputMap[i])); } - - + + // !!! Payment disclosure START unsigned char buffer[32] = {0}; memcpy(&buffer[0], &joinSplitPrivKey_[0], 32); // private key in first half of 64 byte buffer @@ -1003,11 +1003,11 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit( libzcash::SproutPaymentAddress zaddr = output.addr; // randomized output PaymentDisclosureInfo pdInfo = {PAYMENT_DISCLOSURE_VERSION_EXPERIMENTAL, esk, joinSplitPrivKey, zaddr}; paymentDisclosureData_.push_back(PaymentDisclosureKeyInfo(pdKey, pdInfo)); - + LogPrint("paymentdisclosure", "%s: Payment Disclosure: js=%d, n=%d, zaddr=%s\n", getId(), js_index, int(mapped_index), EncodePaymentAddress(zaddr)); } // !!! Payment disclosure END - + UniValue obj(UniValue::VOBJ); obj.push_back(Pair("encryptednote1", encryptedNote1)); obj.push_back(Pair("encryptednote2", encryptedNote2)); @@ -1020,19 +1020,19 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit( std::array AsyncRPCOperation_mergetoaddress::get_memo_from_hex_string(std::string s) { std::array memo = {{0x00}}; - + std::vector rawMemo = ParseHex(s.c_str()); - + // If ParseHex comes across a non-hex char, it will stop but still return results so far. size_t slen = s.length(); if (slen % 2 != 0 || (slen > 0 && rawMemo.size() != slen / 2)) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Memo must be in hexadecimal format"); } - + if (rawMemo.size() > ZC_MEMO_SIZE) { throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Memo size of %d is too big, maximum allowed is %d", rawMemo.size(), ZC_MEMO_SIZE)); } - + // copy vector into boost array int lenMemo = rawMemo.size(); for (int i = 0; i < ZC_MEMO_SIZE && i < lenMemo; i++) { @@ -1050,7 +1050,7 @@ UniValue AsyncRPCOperation_mergetoaddress::getStatus() const if (contextinfo_.isNull()) { return v; } - + UniValue obj = v.get_obj(); obj.push_back(Pair("method", "z_mergetoaddress")); obj.push_back(Pair("params", contextinfo_)); diff --git a/src/wallet/asyncrpcoperation_sendmany.cpp b/src/wallet/asyncrpcoperation_sendmany.cpp index 73288142a..a999f00f6 100644 --- a/src/wallet/asyncrpcoperation_sendmany.cpp +++ b/src/wallet/asyncrpcoperation_sendmany.cpp @@ -169,9 +169,9 @@ void AsyncRPCOperation_sendmany::main() { #ifdef ENABLE_MINING #ifdef ENABLE_WALLET - GenerateBitcoins(GetBoolArg("-gen",false), pwalletMain, GetArg("-genproclimit", 0)); + GenerateBitcoins(GetBoolArg("-gen",false), pwalletMain, GetArg("-genproclimit", 1)); #else - GenerateBitcoins(GetBoolArg("-gen",false), GetArg("-genproclimit", 0)); + GenerateBitcoins(GetBoolArg("-gen",false), GetArg("-genproclimit", 1)); #endif #endif @@ -807,9 +807,9 @@ bool AsyncRPCOperation_sendmany::main_impl() { vOutPoints.push_back(jso); vInputNotes.push_back(note); - + jsInputValue += noteFunds; - + int wtxHeight = -1; int wtxDepth = -1; { @@ -832,14 +832,14 @@ bool AsyncRPCOperation_sendmany::main_impl() { wtxDepth ); } - + // Add history of previous commitments to witness if (vInputNotes.size() > 0) { if (vInputWitnesses.size()==0) { throw JSONRPCError(RPC_WALLET_ERROR, "Could not find witness for note commitment"); } - + for (auto & optionalWitness : vInputWitnesses) { if (!optionalWitness) { throw JSONRPCError(RPC_WALLET_ERROR, "Witness for note commitment is null"); @@ -1061,7 +1061,7 @@ bool AsyncRPCOperation_sendmany::find_utxos(bool fAcceptCoinbase=false) { continue; CAmount nValue = out.tx->vout[out.i].nValue; - + SendManyInputUTXO utxo(out.tx->GetHash(), out.i, nValue, isCoinbase, dest); t_inputs_.push_back(utxo); } @@ -1368,7 +1368,7 @@ void AsyncRPCOperation_sendmany::add_taddr_change_output_to_tx(CBitcoinAddress * std::array AsyncRPCOperation_sendmany::get_memo_from_hex_string(std::string s) { // initialize to default memo (no_memo), see section 5.5 of the protocol spec std::array memo = {{0xF6}}; - + std::vector rawMemo = ParseHex(s.c_str()); // If ParseHex comes across a non-hex char, it will stop but still return results so far. diff --git a/src/wallet/asyncrpcoperation_shieldcoinbase.cpp b/src/wallet/asyncrpcoperation_shieldcoinbase.cpp index 37c771dcb..0f0dc5392 100644 --- a/src/wallet/asyncrpcoperation_shieldcoinbase.cpp +++ b/src/wallet/asyncrpcoperation_shieldcoinbase.cpp @@ -141,9 +141,9 @@ void AsyncRPCOperation_shieldcoinbase::main() { #ifdef ENABLE_MINING #ifdef ENABLE_WALLET - GenerateBitcoins(GetBoolArg("-gen",false), pwalletMain, GetArg("-genproclimit", 0)); + GenerateBitcoins(GetBoolArg("-gen",false), pwalletMain, GetArg("-genproclimit", 1)); #else - GenerateBitcoins(GetBoolArg("-gen",false), GetArg("-genproclimit", 0)); + GenerateBitcoins(GetBoolArg("-gen",false), GetArg("-genproclimit", 1)); #endif #endif diff --git a/src/zcbenchmarks.cpp b/src/zcbenchmarks.cpp index 34e1a2b7d..6b8a910c1 100644 --- a/src/zcbenchmarks.cpp +++ b/src/zcbenchmarks.cpp @@ -63,8 +63,8 @@ void post_wallet_load(){ #ifdef ENABLE_MINING // Generate coins in the background if (pwalletMain || !GetArg("-mineraddress", "").empty()) - GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", 0)); -#endif + GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", 1)); +#endif } From 02efca37aeb97b2677cf0bb7427d40c55aff1bf8 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 17 Dec 2018 13:04:04 +0800 Subject: [PATCH 014/643] revert this change it is wrong, they need to be OR here. --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 20f28d46a..a6c4778db 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4710,7 +4710,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C CValidationState state; CTransaction Tx; const CTransaction &tx = (CTransaction)block.vtx[i]; - if (tx.IsCoinBase() || (!tx.vjoinsplit.empty() && !tx.vShieldedSpend.empty()) || ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED && komodo_isPoS((CBlock *)&block) != 0))) + if (tx.IsCoinBase() || !tx.vjoinsplit.empty() || !tx.vShieldedSpend.empty() || ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED && komodo_isPoS((CBlock *)&block) != 0))) continue; Tx = tx; if ( myAddtomempool(Tx, &state, true) == false ) // happens with out of order tx in block on resync From 52a85f583e7554666f8c07728488d8b5b3d6e5ca Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 17 Dec 2018 02:55:47 -1100 Subject: [PATCH 015/643] Test merge --- src/wallet/rpcwallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index f8b507403..34035908d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4789,8 +4789,8 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp) if (useAnySprout || useAnySapling || zaddrs.size() > 0) { // Get available notes std::vector sproutEntries; - std::vector saplingEntries; - pwalletMain->GetFilteredNotes(sproutEntries, saplingEntries, zaddrs); + std::vector saplingEntries,skipsapling; + pwalletMain->GetFilteredNotes(sproutEntries, useAnySprout != 0 ? saplingEntries : skipsapling, zaddrs); // If Sapling is not active, do not allow sending from a sapling addresses. if (!saplingActive && saplingEntries.size() > 0) { From 89c6763a8f1d3fae49b2fb1e38946ef076d20cd6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 17 Dec 2018 03:25:44 -1100 Subject: [PATCH 016/643] Mutually exclude merging sprout vs sapling --- src/wallet/rpcwallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 34035908d..1d6f056da 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4788,9 +4788,9 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp) if (useAnySprout || useAnySapling || zaddrs.size() > 0) { // Get available notes - std::vector sproutEntries; + std::vector sproutEntries,skipsprout; std::vector saplingEntries,skipsapling; - pwalletMain->GetFilteredNotes(sproutEntries, useAnySprout != 0 ? saplingEntries : skipsapling, zaddrs); + pwalletMain->GetFilteredNotes(useAnySprout != 0 ? sproutEntries : skipsprout, useAnySapling != 0 ? saplingEntries : skipsapling, zaddrs); // If Sapling is not active, do not allow sending from a sapling addresses. if (!saplingActive && saplingEntries.size() > 0) { From 97fe83f4b3f969af56a0d4bded33c2b01d78750c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 17 Dec 2018 04:12:47 -1100 Subject: [PATCH 017/643] Test any sprout --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1d6f056da..bd1ae56d6 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4790,7 +4790,7 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp) // Get available notes std::vector sproutEntries,skipsprout; std::vector saplingEntries,skipsapling; - pwalletMain->GetFilteredNotes(useAnySprout != 0 ? sproutEntries : skipsprout, useAnySapling != 0 ? saplingEntries : skipsapling, zaddrs); + pwalletMain->GetFilteredNotes(sproutEntries, useAnySprout == 0 ? saplingEntries : skipsapling, zaddrs); // If Sapling is not active, do not allow sending from a sapling addresses. if (!saplingActive && saplingEntries.size() > 0) { From 56430117fe4df47e2c6e2ecff4280a8e231ca526 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Mon, 17 Dec 2018 17:56:06 +0100 Subject: [PATCH 018/643] Channels fix (#5) - Fix bug when destination invokes payment (wrong pubkeys in OP_RETURN - validation would fail) - Added channelslist RPC - Changed channelsinfo data to JSON format --- src/cc/CCchannels.h | 2 +- src/cc/channels.cpp | 220 ++++++++++++++++++++++----------------- src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/wallet/rpcwallet.cpp | 9 ++ 5 files changed, 139 insertions(+), 94 deletions(-) diff --git a/src/cc/CCchannels.h b/src/cc/CCchannels.h index 7715a31b8..34c1edd7d 100644 --- a/src/cc/CCchannels.h +++ b/src/cc/CCchannels.h @@ -25,7 +25,7 @@ std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64 std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint256 secret); std::string ChannelClose(uint64_t txfee,uint256 opentxid); std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid); - +UniValue ChannelsList(); // CCcustom UniValue ChannelsInfo(uint256 opentxid); diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 60f907c27..6c8b602c6 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -75,11 +75,11 @@ int64_t IsChannelsvout(struct CCcontract_info *cp,const CTransaction& tx,CPubKey return(0); } -int64_t IsChannelsMarkervout(struct CCcontract_info *cp,const CTransaction& tx,CPubKey srcpub,int32_t v) +int64_t IsChannelsMarkervout(struct CCcontract_info *cp,const CTransaction& tx,CPubKey pubkey,int32_t v) { char destaddr[65],ccaddr[65]; - GetCCaddress(cp,ccaddr,srcpub); + GetCCaddress(cp,ccaddr,pubkey); if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) { if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && strcmp(destaddr,ccaddr) == 0 ) @@ -207,11 +207,11 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return eval->Invalid("vin.1 is CC for channelPayment!"); else if ( IsCCInput(tx.vin[2].scriptSig) == 0 ) return eval->Invalid("vin.2 is CC for channelPayment!"); - else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) + else if ( IsChannelsvout(cp,tx,srcpub,destpub,0)==0 ) return eval->Invalid("vout.0 is CC for channelPayment!"); - else if ( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) + else if ( IsChannelsMarkervout(cp,tx,srcpub,1)==0 ) return eval->Invalid("vout.1 is CC for channelPayment (marker to srcPub)!"); - else if ( tx.vout[2].scriptPubKey.IsPayToCryptoCondition() == 0 ) + else if ( IsChannelsMarkervout(cp,tx,destpub,2)==0 ) return eval->Invalid("vout.2 is CC for channelPayment (marker to dstPub)!"); else if ( tx.vout[3].scriptPubKey.IsPayToCryptoCondition() != 0 ) return eval->Invalid("vout.3 is normal for channelPayment!"); @@ -269,11 +269,11 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return eval->Invalid("vin.1 is CC for channelClose!"); else if ( IsCCInput(tx.vin[2].scriptSig) == 0 ) return eval->Invalid("vin.2 is CC for channelClose!"); - else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) + else if ( IsChannelsvout(cp,tx,srcpub,destpub,0)==0 ) return eval->Invalid("vout.0 is CC for channelClose!"); - else if ( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) + else if ( IsChannelsMarkervout(cp,tx,srcpub,1)==0 ) return eval->Invalid("vout.1 is CC for channelClose (marker to srcPub)!"); - else if ( tx.vout[2].scriptPubKey.IsPayToCryptoCondition() == 0 ) + else if ( IsChannelsMarkervout(cp,tx,destpub,2)==0 ) return eval->Invalid("vout.2 is CC for channelClose (marker to dstPub)!"); else if ( param1 > CHANNELS_MAXPAYMENTS) return eval->Invalid("too many payment increments!"); @@ -314,9 +314,9 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return eval->Invalid("vin.1 is CC for channelRefund!"); else if ( IsCCInput(tx.vin[2].scriptSig) == 0 ) return eval->Invalid("vin.2 is CC for channelRefund!"); - else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) + else if ( IsChannelsMarkervout(cp,tx,srcpub,0)==0 ) return eval->Invalid("vout.0 is CC for channelRefund (marker to srcPub)!"); - else if ( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) + else if ( IsChannelsMarkervout(cp,tx,destpub,1)==0 ) return eval->Invalid("vout.1 is CC for channelRefund (marker to dstPub)!"); else if ( tx.vout[2].scriptPubKey.IsPayToCryptoCondition() != 0 ) return eval->Invalid("vout.2 is normal for channelRefund!"); @@ -366,12 +366,12 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & // helper functions for rpc calls in rpcwallet.cpp -int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, CTransaction openTx, uint256 &prevtxid) +int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, CTransaction openTx, uint256 &prevtxid, CPubKey mypk) { - char coinaddr[65]; int64_t param2,totalinputs = 0,numvouts; uint256 txid=zeroid,tmp_txid,hashBlock,param3; CTransaction tx; int32_t param1; + char coinaddr[65]; int64_t param2,totalinputs = 0,numvouts; uint256 txid=zeroid,tmp_txid,hashBlock,param3; CTransaction tx; int32_t marker,param1; std::vector > unspentOutputs; CPubKey srcpub,destpub; - uint8_t myprivkey[32]; + uint8_t myprivkey[32]; if ((numvouts=openTx.vout.size()) > 0 && DecodeChannelsOpRet(openTx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)=='O') { @@ -383,14 +383,15 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C fprintf(stderr,"invalid channel open txid\n"); return 0; } - + if (srcpub==mypk) marker=1; + else marker=2; for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { if ( (int32_t)it->first.index==0 && GetTransaction(it->first.txhash,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size()) > 0) { if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)!=0 && (tmp_txid==openTx.GetHash() || tx.GetHash()==openTx.GetHash()) && - (totalinputs=IsChannelsvout(cp,tx,srcpub,destpub,0)+IsChannelsMarkervout(cp,tx,srcpub,1))>0) + (totalinputs=IsChannelsvout(cp,tx,srcpub,destpub,0)+IsChannelsMarkervout(cp,tx,srcpub,marker))>0) { txid = it->first.txhash; break; @@ -419,7 +420,7 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C { prevtxid=txid; mtx.vin.push_back(CTxIn(txid,0,CScript())); - mtx.vin.push_back(CTxIn(txid,1,CScript())); + mtx.vin.push_back(CTxIn(txid,marker,CScript())); Myprivkey(myprivkey); CCaddr2set(cp,EVAL_CHANNELS,srcpub,myprivkey,coinaddr); CCaddr3set(cp,EVAL_CHANNELS,destpub,myprivkey,coinaddr); @@ -483,7 +484,7 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 } if (AddNormalinputs(mtx,mypk,2*txfee,3) > 0) { - if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid)) !=0 && (change=funds-amount-txfee)>=0) + if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid,mypk)) !=0 && (change=funds-amount-txfee)>=0) { if ((numvouts=channelOpenTx.vout.size()) > 0 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, totalnumpayments, payment, hashchain)=='O') { @@ -553,11 +554,11 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 fprintf(stderr, "invalid channel open tx\n"); return (""); } - mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS, change, mypk, destpub)); - mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); + mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS, change, srcpub, destpub)); + mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,srcpub)); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,destpub)); mtx.vout.push_back(CTxOut(amount, CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG)); - return (FinalizeCCTx(0, cp, mtx, mypk, txfee, EncodeChannelsOpRet('P', opentxid, mypk, destpub, prevdepth-numpayments, numpayments, secret))); + return (FinalizeCCTx(0, cp, mtx, mypk, txfee, EncodeChannelsOpRet('P', opentxid, srcpub, destpub, prevdepth-numpayments, numpayments, secret))); } else { @@ -600,12 +601,12 @@ std::string ChannelClose(uint64_t txfee,uint256 opentxid) } if ( AddNormalinputs(mtx,mypk,2*txfee,3) > 0 ) { - if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid)) !=0 && funds-txfee>0) + if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid,mypk)) !=0 && funds-txfee>0) { mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS, funds-txfee, mypk, destpub)); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,destpub)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('C',opentxid,mypk,destpub,funds/payment,payment,zeroid))); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('C',opentxid,mypk,destpub,(funds-txfee)/payment,payment,zeroid))); } else { @@ -664,7 +665,7 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) } if ( AddNormalinputs(mtx,mypk,2*txfee,3) > 0 ) { - if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid)) !=0 && funds-txfee>0) + if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid,mypk)) !=0 && funds-txfee>0) { if ((GetTransaction(prevtxid,prevTx,hashblock,false) != 0) && (numvouts=prevTx.vout.size()) > 0 && DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, param1, param2, param3) != 0) @@ -696,84 +697,117 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) } return(""); } - -UniValue ChannelsInfo(uint256 channeltxid) +UniValue ChannelsList() { - UniValue result(UniValue::VOBJ); CTransaction tx,opentx; uint256 txid,tmp_txid,hashBlock,param3,opentxid,hashchain,prevtxid; - struct CCcontract_info *cp,C; char myCCaddr[65],addr[65],str1[512],str2[256]; int32_t vout,numvouts,param1,numpayments; - int64_t nValue,param2,payment; CPubKey srcpub,destpub,mypk; - std::vector > txids; + UniValue result(UniValue::VOBJ); std::vector > txids; struct CCcontract_info *cp,C; uint256 txid,hashBlock,tmp_txid,param3; + CTransaction tx; char myCCaddr[65],addr[65],str[256]; CPubKey mypk,srcpub,destpub; int32_t vout,numvouts,param1; + int64_t nValue,param2; - result.push_back(Pair("result","success")); cp = CCinit(&C,EVAL_CHANNELS); mypk = pubkey2pk(Mypubkey()); - if (channeltxid==zeroid) + GetCCaddress(cp,myCCaddr,mypk); + SetCCtxids(txids,myCCaddr); + result.push_back(Pair("result","success")); + result.push_back(Pair("name","Channels List")); + for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) { - result.push_back(Pair("name","Channels Info")); - GetCCaddress(cp,myCCaddr,mypk); - SetCCtxids(txids,myCCaddr); - for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) + txid = it->first.txhash; + vout = (int32_t)it->first.index; + nValue = (int64_t)it->second; + if ( (vout == 1 || vout == 2) && nValue == 10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) { - //int height = it->first.blockHeight; - txid = it->first.txhash; - vout = (int32_t)it->first.index; - nValue = (int64_t)it->second; - if ( (vout == 1 || vout == 2) && nValue == 10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) - { - if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3) == 'O') - { - GetCCaddress1of2(cp,addr,srcpub,destpub); - sprintf(str1,"%s - %lld payments of %lld satoshi - %s",addr,(long long)param1,(long long)param2,tx.GetHash().ToString().c_str()); - result.push_back(Pair("Channel", str1)); - } - } - } - } - else - { - if (GetTransaction(channeltxid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 && - (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'O')) - { - GetCCaddress1of2(cp,addr,srcpub,destpub); - sprintf(str1,"Channel %s",addr); - result.push_back(Pair("name",str1)); - SetCCtxids(txids,addr); - prevtxid=zeroid; - for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) - { - - txid = it->first.txhash; - if (txid!=prevtxid && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) - { - if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3) == 'O' && tx.GetHash()==channeltxid) - { - sprintf(str1,"%lld payments of %lld satoshi",(long long)param1,(long long)param2); - result.push_back(Pair("Open", str1)); - } - else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'P' && opentxid==channeltxid) - { - if (GetTransaction(opentxid,opentx,hashBlock,false) != 0 && (numvouts=opentx.vout.size()) > 0 && - DecodeChannelsOpRet(opentx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,numpayments,payment,hashchain) == 'O') - { - Getscriptaddress(str2,tx.vout[3].scriptPubKey); - sprintf(str1,"%lld satoshi to %s, %lld payments left",(long long)(param2*payment),str2,(long long)param1); - result.push_back(Pair("Payment",str1)); - } - } - else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'C' && opentxid==channeltxid) - { - result.push_back(Pair("Close","channel")); - } - else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'R' && opentxid==channeltxid) - { - Getscriptaddress(str2,tx.vout[2].scriptPubKey); - sprintf(str1,"%lld satoshi back to %s",(long long)(param1*param2),str2); - result.push_back(Pair("Refund",str1)); - } - } - prevtxid=txid; + if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3) == 'O') + { + GetCCaddress1of2(cp,addr,srcpub,destpub); + sprintf(str,"%s - %lld payments of %lld satoshi",addr,(long long)param1,(long long)param2); + result.push_back(Pair(txid.GetHex().data(),str)); } } } return(result); } + +UniValue ChannelsInfo(uint256 channeltxid) +{ + UniValue result(UniValue::VOBJ),array(UniValue::VARR); CTransaction tx,opentx; uint256 txid,tmp_txid,hashBlock,param3,opentxid,hashchain,prevtxid; + struct CCcontract_info *cp,C; char CCaddr[65],addr[65],str[512]; int32_t vout,numvouts,param1,numpayments; + int64_t nValue,param2,payment; CPubKey srcpub,destpub,mypk; + std::vector > addressIndex; std::vector txids; + + cp = CCinit(&C,EVAL_CHANNELS); + mypk = pubkey2pk(Mypubkey()); + + if (GetTransaction(channeltxid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 && + (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'O')) + { + GetCCaddress(cp,CCaddr,mypk); + Getscriptaddress(addr,CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG); + result.push_back(Pair("result","success")); + result.push_back(Pair("Channel CC address",CCaddr)); + result.push_back(Pair("Destination address",addr)); + result.push_back(Pair("Number of payments",param1)); + result.push_back(Pair("Denomination",param2)); + result.push_back(Pair("Amount",i64tostr(param1*param2)+" satoshi")); + SetCCtxids(addressIndex,CCaddr); + for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) + { + if (GetTransaction(it->first.txhash,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) + if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)!=0 && (tmp_txid==channeltxid || tx.GetHash()==channeltxid)) + txids.push_back(it->first.txhash); + } + BOOST_FOREACH(const CTxMemPoolEntry &e, mempool.mapTx) + { + const CTransaction &txmempool = e.GetTx(); + const uint256 &hash = txmempool.GetHash(); + + if ((numvouts=txmempool.vout.size()) > 0 && DecodeChannelsOpRet(txmempool.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3) == 'P' && tmp_txid==channeltxid) + txids.push_back(hash); + } + prevtxid=zeroid; + for (std::vector::const_iterator it=txids.begin(); it!=txids.end(); it++) + { + txid=*it; + if (txid!=prevtxid && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) + { + UniValue obj(UniValue::VOBJ); + if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3) == 'O' && tx.GetHash()==channeltxid) + { + obj.push_back(Pair("Open",txid.GetHex().data())); + } + else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'P' && opentxid==channeltxid) + { + if (GetTransaction(opentxid,opentx,hashBlock,false) != 0 && (numvouts=opentx.vout.size()) > 0 && + DecodeChannelsOpRet(opentx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,numpayments,payment,hashchain) == 'O') + { + Getscriptaddress(str,tx.vout[3].scriptPubKey); + obj.push_back(Pair("Payment",txid.GetHex().data())); + obj.push_back(Pair("Number",param2)); + obj.push_back(Pair("Amount",param2*payment)); + obj.push_back(Pair("Destination",str)); + obj.push_back(Pair("Secret",param3.ToString().c_str())); + } + } + else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'C' && opentxid==channeltxid) + { + obj.push_back(Pair("Close",txid.GetHex().data())); + } + else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'R' && opentxid==channeltxid) + { + Getscriptaddress(str,tx.vout[2].scriptPubKey); + obj.push_back(Pair("Refund",txid.GetHex().data())); + obj.push_back(Pair("Amount",param1*param2)); + obj.push_back(Pair("Destination",str)); + } + array.push_back(obj); + } + prevtxid=txid; + } + result.push_back(Pair("Transactions",array)); + } + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("Error","Channel not found!")); + } + return(result); +} \ No newline at end of file diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 1b6856be5..8dd32ab6a 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -394,6 +394,7 @@ static const CRPCCommand vRPCCommands[] = // Channels { "channels", "channelsaddress", &channelsaddress, true }, + { "channels", "channelslist", &channelslist, true }, { "channels", "channelsinfo", &channelsinfo, true }, { "channels", "channelsopen", &channelsopen, true }, { "channels", "channelspayment", &channelspayment, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 6638024b8..a129c21c0 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -271,6 +271,7 @@ extern UniValue gatewaysmarkdone(const UniValue& params, bool fHelp); extern UniValue gatewayspending(const UniValue& params, bool fHelp); extern UniValue gatewaysprocessed(const UniValue& params, bool fHelp); extern UniValue gatewaysmultisig(const UniValue& params, bool fHelp); +extern UniValue channelslist(const UniValue& params, bool fHelp); extern UniValue channelsinfo(const UniValue& params, bool fHelp); extern UniValue channelsopen(const UniValue& params, bool fHelp); extern UniValue channelspayment(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index f8b507403..9391261d7 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5672,6 +5672,15 @@ UniValue tokenaddress(const UniValue& params, bool fHelp) return(CCaddress(cp,(char *)"Assets",pubkey)); } +UniValue channelslist(const UniValue& params, bool fHelp) +{ + if ( fHelp || params.size() > 0 ) + throw runtime_error("channelsinfo\n"); + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + return(ChannelsList()); +} + UniValue channelsinfo(const UniValue& params, bool fHelp) { uint256 opentxid; From 7cbe71e5e05109b73601b2b2ca672d71d70a738c Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 18 Dec 2018 02:27:29 +0800 Subject: [PATCH 019/643] Fix check_deposit banning peers on sync. --- src/komodo_gateway.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 102245723..262bf5107 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -90,7 +90,7 @@ struct pax_transaction *komodo_paxmark(int32_t height,uint256 txid,uint16_t vout pax->marked = mark; //if ( height > 214700 || pax->height > 214700 ) // printf("mark ht.%d %.8f %.8f\n",pax->height,dstr(pax->komodoshis),dstr(pax->fiatoshis)); - + } pthread_mutex_unlock(&komodo_mutex); return(pax); @@ -203,9 +203,9 @@ int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t // return(0); incr = 34 + (iskomodo * (2*sizeof(fiatoshis) + 2*sizeof(height) + 20 + 4)); //41e77b91cb68dc2aa02fa88550eae6b6d44db676a7e935337b6d1392d9718f03cb0200305c90660400000000fbcbeb1f000000bde801006201000058e7945ad08ddba1eac9c9b6c8e1e97e8016a2d152 - + // 41e94d736ec69d88c08b5d238abeeca609c02357a8317e0d56c328bcb1c259be5d0200485bc80200000000404b4c000000000059470200b80b000061f22ba7d19fe29ac3baebd839af8b7127d1f9075553440046bb4cc7a3b5cd39dffe7206507a3482a00780e617f68b273cce9817ed69298d02001069ca1b0000000080f0fa02000000005b470200b90b000061f22ba7d19fe29ac3baebd839af8b7127d1f90755 - + //for (i=0; i 1) || NetworkUpgradeActive(height, Params().GetConsensus(), Consensus::UPGRADE_SAPLING) ) { @@ -737,7 +737,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim if ( height > 1000000 && strangeout != 0 ) return(-1); } - else if ( height > 814000 ) + else if ( height > 814000 && KOMODO_INSYNC != 0 ) { script = (uint8_t *)&block.vtx[0].vout[0].scriptPubKey[0]; return(-1 * (komodo_electednotary(&num,script+1,height,0) >= 0) * (height > 1000000)); @@ -774,7 +774,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout,char *source) { - uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t didstats,i,j,n,kvheight,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fee,fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax,*pax2; struct komodo_state *basesp; double diff; + uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t didstats,i,j,n,kvheight,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fee,fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax,*pax2; struct komodo_state *basesp; double diff; const char *typestr = "unknown"; if ( ASSETCHAINS_SYMBOL[0] != 0 && komodo_baseid(ASSETCHAINS_SYMBOL) < 0 && opretbuf[0] != 'K' ) { @@ -1187,7 +1187,7 @@ void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_ printf("numR.%d numV.%d numN.%d count.%d\n",numR,numV,numN,count); /*else if ( func == 'K' ) // KMD height: stop after 1st else if ( func == 'T' ) // KMD height+timestamp: stop after 1st - + else if ( func == 'N' ) // notarization, scan backwards 1440+ blocks; else if ( func == 'V' ) // price feed: can stop after 1440+ else if ( func == 'R' ) // opreturn:*/ @@ -1521,4 +1521,3 @@ void komodo_passport_iteration() printf("READY for %s RPC calls at %u! done PASSPORT %s refid.%d\n",ASSETCHAINS_SYMBOL,(uint32_t)time(NULL),ASSETCHAINS_SYMBOL,refid); } } - From 8d2b0c3f31ecdd4dfe31ea785c637efe2df4443d Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 18 Dec 2018 17:09:37 +0800 Subject: [PATCH 020/643] Fix KMD check_deposit peer ban. --- src/komodo_gateway.h | 7 ++++++- src/main.cpp | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 262bf5107..5572364da 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -737,9 +737,14 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim if ( height > 1000000 && strangeout != 0 ) return(-1); } - else if ( height > 814000 && KOMODO_INSYNC != 0 ) + else if ( height > 814000 ) { script = (uint8_t *)&block.vtx[0].vout[0].scriptPubKey[0]; + //int32_t notary = komodo_electednotary(&num,script+1,height,0); + //if ( (-1 * (komodo_electednotary(&num,script+1,height,0) >= 0) * (height > 1000000)) < 0 ) + // fprintf(stderr, ">>>>>>> FAILED BLOCK.%d notary.%d insync.%d\n",height,notary,KOMODO_INSYNC); + //else + // fprintf(stderr, "<<<<<<< VALID BLOCK.%d notary.%d insync.%d\n",height,notary,KOMODO_INSYNC); return(-1 * (komodo_electednotary(&num,script+1,height,0) >= 0) * (height > 1000000)); } } diff --git a/src/main.cpp b/src/main.cpp index a6c4778db..94f07f72e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4757,7 +4757,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C if (nSigOps > MAX_BLOCK_SIGOPS) return state.DoS(100, error("CheckBlock: out-of-bounds SigOpCount"), REJECT_INVALID, "bad-blk-sigops", true); - if ( komodo_check_deposit(height,block,(pindex==0||pindex->pprev==0)?0:pindex->pprev->nTime) < 0 ) + if ( fCheckPOW && komodo_check_deposit(height,block,(pindex==0||pindex->pprev==0)?0:pindex->pprev->nTime) < 0 ) { //static uint32_t counter; //if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 ) From 45d91c8f0d034c99a22f6072c299b1734375744e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 18 Dec 2018 04:30:25 -1100 Subject: [PATCH 021/643] z_mergetoaddress loop at start of migrate --- src/cc/dapps/zmigrate.c | 78 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/src/cc/dapps/zmigrate.c b/src/cc/dapps/zmigrate.c index 3f26c50a1..61a863e16 100644 --- a/src/cc/dapps/zmigrate.c +++ b/src/cc/dapps/zmigrate.c @@ -647,6 +647,25 @@ int64_t z_getbalance(char *refcoin,char *acname,char *coinaddr) return (amount); } +int32_t z_exportkey(char *privkey,char *refcoin,char *acname,char *zaddr) +{ + cJSON *retjson; char *retstr,cmpstr[64]; int64_t amount=0; + privkey[0] = 0; + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_exportkey",zaddr,"","","")) != 0 ) + { + fprintf(stderr,"z_exportkey.(%s) %s returned json!\n",refcoin,acname); + free_json(retjson); + return(-1); + } + else if ( retstr != 0 ) + { + //printf("retstr %s -> %.8f\n",retstr,dstr(amount)); + strcpy(privkey,retstr); + free(retstr); + return(0); + } +} + int32_t getnewaddress(char *coinaddr,char *refcoin,char *acname) { cJSON *retjson; char *retstr; int64_t amount=0; @@ -664,6 +683,23 @@ int32_t getnewaddress(char *coinaddr,char *refcoin,char *acname) } } +int32_t z_getnewaddress(char *coinaddr,char *refcoin,char *acname) +{ + cJSON *retjson; char *retstr; int64_t amount=0; + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_getnewaddress","","","","")) != 0 ) + { + fprintf(stderr,"z_getnewaddress.(%s) %s returned json!\n",refcoin,acname); + free_json(retjson); + return(-1); + } + else if ( retstr != 0 ) + { + strcpy(coinaddr,retstr); + free(retstr); + return(0); + } +} + int64_t find_onetime_amount(char *coinstr,char *coinaddr) { cJSON *array,*item; int32_t i,n; char *addr; int64_t amount = 0; @@ -751,6 +787,39 @@ int32_t z_sendmany(char *opidstr,char *coinstr,char *acname,char *srcaddr,char * } } +int32_t z_mergetoaddress(char *opidstr,char *coinstr,char *acname,char *destaddr) +{ + cJSON *retjson; char *retstr,addr[128],*opstr; int32_t retval = -1; + sprintf(addr,"\"ANY_SPROUT\""); + //printf("z_sendmany from.(%s) -> %s\n",addr,destaddr); + if ( (retjson= get_komodocli(coinstr,&retstr,acname,"z_mergetoaddress",addr,destaddr,"","")) != 0 ) + { + /*{ + "remainingUTXOs": 0, + "remainingTransparentValue": 0.00000000, + "remainingNotes": 222, + "remainingShieldedValue": 5413.39093055, + "mergingUTXOs": 0, + "mergingTransparentValue": 0.00000000, + "mergingNotes": 10, + "mergingShieldedValue": 822.47447172, + "opid": "opid-f28f6261-4120-436c-aca5-859870a40a70" + }*/ + if ( (opstr= jstr(retjson,"opid")) != 0 ) + strcpy(opidstr,opstr); + retval = jint(retjson,"remainingNotes"); + fprintf(stderr,"%s\n",jprint(retjson,0)); + free_json(retjson); + } + else if ( retstr != 0 ) + { + fprintf(stderr,"z_mergetoaddress.(%s) -> opid.(%s)\n",coinstr,retstr); + strcpy(opidstr,retstr); + free(retstr); + } + return(retval); +} + int32_t empty_mempool(char *coinstr,char *acname) { cJSON *array; int32_t n; @@ -907,11 +976,18 @@ int32_t main(int32_t argc,char **argv) } zsaddr = clonestr(argv[2]); printf("%s: %s %s\n",REFCOIN_CLI,coinstr,zsaddr); - uint32_t lastopid; char coinaddr[64],zcaddr[128],opidstr[128]; int32_t finished; int64_t amount,stdamount,txfee; + uint32_t lastopid; char coinaddr[64],privkey[1024],zcaddr[128],opidstr[128]; int32_t finished; int64_t amount,stdamount,txfee; //stdamount = 500 * SATOSHIDEN; txfee = 10000; again: printf("start processing zmigrate\n"); + if ( z_getnewaddress(zcaddr,coinstr,"") == 0 ) + { + z_exportkey(privkey,coinstr,"",zcaddr); + printf("zcaddr.(%s) -> z_exportkey.(%s)\n",zcaddr,privkey); + while ( z_mergetoaddress(opidstr,coinstr,"",zcaddr) > 0 ) + ; + } lastopid = (uint32_t)time(NULL); finished = 0; while ( 1 ) From a7cd4c0d714a006d9daa29c3a81b4e346a5cbf7f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 18 Dec 2018 04:33:24 -1100 Subject: [PATCH 022/643] z_getnewaddress sprout --- src/cc/dapps/zmigrate.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/dapps/zmigrate.c b/src/cc/dapps/zmigrate.c index 61a863e16..018af2c3b 100644 --- a/src/cc/dapps/zmigrate.c +++ b/src/cc/dapps/zmigrate.c @@ -683,10 +683,10 @@ int32_t getnewaddress(char *coinaddr,char *refcoin,char *acname) } } -int32_t z_getnewaddress(char *coinaddr,char *refcoin,char *acname) +int32_t z_getnewaddress(char *coinaddr,char *refcoin,char *acname,char *typestr) { cJSON *retjson; char *retstr; int64_t amount=0; - if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_getnewaddress","","","","")) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_getnewaddress",typestr,"","","")) != 0 ) { fprintf(stderr,"z_getnewaddress.(%s) %s returned json!\n",refcoin,acname); free_json(retjson); @@ -981,7 +981,7 @@ int32_t main(int32_t argc,char **argv) txfee = 10000; again: printf("start processing zmigrate\n"); - if ( z_getnewaddress(zcaddr,coinstr,"") == 0 ) + if ( z_getnewaddress(zcaddr,coinstr,"","sprout") == 0 ) { z_exportkey(privkey,coinstr,"",zcaddr); printf("zcaddr.(%s) -> z_exportkey.(%s)\n",zcaddr,privkey); From 92fc71b75385ab4c6e034aebd34fe8bffe706a2b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 18 Dec 2018 04:35:49 -1100 Subject: [PATCH 023/643] [] --- src/cc/dapps/zmigrate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dapps/zmigrate.c b/src/cc/dapps/zmigrate.c index 018af2c3b..c11e84e06 100644 --- a/src/cc/dapps/zmigrate.c +++ b/src/cc/dapps/zmigrate.c @@ -790,7 +790,7 @@ int32_t z_sendmany(char *opidstr,char *coinstr,char *acname,char *srcaddr,char * int32_t z_mergetoaddress(char *opidstr,char *coinstr,char *acname,char *destaddr) { cJSON *retjson; char *retstr,addr[128],*opstr; int32_t retval = -1; - sprintf(addr,"\"ANY_SPROUT\""); + sprintf(addr,"[\"ANY_SPROUT\"]"); //printf("z_sendmany from.(%s) -> %s\n",addr,destaddr); if ( (retjson= get_komodocli(coinstr,&retstr,acname,"z_mergetoaddress",addr,destaddr,"","")) != 0 ) { @@ -980,7 +980,6 @@ int32_t main(int32_t argc,char **argv) //stdamount = 500 * SATOSHIDEN; txfee = 10000; again: - printf("start processing zmigrate\n"); if ( z_getnewaddress(zcaddr,coinstr,"","sprout") == 0 ) { z_exportkey(privkey,coinstr,"",zcaddr); @@ -988,6 +987,7 @@ again: while ( z_mergetoaddress(opidstr,coinstr,"",zcaddr) > 0 ) ; } + printf("start processing zmigrate\n"); lastopid = (uint32_t)time(NULL); finished = 0; while ( 1 ) From 45df5812401044b8422b5f72a52de9507a0533bf Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 18 Dec 2018 04:36:36 -1100 Subject: [PATCH 024/643] Test --- src/cc/dapps/zmigrate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dapps/zmigrate.c b/src/cc/dapps/zmigrate.c index c11e84e06..3b32cbdd4 100644 --- a/src/cc/dapps/zmigrate.c +++ b/src/cc/dapps/zmigrate.c @@ -790,7 +790,7 @@ int32_t z_sendmany(char *opidstr,char *coinstr,char *acname,char *srcaddr,char * int32_t z_mergetoaddress(char *opidstr,char *coinstr,char *acname,char *destaddr) { cJSON *retjson; char *retstr,addr[128],*opstr; int32_t retval = -1; - sprintf(addr,"[\"ANY_SPROUT\"]"); + sprintf(addr,"[\\""ANY_SPROUT\\""]"); //printf("z_sendmany from.(%s) -> %s\n",addr,destaddr); if ( (retjson= get_komodocli(coinstr,&retstr,acname,"z_mergetoaddress",addr,destaddr,"","")) != 0 ) { From 776e52508347cc14dfa1fc1d786d897fb975e8bb Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 18 Dec 2018 04:38:02 -1100 Subject: [PATCH 025/643] \" --- src/cc/dapps/zmigrate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dapps/zmigrate.c b/src/cc/dapps/zmigrate.c index 3b32cbdd4..2e3051902 100644 --- a/src/cc/dapps/zmigrate.c +++ b/src/cc/dapps/zmigrate.c @@ -790,7 +790,7 @@ int32_t z_sendmany(char *opidstr,char *coinstr,char *acname,char *srcaddr,char * int32_t z_mergetoaddress(char *opidstr,char *coinstr,char *acname,char *destaddr) { cJSON *retjson; char *retstr,addr[128],*opstr; int32_t retval = -1; - sprintf(addr,"[\\""ANY_SPROUT\\""]"); + sprintf(addr,"[\\\"ANY_SPROUT\\\"]"); //printf("z_sendmany from.(%s) -> %s\n",addr,destaddr); if ( (retjson= get_komodocli(coinstr,&retstr,acname,"z_mergetoaddress",addr,destaddr,"","")) != 0 ) { From 95f4ecf06e733a5f616f8a5caec3d89af04509b3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 18 Dec 2018 05:12:26 -1100 Subject: [PATCH 026/643] Serial mergetoaddress --- src/cc/dapps/zmigrate.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cc/dapps/zmigrate.c b/src/cc/dapps/zmigrate.c index 2e3051902..f1fb4b0a6 100644 --- a/src/cc/dapps/zmigrate.c +++ b/src/cc/dapps/zmigrate.c @@ -984,8 +984,16 @@ again: { z_exportkey(privkey,coinstr,"",zcaddr); printf("zcaddr.(%s) -> z_exportkey.(%s)\n",zcaddr,privkey); - while ( z_mergetoaddress(opidstr,coinstr,"",zcaddr) > 0 ) - ; + while ( 1 ) + { + if ( have_pending_opid(coinstr,0) != 0 ) + { + sleep(10); + continue; + } + if ( z_mergetoaddress(opidstr,coinstr,"",zcaddr) <= 0 ) + break; + } } printf("start processing zmigrate\n"); lastopid = (uint32_t)time(NULL); From 5488101f95053c338a837a325bc11ab48e73bd89 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 18 Dec 2018 05:22:38 -1100 Subject: [PATCH 027/643] Rename shutoff process --- src/init.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index 1fcd87be7..be98f8fb0 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -76,6 +76,7 @@ using namespace std; extern void ThreadSendAlert(); extern int32_t KOMODO_LOADINGBLOCKS; extern bool VERUS_MINTBLOCKS; +extern char ASSETCHAINS_SYMBOL[]; ZCJoinSplit* pzcashParams = NULL; @@ -195,7 +196,10 @@ void Shutdown() /// for example if the data directory was found to be locked. /// Be sure that anything that writes files or flushes caches only does this if the respective /// module was initialized. - RenameThread("verus-shutoff"); + static char shutoffstr[128]; + sprintf(shutoffstr,"%s-shutoff",ASSETCHAINS_SYMBOL); + //RenameThread("verus-shutoff"); + RenameThread(shutoffstr); mempool.AddTransactionsUpdated(1); StopHTTPRPC(); From 4fc0f1977580a1fad68132aea3593e6e84f50383 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 18 Dec 2018 10:13:04 -1100 Subject: [PATCH 028/643] Fix warnings --- src/cc/dapps/zmigrate.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/cc/dapps/zmigrate.c b/src/cc/dapps/zmigrate.c index f1fb4b0a6..145f4575f 100644 --- a/src/cc/dapps/zmigrate.c +++ b/src/cc/dapps/zmigrate.c @@ -649,55 +649,55 @@ int64_t z_getbalance(char *refcoin,char *acname,char *coinaddr) int32_t z_exportkey(char *privkey,char *refcoin,char *acname,char *zaddr) { - cJSON *retjson; char *retstr,cmpstr[64]; int64_t amount=0; + cJSON *retjson; char *retstr,cmpstr[64]; int64_t amount=0; int32_t retval = -1; privkey[0] = 0; if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_exportkey",zaddr,"","","")) != 0 ) { fprintf(stderr,"z_exportkey.(%s) %s returned json!\n",refcoin,acname); free_json(retjson); - return(-1); } else if ( retstr != 0 ) { //printf("retstr %s -> %.8f\n",retstr,dstr(amount)); strcpy(privkey,retstr); free(retstr); - return(0); + retval = 0; } + return(retval); } int32_t getnewaddress(char *coinaddr,char *refcoin,char *acname) { - cJSON *retjson; char *retstr; int64_t amount=0; + cJSON *retjson; char *retstr; int64_t amount=0; int32_t retval = -1; if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getnewaddress","","","","")) != 0 ) { fprintf(stderr,"getnewaddress.(%s) %s returned json!\n",refcoin,acname); free_json(retjson); - return(-1); } else if ( retstr != 0 ) { strcpy(coinaddr,retstr); free(retstr); - return(0); + retval = 0; } + return(retval); } int32_t z_getnewaddress(char *coinaddr,char *refcoin,char *acname,char *typestr) { - cJSON *retjson; char *retstr; int64_t amount=0; + cJSON *retjson; char *retstr; int64_t amount=0; int32_t retval = -1; if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_getnewaddress",typestr,"","","")) != 0 ) { fprintf(stderr,"z_getnewaddress.(%s) %s returned json!\n",refcoin,acname); free_json(retjson); - return(-1); } else if ( retstr != 0 ) { strcpy(coinaddr,retstr); free(retstr); - return(0); + retval = 0; } + return(retval); } int64_t find_onetime_amount(char *coinstr,char *coinaddr) @@ -768,7 +768,7 @@ void importaddress(char *refcoin,char *acname,char *depositaddr) int32_t z_sendmany(char *opidstr,char *coinstr,char *acname,char *srcaddr,char *destaddr,int64_t amount) { - cJSON *retjson; char *retstr,params[1024],addr[128]; + cJSON *retjson; char *retstr,params[1024],addr[128]; int32_t retval = -1; sprintf(params,"'[{\"address\":\"%s\",\"amount\":%.8f}]'",destaddr,dstr(amount)); sprintf(addr,"\"%s\"",srcaddr); printf("z_sendmany from.(%s) -> %s\n",srcaddr,params); @@ -776,15 +776,15 @@ int32_t z_sendmany(char *opidstr,char *coinstr,char *acname,char *srcaddr,char * { printf("unexpected json z_sendmany.(%s)\n",jprint(retjson,0)); free_json(retjson); - return(-1); } else if ( retstr != 0 ) { fprintf(stderr,"z_sendmany.(%s) -> opid.(%s)\n",coinstr,retstr); strcpy(opidstr,retstr); free(retstr); - return(0); + retval = 0; } + return(retval); } int32_t z_mergetoaddress(char *opidstr,char *coinstr,char *acname,char *destaddr) From 2d9c9864d71b8880f3399d3a46ac1097f0aa2975 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Dec 2018 09:26:37 -1100 Subject: [PATCH 029/643] Skip unspendables in zmigrate --- src/cc/dapps/zmigrate.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cc/dapps/zmigrate.c b/src/cc/dapps/zmigrate.c index 145f4575f..d9ec6ec19 100644 --- a/src/cc/dapps/zmigrate.c +++ b/src/cc/dapps/zmigrate.c @@ -712,6 +712,10 @@ int64_t find_onetime_amount(char *coinstr,char *coinaddr) for (i=0; i Date: Thu, 20 Dec 2018 21:13:32 +0800 Subject: [PATCH 030/643] test git diff --- src/komodo_bitcoind.h | 294 ++++++++++++++++++++++- src/main.cpp | 51 ++-- src/miner.cpp | 488 ++++++++++++++++++++------------------- src/rpc/blockchain.cpp | 47 +++- src/rpc/client.cpp | 1 + src/rpc/server.cpp | 11 +- src/wallet/rpcwallet.cpp | 367 +++++------------------------ 7 files changed, 677 insertions(+), 582 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index add4f4e7f..4b47d0682 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -25,7 +25,8 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp); int32_t komodo_electednotary(int32_t *numnotariesp,uint8_t *pubkey33,int32_t height,uint32_t timestamp); unsigned int lwmaGetNextPOSRequired(const CBlockIndex* pindexLast, const Consensus::Params& params); - +bool EnsureWalletIsAvailable(bool avoidException); +extern bool fRequestShutdown; //#define issue_curl(cmdstr) bitcoind_RPC(0,(char *)"curl",(char *)"http://127.0.0.1:7776",0,0,(char *)(cmdstr)) struct MemoryStruct { char *memory; size_t size; }; @@ -610,6 +611,28 @@ uint32_t komodo_txtime2(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr) return(txtime); } +int32_t komodo_WhoStaked(CBlock *pblock, CTxDestination &addressout) +{ + int32_t n,vout; uint32_t txtime; uint64_t value; char voutaddr[64],destaddr[64]; CTxDestination voutaddress; uint256 txid; + if ( (n= pblock->vtx.size()) > 1 && pblock->vtx[n-1].vin.size() == 1 && pblock->vtx[n-1].vout.size() == 1 ) + { + txid = pblock->vtx[n-1].vin[0].prevout.hash; + vout = pblock->vtx[n-1].vin[0].prevout.n; + txtime = komodo_txtime(&value,txid,vout,destaddr); + if ( ExtractDestination(pblock->vtx[n-1].vout[0].scriptPubKey,voutaddress) ) + { + strcpy(voutaddr,CBitcoinAddress(voutaddress).ToString().c_str()); + if ( strcmp(destaddr,voutaddr) == 0 && pblock->vtx[n-1].vout[0].nValue == value ) + { + //fprintf(stderr,"is PoS block!\n"); + addressout = voutaddress; + return(1); + } + } + } + return(0); +} + int32_t komodo_isPoS(CBlock *pblock) { int32_t n,vout; uint32_t txtime; uint64_t value; char voutaddr[64],destaddr[64]; CTxDestination voutaddress; uint256 txid; @@ -1439,7 +1462,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ if ( slowflag != 0 && pindex != 0 ) { pindex->segid = -1; - fprintf(stderr,"PoW block detected set segid.%d <- %d\n",height,pindex->segid); + //fprintf(stderr,"PoW block detected set segid.%d <- %d\n",height,pindex->segid); } } else @@ -1447,11 +1470,17 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ isPoS = 2; // 2 means staking utxo validated if ( slowflag != 0 && height > 100 ) { - segid = -3; - if ( pindex != 0 && pindex->segid == -2 && (segid= komodo_segid(1,height)) >= 0 ) + CTxDestination voutaddress; char voutaddr[64]; + if ( ExtractDestination(pblock->vtx[txn_count-1].vout[0].scriptPubKey,voutaddress) ) + { + strcpy(voutaddr,CBitcoinAddress(voutaddress).ToString().c_str()); + segid = komodo_segid32(voutaddr) & 0x3f; + //fprintf(stderr,"komodo_segid.(%d) -> %d\n",height,segid); + } + if ( pindex != 0 && segid >= 0 ) { pindex->segid = segid; - fprintf(stderr,"B set segid.%d <- %d\n",height,pindex->segid); + //fprintf(stderr,"B set segid.%d <- %d\n",height,pindex->segid); } //else fprintf(stderr,"unexpected null pindex for slowflag set ht.%d segid.%d:%d\n",height,pindex!=0?pindex->segid:-3,segid); } } @@ -1937,3 +1966,258 @@ int64_t komodo_coinsupply(int64_t *zfundsp,int64_t *sproutfundsp,int32_t height) *sproutfundsp = sproutfunds; return(supply); } +struct komodo_staking +{ + char address[64]; + uint256 txid; + arith_uint256 hashval; + uint64_t nValue; + uint32_t segid32,txtime; + int32_t vout; + CScript scriptPubKey; +}; + +struct komodo_staking *komodo_addutxo(struct komodo_staking *array,int32_t *numkp,int32_t *maxkp,uint32_t txtime,uint64_t nValue,uint256 txid,int32_t vout,char *address,uint8_t *hashbuf,CScript pk) +{ + uint256 hash; uint32_t segid32; struct komodo_staking *kp; + segid32 = komodo_stakehash(&hash,address,hashbuf,txid,vout); + if ( *numkp >= *maxkp ) + { + *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; + kp->vout = vout; + kp->hashval = UintToArith256(hash); + kp->txtime = txtime; + kp->segid32 = segid32; + kp->nValue = nValue; + kp->scriptPubKey = pk; + return(array); +} + +arith_uint256 _komodo_eligible(struct komodo_staking *kp,arith_uint256 ratio,uint32_t blocktime,int32_t iter,int32_t minage,int32_t segid,int32_t nHeight,uint32_t prevtime) +{ + int32_t diff; uint64_t coinage; arith_uint256 coinage256,hashval; + diff = (iter + blocktime - kp->txtime - minage); + if ( diff < 0 ) + diff = 60; + else if ( diff > 3600*24*30 ) + diff = 3600*24*30; + if ( iter > 0 ) + diff += segid*2; + coinage = ((uint64_t)kp->nValue * diff); + if ( blocktime+iter+segid*2 > prevtime+480 ) + coinage *= ((blocktime+iter+segid*2) - (prevtime+400)); + coinage256 = arith_uint256(coinage+1); + hashval = ratio * (kp->hashval / coinage256); + return(hashval); +} + +uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komodo_staking *kp,int32_t nHeight,uint32_t blocktime,uint32_t prevtime,int32_t minage,uint8_t *hashbuf) +{ + int32_t maxiters = 600; uint256 hash; + int32_t segid,iter,diff; uint64_t coinage; arith_uint256 hashval,coinage256; + komodo_stakehash(&hash,kp->address,hashbuf,kp->txid,kp->vout); + kp->hashval = UintToArith256(hash); + segid = ((nHeight + kp->segid32) & 0x3f); + hashval = _komodo_eligible(kp,ratio,blocktime,maxiters,minage,segid,nHeight,prevtime); + //for (int i=32; i>=0; i--) + // fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + //fprintf(stderr," b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime); + if ( hashval <= bnTarget ) + { + for (iter=0; itertxtime+minage ) + continue; + hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime); + if ( hashval <= bnTarget ) + { + //fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid); + blocktime += iter; + blocktime += segid * 2; + return(blocktime); + } + } + } else fprintf(stderr,"maxiters is not good enough\n"); + return(0); +} + +int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) +{ + static struct komodo_staking *array; static int32_t numkp,maxkp; static uint32_t lasttime; + set setAddress; struct komodo_staking *kp; int32_t winners,segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t block_from_future_rejecttime,besttime,eligible,eligible2,earliest = 0; CScript best_scriptPubKey; arith_uint256 mindiff,ratio,bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock; + if (!EnsureWalletIsAvailable(0)) + return 0; + + bnTarget.SetCompact(nBits, &fNegative, &fOverflow); + mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + ratio = (mindiff / bnTarget); + assert(pwalletMain != NULL); + *utxovaluep = 0; + memset(utxotxidp,0,sizeof(*utxotxidp)); + memset(utxovoutp,0,sizeof(*utxovoutp)); + memset(utxosig,0,72); + if ( (tipindex= chainActive.Tip()) == 0 ) + return(0); + nHeight = tipindex->GetHeight() + 1; + if ( (minage= nHeight*3) > 6000 ) // about 100 blocks + minage = 6000; + komodo_segids(hashbuf,nHeight-101,100); + 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); + + bool resetstaker = false; + if ( array != 0 ) + { + CBlockIndex* pblockindex = chainActive[tipindex->GetHeight()]; + CBlock block; CTxDestination addressout; + if( ReadBlockFromDisk(block, pblockindex, 1) && komodo_WhoStaked(&block, addressout) != 0 && IsMine(*pwalletMain,addressout) != 0 ) + { + resetstaker = true; + fprintf(stderr, "Reset ram staker after mining a block!\n"); + } + } + + if ( time(NULL) > lasttime+600 || array == 0 || resetstaker ) + { + LOCK2(cs_main, pwalletMain->cs_wallet); + pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); + if ( array != 0 ) + { + free(array); + array = 0; + maxkp = numkp = 0; + lasttime = 0; + } + BOOST_FOREACH(const COutput& out, vecOutputs) + { + if ( (tipindex= chainActive.Tip()) == 0 || tipindex->GetHeight()+1 > nHeight ) + { + fprintf(stderr,"chain tip changed during staking loop t.%u counter.%d\n",(uint32_t)time(NULL),counter); + return(0); + } + counter++; + if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth ) + { + fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth); + continue; + } + CAmount nValue = out.tx->vout[out.i].nValue; + if ( nValue < COIN || !out.fSpendable ) + continue; + const CScript& pk = out.tx->vout[out.i].scriptPubKey; + if ( ExtractDestination(pk,address) != 0 ) + { + if ( IsMine(*pwalletMain,address) == 0 ) + continue; + 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,"numkp.%d blocktime.%u\n",numkp,*blocktimep); + block_from_future_rejecttime = (uint32_t)GetAdjustedTime() + 57; + for (i=winners=0; iGetHeight()+1 > nHeight ) + { + fprintf(stderr,"chain tip changed during staking loop t.%u counter.%d\n",(uint32_t)time(NULL),counter); + return(0); + } + kp = &array[i]; + 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); + if ( eligible > 0 ) + { + besttime = m = 0; + if ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address) ) + { + while ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address) ) + { + besttime = eligible; + eligible--; + 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); + } + } + else + { + fprintf(stderr,"ht.%d error validating winning blocktime %u -> %.8f eligible.%u test prior\n",nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); + continue; + } + 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); + if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || kp->nValue < *utxovaluep)) ) + { + earliest = eligible; + best_scriptPubKey = kp->scriptPubKey; //out.tx->vout[out.i].scriptPubKey; + *utxovaluep = (uint64_t)kp->nValue; + //decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); + decode_hex((uint8_t *)utxotxidp,32,(char *)kp->txid.GetHex().c_str()); + *utxovoutp = kp->vout; + *txtimep = kp->txtime;//(uint32_t)out.tx->nLockTime; + 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"); + } + if ( numkp < 1000 && array != 0 ) + { + free(array); + array = 0; + maxkp = numkp = 0; + lasttime = 0; + } + if ( earliest != 0 ) + { + bool signSuccess; SignatureData sigdata; uint64_t txfee; uint8_t *ptr; uint256 revtxid,utxotxid; + auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); + const CKeyStore& keystore = *pwalletMain; + txNew.vin.resize(1); + txNew.vout.resize(1); + txfee = 0; + for (i=0; i<32; i++) + ((uint8_t *)&revtxid)[i] = ((uint8_t *)utxotxidp)[31 - i]; + txNew.vin[0].prevout.hash = revtxid; + txNew.vin[0].prevout.n = *utxovoutp; + txNew.vout[0].scriptPubKey = best_scriptPubKey;// CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; + txNew.vout[0].nValue = *utxovaluep - txfee; + txNew.nLockTime = earliest; + CTransaction txNewConst(txNew); + signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, *utxovaluep, SIGHASH_ALL), best_scriptPubKey, sigdata, consensusBranchId); + if (!signSuccess) + fprintf(stderr,"failed to create signature\n"); + else + { + UpdateTransaction(txNew,0,sigdata); + ptr = (uint8_t *)&sigdata.scriptSig[0]; + siglen = sigdata.scriptSig.size(); + for (i=0; inTime; + + // is it already in the memory pool? + uint256 hash = tx.GetHash(); + if (pool.exists(hash)) + { + //fprintf(stderr,"already in mempool\n"); + return state.Invalid(false, REJECT_DUPLICATE, "already in mempool"); + } + // Node operator can choose to reject tx by number of transparent inputs static_assert(std::numeric_limits::max() >= std::numeric_limits::max(), "size_t too small"); size_t limit = (size_t) GetArg("-mempooltxinputlimit", 0); @@ -1648,7 +1657,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa } // Rather not work on nonstandard transactions (unless -testnet/-regtest) string reason; - if (Params().RequireStandard() && !IsStandardTx(tx, reason, nextBlockHeight)) + if (!fSkipExpiry && Params().RequireStandard() && !IsStandardTx(tx, reason, nextBlockHeight)) { // //fprintf(stderr,"AcceptToMemoryPool reject nonstandard transaction: %s\nscriptPubKey: %s\n",reason.c_str(),tx.vout[0].scriptPubKey.ToString().c_str()); @@ -1657,21 +1666,14 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // Only accept nLockTime-using transactions that can be mined in the next // block; we don't want our mempool filled up with transactions that can't // be mined yet. - if (!CheckFinalTx(tx, STANDARD_LOCKTIME_VERIFY_FLAGS)) + if (!fSkipExpiry && !CheckFinalTx(tx, STANDARD_LOCKTIME_VERIFY_FLAGS)) { //fprintf(stderr,"AcceptToMemoryPool reject non-final\n"); return state.DoS(0, false, REJECT_NONSTANDARD, "non-final"); } - // is it already in the memory pool? - uint256 hash = tx.GetHash(); - if (pool.exists(hash)) - { - //fprintf(stderr,"already in mempool\n"); - return state.Invalid(false, REJECT_DUPLICATE, "already in mempool"); - } - // Check for conflicts with in-memory transactions + if (!fSkipExpiry) { LOCK(pool.cs); // protect pool.mapNextTx for (unsigned int i = 0; i < tx.vin.size(); i++) @@ -1721,7 +1723,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa if (ExistsImportTombstone(tx, view)) return state.Invalid(false, REJECT_DUPLICATE, "import tombstone exists"); } - else + else if (!fSkipExpiry) { // do all inputs exist? // Note that this does not check for the presence of actual outputs (see the next check for that), @@ -1733,10 +1735,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa if (pfMissingInputs) *pfMissingInputs = true; //fprintf(stderr,"missing inputs\n"); - if (!fSkipExpiry) - return state.DoS(0, error("AcceptToMemoryPool: tx inputs not found"),REJECT_INVALID, "bad-txns-inputs-missing"); - else - return(false); + return state.DoS(0, error("AcceptToMemoryPool: tx inputs not found"),REJECT_INVALID, "bad-txns-inputs-missing"); } } @@ -1744,10 +1743,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa if (!view.HaveInputs(tx)) { //fprintf(stderr,"accept failure.1\n"); - if (!fSkipExpiry) - return state.Invalid(error("AcceptToMemoryPool: inputs already spent"),REJECT_DUPLICATE, "bad-txns-inputs-spent"); - else - return(false); + return state.Invalid(error("AcceptToMemoryPool: inputs already spent"),REJECT_DUPLICATE, "bad-txns-inputs-spent"); } } // are the joinsplit's requirements met? @@ -1756,6 +1752,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa //fprintf(stderr,"accept failure.2\n"); return state.Invalid(error("AcceptToMemoryPool: joinsplit requirements not met"),REJECT_DUPLICATE, "bad-txns-joinsplit-requirements-not-met"); } + // Bring the best block into scope view.GetBestBlock(); @@ -1790,7 +1787,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // Keep track of transactions that spend a coinbase, which we re-scan // during reorgs to ensure COINBASE_MATURITY is still met. bool fSpendsCoinbase = false; - if (!tx.IsCoinImport()) { + if (!fSkipExpiry && !tx.IsCoinImport()) { BOOST_FOREACH(const CTxIn &txin, tx.vin) { const CCoins *coins = view.AccessCoins(txin.prevout.hash); if (coins->IsCoinBase()) { @@ -1865,7 +1862,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // Check against previous transactions // This is done last to help prevent CPU exhaustion denial-of-service attacks. PrecomputedTransactionData txdata(tx); - if (!ContextualCheckInputs(tx, state, view, true, STANDARD_SCRIPT_VERIFY_FLAGS, true, txdata, Params().GetConsensus(), consensusBranchId)) + if (!fSkipExpiry && !ContextualCheckInputs(tx, state, view, true, STANDARD_SCRIPT_VERIFY_FLAGS, true, txdata, Params().GetConsensus(), consensusBranchId)) { //fprintf(stderr,"accept failure.9\n"); return error("AcceptToMemoryPool: ConnectInputs failed %s", hash.ToString()); @@ -1886,7 +1883,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa flag = 1; KOMODO_CONNECTING = (1<<30) + (int32_t)chainActive.LastTip()->GetHeight() + 1; } - if (!ContextualCheckInputs(tx, state, view, true, MANDATORY_SCRIPT_VERIFY_FLAGS, true, txdata, Params().GetConsensus(), consensusBranchId)) + if (!fSkipExpiry && !ContextualCheckInputs(tx, state, view, true, MANDATORY_SCRIPT_VERIFY_FLAGS, true, txdata, Params().GetConsensus(), consensusBranchId)) { if ( flag != 0 ) KOMODO_CONNECTING = -1; @@ -1896,8 +1893,6 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa KOMODO_CONNECTING = -1; // Store transaction in memory - if ( komodo_is_notarytx(tx) == 0 ) - KOMODO_ON_DEMAND++; pool.addUnchecked(hash, entry, !IsInitialBlockDownload()); if (!tx.IsCoinImport()) @@ -4680,12 +4675,15 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C // Check transactions CTransaction sTx; CTransaction *ptx = NULL; + if ( ASSETCHAINS_CC != 0 && !fCheckPOW ) + return true; + if ( ASSETCHAINS_CC != 0 ) // CC contracts might refer to transactions in the current block, from a CC spend within the same block and out of order { int32_t i,j,rejects=0,lastrejects=0; //fprintf(stderr,"put block's tx into mempool\n"); // Copy all non Z-txs in mempool to temporary mempool because there can be tx in local mempool that make the block invalid. - LOCK2(cs_main,mempool.cs); + LOCK(mempool.cs); //fprintf(stderr, "starting... mempoolsize.%ld\n",mempool.size()); list transactionsToRemove; BOOST_FOREACH(const CTxMemPoolEntry& e, mempool.mapTx) { @@ -6977,6 +6975,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, else if (strCommand == "tx") { + if (IsInitialBlockDownload()) + return true; + vector vWorkQueue; vector vEraseQueue; CTransaction tx; diff --git a/src/miner.cpp b/src/miner.cpp index 5c8109f40..9ff925554 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -199,261 +199,266 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, boost::optional cheatSpend; uint256 cbHash; - CBlockIndex* pindexPrev = 0; + SaplingMerkleTree sapling_tree; uint64_t commission; + int nHeight = 0; + const Consensus::Params &consensusParams = chainparams.GetConsensus(); + + CBlockIndex* pindexPrev = chainActive.LastTip();; { - LOCK2(cs_main, mempool.cs); - pindexPrev = chainActive.LastTip(); - const int nHeight = pindexPrev->GetHeight() + 1; - const Consensus::Params &consensusParams = chainparams.GetConsensus(); - uint32_t consensusBranchId = CurrentEpochBranchId(nHeight, consensusParams); - bool sapling = NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_SAPLING); + { // contain lock to block generation and not staking loops. + LOCK2(cs_main, mempool.cs); + nHeight = pindexPrev->GetHeight() + 1; + uint32_t consensusBranchId = CurrentEpochBranchId(nHeight, consensusParams); + bool sapling = NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_SAPLING); - const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast(); - uint32_t proposedTime = GetAdjustedTime(); - if (proposedTime == nMedianTimePast) - { - // too fast or stuck, this addresses the too fast issue, while moving - // forward as quickly as possible - for (int i; i < 100; i++) + const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast(); + uint32_t proposedTime = GetAdjustedTime(); + if (proposedTime == nMedianTimePast) { - proposedTime = GetAdjustedTime(); - if (proposedTime == nMedianTimePast) - MilliSleep(10); - } - } - pblock->nTime = GetAdjustedTime(); - - CCoinsViewCache view(pcoinsTip); - uint32_t expired; uint64_t commission; - - SaplingMerkleTree sapling_tree; - assert(view.GetSaplingAnchorAt(view.GetBestAnchor(SAPLING), sapling_tree)); - - // Priority order to process transactions - list vOrphan; // list memory doesn't move - map > mapDependers; - bool fPrintPriority = GetBoolArg("-printpriority", false); - - // This vector will be sorted into a priority queue: - vector vecPriority; - vecPriority.reserve(mempool.mapTx.size() + 1); - - // now add transactions from the mem pool - for (CTxMemPool::indexed_transaction_set::iterator mi = mempool.mapTx.begin(); - mi != mempool.mapTx.end(); ++mi) - { - const CTransaction& tx = mi->GetTx(); - - int64_t nLockTimeCutoff = (STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST) - ? nMedianTimePast - : pblock->GetBlockTime(); - - if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff) || IsExpiredTx(tx, nHeight)) - { - //fprintf(stderr,"coinbase.%d finaltx.%d expired.%d\n",tx.IsCoinBase(),IsFinalTx(tx, nHeight, nLockTimeCutoff),IsExpiredTx(tx, nHeight)); - continue; - } - - if ( ASSETCHAINS_SYMBOL[0] == 0 && komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,0) < 0 ) - { - //fprintf(stderr,"CreateNewBlock: komodo_validate_interest failure nHeight.%d nTime.%u vs locktime.%u\n",nHeight,(uint32_t)pblock->nTime,(uint32_t)tx.nLockTime); - continue; - } - - COrphan* porphan = NULL; - double dPriority = 0; - CAmount nTotalIn = 0; - bool fMissingInputs = false; - if (tx.IsCoinImport()) - { - CAmount nValueIn = GetCoinImportValue(tx); - nTotalIn += nValueIn; - dPriority += (double)nValueIn * 1000; // flat multiplier - } else { - BOOST_FOREACH(const CTxIn& txin, tx.vin) + // too fast or stuck, this addresses the too fast issue, while moving + // forward as quickly as possible + for (int i; i < 100; i++) { - // Read prev transaction - if (!view.HaveCoins(txin.prevout.hash)) - { - // This should never happen; all transactions in the memory - // pool should connect to either transactions in the chain - // or other transactions in the memory pool. - if (!mempool.mapTx.count(txin.prevout.hash)) - { - LogPrintf("ERROR: mempool transaction missing input\n"); - if (fDebug) assert("mempool transaction missing input" == 0); - fMissingInputs = true; - if (porphan) - vOrphan.pop_back(); - break; - } + proposedTime = GetAdjustedTime(); + if (proposedTime == nMedianTimePast) + MilliSleep(10); + } + } + pblock->nTime = GetAdjustedTime(); - // Has to wait for dependencies - if (!porphan) - { - // Use list for automatic deletion - vOrphan.push_back(COrphan(&tx)); - porphan = &vOrphan.back(); - } - mapDependers[txin.prevout.hash].push_back(porphan); - porphan->setDependsOn.insert(txin.prevout.hash); - nTotalIn += mempool.mapTx.find(txin.prevout.hash)->GetTx().vout[txin.prevout.n].nValue; - continue; - } - const CCoins* coins = view.AccessCoins(txin.prevout.hash); - assert(coins); + CCoinsViewCache view(pcoinsTip); + uint32_t expired; - CAmount nValueIn = coins->vout[txin.prevout.n].nValue; + assert(view.GetSaplingAnchorAt(view.GetBestAnchor(SAPLING), sapling_tree)); + + // Priority order to process transactions + list vOrphan; // list memory doesn't move + map > mapDependers; + bool fPrintPriority = GetBoolArg("-printpriority", false); + + // This vector will be sorted into a priority queue: + vector vecPriority; + vecPriority.reserve(mempool.mapTx.size() + 1); + + // now add transactions from the mem pool + for (CTxMemPool::indexed_transaction_set::iterator mi = mempool.mapTx.begin(); + mi != mempool.mapTx.end(); ++mi) + { + const CTransaction& tx = mi->GetTx(); + + int64_t nLockTimeCutoff = (STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST) + ? nMedianTimePast + : pblock->GetBlockTime(); + + if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff) || IsExpiredTx(tx, nHeight)) + { + //fprintf(stderr,"coinbase.%d finaltx.%d expired.%d\n",tx.IsCoinBase(),IsFinalTx(tx, nHeight, nLockTimeCutoff),IsExpiredTx(tx, nHeight)); + continue; + } + + if ( ASSETCHAINS_SYMBOL[0] == 0 && komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,0) < 0 ) + { + //fprintf(stderr,"CreateNewBlock: komodo_validate_interest failure nHeight.%d nTime.%u vs locktime.%u\n",nHeight,(uint32_t)pblock->nTime,(uint32_t)tx.nLockTime); + continue; + } + + COrphan* porphan = NULL; + double dPriority = 0; + CAmount nTotalIn = 0; + bool fMissingInputs = false; + bool fNotarisation = false; + if (tx.IsCoinImport()) + { + CAmount nValueIn = GetCoinImportValue(tx); nTotalIn += nValueIn; - - int nConf = nHeight - coins->nHeight; - - dPriority += (double)nValueIn * nConf; - } - nTotalIn += tx.GetShieldedValueIn(); - } - - if (fMissingInputs) continue; - - // Priority is sum(valuein * age) / modified_txsize - unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); - dPriority = tx.ComputePriority(dPriority, nTxSize); - - uint256 hash = tx.GetHash(); - mempool.ApplyDeltas(hash, dPriority, nTotalIn); - - CFeeRate feeRate(nTotalIn-tx.GetValueOut(), nTxSize); - - if (porphan) - { - porphan->dPriority = dPriority; - porphan->feeRate = feeRate; - } - else - vecPriority.push_back(TxPriority(dPriority, feeRate, &(mi->GetTx()))); - } - - // Collect transactions into block - uint64_t nBlockSize = 1000; - uint64_t nBlockTx = 0; - int64_t interest; - int nBlockSigOps = 100; - bool fSortedByFee = (nBlockPrioritySize <= 0); - - TxPriorityCompare comparer(fSortedByFee); - std::make_heap(vecPriority.begin(), vecPriority.end(), comparer); - - while (!vecPriority.empty()) - { - // Take highest priority transaction off the priority queue: - double dPriority = vecPriority.front().get<0>(); - CFeeRate feeRate = vecPriority.front().get<1>(); - const CTransaction& tx = *(vecPriority.front().get<2>()); - - std::pop_heap(vecPriority.begin(), vecPriority.end(), comparer); - vecPriority.pop_back(); - - // Size limits - unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); - if (nBlockSize + nTxSize >= nBlockMaxSize-512) // room for extra autotx - { - //fprintf(stderr,"nBlockSize %d + %d nTxSize >= %d nBlockMaxSize\n",(int32_t)nBlockSize,(int32_t)nTxSize,(int32_t)nBlockMaxSize); - continue; - } - - // Legacy limits on sigOps: - unsigned int nTxSigOps = GetLegacySigOpCount(tx); - if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1) - { - //fprintf(stderr,"A nBlockSigOps %d + %d nTxSigOps >= %d MAX_BLOCK_SIGOPS-1\n",(int32_t)nBlockSigOps,(int32_t)nTxSigOps,(int32_t)MAX_BLOCK_SIGOPS); - continue; - } - // Skip free transactions if we're past the minimum block size: - const uint256& hash = tx.GetHash(); - double dPriorityDelta = 0; - CAmount nFeeDelta = 0; - mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta); - if (fSortedByFee && (dPriorityDelta <= 0) && (nFeeDelta <= 0) && (feeRate < ::minRelayTxFee) && (nBlockSize + nTxSize >= nBlockMinSize)) - { - //fprintf(stderr,"fee rate skip\n"); - continue; - } - // Prioritise by fee once past the priority size or we run out of high-priority - // transactions: - if (!fSortedByFee && - ((nBlockSize + nTxSize >= nBlockPrioritySize) || !AllowFree(dPriority))) - { - fSortedByFee = true; - comparer = TxPriorityCompare(fSortedByFee); - std::make_heap(vecPriority.begin(), vecPriority.end(), comparer); - } - - if (!view.HaveInputs(tx)) - { - //fprintf(stderr,"dont have inputs\n"); - continue; - } - CAmount nTxFees = view.GetValueIn(chainActive.LastTip()->GetHeight(),&interest,tx,chainActive.LastTip()->nTime)-tx.GetValueOut(); - - nTxSigOps += GetP2SHSigOpCount(tx, view); - if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1) - { - //fprintf(stderr,"B nBlockSigOps %d + %d nTxSigOps >= %d MAX_BLOCK_SIGOPS-1\n",(int32_t)nBlockSigOps,(int32_t)nTxSigOps,(int32_t)MAX_BLOCK_SIGOPS); - continue; - } - // Note that flags: we don't want to set mempool/IsStandard() - // policy here, but we still have to ensure that the block we - // create only contains transactions that are valid in new blocks. - CValidationState state; - PrecomputedTransactionData txdata(tx); - if (!ContextualCheckInputs(tx, state, view, true, MANDATORY_SCRIPT_VERIFY_FLAGS, true, txdata, Params().GetConsensus(), consensusBranchId)) - { - //fprintf(stderr,"context failure\n"); - continue; - } - UpdateCoins(tx, view, nHeight); - - BOOST_FOREACH(const OutputDescription &outDescription, tx.vShieldedOutput) { - sapling_tree.append(outDescription.cm); - } - - // Added - pblock->vtx.push_back(tx); - pblocktemplate->vTxFees.push_back(nTxFees); - pblocktemplate->vTxSigOps.push_back(nTxSigOps); - nBlockSize += nTxSize; - ++nBlockTx; - nBlockSigOps += nTxSigOps; - nFees += nTxFees; - - if (fPrintPriority) - { - LogPrintf("priority %.1f fee %s txid %s\n",dPriority, feeRate.ToString(), tx.GetHash().ToString()); - } - - // Add transactions that depend on this one to the priority queue - if (mapDependers.count(hash)) - { - BOOST_FOREACH(COrphan* porphan, mapDependers[hash]) - { - if (!porphan->setDependsOn.empty()) + dPriority += (double)nValueIn * 1000; // flat multiplier + } else { + BOOST_FOREACH(const CTxIn& txin, tx.vin) { - porphan->setDependsOn.erase(hash); - if (porphan->setDependsOn.empty()) + // Read prev transaction + if (!view.HaveCoins(txin.prevout.hash)) { - vecPriority.push_back(TxPriority(porphan->dPriority, porphan->feeRate, porphan->ptx)); - std::push_heap(vecPriority.begin(), vecPriority.end(), comparer); + // This should never happen; all transactions in the memory + // pool should connect to either transactions in the chain + // or other transactions in the memory pool. + if (!mempool.mapTx.count(txin.prevout.hash)) + { + LogPrintf("ERROR: mempool transaction missing input\n"); + if (fDebug) assert("mempool transaction missing input" == 0); + fMissingInputs = true; + if (porphan) + vOrphan.pop_back(); + break; + } + + // Has to wait for dependencies + if (!porphan) + { + // Use list for automatic deletion + vOrphan.push_back(COrphan(&tx)); + porphan = &vOrphan.back(); + } + mapDependers[txin.prevout.hash].push_back(porphan); + porphan->setDependsOn.insert(txin.prevout.hash); + nTotalIn += mempool.mapTx.find(txin.prevout.hash)->GetTx().vout[txin.prevout.n].nValue; + continue; + } + const CCoins* coins = view.AccessCoins(txin.prevout.hash); + assert(coins); + + CAmount nValueIn = coins->vout[txin.prevout.n].nValue; + nTotalIn += nValueIn; + + int nConf = nHeight - coins->nHeight; + + dPriority += (double)nValueIn * nConf; + } + nTotalIn += tx.GetShieldedValueIn(); + } + + if (fMissingInputs) continue; + + // Priority is sum(valuein * age) / modified_txsize + unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); + dPriority = tx.ComputePriority(dPriority, nTxSize); + + uint256 hash = tx.GetHash(); + mempool.ApplyDeltas(hash, dPriority, nTotalIn); + + CFeeRate feeRate(nTotalIn-tx.GetValueOut(), nTxSize); + + if (porphan) + { + porphan->dPriority = dPriority; + porphan->feeRate = feeRate; + } + else + vecPriority.push_back(TxPriority(dPriority, feeRate, &(mi->GetTx()))); + } + + // Collect transactions into block + uint64_t nBlockSize = 1000; + uint64_t nBlockTx = 0; + int64_t interest; + int nBlockSigOps = 100; + bool fSortedByFee = (nBlockPrioritySize <= 0); + + TxPriorityCompare comparer(fSortedByFee); + std::make_heap(vecPriority.begin(), vecPriority.end(), comparer); + + while (!vecPriority.empty()) + { + // Take highest priority transaction off the priority queue: + double dPriority = vecPriority.front().get<0>(); + CFeeRate feeRate = vecPriority.front().get<1>(); + const CTransaction& tx = *(vecPriority.front().get<2>()); + + std::pop_heap(vecPriority.begin(), vecPriority.end(), comparer); + vecPriority.pop_back(); + + // Size limits + unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); + if (nBlockSize + nTxSize >= nBlockMaxSize-512) // room for extra autotx + { + //fprintf(stderr,"nBlockSize %d + %d nTxSize >= %d nBlockMaxSize\n",(int32_t)nBlockSize,(int32_t)nTxSize,(int32_t)nBlockMaxSize); + continue; + } + + // Legacy limits on sigOps: + unsigned int nTxSigOps = GetLegacySigOpCount(tx); + if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1) + { + //fprintf(stderr,"A nBlockSigOps %d + %d nTxSigOps >= %d MAX_BLOCK_SIGOPS-1\n",(int32_t)nBlockSigOps,(int32_t)nTxSigOps,(int32_t)MAX_BLOCK_SIGOPS); + continue; + } + // Skip free transactions if we're past the minimum block size: + const uint256& hash = tx.GetHash(); + double dPriorityDelta = 0; + CAmount nFeeDelta = 0; + mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta); + if (fSortedByFee && (dPriorityDelta <= 0) && (nFeeDelta <= 0) && (feeRate < ::minRelayTxFee) && (nBlockSize + nTxSize >= nBlockMinSize)) + { + //fprintf(stderr,"fee rate skip\n"); + continue; + } + // Prioritise by fee once past the priority size or we run out of high-priority + // transactions: + if (!fSortedByFee && + ((nBlockSize + nTxSize >= nBlockPrioritySize) || !AllowFree(dPriority))) + { + fSortedByFee = true; + comparer = TxPriorityCompare(fSortedByFee); + std::make_heap(vecPriority.begin(), vecPriority.end(), comparer); + } + + if (!view.HaveInputs(tx)) + { + //fprintf(stderr,"dont have inputs\n"); + continue; + } + CAmount nTxFees = view.GetValueIn(chainActive.LastTip()->GetHeight(),&interest,tx,chainActive.LastTip()->nTime)-tx.GetValueOut(); + + nTxSigOps += GetP2SHSigOpCount(tx, view); + if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1) + { + //fprintf(stderr,"B nBlockSigOps %d + %d nTxSigOps >= %d MAX_BLOCK_SIGOPS-1\n",(int32_t)nBlockSigOps,(int32_t)nTxSigOps,(int32_t)MAX_BLOCK_SIGOPS); + continue; + } + // Note that flags: we don't want to set mempool/IsStandard() + // policy here, but we still have to ensure that the block we + // create only contains transactions that are valid in new blocks. + CValidationState state; + PrecomputedTransactionData txdata(tx); + if (!ContextualCheckInputs(tx, state, view, true, MANDATORY_SCRIPT_VERIFY_FLAGS, true, txdata, Params().GetConsensus(), consensusBranchId)) + { + //fprintf(stderr,"context failure\n"); + continue; + } + UpdateCoins(tx, view, nHeight); + + BOOST_FOREACH(const OutputDescription &outDescription, tx.vShieldedOutput) { + sapling_tree.append(outDescription.cm); + } + + // Added + pblock->vtx.push_back(tx); + pblocktemplate->vTxFees.push_back(nTxFees); + pblocktemplate->vTxSigOps.push_back(nTxSigOps); + nBlockSize += nTxSize; + ++nBlockTx; + nBlockSigOps += nTxSigOps; + nFees += nTxFees; + + if (fPrintPriority) + { + LogPrintf("priority %.1f fee %s txid %s\n",dPriority, feeRate.ToString(), tx.GetHash().ToString()); + } + + // Add transactions that depend on this one to the priority queue + if (mapDependers.count(hash)) + { + BOOST_FOREACH(COrphan* porphan, mapDependers[hash]) + { + if (!porphan->setDependsOn.empty()) + { + porphan->setDependsOn.erase(hash); + if (porphan->setDependsOn.empty()) + { + vecPriority.push_back(TxPriority(porphan->dPriority, porphan->feeRate, porphan->ptx)); + std::push_heap(vecPriority.begin(), vecPriority.end(), comparer); + } } } } } - } - nLastBlockTx = nBlockTx; - nLastBlockSize = nBlockSize; - blocktime = 1 + std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); - //pblock->nTime = blocktime + 1; - pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); + nLastBlockTx = nBlockTx; + nLastBlockSize = nBlockSize; + blocktime = 1 + std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + //pblock->nTime = blocktime + 1; + pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); + + } // contain lock to block generation only! int32_t stakeHeight = chainActive.Height() + 1; @@ -497,7 +502,6 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, //printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.LastTip()->GetHeight()+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13))); } else return(0); //fprintf(stderr,"no utxos eligible for staking\n"); } - // Create coinbase tx CMutableTransaction txNew = CreateNewContextualCMutableTransaction(consensusParams, nHeight); txNew.vin.resize(1); diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index a69a4ebb3..f024215b6 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -606,6 +606,51 @@ UniValue getblockhash(const UniValue& params, bool fHelp) return pblockindex->GetBlockHash().GetHex(); } +extern uint64_t ASSETCHAINS_STAKED; + +UniValue getlastsegidstakes(const UniValue& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "getlastsegidstakes depth\n" + "\nReturns object containing the counts of the last X blocks staked by each segid.\n" + "\nArguments:\n" + "1. depth (numeric, required) The amount of blocks to scan back." + "\nResult:\n" + "{\n" + " \"0\" : n, (numeric) number of stakes from segid 0 in the last X blocks.\n" + " .....\n" + "}\n" + "\nExamples:\n" + + HelpExampleCli("getlastsegidstakes", "1000") + + HelpExampleRpc("getlastsegidstakes", "1000") + ); + + if ( ASSETCHAINS_STAKED == 0 ) + throw runtime_error("Only applies to ac_staked chains\n"); + + LOCK(cs_main); + + int depth = params[0].get_int(); + int32_t segids[64] = {0}; + + for (int64_t i = chainActive.Height(); i > chainActive.Height()-depth; i--) + { + CBlockIndex* pblockindex = chainActive[i]; + if ( pblockindex->segid >= 0 ) + segids[pblockindex->segid] += 1; + } + + UniValue ret(UniValue::VOBJ); + for (int8_t i = 0; i < 64; i++) + { + char str[4]; + sprintf(str, "%d", i); + ret.push_back(Pair(str,segids[i])); + } + return ret; +} + /*uint256 _komodo_getblockhash(int32_t nHeight) { uint256 hash; @@ -859,7 +904,7 @@ UniValue kvsearch(const UniValue& params, bool fHelp) " \"currentheight\": xxxxx, (numeric) current height of the chain\n" " \"key\": \"xxxxx\", (string) key\n" " \"keylen\": xxxxx, (string) length of the key \n" - " \"owner\": \"xxxxx\" (string) hex string representing the owner of the key \n" + " \"owner\": \"xxxxx\" (string) hex string representing the owner of the key \n" " \"height\": xxxxx, (numeric) height the key was stored at\n" " \"expiration\": xxxxx, (numeric) height the key will expire\n" " \"flags\": x (numeric) 1 if the key was created with a password; 0 otherwise.\n" diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index c4eb16e0e..d09228bcc 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -74,6 +74,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "getblockheader", 1 }, { "gettransaction", 1 }, { "getrawtransaction", 1 }, + { "getlastsegidstakes", 0 }, { "createrawtransaction", 0 }, { "createrawtransaction", 1 }, { "createrawtransaction", 2 }, diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 8dd32ab6a..a4ec30b25 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -302,6 +302,7 @@ static const CRPCCommand vRPCCommands[] = { "blockchain", "getblockhashes", &getblockhashes, true }, { "blockchain", "getblockhash", &getblockhash, true }, { "blockchain", "getblockheader", &getblockheader, true }, + { "blockchain", "getlastsegidstakes", &getlastsegidstakes, true }, { "blockchain", "getchaintips", &getchaintips, true }, { "blockchain", "getdifficulty", &getdifficulty, true }, { "blockchain", "getmempoolinfo", &getmempoolinfo, true }, @@ -364,16 +365,16 @@ static const CRPCCommand vRPCCommands[] = // auction { "auction", "auctionaddress", &auctionaddress, true }, - + // lotto { "lotto", "lottoaddress", &lottoaddress, true }, - + // fsm { "FSM", "FSMaddress", &FSMaddress, true }, { "FSM", "FSMcreate", &FSMcreate, true }, { "FSM", "FSMlist", &FSMlist, true }, { "FSM", "FSMinfo", &FSMinfo, true }, - + // rewards { "rewards", "rewardslist", &rewardslist, true }, { "rewards", "rewardsinfo", &rewardsinfo, true }, @@ -382,7 +383,7 @@ static const CRPCCommand vRPCCommands[] = { "rewards", "rewardslock", &rewardslock, true }, { "rewards", "rewardsunlock", &rewardsunlock, true }, { "rewards", "rewardsaddress", &rewardsaddress, true }, - + // faucet { "faucet", "faucetinfo", &faucetinfo, true }, { "faucet", "faucetfund", &faucetfund, true }, @@ -400,7 +401,7 @@ static const CRPCCommand vRPCCommands[] = { "channels", "channelspayment", &channelspayment, true }, { "channels", "channelsclose", &channelsclose, true }, { "channels", "channelsrefund", &channelsrefund, true }, - + // Oracles { "oracles", "oraclesaddress", &oraclesaddress, true }, { "oracles", "oracleslist", &oracleslist, true }, diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 41d0242a1..c3cb0ebc2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1674,7 +1674,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe if(involvesWatchonly || (::IsMine(*pwalletMain, r.destination) & ISMINE_WATCH_ONLY)) entry.push_back(Pair("involvesWatchonly", true)); entry.push_back(Pair("account", account)); - + CTxDestination dest; if (CScriptExt::ExtractVoutDestination(wtx, r.vout, dest)) MaybePushAddress(entry, dest); @@ -2920,11 +2920,11 @@ UniValue z_listunspent(const UniValue& params, bool fHelp) // User did not provide zaddrs, so use default i.e. all addresses std::set sproutzaddrs = {}; pwalletMain->GetSproutPaymentAddresses(sproutzaddrs); - + // Sapling support std::set saplingzaddrs = {}; pwalletMain->GetSaplingPaymentAddresses(saplingzaddrs); - + zaddrs.insert(sproutzaddrs.begin(), sproutzaddrs.end()); zaddrs.insert(saplingzaddrs.begin(), saplingzaddrs.end()); } @@ -2936,7 +2936,7 @@ UniValue z_listunspent(const UniValue& params, bool fHelp) std::vector saplingEntries; pwalletMain->GetFilteredNotes(sproutEntries, saplingEntries, zaddrs, nMinDepth, nMaxDepth, true, !fIncludeWatchonly, false); std::set> nullifierSet = pwalletMain->GetNullifiersForAddresses(zaddrs); - + for (auto & entry : sproutEntries) { UniValue obj(UniValue::VOBJ); obj.push_back(Pair("txid", entry.jsop.hash.ToString())); @@ -2954,7 +2954,7 @@ UniValue z_listunspent(const UniValue& params, bool fHelp) } results.push_back(obj); } - + for (auto & entry : saplingEntries) { UniValue obj(UniValue::VOBJ); obj.push_back(Pair("txid", entry.op.hash.ToString())); @@ -4115,7 +4115,7 @@ UniValue z_sendmany(const UniValue& params, bool fHelp) } if ( toSapling && ASSETCHAINS_SYMBOL[0] == 0 ) throw JSONRPCError(RPC_INVALID_PARAMETER,"Sprout usage will expire soon"); - + // If we are sending from a shielded address, all recipient // shielded addresses must be of the same type. if ((fromSprout && toSapling) || (fromSapling && toSprout)) { @@ -4534,14 +4534,14 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; - + string enableArg = "zmergetoaddress"; 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" @@ -4590,33 +4590,33 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp) + 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 useAnyUTXO = false; bool useAnySprout = false; bool useAnySapling = false; std::set taddrs = {}; std::set zaddrs = {}; - + 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 setAddress; - + // Sources 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 == "ANY_TADDR") { useAnyUTXO = true; } else if (address == "ANY_SPROUT") { @@ -4636,23 +4636,23 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp) } } } - + 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 isToSproutZaddr = false; @@ -4674,7 +4674,7 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, unknown address format: ") + destaddress ); } } - + // Convert fee from currency format to zatoshis CAmount nFee = SHIELD_COINBASE_DEFAULT_MINERS_FEE; if (params.size() > 2) { @@ -4684,7 +4684,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(); @@ -4692,7 +4692,7 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_INVALID_PARAMETER, "Limit on maximum number of UTXOs cannot be negative"); } } - + int sproutNoteLimit = MERGE_TO_ADDRESS_DEFAULT_SPROUT_LIMIT; int saplingNoteLimit = MERGE_TO_ADDRESS_DEFAULT_SAPLING_LIMIT; if (params.size() > 4) { @@ -4703,7 +4703,7 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp) sproutNoteLimit = nNoteLimit; saplingNoteLimit = nNoteLimit; } - + std::string memo; if (params.size() > 5) { memo = params[5].get_str(); @@ -4716,9 +4716,9 @@ 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); - + // Prepare to get UTXOs and notes std::vector utxoInputs; std::vector sproutNoteInputs; @@ -4732,7 +4732,7 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp) 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 (isToSproutZaddr) { @@ -4740,20 +4740,20 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp) } else if (isToSaplingZaddr) { estimatedTxSize += OUTPUTDESCRIPTION_SIZE; } - + if (useAnyUTXO || taddrs.size() > 0) { // Get available utxos vector 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(scriptPubKey, address)) { continue; @@ -4762,10 +4762,10 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp) if (taddrs.size() > 0 && !taddrs.count(address)) { continue; } - + utxoCounter++; CAmount nValue = out.tx->vout[out.i].nValue; - + if (!maxedOutUTXOsFlag) { size_t increase = (boost::get(&address) != nullptr) ? CTXIN_SPEND_P2SH_SIZE : CTXIN_SPEND_DUST_SIZE; if (estimatedTxSize + increase >= max_tx_size || @@ -4779,19 +4779,19 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp) mergedUTXOValue += nValue; } } - + if (maxedOutUTXOsFlag) { remainingUTXOValue += nValue; } } } - + if (useAnySprout || useAnySapling || zaddrs.size() > 0) { // Get available notes std::vector sproutEntries,skipsprout; std::vector saplingEntries,skipsapling; pwalletMain->GetFilteredNotes(sproutEntries, useAnySprout == 0 ? saplingEntries : skipsapling, 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"); @@ -4808,12 +4808,12 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp) RPC_INVALID_PARAMETER, "Cannot send between Sprout and Sapling addresses using z_mergetoaddress"); } - + // Find unspent notes and update estimated size 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. @@ -4831,12 +4831,12 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp) mergedNoteValue += nValue; } } - + if (maxedOutNotesFlag) { remainingNoteValue += nValue; } } - + for (const SaplingNoteEntry& entry : saplingEntries) { noteCounter++; CAmount nValue = entry.note.value(); @@ -4856,20 +4856,20 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp) mergedNoteValue += nValue; } } - + if (maxedOutNotesFlag) { remainingNoteValue += nValue; } } } - + size_t numUtxos = utxoInputs.size(); 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 @@ -4877,26 +4877,26 @@ 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))); } - + // 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(), @@ -4905,7 +4905,7 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp) if (contextualTx.nVersion == 1 && isSproutShielded) { contextualTx.nVersion = 2; // Tx format should support vjoinsplit } - + // Builder (used if Sapling addresses are involved) boost::optional builder; if (isToSaplingZaddr || saplingNoteInputs.size() > 0) { @@ -4917,7 +4917,7 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp) 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(utxoCounter - numUtxos))); @@ -5066,247 +5066,6 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) return(siglen); } -struct komodo_staking -{ - char address[64]; - uint256 txid; - arith_uint256 hashval; - uint64_t nValue; - uint32_t segid32,txtime; - int32_t vout; - CScript scriptPubKey; -}; - -struct komodo_staking *komodo_addutxo(struct komodo_staking *array,int32_t *numkp,int32_t *maxkp,uint32_t txtime,uint64_t nValue,uint256 txid,int32_t vout,char *address,uint8_t *hashbuf,CScript pk) -{ - uint256 hash; uint32_t segid32; struct komodo_staking *kp; - segid32 = komodo_stakehash(&hash,address,hashbuf,txid,vout); - if ( *numkp >= *maxkp ) - { - *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; - kp->vout = vout; - kp->hashval = UintToArith256(hash); - kp->txtime = txtime; - kp->segid32 = segid32; - kp->nValue = nValue; - kp->scriptPubKey = pk; - return(array); -} - -arith_uint256 _komodo_eligible(struct komodo_staking *kp,arith_uint256 ratio,uint32_t blocktime,int32_t iter,int32_t minage,int32_t segid,int32_t nHeight,uint32_t prevtime) -{ - int32_t diff; uint64_t coinage; arith_uint256 coinage256,hashval; - diff = (iter + blocktime - kp->txtime - minage); - if ( diff < 0 ) - diff = 60; - else if ( diff > 3600*24*30 ) - diff = 3600*24*30; - if ( iter > 0 ) - diff += segid*2; - coinage = ((uint64_t)kp->nValue * diff); - if ( blocktime+iter+segid*2 > prevtime+480 ) - coinage *= ((blocktime+iter+segid*2) - (prevtime+400)); - coinage256 = arith_uint256(coinage+1); - hashval = ratio * (kp->hashval / coinage256); - return(hashval); -} - -uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komodo_staking *kp,int32_t nHeight,uint32_t blocktime,uint32_t prevtime,int32_t minage,uint8_t *hashbuf) -{ - int32_t maxiters = 600; uint256 hash; - int32_t segid,iter,diff; uint64_t coinage; arith_uint256 hashval,coinage256; - komodo_stakehash(&hash,kp->address,hashbuf,kp->txid,kp->vout); - kp->hashval = UintToArith256(hash); - segid = ((nHeight + kp->segid32) & 0x3f); - hashval = _komodo_eligible(kp,ratio,blocktime,maxiters,minage,segid,nHeight,prevtime); - //for (int i=32; i>=0; i--) - // fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); - //fprintf(stderr," b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime); - if ( hashval <= bnTarget ) - { - for (iter=0; itertxtime+minage ) - continue; - hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime); - if ( hashval <= bnTarget ) - { - //fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid); - blocktime += iter; - blocktime += segid * 2; - return(blocktime); - } - } - } else fprintf(stderr,"maxiters is not good enough\n"); - return(0); -} - -int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) -{ - static struct komodo_staking *array; static int32_t numkp,maxkp; static uint32_t lasttime; - set setAddress; struct komodo_staking *kp; int32_t winners,segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t block_from_future_rejecttime,besttime,eligible,eligible2,earliest = 0; CScript best_scriptPubKey; arith_uint256 mindiff,ratio,bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock; - if (!EnsureWalletIsAvailable(0)) - return 0; - - bnTarget.SetCompact(nBits, &fNegative, &fOverflow); - mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - ratio = (mindiff / bnTarget); - assert(pwalletMain != NULL); - LOCK2(cs_main, pwalletMain->cs_wallet); - *utxovaluep = 0; - memset(utxotxidp,0,sizeof(*utxotxidp)); - memset(utxovoutp,0,sizeof(*utxovoutp)); - memset(utxosig,0,72); - pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); - if ( (tipindex= chainActive.Tip()) == 0 ) - return(0); - nHeight = tipindex->GetHeight() + 1; - if ( (minage= nHeight*3) > 6000 ) // about 100 blocks - minage = 6000; - komodo_segids(hashbuf,nHeight-101,100); - 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 || array == 0 ) - { - if ( array != 0 ) - { - free(array); - array = 0; - maxkp = numkp = 0; - lasttime = 0; - } - BOOST_FOREACH(const COutput& out, vecOutputs) - { - if ( (tipindex= chainActive.Tip()) == 0 || tipindex->GetHeight()+1 > nHeight ) - { - fprintf(stderr,"chain tip changed during staking loop t.%u counter.%d\n",(uint32_t)time(NULL),counter); - return(0); - } - counter++; - if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth ) - { - fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth); - continue; - } - CAmount nValue = out.tx->vout[out.i].nValue; - if ( nValue < COIN || !out.fSpendable ) - continue; - const CScript& pk = out.tx->vout[out.i].scriptPubKey; - if ( ExtractDestination(pk,address) != 0 ) - { - if ( IsMine(*pwalletMain,address) == 0 ) - continue; - 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,"numkp.%d blocktime.%u\n",numkp,*blocktimep); - block_from_future_rejecttime = (uint32_t)GetAdjustedTime() + 57; - for (i=winners=0; iGetHeight()+1 > nHeight ) - { - fprintf(stderr,"chain tip changed during staking loop t.%u counter.%d\n",(uint32_t)time(NULL),counter); - return(0); - } - kp = &array[i]; - 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); - if ( eligible > 0 ) - { - besttime = m = 0; - if ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address) ) - { - while ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address) ) - { - besttime = eligible; - eligible--; - 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); - } - } - else - { - fprintf(stderr,"ht.%d error validating winning blocktime %u -> %.8f eligible.%u test prior\n",nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); - continue; - } - 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); - if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || kp->nValue < *utxovaluep)) ) - { - earliest = eligible; - best_scriptPubKey = kp->scriptPubKey; //out.tx->vout[out.i].scriptPubKey; - *utxovaluep = (uint64_t)kp->nValue; - //decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); - decode_hex((uint8_t *)utxotxidp,32,(char *)kp->txid.GetHex().c_str()); - *utxovoutp = kp->vout; - *txtimep = kp->txtime;//(uint32_t)out.tx->nLockTime; - 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"); - } - if ( numkp < 10000 && array != 0 ) - { - free(array); - array = 0; - maxkp = numkp = 0; - lasttime = 0; - } - if ( earliest != 0 ) - { - bool signSuccess; SignatureData sigdata; uint64_t txfee; uint8_t *ptr; uint256 revtxid,utxotxid; - auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); - const CKeyStore& keystore = *pwalletMain; - txNew.vin.resize(1); - txNew.vout.resize(1); - txfee = 0; - for (i=0; i<32; i++) - ((uint8_t *)&revtxid)[i] = ((uint8_t *)utxotxidp)[31 - i]; - txNew.vin[0].prevout.hash = revtxid; - txNew.vin[0].prevout.n = *utxovoutp; - txNew.vout[0].scriptPubKey = best_scriptPubKey;// CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; - txNew.vout[0].nValue = *utxovaluep - txfee; - txNew.nLockTime = earliest; - CTransaction txNewConst(txNew); - signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, *utxovaluep, SIGHASH_ALL), best_scriptPubKey, sigdata, consensusBranchId); - if (!signSuccess) - fprintf(stderr,"failed to create signature\n"); - else - { - UpdateTransaction(txNew,0,sigdata); - ptr = (uint8_t *)&sigdata.scriptSig[0]; - siglen = sigdata.scriptSig.size(); - for (i=0; iVerusStakeTransaction(pBlock, txNew, nBits, hashResult, utxosig, pk); @@ -5677,7 +5436,7 @@ UniValue channelslist(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 0 ) throw runtime_error("channelsinfo\n"); if ( ensure_CCrequirements() < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); return(ChannelsList()); } @@ -6027,7 +5786,7 @@ UniValue gatewaysbind(const UniValue& params, bool fHelp) if ( params.size() < 6+i+1 ) throw runtime_error("not enough parameters for N pubkeys\n"); pubkey = ParseHex(params[6+i].get_str().c_str()); - if (pubkey.size()!= 33) + if (pubkey.size()!= 33) throw runtime_error("invalid destination pubkey"); pubkeys.push_back(pubkey2pk(pubkey)); } @@ -6061,8 +5820,8 @@ UniValue gatewaysdeposit(const UniValue& params, bool fHelp) amount = atof((char *)params[8].get_str().c_str()) * COIN + 0.00000000499999; if ( amount <= 0 || claimvout < 0 ) throw runtime_error("invalid param: amount, numpks or claimvout\n"); - if (destpub.size()!= 33) - throw runtime_error("invalid destination pubkey"); + if (destpub.size()!= 33) + throw runtime_error("invalid destination pubkey"); hex = GatewaysDeposit(0,bindtxid,height,coin,cointxid,claimvout,deposithex,proof,pubkey2pk(destpub),amount); RETURN_IF_ERROR(CCerror); @@ -6087,9 +5846,9 @@ UniValue gatewaysclaim(const UniValue& params, bool fHelp) coin = params[1].get_str(); deposittxid = Parseuint256((char *)params[2].get_str().c_str()); destpub = ParseHex(params[3].get_str()); - amount = atof((char *)params[4].get_str().c_str()) * COIN + 0.00000000499999; - if (destpub.size()!= 33) - throw runtime_error("invalid destination pubkey"); + amount = atof((char *)params[4].get_str().c_str()) * COIN + 0.00000000499999; + if (destpub.size()!= 33) + throw runtime_error("invalid destination pubkey"); hex = GatewaysClaim(0,bindtxid,coin,deposittxid,pubkey2pk(destpub),amount); RETURN_IF_ERROR(CCerror); if ( hex.size() > 0 ) @@ -6112,9 +5871,9 @@ UniValue gatewayswithdraw(const UniValue& params, bool fHelp) bindtxid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); withdrawpub = ParseHex(params[2].get_str()); - amount = atof((char *)params[3].get_str().c_str()) * COIN + 0.00000000499999; - if (withdrawpub.size()!= 33) - throw runtime_error("invalid destination pubkey"); + amount = atof((char *)params[3].get_str().c_str()) * COIN + 0.00000000499999; + if (withdrawpub.size()!= 33) + throw runtime_error("invalid destination pubkey"); hex = GatewaysWithdraw(0,bindtxid,coin,pubkey2pk(withdrawpub),amount); RETURN_IF_ERROR(CCerror); if ( hex.size() > 0 ) @@ -6133,7 +5892,7 @@ UniValue gatewayspartialsign(const UniValue& params, bool fHelp) if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + LOCK2(cs_main, pwalletMain->cs_wallet); txid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); parthex = params[2].get_str(); @@ -6178,7 +5937,7 @@ UniValue gatewaysmarkdone(const UniValue& params, bool fHelp) const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); completetxid = Parseuint256((char *)params[0].get_str().c_str()); - coin = params[1].get_str(); + coin = params[1].get_str(); hex = GatewaysMarkDone(0,completetxid,coin); RETURN_IF_ERROR(CCerror); if ( hex.size() > 0 ) @@ -7182,7 +6941,7 @@ UniValue tokenfillask(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); tokenid = Parseuint256((char *)params[0].get_str().c_str()); asktxid = Parseuint256((char *)params[1].get_str().c_str()); - //fillunits = atol(params[2].get_str().c_str()); + //fillunits = atol(params[2].get_str().c_str()); fillunits = atoll(params[2].get_str().c_str()); // dimxy changed to prevent loss of significance if ( fillunits <= 0 ) { From 5bcdcf0a7502e48858be04c579f18f4d35f7f31f Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 20 Dec 2018 21:23:56 +0800 Subject: [PATCH 031/643] fix build --- src/komodo_bitcoind.h | 1 + src/rpc/server.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 4b47d0682..816cab09d 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -21,6 +21,7 @@ #include "consensus/params.h" #include "komodo_defs.h" #include "script/standard.h" +#include "cc/CCinclude.h" int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp); int32_t komodo_electednotary(int32_t *numnotariesp,uint8_t *pubkey33,int32_t height,uint32_t timestamp); diff --git a/src/rpc/server.h b/src/rpc/server.h index a129c21c0..7a8ed75e3 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -383,6 +383,7 @@ extern UniValue getblockhashes(const UniValue& params, bool fHelp); extern UniValue getblockdeltas(const UniValue& params, bool fHelp); extern UniValue getblockhash(const UniValue& params, bool fHelp); extern UniValue getblockheader(const UniValue& params, bool fHelp); +extern UniValue getlastsegidstakes(const UniValue& params, bool fHelp); extern UniValue getblock(const UniValue& params, bool fHelp); extern UniValue gettxoutsetinfo(const UniValue& params, bool fHelp); extern UniValue gettxout(const UniValue& params, bool fHelp); From 254467774ea75c77c488852414b4d3c003736bda Mon Sep 17 00:00:00 2001 From: Mihail Fedorov Date: Fri, 21 Dec 2018 01:12:53 +0300 Subject: [PATCH 032/643] KSB --- src/ac/ksb | 2 + src/assetchains.json | 11 +- src/assetchains.old | 1 + src/fiat/ksb | 2 + src/fundnotaries | 705 ------------------------------------------- 5 files changed, 15 insertions(+), 706 deletions(-) create mode 100755 src/ac/ksb create mode 100755 src/fiat/ksb delete mode 100755 src/fundnotaries diff --git a/src/ac/ksb b/src/ac/ksb new file mode 100755 index 000000000..450c3b3f6 --- /dev/null +++ b/src/ac/ksb @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=KSB $1 $2 $3 $4 $5 $6 diff --git a/src/assetchains.json b/src/assetchains.json index 1a0ae25e2..1b23bc616 100644 --- a/src/assetchains.json +++ b/src/assetchains.json @@ -215,5 +215,14 @@ "addnode": [ "5.9.102.210" ] - } + }, + { + "ac_name": "KSB", + "ac_supply": "1000000000", + "ac_end": "1", + "ac_public": "1", + "addnode": [ + "37.187.225.231" + ] + } ] diff --git a/src/assetchains.old b/src/assetchains.old index 6df854903..ede6c3e23 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -45,3 +45,4 @@ echo $pubkey ./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 & +./komodod -pubkey=$pubkey -ac_name=KSB -ac_supply=1000000000 -ac_end=1 -ac_public=1 -addnode=37.187.225.231 diff --git a/src/fiat/ksb b/src/fiat/ksb new file mode 100755 index 000000000..450c3b3f6 --- /dev/null +++ b/src/fiat/ksb @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=KSB $1 $2 $3 $4 $5 $6 diff --git a/src/fundnotaries b/src/fundnotaries deleted file mode 100755 index cd6841966..000000000 --- a/src/fundnotaries +++ /dev/null @@ -1,705 +0,0 @@ -./komodo-cli -ac_name=REVS sendtoaddress RNJmgYaFF5DbnrNUX6pMYz9rcnDKC2tuAc 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RDhEGYScNQYetCyG75Kf8Fg61UWPdwc1C5 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RHPGxpiwRHP4dKZXjYPdpon1nCto7qVE8s 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RLQoAcs1RaqW1xfN2NJwoZWW5twexPhuGB 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RXF3aHUaWDUY4fRRYmBNALoHWkgSQCiJ4f 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RL2SkPSCGMvcHqZ56ErfMxbQGdA4nk7MZp 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RFssbc211PJdVy1bvcvAG5X2N4ovPAoy5o 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RNoz2DKPZ2ppMxgYx5tce9sjZBHefvPvNB 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RVxtoUT9CXbC1LdhztNAf9yR5ySnFnSPQh 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress R9XBrbj8iKkwy9M4erUqRaBinAiZSTXav3 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RSHdRnHHGdPtVej7fiehHBQ6dyTbEM1GHi 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RDW8EDkCkzQ1LA4xbVUoAERsBVhhYRLXCr 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RAxQTHdsy89tfSXwoce2sHeWrYXmDsMXQq 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RT2k2voy9n8jwppeTTJMQAhvaqA9pc9jHh 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RRvaVyKS59NJWhPp8Pn7mVPGhMuhJJXrdh 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RBpp98VwHx7SFv7dNbw8NY65t14XFq9fVD 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RPjUmFNcWEW9Bu275kPxzRXyWDz6bfQpPD 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RDY2CvzydimY2AtDqSjBAB1eCeogRE55DX 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RUgW6fLfVsLJ87Ng4zJTqNedJSKYQ9ToAf 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RUreYvNjhZYc1vP8cND9Cztpni1pYsigXb 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RHv3wyVnnanG2kSQmLNmjwAQeYRRAptxUy 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RLVwuTM5TitV4Gk79Rja731RwYkAzz7GWn 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RHbxwDa7JT1KJLHDKwb5n3gd8NREErqtQY 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RFDAZ1yCvKPmpqcgzg8r2qQJ8nPPgeoMrB 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RHsZesZXMfkdrsSEper3JWUBKwk29JTFfT 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RPJjzoKPb8idoUCT9XLBkNojNgysjJ5qrE 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RFQNjTfcvSAmf8D83og1NrdHj1wH2fc5X4 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RPknkGAHMwUBvfKQfvw9FyatTZzicSiN4y 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RMqbQz4NPNbG15QBwy9EFvLn4NX5Fa7w5g 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RQipE6ycbVVb9vCkhqrK8PGZs2p5YmiBtg 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RCA8H1npFPW5pnJRzycF8tFEJmn6XZhD4j 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RJD5jRidYW9Cu8qxjg9HDCsx6J3A4wQ4LU 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RQMwcDYMVBx9f4QCFfFk31px8QZP4e8uhA 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RXzsovGBQ3W97xnVC6JnWxXsV4qb7p7iBi 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RLHr8gUm2MZ3EEgDU4EmK7bdn5ZsxLYmnt 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RFTsWSzgKRd5Xa7d287w9eRFeYefKBso6Z 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress REuQ7EoxKeMYk4EGptV6EwdfV9LZXuc44g 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RX1tP6ftwe96p6scgJn4dpgNdHDgyg9R87 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RERp696QtNTeWDfBy3x3QbRwPYN2NxwxfA 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RNZKqUgoAPwWd7wNtuSKP7k1HSJAyPeH4N 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress R9jhJCwgT78pyjnkNuxgH3CE8ekxgT8iwB 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RSCQKVUhihKb13rb5VJwXsbSY6pdRPUZ6V 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RDVqM6t5xZw9jbYXEw2CJgkiSbrHBHiKR3 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RSSNgf98kiMGUxs55DvhNnumyxVudd2KQQ 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RXqdRmv7n9hygf9C7f7vj4VQyNR9RvzXss 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RE3P8D8rcWZBeKmT8DURPdezW87MU5Ho3F 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RS3v2u6d4SJ1ujLz7CHNSFLSmxn6Tx6mJp 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RREc88bQzxHCvzqErPDnTQH2Qg5yUtjbyp 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RJ9wAk3ZNrFwdso1RVbwASiqqQaDNyKjd2 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RVKtRKozg8RKvEYCumMD43fCU6f212M5RD 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RCvsbvzCwA1AaxeoYVSL9Q3BdnybEWfXaH 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RXtADsErZLmsGhNyQdW2DekHMGZ23cLrav 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RYGrWs5b8CVFFpxGpjiBaMwfYV9X5UqFaB 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RHASfhhM6bvDFakRDqkzA2wc3V4R4oNmXi 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RATaU3jjn4RwHK61YWoJ4eg7Eggk3puZW8 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RXbb9PkefXcsqq8wqiUZZUuq8e3p29mw1G 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RDY9LJZTEJ9FsvugUuD69gceA98uqan5XL 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress R9tjkpdNbzw6mNfxorb5bvTPmsuon5aLrC 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RT2JyVts5tb1prC7KYykmznrqw7VXJo1HB 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RFHRWQ5pAXNfmudHfxdxw3Wo8yFGoeDn6z 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RTw3vi3dGa9n8LLbKvk7jDAwLdt3A5ET7a 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RQeuhk4KcPM3F5hefwTBWezDdcktSGQQSq 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress R9TGdzN25MgdRkYfsYfxZWzHCLVCyWFAei 0.010000 -./komodo-cli -ac_name=REVS sendtoaddress RDYsrWBZkYSWhRDupGRrfGqrVnFtK9hJGC 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RNJmgYaFF5DbnrNUX6pMYz9rcnDKC2tuAc 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RDhEGYScNQYetCyG75Kf8Fg61UWPdwc1C5 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RHPGxpiwRHP4dKZXjYPdpon1nCto7qVE8s 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RLQoAcs1RaqW1xfN2NJwoZWW5twexPhuGB 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RXF3aHUaWDUY4fRRYmBNALoHWkgSQCiJ4f 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RL2SkPSCGMvcHqZ56ErfMxbQGdA4nk7MZp 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RFssbc211PJdVy1bvcvAG5X2N4ovPAoy5o 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RNoz2DKPZ2ppMxgYx5tce9sjZBHefvPvNB 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RVxtoUT9CXbC1LdhztNAf9yR5ySnFnSPQh 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress R9XBrbj8iKkwy9M4erUqRaBinAiZSTXav3 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RSHdRnHHGdPtVej7fiehHBQ6dyTbEM1GHi 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RDW8EDkCkzQ1LA4xbVUoAERsBVhhYRLXCr 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RAxQTHdsy89tfSXwoce2sHeWrYXmDsMXQq 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RT2k2voy9n8jwppeTTJMQAhvaqA9pc9jHh 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RRvaVyKS59NJWhPp8Pn7mVPGhMuhJJXrdh 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RBpp98VwHx7SFv7dNbw8NY65t14XFq9fVD 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RPjUmFNcWEW9Bu275kPxzRXyWDz6bfQpPD 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RDY2CvzydimY2AtDqSjBAB1eCeogRE55DX 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RUgW6fLfVsLJ87Ng4zJTqNedJSKYQ9ToAf 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RUreYvNjhZYc1vP8cND9Cztpni1pYsigXb 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RHv3wyVnnanG2kSQmLNmjwAQeYRRAptxUy 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RLVwuTM5TitV4Gk79Rja731RwYkAzz7GWn 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RHbxwDa7JT1KJLHDKwb5n3gd8NREErqtQY 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RFDAZ1yCvKPmpqcgzg8r2qQJ8nPPgeoMrB 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RHsZesZXMfkdrsSEper3JWUBKwk29JTFfT 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RPJjzoKPb8idoUCT9XLBkNojNgysjJ5qrE 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RFQNjTfcvSAmf8D83og1NrdHj1wH2fc5X4 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RPknkGAHMwUBvfKQfvw9FyatTZzicSiN4y 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RMqbQz4NPNbG15QBwy9EFvLn4NX5Fa7w5g 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RQipE6ycbVVb9vCkhqrK8PGZs2p5YmiBtg 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RCA8H1npFPW5pnJRzycF8tFEJmn6XZhD4j 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RJD5jRidYW9Cu8qxjg9HDCsx6J3A4wQ4LU 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RQMwcDYMVBx9f4QCFfFk31px8QZP4e8uhA 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RXzsovGBQ3W97xnVC6JnWxXsV4qb7p7iBi 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RLHr8gUm2MZ3EEgDU4EmK7bdn5ZsxLYmnt 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RFTsWSzgKRd5Xa7d287w9eRFeYefKBso6Z 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress REuQ7EoxKeMYk4EGptV6EwdfV9LZXuc44g 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RX1tP6ftwe96p6scgJn4dpgNdHDgyg9R87 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RERp696QtNTeWDfBy3x3QbRwPYN2NxwxfA 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RNZKqUgoAPwWd7wNtuSKP7k1HSJAyPeH4N 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress R9jhJCwgT78pyjnkNuxgH3CE8ekxgT8iwB 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RSCQKVUhihKb13rb5VJwXsbSY6pdRPUZ6V 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RDVqM6t5xZw9jbYXEw2CJgkiSbrHBHiKR3 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RSSNgf98kiMGUxs55DvhNnumyxVudd2KQQ 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RXqdRmv7n9hygf9C7f7vj4VQyNR9RvzXss 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RE3P8D8rcWZBeKmT8DURPdezW87MU5Ho3F 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RS3v2u6d4SJ1ujLz7CHNSFLSmxn6Tx6mJp 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RREc88bQzxHCvzqErPDnTQH2Qg5yUtjbyp 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RJ9wAk3ZNrFwdso1RVbwASiqqQaDNyKjd2 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RVKtRKozg8RKvEYCumMD43fCU6f212M5RD 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RCvsbvzCwA1AaxeoYVSL9Q3BdnybEWfXaH 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RXtADsErZLmsGhNyQdW2DekHMGZ23cLrav 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RYGrWs5b8CVFFpxGpjiBaMwfYV9X5UqFaB 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RHASfhhM6bvDFakRDqkzA2wc3V4R4oNmXi 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RATaU3jjn4RwHK61YWoJ4eg7Eggk3puZW8 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RXbb9PkefXcsqq8wqiUZZUuq8e3p29mw1G 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RDY9LJZTEJ9FsvugUuD69gceA98uqan5XL 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress R9tjkpdNbzw6mNfxorb5bvTPmsuon5aLrC 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RT2JyVts5tb1prC7KYykmznrqw7VXJo1HB 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RFHRWQ5pAXNfmudHfxdxw3Wo8yFGoeDn6z 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RTw3vi3dGa9n8LLbKvk7jDAwLdt3A5ET7a 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RQeuhk4KcPM3F5hefwTBWezDdcktSGQQSq 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress R9TGdzN25MgdRkYfsYfxZWzHCLVCyWFAei 0.010000 -./komodo-cli -ac_name=SUPERNET sendtoaddress RDYsrWBZkYSWhRDupGRrfGqrVnFtK9hJGC 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RNJmgYaFF5DbnrNUX6pMYz9rcnDKC2tuAc 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RDhEGYScNQYetCyG75Kf8Fg61UWPdwc1C5 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RHPGxpiwRHP4dKZXjYPdpon1nCto7qVE8s 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RLQoAcs1RaqW1xfN2NJwoZWW5twexPhuGB 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RXF3aHUaWDUY4fRRYmBNALoHWkgSQCiJ4f 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RL2SkPSCGMvcHqZ56ErfMxbQGdA4nk7MZp 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RFssbc211PJdVy1bvcvAG5X2N4ovPAoy5o 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RNoz2DKPZ2ppMxgYx5tce9sjZBHefvPvNB 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RVxtoUT9CXbC1LdhztNAf9yR5ySnFnSPQh 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress R9XBrbj8iKkwy9M4erUqRaBinAiZSTXav3 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RSHdRnHHGdPtVej7fiehHBQ6dyTbEM1GHi 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RDW8EDkCkzQ1LA4xbVUoAERsBVhhYRLXCr 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RAxQTHdsy89tfSXwoce2sHeWrYXmDsMXQq 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RT2k2voy9n8jwppeTTJMQAhvaqA9pc9jHh 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RRvaVyKS59NJWhPp8Pn7mVPGhMuhJJXrdh 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RBpp98VwHx7SFv7dNbw8NY65t14XFq9fVD 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RPjUmFNcWEW9Bu275kPxzRXyWDz6bfQpPD 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RDY2CvzydimY2AtDqSjBAB1eCeogRE55DX 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RUgW6fLfVsLJ87Ng4zJTqNedJSKYQ9ToAf 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RUreYvNjhZYc1vP8cND9Cztpni1pYsigXb 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RHv3wyVnnanG2kSQmLNmjwAQeYRRAptxUy 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RLVwuTM5TitV4Gk79Rja731RwYkAzz7GWn 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RHbxwDa7JT1KJLHDKwb5n3gd8NREErqtQY 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RFDAZ1yCvKPmpqcgzg8r2qQJ8nPPgeoMrB 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RHsZesZXMfkdrsSEper3JWUBKwk29JTFfT 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RPJjzoKPb8idoUCT9XLBkNojNgysjJ5qrE 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RFQNjTfcvSAmf8D83og1NrdHj1wH2fc5X4 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RPknkGAHMwUBvfKQfvw9FyatTZzicSiN4y 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RMqbQz4NPNbG15QBwy9EFvLn4NX5Fa7w5g 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RQipE6ycbVVb9vCkhqrK8PGZs2p5YmiBtg 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RCA8H1npFPW5pnJRzycF8tFEJmn6XZhD4j 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RJD5jRidYW9Cu8qxjg9HDCsx6J3A4wQ4LU 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RQMwcDYMVBx9f4QCFfFk31px8QZP4e8uhA 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RXzsovGBQ3W97xnVC6JnWxXsV4qb7p7iBi 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RLHr8gUm2MZ3EEgDU4EmK7bdn5ZsxLYmnt 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RFTsWSzgKRd5Xa7d287w9eRFeYefKBso6Z 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress REuQ7EoxKeMYk4EGptV6EwdfV9LZXuc44g 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RX1tP6ftwe96p6scgJn4dpgNdHDgyg9R87 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RERp696QtNTeWDfBy3x3QbRwPYN2NxwxfA 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RNZKqUgoAPwWd7wNtuSKP7k1HSJAyPeH4N 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress R9jhJCwgT78pyjnkNuxgH3CE8ekxgT8iwB 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RSCQKVUhihKb13rb5VJwXsbSY6pdRPUZ6V 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RDVqM6t5xZw9jbYXEw2CJgkiSbrHBHiKR3 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RSSNgf98kiMGUxs55DvhNnumyxVudd2KQQ 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RXqdRmv7n9hygf9C7f7vj4VQyNR9RvzXss 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RE3P8D8rcWZBeKmT8DURPdezW87MU5Ho3F 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RS3v2u6d4SJ1ujLz7CHNSFLSmxn6Tx6mJp 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RREc88bQzxHCvzqErPDnTQH2Qg5yUtjbyp 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RJ9wAk3ZNrFwdso1RVbwASiqqQaDNyKjd2 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RVKtRKozg8RKvEYCumMD43fCU6f212M5RD 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RCvsbvzCwA1AaxeoYVSL9Q3BdnybEWfXaH 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RXtADsErZLmsGhNyQdW2DekHMGZ23cLrav 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RYGrWs5b8CVFFpxGpjiBaMwfYV9X5UqFaB 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RHASfhhM6bvDFakRDqkzA2wc3V4R4oNmXi 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RATaU3jjn4RwHK61YWoJ4eg7Eggk3puZW8 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RXbb9PkefXcsqq8wqiUZZUuq8e3p29mw1G 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RDY9LJZTEJ9FsvugUuD69gceA98uqan5XL 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress R9tjkpdNbzw6mNfxorb5bvTPmsuon5aLrC 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RT2JyVts5tb1prC7KYykmznrqw7VXJo1HB 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RFHRWQ5pAXNfmudHfxdxw3Wo8yFGoeDn6z 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RTw3vi3dGa9n8LLbKvk7jDAwLdt3A5ET7a 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RQeuhk4KcPM3F5hefwTBWezDdcktSGQQSq 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress R9TGdzN25MgdRkYfsYfxZWzHCLVCyWFAei 0.010000 -./komodo-cli -ac_name=DEX sendtoaddress RDYsrWBZkYSWhRDupGRrfGqrVnFtK9hJGC 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RNJmgYaFF5DbnrNUX6pMYz9rcnDKC2tuAc 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RDhEGYScNQYetCyG75Kf8Fg61UWPdwc1C5 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RHPGxpiwRHP4dKZXjYPdpon1nCto7qVE8s 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RLQoAcs1RaqW1xfN2NJwoZWW5twexPhuGB 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RXF3aHUaWDUY4fRRYmBNALoHWkgSQCiJ4f 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RL2SkPSCGMvcHqZ56ErfMxbQGdA4nk7MZp 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RFssbc211PJdVy1bvcvAG5X2N4ovPAoy5o 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RNoz2DKPZ2ppMxgYx5tce9sjZBHefvPvNB 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RVxtoUT9CXbC1LdhztNAf9yR5ySnFnSPQh 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress R9XBrbj8iKkwy9M4erUqRaBinAiZSTXav3 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RSHdRnHHGdPtVej7fiehHBQ6dyTbEM1GHi 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RDW8EDkCkzQ1LA4xbVUoAERsBVhhYRLXCr 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RAxQTHdsy89tfSXwoce2sHeWrYXmDsMXQq 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RT2k2voy9n8jwppeTTJMQAhvaqA9pc9jHh 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RRvaVyKS59NJWhPp8Pn7mVPGhMuhJJXrdh 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RBpp98VwHx7SFv7dNbw8NY65t14XFq9fVD 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RPjUmFNcWEW9Bu275kPxzRXyWDz6bfQpPD 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RDY2CvzydimY2AtDqSjBAB1eCeogRE55DX 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RUgW6fLfVsLJ87Ng4zJTqNedJSKYQ9ToAf 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RUreYvNjhZYc1vP8cND9Cztpni1pYsigXb 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RHv3wyVnnanG2kSQmLNmjwAQeYRRAptxUy 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RLVwuTM5TitV4Gk79Rja731RwYkAzz7GWn 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RHbxwDa7JT1KJLHDKwb5n3gd8NREErqtQY 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RFDAZ1yCvKPmpqcgzg8r2qQJ8nPPgeoMrB 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RHsZesZXMfkdrsSEper3JWUBKwk29JTFfT 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RPJjzoKPb8idoUCT9XLBkNojNgysjJ5qrE 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RFQNjTfcvSAmf8D83og1NrdHj1wH2fc5X4 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RPknkGAHMwUBvfKQfvw9FyatTZzicSiN4y 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RMqbQz4NPNbG15QBwy9EFvLn4NX5Fa7w5g 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RQipE6ycbVVb9vCkhqrK8PGZs2p5YmiBtg 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RCA8H1npFPW5pnJRzycF8tFEJmn6XZhD4j 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RJD5jRidYW9Cu8qxjg9HDCsx6J3A4wQ4LU 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RQMwcDYMVBx9f4QCFfFk31px8QZP4e8uhA 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RXzsovGBQ3W97xnVC6JnWxXsV4qb7p7iBi 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RLHr8gUm2MZ3EEgDU4EmK7bdn5ZsxLYmnt 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RFTsWSzgKRd5Xa7d287w9eRFeYefKBso6Z 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress REuQ7EoxKeMYk4EGptV6EwdfV9LZXuc44g 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RX1tP6ftwe96p6scgJn4dpgNdHDgyg9R87 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RERp696QtNTeWDfBy3x3QbRwPYN2NxwxfA 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RNZKqUgoAPwWd7wNtuSKP7k1HSJAyPeH4N 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress R9jhJCwgT78pyjnkNuxgH3CE8ekxgT8iwB 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RSCQKVUhihKb13rb5VJwXsbSY6pdRPUZ6V 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RDVqM6t5xZw9jbYXEw2CJgkiSbrHBHiKR3 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RSSNgf98kiMGUxs55DvhNnumyxVudd2KQQ 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RXqdRmv7n9hygf9C7f7vj4VQyNR9RvzXss 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RE3P8D8rcWZBeKmT8DURPdezW87MU5Ho3F 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RS3v2u6d4SJ1ujLz7CHNSFLSmxn6Tx6mJp 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RREc88bQzxHCvzqErPDnTQH2Qg5yUtjbyp 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RJ9wAk3ZNrFwdso1RVbwASiqqQaDNyKjd2 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RVKtRKozg8RKvEYCumMD43fCU6f212M5RD 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RCvsbvzCwA1AaxeoYVSL9Q3BdnybEWfXaH 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RXtADsErZLmsGhNyQdW2DekHMGZ23cLrav 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RYGrWs5b8CVFFpxGpjiBaMwfYV9X5UqFaB 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RHASfhhM6bvDFakRDqkzA2wc3V4R4oNmXi 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RATaU3jjn4RwHK61YWoJ4eg7Eggk3puZW8 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RXbb9PkefXcsqq8wqiUZZUuq8e3p29mw1G 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RDY9LJZTEJ9FsvugUuD69gceA98uqan5XL 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress R9tjkpdNbzw6mNfxorb5bvTPmsuon5aLrC 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RT2JyVts5tb1prC7KYykmznrqw7VXJo1HB 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RFHRWQ5pAXNfmudHfxdxw3Wo8yFGoeDn6z 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RTw3vi3dGa9n8LLbKvk7jDAwLdt3A5ET7a 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RQeuhk4KcPM3F5hefwTBWezDdcktSGQQSq 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress R9TGdzN25MgdRkYfsYfxZWzHCLVCyWFAei 0.010000 -./komodo-cli -ac_name=PANGEA sendtoaddress RDYsrWBZkYSWhRDupGRrfGqrVnFtK9hJGC 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RNJmgYaFF5DbnrNUX6pMYz9rcnDKC2tuAc 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RDhEGYScNQYetCyG75Kf8Fg61UWPdwc1C5 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RHPGxpiwRHP4dKZXjYPdpon1nCto7qVE8s 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RLQoAcs1RaqW1xfN2NJwoZWW5twexPhuGB 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RXF3aHUaWDUY4fRRYmBNALoHWkgSQCiJ4f 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RL2SkPSCGMvcHqZ56ErfMxbQGdA4nk7MZp 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RFssbc211PJdVy1bvcvAG5X2N4ovPAoy5o 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RNoz2DKPZ2ppMxgYx5tce9sjZBHefvPvNB 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RVxtoUT9CXbC1LdhztNAf9yR5ySnFnSPQh 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress R9XBrbj8iKkwy9M4erUqRaBinAiZSTXav3 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RSHdRnHHGdPtVej7fiehHBQ6dyTbEM1GHi 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RDW8EDkCkzQ1LA4xbVUoAERsBVhhYRLXCr 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RAxQTHdsy89tfSXwoce2sHeWrYXmDsMXQq 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RT2k2voy9n8jwppeTTJMQAhvaqA9pc9jHh 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RRvaVyKS59NJWhPp8Pn7mVPGhMuhJJXrdh 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RBpp98VwHx7SFv7dNbw8NY65t14XFq9fVD 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RPjUmFNcWEW9Bu275kPxzRXyWDz6bfQpPD 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RDY2CvzydimY2AtDqSjBAB1eCeogRE55DX 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RUgW6fLfVsLJ87Ng4zJTqNedJSKYQ9ToAf 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RUreYvNjhZYc1vP8cND9Cztpni1pYsigXb 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RHv3wyVnnanG2kSQmLNmjwAQeYRRAptxUy 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RLVwuTM5TitV4Gk79Rja731RwYkAzz7GWn 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RHbxwDa7JT1KJLHDKwb5n3gd8NREErqtQY 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RFDAZ1yCvKPmpqcgzg8r2qQJ8nPPgeoMrB 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RHsZesZXMfkdrsSEper3JWUBKwk29JTFfT 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RPJjzoKPb8idoUCT9XLBkNojNgysjJ5qrE 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RFQNjTfcvSAmf8D83og1NrdHj1wH2fc5X4 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RPknkGAHMwUBvfKQfvw9FyatTZzicSiN4y 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RMqbQz4NPNbG15QBwy9EFvLn4NX5Fa7w5g 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RQipE6ycbVVb9vCkhqrK8PGZs2p5YmiBtg 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RCA8H1npFPW5pnJRzycF8tFEJmn6XZhD4j 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RJD5jRidYW9Cu8qxjg9HDCsx6J3A4wQ4LU 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RQMwcDYMVBx9f4QCFfFk31px8QZP4e8uhA 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RXzsovGBQ3W97xnVC6JnWxXsV4qb7p7iBi 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RLHr8gUm2MZ3EEgDU4EmK7bdn5ZsxLYmnt 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RFTsWSzgKRd5Xa7d287w9eRFeYefKBso6Z 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress REuQ7EoxKeMYk4EGptV6EwdfV9LZXuc44g 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RX1tP6ftwe96p6scgJn4dpgNdHDgyg9R87 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RERp696QtNTeWDfBy3x3QbRwPYN2NxwxfA 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RNZKqUgoAPwWd7wNtuSKP7k1HSJAyPeH4N 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress R9jhJCwgT78pyjnkNuxgH3CE8ekxgT8iwB 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RSCQKVUhihKb13rb5VJwXsbSY6pdRPUZ6V 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RDVqM6t5xZw9jbYXEw2CJgkiSbrHBHiKR3 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RSSNgf98kiMGUxs55DvhNnumyxVudd2KQQ 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RXqdRmv7n9hygf9C7f7vj4VQyNR9RvzXss 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RE3P8D8rcWZBeKmT8DURPdezW87MU5Ho3F 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RS3v2u6d4SJ1ujLz7CHNSFLSmxn6Tx6mJp 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RREc88bQzxHCvzqErPDnTQH2Qg5yUtjbyp 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RJ9wAk3ZNrFwdso1RVbwASiqqQaDNyKjd2 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RVKtRKozg8RKvEYCumMD43fCU6f212M5RD 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RCvsbvzCwA1AaxeoYVSL9Q3BdnybEWfXaH 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RXtADsErZLmsGhNyQdW2DekHMGZ23cLrav 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RYGrWs5b8CVFFpxGpjiBaMwfYV9X5UqFaB 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RHASfhhM6bvDFakRDqkzA2wc3V4R4oNmXi 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RATaU3jjn4RwHK61YWoJ4eg7Eggk3puZW8 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RXbb9PkefXcsqq8wqiUZZUuq8e3p29mw1G 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RDY9LJZTEJ9FsvugUuD69gceA98uqan5XL 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress R9tjkpdNbzw6mNfxorb5bvTPmsuon5aLrC 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RT2JyVts5tb1prC7KYykmznrqw7VXJo1HB 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RFHRWQ5pAXNfmudHfxdxw3Wo8yFGoeDn6z 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RTw3vi3dGa9n8LLbKvk7jDAwLdt3A5ET7a 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RQeuhk4KcPM3F5hefwTBWezDdcktSGQQSq 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress R9TGdzN25MgdRkYfsYfxZWzHCLVCyWFAei 0.010000 -./komodo-cli -ac_name=JUMBLR sendtoaddress RDYsrWBZkYSWhRDupGRrfGqrVnFtK9hJGC 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RNJmgYaFF5DbnrNUX6pMYz9rcnDKC2tuAc 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RDhEGYScNQYetCyG75Kf8Fg61UWPdwc1C5 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RHPGxpiwRHP4dKZXjYPdpon1nCto7qVE8s 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RLQoAcs1RaqW1xfN2NJwoZWW5twexPhuGB 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RXF3aHUaWDUY4fRRYmBNALoHWkgSQCiJ4f 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RL2SkPSCGMvcHqZ56ErfMxbQGdA4nk7MZp 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RFssbc211PJdVy1bvcvAG5X2N4ovPAoy5o 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RNoz2DKPZ2ppMxgYx5tce9sjZBHefvPvNB 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RVxtoUT9CXbC1LdhztNAf9yR5ySnFnSPQh 0.010000 -./komodo-cli -ac_name=BET sendtoaddress R9XBrbj8iKkwy9M4erUqRaBinAiZSTXav3 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RSHdRnHHGdPtVej7fiehHBQ6dyTbEM1GHi 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RDW8EDkCkzQ1LA4xbVUoAERsBVhhYRLXCr 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RAxQTHdsy89tfSXwoce2sHeWrYXmDsMXQq 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RT2k2voy9n8jwppeTTJMQAhvaqA9pc9jHh 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RRvaVyKS59NJWhPp8Pn7mVPGhMuhJJXrdh 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RBpp98VwHx7SFv7dNbw8NY65t14XFq9fVD 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RPjUmFNcWEW9Bu275kPxzRXyWDz6bfQpPD 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RDY2CvzydimY2AtDqSjBAB1eCeogRE55DX 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RUgW6fLfVsLJ87Ng4zJTqNedJSKYQ9ToAf 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RUreYvNjhZYc1vP8cND9Cztpni1pYsigXb 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RHv3wyVnnanG2kSQmLNmjwAQeYRRAptxUy 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RLVwuTM5TitV4Gk79Rja731RwYkAzz7GWn 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RHbxwDa7JT1KJLHDKwb5n3gd8NREErqtQY 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RFDAZ1yCvKPmpqcgzg8r2qQJ8nPPgeoMrB 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RHsZesZXMfkdrsSEper3JWUBKwk29JTFfT 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RPJjzoKPb8idoUCT9XLBkNojNgysjJ5qrE 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RFQNjTfcvSAmf8D83og1NrdHj1wH2fc5X4 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RPknkGAHMwUBvfKQfvw9FyatTZzicSiN4y 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RMqbQz4NPNbG15QBwy9EFvLn4NX5Fa7w5g 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RQipE6ycbVVb9vCkhqrK8PGZs2p5YmiBtg 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RCA8H1npFPW5pnJRzycF8tFEJmn6XZhD4j 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RJD5jRidYW9Cu8qxjg9HDCsx6J3A4wQ4LU 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RQMwcDYMVBx9f4QCFfFk31px8QZP4e8uhA 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RXzsovGBQ3W97xnVC6JnWxXsV4qb7p7iBi 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RLHr8gUm2MZ3EEgDU4EmK7bdn5ZsxLYmnt 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RFTsWSzgKRd5Xa7d287w9eRFeYefKBso6Z 0.010000 -./komodo-cli -ac_name=BET sendtoaddress REuQ7EoxKeMYk4EGptV6EwdfV9LZXuc44g 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RX1tP6ftwe96p6scgJn4dpgNdHDgyg9R87 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RERp696QtNTeWDfBy3x3QbRwPYN2NxwxfA 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RNZKqUgoAPwWd7wNtuSKP7k1HSJAyPeH4N 0.010000 -./komodo-cli -ac_name=BET sendtoaddress R9jhJCwgT78pyjnkNuxgH3CE8ekxgT8iwB 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RSCQKVUhihKb13rb5VJwXsbSY6pdRPUZ6V 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RDVqM6t5xZw9jbYXEw2CJgkiSbrHBHiKR3 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RSSNgf98kiMGUxs55DvhNnumyxVudd2KQQ 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RXqdRmv7n9hygf9C7f7vj4VQyNR9RvzXss 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RE3P8D8rcWZBeKmT8DURPdezW87MU5Ho3F 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RS3v2u6d4SJ1ujLz7CHNSFLSmxn6Tx6mJp 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RREc88bQzxHCvzqErPDnTQH2Qg5yUtjbyp 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RJ9wAk3ZNrFwdso1RVbwASiqqQaDNyKjd2 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RVKtRKozg8RKvEYCumMD43fCU6f212M5RD 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RCvsbvzCwA1AaxeoYVSL9Q3BdnybEWfXaH 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RXtADsErZLmsGhNyQdW2DekHMGZ23cLrav 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RYGrWs5b8CVFFpxGpjiBaMwfYV9X5UqFaB 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RHASfhhM6bvDFakRDqkzA2wc3V4R4oNmXi 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RATaU3jjn4RwHK61YWoJ4eg7Eggk3puZW8 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RXbb9PkefXcsqq8wqiUZZUuq8e3p29mw1G 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RDY9LJZTEJ9FsvugUuD69gceA98uqan5XL 0.010000 -./komodo-cli -ac_name=BET sendtoaddress R9tjkpdNbzw6mNfxorb5bvTPmsuon5aLrC 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RT2JyVts5tb1prC7KYykmznrqw7VXJo1HB 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RFHRWQ5pAXNfmudHfxdxw3Wo8yFGoeDn6z 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RTw3vi3dGa9n8LLbKvk7jDAwLdt3A5ET7a 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RQeuhk4KcPM3F5hefwTBWezDdcktSGQQSq 0.010000 -./komodo-cli -ac_name=BET sendtoaddress R9TGdzN25MgdRkYfsYfxZWzHCLVCyWFAei 0.010000 -./komodo-cli -ac_name=BET sendtoaddress RDYsrWBZkYSWhRDupGRrfGqrVnFtK9hJGC 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RNJmgYaFF5DbnrNUX6pMYz9rcnDKC2tuAc 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RDhEGYScNQYetCyG75Kf8Fg61UWPdwc1C5 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RHPGxpiwRHP4dKZXjYPdpon1nCto7qVE8s 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RLQoAcs1RaqW1xfN2NJwoZWW5twexPhuGB 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RXF3aHUaWDUY4fRRYmBNALoHWkgSQCiJ4f 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RL2SkPSCGMvcHqZ56ErfMxbQGdA4nk7MZp 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RFssbc211PJdVy1bvcvAG5X2N4ovPAoy5o 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RNoz2DKPZ2ppMxgYx5tce9sjZBHefvPvNB 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RVxtoUT9CXbC1LdhztNAf9yR5ySnFnSPQh 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress R9XBrbj8iKkwy9M4erUqRaBinAiZSTXav3 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RSHdRnHHGdPtVej7fiehHBQ6dyTbEM1GHi 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RDW8EDkCkzQ1LA4xbVUoAERsBVhhYRLXCr 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RAxQTHdsy89tfSXwoce2sHeWrYXmDsMXQq 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RT2k2voy9n8jwppeTTJMQAhvaqA9pc9jHh 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RRvaVyKS59NJWhPp8Pn7mVPGhMuhJJXrdh 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RBpp98VwHx7SFv7dNbw8NY65t14XFq9fVD 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RPjUmFNcWEW9Bu275kPxzRXyWDz6bfQpPD 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RDY2CvzydimY2AtDqSjBAB1eCeogRE55DX 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RUgW6fLfVsLJ87Ng4zJTqNedJSKYQ9ToAf 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RUreYvNjhZYc1vP8cND9Cztpni1pYsigXb 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RHv3wyVnnanG2kSQmLNmjwAQeYRRAptxUy 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RLVwuTM5TitV4Gk79Rja731RwYkAzz7GWn 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RHbxwDa7JT1KJLHDKwb5n3gd8NREErqtQY 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RFDAZ1yCvKPmpqcgzg8r2qQJ8nPPgeoMrB 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RHsZesZXMfkdrsSEper3JWUBKwk29JTFfT 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RPJjzoKPb8idoUCT9XLBkNojNgysjJ5qrE 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RFQNjTfcvSAmf8D83og1NrdHj1wH2fc5X4 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RPknkGAHMwUBvfKQfvw9FyatTZzicSiN4y 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RMqbQz4NPNbG15QBwy9EFvLn4NX5Fa7w5g 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RQipE6ycbVVb9vCkhqrK8PGZs2p5YmiBtg 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RCA8H1npFPW5pnJRzycF8tFEJmn6XZhD4j 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RJD5jRidYW9Cu8qxjg9HDCsx6J3A4wQ4LU 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RQMwcDYMVBx9f4QCFfFk31px8QZP4e8uhA 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RXzsovGBQ3W97xnVC6JnWxXsV4qb7p7iBi 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RLHr8gUm2MZ3EEgDU4EmK7bdn5ZsxLYmnt 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RFTsWSzgKRd5Xa7d287w9eRFeYefKBso6Z 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress REuQ7EoxKeMYk4EGptV6EwdfV9LZXuc44g 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RX1tP6ftwe96p6scgJn4dpgNdHDgyg9R87 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RERp696QtNTeWDfBy3x3QbRwPYN2NxwxfA 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RNZKqUgoAPwWd7wNtuSKP7k1HSJAyPeH4N 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress R9jhJCwgT78pyjnkNuxgH3CE8ekxgT8iwB 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RSCQKVUhihKb13rb5VJwXsbSY6pdRPUZ6V 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RDVqM6t5xZw9jbYXEw2CJgkiSbrHBHiKR3 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RSSNgf98kiMGUxs55DvhNnumyxVudd2KQQ 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RXqdRmv7n9hygf9C7f7vj4VQyNR9RvzXss 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RE3P8D8rcWZBeKmT8DURPdezW87MU5Ho3F 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RS3v2u6d4SJ1ujLz7CHNSFLSmxn6Tx6mJp 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RREc88bQzxHCvzqErPDnTQH2Qg5yUtjbyp 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RJ9wAk3ZNrFwdso1RVbwASiqqQaDNyKjd2 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RVKtRKozg8RKvEYCumMD43fCU6f212M5RD 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RCvsbvzCwA1AaxeoYVSL9Q3BdnybEWfXaH 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RXtADsErZLmsGhNyQdW2DekHMGZ23cLrav 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RYGrWs5b8CVFFpxGpjiBaMwfYV9X5UqFaB 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RHASfhhM6bvDFakRDqkzA2wc3V4R4oNmXi 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RATaU3jjn4RwHK61YWoJ4eg7Eggk3puZW8 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RXbb9PkefXcsqq8wqiUZZUuq8e3p29mw1G 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RDY9LJZTEJ9FsvugUuD69gceA98uqan5XL 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress R9tjkpdNbzw6mNfxorb5bvTPmsuon5aLrC 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RT2JyVts5tb1prC7KYykmznrqw7VXJo1HB 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RFHRWQ5pAXNfmudHfxdxw3Wo8yFGoeDn6z 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RTw3vi3dGa9n8LLbKvk7jDAwLdt3A5ET7a 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RQeuhk4KcPM3F5hefwTBWezDdcktSGQQSq 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress R9TGdzN25MgdRkYfsYfxZWzHCLVCyWFAei 0.010000 -./komodo-cli -ac_name=CRYPTO sendtoaddress RDYsrWBZkYSWhRDupGRrfGqrVnFtK9hJGC 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RNJmgYaFF5DbnrNUX6pMYz9rcnDKC2tuAc 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RDhEGYScNQYetCyG75Kf8Fg61UWPdwc1C5 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RHPGxpiwRHP4dKZXjYPdpon1nCto7qVE8s 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RLQoAcs1RaqW1xfN2NJwoZWW5twexPhuGB 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RXF3aHUaWDUY4fRRYmBNALoHWkgSQCiJ4f 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RL2SkPSCGMvcHqZ56ErfMxbQGdA4nk7MZp 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RFssbc211PJdVy1bvcvAG5X2N4ovPAoy5o 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RNoz2DKPZ2ppMxgYx5tce9sjZBHefvPvNB 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RVxtoUT9CXbC1LdhztNAf9yR5ySnFnSPQh 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress R9XBrbj8iKkwy9M4erUqRaBinAiZSTXav3 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RSHdRnHHGdPtVej7fiehHBQ6dyTbEM1GHi 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RDW8EDkCkzQ1LA4xbVUoAERsBVhhYRLXCr 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RAxQTHdsy89tfSXwoce2sHeWrYXmDsMXQq 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RT2k2voy9n8jwppeTTJMQAhvaqA9pc9jHh 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RRvaVyKS59NJWhPp8Pn7mVPGhMuhJJXrdh 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RBpp98VwHx7SFv7dNbw8NY65t14XFq9fVD 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RPjUmFNcWEW9Bu275kPxzRXyWDz6bfQpPD 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RDY2CvzydimY2AtDqSjBAB1eCeogRE55DX 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RUgW6fLfVsLJ87Ng4zJTqNedJSKYQ9ToAf 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RUreYvNjhZYc1vP8cND9Cztpni1pYsigXb 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RHv3wyVnnanG2kSQmLNmjwAQeYRRAptxUy 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RLVwuTM5TitV4Gk79Rja731RwYkAzz7GWn 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RHbxwDa7JT1KJLHDKwb5n3gd8NREErqtQY 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RFDAZ1yCvKPmpqcgzg8r2qQJ8nPPgeoMrB 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RHsZesZXMfkdrsSEper3JWUBKwk29JTFfT 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RPJjzoKPb8idoUCT9XLBkNojNgysjJ5qrE 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RFQNjTfcvSAmf8D83og1NrdHj1wH2fc5X4 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RPknkGAHMwUBvfKQfvw9FyatTZzicSiN4y 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RMqbQz4NPNbG15QBwy9EFvLn4NX5Fa7w5g 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RQipE6ycbVVb9vCkhqrK8PGZs2p5YmiBtg 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RCA8H1npFPW5pnJRzycF8tFEJmn6XZhD4j 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RJD5jRidYW9Cu8qxjg9HDCsx6J3A4wQ4LU 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RQMwcDYMVBx9f4QCFfFk31px8QZP4e8uhA 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RXzsovGBQ3W97xnVC6JnWxXsV4qb7p7iBi 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RLHr8gUm2MZ3EEgDU4EmK7bdn5ZsxLYmnt 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RFTsWSzgKRd5Xa7d287w9eRFeYefKBso6Z 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress REuQ7EoxKeMYk4EGptV6EwdfV9LZXuc44g 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RX1tP6ftwe96p6scgJn4dpgNdHDgyg9R87 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RERp696QtNTeWDfBy3x3QbRwPYN2NxwxfA 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RNZKqUgoAPwWd7wNtuSKP7k1HSJAyPeH4N 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress R9jhJCwgT78pyjnkNuxgH3CE8ekxgT8iwB 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RSCQKVUhihKb13rb5VJwXsbSY6pdRPUZ6V 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RDVqM6t5xZw9jbYXEw2CJgkiSbrHBHiKR3 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RSSNgf98kiMGUxs55DvhNnumyxVudd2KQQ 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RXqdRmv7n9hygf9C7f7vj4VQyNR9RvzXss 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RE3P8D8rcWZBeKmT8DURPdezW87MU5Ho3F 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RS3v2u6d4SJ1ujLz7CHNSFLSmxn6Tx6mJp 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RREc88bQzxHCvzqErPDnTQH2Qg5yUtjbyp 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RJ9wAk3ZNrFwdso1RVbwASiqqQaDNyKjd2 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RVKtRKozg8RKvEYCumMD43fCU6f212M5RD 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RCvsbvzCwA1AaxeoYVSL9Q3BdnybEWfXaH 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RXtADsErZLmsGhNyQdW2DekHMGZ23cLrav 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RYGrWs5b8CVFFpxGpjiBaMwfYV9X5UqFaB 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RHASfhhM6bvDFakRDqkzA2wc3V4R4oNmXi 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RATaU3jjn4RwHK61YWoJ4eg7Eggk3puZW8 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RXbb9PkefXcsqq8wqiUZZUuq8e3p29mw1G 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RDY9LJZTEJ9FsvugUuD69gceA98uqan5XL 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress R9tjkpdNbzw6mNfxorb5bvTPmsuon5aLrC 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RT2JyVts5tb1prC7KYykmznrqw7VXJo1HB 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RFHRWQ5pAXNfmudHfxdxw3Wo8yFGoeDn6z 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RTw3vi3dGa9n8LLbKvk7jDAwLdt3A5ET7a 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RQeuhk4KcPM3F5hefwTBWezDdcktSGQQSq 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress R9TGdzN25MgdRkYfsYfxZWzHCLVCyWFAei 0.010000 -./komodo-cli -ac_name=HODL sendtoaddress RDYsrWBZkYSWhRDupGRrfGqrVnFtK9hJGC 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RNJmgYaFF5DbnrNUX6pMYz9rcnDKC2tuAc 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RDhEGYScNQYetCyG75Kf8Fg61UWPdwc1C5 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RHPGxpiwRHP4dKZXjYPdpon1nCto7qVE8s 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RLQoAcs1RaqW1xfN2NJwoZWW5twexPhuGB 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RXF3aHUaWDUY4fRRYmBNALoHWkgSQCiJ4f 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RL2SkPSCGMvcHqZ56ErfMxbQGdA4nk7MZp 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RFssbc211PJdVy1bvcvAG5X2N4ovPAoy5o 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RNoz2DKPZ2ppMxgYx5tce9sjZBHefvPvNB 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RVxtoUT9CXbC1LdhztNAf9yR5ySnFnSPQh 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress R9XBrbj8iKkwy9M4erUqRaBinAiZSTXav3 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RSHdRnHHGdPtVej7fiehHBQ6dyTbEM1GHi 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RDW8EDkCkzQ1LA4xbVUoAERsBVhhYRLXCr 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RAxQTHdsy89tfSXwoce2sHeWrYXmDsMXQq 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RT2k2voy9n8jwppeTTJMQAhvaqA9pc9jHh 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RRvaVyKS59NJWhPp8Pn7mVPGhMuhJJXrdh 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RBpp98VwHx7SFv7dNbw8NY65t14XFq9fVD 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RPjUmFNcWEW9Bu275kPxzRXyWDz6bfQpPD 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RDY2CvzydimY2AtDqSjBAB1eCeogRE55DX 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RUgW6fLfVsLJ87Ng4zJTqNedJSKYQ9ToAf 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RUreYvNjhZYc1vP8cND9Cztpni1pYsigXb 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RHv3wyVnnanG2kSQmLNmjwAQeYRRAptxUy 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RLVwuTM5TitV4Gk79Rja731RwYkAzz7GWn 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RHbxwDa7JT1KJLHDKwb5n3gd8NREErqtQY 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RFDAZ1yCvKPmpqcgzg8r2qQJ8nPPgeoMrB 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RHsZesZXMfkdrsSEper3JWUBKwk29JTFfT 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RPJjzoKPb8idoUCT9XLBkNojNgysjJ5qrE 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RFQNjTfcvSAmf8D83og1NrdHj1wH2fc5X4 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RPknkGAHMwUBvfKQfvw9FyatTZzicSiN4y 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RMqbQz4NPNbG15QBwy9EFvLn4NX5Fa7w5g 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RQipE6ycbVVb9vCkhqrK8PGZs2p5YmiBtg 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RCA8H1npFPW5pnJRzycF8tFEJmn6XZhD4j 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RJD5jRidYW9Cu8qxjg9HDCsx6J3A4wQ4LU 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RQMwcDYMVBx9f4QCFfFk31px8QZP4e8uhA 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RXzsovGBQ3W97xnVC6JnWxXsV4qb7p7iBi 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RLHr8gUm2MZ3EEgDU4EmK7bdn5ZsxLYmnt 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RFTsWSzgKRd5Xa7d287w9eRFeYefKBso6Z 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress REuQ7EoxKeMYk4EGptV6EwdfV9LZXuc44g 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RX1tP6ftwe96p6scgJn4dpgNdHDgyg9R87 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RERp696QtNTeWDfBy3x3QbRwPYN2NxwxfA 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RNZKqUgoAPwWd7wNtuSKP7k1HSJAyPeH4N 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress R9jhJCwgT78pyjnkNuxgH3CE8ekxgT8iwB 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RSCQKVUhihKb13rb5VJwXsbSY6pdRPUZ6V 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RDVqM6t5xZw9jbYXEw2CJgkiSbrHBHiKR3 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RSSNgf98kiMGUxs55DvhNnumyxVudd2KQQ 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RXqdRmv7n9hygf9C7f7vj4VQyNR9RvzXss 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RE3P8D8rcWZBeKmT8DURPdezW87MU5Ho3F 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RS3v2u6d4SJ1ujLz7CHNSFLSmxn6Tx6mJp 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RREc88bQzxHCvzqErPDnTQH2Qg5yUtjbyp 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RJ9wAk3ZNrFwdso1RVbwASiqqQaDNyKjd2 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RVKtRKozg8RKvEYCumMD43fCU6f212M5RD 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RCvsbvzCwA1AaxeoYVSL9Q3BdnybEWfXaH 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RXtADsErZLmsGhNyQdW2DekHMGZ23cLrav 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RYGrWs5b8CVFFpxGpjiBaMwfYV9X5UqFaB 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RHASfhhM6bvDFakRDqkzA2wc3V4R4oNmXi 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RATaU3jjn4RwHK61YWoJ4eg7Eggk3puZW8 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RXbb9PkefXcsqq8wqiUZZUuq8e3p29mw1G 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RDY9LJZTEJ9FsvugUuD69gceA98uqan5XL 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress R9tjkpdNbzw6mNfxorb5bvTPmsuon5aLrC 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RT2JyVts5tb1prC7KYykmznrqw7VXJo1HB 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RFHRWQ5pAXNfmudHfxdxw3Wo8yFGoeDn6z 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RTw3vi3dGa9n8LLbKvk7jDAwLdt3A5ET7a 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RQeuhk4KcPM3F5hefwTBWezDdcktSGQQSq 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress R9TGdzN25MgdRkYfsYfxZWzHCLVCyWFAei 0.010000 -./komodo-cli -ac_name=SHARK sendtoaddress RDYsrWBZkYSWhRDupGRrfGqrVnFtK9hJGC 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RNJmgYaFF5DbnrNUX6pMYz9rcnDKC2tuAc 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RDhEGYScNQYetCyG75Kf8Fg61UWPdwc1C5 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RHPGxpiwRHP4dKZXjYPdpon1nCto7qVE8s 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RLQoAcs1RaqW1xfN2NJwoZWW5twexPhuGB 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RXF3aHUaWDUY4fRRYmBNALoHWkgSQCiJ4f 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RL2SkPSCGMvcHqZ56ErfMxbQGdA4nk7MZp 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RFssbc211PJdVy1bvcvAG5X2N4ovPAoy5o 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RNoz2DKPZ2ppMxgYx5tce9sjZBHefvPvNB 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RVxtoUT9CXbC1LdhztNAf9yR5ySnFnSPQh 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress R9XBrbj8iKkwy9M4erUqRaBinAiZSTXav3 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RSHdRnHHGdPtVej7fiehHBQ6dyTbEM1GHi 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RDW8EDkCkzQ1LA4xbVUoAERsBVhhYRLXCr 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RAxQTHdsy89tfSXwoce2sHeWrYXmDsMXQq 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RT2k2voy9n8jwppeTTJMQAhvaqA9pc9jHh 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RRvaVyKS59NJWhPp8Pn7mVPGhMuhJJXrdh 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RBpp98VwHx7SFv7dNbw8NY65t14XFq9fVD 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RPjUmFNcWEW9Bu275kPxzRXyWDz6bfQpPD 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RDY2CvzydimY2AtDqSjBAB1eCeogRE55DX 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RUgW6fLfVsLJ87Ng4zJTqNedJSKYQ9ToAf 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RUreYvNjhZYc1vP8cND9Cztpni1pYsigXb 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RHv3wyVnnanG2kSQmLNmjwAQeYRRAptxUy 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RLVwuTM5TitV4Gk79Rja731RwYkAzz7GWn 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RHbxwDa7JT1KJLHDKwb5n3gd8NREErqtQY 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RFDAZ1yCvKPmpqcgzg8r2qQJ8nPPgeoMrB 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RHsZesZXMfkdrsSEper3JWUBKwk29JTFfT 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RPJjzoKPb8idoUCT9XLBkNojNgysjJ5qrE 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RFQNjTfcvSAmf8D83og1NrdHj1wH2fc5X4 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RPknkGAHMwUBvfKQfvw9FyatTZzicSiN4y 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RMqbQz4NPNbG15QBwy9EFvLn4NX5Fa7w5g 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RQipE6ycbVVb9vCkhqrK8PGZs2p5YmiBtg 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RCA8H1npFPW5pnJRzycF8tFEJmn6XZhD4j 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RJD5jRidYW9Cu8qxjg9HDCsx6J3A4wQ4LU 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RQMwcDYMVBx9f4QCFfFk31px8QZP4e8uhA 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RXzsovGBQ3W97xnVC6JnWxXsV4qb7p7iBi 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RLHr8gUm2MZ3EEgDU4EmK7bdn5ZsxLYmnt 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RFTsWSzgKRd5Xa7d287w9eRFeYefKBso6Z 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress REuQ7EoxKeMYk4EGptV6EwdfV9LZXuc44g 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RX1tP6ftwe96p6scgJn4dpgNdHDgyg9R87 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RERp696QtNTeWDfBy3x3QbRwPYN2NxwxfA 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RNZKqUgoAPwWd7wNtuSKP7k1HSJAyPeH4N 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress R9jhJCwgT78pyjnkNuxgH3CE8ekxgT8iwB 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RSCQKVUhihKb13rb5VJwXsbSY6pdRPUZ6V 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RDVqM6t5xZw9jbYXEw2CJgkiSbrHBHiKR3 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RSSNgf98kiMGUxs55DvhNnumyxVudd2KQQ 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RXqdRmv7n9hygf9C7f7vj4VQyNR9RvzXss 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RE3P8D8rcWZBeKmT8DURPdezW87MU5Ho3F 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RS3v2u6d4SJ1ujLz7CHNSFLSmxn6Tx6mJp 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RREc88bQzxHCvzqErPDnTQH2Qg5yUtjbyp 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RJ9wAk3ZNrFwdso1RVbwASiqqQaDNyKjd2 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RVKtRKozg8RKvEYCumMD43fCU6f212M5RD 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RCvsbvzCwA1AaxeoYVSL9Q3BdnybEWfXaH 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RXtADsErZLmsGhNyQdW2DekHMGZ23cLrav 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RYGrWs5b8CVFFpxGpjiBaMwfYV9X5UqFaB 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RHASfhhM6bvDFakRDqkzA2wc3V4R4oNmXi 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RATaU3jjn4RwHK61YWoJ4eg7Eggk3puZW8 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RXbb9PkefXcsqq8wqiUZZUuq8e3p29mw1G 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RDY9LJZTEJ9FsvugUuD69gceA98uqan5XL 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress R9tjkpdNbzw6mNfxorb5bvTPmsuon5aLrC 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RT2JyVts5tb1prC7KYykmznrqw7VXJo1HB 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RFHRWQ5pAXNfmudHfxdxw3Wo8yFGoeDn6z 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RTw3vi3dGa9n8LLbKvk7jDAwLdt3A5ET7a 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RQeuhk4KcPM3F5hefwTBWezDdcktSGQQSq 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress R9TGdzN25MgdRkYfsYfxZWzHCLVCyWFAei 0.010000 -./komodo-cli -ac_name=BOTS sendtoaddress RDYsrWBZkYSWhRDupGRrfGqrVnFtK9hJGC 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RNJmgYaFF5DbnrNUX6pMYz9rcnDKC2tuAc 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RDhEGYScNQYetCyG75Kf8Fg61UWPdwc1C5 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RHPGxpiwRHP4dKZXjYPdpon1nCto7qVE8s 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RLQoAcs1RaqW1xfN2NJwoZWW5twexPhuGB 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RXF3aHUaWDUY4fRRYmBNALoHWkgSQCiJ4f 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RL2SkPSCGMvcHqZ56ErfMxbQGdA4nk7MZp 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RFssbc211PJdVy1bvcvAG5X2N4ovPAoy5o 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RNoz2DKPZ2ppMxgYx5tce9sjZBHefvPvNB 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RVxtoUT9CXbC1LdhztNAf9yR5ySnFnSPQh 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress R9XBrbj8iKkwy9M4erUqRaBinAiZSTXav3 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RSHdRnHHGdPtVej7fiehHBQ6dyTbEM1GHi 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RDW8EDkCkzQ1LA4xbVUoAERsBVhhYRLXCr 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RAxQTHdsy89tfSXwoce2sHeWrYXmDsMXQq 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RT2k2voy9n8jwppeTTJMQAhvaqA9pc9jHh 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RRvaVyKS59NJWhPp8Pn7mVPGhMuhJJXrdh 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RBpp98VwHx7SFv7dNbw8NY65t14XFq9fVD 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RPjUmFNcWEW9Bu275kPxzRXyWDz6bfQpPD 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RDY2CvzydimY2AtDqSjBAB1eCeogRE55DX 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RUgW6fLfVsLJ87Ng4zJTqNedJSKYQ9ToAf 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RUreYvNjhZYc1vP8cND9Cztpni1pYsigXb 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RHv3wyVnnanG2kSQmLNmjwAQeYRRAptxUy 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RLVwuTM5TitV4Gk79Rja731RwYkAzz7GWn 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RHbxwDa7JT1KJLHDKwb5n3gd8NREErqtQY 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RFDAZ1yCvKPmpqcgzg8r2qQJ8nPPgeoMrB 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RHsZesZXMfkdrsSEper3JWUBKwk29JTFfT 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RPJjzoKPb8idoUCT9XLBkNojNgysjJ5qrE 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RFQNjTfcvSAmf8D83og1NrdHj1wH2fc5X4 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RPknkGAHMwUBvfKQfvw9FyatTZzicSiN4y 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RMqbQz4NPNbG15QBwy9EFvLn4NX5Fa7w5g 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RQipE6ycbVVb9vCkhqrK8PGZs2p5YmiBtg 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RCA8H1npFPW5pnJRzycF8tFEJmn6XZhD4j 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RJD5jRidYW9Cu8qxjg9HDCsx6J3A4wQ4LU 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RQMwcDYMVBx9f4QCFfFk31px8QZP4e8uhA 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RXzsovGBQ3W97xnVC6JnWxXsV4qb7p7iBi 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RLHr8gUm2MZ3EEgDU4EmK7bdn5ZsxLYmnt 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RFTsWSzgKRd5Xa7d287w9eRFeYefKBso6Z 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress REuQ7EoxKeMYk4EGptV6EwdfV9LZXuc44g 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RX1tP6ftwe96p6scgJn4dpgNdHDgyg9R87 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RERp696QtNTeWDfBy3x3QbRwPYN2NxwxfA 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RNZKqUgoAPwWd7wNtuSKP7k1HSJAyPeH4N 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress R9jhJCwgT78pyjnkNuxgH3CE8ekxgT8iwB 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RSCQKVUhihKb13rb5VJwXsbSY6pdRPUZ6V 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RDVqM6t5xZw9jbYXEw2CJgkiSbrHBHiKR3 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RSSNgf98kiMGUxs55DvhNnumyxVudd2KQQ 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RXqdRmv7n9hygf9C7f7vj4VQyNR9RvzXss 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RE3P8D8rcWZBeKmT8DURPdezW87MU5Ho3F 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RS3v2u6d4SJ1ujLz7CHNSFLSmxn6Tx6mJp 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RREc88bQzxHCvzqErPDnTQH2Qg5yUtjbyp 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RJ9wAk3ZNrFwdso1RVbwASiqqQaDNyKjd2 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RVKtRKozg8RKvEYCumMD43fCU6f212M5RD 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RCvsbvzCwA1AaxeoYVSL9Q3BdnybEWfXaH 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RXtADsErZLmsGhNyQdW2DekHMGZ23cLrav 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RYGrWs5b8CVFFpxGpjiBaMwfYV9X5UqFaB 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RHASfhhM6bvDFakRDqkzA2wc3V4R4oNmXi 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RATaU3jjn4RwHK61YWoJ4eg7Eggk3puZW8 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RXbb9PkefXcsqq8wqiUZZUuq8e3p29mw1G 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RDY9LJZTEJ9FsvugUuD69gceA98uqan5XL 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress R9tjkpdNbzw6mNfxorb5bvTPmsuon5aLrC 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RT2JyVts5tb1prC7KYykmznrqw7VXJo1HB 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RFHRWQ5pAXNfmudHfxdxw3Wo8yFGoeDn6z 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RTw3vi3dGa9n8LLbKvk7jDAwLdt3A5ET7a 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RQeuhk4KcPM3F5hefwTBWezDdcktSGQQSq 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress R9TGdzN25MgdRkYfsYfxZWzHCLVCyWFAei 0.010000 -./komodo-cli -ac_name=MGW sendtoaddress RDYsrWBZkYSWhRDupGRrfGqrVnFtK9hJGC 0.010000 - From 0f7b6c143894a0865da6e00a73d0488358b05e3b Mon Sep 17 00:00:00 2001 From: SHossain Date: Fri, 21 Dec 2018 15:14:38 +0000 Subject: [PATCH 033/643] Update assetchains.old --- src/assetchains.old | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assetchains.old b/src/assetchains.old index ede6c3e23..136f7c709 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -45,4 +45,4 @@ echo $pubkey ./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 & -./komodod -pubkey=$pubkey -ac_name=KSB -ac_supply=1000000000 -ac_end=1 -ac_public=1 -addnode=37.187.225.231 +./komodod -pubkey=$pubkey -ac_name=KSB -ac_supply=1000000000 -ac_end=1 -ac_public=1 -addnode=37.187.225.231 & From 2e9bcdc6b8789ab1b7ab099ecd12d2ad1a940f56 Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Tue, 25 Dec 2018 20:00:29 +0600 Subject: [PATCH 034/643] adjusted channels tests for new RPC call --- qa/rpc-tests/cryptoconditions_channels.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions_channels.py b/qa/rpc-tests/cryptoconditions_channels.py index 053b532cb..cec45687f 100755 --- a/qa/rpc-tests/cryptoconditions_channels.py +++ b/qa/rpc-tests/cryptoconditions_channels.py @@ -26,10 +26,10 @@ class CryptoconditionsChannelsTest(CryptoconditionsTestFramework): rpc1 = self.nodes[1] # getting empty channels list - result = rpc.channelsinfo() + result = rpc.channelslist() assert_equal(len(result), 2) assert_equal(result["result"], "success") - assert_equal(result["name"], "Channels Info") + assert_equal(result["name"], "Channels List") # 10 payments, 100000 sat denomination channel opening with second node pubkey new_channel_hex = rpc.channelsopen(self.pubkey1, "10", "100000") @@ -38,13 +38,13 @@ class CryptoconditionsChannelsTest(CryptoconditionsTestFramework): assert channel_txid, "got channel txid" # checking if our new channel in common channels list - result = rpc.channelsinfo() + result = rpc.channelslist() assert_equal(len(result), 3) # checking info about channel directly result = rpc.channelsinfo(channel_txid) assert_success(result) - assert_equal(result["Open"], "10 payments of 100000 satoshi") + assert_equal(result["Transactions"][0]["Open"], channel_txid) # open transaction should be confirmed rpc.generate(1) @@ -69,7 +69,7 @@ class CryptoconditionsChannelsTest(CryptoconditionsTestFramework): # now in channelinfo payment information should appear result = rpc.channelsinfo(channel_txid) - assert_equal(result["Payment"], "100000 satoshi to {}, 9 payments left".format(self.addr1)) + assert_equal(result["Transactions"][1]["Payment"], payment_tx_id) # executing channel close result = rpc.channelsclose(channel_txid) @@ -82,7 +82,7 @@ class CryptoconditionsChannelsTest(CryptoconditionsTestFramework): # now in channelinfo closed flag should appear result = rpc.channelsinfo(channel_txid) - assert_equal(result["Close"], "channel") + assert_equal(result["Transactions"][2]["Close"], channel_close_txid) # executing channel refund result = rpc.channelsrefund(channel_txid, channel_close_txid) From 07555bf23742bb4b6c452ad910505ad6321918cc Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Tue, 25 Dec 2018 20:05:24 +0600 Subject: [PATCH 035/643] temporary disabled gateways tests --- qa/pull-tester/cc-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qa/pull-tester/cc-tests.sh b/qa/pull-tester/cc-tests.sh index 4e8dde894..f2abde883 100755 --- a/qa/pull-tester/cc-tests.sh +++ b/qa/pull-tester/cc-tests.sh @@ -18,7 +18,7 @@ testScripts=( 'cryptoconditions_oracles.py' 'cryptoconditions_rewards.py' 'cryptoconditions_token.py' - 'cryptoconditions_gateways.py' + #'cryptoconditions_gateways.py' ); extArg="-extended" From 478a31f4635618e30075fd5672c2296608639e34 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Tue, 25 Dec 2018 17:13:54 +0100 Subject: [PATCH 036/643] Channels fix (#6) - Fix bug for not able to issue last payment in channel - Add more info in channelsinfo --- src/cc/channels.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 6c8b602c6..9269096cc 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -207,7 +207,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return eval->Invalid("vin.1 is CC for channelPayment!"); else if ( IsCCInput(tx.vin[2].scriptSig) == 0 ) return eval->Invalid("vin.2 is CC for channelPayment!"); - else if ( IsChannelsvout(cp,tx,srcpub,destpub,0)==0 ) + else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition()==0 ) return eval->Invalid("vout.0 is CC for channelPayment!"); else if ( IsChannelsMarkervout(cp,tx,srcpub,1)==0 ) return eval->Invalid("vout.1 is CC for channelPayment (marker to srcPub)!"); @@ -746,7 +746,7 @@ UniValue ChannelsInfo(uint256 channeltxid) result.push_back(Pair("Channel CC address",CCaddr)); result.push_back(Pair("Destination address",addr)); result.push_back(Pair("Number of payments",param1)); - result.push_back(Pair("Denomination",param2)); + result.push_back(Pair("Denomination",i64tostr(param2)+" satoshi")); result.push_back(Pair("Amount",i64tostr(param1*param2)+" satoshi")); SetCCtxids(addressIndex,CCaddr); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) @@ -781,10 +781,11 @@ UniValue ChannelsInfo(uint256 channeltxid) { Getscriptaddress(str,tx.vout[3].scriptPubKey); obj.push_back(Pair("Payment",txid.GetHex().data())); - obj.push_back(Pair("Number",param2)); + obj.push_back(Pair("Number of payments",param2)); obj.push_back(Pair("Amount",param2*payment)); obj.push_back(Pair("Destination",str)); obj.push_back(Pair("Secret",param3.ToString().c_str())); + obj.push_back(Pair("Payments left",param1)); } } else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'C' && opentxid==channeltxid) From 2d5537af0036596a91db7eb2313a25c6961ef7fc Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Dec 2018 00:59:35 -1100 Subject: [PATCH 037/643] Stubs for -ac_import --- src/cc/import.cpp | 119 ++++++++++++++++++++++++++++++++++++++--- src/crosschain.cpp | 13 ++++- src/komodo_globals.h | 4 +- src/komodo_utils.h | 38 +++++++++++-- src/rpc/crosschain.cpp | 19 ++++--- 5 files changed, 173 insertions(+), 20 deletions(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index b250bb7bf..c569ffaa8 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -25,7 +25,90 @@ * * This method should control every parameter of the ImportCoin transaction, since it has no signature * to protect it from malleability. + + ##### 0xffffffff is a special CCid for single chain/dual daemon imports */ + +extern std::string ASSETCHAINS_SELFIMPORT; +extern uint16_t ASSETCHAINS_CODAPORT,ASSETCHAINS_BEAMPORT; + +int32_t GetBEAMProof(TxProof &proof,CTransaction burnTx,uint256 hash) +{ + // confirm via ASSETCHAINS_BEAMPORT that burnTx/hash is a valid BEAM burn + return(-1); +} + +int32_t GetCODAProof(TxProof &proof,CTransaction burnTx,uint256 hash) +{ + // confirm via ASSETCHAINS_CODAPORT that burnTx/hash is a valid CODA burn + return(-1); +} + +int32_t GetPUBKEYProof(TxProof &proof,CTransaction burnTx,uint256 hash) +{ + // make sure vin0 is signed by ASSETCHAINS_OVERRIDE_PUBKEY33 + return(-1); +} + +int32_t GetGATEWAYProof(TxProof &proof,CTransaction burnTx,uint256 hash) +{ + // external coin is the assetchains symbol in the burnTx OP_RETURN + return(-1); +} + +int32_t GetSelfimportProof(TxProof &proof,CTransaction burnTx,uint256 hash) // find burnTx with hash from "other" daemon +{ + if ( ASSETCHAINS_SELFIMPORT == "BEAM" ) + { + if ( GetBEAMproof(proof,burnTx,hash) < 0 ) + return(-1); + } + else if ( ASSETCHAINS_SELFIMPORT == "CODA" ) + { + if ( GetCODAproof(proof,burnTx,hash) < 0 ) + return(-1); + } + else if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) + { + if ( GetPUBKEYproof(proof,burnTx,hash) < 0 ) + return(-1); + } + else if ( ASSETCHAINS_SELFIMPORT == "GATEWAY" ) + { + if ( GetGATEWAYproof(proof,burnTx,hash) < 0 ) // extract source coin from burnTx opreturn + return(-1); + } + else return(-1); + return(0); +} + +// use proof from the above functions to validate the import + +int32_t CheckBEAMimport(TxProof proof,CTransaction burnTx,td::vector payouts) +{ + // check with dual-BEAM daemon via ASSETCHAINS_BEAMPORT for validity of burnTx + return(-1); +} + +int32_t CheckCODAimport(TxProof proof,CTransaction burnTx,td::vector payouts) +{ + // check with dual-CODA daemon via ASSETCHAINS_CODAPORT for validity of burnTx + return(-1); +} + +int32_t CheckGATEWAYimport(std::string coin,TxProof proof,CTransaction burnTx,td::vector payouts) +{ + // check for valid burn from external coin blockchain and if valid return(0); + return(-1); +} + +int32_t CheckPUBKEYimport(TxProof proof,CTransaction burnTx,td::vector payouts) +{ + // if burnTx has ASSETCHAINS_PUBKEY vin, it is valid return(0); + return(0); + return(-1); +} + bool Eval::ImportCoin(const std::vector params, const CTransaction &importTx, unsigned int nIn) { if (importTx.vout.size() < 2) @@ -52,12 +135,6 @@ bool Eval::ImportCoin(const std::vector params, const CTransaction &imp if (!UnmarshalBurnTx(burnTx, targetSymbol, &targetCcid, payoutsHash)) return Invalid("invalid-burn-tx"); - if (targetCcid != GetAssetchainsCC() || targetSymbol != GetAssetchainsSymbol()) - return Invalid("importcoin-wrong-chain"); - - if (targetCcid < KOMODO_FIRSTFUNGIBLEID) - return Invalid("chain-not-fungible"); - // check burn amount { uint64_t burnAmount = burnTx.vout.back().nValue; @@ -74,13 +151,41 @@ bool Eval::ImportCoin(const std::vector params, const CTransaction &imp if (payoutsHash != SerializeHash(payouts)) return Invalid("wrong-payouts"); + if (targetCcid < KOMODO_FIRSTFUNGIBLEID) + return Invalid("chain-not-fungible"); + // Check proof confirms existance of burnTx + if ( targetCcid != 0xffffffff ) { + if (targetCcid != GetAssetchainsCC() || targetSymbol != GetAssetchainsSymbol()) + return Invalid("importcoin-wrong-chain"); uint256 target = proof.second.Exec(burnTx.GetHash()); if (!CheckMoMoM(proof.first, target)) return Invalid("momom-check-fail"); } - + else if ( ASSETCHAINS_SELFIMPORT == targetSymbol || ASSETCHAINS_SELFIMPORT == "GATEWAY" ) // various selfchain imports + { + if ( GetAssetchainsSymbol() == "BEAM" ) + { + if ( CheckBEAMimport(proof,burnTx,payouts) < 0 ) + return Invalid("BEAM-import-failure"); + } + else if ( GetAssetchainsSymbol() == "CODA" ) + { + if ( CheckCODAimport(proof,burnTx,payouts) < 0 ) + return Invalid("CODA-import-failure"); + } + else if ( GetAssetchainsSymbol() == "PUBKEY" ) + { + if ( CheckPUBKEYimport(proof,burnTx,payouts) < 0 ) + return Invalid("PUBKEY-import-failure"); + } + else + { + if ( CheckGATEWAYimport(GetAssetchainsSymbol(),proof,burnTx,payouts) < 0 ) + return Invalid("GATEWAY-import-failure"); + } + } return Valid(); } diff --git a/src/crosschain.cpp b/src/crosschain.cpp index e9444c607..806641f6a 100644 --- a/src/crosschain.cpp +++ b/src/crosschain.cpp @@ -26,6 +26,8 @@ int NOTARISATION_SCAN_LIMIT_BLOCKS = 1440; CBlockIndex *komodo_getblockindex(uint256 hash); +extern std::string ASSETCHAINS_SELFIMPORT; +int32_t GetSelfimportProof(TxProof &proof,CTransaction burnTx,uint256 hash); /* On KMD */ @@ -284,13 +286,20 @@ bool CheckMoMoM(uint256 kmdNotarisationHash, uint256 momom) * in: txid * out: pair */ -TxProof GetAssetchainProof(uint256 hash) + +TxProof GetAssetchainProof(uint256 hash,CTransaction burnTx) { int nIndex; CBlockIndex* blockIndex; Notarisation nota; std::vector branch; - + if ( ASSETCHAINS_SELFIMPORT.size() > 0 ) + { + TxProof proof; + if ( GetSelfimportProof(proof,burnTx,hash) < 0 ) + throw std::runtime_error("Failed validating selfimport"); + return(proof); + } { uint256 blockHash; CTransaction tx; diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 3e9b84db1..bd28d39f3 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -47,12 +47,12 @@ int COINBASE_MATURITY = _COINBASE_MATURITY;//100; int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1,KOMODO_DEALERNODE,KOMODO_EXTRASATOSHI,ASSETCHAINS_FOUNDERS; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1; -std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB; +std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB,ASSETCHAINS_SELFIMPORT; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW; bool VERUS_MINTBLOCKS; char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096]; -uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; +uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT,ASSETCHAINS_BEAMPORT,ASSETCHAINS_CODAPORT; uint32_t ASSETCHAIN_INIT,ASSETCHAINS_CC,KOMODO_STOPAT,KOMODO_DPOWCONFS = 1; uint32_t ASSETCHAINS_MAGIC = 2387029918; int64_t ASSETCHAINS_GENESISTXVAL = 5000000000; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 19941a172..2a3617748 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1773,6 +1773,30 @@ void komodo_args(char *argv0) ASSETCHAINS_COMMISSION = GetArg("-ac_perc",0); ASSETCHAINS_OVERRIDE_PUBKEY = GetArg("-ac_pubkey",""); ASSETCHAINS_SCRIPTPUB = GetArg("-ac_script",""); + ASSETCHAINS_BEAMPORT = GetArg("-ac_beam",0); + ASSETCHAINS_CODAPORT = GetArg("-ac_coda",0); + + ASSETCHAINS_SELFIMPORT = GetArg("-ac_import",""); // BEAM, CODA, PUBKEY, GATEWAY + if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" && strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) != 66 ) + { + fprintf(stderr,"invalid -ac_pubkey for -ac_import=PUBKEY\n"); + ASSETCHAINS_SELFIMPORT = ""; + } + else if ( ASSETCHAINS_SELFIMPORT == "BEAM" && ASSETCHAINS_BEAMPORT == 0 ) + { + fprintf(stderr,"missing -ac_beam for BEAM rpcport\n"); + ASSETCHAINS_SELFIMPORT = ""; + } + else if ( ASSETCHAINS_SELFIMPORT == "CODA" && ASSETCHAINS_CODAPORT == 0 ) + { + fprintf(stderr,"missing -ac_coda for CODA rpcport\n"); + ASSETCHAINS_SELFIMPORT = ""; + } + else if ( ASSETCHAINS_SELFIMPORT != "GATEWAY" ) + { + fprintf(stderr,"invalid -ac_import type\n"); + ASSETCHAINS_SELFIMPORT = ""; + } //ASSETCHAINS_FOUNDERS_PERIOD = GetArg("-ac_period",0); if ( (ASSETCHAINS_STAKED= GetArg("-ac_staked",0)) > 100 ) @@ -1809,7 +1833,7 @@ void komodo_args(char *argv0) } else { - ASSETCHAINS_OVERRIDE_PUBKEY.clear(); + //ASSETCHAINS_OVERRIDE_PUBKEY.clear(); printf("-ac_perc must be set with -ac_pubkey\n"); } } @@ -1827,7 +1851,7 @@ void komodo_args(char *argv0) printf("ASSETCHAINS_FOUNDERS needs an ASETCHAINS_OVERRIDE_PUBKEY\n"); } } - if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 ) + if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 ) { fprintf(stderr,"perc %.4f%% ac_pub=[%02x%02x%02x...] acsize.%d\n",dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0],ASSETCHAINS_OVERRIDE_PUBKEY33[1],ASSETCHAINS_OVERRIDE_PUBKEY33[2],(int32_t)ASSETCHAINS_SCRIPTPUB.size()); extraptr = extrabuf; @@ -1889,6 +1913,14 @@ void komodo_args(char *argv0) //extralen += iguana_rwnum(1,&extraptr[extralen],(int32_t)ASSETCHAINS_SCRIPTPUB.size(),(void *)ASSETCHAINS_SCRIPTPUB.c_str()); fprintf(stderr,"append ac_script %s\n",ASSETCHAINS_SCRIPTPUB.c_str()); } + if ( ASSETCHAINS_SELFIMPORT.size() > 0 ) + { + memcpy(&extraptr[extralen],(char *)ASSETCHAINS_SELFIMPORT.c_str(),ASSETCHAINS_SELFIMPORT.size()); + for (i=0; i 0 ) + { + if ( ASSETCHAINS_SELFIMPORT == targetSymbol || ASSETCHAINS_SELFIMPORT == "GATEWAY" ) + { + ccid = 0xffffffff; + } // else maybe clusters of self-import chains can be supported? + } + CTxOut burnOut = MakeBurnOutput(burnAmount, ccid, targetSymbol, tx.vout); UniValue ret(UniValue::VOBJ); ret.push_back(Pair("payouts", HexStr(E_MARSHAL(ss << tx.vout)))); tx.vout.clear(); @@ -229,7 +236,7 @@ UniValue migrate_createimporttransaction(const UniValue& params, bool fHelp) throw runtime_error("Couldn't parse payouts"); uint256 txid = burnTx.GetHash(); - TxProof proof = GetAssetchainProof(burnTx.GetHash()); + TxProof proof = GetAssetchainProof(burnTx.GetHash(),burnTx); CTransaction importTx = MakeImportCoinTransaction(proof, burnTx, payouts); return HexStr(E_MARSHAL(ss << importTx)); From ac96ea51783445f5c8a5db98bb90bea567d535b8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Dec 2018 01:09:24 -1100 Subject: [PATCH 038/643] std --- src/cc/import.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index c569ffaa8..e034d5fa5 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -84,25 +84,25 @@ int32_t GetSelfimportProof(TxProof &proof,CTransaction burnTx,uint256 hash) // f // use proof from the above functions to validate the import -int32_t CheckBEAMimport(TxProof proof,CTransaction burnTx,td::vector payouts) +int32_t CheckBEAMimport(TxProof proof,CTransaction burnTx,std::vector payouts) { // check with dual-BEAM daemon via ASSETCHAINS_BEAMPORT for validity of burnTx return(-1); } -int32_t CheckCODAimport(TxProof proof,CTransaction burnTx,td::vector payouts) +int32_t CheckCODAimport(TxProof proof,CTransaction burnTx,std::vector payouts) { // check with dual-CODA daemon via ASSETCHAINS_CODAPORT for validity of burnTx return(-1); } -int32_t CheckGATEWAYimport(std::string coin,TxProof proof,CTransaction burnTx,td::vector payouts) +int32_t CheckGATEWAYimport(std::string coin,TxProof proof,CTransaction burnTx,std::vector payouts) { // check for valid burn from external coin blockchain and if valid return(0); return(-1); } -int32_t CheckPUBKEYimport(TxProof proof,CTransaction burnTx,td::vector payouts) +int32_t CheckPUBKEYimport(TxProof proof,CTransaction burnTx,std::vector payouts) { // if burnTx has ASSETCHAINS_PUBKEY vin, it is valid return(0); return(0); From 75ecbdebb4cb1d46d5c0358692bd77fa5668cd77 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Dec 2018 01:11:03 -1100 Subject: [PATCH 039/643] selfimports --- src/cc/import.cpp | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index e034d5fa5..a5deea0cd 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -32,50 +32,26 @@ extern std::string ASSETCHAINS_SELFIMPORT; extern uint16_t ASSETCHAINS_CODAPORT,ASSETCHAINS_BEAMPORT; -int32_t GetBEAMProof(TxProof &proof,CTransaction burnTx,uint256 hash) -{ - // confirm via ASSETCHAINS_BEAMPORT that burnTx/hash is a valid BEAM burn - return(-1); -} - -int32_t GetCODAProof(TxProof &proof,CTransaction burnTx,uint256 hash) -{ - // confirm via ASSETCHAINS_CODAPORT that burnTx/hash is a valid CODA burn - return(-1); -} - -int32_t GetPUBKEYProof(TxProof &proof,CTransaction burnTx,uint256 hash) -{ - // make sure vin0 is signed by ASSETCHAINS_OVERRIDE_PUBKEY33 - return(-1); -} - -int32_t GetGATEWAYProof(TxProof &proof,CTransaction burnTx,uint256 hash) -{ - // external coin is the assetchains symbol in the burnTx OP_RETURN - return(-1); -} - int32_t GetSelfimportProof(TxProof &proof,CTransaction burnTx,uint256 hash) // find burnTx with hash from "other" daemon { if ( ASSETCHAINS_SELFIMPORT == "BEAM" ) { - if ( GetBEAMproof(proof,burnTx,hash) < 0 ) + // confirm via ASSETCHAINS_BEAMPORT that burnTx/hash is a valid BEAM burn return(-1); } else if ( ASSETCHAINS_SELFIMPORT == "CODA" ) { - if ( GetCODAproof(proof,burnTx,hash) < 0 ) + // confirm via ASSETCHAINS_CODAPORT that burnTx/hash is a valid CODA burn return(-1); } else if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) { - if ( GetPUBKEYproof(proof,burnTx,hash) < 0 ) + // make sure vin0 is signed by ASSETCHAINS_OVERRIDE_PUBKEY33 return(-1); } else if ( ASSETCHAINS_SELFIMPORT == "GATEWAY" ) { - if ( GetGATEWAYproof(proof,burnTx,hash) < 0 ) // extract source coin from burnTx opreturn + // external coin is the assetchains symbol in the burnTx OP_RETURN return(-1); } else return(-1); From 33f99eb34a7a7e99b572e0e79b1d04909c8ea565 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Dec 2018 01:12:37 -1100 Subject: [PATCH 040/643] Allow any ac_pubkey import for testing --- src/cc/import.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index a5deea0cd..4d61b4bf8 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -47,7 +47,7 @@ int32_t GetSelfimportProof(TxProof &proof,CTransaction burnTx,uint256 hash) // f else if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) { // make sure vin0 is signed by ASSETCHAINS_OVERRIDE_PUBKEY33 - return(-1); + return(0); } else if ( ASSETCHAINS_SELFIMPORT == "GATEWAY" ) { From 141560e39adab62b3a4d185c093f17f8c0fadc63 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Dec 2018 01:14:33 -1100 Subject: [PATCH 041/643] Fix define --- src/crosschain.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crosschain.h b/src/crosschain.h index 1fbd7603a..57e4a79d0 100644 --- a/src/crosschain.h +++ b/src/crosschain.h @@ -5,7 +5,7 @@ /* On assetchain */ -TxProof GetAssetchainProof(uint256 hash); +TxProof GetAssetchainProof(uint256 hash,CTransaction burnTx); /* On KMD */ uint256 CalculateProofRoot(const char* symbol, uint32_t targetCCid, int kmdHeight, From 722964362a4e1c2297fe8181dd417f6ce7606c6d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Dec 2018 08:28:37 -1100 Subject: [PATCH 042/643] Fix -ac_import --- src/komodo_utils.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 2a3617748..eeedf1949 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1777,10 +1777,13 @@ void komodo_args(char *argv0) ASSETCHAINS_CODAPORT = GetArg("-ac_coda",0); ASSETCHAINS_SELFIMPORT = GetArg("-ac_import",""); // BEAM, CODA, PUBKEY, GATEWAY - if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" && strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) != 66 ) + if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) { - fprintf(stderr,"invalid -ac_pubkey for -ac_import=PUBKEY\n"); - ASSETCHAINS_SELFIMPORT = ""; + if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) != 66 ) + { + fprintf(stderr,"invalid -ac_pubkey for -ac_import=PUBKEY\n"); + ASSETCHAINS_SELFIMPORT = ""; + } } else if ( ASSETCHAINS_SELFIMPORT == "BEAM" && ASSETCHAINS_BEAMPORT == 0 ) { @@ -1831,7 +1834,7 @@ void komodo_args(char *argv0) ASSETCHAINS_COMMISSION = 53846154; // maps to 35% printf("ASSETCHAINS_COMMISSION defaulted to 35%% when founders reward active\n"); } - else + else if ( ASSETCHAINS_SELFIMPORT.size() == 0 ) { //ASSETCHAINS_OVERRIDE_PUBKEY.clear(); printf("-ac_perc must be set with -ac_pubkey\n"); From b56025fd2fa8a2516cbbec61be3da3d21177f091 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 28 Dec 2018 16:10:38 +0800 Subject: [PATCH 043/643] Fix upload bandwidth and needless flood of AcceptToMemorypool errors on nodes being seeded from. Not sure why this fixes it, but it does. --- src/miner.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/miner.cpp b/src/miner.cpp index 9ff925554..e54cbbed9 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -761,6 +761,8 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, void komodo_broadcast(CBlock *pblock,int32_t limit) { + if (IsInitialBlockDownload()) + return; int32_t n = 1; //fprintf(stderr,"broadcast new block t.%u\n",(uint32_t)time(NULL)); { From a3f0af586e63e81e62ae1f99792c71ff8f857849 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 28 Dec 2018 03:25:18 -1100 Subject: [PATCH 044/643] Check for -port --- src/crosschain.cpp | 9 --------- src/komodo_utils.h | 22 ++++++++++++++++++---- src/rpc/crosschain.cpp | 28 ++++++++++++++++++++++++++-- 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/crosschain.cpp b/src/crosschain.cpp index 806641f6a..8dc5657b8 100644 --- a/src/crosschain.cpp +++ b/src/crosschain.cpp @@ -26,8 +26,6 @@ int NOTARISATION_SCAN_LIMIT_BLOCKS = 1440; CBlockIndex *komodo_getblockindex(uint256 hash); -extern std::string ASSETCHAINS_SELFIMPORT; -int32_t GetSelfimportProof(TxProof &proof,CTransaction burnTx,uint256 hash); /* On KMD */ @@ -293,13 +291,6 @@ TxProof GetAssetchainProof(uint256 hash,CTransaction burnTx) CBlockIndex* blockIndex; Notarisation nota; std::vector branch; - if ( ASSETCHAINS_SELFIMPORT.size() > 0 ) - { - TxProof proof; - if ( GetSelfimportProof(proof,burnTx,hash) < 0 ) - throw std::runtime_error("Failed validating selfimport"); - return(proof); - } { uint256 blockHash; CTransaction tx; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index eeedf1949..f0cecfe66 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1783,22 +1783,31 @@ void komodo_args(char *argv0) { fprintf(stderr,"invalid -ac_pubkey for -ac_import=PUBKEY\n"); ASSETCHAINS_SELFIMPORT = ""; + exit(0); } } else if ( ASSETCHAINS_SELFIMPORT == "BEAM" && ASSETCHAINS_BEAMPORT == 0 ) { fprintf(stderr,"missing -ac_beam for BEAM rpcport\n"); ASSETCHAINS_SELFIMPORT = ""; + exit(0); } else if ( ASSETCHAINS_SELFIMPORT == "CODA" && ASSETCHAINS_CODAPORT == 0 ) { fprintf(stderr,"missing -ac_coda for CODA rpcport\n"); ASSETCHAINS_SELFIMPORT = ""; + exit(0); } - else if ( ASSETCHAINS_SELFIMPORT != "GATEWAY" ) + else if ( ASSETCHAINS_SELFIMPORT.size() > 0 && ASSETCHAINS_SELFIMPORT != "GATEWAY" ) { fprintf(stderr,"invalid -ac_import type\n"); ASSETCHAINS_SELFIMPORT = ""; + exit(0); + } + if ( ASSETCHAINS_SELFIMPORT.size() > 0 && ASSETCHAINS_CC >= KOMODO_FIRST_FUNGIBLEID ) + { + fprintf(stderr,"selfimport chains cant be in a fungible cluster\n"); + exit(0); } //ASSETCHAINS_FOUNDERS_PERIOD = GetArg("-ac_period",0); @@ -1834,11 +1843,11 @@ void komodo_args(char *argv0) ASSETCHAINS_COMMISSION = 53846154; // maps to 35% printf("ASSETCHAINS_COMMISSION defaulted to 35%% when founders reward active\n"); } - else if ( ASSETCHAINS_SELFIMPORT.size() == 0 ) + /*else if ( ASSETCHAINS_SELFIMPORT.size() == 0 ) { //ASSETCHAINS_OVERRIDE_PUBKEY.clear(); printf("-ac_perc must be set with -ac_pubkey\n"); - } + }*/ } } else @@ -1946,7 +1955,12 @@ void komodo_args(char *argv0) MAX_MONEY = 10000100000LL*SATOSHIDEN; //fprintf(stderr,"MAX_MONEY %llu %.8f\n",(long long)MAX_MONEY,(double)MAX_MONEY/SATOSHIDEN); //printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,ASSETCHAINS_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); - ASSETCHAINS_P2PPORT = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); + port = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); + if ( GetArgs("-port",0) == 0 ) + ASSETCHAINS_P2PPORT = GetArgs("-port",0); + else ASSETCHAINS_P2PPORT = port; + mainParams.SetDefaultPort(ASSETCHAINS_P2PPORT); + while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 ) { fprintf(stderr,"waiting for datadir\n"); diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 617af120b..4495ab0f3 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -183,10 +183,11 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp) } if ( ASSETCHAINS_SELFIMPORT.size() > 0 ) { - if ( ASSETCHAINS_SELFIMPORT == targetSymbol || ASSETCHAINS_SELFIMPORT == "GATEWAY" ) + throw runtime_error("self-import chains cant be fungible"); + /*if ( ASSETCHAINS_SELFIMPORT == targetSymbol || ASSETCHAINS_SELFIMPORT == "GATEWAY" ) { ccid = 0xffffffff; - } // else maybe clusters of self-import chains can be supported? + } // else maybe clusters of self-import chains can be supported?*/ } CTxOut burnOut = MakeBurnOutput(burnAmount, ccid, targetSymbol, tx.vout); UniValue ret(UniValue::VOBJ); @@ -262,6 +263,29 @@ UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp) return HexStr(E_MARSHAL(ss << importTx)); } +#ifdef selfimport +UniValue selfimport(const UniValue& params, bool fHelp) +{ + TxProof proof; CTransaction importTx,burnTx; CTxOut burnOut; uint64_t burnAmount; uint256 blockHash; + if ( ASSETCHAINS_SELFIMPORT.size() == 0 ) + throw runtime_error("selfimport only works on -ac_import chains"); + if (fHelp || params.size() != 2) + throw runtime_error("selfimport txid burnamount\n\n" + "creates signed selfimport transaction from txid"); + //txid = + //burnAmount = + + if ( GetTransaction(txid,burnTx,hashBlock,false) == 0 ) + throw runtime_error("selfimport couldnt find txid"); + if ( GetSelfimportProof(proof,burnTx,txid) < 0 ) + throw std::runtime_error("Failed validating selfimport"); + + burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,burnTx.vout); + importTx = MakeImportCoinTransaction(proof,burnTx,payouts); + importTx.vout.clear(); + importTx.vout.push_back(burnOut); +} +#endif UniValue getNotarisationsForBlock(const UniValue& params, bool fHelp) { From 6fdc83c22d716b29203af6b3d14a318a3a8c157b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 28 Dec 2018 03:27:13 -1100 Subject: [PATCH 045/643] Syntax --- src/komodo_utils.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index f0cecfe66..373b0d16a 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1955,11 +1955,10 @@ void komodo_args(char *argv0) MAX_MONEY = 10000100000LL*SATOSHIDEN; //fprintf(stderr,"MAX_MONEY %llu %.8f\n",(long long)MAX_MONEY,(double)MAX_MONEY/SATOSHIDEN); //printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,ASSETCHAINS_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); - port = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); - if ( GetArgs("-port",0) == 0 ) - ASSETCHAINS_P2PPORT = GetArgs("-port",0); - else ASSETCHAINS_P2PPORT = port; - mainParams.SetDefaultPort(ASSETCHAINS_P2PPORT); + uint16_t tmpport = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); + if ( GetArg("-port",0) == 0 ) + ASSETCHAINS_P2PPORT = GetArg("-port",0); + else ASSETCHAINS_P2PPORT = tmpport; while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 ) { From df7b0fd17c841fbe68493831d46a0fa5c784c92f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 28 Dec 2018 03:30:25 -1100 Subject: [PATCH 046/643] KOMODO_FIRSTFUNGIBLEID --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 373b0d16a..b58fe3665 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1804,7 +1804,7 @@ void komodo_args(char *argv0) ASSETCHAINS_SELFIMPORT = ""; exit(0); } - if ( ASSETCHAINS_SELFIMPORT.size() > 0 && ASSETCHAINS_CC >= KOMODO_FIRST_FUNGIBLEID ) + if ( ASSETCHAINS_SELFIMPORT.size() > 0 && ASSETCHAINS_CC >= KOMODO_FIRSTFUNGIBLEID ) { fprintf(stderr,"selfimport chains cant be in a fungible cluster\n"); exit(0); From 0b2804b365c8d7a247a48191cabd3d5bc894ed0e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 28 Dec 2018 03:37:04 -1100 Subject: [PATCH 047/643] +print --- src/komodo_utils.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index b58fe3665..92e55fec5 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1957,8 +1957,10 @@ void komodo_args(char *argv0) //printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,ASSETCHAINS_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); uint16_t tmpport = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); if ( GetArg("-port",0) == 0 ) + { ASSETCHAINS_P2PPORT = GetArg("-port",0); - else ASSETCHAINS_P2PPORT = tmpport; + fprintf(stderr,"set port.%u\n",ASSETCHAINS_P2PPORT); + } else ASSETCHAINS_P2PPORT = tmpport; while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 ) { From ca4d8cbceddd856e683dd88c417e0eb343ac928b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 28 Dec 2018 03:39:29 -1100 Subject: [PATCH 048/643] Set p2pport! --- src/komodo_utils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 92e55fec5..5e25898b5 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1956,10 +1956,10 @@ void komodo_args(char *argv0) //fprintf(stderr,"MAX_MONEY %llu %.8f\n",(long long)MAX_MONEY,(double)MAX_MONEY/SATOSHIDEN); //printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,ASSETCHAINS_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); uint16_t tmpport = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); - if ( GetArg("-port",0) == 0 ) + if ( GetArg("-port",0) != 0 ) { ASSETCHAINS_P2PPORT = GetArg("-port",0); - fprintf(stderr,"set port.%u\n",ASSETCHAINS_P2PPORT); + fprintf(stderr,"set p2pport.%u\n",ASSETCHAINS_P2PPORT); } else ASSETCHAINS_P2PPORT = tmpport; while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 ) From 425bba692c6fd335734945ed9cb6e7d9bde503e3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 28 Dec 2018 03:41:26 -1100 Subject: [PATCH 049/643] Fix -port --- src/komodo_utils.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 19941a172..47b0e1755 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1911,7 +1911,13 @@ void komodo_args(char *argv0) MAX_MONEY = 10000100000LL*SATOSHIDEN; //fprintf(stderr,"MAX_MONEY %llu %.8f\n",(long long)MAX_MONEY,(double)MAX_MONEY/SATOSHIDEN); //printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,ASSETCHAINS_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); - ASSETCHAINS_P2PPORT = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); + uint16_t tmpport = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); + if ( GetArg("-port",0) != 0 ) + { + ASSETCHAINS_P2PPORT = GetArg("-port",0); + fprintf(stderr,"set p2pport.%u\n",ASSETCHAINS_P2PPORT); + } else ASSETCHAINS_P2PPORT = tmpport; + while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 ) { fprintf(stderr,"waiting for datadir\n"); From 6c23fd4159a98a7eee33dfb5350aa12e84bef27c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 00:59:36 -1100 Subject: [PATCH 050/643] Fix import tx CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); --- src/importcoin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/importcoin.cpp b/src/importcoin.cpp index d36943b5d..e6b5a166f 100644 --- a/src/importcoin.cpp +++ b/src/importcoin.cpp @@ -10,7 +10,7 @@ CTransaction MakeImportCoinTransaction(const TxProof proof, const CTransaction burnTx, const std::vector payouts) { std::vector payload = E_MARSHAL(ss << EVAL_IMPORTCOIN); - CMutableTransaction mtx; + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); mtx.vin.push_back(CTxIn(COutPoint(burnTx.GetHash(), 10e8), CScript() << payload)); mtx.vout = payouts; auto importData = E_MARSHAL(ss << proof; ss << burnTx); From 56d7a71dccb61aacb6ef13f11c0a4505ea198ecf Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 01:27:34 -1100 Subject: [PATCH 051/643] int32_t komodo_nextheight(); --- src/importcoin.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/importcoin.cpp b/src/importcoin.cpp index e6b5a166f..c80062390 100644 --- a/src/importcoin.cpp +++ b/src/importcoin.cpp @@ -6,6 +6,7 @@ #include "script/cc.h" #include "primitives/transaction.h" +int32_t komodo_nextheight(); CTransaction MakeImportCoinTransaction(const TxProof proof, const CTransaction burnTx, const std::vector payouts) { From ff966e77e8e1846909d1520553255dd88c638fa4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 01:29:05 -1100 Subject: [PATCH 052/643] #include "../wallet/wallet.h" --- src/importcoin.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/importcoin.cpp b/src/importcoin.cpp index c80062390..0366b4aac 100644 --- a/src/importcoin.cpp +++ b/src/importcoin.cpp @@ -5,6 +5,7 @@ #include "hash.h" #include "script/cc.h" #include "primitives/transaction.h" +#include "wallet/wallet.h" int32_t komodo_nextheight(); From cd1dc554ba41927e5b84dc35f2f793f4bce490c7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 01:29:55 -1100 Subject: [PATCH 053/643] #include "../core_io.h" #include "../script/sign.h" --- src/importcoin.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/importcoin.cpp b/src/importcoin.cpp index 0366b4aac..3c5ae323b 100644 --- a/src/importcoin.cpp +++ b/src/importcoin.cpp @@ -5,6 +5,8 @@ #include "hash.h" #include "script/cc.h" #include "primitives/transaction.h" +#include "core_io.h" +#include "script/sign.h" #include "wallet/wallet.h" int32_t komodo_nextheight(); From c10c7d330986f239dbd5b5522e923a7336f7c31b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 01:37:53 -1100 Subject: [PATCH 054/643] Komod-tx functions --- src/cc/channels.cpp | 8 +++++++- src/komodo-tx.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 9269096cc..3877ece2d 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -429,6 +429,12 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C else return 0; } + +int32_t komodo_nextheight() +{ + return(100000000); +} + std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64_t payment) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); @@ -811,4 +817,4 @@ UniValue ChannelsInfo(uint256 channeltxid) result.push_back(Pair("Error","Channel not found!")); } return(result); -} \ No newline at end of file +} diff --git a/src/komodo-tx.cpp b/src/komodo-tx.cpp index 3165023e0..1e3e632d4 100644 --- a/src/komodo-tx.cpp +++ b/src/komodo-tx.cpp @@ -177,6 +177,31 @@ static void RegisterLoad(const std::string& strInput) RegisterSetJson(key, valStr); } + +// Set default values of new CMutableTransaction based on consensus rules at given height. +CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Params& consensusParams, int nHeight) +{ + CMutableTransaction mtx; + + bool isOverwintered = NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_OVERWINTER); + if (isOverwintered) { + mtx.fOverwintered = true; + mtx.nExpiryHeight = nHeight + 60; + + if (NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_SAPLING)) { + mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; + mtx.nVersion = SAPLING_TX_VERSION; + } else { + mtx.nVersionGroupId = OVERWINTER_VERSION_GROUP_ID; + mtx.nVersion = OVERWINTER_TX_VERSION; + mtx.nExpiryHeight = std::min( + mtx.nExpiryHeight, + static_cast(consensusParams.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight - 1)); + } + } + return mtx; +} + static void MutateTxVersion(CMutableTransaction& tx, const std::string& cmdVal) { int64_t newVersion = atoi64(cmdVal); From 6a71342500b173cf60a05698efd2b18835b21249 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 01:39:30 -1100 Subject: [PATCH 055/643] Fixes --- src/cc/channels.cpp | 6 ------ src/komodo-tx.cpp | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 3877ece2d..4ee2d73e1 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -429,12 +429,6 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C else return 0; } - -int32_t komodo_nextheight() -{ - return(100000000); -} - std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64_t payment) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); diff --git a/src/komodo-tx.cpp b/src/komodo-tx.cpp index 1e3e632d4..b1b478972 100644 --- a/src/komodo-tx.cpp +++ b/src/komodo-tx.cpp @@ -178,6 +178,12 @@ static void RegisterLoad(const std::string& strInput) } +int32_t komodo_nextheight() +{ + return(100000000); +} + + // Set default values of new CMutableTransaction based on consensus rules at given height. CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Params& consensusParams, int nHeight) { From 142f5c112f14724af67e4b4cf0fda557f2227e26 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 01:47:55 -1100 Subject: [PATCH 056/643] Selfimport --- src/rpc/crosschain.cpp | 11 +++++------ src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 4495ab0f3..77ca43f73 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -263,7 +263,6 @@ UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp) return HexStr(E_MARSHAL(ss << importTx)); } -#ifdef selfimport UniValue selfimport(const UniValue& params, bool fHelp) { TxProof proof; CTransaction importTx,burnTx; CTxOut burnOut; uint64_t burnAmount; uint256 blockHash; @@ -272,10 +271,10 @@ UniValue selfimport(const UniValue& params, bool fHelp) if (fHelp || params.size() != 2) throw runtime_error("selfimport txid burnamount\n\n" "creates signed selfimport transaction from txid"); - //txid = - //burnAmount = - - if ( GetTransaction(txid,burnTx,hashBlock,false) == 0 ) + txid = Parseuint256((char *)params[0].get_str().c_str()); + burnAmount = atof(params[1].get_str().c_str()) * COIN + 0.00000000499999; + + if ( GetTransaction(txid,burnTx,blockHash,false) == 0 ) throw runtime_error("selfimport couldnt find txid"); if ( GetSelfimportProof(proof,burnTx,txid) < 0 ) throw std::runtime_error("Failed validating selfimport"); @@ -284,8 +283,8 @@ UniValue selfimport(const UniValue& params, bool fHelp) importTx = MakeImportCoinTransaction(proof,burnTx,payouts); importTx.vout.clear(); importTx.vout.push_back(burnOut); + return HexStr(E_MARSHAL(ss << importTx)); } -#endif UniValue getNotarisationsForBlock(const UniValue& params, bool fHelp) { diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index a4ec30b25..5bdc0b3ce 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -334,6 +334,7 @@ static const CRPCCommand vRPCCommands[] = { "crosschain", "migrate_converttoexport", &migrate_converttoexport, true }, { "crosschain", "migrate_createimporttransaction", &migrate_createimporttransaction, true }, { "crosschain", "migrate_completeimporttransaction", &migrate_completeimporttransaction, true }, + { "crosschain", "selfimport", &selfimport, true }, /* Mining */ { "mining", "getblocktemplate", &getblocktemplate, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 7a8ed75e3..96e3da82f 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -392,6 +392,7 @@ extern UniValue getchaintips(const UniValue& params, bool fHelp); extern UniValue invalidateblock(const UniValue& params, bool fHelp); extern UniValue reconsiderblock(const UniValue& params, bool fHelp); extern UniValue getspentinfo(const UniValue& params, bool fHelp); +extern UniValue selfimport(const UniValue& params, bool fHelp); extern UniValue getblocksubsidy(const UniValue& params, bool fHelp); From 35b0a03eeabc00a5328cbcb7ce02d9783bc16bb3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 01:51:37 -1100 Subject: [PATCH 057/643] burnTx.vout --- src/rpc/crosschain.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 77ca43f73..b90b8b3c4 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -265,7 +265,7 @@ UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp) UniValue selfimport(const UniValue& params, bool fHelp) { - TxProof proof; CTransaction importTx,burnTx; CTxOut burnOut; uint64_t burnAmount; uint256 blockHash; + TxProof proof; CTransaction importTx,burnTx; CTxOut burnOut; uint64_t burnAmount; uint256 txid,blockHash; if ( ASSETCHAINS_SELFIMPORT.size() == 0 ) throw runtime_error("selfimport only works on -ac_import chains"); if (fHelp || params.size() != 2) @@ -280,7 +280,7 @@ UniValue selfimport(const UniValue& params, bool fHelp) throw std::runtime_error("Failed validating selfimport"); burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,burnTx.vout); - importTx = MakeImportCoinTransaction(proof,burnTx,payouts); + importTx = MakeImportCoinTransaction(proof,burnTx,burnTx.vout); importTx.vout.clear(); importTx.vout.push_back(burnOut); return HexStr(E_MARSHAL(ss << importTx)); From 66fa31ba94c21e95f3259a7f75ac9ac9ccf37183 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 01:54:43 -1100 Subject: [PATCH 058/643] Max --- src/rpc/crosschain.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index b90b8b3c4..c2df6ef5e 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -265,7 +265,8 @@ UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp) UniValue selfimport(const UniValue& params, bool fHelp) { - TxProof proof; CTransaction importTx,burnTx; CTxOut burnOut; uint64_t burnAmount; uint256 txid,blockHash; + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + TxProof proof; CTransaction burnTx; CTxOut burnOut; uint64_t burnAmount; uint256 txid,blockHash; if ( ASSETCHAINS_SELFIMPORT.size() == 0 ) throw runtime_error("selfimport only works on -ac_import chains"); if (fHelp || params.size() != 2) @@ -280,10 +281,10 @@ UniValue selfimport(const UniValue& params, bool fHelp) throw std::runtime_error("Failed validating selfimport"); burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,burnTx.vout); - importTx = MakeImportCoinTransaction(proof,burnTx,burnTx.vout); - importTx.vout.clear(); - importTx.vout.push_back(burnOut); - return HexStr(E_MARSHAL(ss << importTx)); + mtx = MakeImportCoinTransaction(proof,burnTx,burnTx.vout); + mtx.vout.clear(); + mtx.vout.push_back(burnOut); + return HexStr(E_MARSHAL(ss << mtx)); } UniValue getNotarisationsForBlock(const UniValue& params, bool fHelp) From 588eb54211cd4f064645d305159b37dc554bb943 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 01:56:13 -1100 Subject: [PATCH 059/643] Externs --- src/rpc/crosschain.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index c2df6ef5e..098076ef3 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -31,6 +31,10 @@ int32_t komodo_MoMoMdata(char *hexstr,int32_t hexsize,struct komodo_ccdataMoMoM struct komodo_ccdata_entry *komodo_allMoMs(int32_t *nump,uint256 *MoMoMp,int32_t kmdstarti,int32_t kmdendi); uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth); extern std::string ASSETCHAINS_SELFIMPORT; +int komodo_nextheight(); +uint256 Parseuint256(char *hexstr); +int32_t GetSelfimportProof(TxProof &proof,CTransaction burnTx,uint256 hash); + UniValue assetchainproof(const UniValue& params, bool fHelp) { From 5f3417a2206d3e73fd0654bd1f8a86f9cdcecb33 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 02:26:40 -1100 Subject: [PATCH 060/643] Tombstone of 4 --- src/importcoin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/importcoin.cpp b/src/importcoin.cpp index 3c5ae323b..c16822579 100644 --- a/src/importcoin.cpp +++ b/src/importcoin.cpp @@ -106,7 +106,7 @@ void AddImportTombstone(const CTransaction &importTx, CCoinsViewCache &inputs, i uint256 burnHash = importTx.vin[0].prevout.hash; CCoinsModifier modifier = inputs.ModifyCoins(burnHash); modifier->nHeight = nHeight; - modifier->nVersion = 1; + modifier->nVersion = 4;//1; modifier->vout.push_back(CTxOut(0, CScript() << OP_0)); } From 9840fc08d982f5583e64ed8a0a1944c9cd92f2db Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 02:58:10 -1100 Subject: [PATCH 061/643] +prints --- src/importcoin.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/importcoin.cpp b/src/importcoin.cpp index c16822579..d7d75290c 100644 --- a/src/importcoin.cpp +++ b/src/importcoin.cpp @@ -104,6 +104,7 @@ bool VerifyCoinImport(const CScript& scriptSig, TransactionSignatureChecker& che void AddImportTombstone(const CTransaction &importTx, CCoinsViewCache &inputs, int nHeight) { uint256 burnHash = importTx.vin[0].prevout.hash; + fprintf(stderr,"add tombstone.(%s)\n",burnHash.GetHex()); CCoinsModifier modifier = inputs.ModifyCoins(burnHash); modifier->nHeight = nHeight; modifier->nVersion = 4;//1; @@ -121,5 +122,6 @@ void RemoveImportTombstone(const CTransaction &importTx, CCoinsViewCache &inputs int ExistsImportTombstone(const CTransaction &importTx, const CCoinsViewCache &inputs) { uint256 burnHash = importTx.vin[0].prevout.hash; + fprintf(stderr,"check tombstone.(%s)\n",burnHash.GetHex()); return inputs.HaveCoins(burnHash); } From 8ba558a7c21019794ace21f902ad74761b95381d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 03:02:46 -1100 Subject: [PATCH 062/643] +print --- src/importcoin.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/importcoin.cpp b/src/importcoin.cpp index d7d75290c..e83a71add 100644 --- a/src/importcoin.cpp +++ b/src/importcoin.cpp @@ -104,7 +104,7 @@ bool VerifyCoinImport(const CScript& scriptSig, TransactionSignatureChecker& che void AddImportTombstone(const CTransaction &importTx, CCoinsViewCache &inputs, int nHeight) { uint256 burnHash = importTx.vin[0].prevout.hash; - fprintf(stderr,"add tombstone.(%s)\n",burnHash.GetHex()); + fprintf(stderr,"add tombstone.(%s)\n",burnHash.GetHex().c_str()); CCoinsModifier modifier = inputs.ModifyCoins(burnHash); modifier->nHeight = nHeight; modifier->nVersion = 4;//1; @@ -115,6 +115,7 @@ void AddImportTombstone(const CTransaction &importTx, CCoinsViewCache &inputs, i void RemoveImportTombstone(const CTransaction &importTx, CCoinsViewCache &inputs) { uint256 burnHash = importTx.vin[0].prevout.hash; + fprintf(stderr,"remove tombstone.(%s)\n",burnHash.GetHex().c_str()); inputs.ModifyCoins(burnHash)->Clear(); } @@ -122,6 +123,6 @@ void RemoveImportTombstone(const CTransaction &importTx, CCoinsViewCache &inputs int ExistsImportTombstone(const CTransaction &importTx, const CCoinsViewCache &inputs) { uint256 burnHash = importTx.vin[0].prevout.hash; - fprintf(stderr,"check tombstone.(%s)\n",burnHash.GetHex()); + fprintf(stderr,"check tombstone.(%s) in %s\n",burnHash.GetHex().c_str(),importTx.GetHash().GetHex().c_str()); return inputs.HaveCoins(burnHash); } From 061b5bd8cb59c2c5fb54695485aa14a9fed21505 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 03:20:18 -1100 Subject: [PATCH 063/643] Can't have burn txid onchain for selfimport --- src/rpc/crosschain.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 098076ef3..458496854 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -278,12 +278,12 @@ UniValue selfimport(const UniValue& params, bool fHelp) "creates signed selfimport transaction from txid"); txid = Parseuint256((char *)params[0].get_str().c_str()); burnAmount = atof(params[1].get_str().c_str()) * COIN + 0.00000000499999; - + if ( GetTransaction(txid,burnTx,blockHash,false) == 0 ) throw runtime_error("selfimport couldnt find txid"); + ((uint_8 *)&txid)[0] = 0; //make burntx but dont confirm it, it needs to be as if it was from a different chain if ( GetSelfimportProof(proof,burnTx,txid) < 0 ) throw std::runtime_error("Failed validating selfimport"); - burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,burnTx.vout); mtx = MakeImportCoinTransaction(proof,burnTx,burnTx.vout); mtx.vout.clear(); From d721008ae77f3c7256d68ddd8c358479869d29be Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 03:22:00 -1100 Subject: [PATCH 064/643] uint8_t --- src/rpc/crosschain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 458496854..91b59c73d 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -281,7 +281,7 @@ UniValue selfimport(const UniValue& params, bool fHelp) if ( GetTransaction(txid,burnTx,blockHash,false) == 0 ) throw runtime_error("selfimport couldnt find txid"); - ((uint_8 *)&txid)[0] = 0; //make burntx but dont confirm it, it needs to be as if it was from a different chain + ((uint8_t *)&txid)[0] = 0; //make burntx but dont confirm it, it needs to be as if it was from a different chain if ( GetSelfimportProof(proof,burnTx,txid) < 0 ) throw std::runtime_error("Failed validating selfimport"); burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,burnTx.vout); From e55a510f506be367ef6be08ac5f14eb17d7bc7a3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 03:25:11 -1100 Subject: [PATCH 065/643] use mtx for burn --- src/rpc/crosschain.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 91b59c73d..fc8ae9a2b 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -281,7 +281,11 @@ UniValue selfimport(const UniValue& params, bool fHelp) if ( GetTransaction(txid,burnTx,blockHash,false) == 0 ) throw runtime_error("selfimport couldnt find txid"); - ((uint8_t *)&txid)[0] = 0; //make burntx but dont confirm it, it needs to be as if it was from a different chain + burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,burnTx.vout); + mtx = burnTx; + mtx.vout.clear(); + mtx.vout.push_back(burnOut); + burnTx = mtx; if ( GetSelfimportProof(proof,burnTx,txid) < 0 ) throw std::runtime_error("Failed validating selfimport"); burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,burnTx.vout); From 8844b055165b29e07709adf823e8d49892e41a04 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 03:28:37 -1100 Subject: [PATCH 066/643] Test --- src/rpc/crosschain.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index fc8ae9a2b..7626d6424 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -290,8 +290,6 @@ UniValue selfimport(const UniValue& params, bool fHelp) throw std::runtime_error("Failed validating selfimport"); burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,burnTx.vout); mtx = MakeImportCoinTransaction(proof,burnTx,burnTx.vout); - mtx.vout.clear(); - mtx.vout.push_back(burnOut); return HexStr(E_MARSHAL(ss << mtx)); } From 89a38e9e2fab7c157b6915632f7d89cb2345bd5e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 03:32:04 -1100 Subject: [PATCH 067/643] Set amount --- src/rpc/crosschain.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 7626d6424..3b5a06e9f 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -290,6 +290,8 @@ UniValue selfimport(const UniValue& params, bool fHelp) throw std::runtime_error("Failed validating selfimport"); burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,burnTx.vout); mtx = MakeImportCoinTransaction(proof,burnTx,burnTx.vout); + mtx.vout[1] = burnTx.vout[0]; + mtx.vout[1].nValue = burnAmount; return HexStr(E_MARSHAL(ss << mtx)); } From b36413b8e5c7744ec6afd2ab905ad974b3a6f134 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 03:32:57 -1100 Subject: [PATCH 068/643] Test --- src/rpc/crosschain.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 3b5a06e9f..52af705bf 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -270,7 +270,7 @@ UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp) UniValue selfimport(const UniValue& params, bool fHelp) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - TxProof proof; CTransaction burnTx; CTxOut burnOut; uint64_t burnAmount; uint256 txid,blockHash; + TxProof proof; CTransaction burnTx; CTxOut burnOut,tmpvout; uint64_t burnAmount; uint256 txid,blockHash; if ( ASSETCHAINS_SELFIMPORT.size() == 0 ) throw runtime_error("selfimport only works on -ac_import chains"); if (fHelp || params.size() != 2) @@ -290,8 +290,10 @@ UniValue selfimport(const UniValue& params, bool fHelp) throw std::runtime_error("Failed validating selfimport"); burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,burnTx.vout); mtx = MakeImportCoinTransaction(proof,burnTx,burnTx.vout); - mtx.vout[1] = burnTx.vout[0]; - mtx.vout[1].nValue = burnAmount; + mtx.vout[0] = burnTx.vout[0]; + mtx.vout[0].nValue = burnAmount; + tmpvout = mtx.vout[0]; + mtx.vout[1] = tmpvout; return HexStr(E_MARSHAL(ss << mtx)); } From 504af0a7559b3266c2c3873ae67d881424e6d5d2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 03:34:37 -1100 Subject: [PATCH 069/643] Test --- src/rpc/crosschain.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 52af705bf..3b5a06e9f 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -270,7 +270,7 @@ UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp) UniValue selfimport(const UniValue& params, bool fHelp) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - TxProof proof; CTransaction burnTx; CTxOut burnOut,tmpvout; uint64_t burnAmount; uint256 txid,blockHash; + TxProof proof; CTransaction burnTx; CTxOut burnOut; uint64_t burnAmount; uint256 txid,blockHash; if ( ASSETCHAINS_SELFIMPORT.size() == 0 ) throw runtime_error("selfimport only works on -ac_import chains"); if (fHelp || params.size() != 2) @@ -290,10 +290,8 @@ UniValue selfimport(const UniValue& params, bool fHelp) throw std::runtime_error("Failed validating selfimport"); burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,burnTx.vout); mtx = MakeImportCoinTransaction(proof,burnTx,burnTx.vout); - mtx.vout[0] = burnTx.vout[0]; - mtx.vout[0].nValue = burnAmount; - tmpvout = mtx.vout[0]; - mtx.vout[1] = tmpvout; + mtx.vout[1] = burnTx.vout[0]; + mtx.vout[1].nValue = burnAmount; return HexStr(E_MARSHAL(ss << mtx)); } From c182e9a4809cdb8e9f73eca2d70dd208ebf6ee0c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 03:37:00 -1100 Subject: [PATCH 070/643] burnv --- src/rpc/crosschain.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 3b5a06e9f..153ce6a8d 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -270,7 +270,7 @@ UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp) UniValue selfimport(const UniValue& params, bool fHelp) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - TxProof proof; CTransaction burnTx; CTxOut burnOut; uint64_t burnAmount; uint256 txid,blockHash; + TxProof proof; CTransaction burnTx; CTxOut burnOut,savevout; uint64_t burnAmount; uint256 txid,blockHash; if ( ASSETCHAINS_SELFIMPORT.size() == 0 ) throw runtime_error("selfimport only works on -ac_import chains"); if (fHelp || params.size() != 2) @@ -282,6 +282,7 @@ UniValue selfimport(const UniValue& params, bool fHelp) if ( GetTransaction(txid,burnTx,blockHash,false) == 0 ) throw runtime_error("selfimport couldnt find txid"); burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,burnTx.vout); + savevout = burnTx.vout[0]; mtx = burnTx; mtx.vout.clear(); mtx.vout.push_back(burnOut); @@ -290,7 +291,7 @@ UniValue selfimport(const UniValue& params, bool fHelp) throw std::runtime_error("Failed validating selfimport"); burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,burnTx.vout); mtx = MakeImportCoinTransaction(proof,burnTx,burnTx.vout); - mtx.vout[1] = burnTx.vout[0]; + mtx.vout[1] = savevout; mtx.vout[1].nValue = burnAmount; return HexStr(E_MARSHAL(ss << mtx)); } From 79f63e2a86633f337b57d28a578803279680adf9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 03:45:00 -1100 Subject: [PATCH 071/643] Test --- src/rpc/crosschain.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 153ce6a8d..7f7f43452 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -281,11 +281,9 @@ UniValue selfimport(const UniValue& params, bool fHelp) if ( GetTransaction(txid,burnTx,blockHash,false) == 0 ) throw runtime_error("selfimport couldnt find txid"); - burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,burnTx.vout); savevout = burnTx.vout[0]; mtx = burnTx; - mtx.vout.clear(); - mtx.vout.push_back(burnOut); + mtx.vin.clear(); burnTx = mtx; if ( GetSelfimportProof(proof,burnTx,txid) < 0 ) throw std::runtime_error("Failed validating selfimport"); From b919700d633e3b2e4a629f1a4135e549ee75e879 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 03:54:58 -1100 Subject: [PATCH 072/643] Fix burn --- src/rpc/crosschain.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 7f7f43452..a016a5909 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -281,12 +281,16 @@ UniValue selfimport(const UniValue& params, bool fHelp) if ( GetTransaction(txid,burnTx,blockHash,false) == 0 ) throw runtime_error("selfimport couldnt find txid"); + burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,burnTx.vout); savevout = burnTx.vout[0]; mtx = burnTx; - mtx.vin.clear(); + mtx.vout.clear(); + mtx.vout.push_back(burnOut); burnTx = mtx; - if ( GetSelfimportProof(proof,burnTx,txid) < 0 ) + if ( GetSelfimportProof(proof,burnTx,burnTx.GetHash()) < 0 ) throw std::runtime_error("Failed validating selfimport"); + if ( GetTransaction(txid,burnTx,blockHash,false) == 0 ) + throw runtime_error("selfimport couldnt find txid"); burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,burnTx.vout); mtx = MakeImportCoinTransaction(proof,burnTx,burnTx.vout); mtx.vout[1] = savevout; From 48282958ae0a09e3ceb4c6c97a3cc285e03b6a60 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 03:58:50 -1100 Subject: [PATCH 073/643] Test --- src/rpc/crosschain.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index a016a5909..6ccf3c0f2 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -270,7 +270,7 @@ UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp) UniValue selfimport(const UniValue& params, bool fHelp) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - TxProof proof; CTransaction burnTx; CTxOut burnOut,savevout; uint64_t burnAmount; uint256 txid,blockHash; + TxProof proof; CTransaction burnTx; CTxOut burnOut,savevout; uint64_t burnAmount; uint256 txid,blockHash; std::vector CTxOut vouts; if ( ASSETCHAINS_SELFIMPORT.size() == 0 ) throw runtime_error("selfimport only works on -ac_import chains"); if (fHelp || params.size() != 2) @@ -283,18 +283,16 @@ UniValue selfimport(const UniValue& params, bool fHelp) throw runtime_error("selfimport couldnt find txid"); burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,burnTx.vout); savevout = burnTx.vout[0]; + vouts = burnTx.vout; mtx = burnTx; mtx.vout.clear(); mtx.vout.push_back(burnOut); burnTx = mtx; if ( GetSelfimportProof(proof,burnTx,burnTx.GetHash()) < 0 ) throw std::runtime_error("Failed validating selfimport"); - if ( GetTransaction(txid,burnTx,blockHash,false) == 0 ) - throw runtime_error("selfimport couldnt find txid"); - burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,burnTx.vout); - mtx = MakeImportCoinTransaction(proof,burnTx,burnTx.vout); - mtx.vout[1] = savevout; - mtx.vout[1].nValue = burnAmount; + mtx = MakeImportCoinTransaction(proof,burnTx,vouts); + //mtx.vout[1] = savevout; + //mtx.vout[1].nValue = burnAmount; return HexStr(E_MARSHAL(ss << mtx)); } From ed7a77697a0ecb64389afba212c82c94422a34f2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 04:00:26 -1100 Subject: [PATCH 074/643] <> --- src/rpc/crosschain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 6ccf3c0f2..91fe6fcf8 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -270,7 +270,7 @@ UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp) UniValue selfimport(const UniValue& params, bool fHelp) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - TxProof proof; CTransaction burnTx; CTxOut burnOut,savevout; uint64_t burnAmount; uint256 txid,blockHash; std::vector CTxOut vouts; + TxProof proof; CTransaction burnTx; CTxOut burnOut,savevout; uint64_t burnAmount; uint256 txid,blockHash; std::vector vouts; if ( ASSETCHAINS_SELFIMPORT.size() == 0 ) throw runtime_error("selfimport only works on -ac_import chains"); if (fHelp || params.size() != 2) From 24a9e7c408b77f0f3e50016676053dfe07436c0a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 04:03:29 -1100 Subject: [PATCH 075/643] test --- src/rpc/crosschain.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 91fe6fcf8..385e23012 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -291,8 +291,9 @@ UniValue selfimport(const UniValue& params, bool fHelp) if ( GetSelfimportProof(proof,burnTx,burnTx.GetHash()) < 0 ) throw std::runtime_error("Failed validating selfimport"); mtx = MakeImportCoinTransaction(proof,burnTx,vouts); - //mtx.vout[1] = savevout; - //mtx.vout[1].nValue = burnAmount; + mtx.vout.resize(2); + mtx.vout[1] = savevout; + mtx.vout[1].nValue = burnAmount; return HexStr(E_MARSHAL(ss << mtx)); } From 27d672a972b15abd6cc9f717bae46168e524cc20 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 04:13:20 -1100 Subject: [PATCH 076/643] Test --- src/rpc/crosschain.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 385e23012..a41b7eb7c 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -281,9 +281,12 @@ UniValue selfimport(const UniValue& params, bool fHelp) if ( GetTransaction(txid,burnTx,blockHash,false) == 0 ) throw runtime_error("selfimport couldnt find txid"); - burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,burnTx.vout); savevout = burnTx.vout[0]; - vouts = burnTx.vout; + mtx.vout.resize(2); + mtx.vout[1] = savevout; + mtx.vout[1].nValue = burnAmount; + vouts = mtx.vout; + burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,vouts); mtx = burnTx; mtx.vout.clear(); mtx.vout.push_back(burnOut); From 31129381b4952440085621c064f7aba72df96e19 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 04:24:00 -1100 Subject: [PATCH 077/643] Test --- src/rpc/crosschain.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index a41b7eb7c..fa07be9ef 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -282,10 +282,7 @@ UniValue selfimport(const UniValue& params, bool fHelp) if ( GetTransaction(txid,burnTx,blockHash,false) == 0 ) throw runtime_error("selfimport couldnt find txid"); savevout = burnTx.vout[0]; - mtx.vout.resize(2); - mtx.vout[1] = savevout; - mtx.vout[1].nValue = burnAmount; - vouts = mtx.vout; + vouts = burnTx.vout; burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,vouts); mtx = burnTx; mtx.vout.clear(); @@ -293,10 +290,11 @@ UniValue selfimport(const UniValue& params, bool fHelp) burnTx = mtx; if ( GetSelfimportProof(proof,burnTx,burnTx.GetHash()) < 0 ) throw std::runtime_error("Failed validating selfimport"); + mtx.clear(); mtx = MakeImportCoinTransaction(proof,burnTx,vouts); - mtx.vout.resize(2); - mtx.vout[1] = savevout; - mtx.vout[1].nValue = burnAmount; + //mtx.vout.resize(2); + //mtx.vout[1] = savevout; + //mtx.vout[1].nValue = burnAmount; return HexStr(E_MARSHAL(ss << mtx)); } From 5e890aa4f19f8bacbfc60526ce9bce52b6521946 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 04:26:40 -1100 Subject: [PATCH 078/643] Test --- src/rpc/crosschain.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index fa07be9ef..e006920e2 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -290,12 +290,11 @@ UniValue selfimport(const UniValue& params, bool fHelp) burnTx = mtx; if ( GetSelfimportProof(proof,burnTx,burnTx.GetHash()) < 0 ) throw std::runtime_error("Failed validating selfimport"); - mtx.clear(); - mtx = MakeImportCoinTransaction(proof,burnTx,vouts); + //mtx = MakeImportCoinTransaction(proof,burnTx,vouts); //mtx.vout.resize(2); //mtx.vout[1] = savevout; //mtx.vout[1].nValue = burnAmount; - return HexStr(E_MARSHAL(ss << mtx)); + return HexStr(E_MARSHAL(ss << MakeImportCoinTransaction(proof,burnTx,vouts))); } UniValue getNotarisationsForBlock(const UniValue& params, bool fHelp) From b6c528f6dfd296d7d24542795e75e07c5d3fced2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 04:29:35 -1100 Subject: [PATCH 079/643] Ignore absurd fees for import --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 9e7473fd0..0e4fc24e5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1850,7 +1850,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa dFreeCount += nSize; } - if (fRejectAbsurdFee && nFees > ::minRelayTxFee.GetFee(nSize) * 10000 && nFees > nValueOut/19) + if (!tx.IsCoinImport() && fRejectAbsurdFee && nFees > ::minRelayTxFee.GetFee(nSize) * 10000 && nFees > nValueOut/19) { string errmsg = strprintf("absurdly high fees %s, %d > %d", hash.ToString(), From 7598b1c37586cbd34ec9ff23db130887d2714ce6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 04:32:00 -1100 Subject: [PATCH 080/643] Fix --- src/cc/import.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index 4d61b4bf8..a6af41024 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -141,17 +141,17 @@ bool Eval::ImportCoin(const std::vector params, const CTransaction &imp } else if ( ASSETCHAINS_SELFIMPORT == targetSymbol || ASSETCHAINS_SELFIMPORT == "GATEWAY" ) // various selfchain imports { - if ( GetAssetchainsSymbol() == "BEAM" ) + if ( ASSETCHAINS_SELFIMPORT == "BEAM" ) { if ( CheckBEAMimport(proof,burnTx,payouts) < 0 ) return Invalid("BEAM-import-failure"); } - else if ( GetAssetchainsSymbol() == "CODA" ) + else if ( ASSETCHAINS_SELFIMPORT == "CODA" ) { if ( CheckCODAimport(proof,burnTx,payouts) < 0 ) return Invalid("CODA-import-failure"); } - else if ( GetAssetchainsSymbol() == "PUBKEY" ) + else if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) { if ( CheckPUBKEYimport(proof,burnTx,payouts) < 0 ) return Invalid("PUBKEY-import-failure"); From a1cdd5642535c92e7a4d96a13c41e38e750979b3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 04:37:06 -1100 Subject: [PATCH 081/643] Test --- src/rpc/crosschain.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index e006920e2..4a140b468 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -282,7 +282,12 @@ UniValue selfimport(const UniValue& params, bool fHelp) if ( GetTransaction(txid,burnTx,blockHash,false) == 0 ) throw runtime_error("selfimport couldnt find txid"); savevout = burnTx.vout[0]; - vouts = burnTx.vout; + mtx = burnTx; + mtx.vout.clear(); + mtx.vout.resize(1); + mtx.vout[0] = savevout; + mtx.vout[0].nValue = burnValue; + vouts = mtx.vout; burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,vouts); mtx = burnTx; mtx.vout.clear(); From 302c65efd615c8b7f1fde8352ee96ea0e5f33286 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 04:37:38 -1100 Subject: [PATCH 082/643] burnAmount --- src/rpc/crosschain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 4a140b468..595d3bbcb 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -286,7 +286,7 @@ UniValue selfimport(const UniValue& params, bool fHelp) mtx.vout.clear(); mtx.vout.resize(1); mtx.vout[0] = savevout; - mtx.vout[0].nValue = burnValue; + mtx.vout[0].nValue = burnAmount; vouts = mtx.vout; burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,vouts); mtx = burnTx; From 0841122cf4ee39b7078e29f83474c92981b116e3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 04:43:07 -1100 Subject: [PATCH 083/643] - --- src/rpc/crosschain.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 595d3bbcb..f3c0e887d 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -295,10 +295,6 @@ UniValue selfimport(const UniValue& params, bool fHelp) burnTx = mtx; if ( GetSelfimportProof(proof,burnTx,burnTx.GetHash()) < 0 ) throw std::runtime_error("Failed validating selfimport"); - //mtx = MakeImportCoinTransaction(proof,burnTx,vouts); - //mtx.vout.resize(2); - //mtx.vout[1] = savevout; - //mtx.vout[1].nValue = burnAmount; return HexStr(E_MARSHAL(ss << MakeImportCoinTransaction(proof,burnTx,vouts))); } From e5c1fd79cad561c53a3acc4764998b161d385492 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 04:51:35 -1100 Subject: [PATCH 084/643] -prints --- src/importcoin.cpp | 6 +++--- src/rpc/crosschain.cpp | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/importcoin.cpp b/src/importcoin.cpp index e83a71add..b2d48b848 100644 --- a/src/importcoin.cpp +++ b/src/importcoin.cpp @@ -104,7 +104,7 @@ bool VerifyCoinImport(const CScript& scriptSig, TransactionSignatureChecker& che void AddImportTombstone(const CTransaction &importTx, CCoinsViewCache &inputs, int nHeight) { uint256 burnHash = importTx.vin[0].prevout.hash; - fprintf(stderr,"add tombstone.(%s)\n",burnHash.GetHex().c_str()); + //fprintf(stderr,"add tombstone.(%s)\n",burnHash.GetHex().c_str()); CCoinsModifier modifier = inputs.ModifyCoins(burnHash); modifier->nHeight = nHeight; modifier->nVersion = 4;//1; @@ -115,7 +115,7 @@ void AddImportTombstone(const CTransaction &importTx, CCoinsViewCache &inputs, i void RemoveImportTombstone(const CTransaction &importTx, CCoinsViewCache &inputs) { uint256 burnHash = importTx.vin[0].prevout.hash; - fprintf(stderr,"remove tombstone.(%s)\n",burnHash.GetHex().c_str()); + //fprintf(stderr,"remove tombstone.(%s)\n",burnHash.GetHex().c_str()); inputs.ModifyCoins(burnHash)->Clear(); } @@ -123,6 +123,6 @@ void RemoveImportTombstone(const CTransaction &importTx, CCoinsViewCache &inputs int ExistsImportTombstone(const CTransaction &importTx, const CCoinsViewCache &inputs) { uint256 burnHash = importTx.vin[0].prevout.hash; - fprintf(stderr,"check tombstone.(%s) in %s\n",burnHash.GetHex().c_str(),importTx.GetHash().GetHex().c_str()); + //fprintf(stderr,"check tombstone.(%s) in %s\n",burnHash.GetHex().c_str(),importTx.GetHash().GetHex().c_str()); return inputs.HaveCoins(burnHash); } diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index f3c0e887d..a2e74477a 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -278,7 +278,8 @@ UniValue selfimport(const UniValue& params, bool fHelp) "creates signed selfimport transaction from txid"); txid = Parseuint256((char *)params[0].get_str().c_str()); burnAmount = atof(params[1].get_str().c_str()) * COIN + 0.00000000499999; - + // txid is just used to specify the import recv address + // in reality it would be rawtx from the other chain if ( GetTransaction(txid,burnTx,blockHash,false) == 0 ) throw runtime_error("selfimport couldnt find txid"); savevout = burnTx.vout[0]; From 8624abc6169abdc87f35bb38031a50838356f348 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 04:57:40 -1100 Subject: [PATCH 085/643] Self burn --- src/rpc/crosschain.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index a2e74477a..4f7603507 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -270,7 +270,7 @@ UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp) UniValue selfimport(const UniValue& params, bool fHelp) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - TxProof proof; CTransaction burnTx; CTxOut burnOut,savevout; uint64_t burnAmount; uint256 txid,blockHash; std::vector vouts; + TxProof proof; CTransaction burnTx,tx; CTxOut burnOut,savevout; uint64_t burnAmount; uint256 txid,blockHash; std::vector vouts; if ( ASSETCHAINS_SELFIMPORT.size() == 0 ) throw runtime_error("selfimport only works on -ac_import chains"); if (fHelp || params.size() != 2) @@ -280,21 +280,21 @@ UniValue selfimport(const UniValue& params, bool fHelp) burnAmount = atof(params[1].get_str().c_str()) * COIN + 0.00000000499999; // txid is just used to specify the import recv address // in reality it would be rawtx from the other chain - if ( GetTransaction(txid,burnTx,blockHash,false) == 0 ) + if ( GetTransaction(txid,tx,blockHash,false) == 0 ) throw runtime_error("selfimport couldnt find txid"); - savevout = burnTx.vout[0]; - mtx = burnTx; + savevout = tx.vout[0]; + mtx = tx; mtx.vout.clear(); mtx.vout.resize(1); mtx.vout[0] = savevout; mtx.vout[0].nValue = burnAmount; vouts = mtx.vout; burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,vouts); - mtx = burnTx; + mtx = tx; mtx.vout.clear(); mtx.vout.push_back(burnOut); burnTx = mtx; - if ( GetSelfimportProof(proof,burnTx,burnTx.GetHash()) < 0 ) + if ( GetSelfimportProof(proof,tx,txid) < 0 ) throw std::runtime_error("Failed validating selfimport"); return HexStr(E_MARSHAL(ss << MakeImportCoinTransaction(proof,burnTx,vouts))); } From cfa2f63f429a27d4354901eb270c61523edf5c75 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Mon, 31 Dec 2018 11:11:07 +0100 Subject: [PATCH 086/643] Fix daemon crashing when sending funds to oracles marker and doing oracleslist --- src/cc/oracles.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 135f822dc..17679bccd 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -108,7 +108,7 @@ uint8_t DecodeOraclesCreateOpRet(const CScript &scriptPubKey,std::string &name,s std::vector vopret; uint8_t *script,e,f,funcid; GetOpReturnData(scriptPubKey,vopret); script = (uint8_t *)vopret.data(); - if ( script[0] == EVAL_ORACLES ) + if ( vopret.size() > 2 && script[0] == EVAL_ORACLES ) { if ( script[1] == 'C' ) { @@ -133,7 +133,7 @@ uint8_t DecodeOraclesOpRet(const CScript &scriptPubKey,uint256 &oracletxid,CPubK std::vector vopret; uint8_t *script,e,f; GetOpReturnData(scriptPubKey,vopret); script = (uint8_t *)vopret.data(); - if ( vopret.size() > 1 && script[0] == EVAL_ORACLES ) + if ( vopret.size() > 2 && script[0] == EVAL_ORACLES ) { if (script[0] == EVAL_ORACLES && (script[1]== 'R' || script[1] == 'S') && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> oracletxid; ss >> pk; ss >> num)!=0) return(f); @@ -154,7 +154,7 @@ uint8_t DecodeOraclesData(const CScript &scriptPubKey,uint256 &oracletxid,uint25 std::vector vopret; uint8_t *script,e,f; GetOpReturnData(scriptPubKey,vopret); script = (uint8_t *)vopret.data(); - if ( vopret.size() > 1 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> oracletxid; ss >> batontxid; ss >> pk; ss >> data) != 0 ) + if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> oracletxid; ss >> batontxid; ss >> pk; ss >> data) != 0 ) { if ( e == EVAL_ORACLES && f == 'D' ) return(f); From 0ea9ae3c0577020c22c934084e6980c4d391a0eb Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Dec 2018 21:41:05 -1100 Subject: [PATCH 087/643] Update copyright to 2019 --- COPYING | 344 +++++++++++++++++- src/addrman.cpp | 15 + src/addrman.h | 15 + src/alert.cpp | 15 + src/alert.h | 15 + src/alertkeys.h | 15 + src/amount.cpp | 15 + src/amount.h | 15 + src/arith_uint256.cpp | 15 + src/arith_uint256.h | 15 + src/asyncrpcoperation.cpp | 15 + src/asyncrpcoperation.h | 14 + src/asyncrpcqueue.cpp | 15 + src/asyncrpcqueue.h | 15 + src/base58.cpp | 15 + src/base58.h | 15 + src/bitcoin-cli.cpp | 15 + src/bitcoind.cpp | 15 + src/bloom.cpp | 15 + src/bloom.h | 15 + src/cJSON.c | 15 + src/cJSON.h | 15 + src/cc/CC made easy.md | 2 +- src/cc/CCGateways.h | 2 +- src/cc/CCHeir.h | 2 +- src/cc/CCOracles.h | 2 +- src/cc/CCPayments.h | 2 +- src/cc/CCPegs.h | 2 +- src/cc/CCPrices.h | 2 +- src/cc/CCTriggers.h | 2 +- src/cc/CCassets.h | 2 +- src/cc/CCassetsCore.cpp | 4 +- src/cc/CCassetstx.cpp | 2 +- src/cc/CCauction.h | 2 +- src/cc/CCchannels.h | 2 +- src/cc/CCcustom.cpp | 2 +- src/cc/CCdice.h | 2 +- src/cc/CCfaucet.h | 2 +- src/cc/CCfsm.h | 2 +- src/cc/CCinclude.h | 2 +- src/cc/CClotto.h | 2 +- src/cc/CCrewards.h | 2 +- src/cc/CCtx.cpp | 2 +- src/cc/CCutils.cpp | 2 +- src/cc/assets.cpp | 2 +- src/cc/auction.cpp | 2 +- src/cc/betprotocol.cpp | 2 +- src/cc/betprotocol.h | 2 +- src/cc/channels.cpp | 2 +- src/cc/crypto777/OS_portable.h | 2 +- src/cc/dapps/cJSON.c | 2 +- src/cc/dapps/oraclefeed.c | 2 +- src/cc/dapps/zmigrate.c | 2 +- src/cc/dice.cpp | 2 +- src/cc/disputepayout.cpp | 15 + src/cc/eval.cpp | 2 +- src/cc/eval.h | 2 +- src/cc/faucet.cpp | 2 +- src/cc/fsm.cpp | 2 +- src/cc/gateways.cpp | 2 +- src/cc/heir.cpp | 2 +- src/cc/import.cpp | 2 +- src/cc/importpayout.cpp | 15 + src/cc/includes/cJSON.h | 15 + src/cc/includes/curve25519.h | 2 +- src/cc/includes/libgfshare.h | 15 + src/cc/lotto.cpp | 2 +- src/cc/oracles.cpp | 2 +- src/cc/payments.cpp | 2 +- src/cc/pegs.cpp | 2 +- src/cc/prices.cpp | 2 +- src/cc/rewards.cpp | 2 +- src/cc/triggers.cpp | 2 +- src/cc/utils.h | 2 +- src/chain.cpp | 15 + src/chain.h | 15 + src/chainparams.cpp | 15 + src/chainparams.h | 15 + src/chainparamsbase.cpp | 15 + src/chainparamsbase.h | 15 + src/chainparamsseeds.h | 15 + src/checkpoints.cpp | 15 + src/checkpoints.h | 15 + src/checkqueue.h | 15 + src/clientversion.cpp | 15 + src/clientversion.h | 15 + src/coincontrol.h | 15 + src/coins.cpp | 15 + src/coins.h | 15 + src/compat.h | 15 + src/compressor.cpp | 15 + src/compressor.h | 15 + src/consensus/consensus.h | 15 + src/consensus/params.h | 15 + src/consensus/upgrades.cpp | 15 + src/consensus/upgrades.h | 15 + src/consensus/validation.h | 15 + src/core_io.h | 15 + src/core_read.cpp | 15 + src/core_write.cpp | 15 + src/crosschain.cpp | 15 + src/crosschain.h | 15 + .../include/cryptoconditions.h | 15 + src/cryptoconditions/src/anon.c | 2 +- src/cryptoconditions/src/cryptoconditions.c | 2 +- src/cryptoconditions/src/ed25519.c | 2 +- src/cryptoconditions/src/eval.c | 2 +- src/cryptoconditions/src/include/cJSON.c | 15 + src/cryptoconditions/src/include/cJSON.h | 15 + src/cryptoconditions/src/include/libbase58.h | 15 + src/cryptoconditions/src/internal.h | 2 +- src/cryptoconditions/src/json_rpc.c | 2 +- src/cryptoconditions/src/prefix.c | 2 +- src/cryptoconditions/src/preimage.c | 2 +- src/cryptoconditions/src/secp256k1.c | 15 + src/cryptoconditions/src/threshold.c | 2 +- src/cryptoconditions/src/utils.c | 2 +- src/deprecation.cpp | 15 + src/deprecation.h | 15 + src/hash.cpp | 15 + src/hash.h | 15 + src/httprpc.cpp | 15 + src/httprpc.h | 15 + src/importcoin.cpp | 15 + src/importcoin.h | 15 + src/init.cpp | 15 + src/init.h | 15 + src/key.cpp | 15 + src/key.h | 15 + src/keystore.cpp | 15 + src/keystore.h | 15 + src/komodo-tx.cpp | 15 + src/komodo.h | 2 +- src/komodo_bitcoind.h | 2 +- src/komodo_cJSON.c | 2 +- src/komodo_cJSON.h | 15 + src/komodo_ccdata.h | 2 +- src/komodo_curve25519.h | 2 +- src/komodo_defs.h | 15 + src/komodo_events.h | 2 +- src/komodo_gateway.h | 2 +- src/komodo_globals.h | 2 +- src/komodo_interest.h | 2 +- src/komodo_jumblr.h | 2 +- src/komodo_kv.h | 2 +- src/komodo_notary.h | 2 +- src/komodo_pax.h | 2 +- src/komodo_port.c | 21 +- src/komodo_structs.h | 2 +- src/komodo_utils.h | 2 +- src/main.cpp | 15 + src/main.h | 15 + src/memusage.h | 15 + src/merkleblock.cpp | 15 + src/merkleblock.h | 15 + src/metrics.cpp | 15 + src/metrics.h | 15 + src/miner.cpp | 15 + src/miner.h | 15 + src/mini-gmp.c | 15 + src/mini-gmp.h | 15 + src/mruset.h | 15 + src/net.cpp | 15 + src/net.h | 15 + src/netbase.cpp | 15 + src/netbase.h | 15 + src/noui.cpp | 15 + src/noui.h | 15 + src/policy/fees.cpp | 15 + src/policy/fees.h | 16 + src/pow.cpp | 15 + src/pow.h | 15 + src/primitives/block.cpp | 15 + src/primitives/block.h | 15 + src/primitives/nonce.cpp | 15 + src/primitives/nonce.h | 15 + src/primitives/transaction.cpp | 15 + src/primitives/transaction.h | 15 + src/protocol.cpp | 15 + src/protocol.h | 15 + src/pubkey.cpp | 15 + src/pubkey.h | 15 + src/random.cpp | 15 + src/random.h | 15 + src/rest.cpp | 15 + src/reverselock.h | 15 + src/rpc/blockchain.cpp | 15 + src/rpc/client.cpp | 15 + src/rpc/client.h | 15 + src/rpc/crosschain.cpp | 17 +- src/rpc/mining.cpp | 15 + src/rpc/misc.cpp | 15 + src/rpc/net.cpp | 15 + src/rpc/protocol.cpp | 15 + src/rpc/protocol.h | 15 + src/rpc/rawtransaction.cpp | 15 + src/rpc/register.h | 15 + src/rpc/server.cpp | 15 + src/rpc/server.h | 15 + src/scheduler.cpp | 15 + src/scheduler.h | 15 + src/script/cc.cpp | 15 + src/script/cc.h | 15 + src/script/interpreter.cpp | 15 + src/script/interpreter.h | 15 + src/script/script.cpp | 15 + src/script/script.h | 15 + src/script/script_error.cpp | 15 + src/script/script_error.h | 15 + src/script/script_ext.cpp | 15 + src/script/script_ext.h | 15 + src/script/serverchecker.cpp | 15 + src/script/serverchecker.h | 15 + src/script/sigcache.cpp | 15 + src/script/sigcache.h | 15 + src/script/sign.cpp | 15 + src/script/sign.h | 15 + src/script/standard.cpp | 15 + src/script/standard.h | 15 + src/script/zcashconsensus.cpp | 15 + src/script/zcashconsensus.h | 15 + src/sendalert.cpp | 15 + src/serialize.h | 15 + src/streams.h | 15 + src/sync.cpp | 15 + src/sync.h | 15 + src/timedata.cpp | 15 + src/txdb.cpp | 15 + src/txdb.h | 15 + src/txmempool.cpp | 15 + src/txmempool.h | 15 + src/uint256.cpp | 15 + src/uint256.h | 15 + src/util.cpp | 15 + src/version.h | 15 + .../asyncrpcoperation_mergetoaddress.cpp | 15 + src/wallet/asyncrpcoperation_mergetoaddress.h | 15 + src/wallet/asyncrpcoperation_sendmany.cpp | 15 + src/wallet/asyncrpcoperation_sendmany.h | 15 + .../asyncrpcoperation_shieldcoinbase.cpp | 15 + src/wallet/asyncrpcoperation_shieldcoinbase.h | 15 + src/wallet/crypter.cpp | 15 + src/wallet/crypter.h | 15 + src/wallet/db.cpp | 15 + src/wallet/db.h | 15 + src/wallet/rpcdisclosure.cpp | 15 + src/wallet/rpcdump.cpp | 15 + src/wallet/rpcwallet.cpp | 15 + src/wallet/rpcwallet.h | 15 + src/wallet/wallet.cpp | 15 + src/wallet/wallet.h | 15 + src/wallet/wallet_ismine.cpp | 15 + src/wallet/wallet_ismine.h | 15 + src/wallet/walletdb.cpp | 15 + src/wallet/walletdb.h | 15 + 255 files changed, 3132 insertions(+), 83 deletions(-) diff --git a/COPYING b/COPYING index 7c046110d..587a47035 100644 --- a/COPYING +++ b/COPYING @@ -1,7 +1,7 @@ Copyright (c) 2009-2017 The Bitcoin Core developers Copyright (c) 2009-2018 Bitcoin Developers Copyright (c) 2016-2017 The Zcash developers -Copyright (c) 2016-2018 The Komodo developers +Copyright (c) 2016-2019 The Komodo developers Copyright (c) 2018 The VerusCoin developers Permission is hereby granted, free of charge, to any person obtaining a copy @@ -38,3 +38,345 @@ Although almost all of the Zcash/Komodo/VerusCoin code is licensed under "permis licenses, users and distributors should note that when built using the default build options, Zcash depends on Oracle Berkeley DB 6.2.x, which is licensed under the GNU Affero General Public License. + +SuperNET COPYING terms: +GNU GENERAL PUBLIC LICENSE +Version 2, June 1991 + +Copyright (C) 1989, 1991 Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + +Preamble + +The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + +When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + +To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + +For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + +We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + +Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + +Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + +The precise terms and conditions for copying, distribution and +modification follow. + +GNU GENERAL PUBLIC LICENSE +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + +1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + +a) You must cause the modified files to carry prominent notices +stating that you changed the files and the date of any change. + +b) You must cause any work that you distribute or publish, that in +whole or in part contains or is derived from the Program or any +part thereof, to be licensed as a whole at no charge to all third +parties under the terms of this License. + +c) If the modified program normally reads commands interactively +when run, you must cause it, when started running for such +interactive use in the most ordinary way, to print or display an +announcement including an appropriate copyright notice and a +notice that there is no warranty (or else, saying that you provide +a warranty) and that users may redistribute the program under +these conditions, and telling the user how to view a copy of this +License. (Exception: if the Program itself is interactive but +does not normally print such an announcement, your work based on +the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + +3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + +a) Accompany it with the complete corresponding machine-readable +source code, which must be distributed under the terms of Sections +1 and 2 above on a medium customarily used for software interchange; or, + +b) Accompany it with a written offer, valid for at least three +years, to give any third party, for a charge no more than your +cost of physically performing source distribution, a complete +machine-readable copy of the corresponding source code, to be +distributed under the terms of Sections 1 and 2 above on a medium +customarily used for software interchange; or, + +c) Accompany it with the information you received as to the offer +to distribute corresponding source code. (This alternative is +allowed only for noncommercial distribution and only if you +received the program in object code or executable form with such +an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + +4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + +5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + +6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + +7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + +8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + +9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + +10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + +NO WARRANTY + +11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + +12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + +END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + +Copyright (C) + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + +Gnomovision version 69, Copyright (C) year name of author +Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. +This is free software, and you are welcome to redistribute it +under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + +Yoyodyne, Inc., hereby disclaims all copyright interest in the program +`Gnomovision' (which makes passes at compilers) written by James Hacker. + +, 1 April 1989 +Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. + diff --git a/src/addrman.cpp b/src/addrman.cpp index c4a2e6e80..1c8bf4b7c 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "addrman.h" #include "hash.h" diff --git a/src/addrman.h b/src/addrman.h index 5c77a4fdb..0390b4e9b 100644 --- a/src/addrman.h +++ b/src/addrman.h @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_ADDRMAN_H #define BITCOIN_ADDRMAN_H diff --git a/src/alert.cpp b/src/alert.cpp index ea9cbad21..4d832da7c 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "alert.h" #include "clientversion.h" diff --git a/src/alert.h b/src/alert.h index 4e3b88775..16204c9c5 100644 --- a/src/alert.h +++ b/src/alert.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_ALERT_H #define BITCOIN_ALERT_H diff --git a/src/alertkeys.h b/src/alertkeys.h index 32d26638e..106576add 100644 --- a/src/alertkeys.h +++ b/src/alertkeys.h @@ -1,3 +1,18 @@ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_ALERTKEYS_H #define BITCOIN_ALERTKEYS_H diff --git a/src/amount.cpp b/src/amount.cpp index 4e32ff45b..3feb37ccc 100644 --- a/src/amount.cpp +++ b/src/amount.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "amount.h" #include "tinyformat.h" diff --git a/src/amount.h b/src/amount.h index 7423fdaa1..be1c39a6e 100644 --- a/src/amount.h +++ b/src/amount.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_AMOUNT_H #define BITCOIN_AMOUNT_H diff --git a/src/arith_uint256.cpp b/src/arith_uint256.cpp index c9074fe91..e9c0dd056 100644 --- a/src/arith_uint256.cpp +++ b/src/arith_uint256.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "arith_uint256.h" #include "uint256.h" diff --git a/src/arith_uint256.h b/src/arith_uint256.h index 103c78bb8..b51f82f14 100644 --- a/src/arith_uint256.h +++ b/src/arith_uint256.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_ARITH_UINT256_H #define BITCOIN_ARITH_UINT256_H diff --git a/src/asyncrpcoperation.cpp b/src/asyncrpcoperation.cpp index ff5c4cb9f..75c8da9e6 100644 --- a/src/asyncrpcoperation.cpp +++ b/src/asyncrpcoperation.cpp @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "asyncrpcoperation.h" #include diff --git a/src/asyncrpcoperation.h b/src/asyncrpcoperation.h index 2b821e256..3fe966977 100644 --- a/src/asyncrpcoperation.h +++ b/src/asyncrpcoperation.h @@ -2,6 +2,20 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ #ifndef ASYNCRPCOPERATION_H #define ASYNCRPCOPERATION_H diff --git a/src/asyncrpcqueue.cpp b/src/asyncrpcqueue.cpp index afe6d4bef..5bcb20f8d 100644 --- a/src/asyncrpcqueue.cpp +++ b/src/asyncrpcqueue.cpp @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "asyncrpcqueue.h" static std::atomic workerCounter(0); diff --git a/src/asyncrpcqueue.h b/src/asyncrpcqueue.h index 1a099a263..0d228564f 100644 --- a/src/asyncrpcqueue.h +++ b/src/asyncrpcqueue.h @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef ASYNCRPCQUEUE_H #define ASYNCRPCQUEUE_H diff --git a/src/base58.cpp b/src/base58.cpp index 12978fa1c..9d10b7e6a 100644 --- a/src/base58.cpp +++ b/src/base58.cpp @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "base58.h" #include diff --git a/src/base58.h b/src/base58.h index 66cb7e7a0..4decb4922 100644 --- a/src/base58.h +++ b/src/base58.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + /** * Why base-58 instead of standard base-64 encoding? * - Don't want 0OIl characters that look the same in some fonts and diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 64830d463..544972586 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "chainparamsbase.h" #include "clientversion.h" #include "rpc/client.h" diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 34e1b5d91..86d3165cf 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "clientversion.h" #include "rpc/server.h" #include "init.h" diff --git a/src/bloom.cpp b/src/bloom.cpp index de8720659..d7a7742fe 100644 --- a/src/bloom.cpp +++ b/src/bloom.cpp @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "bloom.h" #include "primitives/transaction.h" diff --git a/src/bloom.h b/src/bloom.h index df5c30b1e..e4677d6d0 100644 --- a/src/bloom.h +++ b/src/bloom.h @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_BLOOM_H #define BITCOIN_BLOOM_H diff --git a/src/cJSON.c b/src/cJSON.c index b67ca698d..09da06889 100644 --- a/src/cJSON.c +++ b/src/cJSON.c @@ -20,6 +20,21 @@ THE SOFTWARE. */ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + /* cJSON */ /* JSON parser in C. */ diff --git a/src/cJSON.h b/src/cJSON.h index 1e388137e..2a6139680 100644 --- a/src/cJSON.h +++ b/src/cJSON.h @@ -20,6 +20,21 @@ THE SOFTWARE. */ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef cJSON__h #define cJSON__h diff --git a/src/cc/CC made easy.md b/src/cc/CC made easy.md index 3f15a6b6b..453aa5467 100644 --- a/src/cc/CC made easy.md +++ b/src/cc/CC made easy.md @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/CCGateways.h b/src/cc/CCGateways.h index 2470665d4..b629ade1f 100644 --- a/src/cc/CCGateways.h +++ b/src/cc/CCGateways.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/CCHeir.h b/src/cc/CCHeir.h index 9a8193428..214b566c7 100644 --- a/src/cc/CCHeir.h +++ b/src/cc/CCHeir.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/CCOracles.h b/src/cc/CCOracles.h index 5e2fcc8b9..7f952e5f5 100644 --- a/src/cc/CCOracles.h +++ b/src/cc/CCOracles.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/CCPayments.h b/src/cc/CCPayments.h index 18f6cb7ef..187d9c9ad 100644 --- a/src/cc/CCPayments.h +++ b/src/cc/CCPayments.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/CCPegs.h b/src/cc/CCPegs.h index 0e20d278f..8d2a268f1 100644 --- a/src/cc/CCPegs.h +++ b/src/cc/CCPegs.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index 55877cce0..1a68be7dd 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/CCTriggers.h b/src/cc/CCTriggers.h index bd243842f..a75806dce 100644 --- a/src/cc/CCTriggers.h +++ b/src/cc/CCTriggers.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/CCassets.h b/src/cc/CCassets.h index 67bed7941..5e4441646 100644 --- a/src/cc/CCassets.h +++ b/src/cc/CCassets.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index 3fce95f0c..52f1ed28c 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * @@ -553,4 +553,4 @@ bool AssetExactAmounts(int maxDepth, struct CCcontract_info *cp, int64_t &inputs std::vector ccVinsTxs; return AssetExactAmounts(true, cp, inputs, starti, outputs, eval, tx, assetid); -}*/ \ No newline at end of file +}*/ diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index f96170267..fbc53406b 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/CCauction.h b/src/cc/CCauction.h index be636e76b..cfcd615cc 100644 --- a/src/cc/CCauction.h +++ b/src/cc/CCauction.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/CCchannels.h b/src/cc/CCchannels.h index 34c1edd7d..49b4a7adf 100644 --- a/src/cc/CCchannels.h +++ b/src/cc/CCchannels.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/CCcustom.cpp b/src/cc/CCcustom.cpp index b17a7cd89..3e42109fc 100644 --- a/src/cc/CCcustom.cpp +++ b/src/cc/CCcustom.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/CCdice.h b/src/cc/CCdice.h index cb0398129..363aad735 100644 --- a/src/cc/CCdice.h +++ b/src/cc/CCdice.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/CCfaucet.h b/src/cc/CCfaucet.h index 895327d09..3cb6c66e5 100644 --- a/src/cc/CCfaucet.h +++ b/src/cc/CCfaucet.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/CCfsm.h b/src/cc/CCfsm.h index 0aafdb6b9..2bce35597 100644 --- a/src/cc/CCfsm.h +++ b/src/cc/CCfsm.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 28091b957..0906a57c6 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/CClotto.h b/src/cc/CClotto.h index 838aac338..2f0595371 100644 --- a/src/cc/CClotto.h +++ b/src/cc/CClotto.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/CCrewards.h b/src/cc/CCrewards.h index ac90423b2..4d6cc80f9 100644 --- a/src/cc/CCrewards.h +++ b/src/cc/CCrewards.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 27d796ba0..32d525517 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index e10d97224..ed16805d7 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index 378c427a9..a1fa39192 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/auction.cpp b/src/cc/auction.cpp index 1bc8533ec..70bc64379 100644 --- a/src/cc/auction.cpp +++ b/src/cc/auction.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/betprotocol.cpp b/src/cc/betprotocol.cpp index 3efa4ae37..0724f2fea 100644 --- a/src/cc/betprotocol.cpp +++ b/src/cc/betprotocol.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/betprotocol.h b/src/cc/betprotocol.h index ac76f87b1..688db370f 100644 --- a/src/cc/betprotocol.h +++ b/src/cc/betprotocol.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 4ee2d73e1..d516d0144 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/crypto777/OS_portable.h b/src/cc/crypto777/OS_portable.h index 9da753811..d6abc98c5 100755 --- a/src/cc/crypto777/OS_portable.h +++ b/src/cc/crypto777/OS_portable.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/dapps/cJSON.c b/src/cc/dapps/cJSON.c index e0665e378..62f46444c 100755 --- a/src/cc/dapps/cJSON.c +++ b/src/cc/dapps/cJSON.c @@ -669,7 +669,7 @@ void cJSON_Minify(char *json) // the following written by jl777 /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 68c02310b..33e6908fb 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/dapps/zmigrate.c b/src/cc/dapps/zmigrate.c index d9ec6ec19..cfbd29d70 100644 --- a/src/cc/dapps/zmigrate.c +++ b/src/cc/dapps/zmigrate.c @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 45e101e9c..05dad9bf6 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/disputepayout.cpp b/src/cc/disputepayout.cpp index 1271b0da5..60924b00b 100644 --- a/src/cc/disputepayout.cpp +++ b/src/cc/disputepayout.cpp @@ -1,3 +1,18 @@ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include #include "hash.h" diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index 35644a82a..d50bc8a0d 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/eval.h b/src/cc/eval.h index 006fca950..9c6a050b7 100644 --- a/src/cc/eval.h +++ b/src/cc/eval.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index afd97c1aa..6e59b6c1a 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/fsm.cpp b/src/cc/fsm.cpp index e75c53bcc..04ca1d5a0 100644 --- a/src/cc/fsm.cpp +++ b/src/cc/fsm.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 94d662193..2768e9fbd 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 24aa35f59..5caa6594a 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/import.cpp b/src/cc/import.cpp index a6af41024..7902a74b3 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/importpayout.cpp b/src/cc/importpayout.cpp index 1363eb924..be31a8414 100644 --- a/src/cc/importpayout.cpp +++ b/src/cc/importpayout.cpp @@ -1,3 +1,18 @@ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include #include "main.h" diff --git a/src/cc/includes/cJSON.h b/src/cc/includes/cJSON.h index 3ecdadc69..ed8c26b7f 100755 --- a/src/cc/includes/cJSON.h +++ b/src/cc/includes/cJSON.h @@ -20,6 +20,21 @@ THE SOFTWARE. */ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef cJSON__h #define cJSON__h diff --git a/src/cc/includes/curve25519.h b/src/cc/includes/curve25519.h index 9f8c9ba16..19abe8d10 100755 --- a/src/cc/includes/curve25519.h +++ b/src/cc/includes/curve25519.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2015 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/includes/libgfshare.h b/src/cc/includes/libgfshare.h index a4d494aff..dc8747fe9 100755 --- a/src/cc/includes/libgfshare.h +++ b/src/cc/includes/libgfshare.h @@ -23,6 +23,21 @@ * */ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef LIBGFSHARE_H #define LIBGFSHARE_H #include diff --git a/src/cc/lotto.cpp b/src/cc/lotto.cpp index e89f2692a..7b44a99b7 100644 --- a/src/cc/lotto.cpp +++ b/src/cc/lotto.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 135f822dc..f09dd0957 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 70f1ab914..1b6d88214 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/pegs.cpp b/src/cc/pegs.cpp index 403dfb87a..4e414d695 100644 --- a/src/cc/pegs.cpp +++ b/src/cc/pegs.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 50787fd34..8c2ecc021 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 7e4626b19..bd5a6d919 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/triggers.cpp b/src/cc/triggers.cpp index ce6f10f58..a98e4da02 100644 --- a/src/cc/triggers.cpp +++ b/src/cc/triggers.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cc/utils.h b/src/cc/utils.h index f0b91962d..39bce0e95 100644 --- a/src/cc/utils.h +++ b/src/cc/utils.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/chain.cpp b/src/chain.cpp index 0d4ac7f2a..43d893620 100644 --- a/src/chain.cpp +++ b/src/chain.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "chain.h" using namespace std; diff --git a/src/chain.h b/src/chain.h index 0b6e2b046..49b206480 100644 --- a/src/chain.h +++ b/src/chain.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_CHAIN_H #define BITCOIN_CHAIN_H diff --git a/src/chainparams.cpp b/src/chainparams.cpp index a04e4131a..49f08e98e 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "key_io.h" #include "main.h" #include "crypto/equihash.h" diff --git a/src/chainparams.h b/src/chainparams.h index 566f07f36..ea700c6ca 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_CHAINPARAMS_H #define BITCOIN_CHAINPARAMS_H diff --git a/src/chainparamsbase.cpp b/src/chainparamsbase.cpp index 475f200e6..4ec957ba1 100644 --- a/src/chainparamsbase.cpp +++ b/src/chainparamsbase.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "chainparamsbase.h" #include "util.h" diff --git a/src/chainparamsbase.h b/src/chainparamsbase.h index 33765f0fc..94e3a4238 100644 --- a/src/chainparamsbase.h +++ b/src/chainparamsbase.h @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_CHAINPARAMSBASE_H #define BITCOIN_CHAINPARAMSBASE_H diff --git a/src/chainparamsseeds.h b/src/chainparamsseeds.h index 4b091457b..e3dac3ca6 100644 --- a/src/chainparamsseeds.h +++ b/src/chainparamsseeds.h @@ -1,3 +1,18 @@ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_CHAINPARAMSSEEDS_H #define BITCOIN_CHAINPARAMSSEEDS_H /** diff --git a/src/checkpoints.cpp b/src/checkpoints.cpp index 70fd1e8f2..7fd94e4e7 100644 --- a/src/checkpoints.cpp +++ b/src/checkpoints.cpp @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "checkpoints.h" #include "chainparams.h" diff --git a/src/checkpoints.h b/src/checkpoints.h index b75da9ef2..1b21755f0 100644 --- a/src/checkpoints.h +++ b/src/checkpoints.h @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_CHECKPOINTS_H #define BITCOIN_CHECKPOINTS_H diff --git a/src/checkqueue.h b/src/checkqueue.h index 20ba25bb4..fc3cdb610 100644 --- a/src/checkqueue.h +++ b/src/checkqueue.h @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_CHECKQUEUE_H #define BITCOIN_CHECKQUEUE_H diff --git a/src/clientversion.cpp b/src/clientversion.cpp index 9b523e582..4f004aac2 100644 --- a/src/clientversion.cpp +++ b/src/clientversion.cpp @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "clientversion.h" #include "tinyformat.h" diff --git a/src/clientversion.h b/src/clientversion.h index d8117a6ba..36f37f2e2 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_CLIENTVERSION_H #define BITCOIN_CLIENTVERSION_H diff --git a/src/coincontrol.h b/src/coincontrol.h index 3e8de83c3..02d487a4c 100644 --- a/src/coincontrol.h +++ b/src/coincontrol.h @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_COINCONTROL_H #define BITCOIN_COINCONTROL_H diff --git a/src/coins.cpp b/src/coins.cpp index 656f2c92e..f97ba5eee 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "coins.h" #include "memusage.h" diff --git a/src/coins.h b/src/coins.h index 39d1e22fc..f83fda7d2 100644 --- a/src/coins.h +++ b/src/coins.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_COINS_H #define BITCOIN_COINS_H diff --git a/src/compat.h b/src/compat.h index 27afc8b2a..44b7dcee2 100644 --- a/src/compat.h +++ b/src/compat.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_COMPAT_H #define BITCOIN_COMPAT_H diff --git a/src/compressor.cpp b/src/compressor.cpp index 20c154fc1..e3479474d 100644 --- a/src/compressor.cpp +++ b/src/compressor.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "compressor.h" #include "hash.h" diff --git a/src/compressor.h b/src/compressor.h index 961365d26..f4e4a256d 100644 --- a/src/compressor.h +++ b/src/compressor.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_COMPRESSOR_H #define BITCOIN_COMPRESSOR_H diff --git a/src/consensus/consensus.h b/src/consensus/consensus.h index 3f44bcafd..eba39b644 100644 --- a/src/consensus/consensus.h +++ b/src/consensus/consensus.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_CONSENSUS_CONSENSUS_H #define BITCOIN_CONSENSUS_CONSENSUS_H diff --git a/src/consensus/params.h b/src/consensus/params.h index b7dc8b475..946b11c8d 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_CONSENSUS_PARAMS_H #define BITCOIN_CONSENSUS_PARAMS_H diff --git a/src/consensus/upgrades.cpp b/src/consensus/upgrades.cpp index 5f484e949..3cd30399f 100644 --- a/src/consensus/upgrades.cpp +++ b/src/consensus/upgrades.cpp @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "consensus/upgrades.h" /** diff --git a/src/consensus/upgrades.h b/src/consensus/upgrades.h index 920ec1ea8..38eadc9ef 100644 --- a/src/consensus/upgrades.h +++ b/src/consensus/upgrades.h @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef ZCASH_CONSENSUS_UPGRADES_H #define ZCASH_CONSENSUS_UPGRADES_H diff --git a/src/consensus/validation.h b/src/consensus/validation.h index 6c4db4c59..a3d718c05 100644 --- a/src/consensus/validation.h +++ b/src/consensus/validation.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_CONSENSUS_VALIDATION_H #define BITCOIN_CONSENSUS_VALIDATION_H diff --git a/src/core_io.h b/src/core_io.h index ba5b4e648..dbf30b9e9 100644 --- a/src/core_io.h +++ b/src/core_io.h @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_CORE_IO_H #define BITCOIN_CORE_IO_H diff --git a/src/core_read.cpp b/src/core_read.cpp index 4be24f8e0..9817a2165 100644 --- a/src/core_read.cpp +++ b/src/core_read.cpp @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "core_io.h" #include "primitives/block.h" diff --git a/src/core_write.cpp b/src/core_write.cpp index 43344656b..780540027 100644 --- a/src/core_write.cpp +++ b/src/core_write.cpp @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "core_io.h" #include "key_io.h" diff --git a/src/crosschain.cpp b/src/crosschain.cpp index 8dc5657b8..447f907cc 100644 --- a/src/crosschain.cpp +++ b/src/crosschain.cpp @@ -1,3 +1,18 @@ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "cc/eval.h" #include "crosschain.h" #include "importcoin.h" diff --git a/src/crosschain.h b/src/crosschain.h index 57e4a79d0..b97afde98 100644 --- a/src/crosschain.h +++ b/src/crosschain.h @@ -1,3 +1,18 @@ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef CROSSCHAIN_H #define CROSSCHAIN_H diff --git a/src/cryptoconditions/include/cryptoconditions.h b/src/cryptoconditions/include/cryptoconditions.h index 71f9cb460..68fedb946 100644 --- a/src/cryptoconditions/include/cryptoconditions.h +++ b/src/cryptoconditions/include/cryptoconditions.h @@ -1,3 +1,18 @@ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include #include diff --git a/src/cryptoconditions/src/anon.c b/src/cryptoconditions/src/anon.c index f3214995b..55d7a3b7f 100644 --- a/src/cryptoconditions/src/anon.c +++ b/src/cryptoconditions/src/anon.c @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cryptoconditions/src/cryptoconditions.c b/src/cryptoconditions/src/cryptoconditions.c index 11410a3ec..9bbdfbd95 100644 --- a/src/cryptoconditions/src/cryptoconditions.c +++ b/src/cryptoconditions/src/cryptoconditions.c @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cryptoconditions/src/ed25519.c b/src/cryptoconditions/src/ed25519.c index 4fb3bbb8d..8d73d3cf1 100644 --- a/src/cryptoconditions/src/ed25519.c +++ b/src/cryptoconditions/src/ed25519.c @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cryptoconditions/src/eval.c b/src/cryptoconditions/src/eval.c index 544f6dd54..99ff1ebf5 100644 --- a/src/cryptoconditions/src/eval.c +++ b/src/cryptoconditions/src/eval.c @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cryptoconditions/src/include/cJSON.c b/src/cryptoconditions/src/include/cJSON.c index 306bb5b0d..5c99b8cb2 100644 --- a/src/cryptoconditions/src/include/cJSON.c +++ b/src/cryptoconditions/src/include/cJSON.c @@ -20,6 +20,21 @@ THE SOFTWARE. */ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + /* cJSON */ /* JSON parser in C. */ diff --git a/src/cryptoconditions/src/include/cJSON.h b/src/cryptoconditions/src/include/cJSON.h index 1e388137e..2a6139680 100644 --- a/src/cryptoconditions/src/include/cJSON.h +++ b/src/cryptoconditions/src/include/cJSON.h @@ -20,6 +20,21 @@ THE SOFTWARE. */ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef cJSON__h #define cJSON__h diff --git a/src/cryptoconditions/src/include/libbase58.h b/src/cryptoconditions/src/include/libbase58.h index fafe6539f..78f1b4591 100644 --- a/src/cryptoconditions/src/include/libbase58.h +++ b/src/cryptoconditions/src/include/libbase58.h @@ -1,3 +1,18 @@ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef LIBBASE58_H #define LIBBASE58_H diff --git a/src/cryptoconditions/src/internal.h b/src/cryptoconditions/src/internal.h index 41080186e..790e28962 100644 --- a/src/cryptoconditions/src/internal.h +++ b/src/cryptoconditions/src/internal.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cryptoconditions/src/json_rpc.c b/src/cryptoconditions/src/json_rpc.c index 73377af50..150bcb12b 100644 --- a/src/cryptoconditions/src/json_rpc.c +++ b/src/cryptoconditions/src/json_rpc.c @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cryptoconditions/src/prefix.c b/src/cryptoconditions/src/prefix.c index 626fc5992..45c6d8033 100644 --- a/src/cryptoconditions/src/prefix.c +++ b/src/cryptoconditions/src/prefix.c @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cryptoconditions/src/preimage.c b/src/cryptoconditions/src/preimage.c index 7c8e56996..9e7fe12f4 100644 --- a/src/cryptoconditions/src/preimage.c +++ b/src/cryptoconditions/src/preimage.c @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cryptoconditions/src/secp256k1.c b/src/cryptoconditions/src/secp256k1.c index a95895fa4..31bab06e5 100644 --- a/src/cryptoconditions/src/secp256k1.c +++ b/src/cryptoconditions/src/secp256k1.c @@ -1,3 +1,18 @@ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #define _GNU_SOURCE 1 #if __linux diff --git a/src/cryptoconditions/src/threshold.c b/src/cryptoconditions/src/threshold.c index 13c3fdab3..82f0e1b0a 100644 --- a/src/cryptoconditions/src/threshold.c +++ b/src/cryptoconditions/src/threshold.c @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/cryptoconditions/src/utils.c b/src/cryptoconditions/src/utils.c index 25783ddfc..6a2167119 100644 --- a/src/cryptoconditions/src/utils.c +++ b/src/cryptoconditions/src/utils.c @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/deprecation.cpp b/src/deprecation.cpp index 9b34b1d0f..6005918ec 100644 --- a/src/deprecation.cpp +++ b/src/deprecation.cpp @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "deprecation.h" #include "alert.h" diff --git a/src/deprecation.h b/src/deprecation.h index 16484ed5a..427234b4a 100644 --- a/src/deprecation.h +++ b/src/deprecation.h @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef ZCASH_DEPRECATION_H #define ZCASH_DEPRECATION_H diff --git a/src/hash.cpp b/src/hash.cpp index 9711293e3..7471da8fb 100644 --- a/src/hash.cpp +++ b/src/hash.cpp @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "hash.h" #include "crypto/common.h" #include "crypto/hmac_sha512.h" diff --git a/src/hash.h b/src/hash.h index 09f71b432..9a8edc72c 100644 --- a/src/hash.h +++ b/src/hash.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_HASH_H #define BITCOIN_HASH_H diff --git a/src/httprpc.cpp b/src/httprpc.cpp index d60770aba..799d2fbe6 100644 --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -1,3 +1,18 @@ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "httprpc.h" #include "chainparams.h" diff --git a/src/httprpc.h b/src/httprpc.h index d35445718..6827a7063 100644 --- a/src/httprpc.h +++ b/src/httprpc.h @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_HTTPRPC_H #define BITCOIN_HTTPRPC_H diff --git a/src/importcoin.cpp b/src/importcoin.cpp index b2d48b848..c72aea210 100644 --- a/src/importcoin.cpp +++ b/src/importcoin.cpp @@ -1,3 +1,18 @@ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "crosschain.h" #include "importcoin.h" #include "cc/utils.h" diff --git a/src/importcoin.h b/src/importcoin.h index f62bb45a1..53611cac9 100644 --- a/src/importcoin.h +++ b/src/importcoin.h @@ -1,3 +1,18 @@ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef IMPORTCOIN_H #define IMPORTCOIN_H diff --git a/src/init.cpp b/src/init.cpp index be98f8fb0..3dd09ac50 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #if defined(HAVE_CONFIG_H) #include "config/bitcoin-config.h" #endif diff --git a/src/init.h b/src/init.h index 710e43c69..108339865 100644 --- a/src/init.h +++ b/src/init.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_INIT_H #define BITCOIN_INIT_H diff --git a/src/key.cpp b/src/key.cpp index 5688b1302..3b6fed81b 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "key.h" #include "arith_uint256.h" diff --git a/src/key.h b/src/key.h index 8d64151e3..c41208003 100644 --- a/src/key.h +++ b/src/key.h @@ -4,6 +4,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_KEY_H #define BITCOIN_KEY_H diff --git a/src/keystore.cpp b/src/keystore.cpp index e1e3ae89b..34bab456c 100644 --- a/src/keystore.cpp +++ b/src/keystore.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "keystore.h" #include "key.h" diff --git a/src/keystore.h b/src/keystore.h index bf2c9b246..bab236e24 100644 --- a/src/keystore.h +++ b/src/keystore.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_KEYSTORE_H #define BITCOIN_KEYSTORE_H diff --git a/src/komodo-tx.cpp b/src/komodo-tx.cpp index b1b478972..67ac68cd4 100644 --- a/src/komodo-tx.cpp +++ b/src/komodo-tx.cpp @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "clientversion.h" #include "coins.h" #include "consensus/consensus.h" diff --git a/src/komodo.h b/src/komodo.h index 4c9edee89..4c97a8171 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 816cab09d..c6eb05324 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/komodo_cJSON.c b/src/komodo_cJSON.c index 8569b7802..10140ad02 100755 --- a/src/komodo_cJSON.c +++ b/src/komodo_cJSON.c @@ -56,7 +56,7 @@ static int32_t cJSON_strcasecmp(const char *s1,const char *s2) // the following written by jl777 /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/komodo_cJSON.h b/src/komodo_cJSON.h index 2639d3c52..c104a4f79 100755 --- a/src/komodo_cJSON.h +++ b/src/komodo_cJSON.h @@ -20,6 +20,21 @@ THE SOFTWARE. */ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef komodo_cJSON__h #define komodo_cJSON__h diff --git a/src/komodo_ccdata.h b/src/komodo_ccdata.h index 012183fc7..3969532fd 100644 --- a/src/komodo_ccdata.h +++ b/src/komodo_ccdata.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/komodo_curve25519.h b/src/komodo_curve25519.h index 90d9a7e00..cba40561b 100644 --- a/src/komodo_curve25519.h +++ b/src/komodo_curve25519.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/komodo_defs.h b/src/komodo_defs.h index e604e1779..c0a3caffd 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -1,3 +1,18 @@ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef KOMODO_DEFS_H #define KOMODO_DEFS_H diff --git a/src/komodo_events.h b/src/komodo_events.h index d4ea17ce5..5500a341e 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 5572364da..982f16b0b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/komodo_globals.h b/src/komodo_globals.h index bd28d39f3..a14cea753 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/komodo_interest.h b/src/komodo_interest.h index b76fbbdc9..b9549d860 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/komodo_jumblr.h b/src/komodo_jumblr.h index 79bd049f4..5a5ad0885 100755 --- a/src/komodo_jumblr.h +++ b/src/komodo_jumblr.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 834584e44..a879340ff 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 8c51c7924..fca7fd223 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 6f408042e..9935f3463 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/komodo_port.c b/src/komodo_port.c index 14a97e159..fd68db881 100644 --- a/src/komodo_port.c +++ b/src/komodo_port.c @@ -1,10 +1,17 @@ -// -// main.c -// spawn -// -// Created by Mac on 4/7/18. -// Copyright © 2018 SuperNET. All rights reserved. -// +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ #include #include diff --git a/src/komodo_structs.h b/src/komodo_structs.h index 8595adc76..6b7c316b6 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 5e25898b5..f5d394c7e 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * + * Copyright © 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/main.cpp b/src/main.cpp index 0e4fc24e5..22368a7eb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "main.h" #include "sodium.h" diff --git a/src/main.h b/src/main.h index fdd9fcae8..f318a8c13 100644 --- a/src/main.h +++ b/src/main.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_MAIN_H #define BITCOIN_MAIN_H diff --git a/src/memusage.h b/src/memusage.h index 0b232d88b..a3fd11b5f 100644 --- a/src/memusage.h +++ b/src/memusage.h @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_MEMUSAGE_H #define BITCOIN_MEMUSAGE_H diff --git a/src/merkleblock.cpp b/src/merkleblock.cpp index 0e6215db5..db4ccfc96 100644 --- a/src/merkleblock.cpp +++ b/src/merkleblock.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "merkleblock.h" #include "hash.h" diff --git a/src/merkleblock.h b/src/merkleblock.h index 97223ed92..f970ee91d 100644 --- a/src/merkleblock.h +++ b/src/merkleblock.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_MERKLEBLOCK_H #define BITCOIN_MERKLEBLOCK_H diff --git a/src/metrics.cpp b/src/metrics.cpp index aafb114f2..a01d381a1 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "metrics.h" #include "chainparams.h" diff --git a/src/metrics.h b/src/metrics.h index 0fc03bf8a..84ea9ed51 100644 --- a/src/metrics.h +++ b/src/metrics.h @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "uint256.h" #include diff --git a/src/miner.cpp b/src/miner.cpp index e54cbbed9..b0f801b01 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "miner.h" #ifdef ENABLE_MINING #include "pow/tromp/equi_miner.h" diff --git a/src/miner.h b/src/miner.h index 71b89f320..5494022bd 100644 --- a/src/miner.h +++ b/src/miner.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_MINER_H #define BITCOIN_MINER_H diff --git a/src/mini-gmp.c b/src/mini-gmp.c index 4cc08c27c..f9ee23f15 100644 --- a/src/mini-gmp.c +++ b/src/mini-gmp.c @@ -41,6 +41,21 @@ see https://www.gnu.org/licenses/. */ mpn/generic/sbpi1_div_qr.c, mpn/generic/sub_n.c, mpn/generic/submul_1.c. */ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include #include #include diff --git a/src/mini-gmp.h b/src/mini-gmp.h index 75f5a3aac..56647ee77 100644 --- a/src/mini-gmp.h +++ b/src/mini-gmp.h @@ -35,6 +35,21 @@ see https://www.gnu.org/licenses/. */ This file defines the public interface. */ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef __MINI_GMP_H__ #define __MINI_GMP_H__ diff --git a/src/mruset.h b/src/mruset.h index 398aa173b..cd3af8664 100644 --- a/src/mruset.h +++ b/src/mruset.h @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_MRUSET_H #define BITCOIN_MRUSET_H diff --git a/src/net.cpp b/src/net.cpp index 85bb8a13e..d403660b6 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #if defined(HAVE_CONFIG_H) #include "config/bitcoin-config.h" #endif diff --git a/src/net.h b/src/net.h index e2fbdb0bd..7d3047d80 100644 --- a/src/net.h +++ b/src/net.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_NET_H #define BITCOIN_NET_H diff --git a/src/netbase.cpp b/src/netbase.cpp index 7369b0167..88439f446 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifdef HAVE_CONFIG_H #include "config/bitcoin-config.h" #endif diff --git a/src/netbase.h b/src/netbase.h index d0262eaeb..8eb40b6b7 100644 --- a/src/netbase.h +++ b/src/netbase.h @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_NETBASE_H #define BITCOIN_NETBASE_H diff --git a/src/noui.cpp b/src/noui.cpp index 0d9207c11..5e2b28318 100644 --- a/src/noui.cpp +++ b/src/noui.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "noui.h" #include "ui_interface.h" diff --git a/src/noui.h b/src/noui.h index 15cd30a63..185d4d0ce 100644 --- a/src/noui.h +++ b/src/noui.h @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_NOUI_H #define BITCOIN_NOUI_H diff --git a/src/policy/fees.cpp b/src/policy/fees.cpp index e4ff99246..3d12aee15 100644 --- a/src/policy/fees.cpp +++ b/src/policy/fees.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "policy/fees.h" #include "amount.h" diff --git a/src/policy/fees.h b/src/policy/fees.h index 6d43189be..514f17724 100644 --- a/src/policy/fees.h +++ b/src/policy/fees.h @@ -2,6 +2,22 @@ // Copyright (c) 2009-2015 The Bitcoin developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_POLICYESTIMATOR_H #define BITCOIN_POLICYESTIMATOR_H diff --git a/src/pow.cpp b/src/pow.cpp index 7e72a9e01..b69c4fce6 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "pow.h" #include "consensus/upgrades.h" diff --git a/src/pow.h b/src/pow.h index 0c6c899b8..4946cb6e8 100644 --- a/src/pow.h +++ b/src/pow.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_POW_H #define BITCOIN_POW_H diff --git a/src/primitives/block.cpp b/src/primitives/block.cpp index c34238702..00fc8cee9 100644 --- a/src/primitives/block.cpp +++ b/src/primitives/block.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "primitives/block.h" #include "hash.h" diff --git a/src/primitives/block.h b/src/primitives/block.h index 053b1c80e..5cd0a72fe 100644 --- a/src/primitives/block.h +++ b/src/primitives/block.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_PRIMITIVES_BLOCK_H #define BITCOIN_PRIMITIVES_BLOCK_H diff --git a/src/primitives/nonce.cpp b/src/primitives/nonce.cpp index 85cb7155a..d90a4d78c 100644 --- a/src/primitives/nonce.cpp +++ b/src/primitives/nonce.cpp @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "hash.h" #include "nonce.h" #include diff --git a/src/primitives/nonce.h b/src/primitives/nonce.h index a3da4b6b5..605564671 100644 --- a/src/primitives/nonce.h +++ b/src/primitives/nonce.h @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_PRIMITIVES_NONCE_H #define BITCOIN_PRIMITIVES_NONCE_H diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index fff573496..ea24f9d23 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "primitives/transaction.h" #include "hash.h" diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 0f0690b5c..d97ff03fb 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_PRIMITIVES_TRANSACTION_H #define BITCOIN_PRIMITIVES_TRANSACTION_H diff --git a/src/protocol.cpp b/src/protocol.cpp index 33b9ee773..c7d95f809 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "protocol.h" #include "util.h" diff --git a/src/protocol.h b/src/protocol.h index d908191cc..d2a3cf556 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef __cplusplus #error This header can only be compiled as C++. #endif diff --git a/src/pubkey.cpp b/src/pubkey.cpp index 53e94fbdb..c714c8671 100644 --- a/src/pubkey.cpp +++ b/src/pubkey.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "pubkey.h" #include diff --git a/src/pubkey.h b/src/pubkey.h index 12f11c249..18e4dda8f 100644 --- a/src/pubkey.h +++ b/src/pubkey.h @@ -4,6 +4,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_PUBKEY_H #define BITCOIN_PUBKEY_H diff --git a/src/random.cpp b/src/random.cpp index 87b3f648e..e13bbd9d8 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "random.h" #include "support/cleanse.h" diff --git a/src/random.h b/src/random.h index 8cec678ef..b65c7e08a 100644 --- a/src/random.h +++ b/src/random.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_RANDOM_H #define BITCOIN_RANDOM_H diff --git a/src/rest.cpp b/src/rest.cpp index 566732ca2..1609891a3 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "primitives/block.h" #include "primitives/transaction.h" #include "main.h" diff --git a/src/reverselock.h b/src/reverselock.h index fac1ccb79..dd79cf3da 100644 --- a/src/reverselock.h +++ b/src/reverselock.h @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_REVERSELOCK_H #define BITCOIN_REVERSELOCK_H diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index f024215b6..8e08056df 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "amount.h" #include "chain.h" #include "chainparams.h" diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index d09228bcc..ac45cd107 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "rpc/client.h" #include "rpc/protocol.h" #include "util.h" diff --git a/src/rpc/client.h b/src/rpc/client.h index 8937a56f0..79527b7be 100644 --- a/src/rpc/client.h +++ b/src/rpc/client.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_RPCCLIENT_H #define BITCOIN_RPCCLIENT_H diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 4f7603507..c9a96165a 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -1,3 +1,18 @@ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "amount.h" #include "chain.h" #include "chainparams.h" @@ -279,7 +294,7 @@ UniValue selfimport(const UniValue& params, bool fHelp) txid = Parseuint256((char *)params[0].get_str().c_str()); burnAmount = atof(params[1].get_str().c_str()) * COIN + 0.00000000499999; // txid is just used to specify the import recv address - // in reality it would be rawtx from the other chain + // in reality it would be rawtx from the other chain and maybe better to specify address if ( GetTransaction(txid,tx,blockHash,false) == 0 ) throw runtime_error("selfimport couldnt find txid"); savevout = tx.vout[0]; diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 042dd9b00..a0643528d 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "amount.h" #include "chainparams.h" #include "consensus/consensus.h" diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 7bfb98f7b..47940be4d 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "clientversion.h" #include "init.h" #include "key_io.h" diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index d922daad4..e280b1a0b 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "rpc/server.h" #include "clientversion.h" diff --git a/src/rpc/protocol.cpp b/src/rpc/protocol.cpp index 7713a54b3..2366fca14 100644 --- a/src/rpc/protocol.cpp +++ b/src/rpc/protocol.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "rpc/protocol.h" #include "random.h" diff --git a/src/rpc/protocol.h b/src/rpc/protocol.h index 816ce9ec5..91a14c023 100644 --- a/src/rpc/protocol.h +++ b/src/rpc/protocol.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_RPCPROTOCOL_H #define BITCOIN_RPCPROTOCOL_H diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 21a6e26cd..067471c2c 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "consensus/upgrades.h" #include "consensus/validation.h" #include "core_io.h" diff --git a/src/rpc/register.h b/src/rpc/register.h index 01aa58a25..072517d88 100644 --- a/src/rpc/register.h +++ b/src/rpc/register.h @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_RPCREGISTER_H #define BITCOIN_RPCREGISTER_H diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 5bdc0b3ce..acd8c4bb8 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "rpc/server.h" #include "init.h" diff --git a/src/rpc/server.h b/src/rpc/server.h index 96e3da82f..f5b28538c 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_RPCSERVER_H #define BITCOIN_RPCSERVER_H diff --git a/src/scheduler.cpp b/src/scheduler.cpp index 8729f2a5a..e085791fc 100644 --- a/src/scheduler.cpp +++ b/src/scheduler.cpp @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "scheduler.h" #include "reverselock.h" diff --git a/src/scheduler.h b/src/scheduler.h index 436659e58..af1d7a24c 100644 --- a/src/scheduler.h +++ b/src/scheduler.h @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_SCHEDULER_H #define BITCOIN_SCHEDULER_H diff --git a/src/script/cc.cpp b/src/script/cc.cpp index ce9262295..a0770a9b2 100644 --- a/src/script/cc.cpp +++ b/src/script/cc.cpp @@ -1,3 +1,18 @@ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "cryptoconditions/include/cryptoconditions.h" #include "script/cc.h" diff --git a/src/script/cc.h b/src/script/cc.h index 583769a38..b3ee612a5 100644 --- a/src/script/cc.h +++ b/src/script/cc.h @@ -1,3 +1,18 @@ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef SCRIPT_CC_H #define SCRIPT_CC_H diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index b66c07771..64d98d783 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include #include "interpreter.h" diff --git a/src/script/interpreter.h b/src/script/interpreter.h index f7a02f26d..11812b6e3 100644 --- a/src/script/interpreter.h +++ b/src/script/interpreter.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_SCRIPT_INTERPRETER_H #define BITCOIN_SCRIPT_INTERPRETER_H diff --git a/src/script/script.cpp b/src/script/script.cpp index 8de75bb22..475acdfd5 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "script.h" #include "tinyformat.h" diff --git a/src/script/script.h b/src/script/script.h index 52d25b3d8..b1294ab25 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_SCRIPT_SCRIPT_H #define BITCOIN_SCRIPT_SCRIPT_H diff --git a/src/script/script_error.cpp b/src/script/script_error.cpp index 41c8a24e0..199161364 100644 --- a/src/script/script_error.cpp +++ b/src/script/script_error.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "script_error.h" const char* ScriptErrorString(const ScriptError serror) diff --git a/src/script/script_error.h b/src/script/script_error.h index 35c8fbfd8..85fe1cff3 100644 --- a/src/script/script_error.h +++ b/src/script/script_error.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_SCRIPT_SCRIPT_ERROR_H #define BITCOIN_SCRIPT_SCRIPT_ERROR_H diff --git a/src/script/script_ext.cpp b/src/script/script_ext.cpp index 613b50c05..532e39d6c 100644 --- a/src/script/script_ext.cpp +++ b/src/script/script_ext.cpp @@ -4,6 +4,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "script_ext.h" using namespace std; diff --git a/src/script/script_ext.h b/src/script/script_ext.h index 187c01a5b..e14cbd1f7 100644 --- a/src/script/script_ext.h +++ b/src/script/script_ext.h @@ -4,6 +4,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_SCRIPT_SCRIPT_EXT_H #define BITCOIN_SCRIPT_SCRIPT_EXT_H diff --git a/src/script/serverchecker.cpp b/src/script/serverchecker.cpp index 469401390..9fc470e14 100644 --- a/src/script/serverchecker.cpp +++ b/src/script/serverchecker.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "serverchecker.h" #include "script/cc.h" #include "cc/eval.h" diff --git a/src/script/serverchecker.h b/src/script/serverchecker.h index 6e5bffe55..08f3acc6c 100644 --- a/src/script/serverchecker.h +++ b/src/script/serverchecker.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_SCRIPT_SERVERCHECKER_H #define BITCOIN_SCRIPT_SERVERCHECKER_H diff --git a/src/script/sigcache.cpp b/src/script/sigcache.cpp index 07ec87a12..b78fc3ce3 100644 --- a/src/script/sigcache.cpp +++ b/src/script/sigcache.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "sigcache.h" #include "pubkey.h" diff --git a/src/script/sigcache.h b/src/script/sigcache.h index 134b72a2d..e9169eab6 100644 --- a/src/script/sigcache.h +++ b/src/script/sigcache.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_SCRIPT_SIGCACHE_H #define BITCOIN_SCRIPT_SIGCACHE_H diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 3bc49ef76..b90ceafb5 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "script/sign.h" #include "primitives/transaction.h" diff --git a/src/script/sign.h b/src/script/sign.h index ac2ab6476..4455d4281 100644 --- a/src/script/sign.h +++ b/src/script/sign.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_SCRIPT_SIGN_H #define BITCOIN_SCRIPT_SIGN_H diff --git a/src/script/standard.cpp b/src/script/standard.cpp index 3b57afd9d..be78aaf76 100644 --- a/src/script/standard.cpp +++ b/src/script/standard.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "script/standard.h" #include "pubkey.h" diff --git a/src/script/standard.h b/src/script/standard.h index 8536b56df..ae7336e2f 100644 --- a/src/script/standard.h +++ b/src/script/standard.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_SCRIPT_STANDARD_H #define BITCOIN_SCRIPT_STANDARD_H diff --git a/src/script/zcashconsensus.cpp b/src/script/zcashconsensus.cpp index 50d732fff..dc4ec7dc1 100644 --- a/src/script/zcashconsensus.cpp +++ b/src/script/zcashconsensus.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "zcashconsensus.h" #include "consensus/upgrades.h" diff --git a/src/script/zcashconsensus.h b/src/script/zcashconsensus.h index ff13471c6..e01a50421 100644 --- a/src/script/zcashconsensus.h +++ b/src/script/zcashconsensus.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_ZCASHCONSENSUS_H #define BITCOIN_ZCASHCONSENSUS_H diff --git a/src/sendalert.cpp b/src/sendalert.cpp index f2c2b8c0f..700146338 100644 --- a/src/sendalert.cpp +++ b/src/sendalert.cpp @@ -1,6 +1,21 @@ // Copyright (c) 2016 The Zcash developers // Original code from: https://gist.github.com/laanwj/0e689cfa37b52bcbbb44 +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + /* To set up a new alert system diff --git a/src/serialize.h b/src/serialize.h index ac2db6edd..3d9c3fae6 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_SERIALIZE_H #define BITCOIN_SERIALIZE_H diff --git a/src/streams.h b/src/streams.h index 9d4a2e39e..83c90cd39 100644 --- a/src/streams.h +++ b/src/streams.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_STREAMS_H #define BITCOIN_STREAMS_H diff --git a/src/sync.cpp b/src/sync.cpp index 1837e8d53..31c3301bd 100644 --- a/src/sync.cpp +++ b/src/sync.cpp @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "sync.h" #include "util.h" diff --git a/src/sync.h b/src/sync.h index c9ba7f8b0..a8f29eb66 100644 --- a/src/sync.h +++ b/src/sync.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_SYNC_H #define BITCOIN_SYNC_H diff --git a/src/timedata.cpp b/src/timedata.cpp index 1dcef2de3..daeb7bae0 100644 --- a/src/timedata.cpp +++ b/src/timedata.cpp @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "timedata.h" #include "netbase.h" diff --git a/src/txdb.cpp b/src/txdb.cpp index 63e00dcd8..164167c29 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "txdb.h" #include "chainparams.h" diff --git a/src/txdb.h b/src/txdb.h index 1370ebeee..b9bae2fe4 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_TXDB_H #define BITCOIN_TXDB_H diff --git a/src/txmempool.cpp b/src/txmempool.cpp index c9b890169..f57860c76 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "txmempool.h" #include "clientversion.h" diff --git a/src/txmempool.h b/src/txmempool.h index 8f6a8c2c0..d3e7f7b57 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_TXMEMPOOL_H #define BITCOIN_TXMEMPOOL_H diff --git a/src/uint256.cpp b/src/uint256.cpp index 25148808c..c238490b8 100644 --- a/src/uint256.cpp +++ b/src/uint256.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "uint256.h" #include "utilstrencodings.h" diff --git a/src/uint256.h b/src/uint256.h index f22a8bafa..d819dc630 100644 --- a/src/uint256.h +++ b/src/uint256.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_UINT256_H #define BITCOIN_UINT256_H diff --git a/src/util.cpp b/src/util.cpp index fa67f02ee..2abbf5bef 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #if defined(HAVE_CONFIG_H) #include "config/bitcoin-config.h" #endif diff --git a/src/version.h b/src/version.h index 72ddac446..8b46fe7cf 100644 --- a/src/version.h +++ b/src/version.h @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_VERSION_H #define BITCOIN_VERSION_H diff --git a/src/wallet/asyncrpcoperation_mergetoaddress.cpp b/src/wallet/asyncrpcoperation_mergetoaddress.cpp index c97999efd..bba44fe50 100644 --- a/src/wallet/asyncrpcoperation_mergetoaddress.cpp +++ b/src/wallet/asyncrpcoperation_mergetoaddress.cpp @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "asyncrpcoperation_mergetoaddress.h" #include "amount.h" diff --git a/src/wallet/asyncrpcoperation_mergetoaddress.h b/src/wallet/asyncrpcoperation_mergetoaddress.h index f7ac81261..be49baff0 100644 --- a/src/wallet/asyncrpcoperation_mergetoaddress.h +++ b/src/wallet/asyncrpcoperation_mergetoaddress.h @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef ASYNCRPCOPERATION_MERGETOADDRESS_H #define ASYNCRPCOPERATION_MERGETOADDRESS_H diff --git a/src/wallet/asyncrpcoperation_sendmany.cpp b/src/wallet/asyncrpcoperation_sendmany.cpp index a999f00f6..d4c5077cc 100644 --- a/src/wallet/asyncrpcoperation_sendmany.cpp +++ b/src/wallet/asyncrpcoperation_sendmany.cpp @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "asyncrpcoperation_sendmany.h" #include "asyncrpcqueue.h" #include "amount.h" diff --git a/src/wallet/asyncrpcoperation_sendmany.h b/src/wallet/asyncrpcoperation_sendmany.h index a93925874..8e39f341a 100644 --- a/src/wallet/asyncrpcoperation_sendmany.h +++ b/src/wallet/asyncrpcoperation_sendmany.h @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef ASYNCRPCOPERATION_SENDMANY_H #define ASYNCRPCOPERATION_SENDMANY_H diff --git a/src/wallet/asyncrpcoperation_shieldcoinbase.cpp b/src/wallet/asyncrpcoperation_shieldcoinbase.cpp index 0f0dc5392..73e70a9d8 100644 --- a/src/wallet/asyncrpcoperation_shieldcoinbase.cpp +++ b/src/wallet/asyncrpcoperation_shieldcoinbase.cpp @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "asyncrpcqueue.h" #include "amount.h" #include "consensus/upgrades.h" diff --git a/src/wallet/asyncrpcoperation_shieldcoinbase.h b/src/wallet/asyncrpcoperation_shieldcoinbase.h index e75bb8e82..b3fef0fc1 100644 --- a/src/wallet/asyncrpcoperation_shieldcoinbase.h +++ b/src/wallet/asyncrpcoperation_shieldcoinbase.h @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef ASYNCRPCOPERATION_SHIELDCOINBASE_H #define ASYNCRPCOPERATION_SHIELDCOINBASE_H diff --git a/src/wallet/crypter.cpp b/src/wallet/crypter.cpp index 05c1a6e76..38aff1a04 100644 --- a/src/wallet/crypter.cpp +++ b/src/wallet/crypter.cpp @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "crypter.h" #include "script/script.h" diff --git a/src/wallet/crypter.h b/src/wallet/crypter.h index 1cfefe886..f42a762af 100644 --- a/src/wallet/crypter.h +++ b/src/wallet/crypter.h @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_WALLET_CRYPTER_H #define BITCOIN_WALLET_CRYPTER_H diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp index c6beb8a52..dd0880b75 100644 --- a/src/wallet/db.cpp +++ b/src/wallet/db.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "db.h" #include "addrman.h" diff --git a/src/wallet/db.h b/src/wallet/db.h index 64071caa3..19b9b6079 100644 --- a/src/wallet/db.h +++ b/src/wallet/db.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_WALLET_DB_H #define BITCOIN_WALLET_DB_H diff --git a/src/wallet/rpcdisclosure.cpp b/src/wallet/rpcdisclosure.cpp index 41195cfc8..19fb44d0e 100644 --- a/src/wallet/rpcdisclosure.cpp +++ b/src/wallet/rpcdisclosure.cpp @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "rpc/server.h" #include "init.h" #include "key_io.h" diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 7ec0c23c1..d233b418a 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "chain.h" #include "key_io.h" #include "rpc/server.h" diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c3cb0ebc2..c3faff238 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "amount.h" #include "consensus/upgrades.h" #include "core_io.h" diff --git a/src/wallet/rpcwallet.h b/src/wallet/rpcwallet.h index a5de7e2de..7739e94a2 100644 --- a/src/wallet/rpcwallet.h +++ b/src/wallet/rpcwallet.h @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_WALLET_RPCWALLET_H #define BITCOIN_WALLET_RPCWALLET_H diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 3857f7090..024194695 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "wallet/wallet.h" #include "checkpoints.h" diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index c5cfedda8..29f1737eb 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_WALLET_WALLET_H #define BITCOIN_WALLET_WALLET_H diff --git a/src/wallet/wallet_ismine.cpp b/src/wallet/wallet_ismine.cpp index 3d8ccd0a8..692d0280d 100644 --- a/src/wallet/wallet_ismine.cpp +++ b/src/wallet/wallet_ismine.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "wallet_ismine.h" #include "key.h" diff --git a/src/wallet/wallet_ismine.h b/src/wallet/wallet_ismine.h index 2f0e1080d..409def1ef 100644 --- a/src/wallet/wallet_ismine.h +++ b/src/wallet/wallet_ismine.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_WALLET_WALLET_ISMINE_H #define BITCOIN_WALLET_WALLET_ISMINE_H diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 41c0de4b2..867bca08b 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #include "wallet/walletdb.h" #include "consensus/validation.h" diff --git a/src/wallet/walletdb.h b/src/wallet/walletdb.h index b3210bbc0..2c57ec1e8 100644 --- a/src/wallet/walletdb.h +++ b/src/wallet/walletdb.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + #ifndef BITCOIN_WALLET_WALLETDB_H #define BITCOIN_WALLET_WALLETDB_H From 2995bbcc794c99f39703c1ed220410065c03a878 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Dec 2018 23:28:35 -1100 Subject: [PATCH 088/643] rework selfimport --- src/cc/import.cpp | 76 +++++++++++++++++++++++++++--------------- src/komodo_utils.h | 6 ---- src/rpc/crosschain.cpp | 39 +++++++--------------- 3 files changed, 61 insertions(+), 60 deletions(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index 7902a74b3..d8006cca2 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -31,9 +31,12 @@ extern std::string ASSETCHAINS_SELFIMPORT; extern uint16_t ASSETCHAINS_CODAPORT,ASSETCHAINS_BEAMPORT; +int32_t komodo_nextheight(); -int32_t GetSelfimportProof(TxProof &proof,CTransaction burnTx,uint256 hash) // find burnTx with hash from "other" daemon +int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 hash,std::vector rawproof) // find burnTx with hash from "other" daemon { + MerkleBranch newBranch; CMutableTransaction &tmpmtx; CTransaction tx,vintx; uint256 blockHash; char destaddr[64],pkaddr[64]; + tmpmtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),komodo_nextheight()); if ( ASSETCHAINS_SELFIMPORT == "BEAM" ) { // confirm via ASSETCHAINS_BEAMPORT that burnTx/hash is a valid BEAM burn @@ -44,15 +47,45 @@ int32_t GetSelfimportProof(TxProof &proof,CTransaction burnTx,uint256 hash) // f // confirm via ASSETCHAINS_CODAPORT that burnTx/hash is a valid CODA burn return(-1); } - else if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) + else { - // make sure vin0 is signed by ASSETCHAINS_OVERRIDE_PUBKEY33 - return(0); - } - else if ( ASSETCHAINS_SELFIMPORT == "GATEWAY" ) - { - // external coin is the assetchains symbol in the burnTx OP_RETURN + if ( !E_UNMARSHAL(rawtx, ss >> tx) ) return(-1); + scriptPubKey = tx.vout[0].scriptPubKey; + mtx = tx; + mtx.fOverwintered = tmptx.fOverwintered; + mtx.nExpiryHeight = tmptx.nExpiryHeight; + mtx.nVersionGroupId = tmptx.nVersionGroupId; + mtx.nVersion = tmptx.nVersion; + mtx.vout.clear(); + mtx.vout.resize(1); + mtx.vout[0].nValue = burnAmount; + mtx.vout[0].scriptPubKey = scriptPubKey; + if ( tx.GetHash() != txid ) + return(-1); + if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) + { + // make sure vin0 is signed by ASSETCHAINS_OVERRIDE_PUBKEY33 + if ( GetTransaction(tx.vin[0].prevout,vintx,blockHash,false) == 0 ) + return(-1); + if ( tx.vin[0].prevn < vintx.vout.size() && Getscriptaddress(destaddr,vintx.vout[tx.vin[0].prevn].scriptPubKey) != 0 ) + { + pubkey2addr(pkaddr,ASSETCHAINS_OVERRIDE_PUBKEY33.data()); + if ( strcmp(pkaddr,destaddr) == 0 ) + { + proof = std::make_pair(txid,newBranch); + return(0); + } + fprintf(stderr,"vin0[%d] -> %s vs %s\n",tx.vin[0].prevn,destaddr,pkaddr); + } + return(-1); + } + else + { + // ASSETCHAINS_SELFIMPORT and external coin is the assetchains symbol in the burnTx OP_RETURN + // burnAmount, rawtx and rawproof should be enough for gatewaysdeposit equivalent + return(-1); + } } else return(-1); return(0); @@ -81,20 +114,18 @@ int32_t CheckGATEWAYimport(std::string coin,TxProof proof,CTransaction burnTx,st int32_t CheckPUBKEYimport(TxProof proof,CTransaction burnTx,std::vector payouts) { // if burnTx has ASSETCHAINS_PUBKEY vin, it is valid return(0); + fprintf(stderr,"proof txid.%s\n",proof.first.GetHex().ToString().c_str()); return(0); return(-1); } -bool Eval::ImportCoin(const std::vector params, const CTransaction &importTx, unsigned int nIn) +bool Eval::ImportCoin(const std::vector params,const CTransaction &importTx,unsigned int nIn) { + TxProof proof; CTransaction burnTx; std::vector payouts; uint64_t txfee = 10000; + uint32_t targetCcid; std::string targetSymbol; uint256 payoutsHash; if (importTx.vout.size() < 2) return Invalid("too-few-vouts"); - // params - TxProof proof; - CTransaction burnTx; - std::vector payouts; - if (!UnmarshalImportTx(importTx, proof, burnTx, payouts)) return Invalid("invalid-params"); @@ -102,15 +133,9 @@ bool Eval::ImportCoin(const std::vector params, const CTransaction &imp // It should not be at all malleable if (MakeImportCoinTransaction(proof, burnTx, payouts).GetHash() != importTx.GetHash()) return Invalid("non-canonical"); - // burn params - uint32_t targetCcid; - std::string targetSymbol; - uint256 payoutsHash; - if (!UnmarshalBurnTx(burnTx, targetSymbol, &targetCcid, payoutsHash)) return Invalid("invalid-burn-tx"); - // check burn amount { uint64_t burnAmount = burnTx.vout.back().nValue; @@ -119,27 +144,24 @@ bool Eval::ImportCoin(const std::vector params, const CTransaction &imp uint64_t totalOut = 0; for (int i=0; i burnAmount) + if (totalOut > burnAmount || totalOut < burnAmount-txfee ) return Invalid("payout-too-high"); } - // Check burntx shows correct outputs hash if (payoutsHash != SerializeHash(payouts)) return Invalid("wrong-payouts"); - if (targetCcid < KOMODO_FIRSTFUNGIBLEID) return Invalid("chain-not-fungible"); - // Check proof confirms existance of burnTx if ( targetCcid != 0xffffffff ) { - if (targetCcid != GetAssetchainsCC() || targetSymbol != GetAssetchainsSymbol()) + if ( targetCcid != GetAssetchainsCC() || targetSymbol != GetAssetchainsSymbol() ) return Invalid("importcoin-wrong-chain"); uint256 target = proof.second.Exec(burnTx.GetHash()); if (!CheckMoMoM(proof.first, target)) return Invalid("momom-check-fail"); } - else if ( ASSETCHAINS_SELFIMPORT == targetSymbol || ASSETCHAINS_SELFIMPORT == "GATEWAY" ) // various selfchain imports + else if ( ASSETCHAINS_SELFIMPORT == targetSymbol ) // various selfchain imports { if ( ASSETCHAINS_SELFIMPORT == "BEAM" ) { @@ -158,7 +180,7 @@ bool Eval::ImportCoin(const std::vector params, const CTransaction &imp } else { - if ( CheckGATEWAYimport(GetAssetchainsSymbol(),proof,burnTx,payouts) < 0 ) + if ( CheckGATEWAYimport(targetSymbol,proof,burnTx,payouts) < 0 ) return Invalid("GATEWAY-import-failure"); } } diff --git a/src/komodo_utils.h b/src/komodo_utils.h index f5d394c7e..a8823e5b3 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1798,12 +1798,6 @@ void komodo_args(char *argv0) ASSETCHAINS_SELFIMPORT = ""; exit(0); } - else if ( ASSETCHAINS_SELFIMPORT.size() > 0 && ASSETCHAINS_SELFIMPORT != "GATEWAY" ) - { - fprintf(stderr,"invalid -ac_import type\n"); - ASSETCHAINS_SELFIMPORT = ""; - exit(0); - } if ( ASSETCHAINS_SELFIMPORT.size() > 0 && ASSETCHAINS_CC >= KOMODO_FIRSTFUNGIBLEID ) { fprintf(stderr,"selfimport chains cant be in a fungible cluster\n"); diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index c9a96165a..9ba93f3f4 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -46,9 +46,8 @@ int32_t komodo_MoMoMdata(char *hexstr,int32_t hexsize,struct komodo_ccdataMoMoM struct komodo_ccdata_entry *komodo_allMoMs(int32_t *nump,uint256 *MoMoMp,int32_t kmdstarti,int32_t kmdendi); uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth); extern std::string ASSETCHAINS_SELFIMPORT; -int komodo_nextheight(); uint256 Parseuint256(char *hexstr); -int32_t GetSelfimportProof(TxProof &proof,CTransaction burnTx,uint256 hash); +int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 hash,std::vector rawproof); UniValue assetchainproof(const UniValue& params, bool fHelp) @@ -201,13 +200,7 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp) throw runtime_error("export_amount too small"); } if ( ASSETCHAINS_SELFIMPORT.size() > 0 ) - { throw runtime_error("self-import chains cant be fungible"); - /*if ( ASSETCHAINS_SELFIMPORT == targetSymbol || ASSETCHAINS_SELFIMPORT == "GATEWAY" ) - { - ccid = 0xffffffff; - } // else maybe clusters of self-import chains can be supported?*/ - } CTxOut burnOut = MakeBurnOutput(burnAmount, ccid, targetSymbol, tx.vout); UniValue ret(UniValue::VOBJ); ret.push_back(Pair("payouts", HexStr(E_MARSHAL(ss << tx.vout)))); @@ -284,33 +277,25 @@ UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp) UniValue selfimport(const UniValue& params, bool fHelp) { - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - TxProof proof; CTransaction burnTx,tx; CTxOut burnOut,savevout; uint64_t burnAmount; uint256 txid,blockHash; std::vector vouts; + CMutableTransaction mtx; + TxProof proof; CTransaction burnTx,tx; CTxOut burnOut; uint64_t burnAmount; uint256 txid,blockHash; std::vector vouts; std::vector rawtx,rawproof; CScript scriptPubKey; if ( ASSETCHAINS_SELFIMPORT.size() == 0 ) throw runtime_error("selfimport only works on -ac_import chains"); - if (fHelp || params.size() != 2) - throw runtime_error("selfimport txid burnamount\n\n" + if (fHelp || params.size() < 3 || params.size() > 4) + throw runtime_error("selfimport rawtx txid burnamount\n\n" "creates signed selfimport transaction from txid"); - txid = Parseuint256((char *)params[0].get_str().c_str()); - burnAmount = atof(params[1].get_str().c_str()) * COIN + 0.00000000499999; - // txid is just used to specify the import recv address - // in reality it would be rawtx from the other chain and maybe better to specify address - if ( GetTransaction(txid,tx,blockHash,false) == 0 ) - throw runtime_error("selfimport couldnt find txid"); - savevout = tx.vout[0]; - mtx = tx; - mtx.vout.clear(); - mtx.vout.resize(1); - mtx.vout[0] = savevout; - mtx.vout[0].nValue = burnAmount; + rawtx = ParseHex(params[0].get_str().c_str()); + txid = Parseuint256((char *)params[1].get_str().c_str()); // allow for txid != hash(rawtx) + burnAmount = atof(params[2].get_str().c_str()) * COIN + 0.00000000499999; + if ( params.size() == 4 ) + rawproof = ParseHex(params[3].get_str().c_str()); + if ( GetSelfimportProof(mtx,scriptPubKey,proof,burnAmount,rawtx,txid,rawproof) < 0 ) + throw std::runtime_error("Failed validating selfimport"); vouts = mtx.vout; burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,vouts); - mtx = tx; mtx.vout.clear(); mtx.vout.push_back(burnOut); burnTx = mtx; - if ( GetSelfimportProof(proof,tx,txid) < 0 ) - throw std::runtime_error("Failed validating selfimport"); return HexStr(E_MARSHAL(ss << MakeImportCoinTransaction(proof,burnTx,vouts))); } From 892067414816e146aa9f8776450a701c98389529 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Dec 2018 23:32:02 -1100 Subject: [PATCH 089/643] Syntax --- src/cc/import.cpp | 18 ++++++++++-------- src/rpc/crosschain.cpp | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index d8006cca2..2395791a8 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -32,8 +32,10 @@ extern std::string ASSETCHAINS_SELFIMPORT; extern uint16_t ASSETCHAINS_CODAPORT,ASSETCHAINS_BEAMPORT; int32_t komodo_nextheight(); +bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock); +uint8_t ASSETCHAINS_OVERRIDE_PUBKEY33[33]; -int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 hash,std::vector rawproof) // find burnTx with hash from "other" daemon +int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 txid,std::vector rawproof) // find burnTx with hash from "other" daemon { MerkleBranch newBranch; CMutableTransaction &tmpmtx; CTransaction tx,vintx; uint256 blockHash; char destaddr[64],pkaddr[64]; tmpmtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),komodo_nextheight()); @@ -53,10 +55,10 @@ int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProo return(-1); scriptPubKey = tx.vout[0].scriptPubKey; mtx = tx; - mtx.fOverwintered = tmptx.fOverwintered; - mtx.nExpiryHeight = tmptx.nExpiryHeight; - mtx.nVersionGroupId = tmptx.nVersionGroupId; - mtx.nVersion = tmptx.nVersion; + mtx.fOverwintered = tmpmtx.fOverwintered; + mtx.nExpiryHeight = tmpmtx.nExpiryHeight; + mtx.nVersionGroupId = tmpmtx.nVersionGroupId; + mtx.nVersion = tmpmtx.nVersion; mtx.vout.clear(); mtx.vout.resize(1); mtx.vout[0].nValue = burnAmount; @@ -66,9 +68,9 @@ int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProo if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) { // make sure vin0 is signed by ASSETCHAINS_OVERRIDE_PUBKEY33 - if ( GetTransaction(tx.vin[0].prevout,vintx,blockHash,false) == 0 ) + if ( myGetTransaction(tx.vin[0].prevout,vintx,blockHash) == 0 ) return(-1); - if ( tx.vin[0].prevn < vintx.vout.size() && Getscriptaddress(destaddr,vintx.vout[tx.vin[0].prevn].scriptPubKey) != 0 ) + if ( tx.vin[0].n < vintx.vout.size() && Getscriptaddress(destaddr,vintx.vout[tx.vin[0].n].scriptPubKey) != 0 ) { pubkey2addr(pkaddr,ASSETCHAINS_OVERRIDE_PUBKEY33.data()); if ( strcmp(pkaddr,destaddr) == 0 ) @@ -76,7 +78,7 @@ int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProo proof = std::make_pair(txid,newBranch); return(0); } - fprintf(stderr,"vin0[%d] -> %s vs %s\n",tx.vin[0].prevn,destaddr,pkaddr); + fprintf(stderr,"vin0[%d] -> %s vs %s\n",tx.vin[0].n,destaddr,pkaddr); } return(-1); } diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 9ba93f3f4..5f40f60fb 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -47,7 +47,7 @@ struct komodo_ccdata_entry *komodo_allMoMs(int32_t *nump,uint256 *MoMoMp,int32_t uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth); extern std::string ASSETCHAINS_SELFIMPORT; uint256 Parseuint256(char *hexstr); -int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 hash,std::vector rawproof); +int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 txid,std::vector rawproof); UniValue assetchainproof(const UniValue& params, bool fHelp) From fec1d8206984d53a0e82b202b71dd3dd45f43ccd Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Dec 2018 23:35:35 -1100 Subject: [PATCH 090/643] Fixes --- src/cc/import.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index 2395791a8..5129354ff 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -34,10 +34,12 @@ extern uint16_t ASSETCHAINS_CODAPORT,ASSETCHAINS_BEAMPORT; int32_t komodo_nextheight(); bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock); uint8_t ASSETCHAINS_OVERRIDE_PUBKEY33[33]; +CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Params& consensusParams, int nHeight); +bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 txid,std::vector rawproof) // find burnTx with hash from "other" daemon { - MerkleBranch newBranch; CMutableTransaction &tmpmtx; CTransaction tx,vintx; uint256 blockHash; char destaddr[64],pkaddr[64]; + MerkleBranch newBranch; CMutableTransaction tmpmtx; CTransaction tx,vintx; uint256 blockHash; char destaddr[64],pkaddr[64]; tmpmtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),komodo_nextheight()); if ( ASSETCHAINS_SELFIMPORT == "BEAM" ) { @@ -70,7 +72,7 @@ int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProo // make sure vin0 is signed by ASSETCHAINS_OVERRIDE_PUBKEY33 if ( myGetTransaction(tx.vin[0].prevout,vintx,blockHash) == 0 ) return(-1); - if ( tx.vin[0].n < vintx.vout.size() && Getscriptaddress(destaddr,vintx.vout[tx.vin[0].n].scriptPubKey) != 0 ) + if ( tx.vin[0].prevout < vintx.vout.size() && Getscriptaddress(destaddr,vintx.vout[tx.vin[0].prevout].scriptPubKey) != 0 ) { pubkey2addr(pkaddr,ASSETCHAINS_OVERRIDE_PUBKEY33.data()); if ( strcmp(pkaddr,destaddr) == 0 ) @@ -78,7 +80,7 @@ int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProo proof = std::make_pair(txid,newBranch); return(0); } - fprintf(stderr,"vin0[%d] -> %s vs %s\n",tx.vin[0].n,destaddr,pkaddr); + fprintf(stderr,"vin0[%d] -> %s vs %s\n",tx.vin[0].prevout,destaddr,pkaddr); } return(-1); } From e3ef4f65a4794714d86c40857f557ee6f3fd44f2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Dec 2018 23:39:24 -1100 Subject: [PATCH 091/643] Include CCinclude --- src/cc/import.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index 5129354ff..ecc12c3f8 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -18,7 +18,7 @@ #include "importcoin.h" #include "crosschain.h" #include "primitives/transaction.h" - +#include "cc/CCinclude.h" /* * CC Eval method for import coin. @@ -31,11 +31,11 @@ extern std::string ASSETCHAINS_SELFIMPORT; extern uint16_t ASSETCHAINS_CODAPORT,ASSETCHAINS_BEAMPORT; -int32_t komodo_nextheight(); -bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock); +//int32_t komodo_nextheight(); +//bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock); uint8_t ASSETCHAINS_OVERRIDE_PUBKEY33[33]; -CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Params& consensusParams, int nHeight); -bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); +//CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Params& consensusParams, int nHeight); +//bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 txid,std::vector rawproof) // find burnTx with hash from "other" daemon { @@ -70,11 +70,11 @@ int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProo if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) { // make sure vin0 is signed by ASSETCHAINS_OVERRIDE_PUBKEY33 - if ( myGetTransaction(tx.vin[0].prevout,vintx,blockHash) == 0 ) + if ( myGetTransaction(tx.vin[0].prevhash,vintx,blockHash) == 0 ) return(-1); if ( tx.vin[0].prevout < vintx.vout.size() && Getscriptaddress(destaddr,vintx.vout[tx.vin[0].prevout].scriptPubKey) != 0 ) { - pubkey2addr(pkaddr,ASSETCHAINS_OVERRIDE_PUBKEY33.data()); + pubkey2addr(pkaddr,ASSETCHAINS_OVERRIDE_PUBKEY33); if ( strcmp(pkaddr,destaddr) == 0 ) { proof = std::make_pair(txid,newBranch); From 0f05fef7e56ae78bf81cb5f155101b83a6ef32f7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Dec 2018 23:41:17 -1100 Subject: [PATCH 092/643] prevout.n --- src/cc/import.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index ecc12c3f8..2faf4fb07 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -70,9 +70,9 @@ int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProo if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) { // make sure vin0 is signed by ASSETCHAINS_OVERRIDE_PUBKEY33 - if ( myGetTransaction(tx.vin[0].prevhash,vintx,blockHash) == 0 ) + if ( myGetTransaction(tx.vin[0].prevout.hash,vintx,blockHash) == 0 ) return(-1); - if ( tx.vin[0].prevout < vintx.vout.size() && Getscriptaddress(destaddr,vintx.vout[tx.vin[0].prevout].scriptPubKey) != 0 ) + if ( tx.vin[0].prevout.n < vintx.vout.size() && Getscriptaddress(destaddr,vintx.vout[tx.vin[0].prevout.n].scriptPubKey) != 0 ) { pubkey2addr(pkaddr,ASSETCHAINS_OVERRIDE_PUBKEY33); if ( strcmp(pkaddr,destaddr) == 0 ) @@ -80,7 +80,7 @@ int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProo proof = std::make_pair(txid,newBranch); return(0); } - fprintf(stderr,"vin0[%d] -> %s vs %s\n",tx.vin[0].prevout,destaddr,pkaddr); + fprintf(stderr,"vin0[%d] -> %s vs %s\n",tx.vin[0].prevout.n,destaddr,pkaddr); } return(-1); } @@ -118,7 +118,7 @@ int32_t CheckGATEWAYimport(std::string coin,TxProof proof,CTransaction burnTx,st int32_t CheckPUBKEYimport(TxProof proof,CTransaction burnTx,std::vector payouts) { // if burnTx has ASSETCHAINS_PUBKEY vin, it is valid return(0); - fprintf(stderr,"proof txid.%s\n",proof.first.GetHex().ToString().c_str()); + fprintf(stderr,"proof txid.%s\n",proof.first.GetHex().c_str()); return(0); return(-1); } From 1839b1d27f084a4906b57c5d4b6c3dc40b1e7ac8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Dec 2018 23:42:54 -1100 Subject: [PATCH 093/643] Fix --- src/cc/import.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index 2faf4fb07..38d054fcb 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -44,12 +44,10 @@ int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProo if ( ASSETCHAINS_SELFIMPORT == "BEAM" ) { // confirm via ASSETCHAINS_BEAMPORT that burnTx/hash is a valid BEAM burn - return(-1); } else if ( ASSETCHAINS_SELFIMPORT == "CODA" ) { // confirm via ASSETCHAINS_CODAPORT that burnTx/hash is a valid CODA burn - return(-1); } else { @@ -80,19 +78,16 @@ int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProo proof = std::make_pair(txid,newBranch); return(0); } - fprintf(stderr,"vin0[%d] -> %s vs %s\n",tx.vin[0].prevout.n,destaddr,pkaddr); + fprintf(stderr,"mismatched vin0[%d] -> %s vs %s\n",tx.vin[0].prevout.n,destaddr,pkaddr); } - return(-1); } else { // ASSETCHAINS_SELFIMPORT and external coin is the assetchains symbol in the burnTx OP_RETURN // burnAmount, rawtx and rawproof should be enough for gatewaysdeposit equivalent - return(-1); } } - else return(-1); - return(0); + return(-1); } // use proof from the above functions to validate the import From 4dbb9e832a447cc7ecd6774a356b13c0a7b533da Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Dec 2018 23:45:27 -1100 Subject: [PATCH 094/643] Extern --- src/cc/import.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index 38d054fcb..3162de1bd 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -31,11 +31,7 @@ extern std::string ASSETCHAINS_SELFIMPORT; extern uint16_t ASSETCHAINS_CODAPORT,ASSETCHAINS_BEAMPORT; -//int32_t komodo_nextheight(); -//bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock); -uint8_t ASSETCHAINS_OVERRIDE_PUBKEY33[33]; -//CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Params& consensusParams, int nHeight); -//bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); +extern uint8_t ASSETCHAINS_OVERRIDE_PUBKEY33[33]; int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 txid,std::vector rawproof) // find burnTx with hash from "other" daemon { From e0903308239eb7b0624a1f185b1a027dea1c42a7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 1 Jan 2019 23:34:31 -1100 Subject: [PATCH 095/643] remove mutually exclusive constraint on selfimport -ac_beam and -ac_coda cannot be active at the same time Clusters can do import coin normally even with self-import chains. -ac_import=KMD (any bitcoinprotocol coin) will make a side chain (not implemented yet) Theoretically -ac_beam or -ac_coda can work with side chain (not implemented yet other than chain params) --- src/cc/import.cpp | 58 ++++++++++++++++++++++++++---------------- src/crosschain.cpp | 6 ++--- src/importcoin.cpp | 40 ++++++++++++++++++++++------- src/importcoin.h | 2 +- src/komodo_utils.h | 23 +++++++++-------- src/rpc/crosschain.cpp | 21 +++++++++------ 6 files changed, 95 insertions(+), 55 deletions(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index 3162de1bd..807b12050 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -33,17 +33,23 @@ extern std::string ASSETCHAINS_SELFIMPORT; extern uint16_t ASSETCHAINS_CODAPORT,ASSETCHAINS_BEAMPORT; extern uint8_t ASSETCHAINS_OVERRIDE_PUBKEY33[33]; -int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 txid,std::vector rawproof) // find burnTx with hash from "other" daemon +int32_t GetSelfimportProof(std::string source,CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 txid,std::vector &rawproof) // find burnTx with hash from "other" daemon { MerkleBranch newBranch; CMutableTransaction tmpmtx; CTransaction tx,vintx; uint256 blockHash; char destaddr[64],pkaddr[64]; tmpmtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),komodo_nextheight()); - if ( ASSETCHAINS_SELFIMPORT == "BEAM" ) + if ( source == "BEAM" ) { + if ( ASSETCHAINS_BEAMPORT == 0 ) + return(-1); // confirm via ASSETCHAINS_BEAMPORT that burnTx/hash is a valid BEAM burn + // return(0); } - else if ( ASSETCHAINS_SELFIMPORT == "CODA" ) + else if ( source == "CODA" ) { + if ( ASSETCHAINS_CODAPORT == 0 ) + return(-1); // confirm via ASSETCHAINS_CODAPORT that burnTx/hash is a valid CODA burn + // return(0); } else { @@ -61,7 +67,7 @@ int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProo mtx.vout[0].scriptPubKey = scriptPubKey; if ( tx.GetHash() != txid ) return(-1); - if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) + if ( source == "PUBKEY" ) { // make sure vin0 is signed by ASSETCHAINS_OVERRIDE_PUBKEY33 if ( myGetTransaction(tx.vin[0].prevout.hash,vintx,blockHash) == 0 ) @@ -77,9 +83,9 @@ int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProo fprintf(stderr,"mismatched vin0[%d] -> %s vs %s\n",tx.vin[0].prevout.n,destaddr,pkaddr); } } - else + else if ( source == ASSETCHAINS_SELFIMPORT ) { - // ASSETCHAINS_SELFIMPORT and external coin is the assetchains symbol in the burnTx OP_RETURN + // source is external coin is the assetchains symbol in the burnTx OP_RETURN // burnAmount, rawtx and rawproof should be enough for gatewaysdeposit equivalent } } @@ -88,25 +94,26 @@ int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProo // use proof from the above functions to validate the import -int32_t CheckBEAMimport(TxProof proof,CTransaction burnTx,std::vector payouts) +int32_t CheckBEAMimport(TxProof proof,std::vector rawproof,CTransaction burnTx,std::vector payouts) { // check with dual-BEAM daemon via ASSETCHAINS_BEAMPORT for validity of burnTx return(-1); } -int32_t CheckCODAimport(TxProof proof,CTransaction burnTx,std::vector payouts) +int32_t CheckCODAimport(TxProof proof,std::vector rawproof,CTransaction burnTx,std::vector payouts) { // check with dual-CODA daemon via ASSETCHAINS_CODAPORT for validity of burnTx return(-1); } -int32_t CheckGATEWAYimport(std::string coin,TxProof proof,CTransaction burnTx,std::vector payouts) +int32_t CheckGATEWAYimport(TxProof proof,std::vector rawproof,CTransaction burnTx,std::vector payouts) { + // ASSETCHAINS_SELFIMPORT is coin // check for valid burn from external coin blockchain and if valid return(0); return(-1); } -int32_t CheckPUBKEYimport(TxProof proof,CTransaction burnTx,std::vector payouts) +int32_t CheckPUBKEYimport(TxProof proof,std::vector rawproof,CTransaction burnTx,std::vector payouts) { // if burnTx has ASSETCHAINS_PUBKEY vin, it is valid return(0); fprintf(stderr,"proof txid.%s\n",proof.first.GetHex().c_str()); @@ -117,19 +124,18 @@ int32_t CheckPUBKEYimport(TxProof proof,CTransaction burnTx,std::vector bool Eval::ImportCoin(const std::vector params,const CTransaction &importTx,unsigned int nIn) { TxProof proof; CTransaction burnTx; std::vector payouts; uint64_t txfee = 10000; - uint32_t targetCcid; std::string targetSymbol; uint256 payoutsHash; - if (importTx.vout.size() < 2) + uint32_t targetCcid; std::string targetSymbol; uint256 payoutsHash; std::vector rawproof; + if ( importTx.vout.size() < 2 ) return Invalid("too-few-vouts"); // params if (!UnmarshalImportTx(importTx, proof, burnTx, payouts)) return Invalid("invalid-params"); - // Control all aspects of this transaction // It should not be at all malleable if (MakeImportCoinTransaction(proof, burnTx, payouts).GetHash() != importTx.GetHash()) return Invalid("non-canonical"); // burn params - if (!UnmarshalBurnTx(burnTx, targetSymbol, &targetCcid, payoutsHash)) + if (!UnmarshalBurnTx(burnTx, targetSymbol, &targetCcid, payoutsHash,rawproof)) return Invalid("invalid-burn-tx"); // check burn amount { @@ -156,26 +162,34 @@ bool Eval::ImportCoin(const std::vector params,const CTransaction &impo if (!CheckMoMoM(proof.first, target)) return Invalid("momom-check-fail"); } - else if ( ASSETCHAINS_SELFIMPORT == targetSymbol ) // various selfchain imports + else { - if ( ASSETCHAINS_SELFIMPORT == "BEAM" ) + if ( targetSymbol == "BEAM" ) { - if ( CheckBEAMimport(proof,burnTx,payouts) < 0 ) + if ( ASSETCHAINS_BEAMPORT == 0 ) + return Invalid("BEAM-import-without-port"); + else if ( CheckBEAMimport(proof,rawproof,burnTx,payouts) < 0 ) return Invalid("BEAM-import-failure"); } - else if ( ASSETCHAINS_SELFIMPORT == "CODA" ) + else if ( targetSymbol == "CODA" ) { - if ( CheckCODAimport(proof,burnTx,payouts) < 0 ) + if ( ASSETCHAINS_CODAPORT == 0 ) + return Invalid("CODA-import-without-port"); + else if ( CheckCODAimport(proof,rawproof,burnTx,payouts) < 0 ) return Invalid("CODA-import-failure"); } - else if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) + else if ( targetSymbol == "PUBKEY" ) { - if ( CheckPUBKEYimport(proof,burnTx,payouts) < 0 ) + if ( ASSETCHAINS_SELFIMPORT != "PUBKEY" ) + return Invalid("PUBKEY-import-when-notPUBKEY"); + else if ( CheckPUBKEYimport(proof,rawproof,burnTx,payouts) < 0 ) return Invalid("PUBKEY-import-failure"); } else { - if ( CheckGATEWAYimport(targetSymbol,proof,burnTx,payouts) < 0 ) + if ( targetSymbol != ASSETCHAINS_SELFIMPORT ) + return Invalid("invalid-gateway-import-coin"); + else if ( CheckGATEWAYimport(proof,rawproof,burnTx,payouts) < 0 ) return Invalid("GATEWAY-import-failure"); } } diff --git a/src/crosschain.cpp b/src/crosschain.cpp index 447f907cc..8b6cb12a4 100644 --- a/src/crosschain.cpp +++ b/src/crosschain.cpp @@ -214,16 +214,14 @@ cont: */ void CompleteImportTransaction(CTransaction &importTx) { - TxProof proof; - CTransaction burnTx; - std::vector payouts; + TxProof proof; CTransaction burnTx; std::vector payouts; std::vector rawproof; if (!UnmarshalImportTx(importTx, proof, burnTx, payouts)) throw std::runtime_error("Couldn't parse importTx"); std::string targetSymbol; uint32_t targetCCid; uint256 payoutsHash; - if (!UnmarshalBurnTx(burnTx, targetSymbol, &targetCCid, payoutsHash)) + if (!UnmarshalBurnTx(burnTx, targetSymbol, &targetCCid, payoutsHash, rawproof)) throw std::runtime_error("Couldn't parse burnTx"); proof = GetCrossChainProof(burnTx.GetHash(), targetSymbol.data(), targetCCid, proof); diff --git a/src/importcoin.cpp b/src/importcoin.cpp index c72aea210..e479757dd 100644 --- a/src/importcoin.cpp +++ b/src/importcoin.cpp @@ -38,11 +38,22 @@ CTransaction MakeImportCoinTransaction(const TxProof proof, const CTransaction b } -CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, std::string targetSymbol, const std::vector payouts) +CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, std::string targetSymbol, const std::vector payouts,std::vector rawproof) { - std::vector opret = E_MARSHAL(ss << VARINT(targetCCid); - ss << targetSymbol; - ss << SerializeHash(payouts)); + std::vector opret; + if ( targetCCid != 0xffffffff ) + { + opret = E_MARSHAL(ss << VARINT(targetCCid); + ss << targetSymbol; + ss << SerializeHash(payouts)); + } + else + { + opret = E_MARSHAL(ss << VARINT(targetCCid); + ss << targetSymbol; + ss << SerializeHash(payouts); + ss << rawproof); + } return CTxOut(value, CScript() << OP_RETURN << opret); } @@ -60,14 +71,25 @@ bool UnmarshalImportTx(const CTransaction &importTx, TxProof &proof, CTransactio } -bool UnmarshalBurnTx(const CTransaction &burnTx, std::string &targetSymbol, uint32_t *targetCCid, uint256 &payoutsHash) +bool UnmarshalBurnTx(const CTransaction &burnTx, std::string &targetSymbol, uint32_t *targetCCid, uint256 &payoutsHash,std::vector&rawproof) { - std::vector burnOpret; + std::vector burnOpret; uint32_t ccid = 0; if (burnTx.vout.size() == 0) return false; GetOpReturnData(burnTx.vout.back().scriptPubKey, burnOpret); - return E_UNMARSHAL(burnOpret, ss >> VARINT(*targetCCid); - ss >> targetSymbol; - ss >> payoutsHash); + E_UNMARSHAL(burnOpret, ss >> VARINT(ccid)); + if ( ccid != 0xffffffff ) + { + return E_UNMARSHAL(burnOpret, ss >> VARINT(*targetCCid); + ss >> targetSymbol; + ss >> payoutsHash); + } + else + { + return E_UNMARSHAL(burnOpret, ss >> VARINT(*targetCCid); + ss >> targetSymbol; + ss >> payoutsHash; + ss >> rawproof); + } } diff --git a/src/importcoin.h b/src/importcoin.h index 53611cac9..3053eaf72 100644 --- a/src/importcoin.h +++ b/src/importcoin.h @@ -30,7 +30,7 @@ CTransaction MakeImportCoinTransaction(const TxProof proof, CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, std::string targetSymbol, const std::vector payouts); -bool UnmarshalBurnTx(const CTransaction &burnTx, std::string &targetSymbol, uint32_t *targetCCid, uint256 &payoutsHash); +bool UnmarshalBurnTx(const CTransaction &burnTx, std::string &targetSymbol, uint32_t *targetCCid, uint256 &payoutsHash,std::vector &rawproof); bool UnmarshalImportTx(const CTransaction &importTx, TxProof &proof, CTransaction &burnTx, std::vector &payouts); diff --git a/src/komodo_utils.h b/src/komodo_utils.h index a8823e5b3..2437b0bf6 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1775,36 +1775,33 @@ void komodo_args(char *argv0) ASSETCHAINS_SCRIPTPUB = GetArg("-ac_script",""); ASSETCHAINS_BEAMPORT = GetArg("-ac_beam",0); ASSETCHAINS_CODAPORT = GetArg("-ac_coda",0); - + if ( ASSETCHAINS_BEAMPORT != 0 && ASSETCHAINS_CODAPORT != 0 ) + { + fprintf(stderr,"can only have one of -ac_beam or -ac_coda\n"); + exit(0); + } ASSETCHAINS_SELFIMPORT = GetArg("-ac_import",""); // BEAM, CODA, PUBKEY, GATEWAY if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) { if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) != 66 ) { fprintf(stderr,"invalid -ac_pubkey for -ac_import=PUBKEY\n"); - ASSETCHAINS_SELFIMPORT = ""; exit(0); } } else if ( ASSETCHAINS_SELFIMPORT == "BEAM" && ASSETCHAINS_BEAMPORT == 0 ) { fprintf(stderr,"missing -ac_beam for BEAM rpcport\n"); - ASSETCHAINS_SELFIMPORT = ""; exit(0); } else if ( ASSETCHAINS_SELFIMPORT == "CODA" && ASSETCHAINS_CODAPORT == 0 ) { fprintf(stderr,"missing -ac_coda for CODA rpcport\n"); - ASSETCHAINS_SELFIMPORT = ""; exit(0); } - if ( ASSETCHAINS_SELFIMPORT.size() > 0 && ASSETCHAINS_CC >= KOMODO_FIRSTFUNGIBLEID ) - { - fprintf(stderr,"selfimport chains cant be in a fungible cluster\n"); - exit(0); - } - //ASSETCHAINS_FOUNDERS_PERIOD = GetArg("-ac_period",0); + // else it can be gateway coin + if ( (ASSETCHAINS_STAKED= GetArg("-ac_staked",0)) > 100 ) ASSETCHAINS_STAKED = 100; @@ -1857,7 +1854,7 @@ void komodo_args(char *argv0) printf("ASSETCHAINS_FOUNDERS needs an ASETCHAINS_OVERRIDE_PUBKEY\n"); } } - if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 ) + if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 ) { fprintf(stderr,"perc %.4f%% ac_pub=[%02x%02x%02x...] acsize.%d\n",dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0],ASSETCHAINS_OVERRIDE_PUBKEY33[1],ASSETCHAINS_OVERRIDE_PUBKEY33[2],(int32_t)ASSETCHAINS_SCRIPTPUB.size()); extraptr = extrabuf; @@ -1927,6 +1924,10 @@ void komodo_args(char *argv0) fprintf(stderr," selfimport\n"); extralen += ASSETCHAINS_SELFIMPORT.size(); } + if ( ASSETCHAINS_BEAMPORT != 0 ) + extraptr[extralen++] = 'b'; + if ( ASSETCHAINS_CODAPORT != 0 ) + extraptr[extralen++] = 'c'; } addn = GetArg("-seednode",""); diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 5f40f60fb..0c4703725 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -47,7 +47,7 @@ struct komodo_ccdata_entry *komodo_allMoMs(int32_t *nump,uint256 *MoMoMp,int32_t uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth); extern std::string ASSETCHAINS_SELFIMPORT; uint256 Parseuint256(char *hexstr); -int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 txid,std::vector rawproof); +int32_t GetSelfimportProof(std::string source,CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 txid,std::vector rawproof); UniValue assetchainproof(const UniValue& params, bool fHelp) @@ -199,8 +199,8 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp) if (burnAmount < needed) throw runtime_error("export_amount too small"); } - if ( ASSETCHAINS_SELFIMPORT.size() > 0 ) - throw runtime_error("self-import chains cant be fungible"); + //if ( ASSETCHAINS_SELFIMPORT.size() > 0 ) + // throw runtime_error("self-import chains cant be fungible"); CTxOut burnOut = MakeBurnOutput(burnAmount, ccid, targetSymbol, tx.vout); UniValue ret(UniValue::VOBJ); ret.push_back(Pair("payouts", HexStr(E_MARSHAL(ss << tx.vout)))); @@ -278,18 +278,23 @@ UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp) UniValue selfimport(const UniValue& params, bool fHelp) { CMutableTransaction mtx; - TxProof proof; CTransaction burnTx,tx; CTxOut burnOut; uint64_t burnAmount; uint256 txid,blockHash; std::vector vouts; std::vector rawtx,rawproof; CScript scriptPubKey; + std::string source; TxProof proof; CTransaction burnTx,tx; CTxOut burnOut; uint64_t burnAmount; uint256 txid,blockHash; std::vector vouts; std::vector rawtx,rawproof; CScript scriptPubKey; if ( ASSETCHAINS_SELFIMPORT.size() == 0 ) throw runtime_error("selfimport only works on -ac_import chains"); - if (fHelp || params.size() < 3 || params.size() > 4) - throw runtime_error("selfimport rawtx txid burnamount\n\n" + if (fHelp || params.size() < 3 || params.size() > 5 ) + throw runtime_error("selfimport rawtx txid burnamount [rawproof source]\n\n" "creates signed selfimport transaction from txid"); rawtx = ParseHex(params[0].get_str().c_str()); txid = Parseuint256((char *)params[1].get_str().c_str()); // allow for txid != hash(rawtx) burnAmount = atof(params[2].get_str().c_str()) * COIN + 0.00000000499999; - if ( params.size() == 4 ) + source = ASSETCHAINS_SELFIMPORT; + if ( params.size() >= 4 ) + { rawproof = ParseHex(params[3].get_str().c_str()); - if ( GetSelfimportProof(mtx,scriptPubKey,proof,burnAmount,rawtx,txid,rawproof) < 0 ) + if ( params.size() == 5 ) + source = params[4].get_str(); + } + if ( GetSelfimportProof(source,mtx,scriptPubKey,proof,burnAmount,rawtx,txid,rawproof) < 0 ) throw std::runtime_error("Failed validating selfimport"); vouts = mtx.vout; burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,vouts); From a5c38d8f9c37dfd87cbf5749bd0de8c9920d19f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 1 Jan 2019 23:37:43 -1100 Subject: [PATCH 096/643] Fix --- src/importcoin.h | 2 +- src/rpc/crosschain.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/importcoin.h b/src/importcoin.h index 3053eaf72..64019ac8f 100644 --- a/src/importcoin.h +++ b/src/importcoin.h @@ -28,7 +28,7 @@ CAmount GetCoinImportValue(const CTransaction &tx); CTransaction MakeImportCoinTransaction(const TxProof proof, const CTransaction burnTx, const std::vector payouts); -CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, std::string targetSymbol, const std::vector payouts); +CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, std::string targetSymbol, const std::vector payouts,std::vector rawproof); bool UnmarshalBurnTx(const CTransaction &burnTx, std::string &targetSymbol, uint32_t *targetCCid, uint256 &payoutsHash,std::vector &rawproof); bool UnmarshalImportTx(const CTransaction &importTx, TxProof &proof, CTransaction &burnTx, diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 0c4703725..d136074d0 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -163,7 +163,7 @@ UniValue calc_MoM(const UniValue& params, bool fHelp) UniValue migrate_converttoexport(const UniValue& params, bool fHelp) { - uint32_t ccid = ASSETCHAINS_CC; + std::vector rawproof; uint32_t ccid = ASSETCHAINS_CC; if (fHelp || params.size() != 3) throw runtime_error( "migrate_converttoexport rawTx dest_symbol export_amount\n" @@ -201,7 +201,7 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp) } //if ( ASSETCHAINS_SELFIMPORT.size() > 0 ) // throw runtime_error("self-import chains cant be fungible"); - CTxOut burnOut = MakeBurnOutput(burnAmount, ccid, targetSymbol, tx.vout); + CTxOut burnOut = MakeBurnOutput(burnAmount, ccid, targetSymbol, tx.vout,rawproof); UniValue ret(UniValue::VOBJ); ret.push_back(Pair("payouts", HexStr(E_MARSHAL(ss << tx.vout)))); tx.vout.clear(); @@ -297,7 +297,7 @@ UniValue selfimport(const UniValue& params, bool fHelp) if ( GetSelfimportProof(source,mtx,scriptPubKey,proof,burnAmount,rawtx,txid,rawproof) < 0 ) throw std::runtime_error("Failed validating selfimport"); vouts = mtx.vout; - burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,vouts); + burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,vouts,rawproof); mtx.vout.clear(); mtx.vout.push_back(burnOut); burnTx = mtx; From 0b4120eefa60aa95a2d3601f3a30c494dd70c571 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 1 Jan 2019 23:40:20 -1100 Subject: [PATCH 097/643] Fix --- src/cc/import.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index 807b12050..107a11e0a 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -33,7 +33,7 @@ extern std::string ASSETCHAINS_SELFIMPORT; extern uint16_t ASSETCHAINS_CODAPORT,ASSETCHAINS_BEAMPORT; extern uint8_t ASSETCHAINS_OVERRIDE_PUBKEY33[33]; -int32_t GetSelfimportProof(std::string source,CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 txid,std::vector &rawproof) // find burnTx with hash from "other" daemon +int32_t GetSelfimportProof(std::string source,CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 txid,std::vector rawproof) // find burnTx with hash from "other" daemon { MerkleBranch newBranch; CMutableTransaction tmpmtx; CTransaction tx,vintx; uint256 blockHash; char destaddr[64],pkaddr[64]; tmpmtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),komodo_nextheight()); From 81e3a485e2c3377e77a801b4a02d514635283eeb Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 1 Jan 2019 23:42:45 -1100 Subject: [PATCH 098/643] Fix test --- src/test-komodo/test_coinimport.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test-komodo/test_coinimport.cpp b/src/test-komodo/test_coinimport.cpp index 8c1d8b0f8..fda62c30c 100644 --- a/src/test-komodo/test_coinimport.cpp +++ b/src/test-komodo/test_coinimport.cpp @@ -26,7 +26,7 @@ static uint8_t testNum = 0; class TestCoinImport : public ::testing::Test, public Eval { public: - CMutableTransaction burnTx; + CMutableTransaction burnTx; std::vector rawproof; std::vector payouts; TxProof proof; uint256 MoMoM; @@ -37,7 +37,7 @@ public: void SetImportTx() { burnTx.vout.resize(0); - burnTx.vout.push_back(MakeBurnOutput(amount, testCcid, testSymbol, payouts)); + burnTx.vout.push_back(MakeBurnOutput(amount, testCcid, testSymbol, payouts,rawproof)); importTx = CMutableTransaction(MakeImportCoinTransaction(proof, CTransaction(burnTx), payouts)); MoMoM = burnTx.GetHash(); // TODO: an actual branch } From d63390197d524653555ef5cf3a01792f63a6010f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 1 Jan 2019 23:53:39 -1100 Subject: [PATCH 099/643] Fix comment --- src/rpc/crosschain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index d136074d0..318acb666 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -283,7 +283,7 @@ UniValue selfimport(const UniValue& params, bool fHelp) throw runtime_error("selfimport only works on -ac_import chains"); if (fHelp || params.size() < 3 || params.size() > 5 ) throw runtime_error("selfimport rawtx txid burnamount [rawproof source]\n\n" - "creates signed selfimport transaction from txid"); + "creates signed selfimport transaction"); rawtx = ParseHex(params[0].get_str().c_str()); txid = Parseuint256((char *)params[1].get_str().c_str()); // allow for txid != hash(rawtx) burnAmount = atof(params[2].get_str().c_str()) * COIN + 0.00000000499999; From bf3cef4edcf5c27886d0589c73f02f9fb28920a2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 2 Jan 2019 02:13:24 -1100 Subject: [PATCH 100/643] Set raw proof to ac_name for cross chain burn --- src/rpc/crosschain.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 318acb666..ace11d6a8 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -201,6 +201,7 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp) } //if ( ASSETCHAINS_SELFIMPORT.size() > 0 ) // throw runtime_error("self-import chains cant be fungible"); + rawproof = GetArg("-ac_name",""); CTxOut burnOut = MakeBurnOutput(burnAmount, ccid, targetSymbol, tx.vout,rawproof); UniValue ret(UniValue::VOBJ); ret.push_back(Pair("payouts", HexStr(E_MARSHAL(ss << tx.vout)))); From c4f5be1c6dbf19c1217ec38522a4aed494b03f82 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 2 Jan 2019 02:16:15 -1100 Subject: [PATCH 101/643] Acname -> raw proof --- src/rpc/crosschain.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index ace11d6a8..55d16288f 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -163,7 +163,7 @@ UniValue calc_MoM(const UniValue& params, bool fHelp) UniValue migrate_converttoexport(const UniValue& params, bool fHelp) { - std::vector rawproof; uint32_t ccid = ASSETCHAINS_CC; + std::vector rawproof; uint8_t *ptr; int32_t i; uint32_t ccid = ASSETCHAINS_CC; if (fHelp || params.size() != 3) throw runtime_error( "migrate_converttoexport rawTx dest_symbol export_amount\n" @@ -201,7 +201,10 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp) } //if ( ASSETCHAINS_SELFIMPORT.size() > 0 ) // throw runtime_error("self-import chains cant be fungible"); - rawproof = GetArg("-ac_name",""); + rawproof.resize(strlen(ASSETCHAINS_SYMBOL)); + ptr = rawproof.data(); + for (i=0; i Date: Wed, 2 Jan 2019 02:16:52 -1100 Subject: [PATCH 102/643] ASSETCHAINS_SYMBOL --- src/rpc/crosschain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 55d16288f..a0a3b507f 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -204,7 +204,7 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp) rawproof.resize(strlen(ASSETCHAINS_SYMBOL)); ptr = rawproof.data(); for (i=0; i Date: Wed, 2 Jan 2019 04:02:49 -1100 Subject: [PATCH 103/643] Fix oracles 'd' and 'D' --- src/cc/import.cpp | 2 +- src/cc/oracles.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index 107a11e0a..ea69745b0 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -146,7 +146,7 @@ bool Eval::ImportCoin(const std::vector params,const CTransaction &impo for (int i=0; i burnAmount || totalOut < burnAmount-txfee ) - return Invalid("payout-too-high"); + return Invalid("payout-too-high-or-too-low"); } // Check burntx shows correct outputs hash if (payoutsHash != SerializeHash(payouts)) diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index f09dd0957..a2ce02fe6 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -370,7 +370,7 @@ int32_t oracle_format(uint256 *hashp,int64_t *valp,char *str,uint8_t fmt,uint8_t { for (i=0; i Date: Wed, 2 Jan 2019 15:26:24 +0100 Subject: [PATCH 104/643] Removed unused tx_notarizedconfirmed in oraclefeed. --- src/cc/dapps/oraclefeed.c | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 33e6908fb..8a819a147 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -822,22 +822,6 @@ int32_t get_gatewaysinfo(char *refcoin,char *acname,char *depositaddr,int32_t *M else return(0); } -int32_t tx_notarizedconfirmed(char *refcoin,char *acname,bits256 txid) -{ - char *retstr,str[65]; cJSON *retjson; int32_t result; - if ( (retjson= get_komodocli(refcoin,&retstr,acname,"txnotarizedconfirmed",bits256_str(str,txid),"","","")) != 0 ) - { - if (is_cJSON_True(jobj(retjson,"result")) != 0 ) result=1; - else result=0; - free_json(retjson); - } - else if ( retstr != 0 ) - { - printf("error parsing txnotarizedconfirmed.(%s)\n",retstr); - free(retstr); - } -} - int32_t tx_has_voutaddress(char *refcoin,char *acname,bits256 txid,char *coinaddr) { cJSON *txobj,*vouts,*vout,*vins,*vin,*sobj,*addresses; char *addr,str[65]; int32_t i,j,n,numarray,retval = 0, hasvout=0; From 5298e3c99a8dcdbb160ea8fa6c2ef5479342bc16 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 2 Jan 2019 04:52:22 -1100 Subject: [PATCH 105/643] Always makeburnoutput raw proof --- src/importcoin.cpp | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/importcoin.cpp b/src/importcoin.cpp index e479757dd..010fbeb7d 100644 --- a/src/importcoin.cpp +++ b/src/importcoin.cpp @@ -41,19 +41,10 @@ CTransaction MakeImportCoinTransaction(const TxProof proof, const CTransaction b CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, std::string targetSymbol, const std::vector payouts,std::vector rawproof) { std::vector opret; - if ( targetCCid != 0xffffffff ) - { - opret = E_MARSHAL(ss << VARINT(targetCCid); - ss << targetSymbol; - ss << SerializeHash(payouts)); - } - else - { - opret = E_MARSHAL(ss << VARINT(targetCCid); - ss << targetSymbol; - ss << SerializeHash(payouts); - ss << rawproof); - } + opret = E_MARSHAL(ss << VARINT(targetCCid); + ss << targetSymbol; + ss << SerializeHash(payouts); + ss << rawproof); return CTxOut(value, CScript() << OP_RETURN << opret); } From 79c1797de38f9f17e7548170ddc6864483c94737 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Wed, 2 Jan 2019 20:51:42 +0100 Subject: [PATCH 106/643] Returned print of CC address in getrawtransaction and similar functions. --- src/script/standard.cpp | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/script/standard.cpp b/src/script/standard.cpp index be78aaf76..2b81abdc8 100644 --- a/src/script/standard.cpp +++ b/src/script/standard.cpp @@ -468,26 +468,27 @@ bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, vecto if (addressRet.empty()) return false; } - else if (IsCryptoConditionsEnabled() != 0 && typeRet == TX_CRYPTOCONDITION) - { - nRequiredRet = vSolutions.front()[0]; - for (unsigned int i = 1; i < vSolutions.size()-1; i++) - { - CTxDestination address; - if (vSolutions[i].size() == 20) - { - address = CKeyID(uint160(vSolutions[i])); - } - else - { - address = CPubKey(vSolutions[i]); - } - addressRet.push_back(address); - } + // Removed to get CC address printed in getrawtransaction and decoderawtransaction + // else if (IsCryptoConditionsEnabled() != 0 && typeRet == TX_CRYPTOCONDITION) + // { + // nRequiredRet = vSolutions.front()[0]; + // for (unsigned int i = 1; i < vSolutions.size()-1; i++) + // { + // CTxDestination address; + // if (vSolutions[i].size() == 20) + // { + // address = CKeyID(uint160(vSolutions[i])); + // } + // else + // { + // address = CPubKey(vSolutions[i]); + // } + // addressRet.push_back(address); + // } - if (addressRet.empty()) - return false; - } + // if (addressRet.empty()) + // return false; + // } else { nRequiredRet = 1; From 31e466f6c7e37b903e640d039e2328ba045d2381 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 2 Jan 2019 19:10:10 -1100 Subject: [PATCH 107/643] Triggers -> Marmara stubs --- src/cc/CCcustom.cpp | 30 ++++++------- src/cc/eval.h | 2 +- src/cc/{triggers.cpp => marmara.cpp} | 66 ++++++++++++++-------------- src/importcoin.cpp | 4 +- src/rpc/server.cpp | 4 +- src/rpc/server.h | 2 +- src/wallet/rpcwallet.cpp | 8 ++-- 7 files changed, 58 insertions(+), 58 deletions(-) rename src/cc/{triggers.cpp => marmara.cpp} (73%) diff --git a/src/cc/CCcustom.cpp b/src/cc/CCcustom.cpp index 3e42109fc..7fdd1b920 100644 --- a/src/cc/CCcustom.cpp +++ b/src/cc/CCcustom.cpp @@ -27,7 +27,7 @@ #include "CCOracles.h" #include "CCPrices.h" #include "CCPegs.h" -#include "CCTriggers.h" +#include "CCMarmara.h" #include "CCPayments.h" #include "CCGateways.h" @@ -189,13 +189,13 @@ uint8_t PegsCCpriv[32] = { 0x52, 0x56, 0x4c, 0x78, 0x87, 0xf7, 0xa2, 0x39, 0xb0, #undef FUNCNAME #undef EVALCODE -// Triggers -#define FUNCNAME IsTriggersInput -#define EVALCODE EVAL_TRIGGERS -const char *TriggersCCaddr = "RGLSRDnUqTB43bYtRtNVgmwSSd1sun2te8"; -const char *TriggersNormaladdr = "RMN25Tn8NNzcyQDiQNuMp8UmwLMFd9thYc"; -char TriggersCChexstr[67] = { "03afc5be570d0ff419425cfcc580cc762ab82baad88c148f5b028d7db7bfeee61d" }; -uint8_t TriggersCCpriv[32] = { 0x7c, 0x0b, 0x54, 0x9b, 0x65, 0xd4, 0x89, 0x57, 0xdf, 0x05, 0xfe, 0xa2, 0x62, 0x41, 0xa9, 0x09, 0x0f, 0x2a, 0x6b, 0x11, 0x2c, 0xbe, 0xbd, 0x06, 0x31, 0x8d, 0xc0, 0xb9, 0x96, 0x76, 0x3f, 0x24 }; +// Marmara +#define FUNCNAME IsMarmaraInput +#define EVALCODE EVAL_MARMARA +const char *MarmaraCCaddr = "RGLSRDnUqTB43bYtRtNVgmwSSd1sun2te8"; +const char *MarmaraNormaladdr = "RMN25Tn8NNzcyQDiQNuMp8UmwLMFd9thYc"; +char MarmaraCChexstr[67] = { "03afc5be570d0ff419425cfcc580cc762ab82baad88c148f5b028d7db7bfeee61d" }; +uint8_t MarmaraCCpriv[32] = { 0x7c, 0x0b, 0x54, 0x9b, 0x65, 0xd4, 0x89, 0x57, 0xdf, 0x05, 0xfe, 0xa2, 0x62, 0x41, 0xa9, 0x09, 0x0f, 0x2a, 0x6b, 0x11, 0x2c, 0xbe, 0xbd, 0x06, 0x31, 0x8d, 0xc0, 0xb9, 0x96, 0x76, 0x3f, 0x24 }; #include "CCcustom.inc" #undef FUNCNAME #undef EVALCODE @@ -323,13 +323,13 @@ struct CCcontract_info *CCinit(struct CCcontract_info *cp, uint8_t evalcode) cp->validate = PegsValidate; cp->ismyvin = IsPegsInput; break; - case EVAL_TRIGGERS: - strcpy(cp->unspendableCCaddr,TriggersCCaddr); - strcpy(cp->normaladdr,TriggersNormaladdr); - strcpy(cp->CChexstr,TriggersCChexstr); - memcpy(cp->CCpriv,TriggersCCpriv,32); - cp->validate = TriggersValidate; - cp->ismyvin = IsTriggersInput; + case EVAL_MARMARA: + strcpy(cp->unspendableCCaddr,MarmaraCCaddr); + strcpy(cp->normaladdr,MarmaraNormaladdr); + strcpy(cp->CChexstr,MarmaraCChexstr); + memcpy(cp->CCpriv,MarmaraCCpriv,32); + cp->validate = MarmaraValidate; + cp->ismyvin = IsMarmaraInput; break; case EVAL_PAYMENTS: strcpy(cp->unspendableCCaddr,PaymentsCCaddr); diff --git a/src/cc/eval.h b/src/cc/eval.h index 9c6a050b7..87b98349b 100644 --- a/src/cc/eval.h +++ b/src/cc/eval.h @@ -53,7 +53,7 @@ EVAL(EVAL_ORACLES, 0xec) \ EVAL(EVAL_PRICES, 0xed) \ EVAL(EVAL_PEGS, 0xee) \ - EVAL(EVAL_TRIGGERS, 0xef) \ + EVAL(EVAL_MARMARA, 0xef) \ EVAL(EVAL_PAYMENTS, 0xf0) \ EVAL(EVAL_GATEWAYS, 0xf1) diff --git a/src/cc/triggers.cpp b/src/cc/marmara.cpp similarity index 73% rename from src/cc/triggers.cpp rename to src/cc/marmara.cpp index a98e4da02..4bbccee4a 100644 --- a/src/cc/triggers.cpp +++ b/src/cc/marmara.cpp @@ -13,16 +13,16 @@ * * ******************************************************************************/ -#include "CCTriggers.h" +#include "CCMarmara.h" /* - Triggers CC is a building block CC that allows creation of event -> action processing, where events are defined during trigger creation and actions to be mostly done via payments, but by making payments to other CC contracts, it can be used to invoke other CC contracts + Marmara CC is for the MARMARA project */ // start of consensus code -int64_t IsTriggersvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsMarmaravout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -33,7 +33,7 @@ int64_t IsTriggersvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t return(0); } -bool TriggersExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool MarmaraExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -51,8 +51,8 @@ bool TriggersExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransacti { //fprintf(stderr,"vini.%d check hash and vout\n",i); if ( hashBlock == zerohash ) - return eval->Invalid("cant Triggers from mempool"); - if ( (assetoshis= IsTriggersvout(cp,vinTx,tx.vin[i].prevout.n)) != 0 ) + return eval->Invalid("cant Marmara from mempool"); + if ( (assetoshis= IsMarmaravout(cp,vinTx,tx.vin[i].prevout.n)) != 0 ) inputs += assetoshis; } } @@ -60,7 +60,7 @@ bool TriggersExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransacti for (i=0; i origpubkey; CTransaction vintx; int32_t vout,n = 0; @@ -126,7 +126,7 @@ int64_t AddTriggersInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP // no need to prevent dup if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - if ( (nValue= IsTriggersvout(cp,vintx,vout)) > 1000000 && myIsutxo_spentinmempool(txid,vout) == 0 ) + if ( (nValue= IsMarmaravout(cp,vintx,vout)) > 1000000 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( total != 0 && maxinputs != 0 ) mtx.vin.push_back(CTxIn(txid,vout,CScript())); @@ -141,28 +141,28 @@ int64_t AddTriggersInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP return(totalinputs); } -std::string TriggersGet(uint64_t txfee,int64_t nValue) +std::string MarmaraGet(uint64_t txfee,int64_t nValue) { CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Triggerspk; int64_t inputs,CCchange=0; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; - cp = CCinit(&C,EVAL_TRIGGERS); + CPubKey mypk,Marmarapk; int64_t inputs,CCchange=0; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; + cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; - Triggerspk = GetUnspendable(cp,0); + Marmarapk = GetUnspendable(cp,0); mypk = pubkey2pk(Mypubkey()); - if ( (inputs= AddTriggersInputs(cp,mtx,Triggerspk,nValue+txfee,60)) > 0 ) + if ( (inputs= AddMarmaraInputs(cp,mtx,Marmarapk,nValue+txfee,60)) > 0 ) { if ( inputs > nValue ) CCchange = (inputs - nValue - txfee); if ( CCchange != 0 ) - mtx.vout.push_back(MakeCC1vout(EVAL_TRIGGERS,CCchange,Triggerspk)); + mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,CCchange,Marmarapk)); mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); fprintf(stderr,"start at %u\n",(uint32_t)time(NULL)); j = rand() & 0xfffffff; for (i=0; i<1000000; i++,j++) { tmpmtx = mtx; - rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_TRIGGERS << (uint8_t)'G' << j)); + rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_MARMARA << (uint8_t)'G' << j)); if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 ) { len >>= 1; @@ -178,37 +178,37 @@ std::string TriggersGet(uint64_t txfee,int64_t nValue) } fprintf(stderr,"couldnt generate valid txid %u\n",(uint32_t)time(NULL)); return(""); - } else fprintf(stderr,"cant find Triggers inputs\n"); + } else fprintf(stderr,"cant find Marmara inputs\n"); return(""); } -std::string TriggersFund(uint64_t txfee,int64_t funds) +std::string MarmaraFund(uint64_t txfee,int64_t funds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Triggerspk; CScript opret; struct CCcontract_info *cp,C; - cp = CCinit(&C,EVAL_TRIGGERS); + CPubKey mypk,Marmarapk; CScript opret; struct CCcontract_info *cp,C; + cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); - Triggerspk = GetUnspendable(cp,0); + Marmarapk = GetUnspendable(cp,0); if ( AddNormalinputs(mtx,mypk,funds+txfee,64) > 0 ) { - mtx.vout.push_back(MakeCC1vout(EVAL_TRIGGERS,funds,Triggerspk)); + mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,funds,Marmarapk)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); } return(""); } -UniValue TriggersInfo() +UniValue MarmaraInfo() { UniValue result(UniValue::VOBJ); char numstr[64]; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey Triggerspk; struct CCcontract_info *cp,C; int64_t funding; + CPubKey Marmarapk; struct CCcontract_info *cp,C; int64_t funding; result.push_back(Pair("result","success")); - result.push_back(Pair("name","Triggers")); - cp = CCinit(&C,EVAL_TRIGGERS); - Triggerspk = GetUnspendable(cp,0); - funding = AddTriggersInputs(cp,mtx,Triggerspk,0,0); + result.push_back(Pair("name","Marmara")); + cp = CCinit(&C,EVAL_MARMARA); + Marmarapk = GetUnspendable(cp,0); + funding = AddMarmaraInputs(cp,mtx,Marmarapk,0,0); sprintf(numstr,"%.8f",(double)funding/COIN); result.push_back(Pair("funding",numstr)); return(result); diff --git a/src/importcoin.cpp b/src/importcoin.cpp index 010fbeb7d..39ff01d68 100644 --- a/src/importcoin.cpp +++ b/src/importcoin.cpp @@ -68,13 +68,13 @@ bool UnmarshalBurnTx(const CTransaction &burnTx, std::string &targetSymbol, uint if (burnTx.vout.size() == 0) return false; GetOpReturnData(burnTx.vout.back().scriptPubKey, burnOpret); E_UNMARSHAL(burnOpret, ss >> VARINT(ccid)); - if ( ccid != 0xffffffff ) + /*if ( ccid != 0xffffffff ) { return E_UNMARSHAL(burnOpret, ss >> VARINT(*targetCCid); ss >> targetSymbol; ss >> payoutsHash); } - else + else*/ { return E_UNMARSHAL(burnOpret, ss >> VARINT(*targetCCid); ss >> targetSymbol; diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index acd8c4bb8..2a3e9afcf 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -441,8 +441,8 @@ static const CRPCCommand vRPCCommands[] = // Pegs { "pegs", "pegsaddress", &pegsaddress, true }, - // Triggers - { "triggers", "triggersaddress", &triggersaddress, true }, + // Marmara + { "marmara", "Marmaraaddress", &Marmaraaddress, true }, // Payments { "payments", "paymentsaddress", &paymentsaddress, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index f5b28538c..3614f0232 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -271,7 +271,7 @@ extern UniValue pricesbet(const UniValue& params, bool fHelp); extern UniValue pricesstatus(const UniValue& params, bool fHelp); extern UniValue pricesfinish(const UniValue& params, bool fHelp); extern UniValue pegsaddress(const UniValue& params, bool fHelp); -extern UniValue triggersaddress(const UniValue& params, bool fHelp); +extern UniValue marmaraaddress(const UniValue& params, bool fHelp); extern UniValue paymentsaddress(const UniValue& params, bool fHelp); extern UniValue gatewaysaddress(const UniValue& params, bool fHelp); extern UniValue gatewayslist(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c3faff238..1e7ee5462 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5291,17 +5291,17 @@ UniValue pegsaddress(const UniValue& params, bool fHelp) return(CCaddress(cp,(char *)"Pegs",pubkey)); } -UniValue triggersaddress(const UniValue& params, bool fHelp) +UniValue marmaraaddress(const UniValue& params, bool fHelp) { struct CCcontract_info *cp,C; std::vector pubkey; - cp = CCinit(&C,EVAL_TRIGGERS); + cp = CCinit(&C,EVAL_MARMARA); if ( fHelp || params.size() > 1 ) - throw runtime_error("triggersaddress [pubkey]\n"); + throw runtime_error("Marmaraaddress [pubkey]\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); if ( params.size() == 1 ) pubkey = ParseHex(params[0].get_str().c_str()); - return(CCaddress(cp,(char *)"Triggers",pubkey)); + return(CCaddress(cp,(char *)"Marmara",pubkey)); } UniValue paymentsaddress(const UniValue& params, bool fHelp) From 520964ae40a535472aeb7cf9258850e98baa639c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 2 Jan 2019 19:11:26 -1100 Subject: [PATCH 108/643] marmara.cpp --- src/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index 874c3a8b4..e6cc5d756 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -300,7 +300,7 @@ libbitcoin_server_a_SOURCES = \ cc/oracles.cpp \ cc/prices.cpp \ cc/pegs.cpp \ - cc/triggers.cpp \ + cc/marmara.cpp \ cc/payments.cpp \ cc/gateways.cpp \ cc/channels.cpp \ From 6392d7f9a05865b0b6fb8745c113e67e6f9fb305 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 2 Jan 2019 19:13:02 -1100 Subject: [PATCH 109/643] Marmara files --- src/cc/{CCTriggers.h => CCMarmara.h} | 4 ++-- src/wallet/rpcwallet.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) rename src/cc/{CCTriggers.h => CCMarmara.h} (90%) diff --git a/src/cc/CCTriggers.h b/src/cc/CCMarmara.h similarity index 90% rename from src/cc/CCTriggers.h rename to src/cc/CCMarmara.h index a75806dce..45fda83bd 100644 --- a/src/cc/CCTriggers.h +++ b/src/cc/CCMarmara.h @@ -19,9 +19,9 @@ #include "CCinclude.h" -bool TriggersValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom -UniValue TriggersInfo(); +UniValue MarmaraInfo(); #endif diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1e7ee5462..45cc99b0f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5111,6 +5111,7 @@ int32_t ensure_CCrequirements() #include "../cc/CCGateways.h" #include "../cc/CCPrices.h" #include "../cc/CCHeir.h" +#include "../cc/CCMarmara.h" UniValue CCaddress(struct CCcontract_info *cp,char *name,std::vector &pubkey) { From 6a1259ba5b2a8a73e8d46a916c7dcec7ee1124ef Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 2 Jan 2019 19:17:55 -1100 Subject: [PATCH 110/643] marmaraaddress --- src/rpc/server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 2a3e9afcf..61b83fbd7 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -442,7 +442,7 @@ static const CRPCCommand vRPCCommands[] = { "pegs", "pegsaddress", &pegsaddress, true }, // Marmara - { "marmara", "Marmaraaddress", &Marmaraaddress, true }, + { "marmara", "Marmaraaddress", &marmaraaddress, true }, // Payments { "payments", "paymentsaddress", &paymentsaddress, true }, From 1db43ae672bd7dad20771c071effdfc7c0af4bf0 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Thu, 3 Jan 2019 11:55:48 +0100 Subject: [PATCH 111/643] Oracles data and format check (#8) - Sanity check of oracle data - Fix oracle format check --- src/cc/oracles.cpp | 101 ++++++++++++++++++++++++++++++++++++--- src/wallet/rpcwallet.cpp | 20 -------- 2 files changed, 94 insertions(+), 27 deletions(-) diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 8bcdf3860..66c0e1b9a 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -416,6 +416,42 @@ int32_t oracle_format(uint256 *hashp,int64_t *valp,char *str,uint8_t fmt,uint8_t return(offset); } +int32_t oracle_parse_data_format(std::vector data,std::string format) +{ + int64_t offset=0,len=0; char fmt; + + for (int i=0; idata.size()-offset) return (0); + if (fmt=='S' || fmt=='s') + { + for (int j=offset;j127) return (0); + } + offset+=len; + } + if (offset!=data.size()) return (0); + else return (offset); +} + int64_t _correlate_price(int64_t *prices,int32_t n,int64_t price) { int32_t i,count = 0; int64_t diff,threshold = (price >> 8); @@ -729,13 +765,29 @@ int64_t LifetimeOraclesFunds(struct CCcontract_info *cp,uint256 oracletxid,CPubK std::string OracleCreate(int64_t txfee,std::string name,std::string description,std::string format) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Oraclespk; struct CCcontract_info *cp,C; + CPubKey mypk,Oraclespk; struct CCcontract_info *cp,C; char fmt; + cp = CCinit(&C,EVAL_ORACLES); if ( name.size() > 32 || description.size() > 4096 || format.size() > 4096 ) { - fprintf(stderr,"name.%d or description.%d is too big\n",(int32_t)name.size(),(int32_t)description.size()); + CCerror = strprintf("name.%d or description.%d is too big",(int32_t)name.size(),(int32_t)description.size()); + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); - } + } + for(int i = 0; i < format.size(); i++) + { + fmt=format[i]; + switch (fmt) + { + case 's': case 'S': case 'd': case 'D': + case 'c': case 'C': case 't': case 'T': + case 'i': case 'I': case 'l': case 'L': + case 'h': break; + default: CCerror = strprintf("invalid format type"); + fprintf(stderr,"%s\n", CCerror.c_str() ); + return(""); + } + } if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); @@ -745,6 +797,8 @@ std::string OracleCreate(int64_t txfee,std::string name,std::string description, mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(Oraclespk)) << OP_CHECKSIG)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeOraclesCreateOpRet('C',name,description,format))); } + CCerror = strprintf("error adding normal inputs"); + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } @@ -757,7 +811,8 @@ std::string OracleRegister(int64_t txfee,uint256 oracletxid,int64_t datafee) txfee = 10000; if ( datafee < txfee ) { - fprintf(stderr,"datafee must be txfee or more\n"); + CCerror = strprintf("datafee must be txfee or more"); + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } mypk = pubkey2pk(Mypubkey()); @@ -769,6 +824,8 @@ std::string OracleRegister(int64_t txfee,uint256 oracletxid,int64_t datafee) mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,batonpk)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeOraclesOpRet('R',oracletxid,mypk,datafee))); } + CCerror = strprintf("error adding normal inputs"); + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } @@ -787,13 +844,17 @@ std::string OracleSubscribe(int64_t txfee,uint256 oracletxid,CPubKey publisher,i mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(markerpubkey)) << OP_CHECKSIG)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeOraclesOpRet('S',oracletxid,mypk,amount))); } + CCerror = strprintf("error adding normal inputs"); + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } std::string OracleData(int64_t txfee,uint256 oracletxid,std::vector data) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CScript pubKey; CPubKey mypk,batonpk; int64_t datafee,inputs,CCchange = 0; struct CCcontract_info *cp,C; uint256 batontxid; char coinaddr[64],batonaddr[64]; std::vector prevdata; + CScript pubKey; CPubKey mypk,batonpk; int64_t offset,datafee,inputs,CCchange = 0; struct CCcontract_info *cp,C; uint256 batontxid,hashBlock; + char coinaddr[64],batonaddr[64]; std::vector prevdata; CTransaction tx; std::string name,description,format; int32_t len,numvouts; + cp = CCinit(&C,EVAL_ORACLES); mypk = pubkey2pk(Mypubkey()); if ( data.size() > 8192 ) @@ -808,6 +869,30 @@ std::string OracleData(int64_t txfee,uint256 oracletxid,std::vector da fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } + if ( GetTransaction(oracletxid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size()) > 0 ) + { + if ( DecodeOraclesCreateOpRet(tx.vout[numvouts-1].scriptPubKey,name,description,format) == 'C' ) + { + if (oracle_parse_data_format(data,format)==0) + { + CCerror = strprintf("data does not match length or content format specification"); + fprintf(stderr,"%s\n", CCerror.c_str() ); + return(""); + } + } + else + { + CCerror = strprintf("invalid oracle txid opret data"); + fprintf(stderr,"%s\n", CCerror.c_str() ); + return(""); + } + } + else + { + CCerror = strprintf("invalid oracle txid"); + fprintf(stderr,"%s\n", CCerror.c_str() ); + return(""); + } if ( txfee == 0 ) txfee = 10000; GetCCaddress(cp,coinaddr,mypk); @@ -831,7 +916,7 @@ std::string OracleData(int64_t txfee,uint256 oracletxid,std::vector da fprintf(stderr,"%s\n", CCerror.c_str() ); } } else { - CCerror = strprintf("couldnt add normal inputs\n"); + CCerror = strprintf("couldnt add normal inputs"); fprintf(stderr,"%s\n", CCerror.c_str() ); } return(""); @@ -855,7 +940,9 @@ UniValue OracleFormat(uint8_t *data,int32_t datalen,char *format,int32_t formatl UniValue OracleDataSamples(uint256 reforacletxid,uint256 batontxid,int32_t num) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); CTransaction tx,oracletx; uint256 hashBlock,btxid,oracletxid; CPubKey pk; std::string name,description,format; int32_t numvouts,n=0; std::vector data; char *formatstr = 0; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); CTransaction tx,oracletx; uint256 hashBlock,btxid,oracletxid; + CPubKey pk; std::string name,description,format; int32_t numvouts,n=0; std::vector data; char *formatstr = 0; + result.push_back(Pair("result","success")); if ( GetTransaction(reforacletxid,oracletx,hashBlock,false) != 0 && (numvouts=oracletx.vout.size()) > 0 ) { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c3faff238..f9a6a6a5e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6089,9 +6089,7 @@ UniValue oraclesdata(const UniValue& params, bool fHelp) txid = Parseuint256((char *)params[0].get_str().c_str()); data = ParseHex(params[1].get_str().c_str()); hex = OracleData(0,txid,data); - RETURN_IF_ERROR(CCerror); - if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); @@ -6127,24 +6125,6 @@ UniValue oraclescreate(const UniValue& params, bool fHelp) ERR_RESULT("oracles format must be <= 4096 characters"); return(result); } - // list of oracle valid formats from oracles.cpp -> oracle_format - const UniValue valid_formats[13] = {"s","S","d","D","c","C","t","T","i","I","l","L","h"}; - const UniValue header_type = "Ihh"; - // checking if oracle data type is valid - bool is_valid_format = false; - for ( int i = 0; i < 13; ++i ) { - if ( valid_formats[i].get_str() == format ) { - is_valid_format = true; - } - } - // additional check for special Ihh data type - if ( format == header_type.get_str() ) { - is_valid_format = true; - } - if ( !is_valid_format ) { - ERR_RESULT("oracles format not valid"); - return(result); - } hex = OracleCreate(0,name,description,format); RETURN_IF_ERROR(CCerror); if ( hex.size() > 0 ) From 8089c2a86ff4f07ac0096870251c55b882671279 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Thu, 3 Jan 2019 14:11:42 +0100 Subject: [PATCH 112/643] Decode CC opret RPC --- src/rpc/misc.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++- src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 47940be4d..37158e5d4 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -28,6 +28,7 @@ #include "timedata.h" #include "txmempool.h" #include "util.h" +#include "cc/eval.h" #ifdef ENABLE_WALLET #include "wallet/wallet.h" #include "wallet/walletdb.h" @@ -1335,7 +1336,53 @@ UniValue txnotarizedconfirmed(const UniValue& params, bool fHelp) txid = uint256S((char *)params[0].get_str().c_str()); notarizedconfirmed=komodo_txnotarizedconfirmed(txid); UniValue result(UniValue::VOBJ); - result.push_back(Pair("result", notarizedconfirmed)); + result.push_back(Pair("result", notarizedconfirmed)); + return result; +} + +UniValue decodeccopret(const UniValue& params, bool fHelp) +{ + CTransaction tx; uint256 txid,hashBlock; + std::vector vopret; uint8_t *script; + UniValue result(UniValue::VOBJ); + + if (fHelp || params.size() < 1 || params.size() > 1) + { + string msg = "decodeccopret hex\n" + "\nReturns eval code and function id for CC OP RETURN data.\n" + + "\nArguments:\n" + "1. txid (string, required) Transaction id.\n" + + "\nResult:\n" + "{\n" + " eval_code, (string) Eval code name.\n" + " function, (char) Function id char.\n" + "}\n" + ; + throw runtime_error(msg); + } + txid = uint256S((char *)params[0].get_str().c_str()); + { + LOCK(cs_main); + if (!GetTransaction(txid, tx, hashBlock, true)) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available about transaction"); + } + GetOpReturnData(tx.vout[tx.vout.size()-1].scriptPubKey,vopret); + script = (uint8_t *)vopret.data(); + if ( vopret.size() > 1) + { + char func[5]; + sprintf(func,"%c",script[1]); + result.push_back(Pair("result", "success")); + result.push_back(Pair("eval_code", EvalToStr(script[0]))); + result.push_back(Pair("function", func)); + } + else + { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "invalid or no CC opret data")); + } return result; } diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index acd8c4bb8..7ebd2c5ef 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -503,6 +503,7 @@ static const CRPCCommand vRPCCommands[] = { "util", "validateaddress", &validateaddress, true }, /* uses wallet if enabled */ { "util", "verifymessage", &verifymessage, true }, { "util", "txnotarizedconfirmed", &txnotarizedconfirmed, true }, + { "util", "decodeccopret", &decodeccopret, true }, { "util", "estimatefee", &estimatefee, true }, { "util", "estimatepriority", &estimatepriority, true }, { "util", "z_validateaddress", &z_validateaddress, true }, /* uses wallet if enabled */ diff --git a/src/rpc/server.h b/src/rpc/server.h index f5b28538c..f462f9363 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -356,6 +356,7 @@ extern UniValue walletlock(const UniValue& params, bool fHelp); extern UniValue encryptwallet(const UniValue& params, bool fHelp); extern UniValue validateaddress(const UniValue& params, bool fHelp); extern UniValue txnotarizedconfirmed(const UniValue& params, bool fHelp); +extern UniValue decodeccopret(const UniValue& params, bool fHelp); extern UniValue getinfo(const UniValue& params, bool fHelp); extern UniValue setpubkey(const UniValue& params, bool fHelp); extern UniValue getwalletinfo(const UniValue& params, bool fHelp); From f24ae214d220ec7ba9cab43192d5dea5fbd30710 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 5 Jan 2019 19:24:14 +0100 Subject: [PATCH 113/643] Add dpowconfs to z_listunspent + listreceivedbyaddress and other small fixes --- src/rpc/blockchain.cpp | 15 +++++++++------ src/rpc/rawtransaction.cpp | 9 ++++++--- src/wallet/rpcwallet.cpp | 21 +++++++++++++++++---- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 8e08056df..c210e3099 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -695,7 +695,8 @@ UniValue getblockheader(const UniValue& params, bool fHelp) "\nResult (for verbose = true):\n" "{\n" " \"hash\" : \"hash\", (string) the block hash (same as provided)\n" - " \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n" + " \"confirmations\" : n, (numeric) The number of notarized DPoW confirmations, or -1 if the block is not on the main chain\n" + " \"rawconfirmations\" : n,(numeric) The number of raw confirmations, or -1 if the block is not on the main chain\n" " \"height\" : n, (numeric) The block height or index\n" " \"version\" : n, (numeric) The block version\n" " \"merkleroot\" : \"xxxx\", (string) The merkle root\n" @@ -755,7 +756,8 @@ UniValue getblock(const UniValue& params, bool fHelp) "\nResult (for verbosity = 1):\n" "{\n" " \"hash\" : \"hash\", (string) the block hash (same as provided hash)\n" - " \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n" + " \"confirmations\" : n, (numeric) The number of notarized DPoW confirmations, or -1 if the block is not on the main chain\n" + " \"rawconfirmations\" : n,(numeric) The number of raw confirmations, or -1 if the block is not on the main chain\n" " \"size\" : n, (numeric) The block size\n" " \"height\" : n, (numeric) The block height or index (same as provided height)\n" " \"version\" : n, (numeric) The block version\n" @@ -1198,7 +1200,8 @@ UniValue gettxout(const UniValue& params, bool fHelp) "\nResult:\n" "{\n" " \"bestblock\" : \"hash\", (string) the block hash\n" - " \"confirmations\" : n, (numeric) The number of confirmations\n" + " \"confirmations\" : n, (numeric) The number of notarized DPoW confirmations\n" + " \"rawconfirmations\" : n, (numeric) The number of raw confirmations\n" " \"value\" : x.xxx, (numeric) The transaction value in " + CURRENCY_UNIT + "\n" " \"scriptPubKey\" : { (json object)\n" " \"asm\" : \"code\", (string) \n" @@ -1251,10 +1254,10 @@ UniValue gettxout(const UniValue& params, bool fHelp) BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); CBlockIndex *pindex = it->second; ret.push_back(Pair("bestblock", pindex->GetBlockHash().GetHex())); - if ((unsigned int)coins.nHeight == MEMPOOL_HEIGHT) + if ((unsigned int)coins.nHeight == MEMPOOL_HEIGHT) { ret.push_back(Pair("confirmations", 0)); - else - { + ret.push_back(Pair("rawconfirmations", 0)); + } else { ret.push_back(Pair("confirmations", komodo_dpowconfs(coins.nHeight,pindex->GetHeight() - coins.nHeight + 1))); ret.push_back(Pair("rawconfirmations", pindex->GetHeight() - coins.nHeight + 1)); } diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 067471c2c..5ab040711 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -297,6 +297,7 @@ void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue& } else { entry.push_back(Pair("height", -1)); entry.push_back(Pair("confirmations", 0)); + entry.push_back(Pair("rawconfirmations", 0)); } } @@ -379,9 +380,10 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) entry.push_back(Pair("confirmations", komodo_dpowconfs(pindex->GetHeight(),1 + chainActive.Height() - pindex->GetHeight()))); entry.push_back(Pair("time", pindex->GetBlockTime())); entry.push_back(Pair("blocktime", pindex->GetBlockTime())); - } - else + } else { entry.push_back(Pair("confirmations", 0)); + entry.push_back(Pair("rawconfirmations", 0)); + } } } } @@ -469,7 +471,8 @@ UniValue getrawtransaction(const UniValue& params, bool fHelp) " ,...\n" " ],\n" " \"blockhash\" : \"hash\", (string) the block hash\n" - " \"confirmations\" : n, (numeric) The confirmations\n" + " \"confirmations\" : n, (numeric) The number of notarized DPoW confirmations\n" + " \"rawconfirmations\" : n, (numeric) The number of raw confirmations\n" " \"time\" : ttt, (numeric) The transaction time in seconds since epoch (Jan 1 1970 GMT)\n" " \"blocktime\" : ttt (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n" "}\n" diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 45cc99b0f..f179ea45a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1435,11 +1435,13 @@ struct tallyitem int nConf; vector txids; bool fIsWatchonly; + int nHeight; tallyitem() { nAmount = 0; nConf = std::numeric_limits::max(); fIsWatchonly = false; + nHeight = 0; } }; @@ -1485,6 +1487,7 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts) tallyitem& item = mapTally[address]; item.nAmount += txout.nValue; // komodo_interest? item.nConf = min(item.nConf, nDepth); + item.nHeight = mapBlockIndex[wtx.hashBlock]->GetHeight(); item.txids.push_back(wtx.GetHash()); if (mine & ISMINE_WATCH_ONLY) item.fIsWatchonly = true; @@ -1504,11 +1507,13 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts) CAmount nAmount = 0; int nConf = std::numeric_limits::max(); bool fIsWatchonly = false; + int nHeight=0; if (it != mapTally.end()) { nAmount = (*it).second.nAmount; nConf = (*it).second.nConf; fIsWatchonly = (*it).second.fIsWatchonly; + nHeight = (*it).second.nHeight; } if (fByAccounts) @@ -1521,12 +1526,14 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts) else { UniValue obj(UniValue::VOBJ); + if(fIsWatchonly) obj.push_back(Pair("involvesWatchonly", true)); obj.push_back(Pair("address", EncodeDestination(dest))); obj.push_back(Pair("account", strAccount)); obj.push_back(Pair("amount", ValueFromAmount(nAmount))); - obj.push_back(Pair("confirmations", (nConf == std::numeric_limits::max() ? 0 : nConf))); + obj.push_back(Pair("rawconfirmations", (nConf == std::numeric_limits::max() ? 0 : nConf))); + obj.push_back(Pair("confirmations", (nConf == std::numeric_limits::max() ? 0 : komodo_dpowconfs(nHeight, nConf)))); UniValue transactions(UniValue::VARR); if (it != mapTally.end()) { @@ -1546,12 +1553,14 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts) { CAmount nAmount = (*it).second.nAmount; int nConf = (*it).second.nConf; + int nHeight = (*it).second.nHeight; UniValue obj(UniValue::VOBJ); if((*it).second.fIsWatchonly) obj.push_back(Pair("involvesWatchonly", true)); obj.push_back(Pair("account", (*it).first)); obj.push_back(Pair("amount", ValueFromAmount(nAmount))); - obj.push_back(Pair("confirmations", (nConf == std::numeric_limits::max() ? 0 : nConf))); + obj.push_back(Pair("rawconfirmations", (nConf == std::numeric_limits::max() ? 0 : nConf))); + obj.push_back(Pair("confirmations", (nConf == std::numeric_limits::max() ? 0 : komodo_dpowconfs(nHeight, nConf)))); ret.push_back(obj); } } @@ -2957,7 +2966,9 @@ UniValue z_listunspent(const UniValue& params, bool fHelp) obj.push_back(Pair("txid", entry.jsop.hash.ToString())); obj.push_back(Pair("jsindex", (int)entry.jsop.js )); obj.push_back(Pair("jsoutindex", (int)entry.jsop.n)); - obj.push_back(Pair("confirmations", entry.confirmations)); + int nHeight = mapBlockIndex[entry.jsop.hash]->GetHeight(); + obj.push_back(Pair("confirmations", komodo_dpowconfs(nHeight, entry.confirmations))); + obj.push_back(Pair("rawconfirmations", entry.confirmations)); bool hasSproutSpendingKey = pwalletMain->HaveSproutSpendingKey(boost::get(entry.address)); obj.push_back(Pair("spendable", hasSproutSpendingKey)); obj.push_back(Pair("address", EncodePaymentAddress(entry.address))); @@ -2974,7 +2985,9 @@ UniValue z_listunspent(const UniValue& params, bool fHelp) UniValue obj(UniValue::VOBJ); obj.push_back(Pair("txid", entry.op.hash.ToString())); obj.push_back(Pair("outindex", (int)entry.op.n)); - obj.push_back(Pair("confirmations", entry.confirmations)); + int nHeight = mapBlockIndex[entry.op.hash]->GetHeight(); + obj.push_back(Pair("confirmations", komodo_dpowconfs(nHeight, entry.confirmations))); + obj.push_back(Pair("rawconfirmations", entry.confirmations)); libzcash::SaplingIncomingViewingKey ivk; libzcash::SaplingFullViewingKey fvk; pwalletMain->GetSaplingIncomingViewingKey(boost::get(entry.address), ivk); From dda20b2760790a098bbfb94fdf792139010d18a7 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 6 Jan 2019 01:39:04 +0100 Subject: [PATCH 114/643] Correctly lookup height of joinsplits in z_listunspent --- src/wallet/rpcwallet.cpp | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index f179ea45a..ccecb3794 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2963,10 +2963,27 @@ UniValue z_listunspent(const UniValue& params, bool fHelp) for (auto & entry : sproutEntries) { UniValue obj(UniValue::VOBJ); + int nHeight = 0; + CTransaction tx; + uint256 hashBlock; + obj.push_back(Pair("txid", entry.jsop.hash.ToString())); obj.push_back(Pair("jsindex", (int)entry.jsop.js )); obj.push_back(Pair("jsoutindex", (int)entry.jsop.n)); - int nHeight = mapBlockIndex[entry.jsop.hash]->GetHeight(); + + if (!GetTransaction(entry.jsop.hash, tx, hashBlock, true)) { + // TODO: should we throw JSONRPCError ? + fprintf(stderr,"tx hash %s does not exist!\n", entry.jsop.hash.ToString().c_str() ); + } + + BlockMap::const_iterator it = mapBlockIndex.find(hashBlock); + if (it != mapBlockIndex.end()) { + nHeight = it->second->GetHeight(); + fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); + } else { + // TODO: should we throw JSONRPCError ? + fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() ); + } obj.push_back(Pair("confirmations", komodo_dpowconfs(nHeight, entry.confirmations))); obj.push_back(Pair("rawconfirmations", entry.confirmations)); bool hasSproutSpendingKey = pwalletMain->HaveSproutSpendingKey(boost::get(entry.address)); @@ -2985,7 +3002,23 @@ UniValue z_listunspent(const UniValue& params, bool fHelp) UniValue obj(UniValue::VOBJ); obj.push_back(Pair("txid", entry.op.hash.ToString())); obj.push_back(Pair("outindex", (int)entry.op.n)); - int nHeight = mapBlockIndex[entry.op.hash]->GetHeight(); + // this is a txid hash but needs to be block hash + int nHeight = 0; + CTransaction tx; + uint256 hashBlock; + if (!GetTransaction(entry.op.hash, tx, hashBlock, true)) { + // TODO: should we throw JSONRPCError ? + fprintf(stderr,"tx hash %s does not exist!\n", entry.op.hash.ToString().c_str() ); + } + + BlockMap::const_iterator it = mapBlockIndex.find(hashBlock); + if (it != mapBlockIndex.end()) { + nHeight = it->second->GetHeight(); + fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); + } else { + // TODO: should we throw JSONRPCError ? + fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() ); + } obj.push_back(Pair("confirmations", komodo_dpowconfs(nHeight, entry.confirmations))); obj.push_back(Pair("rawconfirmations", entry.confirmations)); libzcash::SaplingIncomingViewingKey ivk; From 5070f4397ab7718937b43fdf4661461499209f1c Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 5 Jan 2019 17:02:20 -0800 Subject: [PATCH 115/643] cleanup --- src/wallet/rpcwallet.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index ccecb3794..f3159a94d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3002,7 +3002,6 @@ UniValue z_listunspent(const UniValue& params, bool fHelp) UniValue obj(UniValue::VOBJ); obj.push_back(Pair("txid", entry.op.hash.ToString())); obj.push_back(Pair("outindex", (int)entry.op.n)); - // this is a txid hash but needs to be block hash int nHeight = 0; CTransaction tx; uint256 hashBlock; From 4fa788c76d6a37a01a36b8da2c9a1186cc1f82ab Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 6 Jan 2019 21:24:04 +0800 Subject: [PATCH 116/643] fix mempool lock. --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 22368a7eb..6427b91a0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4698,7 +4698,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C int32_t i,j,rejects=0,lastrejects=0; //fprintf(stderr,"put block's tx into mempool\n"); // Copy all non Z-txs in mempool to temporary mempool because there can be tx in local mempool that make the block invalid. - LOCK(mempool.cs); + LOCK2(cs_main,mempool.cs); //fprintf(stderr, "starting... mempoolsize.%ld\n",mempool.size()); list transactionsToRemove; BOOST_FOREACH(const CTxMemPoolEntry& e, mempool.mapTx) { @@ -4786,6 +4786,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C if ( ASSETCHAINS_CC != 0 ) { + LOCK2(cs_main,mempool.cs); // here we add back all txs from the temp mempool to the main mempool. BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { From 18b0a92c3ed23740a8541b2895c2cf6a2275d1de Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 6 Jan 2019 09:46:22 -0800 Subject: [PATCH 117/643] Add confirmations to z_listreceivedbyaddress --- src/wallet/rpcwallet.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index f3159a94d..5c4e21bfe 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3747,7 +3747,11 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) "{\n" " \"txid\": xxxxx, (string) the transaction id\n" " \"amount\": xxxxx, (numeric) the amount of value in the note\n" - " \"memo\": xxxxx, (string) hexademical string representation of memo field\n" + " \"memo\": xxxxx, (string) hexadecimal string representation of memo field\n" + " \"confirmations\" : n, (numeric) the number of confirmations\n" + " \"jsindex\" (sprout) : n, (numeric) the joinsplit index\n" + " \"jsoutindex\" (sprout) : n, (numeric) the output index of the joinsplit\n" + " \"outindex\" (sapling) : n, (numeric) the output index\n" " \"change\": true|false, (boolean) true if the address that received the note is also one of the sending addresses\n" "}\n" "\nExamples:\n" @@ -3798,6 +3802,7 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) obj.push_back(Pair("memo", HexStr(data))); obj.push_back(Pair("jsindex", entry.jsop.js)); obj.push_back(Pair("jsoutindex", entry.jsop.n)); + obj.push_back(Pair("confirmations", entry.confirmations)); if (hasSpendingKey) { obj.push_back(Pair("change", pwalletMain->IsNoteSproutChange(nullifierSet, entry.address, entry.jsop))); } @@ -3810,6 +3815,7 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) obj.push_back(Pair("amount", ValueFromAmount(CAmount(entry.note.value())))); obj.push_back(Pair("memo", HexStr(entry.memo))); obj.push_back(Pair("outindex", (int)entry.op.n)); + obj.push_back(Pair("confirmations", entry.confirmations)); if (hasSpendingKey) { obj.push_back(Pair("change", pwalletMain->IsNoteSaplingChange(nullifierSet, entry.address, entry.op))); } From 5d5af91e5d19fdb9f6f00da74934e105d02fa41e Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 6 Jan 2019 14:00:09 -0800 Subject: [PATCH 118/643] Add dpowconfs to z_listreceivedbyaddress --- src/wallet/rpcwallet.cpp | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5c4e21bfe..74231a58b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3796,13 +3796,30 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) if (boost::get(&zaddr) != nullptr) { for (CSproutNotePlaintextEntry & entry : sproutEntries) { UniValue obj(UniValue::VOBJ); + int nHeight = 0; + CTransaction tx; + uint256 hashBlock; + + if (GetTransaction(entry.jsop.hash, tx, hashBlock, true)) { + BlockMap::const_iterator it = mapBlockIndex.find(hashBlock); + if (it != mapBlockIndex.end()) { + nHeight = it->second->GetHeight(); + fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); + } else { + fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() ); + } + } else { + fprintf(stderr,"tx hash %s does not exist!\n", entry.jsop.hash.ToString().c_str() ); + } + obj.push_back(Pair("txid", entry.jsop.hash.ToString())); obj.push_back(Pair("amount", ValueFromAmount(CAmount(entry.plaintext.value())))); std::string data(entry.plaintext.memo().begin(), entry.plaintext.memo().end()); obj.push_back(Pair("memo", HexStr(data))); obj.push_back(Pair("jsindex", entry.jsop.js)); obj.push_back(Pair("jsoutindex", entry.jsop.n)); - obj.push_back(Pair("confirmations", entry.confirmations)); + obj.push_back(Pair("rawconfirmations", entry.confirmations)); + obj.push_back(Pair("confirmations", komodo_dpowconfs(nHeight, entry.confirmations))); if (hasSpendingKey) { obj.push_back(Pair("change", pwalletMain->IsNoteSproutChange(nullifierSet, entry.address, entry.jsop))); } @@ -3811,11 +3828,27 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) } else if (boost::get(&zaddr) != nullptr) { for (SaplingNoteEntry & entry : saplingEntries) { UniValue obj(UniValue::VOBJ); + int nHeight = 0; + CTransaction tx; + uint256 hashBlock; + + if (GetTransaction(entry.op.hash, tx, hashBlock, true)) { + BlockMap::const_iterator it = mapBlockIndex.find(hashBlock); + if (it != mapBlockIndex.end()) { + nHeight = it->second->GetHeight(); + fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); + } else { + fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() ); + } + } else { + fprintf(stderr,"tx hash %s does not exist!\n", entry.op.hash.ToString().c_str() ); + } obj.push_back(Pair("txid", entry.op.hash.ToString())); obj.push_back(Pair("amount", ValueFromAmount(CAmount(entry.note.value())))); obj.push_back(Pair("memo", HexStr(entry.memo))); obj.push_back(Pair("outindex", (int)entry.op.n)); - obj.push_back(Pair("confirmations", entry.confirmations)); + obj.push_back(Pair("rawconfirmations", entry.confirmations)); + obj.push_back(Pair("confirmations", komodo_dpowconfs(nHeight, entry.confirmations))); if (hasSpendingKey) { obj.push_back(Pair("change", pwalletMain->IsNoteSaplingChange(nullifierSet, entry.address, entry.op))); } From 2aa63efc1a65153a7424a62deb88c6856f7b450b Mon Sep 17 00:00:00 2001 From: ca333 Date: Mon, 7 Jan 2019 16:09:26 +0100 Subject: [PATCH 119/643] fix libsodium url --- depends/packages/libsodium.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depends/packages/libsodium.mk b/depends/packages/libsodium.mk index 67e096fae..76f0d9a28 100644 --- a/depends/packages/libsodium.mk +++ b/depends/packages/libsodium.mk @@ -9,7 +9,7 @@ $(package)_config_opts= else package=libsodium $(package)_version=1.0.15 -$(package)_download_path=https://download.libsodium.org/libsodium/releases +$(package)_download_path=https://download.libsodium.org/libsodium/releases/old $(package)_file_name=$(package)-$($(package)_version).tar.gz $(package)_sha256_hash=fb6a9e879a2f674592e4328c5d9f79f082405ee4bb05cb6e679b90afe9e178f4 $(package)_dependencies= From 348a23d6c499eaaa10f8cceeaae7899ecc51c8ee Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Jan 2019 07:29:36 -1100 Subject: [PATCH 120/643] tests --- src/main.cpp | 6 +++--- src/miner.cpp | 2 +- src/net.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 6427b91a0..bffddf01f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -81,7 +81,7 @@ extern uint8_t NOTARY_PUBKEY33[33]; extern int32_t KOMODO_LOADINGBLOCKS,KOMODO_LONGESTCHAIN,KOMODO_INSYNC,KOMODO_CONNECTING,KOMODO_EXTRASATOSHI; int32_t KOMODO_NEWBLOCKS; int32_t komodo_block2pubkey33(uint8_t *pubkey33,CBlock *block); -void komodo_broadcast(CBlock *pblock,int32_t limit); +//void komodo_broadcast(CBlock *pblock,int32_t limit); bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); void komodo_setactivation(int32_t height); @@ -3987,10 +3987,10 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * KOMODO_INSYNC = (int32_t)pindexNew->GetHeight(); else KOMODO_INSYNC = 0; //fprintf(stderr,"connect.%d insync.%d ASSETCHAINS_SAPLING.%d\n",(int32_t)pindexNew->GetHeight(),KOMODO_INSYNC,ASSETCHAINS_SAPLING); - if ( KOMODO_INSYNC != 0 ) //ASSETCHAINS_SYMBOL[0] == 0 && + /*if ( KOMODO_INSYNC != 0 ) //ASSETCHAINS_SYMBOL[0] == 0 && komodo_broadcast(pblock,8); else if ( ASSETCHAINS_SYMBOL[0] != 0 ) - komodo_broadcast(pblock,4); + komodo_broadcast(pblock,4);*/ if ( ASSETCHAINS_SAPLING <= 0 && pindexNew->nTime > KOMODO_SAPLING_ACTIVATION - 24*3600 ) komodo_activate_sapling(pindexNew); return true; diff --git a/src/miner.cpp b/src/miner.cpp index b0f801b01..cd79ea6b8 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -848,7 +848,7 @@ static bool ProcessBlockFound(CBlock* pblock) return error("KomodoMiner: ProcessNewBlock, block not accepted"); TrackMinedBlock(pblock->GetHash()); - komodo_broadcast(pblock,16); + //komodo_broadcast(pblock,16); return true; } diff --git a/src/net.h b/src/net.h index 7d3047d80..8901146ca 100644 --- a/src/net.h +++ b/src/net.h @@ -63,7 +63,7 @@ static const unsigned int MAX_INV_SZ = 50000; /** The maximum number of new addresses to accumulate before announcing. */ static const unsigned int MAX_ADDR_TO_SEND = 1000; /** Maximum length of incoming protocol messages (no message over 2 MiB is currently acceptable). */ -static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 2 * 1024 * 1024; +static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1024 * 1024; /** Maximum length of strSubVer in `version` message */ static const unsigned int MAX_SUBVERSION_LENGTH = 256; /** -listen default */ From e5797e6647667c4e7be0ca26fcb3f16215cb2c8d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Jan 2019 07:43:48 -1100 Subject: [PATCH 121/643] Update version --- src/rpc/misc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 37158e5d4..181d6cdbb 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -72,7 +72,7 @@ extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; uint32_t komodo_segid32(char *coinaddr); int64_t komodo_coinsupply(int64_t *zfundsp,int64_t *sproutfundsp,int32_t height); int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp); -#define KOMODO_VERSION "0.3.1" +#define KOMODO_VERSION "0.3.3" #define VERUS_VERSION "0.4.0g" extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; extern uint32_t ASSETCHAINS_CC; From 68ef9dd9a9ba02d4d88560c7881ee7f95b5cd57f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 8 Jan 2019 23:10:49 -1100 Subject: [PATCH 122/643] Add contextual check in connect block from connecttip --- src/main.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index bffddf01f..22c8eb4f4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3180,7 +3180,11 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin //fprintf(stderr,"checkblock failure in connectblock futureblock.%d\n",futureblock); return false; } - + if ( fCheckPOW != 0 && pindex->nTime > 1546028567 && !ContextualCheckBlock(block, state, pindex->pprev) ) + { + fprintf(stderr,"ContextualCheckBlock failed ht.%d\n",(int32_t)pindex->nHeight); + return false; + } // verify that the view's current state corresponds to the previous block uint256 hashPrevBlock = pindex->pprev == NULL ? uint256() : pindex->pprev->GetBlockHash(); if ( hashPrevBlock != view.GetBestBlock() ) From c299983eaf2ccb6e87235e382eb33111ac22ffcc Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 8 Jan 2019 23:11:38 -1100 Subject: [PATCH 123/643] GetHeight() --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 22c8eb4f4..82dae2593 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3182,7 +3182,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin } if ( fCheckPOW != 0 && pindex->nTime > 1546028567 && !ContextualCheckBlock(block, state, pindex->pprev) ) { - fprintf(stderr,"ContextualCheckBlock failed ht.%d\n",(int32_t)pindex->nHeight); + fprintf(stderr,"ContextualCheckBlock failed ht.%d\n",(int32_t)pindex->GetHeight()); return false; } // verify that the view's current state corresponds to the previous block From f52cbb1b069f228b1d6747a0ef25345e61b88d39 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 8 Jan 2019 23:25:42 -1100 Subject: [PATCH 124/643] Jan 15th activation --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 82dae2593..6aebb4708 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3180,7 +3180,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin //fprintf(stderr,"checkblock failure in connectblock futureblock.%d\n",futureblock); return false; } - if ( fCheckPOW != 0 && pindex->nTime > 1546028567 && !ContextualCheckBlock(block, state, pindex->pprev) ) + if ( fCheckPOW != 0 && pindex->nTime > 1547510400 && !ContextualCheckBlock(block, state, pindex->pprev) ) // Activate Jan 15th, 2019 { fprintf(stderr,"ContextualCheckBlock failed ht.%d\n",(int32_t)pindex->GetHeight()); return false; From 665c152e30d29fb7c977a87af083e24ba9d09964 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 8 Jan 2019 23:35:05 -1100 Subject: [PATCH 125/643] +prints --- src/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 6aebb4708..04f26d765 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1091,6 +1091,7 @@ bool ContextualCheckTransaction( } // Rules that apply to Overwinter or later: + fprintf(stderr,"ht.%d overwinterActive.%d tx.overwintered.%d\n",nHeight,overwinterActive,overwinterActive); if (overwinterActive) { // Reject transactions intended for Sprout @@ -3180,7 +3181,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin //fprintf(stderr,"checkblock failure in connectblock futureblock.%d\n",futureblock); return false; } - if ( fCheckPOW != 0 && pindex->nTime > 1547510400 && !ContextualCheckBlock(block, state, pindex->pprev) ) // Activate Jan 15th, 2019 + fprintf(stderr,"connect.%d checkPOW.%d nTime.%u %d\n",fCheckPOW,(uint32_t)pindex->nTime,ContextualCheckBlock(block, state, pindex->pprev)); + if ( fCheckPOW != 0 && !ContextualCheckBlock(block, state, pindex->pprev) ) //&& pindex->nTime > 1547510400 Activate Jan 15th, 2019 { fprintf(stderr,"ContextualCheckBlock failed ht.%d\n",(int32_t)pindex->GetHeight()); return false; From b0a3c8589c8eefb9500ed4affb7bf27c1b1e7d77 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 8 Jan 2019 23:39:49 -1100 Subject: [PATCH 126/643] Type --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 04f26d765..82d548f53 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3181,7 +3181,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin //fprintf(stderr,"checkblock failure in connectblock futureblock.%d\n",futureblock); return false; } - fprintf(stderr,"connect.%d checkPOW.%d nTime.%u %d\n",fCheckPOW,(uint32_t)pindex->nTime,ContextualCheckBlock(block, state, pindex->pprev)); + fprintf(stderr,"connect.%d checkPOW.%d nTime.%u %d\n",pindex->GetHeight(),fCheckPOW,(uint32_t)pindex->nTime,ContextualCheckBlock(block, state, pindex->pprev)); if ( fCheckPOW != 0 && !ContextualCheckBlock(block, state, pindex->pprev) ) //&& pindex->nTime > 1547510400 Activate Jan 15th, 2019 { fprintf(stderr,"ContextualCheckBlock failed ht.%d\n",(int32_t)pindex->GetHeight()); From e5e2d5007f550695acce0f321c8e0aea47fc88cc Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 8 Jan 2019 23:46:02 -1100 Subject: [PATCH 127/643] Cap sapling accept block exemption --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 82d548f53..056f08dbd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5077,7 +5077,7 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C // the problem is when a future sapling block comes in before we detected saplinght if ( saplinght > 0 && (tmpptr= chainActive.LastTip()) != 0 ) { - fprintf(stderr,"saplinght.%d tipht.%d blockht.%d cmp.%d\n",saplinght,(int32_t)tmpptr->GetHeight(),pindex->GetHeight(),pindex->GetHeight() < 0 || pindex->GetHeight() >= saplinght || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720)); + fprintf(stderr,"saplinght.%d tipht.%d blockht.%d cmp.%d\n",saplinght,(int32_t)tmpptr->GetHeight(),pindex->GetHeight(),pindex->GetHeight() < 0 || (pindex->GetHeight() >= saplinght && pindex->GetHeight() < saplinght+10000) || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720)); if ( pindex->GetHeight() < 0 || pindex->GetHeight() >= saplinght || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720) ) *futureblockp = 1; } From f421590c81a074f3fc1764da246da12e994bbeef Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 8 Jan 2019 23:49:16 -1100 Subject: [PATCH 128/643] Fix --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 056f08dbd..14b21b861 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5078,7 +5078,7 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C if ( saplinght > 0 && (tmpptr= chainActive.LastTip()) != 0 ) { fprintf(stderr,"saplinght.%d tipht.%d blockht.%d cmp.%d\n",saplinght,(int32_t)tmpptr->GetHeight(),pindex->GetHeight(),pindex->GetHeight() < 0 || (pindex->GetHeight() >= saplinght && pindex->GetHeight() < saplinght+10000) || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720)); - if ( pindex->GetHeight() < 0 || pindex->GetHeight() >= saplinght || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720) ) + if ( pindex->GetHeight() < 0 || (pindex->GetHeight() >= saplinght && pindex->GetHeight() < saplinght+10000) || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720) ) *futureblockp = 1; } if ( *futureblockp == 0 ) From 21ee92f6f334b62a5988f08ae663fba1a6410786 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 8 Jan 2019 23:58:46 -1100 Subject: [PATCH 129/643] Grandfather logic --- src/main.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 14b21b861..117c6604e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3181,11 +3181,13 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin //fprintf(stderr,"checkblock failure in connectblock futureblock.%d\n",futureblock); return false; } - fprintf(stderr,"connect.%d checkPOW.%d nTime.%u %d\n",pindex->GetHeight(),fCheckPOW,(uint32_t)pindex->nTime,ContextualCheckBlock(block, state, pindex->pprev)); - if ( fCheckPOW != 0 && !ContextualCheckBlock(block, state, pindex->pprev) ) //&& pindex->nTime > 1547510400 Activate Jan 15th, 2019 + //fprintf(stderr,"connect.%d checkPOW.%d nTime.%u %d\n",pindex->GetHeight(),fCheckPOW,(uint32_t)pindex->nTime,ContextualCheckBlock(block, state, pindex->pprev)); + if ( fCheckPOW != 0 && !ContextualCheckBlock(block, state, pindex->pprev) ) // Activate Jan 15th, 2019 { fprintf(stderr,"ContextualCheckBlock failed ht.%d\n",(int32_t)pindex->GetHeight()); - return false; + if ( pindex->nTime > 1547510400 ) + return false; + fprintf(stderr,"grandfathered exception, until jan 15th 2019\n"); } // verify that the view's current state corresponds to the previous block uint256 hashPrevBlock = pindex->pprev == NULL ? uint256() : pindex->pprev->GetBlockHash(); @@ -5077,8 +5079,8 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C // the problem is when a future sapling block comes in before we detected saplinght if ( saplinght > 0 && (tmpptr= chainActive.LastTip()) != 0 ) { - fprintf(stderr,"saplinght.%d tipht.%d blockht.%d cmp.%d\n",saplinght,(int32_t)tmpptr->GetHeight(),pindex->GetHeight(),pindex->GetHeight() < 0 || (pindex->GetHeight() >= saplinght && pindex->GetHeight() < saplinght+10000) || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720)); - if ( pindex->GetHeight() < 0 || (pindex->GetHeight() >= saplinght && pindex->GetHeight() < saplinght+10000) || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720) ) + fprintf(stderr,"saplinght.%d tipht.%d blockht.%d cmp.%d\n",saplinght,(int32_t)tmpptr->GetHeight(),pindex->GetHeight(),pindex->GetHeight() < 0 || (pindex->GetHeight() >= saplinght && pindex->GetHeight() < saplinght+50000) || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720)); + if ( pindex->GetHeight() < 0 || (pindex->GetHeight() >= saplinght && pindex->GetHeight() < saplinght+50000) || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720) ) *futureblockp = 1; } if ( *futureblockp == 0 ) From 0234e33c938cd5531537935221b6ff76d03e471c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 00:00:46 -1100 Subject: [PATCH 130/643] -print --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 117c6604e..c27c1f0e5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1091,7 +1091,7 @@ bool ContextualCheckTransaction( } // Rules that apply to Overwinter or later: - fprintf(stderr,"ht.%d overwinterActive.%d tx.overwintered.%d\n",nHeight,overwinterActive,overwinterActive); + //fprintf(stderr,"ht.%d overwinterActive.%d tx.overwintered.%d\n",nHeight,overwinterActive,overwinterActive); if (overwinterActive) { // Reject transactions intended for Sprout From bce13f9276ce64e1a2def0a0af60def624cb0ec6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 00:07:01 -1100 Subject: [PATCH 131/643] 0.3.3b --- src/main.cpp | 1 - src/rpc/misc.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c27c1f0e5..f5922d840 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3181,7 +3181,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin //fprintf(stderr,"checkblock failure in connectblock futureblock.%d\n",futureblock); return false; } - //fprintf(stderr,"connect.%d checkPOW.%d nTime.%u %d\n",pindex->GetHeight(),fCheckPOW,(uint32_t)pindex->nTime,ContextualCheckBlock(block, state, pindex->pprev)); if ( fCheckPOW != 0 && !ContextualCheckBlock(block, state, pindex->pprev) ) // Activate Jan 15th, 2019 { fprintf(stderr,"ContextualCheckBlock failed ht.%d\n",(int32_t)pindex->GetHeight()); diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 181d6cdbb..0ebfa7b25 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -72,7 +72,7 @@ extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; uint32_t komodo_segid32(char *coinaddr); int64_t komodo_coinsupply(int64_t *zfundsp,int64_t *sproutfundsp,int32_t height); int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp); -#define KOMODO_VERSION "0.3.3" +#define KOMODO_VERSION "0.3.3b" #define VERUS_VERSION "0.4.0g" extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; extern uint32_t ASSETCHAINS_CC; From 42911ea6c2f2af88923b865bee619ed7753dcbc4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 01:21:29 -1100 Subject: [PATCH 132/643] Double maxreorg --- src/main.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.h b/src/main.h index f318a8c13..2c4cef14e 100644 --- a/src/main.h +++ b/src/main.h @@ -78,7 +78,7 @@ static const bool DEFAULT_ALERTS = true; /** Minimum alert priority for enabling safe mode. */ static const int ALERT_PRIORITY_SAFE_MODE = 4000; /** Maximum reorg length we will accept before we shut down and alert the user. */ -static const unsigned int MAX_REORG_LENGTH = _COINBASE_MATURITY - 1; +static const unsigned int MAX_REORG_LENGTH = 2*(_COINBASE_MATURITY - 1); /** Maximum number of signature check operations in an IsStandard() P2SH script */ static const unsigned int MAX_P2SH_SIGOPS = 15; /** The maximum number of sigops we're willing to relay/mine in a single tx */ From 9269bc177c448d4a66e9f88222bb306e1779184f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 01:25:23 -1100 Subject: [PATCH 133/643] Allow tunable maxreorg --- src/komodo_utils.h | 1 + src/main.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 2437b0bf6..6010cf4c4 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1701,6 +1701,7 @@ void komodo_args(char *argv0) } } KOMODO_STOPAT = GetArg("-stopat",0); + MAX_REORG_LENGTH = GetArg("-maxreorg",MAX_REORG_LENGTH); ASSETCHAINS_CC = GetArg("-ac_cc",0); KOMODO_CCACTIVATE = GetArg("-ac_ccactivate",0); ASSETCHAINS_PUBLIC = GetArg("-ac_public",0); diff --git a/src/main.h b/src/main.h index 2c4cef14e..463c91237 100644 --- a/src/main.h +++ b/src/main.h @@ -78,7 +78,7 @@ static const bool DEFAULT_ALERTS = true; /** Minimum alert priority for enabling safe mode. */ static const int ALERT_PRIORITY_SAFE_MODE = 4000; /** Maximum reorg length we will accept before we shut down and alert the user. */ -static const unsigned int MAX_REORG_LENGTH = 2*(_COINBASE_MATURITY - 1); +static unsigned int MAX_REORG_LENGTH = (_COINBASE_MATURITY - 1); /** Maximum number of signature check operations in an IsStandard() P2SH script */ static const unsigned int MAX_P2SH_SIGOPS = 15; /** The maximum number of sigops we're willing to relay/mine in a single tx */ From 10b90968afce6a863ebab317f09510993bc2ff69 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 01:28:17 -1100 Subject: [PATCH 134/643] +comments --- src/chainparams.cpp | 2 +- src/net.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 49f08e98e..d97ed8624 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -230,7 +230,7 @@ void CChainParams::SetCheckpointData(CChainParams::CCheckpointData checkpointDat CChainParams::checkpointData = checkpointData; } -int32_t MAX_BLOCK_SIZE(int32_t height) +int32_t MAX_BLOCK_SIZE(int32_t height) // make sure to change MAX_PROTOCOL_MESSAGE_LENGTH also!!!! { //fprintf(stderr,"MAX_BLOCK_SIZE %d vs. %d\n",height,mainParams.consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight); if ( height <= 0 || (mainParams.consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight > 0 && height >= mainParams.consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight) ) diff --git a/src/net.h b/src/net.h index 8901146ca..3f30175c3 100644 --- a/src/net.h +++ b/src/net.h @@ -63,7 +63,7 @@ static const unsigned int MAX_INV_SZ = 50000; /** The maximum number of new addresses to accumulate before announcing. */ static const unsigned int MAX_ADDR_TO_SEND = 1000; /** Maximum length of incoming protocol messages (no message over 2 MiB is currently acceptable). */ -static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1024 * 1024; +static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1024 * 1024; // depends on MAX_BLOCK_SIZE /** Maximum length of strSubVer in `version` message */ static const unsigned int MAX_SUBVERSION_LENGTH = 256; /** -listen default */ From 59177fa5980649d5fa38f86b7ca767fe7718240d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 01:39:53 -1100 Subject: [PATCH 135/643] No static assert --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index f5922d840..aefb3bcb0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4088,7 +4088,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo // then pindexFork will be null, and we would need to remove the entire chain including // our genesis block. In practice this (probably) won't happen because of checks elsewhere. auto reorgLength = pindexOldTip ? pindexOldTip->GetHeight() - (pindexFork ? pindexFork->GetHeight() : -1) : 0; - static_assert(MAX_REORG_LENGTH > 0, "We must be able to reorg some distance"); + assert(MAX_REORG_LENGTH > 0, "We must be able to reorg some distance"); if (reorgLength > MAX_REORG_LENGTH) { int32_t notarizedht,prevMoMheight; uint256 notarizedhash,txid; From 2f847e2ef4ca3c77b6131183f1913e3b3714afad Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 01:40:34 -1100 Subject: [PATCH 136/643] Assert 1 arg --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index aefb3bcb0..f5e5a6ab0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4088,7 +4088,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo // then pindexFork will be null, and we would need to remove the entire chain including // our genesis block. In practice this (probably) won't happen because of checks elsewhere. auto reorgLength = pindexOldTip ? pindexOldTip->GetHeight() - (pindexFork ? pindexFork->GetHeight() : -1) : 0; - assert(MAX_REORG_LENGTH > 0, "We must be able to reorg some distance"); + assert(MAX_REORG_LENGTH > 0);//, "We must be able to reorg some distance"); if (reorgLength > MAX_REORG_LENGTH) { int32_t notarizedht,prevMoMheight; uint256 notarizedhash,txid; From c5b3b68ace990ee876587a3e2c2794796ef3ace2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 02:18:19 -1100 Subject: [PATCH 137/643] Increase witness cache size for maxreorg --- src/komodo_utils.h | 3 +++ src/wallet/wallet.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 6010cf4c4..2252cce38 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1650,6 +1650,7 @@ uint64_t komodo_ac_block_subsidy(int nHeight) } extern int64_t MAX_MONEY; +extern unsigned int WITNESS_CACHE_SIZE; void komodo_args(char *argv0) { @@ -1702,6 +1703,8 @@ void komodo_args(char *argv0) } KOMODO_STOPAT = GetArg("-stopat",0); MAX_REORG_LENGTH = GetArg("-maxreorg",MAX_REORG_LENGTH); + WITNESS_CACHE_SIZE = MAX_REORG_LENGTH+10; + ASSETCHAINS_CC = GetArg("-ac_cc",0); KOMODO_CCACTIVATE = GetArg("-ac_ccactivate",0); ASSETCHAINS_PUBLIC = GetArg("-ac_public",0); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 29f1737eb..653603ff7 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -76,7 +76,7 @@ static const unsigned int MAX_FREE_TRANSACTION_CREATE_SIZE = 1000; // Should be large enough that we can expect not to reorg beyond our cache // unless there is some exceptional network disruption. #define _COINBASE_MATURITY 100 -static const unsigned int WITNESS_CACHE_SIZE = _COINBASE_MATURITY+10; +unsigned int WITNESS_CACHE_SIZE = _COINBASE_MATURITY+10; //! Size of HD seed in bytes static const size_t HD_WALLET_SEED_LENGTH = 32; From 02d75902ad4a84c2e5042dd29fab9f228d640f28 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 02:30:47 -1100 Subject: [PATCH 138/643] Move declaration WITNESS_CACHE --- src/komodo_globals.h | 1 + src/komodo_utils.h | 1 - src/wallet/wallet.h | 4 ++-- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index a14cea753..8a72b5ad7 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -44,6 +44,7 @@ struct komodo_state KOMODO_STATES[34]; #define _COINBASE_MATURITY 100 int COINBASE_MATURITY = _COINBASE_MATURITY;//100; +unsigned int WITNESS_CACHE_SIZE = _COINBASE_MATURITY+10; int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1,KOMODO_DEALERNODE,KOMODO_EXTRASATOSHI,ASSETCHAINS_FOUNDERS; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 2252cce38..a5b22e592 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1650,7 +1650,6 @@ uint64_t komodo_ac_block_subsidy(int nHeight) } extern int64_t MAX_MONEY; -extern unsigned int WITNESS_CACHE_SIZE; void komodo_args(char *argv0) { diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 653603ff7..c8f9bcbb6 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -75,8 +75,8 @@ static const unsigned int MAX_FREE_TRANSACTION_CREATE_SIZE = 1000; //! Size of witness cache // Should be large enough that we can expect not to reorg beyond our cache // unless there is some exceptional network disruption. -#define _COINBASE_MATURITY 100 -unsigned int WITNESS_CACHE_SIZE = _COINBASE_MATURITY+10; +extern unsigned int WITNESS_CACHE_SIZE; + //! Size of HD seed in bytes static const size_t HD_WALLET_SEED_LENGTH = 32; From 2df13c428f9740e563f0b2a960901b458db21e36 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 04:24:04 -1100 Subject: [PATCH 139/643] Workaround for -maxreorg --- src/komodo_defs.h | 3 ++- src/wallet/wallet.cpp | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index c0a3caffd..bd516be61 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -28,7 +28,8 @@ #define KOMODO_FIRSTFUNGIBLEID 100 #define KOMODO_SAPLING_ACTIVATION 1544832000 // Dec 15th, 2018 #define KOMODO_SAPLING_DEADLINE 1550188800 // Feb 15th, 2019 - +#define _COINBASE_MATURITY 100 + extern uint8_t ASSETCHAINS_TXPOW,ASSETCHAINS_PUBLIC; int32_t MAX_BLOCK_SIZE(int32_t height); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 024194695..969e0c81b 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1184,6 +1184,7 @@ bool DecrementNoteWitnesses(NoteDataMap& noteDataMap, int indexHeight, int64_t n return true; } + void CWallet::DecrementNoteWitnesses(const CBlockIndex* pindex) { LOCK(cs_wallet); @@ -1193,10 +1194,17 @@ void CWallet::DecrementNoteWitnesses(const CBlockIndex* pindex) if (!::DecrementNoteWitnesses(wtxItem.second.mapSaplingNoteData, pindex->GetHeight(), nWitnessCacheSize)) needsRescan = true; } - nWitnessCacheSize -= 1; - // TODO: If nWitnessCache is zero, we need to regenerate the caches (#1302) - assert(nWitnessCacheSize > 0); - + if ( WITNESS_CACHE_SIZE == _COINBASE_MATURITY+10 ) + { + nWitnessCacheSize -= 1; + // TODO: If nWitnessCache is zero, we need to regenerate the caches (#1302) + assert(nWitnessCacheSize > 0); + } + else + { + if ( nWitnessCacheSize > 0 ) + nWitnessCacheSize-- + } // For performance reasons, we write out the witness cache in // CWallet::SetBestChain() (which also ensures that overall consistency // of the wallet.dat is maintained). From 512d96862abc5ab95bd0afd1bd6fd695458f14f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 04:30:24 -1100 Subject: [PATCH 140/643] Help human instructions for -maxreorg --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index f5e5a6ab0..b29e80efc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4114,7 +4114,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo "- " + strprintf(_("Fork point: %s %s, height %d"), ASSETCHAINS_SYMBOL,pindexFork->phashBlock->GetHex(), pindexFork->GetHeight()) + "\n\n" + _("Please help, human!"); - LogPrintf("*** %s\n", msg); + LogPrintf("*** %s\nif you launch with -maxreorg=%d it might be able to resolve this automatically", msg,reorgLength+10); uiInterface.ThreadSafeMessageBox(msg, "", CClientUIInterface::MSG_ERROR); StartShutdown(); return false; From 4f48570935324e2c3a531bfb084810764e7d1fff Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 04:31:04 -1100 Subject: [PATCH 141/643] ; --- src/wallet/wallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 969e0c81b..dd188d418 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1203,8 +1203,8 @@ void CWallet::DecrementNoteWitnesses(const CBlockIndex* pindex) else { if ( nWitnessCacheSize > 0 ) - nWitnessCacheSize-- - } + nWitnessCacheSize--; + } // For performance reasons, we write out the witness cache in // CWallet::SetBestChain() (which also ensures that overall consistency // of the wallet.dat is maintained). From 325f71b713609fe2b01fc2437cf4ce2d4507832a Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 10 Jan 2019 22:36:38 +0800 Subject: [PATCH 142/643] fix possible miner crash up with PoW, fix possible deadlock with large numbers of import transactions. --- src/main.cpp | 1 + src/miner.cpp | 446 +++++++++++++++++++++++++------------------------- 2 files changed, 226 insertions(+), 221 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b29e80efc..cd3c0d35f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2694,6 +2694,7 @@ bool ContextualCheckInputs( if (tx.IsCoinImport()) { + LOCK(cs_main); ServerTransactionSignatureChecker checker(&tx, 0, 0, false, txdata); return VerifyCoinImport(tx.vin[0].scriptSig, checker, state); } diff --git a/src/miner.cpp b/src/miner.cpp index cd79ea6b8..7948fd0cd 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -212,274 +212,273 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, // we will attempt to spend any cheats we see CTransaction cheatTx; boost::optional cheatSpend; - uint256 cbHash; + uint256 cbHash; - SaplingMerkleTree sapling_tree; uint64_t commission; - int nHeight = 0; - const Consensus::Params &consensusParams = chainparams.GetConsensus(); - - CBlockIndex* pindexPrev = chainActive.LastTip();; + CBlockIndex* pindexPrev = 0; { - { // contain lock to block generation and not staking loops. - LOCK2(cs_main, mempool.cs); - nHeight = pindexPrev->GetHeight() + 1; - uint32_t consensusBranchId = CurrentEpochBranchId(nHeight, consensusParams); - bool sapling = NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_SAPLING); + ENTER_CRITICAL_SECTION(cs_main); + ENTER_CRITICAL_SECTION(mempool.cs); + pindexPrev = chainActive.LastTip(); + const int nHeight = pindexPrev->GetHeight() + 1; + const Consensus::Params &consensusParams = chainparams.GetConsensus(); + uint32_t consensusBranchId = CurrentEpochBranchId(nHeight, consensusParams); + bool sapling = NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_SAPLING); - const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast(); - uint32_t proposedTime = GetAdjustedTime(); - if (proposedTime == nMedianTimePast) + const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast(); + uint32_t proposedTime = GetAdjustedTime(); + if (proposedTime == nMedianTimePast) + { + // too fast or stuck, this addresses the too fast issue, while moving + // forward as quickly as possible + for (int i; i < 100; i++) { - // too fast or stuck, this addresses the too fast issue, while moving - // forward as quickly as possible - for (int i; i < 100; i++) - { - proposedTime = GetAdjustedTime(); - if (proposedTime == nMedianTimePast) - MilliSleep(10); - } + proposedTime = GetAdjustedTime(); + if (proposedTime == nMedianTimePast) + MilliSleep(10); } - pblock->nTime = GetAdjustedTime(); + } + pblock->nTime = GetAdjustedTime(); - CCoinsViewCache view(pcoinsTip); - uint32_t expired; + CCoinsViewCache view(pcoinsTip); + uint32_t expired; uint64_t commission; + + SaplingMerkleTree sapling_tree; + assert(view.GetSaplingAnchorAt(view.GetBestAnchor(SAPLING), sapling_tree)); - assert(view.GetSaplingAnchorAt(view.GetBestAnchor(SAPLING), sapling_tree)); + // Priority order to process transactions + list vOrphan; // list memory doesn't move + map > mapDependers; + bool fPrintPriority = GetBoolArg("-printpriority", false); - // Priority order to process transactions - list vOrphan; // list memory doesn't move - map > mapDependers; - bool fPrintPriority = GetBoolArg("-printpriority", false); + // This vector will be sorted into a priority queue: + vector vecPriority; + vecPriority.reserve(mempool.mapTx.size() + 1); - // This vector will be sorted into a priority queue: - vector vecPriority; - vecPriority.reserve(mempool.mapTx.size() + 1); + // now add transactions from the mem pool + for (CTxMemPool::indexed_transaction_set::iterator mi = mempool.mapTx.begin(); + mi != mempool.mapTx.end(); ++mi) + { + const CTransaction& tx = mi->GetTx(); - // now add transactions from the mem pool - for (CTxMemPool::indexed_transaction_set::iterator mi = mempool.mapTx.begin(); - mi != mempool.mapTx.end(); ++mi) + int64_t nLockTimeCutoff = (STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST) + ? nMedianTimePast + : pblock->GetBlockTime(); + + if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff) || IsExpiredTx(tx, nHeight)) { - const CTransaction& tx = mi->GetTx(); + //fprintf(stderr,"coinbase.%d finaltx.%d expired.%d\n",tx.IsCoinBase(),IsFinalTx(tx, nHeight, nLockTimeCutoff),IsExpiredTx(tx, nHeight)); + continue; + } - int64_t nLockTimeCutoff = (STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST) - ? nMedianTimePast - : pblock->GetBlockTime(); + if ( ASSETCHAINS_SYMBOL[0] == 0 && komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,0) < 0 ) + { + //fprintf(stderr,"CreateNewBlock: komodo_validate_interest failure nHeight.%d nTime.%u vs locktime.%u\n",nHeight,(uint32_t)pblock->nTime,(uint32_t)tx.nLockTime); + continue; + } - if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff) || IsExpiredTx(tx, nHeight)) + COrphan* porphan = NULL; + double dPriority = 0; + CAmount nTotalIn = 0; + bool fMissingInputs = false; + bool fNotarisation = false; + if (tx.IsCoinImport()) + { + CAmount nValueIn = GetCoinImportValue(tx); + nTotalIn += nValueIn; + dPriority += (double)nValueIn * 1000; // flat multiplier + } else { + BOOST_FOREACH(const CTxIn& txin, tx.vin) { - //fprintf(stderr,"coinbase.%d finaltx.%d expired.%d\n",tx.IsCoinBase(),IsFinalTx(tx, nHeight, nLockTimeCutoff),IsExpiredTx(tx, nHeight)); - continue; - } + // Read prev transaction + if (!view.HaveCoins(txin.prevout.hash)) + { + // This should never happen; all transactions in the memory + // pool should connect to either transactions in the chain + // or other transactions in the memory pool. + if (!mempool.mapTx.count(txin.prevout.hash)) + { + LogPrintf("ERROR: mempool transaction missing input\n"); + if (fDebug) assert("mempool transaction missing input" == 0); + fMissingInputs = true; + if (porphan) + vOrphan.pop_back(); + break; + } - if ( ASSETCHAINS_SYMBOL[0] == 0 && komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,0) < 0 ) - { - //fprintf(stderr,"CreateNewBlock: komodo_validate_interest failure nHeight.%d nTime.%u vs locktime.%u\n",nHeight,(uint32_t)pblock->nTime,(uint32_t)tx.nLockTime); - continue; - } + // Has to wait for dependencies + if (!porphan) + { + // Use list for automatic deletion + vOrphan.push_back(COrphan(&tx)); + porphan = &vOrphan.back(); + } + mapDependers[txin.prevout.hash].push_back(porphan); + porphan->setDependsOn.insert(txin.prevout.hash); + nTotalIn += mempool.mapTx.find(txin.prevout.hash)->GetTx().vout[txin.prevout.n].nValue; + continue; + } + const CCoins* coins = view.AccessCoins(txin.prevout.hash); + assert(coins); - COrphan* porphan = NULL; - double dPriority = 0; - CAmount nTotalIn = 0; - bool fMissingInputs = false; - bool fNotarisation = false; - if (tx.IsCoinImport()) - { - CAmount nValueIn = GetCoinImportValue(tx); + CAmount nValueIn = coins->vout[txin.prevout.n].nValue; nTotalIn += nValueIn; - dPriority += (double)nValueIn * 1000; // flat multiplier - } else { - BOOST_FOREACH(const CTxIn& txin, tx.vin) - { - // Read prev transaction - if (!view.HaveCoins(txin.prevout.hash)) - { - // This should never happen; all transactions in the memory - // pool should connect to either transactions in the chain - // or other transactions in the memory pool. - if (!mempool.mapTx.count(txin.prevout.hash)) - { - LogPrintf("ERROR: mempool transaction missing input\n"); - if (fDebug) assert("mempool transaction missing input" == 0); - fMissingInputs = true; - if (porphan) - vOrphan.pop_back(); - break; - } - // Has to wait for dependencies - if (!porphan) - { - // Use list for automatic deletion - vOrphan.push_back(COrphan(&tx)); - porphan = &vOrphan.back(); - } - mapDependers[txin.prevout.hash].push_back(porphan); - porphan->setDependsOn.insert(txin.prevout.hash); - nTotalIn += mempool.mapTx.find(txin.prevout.hash)->GetTx().vout[txin.prevout.n].nValue; - continue; - } - const CCoins* coins = view.AccessCoins(txin.prevout.hash); - assert(coins); + int nConf = nHeight - coins->nHeight; - CAmount nValueIn = coins->vout[txin.prevout.n].nValue; - nTotalIn += nValueIn; - - int nConf = nHeight - coins->nHeight; - - dPriority += (double)nValueIn * nConf; - } - nTotalIn += tx.GetShieldedValueIn(); + dPriority += (double)nValueIn * nConf; } - - if (fMissingInputs) continue; - - // Priority is sum(valuein * age) / modified_txsize - unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); - dPriority = tx.ComputePriority(dPriority, nTxSize); - - uint256 hash = tx.GetHash(); - mempool.ApplyDeltas(hash, dPriority, nTotalIn); - - CFeeRate feeRate(nTotalIn-tx.GetValueOut(), nTxSize); - - if (porphan) - { - porphan->dPriority = dPriority; - porphan->feeRate = feeRate; - } - else - vecPriority.push_back(TxPriority(dPriority, feeRate, &(mi->GetTx()))); + nTotalIn += tx.GetShieldedValueIn(); } - // Collect transactions into block - uint64_t nBlockSize = 1000; - uint64_t nBlockTx = 0; - int64_t interest; - int nBlockSigOps = 100; - bool fSortedByFee = (nBlockPrioritySize <= 0); + if (fMissingInputs) continue; - TxPriorityCompare comparer(fSortedByFee); - std::make_heap(vecPriority.begin(), vecPriority.end(), comparer); + // Priority is sum(valuein * age) / modified_txsize + unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); + dPriority = tx.ComputePriority(dPriority, nTxSize); - while (!vecPriority.empty()) + uint256 hash = tx.GetHash(); + mempool.ApplyDeltas(hash, dPriority, nTotalIn); + + CFeeRate feeRate(nTotalIn-tx.GetValueOut(), nTxSize); + + if (porphan) { - // Take highest priority transaction off the priority queue: - double dPriority = vecPriority.front().get<0>(); - CFeeRate feeRate = vecPriority.front().get<1>(); - const CTransaction& tx = *(vecPriority.front().get<2>()); + porphan->dPriority = dPriority; + porphan->feeRate = feeRate; + } + else + vecPriority.push_back(TxPriority(dPriority, feeRate, &(mi->GetTx()))); + } - std::pop_heap(vecPriority.begin(), vecPriority.end(), comparer); - vecPriority.pop_back(); + // Collect transactions into block + uint64_t nBlockSize = 1000; + uint64_t nBlockTx = 0; + int64_t interest; + int nBlockSigOps = 100; + bool fSortedByFee = (nBlockPrioritySize <= 0); - // Size limits - unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); - if (nBlockSize + nTxSize >= nBlockMaxSize-512) // room for extra autotx - { - //fprintf(stderr,"nBlockSize %d + %d nTxSize >= %d nBlockMaxSize\n",(int32_t)nBlockSize,(int32_t)nTxSize,(int32_t)nBlockMaxSize); - continue; - } + TxPriorityCompare comparer(fSortedByFee); + std::make_heap(vecPriority.begin(), vecPriority.end(), comparer); - // Legacy limits on sigOps: - unsigned int nTxSigOps = GetLegacySigOpCount(tx); - if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1) - { - //fprintf(stderr,"A nBlockSigOps %d + %d nTxSigOps >= %d MAX_BLOCK_SIGOPS-1\n",(int32_t)nBlockSigOps,(int32_t)nTxSigOps,(int32_t)MAX_BLOCK_SIGOPS); - continue; - } - // Skip free transactions if we're past the minimum block size: - const uint256& hash = tx.GetHash(); - double dPriorityDelta = 0; - CAmount nFeeDelta = 0; - mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta); - if (fSortedByFee && (dPriorityDelta <= 0) && (nFeeDelta <= 0) && (feeRate < ::minRelayTxFee) && (nBlockSize + nTxSize >= nBlockMinSize)) - { - //fprintf(stderr,"fee rate skip\n"); - continue; - } - // Prioritise by fee once past the priority size or we run out of high-priority - // transactions: - if (!fSortedByFee && - ((nBlockSize + nTxSize >= nBlockPrioritySize) || !AllowFree(dPriority))) - { - fSortedByFee = true; - comparer = TxPriorityCompare(fSortedByFee); - std::make_heap(vecPriority.begin(), vecPriority.end(), comparer); - } + while (!vecPriority.empty()) + { + // Take highest priority transaction off the priority queue: + double dPriority = vecPriority.front().get<0>(); + CFeeRate feeRate = vecPriority.front().get<1>(); + const CTransaction& tx = *(vecPriority.front().get<2>()); - if (!view.HaveInputs(tx)) - { - //fprintf(stderr,"dont have inputs\n"); - continue; - } - CAmount nTxFees = view.GetValueIn(chainActive.LastTip()->GetHeight(),&interest,tx,chainActive.LastTip()->nTime)-tx.GetValueOut(); + std::pop_heap(vecPriority.begin(), vecPriority.end(), comparer); + vecPriority.pop_back(); - nTxSigOps += GetP2SHSigOpCount(tx, view); - if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1) - { - //fprintf(stderr,"B nBlockSigOps %d + %d nTxSigOps >= %d MAX_BLOCK_SIGOPS-1\n",(int32_t)nBlockSigOps,(int32_t)nTxSigOps,(int32_t)MAX_BLOCK_SIGOPS); - continue; - } - // Note that flags: we don't want to set mempool/IsStandard() - // policy here, but we still have to ensure that the block we - // create only contains transactions that are valid in new blocks. - CValidationState state; - PrecomputedTransactionData txdata(tx); - if (!ContextualCheckInputs(tx, state, view, true, MANDATORY_SCRIPT_VERIFY_FLAGS, true, txdata, Params().GetConsensus(), consensusBranchId)) - { - //fprintf(stderr,"context failure\n"); - continue; - } - UpdateCoins(tx, view, nHeight); + // Size limits + unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); + if (nBlockSize + nTxSize >= nBlockMaxSize-512) // room for extra autotx + { + //fprintf(stderr,"nBlockSize %d + %d nTxSize >= %d nBlockMaxSize\n",(int32_t)nBlockSize,(int32_t)nTxSize,(int32_t)nBlockMaxSize); + continue; + } - BOOST_FOREACH(const OutputDescription &outDescription, tx.vShieldedOutput) { - sapling_tree.append(outDescription.cm); - } + // Legacy limits on sigOps: + unsigned int nTxSigOps = GetLegacySigOpCount(tx); + if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1) + { + //fprintf(stderr,"A nBlockSigOps %d + %d nTxSigOps >= %d MAX_BLOCK_SIGOPS-1\n",(int32_t)nBlockSigOps,(int32_t)nTxSigOps,(int32_t)MAX_BLOCK_SIGOPS); + continue; + } + // Skip free transactions if we're past the minimum block size: + const uint256& hash = tx.GetHash(); + double dPriorityDelta = 0; + CAmount nFeeDelta = 0; + mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta); + if (fSortedByFee && (dPriorityDelta <= 0) && (nFeeDelta <= 0) && (feeRate < ::minRelayTxFee) && (nBlockSize + nTxSize >= nBlockMinSize)) + { + //fprintf(stderr,"fee rate skip\n"); + continue; + } + // Prioritise by fee once past the priority size or we run out of high-priority + // transactions: + if (!fSortedByFee && + ((nBlockSize + nTxSize >= nBlockPrioritySize) || !AllowFree(dPriority))) + { + fSortedByFee = true; + comparer = TxPriorityCompare(fSortedByFee); + std::make_heap(vecPriority.begin(), vecPriority.end(), comparer); + } - // Added - pblock->vtx.push_back(tx); - pblocktemplate->vTxFees.push_back(nTxFees); - pblocktemplate->vTxSigOps.push_back(nTxSigOps); - nBlockSize += nTxSize; - ++nBlockTx; - nBlockSigOps += nTxSigOps; - nFees += nTxFees; + if (!view.HaveInputs(tx)) + { + //fprintf(stderr,"dont have inputs\n"); + continue; + } + CAmount nTxFees = view.GetValueIn(chainActive.LastTip()->GetHeight(),&interest,tx,chainActive.LastTip()->nTime)-tx.GetValueOut(); - if (fPrintPriority) + nTxSigOps += GetP2SHSigOpCount(tx, view); + if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1) + { + //fprintf(stderr,"B nBlockSigOps %d + %d nTxSigOps >= %d MAX_BLOCK_SIGOPS-1\n",(int32_t)nBlockSigOps,(int32_t)nTxSigOps,(int32_t)MAX_BLOCK_SIGOPS); + continue; + } + // Note that flags: we don't want to set mempool/IsStandard() + // policy here, but we still have to ensure that the block we + // create only contains transactions that are valid in new blocks. + CValidationState state; + PrecomputedTransactionData txdata(tx); + if (!ContextualCheckInputs(tx, state, view, true, MANDATORY_SCRIPT_VERIFY_FLAGS, true, txdata, Params().GetConsensus(), consensusBranchId)) + { + //fprintf(stderr,"context failure\n"); + continue; + } + UpdateCoins(tx, view, nHeight); + + BOOST_FOREACH(const OutputDescription &outDescription, tx.vShieldedOutput) { + sapling_tree.append(outDescription.cm); + } + + // Added + pblock->vtx.push_back(tx); + pblocktemplate->vTxFees.push_back(nTxFees); + pblocktemplate->vTxSigOps.push_back(nTxSigOps); + nBlockSize += nTxSize; + ++nBlockTx; + nBlockSigOps += nTxSigOps; + nFees += nTxFees; + + if (fPrintPriority) + { + LogPrintf("priority %.1f fee %s txid %s\n",dPriority, feeRate.ToString(), tx.GetHash().ToString()); + } + + // Add transactions that depend on this one to the priority queue + if (mapDependers.count(hash)) + { + BOOST_FOREACH(COrphan* porphan, mapDependers[hash]) { - LogPrintf("priority %.1f fee %s txid %s\n",dPriority, feeRate.ToString(), tx.GetHash().ToString()); - } - - // Add transactions that depend on this one to the priority queue - if (mapDependers.count(hash)) - { - BOOST_FOREACH(COrphan* porphan, mapDependers[hash]) + if (!porphan->setDependsOn.empty()) { - if (!porphan->setDependsOn.empty()) + porphan->setDependsOn.erase(hash); + if (porphan->setDependsOn.empty()) { - porphan->setDependsOn.erase(hash); - if (porphan->setDependsOn.empty()) - { - vecPriority.push_back(TxPriority(porphan->dPriority, porphan->feeRate, porphan->ptx)); - std::push_heap(vecPriority.begin(), vecPriority.end(), comparer); - } + vecPriority.push_back(TxPriority(porphan->dPriority, porphan->feeRate, porphan->ptx)); + std::push_heap(vecPriority.begin(), vecPriority.end(), comparer); } } } } + } - nLastBlockTx = nBlockTx; - nLastBlockSize = nBlockSize; - blocktime = 1 + std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); - //pblock->nTime = blocktime + 1; - pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); - - } // contain lock to block generation only! + nLastBlockTx = nBlockTx; + nLastBlockSize = nBlockSize; + blocktime = 1 + std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + //pblock->nTime = blocktime + 1; + pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); int32_t stakeHeight = chainActive.Height() + 1; //LogPrintf("CreateNewBlock(): total size %u blocktime.%u nBits.%08x\n", nBlockSize,blocktime,pblock->nBits); if ( ASSETCHAINS_SYMBOL[0] != 0 && isStake ) { + LEAVE_CRITICAL_SECTION(cs_main); + LEAVE_CRITICAL_SECTION(mempool.cs); 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); @@ -654,6 +653,11 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, //fprintf(stderr,"valid\n"); } } + if ( ASSETCHAINS_SYMBOL[0] == 0 || (ASSETCHAINS_SYMBOL[0] != 0 && !isStake) ) + { + LEAVE_CRITICAL_SECTION(cs_main); + LEAVE_CRITICAL_SECTION(mempool.cs); + } //fprintf(stderr,"done new block\n"); return pblocktemplate.release(); } From 5b6a65f30a86e816166351e1c1292b8e37cfcf75 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 10 Jan 2019 07:30:00 -1100 Subject: [PATCH 143/643] -prints --- src/wallet/rpcwallet.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6e5bc5b83..79710969a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2979,7 +2979,7 @@ UniValue z_listunspent(const UniValue& params, bool fHelp) BlockMap::const_iterator it = mapBlockIndex.find(hashBlock); if (it != mapBlockIndex.end()) { nHeight = it->second->GetHeight(); - fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); + //fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); } else { // TODO: should we throw JSONRPCError ? fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() ); @@ -3013,7 +3013,7 @@ UniValue z_listunspent(const UniValue& params, bool fHelp) BlockMap::const_iterator it = mapBlockIndex.find(hashBlock); if (it != mapBlockIndex.end()) { nHeight = it->second->GetHeight(); - fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); + //fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); } else { // TODO: should we throw JSONRPCError ? fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() ); @@ -3804,7 +3804,7 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) BlockMap::const_iterator it = mapBlockIndex.find(hashBlock); if (it != mapBlockIndex.end()) { nHeight = it->second->GetHeight(); - fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); + //fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); } else { fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() ); } @@ -3836,7 +3836,7 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) BlockMap::const_iterator it = mapBlockIndex.find(hashBlock); if (it != mapBlockIndex.end()) { nHeight = it->second->GetHeight(); - fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); + //fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); } else { fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() ); } From 4f5c4db6152792ff78035d9cf51c35c92ebb56ec Mon Sep 17 00:00:00 2001 From: ca333 Date: Fri, 11 Jan 2019 05:49:55 +0100 Subject: [PATCH 144/643] update BIP44 cointype we had the wrong cointype - 141 is the correct one and assigned to KMD https://github.com/satoshilabs/slips/blob/master/slip-0044.md --- src/chainparams.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index d97ed8624..23d900d4e 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -107,7 +107,7 @@ public: strNetworkID = "main"; strCurrencyUnits = "KMD"; - bip44CoinType = 133; // As registered in https://github.com/satoshilabs/slips/blob/master/slip-0044.md (ZCASH, should be VRSC) + bip44CoinType = 141; // As registered in https://github.com/satoshilabs/slips/blob/master/slip-0044.md (ZCASH, should be VRSC) consensus.fCoinbaseMustBeProtected = false; // true this is only true wuth Verus and enforced after block 12800 consensus.nSubsidySlowStartInterval = 20000; consensus.nSubsidyHalvingInterval = 840000; From 8b7ca0ed32f9ecb7b137d95fec3182e38ec6f630 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 11 Jan 2019 23:24:12 +0800 Subject: [PATCH 145/643] Exit LOCK when return(0)! --- src/miner.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/miner.cpp b/src/miner.cpp index 7948fd0cd..cbefcbc41 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -547,6 +547,11 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, if (scriptPubKeyIn.IsPayToScriptHash() || scriptPubKeyIn.IsPayToCryptoCondition()) { fprintf(stderr,"CreateNewBlock: attempt to add timelock to pay2sh or pay2cc\n"); + if ( ASSETCHAINS_SYMBOL[0] == 0 || (ASSETCHAINS_SYMBOL[0] != 0 && !isStake) ) + { + LEAVE_CRITICAL_SECTION(cs_main); + LEAVE_CRITICAL_SECTION(mempool.cs); + } return 0; } @@ -639,6 +644,11 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, else { fprintf(stderr,"error adding notaryvin, need to create 0.0001 utxos\n"); + if ( ASSETCHAINS_SYMBOL[0] == 0 || (ASSETCHAINS_SYMBOL[0] != 0 && !isStake) ) + { + LEAVE_CRITICAL_SECTION(cs_main); + LEAVE_CRITICAL_SECTION(mempool.cs); + } return(0); } } From 9392a2b9ecbbd3f2c802df817eb56cfa1e1b1081 Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Sat, 12 Jan 2019 15:27:17 +0700 Subject: [PATCH 146/643] oracles autotests fixed --- qa/rpc-tests/cryptoconditions_oracles.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions_oracles.py b/qa/rpc-tests/cryptoconditions_oracles.py index f295bf020..048b577d1 100755 --- a/qa/rpc-tests/cryptoconditions_oracles.py +++ b/qa/rpc-tests/cryptoconditions_oracles.py @@ -112,17 +112,15 @@ class CryptoconditionsOraclesTest(CryptoconditionsTestFramework): # 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") + assert_equal("[u'01']", str(result["samples"][0]), "Data match") # D type - result = rpc.oraclesdata(globals()["oracle_{}".format("D")], "0101") + result = rpc.oraclesdata(globals()["oracle_{}".format("D")], "010001") 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") + assert_equal("[u'01']", str(result["samples"][0]), "Data match") # c type result = rpc.oraclesdata(globals()["oracle_{}".format("c")], "ff") @@ -198,12 +196,12 @@ class CryptoconditionsOraclesTest(CryptoconditionsTestFramework): assert_equal("[u'ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000']", str(result["samples"][0]), "Data match") # Ihh type - result = rpc.oraclesdata(globals()["oracle_{}".format("Ihh")], "00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff") + result = rpc.oraclesdata(globals()["oracle_{}".format("Ihh")], "ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff") 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'4294967295', u'ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000', u'ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000']", str(result["samples"][0]), "Data match") def run_test(self): From 2bde89c9ce4b3ae6d068a47bc3e2d43c070d829e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 00:29:37 -1100 Subject: [PATCH 147/643] Marmara coinbase initial impl --- src/cc/CCMarmara.h | 5 ++++ src/cc/marmara.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++ src/chainparams.cpp | 2 +- src/komodo_gateway.h | 10 +++++++ src/komodo_globals.h | 2 +- src/komodo_utils.h | 5 +++- 6 files changed, 85 insertions(+), 3 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 45fda83bd..5fc7fd673 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -19,6 +19,11 @@ #include "CCinclude.h" +#define MARMARA_GROUPSIZE 60 +#define MARMARA_MINLOCK (1440 * 3 * 30) +#define MARMARA_MAXLOCK (1440 * 24 * 30) +uint64_t komodo_block_prg(uint32_t nHeight); + bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 4bbccee4a..0f166e5df 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -71,6 +71,70 @@ bool MarmaraExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransactio else return(true); } +int32_t MarmaraRandomize(uint32_t ind) +{ + uint64_t val64; uint32_t val,range = (MARMARA_MAXLOCK - MARMARA_MINLOCK); + val64 = komodo_block_prg(ind); + val = (uint32_t)(val64 >> 32); + val ^= (uint32_t)val64; + return(val % range); +} + +int32_t MarmaraUnlockht(int32_t height) +{ + uint32_t ind = height / MARMARA_GROUPSIZE; + return(height + MarmaraRandomize(ind)); +} + +CScript EncodeMarmaraCoinbaseOpRet(CPubKey pk,int32_t height) +{ + CScript opret; int32_t unlockht; uint8_t evalcode = EVAL_ORACLES; + unlockht = MarmaraUnlockht(ht); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'C' << pk << height << unlockht); + return(opret); +} + +uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int32_t &height,int32_t &unlckht) +{ + std::vector vopret; uint8_t *script,e,f,funcid; + GetOpReturnData(scriptPubKey,vopret); + script = (uint8_t *)vopret.data(); + if ( vopret.size() > 2 && script[0] == EVAL_MARMARA ) + { + if ( script[1] == 'C' ) + { + if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> pk; ss >> height; ss >> unlockht) != 0 ) + { + return(script[1]); + } else fprintf(stderr,"DecodeMaramaraCoinbaseOpRet unmarshal error for C\n"); + } + } + return(0); +} + +int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) +{ + struct CCcontract_info *cp,C; CPubKey pk; int32_t ht,unlockht; CTxOut ccvout; + cp = CCinit(&C,EVAL_MARMARA); + for (ht=0; ht<10000; ht+=MARMARA_GROUPSIZE/3) + fprintf(stderr,"%d ",MarmaraUnlockht(ht)); + fprintf(stderr,"<- unlock hts\n"); + if ( tx.vout.size() == 2 && tx.vout[1].nValue == 0 ) + { + if ( DecodeMaramaraCoinbaseOpRet(tx.vout[1].scriptPubKey,pk,ht,unlockht) == 'C' ) + { + if ( ht == height && MarmaraUnlockht(height) == unlockht ) + { + ccvout = MakeCC1vout(EVAL_MARMARA,0,pk); + if ( ccvout.scriptPubKey == tx.vout[0].scriptPubKey ) + return(0); + fprintf(stderr,"ht.%d mismatched CCvout scriptPubKey\n",height); + } else fprintf(stderr,"ht.%d %d vs %d unlock.%d\n",height,MarmaraUnlockht(height),ht,unlockht); + } else fprintf(stderr,"ht.%d error decoding coinbase opret\n"); + } + return(-1); +} + bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 23d900d4e..47f4d48a8 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -107,7 +107,7 @@ public: strNetworkID = "main"; strCurrencyUnits = "KMD"; - bip44CoinType = 141; // As registered in https://github.com/satoshilabs/slips/blob/master/slip-0044.md (ZCASH, should be VRSC) + bip44CoinType = 141; // As registered in https://github.com/satoshilabs/slips/blob/master/slip-0044.md consensus.fCoinbaseMustBeProtected = false; // true this is only true wuth Verus and enforced after block 12800 consensus.nSubsidySlowStartInterval = 20000; consensus.nSubsidyHalvingInterval = 840000; diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 982f16b0b..360ddfcc0 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -16,6 +16,8 @@ // paxdeposit equivalent in reverse makes opreturn and KMD does the same in reverse #include "komodo_defs.h" +int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx); + int32_t pax_fiatstatus(uint64_t *available,uint64_t *deposited,uint64_t *issued,uint64_t *withdrawn,uint64_t *approved,uint64_t *redeemed,char *base) { int32_t baseid; struct komodo_state *sp; int64_t netliability,maxallowed,maxval; @@ -687,6 +689,14 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim } } } + if ( ASSETCHAINS_MARMARA != 0 && (height & 1) != 0 ) + { + if ( MarmaraValidateCoinbase(height,block.vtx[0]) < 0 ) + { + fprintf(stderr,"MARMARA constrains odd height blocks to pay 100% to CC in vout0\n"); + return(-1); + } + } // we don't want these checks in VRSC, leave it at the Sapling upgrade if ( ASSETCHAINS_SYMBOL[0] == 0 || (ASSETCHAINS_COMMISSION != 0 && height > 1) || diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 8a72b5ad7..f434674b7 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -49,7 +49,7 @@ unsigned int WITNESS_CACHE_SIZE = _COINBASE_MATURITY+10; int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1,KOMODO_DEALERNODE,KOMODO_EXTRASATOSHI,ASSETCHAINS_FOUNDERS; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB,ASSETCHAINS_SELFIMPORT; -uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW; +uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,ASSETCHAINS_MARMARA; bool VERUS_MINTBLOCKS; char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096]; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index a5b22e592..55b9bec35 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1778,6 +1778,7 @@ void komodo_args(char *argv0) ASSETCHAINS_SCRIPTPUB = GetArg("-ac_script",""); ASSETCHAINS_BEAMPORT = GetArg("-ac_beam",0); ASSETCHAINS_CODAPORT = GetArg("-ac_coda",0); + ASSETCHAINS_MARMARA = GetArg("-ac_marmara",0); if ( ASSETCHAINS_BEAMPORT != 0 && ASSETCHAINS_CODAPORT != 0 ) { fprintf(stderr,"can only have one of -ac_beam or -ac_coda\n"); @@ -1857,7 +1858,7 @@ void komodo_args(char *argv0) printf("ASSETCHAINS_FOUNDERS needs an ASETCHAINS_OVERRIDE_PUBKEY\n"); } } - if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 ) + if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 ) { fprintf(stderr,"perc %.4f%% ac_pub=[%02x%02x%02x...] acsize.%d\n",dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0],ASSETCHAINS_OVERRIDE_PUBKEY33[1],ASSETCHAINS_OVERRIDE_PUBKEY33[2],(int32_t)ASSETCHAINS_SCRIPTPUB.size()); extraptr = extrabuf; @@ -1931,6 +1932,8 @@ void komodo_args(char *argv0) extraptr[extralen++] = 'b'; if ( ASSETCHAINS_CODAPORT != 0 ) extraptr[extralen++] = 'c'; + if ( ASSETCHAINS_MARMARA != 0 ) + extraptr[extralen++] = ASSETCHAINS_MARMARA; } addn = GetArg("-seednode",""); From 2515d72e58e6d8606344476da150cd43c0e3447b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 00:32:20 -1100 Subject: [PATCH 148/643] Syntax --- src/cc/marmara.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 0f166e5df..1a67b4df6 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -86,15 +86,15 @@ int32_t MarmaraUnlockht(int32_t height) return(height + MarmaraRandomize(ind)); } -CScript EncodeMarmaraCoinbaseOpRet(CPubKey pk,int32_t height) +CScript EncodeMarmaraCoinbaseOpRet(CPubKey pk,int32_t ht) { CScript opret; int32_t unlockht; uint8_t evalcode = EVAL_ORACLES; unlockht = MarmaraUnlockht(ht); - opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'C' << pk << height << unlockht); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'C' << pk << ht << unlockht); return(opret); } -uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int32_t &height,int32_t &unlckht) +uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int32_t &height,int32_t &unlockht) { std::vector vopret; uint8_t *script,e,f,funcid; GetOpReturnData(scriptPubKey,vopret); @@ -130,7 +130,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) return(0); fprintf(stderr,"ht.%d mismatched CCvout scriptPubKey\n",height); } else fprintf(stderr,"ht.%d %d vs %d unlock.%d\n",height,MarmaraUnlockht(height),ht,unlockht); - } else fprintf(stderr,"ht.%d error decoding coinbase opret\n"); + } else fprintf(stderr,"ht.%d error decoding coinbase opret\n",height); } return(-1); } From 99f0709686d756806394ef7fd07472529d1ab1f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 00:34:24 -1100 Subject: [PATCH 149/643] Fix --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 360ddfcc0..0ad1b66ad 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -693,7 +693,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim { if ( MarmaraValidateCoinbase(height,block.vtx[0]) < 0 ) { - fprintf(stderr,"MARMARA constrains odd height blocks to pay 100% to CC in vout0\n"); + fprintf(stderr,"MARMARA constrains odd height blocks to pay 100%% to CC in vout0 with opreturn\n"); return(-1); } } From c0a9c015adcc209562af07492d9f7bc4b097d0d1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 00:37:41 -1100 Subject: [PATCH 150/643] Even heights with constraint so ac_supply is unlocked --- src/cc/marmara.cpp | 2 ++ src/komodo_gateway.h | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 1a67b4df6..359092ef9 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -119,6 +119,8 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) for (ht=0; ht<10000; ht+=MARMARA_GROUPSIZE/3) fprintf(stderr,"%d ",MarmaraUnlockht(ht)); fprintf(stderr,"<- unlock hts\n"); + if ( (height & 1) != 0 ) + return(0); if ( tx.vout.size() == 2 && tx.vout[1].nValue == 0 ) { if ( DecodeMaramaraCoinbaseOpRet(tx.vout[1].scriptPubKey,pk,ht,unlockht) == 'C' ) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 0ad1b66ad..fcdf4b85e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -689,11 +689,11 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim } } } - if ( ASSETCHAINS_MARMARA != 0 && (height & 1) != 0 ) + if ( height > 0 && ASSETCHAINS_MARMARA != 0 && (height & 1) == 0 ) { if ( MarmaraValidateCoinbase(height,block.vtx[0]) < 0 ) { - fprintf(stderr,"MARMARA constrains odd height blocks to pay 100%% to CC in vout0 with opreturn\n"); + fprintf(stderr,"MARMARA constrains even height blocks to pay 100%% to CC in vout0 with opreturn\n"); return(-1); } } From 5435d63aedd64fa8eb3abdf11d5872bdbe8331c6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 00:57:16 -1100 Subject: [PATCH 151/643] Histogram --- src/cc/marmara.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 359092ef9..908e3557d 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -116,9 +116,18 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { struct CCcontract_info *cp,C; CPubKey pk; int32_t ht,unlockht; CTxOut ccvout; cp = CCinit(&C,EVAL_MARMARA); - for (ht=0; ht<10000; ht+=MARMARA_GROUPSIZE/3) - fprintf(stderr,"%d ",MarmaraUnlockht(ht)); - fprintf(stderr,"<- unlock hts\n"); + int32_t d,histo[365*2]; + for (ht=2; ht<1000000; ht+=MARMARA_GROUPSIZE) + { + memset(histo,0,sizeof(histo)); + d = (MarmaraUnlockht(ht) - ht) / 1440 + if ( d < 0 || d > sizeof(histo)/sizeof(*histo) ) + fprintf(stderr,"d error.%d at ht.%d\n",d,ht); + else histo[d]++; + } + for (ht=0; ht Date: Sat, 12 Jan 2019 00:57:55 -1100 Subject: [PATCH 152/643] ; --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 908e3557d..254b62efd 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -120,7 +120,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) for (ht=2; ht<1000000; ht+=MARMARA_GROUPSIZE) { memset(histo,0,sizeof(histo)); - d = (MarmaraUnlockht(ht) - ht) / 1440 + d = (MarmaraUnlockht(ht) - ht) / 1440; if ( d < 0 || d > sizeof(histo)/sizeof(*histo) ) fprintf(stderr,"d error.%d at ht.%d\n",d,ht); else histo[d]++; From f816960557f9fe8e868bad5733372adf5023dc72 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 01:00:08 -1100 Subject: [PATCH 153/643] memset Outside loop --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 254b62efd..389ed0227 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -117,9 +117,9 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) struct CCcontract_info *cp,C; CPubKey pk; int32_t ht,unlockht; CTxOut ccvout; cp = CCinit(&C,EVAL_MARMARA); int32_t d,histo[365*2]; + memset(histo,0,sizeof(histo)); for (ht=2; ht<1000000; ht+=MARMARA_GROUPSIZE) { - memset(histo,0,sizeof(histo)); d = (MarmaraUnlockht(ht) - ht) / 1440; if ( d < 0 || d > sizeof(histo)/sizeof(*histo) ) fprintf(stderr,"d error.%d at ht.%d\n",d,ht); @@ -127,7 +127,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) } for (ht=0; ht Date: Sat, 12 Jan 2019 01:03:22 -1100 Subject: [PATCH 154/643] += MARMARA_MINLOCK --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 389ed0227..dadbb9249 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -77,7 +77,7 @@ int32_t MarmaraRandomize(uint32_t ind) val64 = komodo_block_prg(ind); val = (uint32_t)(val64 >> 32); val ^= (uint32_t)val64; - return(val % range); + return((val % range) + MARMARA_MINLOCK); } int32_t MarmaraUnlockht(int32_t height) @@ -116,7 +116,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { struct CCcontract_info *cp,C; CPubKey pk; int32_t ht,unlockht; CTxOut ccvout; cp = CCinit(&C,EVAL_MARMARA); - int32_t d,histo[365*2]; + int32_t d,histo[365*2+30]; memset(histo,0,sizeof(histo)); for (ht=2; ht<1000000; ht+=MARMARA_GROUPSIZE) { From 9e55c207256cf83cc98aaa6c792ebb51ac2450d8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 01:08:17 -1100 Subject: [PATCH 155/643] -print --- src/cc/marmara.cpp | 23 +++++++++++++---------- src/komodo_gateway.h | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index dadbb9249..8cfd6f6de 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -116,18 +116,21 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { struct CCcontract_info *cp,C; CPubKey pk; int32_t ht,unlockht; CTxOut ccvout; cp = CCinit(&C,EVAL_MARMARA); - int32_t d,histo[365*2+30]; - memset(histo,0,sizeof(histo)); - for (ht=2; ht<1000000; ht+=MARMARA_GROUPSIZE) + if ( 0 ) { - d = (MarmaraUnlockht(ht) - ht) / 1440; - if ( d < 0 || d > sizeof(histo)/sizeof(*histo) ) - fprintf(stderr,"d error.%d at ht.%d\n",d,ht); - else histo[d]++; + int32_t d,histo[365*2+30]; + memset(histo,0,sizeof(histo)); + for (ht=2; ht<1000000; ht+=MARMARA_GROUPSIZE) + { + d = (MarmaraUnlockht(ht) - ht) / 1440; + if ( d < 0 || d > sizeof(histo)/sizeof(*histo) ) + fprintf(stderr,"d error.%d at ht.%d\n",d,ht); + else histo[d]++; + } + for (ht=0; ht Date: Sat, 12 Jan 2019 01:36:01 -1100 Subject: [PATCH 156/643] Marmara coinbase opret --- src/cc/marmara.cpp | 29 +++++++++++++++++++++++++++++ src/miner.cpp | 14 ++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 8cfd6f6de..a7e9f2d1f 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -112,6 +112,35 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int3 return(0); } +CScript Marmara_scriptPubKey(int32_t height,CScript scriptPubKey) +{ + CTxOut ccvout; uint8_t *ptr; CPubKey pk; + if ( height > 0 && ASSETCHAINS_MARMARA != 0 && (height & 1) == 0 && scriptPubKey.size() == 35 ) + { + ptr = (uint8_t *)pubkey.begin(); + if ( ptr[0] == 33 && ptr[34] == OP_CHECKSIG ) + pk = buf2pk(ptr+1); + ccvout = MakeCC1vout(EVAL_MARMARA,0,pk); + return(ccvout.scriptPubKey); + } + return(scriptPubKey); +} + +CScript MarmaraCoinbaseOpret(int32_t height,CScript scriptPubKey) +{ + uint8_t *ptr; CPubKey pk; + if ( height > 0 && (height & 1) == 0 && scriptPubKey.size() == 35 ) + { + ptr = (uint8_t *)pubkey.begin(); + if ( ptr[0] == 33 && ptr[34] == OP_CHECKSIG ) + { + pk = buf2pk(ptr+1); + return(EncodeMarmaraCoinbaseOpRet(pk,height); + } + } + return(scriptPubKey); +} + int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { struct CCcontract_info *cp,C; CPubKey pk; int32_t ht,unlockht; CTxOut ccvout; diff --git a/src/miner.cpp b/src/miner.cpp index 7948fd0cd..223972c80 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -141,7 +141,7 @@ extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY,ASSETCHAINS_SCRIPTPUB; void vcalc_sha256(char deprecated[(256 >> 3) * 2 + 1],uint8_t hash[256 >> 3],uint8_t *src,int32_t len); -extern uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33]; +extern uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_MARMARA; uint32_t Mining_start,Mining_height; int32_t My_notaryid = -1; int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp); @@ -155,6 +155,8 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt int32_t verus_staked(CBlock *pBlock, CMutableTransaction &txNew, uint32_t &nBits, arith_uint256 &hashResult, uint8_t *utxosig, CPubKey &pk); int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33); int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); +CScript Marmara_scriptPubKey(int32_t height,CScript scriptPubKey); +CScript MarmaraCoinbaseOpret(int32_t height,CScript scriptPubKey); CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake) { @@ -534,7 +536,13 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, // check if coinbase transactions must be time locked at current subsidy and prepend the time lock // to transaction if so, cast for GTE operator - if ((uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE) + if ( ASSETCHAINS_MARMARA != 0 && height > 0 && (height & 1) == 0 ) + { + txNew.vout.resize(2); + txNew.vout[1].nValue = 0; + txNew.vout[1].scriptPubKey = MarmaraCoinbaseOpret(nHeight,scriptPubKeyIn); + } + else if ((uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE) { int32_t opretlen, p2shlen, scriptlen; CScriptExt opretScript = CScriptExt(); @@ -775,6 +783,8 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, //scriptPubKey = CScript() << ToByteVector(pubkey) << OP_CHECKSIG; } } + if ( ASSETCHAINS_MARMARA != 0 ) + scriptPubKey = Marmara_scriptPubKey(height,scriptPubKey); return CreateNewBlock(scriptPubKey, gpucount, isStake); } From 5b4ae1d702358a4cfc171ef599c2152d9e89fc31 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 01:37:41 -1100 Subject: [PATCH 157/643] Fix --- src/cc/marmara.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index a7e9f2d1f..93d24b868 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -115,9 +115,9 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int3 CScript Marmara_scriptPubKey(int32_t height,CScript scriptPubKey) { CTxOut ccvout; uint8_t *ptr; CPubKey pk; - if ( height > 0 && ASSETCHAINS_MARMARA != 0 && (height & 1) == 0 && scriptPubKey.size() == 35 ) + if ( height > 0 && (height & 1) == 0 && scriptPubKey.size() == 35 ) { - ptr = (uint8_t *)pubkey.begin(); + ptr = (uint8_t *)scriptPubKey.begin(); if ( ptr[0] == 33 && ptr[34] == OP_CHECKSIG ) pk = buf2pk(ptr+1); ccvout = MakeCC1vout(EVAL_MARMARA,0,pk); @@ -131,11 +131,11 @@ CScript MarmaraCoinbaseOpret(int32_t height,CScript scriptPubKey) uint8_t *ptr; CPubKey pk; if ( height > 0 && (height & 1) == 0 && scriptPubKey.size() == 35 ) { - ptr = (uint8_t *)pubkey.begin(); + ptr = (uint8_t *)scriptPubKey.begin(); if ( ptr[0] == 33 && ptr[34] == OP_CHECKSIG ) { pk = buf2pk(ptr+1); - return(EncodeMarmaraCoinbaseOpRet(pk,height); + return(EncodeMarmaraCoinbaseOpRet(pk,height)); } } return(scriptPubKey); From e656efa89c2c468921d2297f2bbcb2e474209c0e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 01:38:30 -1100 Subject: [PATCH 158/643] data() --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 93d24b868..f25b0c62a 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -117,7 +117,7 @@ CScript Marmara_scriptPubKey(int32_t height,CScript scriptPubKey) CTxOut ccvout; uint8_t *ptr; CPubKey pk; if ( height > 0 && (height & 1) == 0 && scriptPubKey.size() == 35 ) { - ptr = (uint8_t *)scriptPubKey.begin(); + ptr = (uint8_t *)scriptPubKey.data(); if ( ptr[0] == 33 && ptr[34] == OP_CHECKSIG ) pk = buf2pk(ptr+1); ccvout = MakeCC1vout(EVAL_MARMARA,0,pk); @@ -131,7 +131,7 @@ CScript MarmaraCoinbaseOpret(int32_t height,CScript scriptPubKey) uint8_t *ptr; CPubKey pk; if ( height > 0 && (height & 1) == 0 && scriptPubKey.size() == 35 ) { - ptr = (uint8_t *)scriptPubKey.begin(); + ptr = (uint8_t *)scriptPubKey.data(); if ( ptr[0] == 33 && ptr[34] == OP_CHECKSIG ) { pk = buf2pk(ptr+1); From 9a46e8a5774207d45950fcf7a83251d271a6f050 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 01:45:23 -1100 Subject: [PATCH 159/643] Use pk --- src/cc/marmara.cpp | 29 ++++++++--------------------- src/miner.cpp | 18 +++++++++++------- 2 files changed, 19 insertions(+), 28 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index f25b0c62a..63a8bbe3b 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -112,33 +112,20 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int3 return(0); } -CScript Marmara_scriptPubKey(int32_t height,CScript scriptPubKey) +CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) { - CTxOut ccvout; uint8_t *ptr; CPubKey pk; - if ( height > 0 && (height & 1) == 0 && scriptPubKey.size() == 35 ) - { - ptr = (uint8_t *)scriptPubKey.data(); - if ( ptr[0] == 33 && ptr[34] == OP_CHECKSIG ) - pk = buf2pk(ptr+1); + CTxOut ccvout; + if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) ccvout = MakeCC1vout(EVAL_MARMARA,0,pk); - return(ccvout.scriptPubKey); - } - return(scriptPubKey); + return(ccvout.scriptPubKey); } -CScript MarmaraCoinbaseOpret(int32_t height,CScript scriptPubKey) +CScript MarmaraCoinbaseOpret(int32_t height,CPubKey pk) { uint8_t *ptr; CPubKey pk; - if ( height > 0 && (height & 1) == 0 && scriptPubKey.size() == 35 ) - { - ptr = (uint8_t *)scriptPubKey.data(); - if ( ptr[0] == 33 && ptr[34] == OP_CHECKSIG ) - { - pk = buf2pk(ptr+1); - return(EncodeMarmaraCoinbaseOpRet(pk,height)); - } - } - return(scriptPubKey); + if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) + return(EncodeMarmaraCoinbaseOpRet(pk,height)); + return(CScript()); } int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) diff --git a/src/miner.cpp b/src/miner.cpp index 223972c80..3322bbb16 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -155,8 +155,8 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt int32_t verus_staked(CBlock *pBlock, CMutableTransaction &txNew, uint32_t &nBits, arith_uint256 &hashResult, uint8_t *utxosig, CPubKey &pk); int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33); int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); -CScript Marmara_scriptPubKey(int32_t height,CScript scriptPubKey); -CScript MarmaraCoinbaseOpret(int32_t height,CScript scriptPubKey); +CScript Marmara_scriptPubKey(int32_t height,CPubKey pk); +CScript MarmaraCoinbaseOpret(int32_t height,CPubKey pk); CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake) { @@ -540,7 +540,7 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, { txNew.vout.resize(2); txNew.vout[1].nValue = 0; - txNew.vout[1].scriptPubKey = MarmaraCoinbaseOpret(nHeight,scriptPubKeyIn); + txNew.vout[1].scriptPubKey = MarmaraCoinbaseOpret(nHeight,pk); } else if ((uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE) { @@ -751,7 +751,10 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, if ( nHeight == 1 && ASSETCHAINS_COMMISSION != 0 ) { if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) - scriptPubKey = CScript() << ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY) << OP_CHECKSIG; + { + pubkey = ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY); + scriptPubKey = CScript() << pubkey << OP_CHECKSIG; + } else { len = strlen(ASSETCHAINS_SCRIPTPUB.c_str()); @@ -764,7 +767,8 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, else if ( USE_EXTERNAL_PUBKEY != 0 ) { //fprintf(stderr,"use notary pubkey\n"); - scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; + pubkey = ParseHex(NOTARY_PUBKEY); + scriptPubKey = CScript() << pubkey << OP_CHECKSIG; } else { @@ -783,8 +787,8 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, //scriptPubKey = CScript() << ToByteVector(pubkey) << OP_CHECKSIG; } } - if ( ASSETCHAINS_MARMARA != 0 ) - scriptPubKey = Marmara_scriptPubKey(height,scriptPubKey); + if ( ASSETCHAINS_MARMARA != 0 && height > 0 && (height & 1) == 0 ) + scriptPubKey = Marmara_scriptPubKey(height,pubkey); return CreateNewBlock(scriptPubKey, gpucount, isStake); } From 8b43e641290d0a4bdf34bfb035d2bd0a0b348c1b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 01:45:57 -1100 Subject: [PATCH 160/643] Fx --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 63a8bbe3b..18ba87734 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -122,7 +122,7 @@ CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) CScript MarmaraCoinbaseOpret(int32_t height,CPubKey pk) { - uint8_t *ptr; CPubKey pk; + uint8_t *ptr; if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) return(EncodeMarmaraCoinbaseOpRet(pk,height)); return(CScript()); From 621be31f25d3473bc313fab756bd3fa3ea9b5751 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 01:48:55 -1100 Subject: [PATCH 161/643] nHeight --- src/miner.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 3322bbb16..51078f963 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -536,7 +536,7 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, // check if coinbase transactions must be time locked at current subsidy and prepend the time lock // to transaction if so, cast for GTE operator - if ( ASSETCHAINS_MARMARA != 0 && height > 0 && (height & 1) == 0 ) + if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) { txNew.vout.resize(2); txNew.vout[1].nValue = 0; @@ -753,7 +753,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) { pubkey = ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY); - scriptPubKey = CScript() << pubkey << OP_CHECKSIG; + scriptPubKey = CScript() << ParseHex(HexStr(pubkey)) << OP_CHECKSIG; } else { @@ -768,7 +768,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, { //fprintf(stderr,"use notary pubkey\n"); pubkey = ParseHex(NOTARY_PUBKEY); - scriptPubKey = CScript() << pubkey << OP_CHECKSIG; + scriptPubKey = CScript() << ParseHex(HexStr(pubkey)) << OP_CHECKSIG; } else { @@ -787,8 +787,8 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, //scriptPubKey = CScript() << ToByteVector(pubkey) << OP_CHECKSIG; } } - if ( ASSETCHAINS_MARMARA != 0 && height > 0 && (height & 1) == 0 ) - scriptPubKey = Marmara_scriptPubKey(height,pubkey); + if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) + scriptPubKey = Marmara_scriptPubKey(nHeight,pubkey); return CreateNewBlock(scriptPubKey, gpucount, isStake); } From 4bb5c6cbd311b291ecf9a5259e68175974609a10 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 01:54:01 -1100 Subject: [PATCH 162/643] EVAL_MARMARA --- src/cc/marmara.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 18ba87734..a069af713 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -88,7 +88,7 @@ int32_t MarmaraUnlockht(int32_t height) CScript EncodeMarmaraCoinbaseOpRet(CPubKey pk,int32_t ht) { - CScript opret; int32_t unlockht; uint8_t evalcode = EVAL_ORACLES; + CScript opret; int32_t unlockht; uint8_t evalcode = EVAL_MARMARA; unlockht = MarmaraUnlockht(ht); opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'C' << pk << ht << unlockht); return(opret); @@ -107,8 +107,8 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int3 { return(script[1]); } else fprintf(stderr,"DecodeMaramaraCoinbaseOpRet unmarshal error for C\n"); - } - } + } else fprintf(stderr,"script[1] is %d != 'C' %d\n",script[1],'C'); + } else fprintf(stderr,"vopret.size() is %d [0] is %d != %d\n",vopret.size(),script[0],EVAL_MARMARA); return(0); } From e1dd671e66eb2c243c562b8dff4ea9e12fdeed1f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 01:54:48 -1100 Subject: [PATCH 163/643] (Int32_t) --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index a069af713..41a85802e 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -108,7 +108,7 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int3 return(script[1]); } else fprintf(stderr,"DecodeMaramaraCoinbaseOpRet unmarshal error for C\n"); } else fprintf(stderr,"script[1] is %d != 'C' %d\n",script[1],'C'); - } else fprintf(stderr,"vopret.size() is %d [0] is %d != %d\n",vopret.size(),script[0],EVAL_MARMARA); + } else fprintf(stderr,"vopret.size() is %d [0] is %d != %d\n",(int32_t)vopret.size(),script[0],EVAL_MARMARA); return(0); } From 8250a4bab83940782ef5b0331eb5ff719db58215 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 02:00:17 -1100 Subject: [PATCH 164/643] +print --- src/cc/marmara.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 41a85802e..9cb9ce813 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -91,6 +91,16 @@ CScript EncodeMarmaraCoinbaseOpRet(CPubKey pk,int32_t ht) CScript opret; int32_t unlockht; uint8_t evalcode = EVAL_MARMARA; unlockht = MarmaraUnlockht(ht); opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'C' << pk << ht << unlockht); + { + std::vector vopret; uint8_t *script,i; + GetOpReturnData(opret,vopret); + script = (uint8_t *)vopret.data(); + { + for (i=0; i vopret; uint8_t *script,e,f,funcid; GetOpReturnData(scriptPubKey,vopret); script = (uint8_t *)vopret.data(); + { + int32_t i; + for (i=0; i 2 && script[0] == EVAL_MARMARA ) { if ( script[1] == 'C' ) @@ -108,7 +124,7 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int3 return(script[1]); } else fprintf(stderr,"DecodeMaramaraCoinbaseOpRet unmarshal error for C\n"); } else fprintf(stderr,"script[1] is %d != 'C' %d\n",script[1],'C'); - } else fprintf(stderr,"vopret.size() is %d [0] is %d != %d\n",(int32_t)vopret.size(),script[0],EVAL_MARMARA); + } else fprintf(stderr,"vopret.size() is %d\n",(int32_t)vopret.size()); return(0); } From cf2251127a9044097fbf667bb71b6d5336f1f34d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 02:03:53 -1100 Subject: [PATCH 165/643] +prints --- src/cc/marmara.cpp | 1 + src/miner.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 9cb9ce813..d69585046 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -139,6 +139,7 @@ CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) CScript MarmaraCoinbaseOpret(int32_t height,CPubKey pk) { uint8_t *ptr; + fprintf(stderr,"height.%d pksize.%d\n",height,(int32_t)pk.size()); if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) return(EncodeMarmaraCoinbaseOpRet(pk,height)); return(CScript()); diff --git a/src/miner.cpp b/src/miner.cpp index 51078f963..62eb46f69 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -167,6 +167,7 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, txnouttype txT; if ( scriptPubKeyIn.size() > 0 && Solver(scriptPubKeyIn, txT, vAddrs)) { + fprintf(stderr,"txT.%d vs TX_PUBKEY.%d\n",txT,TX_PUBKEY); if (txT == TX_PUBKEY) pk = CPubKey(vAddrs[0]); } From a06cbd09ae778f953d9e441de36a088ed2cc1684 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 02:10:49 -1100 Subject: [PATCH 166/643] Pass in _pk to CreateBlock --- src/miner.cpp | 23 +++++++++++++---------- src/miner.h | 2 +- src/test/miner_tests.cpp | 26 +++++++++++++------------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 62eb46f69..c6df5cdb6 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -158,19 +158,22 @@ int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); CScript Marmara_scriptPubKey(int32_t height,CPubKey pk); CScript MarmaraCoinbaseOpret(int32_t height,CPubKey pk); -CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake) +CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake) { CScript scriptPubKeyIn(_scriptPubKeyIn); - CPubKey pk = CPubKey(); - std::vector> vAddrs; - txnouttype txT; - if ( scriptPubKeyIn.size() > 0 && Solver(scriptPubKeyIn, txT, vAddrs)) + CPubKey pk; + if ( _pk.size() != 33 ) { - fprintf(stderr,"txT.%d vs TX_PUBKEY.%d\n",txT,TX_PUBKEY); - if (txT == TX_PUBKEY) - pk = CPubKey(vAddrs[0]); - } + pk = CPubKey(); + std::vector> vAddrs; + txnouttype txT; + if ( scriptPubKeyIn.size() > 0 && Solver(scriptPubKeyIn, txT, vAddrs)) + { + if (txT == TX_PUBKEY) + pk = CPubKey(vAddrs[0]); + } + } else pk = _pk; uint64_t deposits; int32_t isrealtime,kmdheight; uint32_t blocktime; const CChainParams& chainparams = Params(); //fprintf(stderr,"create new block\n"); @@ -790,7 +793,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, } if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) scriptPubKey = Marmara_scriptPubKey(nHeight,pubkey); - return CreateNewBlock(scriptPubKey, gpucount, isStake); + return CreateNewBlock(pubkey,scriptPubKey, gpucount, isStake); } void komodo_broadcast(CBlock *pblock,int32_t limit) diff --git a/src/miner.h b/src/miner.h index 5494022bd..a3bedd292 100644 --- a/src/miner.h +++ b/src/miner.h @@ -43,7 +43,7 @@ struct CBlockTemplate #define KOMODO_MAXGPUCOUNT 65 /** Generate a new block, without valid proof-of-work */ -CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, int32_t gpucount, bool isStake = false); +CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& scriptPubKeyIn, int32_t gpucount, bool isStake = false); #ifdef ENABLE_WALLET boost::optional GetMinerScriptPubKey(CReserveKey& reservekey); CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, int32_t gpucount, bool isStake = false); diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp index 6d80fc4b7..277b726c8 100644 --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -158,7 +158,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) for (unsigned int i = 0; i < sizeof(blockinfo)/sizeof(*blockinfo); ++i) { // Simple block creation, nothing special yet: - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); CBlock *pblock = &pblocktemplate->block; // pointer for convenience pblock->nVersion = 4; @@ -273,7 +273,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) } // Just to make sure we can still make simple blocks - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; // block sigops > limit: 1000 CHECKMULTISIG + 1 @@ -292,7 +292,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(spendsCoinbase).FromTx(tx)); tx.vin[0].prevout.hash = hash; } - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; mempool.clear(); @@ -313,14 +313,14 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(spendsCoinbase).FromTx(tx)); tx.vin[0].prevout.hash = hash; } - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; mempool.clear(); // orphan in mempool hash = tx.GetHash(); mempool.addUnchecked(hash, entry.Time(GetTime()).FromTx(tx)); - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; mempool.clear(); @@ -338,7 +338,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) tx.vout[0].nValue = 49000LL; hash = tx.GetHash(); mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; mempool.clear(); @@ -349,7 +349,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) tx.vout[0].nValue = 0; hash = tx.GetHash(); mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(false).FromTx(tx)); - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; mempool.clear(); @@ -367,7 +367,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) tx.vout[0].nValue -= 10000; hash = tx.GetHash(); mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(false).FromTx(tx)); - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; mempool.clear(); @@ -381,17 +381,17 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) tx.vout[0].scriptPubKey = CScript() << OP_2; hash = tx.GetHash(); mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; mempool.clear(); // subsidy changing int nHeight = chainActive.Height(); chainActive.Tip()->SetHeight(209999); - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; chainActive.Tip()->SetHeight(210000); - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; chainActive.Tip()->SetHeight(nHeight); @@ -423,7 +423,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(true).FromTx(tx2)); BOOST_CHECK(!CheckFinalTx(tx2, LOCKTIME_MEDIAN_TIME_PAST)); - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); // Neither tx should have made it into the template. BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 1); @@ -438,7 +438,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) //BOOST_CHECK(CheckFinalTx(tx)); //BOOST_CHECK(CheckFinalTx(tx2)); - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 2); delete pblocktemplate; From 5a8af74e4ddc92784747ce5dbe7497ec4cd3c977 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 02:13:18 -1100 Subject: [PATCH 167/643] Include pubkey.h --- src/miner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/miner.cpp b/src/miner.cpp index c6df5cdb6..35ba20798 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -24,6 +24,7 @@ #endif #include "amount.h" +#include "pubkey.h" #include "chainparams.h" #include "importcoin.h" #include "consensus/consensus.h" From ad0842336bf9c45ea11e44c4170ba1e25de0bf17 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 02:13:32 -1100 Subject: [PATCH 168/643] First --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 35ba20798..fb9ed8820 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -18,13 +18,13 @@ * * ******************************************************************************/ +#include "pubkey.h" #include "miner.h" #ifdef ENABLE_MINING #include "pow/tromp/equi_miner.h" #endif #include "amount.h" -#include "pubkey.h" #include "chainparams.h" #include "importcoin.h" #include "consensus/consensus.h" From 0638d3b056c04e949004f0e5e3b2614a58604117 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 02:18:55 -1100 Subject: [PATCH 169/643] Map all unlock hts in group to same unlockht --- src/cc/marmara.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index d69585046..8cd949981 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -83,6 +83,7 @@ int32_t MarmaraRandomize(uint32_t ind) int32_t MarmaraUnlockht(int32_t height) { uint32_t ind = height / MARMARA_GROUPSIZE; + height = (height / MARMARA_GROUPSIZE) * MARMARA_GROUPSIZE; return(height + MarmaraRandomize(ind)); } @@ -91,6 +92,7 @@ CScript EncodeMarmaraCoinbaseOpRet(CPubKey pk,int32_t ht) CScript opret; int32_t unlockht; uint8_t evalcode = EVAL_MARMARA; unlockht = MarmaraUnlockht(ht); opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'C' << pk << ht << unlockht); + if ( 0 ) { std::vector vopret; uint8_t *script,i; GetOpReturnData(opret,vopret); @@ -109,6 +111,7 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int3 std::vector vopret; uint8_t *script,e,f,funcid; GetOpReturnData(scriptPubKey,vopret); script = (uint8_t *)vopret.data(); + if ( 0 ) { int32_t i; for (i=0; i 0 && (height & 1) == 0 && pk.size() == 33 ) return(EncodeMarmaraCoinbaseOpRet(pk,height)); return(CScript()); @@ -149,10 +152,13 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { struct CCcontract_info *cp,C; CPubKey pk; int32_t ht,unlockht; CTxOut ccvout; cp = CCinit(&C,EVAL_MARMARA); - if ( 0 ) + if ( 1 ) { int32_t d,histo[365*2+30]; memset(histo,0,sizeof(histo)); + for (ht=2; ht<100; ht++) + fprintf(stderr,"%d ",MarmaraUnlockht(ht)); + fprintf(stderr," <- first 100 unlock heights\n"); for (ht=2; ht<1000000; ht+=MARMARA_GROUPSIZE) { d = (MarmaraUnlockht(ht) - ht) / 1440; From f3b0e439c38e96396720ebe03d8e83c0a73340c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 02:21:32 -1100 Subject: [PATCH 170/643] Test --- src/cc/marmara.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 8cd949981..3c011ec02 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -152,7 +152,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { struct CCcontract_info *cp,C; CPubKey pk; int32_t ht,unlockht; CTxOut ccvout; cp = CCinit(&C,EVAL_MARMARA); - if ( 1 ) + if ( 0 ) { int32_t d,histo[365*2+30]; memset(histo,0,sizeof(histo)); @@ -178,6 +178,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { if ( ht == height && MarmaraUnlockht(height) == unlockht ) { + fprintf(stderr,"ht.%d -> unlock.%d\n",ht,unlockht); ccvout = MakeCC1vout(EVAL_MARMARA,0,pk); if ( ccvout.scriptPubKey == tx.vout[0].scriptPubKey ) return(0); From a0c16d089ac51644e0a25c7cf09458b6851d583e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 06:20:30 -1100 Subject: [PATCH 171/643] MarmaraPoolPayout --- src/cc/CCMarmara.h | 1 + src/cc/marmara.cpp | 132 ++++++++++++++++++++++++++++++++++++--------- 2 files changed, 108 insertions(+), 25 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 5fc7fd673..15a8f811f 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -23,6 +23,7 @@ #define MARMARA_MINLOCK (1440 * 3 * 30) #define MARMARA_MAXLOCK (1440 * 24 * 30) uint64_t komodo_block_prg(uint32_t nHeight); +UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKey poolpk,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...] bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 3c011ec02..2167c1364 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -87,11 +87,11 @@ int32_t MarmaraUnlockht(int32_t height) return(height + MarmaraRandomize(ind)); } -CScript EncodeMarmaraCoinbaseOpRet(CPubKey pk,int32_t ht) +CScript EncodeMarmaraCoinbaseOpRet(uint8_t funcid,CPubKey pk,int32_t ht) { CScript opret; int32_t unlockht; uint8_t evalcode = EVAL_MARMARA; unlockht = MarmaraUnlockht(ht); - opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'C' << pk << ht << unlockht); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << pk << ht << unlockht); if ( 0 ) { std::vector vopret; uint8_t *script,i; @@ -100,13 +100,13 @@ CScript EncodeMarmaraCoinbaseOpRet(CPubKey pk,int32_t ht) { for (i=0; i vopret; uint8_t *script,e,f,funcid; GetOpReturnData(scriptPubKey,vopret); @@ -120,13 +120,13 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int3 } if ( vopret.size() > 2 && script[0] == EVAL_MARMARA ) { - if ( script[1] == 'C' ) + if ( script[1] == 'C' || script[1] == 'P' ) { if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> pk; ss >> height; ss >> unlockht) != 0 ) { return(script[1]); - } else fprintf(stderr,"DecodeMaramaraCoinbaseOpRet unmarshal error for C\n"); - } else fprintf(stderr,"script[1] is %d != 'C' %d\n",script[1],'C'); + } else fprintf(stderr,"DecodeMaramaraCoinbaseOpRet unmarshal error for %c\n",script[1]); + } else fprintf(stderr,"script[1] is %d != 'C' %d or 'P' %d\n",script[1],'C','P'); } else fprintf(stderr,"vopret.size() is %d\n",(int32_t)vopret.size()); return(0); } @@ -144,7 +144,7 @@ CScript MarmaraCoinbaseOpret(int32_t height,CPubKey pk) uint8_t *ptr; //fprintf(stderr,"height.%d pksize.%d\n",height,(int32_t)pk.size()); if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) - return(EncodeMarmaraCoinbaseOpRet(pk,height)); + return(EncodeMarmaraCoinbaseOpRet('C',pk,height)); return(CScript()); } @@ -230,29 +230,31 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t // helper functions for rpc calls in rpcwallet.cpp -int64_t AddMarmaraInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx,int32_t firstheight,CPubKey poolpk,int32_t maxinputs) { - // add threshold check - char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; + char coinaddr[64]; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction vintx; int32_t unlockht,ht,vout,unlocks,n = 0; std::vector > unspentOutputs; - GetCCaddress(cp,coinaddr,pk); + GetCCaddress(cp,coinaddr,poolpk); SetCCunspents(unspentOutputs,coinaddr); + unlocks = MarmaraUnlockHt(firstheight); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; - // no need to prevent dup - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + if ( GetTransaction(txid,vintx,hashBlock,false) != 0 && vintx.IsCoinBase() != 0 ) { - if ( (nValue= IsMarmaravout(cp,vintx,vout)) > 1000000 && myIsutxo_spentinmempool(txid,vout) == 0 ) + if ( DecodeMaramaraCoinbaseOpRet(vintx.vout[1].scriptPubKey,pk,ht,unlockht) == 'C' && unlockht == unlocks && pk == poolpk ) { - if ( total != 0 && maxinputs != 0 ) - mtx.vin.push_back(CTxIn(txid,vout,CScript())); - nValue = it->second.satoshis; - totalinputs += nValue; - n++; - if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) - break; + if ( (nValue= IsMarmaravout(cp,vintx,vout)) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + { + if ( maxinputs != 0 ) + mtx.vin.push_back(CTxIn(txid,vout,CScript())); + nValue = it->second.satoshis; + totalinputs += nValue; + n++; + if ( maxinputs > 0 && n >= maxinputs ) + break; + } } } } @@ -326,9 +328,89 @@ UniValue MarmaraInfo() result.push_back(Pair("name","Marmara")); cp = CCinit(&C,EVAL_MARMARA); Marmarapk = GetUnspendable(cp,0); - funding = AddMarmaraInputs(cp,mtx,Marmarapk,0,0); - sprintf(numstr,"%.8f",(double)funding/COIN); - result.push_back(Pair("funding",numstr)); + return(result); +} + +UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKey poolpk,char *jsonstr) // [[pk0, shares0], [pk1, shares1], ...] +{ + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + UniValue result(UniValue::VOBJ); cJSON *item,*array; std::string res; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk; int64_t payout,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; + if ( pubkey2pk(Mypubkey()) != poolpk ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","poolpk is not your pubkey")); + return(result); + } + if ( txfee == 0 ) + txfee = 10000; + cp = CCinit(&C,EVAL_MARMARA); + Marmarapk = GetUnspendable(cp,0); + if ( (array= cJSON_Parse(jsonstr)) != 0 && (n= cJSON_GetArraySize(array)) > 0 ) + { + for (i=0; i SMALLVAL ) + { + shares += shares * perc; + if ( (total= AddMarmaraCoinbases(cp,mtx,firstheight,poolpk,60)) > 0 ) + { + for (i=0; i SMALLVAL ) + { + payout = (share * (total - txfee)) / shares; + if ( payout > 0 ) + { + if ( (pkstr= jstr(jitem(item,0))) != 0 && strlen(pkstr) == 66 ) + { + totalpayout += payout; + decode_hex(buf,33,pkstr); + mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,payout,Marmarapk,buf2pk(buf))); + } + } + } + } + if ( totalpayout > 0 && total > totalpayout-txfee ) + { + mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,total - totalpayout - txfee,Marmarapk,poolpk)); + } + rawtx = FinalizeCCTx(0,cp,mtx,poolpk,txfee,MarmaraCoinbaseOpret('P',height,poolpk))); + if ( rawtx.size() == 0 ) + errorstr = "couldnt finalize CCtx"; + } else errorstr = "couldnt find any coinbases to payout"; + } + else if ( errorstr == 0 ) + errorstr = "no valid shares submitted"; + free(array); + } else errorstr = "couldnt parse poolshares jsonstr"; + if ( rawtx.size() == 0 || errorstr != 0 ) + { + result.push_back(Pair("result","error")); + if ( errorstr != 0 ) + result.push_back(Pair("error",errorstr)); + } + else + { + result.push_back(Pair("result","success")); + result.push_back(Pair("rawtx",rawtx)); + if ( totalpayout > 0 && total > totalpayout-txfee ) + { + result.push_back(Pair("totalpayout",(double)totalpayout/COIN)); + result.push_back(Pair("totalshares",shares)); + result.push_back(Pair("poolfee",(double)(total - totalpayout)/COIN)); + result.push_back(Pair("perc",100. * (double)(total - totalpayout)/totalpayout)); + } + } return(result); } From a36f051e0c4c88f089d2632f2355fc6973eee7dd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 06:23:32 -1100 Subject: [PATCH 172/643] cJSON.h --- src/cc/CCMarmara.h | 1 + src/cc/marmara.cpp | 18 +++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 15a8f811f..a5f816fbe 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -18,6 +18,7 @@ #define CC_TRIGGERS_H #include "CCinclude.h" +#include "../cJSON.h" #define MARMARA_GROUPSIZE 60 #define MARMARA_MINLOCK (1440 * 3 * 30) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 2167c1364..8f3ec46c7 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -232,11 +232,11 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx,int32_t firstheight,CPubKey poolpk,int32_t maxinputs) { - char coinaddr[64]; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction vintx; int32_t unlockht,ht,vout,unlocks,n = 0; + char coinaddr[64]; CPubKey pk; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction vintx; int32_t unlockht,ht,vout,unlocks,n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,poolpk); SetCCunspents(unspentOutputs,coinaddr); - unlocks = MarmaraUnlockHt(firstheight); + unlocks = MarmaraUnlockht(firstheight); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; @@ -334,7 +334,7 @@ UniValue MarmaraInfo() UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKey poolpk,char *jsonstr) // [[pk0, shares0], [pk1, shares1], ...] { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); cJSON *item,*array; std::string res; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk; int64_t payout,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk; int64_t payout,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; if ( pubkey2pk(Mypubkey()) != poolpk ) { result.push_back(Pair("result","error")); @@ -354,7 +354,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKe shares += jdouble(jitem(item,1),0); else { - errorstr = "all items must be of the form [, ]"; + errorstr = (char *)"all items must be of the form [, ]"; break; } } @@ -386,13 +386,13 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKe } rawtx = FinalizeCCTx(0,cp,mtx,poolpk,txfee,MarmaraCoinbaseOpret('P',height,poolpk))); if ( rawtx.size() == 0 ) - errorstr = "couldnt finalize CCtx"; - } else errorstr = "couldnt find any coinbases to payout"; + errorstr = (char *)"couldnt finalize CCtx"; + } else errorstr = (char *)"couldnt find any coinbases to payout"; } else if ( errorstr == 0 ) - errorstr = "no valid shares submitted"; + errorstr = (char *)"no valid shares submitted"; free(array); - } else errorstr = "couldnt parse poolshares jsonstr"; + } else errorstr = (char *)"couldnt parse poolshares jsonstr"; if ( rawtx.size() == 0 || errorstr != 0 ) { result.push_back(Pair("result","error")); @@ -401,7 +401,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKe } else { - result.push_back(Pair("result","success")); + result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); if ( totalpayout > 0 && total > totalpayout-txfee ) { From f9f1452336c235f9932664ffba55abd12a6b0077 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 06:26:34 -1100 Subject: [PATCH 173/643] komodo_cJSON.h --- src/cc/CCMarmara.h | 2 +- src/cc/marmara.cpp | 41 ----------------------------------------- 2 files changed, 1 insertion(+), 42 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index a5f816fbe..b25f73f4b 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -18,7 +18,7 @@ #define CC_TRIGGERS_H #include "CCinclude.h" -#include "../cJSON.h" +#include "../komodo_cJSON.h" #define MARMARA_GROUPSIZE 60 #define MARMARA_MINLOCK (1440 * 3 * 30) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 8f3ec46c7..f04941da3 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -261,47 +261,6 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, return(totalinputs); } -std::string MarmaraGet(uint64_t txfee,int64_t nValue) -{ - CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Marmarapk; int64_t inputs,CCchange=0; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; - cp = CCinit(&C,EVAL_MARMARA); - if ( txfee == 0 ) - txfee = 10000; - Marmarapk = GetUnspendable(cp,0); - mypk = pubkey2pk(Mypubkey()); - if ( (inputs= AddMarmaraInputs(cp,mtx,Marmarapk,nValue+txfee,60)) > 0 ) - { - if ( inputs > nValue ) - CCchange = (inputs - nValue - txfee); - if ( CCchange != 0 ) - mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,CCchange,Marmarapk)); - mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - fprintf(stderr,"start at %u\n",(uint32_t)time(NULL)); - j = rand() & 0xfffffff; - for (i=0; i<1000000; i++,j++) - { - tmpmtx = mtx; - rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_MARMARA << (uint8_t)'G' << j)); - if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 ) - { - len >>= 1; - decode_hex(buf,len,(char *)rawhex.c_str()); - hash = bits256_doublesha256(0,buf,len); - if ( (hash.bytes[0] & 0xff) == 0 && (hash.bytes[31] & 0xff) == 0 ) - { - fprintf(stderr,"found valid txid after %d iterations %u\n",i,(uint32_t)time(NULL)); - return(rawhex); - } - //fprintf(stderr,"%02x%02x ",hash.bytes[0],hash.bytes[31]); - } - } - fprintf(stderr,"couldnt generate valid txid %u\n",(uint32_t)time(NULL)); - return(""); - } else fprintf(stderr,"cant find Marmara inputs\n"); - return(""); -} - std::string MarmaraFund(uint64_t txfee,int64_t funds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); From 38705bdb2168e0cc4a328a618524ec43d6f7bceb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 06:28:04 -1100 Subject: [PATCH 174/643] Syntax --- src/cc/marmara.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index f04941da3..5e9706ca9 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -309,7 +309,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKe for (i=0; i 0 ) { - if ( (pkstr= jstr(jitem(item,0))) != 0 && strlen(pkstr) == 66 ) + if ( (pkstr= jstr(jitem(item,0),0)) != 0 && strlen(pkstr) == 66 ) { totalpayout += payout; decode_hex(buf,33,pkstr); @@ -343,7 +343,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKe { mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,total - totalpayout - txfee,Marmarapk,poolpk)); } - rawtx = FinalizeCCTx(0,cp,mtx,poolpk,txfee,MarmaraCoinbaseOpret('P',height,poolpk))); + rawtx = FinalizeCCTx(0,cp,mtx,poolpk,txfee,MarmaraCoinbaseOpret('P',firstheight,poolpk))); if ( rawtx.size() == 0 ) errorstr = (char *)"couldnt finalize CCtx"; } else errorstr = (char *)"couldnt find any coinbases to payout"; From ee21bd6bc8156e99b3eeb76ef4c552b4b0e19db9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 06:31:29 -1100 Subject: [PATCH 175/643] Coinbaseopret --- src/cc/marmara.cpp | 4 ++-- src/miner.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 5e9706ca9..6ba46dc8f 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -139,12 +139,12 @@ CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) return(ccvout.scriptPubKey); } -CScript MarmaraCoinbaseOpret(int32_t height,CPubKey pk) +CScript MarmaraCoinbaseOpret(uint8_t funcid,int32_t height,CPubKey pk) { uint8_t *ptr; //fprintf(stderr,"height.%d pksize.%d\n",height,(int32_t)pk.size()); if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) - return(EncodeMarmaraCoinbaseOpRet('C',pk,height)); + return(EncodeMarmaraCoinbaseOpRet(funcid,pk,height)); return(CScript()); } diff --git a/src/miner.cpp b/src/miner.cpp index fb9ed8820..5ea5aafe0 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -157,7 +157,7 @@ int32_t verus_staked(CBlock *pBlock, CMutableTransaction &txNew, uint32_t &nBits int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33); int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); CScript Marmara_scriptPubKey(int32_t height,CPubKey pk); -CScript MarmaraCoinbaseOpret(int32_t height,CPubKey pk); +CScript MarmaraCoinbaseOpret(uint8_t funcid,int32_t height,CPubKey pk); CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake) { @@ -545,7 +545,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 { txNew.vout.resize(2); txNew.vout[1].nValue = 0; - txNew.vout[1].scriptPubKey = MarmaraCoinbaseOpret(nHeight,pk); + txNew.vout[1].scriptPubKey = MarmaraCoinbaseOpret('C',nHeight,pk); } else if ((uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE) { From 386286c95d7220174ef1a838db0c2a09639d7b82 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 06:47:18 -1100 Subject: [PATCH 176/643] +prints --- src/komodo_bitcoind.h | 8 ++++---- src/komodo_utils.h | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index c6eb05324..00ce20853 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1721,10 +1721,10 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) matched = 25; if ( matched == 0 ) { - //int32_t i; - //for (i=0; i<25; i++) - // fprintf(stderr,"%02x",script[i]); - //fprintf(stderr," payment to wrong pubkey scriptlen.%d, scriptpub[%d]\n",scriptlen,(int32_t)ASSETCHAINS_SCRIPTPUB.size()/2); + int32_t i; + for (i=0; i 1 && ASSETCHAINS_MARMARA != 0 ) + { + fprintf(stderr,"-ac_script and -ac_marmara are mutually exclusive\n"); + exit(0); + } if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 ) { fprintf(stderr,"perc %.4f%% ac_pub=[%02x%02x%02x...] acsize.%d\n",dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0],ASSETCHAINS_OVERRIDE_PUBKEY33[1],ASSETCHAINS_OVERRIDE_PUBKEY33[2],(int32_t)ASSETCHAINS_SCRIPTPUB.size()); From b02113975d8ca9be2a1d122b0649e6f6d4043bf0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 06:48:09 -1100 Subject: [PATCH 177/643] -) --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 6ba46dc8f..bdd7b2be7 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -343,7 +343,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKe { mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,total - totalpayout - txfee,Marmarapk,poolpk)); } - rawtx = FinalizeCCTx(0,cp,mtx,poolpk,txfee,MarmaraCoinbaseOpret('P',firstheight,poolpk))); + rawtx = FinalizeCCTx(0,cp,mtx,poolpk,txfee,MarmaraCoinbaseOpret('P',firstheight,poolpk)); if ( rawtx.size() == 0 ) errorstr = (char *)"couldnt finalize CCtx"; } else errorstr = (char *)"couldnt find any coinbases to payout"; From dda3ecd759fdae1216ad653bd1f85c25fe4f408a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 06:58:58 -1100 Subject: [PATCH 178/643] Connect marmara_poolpayout --- src/cc/CCMarmara.h | 2 +- src/cc/marmara.cpp | 11 +++-------- src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/wallet/rpcwallet.cpp | 13 +++++++++++++ 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index b25f73f4b..4a50c2539 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -24,7 +24,7 @@ #define MARMARA_MINLOCK (1440 * 3 * 30) #define MARMARA_MAXLOCK (1440 * 24 * 30) uint64_t komodo_block_prg(uint32_t nHeight); -UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKey poolpk,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...] +UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...] bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index bdd7b2be7..bce201383 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -290,16 +290,11 @@ UniValue MarmaraInfo() return(result); } -UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKey poolpk,char *jsonstr) // [[pk0, shares0], [pk1, shares1], ...] +UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr) // [[pk0, shares0], [pk1, shares1], ...] { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk; int64_t payout,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; - if ( pubkey2pk(Mypubkey()) != poolpk ) - { - result.push_back(Pair("result","error")); - result.push_back(Pair("error","poolpk is not your pubkey")); - return(result); - } + UniValue result(UniValue::VOBJ); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk,poolpk; int64_t payout,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; + poolpk = pubkey2pk(Mypubkey()); if ( txfee == 0 ) txfee = 10000; cp = CCinit(&C,EVAL_MARMARA); diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 1a932382e..56b32c837 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -443,6 +443,7 @@ static const CRPCCommand vRPCCommands[] = // Marmara { "marmara", "Marmaraaddress", &marmaraaddress, true }, + { "marmara", "Marmarapoolpayout", &marmara_poolpayout, true }, // Payments { "payments", "paymentsaddress", &paymentsaddress, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 5bdf62799..bd00bb9d1 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -272,6 +272,7 @@ extern UniValue pricesstatus(const UniValue& params, bool fHelp); extern UniValue pricesfinish(const UniValue& params, bool fHelp); extern UniValue pegsaddress(const UniValue& params, bool fHelp); extern UniValue marmaraaddress(const UniValue& params, bool fHelp); +extern UniValue marmara_poolpayout(const UniValue& params, bool fHelp); extern UniValue paymentsaddress(const UniValue& params, bool fHelp); extern UniValue gatewaysaddress(const UniValue& params, bool fHelp); extern UniValue gatewayslist(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 79710969a..36e23c93d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5531,6 +5531,19 @@ UniValue tokenaddress(const UniValue& params, bool fHelp) return(CCaddress(cp,(char *)"Assets",pubkey)); } +UniValue marmara_poolpayout(const UniValue& params, bool fHelp) +{ + int32_t firstheight; double perc; char *jsonstr; + if ( fHelp || params.size() != 3 ) + throw runtime_error("marmara_poolpayout perc firstheight \"[[pubkey:shares], ...]\"\n"); + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + perc = atof(params[0].get_str().c_str()) / 100.; + firstheight = atol(params[1].get_str().c_str()); + jsonstr = (char *)params[2].get_str().c_str(); + return(MarmaraPoolPayout(0,firstheight,perc,jsonstr)); // [[pk0, shares0], [pk1, shares1], ...] +} + UniValue channelslist(const UniValue& params, bool fHelp) { if ( fHelp || params.size() > 0 ) From 45096107db5fa0104989c9b1105e4a71ebb1e4ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 07:24:19 -1100 Subject: [PATCH 179/643] Test --- src/komodo_bitcoind.h | 3 ++- src/miner.cpp | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 00ce20853..b6173def9 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1704,7 +1704,8 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) return(-1); else*/ if ( checktoshis != 0 ) { - script = (uint8_t *)&pblock->vtx[0].vout[1].scriptPubKey[0]; + //script = (uint8_t *)&pblock->vtx[0].vout[1].scriptPubKey[0]; + script = (uint8_t *)pblock->vtx[0].vout[1].scriptPubKey.data(); scriptlen = (int32_t)pblock->vtx[0].vout[1].scriptPubKey.size(); if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) { diff --git a/src/miner.cpp b/src/miner.cpp index 5ea5aafe0..bdbf7a570 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -589,8 +589,12 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 ptr = (uint8_t *)&txNew.vout[1].scriptPubKey[0]; ptr[0] = 33; for (i=0; i<33; i++) + { ptr[i+1] = ASSETCHAINS_OVERRIDE_PUBKEY33[i]; + fprintf(stderr,"%02x",ptr[i+1]); + } ptr[34] = OP_CHECKSIG; + fprintf(stderr," set ASSETCHAINS_OVERRIDE_PUBKEY33 into vout[1]\n"); } //printf("autocreate commision vout\n"); } From bbc8c98e7180a35287bc699b6595807010dd9ac6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 07:26:24 -1100 Subject: [PATCH 180/643] Syntax --- src/komodo_bitcoind.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b6173def9..00ce20853 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1704,8 +1704,7 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) return(-1); else*/ if ( checktoshis != 0 ) { - //script = (uint8_t *)&pblock->vtx[0].vout[1].scriptPubKey[0]; - script = (uint8_t *)pblock->vtx[0].vout[1].scriptPubKey.data(); + script = (uint8_t *)&pblock->vtx[0].vout[1].scriptPubKey[0]; scriptlen = (int32_t)pblock->vtx[0].vout[1].scriptPubKey.size(); if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) { From 18c82335b59c122e76e5f9f81c8208e1083d0cc6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 07:34:05 -1100 Subject: [PATCH 181/643] Test --- src/komodo_bitcoind.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 00ce20853..1b8bb85b0 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1699,13 +1699,19 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) if ( ASSETCHAINS_COMMISSION != 0 ) { checktoshis = komodo_commission(pblock,height); - //fprintf(stderr,"height.%d commission %.8f\n",height,(double)checktoshis/COIN); - /*if ( checktoshis > 10000 && pblock->vtx[0].vout.size() != 2 ) jl777: not sure why this was here + if ( checktoshis >= 10000 && pblock->vtx[0].vout.size() < 2 ) + { + fprintf(stderr,"komodo_checkcommission vsize.%d height.%d commission %.8f\n",(int32_t)pblock->vtx[0].vout.size(),height,(double)checktoshis/COIN); return(-1); - else*/ if ( checktoshis != 0 ) + } + else if ( checktoshis != 0 ) { script = (uint8_t *)&pblock->vtx[0].vout[1].scriptPubKey[0]; scriptlen = (int32_t)pblock->vtx[0].vout[1].scriptPubKey.size(); + int32_t i; + for (i=0; ivtx[0].vout[1].nValue/COIN)); if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) { if ( ASSETCHAINS_SCRIPTPUB.size()/2 == scriptlen && scriptlen < sizeof(scripthex) ) @@ -1721,9 +1727,6 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) matched = 25; if ( matched == 0 ) { - int32_t i; - for (i=0; ivtx[0].vout[0].scriptPubKey[0]; - if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) + scriptlen = (int32_t)pblock->vtx[0].vout[0].scriptPubKey.size(); + if ( scriptlen != 35 || script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) return(-1); } } From 36a74b8d2787ba7ee5ab2976daa33e94c1cf0090 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 07:34:48 -1100 Subject: [PATCH 182/643] -) --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1b8bb85b0..a36e1f744 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1711,7 +1711,7 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) int32_t i; for (i=0; ivtx[0].vout[1].nValue/COIN)); + fprintf(stderr," vout[1] %.8f vs %.8f\n",(double)checktoshis/COIN,(double)pblock->vtx[0].vout[1].nValue/COIN); if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) { if ( ASSETCHAINS_SCRIPTPUB.size()/2 == scriptlen && scriptlen < sizeof(scripthex) ) From 43cbde9fe4f46baf17f6a6618c13e2f60a07cfed Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 07:35:50 -1100 Subject: [PATCH 183/643] scriptlen --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index a36e1f744..341ee49e2 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1745,7 +1745,7 @@ bool KOMODO_TEST_ASSETCHAIN_SKIP_POW = 0; int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) { - uint256 hash; arith_uint256 bnTarget,bhash; bool fNegative,fOverflow; uint8_t *script,pubkey33[33],pubkeys[64][33]; int32_t i,possible,PoSperc,is_PoSblock=0,n,failed = 0,notaryid = -1; int64_t checktoshis,value; CBlockIndex *pprev; + uint256 hash; arith_uint256 bnTarget,bhash; bool fNegative,fOverflow; uint8_t *script,pubkey33[33],pubkeys[64][33]; int32_t i,scriptlen,possible,PoSperc,is_PoSblock=0,n,failed = 0,notaryid = -1; int64_t checktoshis,value; CBlockIndex *pprev; if ( KOMODO_TEST_ASSETCHAIN_SKIP_POW == 0 && Params().NetworkIDString() == "regtest" ) KOMODO_TEST_ASSETCHAIN_SKIP_POW = 1; if ( !CheckEquihashSolution(pblock, Params()) ) From e3110f16fb9b75524cb11688d67d6cad8068dc37 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 07:41:26 -1100 Subject: [PATCH 184/643] Change priority of mining ac_variants --- src/miner.cpp | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index bdbf7a570..5bf230050 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -547,28 +547,6 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 txNew.vout[1].nValue = 0; txNew.vout[1].scriptPubKey = MarmaraCoinbaseOpret('C',nHeight,pk); } - else if ((uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE) - { - int32_t opretlen, p2shlen, scriptlen; - CScriptExt opretScript = CScriptExt(); - - txNew.vout.resize(2); - - // prepend time lock to original script unless original script is P2SH, in which case, we will leave the coins - // protected only by the time lock rather than 100% inaccessible - opretScript.AddCheckLockTimeVerify(komodo_block_unlocktime(nHeight)); - if (scriptPubKeyIn.IsPayToScriptHash() || scriptPubKeyIn.IsPayToCryptoCondition()) - { - fprintf(stderr,"CreateNewBlock: attempt to add timelock to pay2sh or pay2cc\n"); - return 0; - } - - opretScript += scriptPubKeyIn; - - txNew.vout[0].scriptPubKey = CScriptExt().PayToScriptHash(CScriptID(opretScript)); - txNew.vout[1].scriptPubKey = CScriptExt().OpReturnScript(opretScript, OPRETTYPE_TIMELOCK); - txNew.vout[1].nValue = 0; - } // timelocks and commissions are currently incompatible due to validation complexity of the combination else if ( nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0 ) { int32_t i; uint8_t *ptr; @@ -598,6 +576,28 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 } //printf("autocreate commision vout\n"); } + else if ((uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE) + { + int32_t opretlen, p2shlen, scriptlen; + CScriptExt opretScript = CScriptExt(); + + txNew.vout.resize(2); + + // prepend time lock to original script unless original script is P2SH, in which case, we will leave the coins + // protected only by the time lock rather than 100% inaccessible + opretScript.AddCheckLockTimeVerify(komodo_block_unlocktime(nHeight)); + if (scriptPubKeyIn.IsPayToScriptHash() || scriptPubKeyIn.IsPayToCryptoCondition()) + { + fprintf(stderr,"CreateNewBlock: attempt to add timelock to pay2sh or pay2cc\n"); + return 0; + } + + opretScript += scriptPubKeyIn; + + txNew.vout[0].scriptPubKey = CScriptExt().PayToScriptHash(CScriptID(opretScript)); + txNew.vout[1].scriptPubKey = CScriptExt().OpReturnScript(opretScript, OPRETTYPE_TIMELOCK); + txNew.vout[1].nValue = 0; + } // timelocks and commissions are currently incompatible due to validation complexity of the combination pblock->vtx[0] = txNew; pblocktemplate->vTxFees[0] = -nFees; From 6f345c4ed1e0247a148df575756ec062a12ad743 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 07:48:13 -1100 Subject: [PATCH 185/643] +prints --- src/komodo_bitcoind.h | 10 +++++----- src/miner.cpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 341ee49e2..c647b1692 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1162,7 +1162,7 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) n = pblock->vtx[i].vout.size(); for (j=0; jvtx[i].vout[j].nValue; } @@ -1708,10 +1708,10 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) { script = (uint8_t *)&pblock->vtx[0].vout[1].scriptPubKey[0]; scriptlen = (int32_t)pblock->vtx[0].vout[1].scriptPubKey.size(); - int32_t i; - for (i=0; ivtx[0].vout[1].nValue/COIN); + //int32_t i; + //for (i=0; ivtx[0].vout[1].nValue/COIN); if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) { if ( ASSETCHAINS_SCRIPTPUB.size()/2 == scriptlen && scriptlen < sizeof(scripthex) ) diff --git a/src/miner.cpp b/src/miner.cpp index 5bf230050..dc476b4c3 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -576,7 +576,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 } //printf("autocreate commision vout\n"); } - else if ((uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE) + else if ( (uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE) { int32_t opretlen, p2shlen, scriptlen; CScriptExt opretScript = CScriptExt(); From 8ffe7c1119f6a8b3bf3aba589be0ca5bc2280b46 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 07:48:58 -1100 Subject: [PATCH 186/643] Block --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index c647b1692..64faa28bc 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1162,7 +1162,7 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) n = pblock->vtx[i].vout.size(); for (j=0; jvtx[i].vout[j].nValue),j); if ( i != 0 || j != 1 ) total += pblock->vtx[i].vout[j].nValue; } From 5ddb8a234694978fa34034a2e48e043f9c5fedf5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 07:56:04 -1100 Subject: [PATCH 187/643] Test --- src/komodo_bitcoind.h | 1 + src/miner.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 64faa28bc..82abfb1f2 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1171,6 +1171,7 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) } if ( commission < 10000 ) commission = 0; + fprintf(stderr,"-> %.8f\n",(double)commission/COIN); return(commission); } diff --git a/src/miner.cpp b/src/miner.cpp index dc476b4c3..71366bd12 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -554,6 +554,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 txNew.vout[1].nValue = commission; if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) { + fprintf(stderr,"mine to -ac_script\n"); //txNew.vout[1].scriptPubKey = CScript() << ParseHex(); int32_t len = strlen(ASSETCHAINS_SCRIPTPUB.c_str()); len >>= 1; From 36a962d0b58d95ed61acd640776149d2130e052b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:02:03 -1100 Subject: [PATCH 188/643] Test --- src/miner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/miner.cpp b/src/miner.cpp index 71366bd12..0e7c093de 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -539,6 +539,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 if ( ASSETCHAINS_SYMBOL[0] == 0 && IS_KOMODO_NOTARY != 0 && My_notaryid >= 0 ) txNew.vout[0].nValue += 5000; + fprintf(stderr,"ht.%d cmp.%d\n",nHeight,nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0); // check if coinbase transactions must be time locked at current subsidy and prepend the time lock // to transaction if so, cast for GTE operator if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) From c877777d7b88874b098fcdae3a42bc884e22115f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:04:38 -1100 Subject: [PATCH 189/643] +print --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 0e7c093de..a5712025f 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -539,7 +539,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 if ( ASSETCHAINS_SYMBOL[0] == 0 && IS_KOMODO_NOTARY != 0 && My_notaryid >= 0 ) txNew.vout[0].nValue += 5000; - fprintf(stderr,"ht.%d cmp.%d\n",nHeight,nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0); + fprintf(stderr,"ht.%d cmp.%d [%d %d %d %d %d]\n",nHeight,nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0,nHeight > 1,ASSETCHAINS_SYMBOL[0] != 0, (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1), ASSETCHAINS_COMMISSION != 0,(commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0); // check if coinbase transactions must be time locked at current subsidy and prepend the time lock // to transaction if so, cast for GTE operator if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) From de4aed1a620e2406b01e53116b12c9970c0c1efb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:07:56 -1100 Subject: [PATCH 190/643] pblock->vtx[0] = txNew; --- src/miner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/miner.cpp b/src/miner.cpp index a5712025f..f634be072 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -538,6 +538,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 if ( ASSETCHAINS_SYMBOL[0] == 0 && IS_KOMODO_NOTARY != 0 && My_notaryid >= 0 ) txNew.vout[0].nValue += 5000; + pblock->vtx[0] = txNew; fprintf(stderr,"ht.%d cmp.%d [%d %d %d %d %d]\n",nHeight,nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0,nHeight > 1,ASSETCHAINS_SYMBOL[0] != 0, (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1), ASSETCHAINS_COMMISSION != 0,(commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0); // check if coinbase transactions must be time locked at current subsidy and prepend the time lock From 34a26023f206dbbad74abe4cacfa469af4cd6c2b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:09:54 -1100 Subject: [PATCH 191/643] Test --- src/komodo_bitcoind.h | 6 +++--- src/miner.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 82abfb1f2..6e6dc7b35 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1162,7 +1162,7 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) n = pblock->vtx[i].vout.size(); for (j=0; jvtx[i].vout[j].nValue),j); + //fprintf(stderr,"(%d %.8f).%d ",i,dstr(pblock->vtx[i].vout[j].nValue),j); if ( i != 0 || j != 1 ) total += pblock->vtx[i].vout[j].nValue; } @@ -1171,7 +1171,7 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) } if ( commission < 10000 ) commission = 0; - fprintf(stderr,"-> %.8f\n",(double)commission/COIN); + //fprintf(stderr,"-> %.8f\n",(double)commission/COIN); return(commission); } @@ -1702,7 +1702,7 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) checktoshis = komodo_commission(pblock,height); if ( checktoshis >= 10000 && pblock->vtx[0].vout.size() < 2 ) { - fprintf(stderr,"komodo_checkcommission vsize.%d height.%d commission %.8f\n",(int32_t)pblock->vtx[0].vout.size(),height,(double)checktoshis/COIN); + //fprintf(stderr,"komodo_checkcommission vsize.%d height.%d commission %.8f\n",(int32_t)pblock->vtx[0].vout.size(),height,(double)checktoshis/COIN); return(-1); } else if ( checktoshis != 0 ) diff --git a/src/miner.cpp b/src/miner.cpp index f634be072..128a94e3a 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -540,7 +540,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 txNew.vout[0].nValue += 5000; pblock->vtx[0] = txNew; - fprintf(stderr,"ht.%d cmp.%d [%d %d %d %d %d]\n",nHeight,nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0,nHeight > 1,ASSETCHAINS_SYMBOL[0] != 0, (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1), ASSETCHAINS_COMMISSION != 0,(commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0); + //fprintf(stderr,"ht.%d cmp.%d [%d %d %d %d %d]\n",nHeight,nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0,nHeight > 1,ASSETCHAINS_SYMBOL[0] != 0, (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1), ASSETCHAINS_COMMISSION != 0,(commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0); // check if coinbase transactions must be time locked at current subsidy and prepend the time lock // to transaction if so, cast for GTE operator if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) @@ -572,10 +572,10 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 for (i=0; i<33; i++) { ptr[i+1] = ASSETCHAINS_OVERRIDE_PUBKEY33[i]; - fprintf(stderr,"%02x",ptr[i+1]); + //fprintf(stderr,"%02x",ptr[i+1]); } ptr[34] = OP_CHECKSIG; - fprintf(stderr," set ASSETCHAINS_OVERRIDE_PUBKEY33 into vout[1]\n"); + //fprintf(stderr," set ASSETCHAINS_OVERRIDE_PUBKEY33 into vout[1]\n"); } //printf("autocreate commision vout\n"); } From 4c900a4708e44e4cc68a689ccc9f503a78f6dc11 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:21:57 -1100 Subject: [PATCH 192/643] Son --- src/rpc/server.cpp | 4 ++-- src/wallet/rpcwallet.cpp | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 56b32c837..d6b801dd5 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -442,8 +442,8 @@ static const CRPCCommand vRPCCommands[] = { "pegs", "pegsaddress", &pegsaddress, true }, // Marmara - { "marmara", "Marmaraaddress", &marmaraaddress, true }, - { "marmara", "Marmarapoolpayout", &marmara_poolpayout, true }, + { "marmara", "marmaraaddress", &marmaraaddress, true }, + { "marmara", "marmarapoolpayout", &marmara_poolpayout, true }, // Payments { "payments", "paymentsaddress", &paymentsaddress, true }, diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 36e23c93d..a4b30e383 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5535,7 +5535,10 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) { int32_t firstheight; double perc; char *jsonstr; if ( fHelp || params.size() != 3 ) - throw runtime_error("marmara_poolpayout perc firstheight \"[[pubkey:shares], ...]\"\n"); + { + fprintf(stderr,"params.size %d\n",(int32_t)params.size()); + throw runtime_error("marmara_poolpayout perc firstheight \"[[\\\"pubkey\\\":shares], ...]\"\n"); + } if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); perc = atof(params[0].get_str().c_str()) / 100.; From 3fb0d3a82adaf30138f5d98a4575cc17d6312d67 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:24:41 -1100 Subject: [PATCH 193/643] Test --- src/cc/marmara.cpp | 2 +- src/wallet/rpcwallet.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index bce201383..bb06b3e39 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -178,7 +178,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { if ( ht == height && MarmaraUnlockht(height) == unlockht ) { - fprintf(stderr,"ht.%d -> unlock.%d\n",ht,unlockht); + //fprintf(stderr,"ht.%d -> unlock.%d\n",ht,unlockht); ccvout = MakeCC1vout(EVAL_MARMARA,0,pk); if ( ccvout.scriptPubKey == tx.vout[0].scriptPubKey ) return(0); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a4b30e383..4a7024eb4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5534,7 +5534,7 @@ UniValue tokenaddress(const UniValue& params, bool fHelp) UniValue marmara_poolpayout(const UniValue& params, bool fHelp) { int32_t firstheight; double perc; char *jsonstr; - if ( fHelp || params.size() != 3 ) + if ( fHelp || params.size() < 3 ) { fprintf(stderr,"params.size %d\n",(int32_t)params.size()); throw runtime_error("marmara_poolpayout perc firstheight \"[[\\\"pubkey\\\":shares], ...]\"\n"); @@ -5544,6 +5544,7 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) perc = atof(params[0].get_str().c_str()) / 100.; firstheight = atol(params[1].get_str().c_str()); jsonstr = (char *)params[2].get_str().c_str(); + fprintf(stderr,"perc %.2f ht.%d (%s)\n",perc,firstheight,jsonstr); return(MarmaraPoolPayout(0,firstheight,perc,jsonstr)); // [[pk0, shares0], [pk1, shares1], ...] } From 1e17cbc61790d8c0c0bd8ee4df21b05aff73908c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:26:54 -1100 Subject: [PATCH 194/643] -print --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index cd3c0d35f..44dab5ed1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3462,7 +3462,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin { if ( block.vtx[0].vout.size() >= 2 && block.vtx[0].vout[1].nValue == checktoshis ) blockReward += checktoshis; - else fprintf(stderr,"checktoshis %.8f numvouts %d\n",dstr(checktoshis),(int32_t)block.vtx[0].vout.size()); + else if ( pindex->nHeight > 1 ) + fprintf(stderr,"checktoshis %.8f vs %.8f numvouts %d\n",dstr(checktoshis),dstr(block.vtx[0].vout[1].nValue),(int32_t)block.vtx[0].vout.size()); } } if (ASSETCHAINS_SYMBOL[0] != 0 && pindex->GetHeight() == 1 && block.vtx[0].GetValueOut() != blockReward) From 7ebf1d817686b6dfe32465235b5ba3739bd250a2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:41:23 -1100 Subject: [PATCH 195/643] +print --- src/cc/marmara.cpp | 31 ++++++++++++++++++------------- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index bb06b3e39..353f3edba 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -237,26 +237,31 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, GetCCaddress(cp,coinaddr,poolpk); SetCCunspents(unspentOutputs,coinaddr); unlocks = MarmaraUnlockht(firstheight); + fprintf(stderr,"check coinaddr.(%s)\n",coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 && vintx.IsCoinBase() != 0 ) + fprintf(stderr,"txid.%s/v%d\n",txid.GetHex().c_str(),vout); + if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - if ( DecodeMaramaraCoinbaseOpRet(vintx.vout[1].scriptPubKey,pk,ht,unlockht) == 'C' && unlockht == unlocks && pk == poolpk ) + if ( vintx.IsCoinBase() != 0 ) { - if ( (nValue= IsMarmaravout(cp,vintx,vout)) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + if ( DecodeMaramaraCoinbaseOpRet(vintx.vout[1].scriptPubKey,pk,ht,unlockht) == 'C' && unlockht == unlocks && pk == poolpk ) { - if ( maxinputs != 0 ) - mtx.vin.push_back(CTxIn(txid,vout,CScript())); - nValue = it->second.satoshis; - totalinputs += nValue; - n++; - if ( maxinputs > 0 && n >= maxinputs ) - break; - } - } - } + if ( (nValue= IsMarmaravout(cp,vintx,vout)) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + { + if ( maxinputs != 0 ) + mtx.vin.push_back(CTxIn(txid,vout,CScript())); + nValue = it->second.satoshis; + totalinputs += nValue; + n++; + if ( maxinputs > 0 && n >= maxinputs ) + break; + } else fprintf(stderr,"nValue.%8f\n",(double)nValue/COIN); + } else fprintf(stderr,"decode error\n"); + } else fprintf(stderr,"not coinbase\n"); + } else fprintf(stderr,"error getting tx\n"); } return(totalinputs); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 4a7024eb4..6a2a351dc 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5544,7 +5544,7 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) perc = atof(params[0].get_str().c_str()) / 100.; firstheight = atol(params[1].get_str().c_str()); jsonstr = (char *)params[2].get_str().c_str(); - fprintf(stderr,"perc %.2f ht.%d (%s)\n",perc,firstheight,jsonstr); + fprintf(stderr,"perc %.8f ht.%d (%s)\n",perc,firstheight,jsonstr); return(MarmaraPoolPayout(0,firstheight,perc,jsonstr)); // [[pk0, shares0], [pk1, shares1], ...] } From 80c61ba5053b5ba20898e6134aa29217b3634b3a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:44:14 -1100 Subject: [PATCH 196/643] ->GetHeight() --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 44dab5ed1..929ec9d5e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3462,7 +3462,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin { if ( block.vtx[0].vout.size() >= 2 && block.vtx[0].vout[1].nValue == checktoshis ) blockReward += checktoshis; - else if ( pindex->nHeight > 1 ) + else if ( pindex->GetHeight() > 1 ) fprintf(stderr,"checktoshis %.8f vs %.8f numvouts %d\n",dstr(checktoshis),dstr(block.vtx[0].vout[1].nValue),(int32_t)block.vtx[0].vout.size()); } } From c31f8ea3d57d400bd4d51967196efd345a4399ca Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:52:30 -1100 Subject: [PATCH 197/643] Test --- src/cc/marmara.cpp | 5 +++-- src/wallet/rpcwallet.cpp | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 353f3edba..66d082cb9 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -124,6 +124,7 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript scriptPubKey,CPubKey &pk,int32 { if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> pk; ss >> height; ss >> unlockht) != 0 ) { + fprintf(stderr,"return %c\n",script[1]); return(script[1]); } else fprintf(stderr,"DecodeMaramaraCoinbaseOpRet unmarshal error for %c\n",script[1]); } else fprintf(stderr,"script[1] is %d != 'C' %d or 'P' %d\n",script[1],'C','P'); @@ -245,7 +246,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, fprintf(stderr,"txid.%s/v%d\n",txid.GetHex().c_str(),vout); if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - if ( vintx.IsCoinBase() != 0 ) + if ( vintx.IsCoinBase() != 0 && vintx.vout.size() == 2 && vintx.vout[1].nValue == 0 ) { if ( DecodeMaramaraCoinbaseOpRet(vintx.vout[1].scriptPubKey,pk,ht,unlockht) == 'C' && unlockht == unlocks && pk == poolpk ) { @@ -259,7 +260,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, if ( maxinputs > 0 && n >= maxinputs ) break; } else fprintf(stderr,"nValue.%8f\n",(double)nValue/COIN); - } else fprintf(stderr,"decode error\n"); + } else fprintf(stderr,"decode error unlockht.%d vs %d pk.%d\n",unlockht,unlocks,pk == poolpk); } else fprintf(stderr,"not coinbase\n"); } else fprintf(stderr,"error getting tx\n"); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6a2a351dc..fc9655ec1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5536,7 +5536,7 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) int32_t firstheight; double perc; char *jsonstr; if ( fHelp || params.size() < 3 ) { - fprintf(stderr,"params.size %d\n",(int32_t)params.size()); + // marmarapoolpayout "0.5" 2 '[["024131032ed90941e714db8e6dd176fe5a86c9d873d279edecf005c06f773da686",1000],["02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92",100]]'; throw runtime_error("marmara_poolpayout perc firstheight \"[[\\\"pubkey\\\":shares], ...]\"\n"); } if ( ensure_CCrequirements() < 0 ) @@ -5544,7 +5544,6 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) perc = atof(params[0].get_str().c_str()) / 100.; firstheight = atol(params[1].get_str().c_str()); jsonstr = (char *)params[2].get_str().c_str(); - fprintf(stderr,"perc %.8f ht.%d (%s)\n",perc,firstheight,jsonstr); return(MarmaraPoolPayout(0,firstheight,perc,jsonstr)); // [[pk0, shares0], [pk1, shares1], ...] } From f6af25e545ee3ff9e9da583c8039d4c88bd8b7f1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:56:00 -1100 Subject: [PATCH 198/643] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 66d082cb9..304d97f74 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -250,7 +250,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, { if ( DecodeMaramaraCoinbaseOpRet(vintx.vout[1].scriptPubKey,pk,ht,unlockht) == 'C' && unlockht == unlocks && pk == poolpk ) { - if ( (nValue= IsMarmaravout(cp,vintx,vout)) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + if ( (nValue= vintx.vout[vout].nValue) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( maxinputs != 0 ) mtx.vin.push_back(CTxIn(txid,vout,CScript())); From fefe5dbd246bfc1139d0556ffed441d45bf3265b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:59:23 -1100 Subject: [PATCH 199/643] Args 3 --- src/cc/marmara.cpp | 1 - src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 304d97f74..b3be7cb32 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -124,7 +124,6 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript scriptPubKey,CPubKey &pk,int32 { if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> pk; ss >> height; ss >> unlockht) != 0 ) { - fprintf(stderr,"return %c\n",script[1]); return(script[1]); } else fprintf(stderr,"DecodeMaramaraCoinbaseOpRet unmarshal error for %c\n",script[1]); } else fprintf(stderr,"script[1] is %d != 'C' %d or 'P' %d\n",script[1],'C','P'); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index fc9655ec1..2bc4aeeba 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5534,7 +5534,7 @@ UniValue tokenaddress(const UniValue& params, bool fHelp) UniValue marmara_poolpayout(const UniValue& params, bool fHelp) { int32_t firstheight; double perc; char *jsonstr; - if ( fHelp || params.size() < 3 ) + if ( fHelp || params.size() != 3 ) { // marmarapoolpayout "0.5" 2 '[["024131032ed90941e714db8e6dd176fe5a86c9d873d279edecf005c06f773da686",1000],["02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92",100]]'; throw runtime_error("marmara_poolpayout perc firstheight \"[[\\\"pubkey\\\":shares], ...]\"\n"); From 028725471c7a176605512ec4e3d5e7c9185f8b2b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:17:22 -1100 Subject: [PATCH 200/643] Total field --- src/cc/marmara.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index b3be7cb32..103e8d51a 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -364,6 +364,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * result.push_back(Pair("rawtx",rawtx)); if ( totalpayout > 0 && total > totalpayout-txfee ) { + result.push_back(Pair("total",(double)total/COIN)); result.push_back(Pair("totalpayout",(double)totalpayout/COIN)); result.push_back(Pair("totalshares",shares)); result.push_back(Pair("poolfee",(double)(total - totalpayout)/COIN)); From 1b46c66023b207223070d06740516e1e8082987c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:21:54 -1100 Subject: [PATCH 201/643] Payouts --- src/cc/marmara.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 103e8d51a..852ac8469 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -237,12 +237,12 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, GetCCaddress(cp,coinaddr,poolpk); SetCCunspents(unspentOutputs,coinaddr); unlocks = MarmaraUnlockht(firstheight); - fprintf(stderr,"check coinaddr.(%s)\n",coinaddr); + //fprintf(stderr,"check coinaddr.(%s)\n",coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; - fprintf(stderr,"txid.%s/v%d\n",txid.GetHex().c_str(),vout); + //fprintf(stderr,"txid.%s/v%d\n",txid.GetHex().c_str(),vout); if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { if ( vintx.IsCoinBase() != 0 && vintx.vout.size() == 2 && vintx.vout[1].nValue == 0 ) @@ -259,7 +259,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, if ( maxinputs > 0 && n >= maxinputs ) break; } else fprintf(stderr,"nValue.%8f\n",(double)nValue/COIN); - } else fprintf(stderr,"decode error unlockht.%d vs %d pk.%d\n",unlockht,unlocks,pk == poolpk); + } //else fprintf(stderr,"decode error unlockht.%d vs %d pk.%d\n",unlockht,unlocks,pk == poolpk); } else fprintf(stderr,"not coinbase\n"); } else fprintf(stderr,"error getting tx\n"); } @@ -298,7 +298,7 @@ UniValue MarmaraInfo() UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr) // [[pk0, shares0], [pk1, shares1], ...] { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk,poolpk; int64_t payout,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk,poolpk; int64_t payout,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; poolpk = pubkey2pk(Mypubkey()); if ( txfee == 0 ) txfee = 10000; @@ -335,6 +335,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * totalpayout += payout; decode_hex(buf,33,pkstr); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,payout,Marmarapk,buf2pk(buf))); + a.push_back(Pair(pkstr,(double)payout/COIN)); } } } @@ -369,6 +370,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * result.push_back(Pair("totalshares",shares)); result.push_back(Pair("poolfee",(double)(total - totalpayout)/COIN)); result.push_back(Pair("perc",100. * (double)(total - totalpayout)/totalpayout)); + result.push_back(Pair("payouts",a); } } return(result); From cdbdf8662b712b643266f44a736f56c1b81967d1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:23:02 -1100 Subject: [PATCH 202/643] +) --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 852ac8469..82d0a9995 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -370,7 +370,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * result.push_back(Pair("totalshares",shares)); result.push_back(Pair("poolfee",(double)(total - totalpayout)/COIN)); result.push_back(Pair("perc",100. * (double)(total - totalpayout)/totalpayout)); - result.push_back(Pair("payouts",a); + result.push_back(Pair("payouts",a)); } } return(result); From 9e94b62aa3f83d9a422d5c9a7332df6aea9a8455 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:25:30 -1100 Subject: [PATCH 203/643] Payout --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 82d0a9995..b1603cfbc 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -335,7 +335,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * totalpayout += payout; decode_hex(buf,33,pkstr); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,payout,Marmarapk,buf2pk(buf))); - a.push_back(Pair(pkstr,(double)payout/COIN)); + a.push_back((double)payout/COIN); } } } From 70de1f76bd446c74e9a11752a2228e1882af805f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:28:12 -1100 Subject: [PATCH 204/643] x(UniValue::VOBJ), --- src/cc/marmara.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index b1603cfbc..f993d5555 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -332,10 +332,12 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * { if ( (pkstr= jstr(jitem(item,0),0)) != 0 && strlen(pkstr) == 66 ) { + UniValue x(UniValue::VOBJ); totalpayout += payout; decode_hex(buf,33,pkstr); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,payout,Marmarapk,buf2pk(buf))); - a.push_back((double)payout/COIN); + x.push_back(Pair(pkstr, (double)payout/COIN)); + a.push_back(item); } } } From 78b7341aa5aa03248bd3ba74fd1f3cec2e3b555e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:29:45 -1100 Subject: [PATCH 205/643] x --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index f993d5555..4a32639af 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -337,7 +337,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * decode_hex(buf,33,pkstr); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,payout,Marmarapk,buf2pk(buf))); x.push_back(Pair(pkstr, (double)payout/COIN)); - a.push_back(item); + a.push_back(x); } } } From 513c19d096298af8ee832cab2b3471642056ce36 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:38:33 -1100 Subject: [PATCH 206/643] Split commission calc into 2 divs --- src/komodo_bitcoind.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 6e6dc7b35..079e58fc5 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1167,7 +1167,8 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) total += pblock->vtx[i].vout[j].nValue; } } - commission = ((total * ASSETCHAINS_COMMISSION) / COIN); + commission = ((total / 10000) * ASSETCHAINS_COMMISSION) / 10000); + //commission = ((total * ASSETCHAINS_COMMISSION) / COIN); } if ( commission < 10000 ) commission = 0; From 59bb5fd47030ff9d5221edf19108d879e45ca960 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:46:58 -1100 Subject: [PATCH 207/643] -) --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 079e58fc5..841396a00 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1167,7 +1167,7 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) total += pblock->vtx[i].vout[j].nValue; } } - commission = ((total / 10000) * ASSETCHAINS_COMMISSION) / 10000); + commission = ((total / 10000) * ASSETCHAINS_COMMISSION) / 10000; //commission = ((total * ASSETCHAINS_COMMISSION) / COIN); } if ( commission < 10000 ) From f105e133b972f9fdae7ce56eebd304ea0ae85911 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:54:12 -1100 Subject: [PATCH 208/643] First/last heights --- src/cc/marmara.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 4a32639af..763c19ebe 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -367,6 +367,8 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * result.push_back(Pair("rawtx",rawtx)); if ( totalpayout > 0 && total > totalpayout-txfee ) { + result.push_back(Pair("firstheight",firstheight)); + result.push_back(Pair("lastheight",((firstheight / MARMARA_GROUPSIZE)+1) * MARMARA_GROUPSIZE - 1)); result.push_back(Pair("total",(double)total/COIN)); result.push_back(Pair("totalpayout",(double)totalpayout/COIN)); result.push_back(Pair("totalshares",shares)); From cae219a0c8970d80efb52d8cdf810d1fb67d24fe Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:56:52 -1100 Subject: [PATCH 209/643] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 763c19ebe..4b154cc8c 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -247,7 +247,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, { if ( vintx.IsCoinBase() != 0 && vintx.vout.size() == 2 && vintx.vout[1].nValue == 0 ) { - if ( DecodeMaramaraCoinbaseOpRet(vintx.vout[1].scriptPubKey,pk,ht,unlockht) == 'C' && unlockht == unlocks && pk == poolpk ) + if ( DecodeMaramaraCoinbaseOpRet(vintx.vout[1].scriptPubKey,pk,ht,unlockht) == 'C' && unlockht == unlocks && pk == poolpk && ht >= firstheight ) { if ( (nValue= vintx.vout[vout].nValue) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { From 7949fcb64857a72118307ae7818575ab4689fe92 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 15:51:07 -1100 Subject: [PATCH 210/643] Tweak perc calc --- src/cc/marmara.cpp | 2 +- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 4b154cc8c..ccce9083f 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -319,7 +319,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * } if ( errorstr == 0 && shares > SMALLVAL ) { - shares += shares * perc; + shares += (shares / (1. - perc)); if ( (total= AddMarmaraCoinbases(cp,mtx,firstheight,poolpk,60)) > 0 ) { for (i=0; i Date: Sat, 12 Jan 2019 15:55:31 -1100 Subject: [PATCH 211/643] Fix perc math --- src/cc/marmara.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index ccce9083f..639a69567 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -319,7 +319,9 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * } if ( errorstr == 0 && shares > SMALLVAL ) { - shares += (shares / (1. - perc)); + //shares += shares * perc; + shares /= (1. - perc); + if ( (total= AddMarmaraCoinbases(cp,mtx,firstheight,poolpk,60)) > 0 ) { for (i=0; i Date: Sat, 12 Jan 2019 16:00:11 -1100 Subject: [PATCH 212/643] Revert --- src/cc/marmara.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 639a69567..4b154cc8c 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -319,9 +319,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * } if ( errorstr == 0 && shares > SMALLVAL ) { - //shares += shares * perc; - shares /= (1. - perc); - + shares += shares * perc; if ( (total= AddMarmaraCoinbases(cp,mtx,firstheight,poolpk,60)) > 0 ) { for (i=0; i Date: Sat, 12 Jan 2019 16:04:43 -1100 Subject: [PATCH 213/643] Adjust pool fee disp by three --- src/cc/marmara.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 4b154cc8c..751eb569b 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -298,7 +298,7 @@ UniValue MarmaraInfo() UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr) // [[pk0, shares0], [pk1, shares1], ...] { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ),a(UniValue::VARR); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk,poolpk; int64_t payout,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk,poolpk; int64_t payout,poolfee=0,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; poolpk = pubkey2pk(Mypubkey()); if ( txfee == 0 ) txfee = 10000; @@ -344,7 +344,8 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * } if ( totalpayout > 0 && total > totalpayout-txfee ) { - mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,total - totalpayout - txfee,Marmarapk,poolpk)); + poolfee = (total - totalpayout - txfee); + mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,poolfee,Marmarapk,poolpk)); } rawtx = FinalizeCCTx(0,cp,mtx,poolpk,txfee,MarmaraCoinbaseOpret('P',firstheight,poolpk)); if ( rawtx.size() == 0 ) @@ -372,8 +373,8 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * result.push_back(Pair("total",(double)total/COIN)); result.push_back(Pair("totalpayout",(double)totalpayout/COIN)); result.push_back(Pair("totalshares",shares)); - result.push_back(Pair("poolfee",(double)(total - totalpayout)/COIN)); - result.push_back(Pair("perc",100. * (double)(total - totalpayout)/totalpayout)); + result.push_back(Pair("poolfee",(double)poolfee/COIN)); + result.push_back(Pair("perc",100. * (double)poolfee/totalpayout)); result.push_back(Pair("payouts",a)); } } From 5ee45ecb45990a3f3d51480d9f08e5a7d070a2c2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 16:12:24 -1100 Subject: [PATCH 214/643] ValueFromAmount( --- src/cc/marmara.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 751eb569b..ef2f62b40 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -370,10 +370,10 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * { result.push_back(Pair("firstheight",firstheight)); result.push_back(Pair("lastheight",((firstheight / MARMARA_GROUPSIZE)+1) * MARMARA_GROUPSIZE - 1)); - result.push_back(Pair("total",(double)total/COIN)); - result.push_back(Pair("totalpayout",(double)totalpayout/COIN)); + result.push_back(Pair("total",ValueFromAmount(total)); + result.push_back(Pair("totalpayout",ValueFromAmount(totalpayout)); result.push_back(Pair("totalshares",shares)); - result.push_back(Pair("poolfee",(double)poolfee/COIN)); + result.push_back(Pair("poolfee",ValueFromAmount(poolfee)); result.push_back(Pair("perc",100. * (double)poolfee/totalpayout)); result.push_back(Pair("payouts",a)); } From 857bf5f4e6ea57df49c2e1debff69421e7428a39 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 16:13:54 -1100 Subject: [PATCH 215/643] UniValue ValueFromAmount(const CAmount& amount) --- src/cc/CCinclude.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 0906a57c6..aaeadcc61 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -187,5 +187,6 @@ bits256 curve25519_basepoint9(); bits256 curve25519(bits256 mysecret,bits256 basepoint); void vcalc_sha256(char deprecated[(256 >> 3) * 2 + 1],uint8_t hash[256 >> 3],uint8_t *src,int32_t len); bits256 bits256_doublesha256(char *deprecated,uint8_t *data,int32_t datalen); +UniValue ValueFromAmount(const CAmount& amount); #endif From ba5462eec9a2172a9c60344ee0cb646cdc013807 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 16:16:21 -1100 Subject: [PATCH 216/643] +))) --- src/cc/marmara.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index ef2f62b40..593ee48f7 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -370,10 +370,10 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * { result.push_back(Pair("firstheight",firstheight)); result.push_back(Pair("lastheight",((firstheight / MARMARA_GROUPSIZE)+1) * MARMARA_GROUPSIZE - 1)); - result.push_back(Pair("total",ValueFromAmount(total)); - result.push_back(Pair("totalpayout",ValueFromAmount(totalpayout)); + result.push_back(Pair("total",ValueFromAmount(total))); + result.push_back(Pair("totalpayout",ValueFromAmount(totalpayout))); result.push_back(Pair("totalshares",shares)); - result.push_back(Pair("poolfee",ValueFromAmount(poolfee)); + result.push_back(Pair("poolfee",ValueFromAmount(poolfee))); result.push_back(Pair("perc",100. * (double)poolfee/totalpayout)); result.push_back(Pair("payouts",a)); } From 24cd52e8956201c8a8b01d91f686dda6f8486259 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 16:20:09 -1100 Subject: [PATCH 217/643] return eval->Invalid("no validation yet"); --- src/cc/auction.cpp | 2 +- src/cc/fsm.cpp | 2 +- src/cc/heir.cpp | 2 +- src/cc/lotto.cpp | 2 +- src/cc/marmara.cpp | 2 +- src/cc/payments.cpp | 2 +- src/cc/pegs.cpp | 2 +- src/cc/prices.cpp | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cc/auction.cpp b/src/cc/auction.cpp index 70bc64379..0858facfa 100644 --- a/src/cc/auction.cpp +++ b/src/cc/auction.cpp @@ -73,7 +73,7 @@ bool AuctionExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransactio bool AuctionValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; - return(false); // reject any auction CC for now + return eval->Invalid("no validation yet"); numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; diff --git a/src/cc/fsm.cpp b/src/cc/fsm.cpp index 04ca1d5a0..0bcc61a1b 100644 --- a/src/cc/fsm.cpp +++ b/src/cc/fsm.cpp @@ -75,7 +75,7 @@ bool FSMExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &t bool FSMValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; - return(false); // reject any FSM CC for now + return eval->Invalid("no validation yet"); numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 5caa6594a..44f01a8a4 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -74,7 +74,7 @@ bool HeirExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction & bool HeirValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; - return(false); + return eval->Invalid("no validation yet"); std::vector > txids; numvins = tx.vin.size(); numvouts = tx.vout.size(); diff --git a/src/cc/lotto.cpp b/src/cc/lotto.cpp index 7b44a99b7..e9c263ff1 100644 --- a/src/cc/lotto.cpp +++ b/src/cc/lotto.cpp @@ -115,7 +115,7 @@ bool LottoExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction bool LottoValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; - return(false); // reject any lotto CC for now + return eval->Invalid("no validation yet"); numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 593ee48f7..a4d548176 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -192,7 +192,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; - return(false); + return eval->Invalid("no validation yet"); std::vector > txids; numvins = tx.vin.size(); numvouts = tx.vout.size(); diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 1b6d88214..859a5ba3f 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -75,7 +75,7 @@ bool PaymentsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransacti bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; - return(false); + return eval->Invalid("no validation yet"); std::vector > txids; numvins = tx.vin.size(); numvouts = tx.vout.size(); diff --git a/src/cc/pegs.cpp b/src/cc/pegs.cpp index 4e414d695..e2893bec8 100644 --- a/src/cc/pegs.cpp +++ b/src/cc/pegs.cpp @@ -82,7 +82,7 @@ bool PegsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction & bool PegsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; - return(false); + return eval->Invalid("no validation yet"); std::vector > txids; numvins = tx.vin.size(); numvouts = tx.vout.size(); diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 8c2ecc021..5d919d6e8 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -89,7 +89,7 @@ uint8_t DecodePricesFundingOpRet(CScript scriptPubKey,CPubKey &planpk,uint256 &o bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; - return(false); + return eval->Invalid("no validation yet"); std::vector > txids; numvins = tx.vin.size(); numvouts = tx.vout.size(); From b6eed136785c5662cc18d83d231c588943d32392 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 16:22:59 -1100 Subject: [PATCH 218/643] Truncate perc print --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index a4d548176..171ef713d 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -374,7 +374,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * result.push_back(Pair("totalpayout",ValueFromAmount(totalpayout))); result.push_back(Pair("totalshares",shares)); result.push_back(Pair("poolfee",ValueFromAmount(poolfee))); - result.push_back(Pair("perc",100. * (double)poolfee/totalpayout)); + result.push_back(Pair("perc",ValueFromAmount((int64_t)(100. * (double)poolfee/totalpayout)))); result.push_back(Pair("payouts",a)); } } From c38e4a0521534e81e81a25f95c9f33afd52730c5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 16:24:23 -1100 Subject: [PATCH 219/643] * COIN --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 171ef713d..2e56c21b2 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -374,7 +374,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * result.push_back(Pair("totalpayout",ValueFromAmount(totalpayout))); result.push_back(Pair("totalshares",shares)); result.push_back(Pair("poolfee",ValueFromAmount(poolfee))); - result.push_back(Pair("perc",ValueFromAmount((int64_t)(100. * (double)poolfee/totalpayout)))); + result.push_back(Pair("perc",ValueFromAmount((int64_t)(100. * (double)poolfee/totalpayout * COIN)))); result.push_back(Pair("payouts",a)); } } From 0b58392fff0671169aa06f16c8cab9bb2869daac Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 17:29:18 -1100 Subject: [PATCH 220/643] Validation for marmara 'P' --- src/cc/eval.cpp | 5 +++-- src/cc/marmara.cpp | 45 ++++++++++++++++++++++----------------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index d50bc8a0d..9161f2007 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -38,8 +38,9 @@ bool RunCCEval(const CC *cond, const CTransaction &tx, unsigned int nIn) pthread_mutex_lock(&KOMODO_CC_mutex); bool out = eval->Dispatch(cond, tx, nIn); pthread_mutex_unlock(&KOMODO_CC_mutex); - //fprintf(stderr,"out %d vs %d isValid\n",(int32_t)out,(int32_t)eval->state.IsValid()); - assert(eval->state.IsValid() == out); + if ( eval->state.IsValid() != out) + fprintf(stderr,"out %d vs %d isValid\n",(int32_t)out,(int32_t)eval->state.IsValid()); + //assert(eval->state.IsValid() == out); if (eval->state.IsValid()) return true; diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 2e56c21b2..d12959d2a 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -191,40 +191,39 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { - int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; - return eval->Invalid("no validation yet"); - std::vector > txids; + CTransaction vinTx; uint256 hashBlock; int32_t numvins,numvouts,i,ht,unlockht,vht,vunlockht; uint8_t funcid; CPubKey pk,vpk; numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; if ( numvouts < 1 ) return eval->Invalid("no vouts"); - else + else if ( tx.vout.size() >= 2 ) { - for (i=0; iInvalid("illegal normal vini"); + if ( (*cp->ismyvin)(tx.vin[i].scriptSig) != 0 ) + { + if ( eval->GetTxUnconfirmed(tx.vin[i].prevout.hash,vinTx,hashBlock) == 0 ) + return eval->Invalid("cant find vinTx"); + else + { + if ( vinTx.IsCoinbase() == 0 ) + return eval->Invalid("noncoinbase input"); + else if ( vinTx.size() != 2 ) + return eval->Invalid("coinbase doesnt have 2 vouts"); + vfuncid = DecodeMaramaraCoinbaseOpRet(vinTx.vout[1].scriptPubKey,vpk,vht,vunlockht); + if ( vfuncid != 'C' || vpk != pk || vunlockht != unlockht ) + return eval->Invalid("mismatched opreturn"); + } + } } - } - //fprintf(stderr,"check amounts\n"); - if ( MarmaraExactAmounts(cp,eval,tx,1,10000) == false ) - { - fprintf(stderr,"Marmaraget invalid amount\n"); - return false; - } - else - { - txid = tx.GetHash(); - memcpy(hash,&txid,sizeof(hash)); - retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); - if ( retval != 0 ) - fprintf(stderr,"Marmaraget validated\n"); - else fprintf(stderr,"Marmaraget invalid\n"); - return(retval); + return(true); } } + return eval->Invalid("fall through error"); } // end of consensus code From 7c0fb95d183384df38838e634e7555f19bba8a0e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 17:29:47 -1100 Subject: [PATCH 221/643] Syntax --- src/cc/marmara.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index d12959d2a..f272ecf8d 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -194,7 +194,6 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t CTransaction vinTx; uint256 hashBlock; int32_t numvins,numvouts,i,ht,unlockht,vht,vunlockht; uint8_t funcid; CPubKey pk,vpk; numvins = tx.vin.size(); numvouts = tx.vout.size(); - preventCCvins = preventCCvouts = -1; if ( numvouts < 1 ) return eval->Invalid("no vouts"); else if ( tx.vout.size() >= 2 ) From ba281dae9f79fd287151c09211552a01a2736031 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 17:32:15 -1100 Subject: [PATCH 222/643] syntax --- src/cc/marmara.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index f272ecf8d..dd8e304cf 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -191,7 +191,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { - CTransaction vinTx; uint256 hashBlock; int32_t numvins,numvouts,i,ht,unlockht,vht,vunlockht; uint8_t funcid; CPubKey pk,vpk; + CTransaction vinTx; uint256 hashBlock; int32_t numvins,numvouts,i,ht,unlockht,vht,vunlockht; uint8_t funcid,vfuncid; CPubKey pk,vpk; numvins = tx.vin.size(); numvouts = tx.vout.size(); if ( numvouts < 1 ) @@ -209,9 +209,9 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t return eval->Invalid("cant find vinTx"); else { - if ( vinTx.IsCoinbase() == 0 ) + if ( vinTx.IsCoinBase() == 0 ) return eval->Invalid("noncoinbase input"); - else if ( vinTx.size() != 2 ) + else if ( vinTx.vout.size() != 2 ) return eval->Invalid("coinbase doesnt have 2 vouts"); vfuncid = DecodeMaramaraCoinbaseOpRet(vinTx.vout[1].scriptPubKey,vpk,vht,vunlockht); if ( vfuncid != 'C' || vpk != pk || vunlockht != unlockht ) From fe9d96b291bc4bdfdcf164b11765e4d02fb75cf2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 17:35:48 -1100 Subject: [PATCH 223/643] Last vout is I-return --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index dd8e304cf..5c36eb563 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -198,7 +198,7 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t return eval->Invalid("no vouts"); else if ( tx.vout.size() >= 2 ) { - funcid = DecodeMaramaraCoinbaseOpRet(tx.vout[1].scriptPubKey,pk,ht,unlockht); + funcid = DecodeMaramaraCoinbaseOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,pk,ht,unlockht); if ( funcid == 'P' ) { for (i=0; i Date: Sat, 12 Jan 2019 17:38:17 -1100 Subject: [PATCH 224/643] -print --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 5c36eb563..6415671f8 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -256,7 +256,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, n++; if ( maxinputs > 0 && n >= maxinputs ) break; - } else fprintf(stderr,"nValue.%8f\n",(double)nValue/COIN); + } //else fprintf(stderr,"nValue.%8f\n",(double)nValue/COIN); } //else fprintf(stderr,"decode error unlockht.%d vs %d pk.%d\n",unlockht,unlocks,pk == poolpk); } else fprintf(stderr,"not coinbase\n"); } else fprintf(stderr,"error getting tx\n"); From e149a4e4d798b31c6cdc69ba16b5bdcd6ab19530 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 02:34:07 -1100 Subject: [PATCH 225/643] Initial MarmaraReceive --- src/cc/marmara.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 6415671f8..ba4e4b005 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -33,7 +33,7 @@ int64_t IsMarmaravout(struct CCcontract_info *cp,const CTransaction& tx,int32_t return(0); } -bool MarmaraExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +/*bool MarmaraExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -69,7 +69,7 @@ bool MarmaraExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransactio return eval->Invalid("mismatched inputs != outputs + txfee"); } else return(true); -} +}*/ int32_t MarmaraRandomize(uint32_t ind) { @@ -191,16 +191,21 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { - CTransaction vinTx; uint256 hashBlock; int32_t numvins,numvouts,i,ht,unlockht,vht,vunlockht; uint8_t funcid,vfuncid; CPubKey pk,vpk; + std::vector vopret; CTransaction vinTx; uint256 hashBlock; int32_t numvins,numvouts,i,ht,unlockht,vht,vunlockht; uint8_t funcid,vfuncid,*script; CPubKey pk,vpk; numvins = tx.vin.size(); numvouts = tx.vout.size(); if ( numvouts < 1 ) return eval->Invalid("no vouts"); else if ( tx.vout.size() >= 2 ) { - funcid = DecodeMaramaraCoinbaseOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,pk,ht,unlockht); + GetOpReturnData(tx.vout[tx.vout.size()-1].scriptPubKey,vopret); + script = (uint8_t *)vopret.data(); + if ( vopret.size() < 2 || script[0] != EVAL_MARMARA ) + return eval->Invalid("no opreturn"); + funcid = script[1]; if ( funcid == 'P' ) { + funcid = DecodeMaramaraCoinbaseOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,pk,ht,unlockht); for (i=0; iismyvin)(tx.vin[i].scriptSig) != 0 ) @@ -221,6 +226,38 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t } return(true); } + else if ( funcid == 'L' ) // lock -> lock funds with a unlockht + { + return(true); + } + else if ( funcid == 'R' ) // receive -> agree to receive 'I' from pk, amount, currency, dueht + { + return(true); + } + else if ( funcid == 'I' ) // issue -> issue currency to pk with due date height + { + return(true); + } + else if ( funcid == 'T' ) // transfer -> given 'R' transfer 'I' or 'T' to the pk of 'R' + { + return(true); + } + else if ( funcid == 'S' ) // collect -> automatically spend issuers locked funds, given 'I' + { + return(true); + } + else if ( funcid == 'A' ) // agree -> agree that 'I' is unable to be redeemed, remainder + { + return(true); + } + else if ( funcid == 'D' ) // dispute -> given 'I' submit for manual arbitration + { + return(true); + } + else if ( funcid == 'F' ) // foreclose -> given 'A' collect as much of remainder from credit loop + { + return(true); + } } return eval->Invalid("fall through error"); } @@ -264,6 +301,34 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, return(totalinputs); } +UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 issuetxid) +{ + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string rawtx; char *errorstr=0; + cp = CCinit(&C,EVAL_MARMARA); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + errorstr = (char *)"couldnt finalize CCtx"; + if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) + { + mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(senderpk)) << OP_CHECKSIG)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraOpret('R',issuetxid,senderpk,amount,matures,currency)); + } else errorstr = "dont have enough normal inputs for 2*txfee"; + if ( rawtx.size() == 0 || errorstr != 0 ) + { + result.push_back(Pair("result","error")); + if ( errorstr != 0 ) + result.push_back(Pair("error",errorstr)); + } + else + { + result.push_back(Pair("result",(char *)"success")); + result.push_back(Pair("rawtx",rawtx)); + } + return(result); +} + std::string MarmaraFund(uint64_t txfee,int64_t funds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); From b7341671fa97623020bf8e4781549761775f05cf Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 02:45:51 -1100 Subject: [PATCH 226/643] CC baton for credit loop --- src/cc/marmara.cpp | 73 +++++++++++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 26 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index ba4e4b005..75f9e0ee4 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -87,25 +87,6 @@ int32_t MarmaraUnlockht(int32_t height) return(height + MarmaraRandomize(ind)); } -CScript EncodeMarmaraCoinbaseOpRet(uint8_t funcid,CPubKey pk,int32_t ht) -{ - CScript opret; int32_t unlockht; uint8_t evalcode = EVAL_MARMARA; - unlockht = MarmaraUnlockht(ht); - opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << pk << ht << unlockht); - if ( 0 ) - { - std::vector vopret; uint8_t *script,i; - GetOpReturnData(opret,vopret); - script = (uint8_t *)vopret.data(); - { - for (i=0; i vopret; uint8_t *script,e,f,funcid; @@ -131,6 +112,32 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript scriptPubKey,CPubKey &pk,int32 return(0); } +CScript EncodeMarmaraCoinbaseOpRet(uint8_t funcid,CPubKey pk,int32_t ht) +{ + CScript opret; int32_t unlockht; uint8_t evalcode = EVAL_MARMARA; + unlockht = MarmaraUnlockht(ht); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << pk << ht << unlockht); + if ( 0 ) + { + std::vector vopret; uint8_t *script,i; + GetOpReturnData(opret,vopret); + script = (uint8_t *)vopret.data(); + { + for (i=0; i 0 ) + if ( currency != "MARMARA" ) + errorstr = "for now, only MARMARA loops are supported"; + else if ( amount < txfee ) + errorstr = "amount must be for more than txfee"; + else if ( matures <= chainActive.LastTip->GetHeight() ) + errorstr = "it must mature in the future"; + if ( errorstr == 0 ) { - mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(senderpk)) << OP_CHECKSIG)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraOpret('R',issuetxid,senderpk,amount,matures,currency)); - } else errorstr = "dont have enough normal inputs for 2*txfee"; + if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) + { + errorstr = (char *)"couldnt finalize CCtx"; + mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee,senderpk)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('R',createtxid,senderpk,amount,matures,currency)); + } else errorstr = (char *)"dont have enough normal inputs for 2*txfee"; + } if ( rawtx.size() == 0 || errorstr != 0 ) { result.push_back(Pair("result","error")); @@ -325,6 +341,11 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri { result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); + result.push_back(Pair("createtxid",createtxid)); + result.push_back(Pair("senderpk",senderpk)); + result.push_back(Pair("amount",ValueFromAmount(amount))); + result.push_back(Pair("matures",matures)); + result.push_back(Pair("currency",currency)); } return(result); } From cd4b54dfeae90ccfadb39435f99b2eda88bbbb89 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 02:47:18 -1100 Subject: [PATCH 227/643] Strings --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 75f9e0ee4..5db0c07c3 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -341,8 +341,8 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri { result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); - result.push_back(Pair("createtxid",createtxid)); - result.push_back(Pair("senderpk",senderpk)); + result.push_back(Pair("createtxid",createtxid.GetHex())); + result.push_back(Pair("senderpk",HexStr(senderpk))); result.push_back(Pair("amount",ValueFromAmount(amount))); result.push_back(Pair("matures",matures)); result.push_back(Pair("currency",currency)); From 85271fb3a507ae79e8325b2450c2ed48881ce1b7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 02:48:20 -1100 Subject: [PATCH 228/643] Test --- src/cc/marmara.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 5db0c07c3..a50059305 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -317,11 +317,11 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri txfee = 10000; mypk = pubkey2pk(Mypubkey()); if ( currency != "MARMARA" ) - errorstr = "for now, only MARMARA loops are supported"; + errorstr = (char *)"for now, only MARMARA loops are supported"; else if ( amount < txfee ) - errorstr = "amount must be for more than txfee"; - else if ( matures <= chainActive.LastTip->GetHeight() ) - errorstr = "it must mature in the future"; + errorstr = (char *)"amount must be for more than txfee"; + else if ( matures <= chainActive.LastTip()->GetHeight() ) + errorstr = (char *)"it must mature in the future"; if ( errorstr == 0 ) { if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) From 38093ec82aeacf182fd322b69f89498256d5c495 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 02:52:29 -1100 Subject: [PATCH 229/643] Need baton in 'R' --- src/cc/marmara.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index a50059305..1ff1855dd 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -311,7 +311,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); CPubKey mypk; struct CCcontract_info *cp,C; std::string rawtx; char *errorstr=0; + UniValue result(UniValue::VOBJ); CPubKey mypk; struct CCcontract_info *cp,C; std::string rawtx; char *errorstr=0; int32_t needbaton = 0; cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; @@ -324,10 +324,13 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri errorstr = (char *)"it must mature in the future"; if ( errorstr == 0 ) { - if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) + if ( createtxid == zeroid ) + needbaton = 1; + if ( AddNormalinputs(mtx,mypk,(1+needbaton)*txfee,1) > 0 ) { errorstr = (char *)"couldnt finalize CCtx"; - mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee,senderpk)); + if ( needbaton != 0 ) + mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee,senderpk)); rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('R',createtxid,senderpk,amount,matures,currency)); } else errorstr = (char *)"dont have enough normal inputs for 2*txfee"; } From 908ee69451cc2cceb48775b0a9344d331234a261 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 03:04:34 -1100 Subject: [PATCH 230/643] Marmarareceive roc --- src/cc/CCMarmara.h | 1 + src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/wallet/rpcwallet.cpp | 27 ++++++++++++++++++++++++++- 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 4a50c2539..d3eb67b77 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -25,6 +25,7 @@ #define MARMARA_MAXLOCK (1440 * 24 * 30) uint64_t komodo_block_prg(uint32_t nHeight); UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...] +UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid); bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index d6b801dd5..5baadf34a 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -444,6 +444,7 @@ static const CRPCCommand vRPCCommands[] = // Marmara { "marmara", "marmaraaddress", &marmaraaddress, true }, { "marmara", "marmarapoolpayout", &marmara_poolpayout, true }, + { "marmara", "marmarareceive", &marmara_receive, true }, // Payments { "payments", "paymentsaddress", &paymentsaddress, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index bd00bb9d1..4787130e2 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -273,6 +273,7 @@ extern UniValue pricesfinish(const UniValue& params, bool fHelp); extern UniValue pegsaddress(const UniValue& params, bool fHelp); extern UniValue marmaraaddress(const UniValue& params, bool fHelp); extern UniValue marmara_poolpayout(const UniValue& params, bool fHelp); +extern UniValue marmara_receive(const UniValue& params, bool fHelp); extern UniValue paymentsaddress(const UniValue& params, bool fHelp); extern UniValue gatewaysaddress(const UniValue& params, bool fHelp); extern UniValue gatewayslist(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1790a574a..a2b0afa37 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5537,7 +5537,7 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 3 ) { // marmarapoolpayout 0.5 2 '[["024131032ed90941e714db8e6dd176fe5a86c9d873d279edecf005c06f773da686",1000],["02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92",100]]'; - throw runtime_error("marmara_poolpayout perc firstheight \"[[\\\"pubkey\\\":shares], ...]\"\n"); + throw runtime_error("marmarapoolpayout perc firstheight \"[[\\\"pubkey\\\":shares], ...]\"\n"); } if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); @@ -5547,6 +5547,31 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) return(MarmaraPoolPayout(0,firstheight,perc,jsonstr)); // [[pk0, shares0], [pk1, shares1], ...] } +UniValue marmara_receive(const UniValue& params, bool fHelp) +{ + uint256 createtxid; std::vector senderpub; int64_t amount; int32_t matures; + if ( fHelp || (params.size() != 5 && params.size() != 4) ) + { + // marmarareceive 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1440 + throw runtime_error("marmarareceive senderpk amount currency matures createtxid\n"); + } + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + memset(&createtxid,0,sizeof(createtxid)); + senderpub = ParseHex(params[0].get_str().c_str()); + if (senderpub.size()!= 33) + { + ERR_RESULT("invalid sender pubkey"); + return result; + } + amount = atof(params[1].get_str().c_str()) * COIN + 0.00000000499999; + currency = params[2].get_str(); + matures = atol(params[3].get_str().c_str()) + chainActive.LastTip()->GetHeight() + 1; + if ( params.size() == 5 ) + createtxid = Parseuint256((char *)params[4].get_str().c_str()); + return(MarmaraReceive(0,pubkey2pk(senderpub),amount,currency,matures,createtxid)); +} + UniValue channelslist(const UniValue& params, bool fHelp) { if ( fHelp || params.size() > 0 ) From 2084694843126a610875b6a5294219b30e0c3925 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 03:08:37 -1100 Subject: [PATCH 231/643] Syntax --- src/wallet/rpcwallet.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a2b0afa37..7160489de 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5549,10 +5549,11 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) UniValue marmara_receive(const UniValue& params, bool fHelp) { - uint256 createtxid; std::vector senderpub; int64_t amount; int32_t matures; + UniValue result(UniValue::VOBJ); uint256 createtxid; std::vector senderpub; int64_t amount; int32_t matures; std::string currency; if ( fHelp || (params.size() != 5 && params.size() != 4) ) { - // marmarareceive 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1440 + // 1st marmarareceive 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1440 + // after marmarareceive 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1440 throw runtime_error("marmarareceive senderpk amount currency matures createtxid\n"); } if ( ensure_CCrequirements() < 0 ) From a90b1bb7d516a9e21d8ae9f5bb751024923ef016 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 03:10:35 -1100 Subject: [PATCH 232/643] Clear default errorstr --- src/cc/marmara.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 1ff1855dd..353e07a30 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -332,6 +332,8 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri if ( needbaton != 0 ) mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee,senderpk)); rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('R',createtxid,senderpk,amount,matures,currency)); + if ( rawtx.size() > 0 ) + errorstr = 0; } else errorstr = (char *)"dont have enough normal inputs for 2*txfee"; } if ( rawtx.size() == 0 || errorstr != 0 ) From 46069b7159ed360f0ec32e92d79a9553468cfd58 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 03:12:07 -1100 Subject: [PATCH 233/643] funcid --- src/cc/marmara.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 353e07a30..85487f748 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -346,6 +346,7 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri { result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); + result.push_back(Pair("funcid","R")); result.push_back(Pair("createtxid",createtxid.GetHex())); result.push_back(Pair("senderpk",HexStr(senderpk))); result.push_back(Pair("amount",ValueFromAmount(amount))); From c10dfbb858ed1f36384043a82ff1a033f2a6299c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 03:21:20 -1100 Subject: [PATCH 234/643] marmara_issue --- src/cc/CCMarmara.h | 1 + src/cc/marmara.cpp | 45 ++++++++++++++++++++++++++++++++++++++++ src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/wallet/rpcwallet.cpp | 23 ++++++++++++++++++++ 5 files changed, 71 insertions(+) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index d3eb67b77..5fc1ce891 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -26,6 +26,7 @@ uint64_t komodo_block_prg(uint32_t nHeight); UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...] UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid); +UniValue MarmaraIssue(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid); bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 85487f748..5cd623966 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -356,6 +356,51 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri return(result); } +UniValue MarmaraIssue(uint64_t txfee,CPubKey receiverpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid) +{ + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + UniValue result(UniValue::VOBJ); CPubKey mypk; struct CCcontract_info *cp,C; std::string rawtx; char *errorstr=0; + cp = CCinit(&C,EVAL_MARMARA); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + if ( currency != "MARMARA" ) + errorstr = (char *)"for now, only MARMARA loops are supported"; + else if ( amount < txfee ) + errorstr = (char *)"amount must be for more than txfee"; + else if ( matures <= chainActive.LastTip()->GetHeight() ) + errorstr = (char *)"it must mature in the future"; + if ( errorstr == 0 ) + { + if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) + { + errorstr = (char *)"couldnt finalize CCtx"; + mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee,receiverpk)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('I',createtxid,receiverpk,amount,matures,currency)); + if ( rawtx.size() > 0 ) + errorstr = 0; + } else errorstr = (char *)"dont have enough normal inputs for 2*txfee"; + } + if ( rawtx.size() == 0 || errorstr != 0 ) + { + result.push_back(Pair("result","error")); + if ( errorstr != 0 ) + result.push_back(Pair("error",errorstr)); + } + else + { + result.push_back(Pair("result",(char *)"success")); + result.push_back(Pair("rawtx",rawtx)); + result.push_back(Pair("funcid","R")); + result.push_back(Pair("createtxid",createtxid.GetHex())); + result.push_back(Pair("receiverpk",HexStr(receiverpk))); + result.push_back(Pair("amount",ValueFromAmount(amount))); + result.push_back(Pair("matures",matures)); + result.push_back(Pair("currency",currency)); + } + return(result); +} + std::string MarmaraFund(uint64_t txfee,int64_t funds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 5baadf34a..add90902c 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -445,6 +445,7 @@ static const CRPCCommand vRPCCommands[] = { "marmara", "marmaraaddress", &marmaraaddress, true }, { "marmara", "marmarapoolpayout", &marmara_poolpayout, true }, { "marmara", "marmarareceive", &marmara_receive, true }, + { "marmara", "marmaraissue", &marmara_issue, true }, // Payments { "payments", "paymentsaddress", &paymentsaddress, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 4787130e2..b7654da38 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -274,6 +274,7 @@ extern UniValue pegsaddress(const UniValue& params, bool fHelp); extern UniValue marmaraaddress(const UniValue& params, bool fHelp); extern UniValue marmara_poolpayout(const UniValue& params, bool fHelp); extern UniValue marmara_receive(const UniValue& params, bool fHelp); +extern UniValue marmara_issue(const UniValue& params, bool fHelp); extern UniValue paymentsaddress(const UniValue& params, bool fHelp); extern UniValue gatewaysaddress(const UniValue& params, bool fHelp); extern UniValue gatewayslist(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 7160489de..bb6bb8c12 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5573,6 +5573,29 @@ UniValue marmara_receive(const UniValue& params, bool fHelp) return(MarmaraReceive(0,pubkey2pk(senderpub),amount,currency,matures,createtxid)); } +UniValue marmara_issue(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); uint256 createtxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; + if ( fHelp || params.size() != 5 ) + { + // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1440 e5b1ef8ec90e981d3011c8e024cef869b69af2d4dd6837d1ab1d394d3730b7cb + throw runtime_error("marmarareceive receiverpk amount currency matures createtxid\n"); + } + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + receiverpub = ParseHex(params[0].get_str().c_str()); + if (receiverpub.size()!= 33) + { + ERR_RESULT("invalid receiverpub pubkey"); + return result; + } + amount = atof(params[1].get_str().c_str()) * COIN + 0.00000000499999; + currency = params[2].get_str(); + matures = atol(params[3].get_str().c_str()) + chainActive.LastTip()->GetHeight() + 1; + createtxid = Parseuint256((char *)params[4].get_str().c_str()); + return(MarmaraIssue(0,pubkey2pk(receiverpub),amount,currency,matures,createtxid)); +} + UniValue channelslist(const UniValue& params, bool fHelp) { if ( fHelp || params.size() > 0 ) From 8ae7b65569a4f5dc8b0aee5929841a544e518539 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 03:26:43 -1100 Subject: [PATCH 235/643] Off by 1 --- src/cc/marmara.cpp | 2 +- src/wallet/rpcwallet.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 5cd623966..1b06dfd2f 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -391,7 +391,7 @@ UniValue MarmaraIssue(uint64_t txfee,CPubKey receiverpk,int64_t amount,std::stri { result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); - result.push_back(Pair("funcid","R")); + result.push_back(Pair("funcid","I")); result.push_back(Pair("createtxid",createtxid.GetHex())); result.push_back(Pair("receiverpk",HexStr(receiverpk))); result.push_back(Pair("amount",ValueFromAmount(amount))); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index bb6bb8c12..e77f8e55a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5578,8 +5578,8 @@ UniValue marmara_issue(const UniValue& params, bool fHelp) UniValue result(UniValue::VOBJ); uint256 createtxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; if ( fHelp || params.size() != 5 ) { - // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1440 e5b1ef8ec90e981d3011c8e024cef869b69af2d4dd6837d1ab1d394d3730b7cb - throw runtime_error("marmarareceive receiverpk amount currency matures createtxid\n"); + // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 2693 e5b1ef8ec90e981d3011c8e024cef869b69af2d4dd6837d1ab1d394d3730b7cb + throw runtime_error("marmaraissue receiverpk amount currency matures createtxid\n"); } if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); @@ -5591,7 +5591,7 @@ UniValue marmara_issue(const UniValue& params, bool fHelp) } amount = atof(params[1].get_str().c_str()) * COIN + 0.00000000499999; currency = params[2].get_str(); - matures = atol(params[3].get_str().c_str()) + chainActive.LastTip()->GetHeight() + 1; + matures = atol(params[3].get_str().c_str()); createtxid = Parseuint256((char *)params[4].get_str().c_str()); return(MarmaraIssue(0,pubkey2pk(receiverpub),amount,currency,matures,createtxid)); } From c334d5c2e426605445bb6a5372dcfb3c99d634d9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 03:36:14 -1100 Subject: [PATCH 236/643] Marmara transfer --- src/cc/CCMarmara.h | 2 +- src/cc/marmara.cpp | 5 +++-- src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/wallet/rpcwallet.cpp | 25 ++++++++++++++++++++++++- 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 5fc1ce891..8fbe25b62 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -26,7 +26,7 @@ uint64_t komodo_block_prg(uint32_t nHeight); UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...] UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid); -UniValue MarmaraIssue(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid); +UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid); bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 1b06dfd2f..41287c76f 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -356,7 +356,7 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri return(result); } -UniValue MarmaraIssue(uint64_t txfee,CPubKey receiverpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid) +UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); UniValue result(UniValue::VOBJ); CPubKey mypk; struct CCcontract_info *cp,C; std::string rawtx; char *errorstr=0; @@ -391,7 +391,8 @@ UniValue MarmaraIssue(uint64_t txfee,CPubKey receiverpk,int64_t amount,std::stri { result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); - result.push_back(Pair("funcid","I")); + char str[2]; str[0] = funcid, str[1] = 0; + result.push_back(Pair("funcid",str)); result.push_back(Pair("createtxid",createtxid.GetHex())); result.push_back(Pair("receiverpk",HexStr(receiverpk))); result.push_back(Pair("amount",ValueFromAmount(amount))); diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index add90902c..497cb1ae2 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -446,6 +446,7 @@ static const CRPCCommand vRPCCommands[] = { "marmara", "marmarapoolpayout", &marmara_poolpayout, true }, { "marmara", "marmarareceive", &marmara_receive, true }, { "marmara", "marmaraissue", &marmara_issue, true }, + { "marmara", "marmaratransfer", &marmara_transfer, true }, // Payments { "payments", "paymentsaddress", &paymentsaddress, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index b7654da38..19680c0ef 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -275,6 +275,7 @@ extern UniValue marmaraaddress(const UniValue& params, bool fHelp); extern UniValue marmara_poolpayout(const UniValue& params, bool fHelp); extern UniValue marmara_receive(const UniValue& params, bool fHelp); extern UniValue marmara_issue(const UniValue& params, bool fHelp); +extern UniValue marmara_transfer(const UniValue& params, bool fHelp); extern UniValue paymentsaddress(const UniValue& params, bool fHelp); extern UniValue gatewaysaddress(const UniValue& params, bool fHelp); extern UniValue gatewayslist(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e77f8e55a..d0dc60489 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5593,7 +5593,30 @@ UniValue marmara_issue(const UniValue& params, bool fHelp) currency = params[2].get_str(); matures = atol(params[3].get_str().c_str()); createtxid = Parseuint256((char *)params[4].get_str().c_str()); - return(MarmaraIssue(0,pubkey2pk(receiverpub),amount,currency,matures,createtxid)); + return(MarmaraIssue(0,'I',pubkey2pk(receiverpub),amount,currency,matures,createtxid)); +} + +UniValue marmara_transfer(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); uint256 createtxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; + if ( fHelp || params.size() != 5 ) + { + // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 2693 e5b1ef8ec90e981d3011c8e024cef869b69af2d4dd6837d1ab1d394d3730b7cb + throw runtime_error("marmaratransfer receiverpk amount currency matures createtxid\n"); + } + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + receiverpub = ParseHex(params[0].get_str().c_str()); + if (receiverpub.size()!= 33) + { + ERR_RESULT("invalid receiverpub pubkey"); + return result; + } + amount = atof(params[1].get_str().c_str()) * COIN + 0.00000000499999; + currency = params[2].get_str(); + matures = atol(params[3].get_str().c_str()); + createtxid = Parseuint256((char *)params[4].get_str().c_str()); + return(MarmaraIssue(0,'T',pubkey2pk(receiverpub),amount,currency,matures,createtxid)); } UniValue channelslist(const UniValue& params, bool fHelp) From e06138fecf70ac4e36ce1e084e64b1336738ec42 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 05:34:42 -1100 Subject: [PATCH 237/643] Cap -ac_perc to be based on million max --- src/cc/marmara.cpp | 19 +++++-------------- src/komodo_bitcoind.h | 6 ++++-- src/wallet/rpcwallet.cpp | 2 +- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 41287c76f..9a5a1e6ef 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -251,20 +251,9 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t } else if ( funcid == 'S' ) // collect -> automatically spend issuers locked funds, given 'I' { - return(true); - } - else if ( funcid == 'A' ) // agree -> agree that 'I' is unable to be redeemed, remainder - { - return(true); - } - else if ( funcid == 'D' ) // dispute -> given 'I' submit for manual arbitration - { - return(true); - } - else if ( funcid == 'F' ) // foreclose -> given 'A' collect as much of remainder from credit loop - { - return(true); + return(true); // iterate from issuer all remainder after maturity } + // staking only for locked utxo } return eval->Invalid("fall through error"); } @@ -315,6 +304,7 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; + // check for batonownership by senderpk and parameters match createtxid mypk = pubkey2pk(Mypubkey()); if ( currency != "MARMARA" ) errorstr = (char *)"for now, only MARMARA loops are supported"; @@ -363,6 +353,7 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; + // make sure if transfer that it is not too late mypk = pubkey2pk(Mypubkey()); if ( currency != "MARMARA" ) errorstr = (char *)"for now, only MARMARA loops are supported"; @@ -376,7 +367,7 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a { errorstr = (char *)"couldnt finalize CCtx"; mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee,receiverpk)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('I',createtxid,receiverpk,amount,matures,currency)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret(funcid,createtxid,receiverpk,amount,matures,currency)); if ( rawtx.size() > 0 ) errorstr = 0; } else errorstr = (char *)"dont have enough normal inputs for 2*txfee"; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 841396a00..9ecb8ce77 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1165,10 +1165,12 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) //fprintf(stderr,"(%d %.8f).%d ",i,dstr(pblock->vtx[i].vout[j].nValue),j); if ( i != 0 || j != 1 ) total += pblock->vtx[i].vout[j].nValue; + if ( total > 1000000 * COIN ) + total = 1000000 * COIN; } } - commission = ((total / 10000) * ASSETCHAINS_COMMISSION) / 10000; - //commission = ((total * ASSETCHAINS_COMMISSION) / COIN); + //commission = ((total / 10000) * ASSETCHAINS_COMMISSION) / 10000; + commission = ((total * ASSETCHAINS_COMMISSION) / COIN); } if ( commission < 10000 ) commission = 0; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d0dc60489..f17faca58 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5601,7 +5601,7 @@ UniValue marmara_transfer(const UniValue& params, bool fHelp) UniValue result(UniValue::VOBJ); uint256 createtxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; if ( fHelp || params.size() != 5 ) { - // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 2693 e5b1ef8ec90e981d3011c8e024cef869b69af2d4dd6837d1ab1d394d3730b7cb + // marmaratransfer 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 2693 e5b1ef8ec90e981d3011c8e024cef869b69af2d4dd6837d1ab1d394d3730b7cb throw runtime_error("marmaratransfer receiverpk amount currency matures createtxid\n"); } if ( ensure_CCrequirements() < 0 ) From e565e0b7204314b2e48fdf83d6454a97a9b04df3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 06:15:44 -1100 Subject: [PATCH 238/643] Break --- src/komodo_bitcoind.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9ecb8ce77..b99b998e1 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1166,7 +1166,10 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) if ( i != 0 || j != 1 ) total += pblock->vtx[i].vout[j].nValue; if ( total > 1000000 * COIN ) + { total = 1000000 * COIN; + break; + } } } //commission = ((total / 10000) * ASSETCHAINS_COMMISSION) / 10000; From aa7d0e8d888b5f11e4caf5e031924d2b196e8c93 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 06:57:20 -1100 Subject: [PATCH 239/643] Fix pos64 with verushash --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 128a94e3a..ce2b88156 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1197,7 +1197,7 @@ void static BitcoinMiner_noeq() miningTimer.start(); #ifdef ENABLE_WALLET - CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, Mining_height, 0); + CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, Mining_height, ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", -1) == 0); #else CBlockTemplate *ptr = CreateNewBlockWithKey(); #endif From 530fb3901342196b595572ffe6519d0516ec525f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:04:45 -1100 Subject: [PATCH 240/643] +print --- src/komodo_bitcoind.h | 4 ++-- src/miner.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b99b998e1..b640d3db0 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2084,7 +2084,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt komodo_segids(hashbuf,nHeight-101,100); 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); +fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); bool resetstaker = false; if ( array != 0 ) @@ -2140,7 +2140,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt 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,"numkp.%d blocktime.%u\n",numkp,*blocktimep); +fprintf(stderr,"numkp.%d blocktime.%u\n",numkp,*blocktimep); block_from_future_rejecttime = (uint32_t)GetAdjustedTime() + 57; for (i=winners=0; inBits); + printf("isStake.%d\n",isStake); if ( ASSETCHAINS_SYMBOL[0] != 0 && isStake ) { LEAVE_CRITICAL_SECTION(cs_main); From 6c9d66ed0de5ca0af847cbf139251fefa6669dab Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:10:50 -1100 Subject: [PATCH 241/643] Set isStaked --- src/miner.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 02a3e1a91..2c6f4af8d 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -482,7 +482,6 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 int32_t stakeHeight = chainActive.Height() + 1; //LogPrintf("CreateNewBlock(): total size %u blocktime.%u nBits.%08x\n", nBlockSize,blocktime,pblock->nBits); - printf("isStake.%d\n",isStake); if ( ASSETCHAINS_SYMBOL[0] != 0 && isStake ) { LEAVE_CRITICAL_SECTION(cs_main); @@ -802,6 +801,8 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, } if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) scriptPubKey = Marmara_scriptPubKey(nHeight,pubkey); + if ( ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0 ) + isStake = true; return CreateNewBlock(pubkey,scriptPubKey, gpucount, isStake); } @@ -1198,7 +1199,7 @@ void static BitcoinMiner_noeq() miningTimer.start(); #ifdef ENABLE_WALLET - CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, Mining_height, ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", -1) == 0); + CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, Mining_height, 0); #else CBlockTemplate *ptr = CreateNewBlockWithKey(); #endif From db879566f571cc7c123b554fe83769d845ead722 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:16:34 -1100 Subject: [PATCH 242/643] Test --- src/komodo_bitcoind.h | 8 ++++---- src/miner.cpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b640d3db0..66097b3f9 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1312,12 +1312,12 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } if ( validateflag != 0 ) { - /*for (i=31; i>=24; i--) + for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); fprintf(stderr," vs "); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff);*/ + fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff); break; } } @@ -2084,7 +2084,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt komodo_segids(hashbuf,nHeight-101,100); 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); +//fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); bool resetstaker = false; if ( array != 0 ) @@ -2140,7 +2140,7 @@ fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL), 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,"numkp.%d blocktime.%u\n",numkp,*blocktimep); +//fprintf(stderr,"numkp.%d blocktime.%u\n",numkp,*blocktimep); block_from_future_rejecttime = (uint32_t)GetAdjustedTime() + 57; for (i=winners=0; iGetHeight()+1, gpucount, ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", -1) == 0); + CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, pindexPrev->GetHeight()+1, gpucount, ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0); #else CBlockTemplate *ptr = CreateNewBlockWithKey(); #endif @@ -1502,7 +1502,7 @@ void static BitcoinMiner() { static uint32_t counter; if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 ) - fprintf(stderr,"created illegal block, retry\n"); + fprintf(stderr,"created illegal blockB, retry\n"); sleep(1); continue; } From 3118af7d07ab9b9375a8b8c1b4fb6a579a6100be Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:24:38 -1100 Subject: [PATCH 243/643] +print --- src/komodo_bitcoind.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 66097b3f9..478aa9ac4 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2039,9 +2039,9 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod kp->hashval = UintToArith256(hash); segid = ((nHeight + kp->segid32) & 0x3f); hashval = _komodo_eligible(kp,ratio,blocktime,maxiters,minage,segid,nHeight,prevtime); - //for (int i=32; i>=0; i--) - // fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); - //fprintf(stderr," b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime); + for (int i=32; i>=0; i--) + fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + fprintf(stderr," b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime); if ( hashval <= bnTarget ) { for (iter=0; iter Date: Sun, 13 Jan 2019 07:26:02 -1100 Subject: [PATCH 244/643] Test --- src/miner.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index f88b8f260..f6c3e1aac 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1199,14 +1199,14 @@ void static BitcoinMiner_noeq() miningTimer.start(); #ifdef ENABLE_WALLET - CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, Mining_height, 0); + CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, Mining_height, ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0); #else CBlockTemplate *ptr = CreateNewBlockWithKey(); #endif if ( ptr == 0 ) { static uint32_t counter; - if ( counter++ < 100 ) + if ( counter++ < 10 ) fprintf(stderr,"created illegal block, retry\n"); continue; } @@ -1501,7 +1501,7 @@ void static BitcoinMiner() if ( ptr == 0 ) { static uint32_t counter; - if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 ) + if ( counter++ < 10 && ASSETCHAINS_STAKED == 0 ) fprintf(stderr,"created illegal blockB, retry\n"); sleep(1); continue; From 290926a05f81cbb586d60d24f106415507851981 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:34:22 -1100 Subject: [PATCH 245/643] Test --- src/komodo_bitcoind.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 478aa9ac4..fb5ca24a0 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1312,12 +1312,12 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } if ( validateflag != 0 ) { - for (i=31; i>=24; i--) + /*for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); fprintf(stderr," vs "); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff); + fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff);*/ break; } } @@ -2039,8 +2039,11 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod kp->hashval = UintToArith256(hash); segid = ((nHeight + kp->segid32) & 0x3f); hashval = _komodo_eligible(kp,ratio,blocktime,maxiters,minage,segid,nHeight,prevtime); - for (int i=32; i>=0; i--) + for (int i=31; i>=16; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + fprintf(stderr," vs "); + for (int i=31; i>=16; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); fprintf(stderr," b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime); if ( hashval <= bnTarget ) { From 265c9b3c3b04bc1234594bc5aaee344502dff81c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:40:06 -1100 Subject: [PATCH 246/643] Test --- src/komodo_bitcoind.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index fb5ca24a0..9e05ea1f9 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2052,9 +2052,15 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod if ( blocktime+iter+segid*2 < kp->txtime+minage ) continue; hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime); + for (int i=31; i>=16; i--) + fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + fprintf(stderr," vs "); + for (int i=31; i>=16; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," iter.%d\n",iter); if ( hashval <= bnTarget ) { - //fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid); + fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid); blocktime += iter; blocktime += segid * 2; return(blocktime); From 6922cdfa835e697a850bfed64e0a90f61ab42e39 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:43:40 -1100 Subject: [PATCH 247/643] Test --- src/komodo_bitcoind.h | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9e05ea1f9..bf7dff756 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2039,12 +2039,12 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod kp->hashval = UintToArith256(hash); segid = ((nHeight + kp->segid32) & 0x3f); hashval = _komodo_eligible(kp,ratio,blocktime,maxiters,minage,segid,nHeight,prevtime); - for (int i=31; i>=16; i--) + /*for (int i=31; i>=16; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); fprintf(stderr," vs "); for (int i=31; i>=16; i--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime); + fprintf(stderr," b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime);*/ if ( hashval <= bnTarget ) { for (iter=0; itertxtime+minage ) continue; hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime); - for (int i=31; i>=16; i--) - fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); - fprintf(stderr," vs "); - for (int i=31; i>=16; i--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," iter.%d\n",iter); if ( hashval <= bnTarget ) { fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid); @@ -2164,7 +2158,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; @@ -2177,7 +2171,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 @@ -2187,7 +2181,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; @@ -2199,7 +2193,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt *txtimep = kp->txtime;//(uint32_t)out.tx->nLockTime; 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,"utxo not eligible\n"); } if ( numkp < 1000 && array != 0 ) { From 31bad59a04c8a09aa92c53a4d96e203fe4ef9094 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:46:32 -1100 Subject: [PATCH 248/643] Test --- src/komodo_bitcoind.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index bf7dff756..634f61abf 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1267,7 +1267,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { - //fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); + fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); return(0); } if ( value < SATOSHIDEN ) @@ -1312,12 +1312,12 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } if ( validateflag != 0 ) { - /*for (i=31; i>=24; i--) + for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); fprintf(stderr," vs "); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff);*/ + fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff); break; } } @@ -2054,7 +2054,7 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime); if ( hashval <= bnTarget ) { - fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid); + //fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid); blocktime += iter; blocktime += segid * 2; return(blocktime); From 05f3d0f8723ba0810ba099ba5cdcc5e094fcbadf Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:52:01 -1100 Subject: [PATCH 249/643] Test --- src/komodo_bitcoind.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 634f61abf..ae564dc80 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1304,7 +1304,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh winner = 1; if ( validateflag == 0 ) { - //fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); + fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); blocktime += iter; blocktime += segid * 2; } @@ -1312,17 +1312,17 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } if ( validateflag != 0 ) { - for (i=31; i>=24; i--) + /*for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); fprintf(stderr," vs "); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff); + fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff);*/ break; } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - if ( 0 && validateflag != 0 ) + //if ( 0 && validateflag != 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); From b7f3a6778a92c16a5d93eb8ffa2906c2910a2eba Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:58:01 -1100 Subject: [PATCH 250/643] Test --- src/komodo_bitcoind.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index ae564dc80..7741bfb11 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2158,7 +2158,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; @@ -2171,7 +2171,7 @@ fprintf(stderr,"i.%d %u vs %u\n",i,eligible2,eligible); 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 @@ -2181,7 +2181,7 @@ fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u te } 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; @@ -2193,7 +2193,7 @@ fprintf(stderr,"ht.%d validated winning [%d] -> %.8f eligible.%u test prior\n",n *txtimep = kp->txtime;//(uint32_t)out.tx->nLockTime; 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,"utxo not eligible\n"); } if ( numkp < 1000 && array != 0 ) { @@ -2229,7 +2229,7 @@ fprintf(stderr,"ht.%d validated winning [%d] -> %.8f eligible.%u test prior\n",n for (i=0; i Date: Sun, 13 Jan 2019 07:59:28 -1100 Subject: [PATCH 251/643] Split commission calc --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 7741bfb11..9dc481529 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1172,8 +1172,8 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) } } } - //commission = ((total / 10000) * ASSETCHAINS_COMMISSION) / 10000; - commission = ((total * ASSETCHAINS_COMMISSION) / COIN); + commission = ((total / 10000) * ASSETCHAINS_COMMISSION) / 10000; + //commission = ((total * ASSETCHAINS_COMMISSION) / COIN); } if ( commission < 10000 ) commission = 0; From c50181ee6b42b611016553b37fb8615d1de78ce2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 08:10:52 -1100 Subject: [PATCH 252/643] Use BitcoinMiner for staking verushash --- src/komodo_bitcoind.h | 2 +- src/miner.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9dc481529..a469ad2ed 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1322,7 +1322,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - //if ( 0 && validateflag != 0 ) + if ( 0 && validateflag != 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); diff --git a/src/miner.cpp b/src/miner.cpp index f6c3e1aac..d68ea7369 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1907,12 +1907,12 @@ void static BitcoinMiner() for (int i = 0; i < nThreads; i++) { #ifdef ENABLE_WALLET - if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH) + if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH || (ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0) ) minerThreads->create_thread(boost::bind(&BitcoinMiner, pwallet)); else minerThreads->create_thread(boost::bind(&BitcoinMiner_noeq, pwallet)); #else - if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH) + if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH || (ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0) ) minerThreads->create_thread(&BitcoinMiner); else minerThreads->create_thread(&BitcoinMiner_noeq); From 5ee83c628c943094f7ab2c5b60c6d22ed65e5503 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 08:24:46 -1100 Subject: [PATCH 253/643] -print --- src/komodo_bitcoind.h | 6 +++--- src/miner.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index a469ad2ed..ebc50fa62 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1267,7 +1267,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { - fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); + //fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); return(0); } if ( value < SATOSHIDEN ) @@ -1304,7 +1304,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh winner = 1; if ( validateflag == 0 ) { - fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); + //fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); blocktime += iter; blocktime += segid * 2; } @@ -2229,7 +2229,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt for (i=0; i 1 ) { - fprintf(stderr,"mine to -ac_script\n"); + //fprintf(stderr,"mine to -ac_script\n"); //txNew.vout[1].scriptPubKey = CScript() << ParseHex(); int32_t len = strlen(ASSETCHAINS_SCRIPTPUB.c_str()); len >>= 1; From cf9f6577fc260772a5f47ac022246577599d7622 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 14:10:11 -1100 Subject: [PATCH 254/643] Adjust assert --- src/wallet/rpcwallet.cpp | 1 + src/wallet/wallet.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index f17faca58..007c187a6 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5537,6 +5537,7 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 3 ) { // marmarapoolpayout 0.5 2 '[["024131032ed90941e714db8e6dd176fe5a86c9d873d279edecf005c06f773da686",1000],["02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92",100]]'; + marmarapoolpayout 0 2 '[["024131032ed90941e714db8e6dd176fe5a86c9d873d279edecf005c06f773da686",1000]]' throw runtime_error("marmarapoolpayout perc firstheight \"[[\\\"pubkey\\\":shares], ...]\"\n"); } if ( ensure_CCrequirements() < 0 ) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index dd188d418..0000f8d42 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1180,7 +1180,7 @@ bool DecrementNoteWitnesses(NoteDataMap& noteDataMap, int indexHeight, int64_t n assert((nWitnessCacheSize - 1) >= nd->witnesses.size()); } } - assert(KOMODO_REWIND != 0 || nWitnessCacheSize > 0); + assert(KOMODO_REWIND != 0 || nWitnessCacheSize > 0 || WITNESS_CACHE_SIZE != _COINBASE_MATURITY+10); return true; } From 920a182c2bfb26de0416c56e1d983deff0ec4bc8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Jan 2019 21:21:37 -1100 Subject: [PATCH 255/643] marmarainfo firstheight lastheight minamount maxamount [currency issuerpk] --- src/cc/CCMarmara.h | 9 ++- src/cc/CCinclude.h | 2 + src/cc/CCtx.cpp | 4 +- src/cc/marmara.cpp | 167 +++++++++++++++++++++++++++++++++------ src/rpc/server.cpp | 2 + src/rpc/server.h | 2 + src/wallet/rpcwallet.cpp | 69 +++++++++++++--- 7 files changed, 216 insertions(+), 39 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 8fbe25b62..79372fa27 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -23,10 +23,15 @@ #define MARMARA_GROUPSIZE 60 #define MARMARA_MINLOCK (1440 * 3 * 30) #define MARMARA_MAXLOCK (1440 * 24 * 30) + uint64_t komodo_block_prg(uint32_t nHeight); +int32_t MarmaraGetcreatetxid(uint256 &createtxid,uint256 txid); + UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...] -UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid); -UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid); +UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 batontxid); +UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t amount,std::string currency,int32_t matures,uint256 approvaltxid,uint256 batontxid); +UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,std::string currency); +UniValue MarmaraCrediloop(uint256 batontxid); bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index aaeadcc61..0744156a5 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -56,6 +56,8 @@ extern uint32_t ASSETCHAINS_CC; extern char ASSETCHAINS_SYMBOL[]; extern std::string CCerror; +#define CC_MAXVINS 1024 + #define SMALLVAL 0.000000000000001 #ifndef _BITS256 #define _BITS256 diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 32d525517..a70d4f038 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -42,7 +42,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); CTransaction vintx; std::string hex; uint256 hashBlock; uint64_t mask=0,nmask=0,vinimask=0; - int64_t utxovalues[64],change,normalinputs=0,totaloutputs=0,normaloutputs=0,totalinputs=0,normalvins=0,ccvins=0; + int64_t utxovalues[CC_MAXVINS],change,normalinputs=0,totaloutputs=0,normaloutputs=0,totalinputs=0,normalvins=0,ccvins=0; int32_t i,utxovout,n,err = 0; char myaddr[64],destaddr[64],unspendable[64]; uint8_t *privkey,myprivkey[32],unspendablepriv[32],*msg32 = 0; CC *mycond=0,*othercond=0,*othercond2=0,*othercond3=0,*cond; CPubKey unspendablepk; n = mtx.vout.size(); @@ -52,7 +52,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran normaloutputs += mtx.vout[i].nValue; totaloutputs += mtx.vout[i].nValue; } - if ( (n= mtx.vin.size()) > 64 ) + if ( (n= mtx.vin.size()) > CC_MAXVINS ) { fprintf(stderr,"FinalizeCCTx: %d is too many vins\n",n); return("0"); diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 9a5a1e6ef..ba238e755 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -18,6 +18,25 @@ /* Marmara CC is for the MARMARA project + 'R': two forms for initial issuance and for accepting existing + vins normal + vout0 approval to senderpk (issuer or owner of baton) + + 'I' + vin0 approval from 'R' + vins1+ normal + vout0 baton to 1st receiverpk + vout1 marker to Marmara so all issuances can be tracked (spent when loop is closed) + + 'T' + vin0 approval from 'R' + vin1 baton from 'I'/'T' + vins2+ normal + vout0 baton to next receiverpk (following the unspent baton back to original is the credit loop) + + 'S' + vins CC utxos from credit loop + */ // start of consensus code @@ -138,6 +157,29 @@ CScript MarmaraLoopOpret(uint8_t funcid,uint256 createtxid,CPubKey senderpk,int6 return(opret); } +uint8_t MarmaraDecodeLoopOpret(const CScript scriptPubKey,uint256 &createtxid,CPubKey &senderpk,int64_t &amount,int32_t &matures,std::string ¤cy) +{ + std::vector vopret; uint8_t *script,e,f; + GetOpReturnData(scriptPubKey, vopret); + script = (uint8_t *)vopret.data(); + if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> createtxid; ss >> senderpk; ss >> amount; ss >> matures; ss >> currency) != 0 ) + { + return(f); + } + return(0); +} + +int32_t MarmaraGetcreatetxid(uint256 &createtxid,uint256 txid) +{ + CTransaction tx; uint256 hashBlock; int32_t numvouts,matures; std::string currency; CPubKey senderpk; int64_t amount; + if ( myGetTransaction(batontxid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 1 ) + { + if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,senderpk,amount,matures,currency)) == 'I' || funcid == 'T' ) + return(0); + } + return(-1); +} + CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) { CTxOut ccvout; @@ -297,16 +339,51 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, return(totalinputs); } -UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid) +int32_t MarmaraGetCreditloops(int64_t &totalamount,std::vector &issuances,struct CCcontract_info *cp,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,CPubKey refpk,std::string refcurrency) +{ + char coinaddr[64]; CPubKey Marmarapk,senderpk; int64_t amount; uint256 createtxid,txid,hashBlock; CTransaction tx; int32_t numvouts,unlockht,ht,vout,matures,n=0; + std::vector > unspentOutputs; + Marmarapk = GetUnspendable(cp,0); + GetCCaddress(cp,coinaddr,Marmarapk); + SetCCunspents(unspentOutputs,coinaddr); + //fprintf(stderr,"check coinaddr.(%s)\n",coinaddr); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + txid = it->first.txhash; + vout = (int32_t)it->first.index; + //fprintf(stderr,"txid.%s/v%d\n",txid.GetHex().c_str(),vout); + if ( vout == 1 && GetTransaction(txid,tx,hashBlock,false) != 0 ) + { + if ( tx.IsCoinBase() == 0 && (numvouts= tx.vout.size()) > 2 && tx.vout[numvouts - 1].nValue == 0 ) + { + if ( MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,senderpk,amount,matures,currency) == 'I' ) + { + n++; + if ( currency == refcurrency && matures >= firstheight && matures <= lastheight && amount >= minamount && amount <= maxamount && (refpk.size() == 0 || senderpk == refpk) ) + { + issuances.push_back(txid); + totalamount += amount; + } + } + } + } else fprintf(stderr,"error getting tx\n"); + } + return(n); +} + +UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 batontxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); CPubKey mypk; struct CCcontract_info *cp,C; std::string rawtx; char *errorstr=0; int32_t needbaton = 0; + UniValue result(UniValue::VOBJ); CPubKey mypk; struct CCcontract_info *cp,C; std::string rawtx; char *errorstr=0; uint256 createtxid; int32_t needbaton = 0; cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; // check for batonownership by senderpk and parameters match createtxid mypk = pubkey2pk(Mypubkey()); - if ( currency != "MARMARA" ) + memset(&createtxid,0,sizeof(createtxid)); + if ( batontxid != zeroid && MarmaraGetcreatetxid(createtxid,batontxid) < 0 ) + errorstr = (char *)"cant get createtxid from batontxid"; + else if ( currency != "MARMARA" ) errorstr = (char *)"for now, only MARMARA loops are supported"; else if ( amount < txfee ) errorstr = (char *)"amount must be for more than txfee"; @@ -346,16 +423,20 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri return(result); } -UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid) +UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t amount,std::string currency,int32_t matures,uint256 approvaltxid,uint256 batontxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); CPubKey mypk; struct CCcontract_info *cp,C; std::string rawtx; char *errorstr=0; + UniValue result(UniValue::VOBJ); CPubKey mypk,Marmarapk; struct CCcontract_info *cp,C; std::string rawtx; uint256 createtxid; char *errorstr=0; cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; - // make sure if transfer that it is not too late + // make sure receiverpk is unique to creditloop + // make sure less than maxlength + Marmarapk = GetUnspendable(cp,0); mypk = pubkey2pk(Mypubkey()); - if ( currency != "MARMARA" ) + if ( MarmaraGetcreatetxid(createtxid,approvaltxid) < 0 ) + errorstr = (char *)"cant get createtxid from approvaltxid"; + else if ( currency != "MARMARA" ) errorstr = (char *)"for now, only MARMARA loops are supported"; else if ( amount < txfee ) errorstr = (char *)"amount must be for more than txfee"; @@ -363,10 +444,15 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a errorstr = (char *)"it must mature in the future"; if ( errorstr == 0 ) { - if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) + mtx.vin.push_back(CTxIn(approvaltxid,0,CScript())); + if ( funcid == 'T' ) + mtx.vin.push_back(CTxIn(batontxid,0,CScript())); + if ( funcid == 'I' || AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) { errorstr = (char *)"couldnt finalize CCtx"; mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee,receiverpk)); + if ( funcid == 'I' ) + mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee,Marmarapk)); rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret(funcid,createtxid,receiverpk,amount,matures,currency)); if ( rawtx.size() > 0 ) errorstr = 0; @@ -385,6 +471,9 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a char str[2]; str[0] = funcid, str[1] = 0; result.push_back(Pair("funcid",str)); result.push_back(Pair("createtxid",createtxid.GetHex())); + result.push_back(Pair("approvaltxid",approvaltxid.GetHex())); + if ( funcid == 'T' ) + result.push_back(Pair("batontxid",batontxid.GetHex())); result.push_back(Pair("receiverpk",HexStr(receiverpk))); result.push_back(Pair("amount",ValueFromAmount(amount))); result.push_back(Pair("matures",matures)); @@ -393,32 +482,64 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a return(result); } -std::string MarmaraFund(uint64_t txfee,int64_t funds) +// get creditloop pubkeys + +UniValue Marmara(uint64_t txfee,uint256 batontxid) { - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Marmarapk; CScript opret; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ); int64_t avail,amount,paid=0; int32_t i,n = 0; uint256 txid,*revcreditloop=0; CPubKey Marmarapk; struct CCcontract_info *cp,C; + result.push_back(Pair("result","success")); cp = CCinit(&C,EVAL_MARMARA); - if ( txfee == 0 ) - txfee = 10000; - mypk = pubkey2pk(Mypubkey()); Marmarapk = GetUnspendable(cp,0); - if ( AddNormalinputs(mtx,mypk,funds+txfee,64) > 0 ) + txid = batontxid; + while ( txid.hasprev() != 0 ) { - mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,funds,Marmarapk)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); + txid = txid.prev(); + // check for unique, else error + revcreditloop[n++] = txid; } - return(""); + for (i=0; i= amount ) + { + change = (amount - paid); + break; + } + } + + return(result); } -UniValue MarmaraInfo() +UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,std::string currency) { - UniValue result(UniValue::VOBJ); char numstr[64]; - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey Marmarapk; struct CCcontract_info *cp,C; int64_t funding; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); int32_t i,n; int64_t totalamount=0; std::vector issuances; + CPubKey Marmarapk; struct CCcontract_info *cp,C; result.push_back(Pair("result","success")); - result.push_back(Pair("name","Marmara")); + if ( refpk.size() == 33 ) + result.push_back(Pair("issuer",HexStr(refpk))); + if ( currency.size() == 0 ) + currency = (char *)"MARMARA"; + if ( firstheight <= lastheight ) + firstheight = 0, lastheight = (1 << 30); + if ( minamount <= maxamount ) + minamount = 0, maxamount = (1LL << 60); + result.push_back(Pair("firstheight",firstheight)); + result.push_back(Pair("lastheight",lastheight)); + result.push_back(Pair("minamount",ValueFromAmount(minamount))); + result.push_back(Pair("maxamount",ValueFromAmount(maxamount))); + result.push_back(Pair("currency",currency)); cp = CCinit(&C,EVAL_MARMARA); Marmarapk = GetUnspendable(cp,0); + if ( (n= MarmaraGetCreditloops(totalamount,issuances,cp,firstheight,lastheight,minamount,maxamount,refpk,currency)) > 0 ) + { + result.push_back(Pair("n",n)); + matches = (int32_t)issuances.size(); + result.push_back(Pair("matches",matches)); + for (i=0; i senderpub; int64_t amount; int32_t matures; std::string currency; + UniValue result(UniValue::VOBJ); uint256 batontxid; std::vector senderpub; int64_t amount; int32_t matures; std::string currency; if ( fHelp || (params.size() != 5 && params.size() != 4) ) { // 1st marmarareceive 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1440 // after marmarareceive 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1440 - throw runtime_error("marmarareceive senderpk amount currency matures createtxid\n"); + throw runtime_error("marmarareceive senderpk amount currency matures batontxid\n"); } if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - memset(&createtxid,0,sizeof(createtxid)); + memset(&batontxid,0,sizeof(batontxid)); senderpub = ParseHex(params[0].get_str().c_str()); if (senderpub.size()!= 33) { @@ -5570,17 +5570,17 @@ UniValue marmara_receive(const UniValue& params, bool fHelp) currency = params[2].get_str(); matures = atol(params[3].get_str().c_str()) + chainActive.LastTip()->GetHeight() + 1; if ( params.size() == 5 ) - createtxid = Parseuint256((char *)params[4].get_str().c_str()); - return(MarmaraReceive(0,pubkey2pk(senderpub),amount,currency,matures,createtxid)); + batontxid = Parseuint256((char *)params[4].get_str().c_str()); + return(MarmaraReceive(0,pubkey2pk(senderpub),amount,currency,matures,batontxid)); } UniValue marmara_issue(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); uint256 createtxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; + UniValue result(UniValue::VOBJ); uint256 approvaltxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; if ( fHelp || params.size() != 5 ) { // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 2693 e5b1ef8ec90e981d3011c8e024cef869b69af2d4dd6837d1ab1d394d3730b7cb - throw runtime_error("marmaraissue receiverpk amount currency matures createtxid\n"); + throw runtime_error("marmaraissue receiverpk amount currency matures approvaltxid\n"); } if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); @@ -5593,8 +5593,8 @@ UniValue marmara_issue(const UniValue& params, bool fHelp) amount = atof(params[1].get_str().c_str()) * COIN + 0.00000000499999; currency = params[2].get_str(); matures = atol(params[3].get_str().c_str()); - createtxid = Parseuint256((char *)params[4].get_str().c_str()); - return(MarmaraIssue(0,'I',pubkey2pk(receiverpub),amount,currency,matures,createtxid)); + approvaltxid = Parseuint256((char *)params[4].get_str().c_str()); + return(MarmaraIssue(0,'I',pubkey2pk(receiverpub),amount,currency,matures,approvaltxid,zeroid)); } UniValue marmara_transfer(const UniValue& params, bool fHelp) @@ -5603,7 +5603,7 @@ UniValue marmara_transfer(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 5 ) { // marmaratransfer 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 2693 e5b1ef8ec90e981d3011c8e024cef869b69af2d4dd6837d1ab1d394d3730b7cb - throw runtime_error("marmaratransfer receiverpk amount currency matures createtxid\n"); + throw runtime_error("marmaratransfer receiverpk amount currency matures batontxid\n"); } if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); @@ -5616,8 +5616,53 @@ UniValue marmara_transfer(const UniValue& params, bool fHelp) amount = atof(params[1].get_str().c_str()) * COIN + 0.00000000499999; currency = params[2].get_str(); matures = atol(params[3].get_str().c_str()); - createtxid = Parseuint256((char *)params[4].get_str().c_str()); - return(MarmaraIssue(0,'T',pubkey2pk(receiverpub),amount,currency,matures,createtxid)); + batontxid = Parseuint256((char *)params[4].get_str().c_str()); + if ( MarmaraGetcreatetxid(createtxid,batontxid) < 0 ) + throw runtime_error("invalid batontxid"); + return(MarmaraIssue(0,'T',pubkey2pk(receiverpub),amount,currency,matures,createtxid,batontxid)); +} + +UniValue marmara_info(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); CPubKey issuerpk; std::vector issuerpub; int64_t minamount,maxamount; int32_t firstheight,lastheight; std::string currency; + if ( fHelp || params.size() < 4 || params.size() > 6 ) + { + throw runtime_error("marmarainfo firstheight lastheight minamount maxamount [currency issuerpk]\n"); + } + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + firstheight = atol(params[0].get_str().c_str()); + lastheight = atol(params[1].get_str().c_str()); + minamount = atof(params[2].get_str().c_str()) * COIN + 0.00000000499999; + maxamount = atof(params[3].get_str().c_str()) * COIN + 0.00000000499999; + if ( params.size() >= 5 ) + currency = params[4].get_str(); + if ( params.size() == 6 ) + { + issuerpub = ParseHex(params[5].get_str().c_str()); + if ( issuerpub.size()!= 33 ) + { + ERR_RESULT("invalid issuer pubkey"); + return result; + } + issuerpk = pubkey2pk(issuerpub); + } + result = MarmaraInfo(issuerpk,firstheight,lastheight,minamount,maxamount,currency); + return(result); +} + +UniValue marmara_creditloop(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); uint256 createtxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; + if ( fHelp || params.size() != 5 ) + { + // marmaratransfer 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 2693 e5b1ef8ec90e981d3011c8e024cef869b69af2d4dd6837d1ab1d394d3730b7cb + throw runtime_error("marmaratransfer receiverpk amount currency matures batontxid\n"); + } + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + //UniValue MarmaraCrediloop(uint256 batontxid); + return(result); } UniValue channelslist(const UniValue& params, bool fHelp) From fe0e9bd44ef146b8282b2d737543d3134ea581c6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Jan 2019 21:26:39 -1100 Subject: [PATCH 256/643] Syntax --- src/cc/marmara.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index ba238e755..1585bcc6b 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -171,8 +171,8 @@ uint8_t MarmaraDecodeLoopOpret(const CScript scriptPubKey,uint256 &createtxid,CP int32_t MarmaraGetcreatetxid(uint256 &createtxid,uint256 txid) { - CTransaction tx; uint256 hashBlock; int32_t numvouts,matures; std::string currency; CPubKey senderpk; int64_t amount; - if ( myGetTransaction(batontxid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 1 ) + CTransaction tx; uint256 hashBlock; uint8_t funcid; int32_t numvouts,matures; std::string currency; CPubKey senderpk; int64_t amount; + if ( myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 1 ) { if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,senderpk,amount,matures,currency)) == 'I' || funcid == 'T' ) return(0); @@ -341,7 +341,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, int32_t MarmaraGetCreditloops(int64_t &totalamount,std::vector &issuances,struct CCcontract_info *cp,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,CPubKey refpk,std::string refcurrency) { - char coinaddr[64]; CPubKey Marmarapk,senderpk; int64_t amount; uint256 createtxid,txid,hashBlock; CTransaction tx; int32_t numvouts,unlockht,ht,vout,matures,n=0; + char coinaddr[64]; CPubKey Marmarapk,senderpk; int64_t amount; uint256 createtxid,txid,hashBlock; CTransaction tx; int32_t numvouts,vout,matures,n=0; std::string currency; std::vector > unspentOutputs; Marmarapk = GetUnspendable(cp,0); GetCCaddress(cp,coinaddr,Marmarapk); @@ -484,7 +484,7 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a // get creditloop pubkeys -UniValue Marmara(uint64_t txfee,uint256 batontxid) +/*UniValue Marmara(uint64_t txfee,uint256 batontxid) { UniValue result(UniValue::VOBJ); int64_t avail,amount,paid=0; int32_t i,n = 0; uint256 txid,*revcreditloop=0; CPubKey Marmarapk; struct CCcontract_info *cp,C; result.push_back(Pair("result","success")); @@ -509,11 +509,11 @@ UniValue Marmara(uint64_t txfee,uint256 batontxid) } return(result); -} +}*/ UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,std::string currency) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); int32_t i,n; int64_t totalamount=0; std::vector issuances; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); int32_t i,n,matches; int64_t totalamount=0; std::vector issuances; CPubKey Marmarapk; struct CCcontract_info *cp,C; result.push_back(Pair("result","success")); if ( refpk.size() == 33 ) From 4f9ce5d4cc5fe824f6bb7c493042dd8d9f8e98bf Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Jan 2019 21:27:14 -1100 Subject: [PATCH 257/643] -ToString() --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 1585bcc6b..7188f510a 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -537,7 +537,7 @@ UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_ matches = (int32_t)issuances.size(); result.push_back(Pair("matches",matches)); for (i=0; i Date: Mon, 14 Jan 2019 21:32:18 -1100 Subject: [PATCH 258/643] Fix --- src/wallet/rpcwallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index f637f29b1..1c24547c2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5537,7 +5537,7 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 3 ) { // marmarapoolpayout 0.5 2 '[["024131032ed90941e714db8e6dd176fe5a86c9d873d279edecf005c06f773da686",1000],["02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92",100]]'; - marmarapoolpayout 0 2 '[["024131032ed90941e714db8e6dd176fe5a86c9d873d279edecf005c06f773da686",1000]]' + //marmarapoolpayout 0 2 '[["024131032ed90941e714db8e6dd176fe5a86c9d873d279edecf005c06f773da686",1000]]' throw runtime_error("marmarapoolpayout perc firstheight \"[[\\\"pubkey\\\":shares], ...]\"\n"); } if ( ensure_CCrequirements() < 0 ) @@ -5599,7 +5599,7 @@ UniValue marmara_issue(const UniValue& params, bool fHelp) UniValue marmara_transfer(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); uint256 createtxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; + UniValue result(UniValue::VOBJ); uint256 createtxid,batontxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; if ( fHelp || params.size() != 5 ) { // marmaratransfer 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 2693 e5b1ef8ec90e981d3011c8e024cef869b69af2d4dd6837d1ab1d394d3730b7cb From 3246b4306b13162c3b922d628432bb4d229fbc89 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Jan 2019 22:07:24 -1100 Subject: [PATCH 259/643] Allow 'R' --- src/cc/marmara.cpp | 2 +- src/wallet/rpcwallet.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 7188f510a..b69807884 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -174,7 +174,7 @@ int32_t MarmaraGetcreatetxid(uint256 &createtxid,uint256 txid) CTransaction tx; uint256 hashBlock; uint8_t funcid; int32_t numvouts,matures; std::string currency; CPubKey senderpk; int64_t amount; if ( myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 1 ) { - if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,senderpk,amount,matures,currency)) == 'I' || funcid == 'T' ) + if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,senderpk,amount,matures,currency)) == 'I' || funcid == 'T' || funcid == 'R' ) return(0); } return(-1); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1c24547c2..f5427fe70 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5553,8 +5553,8 @@ UniValue marmara_receive(const UniValue& params, bool fHelp) UniValue result(UniValue::VOBJ); uint256 batontxid; std::vector senderpub; int64_t amount; int32_t matures; std::string currency; if ( fHelp || (params.size() != 5 && params.size() != 4) ) { - // 1st marmarareceive 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1440 - // after marmarareceive 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1440 + // 1st marmarareceive 028076d42eb20efc10007fafb5ca66a2052523c0d2221e607adf958d1a332159f6 7.5 MARMARA 1440 + // after marmarareceive 028076d42eb20efc10007fafb5ca66a2052523c0d2221e607adf958d1a332159f6 7.5 MARMARA 1440 throw runtime_error("marmarareceive senderpk amount currency matures batontxid\n"); } if ( ensure_CCrequirements() < 0 ) @@ -5579,7 +5579,7 @@ UniValue marmara_issue(const UniValue& params, bool fHelp) UniValue result(UniValue::VOBJ); uint256 approvaltxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; if ( fHelp || params.size() != 5 ) { - // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 2693 e5b1ef8ec90e981d3011c8e024cef869b69af2d4dd6837d1ab1d394d3730b7cb + // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 3803 16e9d0571c9b9f0f885aabb432bdd68d7fce9c2af8aa56d09972f4c40b8435a1 throw runtime_error("marmaraissue receiverpk amount currency matures approvaltxid\n"); } if ( ensure_CCrequirements() < 0 ) From 00ba2f442039eeed7978fb5e476212d260558d47 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Jan 2019 22:08:26 -1100 Subject: [PATCH 260/643] Set createtxid to txid for 'R" --- src/cc/marmara.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index b69807884..db60040fc 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -174,8 +174,13 @@ int32_t MarmaraGetcreatetxid(uint256 &createtxid,uint256 txid) CTransaction tx; uint256 hashBlock; uint8_t funcid; int32_t numvouts,matures; std::string currency; CPubKey senderpk; int64_t amount; if ( myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 1 ) { - if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,senderpk,amount,matures,currency)) == 'I' || funcid == 'T' || funcid == 'R' ) + if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,senderpk,amount,matures,currency)) == 'I' || funcid == 'T' ) return(0); + else if ( funcid == 'R' ) + { + createtxid = txid; + return(0); + } } return(-1); } From 98a81709d70a4e07cf6d3662cb66b1cae64f42f9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Jan 2019 22:13:46 -1100 Subject: [PATCH 261/643] Test --- src/cc/marmara.cpp | 6 +++--- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index db60040fc..5eb40aebe 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -452,12 +452,12 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a mtx.vin.push_back(CTxIn(approvaltxid,0,CScript())); if ( funcid == 'T' ) mtx.vin.push_back(CTxIn(batontxid,0,CScript())); - if ( funcid == 'I' || AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) + if ( funcid == 'I' || AddNormalinputs(mtx,mypk,txfee,1) > 0 ) { errorstr = (char *)"couldnt finalize CCtx"; - mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee,receiverpk)); + mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee/2,receiverpk)); if ( funcid == 'I' ) - mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee,Marmarapk)); + mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee/2,Marmarapk)); rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret(funcid,createtxid,receiverpk,amount,matures,currency)); if ( rawtx.size() > 0 ) errorstr = 0; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index f5427fe70..89ca92ce7 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5579,7 +5579,7 @@ UniValue marmara_issue(const UniValue& params, bool fHelp) UniValue result(UniValue::VOBJ); uint256 approvaltxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; if ( fHelp || params.size() != 5 ) { - // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 3803 16e9d0571c9b9f0f885aabb432bdd68d7fce9c2af8aa56d09972f4c40b8435a1 + // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 3878 78d4bb8e70578ab28ddf60c0af93c6f459f525271864c9984ccbe14e25124dfc throw runtime_error("marmaraissue receiverpk amount currency matures approvaltxid\n"); } if ( ensure_CCrequirements() < 0 ) From 5e4375ef81232be6714a2e7be9615304f9873c92 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Jan 2019 22:23:31 -1100 Subject: [PATCH 262/643] 'R" to fund 'I' and 'T' --- src/cc/marmara.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 5eb40aebe..29b57bbfd 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -379,7 +379,7 @@ int32_t MarmaraGetCreditloops(int64_t &totalamount,std::vector &issuanc UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 batontxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); CPubKey mypk; struct CCcontract_info *cp,C; std::string rawtx; char *errorstr=0; uint256 createtxid; int32_t needbaton = 0; + UniValue result(UniValue::VOBJ); CPubKey mypk; struct CCcontract_info *cp,C; std::string rawtx; char *errorstr=0; uint256 createtxid; int64_t amount; int32_t needbaton = 0; cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; @@ -396,13 +396,13 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri errorstr = (char *)"it must mature in the future"; if ( errorstr == 0 ) { - if ( createtxid == zeroid ) - needbaton = 1; - if ( AddNormalinputs(mtx,mypk,(1+needbaton)*txfee,1) > 0 ) + if ( batontxid != zeroid ) + amount = txfee; + else amount = 2*txfee; + if ( AddNormalinputs(mtx,mypk,amount + txfee,1) > 0 ) { errorstr = (char *)"couldnt finalize CCtx"; - if ( needbaton != 0 ) - mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee,senderpk)); + mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,amount,senderpk)); rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('R',createtxid,senderpk,amount,matures,currency)); if ( rawtx.size() > 0 ) errorstr = 0; @@ -455,9 +455,9 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a if ( funcid == 'I' || AddNormalinputs(mtx,mypk,txfee,1) > 0 ) { errorstr = (char *)"couldnt finalize CCtx"; - mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee/2,receiverpk)); + mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee,receiverpk)); if ( funcid == 'I' ) - mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee/2,Marmarapk)); + mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee,Marmarapk)); rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret(funcid,createtxid,receiverpk,amount,matures,currency)); if ( rawtx.size() > 0 ) errorstr = 0; From 54b98b84600ade58a2a3a8652d4ca1b3f16a3440 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Jan 2019 22:24:29 -1100 Subject: [PATCH 263/643] batonamount --- src/cc/marmara.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 29b57bbfd..35d465df1 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -379,7 +379,7 @@ int32_t MarmaraGetCreditloops(int64_t &totalamount,std::vector &issuanc UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 batontxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); CPubKey mypk; struct CCcontract_info *cp,C; std::string rawtx; char *errorstr=0; uint256 createtxid; int64_t amount; int32_t needbaton = 0; + UniValue result(UniValue::VOBJ); CPubKey mypk; struct CCcontract_info *cp,C; std::string rawtx; char *errorstr=0; uint256 createtxid; int64_t batonamount; int32_t needbaton = 0; cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; @@ -397,9 +397,9 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri if ( errorstr == 0 ) { if ( batontxid != zeroid ) - amount = txfee; - else amount = 2*txfee; - if ( AddNormalinputs(mtx,mypk,amount + txfee,1) > 0 ) + batonamount = txfee; + else batonamount = 2*txfee; + if ( AddNormalinputs(mtx,mypk,batonamount + txfee,1) > 0 ) { errorstr = (char *)"couldnt finalize CCtx"; mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,amount,senderpk)); From a362c04ae941959ffcf60abab2a7292174f48500 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Jan 2019 22:26:31 -1100 Subject: [PATCH 264/643] Send baton amount --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 35d465df1..e5d5e9094 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -402,7 +402,7 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri if ( AddNormalinputs(mtx,mypk,batonamount + txfee,1) > 0 ) { errorstr = (char *)"couldnt finalize CCtx"; - mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,amount,senderpk)); + mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,batonamount,senderpk)); rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('R',createtxid,senderpk,amount,matures,currency)); if ( rawtx.size() > 0 ) errorstr = 0; From fccecf9b31b6a587ac5bd109662ce4bad6e30d50 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Jan 2019 22:54:40 -1100 Subject: [PATCH 265/643] Total amount --- src/cc/marmara.cpp | 1 + src/wallet/rpcwallet.cpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index e5d5e9094..89e5479c3 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -544,6 +544,7 @@ UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_ for (i=0; i receiverpub; int64_t amount; int32_t matures; std::string currency; if ( fHelp || params.size() != 5 ) { - // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 3878 78d4bb8e70578ab28ddf60c0af93c6f459f525271864c9984ccbe14e25124dfc + // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 3903 010ff7f9256cefe3b5dee3d72c0eeae9fc6f34884e6f32ffe5b60916df54a9be throw runtime_error("marmaraissue receiverpk amount currency matures approvaltxid\n"); } if ( ensure_CCrequirements() < 0 ) @@ -5602,7 +5602,7 @@ UniValue marmara_transfer(const UniValue& params, bool fHelp) UniValue result(UniValue::VOBJ); uint256 createtxid,batontxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; if ( fHelp || params.size() != 5 ) { - // marmaratransfer 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 2693 e5b1ef8ec90e981d3011c8e024cef869b69af2d4dd6837d1ab1d394d3730b7cb + // marmaratransfer 028076d42eb20efc10007fafb5ca66a2052523c0d2221e607adf958d1a332159f6 7.5 MARMARA 3903 e5b1ef8ec90e981d3011c8e024cef869b69af2d4dd6837d1ab1d394d3730b7cb throw runtime_error("marmaratransfer receiverpk amount currency matures batontxid\n"); } if ( ensure_CCrequirements() < 0 ) From 52c163fe458e8bb7e63efc1724bdaef5555e6428 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Jan 2019 23:05:27 -1100 Subject: [PATCH 266/643] Dont increment matures on non-1st 'R' --- src/wallet/rpcwallet.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index f175192bd..f6c79826b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5554,7 +5554,7 @@ UniValue marmara_receive(const UniValue& params, bool fHelp) if ( fHelp || (params.size() != 5 && params.size() != 4) ) { // 1st marmarareceive 028076d42eb20efc10007fafb5ca66a2052523c0d2221e607adf958d1a332159f6 7.5 MARMARA 1440 - // after marmarareceive 028076d42eb20efc10007fafb5ca66a2052523c0d2221e607adf958d1a332159f6 7.5 MARMARA 1440 + // after marmarareceive 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 3903 bf6b4d42aa3ce974c853d73b06c78597dd3b5fb493d5d0d944f72c2017f561ad throw runtime_error("marmarareceive senderpk amount currency matures batontxid\n"); } if ( ensure_CCrequirements() < 0 ) @@ -5568,9 +5568,11 @@ UniValue marmara_receive(const UniValue& params, bool fHelp) } amount = atof(params[1].get_str().c_str()) * COIN + 0.00000000499999; currency = params[2].get_str(); - matures = atol(params[3].get_str().c_str()) + chainActive.LastTip()->GetHeight() + 1; if ( params.size() == 5 ) + { + matures = atol(params[3].get_str().c_str()); batontxid = Parseuint256((char *)params[4].get_str().c_str()); + } else matures = atol(params[3].get_str().c_str()) + chainActive.LastTip()->GetHeight() + 1; return(MarmaraReceive(0,pubkey2pk(senderpub),amount,currency,matures,batontxid)); } @@ -5602,7 +5604,7 @@ UniValue marmara_transfer(const UniValue& params, bool fHelp) UniValue result(UniValue::VOBJ); uint256 createtxid,batontxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; if ( fHelp || params.size() != 5 ) { - // marmaratransfer 028076d42eb20efc10007fafb5ca66a2052523c0d2221e607adf958d1a332159f6 7.5 MARMARA 3903 e5b1ef8ec90e981d3011c8e024cef869b69af2d4dd6837d1ab1d394d3730b7cb + // marmaratransfer 028076d42eb20efc10007fafb5ca66a2052523c0d2221e607adf958d1a332159f6 7.5 MARMARA 3903 bf6b4d42aa3ce974c853d73b06c78597dd3b5fb493d5d0d944f72c2017f561ad throw runtime_error("marmaratransfer receiverpk amount currency matures batontxid\n"); } if ( ensure_CCrequirements() < 0 ) From 3c03185b005d596c7cfa98793dd2ff66d528079c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Jan 2019 23:09:04 -1100 Subject: [PATCH 267/643] Add batontxid to transfer --- src/wallet/rpcwallet.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index f6c79826b..a72518ac2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5601,11 +5601,11 @@ UniValue marmara_issue(const UniValue& params, bool fHelp) UniValue marmara_transfer(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); uint256 createtxid,batontxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; - if ( fHelp || params.size() != 5 ) + UniValue result(UniValue::VOBJ); uint256 batontxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; + if ( fHelp || params.size() != 6 ) { - // marmaratransfer 028076d42eb20efc10007fafb5ca66a2052523c0d2221e607adf958d1a332159f6 7.5 MARMARA 3903 bf6b4d42aa3ce974c853d73b06c78597dd3b5fb493d5d0d944f72c2017f561ad - throw runtime_error("marmaratransfer receiverpk amount currency matures batontxid\n"); + // marmaratransfer 028076d42eb20efc10007fafb5ca66a2052523c0d2221e607adf958d1a332159f6 7.5 MARMARA 3903 748a4c80e6f6b725340fb0f52738f38a11c422d59b3034c8366b3d7b33c99a1e + throw runtime_error("marmaratransfer receiverpk amount currency matures approvaltxid\n"); } if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); @@ -5618,10 +5618,9 @@ UniValue marmara_transfer(const UniValue& params, bool fHelp) amount = atof(params[1].get_str().c_str()) * COIN + 0.00000000499999; currency = params[2].get_str(); matures = atol(params[3].get_str().c_str()); - batontxid = Parseuint256((char *)params[4].get_str().c_str()); - if ( MarmaraGetcreatetxid(createtxid,batontxid) < 0 ) - throw runtime_error("invalid batontxid"); - return(MarmaraIssue(0,'T',pubkey2pk(receiverpub),amount,currency,matures,createtxid,batontxid)); + approvaltxid = Parseuint256((char *)params[4].get_str().c_str()); + batontxid = Parseuint256((char *)params[5].get_str().c_str()); + return(MarmaraIssue(0,'T',pubkey2pk(receiverpub),amount,currency,matures,approvaltxid,batontxid)); } UniValue marmara_info(const UniValue& params, bool fHelp) From cc839d6f773ae3312db3d92bae8edb7564cd1be6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Jan 2019 23:10:21 -1100 Subject: [PATCH 268/643] Approvaltxid --- src/wallet/rpcwallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a72518ac2..67f7fa054 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5601,10 +5601,10 @@ UniValue marmara_issue(const UniValue& params, bool fHelp) UniValue marmara_transfer(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); uint256 batontxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; + UniValue result(UniValue::VOBJ); uint256 approvaltxid,batontxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; if ( fHelp || params.size() != 6 ) { - // marmaratransfer 028076d42eb20efc10007fafb5ca66a2052523c0d2221e607adf958d1a332159f6 7.5 MARMARA 3903 748a4c80e6f6b725340fb0f52738f38a11c422d59b3034c8366b3d7b33c99a1e + // marmaratransfer 028076d42eb20efc10007fafb5ca66a2052523c0d2221e607adf958d1a332159f6 7.5 MARMARA 3903 748a4c80e6f6b725340fb0f52738f38a11c422d59b3034c8366b3d7b33c99a1e bf6b4d42aa3ce974c853d73b06c78597dd3b5fb493d5d0d944f72c2017f561ad throw runtime_error("marmaratransfer receiverpk amount currency matures approvaltxid\n"); } if ( ensure_CCrequirements() < 0 ) From 9755dbc647cb3ffe58abd56dddef1aaee384b205 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Jan 2019 23:25:17 -1100 Subject: [PATCH 269/643] Print batontxid --- src/cc/CCMarmara.h | 1 + src/cc/marmara.cpp | 23 +++++++++++++++++++---- src/wallet/rpcwallet.cpp | 7 ++++--- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 79372fa27..ef8cc678b 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -26,6 +26,7 @@ uint64_t komodo_block_prg(uint32_t nHeight); int32_t MarmaraGetcreatetxid(uint256 &createtxid,uint256 txid); +int32_t MarmaraGetbatontxid(uint256 &batontxid,uint256 txid); UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...] UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 batontxid); diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 89e5479c3..c9976c75d 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -178,13 +178,26 @@ int32_t MarmaraGetcreatetxid(uint256 &createtxid,uint256 txid) return(0); else if ( funcid == 'R' ) { - createtxid = txid; + if ( createtxid == zeroid ) + createtxid = txid; return(0); } } return(-1); } +int32_t MarmaraGetbatontxid(uint256 &batontxid,uint256 txid) +{ + uint256 createtxid; + memset(&batontxid,0,sizeof(batontxid)); + if ( MarmaraGetcreatetxid(createtxid,txid) == 0 ) + { + return(0); + } + return(-1); +} + + CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) { CTxOut ccvout; @@ -420,6 +433,8 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri result.push_back(Pair("rawtx",rawtx)); result.push_back(Pair("funcid","R")); result.push_back(Pair("createtxid",createtxid.GetHex())); + if ( batontxid != zeroid ) + result.push_back(Pair("batontxid",batontxid.GetHex())); result.push_back(Pair("senderpk",HexStr(senderpk))); result.push_back(Pair("amount",ValueFromAmount(amount))); result.push_back(Pair("matures",matures)); @@ -445,8 +460,8 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a errorstr = (char *)"for now, only MARMARA loops are supported"; else if ( amount < txfee ) errorstr = (char *)"amount must be for more than txfee"; - else if ( matures <= chainActive.LastTip()->GetHeight() ) - errorstr = (char *)"it must mature in the future"; + //else if ( matures <= chainActive.LastTip()->GetHeight() ) + // errorstr = (char *)"it must mature in the future"; if ( errorstr == 0 ) { mtx.vin.push_back(CTxIn(approvaltxid,0,CScript())); @@ -544,7 +559,7 @@ UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_ for (i=0; i receiverpub; int64_t amount; int32_t matures; std::string currency; - if ( fHelp || params.size() != 6 ) + if ( fHelp || params.size() != 5 ) { - // marmaratransfer 028076d42eb20efc10007fafb5ca66a2052523c0d2221e607adf958d1a332159f6 7.5 MARMARA 3903 748a4c80e6f6b725340fb0f52738f38a11c422d59b3034c8366b3d7b33c99a1e bf6b4d42aa3ce974c853d73b06c78597dd3b5fb493d5d0d944f72c2017f561ad + // marmaratransfer 028076d42eb20efc10007fafb5ca66a2052523c0d2221e607adf958d1a332159f6 7.5 MARMARA 3903 748a4c80e6f6b725340fb0f52738f38a11c422d59b3034c8366b3d7b33c99a1e throw runtime_error("marmaratransfer receiverpk amount currency matures approvaltxid\n"); } if ( ensure_CCrequirements() < 0 ) @@ -5619,7 +5619,8 @@ UniValue marmara_transfer(const UniValue& params, bool fHelp) currency = params[2].get_str(); matures = atol(params[3].get_str().c_str()); approvaltxid = Parseuint256((char *)params[4].get_str().c_str()); - batontxid = Parseuint256((char *)params[5].get_str().c_str()); + if ( MarmaraGetbatontxid(batontxid,approvaltxid) < 0 ) + throw runtime_error("couldnt find batontxid\n"); return(MarmaraIssue(0,'T',pubkey2pk(receiverpub),amount,currency,matures,approvaltxid,batontxid)); } From 6873cb6653db9457d860d02db6b4c6764bb4d0e1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 00:09:07 -1100 Subject: [PATCH 270/643] Get credit loop --- src/cc/CCMarmara.h | 2 +- src/cc/CCinclude.h | 5 ++++- src/cc/CCtx.cpp | 34 ++++++++++++++++++++++++++++++++++ src/cc/marmara.cpp | 20 +++++++++++++++++--- src/wallet/rpcwallet.cpp | 4 ++-- 5 files changed, 58 insertions(+), 7 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index ef8cc678b..9904a663e 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -26,7 +26,7 @@ uint64_t komodo_block_prg(uint32_t nHeight); int32_t MarmaraGetcreatetxid(uint256 &createtxid,uint256 txid); -int32_t MarmaraGetbatontxid(uint256 &batontxid,uint256 txid); +int32_t MarmaraGetbatontxid(std::vector &creditloop,uint256 &batontxid,uint256 txid); UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...] UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 batontxid); diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 0744156a5..40028ee5c 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -105,15 +105,18 @@ struct oracleprice_info #ifdef ENABLE_WALLET extern CWallet* pwalletMain; #endif +//extern CCoinsViewCache *pcoinsTip; bool GetAddressUnspent(uint160 addressHash, int type,std::vector > &unspentOutputs); CBlockIndex *komodo_getblockindex(uint256 hash); int32_t komodo_nextheight(); +int32_t CCgetspenttxid(uint256 &spenttxid,int32_t &vini,int32_t &height,uint256 txid,int32_t vout); + static const uint256 zeroid; bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock); int32_t is_hexstr(char *str,int32_t n); bool myAddtomempool(CTransaction &tx, CValidationState *pstate = NULL, bool fSkipExpiry = false); -//uint64_t myGettxout(uint256 hash,int32_t n); +int32_t CCgettxout(uint256 txid,int32_t vout,int32_t mempoolflag); bool myIsutxo_spentinmempool(uint256 txid,int32_t vout); bool mytxid_inmempool(uint256 txid); int32_t myIsutxo_spent(uint256 &spenttxid,uint256 txid,int32_t vout); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index a70d4f038..c73bead04 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -247,6 +247,40 @@ int64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout) return(0); } +int32_t CCgettxout(uint256 txid,int32_t vout,int32_t mempoolflag) +{ + CCoins coins; + if ( mempoolflag != 0 ) + { + LOCK(mempool.cs); + CCoinsViewMemPool view(pcoinsTip, mempool); + if (!view.GetCoins(txid, coins)) + return(-1); + if ( myIsutxo_spentinmempool(txid,vout) != 0 ) + return(-1); + } + else + { + if (!pcoinsTip->GetCoins(hash, coins)) + return(-1); + } + if ( vout < coins.vout.size() ) + return(coins.vout[vout].nValue); + else return(-1); +} + +int32_t CCgetspenttxid(uint256 &spenttxid,int32_t &vini,int32_t &height,uint256 txid,int32_t vout) +{ + CSpentIndexKey key(txid, vout); + CSpentIndexValue value; + if ( !GetSpentIndex(key, value) ) + return(-1); + spenttxid = value.txid; + vini = (int32_t)value.inputIndex; + height = value.blockHeight; + return(0); +} + int64_t CCaddress_balance(char *coinaddr) { int64_t sum = 0; std::vector > unspentOutputs; diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index c9976c75d..cfbdbc798 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -186,13 +186,25 @@ int32_t MarmaraGetcreatetxid(uint256 &createtxid,uint256 txid) return(-1); } -int32_t MarmaraGetbatontxid(uint256 &batontxid,uint256 txid) +int32_t MarmaraGetbatontxid(std::vector &creditloop,uint256 &batontxid,uint256 txid) { - uint256 createtxid; + uint256 createtxid,spenttxid; int64_t value; int32_t vini,height,vout = 0; memset(&batontxid,0,sizeof(batontxid)); if ( MarmaraGetcreatetxid(createtxid,txid) == 0 ) { - return(0); + txid = createtxid; + while ( CCgetspenttxid(spenttxid,vini,height,txid,vout) == 0 ) + { + if ( (value= CCgettxout(spenttxid,vout,1)) > 0 ) + { + batontxid = txid; + fprintf(stderr,"got baton %s %.8f\n",batontxid.GetHex(),(double)value/COIN); + return(0); + } + creditloop.push_back(spenttxid); + fprintf(stderr,"%s\n",spenttxid.GetHex()); + txid = spenttxid; + } } return(-1); } @@ -456,6 +468,8 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a mypk = pubkey2pk(Mypubkey()); if ( MarmaraGetcreatetxid(createtxid,approvaltxid) < 0 ) errorstr = (char *)"cant get createtxid from approvaltxid"; + else if ( batontxid == zeroid ) + errorstr = (char *)"null batontxid"; else if ( currency != "MARMARA" ) errorstr = (char *)"for now, only MARMARA loops are supported"; else if ( amount < txfee ) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e22cdae0b..6ecf99204 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5601,7 +5601,7 @@ UniValue marmara_issue(const UniValue& params, bool fHelp) UniValue marmara_transfer(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); uint256 approvaltxid,batontxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; + UniValue result(UniValue::VOBJ); uint256 approvaltxid,batontxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; std::vector creditloop; if ( fHelp || params.size() != 5 ) { // marmaratransfer 028076d42eb20efc10007fafb5ca66a2052523c0d2221e607adf958d1a332159f6 7.5 MARMARA 3903 748a4c80e6f6b725340fb0f52738f38a11c422d59b3034c8366b3d7b33c99a1e @@ -5619,7 +5619,7 @@ UniValue marmara_transfer(const UniValue& params, bool fHelp) currency = params[2].get_str(); matures = atol(params[3].get_str().c_str()); approvaltxid = Parseuint256((char *)params[4].get_str().c_str()); - if ( MarmaraGetbatontxid(batontxid,approvaltxid) < 0 ) + if ( MarmaraGetbatontxid(creditloop,batontxid,approvaltxid) < 0 ) throw runtime_error("couldnt find batontxid\n"); return(MarmaraIssue(0,'T',pubkey2pk(receiverpub),amount,currency,matures,approvaltxid,batontxid)); } From 50cbe82c68e9904ccc784f54b92838129a06a26d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 00:13:48 -1100 Subject: [PATCH 271/643] Hash -> taxied --- src/cc/CCtx.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index c73bead04..a80b3b3cf 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -261,7 +261,7 @@ int32_t CCgettxout(uint256 txid,int32_t vout,int32_t mempoolflag) } else { - if (!pcoinsTip->GetCoins(hash, coins)) + if (!pcoinsTip->GetCoins(txid, coins)) return(-1); } if ( vout < coins.vout.size() ) From 1cf607f70f3fd2e8dc8fe8f90a5c86c5318d7bd7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 00:16:16 -1100 Subject: [PATCH 272/643] c_str --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index cfbdbc798..60d827eca 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -198,7 +198,7 @@ int32_t MarmaraGetbatontxid(std::vector &creditloop,uint256 &batontxid, if ( (value= CCgettxout(spenttxid,vout,1)) > 0 ) { batontxid = txid; - fprintf(stderr,"got baton %s %.8f\n",batontxid.GetHex(),(double)value/COIN); + fprintf(stderr,"got baton %s %.8f\n",batontxid.GetHex().c_str(),(double)value/COIN); return(0); } creditloop.push_back(spenttxid); From 9bf61c22593356c4fcca8386fcb5b61b417657f0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 00:22:43 -1100 Subject: [PATCH 273/643] Tweak batontxid searching --- src/cc/marmara.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 60d827eca..67296f19c 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -188,21 +188,23 @@ int32_t MarmaraGetcreatetxid(uint256 &createtxid,uint256 txid) int32_t MarmaraGetbatontxid(std::vector &creditloop,uint256 &batontxid,uint256 txid) { - uint256 createtxid,spenttxid; int64_t value; int32_t vini,height,vout = 0; + uint256 createtxid,spenttxid; int64_t value; int32_t vini,height,n=0,vout = 0; memset(&batontxid,0,sizeof(batontxid)); if ( MarmaraGetcreatetxid(createtxid,txid) == 0 ) { txid = createtxid; + fprintf(stderr,"txid.%s -> createtxid %s\n",txid.GetHex().c_str(),createtxid.GetHex().c_str()); while ( CCgetspenttxid(spenttxid,vini,height,txid,vout) == 0 ) { + creditloop.push_back(txid); + fprintf(stderr,"%d: %s\n",n,txid.GetHex().c_str()); + n++; if ( (value= CCgettxout(spenttxid,vout,1)) > 0 ) { - batontxid = txid; + batontxid = spenttxid; fprintf(stderr,"got baton %s %.8f\n",batontxid.GetHex().c_str(),(double)value/COIN); return(0); } - creditloop.push_back(spenttxid); - fprintf(stderr,"%s\n",spenttxid.GetHex()); txid = spenttxid; } } From 389e07d1fb5209669b382940747f10cd4d64ca9b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 00:46:27 -1100 Subject: [PATCH 274/643] marmara_creditloop --- src/cc/CCMarmara.h | 2 +- src/cc/marmara.cpp | 36 ++++++++++++++++++++++++++++++++---- src/wallet/rpcwallet.cpp | 9 +++++---- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 9904a663e..1d61a86d4 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -27,12 +27,12 @@ uint64_t komodo_block_prg(uint32_t nHeight); int32_t MarmaraGetcreatetxid(uint256 &createtxid,uint256 txid); int32_t MarmaraGetbatontxid(std::vector &creditloop,uint256 &batontxid,uint256 txid); +UniValue MarmaraCreditloop(uint256 txid); UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...] UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 batontxid); UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t amount,std::string currency,int32_t matures,uint256 approvaltxid,uint256 batontxid); UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,std::string currency); -UniValue MarmaraCrediloop(uint256 batontxid); bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 67296f19c..3ab1317c5 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -203,7 +203,7 @@ int32_t MarmaraGetbatontxid(std::vector &creditloop,uint256 &batontxid, { batontxid = spenttxid; fprintf(stderr,"got baton %s %.8f\n",batontxid.GetHex().c_str(),(double)value/COIN); - return(0); + return(n); } txid = spenttxid; } @@ -211,7 +211,6 @@ int32_t MarmaraGetbatontxid(std::vector &creditloop,uint256 &batontxid, return(-1); } - CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) { CTxOut ccvout; @@ -476,8 +475,8 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a errorstr = (char *)"for now, only MARMARA loops are supported"; else if ( amount < txfee ) errorstr = (char *)"amount must be for more than txfee"; - //else if ( matures <= chainActive.LastTip()->GetHeight() ) - // errorstr = (char *)"it must mature in the future"; + else if ( matures <= chainActive.LastTip()->GetHeight() ) + errorstr = (char *)"it must mature in the future"; if ( errorstr == 0 ) { mtx.vin.push_back(CTxIn(approvaltxid,0,CScript())); @@ -547,6 +546,35 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a return(result); }*/ +UniValue MarmaraCreditloop(uint256 txid) +{ + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid; uint8_t funcid; int32_t numvouts,matures; int64_t amount; CPubKey senderpk; std::string currency; + if ( (n= MarmaraGetbatontxid(creditloop,batontxid,txid)) > 0 ) + { + for (i=0; i 1 ) + { + if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,senderpk,amount,matures,currency)) != 0 ) + { + UniValue obj(UniValue::VOBJ); + obj.push_back(Pair("txid",txid.GetHex())); + obj.push_back(Pair("createtxid",createtxid.GetHex())); + obj.push_back(Pair("senderpk",HexStr(senderpk))); + obj.push_back(Pair("amount",ValueFromAmount(amount))); + obj.push_back(Pair("matures",matures)); + obj.push_back(Pair("currency",currency)); + a.push_back(obj); + } + } + } + result.push_back(Pair("result",(char *)"success")); + result.push_back("creditloop",a); + } + + return(result); +} + UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,std::string currency) { UniValue result(UniValue::VOBJ),a(UniValue::VARR); int32_t i,n,matches; int64_t totalamount=0; std::vector issuances; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6ecf99204..836380f1b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5656,14 +5656,15 @@ UniValue marmara_info(const UniValue& params, bool fHelp) UniValue marmara_creditloop(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); uint256 createtxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; - if ( fHelp || params.size() != 5 ) + if ( fHelp || params.size() != 1 ) { - // marmaratransfer 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 2693 e5b1ef8ec90e981d3011c8e024cef869b69af2d4dd6837d1ab1d394d3730b7cb - throw runtime_error("marmaratransfer receiverpk amount currency matures batontxid\n"); + // marmaracreditloop 010ff7f9256cefe3b5dee3d72c0eeae9fc6f34884e6f32ffe5b60916df54a9be + throw runtime_error("marmaracreditloop txid\n"); } if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - //UniValue MarmaraCrediloop(uint256 batontxid); + txid = Parseuint256((char *)params[0].get_str().c_str()); + result = MarmaraCreditloop(txid); return(result); } From ba76bd2d7033c006dfd59570da936d390af7481c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 00:47:36 -1100 Subject: [PATCH 275/643] Declare vars --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 3ab1317c5..2b71f566b 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -548,7 +548,7 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a UniValue MarmaraCreditloop(uint256 txid) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid; uint8_t funcid; int32_t numvouts,matures; int64_t amount; CPubKey senderpk; std::string currency; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,hashBlock; uint8_t funcid; int32_t numvouts,matures; int64_t amount; CPubKey senderpk; std::string currency; CTransaction tx; if ( (n= MarmaraGetbatontxid(creditloop,batontxid,txid)) > 0 ) { for (i=0; i Date: Tue, 15 Jan 2019 00:48:02 -1100 Subject: [PATCH 276/643] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 2b71f566b..097983ebd 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -569,7 +569,7 @@ UniValue MarmaraCreditloop(uint256 txid) } } result.push_back(Pair("result",(char *)"success")); - result.push_back("creditloop",a); + result.push_back(Pair("creditloop",a)); } return(result); From e620f47e519a0a71daf7153791f63aa883f244c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 00:48:54 -1100 Subject: [PATCH 277/643] N --- src/cc/marmara.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 097983ebd..24bd3d6f3 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -548,7 +548,7 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a UniValue MarmaraCreditloop(uint256 txid) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,hashBlock; uint8_t funcid; int32_t numvouts,matures; int64_t amount; CPubKey senderpk; std::string currency; CTransaction tx; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,hashBlock; uint8_t funcid; int32_t i,n,numvouts,matures; int64_t amount; CPubKey senderpk; std::string currency; CTransaction tx; if ( (n= MarmaraGetbatontxid(creditloop,batontxid,txid)) > 0 ) { for (i=0; i Date: Tue, 15 Jan 2019 00:49:26 -1100 Subject: [PATCH 278/643] ) --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 24bd3d6f3..5c87d7bec 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -569,7 +569,7 @@ UniValue MarmaraCreditloop(uint256 txid) } } result.push_back(Pair("result",(char *)"success")); - result.push_back(Pair("n",n); + result.push_back(Pair("n",n)); result.push_back(Pair("creditloop",a)); } From 41ed37e9693eb2eeff036b9652e22cfaed01affe Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 00:50:18 -1100 Subject: [PATCH 279/643] Funcid --- src/cc/marmara.cpp | 1 + src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 5c87d7bec..2629b7dfd 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -559,6 +559,7 @@ UniValue MarmaraCreditloop(uint256 txid) { UniValue obj(UniValue::VOBJ); obj.push_back(Pair("txid",txid.GetHex())); + obj.push_back(Pair("funcid",funcid)); obj.push_back(Pair("createtxid",createtxid.GetHex())); obj.push_back(Pair("senderpk",HexStr(senderpk))); obj.push_back(Pair("amount",ValueFromAmount(amount))); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 836380f1b..81b692dc0 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5655,7 +5655,7 @@ UniValue marmara_info(const UniValue& params, bool fHelp) UniValue marmara_creditloop(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); uint256 createtxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; + UniValue result(UniValue::VOBJ); uint256 txid; if ( fHelp || params.size() != 1 ) { // marmaracreditloop 010ff7f9256cefe3b5dee3d72c0eeae9fc6f34884e6f32ffe5b60916df54a9be From f03daaf2eb4df9da51c539cd07a4f015feec06a3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 00:58:49 -1100 Subject: [PATCH 280/643] Baton address --- src/cc/marmara.cpp | 61 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 2629b7dfd..681689a6e 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -548,38 +548,63 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a UniValue MarmaraCreditloop(uint256 txid) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,hashBlock; uint8_t funcid; int32_t i,n,numvouts,matures; int64_t amount; CPubKey senderpk; std::string currency; CTransaction tx; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey senderpk; std::string currency,refcurrency; CTransaction tx; char batonaddr[64]; if ( (n= MarmaraGetbatontxid(creditloop,batontxid,txid)) > 0 ) { - for (i=0; i 1 ) { - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 1 ) + result.push_back(Pair("result",(char *)"success")); + result.push_back(Pair("batontxid",batontxid.GetHex())); + if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,refcreatetxid,senderpk,refamount,refmatures,refcurrency)) != 0 ) { - if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,senderpk,amount,matures,currency)) != 0 ) + obj.push_back(Pair("funcid",funcid)); + obj.push_back(Pair("createtxid",createtxid.GetHex())); + obj.push_back(Pair("amount",ValueFromAmount(amount))); + obj.push_back(Pair("matures",matures)); + obj.push_back(Pair("currency",currency)); + GetScriptaddr(batonaddr,tx.vout[0].scriptPubKey); + obj.push_back(Pair("batonaddress",batonaddr)); + for (i=0; i 1 ) + { + if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,senderpk,amount,matures,currency)) != 0 ) + { + UniValue obj(UniValue::VOBJ); + obj.push_back(Pair("txid",txid.GetHex())); + obj.push_back(Pair("funcid",funcid)); + obj.push_back(Pair("senderpk",HexStr(senderpk))); + a.push_back(obj); + } + } } + result.push_back(Pair("n",n)); + result.push_back(Pair("creditloop",a)); + } + else + { + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"couldnt get batontxid opret")); } } - result.push_back(Pair("result",(char *)"success")); - result.push_back(Pair("n",n)); - result.push_back(Pair("creditloop",a)); + else + { + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"couldnt find batontxid")); + } + } + else + { + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"couldnt get creditloop")); } - return(result); } UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,std::string currency) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); int32_t i,n,matches; int64_t totalamount=0; std::vector issuances; + + { UniValue result(UniValue::VOBJ),a(UniValue::VARR); int32_t i,n,matches; int64_t totalamount=0; std::vector issuances; CPubKey Marmarapk; struct CCcontract_info *cp,C; result.push_back(Pair("result","success")); if ( refpk.size() == 33 ) From 8f55cee678dce394ecb1e82d0734fc569723d9e2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 01:02:12 -1100 Subject: [PATCH 281/643] Test --- src/cc/marmara.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 681689a6e..cf3d248e5 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -548,7 +548,7 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a UniValue MarmaraCreditloop(uint256 txid) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey senderpk; std::string currency,refcurrency; CTransaction tx; char batonaddr[64]; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey senderpk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64]; if ( (n= MarmaraGetbatontxid(creditloop,batontxid,txid)) > 0 ) { if ( GetTransaction(batontxid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 1 ) @@ -557,13 +557,13 @@ UniValue MarmaraCreditloop(uint256 txid) result.push_back(Pair("batontxid",batontxid.GetHex())); if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,refcreatetxid,senderpk,refamount,refmatures,refcurrency)) != 0 ) { - obj.push_back(Pair("funcid",funcid)); - obj.push_back(Pair("createtxid",createtxid.GetHex())); - obj.push_back(Pair("amount",ValueFromAmount(amount))); - obj.push_back(Pair("matures",matures)); - obj.push_back(Pair("currency",currency)); - GetScriptaddr(batonaddr,tx.vout[0].scriptPubKey); - obj.push_back(Pair("batonaddress",batonaddr)); + result.push_back(Pair("funcid",funcid)); + result.push_back(Pair("createtxid",createtxid.GetHex())); + result.push_back(Pair("amount",ValueFromAmount(amount))); + result.push_back(Pair("matures",matures)); + result.push_back(Pair("currency",currency)); + GetScriptaddr(coinaddr,tx.vout[0].scriptPubKey); + result.push_back(Pair("batonaddress",coinaddr)); for (i=0; i 1 ) @@ -574,6 +574,10 @@ UniValue MarmaraCreditloop(uint256 txid) obj.push_back(Pair("txid",txid.GetHex())); obj.push_back(Pair("funcid",funcid)); obj.push_back(Pair("senderpk",HexStr(senderpk))); + GetCCaddress(cp,coinaddr,senderpk); + obj.push_back(Pair("sender",coinaddr)); + GetScriptaddr(coinaddr,tx.vout[0].scriptPubKey); + obj.push_back(Pair("nextaddress",coinaddr)); a.push_back(obj); } } From c3d105361d60be8a4c7351970d768496110d7592 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 01:02:46 -1100 Subject: [PATCH 282/643] -{ --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index cf3d248e5..37afeec30 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -608,7 +608,7 @@ UniValue MarmaraCreditloop(uint256 txid) UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,std::string currency) { - { UniValue result(UniValue::VOBJ),a(UniValue::VARR); int32_t i,n,matches; int64_t totalamount=0; std::vector issuances; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); int32_t i,n,matches; int64_t totalamount=0; std::vector issuances; CPubKey Marmarapk; struct CCcontract_info *cp,C; result.push_back(Pair("result","success")); if ( refpk.size() == 33 ) From fdfef30eb9864f90ebc13e5f8c41cc7cb6329307 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 01:04:54 -1100 Subject: [PATCH 283/643] Test --- src/cc/marmara.cpp | 46 ++++------------------------------------------ 1 file changed, 4 insertions(+), 42 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 37afeec30..2c6b4d2d8 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -52,44 +52,6 @@ int64_t IsMarmaravout(struct CCcontract_info *cp,const CTransaction& tx,int32_t return(0); } -/*bool MarmaraExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) -{ - static uint256 zerohash; - CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; - numvins = tx.vin.size(); - numvouts = tx.vout.size(); - for (i=0; iismyvin)(tx.vin[i].scriptSig) != 0 ) - { - //fprintf(stderr,"vini.%d check mempool\n",i); - if ( eval->GetTxUnconfirmed(tx.vin[i].prevout.hash,vinTx,hashBlock) == 0 ) - return eval->Invalid("cant find vinTx"); - else - { - //fprintf(stderr,"vini.%d check hash and vout\n",i); - if ( hashBlock == zerohash ) - return eval->Invalid("cant Marmara from mempool"); - if ( (assetoshis= IsMarmaravout(cp,vinTx,tx.vin[i].prevout.n)) != 0 ) - inputs += assetoshis; - } - } - } - for (i=0; iInvalid("mismatched inputs != outputs + txfee"); - } - else return(true); -}*/ - int32_t MarmaraRandomize(uint32_t ind) { uint64_t val64; uint32_t val,range = (MARMARA_MAXLOCK - MARMARA_MINLOCK); @@ -548,7 +510,8 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a UniValue MarmaraCreditloop(uint256 txid) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey senderpk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64]; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey senderpk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64]; struct CCcontract_info *cp,C; + cp = CCinit(&C,EVAL_MARMARA); if ( (n= MarmaraGetbatontxid(creditloop,batontxid,txid)) > 0 ) { if ( GetTransaction(batontxid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 1 ) @@ -562,7 +525,7 @@ UniValue MarmaraCreditloop(uint256 txid) result.push_back(Pair("amount",ValueFromAmount(amount))); result.push_back(Pair("matures",matures)); result.push_back(Pair("currency",currency)); - GetScriptaddr(coinaddr,tx.vout[0].scriptPubKey); + GetScriptaddress(coinaddr,tx.vout[0].scriptPubKey); result.push_back(Pair("batonaddress",coinaddr)); for (i=0; i issuances; CPubKey Marmarapk; struct CCcontract_info *cp,C; result.push_back(Pair("result","success")); From 9ec06006d7c87c4223ba06b07ae81a0b2d273246 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 01:07:06 -1100 Subject: [PATCH 284/643] Getscriptaddress --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 2c6b4d2d8..e56f7fcc5 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -525,7 +525,7 @@ UniValue MarmaraCreditloop(uint256 txid) result.push_back(Pair("amount",ValueFromAmount(amount))); result.push_back(Pair("matures",matures)); result.push_back(Pair("currency",currency)); - GetScriptaddress(coinaddr,tx.vout[0].scriptPubKey); + Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey); result.push_back(Pair("batonaddress",coinaddr)); for (i=0; i Date: Tue, 15 Jan 2019 01:15:36 -1100 Subject: [PATCH 285/643] Mypubkey() --- src/cc/marmara.cpp | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index e56f7fcc5..df41823cb 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -510,7 +510,7 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a UniValue MarmaraCreditloop(uint256 txid) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey senderpk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64]; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey senderpk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64],str[2]; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_MARMARA); if ( (n= MarmaraGetbatontxid(creditloop,batontxid,txid)) > 0 ) { @@ -520,13 +520,18 @@ UniValue MarmaraCreditloop(uint256 txid) result.push_back(Pair("batontxid",batontxid.GetHex())); if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,refcreatetxid,senderpk,refamount,refmatures,refcurrency)) != 0 ) { - result.push_back(Pair("funcid",funcid)); - result.push_back(Pair("createtxid",createtxid.GetHex())); - result.push_back(Pair("amount",ValueFromAmount(amount))); - result.push_back(Pair("matures",matures)); - result.push_back(Pair("currency",currency)); + str[0] = funcid, str[1] = 0; + result.push_back(Pair("funcid",str)); + result.push_back(Pair("createtxid",refcreatetxid.GetHex())); + result.push_back(Pair("amount",ValueFromAmount(refamount))); + result.push_back(Pair("matures",refmatures)); + result.push_back(Pair("currency",refcurrency)); Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey); result.push_back(Pair("batonaddress",coinaddr)); + Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pubkeys[0])) << OP_CHECKSIG); + result.push_back(Pair("myaddress",coinaddr)); + GetCCaddress(cp,coinaddr,Mypubkey()); + result.push_back(Pair("myCCaddress",coinaddr)); for (i=0; i 1 ) @@ -534,13 +539,22 @@ UniValue MarmaraCreditloop(uint256 txid) if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,senderpk,amount,matures,currency)) != 0 ) { UniValue obj(UniValue::VOBJ); - obj.push_back(Pair("txid",txid.GetHex())); - obj.push_back(Pair("funcid",funcid)); + obj.push_back(Pair("txid",creditloop[i].GetHex())); + str[0] = funcid, str[1] = 0; + obj.push_back(Pair("funcid",str)); obj.push_back(Pair("senderpk",HexStr(senderpk))); GetCCaddress(cp,coinaddr,senderpk); - obj.push_back(Pair("sender",coinaddr)); + obj.push_back(Pair("receiver",coinaddr)); Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey); obj.push_back(Pair("nextaddress",coinaddr)); + if ( createtxid != refcreatetxid || amount != refamount || matures != refmatures || currency != refcurrency ) + { + obj.push_back(Pair("objerror",(char *)"mismatched createtxid or amount or matures or currency"))); + obj.push_back(Pair("createtxid",createtxid.GetHex())); + obj.push_back(Pair("amount",ValueFromAmount(amount))); + obj.push_back(Pair("matures",matures)); + obj.push_back(Pair("currency",currency)); + } a.push_back(obj); } } @@ -570,9 +584,13 @@ UniValue MarmaraCreditloop(uint256 txid) UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,std::string currency) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); int32_t i,n,matches; int64_t totalamount=0; std::vector issuances; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); int32_t i,n,matches; int64_t totalamount=0; std::vector issuances; char coinaddr[64]; CPubKey Marmarapk; struct CCcontract_info *cp,C; result.push_back(Pair("result","success")); + Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(Mypubkey())) << OP_CHECKSIG); + result.push_back(Pair("myaddress",coinaddr)); + GetCCaddress(cp,coinaddr,Mypubkey()); + result.push_back(Pair("myCCaddress",coinaddr)); if ( refpk.size() == 33 ) result.push_back(Pair("issuer",HexStr(refpk))); if ( currency.size() == 0 ) From e56e7dd8f822e437b3514bc0e38362c5b0554817 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 01:16:46 -1100 Subject: [PATCH 286/643] Fix --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index df41823cb..affa2a224 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -528,7 +528,7 @@ UniValue MarmaraCreditloop(uint256 txid) result.push_back(Pair("currency",refcurrency)); Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey); result.push_back(Pair("batonaddress",coinaddr)); - Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pubkeys[0])) << OP_CHECKSIG); + Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(Mypubkey())) << OP_CHECKSIG); result.push_back(Pair("myaddress",coinaddr)); GetCCaddress(cp,coinaddr,Mypubkey()); result.push_back(Pair("myCCaddress",coinaddr)); From 0bf08eedd0e92eef7823868b219d94a62ac23312 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 01:17:30 -1100 Subject: [PATCH 287/643] - --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index affa2a224..c66a49ce3 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -549,7 +549,7 @@ UniValue MarmaraCreditloop(uint256 txid) obj.push_back(Pair("nextaddress",coinaddr)); if ( createtxid != refcreatetxid || amount != refamount || matures != refmatures || currency != refcurrency ) { - obj.push_back(Pair("objerror",(char *)"mismatched createtxid or amount or matures or currency"))); + obj.push_back(Pair("objerror",(char *)"mismatched createtxid or amount or matures or currency")); obj.push_back(Pair("createtxid",createtxid.GetHex())); obj.push_back(Pair("amount",ValueFromAmount(amount))); obj.push_back(Pair("matures",matures)); From e2a8009162d889da75fbfa87048af74da6df41c1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 01:29:54 -1100 Subject: [PATCH 288/643] numerrs --- src/cc/marmara.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index c66a49ce3..34efe2626 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -510,7 +510,7 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a UniValue MarmaraCreditloop(uint256 txid) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey senderpk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64],str[2]; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t err=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey senderpk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64],str[2]; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_MARMARA); if ( (n= MarmaraGetbatontxid(creditloop,batontxid,txid)) > 0 ) { @@ -522,6 +522,12 @@ UniValue MarmaraCreditloop(uint256 txid) { str[0] = funcid, str[1] = 0; result.push_back(Pair("funcid",str)); + if ( refcreatetxid != creditloop[0] ) + { + fprintf(stderr,"invalid refcreatetxid, setting to creditloop[0]\n"); + refcreatetxid = creditloop[0] + err++; + } result.push_back(Pair("createtxid",refcreatetxid.GetHex())); result.push_back(Pair("amount",ValueFromAmount(refamount))); result.push_back(Pair("matures",refmatures)); @@ -547,8 +553,11 @@ UniValue MarmaraCreditloop(uint256 txid) obj.push_back(Pair("receiver",coinaddr)); Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey); obj.push_back(Pair("nextaddress",coinaddr)); + if ( funcid == 'R' && createtxid == zeroid ) + createtxid = creditloop[i]; if ( createtxid != refcreatetxid || amount != refamount || matures != refmatures || currency != refcurrency ) { + err++; obj.push_back(Pair("objerror",(char *)"mismatched createtxid or amount or matures or currency")); obj.push_back(Pair("createtxid",createtxid.GetHex())); obj.push_back(Pair("amount",ValueFromAmount(amount))); @@ -560,6 +569,7 @@ UniValue MarmaraCreditloop(uint256 txid) } } result.push_back(Pair("n",n)); + result.push_back(Pair("numerrors",errs)); result.push_back(Pair("creditloop",a)); } else From ac7814aa59e23753b86b25bc7d8a10d397923420 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 01:30:46 -1100 Subject: [PATCH 289/643] Numbers --- src/cc/marmara.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 34efe2626..beaccea21 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -510,7 +510,7 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a UniValue MarmaraCreditloop(uint256 txid) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t err=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey senderpk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64],str[2]; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey senderpk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64],str[2]; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_MARMARA); if ( (n= MarmaraGetbatontxid(creditloop,batontxid,txid)) > 0 ) { @@ -526,7 +526,7 @@ UniValue MarmaraCreditloop(uint256 txid) { fprintf(stderr,"invalid refcreatetxid, setting to creditloop[0]\n"); refcreatetxid = creditloop[0] - err++; + numerrs++; } result.push_back(Pair("createtxid",refcreatetxid.GetHex())); result.push_back(Pair("amount",ValueFromAmount(refamount))); @@ -557,7 +557,7 @@ UniValue MarmaraCreditloop(uint256 txid) createtxid = creditloop[i]; if ( createtxid != refcreatetxid || amount != refamount || matures != refmatures || currency != refcurrency ) { - err++; + numerrs++; obj.push_back(Pair("objerror",(char *)"mismatched createtxid or amount or matures or currency")); obj.push_back(Pair("createtxid",createtxid.GetHex())); obj.push_back(Pair("amount",ValueFromAmount(amount))); @@ -569,7 +569,7 @@ UniValue MarmaraCreditloop(uint256 txid) } } result.push_back(Pair("n",n)); - result.push_back(Pair("numerrors",errs)); + result.push_back(Pair("numerrors",numerrs)); result.push_back(Pair("creditloop",a)); } else From 4ceddd6a93f5422db5959140bfe5b88f50adfb99 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 01:31:35 -1100 Subject: [PATCH 290/643] ; --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index beaccea21..f7cad1fa9 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -525,7 +525,7 @@ UniValue MarmaraCreditloop(uint256 txid) if ( refcreatetxid != creditloop[0] ) { fprintf(stderr,"invalid refcreatetxid, setting to creditloop[0]\n"); - refcreatetxid = creditloop[0] + refcreatetxid = creditloop[0]; numerrs++; } result.push_back(Pair("createtxid",refcreatetxid.GetHex())); From 49ac671671802c40df7d4f2ea33d77b20cdad9d0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 01:46:00 -1100 Subject: [PATCH 291/643] Test --- src/cc/marmara.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index f7cad1fa9..48dc1f6ef 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -510,13 +510,17 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a UniValue MarmaraCreditloop(uint256 txid) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey senderpk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64],str[2]; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey senderpk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64],myCCaddr[64],str[2]; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_MARMARA); if ( (n= MarmaraGetbatontxid(creditloop,batontxid,txid)) > 0 ) { if ( GetTransaction(batontxid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 1 ) { result.push_back(Pair("result",(char *)"success")); + Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(Mypubkey())) << OP_CHECKSIG); + result.push_back(Pair("myaddress",coinaddr)); + GetCCaddress(cp,myCCaddr,Mypubkey()); + result.push_back(Pair("myCCaddress",myCCaddr)); result.push_back(Pair("batontxid",batontxid.GetHex())); if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,refcreatetxid,senderpk,refamount,refmatures,refcurrency)) != 0 ) { @@ -532,12 +536,15 @@ UniValue MarmaraCreditloop(uint256 txid) result.push_back(Pair("amount",ValueFromAmount(refamount))); result.push_back(Pair("matures",refmatures)); result.push_back(Pair("currency",refcurrency)); + result.push_back(Pair("senderpk",HexStr(senderpk))); + Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(senderpk())) << OP_CHECKSIG); + obj.push_back(Pair("senderaddr",coinaddr)); + Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey); result.push_back(Pair("batonaddress",coinaddr)); - Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(Mypubkey())) << OP_CHECKSIG); - result.push_back(Pair("myaddress",coinaddr)); - GetCCaddress(cp,coinaddr,Mypubkey()); - result.push_back(Pair("myCCaddress",coinaddr)); + if ( strcmp(myCCaddr,coinaddr) == 0 ) + result.push_back(Pair("ismine",1)); + else result.push_back(Pair("ismine",0)); for (i=0; i 1 ) @@ -549,8 +556,8 @@ UniValue MarmaraCreditloop(uint256 txid) str[0] = funcid, str[1] = 0; obj.push_back(Pair("funcid",str)); obj.push_back(Pair("senderpk",HexStr(senderpk))); - GetCCaddress(cp,coinaddr,senderpk); - obj.push_back(Pair("receiver",coinaddr)); + Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(senderpk())) << OP_CHECKSIG); + obj.push_back(Pair("senderaddr",coinaddr)); Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey); obj.push_back(Pair("nextaddress",coinaddr)); if ( funcid == 'R' && createtxid == zeroid ) From 23093607b09f8ccf67cfbf1296da538b58023782 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 01:47:50 -1100 Subject: [PATCH 292/643] Test --- src/cc/marmara.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 48dc1f6ef..394d2d9d8 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -537,9 +537,8 @@ UniValue MarmaraCreditloop(uint256 txid) result.push_back(Pair("matures",refmatures)); result.push_back(Pair("currency",refcurrency)); result.push_back(Pair("senderpk",HexStr(senderpk))); - Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(senderpk())) << OP_CHECKSIG); - obj.push_back(Pair("senderaddr",coinaddr)); - + Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(senderpk)) << OP_CHECKSIG); + result.push_back(Pair("senderaddr",coinaddr)); Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey); result.push_back(Pair("batonaddress",coinaddr)); if ( strcmp(myCCaddr,coinaddr) == 0 ) @@ -556,7 +555,7 @@ UniValue MarmaraCreditloop(uint256 txid) str[0] = funcid, str[1] = 0; obj.push_back(Pair("funcid",str)); obj.push_back(Pair("senderpk",HexStr(senderpk))); - Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(senderpk())) << OP_CHECKSIG); + Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(senderpk)) << OP_CHECKSIG); obj.push_back(Pair("senderaddr",coinaddr)); Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey); obj.push_back(Pair("nextaddress",coinaddr)); From 76ff3a027510c9864887f371ca00d7a9d652ffb0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 01:56:17 -1100 Subject: [PATCH 293/643] Conditional recv/send pk --- src/cc/marmara.cpp | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 394d2d9d8..93f55799e 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -510,7 +510,7 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a UniValue MarmaraCreditloop(uint256 txid) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey senderpk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64],myCCaddr[64],str[2]; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey senderpk,pk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64],myCCaddr[64],str[2]; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_MARMARA); if ( (n= MarmaraGetbatontxid(creditloop,batontxid,txid)) > 0 ) { @@ -522,7 +522,7 @@ UniValue MarmaraCreditloop(uint256 txid) GetCCaddress(cp,myCCaddr,Mypubkey()); result.push_back(Pair("myCCaddress",myCCaddr)); result.push_back(Pair("batontxid",batontxid.GetHex())); - if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,refcreatetxid,senderpk,refamount,refmatures,refcurrency)) != 0 ) + if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,refcreatetxid,pk,refamount,refmatures,refcurrency)) != 0 ) { str[0] = funcid, str[1] = 0; result.push_back(Pair("funcid",str)); @@ -536,9 +536,11 @@ UniValue MarmaraCreditloop(uint256 txid) result.push_back(Pair("amount",ValueFromAmount(refamount))); result.push_back(Pair("matures",refmatures)); result.push_back(Pair("currency",refcurrency)); - result.push_back(Pair("senderpk",HexStr(senderpk))); - Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(senderpk)) << OP_CHECKSIG); - result.push_back(Pair("senderaddr",coinaddr)); + result.push_back(Pair("receiverpk",HexStr(pk))); + Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG); + result.push_back(Pair("receiveraddr",coinaddr)); + GetCCaddress(cp,coinaddr,pk); + result.push_back(Pair("receiverCCaddr",coinaddr)); Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey); result.push_back(Pair("batonaddress",coinaddr)); if ( strcmp(myCCaddr,coinaddr) == 0 ) @@ -548,19 +550,31 @@ UniValue MarmaraCreditloop(uint256 txid) { if ( GetTransaction(creditloop[i],tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 1 ) { - if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,senderpk,amount,matures,currency)) != 0 ) + if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,pk,amount,matures,currency)) != 0 ) { UniValue obj(UniValue::VOBJ); obj.push_back(Pair("txid",creditloop[i].GetHex())); str[0] = funcid, str[1] = 0; obj.push_back(Pair("funcid",str)); - obj.push_back(Pair("senderpk",HexStr(senderpk))); - Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(senderpk)) << OP_CHECKSIG); - obj.push_back(Pair("senderaddr",coinaddr)); + if ( funcid == 'R' && createtxid == zeroid ) + { + createtxid = creditloop[i]; + obj.push_back(Pair("senderpk",HexStr(pk))); + Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG); + obj.push_back(Pair("senderaddr",coinaddr)); + GetCCaddress(cp,coinaddr,pk); + result.push_back(Pair("senderCCaddr",coinaddr)); + } + else + { + obj.push_back(Pair("receiverpk",HexStr(pk))); + Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG); + obj.push_back(Pair("receiveraddr",coinaddr)); + GetCCaddress(cp,coinaddr,pk); + result.push_back(Pair("receiverCCaddr",coinaddr)); + } Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey); obj.push_back(Pair("nextaddress",coinaddr)); - if ( funcid == 'R' && createtxid == zeroid ) - createtxid = creditloop[i]; if ( createtxid != refcreatetxid || amount != refamount || matures != refmatures || currency != refcurrency ) { numerrs++; From a5f19e3399ecc232bf9494bcd98d3b64a1aedbe8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 02:01:28 -1100 Subject: [PATCH 294/643] Fix --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 93f55799e..7e054c369 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -563,7 +563,7 @@ UniValue MarmaraCreditloop(uint256 txid) Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG); obj.push_back(Pair("senderaddr",coinaddr)); GetCCaddress(cp,coinaddr,pk); - result.push_back(Pair("senderCCaddr",coinaddr)); + obj.push_back(Pair("senderCCaddr",coinaddr)); } else { @@ -571,7 +571,7 @@ UniValue MarmaraCreditloop(uint256 txid) Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG); obj.push_back(Pair("receiveraddr",coinaddr)); GetCCaddress(cp,coinaddr,pk); - result.push_back(Pair("receiverCCaddr",coinaddr)); + obj.push_back(Pair("receiverCCaddr",coinaddr)); } Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey); obj.push_back(Pair("nextaddress",coinaddr)); From bad70de66a435485295afca0c2323e5e592a7de1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 02:02:23 -1100 Subject: [PATCH 295/643] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 7e054c369..9097b618b 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -574,7 +574,7 @@ UniValue MarmaraCreditloop(uint256 txid) obj.push_back(Pair("receiverCCaddr",coinaddr)); } Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey); - obj.push_back(Pair("nextaddress",coinaddr)); + obj.push_back(Pair("nextCCaddress",coinaddr)); if ( createtxid != refcreatetxid || amount != refamount || matures != refmatures || currency != refcurrency ) { numerrs++; From b41b4e3a4cc18a43c0a3a5b85d800b92eafe815a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 02:08:25 -1100 Subject: [PATCH 296/643] Test --- src/cc/marmara.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 9097b618b..941c25cb6 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -536,11 +536,11 @@ UniValue MarmaraCreditloop(uint256 txid) result.push_back(Pair("amount",ValueFromAmount(refamount))); result.push_back(Pair("matures",refmatures)); result.push_back(Pair("currency",refcurrency)); - result.push_back(Pair("receiverpk",HexStr(pk))); + result.push_back(Pair("batonpk",HexStr(pk))); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG); - result.push_back(Pair("receiveraddr",coinaddr)); + result.push_back(Pair("batonaddr",coinaddr)); GetCCaddress(cp,coinaddr,pk); - result.push_back(Pair("receiverCCaddr",coinaddr)); + result.push_back(Pair("batonCCaddr",coinaddr)); Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey); result.push_back(Pair("batonaddress",coinaddr)); if ( strcmp(myCCaddr,coinaddr) == 0 ) @@ -559,11 +559,11 @@ UniValue MarmaraCreditloop(uint256 txid) if ( funcid == 'R' && createtxid == zeroid ) { createtxid = creditloop[i]; - obj.push_back(Pair("senderpk",HexStr(pk))); + obj.push_back(Pair("issuerpk",HexStr(pk))); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG); - obj.push_back(Pair("senderaddr",coinaddr)); + obj.push_back(Pair("issueraddr",coinaddr)); GetCCaddress(cp,coinaddr,pk); - obj.push_back(Pair("senderCCaddr",coinaddr)); + obj.push_back(Pair("issuerCCaddr",coinaddr)); } else { @@ -574,7 +574,7 @@ UniValue MarmaraCreditloop(uint256 txid) obj.push_back(Pair("receiverCCaddr",coinaddr)); } Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey); - obj.push_back(Pair("nextCCaddress",coinaddr)); + obj.push_back(Pair("destCCaddress",coinaddr)); if ( createtxid != refcreatetxid || amount != refamount || matures != refmatures || currency != refcurrency ) { numerrs++; From fba668fa077079b1928ee73d96d599d87686ef9f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 02:12:06 -1100 Subject: [PATCH 297/643] Test --- src/cc/marmara.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 941c25cb6..37ba74b5b 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -510,7 +510,7 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a UniValue MarmaraCreditloop(uint256 txid) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey senderpk,pk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64],myCCaddr[64],str[2]; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey senderpk,pk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64],myCCaddr[64],batonCCaddr[64],str[2]; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_MARMARA); if ( (n= MarmaraGetbatontxid(creditloop,batontxid,txid)) > 0 ) { @@ -539,10 +539,14 @@ UniValue MarmaraCreditloop(uint256 txid) result.push_back(Pair("batonpk",HexStr(pk))); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG); result.push_back(Pair("batonaddr",coinaddr)); - GetCCaddress(cp,coinaddr,pk); - result.push_back(Pair("batonCCaddr",coinaddr)); + GetCCaddress(cp,batonCCaddr,pk); + result.push_back(Pair("batonCCaddr",batonCCaddr)); Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey); - result.push_back(Pair("batonaddress",coinaddr)); + if ( strcmp(coinaddr,batonCCaddr) != 0 ) + { + result.push_back(Pair("vout0address",coinaddr)); + numerrs++; + } if ( strcmp(myCCaddr,coinaddr) == 0 ) result.push_back(Pair("ismine",1)); else result.push_back(Pair("ismine",0)); @@ -573,8 +577,12 @@ UniValue MarmaraCreditloop(uint256 txid) GetCCaddress(cp,coinaddr,pk); obj.push_back(Pair("receiverCCaddr",coinaddr)); } - Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey); - obj.push_back(Pair("destCCaddress",coinaddr)); + Getscriptaddress(destaddr,tx.vout[0].scriptPubKey); + if ( strcmp(destaddr,coinaddr) != 0 ) + { + obj.push_back(Pair("vout0address",destaddr)); + numerrs++; + } if ( createtxid != refcreatetxid || amount != refamount || matures != refmatures || currency != refcurrency ) { numerrs++; From 4f194e605386633b3ced025198342d7f734b4972 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 02:14:52 -1100 Subject: [PATCH 298/643] Destaddr --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 37ba74b5b..1e16532d4 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -510,7 +510,7 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a UniValue MarmaraCreditloop(uint256 txid) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey senderpk,pk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64],myCCaddr[64],batonCCaddr[64],str[2]; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey senderpk,pk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2]; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_MARMARA); if ( (n= MarmaraGetbatontxid(creditloop,batontxid,txid)) > 0 ) { From 6620e4cec288090746a3f2aa206bb25d54b36d96 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 04:04:00 -1100 Subject: [PATCH 299/643] marmara_settlement skeleton --- src/cc/CCMarmara.h | 1 + src/cc/marmara.cpp | 73 ++++++++++++++++++++++++++++------------ src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/wallet/rpcwallet.cpp | 15 +++++++++ 5 files changed, 70 insertions(+), 21 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 1d61a86d4..753f8edb6 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -28,6 +28,7 @@ uint64_t komodo_block_prg(uint32_t nHeight); int32_t MarmaraGetcreatetxid(uint256 &createtxid,uint256 txid); int32_t MarmaraGetbatontxid(std::vector &creditloop,uint256 &batontxid,uint256 txid); UniValue MarmaraCreditloop(uint256 txid); +UniValue MarmaraSettlement(uint64_t txfee,uint256 batontxid); UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...] UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 batontxid); diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 1e16532d4..ff4d0dc32 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -479,34 +479,65 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a return(result); } -// get creditloop pubkeys - -/*UniValue Marmara(uint64_t txfee,uint256 batontxid) +UniValue MarmaraSettlement(uint64_t txfee,uint256 batontxid) { - UniValue result(UniValue::VOBJ); int64_t avail,amount,paid=0; int32_t i,n = 0; uint256 txid,*revcreditloop=0; CPubKey Marmarapk; struct CCcontract_info *cp,C; - result.push_back(Pair("result","success")); + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey senderpk,pk; std::string currency,refcurrency; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2]; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_MARMARA); - Marmarapk = GetUnspendable(cp,0); - txid = batontxid; - while ( txid.hasprev() != 0 ) + if ( (n= MarmaraGetbatontxid(creditloop,batontxid,txid)) > 0 ) { - txid = txid.prev(); - // check for unique, else error - revcreditloop[n++] = txid; - } - for (i=0; i= amount ) + if ( GetTransaction(batontxid,batontx,hashBlock,false) != 0 && (numvouts= batontx.vout.size()) > 1 ) { - change = (amount - paid); - break; + if ( (funcid= MarmaraDecodeLoopOpret(batontx.vout[numvouts-1].scriptPubKey,refcreatetxid,pk,refamount,refmatures,refcurrency)) != 0 ) + { + if ( refcreatetxid != creditloop[0] ) + { + fprintf(stderr,"invalid refcreatetxid, setting to creditloop[0]\n"); + refcreatetxid = creditloop[0]; + numerrs++; + } + GetCCaddress(cp,myCCaddr,Mypubkey()); + Getscriptaddress(batonCCaddr,batontx.vout[0].scriptPubKey); + if ( strcmp(myCCaddr,batonCCaddr) == 0 ) + { + for (i=0; i 1 ) + { + if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,pk,amount,matures,currency)) != 0 ) + { + GetCCaddress(cp,coinaddr,pk); + fprintf(stderr,"get locked funds of %s %.8f\n",coinaddr,(double)CCaddress_balance(coinaddr)/COIN); + } + } + } + } + else + { + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"this node does not have the baton")); + result.push_back(Pair("myCCaddr",myCCaddr)); + result.push_back(Pair("batonCCaddr",batonCCaddr)); + } + } + else + { + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"couldnt get batontxid opret")); + } + } + else + { + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"couldnt find batontxid")); } } - + else + { + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"couldnt get creditloop")); + } return(result); -}*/ +} UniValue MarmaraCreditloop(uint256 txid) { diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index c8e2c4113..94403bcc0 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -449,6 +449,7 @@ static const CRPCCommand vRPCCommands[] = { "marmara", "marmaratransfer", &marmara_transfer, true }, { "marmara", "marmarainfo", &marmara_info, true }, { "marmara", "marmaracreditloop", &marmara_creditloop, true }, + { "marmara", "marmarasettlement", &marmara_settlement, true }, // Payments { "payments", "paymentsaddress", &paymentsaddress, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 1bc6bd582..920aac970 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -278,6 +278,7 @@ extern UniValue marmara_issue(const UniValue& params, bool fHelp); extern UniValue marmara_transfer(const UniValue& params, bool fHelp); extern UniValue marmara_info(const UniValue& params, bool fHelp); extern UniValue marmara_creditloop(const UniValue& params, bool fHelp); +extern UniValue marmara_settlement(const UniValue& params, bool fHelp); extern UniValue paymentsaddress(const UniValue& params, bool fHelp); extern UniValue gatewaysaddress(const UniValue& params, bool fHelp); extern UniValue gatewayslist(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 81b692dc0..b9186f5c7 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5668,6 +5668,21 @@ UniValue marmara_creditloop(const UniValue& params, bool fHelp) return(result); } +UniValue marmara_settlement(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); uint256 batontxid; + if ( fHelp || params.size() != 1 ) + { + // marmaracreditloop cc23bf81733556dc06db2fd9c9f4178cad44bdc237d6e62101cf0cdafb5195f7 + throw runtime_error("marmarasettlement batontxid\n"); + } + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + batontxid = Parseuint256((char *)params[0].get_str().c_str()); + result = MarmaraSettlement(batontxid); + return(result); +} + UniValue channelslist(const UniValue& params, bool fHelp) { if ( fHelp || params.size() > 0 ) From 422182a9d7c3525efb12e1b3ef1a8e93afabe892 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 04:05:14 -1100 Subject: [PATCH 300/643] Fix --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index ff4d0dc32..959f2f68c 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -483,7 +483,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 batontxid) { UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey senderpk,pk; std::string currency,refcurrency; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2]; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_MARMARA); - if ( (n= MarmaraGetbatontxid(creditloop,batontxid,txid)) > 0 ) + if ( (n= MarmaraGetbatontxid(creditloop,batontxid,batontxid)) > 0 ) { if ( GetTransaction(batontxid,batontx,hashBlock,false) != 0 && (numvouts= batontx.vout.size()) > 1 ) { From b51a551dde03ba4df8580a0437a0d9ae667a0e0a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 04:06:31 -1100 Subject: [PATCH 301/643] Refbatontxid --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 959f2f68c..07b8d5c5f 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -479,11 +479,11 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a return(result); } -UniValue MarmaraSettlement(uint64_t txfee,uint256 batontxid) +UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) { UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey senderpk,pk; std::string currency,refcurrency; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2]; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_MARMARA); - if ( (n= MarmaraGetbatontxid(creditloop,batontxid,batontxid)) > 0 ) + if ( (n= MarmaraGetbatontxid(creditloop,batontxid,refbatontxid)) > 0 && batontxid == refbatontxid ) { if ( GetTransaction(batontxid,batontx,hashBlock,false) != 0 && (numvouts= batontx.vout.size()) > 1 ) { From e1e112fc248229e901480f553c7bedbc7467fdab Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 04:19:16 -1100 Subject: [PATCH 302/643] Set three --- src/cc/marmara.cpp | 2 ++ src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 07b8d5c5f..e644cbe36 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -482,6 +482,8 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) { UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey senderpk,pk; std::string currency,refcurrency; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2]; struct CCcontract_info *cp,C; + if ( txfee == 0 ) + txfee = 10000; cp = CCinit(&C,EVAL_MARMARA); if ( (n= MarmaraGetbatontxid(creditloop,batontxid,refbatontxid)) > 0 && batontxid == refbatontxid ) { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index b9186f5c7..02cb6afd3 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5679,7 +5679,7 @@ UniValue marmara_settlement(const UniValue& params, bool fHelp) if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); batontxid = Parseuint256((char *)params[0].get_str().c_str()); - result = MarmaraSettlement(batontxid); + result = MarmaraSettlement(0,batontxid); return(result); } From fa756027954860cd988a45a57f6f1df04121a024 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 04:24:30 -1100 Subject: [PATCH 303/643] Test --- src/cc/marmara.cpp | 4 ++-- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index e644cbe36..8f6350daa 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -509,8 +509,8 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) { GetCCaddress(cp,coinaddr,pk); fprintf(stderr,"get locked funds of %s %.8f\n",coinaddr,(double)CCaddress_balance(coinaddr)/COIN); - } - } + } else fprintf(stderr,"null funcid for creditloop[%d]\n",i); + } else fprintf(stderr,"couldnt get creditloop[%d]\n",i); } } else diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 02cb6afd3..63992bf4d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5673,7 +5673,7 @@ UniValue marmara_settlement(const UniValue& params, bool fHelp) UniValue result(UniValue::VOBJ); uint256 batontxid; if ( fHelp || params.size() != 1 ) { - // marmaracreditloop cc23bf81733556dc06db2fd9c9f4178cad44bdc237d6e62101cf0cdafb5195f7 + // marmarasettlement cc23bf81733556dc06db2fd9c9f4178cad44bdc237d6e62101cf0cdafb5195f7 throw runtime_error("marmarasettlement batontxid\n"); } if ( ensure_CCrequirements() < 0 ) From f1971e0054885d83da5d56f117c511eafeb90288 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 04:26:59 -1100 Subject: [PATCH 304/643] Test --- src/cc/marmara.cpp | 2 +- src/wallet/rpcwallet.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 8f6350daa..8386db2c5 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -485,7 +485,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) if ( txfee == 0 ) txfee = 10000; cp = CCinit(&C,EVAL_MARMARA); - if ( (n= MarmaraGetbatontxid(creditloop,batontxid,refbatontxid)) > 0 && batontxid == refbatontxid ) + if ( (n= MarmaraGetbatontxid(creditloop,batontxid,refbatontxid)) > 0 ) { if ( GetTransaction(batontxid,batontx,hashBlock,false) != 0 && (numvouts= batontx.vout.size()) > 1 ) { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 63992bf4d..0dcaaa848 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5673,6 +5673,7 @@ UniValue marmara_settlement(const UniValue& params, bool fHelp) UniValue result(UniValue::VOBJ); uint256 batontxid; if ( fHelp || params.size() != 1 ) { + // marmarasettlement 010ff7f9256cefe3b5dee3d72c0eeae9fc6f34884e6f32ffe5b60916df54a9be // marmarasettlement cc23bf81733556dc06db2fd9c9f4178cad44bdc237d6e62101cf0cdafb5195f7 throw runtime_error("marmarasettlement batontxid\n"); } From 6745e98d48baa6c6a547f289652f35bd13b0d964 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 04:30:37 -1100 Subject: [PATCH 305/643] GetCCaddress1of2 --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 8386db2c5..d8e936839 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -507,7 +507,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) { if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,pk,amount,matures,currency)) != 0 ) { - GetCCaddress(cp,coinaddr,pk); + GetCCaddress1of2(cp,coinaddr,Marmarapk,pk); fprintf(stderr,"get locked funds of %s %.8f\n",coinaddr,(double)CCaddress_balance(coinaddr)/COIN); } else fprintf(stderr,"null funcid for creditloop[%d]\n",i); } else fprintf(stderr,"couldnt get creditloop[%d]\n",i); From 28d6643b3a4a409d2a847504c27d3fe8ca387533 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 04:32:23 -1100 Subject: [PATCH 306/643] -senderpk --- src/cc/marmara.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index d8e936839..4eea7395d 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -481,10 +481,11 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey senderpk,pk; std::string currency,refcurrency; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2]; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey Marmarapk,pk; std::string currency,refcurrency; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2]; struct CCcontract_info *cp,C; if ( txfee == 0 ) txfee = 10000; cp = CCinit(&C,EVAL_MARMARA); + Marmarapk = GetUnspendable(cp,0); if ( (n= MarmaraGetbatontxid(creditloop,batontxid,refbatontxid)) > 0 ) { if ( GetTransaction(batontxid,batontx,hashBlock,false) != 0 && (numvouts= batontx.vout.size()) > 1 ) @@ -543,7 +544,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) UniValue MarmaraCreditloop(uint256 txid) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey senderpk,pk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2]; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey pk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2]; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_MARMARA); if ( (n= MarmaraGetbatontxid(creditloop,batontxid,txid)) > 0 ) { From 7faabcef68d62f204b543ec0689d14dd9d0a6962 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 04:44:29 -1100 Subject: [PATCH 307/643] Mine to 1of2 CC addr --- src/cc/marmara.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 4eea7395d..39d8d01a7 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -175,9 +175,10 @@ int32_t MarmaraGetbatontxid(std::vector &creditloop,uint256 &batontxid, CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) { - CTxOut ccvout; + CTxOut ccvout; struct CCcontract_info *cp,C; CPubKey Marmarapk; + cp = CCinit(&C,EVAL_MARMARA); if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) - ccvout = MakeCC1vout(EVAL_MARMARA,0,pk); + ccvout = MakeCC1of2vout(EVAL_MARMARA,0,Marmarapk,pk); return(ccvout.scriptPubKey); } @@ -298,9 +299,10 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx,int32_t firstheight,CPubKey poolpk,int32_t maxinputs) { - char coinaddr[64]; CPubKey pk; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction vintx; int32_t unlockht,ht,vout,unlocks,n = 0; + char coinaddr[64]; CPubKey Marmarapk,pk; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction vintx; int32_t unlockht,ht,vout,unlocks,n = 0; std::vector > unspentOutputs; - GetCCaddress(cp,coinaddr,poolpk); + Marmarapk = GetUnspendable(cp,0); + MakeCC1of2vout(cp,coinaddr,Marmarapk,poolpk); SetCCunspents(unspentOutputs,coinaddr); unlocks = MarmaraUnlockht(firstheight); //fprintf(stderr,"check coinaddr.(%s)\n",coinaddr); From 6206090faaef1f8e2e7c4a1e0c94e296ad44580b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 04:47:12 -1100 Subject: [PATCH 308/643] EVAL_MARMARA --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 39d8d01a7..587354ff2 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -302,7 +302,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, char coinaddr[64]; CPubKey Marmarapk,pk; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction vintx; int32_t unlockht,ht,vout,unlocks,n = 0; std::vector > unspentOutputs; Marmarapk = GetUnspendable(cp,0); - MakeCC1of2vout(cp,coinaddr,Marmarapk,poolpk); + MakeCC1of2vout(EVAL_MARMARA,coinaddr,Marmarapk,poolpk); SetCCunspents(unspentOutputs,coinaddr); unlocks = MarmaraUnlockht(firstheight); //fprintf(stderr,"check coinaddr.(%s)\n",coinaddr); From 6dc61c6bcf4f22ed3b2a74b8cb8135a27ee5609f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 04:49:21 -1100 Subject: [PATCH 309/643] GetCCaddress1of2 --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 587354ff2..8c2b5df0b 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -302,7 +302,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, char coinaddr[64]; CPubKey Marmarapk,pk; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction vintx; int32_t unlockht,ht,vout,unlocks,n = 0; std::vector > unspentOutputs; Marmarapk = GetUnspendable(cp,0); - MakeCC1of2vout(EVAL_MARMARA,coinaddr,Marmarapk,poolpk); + GetCCaddress1of2(cp,coinaddr,Marmarapk,poolpk); SetCCunspents(unspentOutputs,coinaddr); unlocks = MarmaraUnlockht(firstheight); //fprintf(stderr,"check coinaddr.(%s)\n",coinaddr); From 3e2991000f29126325c05a7a48bcb1487b81a89f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 04:52:18 -1100 Subject: [PATCH 310/643] Fix --- src/cc/marmara.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 8c2b5df0b..01ecaba83 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -195,6 +195,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { struct CCcontract_info *cp,C; CPubKey pk; int32_t ht,unlockht; CTxOut ccvout; cp = CCinit(&C,EVAL_MARMARA); + Marmarapk = GetUnspendable(cp,0); if ( 0 ) { int32_t d,histo[365*2+30]; @@ -222,7 +223,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) if ( ht == height && MarmaraUnlockht(height) == unlockht ) { //fprintf(stderr,"ht.%d -> unlock.%d\n",ht,unlockht); - ccvout = MakeCC1vout(EVAL_MARMARA,0,pk); + ccvout = MakeCC1of2vout(EVAL_MARMARA,0,Marmarapk,pk); if ( ccvout.scriptPubKey == tx.vout[0].scriptPubKey ) return(0); fprintf(stderr,"ht.%d mismatched CCvout scriptPubKey\n",height); From f1046be9dcf72b532785977eba7f3c820271a437 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 04:53:16 -1100 Subject: [PATCH 311/643] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 01ecaba83..3eab9e364 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -193,7 +193,7 @@ CScript MarmaraCoinbaseOpret(uint8_t funcid,int32_t height,CPubKey pk) int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { - struct CCcontract_info *cp,C; CPubKey pk; int32_t ht,unlockht; CTxOut ccvout; + struct CCcontract_info *cp,C; CPubKey Marmarapk,pk; int32_t ht,unlockht; CTxOut ccvout; cp = CCinit(&C,EVAL_MARMARA); Marmarapk = GetUnspendable(cp,0); if ( 0 ) From 6e8e24cbc869cc62f099ea3e91b11e7b2a9cdcea Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 04:57:38 -1100 Subject: [PATCH 312/643] Init marmarapk --- src/cc/marmara.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 3eab9e364..39efecf2f 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -177,6 +177,7 @@ CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) { CTxOut ccvout; struct CCcontract_info *cp,C; CPubKey Marmarapk; cp = CCinit(&C,EVAL_MARMARA); + Marmarapk = GetUnspendable(cp,0); if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) ccvout = MakeCC1of2vout(EVAL_MARMARA,0,Marmarapk,pk); return(ccvout.scriptPubKey); From 5e8d1a2d8734333b1ee732328f043d7c00fbb03f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 05:01:45 -1100 Subject: [PATCH 313/643] Test --- src/cc/marmara.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 39efecf2f..c0697a1ba 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -227,7 +227,10 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) ccvout = MakeCC1of2vout(EVAL_MARMARA,0,Marmarapk,pk); if ( ccvout.scriptPubKey == tx.vout[0].scriptPubKey ) return(0); - fprintf(stderr,"ht.%d mismatched CCvout scriptPubKey\n",height); + char addr0[64],addr1[64]; + Getscriptaddress(addr0,ccvout.scriptPubKey); + Getscriptaddress(addr1,tx.vout[0].scriptPubKey); + fprintf(stderr,"ht.%d mismatched CCvout scriptPubKey %s vs %s\n",height,addr0,addr1); } else fprintf(stderr,"ht.%d %d vs %d unlock.%d\n",height,MarmaraUnlockht(height),ht,unlockht); } else fprintf(stderr,"ht.%d error decoding coinbase opret\n",height); } From 32a6eb7ccecdbab87deb405563bce3f1c964fbe3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 05:04:43 -1100 Subject: [PATCH 314/643] Test --- src/cc/marmara.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index c0697a1ba..aa96ea20c 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -179,7 +179,12 @@ CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) cp = CCinit(&C,EVAL_MARMARA); Marmarapk = GetUnspendable(cp,0); if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) + { ccvout = MakeCC1of2vout(EVAL_MARMARA,0,Marmarapk,pk); + char coinaddr[64]; + Getscriptaddress(coinaddr,ccvout.scriptPubKey); + fprintf(stderr,"Marmara_scriptPubKey %s ht.%d -> %s\n",HexStr(pk),height,coinaddr); + } return(ccvout.scriptPubKey); } @@ -230,7 +235,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) char addr0[64],addr1[64]; Getscriptaddress(addr0,ccvout.scriptPubKey); Getscriptaddress(addr1,tx.vout[0].scriptPubKey); - fprintf(stderr,"ht.%d mismatched CCvout scriptPubKey %s vs %s\n",height,addr0,addr1); + fprintf(stderr,"ht.%d mismatched CCvout scriptPubKey %s vs %s pk %s\n",height,addr0,addr1,HexStr(pk)); } else fprintf(stderr,"ht.%d %d vs %d unlock.%d\n",height,MarmaraUnlockht(height),ht,unlockht); } else fprintf(stderr,"ht.%d error decoding coinbase opret\n",height); } From 503f753e7be090976bb993f09f02a68329634433 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 05:11:01 -1100 Subject: [PATCH 315/643] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index aa96ea20c..6c6f824e7 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -235,7 +235,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) char addr0[64],addr1[64]; Getscriptaddress(addr0,ccvout.scriptPubKey); Getscriptaddress(addr1,tx.vout[0].scriptPubKey); - fprintf(stderr,"ht.%d mismatched CCvout scriptPubKey %s vs %s pk %s\n",height,addr0,addr1,HexStr(pk)); + fprintf(stderr,"ht.%d mismatched CCvout scriptPubKey %s vs %s pk.%d %s\n",height,addr0,addr1,(int32_t)pk.size(),HexStr(pk)); } else fprintf(stderr,"ht.%d %d vs %d unlock.%d\n",height,MarmaraUnlockht(height),ht,unlockht); } else fprintf(stderr,"ht.%d error decoding coinbase opret\n",height); } From 6617435e16d1dc4fdd02622375ae4768c0bb5134 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 05:12:15 -1100 Subject: [PATCH 316/643] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 6c6f824e7..908f80b39 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -235,7 +235,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) char addr0[64],addr1[64]; Getscriptaddress(addr0,ccvout.scriptPubKey); Getscriptaddress(addr1,tx.vout[0].scriptPubKey); - fprintf(stderr,"ht.%d mismatched CCvout scriptPubKey %s vs %s pk.%d %s\n",height,addr0,addr1,(int32_t)pk.size(),HexStr(pk)); + fprintf(stderr,"ht.%d mismatched CCvout scriptPubKey %s vs %s pk.%d %s\n",height,addr0,addr1,(int32_t)pk.size(),HexStr(pk).c_str()); } else fprintf(stderr,"ht.%d %d vs %d unlock.%d\n",height,MarmaraUnlockht(height),ht,unlockht); } else fprintf(stderr,"ht.%d error decoding coinbase opret\n",height); } From 3231c57262d45402f6c1f7fd3f773b92deebdb43 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 05:13:57 -1100 Subject: [PATCH 317/643] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 908f80b39..1afd97dc1 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -183,7 +183,7 @@ CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) ccvout = MakeCC1of2vout(EVAL_MARMARA,0,Marmarapk,pk); char coinaddr[64]; Getscriptaddress(coinaddr,ccvout.scriptPubKey); - fprintf(stderr,"Marmara_scriptPubKey %s ht.%d -> %s\n",HexStr(pk),height,coinaddr); + fprintf(stderr,"Marmara_scriptPubKey %s ht.%d -> %s\n",HexStr(pk).c_str(),height,coinaddr); } return(ccvout.scriptPubKey); } From 72e7bc73b82cdcb5dda6c6dc8b6f082129cc5079 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 05:20:20 -1100 Subject: [PATCH 318/643] Test --- src/miner.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/miner.cpp b/src/miner.cpp index a44eb380c..ba2ceefb8 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -545,6 +545,9 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 // to transaction if so, cast for GTE operator if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) { + char checkaddr[64]; + Getscriptaddress(checkaddr,txNew.vout[0].scriptPubKey); + fprintf(stderr,"set mining coinbase -> %s\n",checkaddr); txNew.vout.resize(2); txNew.vout[1].nValue = 0; txNew.vout[1].scriptPubKey = MarmaraCoinbaseOpret('C',nHeight,pk); From 97f40221f9334c930fda4882743042140de8b391 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 05:21:09 -1100 Subject: [PATCH 319/643] Test --- src/miner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/miner.cpp b/src/miner.cpp index ba2ceefb8..c6309d35e 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -158,6 +158,7 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33); int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); CScript Marmara_scriptPubKey(int32_t height,CPubKey pk); CScript MarmaraCoinbaseOpret(uint8_t funcid,int32_t height,CPubKey pk); +bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake) { From 1d946f881205172886ad209abc8317fdcc6c6c33 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 05:30:48 -1100 Subject: [PATCH 320/643] Test --- src/cc/marmara.cpp | 6 +++--- src/miner.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 1afd97dc1..ce17c0bcb 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -181,9 +181,9 @@ CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) { ccvout = MakeCC1of2vout(EVAL_MARMARA,0,Marmarapk,pk); - char coinaddr[64]; - Getscriptaddress(coinaddr,ccvout.scriptPubKey); - fprintf(stderr,"Marmara_scriptPubKey %s ht.%d -> %s\n",HexStr(pk).c_str(),height,coinaddr); + //char coinaddr[64]; + //Getscriptaddress(coinaddr,ccvout.scriptPubKey); + //fprintf(stderr,"Marmara_scriptPubKey %s ht.%d -> %s\n",HexStr(pk).c_str(),height,coinaddr); } return(ccvout.scriptPubKey); } diff --git a/src/miner.cpp b/src/miner.cpp index c6309d35e..782716fcf 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -548,7 +548,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 { char checkaddr[64]; Getscriptaddress(checkaddr,txNew.vout[0].scriptPubKey); - fprintf(stderr,"set mining coinbase -> %s\n",checkaddr); + //`fprintf(stderr,"set mining coinbase -> %s\n",checkaddr); txNew.vout.resize(2); txNew.vout[1].nValue = 0; txNew.vout[1].scriptPubKey = MarmaraCoinbaseOpret('C',nHeight,pk); From 2dc911558b0a9aa31b0e00356b799330f85261e7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 05:40:47 -1100 Subject: [PATCH 321/643] -print --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index ebc50fa62..fc302c545 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2176,7 +2176,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } else { - fprintf(stderr,"ht.%d error validating winning blocktime %u -> %.8f eligible.%u test prior\n",nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); + //fprintf(stderr,"ht.%d error validating winning blocktime %u -> %.8f eligible.%u test prior\n",nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); continue; } eligible = besttime; From c8af7b80f79b230f0ccaa9a6ac44effe87834ab5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 06:03:51 -1100 Subject: [PATCH 322/643] -print --- src/cc/marmara.cpp | 1 + src/miner.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index ce17c0bcb..5c61ebeef 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -521,6 +521,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,pk,amount,matures,currency)) != 0 ) { GetCCaddress1of2(cp,coinaddr,Marmarapk,pk); + make tx here fprintf(stderr,"get locked funds of %s %.8f\n",coinaddr,(double)CCaddress_balance(coinaddr)/COIN); } else fprintf(stderr,"null funcid for creditloop[%d]\n",i); } else fprintf(stderr,"couldnt get creditloop[%d]\n",i); diff --git a/src/miner.cpp b/src/miner.cpp index 782716fcf..cbc033d47 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1609,7 +1609,7 @@ void static BitcoinMiner() int32_t percPoS,z; bool fNegative,fOverflow; HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); HASHTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - if ( ASSETCHAINS_STAKED < 100 ) + if ( ASSETCHAINS_STAKED < 100 && KOMODO_MININGTHREADS == 0 ) { for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); From 3d8083fb4d4a5de9b116fa9e37d0e7e0dabe853e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 06:05:05 -1100 Subject: [PATCH 323/643] -print --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 5c61ebeef..6a9c78472 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -521,7 +521,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,pk,amount,matures,currency)) != 0 ) { GetCCaddress1of2(cp,coinaddr,Marmarapk,pk); - make tx here + //make tx here fprintf(stderr,"get locked funds of %s %.8f\n",coinaddr,(double)CCaddress_balance(coinaddr)/COIN); } else fprintf(stderr,"null funcid for creditloop[%d]\n",i); } else fprintf(stderr,"couldnt get creditloop[%d]\n",i); From 3dcde0ccf1d8d9cab1b0ecfcc26d18f070bcffe1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 06:07:36 -1100 Subject: [PATCH 324/643] +ht --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index cbc033d47..3a163c637 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1613,7 +1613,7 @@ void static BitcoinMiner() { for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); - fprintf(stderr," PoW for staked coin PoS %d%% vs target %d%%\n",percPoS,(int32_t)ASSETCHAINS_STAKED); + fprintf(stderr," PoW for staked coin PoS %d%% vs target %d%% ht.%d\n",percPoS,(int32_t)ASSETCHAINS_STAKED,Mining_height); } } while (true) From 060986987449d2beca241a4fc14d7978a26251db Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 20:26:02 -1100 Subject: [PATCH 325/643] Ise fixes --- src/cc/CCtx.cpp | 2 +- src/komodo.h | 5 +++++ src/komodo_gateway.h | 2 +- src/komodo_jumblr.h | 10 +++++----- src/main.cpp | 2 ++ src/wallet/rpcwallet.cpp | 2 +- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index a80b3b3cf..546c4cb6b 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -384,8 +384,8 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 { int32_t abovei,belowi,ind,vout,i,n = 0,maxutxos=64; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; #ifdef ENABLE_WALLET - const CKeyStore& keystore = *pwalletMain; assert(pwalletMain != NULL); + const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); utxos = (struct CC_utxo *)calloc(maxutxos,sizeof(*utxos)); diff --git a/src/komodo.h b/src/komodo.h index 4c97a8171..7d2b17963 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -799,6 +799,11 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) uint64_t signedmask,voutmask; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; uint8_t scriptbuf[10001],pubkeys[64][33],rmd160[20],scriptPubKey[35]; uint256 zero,btctxid,txhash; int32_t i,j,k,numnotaries,notarized,scriptlen,isratification,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count; + if ( pindex == 0 ) + { + fprintf(stderr,"komodo_connectblock null pindex\n"); + return; + } memset(&zero,0,sizeof(zero)); komodo_init(pindex->GetHeight()); KOMODO_INITDONE = (uint32_t)time(NULL); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e19d94915..02ab67407 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1388,7 +1388,7 @@ void komodo_passport_iteration() { static long lastpos[34]; static char userpass[33][1024]; static uint32_t lasttime,callcounter,lastinterest; int32_t maxseconds = 10; - FILE *fp; uint8_t *filedata; long fpos,datalen,lastfpos; int32_t baseid,limit,n,ht,isrealtime,expired,refid,blocks,longest; struct komodo_state *sp,*refsp; char *retstr,fname[512],*base,symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; uint32_t buf[3],starttime; cJSON *infoobj,*result; uint64_t RTmask = 0; //CBlockIndex *pindex; + FILE *fp; uint8_t *filedata; long fpos,datalen,lastfpos; int32_t baseid,limit,n,ht,isrealtime,expired,refid,blocks,longest; struct komodo_state *sp,*refsp; char *retstr,fname[512],*base,symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; uint32_t buf[3],starttime; uint64_t RTmask = 0; //CBlockIndex *pindex; expired = 0; while ( KOMODO_INITDONE == 0 ) { diff --git a/src/komodo_jumblr.h b/src/komodo_jumblr.h index 5a5ad0885..fca7395e5 100755 --- a/src/komodo_jumblr.h +++ b/src/komodo_jumblr.h @@ -629,7 +629,7 @@ uint64_t jumblr_increment(uint8_t r,int32_t height,uint64_t total,uint64_t bigge void jumblr_iteration() { static int32_t lastheight; static uint32_t lasttime; - char *zaddr,*addr,*retstr,secretaddr[64]; cJSON *array; int32_t i,iter,height,acpublic,counter,chosen_one,n; uint64_t smallest,medium,biggest,amount=0,total=0; double fee; struct jumblr_item *ptr,*tmp; uint16_t r,s; + char *zaddr,*addr,*retstr=0,secretaddr[64]; cJSON *array; int32_t i,iter,height,acpublic,counter,chosen_one,n; uint64_t smallest,medium,biggest,amount=0,total=0; double fee; struct jumblr_item *ptr,*tmp; uint16_t r,s; acpublic = ASSETCHAINS_PUBLIC; if ( ASSETCHAINS_SYMBOL[0] == 0 && GetTime() >= KOMODO_SAPLING_DEADLINE ) acpublic = 1; @@ -648,7 +648,7 @@ void jumblr_iteration() } free_json(array); } - free(retstr); + free(retstr), retstr = 0; } } height = (int32_t)chainActive.LastTip()->GetHeight(); @@ -691,7 +691,7 @@ void jumblr_iteration() if ( amount > 0 && (retstr= jumblr_sendt_to_z(Jumblr_deposit,addr,dstr(amount))) != 0 ) { printf("sendt_to_z.(%s)\n",retstr); - free(retstr); + free(retstr), retstr = 0; } free(zaddr); } else printf("no zaddr from jumblr_zgetnewaddress\n"); @@ -723,7 +723,7 @@ void jumblr_iteration() if ( (retstr= jumblr_sendz_to_z(ptr->dest,addr,dstr(total))) != 0 ) { printf("n.%d counter.%d chosen_one.%d send z_to_z.(%s)\n",n,counter,chosen_one,retstr); - free(retstr); + free(retstr), retstr = 0; } ptr->spent = (uint32_t)time(NULL); free(zaddr); @@ -768,7 +768,7 @@ void jumblr_iteration() if ( (retstr= jumblr_sendz_to_t(ptr->dest,secretaddr,dstr(total))) != 0 ) { printf("%s send z_to_t.(%s)\n",secretaddr,retstr); - free(retstr); + free(retstr), retstr = 0; } else printf("null return from jumblr_sendz_to_t\n"); ptr->spent = (uint32_t)time(NULL); break; diff --git a/src/main.cpp b/src/main.cpp index 929ec9d5e..21b6b4eb0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3497,6 +3497,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin CDiskBlockPos pos; if (!FindUndoPos(state, pindex->nFile, pos, ::GetSerializeSize(blockundo, SER_DISK, CLIENT_VERSION) + 40)) return error("ConnectBlock(): FindUndoPos failed"); + if ( pindex->pprev == 0 ) + fprintf(stderr,"ConnectBlock: unexpected null pprev\n"); if (!UndoWriteToDisk(blockundo, pos, pindex->pprev->GetBlockHash(), chainparams.MessageStart())) return AbortNode(state, "Failed to write undo data"); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 0dcaaa848..5d15381c6 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5094,8 +5094,8 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) if (!EnsureWalletIsAvailable(0)) return 0; - const CKeyStore& keystore = *pwalletMain; assert(pwalletMain != NULL); + const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); utxovalue = 0; memset(&utxotxid,0,sizeof(utxotxid)); From 88e77b78515358e297f58be35567b801d250c527 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 20:56:41 -1100 Subject: [PATCH 326/643] Allow null batontxid for issue --- src/cc/marmara.cpp | 2 -- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 6a9c78472..94608e1a4 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -443,8 +443,6 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a mypk = pubkey2pk(Mypubkey()); if ( MarmaraGetcreatetxid(createtxid,approvaltxid) < 0 ) errorstr = (char *)"cant get createtxid from approvaltxid"; - else if ( batontxid == zeroid ) - errorstr = (char *)"null batontxid"; else if ( currency != "MARMARA" ) errorstr = (char *)"for now, only MARMARA loops are supported"; else if ( amount < txfee ) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5d15381c6..2ce2435a7 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5581,7 +5581,7 @@ UniValue marmara_issue(const UniValue& params, bool fHelp) UniValue result(UniValue::VOBJ); uint256 approvaltxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; if ( fHelp || params.size() != 5 ) { - // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 3903 010ff7f9256cefe3b5dee3d72c0eeae9fc6f34884e6f32ffe5b60916df54a9be + // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1168 32da4cb3e886ee42de90b4a15042d71169077306badf909099c5c5c692df3f27 throw runtime_error("marmaraissue receiverpk amount currency matures approvaltxid\n"); } if ( ensure_CCrequirements() < 0 ) From 8ef46649e55ecf00b4d04c5a828dfcc3498be0a7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 21:02:23 -1100 Subject: [PATCH 327/643] Fix --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 94608e1a4..d37314e9e 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -669,6 +669,8 @@ UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_ { UniValue result(UniValue::VOBJ),a(UniValue::VARR); int32_t i,n,matches; int64_t totalamount=0; std::vector issuances; char coinaddr[64]; CPubKey Marmarapk; struct CCcontract_info *cp,C; + cp = CCinit(&C,EVAL_MARMARA); + Marmarapk = GetUnspendable(cp,0); result.push_back(Pair("result","success")); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(Mypubkey())) << OP_CHECKSIG); result.push_back(Pair("myaddress",coinaddr)); @@ -687,8 +689,6 @@ UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_ result.push_back(Pair("minamount",ValueFromAmount(minamount))); result.push_back(Pair("maxamount",ValueFromAmount(maxamount))); result.push_back(Pair("currency",currency)); - cp = CCinit(&C,EVAL_MARMARA); - Marmarapk = GetUnspendable(cp,0); if ( (n= MarmaraGetCreditloops(totalamount,issuances,cp,firstheight,lastheight,minamount,maxamount,refpk,currency)) > 0 ) { result.push_back(Pair("n",n)); From e1037c704cef7aa5b8958ad38dbe851013dc80ca Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 23:22:00 -1100 Subject: [PATCH 328/643] Prepare to create settlement tx --- src/cc/CCMarmara.h | 1 + src/cc/marmara.cpp | 176 +++++++++++++++++++++++++-------------- src/komodo_bitcoind.h | 65 ++++++++++----- src/wallet/rpcwallet.cpp | 6 +- 4 files changed, 158 insertions(+), 90 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 753f8edb6..d008095f7 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -24,6 +24,7 @@ #define MARMARA_MINLOCK (1440 * 3 * 30) #define MARMARA_MAXLOCK (1440 * 24 * 30) +extern uint8_t ASSETCHAINS_MARMARA; uint64_t komodo_block_prg(uint32_t nHeight); int32_t MarmaraGetcreatetxid(uint256 &createtxid,uint256 txid); int32_t MarmaraGetbatontxid(std::vector &creditloop,uint256 &batontxid,uint256 txid); diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index d37314e9e..c82a28f4c 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -245,6 +245,8 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { std::vector vopret; CTransaction vinTx; uint256 hashBlock; int32_t numvins,numvouts,i,ht,unlockht,vht,vunlockht; uint8_t funcid,vfuncid,*script; CPubKey pk,vpk; + if ( ASSETCHAINS_MARMARA == 0 ) + return eval->Invalid("-ac_marmara must be set for marmara CC"); numvins = tx.vin.size(); numvouts = tx.vout.size(); if ( numvouts < 1 ) @@ -344,6 +346,116 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, return(totalinputs); } +UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) +{ + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount,remaining,change,avail; CPubKey Marmarapk,mypk,pk; std::string currency,refcurrency,rawtx; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2]; struct CCcontract_info *cp,C; + if ( txfee == 0 ) + txfee = 10000; + cp = CCinit(&C,EVAL_MARMARA); + mypk = pubkey2pk(Mypubkey()); + Marmarapk = GetUnspendable(cp,0); + remaining = change = 0; + if ( (n= MarmaraGetbatontxid(creditloop,batontxid,refbatontxid)) > 0 ) + { + if ( GetTransaction(batontxid,batontx,hashBlock,false) != 0 && (numvouts= batontx.vout.size()) > 1 ) + { + if ( (funcid= MarmaraDecodeLoopOpret(batontx.vout[numvouts-1].scriptPubKey,refcreatetxid,pk,refamount,refmatures,refcurrency)) != 0 ) + { + if ( refcreatetxid != creditloop[0] ) + { + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"invalid refcreatetxid, setting to creditloop[0]")); + return(result); + } + if ( chainActive.LastTip()->GetHeight() < refmatures ) + { + fprintf(stderr,"doesnt mature for another %d blocks\n",refmatures - chainActive.LastTip()->GetHeight())' + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"cant settle immature creditloop")); + return(result); + } + remaining = refamount; + GetCCaddress(cp,myCCaddr,Mypubkey()); + Getscriptaddress(batonCCaddr,batontx.vout[0].scriptPubKey); + if ( strcmp(myCCaddr,batonCCaddr) == 0 ) + { + mtx.vin.push_back(CTxIn(batontxid,0,CScript())); + for (i=0; i 1 ) + { + if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,pk,amount,matures,currency)) != 0 ) + { + GetCCaddress1of2(cp,coinaddr,Marmarapk,pk); + avail = CCaddress_balance(coinaddr); + if ( avail > remaining ) + { + // add remaining + change = (avail - remaining); + mtx.vout.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + if ( change > txfee ) + mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,change,Marmarapk,pk)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,amount,matures,currency)); + result.push_back(Pair("result",(char *)"success")); + result.push_back(Pair("rawtx",rawtx)); + return(result); + } + else if ( avail > txfee ) + { + // add all utxos + remaining -= avail; + } + fprintf(stderr,"get locked funds of %s %.8f\n",coinaddr,(double)avail/COIN); + } else fprintf(stderr,"null funcid for creditloop[%d]\n",i); + } else fprintf(stderr,"couldnt get creditloop[%d]\n",i); + } + if ( amount - remaining > 2*txfee ) + { + mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(CCtxidaddr(txidaddr,createtxid))) << OP_CHECKSIG)); // failure marker + if ( amount-remaining > 3*txfee ) + mtx.vout.push_back(CTxOut(amount-remaining-2*txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,amount-remaining,-remaining,currency)); + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"insufficient funds")); + result.push_back(Pair("rawtx",rawtx)); + result.push_back(Pair("remaining",ValueFromAmount(remaining))); + } + else + { + // jl777: maybe fund a txfee to report no funds avail + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"no funds available at all")); + } + } + else + { + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"this node does not have the baton")); + result.push_back(Pair("myCCaddr",myCCaddr)); + result.push_back(Pair("batonCCaddr",batonCCaddr)); + } + } + else + { + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"couldnt get batontxid opret")); + } + } + else + { + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"couldnt find batontxid")); + } + } + else + { + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"couldnt get creditloop")); + } + return(result); +} + int32_t MarmaraGetCreditloops(int64_t &totalamount,std::vector &issuances,struct CCcontract_info *cp,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,CPubKey refpk,std::string refcurrency) { char coinaddr[64]; CPubKey Marmarapk,senderpk; int64_t amount; uint256 createtxid,txid,hashBlock; CTransaction tx; int32_t numvouts,vout,matures,n=0; std::string currency; @@ -489,70 +601,6 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a return(result); } -UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) -{ - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey Marmarapk,pk; std::string currency,refcurrency; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2]; struct CCcontract_info *cp,C; - if ( txfee == 0 ) - txfee = 10000; - cp = CCinit(&C,EVAL_MARMARA); - Marmarapk = GetUnspendable(cp,0); - if ( (n= MarmaraGetbatontxid(creditloop,batontxid,refbatontxid)) > 0 ) - { - if ( GetTransaction(batontxid,batontx,hashBlock,false) != 0 && (numvouts= batontx.vout.size()) > 1 ) - { - if ( (funcid= MarmaraDecodeLoopOpret(batontx.vout[numvouts-1].scriptPubKey,refcreatetxid,pk,refamount,refmatures,refcurrency)) != 0 ) - { - if ( refcreatetxid != creditloop[0] ) - { - fprintf(stderr,"invalid refcreatetxid, setting to creditloop[0]\n"); - refcreatetxid = creditloop[0]; - numerrs++; - } - GetCCaddress(cp,myCCaddr,Mypubkey()); - Getscriptaddress(batonCCaddr,batontx.vout[0].scriptPubKey); - if ( strcmp(myCCaddr,batonCCaddr) == 0 ) - { - for (i=0; i 1 ) - { - if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,pk,amount,matures,currency)) != 0 ) - { - GetCCaddress1of2(cp,coinaddr,Marmarapk,pk); - //make tx here - fprintf(stderr,"get locked funds of %s %.8f\n",coinaddr,(double)CCaddress_balance(coinaddr)/COIN); - } else fprintf(stderr,"null funcid for creditloop[%d]\n",i); - } else fprintf(stderr,"couldnt get creditloop[%d]\n",i); - } - } - else - { - result.push_back(Pair("result",(char *)"error")); - result.push_back(Pair("error",(char *)"this node does not have the baton")); - result.push_back(Pair("myCCaddr",myCCaddr)); - result.push_back(Pair("batonCCaddr",batonCCaddr)); - } - } - else - { - result.push_back(Pair("result",(char *)"error")); - result.push_back(Pair("error",(char *)"couldnt get batontxid opret")); - } - } - else - { - result.push_back(Pair("result",(char *)"error")); - result.push_back(Pair("error",(char *)"couldnt find batontxid")); - } - } - else - { - result.push_back(Pair("result",(char *)"error")); - result.push_back(Pair("error",(char *)"couldnt get creditloop")); - } - return(result); -} - UniValue MarmaraCreditloop(uint256 txid) { UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey pk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2]; struct CCcontract_info *cp,C; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index fc302c545..19a5f8103 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -643,6 +643,10 @@ int32_t komodo_isPoS(CBlock *pblock) { txid = pblock->vtx[n-1].vin[0].prevout.hash; vout = pblock->vtx[n-1].vin[0].prevout.n; + if ( ASSETCHAINS_MARMARA != 0 ) + { + // need to verify it was signed by the non-Marmarapk of the 1of2 + } txtime = komodo_txtime(&value,txid,vout,destaddr); if ( ExtractDestination(pblock->vtx[n-1].vout[0].scriptPubKey,voutaddress) ) { @@ -2112,34 +2116,42 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt maxkp = numkp = 0; lasttime = 0; } - BOOST_FOREACH(const COutput& out, vecOutputs) + if ( ASSETCHAINS_MARMARA == 0 || 1 ) { - if ( (tipindex= chainActive.Tip()) == 0 || tipindex->GetHeight()+1 > nHeight ) + BOOST_FOREACH(const COutput& out, vecOutputs) { - fprintf(stderr,"chain tip changed during staking loop t.%u counter.%d\n",(uint32_t)time(NULL),counter); - return(0); - } - counter++; - if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth ) - { - fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth); - continue; - } - CAmount nValue = out.tx->vout[out.i].nValue; - if ( nValue < COIN || !out.fSpendable ) - continue; - const CScript& pk = out.tx->vout[out.i].scriptPubKey; - if ( ExtractDestination(pk,address) != 0 ) - { - if ( IsMine(*pwalletMain,address) == 0 ) - continue; - if ( GetTransaction(out.tx->GetHash(),tx,hashBlock,true) != 0 && (pindex= komodo_getblockindex(hashBlock)) != 0 ) + if ( (tipindex= chainActive.Tip()) == 0 || tipindex->GetHeight()+1 > nHeight ) { - 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); + fprintf(stderr,"chain tip changed during staking loop t.%u counter.%d\n",(uint32_t)time(NULL),counter); + return(0); + } + counter++; + if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth ) + { + fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth); + continue; + } + CAmount nValue = out.tx->vout[out.i].nValue; + if ( nValue < COIN || !out.fSpendable ) + continue; + const CScript& pk = out.tx->vout[out.i].scriptPubKey; + if ( ExtractDestination(pk,address) != 0 ) + { + if ( IsMine(*pwalletMain,address) == 0 ) + continue; + 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); + } } } } + else + { + // calc 1of2 address + // iterate all unspents not spent in mempool and komodo_addutxo + } 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); } @@ -2218,7 +2230,14 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt txNew.vout[0].nValue = *utxovaluep - txfee; txNew.nLockTime = earliest; CTransaction txNewConst(txNew); - signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, *utxovaluep, SIGHASH_ALL), best_scriptPubKey, sigdata, consensusBranchId); + if ( ASSETCHAINS_MARMARA == 0 || 1 ) + { + signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, *utxovaluep, SIGHASH_ALL), best_scriptPubKey, sigdata, consensusBranchId); + } + else + { + // signSuccess = CCFinalizetx(...) + } if (!signSuccess) fprintf(stderr,"failed to create signature\n"); else diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 2ce2435a7..877342306 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5554,7 +5554,7 @@ UniValue marmara_receive(const UniValue& params, bool fHelp) if ( fHelp || (params.size() != 5 && params.size() != 4) ) { // 1st marmarareceive 028076d42eb20efc10007fafb5ca66a2052523c0d2221e607adf958d1a332159f6 7.5 MARMARA 1440 - // after marmarareceive 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 3903 bf6b4d42aa3ce974c853d73b06c78597dd3b5fb493d5d0d944f72c2017f561ad + // after marmarareceive 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1168 d72d87aa0d50436de695c93e2bf3d7273c63c92ef6307913aa01a6ee6a16548b throw runtime_error("marmarareceive senderpk amount currency matures batontxid\n"); } if ( ensure_CCrequirements() < 0 ) @@ -5604,7 +5604,7 @@ UniValue marmara_transfer(const UniValue& params, bool fHelp) UniValue result(UniValue::VOBJ); uint256 approvaltxid,batontxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; std::vector creditloop; if ( fHelp || params.size() != 5 ) { - // marmaratransfer 028076d42eb20efc10007fafb5ca66a2052523c0d2221e607adf958d1a332159f6 7.5 MARMARA 3903 748a4c80e6f6b725340fb0f52738f38a11c422d59b3034c8366b3d7b33c99a1e + // marmaratransfer 028076d42eb20efc10007fafb5ca66a2052523c0d2221e607adf958d1a332159f6 7.5 MARMARA 1168 1506c774e4b2804a6e25260920840f4cfca8d1fb400e69fe6b74b8e593dbedc5 throw runtime_error("marmaratransfer receiverpk amount currency matures approvaltxid\n"); } if ( ensure_CCrequirements() < 0 ) @@ -5674,7 +5674,7 @@ UniValue marmara_settlement(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) { // marmarasettlement 010ff7f9256cefe3b5dee3d72c0eeae9fc6f34884e6f32ffe5b60916df54a9be - // marmarasettlement cc23bf81733556dc06db2fd9c9f4178cad44bdc237d6e62101cf0cdafb5195f7 + // marmarasettlement ff3e259869196f3da9b5ea3f9e088a76c4fc063cf36ab586b652e121d441a603 throw runtime_error("marmarasettlement batontxid\n"); } if ( ensure_CCrequirements() < 0 ) From af6dae789e93c63272afd56f9bf8417dfeac504f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 23:23:10 -1100 Subject: [PATCH 329/643] syntax --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index c82a28f4c..9e921df6b 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -349,7 +349,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount,remaining,change,avail; CPubKey Marmarapk,mypk,pk; std::string currency,refcurrency,rawtx; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2]; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount,remaining,change,avail; CPubKey Marmarapk,mypk,pk; std::string currency,refcurrency,rawtx; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2],txidaddr[64]; struct CCcontract_info *cp,C; if ( txfee == 0 ) txfee = 10000; cp = CCinit(&C,EVAL_MARMARA); @@ -370,7 +370,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) } if ( chainActive.LastTip()->GetHeight() < refmatures ) { - fprintf(stderr,"doesnt mature for another %d blocks\n",refmatures - chainActive.LastTip()->GetHeight())' + fprintf(stderr,"doesnt mature for another %d blocks\n",refmatures - chainActive.LastTip()->GetHeight()); result.push_back(Pair("result",(char *)"error")); result.push_back(Pair("error",(char *)"cant settle immature creditloop")); return(result); From 024a9fd81e589daa708850afd12f99709fbb83d4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 21:23:26 -1100 Subject: [PATCH 330/643] implemented marmarasettlement --- src/cc/CCMarmara.h | 1 + src/cc/marmara.cpp | 55 ++++++++++++++++++++++++++++++++-------------- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index d008095f7..6c81ed689 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -23,6 +23,7 @@ #define MARMARA_GROUPSIZE 60 #define MARMARA_MINLOCK (1440 * 3 * 30) #define MARMARA_MAXLOCK (1440 * 24 * 30) +#define MARMARA_VINS 16 extern uint8_t ASSETCHAINS_MARMARA; uint64_t komodo_block_prg(uint32_t nHeight); diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 9e921df6b..ca11f276e 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -82,13 +82,13 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript scriptPubKey,CPubKey &pk,int32 } if ( vopret.size() > 2 && script[0] == EVAL_MARMARA ) { - if ( script[1] == 'C' || script[1] == 'P' ) + if ( script[1] == 'C' || script[1] == 'P' || script[1] == 'L' ) { if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> pk; ss >> height; ss >> unlockht) != 0 ) { return(script[1]); } else fprintf(stderr,"DecodeMaramaraCoinbaseOpRet unmarshal error for %c\n",script[1]); - } else fprintf(stderr,"script[1] is %d != 'C' %d or 'P' %d\n",script[1],'C','P'); + } else fprintf(stderr,"script[1] is %d != 'C' %d or 'P' %d or 'L' %d\n",script[1],'C','P','L'); } else fprintf(stderr,"vopret.size() is %d\n",(int32_t)vopret.size()); return(0); } @@ -346,10 +346,39 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, return(totalinputs); } +int64_t AddMarmarainputs(CMutableTransaction &mtx,char *coinaddr,int64_t total,int32_t maxinputs) +{ + uint64_t threshold,nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction tx; int32_t numvouts,vout,n = 0; uint8_t funcid; + std::vector > unspentOutputs; + SetCCunspents(unspentOutputs,coinaddr); + threshold = total/(maxinputs+1); + for (std::vector >::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 ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 && vout < numvouts && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + { + if ( (funcid= DecodeMaramaraCoinbaseOpRet(tx.vout[numvouts-1].scriptPubKey,pk,ht,unlockht) == 'C' || funcid == 'P' || funcid == 'L' ) + { + char str[64]; fprintf(stderr,"(%s) %s/v%d %.8f ht.%d unlockht.%d\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN,ht,unlockht); + if ( total != 0 && maxinputs != 0 ) + mtx.vin.push_back(CTxIn(txid,vout,CScript())); + totalinputs += it->second.satoshis; + n++; + if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) + break; + } else fprintf(stderr,"null funcid\n"); + } + } + return(totalinputs); +} + UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount,remaining,change,avail; CPubKey Marmarapk,mypk,pk; std::string currency,refcurrency,rawtx; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2],txidaddr[64]; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount,remaining,inputsum,change; CPubKey Marmarapk,mypk,pk; std::string currency,refcurrency,rawtx; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2],txidaddr[64]; struct CCcontract_info *cp,C; if ( txfee == 0 ) txfee = 10000; cp = CCinit(&C,EVAL_MARMARA); @@ -388,25 +417,19 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,pk,amount,matures,currency)) != 0 ) { GetCCaddress1of2(cp,coinaddr,Marmarapk,pk); - avail = CCaddress_balance(coinaddr); - if ( avail > remaining ) + if ( (inputsum= AddMarmarainputs(mtx,coinaddr,remaining,MARMARA_VINS)) >= remaining ) { - // add remaining - change = (avail - remaining); + change = (inputsum - remaining); mtx.vout.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); if ( change > txfee ) mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,change,Marmarapk,pk)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,amount,matures,currency)); + rawtx = FinalizeCCTx(0,cp,mtx,Marmarapk,txfee,MarmaraLoopOpret('S',createtxid,mypk,amount,matures,currency)); result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); return(result); - } - else if ( avail > txfee ) - { - // add all utxos - remaining -= avail; - } - fprintf(stderr,"get locked funds of %s %.8f\n",coinaddr,(double)avail/COIN); + } else remaining -= inputsum; + if ( mtx.vin.size() >= CC_MAXVINS - MARMARA_VINS ) + break; } else fprintf(stderr,"null funcid for creditloop[%d]\n",i); } else fprintf(stderr,"couldnt get creditloop[%d]\n",i); } @@ -415,7 +438,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(CCtxidaddr(txidaddr,createtxid))) << OP_CHECKSIG)); // failure marker if ( amount-remaining > 3*txfee ) mtx.vout.push_back(CTxOut(amount-remaining-2*txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,amount-remaining,-remaining,currency)); + rawtx = FinalizeCCTx(0,cp,mtx,Marmarapk,txfee,MarmaraLoopOpret('S',createtxid,mypk,amount-remaining,-remaining,currency)); result.push_back(Pair("result",(char *)"error")); result.push_back(Pair("error",(char *)"insufficient funds")); result.push_back(Pair("rawtx",rawtx)); From 62d50529edbba03c7af0234927d73fd6c2baef99 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 21:24:53 -1100 Subject: [PATCH 331/643] Fix --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index ca11f276e..81ae9cb29 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -348,7 +348,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, int64_t AddMarmarainputs(CMutableTransaction &mtx,char *coinaddr,int64_t total,int32_t maxinputs) { - uint64_t threshold,nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction tx; int32_t numvouts,vout,n = 0; uint8_t funcid; + uint64_t threshold,nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction tx; int32_t numvouts,ht,vout,n = 0; uint8_t funcid; CPubKey pk; std::vector > unspentOutputs; SetCCunspents(unspentOutputs,coinaddr); threshold = total/(maxinputs+1); @@ -360,7 +360,7 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,char *coinaddr,int64_t total,i continue; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 && vout < numvouts && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { - if ( (funcid= DecodeMaramaraCoinbaseOpRet(tx.vout[numvouts-1].scriptPubKey,pk,ht,unlockht) == 'C' || funcid == 'P' || funcid == 'L' ) + if ( (funcid= DecodeMaramaraCoinbaseOpRet(tx.vout[numvouts-1].scriptPubKey,pk,ht,unlockht)) == 'C' || funcid == 'P' || funcid == 'L' ) { char str[64]; fprintf(stderr,"(%s) %s/v%d %.8f ht.%d unlockht.%d\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN,ht,unlockht); if ( total != 0 && maxinputs != 0 ) From c9b9d1f26f4beaa63477f176e873b1972581674b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 21:25:42 -1100 Subject: [PATCH 332/643] Unlockht --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 81ae9cb29..883e8f08c 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -348,7 +348,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, int64_t AddMarmarainputs(CMutableTransaction &mtx,char *coinaddr,int64_t total,int32_t maxinputs) { - uint64_t threshold,nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction tx; int32_t numvouts,ht,vout,n = 0; uint8_t funcid; CPubKey pk; + uint64_t threshold,nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction tx; int32_t numvouts,ht,unlockht,vout,n = 0; uint8_t funcid; CPubKey pk; std::vector > unspentOutputs; SetCCunspents(unspentOutputs,coinaddr); threshold = total/(maxinputs+1); From a47537398fc07d60391790ac3989ab4f039a27b4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 21:29:43 -1100 Subject: [PATCH 333/643] Sign with mypk --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 883e8f08c..290600ddd 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -423,7 +423,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); if ( change > txfee ) mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,change,Marmarapk,pk)); - rawtx = FinalizeCCTx(0,cp,mtx,Marmarapk,txfee,MarmaraLoopOpret('S',createtxid,mypk,amount,matures,currency)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,amount,matures,currency)); result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); return(result); @@ -438,7 +438,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(CCtxidaddr(txidaddr,createtxid))) << OP_CHECKSIG)); // failure marker if ( amount-remaining > 3*txfee ) mtx.vout.push_back(CTxOut(amount-remaining-2*txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - rawtx = FinalizeCCTx(0,cp,mtx,Marmarapk,txfee,MarmaraLoopOpret('S',createtxid,mypk,amount-remaining,-remaining,currency)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('D',createtxid,mypk,amount-remaining,-remaining,currency)); result.push_back(Pair("result",(char *)"error")); result.push_back(Pair("error",(char *)"insufficient funds")); result.push_back(Pair("rawtx",rawtx)); From 1f3dd2947c8030d7bf5d36f396050a6a08838b51 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 21:42:08 -1100 Subject: [PATCH 334/643] Pubkeys vector --- src/cc/CCinclude.h | 2 +- src/cc/CCtx.cpp | 32 ++++++++++++++++++++++++++------ src/cc/marmara.cpp | 10 +++++++--- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 40028ee5c..871285ae8 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -179,7 +179,7 @@ int64_t CCduration(int32_t &numblocks,uint256 txid); bool komodo_txnotarizedconfirmed(uint256 txid); // CCtx bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey); -std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret); +std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys=0); void SetCCunspents(std::vector > &unspentOutputs,char *coinaddr); void SetCCtxids(std::vector > &addressIndex,char *coinaddr); int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 546c4cb6b..317b9549b 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -38,13 +38,14 @@ bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScrip return(false); } -std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret) +std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys) { auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); - CTransaction vintx; std::string hex; uint256 hashBlock; uint64_t mask=0,nmask=0,vinimask=0; + CTransaction vintx; std::string hex; CPubKey globalpk; uint256 hashBlock; uint64_t mask=0,nmask=0,vinimask=0; int64_t utxovalues[CC_MAXVINS],change,normalinputs=0,totaloutputs=0,normaloutputs=0,totalinputs=0,normalvins=0,ccvins=0; - int32_t i,utxovout,n,err = 0; char myaddr[64],destaddr[64],unspendable[64]; - uint8_t *privkey,myprivkey[32],unspendablepriv[32],*msg32 = 0; CC *mycond=0,*othercond=0,*othercond2=0,*othercond3=0,*cond; CPubKey unspendablepk; + int32_t i,flag,utxovout,n,err = 0; char myaddr[64],destaddr[64],unspendable[64]; + uint8_t *privkey,myprivkey[32],unspendablepriv[32],*msg32 = 0; CC *mycond=0,*othercond=0,*othercond2=0,*othercond3=0,*othercond4=0,*cond; CPubKey unspendablepk; + globalpk = GetUnspendable(cp,0); n = mtx.vout.size(); for (i=0; iunspendablepriv; + if ( othercond4 != 0 ) + cc_free(othercond4); + othercond4 = MakeCCcond1of2(cp->evalcode,globalpk,pubkeys[i]); + cond = othercond4; + flag = 1; + } + } + if ( flag == 0 ) + { + fprintf(stderr,"CC signing error: vini.%d has unknown CC address.(%s)\n",i,destaddr); + continue; + } } uint256 sighash = SignatureHash(CCPubKey(cond), mtx, i, SIGHASH_ALL, utxovalues[i],consensusBranchId, &txdata); if ( cc_signTreeSecp256k1Msg32(cond,privkey,sighash.begin()) != 0 ) @@ -190,6 +208,8 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran cc_free(othercond2); if ( othercond3 != 0 ) cc_free(othercond3); + if ( othercond4 != 0 ) + cc_free(othercond4); std::string strHex = EncodeHexTx(mtx); if ( strHex.size() > 0 ) return(strHex); diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 290600ddd..59ec3d73c 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -346,7 +346,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, return(totalinputs); } -int64_t AddMarmarainputs(CMutableTransaction &mtx,char *coinaddr,int64_t total,int32_t maxinputs) +int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys,char *coinaddr,int64_t total,int32_t maxinputs) { uint64_t threshold,nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction tx; int32_t numvouts,ht,unlockht,vout,n = 0; uint8_t funcid; CPubKey pk; std::vector > unspentOutputs; @@ -364,7 +364,10 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,char *coinaddr,int64_t total,i { char str[64]; fprintf(stderr,"(%s) %s/v%d %.8f ht.%d unlockht.%d\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN,ht,unlockht); if ( total != 0 && maxinputs != 0 ) + { mtx.vin.push_back(CTxIn(txid,vout,CScript())); + pubkeys.push_back(pk); + } totalinputs += it->second.satoshis; n++; if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) @@ -378,7 +381,7 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,char *coinaddr,int64_t total,i UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount,remaining,inputsum,change; CPubKey Marmarapk,mypk,pk; std::string currency,refcurrency,rawtx; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2],txidaddr[64]; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount,remaining,inputsum,change; CPubKey Marmarapk,mypk,pk; std::string currency,refcurrency,rawtx; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2],txidaddr[64]; std::vector pubkeys; struct CCcontract_info *cp,C; if ( txfee == 0 ) txfee = 10000; cp = CCinit(&C,EVAL_MARMARA); @@ -410,6 +413,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) if ( strcmp(myCCaddr,batonCCaddr) == 0 ) { mtx.vin.push_back(CTxIn(batontxid,0,CScript())); + pubkeys.push_back(mypk); for (i=0; i 1 ) @@ -417,7 +421,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,pk,amount,matures,currency)) != 0 ) { GetCCaddress1of2(cp,coinaddr,Marmarapk,pk); - if ( (inputsum= AddMarmarainputs(mtx,coinaddr,remaining,MARMARA_VINS)) >= remaining ) + if ( (inputsum= AddMarmarainputs(mtx,pubkeys,coinaddr,remaining,MARMARA_VINS)) >= remaining ) { change = (inputsum - remaining); mtx.vout.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); From dc737540cf6d67beb53e5fa636d8e09062d05009 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 21:43:20 -1100 Subject: [PATCH 335/643] NULL --- src/cc/CCinclude.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 871285ae8..197929277 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -179,7 +179,7 @@ int64_t CCduration(int32_t &numblocks,uint256 txid); bool komodo_txnotarizedconfirmed(uint256 txid); // CCtx bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey); -std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys=0); +std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys=NULL); void SetCCunspents(std::vector > &unspentOutputs,char *coinaddr); void SetCCtxids(std::vector > &addressIndex,char *coinaddr); int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs); From 8ef1410d28e531d33fd3a76c461a08b5504d5a37 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 21:46:39 -1100 Subject: [PATCH 336/643] Cast --- src/cc/CCinclude.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 197929277..43b851cc6 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -179,7 +179,7 @@ int64_t CCduration(int32_t &numblocks,uint256 txid); bool komodo_txnotarizedconfirmed(uint256 txid); // CCtx bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey); -std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys=NULL); +std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys = (std::vector)NULL); void SetCCunspents(std::vector > &unspentOutputs,char *coinaddr); void SetCCtxids(std::vector > &addressIndex,char *coinaddr); int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs); From d42000a83894c91f93964cd134112b58a7a99379 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 21:48:21 -1100 Subject: [PATCH 337/643] extern std::vector NULL_pubkeys; --- src/cc/CCinclude.h | 3 ++- src/cc/CCtx.cpp | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 43b851cc6..2dc3f0a51 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -179,7 +179,8 @@ int64_t CCduration(int32_t &numblocks,uint256 txid); bool komodo_txnotarizedconfirmed(uint256 txid); // CCtx bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey); -std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys = (std::vector)NULL); +extern std::vector NULL_pubkeys; +std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys = NULL_pubkeys); void SetCCunspents(std::vector > &unspentOutputs,char *coinaddr); void SetCCtxids(std::vector > &addressIndex,char *coinaddr); int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 317b9549b..9b3e9627c 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -16,6 +16,8 @@ #include "CCinclude.h" #include "key_io.h" +std::vector NULL_pubkeys; + /* FinalizeCCTx is a very useful function that will properly sign both CC and normal inputs, adds normal change and the opreturn. From 39a1f86d6887edaad2169ff4cfd1511282092177 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 21:49:31 -1100 Subject: [PATCH 338/643] CCpriv --- src/cc/CCtx.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 9b3e9627c..4f5af7ac7 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -164,12 +164,12 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran else { flag = 0; - if ( pubkeys != 0 ) + if ( pubkeys != NULL_pubkeys ) { GetCCaddress1of2(cp,coinaddr,globalpk,pubkeys[i]); if ( strcmp(destaddr,coinaddr) == 0 ) { - privkey = cp->unspendablepriv; + privkey = cp->CCpriv; if ( othercond4 != 0 ) cc_free(othercond4); othercond4 = MakeCCcond1of2(cp->evalcode,globalpk,pubkeys[i]); From 770873156380ea5768c3626ccb44ef46a0040088 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 21:50:39 -1100 Subject: [PATCH 339/643] Coinaddr --- src/cc/CCtx.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 4f5af7ac7..1a97b4dc1 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -166,6 +166,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran flag = 0; if ( pubkeys != NULL_pubkeys ) { + char coinaddr[64]; GetCCaddress1of2(cp,coinaddr,globalpk,pubkeys[i]); if ( strcmp(destaddr,coinaddr) == 0 ) { From 9bbfa5e89ced283c807feff0f5d6e2cb676b89d3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 21:56:08 -1100 Subject: [PATCH 340/643] Test --- src/cc/CCtx.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 1a97b4dc1..fe6af3f80 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -168,6 +168,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { char coinaddr[64]; GetCCaddress1of2(cp,coinaddr,globalpk,pubkeys[i]); + fprintf(stderr,"%s + %s -> %s vs %s\n",HexStr(globalpk).c_str(),HexStr(pubkeys[i]).c_str(),coinstr,destaddr); if ( strcmp(destaddr,coinaddr) == 0 ) { privkey = cp->CCpriv; From 0480189b29cc7249ae9284118a6a1d03aea24990 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 21:56:47 -1100 Subject: [PATCH 341/643] Coinaddr --- src/cc/CCtx.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index fe6af3f80..c32a79d78 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -168,7 +168,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { char coinaddr[64]; GetCCaddress1of2(cp,coinaddr,globalpk,pubkeys[i]); - fprintf(stderr,"%s + %s -> %s vs %s\n",HexStr(globalpk).c_str(),HexStr(pubkeys[i]).c_str(),coinstr,destaddr); + fprintf(stderr,"%s + %s -> %s vs %s\n",HexStr(globalpk).c_str(),HexStr(pubkeys[i]).c_str(),coinaddr,destaddr); if ( strcmp(destaddr,coinaddr) == 0 ) { privkey = cp->CCpriv; From d4bdc4d79f7f003849598d5fdc5c40b844fbbd51 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 21:58:39 -1100 Subject: [PATCH 342/643] Dont forget to pass in pubkeys --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 59ec3d73c..654cdd600 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -427,7 +427,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); if ( change > txfee ) mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,change,Marmarapk,pk)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,amount,matures,currency)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,amount,matures,currency),pubkeys); result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); return(result); @@ -442,7 +442,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(CCtxidaddr(txidaddr,createtxid))) << OP_CHECKSIG)); // failure marker if ( amount-remaining > 3*txfee ) mtx.vout.push_back(CTxOut(amount-remaining-2*txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('D',createtxid,mypk,amount-remaining,-remaining,currency)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('D',createtxid,mypk,amount-remaining,-remaining,currency),pubkeys); result.push_back(Pair("result",(char *)"error")); result.push_back(Pair("error",(char *)"insufficient funds")); result.push_back(Pair("rawtx",rawtx)); From 41b29fcc3969313750db2b05983a92bf8cf90356 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 22:07:30 -1100 Subject: [PATCH 343/643] Automatic flag -> lsb of matures --- src/cc/CCMarmara.h | 2 +- src/cc/CCtx.cpp | 2 +- src/cc/marmara.cpp | 11 +++++++++-- src/wallet/rpcwallet.cpp | 3 ++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 6c81ed689..fe9f7f30b 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -33,7 +33,7 @@ UniValue MarmaraCreditloop(uint256 txid); UniValue MarmaraSettlement(uint64_t txfee,uint256 batontxid); UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...] -UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 batontxid); +UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 batontxid,bool automaticflag); UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t amount,std::string currency,int32_t matures,uint256 approvaltxid,uint256 batontxid); UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,std::string currency); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index c32a79d78..bb9e02fce 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -168,7 +168,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { char coinaddr[64]; GetCCaddress1of2(cp,coinaddr,globalpk,pubkeys[i]); - fprintf(stderr,"%s + %s -> %s vs %s\n",HexStr(globalpk).c_str(),HexStr(pubkeys[i]).c_str(),coinaddr,destaddr); + //fprintf(stderr,"%s + %s -> %s vs %s\n",HexStr(globalpk).c_str(),HexStr(pubkeys[i]).c_str(),coinaddr,destaddr); if ( strcmp(destaddr,coinaddr) == 0 ) { privkey = cp->CCpriv; diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 654cdd600..fad9921c2 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -301,6 +301,10 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t { return(true); // iterate from issuer all remainder after maturity } + else if ( funcid == 'D' ) // collect -> automatically spend issuers locked funds, given 'I' + { + return(true); // iterate from issuer all remainder after maturity + } // staking only for locked utxo } return eval->Invalid("fall through error"); @@ -515,14 +519,17 @@ int32_t MarmaraGetCreditloops(int64_t &totalamount,std::vector &issuanc return(n); } -UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 batontxid) +UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 batontxid,bool automaticflag) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); UniValue result(UniValue::VOBJ); CPubKey mypk; struct CCcontract_info *cp,C; std::string rawtx; char *errorstr=0; uint256 createtxid; int64_t batonamount; int32_t needbaton = 0; cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; - // check for batonownership by senderpk and parameters match createtxid + if ( automaticflag != 0 && (matures & 1) == 0 ) + matures++; + else if ( automaticflag == 0 && (matures & 1) != 0 ) + matures++; mypk = pubkey2pk(Mypubkey()); memset(&createtxid,0,sizeof(createtxid)); if ( batontxid != zeroid && MarmaraGetcreatetxid(createtxid,batontxid) < 0 ) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 877342306..899fe3099 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5553,6 +5553,7 @@ UniValue marmara_receive(const UniValue& params, bool fHelp) UniValue result(UniValue::VOBJ); uint256 batontxid; std::vector senderpub; int64_t amount; int32_t matures; std::string currency; if ( fHelp || (params.size() != 5 && params.size() != 4) ) { + // automatic flag -> lsb of matures // 1st marmarareceive 028076d42eb20efc10007fafb5ca66a2052523c0d2221e607adf958d1a332159f6 7.5 MARMARA 1440 // after marmarareceive 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1168 d72d87aa0d50436de695c93e2bf3d7273c63c92ef6307913aa01a6ee6a16548b throw runtime_error("marmarareceive senderpk amount currency matures batontxid\n"); @@ -5573,7 +5574,7 @@ UniValue marmara_receive(const UniValue& params, bool fHelp) matures = atol(params[3].get_str().c_str()); batontxid = Parseuint256((char *)params[4].get_str().c_str()); } else matures = atol(params[3].get_str().c_str()) + chainActive.LastTip()->GetHeight() + 1; - return(MarmaraReceive(0,pubkey2pk(senderpub),amount,currency,matures,batontxid)); + return(MarmaraReceive(0,pubkey2pk(senderpub),amount,currency,matures,batontxid,true)); } UniValue marmara_issue(const UniValue& params, bool fHelp) From 5415bbed425cd389b7defb96512b85b25b12ab00 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 22:23:06 -1100 Subject: [PATCH 344/643] Print --- src/cc/marmara.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index fad9921c2..5496590c8 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -404,13 +404,20 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) result.push_back(Pair("error",(char *)"invalid refcreatetxid, setting to creditloop[0]")); return(result); } - if ( chainActive.LastTip()->GetHeight() < refmatures ) + else if ( chainActive.LastTip()->GetHeight() < refmatures ) { fprintf(stderr,"doesnt mature for another %d blocks\n",refmatures - chainActive.LastTip()->GetHeight()); result.push_back(Pair("result",(char *)"error")); result.push_back(Pair("error",(char *)"cant settle immature creditloop")); return(result); } + else if ( (refmatures & 1) == 0 ) + { + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"cant automatic settle even maturity heights")); + return(result); + } + fprintf(stderr,"refmatures.%d\n",refmatures); remaining = refamount; GetCCaddress(cp,myCCaddr,Mypubkey()); Getscriptaddress(batonCCaddr,batontx.vout[0].scriptPubKey); From 8099e3af55182e16b46b5e472a5c99a4423c868e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 22:46:45 -1100 Subject: [PATCH 345/643] Test --- src/cc/marmara.cpp | 23 +++++++++++++++++------ src/wallet/rpcwallet.cpp | 2 ++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 5496590c8..a945474f7 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -155,18 +155,23 @@ int32_t MarmaraGetbatontxid(std::vector &creditloop,uint256 &batontxid, if ( MarmaraGetcreatetxid(createtxid,txid) == 0 ) { txid = createtxid; - fprintf(stderr,"txid.%s -> createtxid %s\n",txid.GetHex().c_str(),createtxid.GetHex().c_str()); + //fprintf(stderr,"txid.%s -> createtxid %s\n",txid.GetHex().c_str(),createtxid.GetHex().c_str()); while ( CCgetspenttxid(spenttxid,vini,height,txid,vout) == 0 ) { creditloop.push_back(txid); - fprintf(stderr,"%d: %s\n",n,txid.GetHex().c_str()); + //fprintf(stderr,"%d: %s\n",n,txid.GetHex().c_str()); n++; - if ( (value= CCgettxout(spenttxid,vout,1)) > 0 ) + if ( (value= CCgettxout(spenttxid,vout,1)) == 10000 ) { batontxid = spenttxid; - fprintf(stderr,"got baton %s %.8f\n",batontxid.GetHex().c_str(),(double)value/COIN); + //fprintf(stderr,"got baton %s %.8f\n",batontxid.GetHex().c_str(),(double)value/COIN); return(n); } + else if ( value > 0 ) + { + fprintf(stderr,"got false baton %s %.8f\n",batontxid.GetHex().c_str(),(double)value/COIN); + break; + } txid = spenttxid; } } @@ -417,15 +422,21 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) result.push_back(Pair("error",(char *)"cant automatic settle even maturity heights")); return(result); } - fprintf(stderr,"refmatures.%d\n",refmatures); + else if ( n < 2 ) + { + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"creditloop too short")); + return(result); + } remaining = refamount; GetCCaddress(cp,myCCaddr,Mypubkey()); Getscriptaddress(batonCCaddr,batontx.vout[0].scriptPubKey); if ( strcmp(myCCaddr,batonCCaddr) == 0 ) { mtx.vin.push_back(CTxIn(batontxid,0,CScript())); + mtx.vin.push_back(CTxIn(creditloop[1],1,CScript())); // issuance marker pubkeys.push_back(mypk); - for (i=0; i 1 ) { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 899fe3099..577c5fcb6 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5583,6 +5583,8 @@ UniValue marmara_issue(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 5 ) { // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1168 32da4cb3e886ee42de90b4a15042d71169077306badf909099c5c5c692df3f27 + // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 700 MARMARA 2629 11fe8bf1de80c2ef69124d08907f259aef7f41e3a632ca2d48ad072a8c8f3078 -> 335df3a5dd6b92a3d020c9465d4d76e0d8242126106b83756dcecbad9813fdf3 + throw runtime_error("marmaraissue receiverpk amount currency matures approvaltxid\n"); } if ( ensure_CCrequirements() < 0 ) From 4ec27d22e8b1c0621ae419f54ddba3443f885e8d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 23:13:21 -1100 Subject: [PATCH 346/643] +print --- src/cc/marmara.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index a945474f7..771b36610 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -35,6 +35,8 @@ vout0 baton to next receiverpk (following the unspent baton back to original is the credit loop) 'S' + vin0 'I' marker + vin1 baton vins CC utxos from credit loop */ @@ -169,9 +171,10 @@ int32_t MarmaraGetbatontxid(std::vector &creditloop,uint256 &batontxid, } else if ( value > 0 ) { - fprintf(stderr,"got false baton %s %.8f\n",batontxid.GetHex().c_str(),(double)value/COIN); - break; + fprintf(stderr,"got false baton %s/v%d %.8f\n",batontxid.GetHex().c_str(),vout,(double)value/COIN); + return(n); } + // get funcid txid = spenttxid; } } @@ -302,13 +305,13 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t { return(true); } - else if ( funcid == 'S' ) // collect -> automatically spend issuers locked funds, given 'I' + else if ( funcid == 'S' ) // settlement -> automatically spend issuers locked funds, given 'I' { - return(true); // iterate from issuer all remainder after maturity + return(true); } - else if ( funcid == 'D' ) // collect -> automatically spend issuers locked funds, given 'I' + else if ( funcid == 'D' ) // insufficient settlement { - return(true); // iterate from issuer all remainder after maturity + return(true); } // staking only for locked utxo } @@ -433,8 +436,9 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) Getscriptaddress(batonCCaddr,batontx.vout[0].scriptPubKey); if ( strcmp(myCCaddr,batonCCaddr) == 0 ) { - mtx.vin.push_back(CTxIn(batontxid,0,CScript())); mtx.vin.push_back(CTxIn(creditloop[1],1,CScript())); // issuance marker + pubkeys.push_back(Marmarapk); + mtx.vin.push_back(CTxIn(batontxid,0,CScript())); pubkeys.push_back(mypk); for (i=1; iGetHeight() ) errorstr = (char *)"it must mature in the future"; @@ -601,7 +605,6 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; - // make sure receiverpk is unique to creditloop // make sure less than maxlength Marmarapk = GetUnspendable(cp,0); mypk = pubkey2pk(Mypubkey()); @@ -609,7 +612,7 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a errorstr = (char *)"cant get createtxid from approvaltxid"; else if ( currency != "MARMARA" ) errorstr = (char *)"for now, only MARMARA loops are supported"; - else if ( amount < txfee ) + else if ( amount <= txfee ) errorstr = (char *)"amount must be for more than txfee"; else if ( matures <= chainActive.LastTip()->GetHeight() ) errorstr = (char *)"it must mature in the future"; @@ -888,3 +891,6 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * return(result); } +// MarmaraLock(uint64_t txfee,int64_t amount,int32_t refunlockht) +// scan all unlocked +// total capped at amount, change -> unlocked, if no change then scan all locked 'C' and 'P' for unlockht < refunlockht From ec2c6122061c2cdf69ea5abcf8fbe0ff65a9577c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 23:15:16 -1100 Subject: [PATCH 347/643] N --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 771b36610..66a36cab0 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -171,7 +171,7 @@ int32_t MarmaraGetbatontxid(std::vector &creditloop,uint256 &batontxid, } else if ( value > 0 ) { - fprintf(stderr,"got false baton %s/v%d %.8f\n",batontxid.GetHex().c_str(),vout,(double)value/COIN); + fprintf(stderr,"n.%d got false baton %s/v%d %.8f\n",n,batontxid.GetHex().c_str(),vout,(double)value/COIN); return(n); } // get funcid From 8d87e118df09455489d7bbd47ec953df2bbdf51e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 23:17:12 -1100 Subject: [PATCH 348/643] batontxid = spenttxid; --- src/cc/marmara.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 66a36cab0..ac8f4d8ce 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -171,6 +171,7 @@ int32_t MarmaraGetbatontxid(std::vector &creditloop,uint256 &batontxid, } else if ( value > 0 ) { + batontxid = spenttxid; fprintf(stderr,"n.%d got false baton %s/v%d %.8f\n",n,batontxid.GetHex().c_str(),vout,(double)value/COIN); return(n); } From 3d93fa24d9a91a8ebecf7fa86e43ff42ab830375 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 23:22:10 -1100 Subject: [PATCH 349/643] 'S' mode --- src/cc/marmara.cpp | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index ac8f4d8ce..7ab5a55d4 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -673,32 +673,41 @@ UniValue MarmaraCreditloop(uint256 txid) result.push_back(Pair("batontxid",batontxid.GetHex())); if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,refcreatetxid,pk,refamount,refmatures,refcurrency)) != 0 ) { - str[0] = funcid, str[1] = 0; - result.push_back(Pair("funcid",str)); if ( refcreatetxid != creditloop[0] ) { fprintf(stderr,"invalid refcreatetxid, setting to creditloop[0]\n"); refcreatetxid = creditloop[0]; numerrs++; } + str[0] = funcid, str[1] = 0; + result.push_back(Pair("funcid",str)); result.push_back(Pair("createtxid",refcreatetxid.GetHex())); result.push_back(Pair("amount",ValueFromAmount(refamount))); result.push_back(Pair("matures",refmatures)); result.push_back(Pair("currency",refcurrency)); - result.push_back(Pair("batonpk",HexStr(pk))); - Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG); - result.push_back(Pair("batonaddr",coinaddr)); - GetCCaddress(cp,batonCCaddr,pk); - result.push_back(Pair("batonCCaddr",batonCCaddr)); - Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey); - if ( strcmp(coinaddr,batonCCaddr) != 0 ) + if ( funcid == 'S' ) { - result.push_back(Pair("vout0address",coinaddr)); - numerrs++; + result.push_back(Pair("settled",HexStr(pk))); + Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG); + result.push_back(Pair("coinaddr",coinaddr)); + } + else + { + result.push_back(Pair("batonpk",HexStr(pk))); + Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG); + result.push_back(Pair("batonaddr",coinaddr)); + GetCCaddress(cp,batonCCaddr,pk); + result.push_back(Pair("batonCCaddr",batonCCaddr)); + Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey); + if ( strcmp(coinaddr,batonCCaddr) != 0 ) + { + result.push_back(Pair("vout0address",coinaddr)); + numerrs++; + } + if ( strcmp(myCCaddr,coinaddr) == 0 ) + result.push_back(Pair("ismine",1)); + else result.push_back(Pair("ismine",0)); } - if ( strcmp(myCCaddr,coinaddr) == 0 ) - result.push_back(Pair("ismine",1)); - else result.push_back(Pair("ismine",0)); for (i=0; i 1 ) From 5de16764e777ba2abaa35bd5df3c881314d5a660 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 23:26:24 -1100 Subject: [PATCH 350/643] Test --- src/cc/marmara.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 7ab5a55d4..146bbeb4f 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -673,12 +673,6 @@ UniValue MarmaraCreditloop(uint256 txid) result.push_back(Pair("batontxid",batontxid.GetHex())); if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,refcreatetxid,pk,refamount,refmatures,refcurrency)) != 0 ) { - if ( refcreatetxid != creditloop[0] ) - { - fprintf(stderr,"invalid refcreatetxid, setting to creditloop[0]\n"); - refcreatetxid = creditloop[0]; - numerrs++; - } str[0] = funcid, str[1] = 0; result.push_back(Pair("funcid",str)); result.push_back(Pair("createtxid",refcreatetxid.GetHex())); @@ -690,9 +684,22 @@ UniValue MarmaraCreditloop(uint256 txid) result.push_back(Pair("settled",HexStr(pk))); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG); result.push_back(Pair("coinaddr",coinaddr)); + obj.push_back(Pair("collected",ValueFromAmount(tx.vout[0].nValue))); + Getscriptaddress(destaddr,tx.vout[0].scriptPubKey); + if ( strcmp(coinaddr,destaddr) != 0 ) + { + result.push_back(Pair("destaddr",destaddr)); + numerrs++; + } } else { + if ( refcreatetxid != creditloop[0] ) + { + fprintf(stderr,"invalid refcreatetxid, setting to creditloop[0]\n"); + refcreatetxid = creditloop[0]; + numerrs++; + } result.push_back(Pair("batonpk",HexStr(pk))); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG); result.push_back(Pair("batonaddr",coinaddr)); From 80d27512be47b37af25f09258f1271e6d57fefb1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 23:27:08 -1100 Subject: [PATCH 351/643] Result --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 146bbeb4f..6821b48a0 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -684,7 +684,7 @@ UniValue MarmaraCreditloop(uint256 txid) result.push_back(Pair("settled",HexStr(pk))); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG); result.push_back(Pair("coinaddr",coinaddr)); - obj.push_back(Pair("collected",ValueFromAmount(tx.vout[0].nValue))); + result.push_back(Pair("collected",ValueFromAmount(tx.vout[0].nValue))); Getscriptaddress(destaddr,tx.vout[0].scriptPubKey); if ( strcmp(coinaddr,destaddr) != 0 ) { From fe514fd5b6ce42fe76412ff279638bdaf69c72a1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 23:31:08 -1100 Subject: [PATCH 352/643] Tweak --- src/cc/marmara.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 6821b48a0..803c66e77 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -394,13 +394,14 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount,remaining,inputsum,change; CPubKey Marmarapk,mypk,pk; std::string currency,refcurrency,rawtx; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2],txidaddr[64]; std::vector pubkeys; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures,height; int64_t amount,refamount,remaining,inputsum,change; CPubKey Marmarapk,mypk,pk; std::string currency,refcurrency,rawtx; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2],txidaddr[64]; std::vector pubkeys; struct CCcontract_info *cp,C; if ( txfee == 0 ) txfee = 10000; cp = CCinit(&C,EVAL_MARMARA); mypk = pubkey2pk(Mypubkey()); Marmarapk = GetUnspendable(cp,0); remaining = change = 0; + height = chainActive.LastTip()->GetHeight(); if ( (n= MarmaraGetbatontxid(creditloop,batontxid,refbatontxid)) > 0 ) { if ( GetTransaction(batontxid,batontx,hashBlock,false) != 0 && (numvouts= batontx.vout.size()) > 1 ) @@ -454,7 +455,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); if ( change > txfee ) mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,change,Marmarapk,pk)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,amount,matures,currency),pubkeys); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,amount,height,currency),pubkeys); result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); return(result); @@ -469,7 +470,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(CCtxidaddr(txidaddr,createtxid))) << OP_CHECKSIG)); // failure marker if ( amount-remaining > 3*txfee ) mtx.vout.push_back(CTxOut(amount-remaining-2*txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('D',createtxid,mypk,amount-remaining,-remaining,currency),pubkeys); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('D',createtxid,mypk,-remaining,height,currency),pubkeys); result.push_back(Pair("result",(char *)"error")); result.push_back(Pair("error",(char *)"insufficient funds")); result.push_back(Pair("rawtx",rawtx)); @@ -691,6 +692,7 @@ UniValue MarmaraCreditloop(uint256 txid) result.push_back(Pair("destaddr",destaddr)); numerrs++; } + refcreatetxid = creditloop[0]; } else { From d320e88b53dbd350fae36c6c37baee37a6ca4cf7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 23:35:14 -1100 Subject: [PATCH 353/643] Test --- src/cc/marmara.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 803c66e77..b59772f35 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -455,7 +455,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); if ( change > txfee ) mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,change,Marmarapk,pk)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,amount,height,currency),pubkeys); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,0,height,currency),pubkeys); result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); return(result); @@ -676,12 +676,13 @@ UniValue MarmaraCreditloop(uint256 txid) { str[0] = funcid, str[1] = 0; result.push_back(Pair("funcid",str)); - result.push_back(Pair("createtxid",refcreatetxid.GetHex())); - result.push_back(Pair("amount",ValueFromAmount(refamount))); - result.push_back(Pair("matures",refmatures)); result.push_back(Pair("currency",refcurrency)); if ( funcid == 'S' ) { + refcreatetxid = creditloop[0]; + result.push_back(Pair("createtxid",refcreatetxid.GetHex())); + result.push_back(Pair("remainder",ValueFromAmount(refamount))); + result.push_back(Pair("height",refmatures)); result.push_back(Pair("settled",HexStr(pk))); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG); result.push_back(Pair("coinaddr",coinaddr)); @@ -692,10 +693,13 @@ UniValue MarmaraCreditloop(uint256 txid) result.push_back(Pair("destaddr",destaddr)); numerrs++; } - refcreatetxid = creditloop[0]; + refamount = -1; } else { + result.push_back(Pair("createtxid",refcreatetxid.GetHex())); + result.push_back(Pair("amount",ValueFromAmount(refamount))); + result.push_back(Pair("matures",refmatures)); if ( refcreatetxid != creditloop[0] ) { fprintf(stderr,"invalid refcreatetxid, setting to creditloop[0]\n"); @@ -750,6 +754,11 @@ UniValue MarmaraCreditloop(uint256 txid) obj.push_back(Pair("vout0address",destaddr)); numerrs++; } + if ( i == 0 && refamount < 0 ) + { + refamount = amount; + refmatures = matures; + } if ( createtxid != refcreatetxid || amount != refamount || matures != refmatures || currency != refcurrency ) { numerrs++; From f2a11ac0afb63db644d5479f19bc6bc7f3cce8d1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 23:37:38 -1100 Subject: [PATCH 354/643] Settletxid --- src/cc/marmara.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index b59772f35..133a8c187 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -671,7 +671,6 @@ UniValue MarmaraCreditloop(uint256 txid) result.push_back(Pair("myaddress",coinaddr)); GetCCaddress(cp,myCCaddr,Mypubkey()); result.push_back(Pair("myCCaddress",myCCaddr)); - result.push_back(Pair("batontxid",batontxid.GetHex())); if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,refcreatetxid,pk,refamount,refmatures,refcurrency)) != 0 ) { str[0] = funcid, str[1] = 0; @@ -680,10 +679,11 @@ UniValue MarmaraCreditloop(uint256 txid) if ( funcid == 'S' ) { refcreatetxid = creditloop[0]; + result.push_back(Pair("settletxid",batontxid.GetHex())); result.push_back(Pair("createtxid",refcreatetxid.GetHex())); result.push_back(Pair("remainder",ValueFromAmount(refamount))); - result.push_back(Pair("height",refmatures)); - result.push_back(Pair("settled",HexStr(pk))); + result.push_back(Pair("settled",refmatures)); + result.push_back(Pair("pubkey",HexStr(pk))); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG); result.push_back(Pair("coinaddr",coinaddr)); result.push_back(Pair("collected",ValueFromAmount(tx.vout[0].nValue))); @@ -697,6 +697,7 @@ UniValue MarmaraCreditloop(uint256 txid) } else { + result.push_back(Pair("batontxid",batontxid.GetHex())); result.push_back(Pair("createtxid",refcreatetxid.GetHex())); result.push_back(Pair("amount",ValueFromAmount(refamount))); result.push_back(Pair("matures",refmatures)); From 4f0a54f26fdfc7d14ddcc335531c06f71df3987e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 23:44:01 -1100 Subject: [PATCH 355/643] 'D' --- src/cc/marmara.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 133a8c187..215a55297 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -679,7 +679,7 @@ UniValue MarmaraCreditloop(uint256 txid) if ( funcid == 'S' ) { refcreatetxid = creditloop[0]; - result.push_back(Pair("settletxid",batontxid.GetHex())); + result.push_back(Pair("settlement",batontxid.GetHex())); result.push_back(Pair("createtxid",refcreatetxid.GetHex())); result.push_back(Pair("remainder",ValueFromAmount(refamount))); result.push_back(Pair("settled",refmatures)); @@ -695,6 +695,18 @@ UniValue MarmaraCreditloop(uint256 txid) } refamount = -1; } + else if ( funcid == 'D' ) + { + refcreatetxid = creditloop[0]; + result.push_back(Pair("settlement",batontxid.GetHex())); + result.push_back(Pair("createtxid",refcreatetxid.GetHex())); + result.push_back(Pair("remainder",ValueFromAmount(refamount))); + result.push_back(Pair("settled",refmatures)); + Getscriptaddress(destaddr,tx.vout[0].scriptPubKey); + result.push_back(Pair("txidaddr",destaddr)); + if ( tx.vout.size() > 1 ) + result.push_back(Pair("collected",ValueFromAmount(tx.vout[1].nValue))); + } else { result.push_back(Pair("batontxid",batontxid.GetHex())); @@ -759,6 +771,8 @@ UniValue MarmaraCreditloop(uint256 txid) { refamount = amount; refmatures = matures; + result.push_back(Pair("amount",ValueFromAmount(refamount))); + result.push_back(Pair("matures",refmatures)); } if ( createtxid != refcreatetxid || amount != refamount || matures != refmatures || currency != refcurrency ) { From a9369c2811ac35f02f6670e991838b328ddb9535 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Jan 2019 04:49:20 -1100 Subject: [PATCH 356/643] Handle short credit loop --- src/cc/marmara.cpp | 93 ++++++++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 40 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 215a55297..1d115f557 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -39,6 +39,10 @@ vin1 baton vins CC utxos from credit loop + 'D' default/partial payment + + 'L' lockfunds + */ // start of consensus code @@ -427,7 +431,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) result.push_back(Pair("error",(char *)"cant automatic settle even maturity heights")); return(result); } - else if ( n < 2 ) + else if ( n < 1 ) { result.push_back(Pair("result",(char *)"error")); result.push_back(Pair("error",(char *)"creditloop too short")); @@ -438,7 +442,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) Getscriptaddress(batonCCaddr,batontx.vout[0].scriptPubKey); if ( strcmp(myCCaddr,batonCCaddr) == 0 ) { - mtx.vin.push_back(CTxIn(creditloop[1],1,CScript())); // issuance marker + mtx.vin.push_back(CTxIn(n == 1 ? batontxid : creditloop[1],1,CScript())); // issuance marker pubkeys.push_back(Marmarapk); mtx.vin.push_back(CTxIn(batontxid,0,CScript())); pubkeys.push_back(mypk); @@ -511,13 +515,14 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) return(result); } -int32_t MarmaraGetCreditloops(int64_t &totalamount,std::vector &issuances,struct CCcontract_info *cp,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,CPubKey refpk,std::string refcurrency) +int32_t MarmaraGetCreditloops(int64_t &totalamount,std::vector &issuances,int64_t &totalclosed,std::vector &closed,struct CCcontract_info *cp,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,CPubKey refpk,std::string refcurrency) { char coinaddr[64]; CPubKey Marmarapk,senderpk; int64_t amount; uint256 createtxid,txid,hashBlock; CTransaction tx; int32_t numvouts,vout,matures,n=0; std::string currency; std::vector > unspentOutputs; Marmarapk = GetUnspendable(cp,0); GetCCaddress(cp,coinaddr,Marmarapk); SetCCunspents(unspentOutputs,coinaddr); + // do all txid, conditional on spent/unspent //fprintf(stderr,"check coinaddr.(%s)\n",coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { @@ -810,43 +815,6 @@ UniValue MarmaraCreditloop(uint256 txid) } return(result); } - -UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,std::string currency) -{ - UniValue result(UniValue::VOBJ),a(UniValue::VARR); int32_t i,n,matches; int64_t totalamount=0; std::vector issuances; char coinaddr[64]; - CPubKey Marmarapk; struct CCcontract_info *cp,C; - cp = CCinit(&C,EVAL_MARMARA); - Marmarapk = GetUnspendable(cp,0); - result.push_back(Pair("result","success")); - Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(Mypubkey())) << OP_CHECKSIG); - result.push_back(Pair("myaddress",coinaddr)); - GetCCaddress(cp,coinaddr,Mypubkey()); - result.push_back(Pair("myCCaddress",coinaddr)); - if ( refpk.size() == 33 ) - result.push_back(Pair("issuer",HexStr(refpk))); - if ( currency.size() == 0 ) - currency = (char *)"MARMARA"; - if ( firstheight <= lastheight ) - firstheight = 0, lastheight = (1 << 30); - if ( minamount <= maxamount ) - minamount = 0, maxamount = (1LL << 60); - result.push_back(Pair("firstheight",firstheight)); - result.push_back(Pair("lastheight",lastheight)); - result.push_back(Pair("minamount",ValueFromAmount(minamount))); - result.push_back(Pair("maxamount",ValueFromAmount(maxamount))); - result.push_back(Pair("currency",currency)); - if ( (n= MarmaraGetCreditloops(totalamount,issuances,cp,firstheight,lastheight,minamount,maxamount,refpk,currency)) > 0 ) - { - result.push_back(Pair("n",n)); - matches = (int32_t)issuances.size(); - result.push_back(Pair("matches",matches)); - for (i=0; i unlocked, if no change then scan all locked 'C' and 'P' for unlockht < refunlockht + +// get all tx, constrain by vout, issuances[] and closed[] + +UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,std::string currency) +{ + UniValue result(UniValue::VOBJ),a(UniValue::VARR),b(UniValue::VARR); int32_t i,n,matches; int64_t totalclosed=0,totalamount=0; std::vector issuances,closed; char coinaddr[64]; + CPubKey Marmarapk; struct CCcontract_info *cp,C; + cp = CCinit(&C,EVAL_MARMARA); + Marmarapk = GetUnspendable(cp,0); + result.push_back(Pair("result","success")); + Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(Mypubkey())) << OP_CHECKSIG); + result.push_back(Pair("myaddress",coinaddr)); + GetCCaddress(cp,coinaddr,Mypubkey()); + result.push_back(Pair("myCCaddress",coinaddr)); + if ( refpk.size() == 33 ) + result.push_back(Pair("issuer",HexStr(refpk))); + if ( currency.size() == 0 ) + currency = (char *)"MARMARA"; + if ( firstheight <= lastheight ) + firstheight = 0, lastheight = (1 << 30); + if ( minamount <= maxamount ) + minamount = 0, maxamount = (1LL << 60); + result.push_back(Pair("firstheight",firstheight)); + result.push_back(Pair("lastheight",lastheight)); + result.push_back(Pair("minamount",ValueFromAmount(minamount))); + result.push_back(Pair("maxamount",ValueFromAmount(maxamount))); + result.push_back(Pair("currency",currency)); + if ( (n= MarmaraGetCreditloops(totalamount,issuances,totalclosed,closed,cp,firstheight,lastheight,minamount,maxamount,refpk,currency)) > 0 ) + { + result.push_back(Pair("n",n)); + matches = (int32_t)issuances.size(); + result.push_back(Pair("pending",matches)); + for (i=0; i Date: Thu, 17 Jan 2019 05:02:34 -1100 Subject: [PATCH 357/643] Ref amount --- src/cc/marmara.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 1d115f557..4cf1a2a42 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -469,11 +469,11 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) } else fprintf(stderr,"null funcid for creditloop[%d]\n",i); } else fprintf(stderr,"couldnt get creditloop[%d]\n",i); } - if ( amount - remaining > 2*txfee ) + if ( refamount - remaining > 2*txfee ) { mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(CCtxidaddr(txidaddr,createtxid))) << OP_CHECKSIG)); // failure marker - if ( amount-remaining > 3*txfee ) - mtx.vout.push_back(CTxOut(amount-remaining-2*txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + if ( refamount-remaining > 3*txfee ) + mtx.vout.push_back(CTxOut(refamount-remaining-2*txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('D',createtxid,mypk,-remaining,height,currency),pubkeys); result.push_back(Pair("result",(char *)"error")); result.push_back(Pair("error",(char *)"insufficient funds")); From 8e8a94404f2d58020637e1a73fa68bca723d6bef Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 7 Jan 2019 23:19:47 +0500 Subject: [PATCH 358/643] Split Asset contract into Tokens and Assets --- src/Makefile.am | 1 + src/cc/CCHeir.h | 25 +- src/cc/CCassets.h | 22 +- src/cc/CCassetsCore.cpp | 401 ++++++----- src/cc/CCassetstx.cpp | 435 ++++++++---- src/cc/CCcustom.cpp | 22 + src/cc/CCinclude.h | 17 +- src/cc/CCtokens.cpp | 487 +++++++++++++ src/cc/CCtokens.h | 76 ++ src/cc/CCtx.cpp | 13 +- src/cc/assets.cpp | 167 +++-- src/cc/eval.h | 3 +- src/cc/heir.cpp | 1426 +++++++++++++++++++++++++++++++++----- src/cc/heir_validate.h | 622 +++++++++++++++++ src/rpc/server.cpp | 15 +- src/rpc/server.h | 9 + src/wallet/rpcwallet.cpp | 441 +++++++++++- 17 files changed, 3591 insertions(+), 591 deletions(-) create mode 100644 src/cc/CCtokens.cpp create mode 100644 src/cc/CCtokens.h create mode 100644 src/cc/heir_validate.h diff --git a/src/Makefile.am b/src/Makefile.am index e6cc5d756..9588cfe44 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -290,6 +290,7 @@ libbitcoin_server_a_SOURCES = \ cc/CCcustom.cpp \ cc/CCtx.cpp \ cc/CCutils.cpp \ + cc/CCtokens.cpp \ cc/assets.cpp \ cc/faucet.cpp \ cc/rewards.cpp \ diff --git a/src/cc/CCHeir.h b/src/cc/CCHeir.h index 214b566c7..18d1f08bb 100644 --- a/src/cc/CCHeir.h +++ b/src/cc/CCHeir.h @@ -18,12 +18,33 @@ #define CC_HEIR_H #include "CCinclude.h" +#include "CCtokens.h" -#define EVAL_HEIR 0xea +//#define EVAL_HEIR 0xea bool HeirValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +class CoinHelper; +class TokenHelper; + // CCcustom -UniValue HeirInfo(); + +// this would not link +//template std::string HeirFund(uint64_t txfee,int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 assetid); +//template UniValue HeirAdd(uint256 fundingtxid, uint64_t txfee, int64_t amount); +//template UniValue HeirClaim(uint256 fundingtxid, uint64_t txfee, int64_t nValue); + +std::string HeirFundCoinCaller(uint64_t txfee, int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 assetid); +std::string HeirFundTokenCaller(uint64_t txfee, int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 assetid); +UniValue HeirClaimCoinCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount); +UniValue HeirClaimTokenCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount); +UniValue HeirAddCoinCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount); +UniValue HeirAddTokenCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount); + +UniValue HeirInfo(uint256 fundingtxid); +UniValue HeirList(); +//std::string Heir_MakeBadTx(uint256 fundingtxid, uint8_t funcId, int64_t amount, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTime, uint32_t errMask); + +//bool HeirExactTokenAmounts(bool compareTotals, struct CCcontract_info *cpHeir, Eval* eval, uint256 assetid, const CTransaction &tx); #endif diff --git a/src/cc/CCassets.h b/src/cc/CCassets.h index 5e4441646..5a5ef2c82 100644 --- a/src/cc/CCassets.h +++ b/src/cc/CCassets.h @@ -30,12 +30,12 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx // CCassetsCore //CTxOut MakeAssetsVout(CAmount nValue,CPubKey pk); -CScript EncodeAssetCreateOpRet(uint8_t funcid,std::vector origpubkey,std::string name,std::string description); -CScript EncodeAssetOpRet(uint8_t funcid,uint256 assetid,uint256 assetid2,int64_t price,std::vector origpubkey); -bool DecodeAssetCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description); -uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey); +//CScript EncodeAssetCreateOpRet(uint8_t funcid,std::vector origpubkey,std::string name,std::string description); +//CScript EncodeAssetOpRet(uint8_t assetFuncId, uint256 tokenid, uint256 assetid2, int64_t price, std::vector origpubkey); +//bool DecodeAssetCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description); +//uint8_t DecodeAssetOpRet(const CScript &scriptPubKey, uint8_t &evalCode, uint256 &assetid, uint256 &assetid2, int64_t &price, std::vector &origpubkey); bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CTransaction &tx); -int64_t IsAssetvout(int32_t maxAssetExactAmountDepth, struct CCcontract_info *cp, Eval* eval, int64_t &price,std::vector &origpubkey,const CTransaction& tx,int32_t v,uint256 refassetid); +int64_t IsAssetvout(struct CCcontract_info *cp, int64_t &price, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 refassetid); bool ValidateBidRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); bool ValidateAskRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); bool ValidateSwapRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); @@ -44,18 +44,18 @@ bool SetAskFillamounts(int64_t &paid,int64_t &remaining_price,int64_t orig_nValu bool SetSwapFillamounts(int64_t &paid,int64_t &remaining_price,int64_t orig_nValue,int64_t &received,int64_t totalprice); int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 refassetid); int64_t AssetValidateSellvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 assetid); -bool AssetExactAmounts(int32_t maxDepth, struct CCcontract_info *cp,int64_t &inputs,int32_t starti,int64_t &outputs,Eval* eval,const CTransaction &tx,uint256 assetid); -//bool AssetExactAmounts(bool doValidateTx, struct CCcontract_info *cp, int64_t &inputs, int32_t starti, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 assetid, std::vector &ccVinsTxs); +bool AssetExactAmounts(struct CCcontract_info *cpAssets, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 assetid); // CCassetstx int64_t GetAssetBalance(CPubKey pk,uint256 tokenid); -int64_t AddAssetInputs(CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs); +int64_t AddAssetInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 assetid, int64_t total, int32_t maxinputs); + UniValue AssetOrders(uint256 tokenid); UniValue AssetInfo(uint256 tokenid); UniValue AssetList(); -std::string CreateAsset(int64_t txfee,int64_t assetsupply,std::string name,std::string description); -std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total); -std::string AssetConvert(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total,int32_t evalcode); +//std::string CreateAsset(int64_t txfee,int64_t assetsupply,std::string name,std::string description); +//std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total); +//std::string AssetConvert(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total,int32_t evalcode); std::string CreateBuyOffer(int64_t txfee,int64_t bidamount,uint256 assetid,int64_t pricetotal); std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid); diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index 52f1ed28c..52c73d47f 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2019 The SuperNET Developers. * + * Copyright © 2014-2018 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * @@ -33,7 +33,7 @@ Yes, this is quite confusing... - In ValudateAssetRemainder the naming convention is nValue is the coin/asset with the offer on the books and "units" is what it is being paid in. The high level check is to make sure we didnt lose any coins or assets, the harder to validate is the actual price paid as the "orderbook" is in terms of the combined nValue for the combined totalunits. + In ValidateAssetRemainder the naming convention is nValue is the coin/asset with the offer on the books and "units" is what it is being paid in. The high level check is to make sure we didnt lose any coins or assets, the harder to validate is the actual price paid as the "orderbook" is in terms of the combined nValue for the combined totalunits. We assume that the effective unit cost in the orderbook is valid and that that amount was paid and also that any remainder will be close enough in effective unit cost to not matter. At the edge cases, this will probably be not true and maybe some orders wont be practically fillable when reduced to fractional state. However, the original pubkey that created the offer can always reclaim it. */ @@ -230,38 +230,45 @@ bool ValidateSwapRemainder(int64_t remaining_price,int64_t remaining_nValue,int6 return(true); } +/* use EncodeTokenCreateOpRet instead: CScript EncodeAssetCreateOpRet(uint8_t funcid,std::vector origpubkey,std::string name,std::string description) { CScript opret; uint8_t evalcode = EVAL_ASSETS; opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << origpubkey << name << description); return(opret); } +*/ -CScript EncodeAssetOpRet(uint8_t funcid,uint256 assetid,uint256 assetid2,int64_t price,std::vector origpubkey) +CScript EncodeAssetOpRet(uint8_t assetFuncId, uint256 tokenid, uint256 assetid2, int64_t price, std::vector origpubkey) { - CScript opret; uint8_t evalcode = EVAL_ASSETS; - assetid = revuint256(assetid); - switch ( funcid ) + CScript opret; + uint8_t evalcode = EVAL_ASSETS; + uint8_t funcId = (uint8_t)'t'; + + tokenid = revuint256(tokenid); + switch ( assetFuncId ) { - case 't': case 'x': case 'o': - opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << assetid); + //case 't': this cannot be here + case 'x': case 'o': + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcId << tokenid << assetFuncId); break; case 's': case 'b': case 'S': case 'B': - opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << assetid << price << origpubkey); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcId << tokenid << assetFuncId << price << origpubkey); break; case 'E': case 'e': assetid2 = revuint256(assetid2); - opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << assetid << assetid2 << price << origpubkey); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcId << tokenid << assetFuncId << assetid2 << price << origpubkey); break; default: - fprintf(stderr,"EncodeOpRet: illegal funcid.%02x\n",funcid); + fprintf(stderr,"EncodeAssetOpRet: illegal funcid.%02x\n", assetFuncId); opret << OP_RETURN; break; } return(opret); } -bool DecodeAssetCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description) +// it is for compatibility, do not use this for new contracts (use DecodeTokenCreateOpRet) +bool DecodeAssetCreateOpRet(const CScript &scriptPubKey, std::vector &origpubkey, std::string &name, std::string &description) { std::vector vopret; uint8_t evalcode,funcid,*script; GetOpReturnData(scriptPubKey, vopret); @@ -274,59 +281,87 @@ bool DecodeAssetCreateOpRet(const CScript &scriptPubKey,std::vector &or return(0); } -uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey) +uint8_t DecodeAssetOpRet(const CScript &scriptPubKey, uint8_t &evalCodeInOpret, uint256 &tokenid, uint256 &assetid2, int64_t &price, std::vector &origpubkey) { - std::vector vopret; uint8_t funcid=0,*script,e,f; - GetOpReturnData(scriptPubKey, vopret); + std::vector vopret; + uint8_t *script, funcId = 0, assetFuncId = 0, dummyEvalCode, dummyFuncId; + uint256 dummyTokenid; + + GetOpReturnData(scriptPubKey, vopret); + script = (uint8_t *)vopret.data(); - memset(&assetid,0,sizeof(assetid)); - memset(&assetid2,0,sizeof(assetid2)); - price = 0; - if ( script != 0 && script[0] == EVAL_ASSETS ) - { - funcid = script[1]; - //fprintf(stderr,"decode.[%c]\n",funcid); - switch ( funcid ) + if (script == 0) { + std::cerr << "DecodeAssetOpRet() script is empty" << std::endl; + return (uint8_t)0; + } + + tokenid = zeroid; + assetid2 = zeroid; + price = 0; + + bool isEof = true; // NOTE: if parse error occures, parse might not be able to set error. It is safer to treat that it was eof if it is not set! + bool result = E_UNMARSHAL(vopret, ss >> evalCodeInOpret; ss >> funcId; ss >> tokenid; ss >> assetFuncId; isEof = ss.eof()); + + if (!result && isEof) { // NOTE: 'result==false' means 'parse error' OR 'not eof state'. Consequently, 'result==false' but 'isEof==true' means just 'parse error' + std::cerr << "DecodeAssetOpRet() incorrect opret or no asset's payload" << std::endl; + return (uint8_t)0; + } + + tokenid = revuint256(tokenid); + + std::cerr << "DecodeAssetOpRet() evalCodeInOpret=" << (int)evalCodeInOpret << " funcId=" << (char)(funcId ? funcId : ' ') << " assetFuncId=" << (char)(assetFuncId ? assetFuncId : ' ') << std::endl; + + if(evalCodeInOpret == EVAL_ASSETS) + { + //fprintf(stderr,"decode.[%c] assetFuncId.[%c]\n", funcId, assetFuncId); + switch( assetFuncId ) { - case 'c': return(funcid); - break; - case 't': case 'x': case 'o': - if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> assetid) != 0 ) + /*case 'c': + return(funcid); + break; */ + /*case 't': + if (E_UNMARSHAL(vopret, ss >> evalCode; ss >> funcId; ss >> tokenid; isEof = ss.eof()) || !isEof) + { + assetid = revuint256(assetid); + return(funcid); + } + break; */ + + case 'x': case 'o': + if (isEof) // no data after 'assetFuncId' allowed { - assetid = revuint256(assetid); - return(funcid); + return(assetFuncId); } break; case 's': case 'b': case 'S': case 'B': - if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> assetid; ss >> price; ss >> origpubkey) != 0 ) + if (E_UNMARSHAL(vopret, ss >> dummyEvalCode; ss >> dummyFuncId; ss >> dummyTokenid; ss >> dummyFuncId; ss >> price; ss >> origpubkey) != 0) { - assetid = revuint256(assetid); //fprintf(stderr,"got price %llu\n",(long long)price); - return(funcid); + return(assetFuncId); } break; case 'E': case 'e': - if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> assetid; ss >> assetid2; ss >> price; ss >> origpubkey) != 0 ) + if ( E_UNMARSHAL(vopret,ss >> dummyEvalCode; ss >> dummyFuncId; ss >> dummyTokenid; ss >> dummyFuncId; ss >> assetid2; ss >> price; ss >> origpubkey) != 0 ) { //fprintf(stderr,"got price %llu\n",(long long)price); - assetid = revuint256(assetid); assetid2 = revuint256(assetid2); - return(funcid); + return(assetFuncId); } break; default: - fprintf(stderr,"DecodeAssetOpRet: illegal funcid.%02x\n",funcid); - funcid = 0; + fprintf(stderr,"DecodeAssetOpRet: illegal funcid.%02x\n", funcId); + funcId = 0; break; } } - return(funcid); + return(funcId); } bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CTransaction &tx) { uint256 assetid,assetid2; - if ( tx.vout.size() > 0 && DecodeAssetOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,assetid,assetid2,price,origpubkey) != 0 ) + uint8_t evalCode; + if ( tx.vout.size() > 0 && DecodeAssetOpRet(tx.vout[tx.vout.size()-1].scriptPubKey, evalCode,assetid,assetid2,price,origpubkey) != 0 ) return(true); else return(false); } @@ -334,8 +369,10 @@ bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CT bool GetAssetorigaddrs(struct CCcontract_info *cp,char *CCaddr,char *destaddr,const CTransaction& tx) { uint256 assetid,assetid2; int64_t price,nValue=0; int32_t n; uint8_t funcid; std::vector origpubkey; CScript script; + uint8_t evalCode; + n = tx.vout.size(); - if ( n == 0 || (funcid= DecodeAssetOpRet(tx.vout[n-1].scriptPubKey,assetid,assetid2,price,origpubkey)) == 0 ) + if ( n == 0 || (funcid= DecodeAssetOpRet(tx.vout[n-1].scriptPubKey, evalCode,assetid,assetid2,price,origpubkey)) == 0 ) return(false); if ( GetCCaddress(cp,CCaddr,pubkey2pk(origpubkey)) != 0 && Getscriptaddress(destaddr,CScript() << origpubkey << OP_CHECKSIG) != 0 ) return(true); @@ -343,76 +380,6 @@ bool GetAssetorigaddrs(struct CCcontract_info *cp,char *CCaddr,char *destaddr,co } -// Checks if the vout is a really Asset CC vout -// if maxAssetExactAmountDepth > 0, it also validates the vin transaction itself: -// it should be either sum(cc vins) == sum(cc vouts) or the transaction is the 'tokenbase' ('c') tx -int64_t IsAssetvout(int32_t maxAssetExactAmountDepth, struct CCcontract_info *cp, Eval* eval, int64_t &price,std::vector &origpubkey,const CTransaction& tx,int32_t v,uint256 refassetid) -{ - uint256 assetid,assetid2; int64_t nValue=0; int32_t n; uint8_t funcid; - - if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) // maybe check address too? - { - - if (maxAssetExactAmountDepth > 0) { - //validate all tx - int64_t myCCVinsAmount = 0, myCCVoutsAmount = 0; - std::vector ccVinsTxs; - - //std::cerr << "IsAssetvout() validate=yes" << std::endl; - const bool validateVinTxs = false; - bool isEqualAmounts = AssetExactAmounts(maxAssetExactAmountDepth, cp, myCCVinsAmount, 0, myCCVoutsAmount, eval, tx, refassetid); - - // if ccInputs != ccOutputs and it is not the tokenbase tx means it is possibly fake tx (dimxy): - if (!isEqualAmounts && refassetid != tx.GetHash()) { // checking that this is the true tokenbase tx, by verifying that funcid=c, is done further in this function (dimxy) - std::cerr << "IsAssetvout() detected bad tx=" << tx.GetHash().GetHex() << ": cc inputs != cc outputs and not the 'tokenbase' tx" << std::endl; - return 0; - } - } - - - n = tx.vout.size(); - if (v >= n - 1) { // just moved this up (dimxy) - std::cerr << "isAssetVout() internal err: (v >= n - 1), returning 0" << std::endl; - return(0); - } - nValue = tx.vout[v].nValue; - - // fprintf(stderr,"IsAssetvout() CC vout v.%d of n=%d amount=%.8f\n",v,n,(double)nValue/COIN); - - if ( (funcid= DecodeAssetOpRet(tx.vout[n-1].scriptPubKey,assetid,assetid2,price,origpubkey)) == 0 ) - { - fprintf(stderr,"IsAssetvout() null decodeopret v.%d\n",v); - return(0); - } - else if ( funcid == 'c' ) - { - if (refassetid == tx.GetHash() && v == 0) { - std::cerr << "isAssetVout() this is the tokenbase 'c' tx, txid=" << tx.GetHash().GetHex() << " returning nValue=" << nValue << std::endl; - return(nValue); - } - } - else if ( (funcid == 'b' || funcid == 'B') && v == 0 ) // critical! 'b'/'B' vout0 is NOT asset - return(0); - else if ( funcid != 'E' ) - { - if ( assetid == refassetid ) - { - fprintf(stderr,"IsAssetvout() returning %.8f\n",(double)nValue/COIN); - return(nValue); - } - } - else if ( funcid == 'E' ) - { - if ( v < 2 && assetid == refassetid ) - return(nValue); - else if ( v == 2 && assetid2 == refassetid ) - return(nValue); - } - } - //fprintf(stderr,"Isassetvout: normal output v.%d %.8f\n",v,(double)tx.vout[v].nValue/COIN); - return(0); -} - int64_t AssetValidateCCvin(struct CCcontract_info *cp,Eval* eval,char *CCaddr,char *origaddr,const CTransaction &tx,int32_t vini,CTransaction &vinTx) { uint256 hashBlock; char destaddr[64]; @@ -446,16 +413,16 @@ int64_t AssetValidateCCvin(struct CCcontract_info *cp,Eval* eval,char *CCaddr,ch int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 refassetid) { - CTransaction vinTx; int64_t nValue; uint256 assetid,assetid2; uint8_t funcid; + CTransaction vinTx; int64_t nValue; uint256 assetid,assetid2; uint8_t funcid, evalCode; CCaddr[0] = origaddr[0] = 0; if ( (nValue= AssetValidateCCvin(cp,eval,CCaddr,origaddr,tx,1,vinTx)) == 0 ) - return(0); + return(0); else if ( vinTx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) return eval->Invalid("invalid normal vout0 for buyvin"); else { //fprintf(stderr,"have %.8f checking assetid origaddr.(%s)\n",(double)nValue/COIN,origaddr); - if ( vinTx.vout.size() > 0 && (funcid= DecodeAssetOpRet(vinTx.vout[vinTx.vout.size()-1].scriptPubKey,assetid,assetid2,tmpprice,tmporigpubkey)) != 'b' && funcid != 'B' ) + if ( vinTx.vout.size() > 0 && (funcid= DecodeAssetOpRet(vinTx.vout[vinTx.vout.size()-1].scriptPubKey, evalCode, assetid,assetid2,tmpprice,tmporigpubkey)) != 'b' && funcid != 'B' ) return eval->Invalid("invalid opreturn for buyvin"); else if ( refassetid != assetid ) return eval->Invalid("invalid assetid for buyvin"); @@ -469,88 +436,162 @@ int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmppr int64_t AssetValidateSellvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 assetid) { CTransaction vinTx; int64_t nValue,assetoshis; - fprintf(stderr,"AssetValidateSellvin\n"); + //fprintf(stderr,"AssetValidateSellvin\n"); if ( (nValue= AssetValidateCCvin(cp,eval,CCaddr,origaddr,tx,1,vinTx)) == 0 ) return(0); - if ( (assetoshis= IsAssetvout(1, cp, NULL, tmpprice,tmporigpubkey,vinTx,0,assetid)) == 0 ) + if ( (assetoshis= IsAssetvout(cp, tmpprice, tmporigpubkey,vinTx,0,assetid)) == 0 ) return eval->Invalid("invalid missing CC vout0 for sellvin"); else return(assetoshis); } -// overload with additional params for deep tx validation (dimxy) -bool AssetExactAmounts(int maxDepth, struct CCcontract_info *cp, int64_t &inputs, int32_t starti, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 assetid) +// validates opret for asset tx: +bool ValidateAssetOpret(CTransaction tx, int32_t v, uint256 assetid, int64_t &price, std::vector &origpubkey) { + + uint256 assetidOpret, assetidOpret2; + uint8_t funcid, evalCode; + + // this is just for log messages indentation fur debugging recursive calls: + int32_t n = tx.vout.size(); + + if ((funcid = DecodeAssetOpRet(tx.vout[n - 1].scriptPubKey, evalCode, assetidOpret, assetidOpret2, price, origpubkey)) == 0) + { + std::cerr << "ValidateAssetOpret() DecodeOpret returned null for n-1=" << n - 1 << " txid=" << tx.GetHash().GetHex() << std::endl; + return(false); + } +/* it is now on token level: + else if (funcid == 'c') + { + if (assetid != zeroid && assetid == tx.GetHash() && v == 0) { + //std::cerr << "ValidateAssetOpret() this is the tokenbase 'c' tx, txid=" << tx.GetHash().GetHex() << " vout=" << v << " returning true" << std::endl; + return(true); + } + } + else if (funcid == 't') // TODO: check if this new block does not influence IsAssetVout + { + //std::cerr << "ValidateAssetOpret() assetid=" << assetid.GetHex() << " assetIdOpret=" << assetidOpret.GetHex() << " txid=" << tx.GetHash().GetHex() << std::endl; + if (assetid != zeroid && assetid == assetidOpret) { + //std::cerr << "ValidateAssetOpret() this is a transfer 't' tx, txid=" << tx.GetHash().GetHex() << " vout=" << v << " returning true" << std::endl; + return(true); + } + } */ + // TODO: hope this was unneeded!!! (dimxy) + else if ((funcid == 'b' || funcid == 'B') && v == 0) // critical! 'b'/'B' vout0 is NOT asset + return(false); + else if (funcid != 'E') + { + if (assetid != zeroid && assetidOpret == assetid) + { + //std::cerr << "ValidateAssetOpret() returns true for not 'E', funcid=" << (char)funcid << std::endl; + return(true); + } + } + else if (funcid == 'E') // NOTE: not implemented yet! + { + if (v < 2 && assetid != zeroid && assetidOpret == assetid) + return(true); + else if (v == 2 && assetid != zeroid && assetidOpret2 == assetid) + return(true); + } + + //std::cerr << "ValidateAssetOpret() return false funcid=" << (char)funcid << " assetid=" << assetid.GetHex() << " assetIdOpret=" << assetidOpret.GetHex() << " txid=" << tx.GetHash().GetHex() << std::endl; + return false; +} + +// Checks if the vout is a really Asset CC vout +// compareTotals == true, the func also validates the passed transaction itself: +// it should be either sum(cc vins) == sum(cc vouts) or the transaction is the 'tokenbase' ('c') tx +int64_t IsAssetvout(struct CCcontract_info *cp, int64_t &price, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 refassetid) { - CTransaction vinTx; uint256 hashBlock,id,id2; int32_t i,flag,numvins,numvouts; int64_t assetoshis; std::vector tmporigpubkey; int64_t tmpprice; - numvins = tx.vin.size(); - numvouts = tx.vout.size(); - inputs = outputs = 0; - maxDepth--; + //std::cerr << "IsAssetvout() entered for txid=" << tx.GetHash().GetHex() << " v=" << v << " for assetid=" << refassetid.GetHex() << std::endl; - for (i=starti; iismyvin)(tx.vin[i].scriptSig) != 0 ) - { - //std::cerr << "AssetExactAmounts() eval is true=" << (eval != NULL) << " ismyvin=ok for_i=" << i << std::endl; - // we are really not inside validation! -- dimxy - if ( (eval && eval->GetTxUnconfirmed(tx.vin[i].prevout.hash,vinTx,hashBlock) == 0) || (!eval && !myGetTransaction(tx.vin[i].prevout.hash, vinTx, hashBlock)) ) - { - fprintf(stderr,"AssetExactAmounts() cannot read vintx i.%d starti.%d numvins.%d\n", i,starti,numvins); - return (!eval) ? false : eval->Invalid("always should find vin, but didnt"); + if (tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0) // maybe check address too? dimxy: possibly no, because there are too many cases with different addresses here + { + int32_t n = tx.vout.size(); + // just check boundaries: + if (v >= n - 1) { // just moved this up (dimxy) + std::cerr << "isAssetVout() internal err: (v >= n - 1), returning 0" << std::endl; + return(0); + } - } // false means 'don't go deeper' -- dimxy - else if ( (assetoshis= IsAssetvout( maxDepth, cp, eval, tmpprice,tmporigpubkey,vinTx,tx.vin[i].prevout.n,assetid)) != 0 ) - { - fprintf(stderr,"AssetExactAmounts() vin%d %llu, ",i,(long long)assetoshis); - inputs += assetoshis; - } - else - { - if ( vinTx.vout[i].scriptPubKey.IsPayToCryptoCondition() != 0 && DecodeAssetOpRet(vinTx.vout[vinTx.vout.size()-1].scriptPubKey,id,id2,tmpprice,tmporigpubkey) == 't' && id == assetid ) - { - assetoshis = vinTx.vout[i].nValue; - fprintf(stderr,"AssetExactAmounts() vin%d assetoshis=%llu special case, ",i,(long long)assetoshis); - inputs += assetoshis; - } - } - } - } + // moved opret checking to this new reusable func (dimxy): + const bool valOpret = ValidateAssetOpret(tx, v, refassetid, price, origpubkey); + //std::cerr << "IsAssetvout() ValidateAssetOpret returned=" << std::boolalpha << valOpret << " for txid=" << tx.GetHash().GetHex() << " for assetid=" << refassetid.GetHex() << std::endl; + if (valOpret) { + //std::cerr << "IsAssetvout() ValidateAssetOpret returned true, returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for assetid=" << refassetid.GetHex() << std::endl; + return tx.vout[v].nValue; + } + //fprintf(stderr,"IsAssetvout() CC vout v.%d of n=%d amount=%.8f txid=%s\n",v,n,(double)0/COIN, tx.GetHash().GetHex().c_str()); + } + //fprintf(stderr,"IsAssetvout() normal output v.%d %.8f\n",v,(double)tx.vout[v].nValue/COIN); + return(0); +} - if ( DecodeAssetOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,id,id2,tmpprice,tmporigpubkey) == 't' && id == assetid ) - flag = 1; - else flag = 0; +// sets cc inputs vs cc outputs and ensures they are equal: +bool AssetExactAmounts(struct CCcontract_info *cpAssets, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 assetid) +{ + CTransaction vinTx; uint256 hashBlock, id, id2; int32_t flag; int64_t assetoshis; std::vector tmporigpubkey; int64_t tmpprice; + int32_t numvins = tx.vin.size(); + int32_t numvouts = tx.vout.size(); + inputs = outputs = 0; - for (i=0; iismyvin)(tx.vin[i].scriptSig) || (*cpTokens->ismyvin)(tx.vin[i].scriptSig)) // || IsVinAllowed(tx.vin[i].scriptSig) != 0) + { + //std::cerr << indentStr << "AssetExactAmounts() eval is true=" << (eval != NULL) << " ismyvin=ok for_i=" << i << std::endl; + // we are not inside the validation code -- dimxy + if ((eval && eval->GetTxUnconfirmed(tx.vin[i].prevout.hash, vinTx, hashBlock) == 0) || (!eval && !myGetTransaction(tx.vin[i].prevout.hash, vinTx, hashBlock))) + { + std::cerr << "AssetExactAmounts() cannot read vintx for i." << i << " numvins." << numvins << std::endl; + return (!eval) ? false : eval->Invalid("always should find vin tx, but didnt"); + } + else { + // validate vouts of vintx + //std::cerr << indentStr << "AssetExactAmounts() check vin i=" << i << " nValue=" << vinTx.vout[tx.vin[i].prevout.n].nValue << std::endl; + assetoshis = IsAssetvout(cpAssets, tmpprice, tmporigpubkey, vinTx, tx.vin[i].prevout.n, assetid); + if (assetoshis != 0) + { + std::cerr << "AssetExactAmounts() vin i=" << i << " assetoshis=" << assetoshis << std::endl; + inputs += assetoshis; + } + } + } + } + + // we do not use this flag anymore + //if ( DecodeAssetOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,id,id2,tmpprice,tmporigpubkey) == 't' && id == assetid ) + //flag = 1; + //else + //flag = 0; + + for (int32_t i = 0; i ccVinsTxs; - - return AssetExactAmounts(true, cp, inputs, starti, outputs, eval, tx, assetid); -}*/ diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index fbc53406b..cae4b42bb 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -14,6 +14,8 @@ ******************************************************************************/ #include "CCassets.h" +//#include "CCtokens.h" + int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs) { @@ -21,25 +23,31 @@ int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); - threshold = total/(maxinputs!=0?maxinputs:64); + + threshold = total/(maxinputs!=0?maxinputs:64); // TODO: is maxinputs really not over 64, what if i want to calc total balance? + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; - if ( it->second.satoshis < threshold ) + + if (it->second.satoshis < threshold) continue; + for (j=0; junspendableCCaddr) != 0 && strcmp(destaddr,cp->unspendableaddr2) != 0 ) + if( strcmp(destaddr,coinaddr) != 0 && strcmp(destaddr,cp->unspendableCCaddr) != 0 && strcmp(destaddr,cp->unspendableaddr2) != 0 ) continue; fprintf(stderr,"AddAssetInputs() check destaddress=%s vout amount=%.8f\n",destaddr,(double)vintx.vout[vout].nValue/COIN); - if ( (nValue= IsAssetvout(1, cp, NULL, price,origpubkey,vintx,vout,assetid)) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + if( (nValue = IsAssetvout(cp, price, origpubkey, vintx, vout, assetid)) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( total != 0 && maxinputs != 0 ) mtx.vin.push_back(CTxIn(txid,vout,CScript())); @@ -57,12 +65,13 @@ int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK return(totalinputs); } + int64_t GetAssetBalance(CPubKey pk,uint256 tokenid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); struct CCcontract_info *cp,C; - cp = CCinit(&C,EVAL_ASSETS); - return(AddAssetInputs(cp,mtx,pk,tokenid,0,0)); + cp = CCinit(&C,EVAL_TOKENS); + return(AddTokenCCInputs(cp,mtx,pk,tokenid,0,0)); } UniValue AssetInfo(uint256 assetid) @@ -75,11 +84,11 @@ UniValue AssetInfo(uint256 assetid) result.push_back(Pair("error","cant find assetid")); return(result); } - if ( vintx.vout.size() > 0 && DecodeAssetCreateOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,origpubkey,name,description) == 0 ) + if ( vintx.vout.size() > 0 && DecodeTokenCreateOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,origpubkey,name,description) == 0 ) { - fprintf(stderr,"assetid isnt assetcreation txid\n"); + fprintf(stderr,"assetid isnt token creation txid\n"); result.push_back(Pair("result","error")); - result.push_back(Pair("error","assetid isnt assetcreation txid")); + result.push_back(Pair("error","assetid isnt token creation txid")); } result.push_back(Pair("result","success")); result.push_back(Pair("tokenid",uint256_str(str,assetid))); @@ -92,15 +101,20 @@ UniValue AssetInfo(uint256 assetid) UniValue AssetList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock; CTransaction vintx; std::vector origpubkey; std::string name,description; char str[65]; - cp = CCinit(&C,EVAL_ASSETS); + UniValue result(UniValue::VARR); + std::vector > addressIndex; + struct CCcontract_info *cp,C; uint256 txid,hashBlock; + CTransaction vintx; std::vector origpubkey; + std::string name,description; char str[65]; + + cp = CCinit(&C,EVAL_TOKENS); SetCCtxids(addressIndex,cp->normaladdr); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) { txid = it->first.txhash; if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - if ( vintx.vout.size() > 0 && DecodeAssetCreateOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,origpubkey,name,description) != 0 ) + if ( vintx.vout.size() > 0 && DecodeTokenCreateOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,origpubkey,name,description) != 0 ) { result.push_back(uint256_str(str,txid)); } @@ -112,17 +126,33 @@ UniValue AssetList() UniValue AssetOrders(uint256 refassetid) { static uint256 zero; - int64_t price; uint256 txid,hashBlock,assetid,assetid2; std::vector origpubkey; CTransaction vintx; UniValue result(UniValue::VARR); std::vector > unspentOutputs; uint8_t funcid; char numstr[32],funcidstr[16],origaddr[64],assetidstr[65]; struct CCcontract_info *cp,C; - cp = CCinit(&C,EVAL_ASSETS); - SetCCunspents(unspentOutputs,(char *)cp->unspendableCCaddr); - for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) - { + UniValue result(UniValue::VARR); + std::vector > unspentOutputsTokens, unspentOutputsAssets; + + struct CCcontract_info *cpTokens, tokensC; + struct CCcontract_info *cpAssets, assetsC; + + cpTokens = CCinit(&tokensC, EVAL_TOKENS); + cpAssets = CCinit(&assetsC, EVAL_ASSETS); + + auto addOrders = [&](struct CCcontract_info *cp, std::vector >::const_iterator it) + { + uint256 txid, hashBlock, assetid, assetid2; + int64_t price; + std::vector origpubkey; + CTransaction vintx; + uint8_t funcid, evalCode; + char numstr[32], funcidstr[16], origaddr[64], assetidstr[65]; + txid = it->first.txhash; - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + //std::cerr << "addOrders txid" << txid.GetHex() << std::endl; + if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - if ( vintx.vout.size() > 0 && (funcid= DecodeAssetOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,assetid,assetid2,price,origpubkey)) != 0 ) + funcid = DecodeAssetOpRet(vintx.vout[vintx.vout.size() - 1].scriptPubKey, evalCode, assetid, assetid2, price, origpubkey); + //std::cerr << "addOrders vintx.vout.size()=" << vintx.vout.size() << " funcid=" << (char)(funcid ? funcid : ' ') << std::endl; + if (vintx.vout.size() > 0 && (funcid = DecodeAssetOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey, evalCode, assetid, assetid2, price, origpubkey)) != 0) { - if ( refassetid != zero && assetid != refassetid ) + if (refassetid != zero && assetid != refassetid) { //int32_t z; //for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&txid)[z]); @@ -131,11 +161,13 @@ UniValue AssetOrders(uint256 refassetid) //fprintf(stderr," assetid\n"); //for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&refassetid)[z]); //fprintf(stderr," refassetid\n"); - continue; + return; } - if ( vintx.vout[it->first.index].nValue == 0 ) - continue; + if (vintx.vout[it->first.index].nValue == 0) + return; + UniValue item(UniValue::VOBJ); + funcidstr[0] = funcid; funcidstr[1] = 0; item.push_back(Pair("funcid", funcidstr)); @@ -157,8 +189,8 @@ UniValue AssetOrders(uint256 refassetid) } if ( origpubkey.size() == 33 ) { - GetCCaddress(cp,origaddr,pubkey2pk(origpubkey)); - item.push_back(Pair("origaddress",origaddr)); + GetCCaddress(cp, origaddr, pubkey2pk(origpubkey)); // TODO: what is this? is it asset or token?? + item.push_back(Pair("origaddress", origaddr)); } if ( assetid != zeroid ) item.push_back(Pair("tokenid",uint256_str(assetidstr,assetid))); @@ -184,11 +216,27 @@ UniValue AssetOrders(uint256 refassetid) //fprintf(stderr,"func.(%c) %s/v%d %.8f\n",funcid,uint256_str(assetidstr,txid),(int32_t)it->first.index,(double)vintx.vout[it->first.index].nValue/COIN); } } - } + }; + + + SetCCunspents(unspentOutputsTokens, (char *)cpTokens->unspendableCCaddr); + SetCCunspents(unspentOutputsAssets, (char *)cpAssets->unspendableCCaddr); + + for (std::vector >::const_iterator itTokens = unspentOutputsTokens.begin(); + itTokens != unspentOutputsTokens.end(); + itTokens++) + addOrders(cpTokens, itTokens); + + for (std::vector >::const_iterator itAssets = unspentOutputsAssets.begin(); + itAssets != unspentOutputsAssets.end(); + itAssets++) + addOrders(cpAssets, itAssets); + return(result); } -std::string CreateAsset(int64_t txfee,int64_t assetsupply,std::string name,std::string description) +// not used (use TokenCreate instead) +/* std::string CreateAsset(int64_t txfee,int64_t assetsupply,std::string name,std::string description) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CPubKey mypk; struct CCcontract_info *cp,C; @@ -213,9 +261,10 @@ std::string CreateAsset(int64_t txfee,int64_t assetsupply,std::string name,std:: return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetCreateOpRet('c',Mypubkey(),name,description))); } return(""); -} - -std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total) +} */ + +// not used (use TokenTransfer instead) +/* std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CPubKey mypk; uint64_t mask; int64_t CCchange=0,inputs=0; struct CCcontract_info *cp,C; @@ -230,11 +279,11 @@ std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector des mypk = pubkey2pk(Mypubkey()); if ( AddNormalinputs(mtx,mypk,txfee,3) > 0 ) { - /*n = outputs.size(); - if ( n == amounts.size() ) - { - for (i=0; i 0 ) { @@ -254,9 +303,10 @@ std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector des //} else fprintf(stderr,"numoutputs.%d != numamounts.%d\n",n,(int32_t)amounts.size()); } return(""); -} +} */ -std::string AssetConvert(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total,int32_t evalcode) +// deprecated +/* std::string AssetConvert(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total,int32_t evalcode) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CPubKey mypk; int64_t CCchange=0,inputs=0; struct CCcontract_info *cp,C; @@ -281,76 +331,106 @@ std::string AssetConvert(int64_t txfee,uint256 assetid,std::vector dest } else fprintf(stderr,"not enough CC asset inputs for %.8f\n",(double)total/COIN); } return(""); -} +} */ -std::string CreateBuyOffer(int64_t txfee,int64_t bidamount,uint256 assetid,int64_t pricetotal) +// rpc tokenbid implementation, locks 'bidamount' coins for the 'pricetotal' of tokens +std::string CreateBuyOffer(int64_t txfee, int64_t bidamount, uint256 assetid, int64_t pricetotal) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; struct CCcontract_info *cp,C; uint256 hashBlock; CTransaction vintx; std::vector origpubkey; std::string name,description; - if ( bidamount < 0 || pricetotal < 0 ) + CPubKey mypk; + struct CCcontract_info *cpAssets, C; + uint256 hashBlock; + CTransaction vintx; + std::vector origpubkey; + std::string name,description; + int64_t inputs; + + std::cerr << "CreateBuyOffer() bidamount=" << bidamount << " numtokens(pricetotal)=" << pricetotal << std::endl; + + if (bidamount < 0 || pricetotal < 0) { - fprintf(stderr,"negative bidamount %lld, pricetotal %lld\n",(long long)bidamount,(long long)pricetotal); + fprintf(stderr,"negative bidamount %lld, pricetotal %lld\n", (long long)bidamount, (long long)pricetotal); return(""); } - if ( GetTransaction(assetid,vintx,hashBlock,false) == 0 ) + if (GetTransaction(assetid, vintx, hashBlock, false) == 0) { fprintf(stderr,"cant find assetid\n"); return(""); } - if ( vintx.vout.size() > 0 && DecodeAssetCreateOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,origpubkey,name,description) == 0 ) + if (vintx.vout.size() > 0 && DecodeTokenCreateOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey, origpubkey, name, description) == 0) { fprintf(stderr,"assetid isnt assetcreation txid\n"); return(""); } - cp = CCinit(&C,EVAL_ASSETS); - if ( txfee == 0 ) + + cpAssets = CCinit(&C,EVAL_ASSETS); // NOTE: assets here! + if (txfee == 0) txfee = 10000; + mypk = pubkey2pk(Mypubkey()); - if ( AddNormalinputs(mtx,mypk,bidamount+txfee,64) > 0 ) + + if ((inputs = AddNormalinputs(mtx, mypk, bidamount+txfee, 64)) > 0) { - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,bidamount,GetUnspendable(cp,0))); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('b',assetid,zeroid,pricetotal,Mypubkey()))); + std::cerr << "CreateBuyOffer() inputs=" << inputs << std::endl; + if (inputs < bidamount+txfee) { + std::cerr << "CreateBuyOffer(): insufficient coins to make buy offer" << std::endl; + CCerror = strprintf("insufficient coins to make buy offer"); + return (""); + } + + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, bidamount, GetUnspendable(cpAssets,0))); + return(FinalizeCCTx(0, cpAssets, mtx, mypk, txfee, EncodeAssetOpRet('b', assetid, zeroid, pricetotal, Mypubkey()))); } + CCerror = strprintf("no coins found to make buy offer"); return(""); } +// rpc tokenask implementation, locks 'askamount' tokens for the 'pricetotal' std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t pricetotal) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; uint64_t mask; int64_t inputs,CCchange; CScript opret; struct CCcontract_info *cp,C; + CPubKey mypk; + uint64_t mask; + int64_t inputs, CCchange; + CScript opret; + struct CCcontract_info *cp,C; //std::cerr << "CreateSell() askamount=" << askamount << " pricetotal=" << pricetotal << std::endl; - if ( askamount < 0 || pricetotal < 0 ) - { + if (askamount < 0 || pricetotal < 0) { fprintf(stderr,"negative askamount %lld, askamount %lld\n",(long long)pricetotal,(long long)askamount); return(""); } - cp = CCinit(&C,EVAL_ASSETS); + + cp = CCinit(&C, EVAL_TOKENS); // NOTE: tokens is here + if ( txfee == 0 ) txfee = 10000; + mypk = pubkey2pk(Mypubkey()); - if ( AddNormalinputs(mtx,mypk,txfee,3) > 0 ) + if (AddNormalinputs(mtx, mypk, txfee, 3) > 0) { mask = ~((1LL << mtx.vin.size()) - 1); - if ( (inputs= AddAssetInputs(cp,mtx,mypk,assetid,askamount,60)) > 0 ) + if ((inputs = AddTokenCCInputs(cp, mtx, mypk, assetid, askamount, 60)) > 0) { if (inputs < askamount) { - //askamount = inputs; + //was: askamount = inputs; std::cerr << "CreateSell(): insufficient tokens for ask" << std::endl; + CCerror = strprintf("insufficient tokens for ask"); return (""); } - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,askamount,GetUnspendable(cp,0))); - if ( inputs > askamount ) + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS,askamount, GetUnspendable(cp,0))); + if (inputs > askamount) CCchange = (inputs - askamount); - if ( CCchange != 0 ) - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk)); - opret = EncodeAssetOpRet('s',assetid,zeroid,pricetotal,Mypubkey()); + if (CCchange != 0) + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, CCchange, mypk)); + + opret = EncodeAssetOpRet('s',assetid, zeroid, pricetotal, Mypubkey()); return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,opret)); } else { - fprintf(stderr, "need some assets to place ask\n"); + fprintf(stderr, "need some tokens to place ask\n"); } } else { // dimxy added 'else', because it was misleading message before @@ -363,34 +443,48 @@ std::string CreateSwap(int64_t txfee,int64_t askamount,uint256 assetid,uint256 a { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CPubKey mypk; uint64_t mask; int64_t inputs,CCchange; CScript opret; struct CCcontract_info *cp,C; + + ////////////////////////////////////////// fprintf(stderr,"asset swaps disabled\n"); return(""); + ////////////////////////////////////////// + if ( askamount < 0 || pricetotal < 0 ) { fprintf(stderr,"negative askamount %lld, askamount %lld\n",(long long)pricetotal,(long long)askamount); return(""); } - cp = CCinit(&C,EVAL_ASSETS); + cp = CCinit(&C, EVAL_ASSETS); + if ( txfee == 0 ) txfee = 10000; + mypk = pubkey2pk(Mypubkey()); - if ( AddNormalinputs(mtx,mypk,txfee,3) > 0 ) + + if (AddNormalinputs(mtx, mypk, txfee, 3) > 0) { mask = ~((1LL << mtx.vin.size()) - 1); - if ( (inputs= AddAssetInputs(cp,mtx,mypk,assetid,askamount,60)) > 0 ) + if ((inputs = AddAssetInputs(cp, mtx, mypk, assetid, askamount, 60)) > 0) { - if ( inputs < askamount ) - askamount = inputs; - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,askamount,GetUnspendable(cp,0))); - if ( inputs > askamount ) + if (inputs < askamount) { + //was: askamount = inputs; + std::cerr << "CreateSwap(): insufficient tokens for ask" << std::endl; + CCerror = strprintf("insufficient tokens for ask"); + return (""); + } + + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, askamount, GetUnspendable(cp, 0))); + + if (inputs > askamount) CCchange = (inputs - askamount); - if ( CCchange != 0 ) - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk)); - if ( assetid2 == zeroid ) - opret = EncodeAssetOpRet('s',assetid,zeroid,pricetotal,Mypubkey()); + if (CCchange != 0) + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, CCchange, mypk)); + + if (assetid2 == zeroid) + opret = EncodeAssetOpRet('s', assetid, zeroid, pricetotal, Mypubkey()); else { - opret = EncodeAssetOpRet('e',assetid,assetid2,pricetotal,Mypubkey()); + opret = EncodeAssetOpRet('e', assetid, assetid2, pricetotal, Mypubkey()); } return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,opret)); } @@ -405,146 +499,213 @@ std::string CreateSwap(int64_t txfee,int64_t askamount,uint256 assetid,uint256 a return(""); } +// unlocks coins std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction vintx; uint64_t mask; uint256 hashBlock; int64_t bidamount; CPubKey mypk; struct CCcontract_info *cp,C; - cp = CCinit(&C,EVAL_ASSETS); + CTransaction vintx; + uint64_t mask; + uint256 hashBlock; + int64_t bidamount; + CPubKey mypk; + struct CCcontract_info *cp,C; + + cp = CCinit(&C, EVAL_ASSETS); + if ( txfee == 0 ) txfee = 10000; + mypk = pubkey2pk(Mypubkey()); - if ( AddNormalinputs(mtx,mypk,txfee,3) > 0 ) + + if (AddNormalinputs(mtx, mypk, txfee, 3) > 0) { mask = ~((1LL << mtx.vin.size()) - 1); - if ( GetTransaction(bidtxid,vintx,hashBlock,false) != 0 ) + if (GetTransaction(bidtxid, vintx, hashBlock, false) != 0) { bidamount = vintx.vout[0].nValue; - mtx.vin.push_back(CTxIn(bidtxid,0,CScript())); + mtx.vin.push_back(CTxIn(bidtxid, 0, CScript())); mtx.vout.push_back(CTxOut(bidamount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,EncodeAssetOpRet('o',assetid,zeroid,0,Mypubkey()))); + return(FinalizeCCTx(mask, cp, mtx, mypk, txfee, EncodeAssetOpRet('o', assetid, zeroid, 0, Mypubkey()))); } } return(""); } +//unlocks tokens std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction vintx; uint64_t mask; uint256 hashBlock; int64_t askamount; CPubKey mypk; struct CCcontract_info *cp,C; - cp = CCinit(&C,EVAL_ASSETS); + CTransaction vintx; uint64_t mask; uint256 hashBlock; int64_t askamount; CPubKey mypk; + struct CCcontract_info *cp,C; + + cp = CCinit(&C, EVAL_TOKENS); + if ( txfee == 0 ) txfee = 10000; + mypk = pubkey2pk(Mypubkey()); - if ( AddNormalinputs(mtx,mypk,txfee,3) > 0 ) + + if (AddNormalinputs(mtx, mypk, txfee, 3) > 0) { mask = ~((1LL << mtx.vin.size()) - 1); - if ( GetTransaction(asktxid,vintx,hashBlock,false) != 0 ) + if (GetTransaction(asktxid, vintx, hashBlock, false) != 0) { askamount = vintx.vout[0].nValue; - mtx.vin.push_back(CTxIn(asktxid,0,CScript())); - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,askamount,mypk)); - return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,EncodeAssetOpRet('x',assetid,zeroid,0,Mypubkey()))); + mtx.vin.push_back(CTxIn(asktxid, 0, CScript())); + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, askamount, mypk)); + return(FinalizeCCTx(mask, cp, mtx, mypk, txfee, EncodeAssetOpRet('x', assetid, zeroid, 0, Mypubkey()))); } } return(""); } +//send tokens, receive coins: std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t fillamount) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction vintx; uint256 hashBlock; CPubKey mypk; std::vector origpubkey; int32_t bidvout=0; uint64_t mask; int64_t origprice,bidamount,paid_amount,remaining_required,inputs,CCchange=0; struct CCcontract_info *cp,C; - if ( fillamount < 0 ) + CTransaction vintx; + uint256 hashBlock; + CPubKey mypk; + std::vector origpubkey; + int32_t bidvout=0; + uint64_t mask; + int64_t origprice, bidamount, paid_amount, remaining_required, inputs, CCchange=0; + struct CCcontract_info *cp,C; + + if (fillamount < 0) { - fprintf(stderr,"negative fillamount %lld\n",(long long)fillamount); + fprintf(stderr,"negative fillamount %lld\n", (long long)fillamount); return(""); } - cp = CCinit(&C,EVAL_ASSETS); - if ( txfee == 0 ) + cp = CCinit(&C, EVAL_TOKENS); + + if ( txfee == 0 ) txfee = 10000; + mypk = pubkey2pk(Mypubkey()); - if ( AddNormalinputs(mtx,mypk,txfee,3) > 0 ) + + if (AddNormalinputs(mtx, mypk, txfee, 3) > 0) { mask = ~((1LL << mtx.vin.size()) - 1); - if ( GetTransaction(bidtxid,vintx,hashBlock,false) != 0 ) + if (GetTransaction(bidtxid, vintx, hashBlock, false) != 0) { bidamount = vintx.vout[bidvout].nValue; - SetAssetOrigpubkey(origpubkey,origprice,vintx); - mtx.vin.push_back(CTxIn(bidtxid,bidvout,CScript())); - if ( (inputs= AddAssetInputs(cp,mtx,mypk,assetid,fillamount,60)) > 0 ) + SetAssetOrigpubkey(origpubkey, origprice, vintx); + + mtx.vin.push_back(CTxIn(bidtxid, bidvout, CScript())); + + if ((inputs = AddTokenCCInputs(cp, mtx, mypk, assetid, fillamount, 60)) > 0) { - if ( inputs < fillamount ) - fillamount = inputs; - SetBidFillamounts(paid_amount,remaining_required,bidamount,fillamount,origprice); - if ( inputs > fillamount ) + if (inputs < fillamount) { + std::cerr << "FillBuyOffer(): insufficient tokens to fill buy offer" << std::endl; + CCerror = strprintf("insufficient tokens to fill buy offer"); + return (""); + } + + SetBidFillamounts(paid_amount, remaining_required, bidamount, fillamount, origprice); + + if (inputs > fillamount) CCchange = (inputs - fillamount); - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,bidamount - paid_amount,GetUnspendable(cp,0))); + + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, bidamount - paid_amount, GetUnspendable(cp,0))); // tokens mtx.vout.push_back(CTxOut(paid_amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,fillamount,pubkey2pk(origpubkey))); - if ( CCchange != 0 ) - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk)); - fprintf(stderr,"remaining %llu -> origpubkey\n",(long long)remaining_required); - return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,EncodeAssetOpRet('B',assetid,zeroid,remaining_required,origpubkey))); + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, fillamount, pubkey2pk(origpubkey))); // coins + + if (CCchange != 0) + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, CCchange, mypk)); // coins + + fprintf(stderr,"remaining %llu -> origpubkey\n", (long long)remaining_required); + + return(FinalizeCCTx(mask,cp,mtx,mypk,txfee, EncodeAssetOpRet('B', assetid, zeroid, remaining_required, origpubkey))); } else return("dont have any assets to fill bid\n"); } } return("no normal coins left"); } + +// send coins, receive tokens std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 asktxid,int64_t fillunits) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction vintx,filltx; uint256 hashBlock; CPubKey mypk; std::vector origpubkey; double dprice; uint64_t mask; int32_t askvout=0; int64_t received_assetoshis,total_nValue,orig_assetoshis,paid_nValue,remaining_nValue,inputs,CCchange=0; struct CCcontract_info *cp,C; - if ( fillunits < 0 ) + CTransaction vintx,filltx; + uint256 hashBlock; + CPubKey mypk; + std::vector origpubkey; + double dprice; + uint64_t mask; + int32_t askvout=0; + int64_t received_assetoshis, total_nValue, orig_assetoshis, paid_nValue, remaining_nValue, inputs, CCchange=0; + struct CCcontract_info *cpTokens, tokensC; + struct CCcontract_info *cpAssets, assetsC; + + if (fillunits < 0) { CCerror = strprintf("negative fillunits %lld\n",(long long)fillunits); fprintf(stderr,"%s\n",CCerror.c_str()); return(""); } - if ( assetid2 != zeroid ) + if (assetid2 != zeroid) { CCerror = "asset swaps disabled"; fprintf(stderr,"%s\n",CCerror.c_str()); return(""); } - cp = CCinit(&C,EVAL_ASSETS); - if ( txfee == 0 ) + cpTokens = CCinit(&tokensC, EVAL_TOKENS); + cpAssets = CCinit(&assetsC, EVAL_ASSETS); + + if (txfee == 0) txfee = 10000; + mypk = pubkey2pk(Mypubkey()); - if ( AddNormalinputs(mtx,mypk,txfee,3) > 0 ) + if (AddNormalinputs(mtx,mypk,txfee,3) > 0) { mask = ~((1LL << mtx.vin.size()) - 1); - if ( GetTransaction(asktxid,vintx,hashBlock,false) != 0 ) + if (GetTransaction(asktxid, vintx, hashBlock, false) != 0) { orig_assetoshis = vintx.vout[askvout].nValue; - SetAssetOrigpubkey(origpubkey,total_nValue,vintx); + SetAssetOrigpubkey(origpubkey, total_nValue, vintx); dprice = (double)total_nValue / orig_assetoshis; paid_nValue = dprice * fillunits; - mtx.vin.push_back(CTxIn(asktxid,askvout,CScript())); - if ( assetid2 != zeroid ) - inputs = AddAssetInputs(cp,mtx,mypk,assetid2,paid_nValue,60); + + mtx.vin.push_back(CTxIn(asktxid, askvout, CScript())); // NOTE: this is the reference to tokens -> send cpTokens for signing into FinalizeCCTx! + + if (assetid2 != zeroid) + inputs = AddAssetInputs(cpTokens, mtx, mypk, assetid2, paid_nValue, 60); else { - inputs = AddNormalinputs(mtx,mypk,paid_nValue,60); + inputs = AddNormalinputs(mtx, mypk, paid_nValue, 60); mask = ~((1LL << mtx.vin.size()) - 1); } - if ( inputs > 0 ) + if (inputs > 0) { - if ( inputs < paid_nValue ) - paid_nValue = inputs; - if ( assetid2 != zeroid ) - SetSwapFillamounts(received_assetoshis,remaining_nValue,orig_assetoshis,paid_nValue,total_nValue); - else SetAskFillamounts(received_assetoshis,remaining_nValue,orig_assetoshis,paid_nValue,total_nValue); - if ( assetid2 != zeroid && inputs > paid_nValue ) + if (inputs < paid_nValue) { + std::cerr << "FillSell(): insufficient coins to fill sell" << std::endl; + CCerror = strprintf("insufficient coins to fill sell"); + return (""); + } + + if (assetid2 != zeroid) + SetSwapFillamounts(received_assetoshis, remaining_nValue, orig_assetoshis, paid_nValue, total_nValue); + else + SetAskFillamounts(received_assetoshis, remaining_nValue, orig_assetoshis, paid_nValue, total_nValue); + + if (assetid2 != zeroid && inputs > paid_nValue) CCchange = (inputs - paid_nValue); - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,orig_assetoshis - received_assetoshis,GetUnspendable(cp,0))); - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,received_assetoshis,mypk)); - if ( assetid2 != zeroid ) - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,paid_nValue,origpubkey)); - else mtx.vout.push_back(CTxOut(paid_nValue,CScript() << origpubkey << OP_CHECKSIG)); - if ( CCchange != 0 ) - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk)); - return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,EncodeAssetOpRet(assetid2!=zeroid?'E':'S',assetid,assetid2,remaining_nValue,origpubkey))); + + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, orig_assetoshis - received_assetoshis, GetUnspendable(cpAssets, NULL))); // coins + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, received_assetoshis, mypk)); // tokens + + if (assetid2 != zeroid) + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, paid_nValue, origpubkey)); // tokens (not implemented correctly) + else + mtx.vout.push_back(CTxOut(paid_nValue, CScript() << origpubkey << OP_CHECKSIG)); // coins + + if (CCchange != 0) + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, CCchange, mypk)); // coins + + return(FinalizeCCTx(mask,cpTokens,mtx,mypk,txfee,EncodeAssetOpRet(assetid2 != zeroid ? 'E' : 'S', assetid, assetid2, remaining_nValue, origpubkey))); } else { CCerror = strprintf("filltx not enough utxos"); fprintf(stderr,"%s\n", CCerror.c_str()); diff --git a/src/cc/CCcustom.cpp b/src/cc/CCcustom.cpp index 7fdd1b920..918ceb24a 100644 --- a/src/cc/CCcustom.cpp +++ b/src/cc/CCcustom.cpp @@ -30,6 +30,7 @@ #include "CCMarmara.h" #include "CCPayments.h" #include "CCGateways.h" +#include "CCtokens.h" /* CCcustom has most of the functions that need to be extended to create a new CC contract. @@ -222,6 +223,18 @@ uint8_t GatewaysCCpriv[32] = { 0xf7, 0x4b, 0x5b, 0xa2, 0x7a, 0x5e, 0x9c, 0xda, 0 #undef FUNCNAME #undef EVALCODE +// Tokens +#define FUNCNAME IsTokensInput +#define EVALCODE EVAL_TOKENS +const char *TokensCCaddr = "RAMvUfoyURBRxAdVeTMHxn3giJZCFWeha2"; +const char *TokensNormaladdr = "RCNgAngYAdrfzujYyPgfbjCGNVQZzCgTad"; +char TokensCChexstr[67] = { "03e6191c70c9c9a28f9fd87089b9488d0e6c02fb629df64979c9cdb6b2b4a68d95" }; +uint8_t TokensCCpriv[32] = { 0x1d, 0x0d, 0x0d, 0xce, 0x2d, 0xd2, 0xe1, 0x9d, 0xf5, 0xb6, 0x26, 0xd5, 0xad, 0xa0, 0xf0, 0x0a, 0xdd, 0x7a, 0x72, 0x7d, 0x17, 0x35, 0xb5, 0xe3, 0x2c, 0x6c, 0xa9, 0xa2, 0x03, 0x16, 0x4b, 0xcf }; +#include "CCcustom.inc" +#undef FUNCNAME +#undef EVALCODE + + struct CCcontract_info *CCinit(struct CCcontract_info *cp, uint8_t evalcode) { cp->evalcode = evalcode; @@ -347,6 +360,15 @@ struct CCcontract_info *CCinit(struct CCcontract_info *cp, uint8_t evalcode) cp->validate = GatewaysValidate; cp->ismyvin = IsGatewaysInput; break; + + case EVAL_TOKENS: + strcpy(cp->unspendableCCaddr, TokensCCaddr); + strcpy(cp->normaladdr, TokensNormaladdr); + strcpy(cp->CChexstr, TokensCChexstr); + memcpy(cp->CCpriv, TokensCCpriv, 32); + cp->validate = TokensValidate; + cp->ismyvin = IsTokensInput; + break; } return(cp); } diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 40028ee5c..56c4b27d5 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -133,13 +133,22 @@ int64_t OraclePrice(int32_t height,uint256 reforacletxid,char *markeraddr,char * uint8_t DecodeOraclesCreateOpRet(const CScript &scriptPubKey,std::string &name,std::string &description,std::string &format); uint256 OracleMerkle(int32_t height,uint256 reforacletxid,char *format,std::vectorpublishers); uint256 OraclesBatontxid(uint256 oracletxid,CPubKey pk); -int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs); + +//int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs); +int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs); + bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx); -bool DecodeAssetCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description); -uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey); +CScript EncodeAssetOpRet(uint8_t assetFuncId, uint256 tokenid, uint256 assetid2, int64_t price, std::vector origpubkey); +bool DecodeAssetCreateOpRet(const CScript &scriptPubKey, std::vector &origpubkey, std::string &name, std::string &description); +uint8_t DecodeAssetOpRet(const CScript &scriptPubKey, uint8_t &evalCodeInOpret, uint256 &tokenid, uint256 &assetid2, int64_t &price, std::vector &origpubkey); +uint8_t DecodeTokenCreateOpRet(const CScript &scriptPubKey, std::vector &origpubkey, std::string &name, std::string &description); +uint8_t DecodeTokenOpRet(const CScript scriptPubKey, uint8_t &evalCode, uint256 &tokenid, std::vector &vopretExtra); + +//uint8_t DecodeAssetOpRet(const CScript &scriptPubKey, uint8_t &evalCode, uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey); uint8_t DecodeOraclesData(const CScript &scriptPubKey,uint256 &oracletxid,uint256 &batontxid,CPubKey &pk,std::vector &data); int32_t oracle_format(uint256 *hashp,int64_t *valp,char *str,uint8_t fmt,uint8_t *data,int32_t offset,int32_t datalen); -CScript EncodeAssetOpRet(uint8_t funcid,uint256 assetid,uint256 assetid2,int64_t price,std::vector origpubkey); + + // CCcustom CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv); diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp new file mode 100644 index 000000000..c85297ddb --- /dev/null +++ b/src/cc/CCtokens.cpp @@ -0,0 +1,487 @@ +/****************************************************************************** + * Copyright © 2014-2018 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#include "CCtokens.h" + +/* TODO: correct this: +----------------------------- + The SetTokenFillamounts() and ValidateTokenRemainder() work in tandem to calculate the vouts for a fill and to validate the vouts, respectively. + + This pair of functions are critical to make sure the trading is correct and is the trickiest part of the tokens contract. + + //vin.0: normal input + //vin.1: unspendable.(vout.0 from buyoffer) buyTx.vout[0] + //vin.2+: valid CC output satisfies buyoffer (*tx.vin[2])->nValue + //vout.0: remaining amount of bid to unspendable + //vout.1: vin.1 value to signer of vin.2 + //vout.2: vin.2 tokenoshis to original pubkey + //vout.3: CC output for tokenoshis change (if any) + //vout.4: normal output for change (if any) + //vout.n-1: opreturn [EVAL_ASSETS] ['B'] [tokenid] [remaining token required] [origpubkey] + ValidateTokenRemainder(remaining_price,tx.vout[0].nValue,nValue,tx.vout[1].nValue,tx.vout[2].nValue,totalunits); + + Yes, this is quite confusing... + + In ValudateTokenRemainder the naming convention is nValue is the coin/token with the offer on the books and "units" is what it is being paid in. The high level check is to make sure we didnt lose any coins or tokens, the harder to validate is the actual price paid as the "orderbook" is in terms of the combined nValue for the combined totalunits. + + We assume that the effective unit cost in the orderbook is valid and that that amount was paid and also that any remainder will be close enough in effective unit cost to not matter. At the edge cases, this will probably be not true and maybe some orders wont be practically fillable when reduced to fractional state. However, the original pubkey that created the offer can always reclaim it. + ------------------------------ +*/ + + +// NOTE: this inital tx won't be used by other contract +// for tokens to be used there should be at least one 't' tx with other contract's custom opret +CScript EncodeTokenCreateOpRet(uint8_t funcid,std::vector origpubkey,std::string name,std::string description) +{ + CScript opret; uint8_t evalcode = EVAL_TOKENS; + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << origpubkey << name << description); + return(opret); +} + +// this is for other contracts which use tokens and build customized extra payloads to token's opret: +CScript EncodeTokenOpRet(uint8_t tokenFuncId, uint8_t evalCodeInOpret, uint256 tokenid, std::vector payload) +{ + CScript opret; + //uint8_t evalcode = EVAL_TOKENS; + tokenid = revuint256(tokenid); + //uint8_t tokenFuncId = (isTransferrable) ? (uint8_t)'t' : (uint8_t)'l'; + + opret << OP_RETURN << E_MARSHAL(ss << evalCodeInOpret << tokenFuncId << tokenid << payload); + return(opret); +} + +uint8_t DecodeTokenCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description) +{ + std::vector vopret; uint8_t dummyEvalcode, funcid, *script; + + GetOpReturnData(scriptPubKey, vopret); + script = (uint8_t *)vopret.data(); + if ( script != 0 && vopret.size() > 2 && script[0] == EVAL_TOKENS && script[1] == 'c' ) + { + if ( E_UNMARSHAL(vopret, ss >> dummyEvalcode; ss >> funcid; ss >> origpubkey; ss >> name; ss >> description) != 0 ) + return(funcid); + } + return (uint8_t)0; +} + +uint8_t DecodeTokenOpRet(const CScript scriptPubKey, uint8_t &evalCode, uint256 &tokenid, std::vector &vopretExtra) +{ + std::vector vopret, extra, dummyPubkey; + uint8_t funcid=0, *script, e, dummyFuncId; + std::string dummyName; std::string dummyDescription; + + GetOpReturnData(scriptPubKey, vopret); + script = (uint8_t *)vopret.data(); + tokenid = zeroid; + + if (script != 0 /*enable all evals: && script[0] == EVAL_TOKENS*/) + { + bool isEof = true; + evalCode = script[0]; + funcid = script[1]; + //fprintf(stderr,"decode.[%c]\n",funcid); + switch ( funcid ) + { + case 'c': + return DecodeTokenCreateOpRet(scriptPubKey, dummyPubkey, dummyName, dummyDescription); + //break; + case 't': + //not used yet: case 'l': + if (E_UNMARSHAL(vopret, ss >> e; ss >> dummyFuncId; ss >> tokenid; isEof = ss.eof(); vopretExtra = std::vector(ss.begin(), ss.end())) || !isEof) + { + tokenid = revuint256(tokenid); + return(funcid); + } + std::cerr << "DecodeTokenOpRet() isEof=" << isEof << std::endl; + fprintf(stderr, "DecodeTokenOpRet() bad opret format\n"); // this may be just check, no error logging + return (uint8_t)0; + + default: + fprintf(stderr, "DecodeTokenOpRet() illegal funcid.%02x\n", funcid); + return (uint8_t)0; + } + } + return (uint8_t)0; +} + + + +// tx validation +bool TokensValidate(struct CCcontract_info *cp, Eval* eval, const CTransaction &tx, uint32_t nIn) +{ + static uint256 zero; + CTxDestination address; CTransaction vinTx, createTx; uint256 hashBlock, tokenid, tokenid2; + int32_t i, starti, numvins, numvouts, preventCCvins, preventCCvouts; + int64_t remaining_price, nValue, tokenoshis, outputs, inputs, tmpprice, totalunits, ignore; std::vector origpubkey, tmporigpubkey, ignorepubkey; + uint8_t funcid, evalCodeInOpret; + char destaddr[64], origaddr[64], CCaddr[64]; + + numvins = tx.vin.size(); + numvouts = tx.vout.size(); + outputs = inputs = 0; + preventCCvins = preventCCvouts = -1; + + if ((funcid = DecodeTokenOpRet(tx.vout[numvouts - 1].scriptPubKey, evalCodeInOpret, tokenid, origpubkey)) == 0) + return eval->Invalid("TokenValidate: invalid opreturn payload"); + + fprintf(stderr, "TokensValidate (%c)\n", funcid); + + if (eval->GetTxUnconfirmed(tokenid, createTx, hashBlock) == 0) + return eval->Invalid("cant find token create txid"); + else if (IsCCInput(tx.vin[0].scriptSig) != 0) + return eval->Invalid("illegal token vin0"); // why? (dimxy) + else if (numvouts < 1) + return eval->Invalid("no vouts"); + else if (funcid != 'c') + { + if (tokenid == zeroid) + return eval->Invalid("illegal tokenid"); + else if (!TokensExactAmounts(true, cp, inputs, outputs, eval, tx, tokenid)) { + if (!eval->Valid()) + return false; //TokenExactAmounts must call eval->Invalid()! + else + return eval->Invalid("tokens cc inputs != cc outputs"); + } + } + + // init for forwarding validation call + struct CCcontract_info *cpOther = NULL, C; + if (evalCodeInOpret != EVAL_TOKENS) + cpOther = CCinit(&C, evalCodeInOpret); + + switch (funcid) + { + case 'c': // create wont be called to be verified as it has no CC inputs + //vin.0: normal input + //vout.0: issuance tokenoshis to CC + //vout.1: normal output for change (if any) + //vout.n-1: opreturn EVAL_TOKENS 'c' + if (evalCodeInOpret != EVAL_TOKENS) + return eval->Invalid("unexpected TokenValidate for createtoken"); + else + return true; + + case 't': // transfer + //vin.0: normal input + //vin.1 .. vin.n-1: valid CC outputs + //vout.0 to n-2: tokenoshis output to CC + //vout.n-2: normal output for change (if any) + //vout.n-1: opreturn 't' tokenid + if (inputs == 0) + return eval->Invalid("no token inputs for transfer"); + + fprintf(stderr, "token transfer preliminarily validated %.8f -> %.8f (%d %d)\n", (double)inputs / COIN, (double)outputs / COIN, preventCCvins, preventCCvouts); + break; // breaking to other contract validation... + + default: + fprintf(stderr, "illegal tokens funcid.(%c)\n", funcid); + return eval->Invalid("unexpected token funcid"); + } + + // forward validation if evalcode in opret is not EVAL_TOKENS + if (cpOther) + return cpOther->validate(cpOther, eval, tx, nIn); + else + return eval->Invalid("unsupported evalcode in opret"); + + // what does this do? + // return(PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts)); +} + + + +// this is just for log messages indentation fur debugging recursive calls: +thread_local uint32_t tokenValIndentSize = 0; + +// validates opret for token tx: +bool ValidateTokenOpret(CTransaction tx, int32_t v, uint256 tokenid, std::vector &vopretExtra) { + + uint256 tokenidOpret, tokenidOpret2; + uint8_t funcid, evalCode; + + // this is just for log messages indentation fur debugging recursive calls: + std::string indentStr = std::string().append(tokenValIndentSize, '.'); + + int32_t n = tx.vout.size(); + + if ((funcid = DecodeTokenOpRet(tx.vout[n - 1].scriptPubKey, evalCode, tokenidOpret, vopretExtra)) == 0) + { + std::cerr << indentStr << "ValidateTokenOpret() DecodeOpret returned null for n-1=" << n - 1 << " txid=" << tx.GetHash().GetHex() << std::endl; + return(false); + } + else if (funcid == 'c') + { + if (tokenid != zeroid && tokenid == tx.GetHash() && v == 0) { + //std::cerr << indentStr << "ValidateTokenOpret() this is the tokenbase 'c' tx, txid=" << tx.GetHash().GetHex() << " vout=" << v << " returning true" << std::endl; + return(true); + } + } + else if (funcid == 't') + { + //std::cerr << indentStr << "ValidateTokenOpret() tokenid=" << tokenid.GetHex() << " tokenIdOpret=" << tokenidOpret.GetHex() << " txid=" << tx.GetHash().GetHex() << std::endl; + if (tokenid != zeroid && tokenid == tokenidOpret) { + //std::cerr << indentStr << "ValidateTokenOpret() this is a transfer 't' tx, txid=" << tx.GetHash().GetHex() << " vout=" << v << " returning true" << std::endl; + return(true); + } + } + //std::cerr << indentStr << "ValidateTokenOpret() return false funcid=" << (char)funcid << " tokenid=" << tokenid.GetHex() << " tokenIdOpret=" << tokenidOpret.GetHex() << " txid=" << tx.GetHash().GetHex() << std::endl; + return false; +} + + +// Checks if the vout is a really Tokens CC vout +// compareTotals == true, the func also validates the passed transaction itself: +// it should be either sum(cc vins) == sum(cc vouts) or the transaction is the 'tokenbase' ('c') tx +int64_t IsTokensvout(bool compareTotals, struct CCcontract_info *cp, Eval* eval, std::vector &vopretExtra, const CTransaction& tx, int32_t v, uint256 reftokenid) +{ + + // this is just for log messages indentation fur debugging recursive calls: + std::string indentStr = std::string().append(tokenValIndentSize, '.'); + //std::cerr << indentStr << "IsTokensvout() entered for txid=" << tx.GetHash().GetHex() << " v=" << v << " for tokenid=" << reftokenid.GetHex() << std::endl; + + //TODO: validate cc vouts are EVAL_TOKENS! + if (tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0) // maybe check address too? dimxy: possibly no, because there are too many cases with different addresses here + { + int32_t n = tx.vout.size(); + // just check boundaries: + if (v >= n - 1) { // just moved this up (dimxy) + std::cerr << indentStr << "isTokensvout() internal err: (v >= n - 1), returning 0" << std::endl; + return(0); + } + + if (compareTotals) { + //std::cerr << indentStr << "IsTokensvout() maxTokenExactAmountDepth=" << maxTokenExactAmountDepth << std::endl; + //validate all tx + int64_t myCCVinsAmount = 0, myCCVoutsAmount = 0; + + tokenValIndentSize++; + // false --> because we already at the 1-st level ancestor tx and do not need to dereference ancestors of next levels + bool isEqual = TokensExactAmounts(false, cp, myCCVinsAmount, myCCVoutsAmount, eval, tx, reftokenid); + tokenValIndentSize--; + + if (!isEqual) { + // if ccInputs != ccOutputs and it is not the tokenbase tx + // this means it is possibly a fake tx (dimxy): + if (reftokenid != tx.GetHash()) { // checking that this is the true tokenbase tx, by verifying that funcid=c, is done further in this function (dimxy) + std::cerr << indentStr << "IsTokensvout() warning: for the verified tx detected a bad vintx=" << tx.GetHash().GetHex() << ": cc inputs != cc outputs and not the 'tokenbase' tx, skipping the verified tx" << std::endl; + return 0; + } + } + } + + // moved opret checking to this new reusable func (dimxy): + const bool valOpret = ValidateTokenOpret(tx, v, reftokenid, vopretExtra); + //std::cerr << indentStr << "IsTokensvout() ValidateTokenOpret returned=" << std::boolalpha << valOpret << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; + if (valOpret) { + //std::cerr << indentStr << "IsTokensvout() ValidateTokenOpret returned true, returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; + return tx.vout[v].nValue; + } + + //std::cerr << indentStr; fprintf(stderr,"IsTokensvout() CC vout v.%d of n=%d amount=%.8f txid=%s\n",v,n,(double)0/COIN, tx.GetHash().GetHex().c_str()); + } + //std::cerr << indentStr; fprintf(stderr,"IsTokensvout() normal output v.%d %.8f\n",v,(double)tx.vout[v].nValue/COIN); + return(0); +} + +// compares cc inputs vs cc outputs (to prevent feeding vouts from normal inputs) +bool TokensExactAmounts(bool compareTotals, struct CCcontract_info *cpTokens, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 tokenid) +{ + CTransaction vinTx; uint256 hashBlock, id, id2; int32_t flag; int64_t tokenoshis; std::vector tmporigpubkey; int64_t tmpprice; + int32_t numvins = tx.vin.size(); + int32_t numvouts = tx.vout.size(); + inputs = outputs = 0; + + // this is just for log messages indentation for debugging recursive calls: + std::string indentStr = std::string().append(tokenValIndentSize, '.'); + + for (int32_t i = 0; iismyvin)(tx.vin[i].scriptSig) /*|| IsVinAllowed(tx.vin[i].scriptSig) != 0*/) + { + //std::cerr << indentStr << "TokensExactAmounts() eval is true=" << (eval != NULL) << " ismyvin=ok for_i=" << i << std::endl; + // we are not inside the validation code -- dimxy + if ((eval && eval->GetTxUnconfirmed(tx.vin[i].prevout.hash, vinTx, hashBlock) == 0) || (!eval && !myGetTransaction(tx.vin[i].prevout.hash, vinTx, hashBlock))) + { + std::cerr << indentStr << "TokensExactAmounts() cannot read vintx for i." << i << " numvins." << numvins << std::endl; + return (!eval) ? false : eval->Invalid("always should find vin tx, but didnt"); + + } + else { + tokenValIndentSize++; + // validate vouts of vintx + //std::cerr << indentStr << "TokenExactAmounts() check vin i=" << i << " nValue=" << vinTx.vout[tx.vin[i].prevout.n].nValue << std::endl; + tokenoshis = IsTokensvout(compareTotals, cpTokens, eval, tmporigpubkey, vinTx, tx.vin[i].prevout.n, tokenid); + tokenValIndentSize--; + if (tokenoshis != 0) + { + std::cerr << indentStr << "TokensExactAmounts() vin i=" << i << " tokenoshis=" << tokenoshis << std::endl; + inputs += tokenoshis; + } + } + } + } + + + for (int32_t i = 0; iInvalid() here! + } + else + return true; +} + +// add inputs from token cc addr +int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs) +{ + char coinaddr[64], destaddr[64]; + int64_t threshold, nValue, price, totalinputs = 0; + uint256 txid, hashBlock; + std::vector vopretExtra; + CTransaction vintx; + int32_t j, vout, n = 0; + std::vector > unspentOutputs; + + GetCCaddress(cp, coinaddr, pk); + SetCCunspents(unspentOutputs, coinaddr); + + threshold = total / (maxinputs != 0 ? maxinputs : 64); // TODO: is maxinputs really could not be over 64? what if i want to calc total balance? + + for (std::vector >::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; + for (j = 0; junspendableCCaddr) != 0 && strcmp(destaddr, cp->unspendableaddr2) != 0) + continue; + fprintf(stderr, "AddTokenCCInputs() check destaddress=%s vout amount=%.8f\n", destaddr, (double)vintx.vout[vout].nValue / COIN); + if ((nValue = IsTokensvout(true, cp, NULL, vopretExtra, vintx, vout, tokenid)) > 0 && myIsutxo_spentinmempool(txid, vout) == 0) + { + if (total != 0 && maxinputs != 0) + mtx.vin.push_back(CTxIn(txid, vout, CScript())); + nValue = it->second.satoshis; + totalinputs += nValue; + //std::cerr << "AddTokenInputs() adding input nValue=" << nValue << std::endl; + n++; + if ((total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs)) + break; + } + } + } + + //std::cerr << "AddTokenInputs() found totalinputs=" << totalinputs << std::endl; + return(totalinputs); +} + + +std::string CreateToken(int64_t txfee, int64_t assetsupply, std::string name, std::string description) +{ + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + CPubKey mypk; struct CCcontract_info *cp, C; + if (assetsupply < 0) + { + fprintf(stderr, "negative assetsupply %lld\n", (long long)assetsupply); + return(""); + } + + cp = CCinit(&C, EVAL_TOKENS); + if (name.size() > 32 || description.size() > 4096) + { + fprintf(stderr, "name.%d or description.%d is too big\n", (int32_t)name.size(), (int32_t)description.size()); + return(""); + } + if (txfee == 0) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + + if (AddNormalinputs(mtx, mypk, assetsupply + 2 * txfee, 64) > 0) + { + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, assetsupply, mypk)); + mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(cp->CChexstr) << OP_CHECKSIG)); + return(FinalizeCCTx(0, cp, mtx, mypk, txfee, EncodeTokenCreateOpRet('c', Mypubkey(), name, description))); + } + return(""); +} + + +std::string TokenTransfer(int64_t txfee, uint256 assetid, std::vector destpubkey, int64_t total) +{ + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + CPubKey mypk; uint64_t mask; int64_t CCchange = 0, inputs = 0; struct CCcontract_info *cp, C; + std::vector emptyExtraOpret; + + if (total < 0) + { + fprintf(stderr, "negative total %lld\n", (long long)total); + return(""); + } + cp = CCinit(&C, EVAL_TOKENS); + if (txfee == 0) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + if (AddNormalinputs(mtx, mypk, txfee, 3) > 0) + { + //n = outputs.size(); + //if ( n == amounts.size() ) + //{ + // for (i=0; i 0) + { + + if (inputs < total) { //added dimxy + std::cerr << "AssetTransfer(): insufficient funds" << std::endl; + return (""); + } + if (inputs > total) + CCchange = (inputs - total); + //for (i=0; i &origpubkey, const CTransaction& tx, int32_t v, uint256 reftokenid); +std::string CreateToken(int64_t txfee, int64_t assetsupply, std::string name, std::string description); +std::string TokenTransfer(int64_t txfee, uint256 assetid, std::vector destpubkey, int64_t total); + +//this is in CCinclude.h int64_t AddTokenInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs); + +//this is in CCinclude.h uint8_t DecodeTokenCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description); + +/* +// CCassetsCore +CScript EncodeAssetCreateOpRet(uint8_t funcid,std::vector origpubkey,std::string name,std::string description); +CScript EncodeAssetOpRet(uint8_t funcid,uint256 assetid,uint256 assetid2,int64_t price,std::vector origpubkey); +bool DecodeAssetCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description); +//uint8_t DecodeAssetOpRet(const CScript &scriptPubKey, uint8_t &evalCode, uint256 &assetid, uint256 &assetid2, int64_t &price, std::vector &origpubkey); +bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CTransaction &tx); +int64_t IsAssetvout(bool compareTotals, struct CCcontract_info *cp, Eval* eval, int64_t &price, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 refassetid); +bool ValidateBidRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); +bool ValidateAskRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); +bool ValidateSwapRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); +bool SetBidFillamounts(int64_t &paid,int64_t &remaining_price,int64_t orig_nValue,int64_t &received,int64_t totalprice); +bool SetAskFillamounts(int64_t &paid,int64_t &remaining_price,int64_t orig_nValue,int64_t &received,int64_t totalprice); +bool SetSwapFillamounts(int64_t &paid,int64_t &remaining_price,int64_t orig_nValue,int64_t &received,int64_t totalprice); +int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 refassetid); +int64_t AssetValidateSellvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 assetid); +bool AssetExactAmounts(bool compareTotals, struct CCcontract_info *cpAssets, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 assetid); + +// CCassetstx +int64_t GetAssetBalance(CPubKey pk,uint256 tokenid); +int64_t AddAssetInputs(CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs); +UniValue AssetOrders(uint256 tokenid); +UniValue AssetInfo(uint256 tokenid); +UniValue AssetList(); +std::string CreateAsset(int64_t txfee,int64_t assetsupply,std::string name,std::string description); +std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total); +std::string AssetConvert(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total,int32_t evalcode); + +std::string CreateBuyOffer(int64_t txfee,int64_t bidamount,uint256 assetid,int64_t pricetotal); +std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid); +std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t fillamount); +std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t pricetotal); +std::string CreateSwap(int64_t txfee,int64_t askamount,uint256 assetid,uint256 assetid2,int64_t pricetotal); +std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid); +std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 asktxid,int64_t fillamount); +*/ + +#endif diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index a80b3b3cf..57a2a327b 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -144,9 +144,9 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { //fprintf(stderr,"matched %s unspendable2!\n",cp->unspendableaddr2); privkey = cp->unspendablepriv2; - if ( othercond2 == 0 && cp->evalcode != EVAL_CHANNELS && cp->evalcode != EVAL_HEIR ) + if ( othercond2 == 0 && cp->evalcode != EVAL_CHANNELS && cp->evalcode != EVAL_HEIR && cp->evalcode != EVAL_ASSETS && cp->evalcode != EVAL_TOKENS) othercond2 = MakeCCcond1(cp->evalcode2,cp->unspendablepk2); - else if ( othercond2 == 0 && (cp->evalcode == EVAL_CHANNELS || cp->evalcode == EVAL_HEIR) ) + else if ( othercond2 == 0 && (cp->evalcode == EVAL_CHANNELS || cp->evalcode == EVAL_HEIR || cp->evalcode == EVAL_ASSETS || cp->evalcode == EVAL_TOKENS) ) othercond2 = MakeCCcond1of2(cp->evalcode2,cp->unspendablepk2,cp->unspendablepk3); cond = othercond2; } @@ -297,7 +297,7 @@ int64_t CCfullsupply(uint256 tokenid) uint256 hashBlock; int32_t numvouts; CTransaction tx; std::vector origpubkey; std::string name,description; if ( GetTransaction(tokenid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) { - if ( DecodeAssetCreateOpRet(tx.vout[numvouts-1].scriptPubKey,origpubkey,name,description) > 0 ) + if (DecodeTokenCreateOpRet(tx.vout[numvouts-1].scriptPubKey,origpubkey,name,description)) { return(tx.vout[0].nValue); } @@ -307,8 +307,11 @@ int64_t CCfullsupply(uint256 tokenid) int64_t CCtoken_balance(char *coinaddr,uint256 tokenid) { - int64_t price,sum = 0; int32_t numvouts; CTransaction tx; uint256 assetid,assetid2,txid,hashBlock; std::vector origpubkey; + int64_t price,sum = 0; int32_t numvouts; CTransaction tx; uint256 assetid,assetid2,txid,hashBlock; + std::vector vopretExtra; std::vector > unspentOutputs; + uint8_t evalCode; + SetCCunspents(unspentOutputs,coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { @@ -316,7 +319,7 @@ int64_t CCtoken_balance(char *coinaddr,uint256 tokenid) if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) { char str[65]; fprintf(stderr,"check %s %.8f\n",uint256_str(str,txid),(double)it->second.satoshis/COIN); - if ( DecodeAssetOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,assetid2,price,origpubkey) != 0 && assetid == tokenid ) + if ( DecodeTokenOpRet(tx.vout[numvouts-1].scriptPubKey, evalCode, assetid, vopretExtra) != 0 && assetid == tokenid ) { sum += it->second.satoshis; } diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index a1fa39192..47b9488c8 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -133,45 +133,63 @@ // tx validation -bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransaction &tx, uint32_t nIn) { static uint256 zero; - CTxDestination address; CTransaction vinTx,createTx; uint256 hashBlock,assetid,assetid2; int32_t i,starti,numvins,numvouts,preventCCvins,preventCCvouts; int64_t remaining_price,nValue,assetoshis,outputs,inputs,tmpprice,totalunits,ignore; std::vector origpubkey,tmporigpubkey,ignorepubkey; uint8_t funcid; char destaddr[64],origaddr[64],CCaddr[64]; + CTxDestination address; CTransaction vinTx,createTx; uint256 hashBlock,assetid,assetid2; + int32_t i,starti,numvins,numvouts,preventCCvins,preventCCvouts; + int64_t remaining_price,nValue,assetoshis,outputs,inputs,tmpprice,totalunits,ignore; std::vector origpubkey,tmporigpubkey,ignorepubkey; + uint8_t funcid, evalCodeInOpret; + char destaddr[64],origaddr[64],CCaddr[64]; + + // we need this for validating tokens' vins/vous: + struct CCcontract_info *cpTokens, tokensC; + cpTokens = CCinit(&tokensC, EVAL_TOKENS); + numvins = tx.vin.size(); numvouts = tx.vout.size(); outputs = inputs = 0; preventCCvins = preventCCvouts = -1; - if ( (funcid= DecodeAssetOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,assetid2,remaining_price,origpubkey)) == 0 ) - return eval->Invalid("Invalid opreturn payload"); + + if((funcid = DecodeAssetOpRet(tx.vout[numvouts-1].scriptPubKey, evalCodeInOpret, assetid, assetid2, remaining_price, origpubkey)) == 0 ) + return eval->Invalid("AssetValidate: invalid opreturn payload"); + fprintf(stderr,"AssetValidate (%c)\n",funcid); - if ( funcid != 'o' && funcid != 'x' && eval->GetTxUnconfirmed(assetid,createTx,hashBlock) == 0 ) + + if( funcid != 'o' && funcid != 'x' && eval->GetTxUnconfirmed(assetid, createTx, hashBlock) == 0 ) return eval->Invalid("cant find asset create txid"); - else if ( funcid != 'o' && funcid != 'x' && assetid2 != zero && eval->GetTxUnconfirmed(assetid2,createTx,hashBlock) == 0 ) + else if( funcid != 'o' && funcid != 'x' && assetid2 != zero && eval->GetTxUnconfirmed(assetid2, createTx, hashBlock) == 0 ) return eval->Invalid("cant find asset2 create txid"); - else if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) + else if( IsCCInput(tx.vin[0].scriptSig) != 0 ) return eval->Invalid("illegal asset vin0"); - else if ( numvouts < 1 ) + else if( numvouts < 1 ) return eval->Invalid("no vouts"); - else if ( funcid != 'c' ) + else if( funcid != 'c' ) { - if ( funcid == 't' ) + /* if( funcid == 't' ) starti = 0; - else starti = 1; - if ( assetid == zero ) + else + starti = 1; */ + + if( assetid == zero ) return eval->Invalid("illegal assetid"); - else if ( AssetExactAmounts(2, cp,inputs,starti,outputs,eval,tx,assetid) == false ) - return eval->Invalid("asset inputs != outputs"); + + else if (!AssetExactAmounts(cpAssets, inputs, outputs, eval, tx, assetid)) { // Only set inputs and outputs. NOTE: we do not need to check cc inputs == cc outputs + return false; // returns false if some problems with reading vintxes + } } - - switch ( funcid ) + switch( funcid ) { case 'c': // create wont be called to be verified as it has no CC inputs //vin.0: normal input //vout.0: issuance assetoshis to CC //vout.1: normal output for change (if any) //vout.n-1: opreturn [EVAL_ASSETS] ['c'] [{"":""}] - return eval->Invalid("unexpected AssetValidate for createasset"); + //if (evalCodeInOpret == EVAL_ASSETS) + // return eval->Invalid("unexpected AssetValidate for createasset"); + // return + return eval->Invalid("invalid asset funcid \'c\'"); break; case 't': // transfer //vin.0: normal input @@ -179,9 +197,10 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx //vout.0 to n-2: assetoshis output to CC //vout.n-2: normal output for change (if any) //vout.n-1: opreturn [EVAL_ASSETS] ['t'] [assetid] - if ( inputs == 0 ) - return eval->Invalid("no asset inputs for transfer"); - fprintf(stderr,"transfer validated %.8f -> %.8f (%d %d)\n",(double)inputs/COIN,(double)outputs/COIN,preventCCvins,preventCCvouts); + //if (inputs == 0) + // return eval->Invalid("no asset inputs for transfer"); + //fprintf(stderr,"transfer preliminarily validated %.8f -> %.8f (%d %d)\n",(double)inputs/COIN,(double)outputs/COIN,preventCCvins,preventCCvouts); + return eval->Invalid("invalid asset funcid \'t\'"); break; case 'b': // buyoffer @@ -189,13 +208,13 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx //vout.0: amount of bid to unspendable //vout.1: normal output for change (if any) // vout.n-1: opreturn [EVAL_ASSETS] ['b'] [assetid] [amount of asset required] [origpubkey] - if ( remaining_price == 0 ) + if( remaining_price == 0 ) return eval->Invalid("illegal null amount for buyoffer"); - else if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) + else if( ConstrainVout(tx.vout[0],1,cpAssets->unspendableCCaddr,0) == 0 ) return eval->Invalid("invalid vout for buyoffer"); preventCCvins = 1; preventCCvouts = 1; - fprintf(stderr,"buy offer validated to destaddr.(%s)\n",cp->unspendableCCaddr); + fprintf(stderr,"buy offer validated to destaddr.(%s)\n",cpAssets->unspendableCCaddr); break; case 'o': // cancelbuy @@ -204,9 +223,9 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx //vout.0: vin.1 value to original pubkey buyTx.vout[0].nValue -> [origpubkey] //vout.1: normal output for change (if any) //vout.n-1: opreturn [EVAL_ASSETS] ['o'] - if ( (nValue= AssetValidateBuyvin(cp,eval,tmpprice,tmporigpubkey,CCaddr,origaddr,tx,assetid)) == 0 ) + if( (nValue= AssetValidateBuyvin(cpAssets, eval, tmpprice, tmporigpubkey, CCaddr, origaddr, tx, assetid)) == 0 ) return(false); - else if ( ConstrainVout(tx.vout[0],0,origaddr,nValue) == 0 ) + else if( ConstrainVout(tx.vout[0],0, origaddr, nValue) == 0 ) return eval->Invalid("invalid refund for cancelbuy"); preventCCvins = 2; preventCCvouts = 0; @@ -224,32 +243,32 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx //vout.4: normal output for change (if any) //vout.n-1: opreturn [EVAL_ASSETS] ['B'] [assetid] [remaining asset required] [origpubkey] preventCCvouts = 4; - if ( (nValue= AssetValidateBuyvin(cp,eval,totalunits,tmporigpubkey,CCaddr,origaddr,tx,assetid)) == 0 ) + if( (nValue = AssetValidateBuyvin(cpAssets, eval, totalunits, tmporigpubkey, CCaddr, origaddr, tx, assetid)) == 0 ) return(false); - else if ( numvouts < 3 ) + else if( numvouts < 3 ) return eval->Invalid("not enough vouts for fillbuy"); - else if ( tmporigpubkey != origpubkey ) + else if( tmporigpubkey != origpubkey ) return eval->Invalid("mismatched origpubkeys for fillbuy"); else { - if ( nValue != tx.vout[0].nValue+tx.vout[1].nValue ) + if( nValue != tx.vout[0].nValue + tx.vout[1].nValue ) return eval->Invalid("locked value doesnt match vout0+1 fillbuy"); - else if ( tx.vout[3].scriptPubKey.IsPayToCryptoCondition() != 0 ) + else if( tx.vout[3].scriptPubKey.IsPayToCryptoCondition() != 0 ) { - if ( ConstrainVout(tx.vout[2],1,CCaddr,0) == 0 ) + if( ConstrainVout(tx.vout[2], 1, CCaddr, 0) == 0 ) return eval->Invalid("vout2 doesnt go to origpubkey fillbuy"); - else if ( inputs != tx.vout[2].nValue+tx.vout[3].nValue ) + else if ( inputs != tx.vout[2].nValue + tx.vout[3].nValue ) return eval->Invalid("asset inputs doesnt match vout2+3 fillbuy"); } - else if ( ConstrainVout(tx.vout[2],1,CCaddr,inputs) == 0 ) + else if( ConstrainVout(tx.vout[2], 1, CCaddr, inputs) == 0 ) return eval->Invalid("vout2 doesnt match inputs fillbuy"); - else if ( ConstrainVout(tx.vout[1],0,0,0) == 0 ) + else if( ConstrainVout(tx.vout[1],0,0,0) == 0 ) return eval->Invalid("vout1 is CC for fillbuy"); - else if ( ValidateBidRemainder(remaining_price,tx.vout[0].nValue,nValue,tx.vout[1].nValue,tx.vout[2].nValue,totalunits) == false ) + else if( ValidateBidRemainder(remaining_price, tx.vout[0].nValue, nValue, tx.vout[1].nValue, tx.vout[2].nValue, totalunits) == false ) return eval->Invalid("mismatched remainder for fillbuy"); - else if ( remaining_price != 0 ) + else if( remaining_price != 0 ) { - if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) + if( ConstrainVout(tx.vout[0], 1, cpAssets->unspendableCCaddr, 0) == 0 ) return eval->Invalid("mismatched vout0 AssetsCCaddr for fillbuy"); } } @@ -266,16 +285,17 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx //'s'.vout.n-1: opreturn [EVAL_ASSETS] ['s'] [assetid] [amount of native coin required] [origpubkey] //'e'.vout.n-1: opreturn [EVAL_ASSETS] ['e'] [assetid] [assetid2] [amount of asset2 required] [origpubkey] preventCCvouts = 1; - if ( remaining_price == 0 ) + if( remaining_price == 0 ) return eval->Invalid("illegal null remaining_price for selloffer"); - if ( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() != 0 ) + if( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() != 0 ) { preventCCvouts++; - if ( ConstrainVout(tx.vout[0],1,(char *)cp->unspendableCCaddr,0) == 0 ) + if( ConstrainVout(tx.vout[0], 1, (char *)cpAssets->unspendableCCaddr, 0) == 0 ) return eval->Invalid("mismatched vout0 AssetsCCaddr for selloffer"); - else if ( tx.vout[0].nValue+tx.vout[1].nValue != inputs ) + else if( tx.vout[0].nValue + tx.vout[1].nValue != inputs ) return eval->Invalid("mismatched vout0+vout1 total for selloffer"); - } else if ( ConstrainVout(tx.vout[0],1,(char *)cp->unspendableCCaddr,inputs) == 0 ) + } + else if( ConstrainVout(tx.vout[0], 1, (char *)cpAssets->unspendableCCaddr, inputs) == 0 ) return eval->Invalid("mismatched vout0 AssetsCCaddr for selloffer"); //fprintf(stderr,"remaining.%d for sell\n",(int32_t)remaining_price); break; @@ -286,9 +306,9 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx //vout.0: vin.1 assetoshis to original pubkey CC sellTx/exchangeTx.vout[0].nValue -> [origpubkey] //vout.1: normal output for change (if any) //vout.n-1: opreturn [EVAL_ASSETS] ['x'] [assetid] - if ( (assetoshis= AssetValidateSellvin(cp,eval,tmpprice,tmporigpubkey,CCaddr,origaddr,tx,assetid)) == 0 ) + if( (assetoshis= AssetValidateSellvin(cpAssets, eval, tmpprice, tmporigpubkey, CCaddr, origaddr, tx, assetid)) == 0 ) return(false); - else if ( ConstrainVout(tx.vout[0],1,CCaddr,assetoshis) == 0 ) + else if( ConstrainVout(tx.vout[0], 1, CCaddr, assetoshis) == 0 ) return eval->Invalid("invalid vout for cancel"); preventCCvins = 2; preventCCvouts = 1; @@ -303,25 +323,25 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx //'S'.vout.2: vin.2 value to original pubkey [origpubkey] //vout.3: normal output for change (if any) //'S'.vout.n-1: opreturn [EVAL_ASSETS] ['S'] [assetid] [amount of coin still required] [origpubkey] - if ( (assetoshis= AssetValidateSellvin(cp,eval,totalunits,tmporigpubkey,CCaddr,origaddr,tx,assetid)) == 0 ) + if( (assetoshis = AssetValidateSellvin(cpTokens, eval, totalunits, tmporigpubkey, CCaddr, origaddr, tx, assetid)) == 0 ) return(false); - else if ( numvouts < 3 ) + else if( numvouts < 3 ) return eval->Invalid("not enough vouts for fillask"); - else if ( tmporigpubkey != origpubkey ) + else if( tmporigpubkey != origpubkey ) return eval->Invalid("mismatched origpubkeys for fillask"); else { - if ( assetoshis != tx.vout[0].nValue+tx.vout[1].nValue ) + if( assetoshis != tx.vout[0].nValue + tx.vout[1].nValue ) return eval->Invalid("locked value doesnt match vout0+1 fillask"); - if ( ValidateAskRemainder(remaining_price,tx.vout[0].nValue,assetoshis,tx.vout[1].nValue,tx.vout[2].nValue,totalunits) == false ) + if( ValidateAskRemainder(remaining_price, tx.vout[0].nValue, assetoshis, tx.vout[1].nValue, tx.vout[2].nValue, totalunits) == false ) return eval->Invalid("mismatched remainder for fillask"); - else if ( ConstrainVout(tx.vout[1],1,0,0) == 0 ) + else if( ConstrainVout(tx.vout[1], 1, 0, 0) == 0 ) return eval->Invalid("normal vout1 for fillask"); - else if ( ConstrainVout(tx.vout[2],0,origaddr,0) == 0 ) + else if( ConstrainVout(tx.vout[2], 0, origaddr, 0) == 0 ) return eval->Invalid("normal vout1 for fillask"); - else if ( remaining_price != 0 ) + else if( remaining_price != 0 ) { - if ( ConstrainVout(tx.vout[0],1,(char *)cp->unspendableCCaddr,0) == 0 ) + if ( ConstrainVout(tx.vout[0], 1, (char *)cpAssets->unspendableCCaddr,0) == 0 ) return eval->Invalid("mismatched vout0 AssetsCCaddr for fill"); } } @@ -339,51 +359,58 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx //vout.3: CC output for asset2 change (if any) //vout.3/4: normal output for change (if any) //vout.n-1: opreturn [EVAL_ASSETS] ['E'] [assetid vin0+1] [assetid vin2] [remaining asset2 required] [origpubkey] - if ( AssetExactAmounts(1, cp,inputs,1,outputs,eval,tx,assetid2) == false ) - eval->Invalid("asset2 inputs != outputs"); - if ( (assetoshis= AssetValidateSellvin(cp,eval,totalunits,tmporigpubkey,CCaddr,origaddr,tx,assetid)) == 0 ) + + //if ( AssetExactAmounts(false, cp,inputs,outputs,eval,tx,assetid2) == false ) + // eval->Invalid("asset2 inputs != outputs"); + + if( (assetoshis= AssetValidateSellvin(cpAssets, eval, totalunits, tmporigpubkey, CCaddr, origaddr, tx, assetid)) == 0 ) return(false); - else if ( numvouts < 3 ) + else if( numvouts < 3 ) return eval->Invalid("not enough vouts for fillex"); - else if ( tmporigpubkey != origpubkey ) + else if( tmporigpubkey != origpubkey ) return eval->Invalid("mismatched origpubkeys for fillex"); else { - if ( assetoshis != tx.vout[0].nValue+tx.vout[1].nValue ) + if( assetoshis != tx.vout[0].nValue + tx.vout[1].nValue ) return eval->Invalid("locked value doesnt match vout0+1 fillex"); - else if ( tx.vout[3].scriptPubKey.IsPayToCryptoCondition() != 0 ) + else if( tx.vout[3].scriptPubKey.IsPayToCryptoCondition() != 0 ) { - if ( ConstrainVout(tx.vout[2],1,CCaddr,0) == 0 ) + if( ConstrainVout(tx.vout[2], 1, CCaddr, 0) == 0 ) return eval->Invalid("vout2 doesnt go to origpubkey fillex"); - else if ( inputs != tx.vout[2].nValue+tx.vout[3].nValue ) + else if( inputs != tx.vout[2].nValue + tx.vout[3].nValue ) { fprintf(stderr,"inputs %.8f != %.8f + %.8f\n",(double)inputs/COIN,(double)tx.vout[2].nValue/COIN,(double)tx.vout[3].nValue/COIN); return eval->Invalid("asset inputs doesnt match vout2+3 fillex"); } } - else if ( ConstrainVout(tx.vout[2],1,CCaddr,inputs) == 0 ) + else if( ConstrainVout(tx.vout[2], 1, CCaddr, inputs) == 0 ) return eval->Invalid("vout2 doesnt match inputs fillex"); - else if ( ConstrainVout(tx.vout[1],0,0,0) == 0 ) + else if( ConstrainVout(tx.vout[1], 0, 0, 0) == 0 ) return eval->Invalid("vout1 is CC for fillex"); fprintf(stderr,"assets vout0 %llu, vin1 %llu, vout2 %llu -> orig, vout1 %llu, total %llu\n",(long long)tx.vout[0].nValue,(long long)assetoshis,(long long)tx.vout[2].nValue,(long long)tx.vout[1].nValue,(long long)totalunits); - if ( ValidateSwapRemainder(remaining_price,tx.vout[0].nValue,assetoshis,tx.vout[1].nValue,tx.vout[2].nValue,totalunits) == false ) + if( ValidateSwapRemainder(remaining_price, tx.vout[0].nValue, assetoshis,tx.vout[1].nValue, tx.vout[2].nValue, totalunits) == false ) return eval->Invalid("mismatched remainder for fillex"); - else if ( ConstrainVout(tx.vout[1],1,0,0) == 0 ) + else if( ConstrainVout(tx.vout[1], 1, 0, 0) == 0 ) return eval->Invalid("normal vout1 for fillex"); - else if ( remaining_price != 0 ) + else if( remaining_price != 0 ) { - if ( ConstrainVout(tx.vout[0],1,(char *)cp->unspendableCCaddr,0) == 0 ) + if( ConstrainVout(tx.vout[0], 1, (char *)cpAssets->unspendableCCaddr, 0) == 0 ) return eval->Invalid("mismatched vout0 AssetsCCaddr for fillex"); } } fprintf(stderr,"fill validated\n"); break; + default: fprintf(stderr,"illegal assets funcid.(%c)\n",funcid); return eval->Invalid("unexpected assets funcid"); - break; + //break; } - return(PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts)); + + // what does this do? + bool bPrevent = PreventCC(eval, tx, preventCCvins, numvins, preventCCvouts, numvouts); + std::cerr << "AssetsValidate() PreventCC returned=" << bPrevent << std::endl; + return (bPrevent); } diff --git a/src/cc/eval.h b/src/cc/eval.h index 87b98349b..de1636ab8 100644 --- a/src/cc/eval.h +++ b/src/cc/eval.h @@ -55,7 +55,8 @@ EVAL(EVAL_PEGS, 0xee) \ EVAL(EVAL_MARMARA, 0xef) \ EVAL(EVAL_PAYMENTS, 0xf0) \ - EVAL(EVAL_GATEWAYS, 0xf1) + EVAL(EVAL_GATEWAYS, 0xf1) \ + EVAL(EVAL_TOKENS, 0xf2) typedef uint8_t EvalCode; diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 44f01a8a4..81318ad1e 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -14,203 +14,1315 @@ ******************************************************************************/ #include "CCHeir.h" +#include "CCassets.h" + +#include "heir_validate.h" + +class CoinHelper; +class TokenHelper; /* The idea of Heir CC is to allow crypto inheritance. A special 1of2 CC address is created that is freely spendable by the creator. The heir is only allowed to spend after the specified amount of idle blocks. The idea is that if the address doesnt spend any funds for a year (or whatever amount set), then it is time to allow the heir to spend. The design requires the heir to spend all the funds at once */ -// start of consensus code +// tx validation code -int64_t IsHeirvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +// this is for indentation of debug log messages (in recursive calls): +//extern thread_local uint32_t assetValIndentSize; + +// check if vout is cc addr and also check sum(inputs) == sum(outputs) for the passed tx, if requested +int64_t IsHeirvout(bool compareTotals, struct CCcontract_info *cpHeir, Eval* eval, uint256 tokenid, const CTransaction& tx, int32_t v) { - char destaddr[64]; - if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) - { - if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && strcmp(destaddr,cp->unspendableCCaddr) == 0 ) - return(tx.vout[v].nValue); - } - return(0); + //std::string indentStr = std::string().append(assetValIndentSize, '.'); + + //std::cerr << indentStr << "IsHeirvout() entered for txid=" << tx.GetHash().GetHex() << " v=" << v << std::boolalpha << " compareTotals=" << compareTotals << std::endl; + if (tx.vout[v].scriptPubKey.IsPayToCryptoCondition()) + { + //std::cerr << indentStr << "IsHeirvout() IsPayToCryptoCondition=true for txid=" << tx.GetHash().GetHex() << std::endl; + /*if (compareTotals) { // totally there are only 2 levels actually + + // call recursively HeirExactTokenAmounts and compare ccinputs = ccoutputs for this tx: + assetValIndentSize++; + const bool isEqual = HeirExactTokenAmounts(false, cpHeir, eval, tokenid, tx); + assetValIndentSize--; + + if (!isEqual) { // ccInputs != ccOutputs means a problem + //std::cerr << indentStr << "IsHeirvout() warning: detected suspicious tx=" << tx.GetHash().GetHex() << ": cc inputs != cc outputs, checking further if it is the tokenbase tx" << std::endl; + // if ccInputs != ccOutputs and it is not the 'tokenbase' tx means it is possibly fake tx (dimxy): + if (tokenid != zeroid && tokenid != tx.GetHash()) { + std::cerr << indentStr << "IsHeirvout() warning: detected bad tx=" << tx.GetHash().GetHex() << ": cc inputs != cc outputs and not the 'tokenbase' tx, skipping this tx" << std::endl; + return 0; + } + } + }*/ + + // TODO: add some validation here + + // lets check asset opreturn for this heir or assets tx (dimxy): + /* + int64_t dummyPrice; std::vector dummyOrigpubkey; + + const bool valOpret = ValidateAssetOpret(tx, v, tokenid, dummyPrice, dummyOrigpubkey); + //std::cerr << indentStr << "IsHeirvout() ValidateAssetOpret returned=" << std::boolalpha << valOpret << " for txid=" << tx.GetHash().GetHex() << std::endl; + if (valOpret) { + std::cerr << indentStr << "IsHeirvout() opret is true, return value=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << std::endl; + return(tx.vout[v].nValue); + }*/ + + return(tx.vout[v].nValue); + } + //std::cerr << indentStr << "IsHeirvout() return value=0" << std::endl; + return(0); } -bool HeirExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +// this function validates that tx cc outputs == cc inputs, +// that is there is no fake token supply from normal inputs (except the initial tokenbase tx) +// the cc inputs are allowed only from the Assets or Heir contracts +/*bool HeirExactTokenAmounts(bool compareTotals, struct CCcontract_info *cpHeir, Eval* eval, uint256 tokenid, const CTransaction &tx) { - static uint256 zerohash; - CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; - numvins = tx.vin.size(); - numvouts = tx.vout.size(); - for (i=0; iismyvin)(tx.vin[i].scriptSig) != 0 ) - { - //fprintf(stderr,"vini.%d check mempool\n",i); - if ( eval->GetTxUnconfirmed(tx.vin[i].prevout.hash,vinTx,hashBlock) == 0 ) - return eval->Invalid("cant find vinTx"); - else - { - //fprintf(stderr,"vini.%d check hash and vout\n",i); - if ( hashBlock == zerohash ) - return eval->Invalid("cant Heir from mempool"); - if ( (assetoshis= IsHeirvout(cp,vinTx,tx.vin[i].prevout.n)) != 0 ) - inputs += assetoshis; - } - } - } - for (i=0; iInvalid("mismatched inputs != outputs + txfee"); - } - else return(true); + static uint256 zerohash; + CTransaction vinTx; + uint256 hashBlock, activehash; + int64_t inputs = 0, outputs = 0, assetoshis; + + struct CCcontract_info *cpAssets, cAssets; + cpAssets = CCinit(&cAssets, EVAL_ASSETS); // init also tokens CC contract to check its cc addresses too + + std::string indentStr = std::string().append(assetValIndentSize, '.'); + + int32_t numvins = tx.vin.size(); + int32_t numvouts = tx.vout.size(); + for (int32_t i = 0; i < numvins; i++) + { + //std::cerr << indentStr << "HeirExactTokenAmounts() vin i=" << i << " cpHeir->ismyvin()=" << std::boolalpha << (*cpHeir->ismyvin)(tx.vin[i].scriptSig) << " cpAssets->ismyvin()=" << (*cpAssets->ismyvin)(tx.vin[i].scriptSig) << std::endl; + + // checking that vin is either from heir or assets: + if ((*cpHeir->ismyvin)(tx.vin[i].scriptSig) || (*cpAssets->ismyvin)(tx.vin[i].scriptSig)) + { + //std::cerr << indentStr; fprintf(stderr,"vini.%d check mempool\n",i); + if ((eval && !eval->GetTxUnconfirmed(tx.vin[i].prevout.hash, vinTx, hashBlock)) || !myGetTransaction(tx.vin[i].prevout.hash, vinTx, hashBlock)) { + std::cerr << indentStr << "HeirExactTokenAmounts(): can't get vintx transaction txid=" << tx.vin[i].prevout.hash.GetHex() << std::endl; + return (eval) ? eval->Invalid("cant find vinTx") : false; + } + else + { + //std::cerr << indentStr; fprintf(stderr,"vini.%d check hash and vout\n",i); + if (hashBlock == zerohash) { + std::cerr << indentStr << "HeirExactTokenAmounts(): can't get vintx from mempool, txid=" << tx.vin[i].prevout.hash.GetHex() << std::endl; + return (eval) ? eval->Invalid("cant Heir from mempool") : false; + } + + std::string dummyRefcoin; uint256 dummyBindtxid, dummyDeposittxid; CPubKey dummyDestpub; int64_t dummyAmount; + uint256 dummyAssetid2; + std::vector dummyOrigpubkey; + + // Note: if tokenid is zeroid, it may mean we are on the first level and just called from HeirValidate, validating claim 't' tx, + // then let's find the tokenid ourselves: + if (tokenid == zeroid && DecodeAssetOpRet(tx.vout[numvouts - 1].scriptPubKey, tokenid, dummyAssetid2, dummyAmount, dummyOrigpubkey) == 't') { + //std::cerr << indentStr << "HeirExactTokenAmounts() will check if this vinx is the tokenbase tokenid=" << tokenid.GetHex() << std::endl; + } + + // checking that the vout of the vintx (that is, referenced by this vin), in its turn, is fed by either from heir' or assets' cryptocondition address: + //std::cerr << indentStr << "HeirExactTokenAmounts() calling IsHeirvout for vintx i=" << i << " prevout.n=" << tx.vin[i].prevout.n << std::endl; + + assetValIndentSize++; + assetoshis = IsHeirvout(compareTotals, cpHeir, eval, tokenid, vinTx, tx.vin[i].prevout.n); + assetValIndentSize--; + if (assetoshis > 0) + inputs += assetoshis; + } + } + } + for (int32_t i = 0; iInvalid("mismatched inputs != outputs + txfee") : false; + } + else { + //std::cerr << indentStr << "HeirExactTokenAmounts() inputs=" << inputs << " vs outputs=" << outputs << " return true" << std::endl; + return(true); + } +}*/ + + +// claim coins tokens validation runner +// sadly we cannot have yet 'templatized' lambdas, if we could we could capture all these params inside HeirValidation() +template bool RunValidationPlans(uint8_t funcId, struct CCcontract_info* cp, Eval* eval, const CTransaction& tx, uint256 latestTxid, CScript fundingOpretScript, bool isHeirSpendingBegan) +{ + int32_t numvins = tx.vin.size(); + int32_t numvouts = tx.vout.size(); + + // setup validation framework (please see its description in heir_validate.h): + // validation 'plans': + CInputValidationPlan vinPlan; + COutputValidationPlan voutPlan; + + // vin 'identifiers' + CNormalInputIdentifier normalInputIdentifier(cp); + CCCInputIdentifier ccInputIdentifier(cp); + + // vin and vout 'validators' + // always check coin inputs: + CMyPubkeyVoutValidator normalInputValidator(cp, fundingOpretScript, true); // check normal input for this opret cause this is first tx + //CMyPubkeyVoutValidator normalInputValidatorLast(cp, latestTxOpRetScript, true); // check normal input for latest opret. TODO: we may also check this opret + + CCC1of2AddressValidator cc1of2ValidatorThis(cp, fundingOpretScript, "checking this tx opreturn:"); // 1of2add validator with pubkeys from this tx opreturn + //CCC1of2AddressValidator cc1of2ValidatorLast(cp, latestTxOpRetScript, "checking last tx opreturn:"); // 1of2add validator with pubkeys from last tx opreturn + CHeirSpendValidator heirSpendValidator(cp, fundingOpretScript, latestTxid, isHeirSpendingBegan); // check if heir allowed to spend + + // only for tokens: + CMyPubkeyVoutValidator ownerCCaddrValidator(cp, fundingOpretScript, false); // check if this correct owner's cc user addr corresponding to opret + //CMyPubkeyVoutValidator ownerCCaddrValidatorLast(cp, latestTxOpRetScript, false); // check if this correct owner's cc user addr corresponding to lastest opret + // TODO: we may also check with current opret + COpRetValidator opRetValidator(cp, fundingOpretScript); // compare opRets in this and last tx + + switch (funcId) { + case 'F': // fund tokens + // vin validation plan: + // we need cast here this is casted inside + vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &normalInputValidator); // txfee - see AddNormalInput parameter + vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &ownerCCaddrValidator); // check cc owner addr + + // vout validation plan: + voutPlan.pushValidators(0, &cc1of2ValidatorThis); // check 1of2 addr funding + // do not check change at this time + // no checking for opret yet + break; + + case 'A': // add tokens + // vin validation plan: + // we need cast here this is casted inside + vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &normalInputValidator/*, &normalInputValidatorLast*/); // txfee - see AddNormalInput parameter + vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &ownerCCaddrValidator); // check cc owner addr + + // vout validation plan: + voutPlan.pushValidators(0, &cc1of2ValidatorThis); // check 1of2 addr funding + // do not check change at this time + voutPlan.pushValidators(numvouts - 1, &opRetValidator); // opreturn check, NOTE: only for C or A: + break; + + case 'C': + // vin validation plan: + // we need cast here this is casted inside + vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &normalInputValidator/*&normalInputValidatorLast*/); // txfee - see AddNormalInput parameter + vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &cc1of2ValidatorThis /*, &cc1of2ValidatorLast*/); // cc1of2 funding addr + + // vout validation plan: + voutPlan.pushValidators(0, &heirSpendValidator); // check if heir is allowed to spend + voutPlan.pushValidators(numvouts - 1, &opRetValidator); // opreturn check, NOTE: only for C or A + break; + } + + // call vin/vout validation + if (!vinPlan.validate(tx, eval)) + return false; + if (!voutPlan.validate(tx, eval)) + return false; + + return true; } -bool HeirValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +/** + * Tx validation entry function + */ +bool HeirValidate(struct CCcontract_info* cp, Eval* eval, const CTransaction& tx, uint32_t nIn) { - int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; - return eval->Invalid("no validation yet"); - std::vector > txids; - numvins = tx.vin.size(); - numvouts = tx.vout.size(); - preventCCvins = preventCCvouts = -1; - if ( numvouts < 1 ) + int32_t numvins = tx.vin.size(); + int32_t numvouts = tx.vout.size(); + //int32_t preventCCvins = -1; + //int32_t preventCCvouts = -1; + + if (numvouts < 1) return eval->Invalid("no vouts"); - else - { - for (i=0; iInvalid("illegal normal vini"); - } + + if (chainActive.Height() < 741) + return true; + + uint8_t funcId; + uint256 fundingTxidInOpret = zeroid, latestTxid = zeroid, tokenid = zeroid; + + //CScript opRetScript = tx.vout[numvouts - 1].scriptPubKey; + + CScript fundingTxOpRetScript; + bool isHeirSpendingBegan = false; + + int32_t heirType = NOT_HEIR; + funcId = DecodeHeirOpRet(tx.vout[numvouts - 1].scriptPubKey, tokenid, fundingTxidInOpret, true); + if(funcId != 0) + heirType = HEIR_COINS; + else { + funcId = DecodeHeirOpRet(tx.vout[numvouts - 1].scriptPubKey, tokenid, fundingTxidInOpret, false); + if (funcId != 0) + heirType = HEIR_TOKENS; + } + + if (heirType == NOT_HEIR) + return eval->Invalid("invalid opreturn format"); + + if (funcId != 'F') { + if (fundingTxidInOpret == zeroid) { + return eval->Invalid("invalid tx opreturn format: no fundingtxid present"); } - //fprintf(stderr,"check amounts\n"); - if ( HeirExactAmounts(cp,eval,tx,1,10000) == false ) - { - fprintf(stderr,"Heirget invalid amount\n"); - return false; - } - else - { - txid = tx.GetHash(); - memcpy(hash,&txid,sizeof(hash)); - retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); - if ( retval != 0 ) - fprintf(stderr,"Heirget validated\n"); - else fprintf(stderr,"Heirget invalid\n"); - return(retval); + if (heirType == HEIR_COINS) + latestTxid = FindLatestFundingTx(fundingTxidInOpret, tokenid, fundingTxOpRetScript, isHeirSpendingBegan); + else + latestTxid = FindLatestFundingTx(fundingTxidInOpret, tokenid, fundingTxOpRetScript, isHeirSpendingBegan); + + if (latestTxid == zeroid) { + return eval->Invalid("invalid heir transaction: no funding tx found"); } + } + else { + fundingTxOpRetScript = tx.vout[numvouts - 1].scriptPubKey; + } + + // validate prev tx cc inputs = outputs: + /* if (heirType == HEIR_TOKENS && funcId == 't' && !HeirExactTokenAmounts(true, cp, eval, zeroid, tx)) { + std::cerr << "HeirValidate() this tx or some of its vin tx has invalid cc amounts" << std::endl; + return eval->Invalid("this tx or some of its vin tx has invalid cc amounts"); + } */ + + switch (funcId) { + case 'F': + // fund coins: + // vins.*: normal inputs + // ----------------------------- + // vout.0: funding CC 1of2 addr for the owner and heir + // vout.1: txfee for CC addr used as a marker + // vout.2: normal change + // vout.n-1: opreturn 'F' ownerpk heirpk inactivitytime heirname + + // fund tokens: + // vin.0: normal inputs txfee + // vins.1+: user's CC addr inputs + // ----------------------- + // vout.0: funding heir CC 1of2 addr for the owner and heir + // vout.1: txfee for CC addr used as a marker + // vout.2: normal change + // vout.n-1: opreturn 't' tokenid 'F' ownerpk heirpk inactivitytime heirname tokenid + if (heirType == HEIR_TOKENS) + return RunValidationPlans(funcId, cp, eval, tx, latestTxid, fundingTxOpRetScript, isHeirSpendingBegan); + else + return eval->Invalid("unexpected HeirValidate for heirfund"); + // break; + + case 'A': + // add funding coins: + // vins.*: normal inputs + // ------------------------ + // vout.0: funding CC 1of2 addr for the owner and heir + // vout.1: normal change + // vout.n-1: opreturn 'A' ownerpk heirpk inactivitytime fundingtx + + // add funding tokens: + // vins.0: normal inputs txfee + // vins.1+: user's CC addr inputs + // ------------------------ + // vout.0: funding CC 1of2 addr for the owner and heir + // vout.1: normal change + // vout.n-1: opreturn 't' tokenid 'A' ownerpk heirpk inactivitytime fundingtx + if (heirType == HEIR_TOKENS) + return RunValidationPlans(funcId, cp, eval, tx, latestTxid, fundingTxOpRetScript, isHeirSpendingBegan); + else + return eval->Invalid("unexpected HeirValidate for heiradd"); + //break; + + case 'C': + // claim coins: + // vin.0: normal input txfee + // vin.1+: input from CC 1of2 addr + // ------------------------------------- + // vout.0: normal output to owner or heir address + // vout.1: change to CC 1of2 addr + // vout.2: change to user's addr from txfee input if any + // vout.n-1: opreturn 'C' ownerpk heirpk inactivitytime fundingtx + + // claim tokens: + // vin.0: normal input txfee + // vin.1+: input from CC 1of2 addr + // -------------------------------------------- + // vout.0: output to user's cc address + // vout.1: change to CC 1of2 addr + // vout.2: change to normal from txfee input if any + // vout.n-1: opreturn 't' tokenid 'C' ownerpk heirpk inactivitytime fundingtx + if (heirType == HEIR_TOKENS) + return RunValidationPlans(funcId, cp, eval, tx, latestTxid, fundingTxOpRetScript, isHeirSpendingBegan); + else + return RunValidationPlans(funcId, cp, eval, tx, latestTxid, fundingTxOpRetScript, isHeirSpendingBegan); + // break; + + default: + std::cerr << "HeirValidate() illegal heir funcid=" << (char)funcId << std::endl; + return eval->Invalid("unexpected HeirValidate funcid"); + // break; } + return eval->Invalid("unexpected"); // (PreventCC(eval, tx, preventCCvins, numvins, preventCCvouts, numvouts)); } // end of consensus code -// helper functions for rpc calls in rpcwallet.cpp -int64_t AddHeirInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +// helper functions used in implementations of rpc calls (in rpcwallet.cpp) or validation code + +/** +* Checks if vout is to cryptocondition address +* @return vout value in satoshis +*/ +int64_t IsHeirFundingVout(struct CCcontract_info* cp, const CTransaction& tx, int32_t voutIndex, CPubKey ownerPubkey, CPubKey heirPubkey) { - // add threshold check - char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; - std::vector > unspentOutputs; - GetCCaddress(cp,coinaddr,pk); - SetCCunspents(unspentOutputs,coinaddr); - for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) - { - txid = it->first.txhash; - vout = (int32_t)it->first.index; + char destaddr[65], heirContractAddr[65]; + + GetCCaddress1of2(cp, heirContractAddr, ownerPubkey, heirPubkey); + if (tx.vout[voutIndex].scriptPubKey.IsPayToCryptoCondition() != 0) { + // NOTE: dimxy it was unsafe 'Getscriptaddress(destaddr,tx.vout[voutIndex].scriptPubKey) > 0' here: + if (Getscriptaddress(destaddr, tx.vout[voutIndex].scriptPubKey) && strcmp(destaddr, heirContractAddr) == 0) + return (tx.vout[voutIndex].nValue); + } + return (0); +} + +// not used +bool HeirExactAmounts(struct CCcontract_info* cp, Eval* eval, const CTransaction& tx, int32_t minage, uint64_t txfee) +{ + static uint256 zerohash; + CTransaction vinTx; + uint256 hashBlock, activehash; + int32_t i, numvins, numvouts; + int64_t inputs = 0, outputs = 0, assetoshis; + numvins = tx.vin.size(); + numvouts = tx.vout.size(); + for (i = 0; i < numvins; i++) { + //fprintf(stderr,"HeirExactAmounts() vini.%d\n",i); + if ((*cp->ismyvin)(tx.vin[i].scriptSig) != 0) { + //fprintf(stderr,"HeirExactAmounts() vini.%d check mempool\n",i); + if (eval->GetTxUnconfirmed(tx.vin[i].prevout.hash, vinTx, hashBlock) == 0) + return eval->Invalid("cant find vinTx"); + else { + //fprintf(stderr,"HeirExactAmounts() vini.%d check hash and vout\n",i); + if (hashBlock == zerohash) + return eval->Invalid("cant Heir from mempool"); + ////if ( (assetoshis= IsHeirCCvout(cp,vinTx,tx.vin[i].prevout.n)) != 0 ) + //// inputs += assetoshis; + } + } + } + for (i = 0; i < numvouts; i++) { + //fprintf(stderr,"i.%d of numvouts.%d\n",i,numvouts); + ////if ( (assetoshis= IsHeirvout(cp,tx,i)) != 0 ) + //// outputs += assetoshis; + } + if (inputs != outputs + txfee) { + fprintf(stderr, "HeirExactAmounts() inputs %llu vs outputs %llu\n", (long long)inputs, (long long)outputs); + return eval->Invalid("mismatched inputs != outputs + txfee"); + } + else + return (true); +} + +// makes coin initial tx opret +CScript EncodeHeirCreateOpRet(uint8_t eval, uint8_t funcid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName) +{ + return CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)eval << (uint8_t)funcid << ownerPubkey << heirPubkey << inactivityTimeSec << heirName); +} + +// makes coin additional tx opret +CScript EncodeHeirOpRet(uint8_t eval, uint8_t funcid, uint256 fundingtxid) +{ + fundingtxid = revuint256(fundingtxid); + return CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)eval << (uint8_t)funcid << fundingtxid); +} +// makes opret for tokens while they are inside Heir contract address space - initial funding +CScript EncodeHeirAssetsCreateOpRet(uint8_t eval, uint8_t funcid, uint256 tokenid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string hearName) +{ + tokenid = revuint256(tokenid); + return CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)eval << (uint8_t)'t' << tokenid << (uint8_t)funcid << ownerPubkey << heirPubkey << inactivityTimeSec << hearName); +} +// makes opret for tokens while they are inside Heir contract address space - additional funding +CScript EncodeHeirAssetsOpRet(uint8_t eval, uint8_t funcid, uint256 tokenid, uint256 fundingtxid) +{ + tokenid = revuint256(tokenid); + fundingtxid = revuint256(fundingtxid); + return CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)eval << (uint8_t)'t' << tokenid << (uint8_t)funcid << fundingtxid); +} + +/** +* decode opret vout for Heir contract +*/ +template uint8_t _DecodeHeirOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret, bool noLogging) +{ + std::vector vopret; + uint8_t opretEval = 0; + uint8_t funcId = 0; + + fundingTxidInOpret = zeroid; //to init + + GetOpReturnData(scriptPubKey, vopret); + + if (vopret.size() > 1) { + // NOTE: it unmarshals for all F, A and C + Helper::UnmarshalOpret(vopret, opretEval, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, fundingTxidInOpret); + + /* + std::cerr << "DecodeHeirOpRet() e=" << (int)e + << " funcId=" << (char)funcId + << " ownerPubkey=" << HexStr(ownerPubkey) + << " heirPubkey=" << HexStr(heirPubkey) + << " heirName=" << heirName << " inactivityTime=" << inactivityTime << '\n'; + */ + + //if (e == EVAL_HEIR && IS_CHARINSTR(funcId, "FAC")) + if (opretEval == EVAL_HEIR && Helper::isMyFuncId(funcId)) { + tokenid = revuint256(tokenid); + fundingTxidInOpret = revuint256(fundingTxidInOpret); + return funcId; + } + else + { + if(!noLogging) std::cerr << "DecodeHeirOpRet() warning unexpected OP_RETURN eval=" << (int)opretEval << " or field type=" << (char)(funcId ? funcId : ' ') << '\n'; + } + } + else { + std::cerr << "DecodeHeirOpRet() unmarshal error (vopret.size() == 0)" << '\n'; + } + return (uint8_t)0; +} + +/** +* overload for 'F' opret +*/ +template uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging) +{ + uint256 dummytxid; + + return _DecodeHeirOpRet(scriptPubKey, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, dummytxid, noLogging); +} + +/** +* overload for A, C oprets and AddHeirContractInputs +*/ +template uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256 &tokenid, uint256& fundingtxidInOpret, bool noLogging) +{ + CPubKey dummyOwnerPubkey, dummyHeirPubkey; + int64_t dummyInactivityTime; + std::string dummyHeirName; + + return _DecodeHeirOpRet(scriptPubKey, tokenid, dummyOwnerPubkey, dummyHeirPubkey, dummyInactivityTime, dummyHeirName, fundingtxidInOpret, noLogging); +} + + + +/** + * find the latest funding tx: it may be the first F tx or one of A or C tx's + * Note: this function is also called from validation code (use non-locking calls) + */ +template uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, CScript& fundingOpretScript, bool &isHeirSpendingBegan) +{ + CTransaction fundingtx; + uint256 hashBlock; + const bool allowSlow = false; + + //char markeraddr[64]; + //CCtxidaddr(markeraddr, fundingtxid); + //SetCCunspents(unspentOutputs, markeraddr); + + isHeirSpendingBegan = false; //init the var + funcId = 0; //init the var + + // get initial funding tx and set it as initial lasttx: + if (myGetTransaction(fundingtxid, fundingtx, hashBlock) && fundingtx.vout.size()) { + uint256 dummytxid; + + // set ownerPubkey and heirPubkey: + if ((funcId = DecodeHeirOpRet(fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName)) != 0) { + // found at least funding tx! + std::cerr << "FindLatestFundingTx() lasttx currently is fundingtx, txid=" << fundingtxid.GetHex() << " opreturn type=" << (char)funcId << '\n'; + fundingOpretScript = fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey; + } else { + std::cerr << "FindLatestFundingTx() could not decode opreturn for fundingtxid=" << fundingtxid.GetHex() << '\n'; + return zeroid; + } + } else { + std::cerr << "FindLatestFundingTx() could not find funding tx for fundingtxid=" << fundingtxid.GetHex() << '\n'; + return zeroid; + } + + std::vector> unspentOutputs; + struct CCcontract_info *cp, C; + cp = CCinit(&C, Helper::getMyEval()); + char coinaddr[64]; + GetCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); // get the address of cryptocondition '1 of 2 pubkeys' + + SetCCunspents(unspentOutputs, coinaddr); // get vector with tx's with unspent vouts of 1of2pubkey address: + //std::cerr << "FindLatestFundingTx() using 1of2address=" << coinaddr << " unspentOutputs.size()=" << unspentOutputs.size() << '\n'; + + int32_t maxBlockHeight = 0; // max block height + uint256 latesttxid = fundingtxid; + + // try to find the last funding or spending tx by checking fundingtxid in 'opreturn': + for (std::vector>::const_iterator it = unspentOutputs.begin(); it != unspentOutputs.end(); it++) { + CTransaction regtx; + uint256 hash; + + uint256 txid = it->first.txhash; + //std::cerr << "FindLatestFundingTx() checking unspents for txid=" << txid.GetHex() << '\n'; + + int32_t blockHeight = (int32_t)it->second.blockHeight; + uint256 fundingTxidInOpret; + + //NOTE: maybe called from validation code: + if (myGetTransaction(txid, regtx, hash)) { + std::cerr << "FindLatestFundingTx() found tx for txid=" << txid.GetHex() << " blockHeight=" << blockHeight << " maxBlockHeight=" << maxBlockHeight << '\n'; + + { // debug code: + uint256 debAssetid; + uint8_t debfuncid = DecodeHeirOpRet(regtx.vout[regtx.vout.size() - 1].scriptPubKey, debAssetid, fundingTxidInOpret, true); + std::cerr << "FindLatestFundingTx() regtx.vout.size()=" << regtx.vout.size() << " funcId=" << (char)(debfuncid ? debfuncid : ' ') << " tokenid=" << debAssetid.GetHex() << " fundingtxidInOpret=" << fundingTxidInOpret.GetHex() << std::endl; + } + + uint256 dummyTokenid; // not to contaminate the tokenid from the params! + uint8_t tmpFuncId; + + if (regtx.vout.size() > 0 && + (tmpFuncId = DecodeHeirOpRet(regtx.vout[regtx.vout.size() - 1].scriptPubKey, dummyTokenid, fundingTxidInOpret, true)) != 0 && + fundingtxid == fundingTxidInOpret) { + + // check if heir has begun spending: + if (Helper::isSpendingTx(tmpFuncId)) { // if 'C' or 't' opret + const CScript heirScriptPubkey = CScript() << ParseHex(HexStr(heirPubkey)) << OP_CHECKSIG; + + for (int32_t v = 0; v < regtx.vout.size() - 1; v++) { // do not check opret vout + if (heirScriptPubkey == regtx.vout[v].scriptPubKey) + isHeirSpendingBegan = true; + } + } + + if (blockHeight > maxBlockHeight) { + maxBlockHeight = blockHeight; + latesttxid = txid; + ///// fundingOpretScript = regtx.vout[regtx.vout.size() - 1].scriptPubKey; + funcId = tmpFuncId; + std::cerr << "FindLatestFundingTx() txid=" << latesttxid.GetHex() << " at blockHeight=" << maxBlockHeight << " opreturn type=" << (char)(funcId ? funcId : ' ') << " set as current lasttxid" << '\n'; + } + } + } + } + + return latesttxid; +} + +// overload for validation code +template uint256 FindLatestFundingTx(uint256 fundingtxid, uint256 &tokenid, CScript& opRetScript, bool &isHeirSpendingBegan) +{ + uint8_t funcId; + CPubKey ownerPubkey; + CPubKey heirPubkey; + int64_t inactivityTime; + std::string heirName; + + return _FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, opRetScript, isHeirSpendingBegan); +} + +// overload for transaction creation code +template uint256 FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool &isHeirSpendingBegan) +{ + CScript opRetScript; + + return _FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, opRetScript, isHeirSpendingBegan); +} + +// add owner input in tokens +/*int64_t AddHeirTokenInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 refassetid, int64_t total, int32_t maxinputs) +{ + char coinaddr[64], destaddr[64]; int64_t threshold, nValue, price, totalinputs = 0; uint256 tokenid, txid, hashBlock; std::vector origpubkey; std::vector vopret; CTransaction vintx; int32_t j, vout, n = 0; uint8_t evalcode, funcid; + std::vector > unspentOutputs; + GetCCaddress(cp, coinaddr, pk); + SetCCunspents(unspentOutputs, coinaddr); + threshold = total / (maxinputs + 1); + + //fprintf(stderr,"AddHeirTokenInputs() check cc addr=%s for token inputs\n",coinaddr); + for (std::vector >::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; + for (j = 0; jsecond=" << it->second.satoshis << std::endl; + + if (strcmp(destaddr, coinaddr) != 0 && strcmp(destaddr, cp->unspendableCCaddr) != 0 && strcmp(destaddr, cp->unspendableaddr2) != 0) + continue; + GetOpReturnData(vintx.vout[vintx.vout.size() - 1].scriptPubKey, vopret); + + // NOTE: special opret decode: + // we should not check for E_UNMARSHAL return code because it returns false if not EOF, + // but we have our remainder after tokenid! + bool isEof = false; + bool unmarshalResult = E_UNMARSHAL(vopret, ss >> evalcode; ss >> funcid; ss >> tokenid; isEof=ss.eof()); + if (unmarshalResult || !isEof) + { + tokenid = revuint256(tokenid); // usually DecodeOpretXXX() funcs do this + + //std::cerr << "AddHeirTokenInputs() vout=" << vout << " evalcode=" << (int)evalcode << " cp->evalcode=" << (int)cp->evalcode << " funcid=" << (char)funcid << " check for refassetid=" << refassetid.GetHex() << " vs tokenid in opret=" << tokenid.GetHex() << " coins=" << (double)vintx.vout[vout].nValue / COIN << std::endl; + if (tokenid == refassetid && + IS_CHARINSTR(funcid, "tGB") && + (nValue = vintx.vout[vout].nValue) > 0 && myIsutxo_spentinmempool(txid, vout) == 0) + { + std::cerr << "AddHeirTokenInputs() total=" << total << " maxinputs=" << maxinputs << " uxto value=" << it->second.satoshis << std::endl; + if (total != 0 && maxinputs != 0) + mtx.vin.push_back(CTxIn(txid, vout, CScript())); + //nValue = it->second.satoshis; + totalinputs += nValue; + n++; + if ((total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs)) + break; + } + } + } + } + return(totalinputs); +}*/ + +// add inputs of 1 of 2 cc address +template int64_t Add1of2AddressInputs(struct CCcontract_info* cp, uint256 fundingtxid, CMutableTransaction& mtx, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t total, int32_t maxinputs) +{ + // TODO: add threshold check + int64_t nValue, voutValue, totalinputs = 0; + CTransaction vintx; + int32_t n = 0; + std::vector> unspentOutputs; + + char coinaddr[64]; + GetCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); // get address of cryptocondition '1 pubkey of 2 pubkeys' + SetCCunspents(unspentOutputs, coinaddr); + + // char markeraddr[64]; + // CCtxidaddr(markeraddr, fundingtxid); + // SetCCunspents(unspentOutputs, markeraddr); + //std::cerr << "Add1of2AddressInputs() using 1of2addr=" << coinaddr << " unspentOutputs.size()=" << unspentOutputs.size() << '\n'; + + for (std::vector>::const_iterator it = unspentOutputs.begin(); it != unspentOutputs.end(); it++) { + uint256 txid = it->first.txhash; + uint256 hashBlock; + int32_t voutIndex = (int32_t)it->first.index; // no need to prevent dup - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) - { - if ( (nValue= IsHeirvout(cp,vintx,vout)) > 1000000 && myIsutxo_spentinmempool(txid,vout) == 0 ) - { - if ( total != 0 && maxinputs != 0 ) - mtx.vin.push_back(CTxIn(txid,vout,CScript())); + // dimxy: maybe it is good to put tx's in cache? + if (GetTransaction(txid, vintx, hashBlock, false) != 0) { + uint256 tokenid; + uint256 fundingTxidInOpret; + + uint8_t funcId = DecodeHeirOpRet(vintx.vout[vintx.vout.size() - 1].scriptPubKey, tokenid, fundingTxidInOpret, true); + // note: it returns in in satoshis too... + if ((txid == fundingtxid || fundingTxidInOpret == fundingtxid) && // we're spending only tx's in this funding plan + funcId != 0 && + Helper::isMyFuncId(funcId) && + // deep validation for tokens: + (typeid(Helper) == typeid(TokenHelper) && IsHeirvout(true, cp, nullptr, tokenid, vintx, voutIndex) > 0) && + (voutValue = IsHeirFundingVout(cp, vintx, voutIndex, ownerPubkey, heirPubkey)) > 0 && + !myIsutxo_spentinmempool(txid, voutIndex)) + { + std::cerr << "Add1of2AddressInputs() voutValue=" << voutValue << " satoshis=" << it->second.satoshis << '\n'; + if (total != 0 && maxinputs != 0) + mtx.vin.push_back(CTxIn(txid, voutIndex, CScript())); nValue = it->second.satoshis; totalinputs += nValue; n++; - if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) + if ((total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs)) break; } } } - return(totalinputs); + return totalinputs; } -std::string HeirGet(uint64_t txfee,int64_t nValue) +/** + * enumerate all tx's sending to CCHeir 1of2address and calc total lifetime funds + */ +template int64_t LifetimeHeirContractFunds(struct CCcontract_info* cp, uint256 fundingtxid, CPubKey ownerPubkey, CPubKey heirPubkey) { - CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Heirpk; int64_t inputs,CCchange=0; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; - cp = CCinit(&C,EVAL_HEIR); - if ( txfee == 0 ) - txfee = 10000; - Heirpk = GetUnspendable(cp,0); - mypk = pubkey2pk(Mypubkey()); - if ( (inputs= AddHeirInputs(cp,mtx,Heirpk,nValue+txfee,60)) > 0 ) - { - if ( inputs > nValue ) - CCchange = (inputs - nValue - txfee); - if ( CCchange != 0 ) - mtx.vout.push_back(MakeCC1vout(EVAL_HEIR,CCchange,Heirpk)); - mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - fprintf(stderr,"start at %u\n",(uint32_t)time(NULL)); - j = rand() & 0xfffffff; - for (i=0; i<1000000; i++,j++) - { - tmpmtx = mtx; - rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_HEIR << (uint8_t)'G' << j)); - if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 ) + char coinaddr[64]; + GetCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); // get the address of cryptocondition '1 of 2 pubkeys' + + std::vector> addressIndexes; + SetCCtxids(addressIndexes, coinaddr); + + //fprintf(stderr,"LifetimeHeirContractFunds() scan lifetime of %s\n",coinaddr); + int64_t total = 0; + for (std::vector>::const_iterator it = addressIndexes.begin(); it != addressIndexes.end(); it++) { + uint256 hashBlock; + uint256 txid = it->first.txhash; + CTransaction tx; + + if (GetTransaction(txid, tx, hashBlock, false) && tx.vout.size() > 0) { + uint8_t funcId; + uint256 tokenid; + uint256 fundingTxidInOpret; + const int32_t ivout = 0; + + funcId = DecodeHeirOpRet(tx.vout[tx.vout.size() - 1].scriptPubKey, tokenid, fundingTxidInOpret, true); + + //std::cerr << "LifetimeHeirContractFunds() found tx=" << txid.GetHex() << " vout[0].nValue=" << subtx.vout[ccVoutIdx].nValue << " opreturn=" << (char)funcId << '\n'; + + if (funcId != 0 && (txid == fundingtxid || fundingTxidInOpret == fundingtxid) && Helper::isMyFuncId(funcId) && !Helper::isSpendingTx(funcId) + /* && !myIsutxo_spentinmempool(txid, ccVoutIdx) */) // include also tx in mempool { - len >>= 1; - decode_hex(buf,len,(char *)rawhex.c_str()); - hash = bits256_doublesha256(0,buf,len); - if ( (hash.bytes[0] & 0xff) == 0 && (hash.bytes[31] & 0xff) == 0 ) - { - fprintf(stderr,"found valid txid after %d iterations %u\n",i,(uint32_t)time(NULL)); - return(rawhex); - } - //fprintf(stderr,"%02x%02x ",hash.bytes[0],hash.bytes[31]); + total += it->second; // dont do this: tx.vout[ivout].nValue; // in vin[0] always is the pay to 1of2 addr (funding or change) + std::cerr << "LifetimeHeirContractFunds() added tx=" << txid.GetHex() << " it->second=" << it->second << " vout[0].nValue=" << tx.vout[ivout].nValue << " opreturn=" << (char)funcId << '\n'; } } - fprintf(stderr,"couldnt generate valid txid %u\n",(uint32_t)time(NULL)); - return(""); - } else fprintf(stderr,"cant find Heir inputs\n"); - return(""); -} - -std::string HeirFund(uint64_t txfee,int64_t funds) -{ - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Heirpk; CScript opret; struct CCcontract_info *cp,C; - cp = CCinit(&C,EVAL_HEIR); - if ( txfee == 0 ) - txfee = 10000; - mypk = pubkey2pk(Mypubkey()); - Heirpk = GetUnspendable(cp,0); - if ( AddNormalinputs(mtx,mypk,funds+txfee,64) > 0 ) - { - mtx.vout.push_back(MakeCC1vout(EVAL_HEIR,funds,Heirpk)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); } - return(""); + return (total); } -UniValue HeirInfo() +/* rpc functions' implementation: */ + +/** + * heirfund rpc call implementation + * creates tx for initial funds deposit on cryptocondition address which locks funds for spending by either of address. + * and also for setting spending plan for the funds' owner and heir + * @return fundingtxid handle for subsequent references to this heir funding plan + */ +template std::string HeirFund(uint64_t txfee, int64_t amount, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid) { - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); char numstr[64]; - CPubKey Heirpk; struct CCcontract_info *cp,C; int64_t funding; - result.push_back(Pair("result","success")); - result.push_back(Pair("name","Heir")); - cp = CCinit(&C,EVAL_HEIR); - Heirpk = GetUnspendable(cp,0); - funding = AddHeirInputs(cp,mtx,Heirpk,0,0); - sprintf(numstr,"%.8f",(double)funding/COIN); - result.push_back(Pair("funding",numstr)); - return(result); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + struct CCcontract_info *cp, C; + + cp = CCinit(&C, Helper::getMyEval()); + if (txfee == 0) + txfee = 10000; + + //std::cerr << "HeirFund() amount=" << amount << " txfee=" << txfee << " heirPubkey IsValid()=" << heirPubkey.IsValid() << " inactivityTime(sec)=" << inactivityTimeSec << " tokenid=" << tokenid.GetHex() << std::endl; + + if (!heirPubkey.IsValid()) { + std::cerr << "HeirFund() heirPubkey is not valid!" << std::endl; + return std::string(""); + } + + CPubKey myPubkey = pubkey2pk(Mypubkey()); + + if (AddNormalinputs(mtx, myPubkey, txfee, 3) > 0) { // txfee for miners + int64_t inputs, change; + + if ((inputs=Helper::addOwnerInputs(cp, tokenid, mtx, myPubkey, amount, (int32_t)64)) > 0) { // 2 x txfee: 1st for marker vout, 2nd to miners + //mtx.vout.push_back(MakeCC1vout(EVAL_HEIR,amount,HeirCCpk)); + mtx.vout.push_back(MakeCC1of2vout(Helper::getMyEval(), amount, myPubkey, heirPubkey)); // add cryptocondition to spend amount for either pk + + // add a marker for finding all plans in HeirList() + CPubKey HeirContractPubKey = GetUnspendable(cp, 0); + mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(HeirContractPubKey)) << OP_CHECKSIG)); // TODO: do we need this marker? + + // calc and add change vout: + if (inputs > amount) + change = (inputs - amount); // -txfee <-- txfee pays user + + //std::cerr << "HeirFund() inputs=" << inputs << " amount=" << amount << " txfee=" << txfee << " change=" << change << '\n'; + + if (change != 0) { // vout[1] + mtx.vout.push_back(Helper::makeUserVout(change, myPubkey)); + } + + // add change for txfee and opreturn vouts and sign tx: + return (FinalizeCCTx(0, cp, mtx, myPubkey, txfee, + // CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_HEIR << (uint8_t)'F' << myPubkey << heirPubkey << inactivityTimeSec << heirName))); + Helper::makeCreateOpRet(tokenid, myPubkey, heirPubkey, inactivityTimeSec, heirName))); + } + else // TODO: need result return unification with heiradd and claim + std::cerr << "HeirFund() could not find owner inputs" << std::endl; + + } + else + std::cerr << "HeirFund() could not find normal inputs" << std::endl; + return std::string(""); +} + +// if no these callers - it could not link +std::string HeirFundCoinCaller(uint64_t txfee, int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid){ + return HeirFund(txfee, funds, heirName, heirPubkey, inactivityTimeSec, tokenid); +} + +std::string HeirFundTokenCaller(uint64_t txfee, int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid) { + return HeirFund(txfee, funds, heirName, heirPubkey, inactivityTimeSec, tokenid); +} + +/** + * heiradd rpc call implementation + * creates tx to add more funds to cryptocondition address for spending by either funds' owner or heir + * @return result object with raw tx or error text + */ +template UniValue HeirAdd(uint256 fundingtxid, uint64_t txfee, int64_t amount) +{ + UniValue result(UniValue::VOBJ); //, a(UniValue::VARR); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + CPubKey ownerPubkey, heirPubkey; + int64_t inputs, CCchange = 0; + int64_t inactivityTimeSec; + struct CCcontract_info *cp, C; + std::string rawhex; + uint256 lasttxid, tokenid; + std::string heirName; + uint8_t funcId; + bool isHeirSpendingBegan = false; + + cp = CCinit(&C, Helper::getMyEval()); + if (txfee == 0) + txfee = 10000; + + if ((lasttxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, isHeirSpendingBegan)) != zeroid) { + int32_t numblocks; + + CPubKey myPubkey = pubkey2pk(Mypubkey()); + + // check if it is the owner + if (myPubkey != ownerPubkey) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "adding funds is only allowed for the owner of this contract")); + return result; + } + + if (AddNormalinputs(mtx, myPubkey, txfee, 3) > 0) { // txfee for miners + + int64_t inputs, change; + + //if (AddNormalinputs(mtx, myPubkey, amount + 1 * txfee, 64) > 0) { // TODO: why 64 max inputs? + if ((inputs = Helper::addOwnerInputs(cp, tokenid, mtx, myPubkey, amount, 64)) > 0) { // TODO: why 64 max inputs? + + // we do not use markers anymore - storing data in opreturn is better + // add marker vout: + /* char markeraddr[64]; + CPubKey markerpubkey = CCtxidaddr(markeraddr, fundingtxid); + mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(markerpubkey)) << OP_CHECKSIG)); // txfee 1, txfee 2 - for miners + std::cerr << "HeirAdd() adding markeraddr=" << markeraddr << '\n'; */ + + // add cryptocondition to spend this funded amount for either pk + mtx.vout.push_back(MakeCC1of2vout(Helper::getMyEval(), amount, ownerPubkey, heirPubkey)); // using always pubkeys from OP_RETURN in order to not mixing them up! + + // calc and add change vout: + if (inputs > amount) + change = (inputs - amount); // -txfee <-- txfee pays user + + //std::cerr << "HeirAdd() inputs=" << inputs << " amount=" << amount << " txfee=" << txfee << " change=" << change << '\n'; + + if (change != 0) { // vout[1] + mtx.vout.push_back(Helper::makeUserVout(change, myPubkey)); + } + + // add opreturn 'A' and sign tx: // this txfee ignored + std::string rawhextx = (FinalizeCCTx(0, cp, mtx, myPubkey, txfee, + Helper::makeAddOpRet(tokenid, fundingtxid))); + + result.push_back(Pair("result", "success")); + result.push_back(Pair("hextx", rawhextx)); + } + else { + std::cerr << "HeirAdd cannot find owner inputs" << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "can't find owner inputs")); + } + } + else { + std::cerr << "HeirAdd cannot find normal inputs for tx fee" << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "can't find normal inputs for tx fee")); + } + + } else { + fprintf(stderr, "HeirAdd() can't find any heir CC funding tx's\n"); + + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "can't find any heir CC funding transactions")); + } + + return result; +} + + +UniValue HeirAddCoinCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount) { + return HeirAdd(fundingtxid, txfee, amount); +} +UniValue HeirAddTokenCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount) { + return HeirAdd(fundingtxid, txfee, amount); +} + + +/** + * heirclaim rpc call implementation + * creates tx to spend funds from cryptocondition address by either funds' owner or heir + * @return result object with raw tx or error text + */ +template UniValue HeirClaim(uint256 fundingtxid, uint64_t txfee, int64_t amount) +{ + UniValue result(UniValue::VOBJ); //, a(UniValue::VARR); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + CPubKey myPubkey, ownerPubkey, heirPubkey; + int64_t inputs, change = 0; + int64_t inactivityTimeSec; + struct CCcontract_info *cp, C; + + uint256 latesttxid, tokenid; + uint8_t funcId; + std::string heirName; + bool isHeirSpendingBegan = false; + + + cp = CCinit(&C, Helper::getMyEval()); + if (txfee == 0) + txfee = 10000; + + if ((latesttxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, isHeirSpendingBegan)) != zeroid) { + int32_t numblocks; + uint64_t durationSec = 0; + + // we do not need to find duration if spending already has begun + if (!isHeirSpendingBegan) { + durationSec = CCduration(numblocks, latesttxid); + std::cerr << "HeirClaim() duration=" << durationSec << " inactivityTime=" << inactivityTimeSec << " numblocks=" << numblocks << std::endl; + } + + // spending is allowed if there is already spending tx or inactivity time + //bool isAllowedToHeir = (funcId == 'C' || durationSec > inactivityTimeSec) ? true : false; + bool isAllowedToHeir = (isHeirSpendingBegan || durationSec > inactivityTimeSec) ? true : false; + myPubkey = pubkey2pk(Mypubkey()); + + // if it is the heir, check if spending not allowed to heir yet + if (myPubkey == heirPubkey && !isAllowedToHeir) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "spending is not allowed yet for the heir")); + return result; + } + + // we do not use markers any more: + // we allow owner to spend funds at any time: + // if it is the owner, check if spending already allowed to heir + /* if (myPubkey == ownerPubkey && isAllowedToHeir) { + result.push_back(Pair("result", "spending is not already allowed for the owner")); + return result; + } */ + + // add spending txfee from the calling user + if (AddNormalinputs(mtx, myPubkey, txfee, 3) > 0) { + + // add spending from cc 1of2 address + if ((inputs = Add1of2AddressInputs(cp, fundingtxid, mtx, ownerPubkey, heirPubkey, amount, 60)) >= amount) // TODO: why only 60 inputs? + { + /*if (inputs < amount) { + std::cerr << "HeirClaim() cant find enough HeirCC 1of2 inputs, found=" << inputs << " required=" << amount << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "can't find heir CC funding")); + + return result; + }*/ + + // add vout with amount to claiming address + mtx.vout.push_back(Helper::makeClaimerVout(amount, myPubkey)); // vout[0] + + // calc and add change vout: + if (inputs > amount) + change = (inputs - amount); // -txfee <-- txfee pays user + + //std::cerr << "HeirClaim() inputs=" << inputs << " amount=" << amount << " txfee=" << txfee << " change=" << change << '\n'; + + // change to 1of2 funding addr: + if (change != 0) { // vout[1] + mtx.vout.push_back(MakeCC1of2vout(Helper::getMyEval(), change, ownerPubkey, heirPubkey)); // using always pubkeys from OP_RETURN in order to not mixing them up! + } + + // add marker vout: + /*char markeraddr[64]; + CPubKey markerpubkey = CCtxidaddr(markeraddr, fundingtxid); + // NOTE: amount = 0 is not working: causes error code: -26, error message : 64 : dust + mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(markerpubkey)) << OP_CHECKSIG)); // txfee 1, txfee 2 - for miners + std::cerr << "HeirClaim() adding markeraddr=" << markeraddr << '\n'; */ + + uint8_t myprivkey[32]; + char coinaddr[64]; + // set priv key addresses in CC structure: + GetCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); + Myprivkey(myprivkey); + + //fprintf(stderr,"HeirClaim() before setting unspendable CC addr2= (%s) addr3= (%s)\n", cp->unspendableaddr2, cp->unspendableaddr3); + CCaddr2set(cp, Helper::getMyEval(), ownerPubkey, myprivkey, coinaddr); + CCaddr3set(cp, Helper::getMyEval(), heirPubkey, myprivkey, coinaddr); + + fprintf(stderr, "HeirClaim() after setting unspendable CC addr2=(%s) addr3=(%s)\n", cp->unspendableaddr2, cp->unspendableaddr3); + + // add opreturn 'C' and sign tx: // this txfee will be ignored + std::string rawhextx = FinalizeCCTx(0, cp, mtx, myPubkey, txfee, + Helper::makeClaimOpRet(tokenid, fundingtxid)); + + result.push_back(Pair("result", "success")); + result.push_back(Pair("hextx", rawhextx)); + + } else { + fprintf(stderr, "HeirClaim() cant find Heir CC inputs\n"); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "can't find heir CC funding")); + } + } else { + fprintf(stderr, "HeirClaim() cant find sufficient user inputs for tx fee\n"); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "can't find sufficient user inputs to pay transaction fee")); + } + } else { + fprintf(stderr, "HeirClaim() can't find any heir CC funding tx's\n"); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "can't find any heir CC funding transactions")); + } + + return result; +} + +UniValue HeirClaimCoinCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount) { + return HeirClaim(fundingtxid, txfee, amount); +} +UniValue HeirClaimTokenCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount) { + return HeirClaim(fundingtxid, txfee, amount); +} + + + +/** + * heirinfo rpc call implementation + * returns some information about heir CC contract plan by a handle of initial fundingtxid: + * plan name, owner and heir pubkeys, funds deposited and available, flag if spending is enabled for the heir + * @return heir info data + */ +UniValue HeirInfo(uint256 fundingtxid) +{ + UniValue result(UniValue::VOBJ); + + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + CPubKey ownerPubkey, heirPubkey; + uint256 latestFundingTxid; + uint256 dummyTokenid, tokenid; + + std::string heirName; + uint8_t funcId; + int64_t inactivityTimeSec; + + CTransaction fundingtx; + uint256 hashBlock; + const bool allowSlow = false; + + //char markeraddr[64]; + //CCtxidaddr(markeraddr, fundingtxid); + //SetCCunspents(unspentOutputs, markeraddr); + + // get initial funding tx and set it as initial lasttx: + if (myGetTransaction(fundingtxid, fundingtx, hashBlock) && fundingtx.vout.size()) { + + int32_t heirType = NOT_HEIR; + if (DecodeHeirOpRet(fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey, dummyTokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, true) == 'F') + heirType = HEIR_COINS; + else if (DecodeHeirOpRet(fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, true) == 'F') + heirType = HEIR_TOKENS; + else + { + std::cerr << "HeirInfo() initial tx F not found for this fundingtx" << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "initial tx F not found")); + return result; + } + + struct CCcontract_info *cp, C; + if (heirType == HEIR_COINS) + cp = CCinit(&C, CoinHelper::getMyEval()); + else + cp = CCinit(&C, TokenHelper::getMyEval()); + + bool isHeirSpendingBegan = false; + + if (heirType == HEIR_COINS) + latestFundingTxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, isHeirSpendingBegan); + else + latestFundingTxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, isHeirSpendingBegan); + + if (latestFundingTxid != zeroid) { + int32_t numblocks; + uint64_t durationSec = 0; + + std::cerr << "HeirInfo() latesttxid=" << latestFundingTxid.GetHex() << '\n'; + + std::ostringstream stream; + std::string msg; + + result.push_back(Pair("fundingtxid", fundingtxid.GetHex())); + result.push_back(Pair("name", heirName.c_str())); + + if (heirType == HEIR_TOKENS) { + stream << tokenid.GetHex(); + msg = "tokenid"; + result.push_back(Pair(msg, stream.str().c_str())); + stream.str(""); + stream.clear(); + } + + char hexbuf[67]; + stream << pubkey33_str(hexbuf, (uint8_t*)ownerPubkey.begin()); + result.push_back(Pair("owner", stream.str().c_str())); + stream.str(""); + stream.clear(); + + stream << pubkey33_str(hexbuf, (uint8_t*)heirPubkey.begin()); + result.push_back(Pair("heir", stream.str().c_str())); + stream.str(""); + stream.clear(); + + int64_t total; + if (heirType == HEIR_COINS) + total = LifetimeHeirContractFunds(cp, fundingtxid, ownerPubkey, heirPubkey); + else + total = LifetimeHeirContractFunds(cp, fundingtxid, ownerPubkey, heirPubkey); + + if (heirType == HEIR_COINS) { + msg = "funding total in coins"; + stream << (double)total / COIN; + } + else { + msg = "funding total in tokens"; + stream << total; + } + result.push_back(Pair(msg, stream.str().c_str())); + stream.str(""); + stream.clear(); + + int64_t inputs; + if (heirType == HEIR_COINS) + inputs = Add1of2AddressInputs(cp, fundingtxid, mtx, ownerPubkey, heirPubkey, 0, 60); //NOTE: amount = 0 means all unspent inputs + else + inputs = Add1of2AddressInputs(cp, fundingtxid, mtx, ownerPubkey, heirPubkey, 0, 60); + + if (heirType == HEIR_COINS) { + msg = "funding available in coins"; + stream << (double)inputs / COIN; + } + else { + msg = "funding available in tokens"; + stream << inputs; + } + result.push_back(Pair(msg, stream.str().c_str())); + stream.str(""); + stream.clear(); + + if (heirType == HEIR_TOKENS) { + int64_t ownerInputs = TokenHelper::addOwnerInputs(cp, tokenid, mtx, ownerPubkey, 0, (int32_t)64); + stream << ownerInputs; + msg = "owner funding available in tokens"; + result.push_back(Pair(msg, stream.str().c_str())); + stream.str(""); + stream.clear(); + } + + stream << inactivityTimeSec; + result.push_back(Pair("inactivity time setting", stream.str().c_str())); + stream.str(""); + stream.clear(); + + if (!isHeirSpendingBegan) { // we do not need find duration if the spending already has begun + durationSec = CCduration(numblocks, latestFundingTxid); + std::cerr << "HeirInfo() duration=" << durationSec << " inactivityTime=" << inactivityTimeSec << " numblocks=" << numblocks << '\n'; + } + + stream << std::boolalpha << (isHeirSpendingBegan || durationSec > inactivityTimeSec); + result.push_back(Pair("spending allowed for the heir", stream.str().c_str())); + stream.str(""); + stream.clear(); + + result.push_back(Pair("result", "success")); + } + else { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "could not find heir cc plan for this txid")); + } + } + else { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "could not find heir cc plan for this txid (no initial tx)")); + } + return (result); +} + +/** + * heirlist rpc call implementation + * @return list of heir plan handles (fundingtxid) + */ + +template void _HeirList(struct CCcontract_info *cp, UniValue &result) +{ + std::vector> unspentOutputs; + char coinaddr[64]; + CPubKey ccPubKeyEmpty; + GetCCaddress(cp, coinaddr, ccPubKeyEmpty); + SetCCunspents(unspentOutputs, cp->normaladdr); + + std::cerr << "HeirList() finding heir marker from Heir contract addr=" << cp->normaladdr << " unspentOutputs.size()=" << unspentOutputs.size() << '\n'; + + // TODO: move marker to special cc addr to prevent checking all tokens + for (std::vector>::const_iterator it = unspentOutputs.begin(); it != unspentOutputs.end(); it++) { + uint256 hashBlock; + uint256 txid = it->first.txhash; + uint256 tokenid; + int32_t vout = (int32_t)it->first.index; + + std::cerr << "HeirList() checking txid=" << txid.GetHex() << " vout=" << vout << '\n'; + + CTransaction vintx; + if (GetTransaction(txid, vintx, hashBlock, false) != 0 && (vintx.vout.size() - 1) > 0) { + CPubKey ownerPubkey, heirPubkey; + std::string heirName; + int64_t inactivityTimeSec; + + uint8_t funcId = DecodeHeirOpRet(vintx.vout[vintx.vout.size() - 1].scriptPubKey, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName); + + // note: if it is not Heir token funcId would be equal to 0 + if (funcId == 'F') { + result.push_back(Pair("fundingtxid heirName", txid.GetHex() + std::string(" ") + (typeid(Helper) == typeid(TokenHelper) ? std::string("token") : std::string("coin")) + std::string(" ") + heirName)); + } + else { + fprintf(stderr, "HeirList() couldnt find initial transaction\n"); + } + } + else { + fprintf(stderr, "HeirList() couldnt load transaction\n"); + } + } +} + + +UniValue HeirList() +{ + UniValue result(UniValue::VOBJ); + result.push_back(Pair("result", "success")); + + struct CCcontract_info *cpHeir, *cpTokens, C; + + cpHeir = CCinit(&C, EVAL_HEIR); + cpTokens = CCinit(&C, EVAL_TOKENS); + + _HeirList(cpHeir, result); + _HeirList(cpTokens, result); + + return result; } diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h new file mode 100644 index 000000000..8b432e8e0 --- /dev/null +++ b/src/cc/heir_validate.h @@ -0,0 +1,622 @@ +#ifndef HEIR_VALIDATE_H +#define HEIR_VALIDATE_H + +#include "CCinclude.h" +#include "CCHeir.h" + +#define NOT_HEIR (-1) +#define HEIR_COINS 1 +#define HEIR_TOKENS 2 +#define IS_CHARINSTR(c, str) (std::string(str).find((char)(c)) != std::string::npos) + + +// makes coin initial tx opret +CScript EncodeHeirCreateOpRet(uint8_t eval, uint8_t funcid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName); +// makes coin additional tx opret +CScript EncodeHeirOpRet(uint8_t eval, uint8_t funcid, uint256 fundingtxid); + +CScript EncodeHeirAssetsCreateOpRet(uint8_t eval, uint8_t funcid, uint256 tokenid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string hearName); +CScript EncodeHeirAssetsOpRet(uint8_t eval, uint8_t funcid, uint256 tokenid, uint256 fundingtxid); +//CScript EncodeHeirConvertedAssetsOpRet(uint8_t eval, uint8_t funcid, uint256 tokenid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 fundingtxid); + +template uint256 FindLatestFundingTx(uint256 fundingtxid, uint256 &tokenid, CScript& opRetScript, bool &isHeirSpendingBegan); +template uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256 &tokenid, uint256& fundingtxid, bool noLogging = false); +//template uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging = false); +template uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging = false); + +//int64_t AddHeirTokenInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 reftokenid, int64_t total, int32_t maxinputs); + + +// helper class to allow polymorphic behaviour for HeirXXX() functions in case of coins +class CoinHelper { +public: + + static bool isMyFuncId(uint8_t funcid) { return IS_CHARINSTR(funcid, "FAC"); } + static uint8_t getMyEval() { return EVAL_HEIR; } + static int64_t addOwnerInputs(struct CCcontract_info* cp, uint256 dummyid, CMutableTransaction& mtx, CPubKey ownerPubkey, int64_t total, int32_t maxinputs) { + return AddNormalinputs(mtx, ownerPubkey, total, maxinputs); + } + + static CScript makeCreateOpRet(uint256 dummyid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName) { + return EncodeHeirCreateOpRet((uint8_t)EVAL_HEIR, (uint8_t)'F', ownerPubkey, heirPubkey, inactivityTimeSec, heirName); + } + static CScript makeAddOpRet(uint256 dummyid, uint256 fundingtxid) { + return EncodeHeirOpRet((uint8_t)EVAL_HEIR, (uint8_t)'A', fundingtxid); + } + static CScript makeClaimOpRet(uint256 dummyid, uint256 fundingtxid) { + return EncodeHeirOpRet((uint8_t)EVAL_HEIR, (uint8_t)'C', fundingtxid); + } + + static void UnmarshalOpret(std::vector vopret, uint8_t &e, uint8_t &funcId, uint256 &dummytokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret) { + E_UNMARSHAL(vopret, { ss >> e; ss >> funcId; ss >> ownerPubkey; ss >> heirPubkey; ss >> inactivityTime; if (IS_CHARINSTR(funcId, "F")) { ss >> heirName; } if (IS_CHARINSTR(funcId, "AC")) { ss >> fundingTxidInOpret; } }); + } + + static bool isSpendingTx(uint8_t funcid) { return (funcid == 'C'); } + + static CTxOut makeUserVout(int64_t amount, CPubKey myPubkey) { + return CTxOut(amount, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG); + } + static CTxOut makeClaimerVout(int64_t amount, CPubKey myPubkey) { + return CTxOut(amount, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG); + } +}; + +// helper class to allow polymorphic behaviour for HeirXXX() functions in case of tokens +class TokenHelper { +public: + + static bool isMyFuncId(uint8_t funcid) { return IS_CHARINSTR(funcid, "FAC"); } + static uint8_t getMyEval() { return EVAL_TOKENS; } + static int64_t addOwnerInputs(struct CCcontract_info* cp, uint256 tokenid, CMutableTransaction& mtx, CPubKey ownerPubkey, int64_t total, int32_t maxinputs) { + return AddTokenCCInputs(cp, mtx, ownerPubkey, tokenid, total, maxinputs); + } + + static CScript makeCreateOpRet(uint256 tokenid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName) { + return EncodeHeirAssetsCreateOpRet((uint8_t)EVAL_HEIR, (uint8_t)'F', tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName); + } + static CScript makeAddOpRet(uint256 tokenid, uint256 fundingtxid) { + return EncodeHeirAssetsOpRet((uint8_t)EVAL_HEIR, (uint8_t)'A', tokenid, fundingtxid); + } + static CScript makeClaimOpRet(uint256 tokenid, uint256 fundingtxid) { + return EncodeHeirAssetsOpRet((uint8_t)EVAL_HEIR, (uint8_t)'C', tokenid, fundingtxid); + } + + static void UnmarshalOpret(std::vector vopret, uint8_t &e, uint8_t &funcId, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingtxidInOpret) { + uint8_t assetFuncId = '\0'; + bool result = E_UNMARSHAL(vopret, { ss >> e; ss >> assetFuncId; ss >> tokenid; ss >> funcId; if (IS_CHARINSTR(funcId, "F")) { ss >> ownerPubkey; ss >> heirPubkey; ss >> inactivityTime; ss >> heirName; } if (IS_CHARINSTR(funcId, "AC")) { ss >> fundingtxidInOpret; } }); + if (!result /*|| assetFuncId != 't' -- any tx is ok*/) + funcId = 0; + } + static bool isSpendingTx(uint8_t funcid) { return (funcid == 'C'); } + + static CTxOut makeUserVout(int64_t amount, CPubKey myPubkey) { + return MakeCC1vout(EVAL_TOKENS, amount, myPubkey); + } + static CTxOut makeClaimerVout(int64_t amount, CPubKey myPubkey) { + return MakeCC1vout(EVAL_TOKENS, amount, myPubkey); + } +}; + +//#define OPTIONAL_VOUT 0 // if vout is optional then in a validation plan it will be skipped without error, if all validators return false + + + +/** +* Small framework for vins and vouts validation implementing a variation of 'chain of responsibility' pattern: +* It consists of two classes CInputValidationPlan and COutputValidationPlan which both are configured with an array of vectors of validators +* (These validators are derived from the class CValidatorBase). +* +* A example of a validator may verify for a vout if its public key corresponds to the public key which is stored in opreturn. +* Or, vin validator may check if this vin depicts correctly to the CC contract's address. +* +* For validating vins CInputValidator additionally is provided with an instance of a class derived from the CInputIdentifierBase class. +* this identifier class allows to select identical vins (for example, normal vins or cc input vins) and apply validators from the corresponding vector to it. +* Note: CInputValidator treats that at least one identified vin should be present, otherwise it returns eval->invalid() and false. +* +* For validating vouts COutputValidator is configured for each vector of validators with the vout index to which these validators are applied +* (see constructors of both CInputValidator and COutputValidator) +* +* +* Base class for all validators +*/ +/** + * base class for all validators + */ +class CValidatorBase +{ +public: + CValidatorBase(CCcontract_info* cp) : m_cp(cp) {} + virtual bool isVinValidator() const = 0; + virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const = 0; + virtual bool validateVout(CTxOut vout, std::string& message) const = 0; + +protected: + CCcontract_info * m_cp; +}; + + +/** + * Base class for classes which identify vins as normal or cc inputs + */ +class CInputIdentifierBase +{ +public: + CInputIdentifierBase(CCcontract_info* cp) : m_cp(cp) {} + virtual std::string inputName() const = 0; + virtual bool identifyInput(CTxIn vin) const = 0; +protected: + CCcontract_info * m_cp; +}; + + + + +/** +* Encapsulates an array containing rows of validators +* Each row is a vector of validators (zero is possible) for validating vins or prev tx's vouts +* this validation plan is used for validating tx inputs +*/ +template +class CInputValidationPlan +{ + using ValidatorsRow = std::vector; + +public: + + // Pushes a row of validators for validating a vin or vout + // @param CInputIdentifierBase* pointer to class-identifier which determines several identical adjacent vins (like in schema "vin.0+: normal inputs") + // @param pargs parameter pack of zero or more pointer to validator objects + // Why pointers? because we store the base class in validators' row and then call its virtual functions + template + void pushValidators(CInputIdentifierBase *identifier, ARGS*... pargs) // validators row passed as variadic arguments CValidatorX *val1, CValidatorY *val2 ... + { + ValidatorsRow vValidators({ (TValidatorBase*)pargs... }); + m_arrayValidators.push_back(std::make_pair(identifier, vValidators)); + } + + // validate tx inputs and corresponding prev tx vouts + bool validate(const CTransaction& tx, Eval* eval) + { + std::string message = ""; + //std::cerr << "CInputValidationPlan::validate() starting vins validation..." << std::endl; + + int32_t ival = 0; + int32_t iv = 0; + int32_t numv = tx.vin.size(); + int32_t numValidators = m_arrayValidators.size(); + + // run over vins: + while (iv < numv && ival < numValidators) { + + int32_t identifiedCount = 0; + CInputIdentifierBase *identifier = m_arrayValidators[ival].first; + // check if this is 'our' input: + while (iv < numv && identifier->identifyInput(tx.vin[iv])) { + + // get prev tx: + CTransaction prevTx, *pPrevTxOrNull = NULL; + uint256 hashBlock; + + if (!eval->GetTxUnconfirmed(tx.vin[iv].prevout.hash, prevTx, hashBlock)) { + std::ostringstream stream; + stream << "can't find vinTx for vin=" << iv << "."; + return eval->Invalid(stream.str().c_str()); + } + pPrevTxOrNull = &prevTx; // TODO: get prev tx only if it required (i.e. if vout validators are present) + + // exec 'validators' from validator row of ival index, for tx.vin[iv] + if (!execValidatorsInRow(&tx, pPrevTxOrNull, iv, ival, message)) { + std::ostringstream stream; + stream << "invalid tx vin[" << iv << "]:" << message; + return eval->Invalid(stream.str().c_str()); // ... if not, return 'invalid' + } + + identifiedCount++; // how many vins we identified + iv++; // advance to the next vin + } + + // CInputValidationPlan treats that there must be at least one identified vin for configured validators' row + // like in 'vin.0: normal input' + if (identifiedCount == 0) { + std::ostringstream stream; + stream << "can't find required vins for " << identifier->inputName() << "."; + return eval->Invalid(stream.str().c_str()); + } + + ival++; // advance to the next validator row + // and it will try the same vin with the new CInputIdentifierBase and validators row + } + + // validation is successful if all validators have been used (i.e. ival = numValidators) + if (ival < numValidators) { + std::cerr << "CInputValidationPlan::validate() incorrect tx" << " ival=" << ival << " numValidators=" << numValidators << std::endl; + return eval->Invalid("incorrect tx structure: not all required vins are present."); + } + + std::cerr << "CInputValidationPlan::validate() returns with true" << std::endl; + return true; + } + +private: + // Executes validators from the requested row of validators (selected by iValidators) for selected vin or vout (selected by iv) + bool execValidatorsInRow(const CTransaction* pTx, const CTransaction* pPrevTx, int32_t iv, int32_t ival, std::string& refMessage) const + { + // check boundaries: + if (ival < 0 || ival >= m_arrayValidators.size()) { + std::cerr << "CInputValidationPlan::execValidatorsInRow() internal error: incorrect param ival=" << ival << " size=" << m_arrayValidators.size(); + refMessage = "internal error: incorrect param ival index"; + return false; + } + + if (iv < 0 || iv >= pTx->vin.size()) { + std::cerr << "CInputValidationPlan::execValidatorsInRow() internal error: incorrect param iv=" << iv << " size=" << m_arrayValidators.size(); + refMessage = "internal error: incorrect param iv index"; + return false; + } + + // get requested row of validators: + ValidatorsRow vValidators = m_arrayValidators[ival].second; + + std::cerr << "CInputValidationPlan::execValidatorsInRow() calling validators" << " for vin iv=" << iv << " ival=" << ival << std::endl; + + for (auto v : vValidators) { + bool result; + + if (v->isVinValidator()) + // validate this vin and previous vout: + result = v->validateVin(pTx->vin[iv], pPrevTx->vout[pTx->vin[iv].prevout.n], refMessage); + else + // if it is vout validator pass the previous tx vout: + result = v->validateVout( pPrevTx->vout[pTx->vin[iv].prevout.n], refMessage); + if (!result) { + return result; + } + } + return true; // validation OK + } + + +private: + //std::map m_arrayValidators; + std::vector< std::pair > m_arrayValidators; + +}; + + +/** +* Encapsulates an array containing rows of validators +* Each row is a vector of validators (zero is possible) for validating vouts +* this validation plan is used for validating tx outputs +*/ +template +class COutputValidationPlan +{ + using ValidatorsRow = std::vector; + +public: + // Pushes a row of validators for validating a vout + // @param ivout index to vout to validate + // @param pargs parameter pack of zero or more pointer to validator objects + // Why pointers? because we store base class and call its virtual functions + + template + void pushValidators(int32_t ivout, ARGS*... pargs) // validators row passed as variadic arguments CValidatorX *val1, CValidatorY *val2 ... + { + ValidatorsRow vValidators({ (TValidatorBase*)pargs... }); + m_arrayValidators.push_back(std::make_pair(ivout, vValidators)); + } + + // validate tx outputs + bool validate(const CTransaction& tx, Eval* eval) + { + std::string message = ""; + //std::cerr << "COutputValidationPlan::validateOutputs() starting vouts validation..." << std::endl; + + int32_t ival = 0; + int32_t numVouts = tx.vout.size(); + int32_t numValidators = m_arrayValidators.size(); + + // run over vouts: + while (ival < numValidators) { + + int32_t ivout = m_arrayValidators[ival].first; + if (ivout >= numVouts) { + std::cerr << "COutputValidationPlan::validate() incorrect tx" << "for ival=" << ival << " in tx.vout no such ivout=" << ivout << std::endl; + return eval->Invalid("incorrect tx structure: not all required vouts are present."); + } + else + { + // exec 'validators' from validator row of ival index, for tx.vout[ivout] + if (!execValidatorsInRow(&tx, ivout, ival, message)) { + std::ostringstream stream; + stream << "invalid tx vout[" << ivout << "]:" << message; + return eval->Invalid(stream.str().c_str()); // ... if not, return 'invalid' + } + } + + ival++; // advance to the next vout + + } + + std::cerr << "COutputValidationPlan::validate() returns with true" << std::endl; + return true; + } + +private: + // Executes validators from the requested row of validators (selected by iValidators) for selected vin or vout (selected by iv) + bool execValidatorsInRow(const CTransaction* pTx, int32_t iv, int32_t ival, std::string& refMessage) const + { + // check boundaries: + if (ival < 0 || ival >= m_arrayValidators.size()) { + std::cerr << "COutputValidationPlan::execValidatorsInRow() internal error: incorrect param ival=" << ival << " size=" << m_arrayValidators.size(); + refMessage = "internal error: incorrect param ival index"; + return false; + } + + if (iv < 0 || iv >= pTx->vout.size()) { + std::cerr << "COutputValidationPlan::execValidatorsInRow() internal error: incorrect param iv=" << iv << " size=" << m_arrayValidators.size(); + refMessage = "internal error: incorrect param iv index"; + return false; + } + + // get requested row of validators: + ValidatorsRow vValidators = m_arrayValidators[ival].second; + + std::cerr << "COutputValidationPlan::execRow() calling validators" << " for vout iv=" << iv << " ival=" << ival << std::endl; + + for (auto v : vValidators) { + + if (!v->isVinValidator()) { + // if this is a 'in' validation plan then pass the previous tx vout: + bool result = v->validateVout(pTx->vout[iv], refMessage); + if (!result) + return result; + } + } + return true; // validation OK + } + + +private: + //std::map m_mapValidators; + std::vector< std::pair > m_arrayValidators; + +}; + + +class CNormalInputIdentifier : CInputIdentifierBase { +public: + CNormalInputIdentifier(CCcontract_info* cp) : CInputIdentifierBase(cp) {} + virtual std::string inputName() const { return std::string("normal input"); } + virtual bool identifyInput(CTxIn vin) const { + return !IsCCInput(vin.scriptSig); + } +}; + +class CCCInputIdentifier : CInputIdentifierBase { +public: + CCCInputIdentifier(CCcontract_info* cp) : CInputIdentifierBase(cp) {} + virtual std::string inputName() const { return std::string("CC input"); } + virtual bool identifyInput(CTxIn vin) const { + return IsCCInput(vin.scriptSig); + } +}; + + +/** +* Validates 1of2address for vout (may be used for either this or prev tx) +*/ +template class CCC1of2AddressValidator : CValidatorBase +{ +public: + CCC1of2AddressValidator(CCcontract_info* cp, CScript opRetScript, std::string customMessage = "") : + m_fundingOpretScript(opRetScript), m_customMessage(customMessage), CValidatorBase(cp) {} + + virtual bool isVinValidator() const { return false; } + virtual bool validateVout(CTxOut vout, std::string& message) const + { + //std::cerr << "CCC1of2AddressValidator::validateVout() entered" << std::endl; + uint8_t funcId; + CPubKey ownerPubkey, heirPubkey; + int64_t inactivityTime; + std::string heirName; + uint256 tokenid; + + if ((funcId = DecodeHeirOpRet(m_fundingOpretScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName)) == 0) { + message = m_customMessage + std::string(" invalid opreturn format"); + std::cerr << "CCC1of2AddressValidator::validateVout() exits with false: " << message << std::endl; + return false; + } + + char shouldBeAddr[65], ccAddr[65]; + + GetCCaddress1of2(m_cp, shouldBeAddr, ownerPubkey, heirPubkey); + if (vout.scriptPubKey.IsPayToCryptoCondition()) { + if (Getscriptaddress(ccAddr, vout.scriptPubKey) && strcmp(shouldBeAddr, ccAddr) == 0) { + std::cerr << "CCC1of2AddressValidator::validateVout() exits with true" << std::endl; + return true; + } + else { + message = m_customMessage + std::string(" incorrect heir funding address: incorrect pubkey(s)"); + } + } + else { + message = m_customMessage + std::string(" incorrect heir funding address: not a 1of2addr"); + } + + std::cerr << "CCC1of2AddressValidator::validateVout() exits with false: " << message << std::endl; + return false; + } + virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return false; } + +private: + CScript m_fundingOpretScript; + std::string m_customMessage; +}; + + +/** +* Validates if this is vout to owner or heir from opret (funding or change) +*/ +template class CMyPubkeyVoutValidator : CValidatorBase +{ +public: + CMyPubkeyVoutValidator(CCcontract_info* cp, CScript opRetScript, bool checkNormals) + : m_fundingOpretScript(opRetScript), m_checkNormals(checkNormals), CValidatorBase(cp) { } + + virtual bool isVinValidator() const { return false; } + virtual bool validateVout(CTxOut vout, std::string& message) const + { + //std::cerr << "CMyPubkeyVoutValidator::validateVout() entered" << std::endl; + + uint8_t funcId; + CPubKey ownerPubkey, heirPubkey; + int64_t inactivityTime; + std::string heirName; + uint256 tokenid; + + ///std::cerr << "CMyPubkeyVoutValidator::validateVout() m_opRetScript=" << m_opRetScript.ToString() << std::endl; + // get both pubkeys: + if ((funcId = DecodeHeirOpRet(m_fundingOpretScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName)) == 0) { + message = std::string("invalid opreturn format"); + return false; + } + + CScript ownerScript; + CScript heirScript; + if (m_checkNormals) { + ownerScript = CoinHelper::makeUserVout(vout.nValue, ownerPubkey).scriptPubKey; + heirScript = CoinHelper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey; + } + else { + ownerScript = Helper::makeUserVout(vout.nValue, ownerPubkey).scriptPubKey; + heirScript = Helper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey; + } + + //std::cerr << "CMyPubkeyVoutValidator::validateVout() vout.scriptPubKey=" << vout.scriptPubKey.ToString() << " makeUserVout=" << Helper::makeUserVout(vout.nValue, ownerPubkey).scriptPubKey.ToString() << std::endl; + + // recreate scriptPubKey for owner and heir and compare it with that of the vout to check: + if (vout.scriptPubKey == ownerScript || vout.scriptPubKey == heirScript) { + // this is vout to owner or heir addr: + std::cerr << "CMyPubkeyVoutValidator::validateVout() exits with true" << std::endl; + return true; + + } + + std::cerr << "CMyPubkeyVoutValidator::validateVout() exits with false (not the owner's or heir's addresses)" << std::endl; + return false; + } + virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } + +private: + CScript m_fundingOpretScript; + //uint256 m_lasttxid; + bool m_checkNormals; +}; + +/** +* Check if the user is the heir and the heir is allowed to spend (duration > inactivityTime) +*/ +template class CHeirSpendValidator : CValidatorBase +{ +public: + CHeirSpendValidator(CCcontract_info* cp, CScript opRetScript, uint256 latesttxid, bool isHeirSpendingBegan) + : m_fundingOpretScript(opRetScript), m_latesttxid(latesttxid), m_isHeirSpendingBegan(isHeirSpendingBegan), CValidatorBase(cp) {} + + virtual bool isVinValidator() const { return false; } + virtual bool validateVout(CTxOut vout, std::string& message) const + { + //std::cerr << "CHeirSpendValidator::validateVout() entered" << std::endl; + + uint8_t funcId; + CPubKey ownerPubkey, heirPubkey; + int64_t inactivityTime; + std::string heirName; + uint256 tokenid; + + + // get heir pubkey: + if ((funcId = DecodeHeirOpRet(m_fundingOpretScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, false)) == 0) { + message = std::string("invalid opreturn format"); + return false; + } + + int32_t numblocks; + int64_t durationSec = CCduration(numblocks, m_latesttxid); + + // recreate scriptPubKey for heir and compare it with that of the vout: + if (vout.scriptPubKey == Helper::makeClaimerVout(vout.nValue, heirPubkey).scriptPubKey) { + // this is the heir is trying to spend + if (!m_isHeirSpendingBegan && durationSec <= inactivityTime) { + message = "heir is not allowed yet to spend funds"; + std::cerr << "CHeirSpendValidator::validateVout() heir is not allowed yet to spend funds" << std::endl; + return false; + } + else { + // heir is allowed to spend + return true; + } + } + + std::cerr << "CHeirSpendValidator::validateVout() exits with true" << std::endl; + + // this is not heir: + return true; + } + virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } + +private: + CScript m_fundingOpretScript; + uint256 m_latesttxid; + bool m_isHeirSpendingBegan; +}; + +/** +* Validates this opreturn and compares it with the opreturn from the previous tx +*/ +template class COpRetValidator : CValidatorBase +{ +public: + COpRetValidator(CCcontract_info* cp, CScript opret) + : m_fundingOpretScript(opret), CValidatorBase(cp) {} + + virtual bool isVinValidator() const { return false; } + virtual bool validateVout(CTxOut vout, std::string& message) const + { + //std::cerr << "COpRetValidator::validateVout() entered" << std::endl; + + uint8_t funcId, initialFuncId; // do not check heir name + uint256 fundingTxidInOpret = zeroid, dummyTxid, tokenid, initialTokenid; + + if ((funcId = DecodeHeirOpRet(vout.scriptPubKey, tokenid, fundingTxidInOpret)) == 0) { + message = std::string("invalid opreturn format"); + return false; + } + if ((initialFuncId = DecodeHeirOpRet(m_fundingOpretScript, initialTokenid, dummyTxid)) == 0) { + message = std::string("invalid initial tx opreturn format"); + return false; + } + + // validation rules: + if (!Helper::isMyFuncId(funcId)) { + message = std::string("invalid funcid in opret"); + return false; + } + + if(tokenid != initialTokenid ) { + message = std::string("invalid tokenid in opret"); + return false; + } + + std::cerr << "COpRetValidator::validateVout() exits with true" << std::endl; + return true; + } + virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } + +private: + CScript m_fundingOpretScript; +}; + + + +#endif \ No newline at end of file diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 94403bcc0..5c32b2f5a 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -406,8 +406,16 @@ static const CRPCCommand vRPCCommands[] = { "faucet", "faucetget", &faucetget, true }, { "faucet", "faucetaddress", &faucetaddress, true }, - // Heir - { "heir", "heiraddress", &heiraddress, true }, + // Heir + { "heir", "heiraddress", &heiraddress, true }, + { "heir", "heirfund", &heirfund, true }, + { "heir", "heiradd", &heiradd, true }, + { "heir", "heirclaim", &heirclaim, true }, + { "heir", "heirfundtokens", &heirfundtokens, true }, + { "heir", "heiraddtokens", &heiraddtokens, true }, + { "heir", "heirclaimtokens", &heirclaimtokens, true }, + { "heir", "heirinfo", &heirinfo, true }, + { "heir", "heirlist", &heirlist, true }, // Channels { "channels", "channelsaddress", &channelsaddress, true }, @@ -479,7 +487,8 @@ static const CRPCCommand vRPCCommands[] = { "dice", "dicestatus", &dicestatus, true }, { "dice", "diceaddress", &diceaddress, true }, - // tokens + // tokens & assets + { "tokens", "assetsaddress", &assetsaddress, true }, { "tokens", "tokeninfo", &tokeninfo, true }, { "tokens", "tokenlist", &tokenlist, true }, { "tokens", "tokenorders", &tokenorders, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 920aac970..7c85c43b6 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -242,6 +242,7 @@ extern UniValue tokeninfo(const UniValue& params, bool fHelp); extern UniValue tokenlist(const UniValue& params, bool fHelp); extern UniValue tokenorders(const UniValue& params, bool fHelp); extern UniValue tokenbalance(const UniValue& params, bool fHelp); +extern UniValue assetsaddress(const UniValue& params, bool fHelp); extern UniValue tokenaddress(const UniValue& params, bool fHelp); extern UniValue tokencreate(const UniValue& params, bool fHelp); extern UniValue tokentransfer(const UniValue& params, bool fHelp); @@ -253,6 +254,14 @@ extern UniValue tokencancelask(const UniValue& params, bool fHelp); extern UniValue tokenfillask(const UniValue& params, bool fHelp); extern UniValue tokenconvert(const UniValue& params, bool fHelp); extern UniValue heiraddress(const UniValue& params, bool fHelp); +extern UniValue heirfund(const UniValue& params, bool fHelp); +extern UniValue heiradd(const UniValue& params, bool fHelp); +extern UniValue heirclaim(const UniValue& params, bool fHelp); +extern UniValue heirfundtokens(const UniValue& params, bool fHelp); +extern UniValue heiraddtokens(const UniValue& params, bool fHelp); +extern UniValue heirclaimtokens(const UniValue& params, bool fHelp); +extern UniValue heirinfo(const UniValue& params, bool fHelp); +extern UniValue heirlist(const UniValue& params, bool fHelp); extern UniValue channelsaddress(const UniValue& params, bool fHelp); extern UniValue oraclesaddress(const UniValue& params, bool fHelp); extern UniValue oracleslist(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 0dcaaa848..b39a19668 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5417,27 +5417,145 @@ UniValue gatewaysaddress(const UniValue& params, bool fHelp) UniValue heiraddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector destPubkey; + /* + struct CCcontract_info *cp,C; std::vector pubkey; + cp = CCinit(&C,EVAL_HEIR); + if ( fHelp || params.size() > 1 ) + throw runtime_error("heiraddress [pubkey]\n"); + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + if ( params.size() == 1 ) + pubkey = ParseHex(params[0].get_str().c_str()); + return(CCaddress(cp,(char *)"Heir",pubkey)); + */ - cp = CCinit(&C,EVAL_HEIR); - if ( fHelp || (params.size() != 4 && params.size() != 3)) - throw runtime_error("heiraddress func txid amount [destpubkey]\n"); - if ( ensure_CCrequirements() < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - //if ( params.size() == 1 ) - // pubkey = ParseHex(params[0].get_str().c_str()); - char funcid = ((char *)params[0].get_str().c_str())[0]; - uint256 assetid = Parseuint256((char *)params[1].get_str().c_str()); - int64_t funds = atof(params[2].get_str().c_str()) * COIN ; - if(params.size() == 4) - destPubkey = ParseHex(params[3].get_str().c_str()); + // make fake token tx: + struct CCcontract_info *cp, C; - //return HeirFundBad(funcid, assetid, funds, destPubkey); + if (fHelp || (params.size() < 1)) + throw runtime_error("heiraddress A|G|H|T|R assetid|destpubkey amountcoins [heirpubkey] [fundingtxid]\n"); + if (ensure_CCrequirements() < 0) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - return(CCaddress(cp,(char *)"Heir",destPubkey)); + char badKind = ((char *)params[0].get_str().c_str())[0]; + + if (badKind == 'A') { + std::vector destPubkey; + if (params.size() == 2) { + cp = CCinit(&C, EVAL_HEIR); + destPubkey = ParseHex(params[1].get_str().c_str()); + return(CCaddress(cp, (char *)"Heir", destPubkey)); + } + else + return std::string("bad params for A"); + } + + CPubKey myPubkey = pubkey2pk(Mypubkey()); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());; + + if (badKind != 'R') { + + if (badKind == 'G' && params.size() != 3) + return std::string("incorrect params for G"); + if (badKind == 'H' && params.size() != 5) + return std::string("incorrect params for H, = 5"); + if (badKind == 'T' && params.size() != 3) + return std::string("incorrect params for T, = 3"); + + + uint256 assetid = Parseuint256((char *)params[1].get_str().c_str()); + int64_t amount = atof(params[2].get_str().c_str()) * COIN; + + uint256 fundingtxid; + CPubKey heirPubkey; + + if (badKind == 'H') { + + std::vector heirPubkeyStr = ParseHex(params[3].get_str().c_str()); + heirPubkey = pubkey2pk(heirPubkeyStr); + + fundingtxid = Parseuint256((char *)params[4].get_str().c_str()); + } + + + + int64_t txfee = 10000; + + uint8_t evalCodeInOpret = (badKind == 'H') ? EVAL_HEIR : EVAL_GATEWAYS; + cp = CCinit(&C, EVAL_ASSETS); + + int64_t normalInputs = AddNormalinputs(mtx, myPubkey, txfee + amount, 60); + // int64_t ccInputs = 0; + + + if (badKind == 'T') { + // just empty fake token + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, amount, myPubkey)); //note you need destPubkey for sending to gateways + } + else if (badKind == 'H') { + // heir add funding tx + mtx.vout.push_back(MakeCC1of2vout(EVAL_ASSETS, amount, myPubkey, heirPubkey)); // add cryptocondition to spend amount for either pk + } + else { // if (badKind == 'G') + CPubKey gatewayContractPubKey = GetUnspendable(cp, 0); + mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(gatewayContractPubKey)) << OP_CHECKSIG)); + } + + int64_t change = (normalInputs - amount); + if (change != 0) { + mtx.vout.push_back(CTxOut(change, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG)); + } + std::cerr << "make fake token for contract=" << badKind << " added normalInputs=" << normalInputs << " change=" << change << std::endl; + + // note: it sets eval=EVAL_ASSETS in opreturn both for tokens and gateways cc addr + //script = EncodeAssetOpRet('t', assetid, zeroid, 0, (badKind == 'A' ? Mypubkey() : destPubkey)); // dimxy: are we sure about destPubkey here? it may be just pubkey of the author... + CScript opret; + assetid = revuint256(assetid); + fundingtxid = revuint256(fundingtxid); + if (badKind == 'T') + opret << OP_RETURN << E_MARSHAL(ss << (uint8_t)evalCodeInOpret << (uint8_t)'t' << assetid ); + else if (badKind == 'H') + opret << OP_RETURN << E_MARSHAL(ss << (uint8_t)evalCodeInOpret << (uint8_t)'t' << assetid << (uint8_t)'A' << myPubkey << heirPubkey << (int64_t)120 << fundingtxid); + else + opret << OP_RETURN << E_MARSHAL(ss << (uint8_t)evalCodeInOpret << (uint8_t)'t' << assetid); // EVAL_GATEWAYS + + return(FinalizeCCTx(0, cp, mtx, myPubkey, txfee, opret)); // normal change added here + } + else + { + // move vout from user cc addr to gateways unspendable + CTransaction srctx; + + uint256 hashBlock; + const bool allowSlow = false; + uint256 srctxid = Parseuint256((char *)params[1].get_str().c_str()); + + struct CCcontract_info *cp, C; + cp = CCinit(&C, EVAL_GATEWAYS); + + uint64_t txfee = 10000; + CPubKey gatewayspk = GetUnspendable(cp, 0); + + if (myGetTransaction(srctxid, srctx, hashBlock) && srctx.vout.size() > 0) { + + int64_t normalInputs = AddNormalinputs(mtx, myPubkey, 2 * txfee, 4); + + mtx.vin.push_back(CTxIn(srctxid, 2, CScript())); // repaired src tx + mtx.vout.push_back(MakeCC1vout(EVAL_GATEWAYS, srctx.vout[2].nValue, gatewayspk)); + + CScript script = srctx.vout[srctx.vout.size() - 1].scriptPubKey; + + //mtx.fOverwintered = true; + + return(FinalizeCCTx(0, cp, mtx, myPubkey, txfee, script)); // normal change added here + } + } + return std::string("there has been some error"); } + + UniValue lottoaddress(const UniValue& params, bool fHelp) { struct CCcontract_info *cp,C; std::vector pubkey; @@ -5518,17 +5636,30 @@ UniValue rewardsaddress(const UniValue& params, bool fHelp) return(CCaddress(cp,(char *)"Rewards",pubkey)); } +UniValue assetsaddress(const UniValue& params, bool fHelp) +{ + struct CCcontract_info *cp, C; std::vector pubkey; + cp = CCinit(&C, EVAL_ASSETS); + if (fHelp || params.size() > 1) + throw runtime_error("assetsaddress [pubkey]\n"); + if (ensure_CCrequirements() < 0) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + if (params.size() == 1) + pubkey = ParseHex(params[0].get_str().c_str()); + return(CCaddress(cp, (char *)"Assets", pubkey)); +} + UniValue tokenaddress(const UniValue& params, bool fHelp) { struct CCcontract_info *cp,C; std::vector pubkey; - cp = CCinit(&C,EVAL_ASSETS); + cp = CCinit(&C,EVAL_TOKENS); if ( fHelp || params.size() > 1 ) throw runtime_error("tokenaddress [pubkey]\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); if ( params.size() == 1 ) pubkey = ParseHex(params[0].get_str().c_str()); - return(CCaddress(cp,(char *)"Assets",pubkey)); + return(CCaddress(cp,(char *)"Tokens", pubkey)); } UniValue marmara_poolpayout(const UniValue& params, bool fHelp) @@ -6895,7 +7026,7 @@ UniValue tokencreate(const UniValue& params, bool fHelp) return(result); } } - hex = CreateAsset(0,supply,name,description); + hex = CreateToken(0,supply,name,description); if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); @@ -6927,7 +7058,7 @@ UniValue tokentransfer(const UniValue& params, bool fHelp) ERR_RESULT("amount must be positive"); return(result); } - hex = AssetTransfer(0,tokenid,pubkey,amount); + hex = TokenTransfer(0,tokenid,pubkey,amount); if (amount > 0) { if ( hex.size() > 0 ) { @@ -6964,7 +7095,11 @@ UniValue tokenconvert(const UniValue& params, bool fHelp) ERR_RESULT("amount must be positive"); return(result); } - hex = AssetConvert(0,tokenid,pubkey,amount,evalcode); + + ERR_RESULT("deprecated"); + return(result); + +/* hex = AssetConvert(0,tokenid,pubkey,amount,evalcode); if (amount > 0) { if ( hex.size() > 0 ) { @@ -6974,7 +7109,7 @@ UniValue tokenconvert(const UniValue& params, bool fHelp) } else { ERR_RESULT("amount must be positive"); } - return(result); + return(result); */ } UniValue tokenbid(const UniValue& params, bool fHelp) @@ -7271,6 +7406,270 @@ UniValue getbalance64(const UniValue& params, bool fHelp) return ret; } +// heir contract functions for coins +UniValue heirfund(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); + //uint256 txid; + int64_t txfee; + int64_t amount; + int64_t inactivitytime; + std::string hex; + std::vector pubkey; + std::string name; + + //TODO: do we need this? + if (!EnsureWalletIsAvailable(fHelp)) + return NullUniValue; + + if (fHelp || params.size() != 5) + throw runtime_error("heirfund fee funds heirname heirpubkey inactivitytime\n"); + if (ensure_CCrequirements() < 0) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + + txfee = atof((char*)params[0].get_str().c_str()) * COIN; + amount = atof((char*)params[1].get_str().c_str()) * COIN; + name = params[2].get_str(); + pubkey = ParseHex(params[3].get_str().c_str()); + inactivitytime = atof((char*)params[4].get_str().c_str()); + + + hex = HeirFundCoinCaller(txfee, amount, name, pubkey2pk(pubkey), inactivitytime, zeroid); + if (hex.size() > 0) { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } + else + ERR_RESULT("couldn't create heir fund"); + + return result; +} + + +UniValue heiradd(const UniValue& params, bool fHelp) +{ + UniValue result; // UniValue result(UniValue::VOBJ); + uint256 fundingtxid; + uint64_t txfee; + int64_t amount; + int64_t inactivitytime; + std::string hex; + std::vector pubkey; + std::string name; + + // TODO: do we need this? + if (!EnsureWalletIsAvailable(fHelp)) + return NullUniValue; + + if (fHelp || params.size() != 3) + throw runtime_error("heiradd fee funds fundingtxid\n"); + if (ensure_CCrequirements() < 0) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + + txfee = atof((char*)params[0].get_str().c_str()) * COIN; + amount = atof((char*)params[1].get_str().c_str()) * COIN; + fundingtxid = Parseuint256((char*)params[2].get_str().c_str()); + + result = HeirAddCoinCaller(fundingtxid, txfee, amount); + /* if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else ERR_RESULT("couldn't claim heir fund"); */ + + + return result; +} + +UniValue heirclaim(const UniValue& params, bool fHelp) +{ + UniValue result; // result(UniValue::VOBJ); + uint256 fundingtxid; + uint64_t txfee; + int64_t amount; + int64_t inactivitytime; + std::string hex; + std::vector pubkey; + std::string name; + + // do we need this? + if (!EnsureWalletIsAvailable(fHelp)) + return NullUniValue; + + if (fHelp || params.size() != 3) + throw runtime_error("heirclaim fee funds fundingtxid\n"); + if (ensure_CCrequirements() < 0) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + + txfee = atof((char*)params[0].get_str().c_str()) * COIN; + amount = atof((char*)params[1].get_str().c_str()) * COIN; + fundingtxid = Parseuint256((char*)params[2].get_str().c_str()); + + result = HeirClaimCoinCaller(fundingtxid, txfee, amount); + /* if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else ERR_RESULT("couldn't claim heir fund"); */ + + return result; +} + +// same heir contract functions for tokens +UniValue heirfundtokens(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); + uint256 assetid; + uint64_t txfee; + int64_t amount; + int64_t inactivitytime; + std::string hex; + std::vector pubkey; + std::string name; + + //TODO: do we need this (dimxy)? + if (!EnsureWalletIsAvailable(fHelp)) + return NullUniValue; + + if (fHelp || params.size() != 6) + throw runtime_error("heirfundtokens fee funds heirname heirpubkey inactivitytime assetid\n"); + if (ensure_CCrequirements() < 0) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + + txfee = atoll((char*)params[0].get_str().c_str()); + amount = atoll((char*)params[1].get_str().c_str()); + name = params[2].get_str(); + pubkey = ParseHex(params[3].get_str().c_str()); + inactivitytime = atof((char*)params[4].get_str().c_str()); + assetid = Parseuint256((char*)params[5].get_str().c_str()); + + + hex = HeirFundTokenCaller(txfee, amount, name, pubkey2pk(pubkey), inactivitytime, assetid); + if (hex.size() > 0) { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } + else + ERR_RESULT("couldn't create heir fund"); + + + return result; +} + + +UniValue heiraddtokens(const UniValue& params, bool fHelp) +{ + UniValue result; // UniValue result(UniValue::VOBJ); + uint256 fundingtxid; + uint64_t txfee; + int64_t amount; + int64_t inactivitytime; + std::string hex; + std::vector pubkey; + std::string name; + + // TODO: do we need this? + if (!EnsureWalletIsAvailable(fHelp)) + return NullUniValue; + + if (fHelp || params.size() != 3) + throw runtime_error("heiraddtokens fee funds fundingtxid\n"); + if (ensure_CCrequirements() < 0) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + + txfee = atoll((char*)params[0].get_str().c_str()); + amount = atoll((char*)params[1].get_str().c_str()); + fundingtxid = Parseuint256((char*)params[2].get_str().c_str()); + + result = HeirAddTokenCaller(fundingtxid, txfee, amount); + /* if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else ERR_RESULT("couldn't claim heir fund"); */ + + + return result; +} + +UniValue heirclaimtokens(const UniValue& params, bool fHelp) +{ + UniValue result; // result(UniValue::VOBJ); + uint256 fundingtxid; + int64_t txfee; + int64_t amount; + int64_t inactivitytime; + std::string hex; + std::vector pubkey; + std::string name; + + // do we need this? + if (!EnsureWalletIsAvailable(fHelp)) + return NullUniValue; + + if (fHelp || params.size() != 3) + throw runtime_error("heirclaimtokens fee funds fundingtxid\n"); + if (ensure_CCrequirements() < 0) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + + txfee = atoll((char*)params[0].get_str().c_str()); + amount = atoll((char*)params[1].get_str().c_str()); + fundingtxid = Parseuint256((char*)params[2].get_str().c_str()); + + result = HeirClaimTokenCaller(fundingtxid, txfee, amount); + /* if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else ERR_RESULT("couldn't claim heir fund"); */ + + return result; +} + +UniValue heirinfo(const UniValue& params, bool fHelp) +{ + uint256 fundingtxid; + if (fHelp || params.size() != 1) // or 0? + throw runtime_error("heirinfo fundingtxid\n"); + // if ( ensure_CCrequirements() < 0 ) + // throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + + fundingtxid = Parseuint256((char*)params[0].get_str().c_str()); + return (HeirInfo(fundingtxid)); +} + +UniValue heirlist(const UniValue& params, bool fHelp) +{ + if (fHelp || params.size() != 0) // or 0? + throw runtime_error("heirlist\n"); + + // if ( ensure_CCrequirements() < 0 ) + // throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + + return (HeirList()); +} + + + + extern UniValue dumpprivkey(const UniValue& params, bool fHelp); // in rpcdump.cpp extern UniValue importprivkey(const UniValue& params, bool fHelp); extern UniValue importaddress(const UniValue& params, bool fHelp); From be71d108b296df1a6ac540af90bee4996a3d947f Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 7 Jan 2019 23:21:57 +0500 Subject: [PATCH 359/643] Added CCaddr1of2set and FinalizeCCtx modified to support it (small test CCerror code added - temp) --- src/cc/CCassetstx.cpp | 65 +++++++++++++++++++++++----------------- src/cc/CCinclude.h | 28 +++++++++++++---- src/cc/CCtx.cpp | 24 +++++++++++---- src/cc/CCutils.cpp | 8 +++++ src/cc/heir.cpp | 9 +++--- src/wallet/rpcwallet.cpp | 8 +++++ 6 files changed, 100 insertions(+), 42 deletions(-) diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index cae4b42bb..17c16bd6a 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -393,7 +393,7 @@ std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t p uint64_t mask; int64_t inputs, CCchange; CScript opret; - struct CCcontract_info *cp,C; + struct CCcontract_info *cpTokens,C; //std::cerr << "CreateSell() askamount=" << askamount << " pricetotal=" << pricetotal << std::endl; @@ -402,16 +402,16 @@ std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t p return(""); } - cp = CCinit(&C, EVAL_TOKENS); // NOTE: tokens is here + cpTokens = CCinit(&C, EVAL_TOKENS); // NOTE: tokens is here - if ( txfee == 0 ) + if (txfee == 0) txfee = 10000; mypk = pubkey2pk(Mypubkey()); if (AddNormalinputs(mtx, mypk, txfee, 3) > 0) { mask = ~((1LL << mtx.vin.size()) - 1); - if ((inputs = AddTokenCCInputs(cp, mtx, mypk, assetid, askamount, 60)) > 0) + if ((inputs = AddTokenCCInputs(cpTokens, mtx, mypk, assetid, askamount, 60)) > 0) { if (inputs < askamount) { //was: askamount = inputs; @@ -420,14 +420,14 @@ std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t p return (""); } - mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS,askamount, GetUnspendable(cp,0))); + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS,askamount, GetUnspendable(cpTokens,0))); if (inputs > askamount) CCchange = (inputs - askamount); if (CCchange != 0) mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, CCchange, mypk)); opret = EncodeAssetOpRet('s',assetid, zeroid, pricetotal, Mypubkey()); - return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,opret)); + return(FinalizeCCTx(mask,cpTokens,mtx,mypk,txfee,opret)); } else { fprintf(stderr, "need some tokens to place ask\n"); @@ -439,6 +439,7 @@ std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t p return(""); } +////////////////////////// NOT IMPLEMENTED YET///////////////////////////////// std::string CreateSwap(int64_t txfee,int64_t askamount,uint256 assetid,uint256 assetid2,int64_t pricetotal) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); @@ -497,7 +498,7 @@ std::string CreateSwap(int64_t txfee,int64_t askamount,uint256 assetid,uint256 a } return(""); -} +} ////////////////////////// NOT IMPLEMENTED YET///////////////////////////////// // unlocks coins std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid) @@ -508,11 +509,11 @@ std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid) uint256 hashBlock; int64_t bidamount; CPubKey mypk; - struct CCcontract_info *cp,C; + struct CCcontract_info *cpAssets, C; - cp = CCinit(&C, EVAL_ASSETS); + cpAssets = CCinit(&C, EVAL_ASSETS); - if ( txfee == 0 ) + if (txfee == 0) txfee = 10000; mypk = pubkey2pk(Mypubkey()); @@ -525,7 +526,7 @@ std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid) bidamount = vintx.vout[0].nValue; mtx.vin.push_back(CTxIn(bidtxid, 0, CScript())); mtx.vout.push_back(CTxOut(bidamount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - return(FinalizeCCTx(mask, cp, mtx, mypk, txfee, EncodeAssetOpRet('o', assetid, zeroid, 0, Mypubkey()))); + return(FinalizeCCTx(mask, cpAssets, mtx, mypk, txfee, EncodeAssetOpRet('o', assetid, zeroid, 0, Mypubkey()))); } } return(""); @@ -536,11 +537,11 @@ std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CTransaction vintx; uint64_t mask; uint256 hashBlock; int64_t askamount; CPubKey mypk; - struct CCcontract_info *cp,C; + struct CCcontract_info *cpTokens, C; - cp = CCinit(&C, EVAL_TOKENS); + cpTokens = CCinit(&C, EVAL_TOKENS); - if ( txfee == 0 ) + if (txfee == 0) txfee = 10000; mypk = pubkey2pk(Mypubkey()); @@ -553,7 +554,7 @@ std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) askamount = vintx.vout[0].nValue; mtx.vin.push_back(CTxIn(asktxid, 0, CScript())); mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, askamount, mypk)); - return(FinalizeCCTx(mask, cp, mtx, mypk, txfee, EncodeAssetOpRet('x', assetid, zeroid, 0, Mypubkey()))); + return(FinalizeCCTx(mask, cpTokens, mtx, mypk, txfee, EncodeAssetOpRet('x', assetid, zeroid, 0, Mypubkey()))); } } return(""); @@ -570,16 +571,18 @@ std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t f int32_t bidvout=0; uint64_t mask; int64_t origprice, bidamount, paid_amount, remaining_required, inputs, CCchange=0; - struct CCcontract_info *cp,C; + struct CCcontract_info *cpTokens, tokensC; + struct CCcontract_info *cpAssets, assetsC; if (fillamount < 0) { fprintf(stderr,"negative fillamount %lld\n", (long long)fillamount); return(""); } - cp = CCinit(&C, EVAL_TOKENS); + cpTokens = CCinit(&tokensC, EVAL_TOKENS); + cpAssets = CCinit(&assetsC, EVAL_ASSETS); - if ( txfee == 0 ) + if (txfee == 0) txfee = 10000; mypk = pubkey2pk(Mypubkey()); @@ -594,7 +597,7 @@ std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t f mtx.vin.push_back(CTxIn(bidtxid, bidvout, CScript())); - if ((inputs = AddTokenCCInputs(cp, mtx, mypk, assetid, fillamount, 60)) > 0) + if ((inputs = AddTokenCCInputs(cpTokens, mtx, mypk, assetid, fillamount, 60)) > 0) { if (inputs < fillamount) { std::cerr << "FillBuyOffer(): insufficient tokens to fill buy offer" << std::endl; @@ -607,16 +610,24 @@ std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t f if (inputs > fillamount) CCchange = (inputs - fillamount); - mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, bidamount - paid_amount, GetUnspendable(cp,0))); // tokens + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, bidamount - paid_amount, GetUnspendable(cpTokens, NULL))); // tokens mtx.vout.push_back(CTxOut(paid_amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, fillamount, pubkey2pk(origpubkey))); // coins + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, fillamount, pubkey2pk(origpubkey))); // coins on assets if (CCchange != 0) - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, CCchange, mypk)); // coins + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, CCchange, mypk)); // coins on assets fprintf(stderr,"remaining %llu -> origpubkey\n", (long long)remaining_required); - return(FinalizeCCTx(mask,cp,mtx,mypk,txfee, EncodeAssetOpRet('B', assetid, zeroid, remaining_required, origpubkey))); + // add additional unspendable addr from Assets: + char unspendableAssetsAddr[64]; + uint8_t unspendableAssetsPrivkey[32]; + + CPubKey unspendableAssetsPk = GetUnspendable(cpAssets, unspendableAssetsPrivkey); + GetCCaddress(cpAssets, unspendableAssetsAddr, unspendableAssetsPk); + CCaddr2set(cpTokens, EVAL_ASSETS, unspendableAssetsPk, unspendableAssetsPrivkey, unspendableAssetsAddr); + + return(FinalizeCCTx(mask,cpTokens,mtx,mypk,txfee, EncodeAssetOpRet('B', assetid, zeroid, remaining_required, origpubkey))); } else return("dont have any assets to fill bid\n"); } } @@ -694,16 +705,16 @@ std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 askt if (assetid2 != zeroid && inputs > paid_nValue) CCchange = (inputs - paid_nValue); - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, orig_assetoshis - received_assetoshis, GetUnspendable(cpAssets, NULL))); // coins + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, orig_assetoshis - received_assetoshis, GetUnspendable(cpAssets, NULL))); // coins in Assets cc addr mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, received_assetoshis, mypk)); // tokens if (assetid2 != zeroid) - mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, paid_nValue, origpubkey)); // tokens (not implemented correctly) + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, paid_nValue, origpubkey)); // tokens... (swap is not implemented yet) else - mtx.vout.push_back(CTxOut(paid_nValue, CScript() << origpubkey << OP_CHECKSIG)); // coins + mtx.vout.push_back(CTxOut(paid_nValue, CScript() << origpubkey << OP_CHECKSIG)); // coins normal if (CCchange != 0) - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, CCchange, mypk)); // coins + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, CCchange, mypk)); // coins in Assets cc addr return(FinalizeCCTx(mask,cpTokens,mtx,mypk,txfee,EncodeAssetOpRet(assetid2 != zeroid ? 'E' : 'S', assetid, assetid2, remaining_nValue, origpubkey))); } else { diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 56c4b27d5..ec1557e2b 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -86,12 +86,27 @@ struct CC_meta struct CCcontract_info { - char unspendableCCaddr[64],CChexstr[72],normaladdr[64],unspendableaddr2[64],unspendableaddr3[64]; - uint8_t CCpriv[32],unspendablepriv2[32],unspendablepriv3[32]; - CPubKey unspendablepk2,unspendablepk3; - bool (*validate)(struct CCcontract_info *cp, Eval* eval, const CTransaction &tx, uint32_t nIn); - bool (*ismyvin)(CScript const& scriptSig); - uint8_t evalcode,evalcode2,evalcode3,didinit; + // this is for spending from 'unspendable' CC address + uint8_t evalcode; + char unspendableCCaddr[64], CChexstr[72], normaladdr[64]; + uint8_t CCpriv[32]; + + // this for 1of2 key spending condition (for this evalcode) + // NOTE: only one evalcode is allowed at this time + char unspendable1of2addr[64]; + CPubKey unspendable1of2pk[2]; + + // this is for spending from two additional 'unspendable' CC addresses of other eval codes + // (that is, for spending from several cc contract 'unspendable' addresses): + uint8_t evalcode2, evalcode3; + char unspendableaddr2[64], unspendableaddr3[64]; + uint8_t unspendablepriv2[32], unspendablepriv3[32]; + CPubKey unspendablepk2, unspendablepk3; + + bool (*validate)(struct CCcontract_info *cp, Eval* eval, const CTransaction &tx, uint32_t nIn); // cc contract tx validation callback + bool (*ismyvin)(CScript const& scriptSig); // checks if evalcode is present in the scriptSig param + + uint8_t didinit; }; struct CCcontract_info *CCinit(struct CCcontract_info *cp,uint8_t evalcode); @@ -164,6 +179,7 @@ CC *MakeCCcond1of2(uint8_t evalcode,CPubKey pk1,CPubKey pk2); CC* GetCryptoCondition(CScript const& scriptSig); void CCaddr2set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr); void CCaddr3set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr); +void CCaddr1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr); bool IsCCInput(CScript const& scriptSig); int32_t unstringbits(char *buf,uint64_t bits); uint64_t stringbits(char *str); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 57a2a327b..dc8b4788e 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -44,7 +44,10 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran CTransaction vintx; std::string hex; uint256 hashBlock; uint64_t mask=0,nmask=0,vinimask=0; int64_t utxovalues[CC_MAXVINS],change,normalinputs=0,totaloutputs=0,normaloutputs=0,totalinputs=0,normalvins=0,ccvins=0; int32_t i,utxovout,n,err = 0; char myaddr[64],destaddr[64],unspendable[64]; - uint8_t *privkey,myprivkey[32],unspendablepriv[32],*msg32 = 0; CC *mycond=0,*othercond=0,*othercond2=0,*othercond3=0,*cond; CPubKey unspendablepk; + uint8_t *privkey,myprivkey[32],unspendablepriv[32],*msg32 = 0; + CC *mycond=0, *othercond=0, *othercond2=0, *othercond3=0, *othercond1of2=NULL, *cond; + CPubKey unspendablepk; + n = mtx.vout.size(); for (i=0; iunspendableaddr2) == 0) { //fprintf(stderr,"matched %s unspendable2!\n",cp->unspendableaddr2); privkey = cp->unspendablepriv2; - if ( othercond2 == 0 && cp->evalcode != EVAL_CHANNELS && cp->evalcode != EVAL_HEIR && cp->evalcode != EVAL_ASSETS && cp->evalcode != EVAL_TOKENS) - othercond2 = MakeCCcond1(cp->evalcode2,cp->unspendablepk2); - else if ( othercond2 == 0 && (cp->evalcode == EVAL_CHANNELS || cp->evalcode == EVAL_HEIR || cp->evalcode == EVAL_ASSETS || cp->evalcode == EVAL_TOKENS) ) - othercond2 = MakeCCcond1of2(cp->evalcode2,cp->unspendablepk2,cp->unspendablepk3); + if ( othercond2 == 0 ) //&& cp->evalcode != EVAL_CHANNELS && cp->evalcode != EVAL_HEIR && cp->evalcode != EVAL_ASSETS && cp->evalcode != EVAL_TOKENS) + othercond2 = MakeCCcond1(cp->evalcode2, cp->unspendablepk2); + //else if ( othercond2 == 0 && (cp->evalcode == EVAL_CHANNELS || cp->evalcode == EVAL_HEIR || cp->evalcode == EVAL_ASSETS || cp->evalcode == EVAL_TOKENS) ) + // othercond2 = MakeCCcond1of2(cp->evalcode2,cp->unspendablepk2,cp->unspendablepk3); cond = othercond2; } + // check if this is 3rd additional evalcode + 'unspendable' cc addr: else if ( strcmp(destaddr,cp->unspendableaddr3) == 0 ) { //fprintf(stderr,"matched %s unspendable3!\n",cp->unspendableaddr3); @@ -158,6 +163,15 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran othercond3 = MakeCCcond1(cp->evalcode3,cp->unspendablepk3); cond = othercond3; } + // check if this is spending from 1of2 cc addr: + else if (strcmp(cp->unspendable1of2addr, destaddr) == 0) + { + //fprintf(stderr,"matched %s unspendable1of2!\n",cp->unspendable1of2addr); + privkey = myprivkey; + if (othercond1of2 == 0) + othercond1of2 = MakeCCcond1of2(cp->evalcode, cp->unspendable1of2pk[0], cp->unspendable1of2pk[1]); + cond = othercond1of2; + } else { fprintf(stderr,"CC signing error: vini.%d has unknown CC address.(%s)\n",i,destaddr); diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index ed16805d7..c0fea0c9f 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -195,6 +195,14 @@ void CCaddr3set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t * strcpy(cp->unspendableaddr3,coinaddr); } +// set pubkeys, myprivkey and 1of2 cc addr for spending from 1of2 cryptocondition vout: +void CCaddr1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr) +{ + cp->unspendable1of2pk[0] = pk1; + cp->unspendable1of2pk[1] = pk2; + strcpy(cp->unspendable1of2addr, coinaddr); +} + bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey) { CTxDestination address; txnouttype whichType; diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 81318ad1e..90557d7ac 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -1061,11 +1061,12 @@ template UniValue HeirClaim(uint256 fundingtxid, uint64_t txfee GetCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); Myprivkey(myprivkey); - //fprintf(stderr,"HeirClaim() before setting unspendable CC addr2= (%s) addr3= (%s)\n", cp->unspendableaddr2, cp->unspendableaddr3); - CCaddr2set(cp, Helper::getMyEval(), ownerPubkey, myprivkey, coinaddr); - CCaddr3set(cp, Helper::getMyEval(), heirPubkey, myprivkey, coinaddr); + ////fprintf(stderr,"HeirClaim() before setting unspendable CC addr2= (%s) addr3= (%s)\n", cp->unspendableaddr2, cp->unspendableaddr3); + //CCaddr2set(cp, Helper::getMyEval(), ownerPubkey, myprivkey, coinaddr); + //CCaddr3set(cp, Helper::getMyEval(), heirPubkey, myprivkey, coinaddr); + ////fprintf(stderr, "HeirClaim() after setting unspendable CC addr2=(%s) addr3=(%s)\n", cp->unspendableaddr2, cp->unspendableaddr3); - fprintf(stderr, "HeirClaim() after setting unspendable CC addr2=(%s) addr3=(%s)\n", cp->unspendableaddr2, cp->unspendableaddr3); + CCaddr1of2set(cp, ownerPubkey, heirPubkey, coinaddr); // add opreturn 'C' and sign tx: // this txfee will be ignored std::string rawhextx = FinalizeCCTx(0, cp, mtx, myPubkey, txfee, diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index b39a19668..1320da61c 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6952,12 +6952,20 @@ UniValue tokenlist(const UniValue& params, bool fHelp) UniValue tokeninfo(const UniValue& params, bool fHelp) { +#ifdef TESTMODE + std::cerr << "is CCerror clear? CCerror=" << CCerror << std::endl; +#endif uint256 tokenid; if ( fHelp || params.size() != 1 ) throw runtime_error("tokeninfo tokenid\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); tokenid = Parseuint256((char *)params[0].get_str().c_str()); + +#ifdef TESTMODE + CCerror = "test error"; +#endif + return(AssetInfo(tokenid)); } From 675787d67658245c64c795433a28816b9a0e2552 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 7 Jan 2019 23:24:13 +0500 Subject: [PATCH 360/643] Asset contract modified to support the Tokens contract --- src/cc/CCassetsCore.cpp | 100 +++++++++++++++++------------- src/cc/CCassetstx.cpp | 113 ++++++++++++++++++++++------------ src/cc/CCinclude.h | 6 +- src/cc/CCtokens.cpp | 132 ++++++++++++++++++++++++++++++++-------- src/cc/CCtokens.h | 4 +- src/cc/CCtx.cpp | 3 +- src/cc/CCutils.cpp | 8 +-- src/cc/assets.cpp | 52 +++++++++------- src/cc/prices.cpp | 4 +- src/script/script.cpp | 14 +++++ src/script/script.h | 2 + 11 files changed, 303 insertions(+), 135 deletions(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index 52c73d47f..837c4361e 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -239,25 +239,28 @@ CScript EncodeAssetCreateOpRet(uint8_t funcid,std::vector origpubkey,st } */ -CScript EncodeAssetOpRet(uint8_t assetFuncId, uint256 tokenid, uint256 assetid2, int64_t price, std::vector origpubkey) +CScript EncodeAssetOpRet(uint8_t assetFuncId, uint256 tokenid, uint256 assetid2, int64_t price, std::vector voutPubkeys, std::vector origpubkey) { CScript opret; uint8_t evalcode = EVAL_ASSETS; uint8_t funcId = (uint8_t)'t'; + uint8_t ccType = 0; + if (voutPubkeys.size() >= 1 && voutPubkeys.size() <= 2) + ccType = voutPubkeys.size(); tokenid = revuint256(tokenid); switch ( assetFuncId ) { //case 't': this cannot be here case 'x': case 'o': - opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcId << tokenid << assetFuncId); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcId << tokenid << ccType; if(ccType >= 1) ss << voutPubkeys[0]; if(ccType == 2) ss << voutPubkeys[1]; ss << assetFuncId); break; case 's': case 'b': case 'S': case 'B': - opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcId << tokenid << assetFuncId << price << origpubkey); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcId << tokenid << ccType; if(ccType >= 1) ss << voutPubkeys[0]; if(ccType == 2) ss << voutPubkeys[1]; ss << assetFuncId << price << origpubkey); break; case 'E': case 'e': assetid2 = revuint256(assetid2); - opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcId << tokenid << assetFuncId << assetid2 << price << origpubkey); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcId << tokenid << ccType; if(ccType >= 1) ss << voutPubkeys[0]; if(ccType == 2) ss << voutPubkeys[1]; ss << assetFuncId << assetid2 << price << origpubkey); break; default: fprintf(stderr,"EncodeAssetOpRet: illegal funcid.%02x\n", assetFuncId); @@ -283,33 +286,38 @@ bool DecodeAssetCreateOpRet(const CScript &scriptPubKey, std::vector &o uint8_t DecodeAssetOpRet(const CScript &scriptPubKey, uint8_t &evalCodeInOpret, uint256 &tokenid, uint256 &assetid2, int64_t &price, std::vector &origpubkey) { - std::vector vopret; - uint8_t *script, funcId = 0, assetFuncId = 0, dummyEvalCode, dummyFuncId; + std::vector vopretExtra; + uint8_t *script, funcId = 0, assetFuncId = 0, dummyEvalCode, dummyAssetFuncId; uint256 dummyTokenid; - - GetOpReturnData(scriptPubKey, vopret); - - script = (uint8_t *)vopret.data(); - if (script == 0) { - std::cerr << "DecodeAssetOpRet() script is empty" << std::endl; - return (uint8_t)0; - } + std::vector voutPubkeysDummy; tokenid = zeroid; assetid2 = zeroid; price = 0; - bool isEof = true; // NOTE: if parse error occures, parse might not be able to set error. It is safer to treat that it was eof if it is not set! - bool result = E_UNMARSHAL(vopret, ss >> evalCodeInOpret; ss >> funcId; ss >> tokenid; ss >> assetFuncId; isEof = ss.eof()); + // First - decode token opret: + funcId = DecodeTokenOpRet(scriptPubKey, evalCodeInOpret, tokenid, voutPubkeysDummy, vopretExtra); - if (!result && isEof) { // NOTE: 'result==false' means 'parse error' OR 'not eof state'. Consequently, 'result==false' but 'isEof==true' means just 'parse error' - std::cerr << "DecodeAssetOpRet() incorrect opret or no asset's payload" << std::endl; + + /*GetOpReturnData(scriptPubKey, vopret); + script = (uint8_t *)vopret.data(); + if (script == 0) { + std::cerr << "DecodeAssetOpRet() script is empty" << std::endl; + return (uint8_t)0; + }*/ + //bool isEof = true; // NOTE: if parse error occures, parse might not be able to set error. It is safer to treat that it was eof if it is not set! + //bool result = E_UNMARSHAL(vopret, ss >> evalCodeInOpret; ss >> funcId; ss >> tokenid; ss >> assetFuncId; isEof = ss.eof()); + + if (funcId == 0 || vopretExtra.size() == 0) { + std::cerr << "DecodeAssetOpRet() incorrect opret or no asset's payload" << " funcId=" << (int)funcId << " vopretExtra.size()=" << vopretExtra.size() << std::endl; return (uint8_t)0; } - tokenid = revuint256(tokenid); + ////tokenid = revuint256(tokenid); already done in DecodeToken! - std::cerr << "DecodeAssetOpRet() evalCodeInOpret=" << (int)evalCodeInOpret << " funcId=" << (char)(funcId ? funcId : ' ') << " assetFuncId=" << (char)(assetFuncId ? assetFuncId : ' ') << std::endl; + assetFuncId = vopretExtra.begin()[0]; + + //std::cerr << "DecodeAssetOpRet() evalCodeInOpret=" << (int)evalCodeInOpret << " funcId=" << (char)(funcId ? funcId : ' ') << " assetFuncId=" << (char)(assetFuncId ? assetFuncId : ' ') << std::endl; if(evalCodeInOpret == EVAL_ASSETS) { @@ -328,20 +336,20 @@ uint8_t DecodeAssetOpRet(const CScript &scriptPubKey, uint8_t &evalCodeInOpret, break; */ case 'x': case 'o': - if (isEof) // no data after 'assetFuncId' allowed + if (vopretExtra.size() == 1) // no data after 'assetFuncId' allowed { return(assetFuncId); } break; case 's': case 'b': case 'S': case 'B': - if (E_UNMARSHAL(vopret, ss >> dummyEvalCode; ss >> dummyFuncId; ss >> dummyTokenid; ss >> dummyFuncId; ss >> price; ss >> origpubkey) != 0) + if (E_UNMARSHAL(vopretExtra, ss >> dummyAssetFuncId; ss >> price; ss >> origpubkey) != 0) { //fprintf(stderr,"got price %llu\n",(long long)price); return(assetFuncId); } break; case 'E': case 'e': - if ( E_UNMARSHAL(vopret,ss >> dummyEvalCode; ss >> dummyFuncId; ss >> dummyTokenid; ss >> dummyFuncId; ss >> assetid2; ss >> price; ss >> origpubkey) != 0 ) + if ( E_UNMARSHAL(vopretExtra, ss >> dummyAssetFuncId; ss >> assetid2; ss >> price; ss >> origpubkey) != 0 ) { //fprintf(stderr,"got price %llu\n",(long long)price); assetid2 = revuint256(assetid2); @@ -349,34 +357,37 @@ uint8_t DecodeAssetOpRet(const CScript &scriptPubKey, uint8_t &evalCodeInOpret, } break; default: - fprintf(stderr,"DecodeAssetOpRet: illegal funcid.%02x\n", funcId); - funcId = 0; + fprintf(stderr,"DecodeAssetOpRet: illegal assetFuncId.%02x\n", assetFuncId); + //funcId = 0; break; } } - return(funcId); + return (uint8_t)0; } bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CTransaction &tx) { uint256 assetid,assetid2; uint8_t evalCode; - if ( tx.vout.size() > 0 && DecodeAssetOpRet(tx.vout[tx.vout.size()-1].scriptPubKey, evalCode,assetid,assetid2,price,origpubkey) != 0 ) + if ( tx.vout.size() > 0 && DecodeAssetOpRet(tx.vout[tx.vout.size()-1].scriptPubKey, evalCode, assetid, assetid2, price, origpubkey) != 0 ) return(true); - else return(false); + else + return(false); } bool GetAssetorigaddrs(struct CCcontract_info *cp,char *CCaddr,char *destaddr,const CTransaction& tx) { - uint256 assetid,assetid2; int64_t price,nValue=0; int32_t n; uint8_t funcid; std::vector origpubkey; CScript script; + uint256 assetid,assetid2; int64_t price,nValue=0; int32_t n; uint8_t funcid; std::vector origpubkey; + CScript script; uint8_t evalCode; n = tx.vout.size(); if ( n == 0 || (funcid= DecodeAssetOpRet(tx.vout[n-1].scriptPubKey, evalCode,assetid,assetid2,price,origpubkey)) == 0 ) return(false); - if ( GetCCaddress(cp,CCaddr,pubkey2pk(origpubkey)) != 0 && Getscriptaddress(destaddr,CScript() << origpubkey << OP_CHECKSIG) != 0 ) + if ( GetCCaddress(cp, CCaddr, pubkey2pk(origpubkey)) != 0 && Getscriptaddress(destaddr, CScript() << origpubkey << OP_CHECKSIG) != 0 ) return(true); - else return(false); + else + return(false); } @@ -398,7 +409,7 @@ int64_t AssetValidateCCvin(struct CCcontract_info *cp,Eval* eval,char *CCaddr,ch } else if ( Getscriptaddress(destaddr,vinTx.vout[tx.vin[vini].prevout.n].scriptPubKey) == 0 || strcmp(destaddr,(char *)cp->unspendableCCaddr) != 0 ) { - fprintf(stderr,"%s vs %s\n",destaddr,(char *)cp->unspendableCCaddr); + fprintf(stderr,"AssetValidateCCvin cc addr %s is not evalcode 0x%02x unspendable %s\n", destaddr, (int)cp->evalcode, (char *)cp->unspendableCCaddr); return eval->Invalid("invalid vin AssetsCCaddr"); } //else if ( vinTx.vout[0].nValue < 10000 ) @@ -415,6 +426,8 @@ int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmppr { CTransaction vinTx; int64_t nValue; uint256 assetid,assetid2; uint8_t funcid, evalCode; CCaddr[0] = origaddr[0] = 0; + + // validate locked coins on Assets vin[1] if ( (nValue= AssetValidateCCvin(cp,eval,CCaddr,origaddr,tx,1,vinTx)) == 0 ) return(0); else if ( vinTx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) @@ -441,7 +454,8 @@ int64_t AssetValidateSellvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpp return(0); if ( (assetoshis= IsAssetvout(cp, tmpprice, tmporigpubkey,vinTx,0,assetid)) == 0 ) return eval->Invalid("invalid missing CC vout0 for sellvin"); - else return(assetoshis); + else + return(assetoshis); } @@ -475,9 +489,8 @@ bool ValidateAssetOpret(CTransaction tx, int32_t v, uint256 assetid, int64_t &pr return(true); } } */ - // TODO: hope this was unneeded!!! (dimxy) - else if ((funcid == 'b' || funcid == 'B') && v == 0) // critical! 'b'/'B' vout0 is NOT asset - return(false); + //else if ((funcid == 'b' || funcid == 'B') && v == 0) // critical! 'b'/'B' vout0 is NOT asset + // return(false); else if (funcid != 'E') { if (assetid != zeroid && assetidOpret == assetid) @@ -542,8 +555,8 @@ bool AssetExactAmounts(struct CCcontract_info *cpAssets, int64_t &inputs, int64_ cpTokens = CCinit(&C, EVAL_TOKENS); for (int32_t i = 0; iismyvin)(tx.vin[i].scriptSig) || (*cpTokens->ismyvin)(tx.vin[i].scriptSig)) // || IsVinAllowed(tx.vin[i].scriptSig) != 0) + { // only tokens are relevant!! + if (/*(*cpAssets->ismyvin)(tx.vin[i].scriptSig)*/ (*cpTokens->ismyvin)(tx.vin[i].scriptSig) ) // || IsVinAllowed(tx.vin[i].scriptSig) != 0) { //std::cerr << indentStr << "AssetExactAmounts() eval is true=" << (eval != NULL) << " ismyvin=ok for_i=" << i << std::endl; // we are not inside the validation code -- dimxy @@ -555,7 +568,10 @@ bool AssetExactAmounts(struct CCcontract_info *cpAssets, int64_t &inputs, int64_ else { // validate vouts of vintx //std::cerr << indentStr << "AssetExactAmounts() check vin i=" << i << " nValue=" << vinTx.vout[tx.vin[i].prevout.n].nValue << std::endl; - assetoshis = IsAssetvout(cpAssets, tmpprice, tmporigpubkey, vinTx, tx.vin[i].prevout.n, assetid); + //assetoshis = IsAssetvout(cpAssets, tmpprice, tmporigpubkey, vinTx, tx.vin[i].prevout.n, assetid); + std::vector vopretExtra; + std::vector vinPubkeysEmpty; + assetoshis = IsTokensvout(false, false, cpTokens, NULL, vopretExtra, vinTx, tx.vin[i].prevout.n, assetid, vinPubkeysEmpty); if (assetoshis != 0) { std::cerr << "AssetExactAmounts() vin i=" << i << " assetoshis=" << assetoshis << std::endl; @@ -585,9 +601,11 @@ bool AssetExactAmounts(struct CCcontract_info *cpAssets, int64_t &inputs, int64_ } } - //std::cerr << "AssetExactAmounts() inputs=" << inputs << " outputs=" << outputs << " for txid=" << tx.GetHash().GetHex() << std::endl; + std::cerr << "AssetExactAmounts() inputs=" << inputs << " outputs=" << outputs << " for txid=" << tx.GetHash().GetHex() << std::endl; - /* if (inputs != outputs) { + /* we do not verify inputs == outputs here, + it's done in Tokens: + if (inputs != outputs) { if (tx.GetHash() != assetid) { std::cerr << "AssetExactAmounts() unequal inputs=" << inputs << " vs outputs=" << outputs << " for txid=" << tx.GetHash().GetHex() << std::endl; return (!eval) ? false : eval->Invalid("assets cc inputs != cc outputs"); diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 17c16bd6a..fe86d58de 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -145,11 +145,11 @@ UniValue AssetOrders(uint256 refassetid) char numstr[32], funcidstr[16], origaddr[64], assetidstr[65]; txid = it->first.txhash; - //std::cerr << "addOrders txid" << txid.GetHex() << std::endl; + //std::cerr << "addOrders() txid=" << txid.GetHex() << std::endl; if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { funcid = DecodeAssetOpRet(vintx.vout[vintx.vout.size() - 1].scriptPubKey, evalCode, assetid, assetid2, price, origpubkey); - //std::cerr << "addOrders vintx.vout.size()=" << vintx.vout.size() << " funcid=" << (char)(funcid ? funcid : ' ') << std::endl; + //std::cerr << "addOrders() vintx.vout.size()=" << vintx.vout.size() << " funcid=" << (char)(funcid ? funcid : ' ') << " assetid=" << assetid.GetHex() << std::endl; if (vintx.vout.size() > 0 && (funcid = DecodeAssetOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey, evalCode, assetid, assetid2, price, origpubkey)) != 0) { if (refassetid != zero && assetid != refassetid) @@ -163,6 +163,8 @@ UniValue AssetOrders(uint256 refassetid) //fprintf(stderr," refassetid\n"); return; } + + //std::cerr << "addOrders() it->first.index=" << it->first.index << " vintx.vout[it->first.index].nValue=" << vintx.vout[it->first.index].nValue << std::endl; if (vintx.vout[it->first.index].nValue == 0) return; @@ -213,7 +215,7 @@ UniValue AssetOrders(uint256 refassetid) } } result.push_back(item); - //fprintf(stderr,"func.(%c) %s/v%d %.8f\n",funcid,uint256_str(assetidstr,txid),(int32_t)it->first.index,(double)vintx.vout[it->first.index].nValue/COIN); + //fprintf(stderr,"addOrders() func.(%c) %s/v%d %.8f\n",funcid,uint256_str(assetidstr,txid),(int32_t)it->first.index,(double)vintx.vout[it->first.index].nValue/COIN); } } }; @@ -378,8 +380,12 @@ std::string CreateBuyOffer(int64_t txfee, int64_t bidamount, uint256 assetid, in return (""); } - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, bidamount, GetUnspendable(cpAssets,0))); - return(FinalizeCCTx(0, cpAssets, mtx, mypk, txfee, EncodeAssetOpRet('b', assetid, zeroid, pricetotal, Mypubkey()))); + CPubKey unspendablePubkey = GetUnspendable(cpAssets, 0); + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, bidamount, unspendablePubkey)); + + std::vector voutTokenPubkeys; // should be empty - no token vouts + + return(FinalizeCCTx(0, cpAssets, mtx, mypk, txfee, EncodeAssetOpRet('b', assetid, zeroid, pricetotal, voutTokenPubkeys, Mypubkey()))); } CCerror = strprintf("no coins found to make buy offer"); return(""); @@ -420,13 +426,17 @@ std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t p return (""); } - mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS,askamount, GetUnspendable(cpTokens,0))); + CPubKey unspendablePubkey = GetUnspendable(cpTokens, 0); + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, askamount, unspendablePubkey)); if (inputs > askamount) CCchange = (inputs - askamount); if (CCchange != 0) mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, CCchange, mypk)); - opret = EncodeAssetOpRet('s',assetid, zeroid, pricetotal, Mypubkey()); + std::vector voutTokenPubkeys; + voutTokenPubkeys.push_back(unspendablePubkey); + + opret = EncodeAssetOpRet('s',assetid, zeroid, pricetotal, voutTokenPubkeys, Mypubkey()); return(FinalizeCCTx(mask,cpTokens,mtx,mypk,txfee,opret)); } else { @@ -474,18 +484,22 @@ std::string CreateSwap(int64_t txfee,int64_t askamount,uint256 assetid,uint256 a return (""); } - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, askamount, GetUnspendable(cp, 0))); + CPubKey unspendablePubkey = GetUnspendable(cp, 0); + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, askamount, unspendablePubkey)); if (inputs > askamount) CCchange = (inputs - askamount); if (CCchange != 0) mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, CCchange, mypk)); - if (assetid2 == zeroid) - opret = EncodeAssetOpRet('s', assetid, zeroid, pricetotal, Mypubkey()); - else - { - opret = EncodeAssetOpRet('e', assetid, assetid2, pricetotal, Mypubkey()); + + std::vector voutTokenPubkeys; // should be empty - no token vouts + + if (assetid2 == zeroid) { + opret = EncodeAssetOpRet('s', assetid, zeroid, pricetotal, voutTokenPubkeys, Mypubkey()); + } + else { + opret = EncodeAssetOpRet('e', assetid, assetid2, pricetotal, voutTokenPubkeys, Mypubkey()); } return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,opret)); } @@ -524,9 +538,12 @@ std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid) if (GetTransaction(bidtxid, vintx, hashBlock, false) != 0) { bidamount = vintx.vout[0].nValue; - mtx.vin.push_back(CTxIn(bidtxid, 0, CScript())); + mtx.vin.push_back(CTxIn(bidtxid, 0, CScript())); // coins in Assets mtx.vout.push_back(CTxOut(bidamount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - return(FinalizeCCTx(mask, cpAssets, mtx, mypk, txfee, EncodeAssetOpRet('o', assetid, zeroid, 0, Mypubkey()))); + + std::vector voutTokenPubkeys; // should be empty, no tokens vout + + return(FinalizeCCTx(mask, cpAssets, mtx, mypk, txfee, EncodeAssetOpRet('o', assetid, zeroid, 0, voutTokenPubkeys, Mypubkey()))); } } return(""); @@ -554,7 +571,11 @@ std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) askamount = vintx.vout[0].nValue; mtx.vin.push_back(CTxIn(asktxid, 0, CScript())); mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, askamount, mypk)); - return(FinalizeCCTx(mask, cpTokens, mtx, mypk, txfee, EncodeAssetOpRet('x', assetid, zeroid, 0, Mypubkey()))); + + std::vector voutTokenPubkeys; + voutTokenPubkeys.push_back(mypk); + + return(FinalizeCCTx(mask, cpTokens, mtx, mypk, txfee, EncodeAssetOpRet('x', assetid, zeroid, 0, voutTokenPubkeys, Mypubkey()))); } } return(""); @@ -595,7 +616,7 @@ std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t f bidamount = vintx.vout[bidvout].nValue; SetAssetOrigpubkey(origpubkey, origprice, vintx); - mtx.vin.push_back(CTxIn(bidtxid, bidvout, CScript())); + mtx.vin.push_back(CTxIn(bidtxid, bidvout, CScript())); // Coins on Assets unspendable if ((inputs = AddTokenCCInputs(cpTokens, mtx, mypk, assetid, fillamount, 60)) > 0) { @@ -610,25 +631,30 @@ std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t f if (inputs > fillamount) CCchange = (inputs - fillamount); - mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, bidamount - paid_amount, GetUnspendable(cpTokens, NULL))); // tokens - mtx.vout.push_back(CTxOut(paid_amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, fillamount, pubkey2pk(origpubkey))); // coins on assets + CPubKey unspendableTokensPk = GetUnspendable(cpTokens, NULL); + uint8_t unspendableAssetsPrivkey[32]; + CPubKey unspendableAssetsPk = GetUnspendable(cpAssets, unspendableAssetsPrivkey); + + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, bidamount - paid_amount, unspendableAssetsPk)); // 0 coins remainder + mtx.vout.push_back(CTxOut(paid_amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); // 1 coins to normal + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, fillamount, pubkey2pk(origpubkey))); // 2 tokens paid if (CCchange != 0) - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, CCchange, mypk)); // coins on assets + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, CCchange, mypk)); // 3 change in tokens fprintf(stderr,"remaining %llu -> origpubkey\n", (long long)remaining_required); - // add additional unspendable addr from Assets: char unspendableAssetsAddr[64]; - uint8_t unspendableAssetsPrivkey[32]; - - CPubKey unspendableAssetsPk = GetUnspendable(cpAssets, unspendableAssetsPrivkey); GetCCaddress(cpAssets, unspendableAssetsAddr, unspendableAssetsPk); + // add additional unspendable addr from Assets: CCaddr2set(cpTokens, EVAL_ASSETS, unspendableAssetsPk, unspendableAssetsPrivkey, unspendableAssetsAddr); - return(FinalizeCCTx(mask,cpTokens,mtx,mypk,txfee, EncodeAssetOpRet('B', assetid, zeroid, remaining_required, origpubkey))); - } else return("dont have any assets to fill bid\n"); + // token vout verification pubkeys: + std::vector voutTokenPubkeys; + voutTokenPubkeys.push_back(unspendableTokensPk); + + return(FinalizeCCTx(mask,cpTokens,mtx,mypk,txfee, EncodeAssetOpRet('B', assetid, zeroid, remaining_required, voutTokenPubkeys, origpubkey))); + } else return("dont have any assets to fill bid"); } } return("no normal coins left"); @@ -683,7 +709,7 @@ std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 askt mtx.vin.push_back(CTxIn(asktxid, askvout, CScript())); // NOTE: this is the reference to tokens -> send cpTokens for signing into FinalizeCCTx! if (assetid2 != zeroid) - inputs = AddAssetInputs(cpTokens, mtx, mypk, assetid2, paid_nValue, 60); + inputs = AddAssetInputs(cpTokens, mtx, mypk, assetid2, paid_nValue, 60); // not implemented yet else { inputs = AddNormalinputs(mtx, mypk, paid_nValue, 60); @@ -698,25 +724,36 @@ std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 askt } if (assetid2 != zeroid) - SetSwapFillamounts(received_assetoshis, remaining_nValue, orig_assetoshis, paid_nValue, total_nValue); + SetSwapFillamounts(received_assetoshis, remaining_nValue, orig_assetoshis, paid_nValue, total_nValue); //not implemented correctly yet else SetAskFillamounts(received_assetoshis, remaining_nValue, orig_assetoshis, paid_nValue, total_nValue); if (assetid2 != zeroid && inputs > paid_nValue) CCchange = (inputs - paid_nValue); - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, orig_assetoshis - received_assetoshis, GetUnspendable(cpAssets, NULL))); // coins in Assets cc addr - mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, received_assetoshis, mypk)); // tokens + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, orig_assetoshis - received_assetoshis, GetUnspendable(cpTokens, NULL))); // 0 tokens cc addr - ask remainder + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, received_assetoshis, mypk)); //1 tokens to self - if (assetid2 != zeroid) - mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, paid_nValue, origpubkey)); // tokens... (swap is not implemented yet) - else - mtx.vout.push_back(CTxOut(paid_nValue, CScript() << origpubkey << OP_CHECKSIG)); // coins normal + if (assetid2 != zeroid) { + std::cerr << "FillSell() WARNING: asset swap not implemented yet! (paid_nValue)" << std::endl; + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, paid_nValue, origpubkey)); //2 tokens... (swap is not implemented yet) + } + else { + //std::cerr << "FillSell() paid_value=" << paid_nValue << " origpubkey=" << HexStr(pubkey2pk(origpubkey)) << std::endl; + mtx.vout.push_back(CTxOut(paid_nValue, CScript() << origpubkey << OP_CHECKSIG)); //2 coins normal to whom who asked token + } - if (CCchange != 0) - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, CCchange, mypk)); // coins in Assets cc addr + // not implemented + if (CCchange != 0) { + std::cerr << "FillSell() WARNING: asset swap not implemented yet! (CCchange)" << std::endl; + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, CCchange, mypk)); //3 coins in Assets cc addr + } - return(FinalizeCCTx(mask,cpTokens,mtx,mypk,txfee,EncodeAssetOpRet(assetid2 != zeroid ? 'E' : 'S', assetid, assetid2, remaining_nValue, origpubkey))); + // vout verification pubkeys: + std::vector voutTokenPubkeys; + voutTokenPubkeys.push_back(mypk); + + return(FinalizeCCTx(mask,cpTokens,mtx,mypk,txfee,EncodeAssetOpRet(assetid2 != zeroid ? 'E' : 'S', assetid, assetid2, remaining_nValue, voutTokenPubkeys, origpubkey))); } else { CCerror = strprintf("filltx not enough utxos"); fprintf(stderr,"%s\n", CCerror.c_str()); diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index ec1557e2b..1b6e804fc 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -151,13 +151,15 @@ uint256 OraclesBatontxid(uint256 oracletxid,CPubKey pk); //int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs); int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs); +int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 reftokenid, std::vector vinPubkeys); + bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx); -CScript EncodeAssetOpRet(uint8_t assetFuncId, uint256 tokenid, uint256 assetid2, int64_t price, std::vector origpubkey); +CScript EncodeAssetOpRet(uint8_t assetFuncId, uint256 tokenid, uint256 assetid2, int64_t price, std::vector voutPubkeys, std::vector origpubkey); bool DecodeAssetCreateOpRet(const CScript &scriptPubKey, std::vector &origpubkey, std::string &name, std::string &description); uint8_t DecodeAssetOpRet(const CScript &scriptPubKey, uint8_t &evalCodeInOpret, uint256 &tokenid, uint256 &assetid2, int64_t &price, std::vector &origpubkey); uint8_t DecodeTokenCreateOpRet(const CScript &scriptPubKey, std::vector &origpubkey, std::string &name, std::string &description); -uint8_t DecodeTokenOpRet(const CScript scriptPubKey, uint8_t &evalCode, uint256 &tokenid, std::vector &vopretExtra); +uint8_t DecodeTokenOpRet(const CScript scriptPubKey, uint8_t &evalCode, uint256 &tokenid, std::vector &voutPubkeys, std::vector &vopretExtra); //uint8_t DecodeAssetOpRet(const CScript &scriptPubKey, uint8_t &evalCode, uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey); uint8_t DecodeOraclesData(const CScript &scriptPubKey,uint256 &oracletxid,uint256 &batontxid,CPubKey &pk,std::vector &data); diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index c85297ddb..d9e689f85 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -76,11 +76,12 @@ uint8_t DecodeTokenCreateOpRet(const CScript &scriptPubKey,std::vector return (uint8_t)0; } -uint8_t DecodeTokenOpRet(const CScript scriptPubKey, uint8_t &evalCode, uint256 &tokenid, std::vector &vopretExtra) +uint8_t DecodeTokenOpRet(const CScript scriptPubKey, uint8_t &evalCode, uint256 &tokenid, std::vector &voutPubkeys, std::vector &vopretExtra) { std::vector vopret, extra, dummyPubkey; - uint8_t funcid=0, *script, e, dummyFuncId; + uint8_t funcId=0, *script, dummyEvalCode, dummyFuncId, ccType; std::string dummyName; std::string dummyDescription; + CPubKey voutPubkey1, voutPubkey2; GetOpReturnData(scriptPubKey, vopret); script = (uint8_t *)vopret.data(); @@ -88,28 +89,45 @@ uint8_t DecodeTokenOpRet(const CScript scriptPubKey, uint8_t &evalCode, uint256 if (script != 0 /*enable all evals: && script[0] == EVAL_TOKENS*/) { + // NOTE: if parse error occures, parse might not be able to set error. It is safer to treat that it was eof if it is not set! bool isEof = true; + evalCode = script[0]; - funcid = script[1]; - //fprintf(stderr,"decode.[%c]\n",funcid); - switch ( funcid ) + funcId = script[1]; + //fprintf(stderr,"decode.[%c]\n",funcId); + + switch ( funcId ) { case 'c': return DecodeTokenCreateOpRet(scriptPubKey, dummyPubkey, dummyName, dummyDescription); //break; case 't': //not used yet: case 'l': - if (E_UNMARSHAL(vopret, ss >> e; ss >> dummyFuncId; ss >> tokenid; isEof = ss.eof(); vopretExtra = std::vector(ss.begin(), ss.end())) || !isEof) + // NOTE: 'E_UNMARSHAL result==false' means 'parse error' OR 'not eof state'. Consequently, 'result==false' but 'isEof==true' means just 'parse error' + if (E_UNMARSHAL(vopret, ss >> dummyEvalCode; ss >> dummyFuncId; ss >> tokenid; ss >> ccType; if (ccType >= 1) ss >> voutPubkey1; if (ccType == 2) ss >> voutPubkey2; isEof = ss.eof(); vopretExtra = std::vector(ss.begin(), ss.end())) + || !isEof) { + + if (!(ccType >= 0 && ccType <= 2)) { //incorrect ccType + std::cerr << "DecodeTokenOpRet() incorrect ccType=" << (int)ccType << std::endl; + return (uint8_t)0; + } + + // add verification pubkeys: + voutPubkeys.clear(); + if (voutPubkey1.IsValid()) + voutPubkeys.push_back(voutPubkey1); + if (voutPubkey2.IsValid()) + voutPubkeys.push_back(voutPubkey2); + tokenid = revuint256(tokenid); - return(funcid); + return(funcId); } - std::cerr << "DecodeTokenOpRet() isEof=" << isEof << std::endl; - fprintf(stderr, "DecodeTokenOpRet() bad opret format\n"); // this may be just check, no error logging + std::cerr << "DecodeTokenOpRet() warning: bad opret format, isEof=" << isEof << " ccType=" << ccType << " tokenid=" << revuint256(tokenid).GetHex() << std::endl; return (uint8_t)0; default: - fprintf(stderr, "DecodeTokenOpRet() illegal funcid.%02x\n", funcid); + std::cerr << "DecodeTokenOpRet() illegal funcid=" << (int)funcId << std::endl; return (uint8_t)0; } } @@ -124,16 +142,18 @@ bool TokensValidate(struct CCcontract_info *cp, Eval* eval, const CTransaction & static uint256 zero; CTxDestination address; CTransaction vinTx, createTx; uint256 hashBlock, tokenid, tokenid2; int32_t i, starti, numvins, numvouts, preventCCvins, preventCCvouts; - int64_t remaining_price, nValue, tokenoshis, outputs, inputs, tmpprice, totalunits, ignore; std::vector origpubkey, tmporigpubkey, ignorepubkey; + int64_t remaining_price, nValue, tokenoshis, outputs, inputs, tmpprice, totalunits, ignore; + std::vector vopretExtra, tmporigpubkey, ignorepubkey; uint8_t funcid, evalCodeInOpret; char destaddr[64], origaddr[64], CCaddr[64]; + std::vector voutTokenPubkeys; numvins = tx.vin.size(); numvouts = tx.vout.size(); outputs = inputs = 0; preventCCvins = preventCCvouts = -1; - if ((funcid = DecodeTokenOpRet(tx.vout[numvouts - 1].scriptPubKey, evalCodeInOpret, tokenid, origpubkey)) == 0) + if ((funcid = DecodeTokenOpRet(tx.vout[numvouts - 1].scriptPubKey, evalCodeInOpret, tokenid, voutTokenPubkeys, vopretExtra)) == 0) return eval->Invalid("TokenValidate: invalid opreturn payload"); fprintf(stderr, "TokensValidate (%c)\n", funcid); @@ -206,7 +226,7 @@ bool TokensValidate(struct CCcontract_info *cp, Eval* eval, const CTransaction & thread_local uint32_t tokenValIndentSize = 0; // validates opret for token tx: -bool ValidateTokenOpret(CTransaction tx, int32_t v, uint256 tokenid, std::vector &vopretExtra) { +bool ValidateTokenOpret(CTransaction tx, int32_t v, uint256 tokenid, std::vector &voutPubkeys, std::vector &vopretExtra) { uint256 tokenidOpret, tokenidOpret2; uint8_t funcid, evalCode; @@ -216,7 +236,7 @@ bool ValidateTokenOpret(CTransaction tx, int32_t v, uint256 tokenid, std::vector int32_t n = tx.vout.size(); - if ((funcid = DecodeTokenOpRet(tx.vout[n - 1].scriptPubKey, evalCode, tokenidOpret, vopretExtra)) == 0) + if ((funcid = DecodeTokenOpRet(tx.vout[n - 1].scriptPubKey, evalCode, tokenidOpret, voutPubkeys, vopretExtra)) == 0) { std::cerr << indentStr << "ValidateTokenOpret() DecodeOpret returned null for n-1=" << n - 1 << " txid=" << tx.GetHash().GetHex() << std::endl; return(false); @@ -241,18 +261,20 @@ bool ValidateTokenOpret(CTransaction tx, int32_t v, uint256 tokenid, std::vector } + // Checks if the vout is a really Tokens CC vout // compareTotals == true, the func also validates the passed transaction itself: // it should be either sum(cc vins) == sum(cc vouts) or the transaction is the 'tokenbase' ('c') tx -int64_t IsTokensvout(bool compareTotals, struct CCcontract_info *cp, Eval* eval, std::vector &vopretExtra, const CTransaction& tx, int32_t v, uint256 reftokenid) +int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, std::vector &vopretExtra, const CTransaction& tx, int32_t v, uint256 reftokenid, std::vector vinPubkeys) { // this is just for log messages indentation fur debugging recursive calls: std::string indentStr = std::string().append(tokenValIndentSize, '.'); //std::cerr << indentStr << "IsTokensvout() entered for txid=" << tx.GetHash().GetHex() << " v=" << v << " for tokenid=" << reftokenid.GetHex() << std::endl; + //TODO: validate cc vouts are EVAL_TOKENS! - if (tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0) // maybe check address too? dimxy: possibly no, because there are too many cases with different addresses here + if (tx.vout[v].scriptPubKey.IsPayToCryptoCondition()) // maybe check address too? dimxy: possibly no, because there are too many cases with different addresses here { int32_t n = tx.vout.size(); // just check boundaries: @@ -261,7 +283,7 @@ int64_t IsTokensvout(bool compareTotals, struct CCcontract_info *cp, Eval* eval, return(0); } - if (compareTotals) { + if (goDeeper) { //std::cerr << indentStr << "IsTokensvout() maxTokenExactAmountDepth=" << maxTokenExactAmountDepth << std::endl; //validate all tx int64_t myCCVinsAmount = 0, myCCVoutsAmount = 0; @@ -282,11 +304,41 @@ int64_t IsTokensvout(bool compareTotals, struct CCcontract_info *cp, Eval* eval, } // moved opret checking to this new reusable func (dimxy): - const bool valOpret = ValidateTokenOpret(tx, v, reftokenid, vopretExtra); + std::vector voutPubkeys; + const bool valOpret = ValidateTokenOpret(tx, v, reftokenid, voutPubkeys, vopretExtra); //std::cerr << indentStr << "IsTokensvout() ValidateTokenOpret returned=" << std::boolalpha << valOpret << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; if (valOpret) { - //std::cerr << indentStr << "IsTokensvout() ValidateTokenOpret returned true, returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; - return tx.vout[v].nValue; + //std::cerr << indentStr << "IsTokensvout() ValidateTokenOpret returned true" << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; + + if (checkPubkeys) { + // verify that the vout is within EVAL_TOKENS: + + if (voutPubkeys.size() >= 1 && voutPubkeys.size() <= 2) { + CTxOut testVout; + if (voutPubkeys.size() == 1) + testVout = MakeCC1vout(EVAL_TOKENS, tx.vout[v].nValue, voutPubkeys[0]); + else // voutPubkeys.size() == 2 + testVout = MakeCC1of2vout(EVAL_TOKENS, tx.vout[v].nValue, voutPubkeys[0], voutPubkeys[1]); + + if (tx.vout[v].scriptPubKey == testVout.scriptPubKey) { + std::cerr << indentStr << "IsTokensvout() vout is EVAL_TOKENS, returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; + return tx.vout[v].nValue; + } + } + + // maybe it is change? + for(std::vector::iterator it = vinPubkeys.begin(); it != vinPubkeys.end(); it++) { + CTxOut testVout = MakeCC1vout(EVAL_TOKENS, tx.vout[v].nValue, *it); + + if (tx.vout[v].scriptPubKey == testVout.scriptPubKey) { + std::cerr << indentStr << "IsTokensvout() vout is EVAL_TOKENS change, returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; + return tx.vout[v].nValue; + } + } + } + else { + return tx.vout[v].nValue; + } } //std::cerr << indentStr; fprintf(stderr,"IsTokensvout() CC vout v.%d of n=%d amount=%.8f txid=%s\n",v,n,(double)0/COIN, tx.GetHash().GetHex().c_str()); @@ -296,9 +348,12 @@ int64_t IsTokensvout(bool compareTotals, struct CCcontract_info *cp, Eval* eval, } // compares cc inputs vs cc outputs (to prevent feeding vouts from normal inputs) -bool TokensExactAmounts(bool compareTotals, struct CCcontract_info *cpTokens, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 tokenid) +bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 tokenid) { CTransaction vinTx; uint256 hashBlock, id, id2; int32_t flag; int64_t tokenoshis; std::vector tmporigpubkey; int64_t tmpprice; + std::vector vinPubkeys, vinPubkeysEmpty; + CPubKey pubkey; + int32_t numvins = tx.vin.size(); int32_t numvouts = tx.vout.size(); inputs = outputs = 0; @@ -310,6 +365,33 @@ bool TokensExactAmounts(bool compareTotals, struct CCcontract_info *cpTokens, in { // check for additional contracts which may send tokens to the Tokens contract if ((*cpTokens->ismyvin)(tx.vin[i].scriptSig) /*|| IsVinAllowed(tx.vin[i].scriptSig) != 0*/) { + + // extract my vins pubkeys: + + auto findEval = [](CC *cond, struct CCVisitor _) { + bool r = false; //cc_typeId(cond) == CC_Eval && cond->codeLength == 1 && cond->code[0] == EVAL_TOKENS; + + if (cc_typeId(cond) == CC_Secp256k1) { + *(CPubKey*)_.context = buf2pk(cond->publicKey); + std::cerr << "findEval found pubkey=" << HexStr(*(CPubKey*)_.context) << std::endl; + r = true; + } + // false for a match, true for continue + return r ? 0 : 1; + }; + + CC *cond = GetCryptoCondition(tx.vin[i].scriptSig); + + if (cond) { + CCVisitor visitor = { findEval, (uint8_t*)"", 0, &pubkey }; + bool out = !cc_visit(cond, visitor); + cc_free(cond); + + if (pubkey.IsValid()) + vinPubkeys.push_back(pubkey); + } + + //std::cerr << indentStr << "TokensExactAmounts() eval is true=" << (eval != NULL) << " ismyvin=ok for_i=" << i << std::endl; // we are not inside the validation code -- dimxy if ((eval && eval->GetTxUnconfirmed(tx.vin[i].prevout.hash, vinTx, hashBlock) == 0) || (!eval && !myGetTransaction(tx.vin[i].prevout.hash, vinTx, hashBlock))) @@ -322,7 +404,7 @@ bool TokensExactAmounts(bool compareTotals, struct CCcontract_info *cpTokens, in tokenValIndentSize++; // validate vouts of vintx //std::cerr << indentStr << "TokenExactAmounts() check vin i=" << i << " nValue=" << vinTx.vout[tx.vin[i].prevout.n].nValue << std::endl; - tokenoshis = IsTokensvout(compareTotals, cpTokens, eval, tmporigpubkey, vinTx, tx.vin[i].prevout.n, tokenid); + tokenoshis = IsTokensvout(goDeeper, false/*<--do not have pubkeys*/, cpTokens, eval, tmporigpubkey, vinTx, tx.vin[i].prevout.n, tokenid, vinPubkeysEmpty); tokenValIndentSize--; if (tokenoshis != 0) { @@ -339,7 +421,7 @@ bool TokensExactAmounts(bool compareTotals, struct CCcontract_info *cpTokens, in tokenValIndentSize++; // Note: we pass in here 'false' because we don't need to call TokenExactAmounts() recursively from IsTokenvout // indeed, in this case we'll be checking this tx again - tokenoshis = IsTokensvout(false, cpTokens, eval, tmporigpubkey, tx, i, tokenid); + tokenoshis = IsTokensvout(false, true /*<--exclude non-tokens vouts*/, cpTokens, eval, tmporigpubkey, tx, i, tokenid, vinPubkeys); tokenValIndentSize--; if (tokenoshis != 0) @@ -393,7 +475,9 @@ int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, C if (strcmp(destaddr, coinaddr) != 0 && strcmp(destaddr, cp->unspendableCCaddr) != 0 && strcmp(destaddr, cp->unspendableaddr2) != 0) continue; fprintf(stderr, "AddTokenCCInputs() check destaddress=%s vout amount=%.8f\n", destaddr, (double)vintx.vout[vout].nValue / COIN); - if ((nValue = IsTokensvout(true, cp, NULL, vopretExtra, vintx, vout, tokenid)) > 0 && myIsutxo_spentinmempool(txid, vout) == 0) + + std::vector vinPubkeysEmpty; + if ((nValue = IsTokensvout(true, false, cp, NULL, vopretExtra, vintx, vout, tokenid, vinPubkeysEmpty)) > 0 && myIsutxo_spentinmempool(txid, vout) == 0) { if (total != 0 && maxinputs != 0) mtx.vin.push_back(CTxIn(txid, vout, CScript())); diff --git a/src/cc/CCtokens.h b/src/cc/CCtokens.h index 2dc9a8e56..8ecbc1094 100644 --- a/src/cc/CCtokens.h +++ b/src/cc/CCtokens.h @@ -27,8 +27,8 @@ // CCcustom bool TokensValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); -bool TokensExactAmounts(bool compareTotals, struct CCcontract_info *cpTokens, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 tokenid); -int64_t IsTokensvout(bool compareTotals, struct CCcontract_info *cp, Eval* eval, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 reftokenid); +bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 tokenid); +//int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 reftokenid, std::vector vinPubkeys); std::string CreateToken(int64_t txfee, int64_t assetsupply, std::string name, std::string description); std::string TokenTransfer(int64_t txfee, uint256 assetid, std::vector destpubkey, int64_t total); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index dc8b4788e..3d95d0f17 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -333,7 +333,8 @@ int64_t CCtoken_balance(char *coinaddr,uint256 tokenid) if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) { char str[65]; fprintf(stderr,"check %s %.8f\n",uint256_str(str,txid),(double)it->second.satoshis/COIN); - if ( DecodeTokenOpRet(tx.vout[numvouts-1].scriptPubKey, evalCode, assetid, vopretExtra) != 0 && assetid == tokenid ) + std::vector voutTokenPubkeys; + if ( DecodeTokenOpRet(tx.vout[numvouts-1].scriptPubKey, evalCode, assetid, voutTokenPubkeys, vopretExtra) != 0 && assetid == tokenid ) { sum += it->second.satoshis; } diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index c0fea0c9f..eef21c72a 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -307,17 +307,17 @@ bool GetCCaddress1of2(struct CCcontract_info *cp,char *destaddr,CPubKey pk,CPubK return(destaddr[0] != 0); } -bool ConstrainVout(CTxOut vout,int32_t CCflag,char *cmpaddr,int64_t nValue) +bool ConstrainVout(CTxOut vout, int32_t CCflag, char *cmpaddr, int64_t nValue) { char destaddr[64]; if ( vout.scriptPubKey.IsPayToCryptoCondition() != CCflag ) { - fprintf(stderr,"constrain vout error isCC %d vs %d CCflag\n",vout.scriptPubKey.IsPayToCryptoCondition(),CCflag); + fprintf(stderr,"constrain vout error isCC %d vs %d CCflag\n", vout.scriptPubKey.IsPayToCryptoCondition(), CCflag); return(false); } - else if ( cmpaddr != 0 && (Getscriptaddress(destaddr,vout.scriptPubKey) == 0 || strcmp(destaddr,cmpaddr) != 0) ) + else if ( cmpaddr != 0 && (Getscriptaddress(destaddr, vout.scriptPubKey) == 0 || strcmp(destaddr, cmpaddr) != 0) ) { - fprintf(stderr,"constrain vout error addr %s vs %s\n",cmpaddr!=0?cmpaddr:"",destaddr!=0?destaddr:""); + fprintf(stderr,"constrain vout error addr %s vs %s\n", cmpaddr!=0?cmpaddr:"", destaddr!=0?destaddr:""); return(false); } else if ( nValue != 0 && nValue != vout.nValue ) //(nValue == 0 && vout.nValue < 10000) || ( diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index 47b9488c8..3a62a526a 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -140,12 +140,16 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti int32_t i,starti,numvins,numvouts,preventCCvins,preventCCvouts; int64_t remaining_price,nValue,assetoshis,outputs,inputs,tmpprice,totalunits,ignore; std::vector origpubkey,tmporigpubkey,ignorepubkey; uint8_t funcid, evalCodeInOpret; - char destaddr[64],origaddr[64],CCaddr[64]; + char destaddr[64], origaddr[64], assetsCCaddr[64], tokensCCaddr[64]; // we need this for validating tokens' vins/vous: struct CCcontract_info *cpTokens, tokensC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); + //CPubKey unspendableTokensPk = GetUnspendable(cpTokens, NULL); + //CPubKey unspendableAssetsPk = GetUnspendable(cpAssets, NULL); + //GetCCaddress(cpTokens, tokensUnspendableCCaddr, unspendableTokensPk); + numvins = tx.vin.size(); numvouts = tx.vout.size(); outputs = inputs = 0; @@ -154,6 +158,9 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti if((funcid = DecodeAssetOpRet(tx.vout[numvouts-1].scriptPubKey, evalCodeInOpret, assetid, assetid2, remaining_price, origpubkey)) == 0 ) return eval->Invalid("AssetValidate: invalid opreturn payload"); + // find token user cc addr + GetCCaddress(cpTokens, tokensCCaddr, pubkey2pk(origpubkey)); + fprintf(stderr,"AssetValidate (%c)\n",funcid); if( funcid != 'o' && funcid != 'x' && eval->GetTxUnconfirmed(assetid, createTx, hashBlock) == 0 ) @@ -162,8 +169,8 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti return eval->Invalid("cant find asset2 create txid"); else if( IsCCInput(tx.vin[0].scriptSig) != 0 ) return eval->Invalid("illegal asset vin0"); - else if( numvouts < 1 ) - return eval->Invalid("no vouts"); + else if( numvouts < 2 ) + return eval->Invalid("too few vouts"); // it was if(numvouts < 1) but it refers at least to vout[1] below else if( funcid != 'c' ) { /* if( funcid == 't' ) @@ -223,7 +230,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti //vout.0: vin.1 value to original pubkey buyTx.vout[0].nValue -> [origpubkey] //vout.1: normal output for change (if any) //vout.n-1: opreturn [EVAL_ASSETS] ['o'] - if( (nValue= AssetValidateBuyvin(cpAssets, eval, tmpprice, tmporigpubkey, CCaddr, origaddr, tx, assetid)) == 0 ) + if( (nValue= AssetValidateBuyvin(cpAssets, eval, tmpprice, tmporigpubkey, assetsCCaddr, origaddr, tx, assetid)) == 0 ) return(false); else if( ConstrainVout(tx.vout[0],0, origaddr, nValue) == 0 ) return eval->Invalid("invalid refund for cancelbuy"); @@ -243,7 +250,8 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti //vout.4: normal output for change (if any) //vout.n-1: opreturn [EVAL_ASSETS] ['B'] [assetid] [remaining asset required] [origpubkey] preventCCvouts = 4; - if( (nValue = AssetValidateBuyvin(cpAssets, eval, totalunits, tmporigpubkey, CCaddr, origaddr, tx, assetid)) == 0 ) + + if( (nValue = AssetValidateBuyvin(cpAssets, eval, totalunits, tmporigpubkey, assetsCCaddr, origaddr, tx, assetid)) == 0 ) return(false); else if( numvouts < 3 ) return eval->Invalid("not enough vouts for fillbuy"); @@ -255,12 +263,12 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti return eval->Invalid("locked value doesnt match vout0+1 fillbuy"); else if( tx.vout[3].scriptPubKey.IsPayToCryptoCondition() != 0 ) { - if( ConstrainVout(tx.vout[2], 1, CCaddr, 0) == 0 ) + if( ConstrainVout(tx.vout[2], 1, tokensCCaddr, 0) == 0 ) // tokens on user cc addr return eval->Invalid("vout2 doesnt go to origpubkey fillbuy"); else if ( inputs != tx.vout[2].nValue + tx.vout[3].nValue ) return eval->Invalid("asset inputs doesnt match vout2+3 fillbuy"); } - else if( ConstrainVout(tx.vout[2], 1, CCaddr, inputs) == 0 ) + else if( ConstrainVout(tx.vout[2], 1, tokensCCaddr, inputs) == 0 ) // tokens on user cc addr return eval->Invalid("vout2 doesnt match inputs fillbuy"); else if( ConstrainVout(tx.vout[1],0,0,0) == 0 ) return eval->Invalid("vout1 is CC for fillbuy"); @@ -268,7 +276,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti return eval->Invalid("mismatched remainder for fillbuy"); else if( remaining_price != 0 ) { - if( ConstrainVout(tx.vout[0], 1, cpAssets->unspendableCCaddr, 0) == 0 ) + if( ConstrainVout(tx.vout[0], 1, cpAssets->unspendableCCaddr, 0) == 0 ) // coins on asset unspendable cc addr return eval->Invalid("mismatched vout0 AssetsCCaddr for fillbuy"); } } @@ -287,16 +295,16 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti preventCCvouts = 1; if( remaining_price == 0 ) return eval->Invalid("illegal null remaining_price for selloffer"); - if( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() != 0 ) + if( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() != 0 ) // is cc change present? { preventCCvouts++; - if( ConstrainVout(tx.vout[0], 1, (char *)cpAssets->unspendableCCaddr, 0) == 0 ) - return eval->Invalid("mismatched vout0 AssetsCCaddr for selloffer"); + if( ConstrainVout(tx.vout[0], 1, (char *)cpTokens->unspendableCCaddr, 0) == 0 ) // check also vout[0] + return eval->Invalid("mismatched vout0 TokensCCaddr for selloffer"); else if( tx.vout[0].nValue + tx.vout[1].nValue != inputs ) return eval->Invalid("mismatched vout0+vout1 total for selloffer"); } - else if( ConstrainVout(tx.vout[0], 1, (char *)cpAssets->unspendableCCaddr, inputs) == 0 ) - return eval->Invalid("mismatched vout0 AssetsCCaddr for selloffer"); + else if( ConstrainVout(tx.vout[0], 1, (char *)cpTokens->unspendableCCaddr, inputs) == 0 ) // no cc change, just vout[0] + return eval->Invalid("mismatched vout0 TokensCCaddr for selloffer"); //fprintf(stderr,"remaining.%d for sell\n",(int32_t)remaining_price); break; @@ -306,9 +314,9 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti //vout.0: vin.1 assetoshis to original pubkey CC sellTx/exchangeTx.vout[0].nValue -> [origpubkey] //vout.1: normal output for change (if any) //vout.n-1: opreturn [EVAL_ASSETS] ['x'] [assetid] - if( (assetoshis= AssetValidateSellvin(cpAssets, eval, tmpprice, tmporigpubkey, CCaddr, origaddr, tx, assetid)) == 0 ) + if( (assetoshis= AssetValidateSellvin(cpTokens, eval, tmpprice, tmporigpubkey, tokensCCaddr, origaddr, tx, assetid)) == 0 ) return(false); - else if( ConstrainVout(tx.vout[0], 1, CCaddr, assetoshis) == 0 ) + else if( ConstrainVout(tx.vout[0], 1, tokensCCaddr, assetoshis) == 0 ) return eval->Invalid("invalid vout for cancel"); preventCCvins = 2; preventCCvouts = 1; @@ -323,7 +331,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti //'S'.vout.2: vin.2 value to original pubkey [origpubkey] //vout.3: normal output for change (if any) //'S'.vout.n-1: opreturn [EVAL_ASSETS] ['S'] [assetid] [amount of coin still required] [origpubkey] - if( (assetoshis = AssetValidateSellvin(cpTokens, eval, totalunits, tmporigpubkey, CCaddr, origaddr, tx, assetid)) == 0 ) + if( (assetoshis = AssetValidateSellvin(cpTokens, eval, totalunits, tmporigpubkey, tokensCCaddr, origaddr, tx, assetid)) == 0 ) return(false); else if( numvouts < 3 ) return eval->Invalid("not enough vouts for fillask"); @@ -341,8 +349,8 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti return eval->Invalid("normal vout1 for fillask"); else if( remaining_price != 0 ) { - if ( ConstrainVout(tx.vout[0], 1, (char *)cpAssets->unspendableCCaddr,0) == 0 ) - return eval->Invalid("mismatched vout0 AssetsCCaddr for fill"); + if ( ConstrainVout(tx.vout[0], 1, (char *)cpTokens->unspendableCCaddr,0) == 0 ) + return eval->Invalid("mismatched vout0 TokenCCaddr for fill"); } } fprintf(stderr,"fill validated\n"); @@ -363,7 +371,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti //if ( AssetExactAmounts(false, cp,inputs,outputs,eval,tx,assetid2) == false ) // eval->Invalid("asset2 inputs != outputs"); - if( (assetoshis= AssetValidateSellvin(cpAssets, eval, totalunits, tmporigpubkey, CCaddr, origaddr, tx, assetid)) == 0 ) + if( (assetoshis= AssetValidateSellvin(cpTokens, eval, totalunits, tmporigpubkey, tokensCCaddr, origaddr, tx, assetid)) == 0 ) return(false); else if( numvouts < 3 ) return eval->Invalid("not enough vouts for fillex"); @@ -375,7 +383,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti return eval->Invalid("locked value doesnt match vout0+1 fillex"); else if( tx.vout[3].scriptPubKey.IsPayToCryptoCondition() != 0 ) { - if( ConstrainVout(tx.vout[2], 1, CCaddr, 0) == 0 ) + if( ConstrainVout(tx.vout[2], 1, tokensCCaddr, 0) == 0 ) return eval->Invalid("vout2 doesnt go to origpubkey fillex"); else if( inputs != tx.vout[2].nValue + tx.vout[3].nValue ) { @@ -383,7 +391,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti return eval->Invalid("asset inputs doesnt match vout2+3 fillex"); } } - else if( ConstrainVout(tx.vout[2], 1, CCaddr, inputs) == 0 ) + else if( ConstrainVout(tx.vout[2], 1, tokensCCaddr, inputs) == 0 ) return eval->Invalid("vout2 doesnt match inputs fillex"); else if( ConstrainVout(tx.vout[1], 0, 0, 0) == 0 ) return eval->Invalid("vout1 is CC for fillex"); @@ -394,7 +402,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti return eval->Invalid("normal vout1 for fillex"); else if( remaining_price != 0 ) { - if( ConstrainVout(tx.vout[0], 1, (char *)cpAssets->unspendableCCaddr, 0) == 0 ) + if( ConstrainVout(tx.vout[0], 1, (char *)cpAssets->unspendableCCaddr, 0) == 0 ) // TODO: unsure about this, but this is not impl yet anyway return eval->Invalid("mismatched vout0 AssetsCCaddr for fillex"); } } diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 5d919d6e8..9ba6d4a84 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -326,7 +326,9 @@ std::string PricesAddFunding(uint64_t txfee,uint256 refbettoken,uint256 fundingt CCchange = (inputs - amount); mtx.vout.push_back(MakeCC1vout(cp->evalcode,CCchange,mypk)); // add addr2 - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('t',bettoken,zeroid,0,Mypubkey()))); + + std::vector voutTokenPubkeysEmpty; //TODO: add token vout pubkeys + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('t',bettoken,zeroid,0, voutTokenPubkeysEmpty, Mypubkey()))); } else { diff --git a/src/script/script.cpp b/src/script/script.cpp index 475acdfd5..ba3c7f78f 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -407,6 +407,20 @@ bool CScript::MayAcceptCryptoCondition() const cc_free(cond); return out; } +struct CC *CScript::GetCryptoCondition() const +{ + // Get the type mask of the condition + const_iterator pc = this->begin(); + vector data; + opcodetype opcode; + if (!this->GetOp(pc, opcode, data)) return NULL; + if (!(opcode > OP_0 && opcode < OP_PUSHDATA1)) return NULL; + struct CC *cond = cc_readConditionBinary(data.data(), data.size()); + if (!cond) return NULL; + //bool out = IsSupportedCryptoCondition(cond); + //cc_free(cond); + return cond; +} bool CScript::IsCoinImport() const { diff --git a/src/script/script.h b/src/script/script.h index b1294ab25..68757ef12 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -601,6 +601,8 @@ public: bool IsPayToCryptoCondition() const; bool IsCoinImport() const; bool MayAcceptCryptoCondition() const; + struct CC *GetCryptoCondition() const; + /** Called by IsStandardTx and P2SH/BIP62 VerifyScript (which makes it consensus-critical). */ bool IsPushOnly() const; From da58ead2d35ed374fa24b867d65b75a4e1ecc84c Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Fri, 4 Jan 2019 16:06:37 +0100 Subject: [PATCH 361/643] Prevent sell and buy offers to be canceled by anybody (#9) - Prevent sell and buy offers to be canceled by anybody --- src/cc/CCassetsCore.cpp | 2 ++ src/cc/CCassetstx.cpp | 28 ++++++++++++------ src/cc/CCtx.cpp | 3 +- src/cc/assets.cpp | 63 ++++++++++++++++++----------------------- 4 files changed, 52 insertions(+), 44 deletions(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index 837c4361e..f0afd2b84 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -432,6 +432,8 @@ int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmppr return(0); else if ( vinTx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) return eval->Invalid("invalid normal vout0 for buyvin"); + else if ( vinTx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) + return eval->Invalid("invalid normal vout1 for buyvin"); else { //fprintf(stderr,"have %.8f checking assetid origaddr.(%s)\n",(double)nValue/COIN,origaddr); diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index fe86d58de..a1ec8a816 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -371,7 +371,7 @@ std::string CreateBuyOffer(int64_t txfee, int64_t bidamount, uint256 assetid, in mypk = pubkey2pk(Mypubkey()); - if ((inputs = AddNormalinputs(mtx, mypk, bidamount+txfee, 64)) > 0) + if ((inputs = AddNormalinputs(mtx, mypk, bidamount+(2*txfee), 64)) > 0) { std::cerr << "CreateBuyOffer() inputs=" << inputs << std::endl; if (inputs < bidamount+txfee) { @@ -382,7 +382,7 @@ std::string CreateBuyOffer(int64_t txfee, int64_t bidamount, uint256 assetid, in CPubKey unspendablePubkey = GetUnspendable(cpAssets, 0); mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, bidamount, unspendablePubkey)); - + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, txfee, mypk)); std::vector voutTokenPubkeys; // should be empty - no token vouts return(FinalizeCCTx(0, cpAssets, mtx, mypk, txfee, EncodeAssetOpRet('b', assetid, zeroid, pricetotal, voutTokenPubkeys, Mypubkey()))); @@ -409,12 +409,12 @@ std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t p } cpTokens = CCinit(&C, EVAL_TOKENS); // NOTE: tokens is here - + if (txfee == 0) txfee = 10000; mypk = pubkey2pk(Mypubkey()); - if (AddNormalinputs(mtx, mypk, txfee, 3) > 0) + if (AddNormalinputs(mtx, mypk, 2*txfee, 3) > 0) { mask = ~((1LL << mtx.vin.size()) - 1); if ((inputs = AddTokenCCInputs(cpTokens, mtx, mypk, assetid, askamount, 60)) > 0) @@ -428,13 +428,14 @@ std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t p CPubKey unspendablePubkey = GetUnspendable(cpTokens, 0); mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, askamount, unspendablePubkey)); + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, txfee, mypk)); if (inputs > askamount) CCchange = (inputs - askamount); if (CCchange != 0) mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, CCchange, mypk)); std::vector voutTokenPubkeys; - voutTokenPubkeys.push_back(unspendablePubkey); + voutTokenPubkeys.push_back(unspendablePubkey); opret = EncodeAssetOpRet('s',assetid, zeroid, pricetotal, voutTokenPubkeys, Mypubkey()); return(FinalizeCCTx(mask,cpTokens,mtx,mypk,txfee,opret)); @@ -539,7 +540,9 @@ std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid) { bidamount = vintx.vout[0].nValue; mtx.vin.push_back(CTxIn(bidtxid, 0, CScript())); // coins in Assets + mtx.vin.push_back(CTxIn(bidtxid, 1, CScript())); mtx.vout.push_back(CTxOut(bidamount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); std::vector voutTokenPubkeys; // should be empty, no tokens vout @@ -554,27 +557,36 @@ std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CTransaction vintx; uint64_t mask; uint256 hashBlock; int64_t askamount; CPubKey mypk; - struct CCcontract_info *cpTokens, C; + struct CCcontract_info *cpTokens,*cpAssets,C,assetsC; cpTokens = CCinit(&C, EVAL_TOKENS); + cpAssets = CCinit(&assetsC, EVAL_ASSETS); if (txfee == 0) txfee = 10000; mypk = pubkey2pk(Mypubkey()); - if (AddNormalinputs(mtx, mypk, txfee, 3) > 0) + if (AddNormalinputs(mtx, mypk, txfee, 3) > 0) { mask = ~((1LL << mtx.vin.size()) - 1); if (GetTransaction(asktxid, vintx, hashBlock, false) != 0) { askamount = vintx.vout[0].nValue; mtx.vin.push_back(CTxIn(asktxid, 0, CScript())); + mtx.vin.push_back(CTxIn(asktxid, 1, CScript())); mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, askamount, mypk)); - + mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + std::vector voutTokenPubkeys; voutTokenPubkeys.push_back(mypk); + char myCCaddr[65]; + uint8_t myPrivkey[32]; + Myprivkey(myPrivkey); + GetCCaddress(cpAssets, myCCaddr, mypk); + CCaddr2set(cpTokens, EVAL_ASSETS, mypk, myPrivkey, myCCaddr); + return(FinalizeCCTx(mask, cpTokens, mtx, mypk, txfee, EncodeAssetOpRet('x', assetid, zeroid, 0, voutTokenPubkeys, Mypubkey()))); } } diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 3d95d0f17..971ba160d 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -175,7 +175,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran else { fprintf(stderr,"CC signing error: vini.%d has unknown CC address.(%s)\n",i,destaddr); - continue; + return(""); } uint256 sighash = SignatureHash(CCPubKey(cond), mtx, i, SIGHASH_ALL, utxovalues[i],consensusBranchId, &txdata); if ( cc_signTreeSecp256k1Msg32(cond,privkey,sighash.begin()) != 0 ) @@ -192,6 +192,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran else { fprintf(stderr,"vini.%d has CC signing error address.(%s)\n",i,destaddr); + return(""); } } } else fprintf(stderr,"FinalizeCCTx couldnt find %s\n",mtx.vin[i].prevout.hash.ToString().c_str()); diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index 3a62a526a..127a0e50a 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -45,32 +45,20 @@ valid CC output: create or transfer or buyoffer or selloffer or exchange or cancel or fill - create - vin.0: normal input - vout.0: issuance assetoshis to CC - vout.1: tag sent to normal address of AssetsCCaddress - vout.2: normal output for change (if any) - vout.n-1: opreturn [EVAL_ASSETS] ['c'] [origpubkey] "" "" - - transfer - vin.0: normal input - vin.1 .. vin.n-1: valid CC outputs - vout.0 to n-2: assetoshis output to CC - vout.n-2: normal output for change (if any) - vout.n-1: opreturn [EVAL_ASSETS] ['t'] [assetid] buyoffer: vins.*: normal inputs (bid + change) vout.0: amount of bid to unspendable - vout.1: normal output for change (if any) + vout.1: CC output for marker + vout.2: normal output for change (if any) vout.n-1: opreturn [EVAL_ASSETS] ['b'] [assetid] [amount of asset required] [origpubkey] cancelbuy: - vin.0: normal input - vin.1: unspendable.(vout.0 from buyoffer) buyTx.vout[0] + vin.0: unspendable.(vout.0 from buyoffer) buyTx.vout[0] + vin.1: CC marker from buyoffer for txfee vout.0: vin.1 value to original pubkey buyTx.vout[0].nValue -> [origpubkey] vout.1: normal output for change (if any) - vout.n-1: opreturn [EVAL_ASSETS] ['o'] [assetid] + vout.n-1: opreturn [EVAL_ASSETS] ['o'] [assetid] 0 0 [origpubkey] fillbuy: vin.0: normal input @@ -87,8 +75,9 @@ vin.0: normal input vin.1+: valid CC output for sale vout.0: vin.1 assetoshis output to CC to unspendable - vout.1: CC output for change (if any) - vout.2: normal output for change (if any) + vout.1: CC output for marker + vout.2: CC output for change (if any) + vout.3: normal output for change (if any) vout.n-1: opreturn [EVAL_ASSETS] ['s'] [assetid] [amount of native coin required] [origpubkey] exchange: @@ -100,8 +89,8 @@ vout.n-1: opreturn [EVAL_ASSETS] ['e'] [assetid] [assetid2] [amount of asset2 required] [origpubkey] cancel: - vin.0: normal input - vin.1: unspendable.(vout.0 from exchange or selloffer) sellTx/exchangeTx.vout[0] inputTx + vin.0: unspendable.(vout.0 from exchange or selloffer) sellTx/exchangeTx.vout[0] inputTx + vin.1: CC marker from selloffer for txfee vout.0: vin.1 assetoshis to original pubkey CC sellTx/exchangeTx.vout[0].nValue -> [origpubkey] vout.1: normal output for change (if any) vout.n-1: opreturn [EVAL_ASSETS] ['x'] [assetid] @@ -213,7 +202,8 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti case 'b': // buyoffer //vins.*: normal inputs (bid + change) //vout.0: amount of bid to unspendable - //vout.1: normal output for change (if any) + //vout.1: CC output for marker + //vout.2: normal output for change (if any) // vout.n-1: opreturn [EVAL_ASSETS] ['b'] [assetid] [amount of asset required] [origpubkey] if( remaining_price == 0 ) return eval->Invalid("illegal null amount for buyoffer"); @@ -225,8 +215,8 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti break; case 'o': // cancelbuy - //vin.0: normal input - //vin.1: unspendable.(vout.0 from buyoffer) buyTx.vout[0] + //vin.0: unspendable.(vout.0 from buyoffer) buyTx.vout[0] + //vin.1: CC marker from buyoffer for txfee //vout.0: vin.1 value to original pubkey buyTx.vout[0].nValue -> [origpubkey] //vout.1: normal output for change (if any) //vout.n-1: opreturn [EVAL_ASSETS] ['o'] @@ -234,7 +224,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti return(false); else if( ConstrainVout(tx.vout[0],0, origaddr, nValue) == 0 ) return eval->Invalid("invalid refund for cancelbuy"); - preventCCvins = 2; + preventCCvins = 3; preventCCvouts = 0; fprintf(stderr,"cancelbuy validated to origaddr.(%s)\n",origaddr); break; @@ -288,29 +278,32 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti //vin.0: normal input //vin.1+: valid CC output for sale //vout.0: vin.1 assetoshis output to CC to unspendable - //vout.1: CC output for change (if any) - //vout.2: normal output for change (if any) + //vout.1: CC output for marker + //vout.2: CC output for change (if any) + //vout.3: normal output for change (if any) //'s'.vout.n-1: opreturn [EVAL_ASSETS] ['s'] [assetid] [amount of native coin required] [origpubkey] //'e'.vout.n-1: opreturn [EVAL_ASSETS] ['e'] [assetid] [assetid2] [amount of asset2 required] [origpubkey] - preventCCvouts = 1; + preventCCvouts = 2; if( remaining_price == 0 ) return eval->Invalid("illegal null remaining_price for selloffer"); - if( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() != 0 ) // is cc change present? + if ( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) + return eval->Invalid("invalid normal vout1 for sellvin"); + if( tx.vout[2].scriptPubKey.IsPayToCryptoCondition() != 0 ) { preventCCvouts++; if( ConstrainVout(tx.vout[0], 1, (char *)cpTokens->unspendableCCaddr, 0) == 0 ) // check also vout[0] return eval->Invalid("mismatched vout0 TokensCCaddr for selloffer"); - else if( tx.vout[0].nValue + tx.vout[1].nValue != inputs ) - return eval->Invalid("mismatched vout0+vout1 total for selloffer"); + else if( tx.vout[0].nValue + tx.vout[2].nValue != inputs ) + return eval->Invalid("mismatched vout0+vout2 total for selloffer"); } else if( ConstrainVout(tx.vout[0], 1, (char *)cpTokens->unspendableCCaddr, inputs) == 0 ) // no cc change, just vout[0] return eval->Invalid("mismatched vout0 TokensCCaddr for selloffer"); //fprintf(stderr,"remaining.%d for sell\n",(int32_t)remaining_price); break; - case 'x': // cancel - //vin.0: normal input - //vin.1: unspendable.(vout.0 from exchange or selloffer) sellTx/exchangeTx.vout[0] inputTx + case 'x': // cancel + //vin.0: unspendable.(vout.0 from exchange or selloffer) sellTx/exchangeTx.vout[0] inputTx + //vin.1: CC marker from selloffer for txfee //vout.0: vin.1 assetoshis to original pubkey CC sellTx/exchangeTx.vout[0].nValue -> [origpubkey] //vout.1: normal output for change (if any) //vout.n-1: opreturn [EVAL_ASSETS] ['x'] [assetid] @@ -318,7 +311,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti return(false); else if( ConstrainVout(tx.vout[0], 1, tokensCCaddr, assetoshis) == 0 ) return eval->Invalid("invalid vout for cancel"); - preventCCvins = 2; + preventCCvins = 3; preventCCvouts = 1; break; From 5c95c974fdc54d8071329e7372d02203e4d4dc2b Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Fri, 4 Jan 2019 16:13:47 +0100 Subject: [PATCH 362/643] Change vin.vout structure in comments --- src/cc/assets.cpp | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index 127a0e50a..7c413d96a 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -54,10 +54,12 @@ vout.n-1: opreturn [EVAL_ASSETS] ['b'] [assetid] [amount of asset required] [origpubkey] cancelbuy: - vin.0: unspendable.(vout.0 from buyoffer) buyTx.vout[0] - vin.1: CC marker from buyoffer for txfee + vin.0: normal input + vin.1: unspendable.(vout.0 from buyoffer) buyTx.vout[0] + vin.2: CC marker from buyoffer for txfee vout.0: vin.1 value to original pubkey buyTx.vout[0].nValue -> [origpubkey] - vout.1: normal output for change (if any) + vout.1: vin.2 back to users pubkey + vout.2: normal output for change (if any) vout.n-1: opreturn [EVAL_ASSETS] ['o'] [assetid] 0 0 [origpubkey] fillbuy: @@ -89,10 +91,12 @@ vout.n-1: opreturn [EVAL_ASSETS] ['e'] [assetid] [assetid2] [amount of asset2 required] [origpubkey] cancel: - vin.0: unspendable.(vout.0 from exchange or selloffer) sellTx/exchangeTx.vout[0] inputTx - vin.1: CC marker from selloffer for txfee + vin.0: normal input + vin.1: unspendable.(vout.0 from exchange or selloffer) sellTx/exchangeTx.vout[0] inputTx + vin.2: CC marker from selloffer for txfee vout.0: vin.1 assetoshis to original pubkey CC sellTx/exchangeTx.vout[0].nValue -> [origpubkey] - vout.1: normal output for change (if any) + vout.1: vin.2 back to users pubkey + vout.2: normal output for change (if any) vout.n-1: opreturn [EVAL_ASSETS] ['x'] [assetid] fillsell: @@ -215,10 +219,12 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti break; case 'o': // cancelbuy - //vin.0: unspendable.(vout.0 from buyoffer) buyTx.vout[0] - //vin.1: CC marker from buyoffer for txfee + //vin.0: normal input + //vin.1: unspendable.(vout.0 from buyoffer) buyTx.vout[0] + //vin.2: CC marker from buyoffer for txfee //vout.0: vin.1 value to original pubkey buyTx.vout[0].nValue -> [origpubkey] - //vout.1: normal output for change (if any) + //vout.1: vin.2 back to users pubkey + //vout.2: normal output for change (if any) //vout.n-1: opreturn [EVAL_ASSETS] ['o'] if( (nValue= AssetValidateBuyvin(cpAssets, eval, tmpprice, tmporigpubkey, assetsCCaddr, origaddr, tx, assetid)) == 0 ) return(false); @@ -302,10 +308,12 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti break; case 'x': // cancel - //vin.0: unspendable.(vout.0 from exchange or selloffer) sellTx/exchangeTx.vout[0] inputTx - //vin.1: CC marker from selloffer for txfee + //vin.0: normal input + //vin.1: unspendable.(vout.0 from exchange or selloffer) sellTx/exchangeTx.vout[0] inputTx + //vin.2: CC marker from selloffer for txfee //vout.0: vin.1 assetoshis to original pubkey CC sellTx/exchangeTx.vout[0].nValue -> [origpubkey] - //vout.1: normal output for change (if any) + //vout.1: vin.2 back to users pubkey + //vout.2: normal output for change (if any) //vout.n-1: opreturn [EVAL_ASSETS] ['x'] [assetid] if( (assetoshis= AssetValidateSellvin(cpTokens, eval, tmpprice, tmporigpubkey, tokensCCaddr, origaddr, tx, assetid)) == 0 ) return(false); From a0fc5d6ae472cd5830f91a74fa1df6ed48de1108 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 7 Jan 2019 23:30:57 +0500 Subject: [PATCH 363/643] Corrected both Cancels, 'B' and TokenTransfer --- src/Makefile.am | 2 ++ src/cc/CCassetsCore.cpp | 4 +-- src/cc/CCassetstx.cpp | 34 ++++++++++++++++++-------- src/cc/CCtokens.cpp | 54 +++++++++++++++++++++++++++-------------- src/cc/CCtokens.h | 39 ++--------------------------- src/cc/assets.cpp | 2 ++ src/script/script.cpp | 14 ----------- src/script/script.h | 2 -- 8 files changed, 68 insertions(+), 83 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 9588cfe44..5e665cc3c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -384,6 +384,8 @@ libbitcoin_wallet_a_SOURCES = \ transaction_builder.cpp \ wallet/rpcdisclosure.cpp \ wallet/rpcdump.cpp \ + cc/CCtokens.cpp \ + cc/CCassetsCore.cpp \ cc/CCassetstx.cpp \ cc/CCtx.cpp \ wallet/rpcwallet.cpp \ diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index f0afd2b84..67e23837f 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -432,12 +432,12 @@ int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmppr return(0); else if ( vinTx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) return eval->Invalid("invalid normal vout0 for buyvin"); - else if ( vinTx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) + else if ((funcid = DecodeAssetOpRet(vinTx.vout[vinTx.vout.size() - 1].scriptPubKey, evalCode, assetid, assetid2, tmpprice, tmporigpubkey)) == 'b' && vinTx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) // marker is only in 'b'? return eval->Invalid("invalid normal vout1 for buyvin"); else { //fprintf(stderr,"have %.8f checking assetid origaddr.(%s)\n",(double)nValue/COIN,origaddr); - if ( vinTx.vout.size() > 0 && (funcid= DecodeAssetOpRet(vinTx.vout[vinTx.vout.size()-1].scriptPubKey, evalCode, assetid,assetid2,tmpprice,tmporigpubkey)) != 'b' && funcid != 'B' ) + if ( vinTx.vout.size() > 0 && funcid != 'b' && funcid != 'B' ) return eval->Invalid("invalid opreturn for buyvin"); else if ( refassetid != assetid ) return eval->Invalid("invalid assetid for buyvin"); diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index a1ec8a816..6bf176f24 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -148,7 +148,7 @@ UniValue AssetOrders(uint256 refassetid) //std::cerr << "addOrders() txid=" << txid.GetHex() << std::endl; if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - funcid = DecodeAssetOpRet(vintx.vout[vintx.vout.size() - 1].scriptPubKey, evalCode, assetid, assetid2, price, origpubkey); + // for logging: funcid = DecodeAssetOpRet(vintx.vout[vintx.vout.size() - 1].scriptPubKey, evalCode, assetid, assetid2, price, origpubkey); //std::cerr << "addOrders() vintx.vout.size()=" << vintx.vout.size() << " funcid=" << (char)(funcid ? funcid : ' ') << " assetid=" << assetid.GetHex() << std::endl; if (vintx.vout.size() > 0 && (funcid = DecodeAssetOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey, evalCode, assetid, assetid2, price, origpubkey)) != 0) { @@ -428,7 +428,7 @@ std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t p CPubKey unspendablePubkey = GetUnspendable(cpTokens, 0); mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, askamount, unspendablePubkey)); - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, txfee, mypk)); + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, txfee, mypk)); //marker if (inputs > askamount) CCchange = (inputs - askamount); if (CCchange != 0) @@ -526,6 +526,8 @@ std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid) CPubKey mypk; struct CCcontract_info *cpAssets, C; + uint8_t dummyEvalCode; uint256 dummyAssetid, dummyAssetid2; int64_t dummyPrice; std::vector dummyOrigpubkey; + cpAssets = CCinit(&C, EVAL_ASSETS); if (txfee == 0) @@ -540,7 +542,11 @@ std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid) { bidamount = vintx.vout[0].nValue; mtx.vin.push_back(CTxIn(bidtxid, 0, CScript())); // coins in Assets - mtx.vin.push_back(CTxIn(bidtxid, 1, CScript())); + + if( DecodeAssetOpRet(vintx.vout[vintx.vout.size() - 1].scriptPubKey, dummyEvalCode, dummyAssetid, dummyAssetid2, dummyPrice, dummyOrigpubkey) == 'b') + mtx.vin.push_back(CTxIn(bidtxid, 1, CScript())); // spend marker if funcid='b' (not 'B') + // TODO: spend it also in FillBuyOffer? + mtx.vout.push_back(CTxOut(bidamount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); @@ -559,6 +565,8 @@ std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) CTransaction vintx; uint64_t mask; uint256 hashBlock; int64_t askamount; CPubKey mypk; struct CCcontract_info *cpTokens,*cpAssets,C,assetsC; + uint8_t dummyEvalCode; uint256 dummyAssetid, dummyAssetid2; int64_t dummyPrice; std::vector dummyOrigpubkey; + cpTokens = CCinit(&C, EVAL_TOKENS); cpAssets = CCinit(&assetsC, EVAL_ASSETS); @@ -574,7 +582,11 @@ std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) { askamount = vintx.vout[0].nValue; mtx.vin.push_back(CTxIn(asktxid, 0, CScript())); - mtx.vin.push_back(CTxIn(asktxid, 1, CScript())); + + if (DecodeAssetOpRet(vintx.vout[vintx.vout.size() - 1].scriptPubKey, dummyEvalCode, dummyAssetid, dummyAssetid2, dummyPrice, dummyOrigpubkey) == 's') + mtx.vin.push_back(CTxIn(asktxid, 1, CScript())); // marker if funcid='s' (not 'S') + // TODO: spend it also in FillSell? + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, askamount, mypk)); mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); @@ -663,7 +675,7 @@ std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t f // token vout verification pubkeys: std::vector voutTokenPubkeys; - voutTokenPubkeys.push_back(unspendableTokensPk); + voutTokenPubkeys.push_back(pubkey2pk(origpubkey)); return(FinalizeCCTx(mask,cpTokens,mtx,mypk,txfee, EncodeAssetOpRet('B', assetid, zeroid, remaining_required, voutTokenPubkeys, origpubkey))); } else return("dont have any assets to fill bid"); @@ -743,22 +755,24 @@ std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 askt if (assetid2 != zeroid && inputs > paid_nValue) CCchange = (inputs - paid_nValue); - mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, orig_assetoshis - received_assetoshis, GetUnspendable(cpTokens, NULL))); // 0 tokens cc addr - ask remainder - mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, received_assetoshis, mypk)); //1 tokens to self + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, orig_assetoshis - received_assetoshis, GetUnspendable(cpTokens, NULL))); // vout.0 tokens cc addr - ask remainder + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, received_assetoshis, mypk)); //vout.1 tokens to self + // NOTE: no marker here + if (assetid2 != zeroid) { std::cerr << "FillSell() WARNING: asset swap not implemented yet! (paid_nValue)" << std::endl; - mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, paid_nValue, origpubkey)); //2 tokens... (swap is not implemented yet) + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, paid_nValue, origpubkey)); //vout.2 tokens... (swap is not implemented yet) } else { //std::cerr << "FillSell() paid_value=" << paid_nValue << " origpubkey=" << HexStr(pubkey2pk(origpubkey)) << std::endl; - mtx.vout.push_back(CTxOut(paid_nValue, CScript() << origpubkey << OP_CHECKSIG)); //2 coins normal to whom who asked token + mtx.vout.push_back(CTxOut(paid_nValue, CScript() << origpubkey << OP_CHECKSIG)); //vout.2 coins normal to whom who asked token } // not implemented if (CCchange != 0) { std::cerr << "FillSell() WARNING: asset swap not implemented yet! (CCchange)" << std::endl; - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, CCchange, mypk)); //3 coins in Assets cc addr + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, CCchange, mypk)); //vout.3 coins in Assets cc addr } // vout verification pubkeys: diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index d9e689f85..8e5d98f47 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -51,14 +51,19 @@ CScript EncodeTokenCreateOpRet(uint8_t funcid,std::vector origpubkey,st } // this is for other contracts which use tokens and build customized extra payloads to token's opret: -CScript EncodeTokenOpRet(uint8_t tokenFuncId, uint8_t evalCodeInOpret, uint256 tokenid, std::vector payload) +CScript EncodeTokenOpRet(uint8_t tokenFuncId, uint8_t evalCodeInOpret, uint256 tokenid, std::vector voutPubkeys) { CScript opret; + uint8_t ccType = 0; + if (voutPubkeys.size() >= 1 && voutPubkeys.size() <= 2) + ccType = voutPubkeys.size(); + //uint8_t evalcode = EVAL_TOKENS; tokenid = revuint256(tokenid); //uint8_t tokenFuncId = (isTransferrable) ? (uint8_t)'t' : (uint8_t)'l'; - opret << OP_RETURN << E_MARSHAL(ss << evalCodeInOpret << tokenFuncId << tokenid << payload); + //opret << OP_RETURN << E_MARSHAL(ss << evalCodeInOpret << tokenFuncId << tokenid << payload); + opret << OP_RETURN << E_MARSHAL(ss << evalCodeInOpret << tokenFuncId << tokenid << ccType; if (ccType >= 1) ss << voutPubkeys[0]; if (ccType == 2) ss << voutPubkeys[1];); return(opret); } @@ -148,6 +153,8 @@ bool TokensValidate(struct CCcontract_info *cp, Eval* eval, const CTransaction & char destaddr[64], origaddr[64], CCaddr[64]; std::vector voutTokenPubkeys; + //return true; + numvins = tx.vin.size(); numvouts = tx.vout.size(); outputs = inputs = 0; @@ -161,7 +168,7 @@ bool TokensValidate(struct CCcontract_info *cp, Eval* eval, const CTransaction & if (eval->GetTxUnconfirmed(tokenid, createTx, hashBlock) == 0) return eval->Invalid("cant find token create txid"); else if (IsCCInput(tx.vin[0].scriptSig) != 0) - return eval->Invalid("illegal token vin0"); // why? (dimxy) + return eval->Invalid("illegal token vin0"); else if (numvouts < 1) return eval->Invalid("no vouts"); else if (funcid != 'c') @@ -176,10 +183,6 @@ bool TokensValidate(struct CCcontract_info *cp, Eval* eval, const CTransaction & } } - // init for forwarding validation call - struct CCcontract_info *cpOther = NULL, C; - if (evalCodeInOpret != EVAL_TOKENS) - cpOther = CCinit(&C, evalCodeInOpret); switch (funcid) { @@ -211,11 +214,17 @@ bool TokensValidate(struct CCcontract_info *cp, Eval* eval, const CTransaction & } // forward validation if evalcode in opret is not EVAL_TOKENS - if (cpOther) - return cpOther->validate(cpOther, eval, tx, nIn); - else - return eval->Invalid("unsupported evalcode in opret"); + // init for forwarding validation call + if (evalCodeInOpret != EVAL_TOKENS) { // TODO: should we check also only allowed for tokens evalcodes, like EVAL_ASSETS, EVAL_GATEWAYS? + struct CCcontract_info *cpOther = NULL, C; + cpOther = CCinit(&C, evalCodeInOpret); + if (cpOther) + return cpOther->validate(cpOther, eval, tx, nIn); + else + return eval->Invalid("unsupported evalcode in opret"); + } + return true; // what does this do? // return(PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts)); } @@ -404,7 +413,7 @@ bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t tokenValIndentSize++; // validate vouts of vintx //std::cerr << indentStr << "TokenExactAmounts() check vin i=" << i << " nValue=" << vinTx.vout[tx.vin[i].prevout.n].nValue << std::endl; - tokenoshis = IsTokensvout(goDeeper, false/*<--do not have pubkeys*/, cpTokens, eval, tmporigpubkey, vinTx, tx.vin[i].prevout.n, tokenid, vinPubkeysEmpty); + tokenoshis = IsTokensvout(goDeeper, false/*<--do not have pubkeys for now*/, cpTokens, eval, tmporigpubkey, vinTx, tx.vin[i].prevout.n, tokenid, vinPubkeysEmpty); tokenValIndentSize--; if (tokenoshis != 0) { @@ -435,7 +444,7 @@ bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t if (inputs != outputs) { if (tx.GetHash() != tokenid) - std::cerr << indentStr << "TokenExactAmounts() found unequal inputs=" << inputs << " vs outputs=" << outputs << " for txid=" << tx.GetHash().GetHex() << " and this is not create tx" << std::endl; + std::cerr << indentStr << "TokenExactAmounts() found unequal token cc inputs=" << inputs << " vs cc outputs=" << outputs << " for txid=" << tx.GetHash().GetHex() << " and this is not the create tx" << std::endl; return false; // do not call eval->Invalid() here! } else @@ -477,7 +486,7 @@ int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, C fprintf(stderr, "AddTokenCCInputs() check destaddress=%s vout amount=%.8f\n", destaddr, (double)vintx.vout[vout].nValue / COIN); std::vector vinPubkeysEmpty; - if ((nValue = IsTokensvout(true, false, cp, NULL, vopretExtra, vintx, vout, tokenid, vinPubkeysEmpty)) > 0 && myIsutxo_spentinmempool(txid, vout) == 0) + if ((nValue = IsTokensvout(true, false/*<-- do not check spending outside EVAL_TOKENS for now */, cp, NULL, vopretExtra, vintx, vout, tokenid, vinPubkeysEmpty)) > 0 && myIsutxo_spentinmempool(txid, vout) == 0) { if (total != 0 && maxinputs != 0) mtx.vin.push_back(CTxIn(txid, vout, CScript())); @@ -559,13 +568,22 @@ std::string TokenTransfer(int64_t txfee, uint256 assetid, std::vector d if (inputs > total) CCchange = (inputs - total); //for (i=0; i voutTokenPubkeys; + voutTokenPubkeys.push_back(pubkey2pk(destpubkey)); // dest pubkey for validating vout + + return(FinalizeCCTx(mask, cp, mtx, mypk, txfee, EncodeTokenOpRet('t', EVAL_TOKENS, assetid, voutTokenPubkeys))); // By setting EVAL_TOKENS we're getting out from assets validation code + } + else { + fprintf(stderr, "not enough CC token inputs for %.8f\n", (double)total / COIN); } - else fprintf(stderr, "not enough CC asset inputs for %.8f\n", (double)total / COIN); //} else fprintf(stderr,"numoutputs.%d != numamounts.%d\n",n,(int32_t)amounts.size()); } + else { + fprintf(stderr, "not enough normal inputs for txfee\n"); + } return(""); } \ No newline at end of file diff --git a/src/cc/CCtokens.h b/src/cc/CCtokens.h index 8ecbc1094..f65a56b41 100644 --- a/src/cc/CCtokens.h +++ b/src/cc/CCtokens.h @@ -31,46 +31,11 @@ bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t //int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 reftokenid, std::vector vinPubkeys); std::string CreateToken(int64_t txfee, int64_t assetsupply, std::string name, std::string description); std::string TokenTransfer(int64_t txfee, uint256 assetid, std::vector destpubkey, int64_t total); +CScript EncodeTokenOpRet(uint8_t tokenFuncId, uint8_t evalCodeInOpret, uint256 tokenid, std::vector voutPubkeys); -//this is in CCinclude.h int64_t AddTokenInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs); +//this is in CCinclude.h int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs); //this is in CCinclude.h uint8_t DecodeTokenCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description); -/* -// CCassetsCore -CScript EncodeAssetCreateOpRet(uint8_t funcid,std::vector origpubkey,std::string name,std::string description); -CScript EncodeAssetOpRet(uint8_t funcid,uint256 assetid,uint256 assetid2,int64_t price,std::vector origpubkey); -bool DecodeAssetCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description); -//uint8_t DecodeAssetOpRet(const CScript &scriptPubKey, uint8_t &evalCode, uint256 &assetid, uint256 &assetid2, int64_t &price, std::vector &origpubkey); -bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CTransaction &tx); -int64_t IsAssetvout(bool compareTotals, struct CCcontract_info *cp, Eval* eval, int64_t &price, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 refassetid); -bool ValidateBidRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); -bool ValidateAskRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); -bool ValidateSwapRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); -bool SetBidFillamounts(int64_t &paid,int64_t &remaining_price,int64_t orig_nValue,int64_t &received,int64_t totalprice); -bool SetAskFillamounts(int64_t &paid,int64_t &remaining_price,int64_t orig_nValue,int64_t &received,int64_t totalprice); -bool SetSwapFillamounts(int64_t &paid,int64_t &remaining_price,int64_t orig_nValue,int64_t &received,int64_t totalprice); -int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 refassetid); -int64_t AssetValidateSellvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 assetid); -bool AssetExactAmounts(bool compareTotals, struct CCcontract_info *cpAssets, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 assetid); - -// CCassetstx -int64_t GetAssetBalance(CPubKey pk,uint256 tokenid); -int64_t AddAssetInputs(CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs); -UniValue AssetOrders(uint256 tokenid); -UniValue AssetInfo(uint256 tokenid); -UniValue AssetList(); -std::string CreateAsset(int64_t txfee,int64_t assetsupply,std::string name,std::string description); -std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total); -std::string AssetConvert(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total,int32_t evalcode); - -std::string CreateBuyOffer(int64_t txfee,int64_t bidamount,uint256 assetid,int64_t pricetotal); -std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid); -std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t fillamount); -std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t pricetotal); -std::string CreateSwap(int64_t txfee,int64_t askamount,uint256 assetid,uint256 assetid2,int64_t pricetotal); -std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid); -std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 asktxid,int64_t fillamount); -*/ #endif diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index 7c413d96a..ea44453ff 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -135,6 +135,8 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti uint8_t funcid, evalCodeInOpret; char destaddr[64], origaddr[64], assetsCCaddr[64], tokensCCaddr[64]; + //return true; + // we need this for validating tokens' vins/vous: struct CCcontract_info *cpTokens, tokensC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); diff --git a/src/script/script.cpp b/src/script/script.cpp index ba3c7f78f..475acdfd5 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -407,20 +407,6 @@ bool CScript::MayAcceptCryptoCondition() const cc_free(cond); return out; } -struct CC *CScript::GetCryptoCondition() const -{ - // Get the type mask of the condition - const_iterator pc = this->begin(); - vector data; - opcodetype opcode; - if (!this->GetOp(pc, opcode, data)) return NULL; - if (!(opcode > OP_0 && opcode < OP_PUSHDATA1)) return NULL; - struct CC *cond = cc_readConditionBinary(data.data(), data.size()); - if (!cond) return NULL; - //bool out = IsSupportedCryptoCondition(cond); - //cc_free(cond); - return cond; -} bool CScript::IsCoinImport() const { diff --git a/src/script/script.h b/src/script/script.h index 68757ef12..b1294ab25 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -601,8 +601,6 @@ public: bool IsPayToCryptoCondition() const; bool IsCoinImport() const; bool MayAcceptCryptoCondition() const; - struct CC *GetCryptoCondition() const; - /** Called by IsStandardTx and P2SH/BIP62 VerifyScript (which makes it consensus-critical). */ bool IsPushOnly() const; From 90f682f022ba5284ae506e31d0522284e85045c2 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 7 Jan 2019 19:00:34 +0500 Subject: [PATCH 364/643] Heir corrected for Tokens contract --- src/cc/CCassetstx.cpp | 2 +- src/cc/heir.cpp | 89 ++++++++++++++++++++++++++++++++---------- src/cc/heir_validate.h | 43 ++++++++------------ 3 files changed, 85 insertions(+), 49 deletions(-) diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 6bf176f24..1c2012534 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -597,7 +597,7 @@ std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) uint8_t myPrivkey[32]; Myprivkey(myPrivkey); GetCCaddress(cpAssets, myCCaddr, mypk); - CCaddr2set(cpTokens, EVAL_ASSETS, mypk, myPrivkey, myCCaddr); + CCaddr2set(cpTokens, EVAL_ASSETS, mypk, myPrivkey, myCCaddr); //do we need this? Seems FinalizeCCTx can attach to any evalcode cc addr by calling Getscriptaddress return(FinalizeCCTx(mask, cpTokens, mtx, mypk, txfee, EncodeAssetOpRet('x', assetid, zeroid, 0, voutTokenPubkeys, Mypubkey()))); } diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 90557d7ac..7512b54ed 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -14,7 +14,7 @@ ******************************************************************************/ #include "CCHeir.h" -#include "CCassets.h" +#include "CCtokens.h" #include "heir_validate.h" @@ -433,47 +433,79 @@ bool HeirExactAmounts(struct CCcontract_info* cp, Eval* eval, const CTransaction } // makes coin initial tx opret -CScript EncodeHeirCreateOpRet(uint8_t eval, uint8_t funcid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName) +CScript EncodeHeirCreateOpRet(uint8_t funcid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName) { - return CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)eval << (uint8_t)funcid << ownerPubkey << heirPubkey << inactivityTimeSec << heirName); + uint8_t evalcode = EVAL_HEIR; + + return CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)evalcode << (uint8_t)funcid << ownerPubkey << heirPubkey << inactivityTimeSec << heirName); } // makes coin additional tx opret -CScript EncodeHeirOpRet(uint8_t eval, uint8_t funcid, uint256 fundingtxid) +CScript EncodeHeirOpRet(uint8_t funcid, uint256 fundingtxid) { + uint8_t evalcode = EVAL_HEIR; + fundingtxid = revuint256(fundingtxid); - return CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)eval << (uint8_t)funcid << fundingtxid); + return CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)evalcode << (uint8_t)funcid << fundingtxid); } // makes opret for tokens while they are inside Heir contract address space - initial funding -CScript EncodeHeirAssetsCreateOpRet(uint8_t eval, uint8_t funcid, uint256 tokenid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string hearName) +CScript EncodeHeirTokensCreateOpRet(uint8_t funcid, uint256 tokenid, std::vector voutPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string hearName) { + uint8_t evalcode = EVAL_TOKENS; + uint8_t ccType = 0; + if (voutPubkeys.size() >= 1 && voutPubkeys.size() <= 2) + ccType = voutPubkeys.size(); + tokenid = revuint256(tokenid); - return CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)eval << (uint8_t)'t' << tokenid << (uint8_t)funcid << ownerPubkey << heirPubkey << inactivityTimeSec << hearName); + return CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)evalcode << (uint8_t)'t' << tokenid << (uint8_t)funcid << ccType; if (ccType >= 1) ss << voutPubkeys[0]; if (ccType == 2) ss << voutPubkeys[1]; ss << ownerPubkey << heirPubkey << inactivityTimeSec << hearName); } // makes opret for tokens while they are inside Heir contract address space - additional funding -CScript EncodeHeirAssetsOpRet(uint8_t eval, uint8_t funcid, uint256 tokenid, uint256 fundingtxid) +CScript EncodeHeirTokensOpRet(uint8_t funcid, uint256 tokenid, std::vector voutPubkeys, uint256 fundingtxid) { + uint8_t evalcode = EVAL_HEIR; + uint8_t ccType = 0; + if (voutPubkeys.size() >= 1 && voutPubkeys.size() <= 2) + ccType = voutPubkeys.size(); + tokenid = revuint256(tokenid); fundingtxid = revuint256(fundingtxid); - return CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)eval << (uint8_t)'t' << tokenid << (uint8_t)funcid << fundingtxid); + return CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)evalcode << (uint8_t)'t' << tokenid << ccType; if (ccType >= 1) ss << voutPubkeys[0]; if (ccType == 2) ss << voutPubkeys[1]; ss << (uint8_t)funcid << fundingtxid); } +// helper for decode heir opret payload +// NOTE: Heir for coins has the same opret as Heir for tokens +uint8_t _UnmarshalOpret(std::vector vopretExtra, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret) { + uint8_t heirFuncId = 0; + + bool result = E_UNMARSHAL(vopretExtra, { ss >> heirFuncId; ss >> ownerPubkey; ss >> heirPubkey; ss >> inactivityTime; if (IS_CHARINSTR(heirFuncId, "F")) { ss >> heirName; } if (IS_CHARINSTR(heirFuncId, "AC")) { ss >> fundingTxidInOpret; } }); + if (!result /*|| assetFuncId != 't' -- any tx is ok*/) + return (uint8_t)0; + + return heirFuncId; +} /** * decode opret vout for Heir contract */ template uint8_t _DecodeHeirOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret, bool noLogging) { - std::vector vopret; - uint8_t opretEval = 0; - uint8_t funcId = 0; + uint8_t evalCodeInOpret = 0; + + std::vector vopretExtra; + uint256 dummyTokenid; + std::vector voutPubkeysDummy; fundingTxidInOpret = zeroid; //to init + tokenid = zeroid; - GetOpReturnData(scriptPubKey, vopret); - if (vopret.size() > 1) { + // First - decode token opret: + uint8_t funcId = DecodeTokenOpRet(scriptPubKey, evalCodeInOpret, tokenid, voutPubkeysDummy, vopretExtra); + + //GetOpReturnData(scriptPubKey, vopret); + + if (funcId != 0 && vopretExtra.size() > 1) { // TODO: add this funcId cond in Assets too // NOTE: it unmarshals for all F, A and C - Helper::UnmarshalOpret(vopret, opretEval, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, fundingTxidInOpret); + uint8_t heirFuncId = _UnmarshalOpret(vopretExtra, ownerPubkey, heirPubkey, inactivityTime, heirName, fundingTxidInOpret); /* std::cerr << "DecodeHeirOpRet() e=" << (int)e @@ -484,14 +516,14 @@ template uint8_t _DecodeHeirOpRet(CScript scriptPubKey, uint256 & */ //if (e == EVAL_HEIR && IS_CHARINSTR(funcId, "FAC")) - if (opretEval == EVAL_HEIR && Helper::isMyFuncId(funcId)) { + if (evalCodeInOpret == EVAL_HEIR && Helper::isMyFuncId(heirFuncId)) { tokenid = revuint256(tokenid); fundingTxidInOpret = revuint256(fundingTxidInOpret); - return funcId; + return heirFuncId; } else { - if(!noLogging) std::cerr << "DecodeHeirOpRet() warning unexpected OP_RETURN eval=" << (int)opretEval << " or field type=" << (char)(funcId ? funcId : ' ') << '\n'; + if(!noLogging) std::cerr << "DecodeHeirOpRet() warning unexpected OP_RETURN eval=" << (int)evalCodeInOpret << " or field type=" << (char)(heirFuncId ? heirFuncId : ' ') << '\n'; } } else { @@ -843,10 +875,15 @@ template std::string HeirFund(uint64_t txfee, int64_t amount, mtx.vout.push_back(Helper::makeUserVout(change, myPubkey)); } + // add 1of2 vout validation pubkeys: + std::vector voutTokenPubkeys; + voutTokenPubkeys.push_back(myPubkey); + voutTokenPubkeys.push_back(heirPubkey); + // add change for txfee and opreturn vouts and sign tx: return (FinalizeCCTx(0, cp, mtx, myPubkey, txfee, // CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_HEIR << (uint8_t)'F' << myPubkey << heirPubkey << inactivityTimeSec << heirName))); - Helper::makeCreateOpRet(tokenid, myPubkey, heirPubkey, inactivityTimeSec, heirName))); + Helper::makeCreateOpRet(tokenid, voutTokenPubkeys, myPubkey, heirPubkey, inactivityTimeSec, heirName))); } else // TODO: need result return unification with heiradd and claim std::cerr << "HeirFund() could not find owner inputs" << std::endl; @@ -928,9 +965,14 @@ template UniValue HeirAdd(uint256 fundingtxid, uint64_t txfee, in mtx.vout.push_back(Helper::makeUserVout(change, myPubkey)); } + // add 1of2 vout validation pubkeys: + std::vector voutTokenPubkeys; + voutTokenPubkeys.push_back(ownerPubkey); + voutTokenPubkeys.push_back(heirPubkey); + // add opreturn 'A' and sign tx: // this txfee ignored std::string rawhextx = (FinalizeCCTx(0, cp, mtx, myPubkey, txfee, - Helper::makeAddOpRet(tokenid, fundingtxid))); + Helper::makeAddOpRet(tokenid, voutTokenPubkeys, fundingtxid))); result.push_back(Pair("result", "success")); result.push_back(Pair("hextx", rawhextx)); @@ -1068,9 +1110,14 @@ template UniValue HeirClaim(uint256 fundingtxid, uint64_t txfee CCaddr1of2set(cp, ownerPubkey, heirPubkey, coinaddr); + // add 1of2 vout validation pubkeys: + std::vector voutTokenPubkeys; + voutTokenPubkeys.push_back(ownerPubkey); + voutTokenPubkeys.push_back(heirPubkey); + // add opreturn 'C' and sign tx: // this txfee will be ignored std::string rawhextx = FinalizeCCTx(0, cp, mtx, myPubkey, txfee, - Helper::makeClaimOpRet(tokenid, fundingtxid)); + Helper::makeClaimOpRet(tokenid, voutTokenPubkeys, fundingtxid)); result.push_back(Pair("result", "success")); result.push_back(Pair("hextx", rawhextx)); diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index 8b432e8e0..108562e24 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -11,12 +11,12 @@ // makes coin initial tx opret -CScript EncodeHeirCreateOpRet(uint8_t eval, uint8_t funcid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName); +CScript EncodeHeirCreateOpRet(uint8_t funcid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName); // makes coin additional tx opret -CScript EncodeHeirOpRet(uint8_t eval, uint8_t funcid, uint256 fundingtxid); +CScript EncodeHeirOpRet(uint8_t funcid, uint256 fundingtxid); -CScript EncodeHeirAssetsCreateOpRet(uint8_t eval, uint8_t funcid, uint256 tokenid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string hearName); -CScript EncodeHeirAssetsOpRet(uint8_t eval, uint8_t funcid, uint256 tokenid, uint256 fundingtxid); +CScript EncodeHeirTokensCreateOpRet(uint8_t funcid, uint256 tokenid, std::vector voutPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string hearName); +CScript EncodeHeirTokensOpRet(uint8_t funcid, uint256 tokenid, std::vector voutPubkeys, uint256 fundingtxid); //CScript EncodeHeirConvertedAssetsOpRet(uint8_t eval, uint8_t funcid, uint256 tokenid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 fundingtxid); template uint256 FindLatestFundingTx(uint256 fundingtxid, uint256 &tokenid, CScript& opRetScript, bool &isHeirSpendingBegan); @@ -37,18 +37,14 @@ public: return AddNormalinputs(mtx, ownerPubkey, total, maxinputs); } - static CScript makeCreateOpRet(uint256 dummyid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName) { - return EncodeHeirCreateOpRet((uint8_t)EVAL_HEIR, (uint8_t)'F', ownerPubkey, heirPubkey, inactivityTimeSec, heirName); + static CScript makeCreateOpRet(uint256 dummyid, std::vector dummyPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName) { + return EncodeHeirCreateOpRet((uint8_t)'F', ownerPubkey, heirPubkey, inactivityTimeSec, heirName); } - static CScript makeAddOpRet(uint256 dummyid, uint256 fundingtxid) { - return EncodeHeirOpRet((uint8_t)EVAL_HEIR, (uint8_t)'A', fundingtxid); + static CScript makeAddOpRet(uint256 dummyid, std::vector dummyPubkeys, uint256 fundingtxid) { + return EncodeHeirOpRet((uint8_t)'A', fundingtxid); } - static CScript makeClaimOpRet(uint256 dummyid, uint256 fundingtxid) { - return EncodeHeirOpRet((uint8_t)EVAL_HEIR, (uint8_t)'C', fundingtxid); - } - - static void UnmarshalOpret(std::vector vopret, uint8_t &e, uint8_t &funcId, uint256 &dummytokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret) { - E_UNMARSHAL(vopret, { ss >> e; ss >> funcId; ss >> ownerPubkey; ss >> heirPubkey; ss >> inactivityTime; if (IS_CHARINSTR(funcId, "F")) { ss >> heirName; } if (IS_CHARINSTR(funcId, "AC")) { ss >> fundingTxidInOpret; } }); + static CScript makeClaimOpRet(uint256 dummyid, std::vector dummyPubkeys, uint256 fundingtxid) { + return EncodeHeirOpRet((uint8_t)'C', fundingtxid); } static bool isSpendingTx(uint8_t funcid) { return (funcid == 'C'); } @@ -64,29 +60,22 @@ public: // helper class to allow polymorphic behaviour for HeirXXX() functions in case of tokens class TokenHelper { public: - static bool isMyFuncId(uint8_t funcid) { return IS_CHARINSTR(funcid, "FAC"); } static uint8_t getMyEval() { return EVAL_TOKENS; } static int64_t addOwnerInputs(struct CCcontract_info* cp, uint256 tokenid, CMutableTransaction& mtx, CPubKey ownerPubkey, int64_t total, int32_t maxinputs) { return AddTokenCCInputs(cp, mtx, ownerPubkey, tokenid, total, maxinputs); } - static CScript makeCreateOpRet(uint256 tokenid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName) { - return EncodeHeirAssetsCreateOpRet((uint8_t)EVAL_HEIR, (uint8_t)'F', tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName); + static CScript makeCreateOpRet(uint256 tokenid, std::vector voutTokenPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName) { + return EncodeHeirTokensCreateOpRet((uint8_t)'F', tokenid, voutTokenPubkeys, ownerPubkey, heirPubkey, inactivityTimeSec, heirName); } - static CScript makeAddOpRet(uint256 tokenid, uint256 fundingtxid) { - return EncodeHeirAssetsOpRet((uint8_t)EVAL_HEIR, (uint8_t)'A', tokenid, fundingtxid); + static CScript makeAddOpRet(uint256 tokenid, std::vector voutTokenPubkeys, uint256 fundingtxid) { + return EncodeHeirTokensOpRet((uint8_t)'A', tokenid, voutTokenPubkeys, fundingtxid); } - static CScript makeClaimOpRet(uint256 tokenid, uint256 fundingtxid) { - return EncodeHeirAssetsOpRet((uint8_t)EVAL_HEIR, (uint8_t)'C', tokenid, fundingtxid); + static CScript makeClaimOpRet(uint256 tokenid, std::vector voutTokenPubkeys, uint256 fundingtxid) { + return EncodeHeirTokensOpRet((uint8_t)'C', tokenid, voutTokenPubkeys, fundingtxid); } - static void UnmarshalOpret(std::vector vopret, uint8_t &e, uint8_t &funcId, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingtxidInOpret) { - uint8_t assetFuncId = '\0'; - bool result = E_UNMARSHAL(vopret, { ss >> e; ss >> assetFuncId; ss >> tokenid; ss >> funcId; if (IS_CHARINSTR(funcId, "F")) { ss >> ownerPubkey; ss >> heirPubkey; ss >> inactivityTime; ss >> heirName; } if (IS_CHARINSTR(funcId, "AC")) { ss >> fundingtxidInOpret; } }); - if (!result /*|| assetFuncId != 't' -- any tx is ok*/) - funcId = 0; - } static bool isSpendingTx(uint8_t funcid) { return (funcid == 'C'); } static CTxOut makeUserVout(int64_t amount, CPubKey myPubkey) { From d1bd5b3b6c0cc645addf8889e7252baa9ca6b413 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 9 Jan 2019 16:58:52 +0500 Subject: [PATCH 365/643] Squashed commit of the following: commit 843168eddff34390f19fa661ac6315e1a51aafe2 Author: dimxy Date: Wed Jan 9 14:34:03 2019 +0500 logging improved for CCtokens.cpp commit 43c5b3a5c4e36e76a235f987e07fe893d941d95e Author: dimxy Date: Wed Jan 9 14:23:41 2019 +0500 more extra logging disabled for heir and token commit a3f7ca963a0042237f4c97d6d89852646b541c6c Author: dimxy Date: Wed Jan 9 14:13:58 2019 +0500 more extra logging disabled commit f4dec8f8ad733c5a61dd0fc9f3decd103dd7a0c3 Author: dimxy Date: Wed Jan 9 14:05:45 2019 +0500 more extra logging disabled commit eb9a41472004ccdacdacfc12b79880ac6da390ee Author: dimxy Date: Wed Jan 9 13:50:11 2019 +0500 extra logging disabled in heir and tokens commit 0fe01c8a7b52b03e0c0a3ba5d77f916862031d23 Author: dimxy Date: Wed Jan 9 13:15:08 2019 +0500 heir normal input validator changed to CNullValidator commit 3b86e87c83b6993d5a3b4c056c10120223e8c9ed Author: dimxy Date: Wed Jan 9 12:58:03 2019 +0500 enabled logiing in FinalizeCCtx commit 2ea87c1b3c7967b316d22e2e65fc3c0203cc4b03 Author: dimxy Date: Wed Jan 9 12:37:43 2019 +0500 corrected parameters for tests commit 216eb4ed84c6fd23e3fc22cd79509a09c8504c0c Author: dimxy Date: Wed Jan 9 12:22:30 2019 +0500 changed to eval_assets for test commit 2af850f06a4692200864a316208cdfc0709b1634 Author: dimxy Date: Wed Jan 9 02:42:43 2019 +0500 heiradd loggin vin commit 28e033d2b2a1a01b2bc9c2d51a81b61ae53f3a29 Author: dimxy Date: Wed Jan 9 02:04:33 2019 +0500 logging added commit ef1dbc504c5984a4997b5e06e736fa7b5b4e125d Author: dimxy Date: Wed Jan 9 01:29:46 2019 +0500 logging added and corrected commit 98c1e5a6896a97667c9d64f347c26b36c6a320a9 Author: dimxy Date: Wed Jan 9 01:05:17 2019 +0500 corrected isHeirSpendingBegan init in _UnmarshalOpret commit 6006f073bfc136ed06c1636b3e6ffa7b403ce1d9 Author: dimxy Date: Wed Jan 9 01:01:18 2019 +0500 corrected dummyIsHeirSpendingBegan using commit 9a95edf4e311a80538dd7b13aeeb201e97474ee8 Author: dimxy Date: Wed Jan 9 00:53:50 2019 +0500 isHeirSpendingBegan is put in opret commit 4bd210709626e2f8b99889e50410eb0f75b3dbda Author: dimxy Date: Tue Jan 8 20:16:20 2019 +0500 added logging to _FindLastextFundingTx for print C vouts commit 3603b49c1143b1efe82dd545b9d7dca43f5bcec0 Author: dimxy Date: Tue Jan 8 19:25:11 2019 +0500 corrected isHeirSpendingBegun calc commit e7d6923d4be080a5e98405634fafb175fa55f801 Author: dimxy Date: Tue Jan 8 18:43:35 2019 +0500 yet another cpToken correction in RunValidators commit e425dcc4497652a062b45d4a5ce4c137bd2caa3d Author: dimxy Date: Tue Jan 8 18:22:08 2019 +0500 changed cp param to cpTokens for heir tokens in validation commit a4420f30d42d93dbc2729db4a5b2895d4b16d22b Author: dimxy Date: Tue Jan 8 17:11:10 2019 +0500 corrected EVAL_HEIR in create opret commit 788d75263fd5aaa7b66417441622c9bb6603ab81 Author: dimxy Date: Tue Jan 8 16:41:07 2019 +0500 corrected opret forming for 'F', tokens commit 92bf6c53b36a5a4450b5c7079383792d634d61a7 Author: dimxy Date: Tue Jan 8 16:12:09 2019 +0500 _UnmarshalOpret corrected for non F commit e4eb26e875d44f3e4c1d45aff6df8a7026b3329a Author: dimxy Date: Tue Jan 8 15:26:34 2019 +0500 Revert "CCduration debug logging added" This reverts commit 5ffc2b0a8b49d387cd175754738d2c07701c7856. commit ce97ac88af0b87b304ad1fc9cb29db0803d0bd42 Author: dimxy Date: Tue Jan 8 15:17:10 2019 +0500 changed pindex to pindexTip in CCduration for better reading commit 5ffc2b0a8b49d387cd175754738d2c07701c7856 Author: dimxy Date: Tue Jan 8 14:43:07 2019 +0500 CCduration debug logging added commit 34afdd16f0f6b5b97da864f082dcd019a7566da7 Author: dimxy Date: Tue Jan 8 12:23:31 2019 +0500 corrected again order to DecodeOpRet call in heir commit bba6149969ea23aa4e3c6263a36bae0ba7fa6f5d Author: dimxy Date: Tue Jan 8 12:17:11 2019 +0500 logging added in IsHeirFundingVout commit 6c5d4b313ef3e54cb5eb2bf67b2fa78d9ffd0b04 Author: dimxy Date: Tue Jan 8 12:02:15 2019 +0500 logging added to Add1of2AddrInputs commit 40d6d84971a8ed764523567f08df4c74fda4f12d Author: dimxy Date: Tue Jan 8 11:36:23 2019 +0500 corrected vopretExtra getting for heir for coins commit 36061d25fb8992551915afc3dd0600878a64c540 Author: dimxy Date: Tue Jan 8 11:13:30 2019 +0500 corrected CCinit C-param separate commit 0a6710433868c315afe3f656c1bc5f5138fe5288 Author: dimxy Date: Tue Jan 8 10:58:19 2019 +0500 logging added in decodeheiropret commit 2503d8cb59b94b024a9ded43a0602f89800a9549 Author: dimxy Date: Tue Jan 8 10:39:21 2019 +0500 corrected decode opret for heir for coins --- src/cc/CCtokens.cpp | 19 +- src/cc/CCtx.cpp | 1 - src/cc/heir.cpp | 534 ++++++++++++++--------------------------- src/cc/heir_validate.h | 84 +++---- 4 files changed, 237 insertions(+), 401 deletions(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 8e5d98f47..4a2c6031e 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -92,7 +92,7 @@ uint8_t DecodeTokenOpRet(const CScript scriptPubKey, uint8_t &evalCode, uint256 script = (uint8_t *)vopret.data(); tokenid = zeroid; - if (script != 0 /*enable all evals: && script[0] == EVAL_TOKENS*/) + if (script != 0 && vopret.size() > 2) { // NOTE: if parse error occures, parse might not be able to set error. It is safer to treat that it was eof if it is not set! bool isEof = true; @@ -114,7 +114,7 @@ uint8_t DecodeTokenOpRet(const CScript scriptPubKey, uint8_t &evalCode, uint256 { if (!(ccType >= 0 && ccType <= 2)) { //incorrect ccType - std::cerr << "DecodeTokenOpRet() incorrect ccType=" << (int)ccType << std::endl; + std::cerr << "DecodeTokenOpRet() incorrect ccType=" << (int)ccType << " tokenid=" << revuint256(tokenid).GetHex() << std::endl; return (uint8_t)0; } @@ -128,7 +128,7 @@ uint8_t DecodeTokenOpRet(const CScript scriptPubKey, uint8_t &evalCode, uint256 tokenid = revuint256(tokenid); return(funcId); } - std::cerr << "DecodeTokenOpRet() warning: bad opret format, isEof=" << isEof << " ccType=" << ccType << " tokenid=" << revuint256(tokenid).GetHex() << std::endl; + std::cerr << "DecodeTokenOpRet() bad opret format, isEof=" << isEof << " ccType=" << ccType << " tokenid=" << revuint256(tokenid).GetHex() << std::endl; return (uint8_t)0; default: @@ -136,6 +136,9 @@ uint8_t DecodeTokenOpRet(const CScript scriptPubKey, uint8_t &evalCode, uint256 return (uint8_t)0; } } + else { + std::cerr << "DecodeTokenOpRet() empty opret, could not parse" << std::endl; + } return (uint8_t)0; } @@ -247,7 +250,7 @@ bool ValidateTokenOpret(CTransaction tx, int32_t v, uint256 tokenid, std::vector if ((funcid = DecodeTokenOpRet(tx.vout[n - 1].scriptPubKey, evalCode, tokenidOpret, voutPubkeys, vopretExtra)) == 0) { - std::cerr << indentStr << "ValidateTokenOpret() DecodeOpret returned null for n-1=" << n - 1 << " txid=" << tx.GetHash().GetHex() << std::endl; + std::cerr << indentStr << "ValidateTokenOpret() DecodeTokenOpret could not parse opret for txid=" << tx.GetHash().GetHex() << std::endl; return(false); } else if (funcid == 'c') @@ -330,7 +333,7 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c testVout = MakeCC1of2vout(EVAL_TOKENS, tx.vout[v].nValue, voutPubkeys[0], voutPubkeys[1]); if (tx.vout[v].scriptPubKey == testVout.scriptPubKey) { - std::cerr << indentStr << "IsTokensvout() vout is EVAL_TOKENS, returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; + //std::cerr << indentStr << "IsTokensvout() vout is EVAL_TOKENS, returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; return tx.vout[v].nValue; } } @@ -340,7 +343,7 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c CTxOut testVout = MakeCC1vout(EVAL_TOKENS, tx.vout[v].nValue, *it); if (tx.vout[v].scriptPubKey == testVout.scriptPubKey) { - std::cerr << indentStr << "IsTokensvout() vout is EVAL_TOKENS change, returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; + //std::cerr << indentStr << "IsTokensvout() vout is EVAL_TOKENS change, returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; return tx.vout[v].nValue; } } @@ -382,7 +385,7 @@ bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t if (cc_typeId(cond) == CC_Secp256k1) { *(CPubKey*)_.context = buf2pk(cond->publicKey); - std::cerr << "findEval found pubkey=" << HexStr(*(CPubKey*)_.context) << std::endl; + //std::cerr << "findEval found pubkey=" << HexStr(*(CPubKey*)_.context) << std::endl; r = true; } // false for a match, true for continue @@ -483,7 +486,7 @@ int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, C Getscriptaddress(destaddr, vintx.vout[vout].scriptPubKey); if (strcmp(destaddr, coinaddr) != 0 && strcmp(destaddr, cp->unspendableCCaddr) != 0 && strcmp(destaddr, cp->unspendableaddr2) != 0) continue; - fprintf(stderr, "AddTokenCCInputs() check destaddress=%s vout amount=%.8f\n", destaddr, (double)vintx.vout[vout].nValue / COIN); + //fprintf(stderr, "AddTokenCCInputs() check destaddress=%s vout amount=%.8f\n", destaddr, (double)vintx.vout[vout].nValue / COIN); std::vector vinPubkeysEmpty; if ((nValue = IsTokensvout(true, false/*<-- do not check spending outside EVAL_TOKENS for now */, cp, NULL, vopretExtra, vintx, vout, tokenid, vinPubkeysEmpty)) > 0 && myIsutxo_spentinmempool(txid, vout) == 0) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 971ba160d..79473b87a 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -135,7 +135,6 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { privkey = myprivkey; cond = mycond; - } else if ( strcmp(destaddr,unspendable) == 0 ) { diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 7512b54ed..d75580cec 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -23,145 +23,20 @@ class TokenHelper; /* The idea of Heir CC is to allow crypto inheritance. - A special 1of2 CC address is created that is freely spendable by the creator. The heir is only allowed to spend after the specified amount of idle blocks. The idea is that if the address doesnt spend any funds for a year (or whatever amount set), then it is time to allow the heir to spend. The design requires the heir to spend all the funds at once + A special 1of2 CC address is created that is freely spendable by the creator (funds owner). + The owner may add additional funds to this 1of2 address. + The heir is only allowed to spend after "the specified amount of idle blocks" (changed to "the owner inactivityTime"). + The idea is that if the address doesnt spend any funds for a year (or whatever amount set), then it is time to allow the heir to spend. + "The design requires the heir to spend all the funds at once" (this requirement was changed to "after the inactivity time both the heir and owner may freely spend available funds") + After the first heir spending a flag is set that spending is allowed for the heir whether the owner adds more funds or spends them. + This Heir contract supports both coins and tokens. */ // tx validation code -// this is for indentation of debug log messages (in recursive calls): -//extern thread_local uint32_t assetValIndentSize; - -// check if vout is cc addr and also check sum(inputs) == sum(outputs) for the passed tx, if requested -int64_t IsHeirvout(bool compareTotals, struct CCcontract_info *cpHeir, Eval* eval, uint256 tokenid, const CTransaction& tx, int32_t v) -{ - //std::string indentStr = std::string().append(assetValIndentSize, '.'); - - //std::cerr << indentStr << "IsHeirvout() entered for txid=" << tx.GetHash().GetHex() << " v=" << v << std::boolalpha << " compareTotals=" << compareTotals << std::endl; - if (tx.vout[v].scriptPubKey.IsPayToCryptoCondition()) - { - //std::cerr << indentStr << "IsHeirvout() IsPayToCryptoCondition=true for txid=" << tx.GetHash().GetHex() << std::endl; - /*if (compareTotals) { // totally there are only 2 levels actually - - // call recursively HeirExactTokenAmounts and compare ccinputs = ccoutputs for this tx: - assetValIndentSize++; - const bool isEqual = HeirExactTokenAmounts(false, cpHeir, eval, tokenid, tx); - assetValIndentSize--; - - if (!isEqual) { // ccInputs != ccOutputs means a problem - //std::cerr << indentStr << "IsHeirvout() warning: detected suspicious tx=" << tx.GetHash().GetHex() << ": cc inputs != cc outputs, checking further if it is the tokenbase tx" << std::endl; - // if ccInputs != ccOutputs and it is not the 'tokenbase' tx means it is possibly fake tx (dimxy): - if (tokenid != zeroid && tokenid != tx.GetHash()) { - std::cerr << indentStr << "IsHeirvout() warning: detected bad tx=" << tx.GetHash().GetHex() << ": cc inputs != cc outputs and not the 'tokenbase' tx, skipping this tx" << std::endl; - return 0; - } - } - }*/ - - // TODO: add some validation here - - // lets check asset opreturn for this heir or assets tx (dimxy): - /* - int64_t dummyPrice; std::vector dummyOrigpubkey; - - const bool valOpret = ValidateAssetOpret(tx, v, tokenid, dummyPrice, dummyOrigpubkey); - //std::cerr << indentStr << "IsHeirvout() ValidateAssetOpret returned=" << std::boolalpha << valOpret << " for txid=" << tx.GetHash().GetHex() << std::endl; - if (valOpret) { - std::cerr << indentStr << "IsHeirvout() opret is true, return value=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << std::endl; - return(tx.vout[v].nValue); - }*/ - - return(tx.vout[v].nValue); - } - //std::cerr << indentStr << "IsHeirvout() return value=0" << std::endl; - return(0); -} - -// this function validates that tx cc outputs == cc inputs, -// that is there is no fake token supply from normal inputs (except the initial tokenbase tx) -// the cc inputs are allowed only from the Assets or Heir contracts -/*bool HeirExactTokenAmounts(bool compareTotals, struct CCcontract_info *cpHeir, Eval* eval, uint256 tokenid, const CTransaction &tx) -{ - static uint256 zerohash; - CTransaction vinTx; - uint256 hashBlock, activehash; - int64_t inputs = 0, outputs = 0, assetoshis; - - struct CCcontract_info *cpAssets, cAssets; - cpAssets = CCinit(&cAssets, EVAL_ASSETS); // init also tokens CC contract to check its cc addresses too - - std::string indentStr = std::string().append(assetValIndentSize, '.'); - - int32_t numvins = tx.vin.size(); - int32_t numvouts = tx.vout.size(); - for (int32_t i = 0; i < numvins; i++) - { - //std::cerr << indentStr << "HeirExactTokenAmounts() vin i=" << i << " cpHeir->ismyvin()=" << std::boolalpha << (*cpHeir->ismyvin)(tx.vin[i].scriptSig) << " cpAssets->ismyvin()=" << (*cpAssets->ismyvin)(tx.vin[i].scriptSig) << std::endl; - - // checking that vin is either from heir or assets: - if ((*cpHeir->ismyvin)(tx.vin[i].scriptSig) || (*cpAssets->ismyvin)(tx.vin[i].scriptSig)) - { - //std::cerr << indentStr; fprintf(stderr,"vini.%d check mempool\n",i); - if ((eval && !eval->GetTxUnconfirmed(tx.vin[i].prevout.hash, vinTx, hashBlock)) || !myGetTransaction(tx.vin[i].prevout.hash, vinTx, hashBlock)) { - std::cerr << indentStr << "HeirExactTokenAmounts(): can't get vintx transaction txid=" << tx.vin[i].prevout.hash.GetHex() << std::endl; - return (eval) ? eval->Invalid("cant find vinTx") : false; - } - else - { - //std::cerr << indentStr; fprintf(stderr,"vini.%d check hash and vout\n",i); - if (hashBlock == zerohash) { - std::cerr << indentStr << "HeirExactTokenAmounts(): can't get vintx from mempool, txid=" << tx.vin[i].prevout.hash.GetHex() << std::endl; - return (eval) ? eval->Invalid("cant Heir from mempool") : false; - } - - std::string dummyRefcoin; uint256 dummyBindtxid, dummyDeposittxid; CPubKey dummyDestpub; int64_t dummyAmount; - uint256 dummyAssetid2; - std::vector dummyOrigpubkey; - - // Note: if tokenid is zeroid, it may mean we are on the first level and just called from HeirValidate, validating claim 't' tx, - // then let's find the tokenid ourselves: - if (tokenid == zeroid && DecodeAssetOpRet(tx.vout[numvouts - 1].scriptPubKey, tokenid, dummyAssetid2, dummyAmount, dummyOrigpubkey) == 't') { - //std::cerr << indentStr << "HeirExactTokenAmounts() will check if this vinx is the tokenbase tokenid=" << tokenid.GetHex() << std::endl; - } - - // checking that the vout of the vintx (that is, referenced by this vin), in its turn, is fed by either from heir' or assets' cryptocondition address: - //std::cerr << indentStr << "HeirExactTokenAmounts() calling IsHeirvout for vintx i=" << i << " prevout.n=" << tx.vin[i].prevout.n << std::endl; - - assetValIndentSize++; - assetoshis = IsHeirvout(compareTotals, cpHeir, eval, tokenid, vinTx, tx.vin[i].prevout.n); - assetValIndentSize--; - if (assetoshis > 0) - inputs += assetoshis; - } - } - } - for (int32_t i = 0; iInvalid("mismatched inputs != outputs + txfee") : false; - } - else { - //std::cerr << indentStr << "HeirExactTokenAmounts() inputs=" << inputs << " vs outputs=" << outputs << " return true" << std::endl; - return(true); - } -}*/ - - -// claim coins tokens validation runner -// sadly we cannot have yet 'templatized' lambdas, if we could we could capture all these params inside HeirValidation() -template bool RunValidationPlans(uint8_t funcId, struct CCcontract_info* cp, Eval* eval, const CTransaction& tx, uint256 latestTxid, CScript fundingOpretScript, bool isHeirSpendingBegan) +// Plan validation runner, it may be called twice - for coins and tokens +// (sadly we cannot have yet 'templatized' lambdas, if we could we could capture all these params inside HeirValidation()...) +template bool RunValidationPlans(uint8_t funcId, struct CCcontract_info* cp, Eval* eval, const CTransaction& tx, uint256 latestTxid, CScript fundingOpretScript, uint8_t isHeirSpendingBegan) { int32_t numvins = tx.vin.size(); int32_t numvouts = tx.vout.size(); @@ -176,26 +51,20 @@ template bool RunValidationPlans(uint8_t funcId, struct CCcont CCCInputIdentifier ccInputIdentifier(cp); // vin and vout 'validators' - // always check coin inputs: - CMyPubkeyVoutValidator normalInputValidator(cp, fundingOpretScript, true); // check normal input for this opret cause this is first tx - //CMyPubkeyVoutValidator normalInputValidatorLast(cp, latestTxOpRetScript, true); // check normal input for latest opret. TODO: we may also check this opret - - CCC1of2AddressValidator cc1of2ValidatorThis(cp, fundingOpretScript, "checking this tx opreturn:"); // 1of2add validator with pubkeys from this tx opreturn - //CCC1of2AddressValidator cc1of2ValidatorLast(cp, latestTxOpRetScript, "checking last tx opreturn:"); // 1of2add validator with pubkeys from last tx opreturn + // not used, too strict for 2 pubkeys: CMyPubkeyVoutValidator normalInputValidator(cp, fundingOpretScript, true); // check normal input for this opret cause this is first tx + CCC1of2AddressValidator cc1of2ValidatorThis(cp, fundingOpretScript, "checking this tx opreturn:"); // 1of2add validator with pubkeys from this tx opreturn CHeirSpendValidator heirSpendValidator(cp, fundingOpretScript, latestTxid, isHeirSpendingBegan); // check if heir allowed to spend // only for tokens: - CMyPubkeyVoutValidator ownerCCaddrValidator(cp, fundingOpretScript, false); // check if this correct owner's cc user addr corresponding to opret - //CMyPubkeyVoutValidator ownerCCaddrValidatorLast(cp, latestTxOpRetScript, false); // check if this correct owner's cc user addr corresponding to lastest opret - // TODO: we may also check with current opret - COpRetValidator opRetValidator(cp, fundingOpretScript); // compare opRets in this and last tx + CMyPubkeyVoutValidator ownerCCaddrValidator(cp, fundingOpretScript, false); // check if this correct owner's cc user addr corresponding to opret + COpRetValidator opRetValidator(cp, fundingOpretScript); // compare opRets in this and last tx + CNullValidator nullValidator(cp); switch (funcId) { case 'F': // fund tokens // vin validation plan: - // we need cast here this is casted inside - vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &normalInputValidator); // txfee - see AddNormalInput parameter - vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &ownerCCaddrValidator); // check cc owner addr + vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &nullValidator); // txfee vin + vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &ownerCCaddrValidator); // check cc owner addr // vout validation plan: voutPlan.pushValidators(0, &cc1of2ValidatorThis); // check 1of2 addr funding @@ -205,22 +74,20 @@ template bool RunValidationPlans(uint8_t funcId, struct CCcont case 'A': // add tokens // vin validation plan: - // we need cast here this is casted inside - vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &normalInputValidator/*, &normalInputValidatorLast*/); // txfee - see AddNormalInput parameter - vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &ownerCCaddrValidator); // check cc owner addr + vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &nullValidator); // txfee vin + vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &ownerCCaddrValidator); // check cc owner addr - // vout validation plan: + // vout validation plan: voutPlan.pushValidators(0, &cc1of2ValidatorThis); // check 1of2 addr funding - // do not check change at this time - voutPlan.pushValidators(numvouts - 1, &opRetValidator); // opreturn check, NOTE: only for C or A: + // do not check change at this time + voutPlan.pushValidators(numvouts - 1, &opRetValidator); // opreturn check, NOTE: only for C or A: break; case 'C': // vin validation plan: - // we need cast here this is casted inside - vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &normalInputValidator/*&normalInputValidatorLast*/); // txfee - see AddNormalInput parameter - vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &cc1of2ValidatorThis /*, &cc1of2ValidatorLast*/); // cc1of2 funding addr - + vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &nullValidator); // txfee vin + vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &cc1of2ValidatorThis); // cc1of2 funding addr + // vout validation plan: voutPlan.pushValidators(0, &heirSpendValidator); // check if heir is allowed to spend voutPlan.pushValidators(numvouts - 1, &opRetValidator); // opreturn check, NOTE: only for C or A @@ -239,33 +106,34 @@ template bool RunValidationPlans(uint8_t funcId, struct CCcont /** * Tx validation entry function */ -bool HeirValidate(struct CCcontract_info* cp, Eval* eval, const CTransaction& tx, uint32_t nIn) +bool HeirValidate(struct CCcontract_info* cpHeir, Eval* eval, const CTransaction& tx, uint32_t nIn) { int32_t numvins = tx.vin.size(); int32_t numvouts = tx.vout.size(); //int32_t preventCCvins = -1; //int32_t preventCCvouts = -1; + struct CCcontract_info *cpTokens, tokensC; + cpTokens = CCinit(&tokensC, EVAL_TOKENS); + if (numvouts < 1) return eval->Invalid("no vouts"); - if (chainActive.Height() < 741) - return true; + //if (chainActive.Height() < 741) + // return true; uint8_t funcId; - uint256 fundingTxidInOpret = zeroid, latestTxid = zeroid, tokenid = zeroid; + uint256 fundingTxidInOpret = zeroid, latestTxid = zeroid, dummyTokenid, tokenid = zeroid; - //CScript opRetScript = tx.vout[numvouts - 1].scriptPubKey; - CScript fundingTxOpRetScript; - bool isHeirSpendingBegan = false; + uint8_t isHeirSpendingBegan = 0, dummyIsHeirSpendingBegan; int32_t heirType = NOT_HEIR; - funcId = DecodeHeirOpRet(tx.vout[numvouts - 1].scriptPubKey, tokenid, fundingTxidInOpret, true); + funcId = DecodeHeirOpRet(tx.vout[numvouts - 1].scriptPubKey, dummyTokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan, true); if(funcId != 0) heirType = HEIR_COINS; else { - funcId = DecodeHeirOpRet(tx.vout[numvouts - 1].scriptPubKey, tokenid, fundingTxidInOpret, false); + funcId = DecodeHeirOpRet(tx.vout[numvouts - 1].scriptPubKey, tokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan, false); if (funcId != 0) heirType = HEIR_TOKENS; } @@ -278,7 +146,7 @@ bool HeirValidate(struct CCcontract_info* cp, Eval* eval, const CTransaction& tx return eval->Invalid("invalid tx opreturn format: no fundingtxid present"); } if (heirType == HEIR_COINS) - latestTxid = FindLatestFundingTx(fundingTxidInOpret, tokenid, fundingTxOpRetScript, isHeirSpendingBegan); + latestTxid = FindLatestFundingTx(fundingTxidInOpret, dummyTokenid, fundingTxOpRetScript, isHeirSpendingBegan); else latestTxid = FindLatestFundingTx(fundingTxidInOpret, tokenid, fundingTxOpRetScript, isHeirSpendingBegan); @@ -290,11 +158,7 @@ bool HeirValidate(struct CCcontract_info* cp, Eval* eval, const CTransaction& tx fundingTxOpRetScript = tx.vout[numvouts - 1].scriptPubKey; } - // validate prev tx cc inputs = outputs: - /* if (heirType == HEIR_TOKENS && funcId == 't' && !HeirExactTokenAmounts(true, cp, eval, zeroid, tx)) { - std::cerr << "HeirValidate() this tx or some of its vin tx has invalid cc amounts" << std::endl; - return eval->Invalid("this tx or some of its vin tx has invalid cc amounts"); - } */ + std::cerr << "HeirValidate funcid=" << (char)funcId << std::endl; switch (funcId) { case 'F': @@ -315,7 +179,7 @@ bool HeirValidate(struct CCcontract_info* cp, Eval* eval, const CTransaction& tx // vout.2: normal change // vout.n-1: opreturn 't' tokenid 'F' ownerpk heirpk inactivitytime heirname tokenid if (heirType == HEIR_TOKENS) - return RunValidationPlans(funcId, cp, eval, tx, latestTxid, fundingTxOpRetScript, isHeirSpendingBegan); + return RunValidationPlans(funcId, cpTokens, eval, tx, latestTxid, fundingTxOpRetScript, isHeirSpendingBegan); else return eval->Invalid("unexpected HeirValidate for heirfund"); // break; @@ -336,7 +200,7 @@ bool HeirValidate(struct CCcontract_info* cp, Eval* eval, const CTransaction& tx // vout.1: normal change // vout.n-1: opreturn 't' tokenid 'A' ownerpk heirpk inactivitytime fundingtx if (heirType == HEIR_TOKENS) - return RunValidationPlans(funcId, cp, eval, tx, latestTxid, fundingTxOpRetScript, isHeirSpendingBegan); + return RunValidationPlans(funcId, cpTokens, eval, tx, latestTxid, fundingTxOpRetScript, isHeirSpendingBegan); else return eval->Invalid("unexpected HeirValidate for heiradd"); //break; @@ -360,9 +224,9 @@ bool HeirValidate(struct CCcontract_info* cp, Eval* eval, const CTransaction& tx // vout.2: change to normal from txfee input if any // vout.n-1: opreturn 't' tokenid 'C' ownerpk heirpk inactivitytime fundingtx if (heirType == HEIR_TOKENS) - return RunValidationPlans(funcId, cp, eval, tx, latestTxid, fundingTxOpRetScript, isHeirSpendingBegan); + return RunValidationPlans(funcId, cpTokens, eval, tx, latestTxid, fundingTxOpRetScript, isHeirSpendingBegan); else - return RunValidationPlans(funcId, cp, eval, tx, latestTxid, fundingTxOpRetScript, isHeirSpendingBegan); + return RunValidationPlans(funcId, cpHeir, eval, tx, latestTxid, fundingTxOpRetScript, isHeirSpendingBegan); // break; default: @@ -383,13 +247,15 @@ bool HeirValidate(struct CCcontract_info* cp, Eval* eval, const CTransaction& tx */ int64_t IsHeirFundingVout(struct CCcontract_info* cp, const CTransaction& tx, int32_t voutIndex, CPubKey ownerPubkey, CPubKey heirPubkey) { - char destaddr[65], heirContractAddr[65]; + char destaddr[65], heirFundingAddr[65]; - GetCCaddress1of2(cp, heirContractAddr, ownerPubkey, heirPubkey); + GetCCaddress1of2(cp, heirFundingAddr, ownerPubkey, heirPubkey); if (tx.vout[voutIndex].scriptPubKey.IsPayToCryptoCondition() != 0) { // NOTE: dimxy it was unsafe 'Getscriptaddress(destaddr,tx.vout[voutIndex].scriptPubKey) > 0' here: - if (Getscriptaddress(destaddr, tx.vout[voutIndex].scriptPubKey) && strcmp(destaddr, heirContractAddr) == 0) + if (Getscriptaddress(destaddr, tx.vout[voutIndex].scriptPubKey) && strcmp(destaddr, heirFundingAddr) == 0) return (tx.vout[voutIndex].nValue); + else + std::cerr << "IsHeirFundingVout() heirFundingAddr=" << heirFundingAddr << " not equal to destaddr=" << destaddr << std::endl; } return (0); } @@ -437,30 +303,19 @@ CScript EncodeHeirCreateOpRet(uint8_t funcid, CPubKey ownerPubkey, CPubKey heirP { uint8_t evalcode = EVAL_HEIR; - return CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)evalcode << (uint8_t)funcid << ownerPubkey << heirPubkey << inactivityTimeSec << heirName); + return CScript() << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << ownerPubkey << heirPubkey << inactivityTimeSec << heirName); } // makes coin additional tx opret -CScript EncodeHeirOpRet(uint8_t funcid, uint256 fundingtxid) +CScript EncodeHeirOpRet(uint8_t funcid, uint256 fundingtxid, uint8_t isHeirSpendingBegan) { uint8_t evalcode = EVAL_HEIR; fundingtxid = revuint256(fundingtxid); - return CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)evalcode << (uint8_t)funcid << fundingtxid); + return CScript() << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << fundingtxid << isHeirSpendingBegan); } // makes opret for tokens while they are inside Heir contract address space - initial funding -CScript EncodeHeirTokensCreateOpRet(uint8_t funcid, uint256 tokenid, std::vector voutPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string hearName) -{ - uint8_t evalcode = EVAL_TOKENS; - uint8_t ccType = 0; - if (voutPubkeys.size() >= 1 && voutPubkeys.size() <= 2) - ccType = voutPubkeys.size(); - - tokenid = revuint256(tokenid); - return CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)evalcode << (uint8_t)'t' << tokenid << (uint8_t)funcid << ccType; if (ccType >= 1) ss << voutPubkeys[0]; if (ccType == 2) ss << voutPubkeys[1]; ss << ownerPubkey << heirPubkey << inactivityTimeSec << hearName); -} -// makes opret for tokens while they are inside Heir contract address space - additional funding -CScript EncodeHeirTokensOpRet(uint8_t funcid, uint256 tokenid, std::vector voutPubkeys, uint256 fundingtxid) +CScript EncodeHeirTokensCreateOpRet(uint8_t heirFuncId, uint256 tokenid, std::vector voutPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string hearName) { uint8_t evalcode = EVAL_HEIR; uint8_t ccType = 0; @@ -468,16 +323,43 @@ CScript EncodeHeirTokensOpRet(uint8_t funcid, uint256 tokenid, std::vector= 1) ss << voutPubkeys[0]; \ + if (ccType == 2) ss << voutPubkeys[1]; \ + ss << heirFuncId << ownerPubkey << heirPubkey << inactivityTimeSec << hearName); +} +// makes opret for tokens while they are inside Heir contract address space - additional funding +CScript EncodeHeirTokensOpRet(uint8_t heirFuncId, uint256 tokenid, std::vector voutPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) +{ + uint8_t evalcode = EVAL_HEIR; + uint8_t ccType = 0; + if (voutPubkeys.size() >= 1 && voutPubkeys.size() <= 2) + ccType = voutPubkeys.size(); + + tokenid = revuint256(tokenid); // for visualization in debug logs fundingtxid = revuint256(fundingtxid); - return CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)evalcode << (uint8_t)'t' << tokenid << ccType; if (ccType >= 1) ss << voutPubkeys[0]; if (ccType == 2) ss << voutPubkeys[1]; ss << (uint8_t)funcid << fundingtxid); + return CScript() << OP_RETURN << + E_MARSHAL(ss << evalcode << (uint8_t)'t' << tokenid << ccType; \ + if (ccType >= 1) ss << voutPubkeys[0]; \ + if (ccType == 2) ss << voutPubkeys[1]; \ + ss << heirFuncId << fundingtxid << isHeirSpendingBegan); } // helper for decode heir opret payload // NOTE: Heir for coins has the same opret as Heir for tokens -uint8_t _UnmarshalOpret(std::vector vopretExtra, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret) { +uint8_t _UnmarshalOpret(std::vector vopretExtra, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret, uint8_t &isHeirSpendingBegan) { uint8_t heirFuncId = 0; + isHeirSpendingBegan = 0; + + bool result = E_UNMARSHAL(vopretExtra, { ss >> heirFuncId; \ + if( heirFuncId == 'F') { \ + ss >> ownerPubkey; ss >> heirPubkey; ss >> inactivityTime; ss >> heirName; \ + } else { \ + ss >> fundingTxidInOpret >> isHeirSpendingBegan; \ + } \ + }); - bool result = E_UNMARSHAL(vopretExtra, { ss >> heirFuncId; ss >> ownerPubkey; ss >> heirPubkey; ss >> inactivityTime; if (IS_CHARINSTR(heirFuncId, "F")) { ss >> heirName; } if (IS_CHARINSTR(heirFuncId, "AC")) { ss >> fundingTxidInOpret; } }); if (!result /*|| assetFuncId != 't' -- any tx is ok*/) return (uint8_t)0; @@ -486,11 +368,11 @@ uint8_t _UnmarshalOpret(std::vector vopretExtra, CPubKey& ownerPubkey, /** * decode opret vout for Heir contract */ -template uint8_t _DecodeHeirOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret, bool noLogging) +template uint8_t _DecodeHeirOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret, uint8_t &isHeirSpendingBegan, bool noLogging) { - uint8_t evalCodeInOpret = 0; std::vector vopretExtra; + uint8_t evalCodeInOpret = 0; uint256 dummyTokenid; std::vector voutPubkeysDummy; @@ -498,36 +380,50 @@ template uint8_t _DecodeHeirOpRet(CScript scriptPubKey, uint256 & tokenid = zeroid; - // First - decode token opret: - uint8_t funcId = DecodeTokenOpRet(scriptPubKey, evalCodeInOpret, tokenid, voutPubkeysDummy, vopretExtra); + if (typeid(Helper) == typeid(TokenHelper)) { // if caller thinks it is a token - //GetOpReturnData(scriptPubKey, vopret); - - if (funcId != 0 && vopretExtra.size() > 1) { // TODO: add this funcId cond in Assets too - // NOTE: it unmarshals for all F, A and C - uint8_t heirFuncId = _UnmarshalOpret(vopretExtra, ownerPubkey, heirPubkey, inactivityTime, heirName, fundingTxidInOpret); - - /* - std::cerr << "DecodeHeirOpRet() e=" << (int)e - << " funcId=" << (char)funcId - << " ownerPubkey=" << HexStr(ownerPubkey) - << " heirPubkey=" << HexStr(heirPubkey) - << " heirName=" << heirName << " inactivityTime=" << inactivityTime << '\n'; - */ - - //if (e == EVAL_HEIR && IS_CHARINSTR(funcId, "FAC")) - if (evalCodeInOpret == EVAL_HEIR && Helper::isMyFuncId(heirFuncId)) { - tokenid = revuint256(tokenid); - fundingTxidInOpret = revuint256(fundingTxidInOpret); - return heirFuncId; - } - else - { - if(!noLogging) std::cerr << "DecodeHeirOpRet() warning unexpected OP_RETURN eval=" << (int)evalCodeInOpret << " or field type=" << (char)(heirFuncId ? heirFuncId : ' ') << '\n'; + // First - decode token opret: + uint8_t tokenFuncId = DecodeTokenOpRet(scriptPubKey, evalCodeInOpret, tokenid, voutPubkeysDummy, vopretExtra); + if (tokenFuncId == 0) { + if (!noLogging) std::cerr << "DecodeHeirOpRet() warning: not heir token opret, tokenFuncId=" << (int)tokenFuncId << std::endl; + return (uint8_t)0; } } else { - std::cerr << "DecodeHeirOpRet() unmarshal error (vopret.size() == 0)" << '\n'; + std::vector vopret; + + GetOpReturnData(scriptPubKey, vopret); + if (vopret.size() == 0) { + if (!noLogging) std::cerr << "DecodeHeirOpRet() warning: empty opret" << std::endl; + return (uint8_t)0; + } + evalCodeInOpret = vopret.begin()[0]; + vopretExtra = std::vector( vopret.begin()+1, vopret.end() ); // vopretExtra = vopret + 1, get it for futher parsing + } + + if (vopretExtra.size() > 1 && evalCodeInOpret == EVAL_HEIR) { + // NOTE: it unmarshals for all F, A and C + uint8_t heirFuncId = _UnmarshalOpret(vopretExtra, ownerPubkey, heirPubkey, inactivityTime, heirName, fundingTxidInOpret, isHeirSpendingBegan); + + /*std::cerr << "DecodeHeirOpRet()" + << " heirFuncId=" << (char)(heirFuncId ? heirFuncId : ' ') + << " ownerPubkey=" << HexStr(ownerPubkey) + << " heirPubkey=" << HexStr(heirPubkey) + << " heirName=" << heirName << " inactivityTime=" << inactivityTime + << " isHeirSpendingBegan=" << (int)isHeirSpendingBegan << std::endl;*/ + + + //if (e == EVAL_HEIR && IS_CHARINSTR(funcId, "FAC")) + if (Helper::isMyFuncId(heirFuncId)) { + fundingTxidInOpret = revuint256(fundingTxidInOpret); + return heirFuncId; + } + else { + if(!noLogging) std::cerr << "DecodeHeirOpRet() error: unexpected opret, heirFuncId=" << (char)(heirFuncId ? heirFuncId : ' ') << std::endl; + } + } + else { + if (!noLogging) std::cerr << "DecodeHeirOpRet() error: not a heir opret, vopretExtra.size() == 0 or not EVAL_HEIR evalcode=" << (int)evalCodeInOpret << std::endl; } return (uint8_t)0; } @@ -538,20 +434,21 @@ template uint8_t _DecodeHeirOpRet(CScript scriptPubKey, uint256 & template uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging) { uint256 dummytxid; + uint8_t dummyIsHeirSpendingBegan; - return _DecodeHeirOpRet(scriptPubKey, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, dummytxid, noLogging); + return _DecodeHeirOpRet(scriptPubKey, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, dummytxid, dummyIsHeirSpendingBegan, noLogging); } /** * overload for A, C oprets and AddHeirContractInputs */ -template uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256 &tokenid, uint256& fundingtxidInOpret, bool noLogging) +template uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256 &tokenid, uint256& fundingtxidInOpret, uint8_t &isHeirSpendingBegan, bool noLogging) { CPubKey dummyOwnerPubkey, dummyHeirPubkey; int64_t dummyInactivityTime; std::string dummyHeirName; - return _DecodeHeirOpRet(scriptPubKey, tokenid, dummyOwnerPubkey, dummyHeirPubkey, dummyInactivityTime, dummyHeirName, fundingtxidInOpret, noLogging); + return _DecodeHeirOpRet(scriptPubKey, tokenid, dummyOwnerPubkey, dummyHeirPubkey, dummyInactivityTime, dummyHeirName, fundingtxidInOpret, isHeirSpendingBegan, noLogging); } @@ -560,7 +457,7 @@ template uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256 &t * find the latest funding tx: it may be the first F tx or one of A or C tx's * Note: this function is also called from validation code (use non-locking calls) */ -template uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, CScript& fundingOpretScript, bool &isHeirSpendingBegan) +template uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, CScript& fundingOpretScript, uint8_t &isHeirSpendingBegan) { CTransaction fundingtx; uint256 hashBlock; @@ -570,8 +467,8 @@ template uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_ //CCtxidaddr(markeraddr, fundingtxid); //SetCCunspents(unspentOutputs, markeraddr); - isHeirSpendingBegan = false; //init the var - funcId = 0; //init the var + isHeirSpendingBegan = 0; + funcId = 0; // get initial funding tx and set it as initial lasttx: if (myGetTransaction(fundingtxid, fundingtx, hashBlock) && fundingtx.vout.size()) { @@ -580,7 +477,7 @@ template uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_ // set ownerPubkey and heirPubkey: if ((funcId = DecodeHeirOpRet(fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName)) != 0) { // found at least funding tx! - std::cerr << "FindLatestFundingTx() lasttx currently is fundingtx, txid=" << fundingtxid.GetHex() << " opreturn type=" << (char)funcId << '\n'; + //std::cerr << "FindLatestFundingTx() lasttx currently is fundingtx, txid=" << fundingtxid.GetHex() << " opreturn type=" << (char)funcId << '\n'; fundingOpretScript = fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey; } else { std::cerr << "FindLatestFundingTx() could not decode opreturn for fundingtxid=" << fundingtxid.GetHex() << '\n'; @@ -616,37 +513,33 @@ template uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_ //NOTE: maybe called from validation code: if (myGetTransaction(txid, regtx, hash)) { - std::cerr << "FindLatestFundingTx() found tx for txid=" << txid.GetHex() << " blockHeight=" << blockHeight << " maxBlockHeight=" << maxBlockHeight << '\n'; + //std::cerr << "FindLatestFundingTx() found tx for txid=" << txid.GetHex() << " blockHeight=" << blockHeight << " maxBlockHeight=" << maxBlockHeight << '\n'; - { // debug code: + /*{ // debug code: uint256 debAssetid; - uint8_t debfuncid = DecodeHeirOpRet(regtx.vout[regtx.vout.size() - 1].scriptPubKey, debAssetid, fundingTxidInOpret, true); - std::cerr << "FindLatestFundingTx() regtx.vout.size()=" << regtx.vout.size() << " funcId=" << (char)(debfuncid ? debfuncid : ' ') << " tokenid=" << debAssetid.GetHex() << " fundingtxidInOpret=" << fundingTxidInOpret.GetHex() << std::endl; - } + uint8_t debIsHeirSpendingBegan; + uint8_t debfuncid = DecodeHeirOpRet(regtx.vout[regtx.vout.size() - 1].scriptPubKey, debAssetid, fundingTxidInOpret, debIsHeirSpendingBegan, true); + + std::cerr << "FindLatestFundingTx() regtx.vout.size()=" << regtx.vout.size() << " funcId=" << (char)(debfuncid ? debfuncid : ' ') + << " tokenid=" << debAssetid.GetHex() << " fundingtxidInOpret=" << fundingTxidInOpret.GetHex() << " debIsHeirSpendingBegan=" << (int)debIsHeirSpendingBegan << std::endl; + }*/ uint256 dummyTokenid; // not to contaminate the tokenid from the params! uint8_t tmpFuncId; + uint8_t tmpIsHeirSpendingBegan; if (regtx.vout.size() > 0 && - (tmpFuncId = DecodeHeirOpRet(regtx.vout[regtx.vout.size() - 1].scriptPubKey, dummyTokenid, fundingTxidInOpret, true)) != 0 && + (tmpFuncId = DecodeHeirOpRet(regtx.vout[regtx.vout.size() - 1].scriptPubKey, dummyTokenid, fundingTxidInOpret, tmpIsHeirSpendingBegan, true)) != 0 && fundingtxid == fundingTxidInOpret) { - // check if heir has begun spending: - if (Helper::isSpendingTx(tmpFuncId)) { // if 'C' or 't' opret - const CScript heirScriptPubkey = CScript() << ParseHex(HexStr(heirPubkey)) << OP_CHECKSIG; - - for (int32_t v = 0; v < regtx.vout.size() - 1; v++) { // do not check opret vout - if (heirScriptPubkey == regtx.vout[v].scriptPubKey) - isHeirSpendingBegan = true; - } - } - if (blockHeight > maxBlockHeight) { maxBlockHeight = blockHeight; latesttxid = txid; - ///// fundingOpretScript = regtx.vout[regtx.vout.size() - 1].scriptPubKey; funcId = tmpFuncId; - std::cerr << "FindLatestFundingTx() txid=" << latesttxid.GetHex() << " at blockHeight=" << maxBlockHeight << " opreturn type=" << (char)(funcId ? funcId : ' ') << " set as current lasttxid" << '\n'; + isHeirSpendingBegan = tmpIsHeirSpendingBegan; + + //std::cerr << "FindLatestFundingTx() txid=" << latesttxid.GetHex() << " at blockHeight=" << maxBlockHeight + // << " opreturn type=" << (char)(funcId ? funcId : ' ') << " isHeirSpendingBegan=" << (int)isHeirSpendingBegan << " - set as current lasttxid" << '\n'; } } } @@ -656,7 +549,7 @@ template uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_ } // overload for validation code -template uint256 FindLatestFundingTx(uint256 fundingtxid, uint256 &tokenid, CScript& opRetScript, bool &isHeirSpendingBegan) +template uint256 FindLatestFundingTx(uint256 fundingtxid, uint256 &tokenid, CScript& opRetScript, uint8_t &isHeirSpendingBegan) { uint8_t funcId; CPubKey ownerPubkey; @@ -668,81 +561,19 @@ template uint256 FindLatestFundingTx(uint256 fundingtxid, uint256 } // overload for transaction creation code -template uint256 FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool &isHeirSpendingBegan) +template uint256 FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint8_t &isHeirSpendingBegan) { CScript opRetScript; return _FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, opRetScript, isHeirSpendingBegan); } -// add owner input in tokens -/*int64_t AddHeirTokenInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 refassetid, int64_t total, int32_t maxinputs) -{ - char coinaddr[64], destaddr[64]; int64_t threshold, nValue, price, totalinputs = 0; uint256 tokenid, txid, hashBlock; std::vector origpubkey; std::vector vopret; CTransaction vintx; int32_t j, vout, n = 0; uint8_t evalcode, funcid; - std::vector > unspentOutputs; - GetCCaddress(cp, coinaddr, pk); - SetCCunspents(unspentOutputs, coinaddr); - threshold = total / (maxinputs + 1); - - //fprintf(stderr,"AddHeirTokenInputs() check cc addr=%s for token inputs\n",coinaddr); - for (std::vector >::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; - for (j = 0; jsecond=" << it->second.satoshis << std::endl; - - if (strcmp(destaddr, coinaddr) != 0 && strcmp(destaddr, cp->unspendableCCaddr) != 0 && strcmp(destaddr, cp->unspendableaddr2) != 0) - continue; - GetOpReturnData(vintx.vout[vintx.vout.size() - 1].scriptPubKey, vopret); - - // NOTE: special opret decode: - // we should not check for E_UNMARSHAL return code because it returns false if not EOF, - // but we have our remainder after tokenid! - bool isEof = false; - bool unmarshalResult = E_UNMARSHAL(vopret, ss >> evalcode; ss >> funcid; ss >> tokenid; isEof=ss.eof()); - if (unmarshalResult || !isEof) - { - tokenid = revuint256(tokenid); // usually DecodeOpretXXX() funcs do this - - //std::cerr << "AddHeirTokenInputs() vout=" << vout << " evalcode=" << (int)evalcode << " cp->evalcode=" << (int)cp->evalcode << " funcid=" << (char)funcid << " check for refassetid=" << refassetid.GetHex() << " vs tokenid in opret=" << tokenid.GetHex() << " coins=" << (double)vintx.vout[vout].nValue / COIN << std::endl; - if (tokenid == refassetid && - IS_CHARINSTR(funcid, "tGB") && - (nValue = vintx.vout[vout].nValue) > 0 && myIsutxo_spentinmempool(txid, vout) == 0) - { - std::cerr << "AddHeirTokenInputs() total=" << total << " maxinputs=" << maxinputs << " uxto value=" << it->second.satoshis << std::endl; - if (total != 0 && maxinputs != 0) - mtx.vin.push_back(CTxIn(txid, vout, CScript())); - //nValue = it->second.satoshis; - totalinputs += nValue; - n++; - if ((total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs)) - break; - } - } - } - } - return(totalinputs); -}*/ - // add inputs of 1 of 2 cc address template int64_t Add1of2AddressInputs(struct CCcontract_info* cp, uint256 fundingtxid, CMutableTransaction& mtx, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t total, int32_t maxinputs) { // TODO: add threshold check int64_t nValue, voutValue, totalinputs = 0; - CTransaction vintx; + CTransaction heirtx; int32_t n = 0; std::vector> unspentOutputs; @@ -753,7 +584,7 @@ template int64_t Add1of2AddressInputs(struct CCcontract_info* cp, // char markeraddr[64]; // CCtxidaddr(markeraddr, fundingtxid); // SetCCunspents(unspentOutputs, markeraddr); - //std::cerr << "Add1of2AddressInputs() using 1of2addr=" << coinaddr << " unspentOutputs.size()=" << unspentOutputs.size() << '\n'; + // std::cerr << "Add1of2AddressInputs() using 1of2addr=" << coinaddr << " unspentOutputs.size()=" << unspentOutputs.size() << std::endl; for (std::vector>::const_iterator it = unspentOutputs.begin(); it != unspentOutputs.end(); it++) { uint256 txid = it->first.txhash; @@ -761,21 +592,20 @@ template int64_t Add1of2AddressInputs(struct CCcontract_info* cp, int32_t voutIndex = (int32_t)it->first.index; // no need to prevent dup // dimxy: maybe it is good to put tx's in cache? - if (GetTransaction(txid, vintx, hashBlock, false) != 0) { + if (GetTransaction(txid, heirtx, hashBlock, false) != 0) { uint256 tokenid; uint256 fundingTxidInOpret; - - uint8_t funcId = DecodeHeirOpRet(vintx.vout[vintx.vout.size() - 1].scriptPubKey, tokenid, fundingTxidInOpret, true); - // note: it returns in in satoshis too... - if ((txid == fundingtxid || fundingTxidInOpret == fundingtxid) && // we're spending only tx's in this funding plan - funcId != 0 && + uint8_t dummyIsHeirSpendingBegan; + + uint8_t funcId = DecodeHeirOpRet(heirtx.vout[heirtx.vout.size() - 1].scriptPubKey, tokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan, true); + if ((txid == fundingtxid || fundingTxidInOpret == fundingtxid) && + funcId != 0 && Helper::isMyFuncId(funcId) && - // deep validation for tokens: - (typeid(Helper) == typeid(TokenHelper) && IsHeirvout(true, cp, nullptr, tokenid, vintx, voutIndex) > 0) && - (voutValue = IsHeirFundingVout(cp, vintx, voutIndex, ownerPubkey, heirPubkey)) > 0 && + // (typeid(Helper) == typeid(TokenHelper) && IsHeirvout(true, cp, nullptr, tokenid, vintx, voutIndex) > 0) && // deep validation for tokens - not used anymore + (voutValue = IsHeirFundingVout(cp, heirtx, voutIndex, ownerPubkey, heirPubkey)) > 0 && !myIsutxo_spentinmempool(txid, voutIndex)) { - std::cerr << "Add1of2AddressInputs() voutValue=" << voutValue << " satoshis=" << it->second.satoshis << '\n'; + //std::cerr << "Add1of2AddressInputs() voutValue=" << voutValue << " satoshis=" << it->second.satoshis << '\n'; if (total != 0 && maxinputs != 0) mtx.vin.push_back(CTxIn(txid, voutIndex, CScript())); nValue = it->second.satoshis; @@ -812,8 +642,9 @@ template int64_t LifetimeHeirContractFunds(struct CCcontract_info uint256 tokenid; uint256 fundingTxidInOpret; const int32_t ivout = 0; + uint8_t dummyIsHeirSpendingBegan; - funcId = DecodeHeirOpRet(tx.vout[tx.vout.size() - 1].scriptPubKey, tokenid, fundingTxidInOpret, true); + funcId = DecodeHeirOpRet(tx.vout[tx.vout.size() - 1].scriptPubKey, tokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan, true); //std::cerr << "LifetimeHeirContractFunds() found tx=" << txid.GetHex() << " vout[0].nValue=" << subtx.vout[ccVoutIdx].nValue << " opreturn=" << (char)funcId << '\n'; @@ -821,7 +652,7 @@ template int64_t LifetimeHeirContractFunds(struct CCcontract_info /* && !myIsutxo_spentinmempool(txid, ccVoutIdx) */) // include also tx in mempool { total += it->second; // dont do this: tx.vout[ivout].nValue; // in vin[0] always is the pay to 1of2 addr (funding or change) - std::cerr << "LifetimeHeirContractFunds() added tx=" << txid.GetHex() << " it->second=" << it->second << " vout[0].nValue=" << tx.vout[ivout].nValue << " opreturn=" << (char)funcId << '\n'; + //std::cerr << "LifetimeHeirContractFunds() added tx=" << txid.GetHex() << " it->second=" << it->second << " vout[0].nValue=" << tx.vout[ivout].nValue << " opreturn=" << (char)funcId << '\n'; } } } @@ -920,9 +751,10 @@ template UniValue HeirAdd(uint256 fundingtxid, uint64_t txfee, in uint256 lasttxid, tokenid; std::string heirName; uint8_t funcId; - bool isHeirSpendingBegan = false; + uint8_t isHeirSpendingBegan = 0; cp = CCinit(&C, Helper::getMyEval()); + if (txfee == 0) txfee = 10000; @@ -942,7 +774,6 @@ template UniValue HeirAdd(uint256 fundingtxid, uint64_t txfee, in int64_t inputs, change; - //if (AddNormalinputs(mtx, myPubkey, amount + 1 * txfee, 64) > 0) { // TODO: why 64 max inputs? if ((inputs = Helper::addOwnerInputs(cp, tokenid, mtx, myPubkey, amount, 64)) > 0) { // TODO: why 64 max inputs? // we do not use markers anymore - storing data in opreturn is better @@ -955,7 +786,6 @@ template UniValue HeirAdd(uint256 fundingtxid, uint64_t txfee, in // add cryptocondition to spend this funded amount for either pk mtx.vout.push_back(MakeCC1of2vout(Helper::getMyEval(), amount, ownerPubkey, heirPubkey)); // using always pubkeys from OP_RETURN in order to not mixing them up! - // calc and add change vout: if (inputs > amount) change = (inputs - amount); // -txfee <-- txfee pays user @@ -972,7 +802,7 @@ template UniValue HeirAdd(uint256 fundingtxid, uint64_t txfee, in // add opreturn 'A' and sign tx: // this txfee ignored std::string rawhextx = (FinalizeCCTx(0, cp, mtx, myPubkey, txfee, - Helper::makeAddOpRet(tokenid, voutTokenPubkeys, fundingtxid))); + Helper::makeAddOpRet(tokenid, voutTokenPubkeys, fundingtxid, isHeirSpendingBegan))); result.push_back(Pair("result", "success")); result.push_back(Pair("hextx", rawhextx)); @@ -1025,7 +855,7 @@ template UniValue HeirClaim(uint256 fundingtxid, uint64_t txfee uint256 latesttxid, tokenid; uint8_t funcId; std::string heirName; - bool isHeirSpendingBegan = false; + uint8_t isHeirSpendingBegan = 0; cp = CCinit(&C, Helper::getMyEval()); @@ -1117,7 +947,7 @@ template UniValue HeirClaim(uint256 fundingtxid, uint64_t txfee // add opreturn 'C' and sign tx: // this txfee will be ignored std::string rawhextx = FinalizeCCTx(0, cp, mtx, myPubkey, txfee, - Helper::makeClaimOpRet(tokenid, voutTokenPubkeys, fundingtxid)); + Helper::makeClaimOpRet(tokenid, voutTokenPubkeys, fundingtxid, (myPubkey == heirPubkey) ? 1 : isHeirSpendingBegan)); // forward isHeirSpending to the next latest tx result.push_back(Pair("result", "success")); result.push_back(Pair("hextx", rawhextx)); @@ -1181,9 +1011,11 @@ UniValue HeirInfo(uint256 fundingtxid) if (myGetTransaction(fundingtxid, fundingtx, hashBlock) && fundingtx.vout.size()) { int32_t heirType = NOT_HEIR; - if (DecodeHeirOpRet(fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey, dummyTokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, true) == 'F') + const bool noLogging = true; + + if (DecodeHeirOpRet(fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey, dummyTokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, noLogging) == 'F') heirType = HEIR_COINS; - else if (DecodeHeirOpRet(fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, true) == 'F') + else if (DecodeHeirOpRet(fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, noLogging) == 'F') heirType = HEIR_TOKENS; else { @@ -1199,7 +1031,7 @@ UniValue HeirInfo(uint256 fundingtxid) else cp = CCinit(&C, TokenHelper::getMyEval()); - bool isHeirSpendingBegan = false; + uint8_t isHeirSpendingBegan = 0; if (heirType == HEIR_COINS) latestFundingTxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, isHeirSpendingBegan); @@ -1210,7 +1042,7 @@ UniValue HeirInfo(uint256 fundingtxid) int32_t numblocks; uint64_t durationSec = 0; - std::cerr << "HeirInfo() latesttxid=" << latestFundingTxid.GetHex() << '\n'; + //std::cerr << "HeirInfo() latesttxid=" << latestFundingTxid.GetHex() << '\n'; std::ostringstream stream; std::string msg; @@ -1324,7 +1156,7 @@ template void _HeirList(struct CCcontract_info *cp, UniValue &r GetCCaddress(cp, coinaddr, ccPubKeyEmpty); SetCCunspents(unspentOutputs, cp->normaladdr); - std::cerr << "HeirList() finding heir marker from Heir contract addr=" << cp->normaladdr << " unspentOutputs.size()=" << unspentOutputs.size() << '\n'; + //std::cerr << "HeirList() finding heir marker from Heir contract addr=" << cp->normaladdr << " unspentOutputs.size()=" << unspentOutputs.size() << '\n'; // TODO: move marker to special cc addr to prevent checking all tokens for (std::vector>::const_iterator it = unspentOutputs.begin(); it != unspentOutputs.end(); it++) { @@ -1333,26 +1165,28 @@ template void _HeirList(struct CCcontract_info *cp, UniValue &r uint256 tokenid; int32_t vout = (int32_t)it->first.index; - std::cerr << "HeirList() checking txid=" << txid.GetHex() << " vout=" << vout << '\n'; + //std::cerr << "HeirList() checking txid=" << txid.GetHex() << " vout=" << vout << '\n'; - CTransaction vintx; - if (GetTransaction(txid, vintx, hashBlock, false) != 0 && (vintx.vout.size() - 1) > 0) { + CTransaction inittx; + if (GetTransaction(txid, inittx, hashBlock, false) != 0 && (inittx.vout.size() - 1) > 0) { CPubKey ownerPubkey, heirPubkey; std::string heirName; int64_t inactivityTimeSec; + const bool noLogging = true; - uint8_t funcId = DecodeHeirOpRet(vintx.vout[vintx.vout.size() - 1].scriptPubKey, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName); + uint8_t funcId = DecodeHeirOpRet(inittx.vout[inittx.vout.size() - 1].scriptPubKey, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, noLogging); // note: if it is not Heir token funcId would be equal to 0 if (funcId == 'F') { - result.push_back(Pair("fundingtxid heirName", txid.GetHex() + std::string(" ") + (typeid(Helper) == typeid(TokenHelper) ? std::string("token") : std::string("coin")) + std::string(" ") + heirName)); + //result.push_back(Pair("fundingtxid kind name", txid.GetHex() + std::string(" ") + (typeid(Helper) == typeid(TokenHelper) ? std::string("token") : std::string("coin")) + std::string(" ") + heirName)); + result.push_back( Pair("fundingtxid", txid.GetHex()) ); } else { - fprintf(stderr, "HeirList() couldnt find initial transaction\n"); + std::cerr << "HeirList() this is not the initial F transaction=" << txid.GetHex() << std::endl; } } else { - fprintf(stderr, "HeirList() couldnt load transaction\n"); + std::cerr << "HeirList() could not load transaction=" << txid.GetHex() << std::endl; } } } @@ -1363,10 +1197,10 @@ UniValue HeirList() UniValue result(UniValue::VOBJ); result.push_back(Pair("result", "success")); - struct CCcontract_info *cpHeir, *cpTokens, C; + struct CCcontract_info *cpHeir, *cpTokens, heirC, tokenC; // NOTE we must use a separate 'C' structure for each CCinit! - cpHeir = CCinit(&C, EVAL_HEIR); - cpTokens = CCinit(&C, EVAL_TOKENS); + cpHeir = CCinit(&heirC, EVAL_HEIR); + cpTokens = CCinit(&tokenC, EVAL_TOKENS); _HeirList(cpHeir, result); _HeirList(cpTokens, result); diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index 108562e24..5b5df2110 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -12,21 +12,15 @@ // makes coin initial tx opret CScript EncodeHeirCreateOpRet(uint8_t funcid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName); -// makes coin additional tx opret -CScript EncodeHeirOpRet(uint8_t funcid, uint256 fundingtxid); - +CScript EncodeHeirOpRet(uint8_t funcid, uint256 fundingtxid, uint8_t isHeirSpendingBegan); +// makes token opret CScript EncodeHeirTokensCreateOpRet(uint8_t funcid, uint256 tokenid, std::vector voutPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string hearName); -CScript EncodeHeirTokensOpRet(uint8_t funcid, uint256 tokenid, std::vector voutPubkeys, uint256 fundingtxid); -//CScript EncodeHeirConvertedAssetsOpRet(uint8_t eval, uint8_t funcid, uint256 tokenid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 fundingtxid); +CScript EncodeHeirTokensOpRet(uint8_t funcid, uint256 tokenid, std::vector voutPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan); -template uint256 FindLatestFundingTx(uint256 fundingtxid, uint256 &tokenid, CScript& opRetScript, bool &isHeirSpendingBegan); -template uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256 &tokenid, uint256& fundingtxid, bool noLogging = false); -//template uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging = false); +template uint256 FindLatestFundingTx(uint256 fundingtxid, uint256 &tokenid, CScript& opRetScript, uint8_t &isHeirSpendingBegan); +template uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256 &tokenid, uint256& fundingtxid, uint8_t &isHeirSpendingBegan, bool noLogging = false); template uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging = false); -//int64_t AddHeirTokenInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 reftokenid, int64_t total, int32_t maxinputs); - - // helper class to allow polymorphic behaviour for HeirXXX() functions in case of coins class CoinHelper { public: @@ -40,11 +34,11 @@ public: static CScript makeCreateOpRet(uint256 dummyid, std::vector dummyPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName) { return EncodeHeirCreateOpRet((uint8_t)'F', ownerPubkey, heirPubkey, inactivityTimeSec, heirName); } - static CScript makeAddOpRet(uint256 dummyid, std::vector dummyPubkeys, uint256 fundingtxid) { - return EncodeHeirOpRet((uint8_t)'A', fundingtxid); + static CScript makeAddOpRet(uint256 dummyid, std::vector dummyPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) { + return EncodeHeirOpRet((uint8_t)'A', fundingtxid, isHeirSpendingBegan); } - static CScript makeClaimOpRet(uint256 dummyid, std::vector dummyPubkeys, uint256 fundingtxid) { - return EncodeHeirOpRet((uint8_t)'C', fundingtxid); + static CScript makeClaimOpRet(uint256 dummyid, std::vector dummyPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) { + return EncodeHeirOpRet((uint8_t)'C', fundingtxid, isHeirSpendingBegan); } static bool isSpendingTx(uint8_t funcid) { return (funcid == 'C'); } @@ -69,11 +63,11 @@ public: static CScript makeCreateOpRet(uint256 tokenid, std::vector voutTokenPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName) { return EncodeHeirTokensCreateOpRet((uint8_t)'F', tokenid, voutTokenPubkeys, ownerPubkey, heirPubkey, inactivityTimeSec, heirName); } - static CScript makeAddOpRet(uint256 tokenid, std::vector voutTokenPubkeys, uint256 fundingtxid) { - return EncodeHeirTokensOpRet((uint8_t)'A', tokenid, voutTokenPubkeys, fundingtxid); + static CScript makeAddOpRet(uint256 tokenid, std::vector voutTokenPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) { + return EncodeHeirTokensOpRet((uint8_t)'A', tokenid, voutTokenPubkeys, fundingtxid, isHeirSpendingBegan); } - static CScript makeClaimOpRet(uint256 tokenid, std::vector voutTokenPubkeys, uint256 fundingtxid) { - return EncodeHeirTokensOpRet((uint8_t)'C', tokenid, voutTokenPubkeys, fundingtxid); + static CScript makeClaimOpRet(uint256 tokenid, std::vector voutTokenPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) { + return EncodeHeirTokensOpRet((uint8_t)'C', tokenid, voutTokenPubkeys, fundingtxid, isHeirSpendingBegan); } static bool isSpendingTx(uint8_t funcid) { return (funcid == 'C'); } @@ -86,9 +80,6 @@ public: } }; -//#define OPTIONAL_VOUT 0 // if vout is optional then in a validation plan it will be skipped without error, if all validators return false - - /** * Small framework for vins and vouts validation implementing a variation of 'chain of responsibility' pattern: @@ -104,10 +95,8 @@ public: * * For validating vouts COutputValidator is configured for each vector of validators with the vout index to which these validators are applied * (see constructors of both CInputValidator and COutputValidator) -* -* -* Base class for all validators */ + /** * base class for all validators */ @@ -123,7 +112,6 @@ protected: CCcontract_info * m_cp; }; - /** * Base class for classes which identify vins as normal or cc inputs */ @@ -137,9 +125,6 @@ protected: CCcontract_info * m_cp; }; - - - /** * Encapsulates an array containing rows of validators * Each row is a vector of validators (zero is possible) for validating vins or prev tx's vouts @@ -222,7 +207,7 @@ public: return eval->Invalid("incorrect tx structure: not all required vins are present."); } - std::cerr << "CInputValidationPlan::validate() returns with true" << std::endl; + //std::cerr << "CInputValidationPlan::validate() returns with true" << std::endl; return true; } @@ -246,7 +231,7 @@ private: // get requested row of validators: ValidatorsRow vValidators = m_arrayValidators[ival].second; - std::cerr << "CInputValidationPlan::execValidatorsInRow() calling validators" << " for vin iv=" << iv << " ival=" << ival << std::endl; + //std::cerr << "CInputValidationPlan::execValidatorsInRow() calling validators" << " for vin iv=" << iv << " ival=" << ival << std::endl; for (auto v : vValidators) { bool result; @@ -327,7 +312,7 @@ public: } - std::cerr << "COutputValidationPlan::validate() returns with true" << std::endl; + //std::cerr << "COutputValidationPlan::validate() returns with true" << std::endl; return true; } @@ -351,7 +336,7 @@ private: // get requested row of validators: ValidatorsRow vValidators = m_arrayValidators[ival].second; - std::cerr << "COutputValidationPlan::execRow() calling validators" << " for vout iv=" << iv << " ival=" << ival << std::endl; + //std::cerr << "COutputValidationPlan::execRow() calling validators" << " for vout iv=" << iv << " ival=" << ival << std::endl; for (auto v : vValidators) { @@ -422,7 +407,7 @@ public: GetCCaddress1of2(m_cp, shouldBeAddr, ownerPubkey, heirPubkey); if (vout.scriptPubKey.IsPayToCryptoCondition()) { if (Getscriptaddress(ccAddr, vout.scriptPubKey) && strcmp(shouldBeAddr, ccAddr) == 0) { - std::cerr << "CCC1of2AddressValidator::validateVout() exits with true" << std::endl; + //std::cerr << "CCC1of2AddressValidator::validateVout() exits with true" << std::endl; return true; } else { @@ -476,23 +461,24 @@ public: if (m_checkNormals) { ownerScript = CoinHelper::makeUserVout(vout.nValue, ownerPubkey).scriptPubKey; heirScript = CoinHelper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey; + std::cerr << "CMyPubkeyVoutValidator::validateVout() vout.scriptPubKey=" << vout.scriptPubKey.ToString() << " makeUserVout(coin,owner)=" << CoinHelper::makeUserVout(vout.nValue, ownerPubkey).scriptPubKey.ToString() << " makeUserVout(coin,heir)=" << CoinHelper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey.ToString() << std::endl; } else { ownerScript = Helper::makeUserVout(vout.nValue, ownerPubkey).scriptPubKey; heirScript = Helper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey; + std::cerr << "CMyPubkeyVoutValidator::validateVout() vout.scriptPubKey=" << vout.scriptPubKey.ToString() << " makeUserVout(owner)=" << Helper::makeUserVout(vout.nValue, ownerPubkey).scriptPubKey.ToString() << " makeUserVout(heir)=" << Helper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey.ToString() << std::endl; } - //std::cerr << "CMyPubkeyVoutValidator::validateVout() vout.scriptPubKey=" << vout.scriptPubKey.ToString() << " makeUserVout=" << Helper::makeUserVout(vout.nValue, ownerPubkey).scriptPubKey.ToString() << std::endl; - // recreate scriptPubKey for owner and heir and compare it with that of the vout to check: if (vout.scriptPubKey == ownerScript || vout.scriptPubKey == heirScript) { // this is vout to owner or heir addr: - std::cerr << "CMyPubkeyVoutValidator::validateVout() exits with true" << std::endl; + //std::cerr << "CMyPubkeyVoutValidator::validateVout() exits with true" << std::endl; return true; } std::cerr << "CMyPubkeyVoutValidator::validateVout() exits with false (not the owner's or heir's addresses)" << std::endl; + message = std::string("invalid pubkey"); return false; } virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } @@ -509,7 +495,7 @@ private: template class CHeirSpendValidator : CValidatorBase { public: - CHeirSpendValidator(CCcontract_info* cp, CScript opRetScript, uint256 latesttxid, bool isHeirSpendingBegan) + CHeirSpendValidator(CCcontract_info* cp, CScript opRetScript, uint256 latesttxid, uint8_t isHeirSpendingBegan) : m_fundingOpretScript(opRetScript), m_latesttxid(latesttxid), m_isHeirSpendingBegan(isHeirSpendingBegan), CValidatorBase(cp) {} virtual bool isVinValidator() const { return false; } @@ -547,7 +533,7 @@ public: } } - std::cerr << "CHeirSpendValidator::validateVout() exits with true" << std::endl; + //std::cerr << "CHeirSpendValidator::validateVout() exits with true" << std::endl; // this is not heir: return true; @@ -557,7 +543,7 @@ public: private: CScript m_fundingOpretScript; uint256 m_latesttxid; - bool m_isHeirSpendingBegan; + uint8_t m_isHeirSpendingBegan; }; /** @@ -576,12 +562,13 @@ public: uint8_t funcId, initialFuncId; // do not check heir name uint256 fundingTxidInOpret = zeroid, dummyTxid, tokenid, initialTokenid; + uint8_t dummyIsHeirSpendingBegan; - if ((funcId = DecodeHeirOpRet(vout.scriptPubKey, tokenid, fundingTxidInOpret)) == 0) { + if ((funcId = DecodeHeirOpRet(vout.scriptPubKey, tokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan)) == 0) { message = std::string("invalid opreturn format"); return false; } - if ((initialFuncId = DecodeHeirOpRet(m_fundingOpretScript, initialTokenid, dummyTxid)) == 0) { + if ((initialFuncId = DecodeHeirOpRet(m_fundingOpretScript, initialTokenid, dummyTxid, dummyIsHeirSpendingBegan)) == 0) { message = std::string("invalid initial tx opreturn format"); return false; } @@ -606,6 +593,19 @@ private: CScript m_fundingOpretScript; }; +/** +* empty validator always returns true +*/ +template class CNullValidator : CValidatorBase +{ +public: + CNullValidator(CCcontract_info* cp) + : CValidatorBase(cp) { } + + virtual bool isVinValidator() const { return false; } + virtual bool validateVout(CTxOut vout, std::string& message) const { return true; } + virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } +}; #endif \ No newline at end of file From 8e8d4e0057313fb94ad0ee880faf0e21775a6504 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 9 Jan 2019 17:19:49 +0500 Subject: [PATCH 366/643] improved heir spending var name --- src/cc/heir.cpp | 110 ++++++++++++++++++++++++------------------------ 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index d75580cec..ad71b3b2a 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -36,7 +36,7 @@ class TokenHelper; // Plan validation runner, it may be called twice - for coins and tokens // (sadly we cannot have yet 'templatized' lambdas, if we could we could capture all these params inside HeirValidation()...) -template bool RunValidationPlans(uint8_t funcId, struct CCcontract_info* cp, Eval* eval, const CTransaction& tx, uint256 latestTxid, CScript fundingOpretScript, uint8_t isHeirSpendingBegan) +template bool RunValidationPlans(uint8_t funcId, struct CCcontract_info* cp, Eval* eval, const CTransaction& tx, uint256 latestTxid, CScript fundingOpretScript, uint8_t hasHeirSpendingBegun) { int32_t numvins = tx.vin.size(); int32_t numvouts = tx.vout.size(); @@ -53,7 +53,7 @@ template bool RunValidationPlans(uint8_t funcId, struct CCcont // vin and vout 'validators' // not used, too strict for 2 pubkeys: CMyPubkeyVoutValidator normalInputValidator(cp, fundingOpretScript, true); // check normal input for this opret cause this is first tx CCC1of2AddressValidator cc1of2ValidatorThis(cp, fundingOpretScript, "checking this tx opreturn:"); // 1of2add validator with pubkeys from this tx opreturn - CHeirSpendValidator heirSpendValidator(cp, fundingOpretScript, latestTxid, isHeirSpendingBegan); // check if heir allowed to spend + CHeirSpendValidator heirSpendValidator(cp, fundingOpretScript, latestTxid, hasHeirSpendingBegun); // check if heir allowed to spend // only for tokens: CMyPubkeyVoutValidator ownerCCaddrValidator(cp, fundingOpretScript, false); // check if this correct owner's cc user addr corresponding to opret @@ -126,14 +126,14 @@ bool HeirValidate(struct CCcontract_info* cpHeir, Eval* eval, const CTransaction uint256 fundingTxidInOpret = zeroid, latestTxid = zeroid, dummyTokenid, tokenid = zeroid; CScript fundingTxOpRetScript; - uint8_t isHeirSpendingBegan = 0, dummyIsHeirSpendingBegan; + uint8_t hasHeirSpendingBegun = 0, dummyhasHeirSpendingBegun; int32_t heirType = NOT_HEIR; - funcId = DecodeHeirOpRet(tx.vout[numvouts - 1].scriptPubKey, dummyTokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan, true); + funcId = DecodeHeirOpRet(tx.vout[numvouts - 1].scriptPubKey, dummyTokenid, fundingTxidInOpret, dummyhasHeirSpendingBegun, true); if(funcId != 0) heirType = HEIR_COINS; else { - funcId = DecodeHeirOpRet(tx.vout[numvouts - 1].scriptPubKey, tokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan, false); + funcId = DecodeHeirOpRet(tx.vout[numvouts - 1].scriptPubKey, tokenid, fundingTxidInOpret, dummyhasHeirSpendingBegun, false); if (funcId != 0) heirType = HEIR_TOKENS; } @@ -146,9 +146,9 @@ bool HeirValidate(struct CCcontract_info* cpHeir, Eval* eval, const CTransaction return eval->Invalid("invalid tx opreturn format: no fundingtxid present"); } if (heirType == HEIR_COINS) - latestTxid = FindLatestFundingTx(fundingTxidInOpret, dummyTokenid, fundingTxOpRetScript, isHeirSpendingBegan); + latestTxid = FindLatestFundingTx(fundingTxidInOpret, dummyTokenid, fundingTxOpRetScript, hasHeirSpendingBegun); else - latestTxid = FindLatestFundingTx(fundingTxidInOpret, tokenid, fundingTxOpRetScript, isHeirSpendingBegan); + latestTxid = FindLatestFundingTx(fundingTxidInOpret, tokenid, fundingTxOpRetScript, hasHeirSpendingBegun); if (latestTxid == zeroid) { return eval->Invalid("invalid heir transaction: no funding tx found"); @@ -179,7 +179,7 @@ bool HeirValidate(struct CCcontract_info* cpHeir, Eval* eval, const CTransaction // vout.2: normal change // vout.n-1: opreturn 't' tokenid 'F' ownerpk heirpk inactivitytime heirname tokenid if (heirType == HEIR_TOKENS) - return RunValidationPlans(funcId, cpTokens, eval, tx, latestTxid, fundingTxOpRetScript, isHeirSpendingBegan); + return RunValidationPlans(funcId, cpTokens, eval, tx, latestTxid, fundingTxOpRetScript, hasHeirSpendingBegun); else return eval->Invalid("unexpected HeirValidate for heirfund"); // break; @@ -200,7 +200,7 @@ bool HeirValidate(struct CCcontract_info* cpHeir, Eval* eval, const CTransaction // vout.1: normal change // vout.n-1: opreturn 't' tokenid 'A' ownerpk heirpk inactivitytime fundingtx if (heirType == HEIR_TOKENS) - return RunValidationPlans(funcId, cpTokens, eval, tx, latestTxid, fundingTxOpRetScript, isHeirSpendingBegan); + return RunValidationPlans(funcId, cpTokens, eval, tx, latestTxid, fundingTxOpRetScript, hasHeirSpendingBegun); else return eval->Invalid("unexpected HeirValidate for heiradd"); //break; @@ -224,9 +224,9 @@ bool HeirValidate(struct CCcontract_info* cpHeir, Eval* eval, const CTransaction // vout.2: change to normal from txfee input if any // vout.n-1: opreturn 't' tokenid 'C' ownerpk heirpk inactivitytime fundingtx if (heirType == HEIR_TOKENS) - return RunValidationPlans(funcId, cpTokens, eval, tx, latestTxid, fundingTxOpRetScript, isHeirSpendingBegan); + return RunValidationPlans(funcId, cpTokens, eval, tx, latestTxid, fundingTxOpRetScript, hasHeirSpendingBegun); else - return RunValidationPlans(funcId, cpHeir, eval, tx, latestTxid, fundingTxOpRetScript, isHeirSpendingBegan); + return RunValidationPlans(funcId, cpHeir, eval, tx, latestTxid, fundingTxOpRetScript, hasHeirSpendingBegun); // break; default: @@ -307,12 +307,12 @@ CScript EncodeHeirCreateOpRet(uint8_t funcid, CPubKey ownerPubkey, CPubKey heirP } // makes coin additional tx opret -CScript EncodeHeirOpRet(uint8_t funcid, uint256 fundingtxid, uint8_t isHeirSpendingBegan) +CScript EncodeHeirOpRet(uint8_t funcid, uint256 fundingtxid, uint8_t hasHeirSpendingBegun) { uint8_t evalcode = EVAL_HEIR; fundingtxid = revuint256(fundingtxid); - return CScript() << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << fundingtxid << isHeirSpendingBegan); + return CScript() << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << fundingtxid << hasHeirSpendingBegun); } // makes opret for tokens while they are inside Heir contract address space - initial funding CScript EncodeHeirTokensCreateOpRet(uint8_t heirFuncId, uint256 tokenid, std::vector voutPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string hearName) @@ -330,7 +330,7 @@ CScript EncodeHeirTokensCreateOpRet(uint8_t heirFuncId, uint256 tokenid, std::ve ss << heirFuncId << ownerPubkey << heirPubkey << inactivityTimeSec << hearName); } // makes opret for tokens while they are inside Heir contract address space - additional funding -CScript EncodeHeirTokensOpRet(uint8_t heirFuncId, uint256 tokenid, std::vector voutPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) +CScript EncodeHeirTokensOpRet(uint8_t heirFuncId, uint256 tokenid, std::vector voutPubkeys, uint256 fundingtxid, uint8_t hasHeirSpendingBegun) { uint8_t evalcode = EVAL_HEIR; uint8_t ccType = 0; @@ -343,20 +343,20 @@ CScript EncodeHeirTokensOpRet(uint8_t heirFuncId, uint256 tokenid, std::vector= 1) ss << voutPubkeys[0]; \ if (ccType == 2) ss << voutPubkeys[1]; \ - ss << heirFuncId << fundingtxid << isHeirSpendingBegan); + ss << heirFuncId << fundingtxid << hasHeirSpendingBegun); } // helper for decode heir opret payload // NOTE: Heir for coins has the same opret as Heir for tokens -uint8_t _UnmarshalOpret(std::vector vopretExtra, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret, uint8_t &isHeirSpendingBegan) { +uint8_t _UnmarshalOpret(std::vector vopretExtra, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret, uint8_t &hasHeirSpendingBegun) { uint8_t heirFuncId = 0; - isHeirSpendingBegan = 0; + hasHeirSpendingBegun = 0; bool result = E_UNMARSHAL(vopretExtra, { ss >> heirFuncId; \ if( heirFuncId == 'F') { \ ss >> ownerPubkey; ss >> heirPubkey; ss >> inactivityTime; ss >> heirName; \ } else { \ - ss >> fundingTxidInOpret >> isHeirSpendingBegan; \ + ss >> fundingTxidInOpret >> hasHeirSpendingBegun; \ } \ }); @@ -368,7 +368,7 @@ uint8_t _UnmarshalOpret(std::vector vopretExtra, CPubKey& ownerPubkey, /** * decode opret vout for Heir contract */ -template uint8_t _DecodeHeirOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret, uint8_t &isHeirSpendingBegan, bool noLogging) +template uint8_t _DecodeHeirOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging) { std::vector vopretExtra; @@ -403,14 +403,14 @@ template uint8_t _DecodeHeirOpRet(CScript scriptPubKey, uint256 & if (vopretExtra.size() > 1 && evalCodeInOpret == EVAL_HEIR) { // NOTE: it unmarshals for all F, A and C - uint8_t heirFuncId = _UnmarshalOpret(vopretExtra, ownerPubkey, heirPubkey, inactivityTime, heirName, fundingTxidInOpret, isHeirSpendingBegan); + uint8_t heirFuncId = _UnmarshalOpret(vopretExtra, ownerPubkey, heirPubkey, inactivityTime, heirName, fundingTxidInOpret, hasHeirSpendingBegun); /*std::cerr << "DecodeHeirOpRet()" << " heirFuncId=" << (char)(heirFuncId ? heirFuncId : ' ') << " ownerPubkey=" << HexStr(ownerPubkey) << " heirPubkey=" << HexStr(heirPubkey) << " heirName=" << heirName << " inactivityTime=" << inactivityTime - << " isHeirSpendingBegan=" << (int)isHeirSpendingBegan << std::endl;*/ + << " hasHeirSpendingBegun=" << (int)hasHeirSpendingBegun << std::endl;*/ //if (e == EVAL_HEIR && IS_CHARINSTR(funcId, "FAC")) @@ -434,21 +434,21 @@ template uint8_t _DecodeHeirOpRet(CScript scriptPubKey, uint256 & template uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging) { uint256 dummytxid; - uint8_t dummyIsHeirSpendingBegan; + uint8_t dummyhasHeirSpendingBegun; - return _DecodeHeirOpRet(scriptPubKey, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, dummytxid, dummyIsHeirSpendingBegan, noLogging); + return _DecodeHeirOpRet(scriptPubKey, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, dummytxid, dummyhasHeirSpendingBegun, noLogging); } /** * overload for A, C oprets and AddHeirContractInputs */ -template uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256 &tokenid, uint256& fundingtxidInOpret, uint8_t &isHeirSpendingBegan, bool noLogging) +template uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256 &tokenid, uint256& fundingtxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging) { CPubKey dummyOwnerPubkey, dummyHeirPubkey; int64_t dummyInactivityTime; std::string dummyHeirName; - return _DecodeHeirOpRet(scriptPubKey, tokenid, dummyOwnerPubkey, dummyHeirPubkey, dummyInactivityTime, dummyHeirName, fundingtxidInOpret, isHeirSpendingBegan, noLogging); + return _DecodeHeirOpRet(scriptPubKey, tokenid, dummyOwnerPubkey, dummyHeirPubkey, dummyInactivityTime, dummyHeirName, fundingtxidInOpret, hasHeirSpendingBegun, noLogging); } @@ -457,7 +457,7 @@ template uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256 &t * find the latest funding tx: it may be the first F tx or one of A or C tx's * Note: this function is also called from validation code (use non-locking calls) */ -template uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, CScript& fundingOpretScript, uint8_t &isHeirSpendingBegan) +template uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, CScript& fundingOpretScript, uint8_t &hasHeirSpendingBegun) { CTransaction fundingtx; uint256 hashBlock; @@ -467,7 +467,7 @@ template uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_ //CCtxidaddr(markeraddr, fundingtxid); //SetCCunspents(unspentOutputs, markeraddr); - isHeirSpendingBegan = 0; + hasHeirSpendingBegun = 0; funcId = 0; // get initial funding tx and set it as initial lasttx: @@ -517,29 +517,29 @@ template uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_ /*{ // debug code: uint256 debAssetid; - uint8_t debIsHeirSpendingBegan; - uint8_t debfuncid = DecodeHeirOpRet(regtx.vout[regtx.vout.size() - 1].scriptPubKey, debAssetid, fundingTxidInOpret, debIsHeirSpendingBegan, true); + uint8_t debhasHeirSpendingBegun; + uint8_t debfuncid = DecodeHeirOpRet(regtx.vout[regtx.vout.size() - 1].scriptPubKey, debAssetid, fundingTxidInOpret, debhasHeirSpendingBegun, true); std::cerr << "FindLatestFundingTx() regtx.vout.size()=" << regtx.vout.size() << " funcId=" << (char)(debfuncid ? debfuncid : ' ') - << " tokenid=" << debAssetid.GetHex() << " fundingtxidInOpret=" << fundingTxidInOpret.GetHex() << " debIsHeirSpendingBegan=" << (int)debIsHeirSpendingBegan << std::endl; + << " tokenid=" << debAssetid.GetHex() << " fundingtxidInOpret=" << fundingTxidInOpret.GetHex() << " debhasHeirSpendingBegun=" << (int)debhasHeirSpendingBegun << std::endl; }*/ uint256 dummyTokenid; // not to contaminate the tokenid from the params! uint8_t tmpFuncId; - uint8_t tmpIsHeirSpendingBegan; + uint8_t tmphasHeirSpendingBegun; if (regtx.vout.size() > 0 && - (tmpFuncId = DecodeHeirOpRet(regtx.vout[regtx.vout.size() - 1].scriptPubKey, dummyTokenid, fundingTxidInOpret, tmpIsHeirSpendingBegan, true)) != 0 && + (tmpFuncId = DecodeHeirOpRet(regtx.vout[regtx.vout.size() - 1].scriptPubKey, dummyTokenid, fundingTxidInOpret, tmphasHeirSpendingBegun, true)) != 0 && fundingtxid == fundingTxidInOpret) { if (blockHeight > maxBlockHeight) { maxBlockHeight = blockHeight; latesttxid = txid; funcId = tmpFuncId; - isHeirSpendingBegan = tmpIsHeirSpendingBegan; + hasHeirSpendingBegun = tmphasHeirSpendingBegun; //std::cerr << "FindLatestFundingTx() txid=" << latesttxid.GetHex() << " at blockHeight=" << maxBlockHeight - // << " opreturn type=" << (char)(funcId ? funcId : ' ') << " isHeirSpendingBegan=" << (int)isHeirSpendingBegan << " - set as current lasttxid" << '\n'; + // << " opreturn type=" << (char)(funcId ? funcId : ' ') << " hasHeirSpendingBegun=" << (int)hasHeirSpendingBegun << " - set as current lasttxid" << '\n'; } } } @@ -549,7 +549,7 @@ template uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_ } // overload for validation code -template uint256 FindLatestFundingTx(uint256 fundingtxid, uint256 &tokenid, CScript& opRetScript, uint8_t &isHeirSpendingBegan) +template uint256 FindLatestFundingTx(uint256 fundingtxid, uint256 &tokenid, CScript& opRetScript, uint8_t &hasHeirSpendingBegun) { uint8_t funcId; CPubKey ownerPubkey; @@ -557,15 +557,15 @@ template uint256 FindLatestFundingTx(uint256 fundingtxid, uint256 int64_t inactivityTime; std::string heirName; - return _FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, opRetScript, isHeirSpendingBegan); + return _FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, opRetScript, hasHeirSpendingBegun); } // overload for transaction creation code -template uint256 FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint8_t &isHeirSpendingBegan) +template uint256 FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint8_t &hasHeirSpendingBegun) { CScript opRetScript; - return _FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, opRetScript, isHeirSpendingBegan); + return _FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, opRetScript, hasHeirSpendingBegun); } // add inputs of 1 of 2 cc address @@ -595,9 +595,9 @@ template int64_t Add1of2AddressInputs(struct CCcontract_info* cp, if (GetTransaction(txid, heirtx, hashBlock, false) != 0) { uint256 tokenid; uint256 fundingTxidInOpret; - uint8_t dummyIsHeirSpendingBegan; + uint8_t dummyhasHeirSpendingBegun; - uint8_t funcId = DecodeHeirOpRet(heirtx.vout[heirtx.vout.size() - 1].scriptPubKey, tokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan, true); + uint8_t funcId = DecodeHeirOpRet(heirtx.vout[heirtx.vout.size() - 1].scriptPubKey, tokenid, fundingTxidInOpret, dummyhasHeirSpendingBegun, true); if ((txid == fundingtxid || fundingTxidInOpret == fundingtxid) && funcId != 0 && Helper::isMyFuncId(funcId) && @@ -642,9 +642,9 @@ template int64_t LifetimeHeirContractFunds(struct CCcontract_info uint256 tokenid; uint256 fundingTxidInOpret; const int32_t ivout = 0; - uint8_t dummyIsHeirSpendingBegan; + uint8_t dummyhasHeirSpendingBegun; - funcId = DecodeHeirOpRet(tx.vout[tx.vout.size() - 1].scriptPubKey, tokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan, true); + funcId = DecodeHeirOpRet(tx.vout[tx.vout.size() - 1].scriptPubKey, tokenid, fundingTxidInOpret, dummyhasHeirSpendingBegun, true); //std::cerr << "LifetimeHeirContractFunds() found tx=" << txid.GetHex() << " vout[0].nValue=" << subtx.vout[ccVoutIdx].nValue << " opreturn=" << (char)funcId << '\n'; @@ -751,14 +751,14 @@ template UniValue HeirAdd(uint256 fundingtxid, uint64_t txfee, in uint256 lasttxid, tokenid; std::string heirName; uint8_t funcId; - uint8_t isHeirSpendingBegan = 0; + uint8_t hasHeirSpendingBegun = 0; cp = CCinit(&C, Helper::getMyEval()); if (txfee == 0) txfee = 10000; - if ((lasttxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, isHeirSpendingBegan)) != zeroid) { + if ((lasttxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun)) != zeroid) { int32_t numblocks; CPubKey myPubkey = pubkey2pk(Mypubkey()); @@ -802,7 +802,7 @@ template UniValue HeirAdd(uint256 fundingtxid, uint64_t txfee, in // add opreturn 'A' and sign tx: // this txfee ignored std::string rawhextx = (FinalizeCCTx(0, cp, mtx, myPubkey, txfee, - Helper::makeAddOpRet(tokenid, voutTokenPubkeys, fundingtxid, isHeirSpendingBegan))); + Helper::makeAddOpRet(tokenid, voutTokenPubkeys, fundingtxid, hasHeirSpendingBegun))); result.push_back(Pair("result", "success")); result.push_back(Pair("hextx", rawhextx)); @@ -855,26 +855,26 @@ template UniValue HeirClaim(uint256 fundingtxid, uint64_t txfee uint256 latesttxid, tokenid; uint8_t funcId; std::string heirName; - uint8_t isHeirSpendingBegan = 0; + uint8_t hasHeirSpendingBegun = 0; cp = CCinit(&C, Helper::getMyEval()); if (txfee == 0) txfee = 10000; - if ((latesttxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, isHeirSpendingBegan)) != zeroid) { + if ((latesttxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun)) != zeroid) { int32_t numblocks; uint64_t durationSec = 0; // we do not need to find duration if spending already has begun - if (!isHeirSpendingBegan) { + if (!hasHeirSpendingBegun) { durationSec = CCduration(numblocks, latesttxid); std::cerr << "HeirClaim() duration=" << durationSec << " inactivityTime=" << inactivityTimeSec << " numblocks=" << numblocks << std::endl; } // spending is allowed if there is already spending tx or inactivity time //bool isAllowedToHeir = (funcId == 'C' || durationSec > inactivityTimeSec) ? true : false; - bool isAllowedToHeir = (isHeirSpendingBegan || durationSec > inactivityTimeSec) ? true : false; + bool isAllowedToHeir = (hasHeirSpendingBegun || durationSec > inactivityTimeSec) ? true : false; myPubkey = pubkey2pk(Mypubkey()); // if it is the heir, check if spending not allowed to heir yet @@ -947,7 +947,7 @@ template UniValue HeirClaim(uint256 fundingtxid, uint64_t txfee // add opreturn 'C' and sign tx: // this txfee will be ignored std::string rawhextx = FinalizeCCTx(0, cp, mtx, myPubkey, txfee, - Helper::makeClaimOpRet(tokenid, voutTokenPubkeys, fundingtxid, (myPubkey == heirPubkey) ? 1 : isHeirSpendingBegan)); // forward isHeirSpending to the next latest tx + Helper::makeClaimOpRet(tokenid, voutTokenPubkeys, fundingtxid, (myPubkey == heirPubkey) ? 1 : hasHeirSpendingBegun)); // forward isHeirSpending to the next latest tx result.push_back(Pair("result", "success")); result.push_back(Pair("hextx", rawhextx)); @@ -1031,12 +1031,12 @@ UniValue HeirInfo(uint256 fundingtxid) else cp = CCinit(&C, TokenHelper::getMyEval()); - uint8_t isHeirSpendingBegan = 0; + uint8_t hasHeirSpendingBegun = 0; if (heirType == HEIR_COINS) - latestFundingTxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, isHeirSpendingBegan); + latestFundingTxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); else - latestFundingTxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, isHeirSpendingBegan); + latestFundingTxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); if (latestFundingTxid != zeroid) { int32_t numblocks; @@ -1119,12 +1119,12 @@ UniValue HeirInfo(uint256 fundingtxid) stream.str(""); stream.clear(); - if (!isHeirSpendingBegan) { // we do not need find duration if the spending already has begun + if (!hasHeirSpendingBegun) { // we do not need find duration if the spending already has begun durationSec = CCduration(numblocks, latestFundingTxid); std::cerr << "HeirInfo() duration=" << durationSec << " inactivityTime=" << inactivityTimeSec << " numblocks=" << numblocks << '\n'; } - stream << std::boolalpha << (isHeirSpendingBegan || durationSec > inactivityTimeSec); + stream << std::boolalpha << (hasHeirSpendingBegun || durationSec > inactivityTimeSec); result.push_back(Pair("spending allowed for the heir", stream.str().c_str())); stream.str(""); stream.clear(); From 6e353a59a453b1363e0c2c788718d024dbd1bd13 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 9 Jan 2019 17:28:34 +0500 Subject: [PATCH 367/643] more var name hasheirspendingbegun improved --- src/cc/heir.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index ad71b3b2a..7d5ea7cfe 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -126,14 +126,14 @@ bool HeirValidate(struct CCcontract_info* cpHeir, Eval* eval, const CTransaction uint256 fundingTxidInOpret = zeroid, latestTxid = zeroid, dummyTokenid, tokenid = zeroid; CScript fundingTxOpRetScript; - uint8_t hasHeirSpendingBegun = 0, dummyhasHeirSpendingBegun; + uint8_t hasHeirSpendingBegun = 0, dummyHasHeirSpendingBegun; int32_t heirType = NOT_HEIR; - funcId = DecodeHeirOpRet(tx.vout[numvouts - 1].scriptPubKey, dummyTokenid, fundingTxidInOpret, dummyhasHeirSpendingBegun, true); + funcId = DecodeHeirOpRet(tx.vout[numvouts - 1].scriptPubKey, dummyTokenid, fundingTxidInOpret, dummyHasHeirSpendingBegun, true); if(funcId != 0) heirType = HEIR_COINS; else { - funcId = DecodeHeirOpRet(tx.vout[numvouts - 1].scriptPubKey, tokenid, fundingTxidInOpret, dummyhasHeirSpendingBegun, false); + funcId = DecodeHeirOpRet(tx.vout[numvouts - 1].scriptPubKey, tokenid, fundingTxidInOpret, dummyHasHeirSpendingBegun, false); if (funcId != 0) heirType = HEIR_TOKENS; } @@ -434,9 +434,9 @@ template uint8_t _DecodeHeirOpRet(CScript scriptPubKey, uint256 & template uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging) { uint256 dummytxid; - uint8_t dummyhasHeirSpendingBegun; + uint8_t dummyHasHeirSpendingBegun; - return _DecodeHeirOpRet(scriptPubKey, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, dummytxid, dummyhasHeirSpendingBegun, noLogging); + return _DecodeHeirOpRet(scriptPubKey, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, dummytxid, dummyHasHeirSpendingBegun, noLogging); } /** @@ -517,11 +517,11 @@ template uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_ /*{ // debug code: uint256 debAssetid; - uint8_t debhasHeirSpendingBegun; - uint8_t debfuncid = DecodeHeirOpRet(regtx.vout[regtx.vout.size() - 1].scriptPubKey, debAssetid, fundingTxidInOpret, debhasHeirSpendingBegun, true); + uint8_t debHasHeirSpendingBegun; + uint8_t debfuncid = DecodeHeirOpRet(regtx.vout[regtx.vout.size() - 1].scriptPubKey, debAssetid, fundingTxidInOpret, debHasHeirSpendingBegun, true); std::cerr << "FindLatestFundingTx() regtx.vout.size()=" << regtx.vout.size() << " funcId=" << (char)(debfuncid ? debfuncid : ' ') - << " tokenid=" << debAssetid.GetHex() << " fundingtxidInOpret=" << fundingTxidInOpret.GetHex() << " debhasHeirSpendingBegun=" << (int)debhasHeirSpendingBegun << std::endl; + << " tokenid=" << debAssetid.GetHex() << " fundingtxidInOpret=" << fundingTxidInOpret.GetHex() << " debHasHeirSpendingBegun=" << (int)debHasHeirSpendingBegun << std::endl; }*/ uint256 dummyTokenid; // not to contaminate the tokenid from the params! @@ -595,9 +595,9 @@ template int64_t Add1of2AddressInputs(struct CCcontract_info* cp, if (GetTransaction(txid, heirtx, hashBlock, false) != 0) { uint256 tokenid; uint256 fundingTxidInOpret; - uint8_t dummyhasHeirSpendingBegun; + uint8_t dummyHasHeirSpendingBegun; - uint8_t funcId = DecodeHeirOpRet(heirtx.vout[heirtx.vout.size() - 1].scriptPubKey, tokenid, fundingTxidInOpret, dummyhasHeirSpendingBegun, true); + uint8_t funcId = DecodeHeirOpRet(heirtx.vout[heirtx.vout.size() - 1].scriptPubKey, tokenid, fundingTxidInOpret, dummyHasHeirSpendingBegun, true); if ((txid == fundingtxid || fundingTxidInOpret == fundingtxid) && funcId != 0 && Helper::isMyFuncId(funcId) && @@ -642,9 +642,9 @@ template int64_t LifetimeHeirContractFunds(struct CCcontract_info uint256 tokenid; uint256 fundingTxidInOpret; const int32_t ivout = 0; - uint8_t dummyhasHeirSpendingBegun; + uint8_t dummyHasHeirSpendingBegun; - funcId = DecodeHeirOpRet(tx.vout[tx.vout.size() - 1].scriptPubKey, tokenid, fundingTxidInOpret, dummyhasHeirSpendingBegun, true); + funcId = DecodeHeirOpRet(tx.vout[tx.vout.size() - 1].scriptPubKey, tokenid, fundingTxidInOpret, dummyHasHeirSpendingBegun, true); //std::cerr << "LifetimeHeirContractFunds() found tx=" << txid.GetHex() << " vout[0].nValue=" << subtx.vout[ccVoutIdx].nValue << " opreturn=" << (char)funcId << '\n'; From 884c58e3cf341763d8dbadcc844d75d894c4a72f Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 9 Jan 2019 18:04:15 +0500 Subject: [PATCH 368/643] removed test CCerror code --- src/wallet/rpcwallet.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1320da61c..b39a19668 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6952,20 +6952,12 @@ UniValue tokenlist(const UniValue& params, bool fHelp) UniValue tokeninfo(const UniValue& params, bool fHelp) { -#ifdef TESTMODE - std::cerr << "is CCerror clear? CCerror=" << CCerror << std::endl; -#endif uint256 tokenid; if ( fHelp || params.size() != 1 ) throw runtime_error("tokeninfo tokenid\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); tokenid = Parseuint256((char *)params[0].get_str().c_str()); - -#ifdef TESTMODE - CCerror = "test error"; -#endif - return(AssetInfo(tokenid)); } From 1f6d62e7c84a43cbf58a70e82cb1dcd5ec1f196d Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 10 Jan 2019 13:40:21 +0500 Subject: [PATCH 369/643] MakeTokensCC1of2vout MakeTokensCCcond1of2 test code added gateways partially adapted for tokens --- src/cc/CCinclude.h | 18 ++++-- src/cc/CCtokens.cpp | 10 ++- src/cc/CCtokens.h | 1 - src/cc/CCtx.cpp | 31 +++++---- src/cc/CCutils.cpp | 47 +++++++++++++- src/cc/gateways.cpp | 153 ++++++++++++++++++++++++++++---------------- src/cc/heir.cpp | 2 +- 7 files changed, 182 insertions(+), 80 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 1b6e804fc..3e70ba380 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -91,10 +91,14 @@ struct CCcontract_info char unspendableCCaddr[64], CChexstr[72], normaladdr[64]; uint8_t CCpriv[32]; - // this for 1of2 key spending condition (for this evalcode) + // this for 1of2 keys coins cryptocondition (for this evalcode) // NOTE: only one evalcode is allowed at this time - char unspendable1of2addr[64]; - CPubKey unspendable1of2pk[2]; + char coins1of2addr[64]; + CPubKey coins1of2pk[2]; + + // the same for tokens 1of2 keys cc + char tokens1of2addr[64]; + CPubKey tokens1of2pk[2]; // this is for spending from two additional 'unspendable' CC addresses of other eval codes // (that is, for spending from several cc contract 'unspendable' addresses): @@ -153,15 +157,15 @@ uint256 OraclesBatontxid(uint256 oracletxid,CPubKey pk); int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs); int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 reftokenid, std::vector vinPubkeys); - bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx); CScript EncodeAssetOpRet(uint8_t assetFuncId, uint256 tokenid, uint256 assetid2, int64_t price, std::vector voutPubkeys, std::vector origpubkey); bool DecodeAssetCreateOpRet(const CScript &scriptPubKey, std::vector &origpubkey, std::string &name, std::string &description); uint8_t DecodeAssetOpRet(const CScript &scriptPubKey, uint8_t &evalCodeInOpret, uint256 &tokenid, uint256 &assetid2, int64_t &price, std::vector &origpubkey); + +CScript EncodeTokenOpRet(uint8_t tokenFuncId, uint8_t evalCodeInOpret, uint256 tokenid, std::vector voutPubkeys, CScript payload); uint8_t DecodeTokenCreateOpRet(const CScript &scriptPubKey, std::vector &origpubkey, std::string &name, std::string &description); uint8_t DecodeTokenOpRet(const CScript scriptPubKey, uint8_t &evalCode, uint256 &tokenid, std::vector &voutPubkeys, std::vector &vopretExtra); -//uint8_t DecodeAssetOpRet(const CScript &scriptPubKey, uint8_t &evalCode, uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey); uint8_t DecodeOraclesData(const CScript &scriptPubKey,uint256 &oracletxid,uint256 &batontxid,CPubKey &pk,std::vector &data); int32_t oracle_format(uint256 *hashp,int64_t *valp,char *str,uint8_t fmt,uint8_t *data,int32_t offset,int32_t datalen); @@ -182,6 +186,10 @@ CC* GetCryptoCondition(CScript const& scriptSig); void CCaddr2set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr); void CCaddr3set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr); void CCaddr1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr); + +CTxOut MakeTokensCC1of2vout(uint8_t evalcode, CAmount nValue, CPubKey pk1, CPubKey pk2); +CC *MakeTokensCCcond1of2(uint8_t evalcode, CPubKey pk1, CPubKey pk2); + bool IsCCInput(CScript const& scriptSig); int32_t unstringbits(char *buf,uint64_t bits); uint64_t stringbits(char *str); diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 4a2c6031e..62fb1fa78 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -51,7 +51,7 @@ CScript EncodeTokenCreateOpRet(uint8_t funcid,std::vector origpubkey,st } // this is for other contracts which use tokens and build customized extra payloads to token's opret: -CScript EncodeTokenOpRet(uint8_t tokenFuncId, uint8_t evalCodeInOpret, uint256 tokenid, std::vector voutPubkeys) +CScript EncodeTokenOpRet(uint8_t tokenFuncId, uint8_t evalCodeInOpret, uint256 tokenid, std::vector voutPubkeys, CScript payload) { CScript opret; uint8_t ccType = 0; @@ -63,10 +63,14 @@ CScript EncodeTokenOpRet(uint8_t tokenFuncId, uint8_t evalCodeInOpret, uint256 t //uint8_t tokenFuncId = (isTransferrable) ? (uint8_t)'t' : (uint8_t)'l'; //opret << OP_RETURN << E_MARSHAL(ss << evalCodeInOpret << tokenFuncId << tokenid << payload); - opret << OP_RETURN << E_MARSHAL(ss << evalCodeInOpret << tokenFuncId << tokenid << ccType; if (ccType >= 1) ss << voutPubkeys[0]; if (ccType == 2) ss << voutPubkeys[1];); + opret << OP_RETURN << E_MARSHAL(ss << evalCodeInOpret << tokenFuncId << tokenid << ccType; \ + if(ccType >= 1) ss << voutPubkeys[0]; \ + if(ccType == 2) ss << voutPubkeys[1]; \ + if(payload.size() > 0) ss << payload); return(opret); } + uint8_t DecodeTokenCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description) { std::vector vopret; uint8_t dummyEvalcode, funcid, *script; @@ -578,7 +582,7 @@ std::string TokenTransfer(int64_t txfee, uint256 assetid, std::vector d std::vector voutTokenPubkeys; voutTokenPubkeys.push_back(pubkey2pk(destpubkey)); // dest pubkey for validating vout - return(FinalizeCCTx(mask, cp, mtx, mypk, txfee, EncodeTokenOpRet('t', EVAL_TOKENS, assetid, voutTokenPubkeys))); // By setting EVAL_TOKENS we're getting out from assets validation code + return(FinalizeCCTx(mask, cp, mtx, mypk, txfee, EncodeTokenOpRet('t', EVAL_TOKENS, assetid, voutTokenPubkeys, CScript()))); // By setting EVAL_TOKENS we're getting out from assets validation code } else { fprintf(stderr, "not enough CC token inputs for %.8f\n", (double)total / COIN); diff --git a/src/cc/CCtokens.h b/src/cc/CCtokens.h index f65a56b41..34223bc0b 100644 --- a/src/cc/CCtokens.h +++ b/src/cc/CCtokens.h @@ -31,7 +31,6 @@ bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t //int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 reftokenid, std::vector vinPubkeys); std::string CreateToken(int64_t txfee, int64_t assetsupply, std::string name, std::string description); std::string TokenTransfer(int64_t txfee, uint256 assetid, std::vector destpubkey, int64_t total); -CScript EncodeTokenOpRet(uint8_t tokenFuncId, uint8_t evalCodeInOpret, uint256 tokenid, std::vector voutPubkeys); //this is in CCinclude.h int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 79473b87a..ec0a24b3f 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -45,7 +45,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran int64_t utxovalues[CC_MAXVINS],change,normalinputs=0,totaloutputs=0,normaloutputs=0,totalinputs=0,normalvins=0,ccvins=0; int32_t i,utxovout,n,err = 0; char myaddr[64],destaddr[64],unspendable[64]; uint8_t *privkey,myprivkey[32],unspendablepriv[32],*msg32 = 0; - CC *mycond=0, *othercond=0, *othercond2=0, *othercond3=0, *othercond1of2=NULL, *cond; + CC *mycond=0, *othercond=0, *othercond2=0, *othercond3=0, *othercond1of2=NULL, *othercond1of2tokens = NULL, *cond; CPubKey unspendablepk; n = mtx.vout.size(); @@ -130,7 +130,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran else { Getscriptaddress(destaddr,vintx.vout[utxovout].scriptPubKey); - //fprintf(stderr,"vin.%d is CC %.8f -> (%s)\n",i,(double)utxovalues[i]/COIN,destaddr); + //fprintf(stderr,"FinalizeCCTx() vin.%d is CC %.8f -> (%s)\n",i,(double)utxovalues[i]/COIN,destaddr); if ( strcmp(destaddr,myaddr) == 0 ) { privkey = myprivkey; @@ -140,37 +140,44 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { privkey = unspendablepriv; cond = othercond; - //fprintf(stderr,"unspendable CC addr.(%s)\n",unspendable); + //fprintf(stderr,"FinalizeCCTx() unspendable CC addr.(%s)\n",unspendable); } // check if this is the 2nd additional evalcode + 'unspendable' cc addr: else if ( strcmp(destaddr,cp->unspendableaddr2) == 0) { - //fprintf(stderr,"matched %s unspendable2!\n",cp->unspendableaddr2); + //fprintf(stderr,"FinalizeCCTx() matched %s unspendable2!\n",cp->unspendableaddr2); privkey = cp->unspendablepriv2; - if ( othercond2 == 0 ) //&& cp->evalcode != EVAL_CHANNELS && cp->evalcode != EVAL_HEIR && cp->evalcode != EVAL_ASSETS && cp->evalcode != EVAL_TOKENS) + if ( othercond2 == 0 ) othercond2 = MakeCCcond1(cp->evalcode2, cp->unspendablepk2); - //else if ( othercond2 == 0 && (cp->evalcode == EVAL_CHANNELS || cp->evalcode == EVAL_HEIR || cp->evalcode == EVAL_ASSETS || cp->evalcode == EVAL_TOKENS) ) - // othercond2 = MakeCCcond1of2(cp->evalcode2,cp->unspendablepk2,cp->unspendablepk3); cond = othercond2; } // check if this is 3rd additional evalcode + 'unspendable' cc addr: else if ( strcmp(destaddr,cp->unspendableaddr3) == 0 ) { - //fprintf(stderr,"matched %s unspendable3!\n",cp->unspendableaddr3); + //fprintf(stderr,"FinalizeCCTx() matched %s unspendable3!\n",cp->unspendableaddr3); privkey = cp->unspendablepriv3; if ( othercond3 == 0 ) othercond3 = MakeCCcond1(cp->evalcode3,cp->unspendablepk3); cond = othercond3; } - // check if this is spending from 1of2 cc addr: - else if (strcmp(cp->unspendable1of2addr, destaddr) == 0) + // check if this is spending from 1of2 cc coins addr: + else if (strcmp(cp->coins1of2addr, destaddr) == 0) { - //fprintf(stderr,"matched %s unspendable1of2!\n",cp->unspendable1of2addr); + fprintf(stderr,"FinalizeCCTx() matched %s unspendable1of2!\n",cp->coins1of2addr); privkey = myprivkey; if (othercond1of2 == 0) - othercond1of2 = MakeCCcond1of2(cp->evalcode, cp->unspendable1of2pk[0], cp->unspendable1of2pk[1]); + othercond1of2 = MakeCCcond1of2(cp->evalcode, cp->coins1of2pk[0], cp->coins1of2pk[1]); cond = othercond1of2; } + // check if this is spending from 1of2 cc tokens addr: + else if (strcmp(cp->tokens1of2addr, destaddr) == 0) + { + fprintf(stderr,"FinalizeCCTx() matched %s cp->tokens1of2addr!\n", cp->tokens1of2addr); + privkey = myprivkey; + if (othercond1of2tokens == 0) + othercond1of2tokens = MakeTokensCCcond1of2(cp->evalcode, cp->tokens1of2pk[0], cp->tokens1of2pk[1]); + cond = othercond1of2tokens; + } else { fprintf(stderr,"CC signing error: vini.%d has unknown CC address.(%s)\n",i,destaddr); diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index eef21c72a..c07755c2a 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -76,6 +76,39 @@ CTxOut MakeCC1of2vout(uint8_t evalcode,CAmount nValue,CPubKey pk1,CPubKey pk2) return(vout); } +CC *MakeTokensCCcond1of2(uint8_t evalcode, CPubKey pk1, CPubKey pk2) +{ + // make 1of2 sigs cond + std::vector pks; + pks.push_back(CCNewSecp256k1(pk1)); + pks.push_back(CCNewSecp256k1(pk2)); + CC *condEvalCC = CCNewEval(E_MARSHAL(ss << evalcode)); // this is eval cc + CC *cond1of2Sig = CCNewThreshold(1, pks); // this is 1 of 2 sigs cc + CC *cond1of2Threshold = CCNewThreshold(2, { condEvalCC, cond1of2Sig }); + + // make token cond + struct CCcontract_info *cpTokens, tokensC; + cpTokens = CCinit(&tokensC, EVAL_TOKENS); + CPubKey unspendableTokensPk = GetUnspendable(cpTokens, NULL); + + std::vector pksTokens; + pks.push_back(CCNewSecp256k1(unspendableTokensPk)); + CC *condEvalTokensCC = CCNewEval(E_MARSHAL(ss << (uint8_t)EVAL_TOKENS)); // this is eval cc + CC *condUnspendableSig = CCNewThreshold(1, pksTokens); // this is 1 of 2 sigs cc + CC *condTopThreshold = CCNewThreshold(2, { condEvalTokensCC, condUnspendableSig }); + + return CCNewThreshold(2, { cond1of2Threshold, condTopThreshold }); +} + +CTxOut MakeTokensCC1of2vout(uint8_t evalcode, CAmount nValue, CPubKey pk1, CPubKey pk2) +{ + CTxOut vout; + CC *payoutCond = MakeTokensCCcond1of2(evalcode, pk1, pk2); + vout = CTxOut(nValue, CCPubKey(payoutCond)); + cc_free(payoutCond); + return(vout); +} + CC* GetCryptoCondition(CScript const& scriptSig) { auto pc = scriptSig.begin(); @@ -198,9 +231,17 @@ void CCaddr3set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t * // set pubkeys, myprivkey and 1of2 cc addr for spending from 1of2 cryptocondition vout: void CCaddr1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr) { - cp->unspendable1of2pk[0] = pk1; - cp->unspendable1of2pk[1] = pk2; - strcpy(cp->unspendable1of2addr, coinaddr); + cp->coins1of2pk[0] = pk1; + cp->coins1of2pk[1] = pk2; + strcpy(cp->coins1of2addr, coinaddr); +} + +// set pubkeys, myprivkey and 1of2 cc addr for spending from 1of2 tokens cryptocondition vout: +void CCaddr1of2setTokens(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr) +{ + cp->tokens1of2pk[0] = pk1; + cp->tokens1of2pk[1] = pk2; + strcpy(cp->tokens1of2addr, coinaddr); } bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 2768e9fbd..c64d56b80 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -132,14 +132,18 @@ Implementation Issues: - When thinking about validation, it is clear that we cant use EVAL_ASSETS for the locked coins as there wont be any enforcement of the gateways locking. This means we need a way to transfer assets into gateways outputs and back. It seems a tokenconvert rpc will be needed and hopefully that will be enough to make it all work properly. + -- When thinking about validation, it is clear that we cant use EVAL_ASSETS for the locked coins as there wont be any enforcement of the gateways locking. + -- This means we need a way to transfer assets into gateways outputs and back. It seems a tokenconvert rpc will be needed and hopefully that will be enough to make it all work properly. + ++ The use of tokenconvert has been changed to the use of the new Tokens contract which can enforce other contracts validation by forwarding eval->validate call to GatewaysValidate + ++ So all tokens remain within that Tokens contract eval code. - Care must be taken so that tokens are not lost and can be converted back. - - This changes the usage to require tokenconvert before doing the bind and also tokenconvert before doing a withdraw. EVAL_GATEWAYS has evalcode of 241 - - The gatewaysclaim automatically converts the deposit amount of tokens back to EVAL_ASSETS. + -- Care must be taken so that tokens are not lost and can be converted back. + -- This changes the usage to require tokenconvert before doing the bind and also tokenconvert before doing a withdraw. EVAL_GATEWAYS has evalcode of 241 + ++ tokenconvert now returns 'not implemented', no need to use it at all. + -- The gatewaysclaim automatically converts the deposit amount of tokens back to EVAL_ASSETS. + ++ The gatewaysclaim automatically transfers the deposit amount of tokens to depositor's address (within EVAL_TOKENS). + */ @@ -204,38 +208,42 @@ uint8_t DecodeGatewaysDepositOpRet(const CScript &scriptPubKey,std::string &coin return(0); } -CScript EncodeGatewaysClaimOpRet(uint8_t funcid,uint256 assetid,std::string refcoin,uint256 bindtxid,uint256 deposittxid,CPubKey destpub,int64_t amount) +// encodes payload for the token opret (needs to be added to the tail of it) +CScript EncodeGatewaysClaimOpRet(uint8_t funcid, std::string refcoin, uint256 bindtxid, uint256 deposittxid, CPubKey destpub, int64_t amount) { - CScript opret; uint8_t evalcode = EVAL_ASSETS; - opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << assetid << refcoin << bindtxid << deposittxid << destpub << amount); + CScript opret; + + opret << OP_RETURN << E_MARSHAL(ss << funcid << refcoin << bindtxid << deposittxid << destpub << amount); return(opret); } -uint8_t DecodeGatewaysClaimOpRet(const CScript &scriptPubKey,uint256 &assetid,std::string &refcoin,uint256 &bindtxid,uint256 &deposittxid,CPubKey &destpub,int64_t &amount) +uint8_t DecodeGatewaysClaimOpRet(const CScript &scriptPubKey,uint256 &tokenid,std::string &refcoin,uint256 &bindtxid,uint256 &deposittxid,CPubKey &destpub,int64_t &amount) { std::vector vopret; uint8_t *script,e,f; GetOpReturnData(scriptPubKey, vopret); script = (uint8_t *)vopret.data(); - if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> assetid; ss >> refcoin; ss >> bindtxid; ss >> deposittxid; ss >> destpub; ss >> amount) != 0 ) + if ( vopret.size() > 2 && E_UNMARSHAL(vopret, ss >> e; ss >> f; ss >> tokenid; ss >> refcoin; ss >> bindtxid; ss >> deposittxid; ss >> destpub; ss >> amount) != 0 ) { return(f); } return(0); } -CScript EncodeGatewaysWithdrawOpRet(uint8_t funcid,uint256 assetid, std::string refcoin, CPubKey withdrawpub, int64_t amount) +CScript EncodeGatewaysWithdrawOpRet(uint8_t funcid, std::string refcoin, CPubKey withdrawpub, int64_t amount) { - CScript opret; uint8_t evalcode = EVAL_GATEWAYS; - opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << assetid << refcoin << withdrawpub << amount); + CScript opret; + opret << OP_RETURN << E_MARSHAL(ss << funcid << refcoin << withdrawpub << amount); return(opret); } -uint8_t DecodeGatewaysWithdrawOpRet(const CScript &scriptPubKey, uint256 &assetid, std::string &refcoin, CPubKey &withdrawpub, int64_t &amount) +uint8_t DecodeGatewaysWithdrawOpRet(const CScript &scriptPubKey, uint256 &tokenid, std::string &refcoin, CPubKey &withdrawpub, int64_t &amount) { std::vector vopret; uint8_t *script,e,f; + + GetOpReturnData(scriptPubKey, vopret); script = (uint8_t *)vopret.data(); - if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> assetid; ss >> refcoin; ss >> withdrawpub; ss >> amount) != 0 ) + if ( vopret.size() > 2 && E_UNMARSHAL(vopret, ss >> e; ss >> f; ss >> tokenid; ss >> refcoin; ss >> withdrawpub; ss >> amount) != 0 ) { return(f); } @@ -304,7 +312,7 @@ uint8_t DecodeGatewaysOpRet(const CScript &scriptPubKey) std::vector vopret; uint8_t *script,e,f; GetOpReturnData(scriptPubKey, vopret); script = (uint8_t *)vopret.data(); - if ( vopret.size() > 2 && (script[0] == EVAL_GATEWAYS || script[0] == EVAL_ASSETS) && E_UNMARSHAL(vopret,ss >> e; ss >> f) != 0 ) + if ( vopret.size() > 2 && (script[0] == EVAL_GATEWAYS || script[0] == EVAL_TOKENS) && E_UNMARSHAL(vopret,ss >> e; ss >> f) != 0 ) { if (f == 'B' && f == 'D' && f == 't' && f == 'W' && f == 'P' && f == 'M') return(f); @@ -512,7 +520,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks,height,claimvout; bool retval; uint8_t funcid,hash[32],M,N,taddr,prefix,prefix2; char str[65],destaddr[64],depositaddr[65],validationError[512]; std::vector txids; std::vector pubkeys,publishers,tmppublishers; std::vector proof; int64_t totalsupply,amount,tmpamount; - uint256 hashblock,txid,bindtxid,deposittxid,assetid,oracletxid,tokenid,cointxid,tmptxid,tmpxtxid2,merkleroot,mhash; CTransaction bindtx,deposittx,oracletx; + uint256 hashblock,txid,bindtxid,deposittxid,tokenidClaim,oracletxid,tokenidBind,cointxid,tmptxid,tmpxtxid2,merkleroot,mhash; CTransaction bindtx,deposittx,oracletx; std::string refcoin,tmprefcoin,deposithex; CPubKey destpub,tmpdestpub; fprintf(stderr,"return true without gateways validation\n"); @@ -565,8 +573,8 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & //vin.2: CC input of marker from gatewaysdeposit tx //vout.0: CC vout of total tokens from deposit amount to asset eval code //(vout.1): CC vout if there is change of unused tokens back to owner of tokens (deposit amount less than available tokens) - //vout.n-1: opreturn - 't' assetid zeroid 0 mypubkey (NOTE: opreturn is with asset eval code) - if ((numvouts=tx.vout.size()) > 0 && DecodeGatewaysClaimOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,refcoin,bindtxid,deposittxid,destpub,amount)==0) + //vout.n-1: opreturn - 't' tokenid zeroid 0 mypubkey (NOTE: opreturn is with asset eval code) + if ((numvouts=tx.vout.size()) > 0 && DecodeGatewaysClaimOpRet(tx.vout[numvouts-1].scriptPubKey,tokenidClaim,refcoin,bindtxid,deposittxid,destpub,amount)==0) return eval->Invalid("invalid gatewaysclaim OP_RETURN data!"); else if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) return eval->Invalid("vin.0 is normal for gatewaysClaim!"); @@ -580,12 +588,12 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & return eval->Invalid("vout.1 is CC for gatewaysClaim!"); else if (myGetTransaction(bindtxid,bindtx,hashblock) == 0) return eval->Invalid("invalid gatewaysbind txid!"); - else if ((numvouts=bindtx.vout.size()) > 0 && DecodeGatewaysBindOpRet(depositaddr,bindtx.vout[numvouts-1].scriptPubKey,tmprefcoin,tokenid,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 'B') + else if ((numvouts=bindtx.vout.size()) > 0 && DecodeGatewaysBindOpRet(depositaddr,bindtx.vout[numvouts-1].scriptPubKey,tmprefcoin,tokenidBind,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 'B') return eval->Invalid("invalid gatewaysbind OP_RETURN data!"); else if (tmprefcoin!=refcoin) return eval->Invalid("refcoin different in bind tx"); - else if (tokenid!=assetid) - return eval->Invalid("assetid does not match tokenid from gatewaysbind"); + else if (tokenidClaim!=tokenidBind) + return eval->Invalid("tokenid does not match tokenid from gatewaysbind"); else if (komodo_txnotarizedconfirmed(bindtxid) == false) return eval->Invalid("gatewaysbind tx is not yet confirmed(notarised)!"); else if (myGetTransaction(deposittxid,deposittx,hashblock) == 0) @@ -642,7 +650,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & //vout.1: normal vout txfee marker to withdraw destination pubkey //vout.2: CC vout txfee marker to gateways CC address //vout.n-2: CC vout if there is change of unused tokens back to owner of tokens (withdraw amount less than owner available tokens) - //vout.n-1: opreturn - 'W' assetid refcoin withdrawpub amount + //vout.n-1: opreturn - 'W' tokenid refcoin withdrawpub amount break; case 'P': //vin.0: normal input @@ -675,9 +683,9 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & // helper functions for rpc calls in rpcwallet.cpp -int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 refassetid,int64_t total,int32_t maxinputs) +int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 reftokenid,int64_t total,int32_t maxinputs) { - char coinaddr[64],destaddr[64]; int64_t threshold,nValue,price,totalinputs = 0; uint256 assetid,txid,hashBlock; std::vector origpubkey; std::vector vopret; CTransaction vintx; int32_t j,vout,n = 0; uint8_t evalcode,funcid; + char coinaddr[64],destaddr[64]; int64_t threshold,nValue,price,totalinputs = 0; uint256 tokenid,txid,hashBlock; std::vector origpubkey; std::vector vopret; CTransaction vintx; int32_t j,vout,n = 0; uint8_t evalcode,funcid; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); @@ -701,11 +709,11 @@ int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP if ( strcmp(destaddr,coinaddr) != 0 && strcmp(destaddr,cp->unspendableCCaddr) != 0 && strcmp(destaddr,cp->unspendableaddr2) != 0 ) continue; GetOpReturnData(vintx.vout[vintx.vout.size()-1].scriptPubKey, vopret); - if ( E_UNMARSHAL(vopret,ss >> evalcode; ss >> funcid; ss >> assetid) != 0 ) + if ( E_UNMARSHAL(vopret,ss >> evalcode; ss >> funcid; ss >> tokenid) != 0 ) { - assetid = revuint256(assetid); - char str[65],str2[65]; fprintf(stderr,"vout.%d %d:%d (%c) check for refassetid.%s vs %s %.8f\n",vout,evalcode,cp->evalcode,funcid,uint256_str(str,refassetid),uint256_str(str2,assetid),(double)vintx.vout[vout].nValue/COIN); - if ( assetid == refassetid && funcid == 't' && (nValue= vintx.vout[vout].nValue) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + tokenid = revuint256(tokenid); + char str[65],str2[65]; fprintf(stderr,"vout.%d %d:%d (%c) check for reftokenid.%s vs %s %.8f\n",vout,evalcode,cp->evalcode,funcid,uint256_str(str,reftokenid),uint256_str(str2,tokenid),(double)vintx.vout[vout].nValue/COIN); + if ( tokenid == reftokenid && funcid == 't' && (nValue= vintx.vout[vout].nValue) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { //fprintf(stderr,"total %llu maxinputs.%d %.8f\n",(long long)total,maxinputs,(double)it->second.satoshis/COIN); if ( total != 0 && maxinputs != 0 ) @@ -905,7 +913,7 @@ std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,ui CTransaction tx; CPubKey mypk,gatewayspk,tmpdestpub; struct CCcontract_info *cp,C; uint8_t M,N,taddr,prefix,prefix2; std::string coin, deposithex; std::vector msigpubkeys,publishers; int64_t totalsupply,depositamount,tmpamount,inputs,CCchange=0; int32_t numvouts,claimvout,height; std::vector proof; - uint256 hashBlock,assetid,oracletxid,tmptxid,cointxid; char str[65],depositaddr[64],coinaddr[64],destaddr[64]; std::vector txids; + uint256 hashBlock,tokenid,oracletxid,tmptxid,cointxid; char str[65],depositaddr[64],coinaddr[64],destaddr[64]; std::vector txids; cp = CCinit(&C,EVAL_GATEWAYS); if ( txfee == 0 ) @@ -917,7 +925,7 @@ std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,ui fprintf(stderr,"cant find bindtxid %s\n",uint256_str(str,bindtxid)); return(""); } - if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,coin,assetid,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2) != 'B' || coin != refcoin ) + if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,coin,tokenid,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2) != 'B' || coin != refcoin ) { fprintf(stderr,"invalid coin - bindtxid %s coin.%s\n",uint256_str(str,bindtxid),coin.c_str()); return(""); @@ -945,17 +953,24 @@ std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,ui //fprintf(stderr,"depositaddr.(%s) vs %s\n",depositaddr,cp->unspendableaddr2); if ( AddNormalinputs(mtx,mypk,txfee,3) > 0 ) { - if ( (inputs= AddGatewaysInputs(cp,mtx,gatewayspk,assetid,amount,60)) > 0 ) + ///////// if ( (inputs= AddGatewaysInputs(cp,mtx,gatewayspk,tokenid,amount,60)) > 0 ) + if ((inputs = AddTokenCCInputs(cp, mtx, gatewayspk, tokenid, amount, 60)) > 0) { if ( inputs > amount ) CCchange = (inputs - amount); _GetCCaddress(destaddr,EVAL_GATEWAYS,mypk); //printf("expecting deposittxid/v0 to be to %s\n",destaddr); mtx.vin.push_back(CTxIn(deposittxid,0,CScript())); // triggers EVAL_GATEWAYS validation - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,amount,mypk)); // transfer back to normal token + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS,amount,mypk)); // transfer back to normal token if ( CCchange != 0 ) - mtx.vout.push_back(MakeCC1vout(EVAL_GATEWAYS,CCchange,gatewayspk)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeGatewaysClaimOpRet('t',assetid,refcoin,bindtxid,deposittxid,destpub,amount))); + mtx.vout.push_back(MakeCC1vout(EVAL_GATEWAYS,CCchange,gatewayspk)); + + std::vector voutTokenPubkeys; + voutTokenPubkeys.push_back(mypk); // the pubkey where tokens are going (vout[0]) + + return(FinalizeCCTx(0,cp,mtx,mypk,txfee, + EncodeTokenOpRet('t', EVAL_GATEWAYS, tokenid, voutTokenPubkeys, + EncodeGatewaysClaimOpRet('t', refcoin, bindtxid, deposittxid, destpub, amount)))); // yes, 't' is passed twice } } CCerror = strprintf("cant find enough inputs or mismatched total"); @@ -966,39 +981,67 @@ std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,ui std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin,CPubKey withdrawpub,int64_t amount) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction tx; CPubKey mypk,gatewayspk; struct CCcontract_info *cp,C; - uint256 assetid,hashBlock,oracletxid; int32_t numvouts; int64_t totalsupply,inputs,CCchange=0; uint8_t M,N,taddr,prefix,prefix2; std::string coin; + CTransaction tx; + CPubKey mypk, gatewayspk; + uint256 tokenid,hashBlock,oracletxid; int32_t numvouts; int64_t totalsupply,inputs,CCchange=0; uint8_t M,N,taddr,prefix,prefix2; std::string coin; std::vector msigpubkeys; char depositaddr[64],str[65],coinaddr[64]; - cp = CCinit(&C,EVAL_GATEWAYS); + struct CCcontract_info *cpGateways, gatewaysC; + struct CCcontract_info *cpTokens, tokensC; + + cpGateways = CCinit(&gatewaysC, EVAL_GATEWAYS); + cpTokens = CCinit(&tokensC, EVAL_TOKENS); + if ( txfee == 0 ) txfee = 10000; + mypk = pubkey2pk(Mypubkey()); - gatewayspk = GetUnspendable(cp,0); - if ( GetTransaction(bindtxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 ) + gatewayspk = GetUnspendable(cpGateways, 0); + + if( GetTransaction(bindtxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 ) { fprintf(stderr,"cant find bindtxid %s\n",uint256_str(str,bindtxid)); return(""); } - if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,coin,assetid,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2) != 'B' || coin != refcoin ) + if( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,coin,tokenid,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2) != 'B' || coin != refcoin ) { fprintf(stderr,"invalid bindtxid %s coin.%s\n",uint256_str(str,bindtxid),coin.c_str()); return(""); } - if ( AddNormalinputs(mtx,mypk,3*txfee,4) > 0 ) + if( AddNormalinputs(mtx, mypk, 3*txfee, 4) > 0 ) { - if ( (inputs= AddGatewaysInputs(cp,mtx,mypk,assetid,amount,60)) > 0 ) + /////if ( (inputs= AddGatewaysInputs(cp,mtx,mypk,tokenid,amount,60)) > 0 ) + if ((inputs = AddTokenCCInputs(cpTokens, mtx, mypk, tokenid, amount, 60)) > 0) { if ( inputs > amount ) CCchange = (inputs - amount); - mtx.vout.push_back(MakeCC1vout(EVAL_GATEWAYS,amount,gatewayspk)); + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, amount, gatewayspk)); mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(withdrawpub)) << OP_CHECKSIG)); - mtx.vout.push_back(MakeCC1vout(EVAL_GATEWAYS,txfee,gatewayspk)); + mtx.vout.push_back(MakeCC1vout(EVAL_GATEWAYS, txfee, gatewayspk)); if ( CCchange != 0 ) - mtx.vout.push_back(MakeCC1vout(EVAL_GATEWAYS,CCchange,mypk)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeGatewaysWithdrawOpRet('W',assetid,refcoin,withdrawpub,amount))); + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, CCchange, mypk)); + + char unspendableGatewaysAddr[64]; + GetCCaddress(cpGateways, unspendableGatewaysAddr, gatewayspk); + + uint8_t unspendableGatewaysPrivkey[32]; + GetUnspendable(cpGateways, unspendableGatewaysPrivkey); + + // add additional unspendable addr from Gateways: + CCaddr2set(cpTokens, EVAL_GATEWAYS, gatewayspk, unspendableGatewaysPrivkey, unspendableGatewaysAddr); + + std::vector voutTokenPubkeys; + voutTokenPubkeys.push_back(gatewayspk); // the pubkey where tokens are going vout[0] (and for checking the 'change' the Tokens contract will find pubkeys itself) + + return(FinalizeCCTx(0, cpTokens, mtx, mypk, txfee, + EncodeTokenOpRet('t', EVAL_GATEWAYS, tokenid, voutTokenPubkeys, + EncodeGatewaysWithdrawOpRet('W', refcoin, withdrawpub, amount)))); } + CCerror = strprintf("cant find enough token inputs or mismatched total"); + fprintf(stderr, "%s\n", CCerror.c_str()); + return(""); + } - CCerror = strprintf("cant find enough inputs or mismatched total"); + CCerror = strprintf("cant find enough normal inputs or mismatched total"); fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } @@ -1073,7 +1116,7 @@ std::string GatewaysMarkDone(uint64_t txfee,uint256 completetxid,std::string ref UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) { UniValue result(UniValue::VOBJ),pending(UniValue::VARR); CTransaction tx; std::string tmprefcoin; CPubKey mypk,gatewayspk,withdrawpub; std::vector msigpubkeys; - uint256 hashBlock,assetid,txid,oracletxid; uint8_t M,N,taddr,prefix,prefix2; + uint256 hashBlock,tokenid,txid,oracletxid; uint8_t M,N,taddr,prefix,prefix2; char depositaddr[64],coinaddr[64],destaddr[64],str[65],withaddr[64],numstr[32],txidaddr[64],cctxidaddr[64],signeraddr[64]; int32_t i,n,numvouts,vout,queueflag; int64_t totalsupply,amount,nValue; struct CCcontract_info *cp,C; std::vector > unspentOutputs; @@ -1087,7 +1130,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) fprintf(stderr,"cant find bindtxid %s\n",uint256_str(str,bindtxid)); return(result); } - if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tmprefcoin,assetid,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2) != 'B' || tmprefcoin != refcoin ) + if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tmprefcoin,tokenid,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2) != 'B' || tmprefcoin != refcoin ) { fprintf(stderr,"invalid bindtxid %s coin.%s\n",uint256_str(str,bindtxid),tmprefcoin.c_str()); return(result); @@ -1108,7 +1151,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) nValue = (int64_t)it->second.satoshis; fprintf(stderr,"%s %d %ld\n",txid.ToString().c_str(),vout,(long)nValue); if ( vout == 2 && nValue == 10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size())>0 && - DecodeGatewaysWithdrawOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,tmprefcoin,withdrawpub,amount) == 'W' && myIsutxo_spentinmempool(txid,vout) == 0) + DecodeGatewaysWithdrawOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,withdrawpub,amount) == 'W' && myIsutxo_spentinmempool(txid,vout) == 0) { Getscriptaddress(destaddr,tx.vout[0].scriptPubKey); Getscriptaddress(withaddr,tx.vout[1].scriptPubKey); @@ -1141,7 +1184,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) UniValue GatewaysProcessedWithdraws(uint256 bindtxid,std::string refcoin) { UniValue result(UniValue::VOBJ),processed(UniValue::VARR); CTransaction tx; std::string tmprefcoin,hex; CPubKey mypk,gatewayspk,withdrawpub; std::vector msigpubkeys; - uint256 withdrawtxid,hashBlock,txid,assetid,oracletxid; uint8_t M,N,taddr,prefix,prefix2; + uint256 withdrawtxid,hashBlock,txid,tokenid,oracletxid; uint8_t M,N,taddr,prefix,prefix2; char depositaddr[64],coinaddr[64],str[65],numstr[32],txidaddr[64],cctxidaddr[64],withaddr[64]; int32_t i,n,numvouts,vout,queueflag; int64_t totalsupply,nValue,amount; struct CCcontract_info *cp,C; std::vector > unspentOutputs; @@ -1155,7 +1198,7 @@ UniValue GatewaysProcessedWithdraws(uint256 bindtxid,std::string refcoin) fprintf(stderr,"cant find bindtxid %s\n",uint256_str(str,bindtxid)); return(result); } - if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tmprefcoin,assetid,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2) != 'B' || tmprefcoin != refcoin ) + if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tmprefcoin,tokenid,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2) != 'B' || tmprefcoin != refcoin ) { fprintf(stderr,"invalid bindtxid %s coin.%s\n",uint256_str(str,bindtxid),tmprefcoin.c_str()); return(result); @@ -1178,7 +1221,7 @@ UniValue GatewaysProcessedWithdraws(uint256 bindtxid,std::string refcoin) if ( vout == 0 && nValue == 10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size())>0 && DecodeGatewaysCompleteSigningOpRet(tx.vout[numvouts-1].scriptPubKey,tmprefcoin,withdrawtxid,hex) == 'C' && myIsutxo_spentinmempool(txid,vout) == 0) { - if (GetTransaction(withdrawtxid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size())>0 && DecodeGatewaysWithdrawOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,tmprefcoin,withdrawpub,amount) == 'W') + if (GetTransaction(withdrawtxid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size())>0 && DecodeGatewaysWithdrawOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,withdrawpub,amount) == 'W') { UniValue obj(UniValue::VOBJ); obj.push_back(Pair("txid",uint256_str(str,txid))); diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 7d5ea7cfe..fe93e7a5a 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -690,7 +690,7 @@ template std::string HeirFund(uint64_t txfee, int64_t amount, if ((inputs=Helper::addOwnerInputs(cp, tokenid, mtx, myPubkey, amount, (int32_t)64)) > 0) { // 2 x txfee: 1st for marker vout, 2nd to miners //mtx.vout.push_back(MakeCC1vout(EVAL_HEIR,amount,HeirCCpk)); - mtx.vout.push_back(MakeCC1of2vout(Helper::getMyEval(), amount, myPubkey, heirPubkey)); // add cryptocondition to spend amount for either pk + mtx.vout.push_back(MakeTokensCC1of2vout(/*Helper::getMyEval()*/EVAL_HEIR, amount, myPubkey, heirPubkey)); // add cryptocondition to spend amount for either pk // add a marker for finding all plans in HeirList() CPubKey HeirContractPubKey = GetUnspendable(cp, 0); From 53b30074c22beab4b229884ef558844122ec32ef Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 10 Jan 2019 14:00:29 +0500 Subject: [PATCH 370/643] corrected vpayload serialisation to opret --- src/cc/CCtokens.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 62fb1fa78..8e4dc17ca 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -62,11 +62,14 @@ CScript EncodeTokenOpRet(uint8_t tokenFuncId, uint8_t evalCodeInOpret, uint256 t tokenid = revuint256(tokenid); //uint8_t tokenFuncId = (isTransferrable) ? (uint8_t)'t' : (uint8_t)'l'; + std::vector vpayload; + GetOpReturnData(payload, vpayload); + //opret << OP_RETURN << E_MARSHAL(ss << evalCodeInOpret << tokenFuncId << tokenid << payload); opret << OP_RETURN << E_MARSHAL(ss << evalCodeInOpret << tokenFuncId << tokenid << ccType; \ if(ccType >= 1) ss << voutPubkeys[0]; \ if(ccType == 2) ss << voutPubkeys[1]; \ - if(payload.size() > 0) ss << payload); + if(payload.size() > 0) ss << vpayload); return(opret); } From 00968fd9cbc3353523ed909df5615014bb99760e Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 10 Jan 2019 14:45:39 +0500 Subject: [PATCH 371/643] destaddr logging added --- src/cc/CCtx.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index ec0a24b3f..30c4c1e62 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -131,6 +131,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { Getscriptaddress(destaddr,vintx.vout[utxovout].scriptPubKey); //fprintf(stderr,"FinalizeCCTx() vin.%d is CC %.8f -> (%s)\n",i,(double)utxovalues[i]/COIN,destaddr); + std::cerr << "FinalizeCCtx() destaddr=" << destaddr << " myaddr=" << myaddr << std::endl; if ( strcmp(destaddr,myaddr) == 0 ) { privkey = myprivkey; From c2942d60a487571a6d9c6a1d0a52d72e48fe84b4 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 10 Jan 2019 15:23:07 +0500 Subject: [PATCH 372/643] Tokens CC cond test code added to HeirClaim TokenValidate --- src/cc/CCinclude.h | 2 ++ src/cc/CCtokens.cpp | 2 +- src/cc/CCutils.cpp | 14 +++++++++++++- src/cc/heir.cpp | 6 +++--- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 3e70ba380..2ebba82f7 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -189,6 +189,8 @@ void CCaddr1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *c CTxOut MakeTokensCC1of2vout(uint8_t evalcode, CAmount nValue, CPubKey pk1, CPubKey pk2); CC *MakeTokensCCcond1of2(uint8_t evalcode, CPubKey pk1, CPubKey pk2); +bool GetTokensCCaddress1of2(struct CCcontract_info *cp, char *destaddr, CPubKey pk, CPubKey pk2); +void CCaddrTokens1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr); bool IsCCInput(CScript const& scriptSig); int32_t unstringbits(char *buf,uint64_t bits); diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 8e4dc17ca..362529a53 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -337,7 +337,7 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c if (voutPubkeys.size() == 1) testVout = MakeCC1vout(EVAL_TOKENS, tx.vout[v].nValue, voutPubkeys[0]); else // voutPubkeys.size() == 2 - testVout = MakeCC1of2vout(EVAL_TOKENS, tx.vout[v].nValue, voutPubkeys[0], voutPubkeys[1]); + testVout = MakeTokensCC1of2vout(EVAL_TOKENS, tx.vout[v].nValue, voutPubkeys[0], voutPubkeys[1]); if (tx.vout[v].scriptPubKey == testVout.scriptPubKey) { //std::cerr << indentStr << "IsTokensvout() vout is EVAL_TOKENS, returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index c07755c2a..f677127a6 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -237,7 +237,7 @@ void CCaddr1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *c } // set pubkeys, myprivkey and 1of2 cc addr for spending from 1of2 tokens cryptocondition vout: -void CCaddr1of2setTokens(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr) +void CCaddrTokens1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr) { cp->tokens1of2pk[0] = pk1; cp->tokens1of2pk[1] = pk2; @@ -348,6 +348,18 @@ bool GetCCaddress1of2(struct CCcontract_info *cp,char *destaddr,CPubKey pk,CPubK return(destaddr[0] != 0); } +bool GetTokensCCaddress1of2(struct CCcontract_info *cp, char *destaddr, CPubKey pk, CPubKey pk2) +{ + CC *payoutCond; + destaddr[0] = 0; + if ((payoutCond = MakeTokensCCcond1of2(cp->evalcode, pk, pk2)) != 0) + { + Getscriptaddress(destaddr, CCPubKey(payoutCond)); + cc_free(payoutCond); + } + return(destaddr[0] != 0); +} + bool ConstrainVout(CTxOut vout, int32_t CCflag, char *cmpaddr, int64_t nValue) { char destaddr[64]; diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index fe93e7a5a..1d776a865 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -578,7 +578,7 @@ template int64_t Add1of2AddressInputs(struct CCcontract_info* cp, std::vector> unspentOutputs; char coinaddr[64]; - GetCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); // get address of cryptocondition '1 pubkey of 2 pubkeys' + GetTokensCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); // get address of cryptocondition '1 pubkey of 2 pubkeys' SetCCunspents(unspentOutputs, coinaddr); // char markeraddr[64]; @@ -930,7 +930,7 @@ template UniValue HeirClaim(uint256 fundingtxid, uint64_t txfee uint8_t myprivkey[32]; char coinaddr[64]; // set priv key addresses in CC structure: - GetCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); + GetTokensCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); Myprivkey(myprivkey); ////fprintf(stderr,"HeirClaim() before setting unspendable CC addr2= (%s) addr3= (%s)\n", cp->unspendableaddr2, cp->unspendableaddr3); @@ -938,7 +938,7 @@ template UniValue HeirClaim(uint256 fundingtxid, uint64_t txfee //CCaddr3set(cp, Helper::getMyEval(), heirPubkey, myprivkey, coinaddr); ////fprintf(stderr, "HeirClaim() after setting unspendable CC addr2=(%s) addr3=(%s)\n", cp->unspendableaddr2, cp->unspendableaddr3); - CCaddr1of2set(cp, ownerPubkey, heirPubkey, coinaddr); + CCaddrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); // add 1of2 vout validation pubkeys: std::vector voutTokenPubkeys; From aa7c48f529c5154fbc6ecaba1cda140fb100e005 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 10 Jan 2019 15:35:09 +0500 Subject: [PATCH 373/643] corrected EVAL_HEIR (test) in IsTokenVout --- src/cc/CCtokens.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 362529a53..644e9d414 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -337,7 +337,7 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c if (voutPubkeys.size() == 1) testVout = MakeCC1vout(EVAL_TOKENS, tx.vout[v].nValue, voutPubkeys[0]); else // voutPubkeys.size() == 2 - testVout = MakeTokensCC1of2vout(EVAL_TOKENS, tx.vout[v].nValue, voutPubkeys[0], voutPubkeys[1]); + testVout = MakeTokensCC1of2vout(EVAL_HEIR, tx.vout[v].nValue, voutPubkeys[0], voutPubkeys[1]); if (tx.vout[v].scriptPubKey == testVout.scriptPubKey) { //std::cerr << indentStr << "IsTokensvout() vout is EVAL_TOKENS, returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; From 732144ebb8078179fc8888d21591dfe63ab8729c Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 10 Jan 2019 15:50:55 +0500 Subject: [PATCH 374/643] turn off HeirValidate temp --- src/cc/heir.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 1d776a865..fcea30f58 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -160,6 +160,9 @@ bool HeirValidate(struct CCcontract_info* cpHeir, Eval* eval, const CTransaction std::cerr << "HeirValidate funcid=" << (char)funcId << std::endl; + //////////////// temp //////////////////////// + return true; + switch (funcId) { case 'F': // fund coins: From 37105d851ab083ab430674e16db64f0f8220c616 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 10 Jan 2019 16:06:00 +0500 Subject: [PATCH 375/643] added logging in Add1of2addrinputs in heir --- src/cc/heir.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index fcea30f58..30143a2cf 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -587,7 +587,7 @@ template int64_t Add1of2AddressInputs(struct CCcontract_info* cp, // char markeraddr[64]; // CCtxidaddr(markeraddr, fundingtxid); // SetCCunspents(unspentOutputs, markeraddr); - // std::cerr << "Add1of2AddressInputs() using 1of2addr=" << coinaddr << " unspentOutputs.size()=" << unspentOutputs.size() << std::endl; + std::cerr << "Add1of2AddressInputs() using 1of2addr=" << coinaddr << " unspentOutputs.size()=" << unspentOutputs.size() << std::endl; for (std::vector>::const_iterator it = unspentOutputs.begin(); it != unspentOutputs.end(); it++) { uint256 txid = it->first.txhash; @@ -595,6 +595,9 @@ template int64_t Add1of2AddressInputs(struct CCcontract_info* cp, int32_t voutIndex = (int32_t)it->first.index; // no need to prevent dup // dimxy: maybe it is good to put tx's in cache? + + std::cerr << "Add1of2AddressInputs() txid=" << txid.GetHex() << std::endl; + if (GetTransaction(txid, heirtx, hashBlock, false) != 0) { uint256 tokenid; uint256 fundingTxidInOpret; @@ -608,7 +611,7 @@ template int64_t Add1of2AddressInputs(struct CCcontract_info* cp, (voutValue = IsHeirFundingVout(cp, heirtx, voutIndex, ownerPubkey, heirPubkey)) > 0 && !myIsutxo_spentinmempool(txid, voutIndex)) { - //std::cerr << "Add1of2AddressInputs() voutValue=" << voutValue << " satoshis=" << it->second.satoshis << '\n'; + std::cerr << "Add1of2AddressInputs() voutValue=" << voutValue << " satoshis=" << it->second.satoshis << '\n'; if (total != 0 && maxinputs != 0) mtx.vin.push_back(CTxIn(txid, voutIndex, CScript())); nValue = it->second.satoshis; From 092b4c987ab6c8deebd5a6af41ad2d001a777d66 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 10 Jan 2019 16:12:09 +0500 Subject: [PATCH 376/643] eval_heir corrected temp in HeirClaim --- src/cc/heir.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 30143a2cf..22268279b 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -864,7 +864,8 @@ template UniValue HeirClaim(uint256 fundingtxid, uint64_t txfee uint8_t hasHeirSpendingBegun = 0; - cp = CCinit(&C, Helper::getMyEval()); + //cp = CCinit(&C, Helper::getMyEval()); + cp = CCinit(&C, EVAL_HEIR); if (txfee == 0) txfee = 10000; From 0177628e7dca790f24da6f3692e067dd96a62d5b Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 10 Jan 2019 16:19:48 +0500 Subject: [PATCH 377/643] GetTokensCCaddress1of2 call corrected (test) in IsHeirFundingVout --- src/cc/heir.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 22268279b..57d7c6a79 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -252,7 +252,7 @@ int64_t IsHeirFundingVout(struct CCcontract_info* cp, const CTransaction& tx, in { char destaddr[65], heirFundingAddr[65]; - GetCCaddress1of2(cp, heirFundingAddr, ownerPubkey, heirPubkey); + GetTokensCCaddress1of2(cp, heirFundingAddr, ownerPubkey, heirPubkey); if (tx.vout[voutIndex].scriptPubKey.IsPayToCryptoCondition() != 0) { // NOTE: dimxy it was unsafe 'Getscriptaddress(destaddr,tx.vout[voutIndex].scriptPubKey) > 0' here: if (Getscriptaddress(destaddr, tx.vout[voutIndex].scriptPubKey) && strcmp(destaddr, heirFundingAddr) == 0) From d67ca1779af0e5446cab6ca978d126b4f793e1c5 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 10 Jan 2019 21:28:13 +0500 Subject: [PATCH 378/643] MakeTokensCCcond1of2 corrrected and simplified --- src/cc/CCtokens.cpp | 2 +- src/cc/CCutils.cpp | 16 +++------------- src/cc/heir.cpp | 2 +- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 644e9d414..0829623e6 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -173,7 +173,7 @@ bool TokensValidate(struct CCcontract_info *cp, Eval* eval, const CTransaction & if ((funcid = DecodeTokenOpRet(tx.vout[numvouts - 1].scriptPubKey, evalCodeInOpret, tokenid, voutTokenPubkeys, vopretExtra)) == 0) return eval->Invalid("TokenValidate: invalid opreturn payload"); - fprintf(stderr, "TokensValidate (%c)\n", funcid); + fprintf(stderr, "TokensValidate (%c) evalcode=0x%0x\n", funcid, cp->evalcode); if (eval->GetTxUnconfirmed(tokenid, createTx, hashBlock) == 0) return eval->Invalid("cant find token create txid"); diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index f677127a6..93c82945e 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -83,21 +83,11 @@ CC *MakeTokensCCcond1of2(uint8_t evalcode, CPubKey pk1, CPubKey pk2) pks.push_back(CCNewSecp256k1(pk1)); pks.push_back(CCNewSecp256k1(pk2)); CC *condEvalCC = CCNewEval(E_MARSHAL(ss << evalcode)); // this is eval cc + CC *condEvalTokensCC = CCNewEval(E_MARSHAL(ss << (uint8_t)EVAL_TOKENS)); // this is eval token cc CC *cond1of2Sig = CCNewThreshold(1, pks); // this is 1 of 2 sigs cc - CC *cond1of2Threshold = CCNewThreshold(2, { condEvalCC, cond1of2Sig }); + CC *cond1of2Threshold = CCNewThreshold(3, { condEvalCC, condEvalTokensCC, cond1of2Sig }); - // make token cond - struct CCcontract_info *cpTokens, tokensC; - cpTokens = CCinit(&tokensC, EVAL_TOKENS); - CPubKey unspendableTokensPk = GetUnspendable(cpTokens, NULL); - - std::vector pksTokens; - pks.push_back(CCNewSecp256k1(unspendableTokensPk)); - CC *condEvalTokensCC = CCNewEval(E_MARSHAL(ss << (uint8_t)EVAL_TOKENS)); // this is eval cc - CC *condUnspendableSig = CCNewThreshold(1, pksTokens); // this is 1 of 2 sigs cc - CC *condTopThreshold = CCNewThreshold(2, { condEvalTokensCC, condUnspendableSig }); - - return CCNewThreshold(2, { cond1of2Threshold, condTopThreshold }); + return cond1of2Threshold; } CTxOut MakeTokensCC1of2vout(uint8_t evalcode, CAmount nValue, CPubKey pk1, CPubKey pk2) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 57d7c6a79..9bb3f7f93 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -158,7 +158,7 @@ bool HeirValidate(struct CCcontract_info* cpHeir, Eval* eval, const CTransaction fundingTxOpRetScript = tx.vout[numvouts - 1].scriptPubKey; } - std::cerr << "HeirValidate funcid=" << (char)funcId << std::endl; + std::cerr << "HeirValidate funcid=" << (char)funcId << " evalcode=" << cpHeir->evalcode << std::endl; //////////////// temp //////////////////////// return true; From 805b3da0501341585d06c83fc94d1011023462fe Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 10 Jan 2019 21:42:10 +0500 Subject: [PATCH 379/643] heir evalcode logging added --- src/cc/heir.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 9bb3f7f93..73d8b49aa 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -158,7 +158,7 @@ bool HeirValidate(struct CCcontract_info* cpHeir, Eval* eval, const CTransaction fundingTxOpRetScript = tx.vout[numvouts - 1].scriptPubKey; } - std::cerr << "HeirValidate funcid=" << (char)funcId << " evalcode=" << cpHeir->evalcode << std::endl; + std::cerr << "HeirValidate funcid=" << (char)funcId << " evalcode=" << (int)cpHeir->evalcode << std::endl; //////////////// temp //////////////////////// return true; From 6d509d52931a155992c06711ac93f25350314a4a Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 11 Jan 2019 14:34:56 +0500 Subject: [PATCH 380/643] added MakeTokensCCcond1 and MakeTokensCCvout1 --- src/cc/CCinclude.h | 2 + src/cc/CCtokens.cpp | 102 +++++++++++++++++++++++++------------------- src/cc/CCutils.cpp | 19 +++++++++ src/cc/heir.cpp | 2 +- 4 files changed, 81 insertions(+), 44 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 2ebba82f7..0dc7f446d 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -188,7 +188,9 @@ void CCaddr3set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t * void CCaddr1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr); CTxOut MakeTokensCC1of2vout(uint8_t evalcode, CAmount nValue, CPubKey pk1, CPubKey pk2); +CTxOut MakeTokensCC1vout(uint8_t evalcode, CAmount nValue, CPubKey pk); CC *MakeTokensCCcond1of2(uint8_t evalcode, CPubKey pk1, CPubKey pk2); +CC *MakeTokensCCcond1(uint8_t evalcode, CPubKey pk); bool GetTokensCCaddress1of2(struct CCcontract_info *cp, char *destaddr, CPubKey pk, CPubKey pk2); void CCaddrTokens1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr); diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 0829623e6..2f9a50a93 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -239,23 +239,63 @@ bool TokensValidate(struct CCcontract_info *cp, Eval* eval, const CTransaction & // return(PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts)); } +// helper funcs: +// extract my vins pubkeys: +bool ExtractVinPubkeys(struct CCcontract_info *cp, CTransaction tx, std::vector &vinPubkeys) { + + bool found = false; + CPubKey pubkey; + + for (int32_t i = 0; i < tx.vin.size(); i++) + { // check for additional contracts which may send tokens to the Tokens contract + if( (*cp->ismyvin)(tx.vin[i].scriptSig) ) + { + + auto findEval = [](CC *cond, struct CCVisitor _) { + bool r = false; //cc_typeId(cond) == CC_Eval && cond->codeLength == 1 && cond->code[0] == EVAL_TOKENS; + + if (cc_typeId(cond) == CC_Secp256k1) { + *(CPubKey*)_.context = buf2pk(cond->publicKey); + //std::cerr << "findEval found pubkey=" << HexStr(*(CPubKey*)_.context) << std::endl; + r = true; + } + // false for a match, true for continue + return r ? 0 : 1; + }; + + CC *cond = GetCryptoCondition(tx.vin[i].scriptSig); + + if (cond) { + CCVisitor visitor = { findEval, (uint8_t*)"", 0, &pubkey }; + bool out = !cc_visit(cond, visitor); + cc_free(cond); + + if (pubkey.IsValid()) { + vinPubkeys.push_back(pubkey); + found = true; + } + } + } + } + return found; +} // this is just for log messages indentation fur debugging recursive calls: thread_local uint32_t tokenValIndentSize = 0; // validates opret for token tx: -bool ValidateTokenOpret(CTransaction tx, int32_t v, uint256 tokenid, std::vector &voutPubkeys, std::vector &vopretExtra) { +bool ValidateTokenOpret(CTransaction tx, int32_t v, uint256 tokenid, uint8_t &evalCodeInOpret, std::vector &voutPubkeys, std::vector &vopretExtra) { uint256 tokenidOpret, tokenidOpret2; - uint8_t funcid, evalCode; + uint8_t funcid; // this is just for log messages indentation fur debugging recursive calls: std::string indentStr = std::string().append(tokenValIndentSize, '.'); int32_t n = tx.vout.size(); - if ((funcid = DecodeTokenOpRet(tx.vout[n - 1].scriptPubKey, evalCode, tokenidOpret, voutPubkeys, vopretExtra)) == 0) + if ((funcid = DecodeTokenOpRet(tx.vout[n - 1].scriptPubKey, evalCodeInOpret, tokenidOpret, voutPubkeys, vopretExtra)) == 0) { std::cerr << indentStr << "ValidateTokenOpret() DecodeTokenOpret could not parse opret for txid=" << tx.GetHash().GetHex() << std::endl; return(false); @@ -324,20 +364,20 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c // moved opret checking to this new reusable func (dimxy): std::vector voutPubkeys; - const bool valOpret = ValidateTokenOpret(tx, v, reftokenid, voutPubkeys, vopretExtra); + uint8_t evalCodeInOpret = 0; + const bool valOpret = ValidateTokenOpret(tx, v, reftokenid, evalCodeInOpret, voutPubkeys, vopretExtra); //std::cerr << indentStr << "IsTokensvout() ValidateTokenOpret returned=" << std::boolalpha << valOpret << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; if (valOpret) { //std::cerr << indentStr << "IsTokensvout() ValidateTokenOpret returned true" << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; - if (checkPubkeys) { - // verify that the vout is within EVAL_TOKENS: + if (checkPubkeys) { // verify that the vout is within EVAL_TOKENS: if (voutPubkeys.size() >= 1 && voutPubkeys.size() <= 2) { CTxOut testVout; if (voutPubkeys.size() == 1) - testVout = MakeCC1vout(EVAL_TOKENS, tx.vout[v].nValue, voutPubkeys[0]); + testVout = MakeTokensCC1vout(evalCodeInOpret, tx.vout[v].nValue, voutPubkeys[0]); else // voutPubkeys.size() == 2 - testVout = MakeTokensCC1of2vout(EVAL_HEIR, tx.vout[v].nValue, voutPubkeys[0], voutPubkeys[1]); + testVout = MakeTokensCC1of2vout(evalCodeInOpret, tx.vout[v].nValue, voutPubkeys[0], voutPubkeys[1]); if (tx.vout[v].scriptPubKey == testVout.scriptPubKey) { //std::cerr << indentStr << "IsTokensvout() vout is EVAL_TOKENS, returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; @@ -345,9 +385,9 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c } } - // maybe it is change? + // maybe it is token change? for(std::vector::iterator it = vinPubkeys.begin(); it != vinPubkeys.end(); it++) { - CTxOut testVout = MakeCC1vout(EVAL_TOKENS, tx.vout[v].nValue, *it); + CTxOut testVout = MakeTokensCC1vout(evalCodeInOpret, tx.vout[v].nValue, *it); if (tx.vout[v].scriptPubKey == testVout.scriptPubKey) { //std::cerr << indentStr << "IsTokensvout() vout is EVAL_TOKENS change, returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; @@ -371,7 +411,6 @@ bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t { CTransaction vinTx; uint256 hashBlock, id, id2; int32_t flag; int64_t tokenoshis; std::vector tmporigpubkey; int64_t tmpprice; std::vector vinPubkeys, vinPubkeysEmpty; - CPubKey pubkey; int32_t numvins = tx.vin.size(); int32_t numvouts = tx.vout.size(); @@ -380,37 +419,12 @@ bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t // this is just for log messages indentation for debugging recursive calls: std::string indentStr = std::string().append(tokenValIndentSize, '.'); + ExtractVinPubkeys(cpTokens, tx, vinPubkeys); + for (int32_t i = 0; iismyvin)(tx.vin[i].scriptSig) /*|| IsVinAllowed(tx.vin[i].scriptSig) != 0*/) { - - // extract my vins pubkeys: - - auto findEval = [](CC *cond, struct CCVisitor _) { - bool r = false; //cc_typeId(cond) == CC_Eval && cond->codeLength == 1 && cond->code[0] == EVAL_TOKENS; - - if (cc_typeId(cond) == CC_Secp256k1) { - *(CPubKey*)_.context = buf2pk(cond->publicKey); - //std::cerr << "findEval found pubkey=" << HexStr(*(CPubKey*)_.context) << std::endl; - r = true; - } - // false for a match, true for continue - return r ? 0 : 1; - }; - - CC *cond = GetCryptoCondition(tx.vin[i].scriptSig); - - if (cond) { - CCVisitor visitor = { findEval, (uint8_t*)"", 0, &pubkey }; - bool out = !cc_visit(cond, visitor); - cc_free(cond); - - if (pubkey.IsValid()) - vinPubkeys.push_back(pubkey); - } - - //std::cerr << indentStr << "TokensExactAmounts() eval is true=" << (eval != NULL) << " ismyvin=ok for_i=" << i << std::endl; // we are not inside the validation code -- dimxy if ((eval && eval->GetTxUnconfirmed(tx.vin[i].prevout.hash, vinTx, hashBlock) == 0) || (!eval && !myGetTransaction(tx.vin[i].prevout.hash, vinTx, hashBlock))) @@ -423,7 +437,7 @@ bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t tokenValIndentSize++; // validate vouts of vintx //std::cerr << indentStr << "TokenExactAmounts() check vin i=" << i << " nValue=" << vinTx.vout[tx.vin[i].prevout.n].nValue << std::endl; - tokenoshis = IsTokensvout(goDeeper, false/*<--do not have pubkeys for now*/, cpTokens, eval, tmporigpubkey, vinTx, tx.vin[i].prevout.n, tokenid, vinPubkeysEmpty); + tokenoshis = IsTokensvout(goDeeper, true, cpTokens, eval, tmporigpubkey, vinTx, tx.vin[i].prevout.n, tokenid, vinPubkeys); tokenValIndentSize--; if (tokenoshis != 0) { @@ -488,21 +502,23 @@ int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, C break; if (j != mtx.vin.size()) continue; + if (GetTransaction(txid, vintx, hashBlock, false) != 0) { Getscriptaddress(destaddr, vintx.vout[vout].scriptPubKey); if (strcmp(destaddr, coinaddr) != 0 && strcmp(destaddr, cp->unspendableCCaddr) != 0 && strcmp(destaddr, cp->unspendableaddr2) != 0) continue; - //fprintf(stderr, "AddTokenCCInputs() check destaddress=%s vout amount=%.8f\n", destaddr, (double)vintx.vout[vout].nValue / COIN); + fprintf(stderr, "AddTokenCCInputs() check destaddress=%s vout amount=%.8f\n", destaddr, (double)vintx.vout[vout].nValue / COIN); - std::vector vinPubkeysEmpty; - if ((nValue = IsTokensvout(true, false/*<-- do not check spending outside EVAL_TOKENS for now */, cp, NULL, vopretExtra, vintx, vout, tokenid, vinPubkeysEmpty)) > 0 && myIsutxo_spentinmempool(txid, vout) == 0) + std::vector vinPubkeys; + + if ((nValue = IsTokensvout(true, true/*<--add only checked uxtos */, cp, NULL, vopretExtra, vintx, vout, tokenid, vinPubkeys)) > 0 && myIsutxo_spentinmempool(txid, vout) == 0) { if (total != 0 && maxinputs != 0) mtx.vin.push_back(CTxIn(txid, vout, CScript())); nValue = it->second.satoshis; totalinputs += nValue; - //std::cerr << "AddTokenInputs() adding input nValue=" << nValue << std::endl; + std::cerr << "AddTokenInputs() adding input nValue=" << nValue << std::endl; n++; if ((total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs)) break; diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 93c82945e..82b74cc11 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -90,6 +90,16 @@ CC *MakeTokensCCcond1of2(uint8_t evalcode, CPubKey pk1, CPubKey pk2) return cond1of2Threshold; } +CC *MakeTokensCCcond1(uint8_t evalcode, CPubKey pk) +{ + std::vector pks; + pks.push_back(CCNewSecp256k1(pk)); + CC *condEvalCC = CCNewEval(E_MARSHAL(ss << evalcode)); + CC *condEvalTokensCC = CCNewEval(E_MARSHAL(ss << (uint8_t)EVAL_TOKENS)); // this is eval token cc + CC *Sig = CCNewThreshold(1, pks); + return CCNewThreshold(3, { condEvalCC, condEvalTokensCC, Sig }); +} + CTxOut MakeTokensCC1of2vout(uint8_t evalcode, CAmount nValue, CPubKey pk1, CPubKey pk2) { CTxOut vout; @@ -99,6 +109,15 @@ CTxOut MakeTokensCC1of2vout(uint8_t evalcode, CAmount nValue, CPubKey pk1, CPubK return(vout); } +CTxOut MakeTokensCC1vout(uint8_t evalcode, CAmount nValue, CPubKey pk) +{ + CTxOut vout; + CC *payoutCond = MakeTokensCCcond1(evalcode, pk); + vout = CTxOut(nValue, CCPubKey(payoutCond)); + cc_free(payoutCond); + return(vout); +} + CC* GetCryptoCondition(CScript const& scriptSig) { auto pc = scriptSig.begin(); diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 73d8b49aa..7d1d56006 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -161,7 +161,7 @@ bool HeirValidate(struct CCcontract_info* cpHeir, Eval* eval, const CTransaction std::cerr << "HeirValidate funcid=" << (char)funcId << " evalcode=" << (int)cpHeir->evalcode << std::endl; //////////////// temp //////////////////////// - return true; + ///return true; switch (funcId) { case 'F': From c4c58b484ab83355debb181addf8cb04571f0a30 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 11 Jan 2019 23:02:37 +0500 Subject: [PATCH 381/643] heir modified for two eval Tokens changed to new 2-opret format --- src/cc/CCinclude.h | 2 + src/cc/CCtokens.cpp | 43 ++++--- src/cc/CCtx.cpp | 22 +++- src/cc/CCutils.cpp | 25 ++++- src/cc/heir.cpp | 250 +++++++++++++++++++++++++---------------- src/cc/heir_validate.h | 159 +++++++++++++++++++------- 6 files changed, 342 insertions(+), 159 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 0dc7f446d..4b6b437b4 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -191,6 +191,8 @@ CTxOut MakeTokensCC1of2vout(uint8_t evalcode, CAmount nValue, CPubKey pk1, CPubK CTxOut MakeTokensCC1vout(uint8_t evalcode, CAmount nValue, CPubKey pk); CC *MakeTokensCCcond1of2(uint8_t evalcode, CPubKey pk1, CPubKey pk2); CC *MakeTokensCCcond1(uint8_t evalcode, CPubKey pk); + +bool GetTokensCCaddress(struct CCcontract_info *cp, char *destaddr, CPubKey pk); bool GetTokensCCaddress1of2(struct CCcontract_info *cp, char *destaddr, CPubKey pk, CPubKey pk2); void CCaddrTokens1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr); diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 2f9a50a93..0bd4dd991 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -201,10 +201,10 @@ bool TokensValidate(struct CCcontract_info *cp, Eval* eval, const CTransaction & //vout.0: issuance tokenoshis to CC //vout.1: normal output for change (if any) //vout.n-1: opreturn EVAL_TOKENS 'c' - if (evalCodeInOpret != EVAL_TOKENS) - return eval->Invalid("unexpected TokenValidate for createtoken"); - else - return true; + //if (evalCodeInOpret != EVAL_TOKENS) + // return eval->Invalid("unexpected TokenValidate for createtoken"); + //else + return true; case 't': // transfer //vin.0: normal input @@ -225,15 +225,15 @@ bool TokensValidate(struct CCcontract_info *cp, Eval* eval, const CTransaction & // forward validation if evalcode in opret is not EVAL_TOKENS // init for forwarding validation call - if (evalCodeInOpret != EVAL_TOKENS) { // TODO: should we check also only allowed for tokens evalcodes, like EVAL_ASSETS, EVAL_GATEWAYS? - struct CCcontract_info *cpOther = NULL, C; + //if (evalCodeInOpret != EVAL_TOKENS) { // TODO: should we check also only allowed for tokens evalcodes, like EVAL_ASSETS, EVAL_GATEWAYS? + // struct CCcontract_info *cpOther = NULL, C; - cpOther = CCinit(&C, evalCodeInOpret); - if (cpOther) - return cpOther->validate(cpOther, eval, tx, nIn); - else - return eval->Invalid("unsupported evalcode in opret"); - } + // cpOther = CCinit(&C, evalCodeInOpret); + // if (cpOther) + // return cpOther->validate(cpOther, eval, tx, nIn); + // else + // return eval->Invalid("unsupported evalcode in opret"); + //} return true; // what does this do? // return(PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts)); @@ -285,17 +285,18 @@ bool ExtractVinPubkeys(struct CCcontract_info *cp, CTransaction tx, std::vector< thread_local uint32_t tokenValIndentSize = 0; // validates opret for token tx: -bool ValidateTokenOpret(CTransaction tx, int32_t v, uint256 tokenid, uint8_t &evalCodeInOpret, std::vector &voutPubkeys, std::vector &vopretExtra) { +bool ValidateTokenOpret(CTransaction tx, int32_t v, uint256 tokenid, std::vector &voutPubkeys, std::vector &vopretExtra) { uint256 tokenidOpret, tokenidOpret2; uint8_t funcid; + uint8_t dummyEvalCode; // this is just for log messages indentation fur debugging recursive calls: std::string indentStr = std::string().append(tokenValIndentSize, '.'); int32_t n = tx.vout.size(); - if ((funcid = DecodeTokenOpRet(tx.vout[n - 1].scriptPubKey, evalCodeInOpret, tokenidOpret, voutPubkeys, vopretExtra)) == 0) + if ((funcid = DecodeTokenOpRet(tx.vout[n - 1].scriptPubKey, dummyEvalCode, tokenidOpret, voutPubkeys, vopretExtra)) == 0) { std::cerr << indentStr << "ValidateTokenOpret() DecodeTokenOpret could not parse opret for txid=" << tx.GetHash().GetHex() << std::endl; return(false); @@ -364,14 +365,24 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c // moved opret checking to this new reusable func (dimxy): std::vector voutPubkeys; - uint8_t evalCodeInOpret = 0; - const bool valOpret = ValidateTokenOpret(tx, v, reftokenid, evalCodeInOpret, voutPubkeys, vopretExtra); + const bool valOpret = ValidateTokenOpret(tx, v, reftokenid, voutPubkeys, vopretExtra); //std::cerr << indentStr << "IsTokensvout() ValidateTokenOpret returned=" << std::boolalpha << valOpret << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; if (valOpret) { //std::cerr << indentStr << "IsTokensvout() ValidateTokenOpret returned true" << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; if (checkPubkeys) { // verify that the vout is within EVAL_TOKENS: + CScript contractScript = CScript(vopretExtra); + std::vector vcontractOpret; + + GetOpReturnData(contractScript, vcontractOpret); + if (vcontractOpret.size() == 0) { + std::cerr << "IsTokensvout() empty contract opret" << std::endl; + return 0; + } + + uint8_t evalCodeInOpret = vcontractOpret.begin()[0]; + if (voutPubkeys.size() >= 1 && voutPubkeys.size() <= 2) { CTxOut testVout; if (voutPubkeys.size() == 1) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 30c4c1e62..d85f59473 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -43,9 +43,9 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); CTransaction vintx; std::string hex; uint256 hashBlock; uint64_t mask=0,nmask=0,vinimask=0; int64_t utxovalues[CC_MAXVINS],change,normalinputs=0,totaloutputs=0,normaloutputs=0,totalinputs=0,normalvins=0,ccvins=0; - int32_t i,utxovout,n,err = 0; char myaddr[64],destaddr[64],unspendable[64]; + int32_t i,utxovout,n,err = 0; char myaddr[64],destaddr[64],unspendable[64],mytokensaddr[64]; uint8_t *privkey,myprivkey[32],unspendablepriv[32],*msg32 = 0; - CC *mycond=0, *othercond=0, *othercond2=0, *othercond3=0, *othercond1of2=NULL, *othercond1of2tokens = NULL, *cond; + CC *mycond=0, *othercond=0, *othercond2=0, *othercond3=0, *othercond1of2=NULL, *othercond1of2tokens = NULL, *cond, *mytokenscond = NULL; CPubKey unspendablepk; n = mtx.vout.size(); @@ -61,11 +61,17 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran return("0"); } Myprivkey(myprivkey); - unspendablepk = GetUnspendable(cp,unspendablepriv); + GetCCaddress(cp,myaddr,mypk); mycond = MakeCCcond1(cp->evalcode,mypk); + + GetTokensCCaddress(cp, myaddr, mypk); + mytokenscond = MakeTokensCCcond1(cp->evalcode, mypk); + + unspendablepk = GetUnspendable(cp,unspendablepriv); GetCCaddress(cp,unspendable,unspendablepk); - othercond = MakeCCcond1(cp->evalcode,unspendablepk); + othercond = MakeCCcond1(cp->evalcode,unspendablepk); + //Reorder vins so that for multiple normal vins all other except vin0 goes to the end //This is a must to avoid hardfork change of validation in every CC, because there could be maximum one normal vin at the begining with current validation. for (i=0; icoins1of2addr, destaddr) == 0) + else if (strcmp(cp->coins1of2addr, destaddr) == 0) { fprintf(stderr,"FinalizeCCTx() matched %s unspendable1of2!\n",cp->coins1of2addr); privkey = myprivkey; diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 82b74cc11..6d2d4a037 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -94,8 +94,8 @@ CC *MakeTokensCCcond1(uint8_t evalcode, CPubKey pk) { std::vector pks; pks.push_back(CCNewSecp256k1(pk)); - CC *condEvalCC = CCNewEval(E_MARSHAL(ss << evalcode)); - CC *condEvalTokensCC = CCNewEval(E_MARSHAL(ss << (uint8_t)EVAL_TOKENS)); // this is eval token cc + CC *condEvalCC = CCNewEval(E_MARSHAL(ss << evalcode)); // add eval cc + CC *condEvalTokensCC = CCNewEval(E_MARSHAL(ss << (uint8_t)EVAL_TOKENS)); // add also eval token cc CC *Sig = CCNewThreshold(1, pks); return CCNewThreshold(3, { condEvalCC, condEvalTokensCC, Sig }); } @@ -345,6 +345,27 @@ bool GetCCaddress(struct CCcontract_info *cp,char *destaddr,CPubKey pk) return(_GetCCaddress(destaddr,cp->evalcode,pk)); } +bool _GetTokensCCaddress(char *destaddr, uint8_t evalcode, CPubKey pk) +{ + CC *payoutCond; + destaddr[0] = 0; + if ((payoutCond = MakeTokensCCcond1(evalcode, pk)) != 0) + { + Getscriptaddress(destaddr, CCPubKey(payoutCond)); + cc_free(payoutCond); + } + return(destaddr[0] != 0); +} + +bool GetTokensCCaddress(struct CCcontract_info *cp, char *destaddr, CPubKey pk) +{ + destaddr[0] = 0; + if (pk.size() == 0) + pk = GetUnspendable(cp, 0); + return(_GetTokensCCaddress(destaddr, cp->evalcode, pk)); +} + + bool GetCCaddress1of2(struct CCcontract_info *cp,char *destaddr,CPubKey pk,CPubKey pk2) { CC *payoutCond; diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 7d1d56006..784e0a88c 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -122,23 +122,27 @@ bool HeirValidate(struct CCcontract_info* cpHeir, Eval* eval, const CTransaction //if (chainActive.Height() < 741) // return true; - uint8_t funcId; uint256 fundingTxidInOpret = zeroid, latestTxid = zeroid, dummyTokenid, tokenid = zeroid; CScript fundingTxOpRetScript; uint8_t hasHeirSpendingBegun = 0, dummyHasHeirSpendingBegun; - int32_t heirType = NOT_HEIR; - funcId = DecodeHeirOpRet(tx.vout[numvouts - 1].scriptPubKey, dummyTokenid, fundingTxidInOpret, dummyHasHeirSpendingBegun, true); - if(funcId != 0) - heirType = HEIR_COINS; - else { - funcId = DecodeHeirOpRet(tx.vout[numvouts - 1].scriptPubKey, tokenid, fundingTxidInOpret, dummyHasHeirSpendingBegun, false); - if (funcId != 0) - heirType = HEIR_TOKENS; + + uint8_t evalCodeTokens = 0; + std::vector voutPubkeys; + std::vector vopretExtra; + + CScript heirScript = tx.vout[tx.vout.size() - 1].scriptPubKey; + int32_t heirType = HEIR_COINS; + + uint8_t funcId = DecodeTokenOpRet(heirScript, evalCodeTokens, tokenid, voutPubkeys, vopretExtra); + if (funcId != 0) { + heirScript = CScript(vopretExtra); + heirType = HEIR_TOKENS; } + funcId = DecodeHeirOpRet(heirScript, fundingTxidInOpret, dummyHasHeirSpendingBegun, true); - if (heirType == NOT_HEIR) + if (funcId == 0) return eval->Invalid("invalid opreturn format"); if (funcId != 'F') { @@ -248,11 +252,11 @@ bool HeirValidate(struct CCcontract_info* cpHeir, Eval* eval, const CTransaction * Checks if vout is to cryptocondition address * @return vout value in satoshis */ -int64_t IsHeirFundingVout(struct CCcontract_info* cp, const CTransaction& tx, int32_t voutIndex, CPubKey ownerPubkey, CPubKey heirPubkey) +template int64_t IsHeirFundingVout(struct CCcontract_info* cp, const CTransaction& tx, int32_t voutIndex, CPubKey ownerPubkey, CPubKey heirPubkey) { char destaddr[65], heirFundingAddr[65]; - GetTokensCCaddress1of2(cp, heirFundingAddr, ownerPubkey, heirPubkey); + Helper::GetCoinsOrTokensCCaddress1of2(cp, heirFundingAddr, ownerPubkey, heirPubkey); if (tx.vout[voutIndex].scriptPubKey.IsPayToCryptoCondition() != 0) { // NOTE: dimxy it was unsafe 'Getscriptaddress(destaddr,tx.vout[voutIndex].scriptPubKey) > 0' here: if (Getscriptaddress(destaddr, tx.vout[voutIndex].scriptPubKey) && strcmp(destaddr, heirFundingAddr) == 0) @@ -317,6 +321,8 @@ CScript EncodeHeirOpRet(uint8_t funcid, uint256 fundingtxid, uint8_t hasHeirSpe fundingtxid = revuint256(fundingtxid); return CScript() << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << fundingtxid << hasHeirSpendingBegun); } + +/* // makes opret for tokens while they are inside Heir contract address space - initial funding CScript EncodeHeirTokensCreateOpRet(uint8_t heirFuncId, uint256 tokenid, std::vector voutPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string hearName) { @@ -348,10 +354,11 @@ CScript EncodeHeirTokensOpRet(uint8_t heirFuncId, uint256 tokenid, std::vector vopretExtra, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret, uint8_t &hasHeirSpendingBegun) { +/*uint8_t _UnmarshalOpret(std::vector vopretExtra, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret, uint8_t &hasHeirSpendingBegun) { uint8_t heirFuncId = 0; hasHeirSpendingBegun = 0; @@ -363,70 +370,66 @@ uint8_t _UnmarshalOpret(std::vector vopretExtra, CPubKey& ownerPubkey, } \ }); - if (!result /*|| assetFuncId != 't' -- any tx is ok*/) + if (!result )// || assetFuncId != 't' -- any tx is ok) return (uint8_t)0; return heirFuncId; -} +}*/ + /** * decode opret vout for Heir contract */ -template uint8_t _DecodeHeirOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging) +uint8_t _DecodeHeirOpRet(CScript scriptPubKey, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging) { - - std::vector vopretExtra; + std::vector vopret; uint8_t evalCodeInOpret = 0; - uint256 dummyTokenid; - std::vector voutPubkeysDummy; + uint8_t heirFuncId = 0; fundingTxidInOpret = zeroid; //to init - tokenid = zeroid; - - if (typeid(Helper) == typeid(TokenHelper)) { // if caller thinks it is a token - - // First - decode token opret: - uint8_t tokenFuncId = DecodeTokenOpRet(scriptPubKey, evalCodeInOpret, tokenid, voutPubkeysDummy, vopretExtra); - if (tokenFuncId == 0) { - if (!noLogging) std::cerr << "DecodeHeirOpRet() warning: not heir token opret, tokenFuncId=" << (int)tokenFuncId << std::endl; - return (uint8_t)0; - } + GetOpReturnData(scriptPubKey, vopret); + if (vopret.size() == 0) { + if (!noLogging) std::cerr << "_DecodeHeirOpRet() warning: empty opret" << std::endl; + return (uint8_t)0; } - else { - std::vector vopret; - - GetOpReturnData(scriptPubKey, vopret); - if (vopret.size() == 0) { - if (!noLogging) std::cerr << "DecodeHeirOpRet() warning: empty opret" << std::endl; - return (uint8_t)0; - } - evalCodeInOpret = vopret.begin()[0]; - vopretExtra = std::vector( vopret.begin()+1, vopret.end() ); // vopretExtra = vopret + 1, get it for futher parsing - } - - if (vopretExtra.size() > 1 && evalCodeInOpret == EVAL_HEIR) { + evalCodeInOpret = vopret.begin()[0]; + + if (vopret.size() > 1 && evalCodeInOpret == EVAL_HEIR) { // NOTE: it unmarshals for all F, A and C - uint8_t heirFuncId = _UnmarshalOpret(vopretExtra, ownerPubkey, heirPubkey, inactivityTime, heirName, fundingTxidInOpret, hasHeirSpendingBegun); - - /*std::cerr << "DecodeHeirOpRet()" + uint8_t heirFuncId = 0; + hasHeirSpendingBegun = 0; + + bool result = E_UNMARSHAL(vopret, { ss >> evalCodeInOpret; ss >> heirFuncId; \ + if (heirFuncId == 'F') { \ + ss >> ownerPubkey; ss >> heirPubkey; ss >> inactivityTime; ss >> heirName; \ + } \ + else { \ + ss >> fundingTxidInOpret >> hasHeirSpendingBegun; \ + } \ + }); + + if (!result) { + if (!noLogging) std::cerr << "_DecodeHeirOpRet() could not unmarshal opret, evalCode=" << (int)evalCodeInOpret << std::endl; + return (uint8_t)0; + } + + /* std::cerr << "DecodeHeirOpRet()" << " heirFuncId=" << (char)(heirFuncId ? heirFuncId : ' ') << " ownerPubkey=" << HexStr(ownerPubkey) << " heirPubkey=" << HexStr(heirPubkey) << " heirName=" << heirName << " inactivityTime=" << inactivityTime - << " hasHeirSpendingBegun=" << (int)hasHeirSpendingBegun << std::endl;*/ + << " hasHeirSpendingBegun=" << (int)hasHeirSpendingBegun << std::endl; */ - - //if (e == EVAL_HEIR && IS_CHARINSTR(funcId, "FAC")) - if (Helper::isMyFuncId(heirFuncId)) { + if (isMyFuncId(heirFuncId)) { fundingTxidInOpret = revuint256(fundingTxidInOpret); return heirFuncId; } else { - if(!noLogging) std::cerr << "DecodeHeirOpRet() error: unexpected opret, heirFuncId=" << (char)(heirFuncId ? heirFuncId : ' ') << std::endl; + if(!noLogging) std::cerr << "_DecodeHeirOpRet() unexpected opret type, heirFuncId=" << (char)(heirFuncId ? heirFuncId : ' ') << std::endl; } } else { - if (!noLogging) std::cerr << "DecodeHeirOpRet() error: not a heir opret, vopretExtra.size() == 0 or not EVAL_HEIR evalcode=" << (int)evalCodeInOpret << std::endl; + if (!noLogging) std::cerr << "_DecodeHeirOpRet() not a heir opret, vopretExtra.size() == 0 or not EVAL_HEIR evalcode=" << (int)evalCodeInOpret << std::endl; } return (uint8_t)0; } @@ -434,24 +437,24 @@ template uint8_t _DecodeHeirOpRet(CScript scriptPubKey, uint256 & /** * overload for 'F' opret */ -template uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging) +uint8_t DecodeHeirOpRet(CScript scriptPubKey, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging) { uint256 dummytxid; uint8_t dummyHasHeirSpendingBegun; - return _DecodeHeirOpRet(scriptPubKey, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, dummytxid, dummyHasHeirSpendingBegun, noLogging); + return _DecodeHeirOpRet(scriptPubKey, ownerPubkey, heirPubkey, inactivityTime, heirName, dummytxid, dummyHasHeirSpendingBegun, noLogging); } /** * overload for A, C oprets and AddHeirContractInputs */ -template uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256 &tokenid, uint256& fundingtxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging) +uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256& fundingtxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging) { CPubKey dummyOwnerPubkey, dummyHeirPubkey; int64_t dummyInactivityTime; std::string dummyHeirName; - return _DecodeHeirOpRet(scriptPubKey, tokenid, dummyOwnerPubkey, dummyHeirPubkey, dummyInactivityTime, dummyHeirName, fundingtxidInOpret, hasHeirSpendingBegun, noLogging); + return _DecodeHeirOpRet(scriptPubKey, dummyOwnerPubkey, dummyHeirPubkey, dummyInactivityTime, dummyHeirName, fundingtxidInOpret, hasHeirSpendingBegun, noLogging); } @@ -476,9 +479,22 @@ template uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_ // get initial funding tx and set it as initial lasttx: if (myGetTransaction(fundingtxid, fundingtx, hashBlock) && fundingtx.vout.size()) { uint256 dummytxid; + uint8_t evalCodeTokens = 0; + std::vector vopretExtra; + std::vector dummyVoutPubkeys; - // set ownerPubkey and heirPubkey: - if ((funcId = DecodeHeirOpRet(fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName)) != 0) { + CScript heirScript = fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey; + if (typeid(Helper) == typeid(TokenHelper)) { + if (DecodeTokenOpRet(heirScript, evalCodeTokens, tokenid, dummyVoutPubkeys, vopretExtra) != 0) { + heirScript = CScript(vopretExtra); + } + else { + std::cerr << "FindLatestFundingTx() could not decode token opreturn for fundingtxid=" << fundingtxid.GetHex() << '\n'; + return zeroid; + } + } + funcId = DecodeHeirOpRet(heirScript, ownerPubkey, heirPubkey, inactivityTime, heirName); + if (funcId != 0) { // found at least funding tx! //std::cerr << "FindLatestFundingTx() lasttx currently is fundingtx, txid=" << fundingtxid.GetHex() << " opreturn type=" << (char)funcId << '\n'; fundingOpretScript = fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey; @@ -493,7 +509,7 @@ template uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_ std::vector> unspentOutputs; struct CCcontract_info *cp, C; - cp = CCinit(&C, Helper::getMyEval()); + cp = CCinit(&C, EVAL_HEIR); char coinaddr[64]; GetCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); // get the address of cryptocondition '1 of 2 pubkeys' @@ -531,9 +547,23 @@ template uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_ uint8_t tmpFuncId; uint8_t tmphasHeirSpendingBegun; - if (regtx.vout.size() > 0 && - (tmpFuncId = DecodeHeirOpRet(regtx.vout[regtx.vout.size() - 1].scriptPubKey, dummyTokenid, fundingTxidInOpret, tmphasHeirSpendingBegun, true)) != 0 && - fundingtxid == fundingTxidInOpret) { + uint8_t evalCodeTokens = 0; + std::vector vopretExtra; + std::vector dummyVoutPubkeys; + + CScript heirScript = regtx.vout[regtx.vout.size() - 1].scriptPubKey; + if (typeid(Helper) == typeid(TokenHelper)) { + if (DecodeTokenOpRet(heirScript, evalCodeTokens, tokenid, dummyVoutPubkeys, vopretExtra) != 0) { + heirScript = CScript(vopretExtra); + } + else { + std::cerr << "FindLatestFundingTx() could not decode token opreturn for fundingtxid=" << fundingtxid.GetHex() << '\n'; + return zeroid; + } + } + tmpFuncId = DecodeHeirOpRet(heirScript, fundingTxidInOpret, tmphasHeirSpendingBegun, true); + + if (regtx.vout.size() > 0 && tmpFuncId != 0 && fundingtxid == fundingTxidInOpret) { if (blockHeight > maxBlockHeight) { maxBlockHeight = blockHeight; @@ -581,12 +611,13 @@ template int64_t Add1of2AddressInputs(struct CCcontract_info* cp, std::vector> unspentOutputs; char coinaddr[64]; - GetTokensCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); // get address of cryptocondition '1 pubkey of 2 pubkeys' + Helper::GetCoinsOrTokensCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); // get address of cryptocondition '1 of 2 pubkeys' SetCCunspents(unspentOutputs, coinaddr); // char markeraddr[64]; // CCtxidaddr(markeraddr, fundingtxid); // SetCCunspents(unspentOutputs, markeraddr); + std::cerr << "Add1of2AddressInputs() using 1of2addr=" << coinaddr << " unspentOutputs.size()=" << unspentOutputs.size() << std::endl; for (std::vector>::const_iterator it = unspentOutputs.begin(); it != unspentOutputs.end(); it++) { @@ -602,13 +633,22 @@ template int64_t Add1of2AddressInputs(struct CCcontract_info* cp, uint256 tokenid; uint256 fundingTxidInOpret; uint8_t dummyHasHeirSpendingBegun; + uint8_t evalCodeTokens = 0; + std::vector vopretExtra; + std::vector voutPubkeys; - uint8_t funcId = DecodeHeirOpRet(heirtx.vout[heirtx.vout.size() - 1].scriptPubKey, tokenid, fundingTxidInOpret, dummyHasHeirSpendingBegun, true); + CScript heirScript = heirtx.vout[heirtx.vout.size() - 1].scriptPubKey; + uint8_t funcId = DecodeTokenOpRet(heirScript, evalCodeTokens, tokenid, voutPubkeys, vopretExtra); + if (funcId != 0) { + heirScript = CScript(vopretExtra); + } + funcId = DecodeHeirOpRet(heirScript, fundingTxidInOpret, dummyHasHeirSpendingBegun, true); + if ((txid == fundingtxid || fundingTxidInOpret == fundingtxid) && funcId != 0 && - Helper::isMyFuncId(funcId) && + isMyFuncId(funcId) && // (typeid(Helper) == typeid(TokenHelper) && IsHeirvout(true, cp, nullptr, tokenid, vintx, voutIndex) > 0) && // deep validation for tokens - not used anymore - (voutValue = IsHeirFundingVout(cp, heirtx, voutIndex, ownerPubkey, heirPubkey)) > 0 && + (voutValue = IsHeirFundingVout(cp, heirtx, voutIndex, ownerPubkey, heirPubkey)) > 0 && !myIsutxo_spentinmempool(txid, voutIndex)) { std::cerr << "Add1of2AddressInputs() voutValue=" << voutValue << " satoshis=" << it->second.satoshis << '\n'; @@ -631,7 +671,7 @@ template int64_t Add1of2AddressInputs(struct CCcontract_info* cp, template int64_t LifetimeHeirContractFunds(struct CCcontract_info* cp, uint256 fundingtxid, CPubKey ownerPubkey, CPubKey heirPubkey) { char coinaddr[64]; - GetCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); // get the address of cryptocondition '1 of 2 pubkeys' + Helper::GetCoinsOrTokensCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); // get the address of cryptocondition '1 of 2 pubkeys' std::vector> addressIndexes; SetCCtxids(addressIndexes, coinaddr); @@ -644,17 +684,24 @@ template int64_t LifetimeHeirContractFunds(struct CCcontract_info CTransaction tx; if (GetTransaction(txid, tx, hashBlock, false) && tx.vout.size() > 0) { - uint8_t funcId; + uint8_t evalCodeTokens = 0; uint256 tokenid; uint256 fundingTxidInOpret; - const int32_t ivout = 0; + std::vector vopretExtra; + std::vector voutPubkeys; uint8_t dummyHasHeirSpendingBegun; - - funcId = DecodeHeirOpRet(tx.vout[tx.vout.size() - 1].scriptPubKey, tokenid, fundingTxidInOpret, dummyHasHeirSpendingBegun, true); + const int32_t ivout = 0; + + CScript heirScript = tx.vout[tx.vout.size() - 1].scriptPubKey; + uint8_t funcId = DecodeTokenOpRet(heirScript, evalCodeTokens, tokenid, voutPubkeys, vopretExtra); + if (funcId != 0) { + heirScript = CScript(vopretExtra); + } + funcId = DecodeHeirOpRet(heirScript, fundingTxidInOpret, dummyHasHeirSpendingBegun, true); //std::cerr << "LifetimeHeirContractFunds() found tx=" << txid.GetHex() << " vout[0].nValue=" << subtx.vout[ccVoutIdx].nValue << " opreturn=" << (char)funcId << '\n'; - if (funcId != 0 && (txid == fundingtxid || fundingTxidInOpret == fundingtxid) && Helper::isMyFuncId(funcId) && !Helper::isSpendingTx(funcId) + if (funcId != 0 && (txid == fundingtxid || fundingTxidInOpret == fundingtxid) && isMyFuncId(funcId) && !isSpendingTx(funcId) /* && !myIsutxo_spentinmempool(txid, ccVoutIdx) */) // include also tx in mempool { total += it->second; // dont do this: tx.vout[ivout].nValue; // in vin[0] always is the pay to 1of2 addr (funding or change) @@ -678,7 +725,7 @@ template std::string HeirFund(uint64_t txfee, int64_t amount, CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); struct CCcontract_info *cp, C; - cp = CCinit(&C, Helper::getMyEval()); + cp = CCinit(&C, EVAL_HEIR); if (txfee == 0) txfee = 10000; @@ -719,7 +766,6 @@ template std::string HeirFund(uint64_t txfee, int64_t amount, // add change for txfee and opreturn vouts and sign tx: return (FinalizeCCTx(0, cp, mtx, myPubkey, txfee, - // CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_HEIR << (uint8_t)'F' << myPubkey << heirPubkey << inactivityTimeSec << heirName))); Helper::makeCreateOpRet(tokenid, voutTokenPubkeys, myPubkey, heirPubkey, inactivityTimeSec, heirName))); } else // TODO: need result return unification with heiradd and claim @@ -759,7 +805,7 @@ template UniValue HeirAdd(uint256 fundingtxid, uint64_t txfee, in uint8_t funcId; uint8_t hasHeirSpendingBegun = 0; - cp = CCinit(&C, Helper::getMyEval()); + cp = CCinit(&C, EVAL_HEIR); if (txfee == 0) txfee = 10000; @@ -790,7 +836,7 @@ template UniValue HeirAdd(uint256 fundingtxid, uint64_t txfee, in std::cerr << "HeirAdd() adding markeraddr=" << markeraddr << '\n'; */ // add cryptocondition to spend this funded amount for either pk - mtx.vout.push_back(MakeCC1of2vout(Helper::getMyEval(), amount, ownerPubkey, heirPubkey)); // using always pubkeys from OP_RETURN in order to not mixing them up! + mtx.vout.push_back(Helper::make1of2Vout(amount, ownerPubkey, heirPubkey)); // using always pubkeys from OP_RETURN in order to not mixing them up! if (inputs > amount) change = (inputs - amount); // -txfee <-- txfee pays user @@ -801,7 +847,7 @@ template UniValue HeirAdd(uint256 fundingtxid, uint64_t txfee, in mtx.vout.push_back(Helper::makeUserVout(change, myPubkey)); } - // add 1of2 vout validation pubkeys: + // add 1of2 vout validation pubkeys - needed only for tokens: std::vector voutTokenPubkeys; voutTokenPubkeys.push_back(ownerPubkey); voutTokenPubkeys.push_back(heirPubkey); @@ -863,8 +909,6 @@ template UniValue HeirClaim(uint256 fundingtxid, uint64_t txfee std::string heirName; uint8_t hasHeirSpendingBegun = 0; - - //cp = CCinit(&C, Helper::getMyEval()); cp = CCinit(&C, EVAL_HEIR); if (txfee == 0) txfee = 10000; @@ -924,7 +968,7 @@ template UniValue HeirClaim(uint256 fundingtxid, uint64_t txfee // change to 1of2 funding addr: if (change != 0) { // vout[1] - mtx.vout.push_back(MakeCC1of2vout(Helper::getMyEval(), change, ownerPubkey, heirPubkey)); // using always pubkeys from OP_RETURN in order to not mixing them up! + mtx.vout.push_back(Helper::make1of2Vout(change, ownerPubkey, heirPubkey)); // using always pubkeys from OP_RETURN in order to not mixing them up! } // add marker vout: @@ -937,7 +981,7 @@ template UniValue HeirClaim(uint256 fundingtxid, uint64_t txfee uint8_t myprivkey[32]; char coinaddr[64]; // set priv key addresses in CC structure: - GetTokensCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); + Helper::GetCoinsOrTokensCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); Myprivkey(myprivkey); ////fprintf(stderr,"HeirClaim() before setting unspendable CC addr2= (%s) addr3= (%s)\n", cp->unspendableaddr2, cp->unspendableaddr3); @@ -945,9 +989,9 @@ template UniValue HeirClaim(uint256 fundingtxid, uint64_t txfee //CCaddr3set(cp, Helper::getMyEval(), heirPubkey, myprivkey, coinaddr); ////fprintf(stderr, "HeirClaim() after setting unspendable CC addr2=(%s) addr3=(%s)\n", cp->unspendableaddr2, cp->unspendableaddr3); - CCaddrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); + Helper::CCaddrCoinsOrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); - // add 1of2 vout validation pubkeys: + // add 1of2 vout validation pubkeys (this is for tokens): std::vector voutTokenPubkeys; voutTokenPubkeys.push_back(ownerPubkey); voutTokenPubkeys.push_back(heirPubkey); @@ -1017,15 +1061,22 @@ UniValue HeirInfo(uint256 fundingtxid) // get initial funding tx and set it as initial lasttx: if (myGetTransaction(fundingtxid, fundingtx, hashBlock) && fundingtx.vout.size()) { - int32_t heirType = NOT_HEIR; const bool noLogging = true; + uint8_t evalCodeTokens = 0; + std::vector voutPubkeys; + std::vector vopretExtra; - if (DecodeHeirOpRet(fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey, dummyTokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, noLogging) == 'F') - heirType = HEIR_COINS; - else if (DecodeHeirOpRet(fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, noLogging) == 'F') + CScript heirScript = fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey; + int32_t heirType = HEIR_COINS; + + uint8_t funcId = DecodeTokenOpRet(heirScript, evalCodeTokens, tokenid, voutPubkeys, vopretExtra); + if (funcId != 0) { + heirScript = CScript(vopretExtra); heirType = HEIR_TOKENS; - else - { + } + funcId = DecodeHeirOpRet(heirScript, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, noLogging); + + if( funcId == 0 ) { std::cerr << "HeirInfo() initial tx F not found for this fundingtx" << std::endl; result.push_back(Pair("result", "error")); result.push_back(Pair("error", "initial tx F not found")); @@ -1033,10 +1084,7 @@ UniValue HeirInfo(uint256 fundingtxid) } struct CCcontract_info *cp, C; - if (heirType == HEIR_COINS) - cp = CCinit(&C, CoinHelper::getMyEval()); - else - cp = CCinit(&C, TokenHelper::getMyEval()); + cp = CCinit(&C, EVAL_HEIR); uint8_t hasHeirSpendingBegun = 0; @@ -1174,14 +1222,24 @@ template void _HeirList(struct CCcontract_info *cp, UniValue &r //std::cerr << "HeirList() checking txid=" << txid.GetHex() << " vout=" << vout << '\n'; - CTransaction inittx; - if (GetTransaction(txid, inittx, hashBlock, false) != 0 && (inittx.vout.size() - 1) > 0) { + CTransaction fundingtx; + if (GetTransaction(txid, fundingtx, hashBlock, false) != 0 && (fundingtx.vout.size() - 1) > 0) { CPubKey ownerPubkey, heirPubkey; std::string heirName; int64_t inactivityTimeSec; const bool noLogging = true; - uint8_t funcId = DecodeHeirOpRet(inittx.vout[inittx.vout.size() - 1].scriptPubKey, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, noLogging); + uint8_t evalCodeTokens = 0; + uint256 tokenid; + std::vector vopretExtra; + std::vector voutPubkeys; + + CScript heirScript = fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey; + uint8_t funcId = DecodeTokenOpRet(heirScript, evalCodeTokens, tokenid, voutPubkeys, vopretExtra); + if (funcId != 0) { + heirScript = CScript(vopretExtra); + } + funcId = DecodeHeirOpRet(heirScript, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, noLogging); // note: if it is not Heir token funcId would be equal to 0 if (funcId == 'F') { diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index 5b5df2110..0094f5f4c 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -14,19 +14,21 @@ CScript EncodeHeirCreateOpRet(uint8_t funcid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName); CScript EncodeHeirOpRet(uint8_t funcid, uint256 fundingtxid, uint8_t isHeirSpendingBegan); // makes token opret -CScript EncodeHeirTokensCreateOpRet(uint8_t funcid, uint256 tokenid, std::vector voutPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string hearName); -CScript EncodeHeirTokensOpRet(uint8_t funcid, uint256 tokenid, std::vector voutPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan); +//CScript EncodeHeirTokensCreateOpRet(uint8_t funcid, uint256 tokenid, std::vector voutPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string hearName); +//CScript EncodeHeirTokensOpRet(uint8_t funcid, uint256 tokenid, std::vector voutPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan); template uint256 FindLatestFundingTx(uint256 fundingtxid, uint256 &tokenid, CScript& opRetScript, uint8_t &isHeirSpendingBegan); -template uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256 &tokenid, uint256& fundingtxid, uint8_t &isHeirSpendingBegan, bool noLogging = false); -template uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging = false); +uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256& fundingtxid, uint8_t &isHeirSpendingBegan, bool noLogging = false); +uint8_t DecodeHeirOpRet(CScript scriptPubKey, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging = false); + +inline static bool isMyFuncId(uint8_t funcid) { return IS_CHARINSTR(funcid, "FAC"); } +inline static bool isSpendingTx(uint8_t funcid) { return (funcid == 'C'); } + // helper class to allow polymorphic behaviour for HeirXXX() functions in case of coins class CoinHelper { public: - static bool isMyFuncId(uint8_t funcid) { return IS_CHARINSTR(funcid, "FAC"); } - static uint8_t getMyEval() { return EVAL_HEIR; } static int64_t addOwnerInputs(struct CCcontract_info* cp, uint256 dummyid, CMutableTransaction& mtx, CPubKey ownerPubkey, int64_t total, int32_t maxinputs) { return AddNormalinputs(mtx, ownerPubkey, total, maxinputs); } @@ -40,43 +42,58 @@ public: static CScript makeClaimOpRet(uint256 dummyid, std::vector dummyPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) { return EncodeHeirOpRet((uint8_t)'C', fundingtxid, isHeirSpendingBegan); } - - static bool isSpendingTx(uint8_t funcid) { return (funcid == 'C'); } - + static CTxOut make1of2Vout(int64_t amount, CPubKey ownerPubkey, CPubKey heirPubkey) { + return MakeCC1of2vout(EVAL_HEIR, amount, ownerPubkey, heirPubkey); + } static CTxOut makeUserVout(int64_t amount, CPubKey myPubkey) { return CTxOut(amount, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG); } static CTxOut makeClaimerVout(int64_t amount, CPubKey myPubkey) { return CTxOut(amount, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG); } + static bool GetCoinsOrTokensCCaddress1of2(struct CCcontract_info* cp, char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { + return GetCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); + } + static void CCaddrCoinsOrTokens1of2set(struct CCcontract_info* cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { + CCaddr1of2set(cp, ownerPubkey, heirPubkey, coinaddr); + } }; // helper class to allow polymorphic behaviour for HeirXXX() functions in case of tokens class TokenHelper { public: - static bool isMyFuncId(uint8_t funcid) { return IS_CHARINSTR(funcid, "FAC"); } - static uint8_t getMyEval() { return EVAL_TOKENS; } static int64_t addOwnerInputs(struct CCcontract_info* cp, uint256 tokenid, CMutableTransaction& mtx, CPubKey ownerPubkey, int64_t total, int32_t maxinputs) { return AddTokenCCInputs(cp, mtx, ownerPubkey, tokenid, total, maxinputs); } static CScript makeCreateOpRet(uint256 tokenid, std::vector voutTokenPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName) { - return EncodeHeirTokensCreateOpRet((uint8_t)'F', tokenid, voutTokenPubkeys, ownerPubkey, heirPubkey, inactivityTimeSec, heirName); + return EncodeTokenOpRet((uint8_t)'t', EVAL_TOKENS, tokenid, voutTokenPubkeys, + EncodeHeirCreateOpRet((uint8_t)'F', ownerPubkey, heirPubkey, inactivityTimeSec, heirName)); } static CScript makeAddOpRet(uint256 tokenid, std::vector voutTokenPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) { - return EncodeHeirTokensOpRet((uint8_t)'A', tokenid, voutTokenPubkeys, fundingtxid, isHeirSpendingBegan); + return EncodeTokenOpRet((uint8_t)'t', EVAL_TOKENS, tokenid, voutTokenPubkeys, + EncodeHeirOpRet((uint8_t)'A', fundingtxid, isHeirSpendingBegan)); } static CScript makeClaimOpRet(uint256 tokenid, std::vector voutTokenPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) { - return EncodeHeirTokensOpRet((uint8_t)'C', tokenid, voutTokenPubkeys, fundingtxid, isHeirSpendingBegan); + return EncodeTokenOpRet((uint8_t)'t', EVAL_TOKENS, tokenid, voutTokenPubkeys, + EncodeHeirOpRet((uint8_t)'C', fundingtxid, isHeirSpendingBegan)); } - static bool isSpendingTx(uint8_t funcid) { return (funcid == 'C'); } - + static CTxOut make1of2Vout(int64_t amount, CPubKey ownerPubkey, CPubKey heirPubkey) { + return MakeTokensCC1of2vout(EVAL_HEIR, amount, ownerPubkey, heirPubkey); + } static CTxOut makeUserVout(int64_t amount, CPubKey myPubkey) { - return MakeCC1vout(EVAL_TOKENS, amount, myPubkey); + return MakeTokensCC1vout(EVAL_HEIR, amount, myPubkey); } static CTxOut makeClaimerVout(int64_t amount, CPubKey myPubkey) { - return MakeCC1vout(EVAL_TOKENS, amount, myPubkey); + return MakeTokensCC1vout(EVAL_HEIR, amount, myPubkey); + } + static bool GetCoinsOrTokensCCaddress1of2(struct CCcontract_info* cp, char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { + return GetTokensCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); + } + + static void CCaddrCoinsOrTokens1of2set(struct CCcontract_info* cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { + CCaddrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); } }; @@ -307,11 +324,8 @@ public: return eval->Invalid(stream.str().c_str()); // ... if not, return 'invalid' } } - ival++; // advance to the next vout - } - //std::cerr << "COutputValidationPlan::validate() returns with true" << std::endl; return true; } @@ -350,14 +364,12 @@ private: return true; // validation OK } - private: //std::map m_mapValidators; std::vector< std::pair > m_arrayValidators; }; - class CNormalInputIdentifier : CInputIdentifierBase { public: CNormalInputIdentifier(CCcontract_info* cp) : CInputIdentifierBase(cp) {} @@ -390,13 +402,28 @@ public: virtual bool validateVout(CTxOut vout, std::string& message) const { //std::cerr << "CCC1of2AddressValidator::validateVout() entered" << std::endl; - uint8_t funcId; CPubKey ownerPubkey, heirPubkey; int64_t inactivityTime; std::string heirName; uint256 tokenid; + + uint8_t evalCodeTokens = 0; + std::vector vopretExtra; + std::vector dummyVoutPubkeys; - if ((funcId = DecodeHeirOpRet(m_fundingOpretScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName)) == 0) { + CScript heirScript = m_fundingOpretScript; + if (typeid(Helper) == typeid(TokenHelper)) { + if (DecodeTokenOpRet(heirScript, evalCodeTokens, tokenid, dummyVoutPubkeys, vopretExtra) != 0) { + heirScript = CScript(vopretExtra); + } + else { + message = m_customMessage + std::string(" invalid token opreturn format"); + std::cerr << "CCC1of2AddressValidator::validateVout() exits with false: " << message << std::endl; + return false; + } + } + uint8_t funcId = DecodeHeirOpRet(heirScript, ownerPubkey, heirPubkey, inactivityTime, heirName, false); + if (funcId == 0) { message = m_customMessage + std::string(" invalid opreturn format"); std::cerr << "CCC1of2AddressValidator::validateVout() exits with false: " << message << std::endl; return false; @@ -443,21 +470,35 @@ public: { //std::cerr << "CMyPubkeyVoutValidator::validateVout() entered" << std::endl; - uint8_t funcId; CPubKey ownerPubkey, heirPubkey; int64_t inactivityTime; std::string heirName; uint256 tokenid; ///std::cerr << "CMyPubkeyVoutValidator::validateVout() m_opRetScript=" << m_opRetScript.ToString() << std::endl; + + uint8_t evalCodeTokens = 0; + std::vector vopretExtra; + std::vector dummyVoutPubkeys; + + CScript ownerScript; + CScript heirScript = m_fundingOpretScript; + if (typeid(Helper) == typeid(TokenHelper)) { + if (DecodeTokenOpRet(heirScript, evalCodeTokens, tokenid, dummyVoutPubkeys, vopretExtra) != 0) { + heirScript = CScript(vopretExtra); + } + else { + message = std::string("invalid token opreturn format"); + return false; + } + } // get both pubkeys: - if ((funcId = DecodeHeirOpRet(m_fundingOpretScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName)) == 0) { + uint8_t funcId = DecodeHeirOpRet(heirScript, ownerPubkey, heirPubkey, inactivityTime, heirName, false); + if (funcId == 0) { message = std::string("invalid opreturn format"); return false; } - CScript ownerScript; - CScript heirScript; if (m_checkNormals) { ownerScript = CoinHelper::makeUserVout(vout.nValue, ownerPubkey).scriptPubKey; heirScript = CoinHelper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey; @@ -474,7 +515,6 @@ public: // this is vout to owner or heir addr: //std::cerr << "CMyPubkeyVoutValidator::validateVout() exits with true" << std::endl; return true; - } std::cerr << "CMyPubkeyVoutValidator::validateVout() exits with false (not the owner's or heir's addresses)" << std::endl; @@ -503,15 +543,28 @@ public: { //std::cerr << "CHeirSpendValidator::validateVout() entered" << std::endl; - uint8_t funcId; CPubKey ownerPubkey, heirPubkey; int64_t inactivityTime; std::string heirName; uint256 tokenid; + uint8_t evalCodeTokens = 0; + std::vector vopretExtra; + std::vector dummyVoutPubkeys; + + CScript heirScript = m_fundingOpretScript; + if (typeid(Helper) == typeid(TokenHelper)) { + if (DecodeTokenOpRet(heirScript, evalCodeTokens, tokenid, dummyVoutPubkeys, vopretExtra) != 0) { + heirScript = CScript(vopretExtra); + } else { + message = std::string("invalid token opreturn format"); + return false; + } + } // get heir pubkey: - if ((funcId = DecodeHeirOpRet(m_fundingOpretScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, false)) == 0) { + uint8_t funcId = DecodeHeirOpRet(heirScript, ownerPubkey, heirPubkey, inactivityTime, heirName, false); + if (funcId == 0) { message = std::string("invalid opreturn format"); return false; } @@ -560,28 +613,54 @@ public: { //std::cerr << "COpRetValidator::validateVout() entered" << std::endl; - uint8_t funcId, initialFuncId; // do not check heir name - uint256 fundingTxidInOpret = zeroid, dummyTxid, tokenid, initialTokenid; + uint256 fundingTxidInOpret = zeroid, dummyTxid, tokenid = zeroid, initialTokenid = zeroid; uint8_t dummyIsHeirSpendingBegan; - if ((funcId = DecodeHeirOpRet(vout.scriptPubKey, tokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan)) == 0) { + uint8_t evalCodeTokens = 0; + std::vector vopretExtra; + std::vector dummyVoutPubkeys; + + CScript heirScript = vout.scriptPubKey; + if (typeid(Helper) == typeid(TokenHelper)) { + if (DecodeTokenOpRet(heirScript, evalCodeTokens, tokenid, dummyVoutPubkeys, vopretExtra) != 0) { + heirScript = CScript(vopretExtra); + } else { + message = std::string("invalid token opreturn format"); + return false; + } + } + uint8_t funcId = DecodeHeirOpRet(heirScript, fundingTxidInOpret, dummyIsHeirSpendingBegan); + if (funcId == 0) { message = std::string("invalid opreturn format"); return false; } - if ((initialFuncId = DecodeHeirOpRet(m_fundingOpretScript, initialTokenid, dummyTxid, dummyIsHeirSpendingBegan)) == 0) { + + heirScript = m_fundingOpretScript; + if (typeid(Helper) == typeid(TokenHelper)) { + if (DecodeTokenOpRet(heirScript, evalCodeTokens, initialTokenid, dummyVoutPubkeys, vopretExtra) != 0) { + heirScript = CScript(vopretExtra); + } else { + message = std::string("invalid initial token opreturn format"); + return false; + } + } + uint8_t initialFuncId = DecodeHeirOpRet(heirScript, dummyTxid, dummyIsHeirSpendingBegan); + if (initialFuncId == 0) { message = std::string("invalid initial tx opreturn format"); return false; } // validation rules: - if (!Helper::isMyFuncId(funcId)) { + if (!isMyFuncId(funcId)) { message = std::string("invalid funcid in opret"); return false; } - if(tokenid != initialTokenid ) { - message = std::string("invalid tokenid in opret"); - return false; + if (typeid(Helper) == typeid(TokenHelper)) { + if (tokenid != initialTokenid) { + message = std::string("invalid tokenid in opret"); + return false; + } } std::cerr << "COpRetValidator::validateVout() exits with true" << std::endl; From 6065a6dec46de16b29b271932e1b482cc56eef76 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 12 Jan 2019 01:06:24 +0500 Subject: [PATCH 382/643] corrected -> no token vout pubkey validation for 'c' modified MakeTokenCCcond1 and 1of2 to eliminate duplicate evals --- src/cc/CCtokens.cpp | 22 +++++++++++----------- src/cc/CCutils.cpp | 24 +++++++++++++++--------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 0bd4dd991..5c848b081 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -285,7 +285,7 @@ bool ExtractVinPubkeys(struct CCcontract_info *cp, CTransaction tx, std::vector< thread_local uint32_t tokenValIndentSize = 0; // validates opret for token tx: -bool ValidateTokenOpret(CTransaction tx, int32_t v, uint256 tokenid, std::vector &voutPubkeys, std::vector &vopretExtra) { +uint8_t ValidateTokenOpret(CTransaction tx, int32_t v, uint256 tokenid, std::vector &voutPubkeys, std::vector &vopretExtra) { uint256 tokenidOpret, tokenidOpret2; uint8_t funcid; @@ -305,7 +305,7 @@ bool ValidateTokenOpret(CTransaction tx, int32_t v, uint256 tokenid, std::vector { if (tokenid != zeroid && tokenid == tx.GetHash() && v == 0) { //std::cerr << indentStr << "ValidateTokenOpret() this is the tokenbase 'c' tx, txid=" << tx.GetHash().GetHex() << " vout=" << v << " returning true" << std::endl; - return(true); + return funcid; } } else if (funcid == 't') @@ -313,18 +313,18 @@ bool ValidateTokenOpret(CTransaction tx, int32_t v, uint256 tokenid, std::vector //std::cerr << indentStr << "ValidateTokenOpret() tokenid=" << tokenid.GetHex() << " tokenIdOpret=" << tokenidOpret.GetHex() << " txid=" << tx.GetHash().GetHex() << std::endl; if (tokenid != zeroid && tokenid == tokenidOpret) { //std::cerr << indentStr << "ValidateTokenOpret() this is a transfer 't' tx, txid=" << tx.GetHash().GetHex() << " vout=" << v << " returning true" << std::endl; - return(true); + return funcid; } } //std::cerr << indentStr << "ValidateTokenOpret() return false funcid=" << (char)funcid << " tokenid=" << tokenid.GetHex() << " tokenIdOpret=" << tokenidOpret.GetHex() << " txid=" << tx.GetHash().GetHex() << std::endl; - return false; + return (uint8_t)0; } - - // Checks if the vout is a really Tokens CC vout -// compareTotals == true, the func also validates the passed transaction itself: +// also checks tokenid in opret or txid if this is 'c' tx +// goDeeper is true: the func also validates amounts of the passed transaction: // it should be either sum(cc vins) == sum(cc vouts) or the transaction is the 'tokenbase' ('c') tx +// checkPubkeys is true: validates if the vout is token vout1 or token vout1of2. Should always be true! int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, std::vector &vopretExtra, const CTransaction& tx, int32_t v, uint256 reftokenid, std::vector vinPubkeys) { @@ -365,12 +365,12 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c // moved opret checking to this new reusable func (dimxy): std::vector voutPubkeys; - const bool valOpret = ValidateTokenOpret(tx, v, reftokenid, voutPubkeys, vopretExtra); + const uint8_t funcId = ValidateTokenOpret(tx, v, reftokenid, voutPubkeys, vopretExtra); //std::cerr << indentStr << "IsTokensvout() ValidateTokenOpret returned=" << std::boolalpha << valOpret << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; - if (valOpret) { + if (funcId != 0) { //std::cerr << indentStr << "IsTokensvout() ValidateTokenOpret returned true" << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; - if (checkPubkeys) { // verify that the vout is within EVAL_TOKENS: + if (checkPubkeys && funcId != 'c') { // verify that the vout is token's (for 'c' there is no pubkeys!): CScript contractScript = CScript(vopretExtra); std::vector vcontractOpret; @@ -605,7 +605,7 @@ std::string TokenTransfer(int64_t txfee, uint256 assetid, std::vector d if (inputs > total) CCchange = (inputs - total); //for (i=0; i pks; pks.push_back(CCNewSecp256k1(pk1)); pks.push_back(CCNewSecp256k1(pk2)); - CC *condEvalCC = CCNewEval(E_MARSHAL(ss << evalcode)); // this is eval cc - CC *condEvalTokensCC = CCNewEval(E_MARSHAL(ss << (uint8_t)EVAL_TOKENS)); // this is eval token cc - CC *cond1of2Sig = CCNewThreshold(1, pks); // this is 1 of 2 sigs cc - CC *cond1of2Threshold = CCNewThreshold(3, { condEvalCC, condEvalTokensCC, cond1of2Sig }); - return cond1of2Threshold; + std::vector thresholds; + thresholds.push_back( CCNewEval(E_MARSHAL(ss << evalcode)) ); + if( evalcode != EVAL_TOKENS ) // if evalCode == EVAL_TOKENS, it is actually MakeCCcond1of2()! + thresholds.push_back(CCNewEval(E_MARSHAL(ss << (uint8_t)EVAL_TOKENS))); // this is eval token cc + thresholds.push_back(CCNewThreshold(1, pks)); // this is 1 of 2 sigs cc + + return CCNewThreshold(thresholds.size(), thresholds); } CC *MakeTokensCCcond1(uint8_t evalcode, CPubKey pk) { std::vector pks; pks.push_back(CCNewSecp256k1(pk)); - CC *condEvalCC = CCNewEval(E_MARSHAL(ss << evalcode)); // add eval cc - CC *condEvalTokensCC = CCNewEval(E_MARSHAL(ss << (uint8_t)EVAL_TOKENS)); // add also eval token cc - CC *Sig = CCNewThreshold(1, pks); - return CCNewThreshold(3, { condEvalCC, condEvalTokensCC, Sig }); + + std::vector thresholds; + thresholds.push_back(CCNewEval(E_MARSHAL(ss << evalcode))); + if (evalcode != EVAL_TOKENS) // if evalCode == EVAL_TOKENS, it is actually MakeCCcond1()! + thresholds.push_back(CCNewEval(E_MARSHAL(ss << (uint8_t)EVAL_TOKENS))); // this is eval token cc + thresholds.push_back(CCNewThreshold(1, pks)); // signature + + return CCNewThreshold(thresholds.size(), thresholds); } CTxOut MakeTokensCC1of2vout(uint8_t evalcode, CAmount nValue, CPubKey pk1, CPubKey pk2) From 0a76f9d8972b3a33eac9c0600c093982b85420f1 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 12 Jan 2019 15:20:55 +0500 Subject: [PATCH 383/643] AssetXXX() changed to GetTokenBalance, TokenInfo, TokenList added processing of incorrect tokenid to GetTokenBalance --- src/cc/CCassets.h | 6 ++-- src/cc/CCassetstx.cpp | 57 --------------------------------- src/cc/CCtokens.cpp | 68 ++++++++++++++++++++++++++++++++++++++++ src/cc/CCtokens.h | 4 +++ src/wallet/rpcwallet.cpp | 29 ++++++++++++----- 5 files changed, 96 insertions(+), 68 deletions(-) diff --git a/src/cc/CCassets.h b/src/cc/CCassets.h index 5a5ef2c82..39644efc6 100644 --- a/src/cc/CCassets.h +++ b/src/cc/CCassets.h @@ -47,12 +47,12 @@ int64_t AssetValidateSellvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpp bool AssetExactAmounts(struct CCcontract_info *cpAssets, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 assetid); // CCassetstx -int64_t GetAssetBalance(CPubKey pk,uint256 tokenid); +//int64_t GetAssetBalance(CPubKey pk,uint256 tokenid); // --> GetTokenBalance() int64_t AddAssetInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 assetid, int64_t total, int32_t maxinputs); UniValue AssetOrders(uint256 tokenid); -UniValue AssetInfo(uint256 tokenid); -UniValue AssetList(); +//UniValue AssetInfo(uint256 tokenid); +//UniValue AssetList(); //std::string CreateAsset(int64_t txfee,int64_t assetsupply,std::string name,std::string description); //std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total); //std::string AssetConvert(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total,int32_t evalcode); diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 1c2012534..3047876f4 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -66,63 +66,6 @@ int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK } -int64_t GetAssetBalance(CPubKey pk,uint256 tokenid) -{ - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - struct CCcontract_info *cp,C; - cp = CCinit(&C,EVAL_TOKENS); - return(AddTokenCCInputs(cp,mtx,pk,tokenid,0,0)); -} - -UniValue AssetInfo(uint256 assetid) -{ - UniValue result(UniValue::VOBJ); uint256 hashBlock; CTransaction vintx; std::vector origpubkey; std::string name,description; char str[67],numstr[65]; - if ( GetTransaction(assetid,vintx,hashBlock,false) == 0 ) - { - fprintf(stderr,"cant find assetid\n"); - result.push_back(Pair("result","error")); - result.push_back(Pair("error","cant find assetid")); - return(result); - } - if ( vintx.vout.size() > 0 && DecodeTokenCreateOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,origpubkey,name,description) == 0 ) - { - fprintf(stderr,"assetid isnt token creation txid\n"); - result.push_back(Pair("result","error")); - result.push_back(Pair("error","assetid isnt token creation txid")); - } - result.push_back(Pair("result","success")); - result.push_back(Pair("tokenid",uint256_str(str,assetid))); - result.push_back(Pair("owner",pubkey33_str(str,origpubkey.data()))); - result.push_back(Pair("name",name)); - result.push_back(Pair("supply",vintx.vout[0].nValue)); - result.push_back(Pair("description",description)); - return(result); -} - -UniValue AssetList() -{ - UniValue result(UniValue::VARR); - std::vector > addressIndex; - struct CCcontract_info *cp,C; uint256 txid,hashBlock; - CTransaction vintx; std::vector origpubkey; - std::string name,description; char str[65]; - - cp = CCinit(&C,EVAL_TOKENS); - SetCCtxids(addressIndex,cp->normaladdr); - for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) - { - txid = it->first.txhash; - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) - { - if ( vintx.vout.size() > 0 && DecodeTokenCreateOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,origpubkey,name,description) != 0 ) - { - result.push_back(uint256_str(str,txid)); - } - } - } - return(result); -} - UniValue AssetOrders(uint256 refassetid) { static uint256 zero; diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 5c848b081..613d4452f 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -623,4 +623,72 @@ std::string TokenTransfer(int64_t txfee, uint256 assetid, std::vector d fprintf(stderr, "not enough normal inputs for txfee\n"); } return(""); +} + + +int64_t GetTokenBalance(CPubKey pk, uint256 tokenid) +{ + uint256 hashBlock; + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + CTransaction tokentx; + + if (GetTransaction(tokenid, tokentx, hashBlock, false) == 0) + { + fprintf(stderr, "cant find tokenid\n"); + CCerror = strprintf("cant find tokenid"); + return 0; + } + + struct CCcontract_info *cp, C; + cp = CCinit(&C, EVAL_TOKENS); + return(AddTokenCCInputs(cp, mtx, pk, tokenid, 0, 0)); +} + +UniValue TokenInfo(uint256 tokenid) +{ + UniValue result(UniValue::VOBJ); uint256 hashBlock; CTransaction vintx; std::vector origpubkey; std::string name, description; char str[67], numstr[65]; + if (GetTransaction(tokenid, vintx, hashBlock, false) == 0) + { + fprintf(stderr, "cant find assetid\n"); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "cant find tokenid")); + return(result); + } + if (vintx.vout.size() > 0 && DecodeTokenCreateOpRet(vintx.vout[vintx.vout.size() - 1].scriptPubKey, origpubkey, name, description) == 0) + { + fprintf(stderr, "assetid isnt token creation txid\n"); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "assetid isnt token creation txid")); + } + result.push_back(Pair("result", "success")); + result.push_back(Pair("tokenid", uint256_str(str, tokenid))); + result.push_back(Pair("owner", pubkey33_str(str, origpubkey.data()))); + result.push_back(Pair("name", name)); + result.push_back(Pair("supply", vintx.vout[0].nValue)); + result.push_back(Pair("description", description)); + return(result); +} + +UniValue TokenList() +{ + UniValue result(UniValue::VARR); + std::vector > addressIndex; + struct CCcontract_info *cp, C; uint256 txid, hashBlock; + CTransaction vintx; std::vector origpubkey; + std::string name, description; char str[65]; + + cp = CCinit(&C, EVAL_TOKENS); + SetCCtxids(addressIndex, cp->normaladdr); + for (std::vector >::const_iterator it = addressIndex.begin(); it != addressIndex.end(); it++) + { + txid = it->first.txhash; + if (GetTransaction(txid, vintx, hashBlock, false) != 0) + { + if (vintx.vout.size() > 0 && DecodeTokenCreateOpRet(vintx.vout[vintx.vout.size() - 1].scriptPubKey, origpubkey, name, description) != 0) + { + result.push_back(uint256_str(str, txid)); + } + } + } + return(result); } \ No newline at end of file diff --git a/src/cc/CCtokens.h b/src/cc/CCtokens.h index 34223bc0b..e7bb62101 100644 --- a/src/cc/CCtokens.h +++ b/src/cc/CCtokens.h @@ -32,6 +32,10 @@ bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t std::string CreateToken(int64_t txfee, int64_t assetsupply, std::string name, std::string description); std::string TokenTransfer(int64_t txfee, uint256 assetid, std::vector destpubkey, int64_t total); +int64_t GetTokenBalance(CPubKey pk, uint256 tokenid); +UniValue TokenInfo(uint256 tokenid); +UniValue TokenList(); + //this is in CCinclude.h int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs); //this is in CCinclude.h uint8_t DecodeTokenCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index b39a19668..2cf195661 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6947,7 +6947,7 @@ UniValue tokenlist(const UniValue& params, bool fHelp) throw runtime_error("tokenlist\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - return(AssetList()); + return(TokenList()); } UniValue tokeninfo(const UniValue& params, bool fHelp) @@ -6958,7 +6958,7 @@ UniValue tokeninfo(const UniValue& params, bool fHelp) if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); tokenid = Parseuint256((char *)params[0].get_str().c_str()); - return(AssetInfo(tokenid)); + return(TokenInfo(tokenid)); } UniValue tokenorders(const UniValue& params, bool fHelp) @@ -6977,22 +6977,35 @@ UniValue tokenorders(const UniValue& params, bool fHelp) UniValue tokenbalance(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); char destaddr[64]; uint256 tokenid; uint64_t balance; std::vector pubkey; struct CCcontract_info *cp,C; + CCerror.clear(); + cp = CCinit(&C,EVAL_ASSETS); if ( fHelp || params.size() > 2 ) throw runtime_error("tokenbalance tokenid [pubkey]\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - LOCK(cs_main); + + LOCK(cs_main); + tokenid = Parseuint256((char *)params[0].get_str().c_str()); if ( params.size() == 2 ) pubkey = ParseHex(params[1].get_str().c_str()); - else pubkey = Mypubkey(); + else + pubkey = Mypubkey(); result.push_back(Pair("result", "success")); - if ( GetCCaddress(cp,destaddr,pubkey2pk(pubkey)) != 0 ) + if (GetCCaddress(cp,destaddr,pubkey2pk(pubkey)) != 0) result.push_back(Pair("CCaddress",destaddr)); - balance = GetAssetBalance(pubkey2pk(pubkey),tokenid); - result.push_back(Pair("tokenid", params[0].get_str())); - result.push_back(Pair("balance", (int64_t)balance)); + + balance = GetTokenBalance(pubkey2pk(pubkey),tokenid); + + if (CCerror.empty()) { + result.push_back(Pair("tokenid", params[0].get_str())); + result.push_back(Pair("balance", (int64_t)balance)); + } + else { + ERR_RESULT(CCerror); + } + return(result); } From 15c71c69f1bb0351992a983cb0aa770ee2361f71 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 12 Jan 2019 15:30:21 +0500 Subject: [PATCH 384/643] corrected GetCCaddress call in get TokenBalance --- src/wallet/rpcwallet.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 2cf195661..847ddd921 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6976,7 +6976,7 @@ UniValue tokenorders(const UniValue& params, bool fHelp) UniValue tokenbalance(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); char destaddr[64]; uint256 tokenid; uint64_t balance; std::vector pubkey; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ); uint256 tokenid; uint64_t balance; std::vector pubkey; struct CCcontract_info *cp,C; CCerror.clear(); cp = CCinit(&C,EVAL_ASSETS); @@ -6992,13 +6992,17 @@ UniValue tokenbalance(const UniValue& params, bool fHelp) pubkey = ParseHex(params[1].get_str().c_str()); else pubkey = Mypubkey(); - result.push_back(Pair("result", "success")); - if (GetCCaddress(cp,destaddr,pubkey2pk(pubkey)) != 0) - result.push_back(Pair("CCaddress",destaddr)); balance = GetTokenBalance(pubkey2pk(pubkey),tokenid); if (CCerror.empty()) { + char destaddr[64]; + + result.push_back(Pair("result", "success")); + + if (GetCCaddress(cp, destaddr, pubkey2pk(pubkey)) != 0) + result.push_back(Pair("CCaddress", destaddr)); + result.push_back(Pair("tokenid", params[0].get_str())); result.push_back(Pair("balance", (int64_t)balance)); } From 0d6eb9853a4a8c2a1262cdc669ad2129e9f907d0 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 12 Jan 2019 15:48:45 +0500 Subject: [PATCH 385/643] added logging to IsTokenVout --- src/cc/CCtokens.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 613d4452f..167a0a241 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -366,9 +366,9 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c // moved opret checking to this new reusable func (dimxy): std::vector voutPubkeys; const uint8_t funcId = ValidateTokenOpret(tx, v, reftokenid, voutPubkeys, vopretExtra); - //std::cerr << indentStr << "IsTokensvout() ValidateTokenOpret returned=" << std::boolalpha << valOpret << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; + std::cerr << indentStr << "IsTokensvout() ValidateTokenOpret returned=" << funcId << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; if (funcId != 0) { - //std::cerr << indentStr << "IsTokensvout() ValidateTokenOpret returned true" << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; + std::cerr << indentStr << "IsTokensvout() ValidateTokenOpret returned not-null" << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; if (checkPubkeys && funcId != 'c') { // verify that the vout is token's (for 'c' there is no pubkeys!): @@ -391,7 +391,7 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c testVout = MakeTokensCC1of2vout(evalCodeInOpret, tx.vout[v].nValue, voutPubkeys[0], voutPubkeys[1]); if (tx.vout[v].scriptPubKey == testVout.scriptPubKey) { - //std::cerr << indentStr << "IsTokensvout() vout is EVAL_TOKENS, returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; + std::cerr << indentStr << "IsTokensvout() vout is EVAL_TOKENS, returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; return tx.vout[v].nValue; } } @@ -401,12 +401,13 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c CTxOut testVout = MakeTokensCC1vout(evalCodeInOpret, tx.vout[v].nValue, *it); if (tx.vout[v].scriptPubKey == testVout.scriptPubKey) { - //std::cerr << indentStr << "IsTokensvout() vout is EVAL_TOKENS change, returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; + std::cerr << indentStr << "IsTokensvout() vout is EVAL_TOKENS change, returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; return tx.vout[v].nValue; } } } else { + std::cerr << indentStr << "IsTokensvout() returns without pubkey check value=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; return tx.vout[v].nValue; } } From bfce0c18b87635acdf856f4274ce90910156b56c Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 12 Jan 2019 16:11:04 +0500 Subject: [PATCH 386/643] getMyEval() resurrection --- src/cc/CCtokens.cpp | 10 +++++----- src/cc/heir.cpp | 2 +- src/cc/heir_validate.h | 2 ++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 167a0a241..939f1e7d7 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -108,7 +108,7 @@ uint8_t DecodeTokenOpRet(const CScript scriptPubKey, uint8_t &evalCode, uint256 funcId = script[1]; //fprintf(stderr,"decode.[%c]\n",funcId); - switch ( funcId ) + switch( funcId ) { case 'c': return DecodeTokenCreateOpRet(scriptPubKey, dummyPubkey, dummyName, dummyDescription); @@ -366,7 +366,7 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c // moved opret checking to this new reusable func (dimxy): std::vector voutPubkeys; const uint8_t funcId = ValidateTokenOpret(tx, v, reftokenid, voutPubkeys, vopretExtra); - std::cerr << indentStr << "IsTokensvout() ValidateTokenOpret returned=" << funcId << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; + std::cerr << indentStr << "IsTokensvout() ValidateTokenOpret returned=" << (funcId?funcId:' ') << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; if (funcId != 0) { std::cerr << indentStr << "IsTokensvout() ValidateTokenOpret returned not-null" << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; @@ -490,7 +490,7 @@ bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t // add inputs from token cc addr int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs) { - char coinaddr[64], destaddr[64]; + char tokenaddr[64], destaddr[64]; int64_t threshold, nValue, price, totalinputs = 0; uint256 txid, hashBlock; std::vector vopretExtra; @@ -498,8 +498,8 @@ int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, C int32_t j, vout, n = 0; std::vector > unspentOutputs; - GetCCaddress(cp, coinaddr, pk); - SetCCunspents(unspentOutputs, coinaddr); + GetTokensCCaddress(cp, tokenaddr, pk); + SetCCunspents(unspentOutputs, tokenaddr); threshold = total / (maxinputs != 0 ? maxinputs : 64); // TODO: is maxinputs really could not be over 64? what if i want to calc total balance? diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 784e0a88c..5e9eb4362 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -725,7 +725,7 @@ template std::string HeirFund(uint64_t txfee, int64_t amount, CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); struct CCcontract_info *cp, C; - cp = CCinit(&C, EVAL_HEIR); + cp = CCinit(&C, Helper::getMyEval()); if (txfee == 0) txfee = 10000; diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index 0094f5f4c..88d1d2745 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -29,6 +29,7 @@ inline static bool isSpendingTx(uint8_t funcid) { return (funcid == 'C'); } class CoinHelper { public: + static uint8_t getMyEval() { return EVAL_HEIR; } static int64_t addOwnerInputs(struct CCcontract_info* cp, uint256 dummyid, CMutableTransaction& mtx, CPubKey ownerPubkey, int64_t total, int32_t maxinputs) { return AddNormalinputs(mtx, ownerPubkey, total, maxinputs); } @@ -62,6 +63,7 @@ public: // helper class to allow polymorphic behaviour for HeirXXX() functions in case of tokens class TokenHelper { public: + static uint8_t getMyEval() { return EVAL_TOKENS; } static int64_t addOwnerInputs(struct CCcontract_info* cp, uint256 tokenid, CMutableTransaction& mtx, CPubKey ownerPubkey, int64_t total, int32_t maxinputs) { return AddTokenCCInputs(cp, mtx, ownerPubkey, tokenid, total, maxinputs); } From 9f1c21c5b5729e3635cb221409e39da4d0a9210b Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 12 Jan 2019 16:14:31 +0500 Subject: [PATCH 387/643] corr tokenaddr name --- src/cc/CCtokens.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 939f1e7d7..bc28f62ad 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -518,7 +518,7 @@ int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, C if (GetTransaction(txid, vintx, hashBlock, false) != 0) { Getscriptaddress(destaddr, vintx.vout[vout].scriptPubKey); - if (strcmp(destaddr, coinaddr) != 0 && strcmp(destaddr, cp->unspendableCCaddr) != 0 && strcmp(destaddr, cp->unspendableaddr2) != 0) + if (strcmp(destaddr, tokenaddr) != 0 && strcmp(destaddr, cp->unspendableCCaddr) != 0 && strcmp(destaddr, cp->unspendableaddr2) != 0) continue; fprintf(stderr, "AddTokenCCInputs() check destaddress=%s vout amount=%.8f\n", destaddr, (double)vintx.vout[vout].nValue / COIN); From e1ddbcaf6c8b2ba00a8b824e34e534f50f3e8847 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 12 Jan 2019 16:23:41 +0500 Subject: [PATCH 388/643] corr else if in FinalizeCCtx --- src/cc/CCtokens.cpp | 2 +- src/cc/CCtx.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index bc28f62ad..266035e08 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -366,7 +366,7 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c // moved opret checking to this new reusable func (dimxy): std::vector voutPubkeys; const uint8_t funcId = ValidateTokenOpret(tx, v, reftokenid, voutPubkeys, vopretExtra); - std::cerr << indentStr << "IsTokensvout() ValidateTokenOpret returned=" << (funcId?funcId:' ') << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; + std::cerr << indentStr << "IsTokensvout() ValidateTokenOpret returned=" << (char)(funcId?funcId:' ') << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; if (funcId != 0) { std::cerr << indentStr << "IsTokensvout() ValidateTokenOpret returned not-null" << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index d85f59473..29e1fe0ab 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -138,16 +138,16 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran Getscriptaddress(destaddr,vintx.vout[utxovout].scriptPubKey); //fprintf(stderr,"FinalizeCCTx() vin.%d is CC %.8f -> (%s)\n",i,(double)utxovalues[i]/COIN,destaddr); std::cerr << "FinalizeCCtx() destaddr=" << destaddr << " myaddr=" << myaddr << std::endl; - if ( strcmp(destaddr,myaddr) == 0 ) + if( strcmp(destaddr,myaddr) == 0 ) { privkey = myprivkey; cond = mycond; } - if (strcmp(destaddr, mytokensaddr) == 0) // if this is TokensCC1vout + else if (strcmp(destaddr, mytokensaddr) == 0) // if this is TokensCC1vout { privkey = myprivkey; cond = mytokenscond; - //fprintf(stderr,"FinalizeCCTx() matched TokensCC1vout CC addr.(%s)\n",mytokensaddr); + fprintf(stderr,"FinalizeCCTx() matched TokensCC1vout CC addr.(%s)\n",mytokensaddr); } else if ( strcmp(destaddr,unspendable) == 0 ) { From 034198730a9dc9a02d5e946824813409df97bc7b Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 12 Jan 2019 16:44:49 +0500 Subject: [PATCH 389/643] changed vcontractOpret in IsTokensVout remove extra param from IsTokensVout --- src/cc/CCinclude.h | 2 +- src/cc/CCtokens.cpp | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 4b6b437b4..c42a4799e 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -155,7 +155,7 @@ uint256 OraclesBatontxid(uint256 oracletxid,CPubKey pk); //int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs); int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs); -int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 reftokenid, std::vector vinPubkeys); +int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, /*std::vector &origpubkey,*/ const CTransaction& tx, int32_t v, uint256 reftokenid, std::vector vinPubkeys); bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx); CScript EncodeAssetOpRet(uint8_t assetFuncId, uint256 tokenid, uint256 assetid2, int64_t price, std::vector voutPubkeys, std::vector origpubkey); diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 266035e08..aca45fb70 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -365,17 +365,17 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c // moved opret checking to this new reusable func (dimxy): std::vector voutPubkeys; - const uint8_t funcId = ValidateTokenOpret(tx, v, reftokenid, voutPubkeys, vopretExtra); + std::vector vcontractOpret; + const uint8_t funcId = ValidateTokenOpret(tx, v, reftokenid, voutPubkeys, vcontractOpret); std::cerr << indentStr << "IsTokensvout() ValidateTokenOpret returned=" << (char)(funcId?funcId:' ') << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; if (funcId != 0) { std::cerr << indentStr << "IsTokensvout() ValidateTokenOpret returned not-null" << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; if (checkPubkeys && funcId != 'c') { // verify that the vout is token's (for 'c' there is no pubkeys!): - CScript contractScript = CScript(vopretExtra); - std::vector vcontractOpret; + //CScript contractScript = CScript(vopretExtra); + //GetOpReturnData(contractScript, vcontractOpret); - GetOpReturnData(contractScript, vcontractOpret); if (vcontractOpret.size() == 0) { std::cerr << "IsTokensvout() empty contract opret" << std::endl; return 0; @@ -421,7 +421,11 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c // compares cc inputs vs cc outputs (to prevent feeding vouts from normal inputs) bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 tokenid) { - CTransaction vinTx; uint256 hashBlock, id, id2; int32_t flag; int64_t tokenoshis; std::vector tmporigpubkey; int64_t tmpprice; + CTransaction vinTx; + uint256 hashBlock; //, id, id2; + //int32_t flag; + int64_t tokenoshis; + // std::vector tmporigpubkey; int64_t tmpprice; std::vector vinPubkeys, vinPubkeysEmpty; int32_t numvins = tx.vin.size(); @@ -449,7 +453,7 @@ bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t tokenValIndentSize++; // validate vouts of vintx //std::cerr << indentStr << "TokenExactAmounts() check vin i=" << i << " nValue=" << vinTx.vout[tx.vin[i].prevout.n].nValue << std::endl; - tokenoshis = IsTokensvout(goDeeper, true, cpTokens, eval, tmporigpubkey, vinTx, tx.vin[i].prevout.n, tokenid, vinPubkeys); + tokenoshis = IsTokensvout(goDeeper, true, cpTokens, eval, /*tmporigpubkey,*/ vinTx, tx.vin[i].prevout.n, tokenid, vinPubkeys); tokenValIndentSize--; if (tokenoshis != 0) { @@ -464,9 +468,9 @@ bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t for (int32_t i = 0; i vopretExtra; + //std::vector vopretExtra; CTransaction vintx; int32_t j, vout, n = 0; std::vector > unspentOutputs; @@ -524,7 +528,7 @@ int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, C std::vector vinPubkeys; - if ((nValue = IsTokensvout(true, true/*<--add only checked uxtos */, cp, NULL, vopretExtra, vintx, vout, tokenid, vinPubkeys)) > 0 && myIsutxo_spentinmempool(txid, vout) == 0) + if ((nValue = IsTokensvout(true, true/*<--add only checked uxtos */, cp, NULL, /*vopretExtra,*/ vintx, vout, tokenid, vinPubkeys)) > 0 && myIsutxo_spentinmempool(txid, vout) == 0) { if (total != 0 && maxinputs != 0) mtx.vin.push_back(CTxIn(txid, vout, CScript())); From bdc2915f16d07b7e8fe28cc7f9810402078b646f Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 12 Jan 2019 16:53:14 +0500 Subject: [PATCH 390/643] corrected call to IsTokensVout --- src/cc/CCassetsCore.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index 67e23837f..72404878d 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -573,7 +573,9 @@ bool AssetExactAmounts(struct CCcontract_info *cpAssets, int64_t &inputs, int64_ //assetoshis = IsAssetvout(cpAssets, tmpprice, tmporigpubkey, vinTx, tx.vin[i].prevout.n, assetid); std::vector vopretExtra; std::vector vinPubkeysEmpty; - assetoshis = IsTokensvout(false, false, cpTokens, NULL, vopretExtra, vinTx, tx.vin[i].prevout.n, assetid, vinPubkeysEmpty); + + // TODO: why is IsTokensVout here?? + assetoshis = IsTokensvout(false, false, cpTokens, NULL, /* vopretExtra,*/ vinTx, tx.vin[i].prevout.n, assetid, vinPubkeysEmpty); if (assetoshis != 0) { std::cerr << "AssetExactAmounts() vin i=" << i << " assetoshis=" << assetoshis << std::endl; From d2119d8c45ddf893e502672327f0e255a404a035 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 12 Jan 2019 17:05:47 +0500 Subject: [PATCH 391/643] corr IsTokensVout def - extra param --- src/cc/CCtokens.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index aca45fb70..833797417 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -325,7 +325,7 @@ uint8_t ValidateTokenOpret(CTransaction tx, int32_t v, uint256 tokenid, std::vec // goDeeper is true: the func also validates amounts of the passed transaction: // it should be either sum(cc vins) == sum(cc vouts) or the transaction is the 'tokenbase' ('c') tx // checkPubkeys is true: validates if the vout is token vout1 or token vout1of2. Should always be true! -int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, std::vector &vopretExtra, const CTransaction& tx, int32_t v, uint256 reftokenid, std::vector vinPubkeys) +int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, /*std::vector &vopretExtra,*/ const CTransaction& tx, int32_t v, uint256 reftokenid, std::vector vinPubkeys) { // this is just for log messages indentation fur debugging recursive calls: From 46d9219e2152beb3749dc199eb1fa4139a97dcc4 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 12 Jan 2019 23:49:24 +0500 Subject: [PATCH 392/643] added second opret logging into IsTokenVout --- src/cc/CCtokens.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 833797417..f5716d866 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -365,7 +365,7 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c // moved opret checking to this new reusable func (dimxy): std::vector voutPubkeys; - std::vector vcontractOpret; + std::vector vcontractOpret, vcontractOpret2; const uint8_t funcId = ValidateTokenOpret(tx, v, reftokenid, voutPubkeys, vcontractOpret); std::cerr << indentStr << "IsTokensvout() ValidateTokenOpret returned=" << (char)(funcId?funcId:' ') << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; if (funcId != 0) { @@ -373,15 +373,18 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c if (checkPubkeys && funcId != 'c') { // verify that the vout is token's (for 'c' there is no pubkeys!): - //CScript contractScript = CScript(vopretExtra); - //GetOpReturnData(contractScript, vcontractOpret); + CScript contractScript = CScript(vcontractOpret); + GetOpReturnData(contractScript, vcontractOpret2); - if (vcontractOpret.size() == 0) { + std::cerr << "IsTokensvout() vcontractOpret=" << HexStr( vcontractOpret ); + std::cerr << "IsTokensvout() vcontractOpret2=" << HexStr(vcontractOpret2); + + if (vcontractOpret2.size() == 0) { std::cerr << "IsTokensvout() empty contract opret" << std::endl; return 0; } - uint8_t evalCodeInOpret = vcontractOpret.begin()[0]; + uint8_t evalCodeInOpret = vcontractOpret2.begin()[0]; if (voutPubkeys.size() >= 1 && voutPubkeys.size() <= 2) { CTxOut testVout; From d6214fc9941848f768caac673e8f2ec4983ea727 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sun, 13 Jan 2019 00:12:23 +0500 Subject: [PATCH 393/643] corr second opret building/parsing --- src/cc/CCtokens.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index f5716d866..98199687f 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -62,14 +62,16 @@ CScript EncodeTokenOpRet(uint8_t tokenFuncId, uint8_t evalCodeInOpret, uint256 t tokenid = revuint256(tokenid); //uint8_t tokenFuncId = (isTransferrable) ? (uint8_t)'t' : (uint8_t)'l'; - std::vector vpayload; - GetOpReturnData(payload, vpayload); + //std::vector vpayload; + //GetOpReturnData(payload, vpayload); //opret << OP_RETURN << E_MARSHAL(ss << evalCodeInOpret << tokenFuncId << tokenid << payload); opret << OP_RETURN << E_MARSHAL(ss << evalCodeInOpret << tokenFuncId << tokenid << ccType; \ - if(ccType >= 1) ss << voutPubkeys[0]; \ - if(ccType == 2) ss << voutPubkeys[1]; \ - if(payload.size() > 0) ss << vpayload); + if (ccType >= 1) ss << voutPubkeys[0]; \ + if (ccType == 2) ss << voutPubkeys[1];); + + if (payload.size() > 0) + opret << payload; return(opret); } @@ -365,26 +367,26 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c // moved opret checking to this new reusable func (dimxy): std::vector voutPubkeys; - std::vector vcontractOpret, vcontractOpret2; - const uint8_t funcId = ValidateTokenOpret(tx, v, reftokenid, voutPubkeys, vcontractOpret); + std::vector vopretExtra, vcontractOpret; + const uint8_t funcId = ValidateTokenOpret(tx, v, reftokenid, voutPubkeys, vopretExtra); std::cerr << indentStr << "IsTokensvout() ValidateTokenOpret returned=" << (char)(funcId?funcId:' ') << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; if (funcId != 0) { std::cerr << indentStr << "IsTokensvout() ValidateTokenOpret returned not-null" << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; if (checkPubkeys && funcId != 'c') { // verify that the vout is token's (for 'c' there is no pubkeys!): - CScript contractScript = CScript(vcontractOpret); - GetOpReturnData(contractScript, vcontractOpret2); + CScript contractScript = CScript(vopretExtra); + GetOpReturnData(contractScript, vcontractOpret); - std::cerr << "IsTokensvout() vcontractOpret=" << HexStr( vcontractOpret ); - std::cerr << "IsTokensvout() vcontractOpret2=" << HexStr(vcontractOpret2); + std::cerr << "IsTokensvout() vcontractOpret=" << HexStr(vopretExtra) << std::endl; + std::cerr << "IsTokensvout() vcontractOpret2=" << HexStr(vcontractOpret) << std::endl;; - if (vcontractOpret2.size() == 0) { + if (vcontractOpret.size() == 0) { std::cerr << "IsTokensvout() empty contract opret" << std::endl; return 0; } - uint8_t evalCodeInOpret = vcontractOpret2.begin()[0]; + uint8_t evalCodeInOpret = vcontractOpret.begin()[0]; if (voutPubkeys.size() >= 1 && voutPubkeys.size() <= 2) { CTxOut testVout; From c78b88725f5781f43a58b616326fef131db8aa66 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sun, 13 Jan 2019 00:17:33 +0500 Subject: [PATCH 394/643] corrected opret concat --- src/cc/CCtokens.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 98199687f..2944b6649 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -71,8 +71,8 @@ CScript EncodeTokenOpRet(uint8_t tokenFuncId, uint8_t evalCodeInOpret, uint256 t if (ccType == 2) ss << voutPubkeys[1];); if (payload.size() > 0) - opret << payload; - return(opret); + opret += payload; + return opret; } From fe0cc96584161585a737c2fd9799178f48e0776b Mon Sep 17 00:00:00 2001 From: dimxy Date: Sun, 13 Jan 2019 00:38:22 +0500 Subject: [PATCH 395/643] corr second opret building more --- src/cc/CCtokens.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 2944b6649..53f992520 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -62,16 +62,19 @@ CScript EncodeTokenOpRet(uint8_t tokenFuncId, uint8_t evalCodeInOpret, uint256 t tokenid = revuint256(tokenid); //uint8_t tokenFuncId = (isTransferrable) ? (uint8_t)'t' : (uint8_t)'l'; - //std::vector vpayload; - //GetOpReturnData(payload, vpayload); + std::vector vpayload; + GetOpReturnData(payload, vpayload); //opret << OP_RETURN << E_MARSHAL(ss << evalCodeInOpret << tokenFuncId << tokenid << payload); opret << OP_RETURN << E_MARSHAL(ss << evalCodeInOpret << tokenFuncId << tokenid << ccType; \ if (ccType >= 1) ss << voutPubkeys[0]; \ if (ccType == 2) ss << voutPubkeys[1];); - - if (payload.size() > 0) - opret += payload; + + //add second opret: + opret << OP_RETURN << E_MARSHAL(ss << vpayload); + +// if (payload.size() > 0) +// opret += payload; return opret; } From e24039f137c6934a4da5fcdfe7b09e0268d7434c Mon Sep 17 00:00:00 2001 From: dimxy Date: Sun, 13 Jan 2019 00:44:57 +0500 Subject: [PATCH 396/643] corr concat opret1+opret2 --- src/cc/CCtokens.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 53f992520..20d8fbe59 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -53,7 +53,7 @@ CScript EncodeTokenCreateOpRet(uint8_t funcid,std::vector origpubkey,st // this is for other contracts which use tokens and build customized extra payloads to token's opret: CScript EncodeTokenOpRet(uint8_t tokenFuncId, uint8_t evalCodeInOpret, uint256 tokenid, std::vector voutPubkeys, CScript payload) { - CScript opret; + CScript opret1, opret2; uint8_t ccType = 0; if (voutPubkeys.size() >= 1 && voutPubkeys.size() <= 2) ccType = voutPubkeys.size(); @@ -66,16 +66,16 @@ CScript EncodeTokenOpRet(uint8_t tokenFuncId, uint8_t evalCodeInOpret, uint256 t GetOpReturnData(payload, vpayload); //opret << OP_RETURN << E_MARSHAL(ss << evalCodeInOpret << tokenFuncId << tokenid << payload); - opret << OP_RETURN << E_MARSHAL(ss << evalCodeInOpret << tokenFuncId << tokenid << ccType; \ + opret1 << OP_RETURN << E_MARSHAL(ss << evalCodeInOpret << tokenFuncId << tokenid << ccType; \ if (ccType >= 1) ss << voutPubkeys[0]; \ if (ccType == 2) ss << voutPubkeys[1];); //add second opret: - opret << OP_RETURN << E_MARSHAL(ss << vpayload); + opret2 << OP_RETURN << E_MARSHAL(ss << vpayload); // if (payload.size() > 0) // opret += payload; - return opret; + return opret1 + opret2; } From 20bd5c88b72aa70fbda1f97e6ae27d40a8608d49 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sun, 13 Jan 2019 15:14:06 +0500 Subject: [PATCH 397/643] opret processing returned to the variant without OP_RETURN opcode (cause this caused validation err) --- src/cc/CCtokens.cpp | 46 ++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 20d8fbe59..63e2124ad 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -53,29 +53,32 @@ CScript EncodeTokenCreateOpRet(uint8_t funcid,std::vector origpubkey,st // this is for other contracts which use tokens and build customized extra payloads to token's opret: CScript EncodeTokenOpRet(uint8_t tokenFuncId, uint8_t evalCodeInOpret, uint256 tokenid, std::vector voutPubkeys, CScript payload) { - CScript opret1, opret2; + CScript opret; + + if (evalCodeInOpret != EVAL_TOKENS) { + std::cerr << "EncodeTokenOpRet() evalCode should be EVAL_TOKENS!" << std::endl; + return opret; // return empty + } + + tokenid = revuint256(tokenid); + uint8_t ccType = 0; if (voutPubkeys.size() >= 1 && voutPubkeys.size() <= 2) ccType = voutPubkeys.size(); - //uint8_t evalcode = EVAL_TOKENS; - tokenid = revuint256(tokenid); - //uint8_t tokenFuncId = (isTransferrable) ? (uint8_t)'t' : (uint8_t)'l'; - std::vector vpayload; GetOpReturnData(payload, vpayload); - //opret << OP_RETURN << E_MARSHAL(ss << evalCodeInOpret << tokenFuncId << tokenid << payload); - opret1 << OP_RETURN << E_MARSHAL(ss << evalCodeInOpret << tokenFuncId << tokenid << ccType; \ - if (ccType >= 1) ss << voutPubkeys[0]; \ - if (ccType == 2) ss << voutPubkeys[1];); + opret << OP_RETURN << E_MARSHAL(ss << evalCodeInOpret << tokenFuncId << tokenid << ccType; \ + if (ccType >= 1) ss << voutPubkeys[0]; \ + if (ccType == 2) ss << voutPubkeys[1]; \ + if (vpayload.size() > 0) ss << vpayload;); - //add second opret: - opret2 << OP_RETURN << E_MARSHAL(ss << vpayload); // if (payload.size() > 0) -// opret += payload; - return opret1 + opret2; +// opret += payload; --> "error 64: scriptpubkey" + + return opret; } @@ -370,7 +373,8 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c // moved opret checking to this new reusable func (dimxy): std::vector voutPubkeys; - std::vector vopretExtra, vcontractOpret; + std::vector vopretExtra; + //std::vector vcontractOpret; const uint8_t funcId = ValidateTokenOpret(tx, v, reftokenid, voutPubkeys, vopretExtra); std::cerr << indentStr << "IsTokensvout() ValidateTokenOpret returned=" << (char)(funcId?funcId:' ') << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; if (funcId != 0) { @@ -378,18 +382,18 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c if (checkPubkeys && funcId != 'c') { // verify that the vout is token's (for 'c' there is no pubkeys!): - CScript contractScript = CScript(vopretExtra); - GetOpReturnData(contractScript, vcontractOpret); + //CScript contractScript = CScript(vopretExtra); + //GetOpReturnData(contractScript, vcontractOpret); - std::cerr << "IsTokensvout() vcontractOpret=" << HexStr(vopretExtra) << std::endl; - std::cerr << "IsTokensvout() vcontractOpret2=" << HexStr(vcontractOpret) << std::endl;; + std::cerr << "IsTokensvout() vopretExtra=" << HexStr(vopretExtra) << std::endl; + //std::cerr << "IsTokensvout() vcontractOpret=" << HexStr(vcontractOpret) << std::endl;; - if (vcontractOpret.size() == 0) { - std::cerr << "IsTokensvout() empty contract opret" << std::endl; + if (vopretExtra.size() < 2 /*|| vopretExtra.size() != vopretExtra.begin()[0]*/) { + std::cerr << "IsTokensvout() empty or incorrect contract opret" << std::endl; return 0; } - uint8_t evalCodeInOpret = vcontractOpret.begin()[0]; + uint8_t evalCodeInOpret = vopretExtra.begin()[1]; if (voutPubkeys.size() >= 1 && voutPubkeys.size() <= 2) { CTxOut testVout; From 9edec18b96bb00667daafa0958e307e47c7e41f2 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sun, 13 Jan 2019 15:38:05 +0500 Subject: [PATCH 398/643] heirinfo logging enabled --- src/cc/heir.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 5e9eb4362..7ae5d0241 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -1061,7 +1061,7 @@ UniValue HeirInfo(uint256 fundingtxid) // get initial funding tx and set it as initial lasttx: if (myGetTransaction(fundingtxid, fundingtx, hashBlock) && fundingtx.vout.size()) { - const bool noLogging = true; + const bool noLogging = false; uint8_t evalCodeTokens = 0; std::vector voutPubkeys; std::vector vopretExtra; From 32469f37c1c40cb854248361cd474ea88a9c7269 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sun, 13 Jan 2019 16:47:28 +0500 Subject: [PATCH 399/643] Added DecodeHeirEitherOpret handy func corr serialization second opret via payload --- src/cc/CCtokens.cpp | 8 +-- src/cc/heir.cpp | 145 +++++++++++++++++------------------------ src/cc/heir_validate.h | 2 + 3 files changed, 65 insertions(+), 90 deletions(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 63e2124ad..553f61163 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -71,14 +71,14 @@ CScript EncodeTokenOpRet(uint8_t tokenFuncId, uint8_t evalCodeInOpret, uint256 t opret << OP_RETURN << E_MARSHAL(ss << evalCodeInOpret << tokenFuncId << tokenid << ccType; \ if (ccType >= 1) ss << voutPubkeys[0]; \ - if (ccType == 2) ss << voutPubkeys[1]; \ - if (vpayload.size() > 0) ss << vpayload;); + if (ccType == 2) ss << voutPubkeys[1];); // \ + //if (vpayload.size() > 0) ss << vpayload;); // if (payload.size() > 0) // opret += payload; --> "error 64: scriptpubkey" - - return opret; + // TODO: check or serialization to vpayload! + return opret + payload; } diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 7ae5d0241..4276fee16 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -322,60 +322,6 @@ CScript EncodeHeirOpRet(uint8_t funcid, uint256 fundingtxid, uint8_t hasHeirSpe return CScript() << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << fundingtxid << hasHeirSpendingBegun); } -/* -// makes opret for tokens while they are inside Heir contract address space - initial funding -CScript EncodeHeirTokensCreateOpRet(uint8_t heirFuncId, uint256 tokenid, std::vector voutPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string hearName) -{ - uint8_t evalcode = EVAL_HEIR; - uint8_t ccType = 0; - if (voutPubkeys.size() >= 1 && voutPubkeys.size() <= 2) - ccType = voutPubkeys.size(); - - tokenid = revuint256(tokenid); - return CScript() << OP_RETURN << - E_MARSHAL(ss << evalcode << (uint8_t)'t' << tokenid << ccType; \ - if (ccType >= 1) ss << voutPubkeys[0]; \ - if (ccType == 2) ss << voutPubkeys[1]; \ - ss << heirFuncId << ownerPubkey << heirPubkey << inactivityTimeSec << hearName); -} -// makes opret for tokens while they are inside Heir contract address space - additional funding -CScript EncodeHeirTokensOpRet(uint8_t heirFuncId, uint256 tokenid, std::vector voutPubkeys, uint256 fundingtxid, uint8_t hasHeirSpendingBegun) -{ - uint8_t evalcode = EVAL_HEIR; - uint8_t ccType = 0; - if (voutPubkeys.size() >= 1 && voutPubkeys.size() <= 2) - ccType = voutPubkeys.size(); - - tokenid = revuint256(tokenid); // for visualization in debug logs - fundingtxid = revuint256(fundingtxid); - return CScript() << OP_RETURN << - E_MARSHAL(ss << evalcode << (uint8_t)'t' << tokenid << ccType; \ - if (ccType >= 1) ss << voutPubkeys[0]; \ - if (ccType == 2) ss << voutPubkeys[1]; \ - ss << heirFuncId << fundingtxid << hasHeirSpendingBegun); -} -*/ - -// helper for decode heir opret payload -// NOTE: Heir for coins has the same opret as Heir for tokens -/*uint8_t _UnmarshalOpret(std::vector vopretExtra, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret, uint8_t &hasHeirSpendingBegun) { - uint8_t heirFuncId = 0; - hasHeirSpendingBegun = 0; - - bool result = E_UNMARSHAL(vopretExtra, { ss >> heirFuncId; \ - if( heirFuncId == 'F') { \ - ss >> ownerPubkey; ss >> heirPubkey; ss >> inactivityTime; ss >> heirName; \ - } else { \ - ss >> fundingTxidInOpret >> hasHeirSpendingBegun; \ - } \ - }); - - if (!result )// || assetFuncId != 't' -- any tx is ok) - return (uint8_t)0; - - return heirFuncId; -}*/ - /** * decode opret vout for Heir contract */ @@ -457,7 +403,47 @@ uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256& fundingtxidInOpret, uint8 return _DecodeHeirOpRet(scriptPubKey, dummyOwnerPubkey, dummyHeirPubkey, dummyInactivityTime, dummyHeirName, fundingtxidInOpret, hasHeirSpendingBegun, noLogging); } +// decode combined opret: +uint8_t _DecodeHeirEitherOpret(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging) +{ + uint8_t evalCodeTokens = 0; + std::vector voutPubkeys; + std::vector vopretExtra; + CScript heirScript = scriptPubKey; + int32_t heirType = HEIR_COINS; + + if (DecodeTokenOpRet(heirScript, evalCodeTokens, tokenid, voutPubkeys, vopretExtra) != 0) { + if (vopretExtra.size() > 1) { + // restore the second opret: + heirScript = CScript(); + std::vector vopretStripped = std::vector(vopretExtra.begin()+1, vopretExtra.end()); //strip string size + heirScript << OP_RETURN << E_MARSHAL(ss << vopretStripped); + heirType = HEIR_TOKENS; + } + else { + return (uint8_t)0; + } + } + return DecodeHeirOpRet(heirScript, ownerPubkey, heirPubkey, inactivityTime, heirName, noLogging); +} + +// overload to decode opret in fundingtxid: +uint8_t DecodeHeirEitherOpret(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging) { + uint256 dummyFundingTxidInOpret; + uint8_t dummyHasHeirSpendingBegun; + + return _DecodeHeirEitherOpret(scriptPubKey, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, dummyFundingTxidInOpret, dummyHasHeirSpendingBegun, noLogging); +} + +// overload to decode opret in A and C heir tx: +uint8_t DecodeHeirEitherOpret(CScript scriptPubKey, uint256 &tokenid, uint256 &fundingTxidInOpret, uint8_t hasHeirSpendingBegun, bool noLogging) { + CPubKey dummyOwnerPubkey, dummyHeirPubkey; + int64_t dummyInactivityTime; + std::string dummyHeirName; + + return _DecodeHeirEitherOpret(scriptPubKey, tokenid, dummyOwnerPubkey, dummyHeirPubkey, dummyInactivityTime, dummyHeirName, fundingTxidInOpret, hasHeirSpendingBegun, noLogging); +} /** * find the latest funding tx: it may be the first F tx or one of A or C tx's @@ -1042,14 +1028,6 @@ UniValue HeirInfo(uint256 fundingtxid) UniValue result(UniValue::VOBJ); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey ownerPubkey, heirPubkey; - uint256 latestFundingTxid; - uint256 dummyTokenid, tokenid; - - std::string heirName; - uint8_t funcId; - int64_t inactivityTimeSec; - CTransaction fundingtx; uint256 hashBlock; const bool allowSlow = false; @@ -1061,23 +1039,18 @@ UniValue HeirInfo(uint256 fundingtxid) // get initial funding tx and set it as initial lasttx: if (myGetTransaction(fundingtxid, fundingtx, hashBlock) && fundingtx.vout.size()) { + CPubKey ownerPubkey, heirPubkey; + uint256 latestFundingTxid; + uint256 dummyTokenid, tokenid = zeroid; + std::string heirName; + int64_t inactivityTimeSec; const bool noLogging = false; - uint8_t evalCodeTokens = 0; - std::vector voutPubkeys; - std::vector vopretExtra; - CScript heirScript = fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey; - int32_t heirType = HEIR_COINS; - uint8_t funcId = DecodeTokenOpRet(heirScript, evalCodeTokens, tokenid, voutPubkeys, vopretExtra); - if (funcId != 0) { - heirScript = CScript(vopretExtra); - heirType = HEIR_TOKENS; - } - funcId = DecodeHeirOpRet(heirScript, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, noLogging); - - if( funcId == 0 ) { - std::cerr << "HeirInfo() initial tx F not found for this fundingtx" << std::endl; + CScript opret = fundingtx.vout.size() > 0 ? fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey : CScript(); + uint8_t funcId = DecodeHeirEitherOpret(opret, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, noLogging); + if (funcId == 0) { + std::cerr << "HeirInfo() this fundingtx is incorrect" << std::endl; result.push_back(Pair("result", "error")); result.push_back(Pair("error", "initial tx F not found")); return result; @@ -1088,10 +1061,10 @@ UniValue HeirInfo(uint256 fundingtxid) uint8_t hasHeirSpendingBegun = 0; - if (heirType == HEIR_COINS) - latestFundingTxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); - else - latestFundingTxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + if (tokenid == zeroid) // coins + latestFundingTxid = FindLatestFundingTx(fundingtxid, funcId, dummyTokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + else // tokens + latestFundingTxid = FindLatestFundingTx(fundingtxid, funcId, dummyTokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); if (latestFundingTxid != zeroid) { int32_t numblocks; @@ -1105,7 +1078,7 @@ UniValue HeirInfo(uint256 fundingtxid) result.push_back(Pair("fundingtxid", fundingtxid.GetHex())); result.push_back(Pair("name", heirName.c_str())); - if (heirType == HEIR_TOKENS) { + if (tokenid != zeroid) { // tokens stream << tokenid.GetHex(); msg = "tokenid"; result.push_back(Pair(msg, stream.str().c_str())); @@ -1125,12 +1098,12 @@ UniValue HeirInfo(uint256 fundingtxid) stream.clear(); int64_t total; - if (heirType == HEIR_COINS) + if (tokenid != zeroid) total = LifetimeHeirContractFunds(cp, fundingtxid, ownerPubkey, heirPubkey); else total = LifetimeHeirContractFunds(cp, fundingtxid, ownerPubkey, heirPubkey); - if (heirType == HEIR_COINS) { + if (tokenid == zeroid) { msg = "funding total in coins"; stream << (double)total / COIN; } @@ -1143,12 +1116,12 @@ UniValue HeirInfo(uint256 fundingtxid) stream.clear(); int64_t inputs; - if (heirType == HEIR_COINS) + if (tokenid == zeroid) inputs = Add1of2AddressInputs(cp, fundingtxid, mtx, ownerPubkey, heirPubkey, 0, 60); //NOTE: amount = 0 means all unspent inputs else inputs = Add1of2AddressInputs(cp, fundingtxid, mtx, ownerPubkey, heirPubkey, 0, 60); - if (heirType == HEIR_COINS) { + if (tokenid == zeroid) { msg = "funding available in coins"; stream << (double)inputs / COIN; } @@ -1160,7 +1133,7 @@ UniValue HeirInfo(uint256 fundingtxid) stream.str(""); stream.clear(); - if (heirType == HEIR_TOKENS) { + if (tokenid != zeroid) { int64_t ownerInputs = TokenHelper::addOwnerInputs(cp, tokenid, mtx, ownerPubkey, 0, (int32_t)64); stream << ownerInputs; msg = "owner funding available in tokens"; diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index 88d1d2745..5f56514d5 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -20,6 +20,8 @@ CScript EncodeHeirOpRet(uint8_t funcid, uint256 fundingtxid, uint8_t isHeirSpen template uint256 FindLatestFundingTx(uint256 fundingtxid, uint256 &tokenid, CScript& opRetScript, uint8_t &isHeirSpendingBegan); uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256& fundingtxid, uint8_t &isHeirSpendingBegan, bool noLogging = false); uint8_t DecodeHeirOpRet(CScript scriptPubKey, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging = false); +uint8_t DecodeHeirEitherOpret(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging = false); +uint8_t DecodeHeirEitherOpret(CScript scriptPubKey, uint256 &tokenid, uint256 &fundingTxidInOpret, uint8_t hasHeirSpendingBegun, bool noLogging = false); inline static bool isMyFuncId(uint8_t funcid) { return IS_CHARINSTR(funcid, "FAC"); } inline static bool isSpendingTx(uint8_t funcid) { return (funcid == 'C'); } From 7b7b5bdbc0095f3a4f625a669412a0607d425f1e Mon Sep 17 00:00:00 2001 From: dimxy Date: Sun, 13 Jan 2019 17:09:11 +0500 Subject: [PATCH 400/643] corr encode token opret plus no opcode cscript --- src/cc/CCtokens.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 553f61163..abcae84cd 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -78,7 +78,9 @@ CScript EncodeTokenOpRet(uint8_t tokenFuncId, uint8_t evalCodeInOpret, uint256 t // if (payload.size() > 0) // opret += payload; --> "error 64: scriptpubkey" // TODO: check or serialization to vpayload! - return opret + payload; + CScript opretPayloadNoOpcode(vpayload); + + return opret + opretPayloadNoOpcode; } From 400b798cd242ec110a34a4e82597ba6896681509 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sun, 13 Jan 2019 17:41:41 +0500 Subject: [PATCH 401/643] try to add second opret w/o serialization --- src/cc/CCtokens.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index abcae84cd..917487bbe 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -71,16 +71,25 @@ CScript EncodeTokenOpRet(uint8_t tokenFuncId, uint8_t evalCodeInOpret, uint256 t opret << OP_RETURN << E_MARSHAL(ss << evalCodeInOpret << tokenFuncId << tokenid << ccType; \ if (ccType >= 1) ss << voutPubkeys[0]; \ - if (ccType == 2) ss << voutPubkeys[1];); // \ - //if (vpayload.size() > 0) ss << vpayload;); + if (ccType == 2) ss << voutPubkeys[1]; ); // \ + // if (vpayload.size() > 0) ss << vpayload;); -// if (payload.size() > 0) -// opret += payload; --> "error 64: scriptpubkey" - // TODO: check or serialization to vpayload! - CScript opretPayloadNoOpcode(vpayload); + // "error 64: scriptpubkey": + // if (payload.size() > 0) + // opret += payload; - return opret + opretPayloadNoOpcode; + // error 64: scriptpubkey: + // CScript opretPayloadNoOpcode(vpayload); + // return opret + opretPayloadNoOpcode; + + // how to attach payload without re-serialization: + opret.resize(opret.size() + vpayload.size()); + CScript::iterator it = opret.begin() + opret.size(); + for (int i = 0; i < vpayload.size(); i++) + *it = vpayload[i]; + + return opret; } From ab87b673eb692ea3ae897ca3902d28e21a4fd0e1 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sun, 13 Jan 2019 17:48:03 +0500 Subject: [PATCH 402/643] iterator increment corr --- src/cc/CCtokens.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 917487bbe..3bd94f19d 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -86,7 +86,7 @@ CScript EncodeTokenOpRet(uint8_t tokenFuncId, uint8_t evalCodeInOpret, uint256 t // how to attach payload without re-serialization: opret.resize(opret.size() + vpayload.size()); CScript::iterator it = opret.begin() + opret.size(); - for (int i = 0; i < vpayload.size(); i++) + for (int i = 0; i < vpayload.size(); i++, it++) *it = vpayload[i]; return opret; From 39731c231f9728311a4ac382461cd8a5fa363d68 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sun, 13 Jan 2019 18:06:41 +0500 Subject: [PATCH 403/643] try to construct secod opret w/o serialization --- src/cc/CCtokens.cpp | 13 +++++++------ src/cc/heir.cpp | 15 ++++++++++----- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 3bd94f19d..c759f3704 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -71,8 +71,8 @@ CScript EncodeTokenOpRet(uint8_t tokenFuncId, uint8_t evalCodeInOpret, uint256 t opret << OP_RETURN << E_MARSHAL(ss << evalCodeInOpret << tokenFuncId << tokenid << ccType; \ if (ccType >= 1) ss << voutPubkeys[0]; \ - if (ccType == 2) ss << voutPubkeys[1]; ); // \ - // if (vpayload.size() > 0) ss << vpayload;); + if (ccType == 2) ss << voutPubkeys[1]; \ + if (vpayload.size() > 0) ss << vpayload;); // "error 64: scriptpubkey": @@ -84,10 +84,11 @@ CScript EncodeTokenOpRet(uint8_t tokenFuncId, uint8_t evalCodeInOpret, uint256 t // return opret + opretPayloadNoOpcode; // how to attach payload without re-serialization: - opret.resize(opret.size() + vpayload.size()); - CScript::iterator it = opret.begin() + opret.size(); - for (int i = 0; i < vpayload.size(); i++, it++) - *it = vpayload[i]; + // sig_aborted: + // opret.resize(opret.size() + vpayload.size()); + // CScript::iterator it = opret.begin() + opret.size(); + // for (int i = 0; i < vpayload.size(); i++, it++) + // *it = vpayload[i]; return opret; } diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 4276fee16..bdc485c5d 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -408,18 +408,23 @@ uint8_t _DecodeHeirEitherOpret(CScript scriptPubKey, uint256 &tokenid, CPubKey& { uint8_t evalCodeTokens = 0; std::vector voutPubkeys; - std::vector vopretExtra; + std::vector vopretExtra, vopretStripped; CScript heirScript = scriptPubKey; - int32_t heirType = HEIR_COINS; if (DecodeTokenOpRet(heirScript, evalCodeTokens, tokenid, voutPubkeys, vopretExtra) != 0) { if (vopretExtra.size() > 1) { // restore the second opret: heirScript = CScript(); - std::vector vopretStripped = std::vector(vopretExtra.begin()+1, vopretExtra.end()); //strip string size - heirScript << OP_RETURN << E_MARSHAL(ss << vopretStripped); - heirType = HEIR_TOKENS; + + E_UNMARSHAL(vopretExtra, { ss >> vopretStripped; }); // std::vector(vopretExtra.begin()+1, vopretExtra.end()); //strip string size + + heirScript << OP_RETURN; + uint32_t i = heirScript.size(); + heirScript << E_MARSHAL(ss << vopretStripped); + for (uint32_t iStripped = 0; iStripped < vopretStripped.size(); iStripped++) + heirScript[i] = vopretStripped[iStripped]; + heirScript.resize(heirScript.size()-1); } else { return (uint8_t)0; From 97a030d05ad7f5b92c33fa621ffdb18ec2646ed4 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sun, 13 Jan 2019 22:38:33 +0500 Subject: [PATCH 404/643] corrected passing vopretStripped to DecodeHeirOpRet (instead CScript) --- src/cc/heir.cpp | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index bdc485c5d..b0272542c 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -322,22 +322,15 @@ CScript EncodeHeirOpRet(uint8_t funcid, uint256 fundingtxid, uint8_t hasHeirSpe return CScript() << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << fundingtxid << hasHeirSpendingBegun); } -/** -* decode opret vout for Heir contract -*/ -uint8_t _DecodeHeirOpRet(CScript scriptPubKey, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging) + +// decode opret vout for Heir contract +uint8_t _DecodeHeirOpRet(std::vector vopret, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging) { - std::vector vopret; uint8_t evalCodeInOpret = 0; uint8_t heirFuncId = 0; fundingTxidInOpret = zeroid; //to init - GetOpReturnData(scriptPubKey, vopret); - if (vopret.size() == 0) { - if (!noLogging) std::cerr << "_DecodeHeirOpRet() warning: empty opret" << std::endl; - return (uint8_t)0; - } evalCodeInOpret = vopret.begin()[0]; if (vopret.size() > 1 && evalCodeInOpret == EVAL_HEIR) { @@ -387,8 +380,14 @@ uint8_t DecodeHeirOpRet(CScript scriptPubKey, CPubKey& ownerPubkey, CPubKey& hei { uint256 dummytxid; uint8_t dummyHasHeirSpendingBegun; + std::vector vopret; - return _DecodeHeirOpRet(scriptPubKey, ownerPubkey, heirPubkey, inactivityTime, heirName, dummytxid, dummyHasHeirSpendingBegun, noLogging); + GetOpReturnData(scriptPubKey, vopret); + if (vopret.size() == 0) { + if (!noLogging) std::cerr << "DecodeHeirOpRet() warning: empty opret" << std::endl; + return (uint8_t)0; + } + return _DecodeHeirOpRet(vopret, ownerPubkey, heirPubkey, inactivityTime, heirName, dummytxid, dummyHasHeirSpendingBegun, noLogging); } /** @@ -399,8 +398,15 @@ uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256& fundingtxidInOpret, uint8 CPubKey dummyOwnerPubkey, dummyHeirPubkey; int64_t dummyInactivityTime; std::string dummyHeirName; + std::vector vopret; - return _DecodeHeirOpRet(scriptPubKey, dummyOwnerPubkey, dummyHeirPubkey, dummyInactivityTime, dummyHeirName, fundingtxidInOpret, hasHeirSpendingBegun, noLogging); + GetOpReturnData(scriptPubKey, vopret); + if (vopret.size() == 0) { + if (!noLogging) std::cerr << "DecodeHeirOpRet() warning: empty opret" << std::endl; + return (uint8_t)0; + } + + return _DecodeHeirOpRet(vopret, dummyOwnerPubkey, dummyHeirPubkey, dummyInactivityTime, dummyHeirName, fundingtxidInOpret, hasHeirSpendingBegun, noLogging); } // decode combined opret: @@ -417,20 +423,17 @@ uint8_t _DecodeHeirEitherOpret(CScript scriptPubKey, uint256 &tokenid, CPubKey& // restore the second opret: heirScript = CScript(); - E_UNMARSHAL(vopretExtra, { ss >> vopretStripped; }); // std::vector(vopretExtra.begin()+1, vopretExtra.end()); //strip string size - - heirScript << OP_RETURN; - uint32_t i = heirScript.size(); - heirScript << E_MARSHAL(ss << vopretStripped); - for (uint32_t iStripped = 0; iStripped < vopretStripped.size(); iStripped++) - heirScript[i] = vopretStripped[iStripped]; - heirScript.resize(heirScript.size()-1); + if (E_UNMARSHAL(vopretExtra, { ss >> vopretStripped; })) { //strip string size + if (!noLogging) std::cerr << "_DecodeHeirEitherOpret() could not unmarshal vopretStripped" << std::endl; + return (uint8_t)0; + } } else { + if (!noLogging) std::cerr << "_DecodeHeirEitherOpret() empty vopretExtra" << std::endl; return (uint8_t)0; } } - return DecodeHeirOpRet(heirScript, ownerPubkey, heirPubkey, inactivityTime, heirName, noLogging); + return _DecodeHeirOpRet(vopretStripped, ownerPubkey, heirPubkey, inactivityTime, heirName, fundingTxidInOpret, hasHeirSpendingBegun, noLogging); } // overload to decode opret in fundingtxid: From d41cd8b99178036aeca822a3bd2cfe143b94a593 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sun, 13 Jan 2019 23:07:31 +0500 Subject: [PATCH 405/643] corr unmarshal retcode proc in _DecodeHeirEitherOpRet GetTokenBalance returns error always, obsolete --- src/cc/CCtokens.cpp | 7 +++++-- src/cc/heir.cpp | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index c759f3704..70aa60d92 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -661,7 +661,10 @@ int64_t GetTokenBalance(CPubKey pk, uint256 tokenid) CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CTransaction tokentx; - if (GetTransaction(tokenid, tokentx, hashBlock, false) == 0) + CCerror = strprintf("obsolete, cannot return correct value without eval"); + return 0; + +/* if (GetTransaction(tokenid, tokentx, hashBlock, false) == 0) { fprintf(stderr, "cant find tokenid\n"); CCerror = strprintf("cant find tokenid"); @@ -670,7 +673,7 @@ int64_t GetTokenBalance(CPubKey pk, uint256 tokenid) struct CCcontract_info *cp, C; cp = CCinit(&C, EVAL_TOKENS); - return(AddTokenCCInputs(cp, mtx, pk, tokenid, 0, 0)); + return(AddTokenCCInputs(cp, mtx, pk, tokenid, 0, 0)); */ } UniValue TokenInfo(uint256 tokenid) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index b0272542c..1d74b4970 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -423,7 +423,7 @@ uint8_t _DecodeHeirEitherOpret(CScript scriptPubKey, uint256 &tokenid, CPubKey& // restore the second opret: heirScript = CScript(); - if (E_UNMARSHAL(vopretExtra, { ss >> vopretStripped; })) { //strip string size + if (!E_UNMARSHAL(vopretExtra, { ss >> vopretStripped; })) { //strip string size if (!noLogging) std::cerr << "_DecodeHeirEitherOpret() could not unmarshal vopretStripped" << std::endl; return (uint8_t)0; } From 1a5999e0bdd0aeda5d42e4e14d274d696b5cea28 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 14 Jan 2019 00:30:42 +0500 Subject: [PATCH 406/643] _DecodeHeirEitherOpRet corrected vopretStripped proc --- src/cc/heir.cpp | 84 ++++++++++++++----------------------------------- 1 file changed, 24 insertions(+), 60 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 1d74b4970..909d660d6 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -410,18 +410,15 @@ uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256& fundingtxidInOpret, uint8 } // decode combined opret: -uint8_t _DecodeHeirEitherOpret(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging) +uint8_t _DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging) { uint8_t evalCodeTokens = 0; - std::vector voutPubkeys; + std::vector voutPubkeysDummy; std::vector vopretExtra, vopretStripped; - CScript heirScript = scriptPubKey; - - if (DecodeTokenOpRet(heirScript, evalCodeTokens, tokenid, voutPubkeys, vopretExtra) != 0) { + if (DecodeTokenOpRet(scriptPubKey, evalCodeTokens, tokenid, voutPubkeysDummy, vopretExtra) != 0) { if (vopretExtra.size() > 1) { // restore the second opret: - heirScript = CScript(); if (!E_UNMARSHAL(vopretExtra, { ss >> vopretStripped; })) { //strip string size if (!noLogging) std::cerr << "_DecodeHeirEitherOpret() could not unmarshal vopretStripped" << std::endl; @@ -433,24 +430,28 @@ uint8_t _DecodeHeirEitherOpret(CScript scriptPubKey, uint256 &tokenid, CPubKey& return (uint8_t)0; } } + else + GetOpReturnData(scriptPubKey, vopretStripped); + return _DecodeHeirOpRet(vopretStripped, ownerPubkey, heirPubkey, inactivityTime, heirName, fundingTxidInOpret, hasHeirSpendingBegun, noLogging); + } // overload to decode opret in fundingtxid: -uint8_t DecodeHeirEitherOpret(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging) { +uint8_t DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging) { uint256 dummyFundingTxidInOpret; uint8_t dummyHasHeirSpendingBegun; - return _DecodeHeirEitherOpret(scriptPubKey, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, dummyFundingTxidInOpret, dummyHasHeirSpendingBegun, noLogging); + return _DecodeHeirEitherOpRet(scriptPubKey, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, dummyFundingTxidInOpret, dummyHasHeirSpendingBegun, noLogging); } // overload to decode opret in A and C heir tx: -uint8_t DecodeHeirEitherOpret(CScript scriptPubKey, uint256 &tokenid, uint256 &fundingTxidInOpret, uint8_t hasHeirSpendingBegun, bool noLogging) { +uint8_t DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, uint256 &fundingTxidInOpret, uint8_t hasHeirSpendingBegun, bool noLogging) { CPubKey dummyOwnerPubkey, dummyHeirPubkey; int64_t dummyInactivityTime; std::string dummyHeirName; - return _DecodeHeirEitherOpret(scriptPubKey, tokenid, dummyOwnerPubkey, dummyHeirPubkey, dummyInactivityTime, dummyHeirName, fundingTxidInOpret, hasHeirSpendingBegun, noLogging); + return _DecodeHeirEitherOpRet(scriptPubKey, tokenid, dummyOwnerPubkey, dummyHeirPubkey, dummyInactivityTime, dummyHeirName, fundingTxidInOpret, hasHeirSpendingBegun, noLogging); } /** @@ -472,22 +473,9 @@ template uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_ // get initial funding tx and set it as initial lasttx: if (myGetTransaction(fundingtxid, fundingtx, hashBlock) && fundingtx.vout.size()) { - uint256 dummytxid; - uint8_t evalCodeTokens = 0; - std::vector vopretExtra; - std::vector dummyVoutPubkeys; - - CScript heirScript = fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey; - if (typeid(Helper) == typeid(TokenHelper)) { - if (DecodeTokenOpRet(heirScript, evalCodeTokens, tokenid, dummyVoutPubkeys, vopretExtra) != 0) { - heirScript = CScript(vopretExtra); - } - else { - std::cerr << "FindLatestFundingTx() could not decode token opreturn for fundingtxid=" << fundingtxid.GetHex() << '\n'; - return zeroid; - } - } - funcId = DecodeHeirOpRet(heirScript, ownerPubkey, heirPubkey, inactivityTime, heirName); + CScript heirScript = (fundingtx.vout.size() > 0) ? fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey : CScript(); + + uint8_t funcId = DecodeHeirEitherOpRet(heirScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, true); if (funcId != 0) { // found at least funding tx! //std::cerr << "FindLatestFundingTx() lasttx currently is fundingtx, txid=" << fundingtxid.GetHex() << " opreturn type=" << (char)funcId << '\n'; @@ -522,48 +510,24 @@ template uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_ //std::cerr << "FindLatestFundingTx() checking unspents for txid=" << txid.GetHex() << '\n'; int32_t blockHeight = (int32_t)it->second.blockHeight; - uint256 fundingTxidInOpret; //NOTE: maybe called from validation code: if (myGetTransaction(txid, regtx, hash)) { //std::cerr << "FindLatestFundingTx() found tx for txid=" << txid.GetHex() << " blockHeight=" << blockHeight << " maxBlockHeight=" << maxBlockHeight << '\n'; - - /*{ // debug code: - uint256 debAssetid; - uint8_t debHasHeirSpendingBegun; - uint8_t debfuncid = DecodeHeirOpRet(regtx.vout[regtx.vout.size() - 1].scriptPubKey, debAssetid, fundingTxidInOpret, debHasHeirSpendingBegun, true); - - std::cerr << "FindLatestFundingTx() regtx.vout.size()=" << regtx.vout.size() << " funcId=" << (char)(debfuncid ? debfuncid : ' ') - << " tokenid=" << debAssetid.GetHex() << " fundingtxidInOpret=" << fundingTxidInOpret.GetHex() << " debHasHeirSpendingBegun=" << (int)debHasHeirSpendingBegun << std::endl; - }*/ - - uint256 dummyTokenid; // not to contaminate the tokenid from the params! + uint256 fundingTxidInOpret; + uint256 tokenidInOpret; // not to contaminate the tokenid from the params! uint8_t tmpFuncId; - uint8_t tmphasHeirSpendingBegun; + uint8_t hasHeirSpendingBegunInOpret; - uint8_t evalCodeTokens = 0; - std::vector vopretExtra; - std::vector dummyVoutPubkeys; - - CScript heirScript = regtx.vout[regtx.vout.size() - 1].scriptPubKey; - if (typeid(Helper) == typeid(TokenHelper)) { - if (DecodeTokenOpRet(heirScript, evalCodeTokens, tokenid, dummyVoutPubkeys, vopretExtra) != 0) { - heirScript = CScript(vopretExtra); - } - else { - std::cerr << "FindLatestFundingTx() could not decode token opreturn for fundingtxid=" << fundingtxid.GetHex() << '\n'; - return zeroid; - } - } - tmpFuncId = DecodeHeirOpRet(heirScript, fundingTxidInOpret, tmphasHeirSpendingBegun, true); - - if (regtx.vout.size() > 0 && tmpFuncId != 0 && fundingtxid == fundingTxidInOpret) { + CScript heirScript = (regtx.vout.size() > 0) ? regtx.vout[regtx.vout.size() - 1].scriptPubKey : CScript(); + tmpFuncId = DecodeHeirEitherOpRet(heirScript, tokenidInOpret, fundingTxidInOpret, hasHeirSpendingBegunInOpret, true); + if (tmpFuncId != 0 && fundingtxid == fundingTxidInOpret && (tokenid == zeroid || tokenid == tokenidInOpret)) { // check tokenid also if (blockHeight > maxBlockHeight) { maxBlockHeight = blockHeight; latesttxid = txid; funcId = tmpFuncId; - hasHeirSpendingBegun = tmphasHeirSpendingBegun; + hasHeirSpendingBegun = hasHeirSpendingBegunInOpret; //std::cerr << "FindLatestFundingTx() txid=" << latesttxid.GetHex() << " at blockHeight=" << maxBlockHeight // << " opreturn type=" << (char)(funcId ? funcId : ' ') << " hasHeirSpendingBegun=" << (int)hasHeirSpendingBegun << " - set as current lasttxid" << '\n'; @@ -1049,14 +1013,14 @@ UniValue HeirInfo(uint256 fundingtxid) CPubKey ownerPubkey, heirPubkey; uint256 latestFundingTxid; - uint256 dummyTokenid, tokenid = zeroid; + uint256 dummyTokenid, tokenid = zeroid; // important to clear tokenid std::string heirName; int64_t inactivityTimeSec; const bool noLogging = false; CScript opret = fundingtx.vout.size() > 0 ? fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey : CScript(); - uint8_t funcId = DecodeHeirEitherOpret(opret, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, noLogging); + uint8_t funcId = DecodeHeirEitherOpret(opret, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, true); if (funcId == 0) { std::cerr << "HeirInfo() this fundingtx is incorrect" << std::endl; result.push_back(Pair("result", "error")); @@ -1072,7 +1036,7 @@ UniValue HeirInfo(uint256 fundingtxid) if (tokenid == zeroid) // coins latestFundingTxid = FindLatestFundingTx(fundingtxid, funcId, dummyTokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); else // tokens - latestFundingTxid = FindLatestFundingTx(fundingtxid, funcId, dummyTokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + latestFundingTxid = FindLatestFundingTx(fundingtxid, funcId, tokenid /*<-verify for tokens*/, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); if (latestFundingTxid != zeroid) { int32_t numblocks; From 42a48b9653241c07e60d821f2e79e89ae1c0947f Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 14 Jan 2019 00:38:56 +0500 Subject: [PATCH 407/643] corrected call to DecodeHeirEitherOpRet in Heirinfo --- src/cc/heir.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 909d660d6..a895c9cc2 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -446,7 +446,7 @@ uint8_t DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& o } // overload to decode opret in A and C heir tx: -uint8_t DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, uint256 &fundingTxidInOpret, uint8_t hasHeirSpendingBegun, bool noLogging) { +uint8_t DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, uint256 &fundingTxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging) { CPubKey dummyOwnerPubkey, dummyHeirPubkey; int64_t dummyInactivityTime; std::string dummyHeirName; @@ -1020,7 +1020,7 @@ UniValue HeirInfo(uint256 fundingtxid) CScript opret = fundingtx.vout.size() > 0 ? fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey : CScript(); - uint8_t funcId = DecodeHeirEitherOpret(opret, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, true); + uint8_t funcId = DecodeHeirEitherOpRet(opret, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, true); if (funcId == 0) { std::cerr << "HeirInfo() this fundingtx is incorrect" << std::endl; result.push_back(Pair("result", "error")); From 5c35c03d60c68d9cb1db430c2f9492b4c537144d Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 14 Jan 2019 01:27:45 +0500 Subject: [PATCH 408/643] added isTokenVout call to Add1of2address func in heir.cpp corrected ExtractTokensVinPubkeys call -> in isTokensVout --- src/cc/CCtokens.cpp | 16 +++++++++++----- src/cc/heir.cpp | 16 +++++----------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 70aa60d92..9b110992b 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -262,14 +262,17 @@ bool TokensValidate(struct CCcontract_info *cp, Eval* eval, const CTransaction & // helper funcs: // extract my vins pubkeys: -bool ExtractVinPubkeys(struct CCcontract_info *cp, CTransaction tx, std::vector &vinPubkeys) { +bool ExtractTokensVinPubkeys(CTransaction tx, std::vector &vinPubkeys) { bool found = false; CPubKey pubkey; + struct CCcontract_info *cpTokens, tokensC; + + cpTokens = CCinit(&tokensC, EVAL_TOKENS); for (int32_t i = 0; i < tx.vin.size(); i++) { // check for additional contracts which may send tokens to the Tokens contract - if( (*cp->ismyvin)(tx.vin[i].scriptSig) ) + if( (*cpTokens->ismyvin)(tx.vin[i].scriptSig) ) { auto findEval = [](CC *cond, struct CCVisitor _) { @@ -345,7 +348,7 @@ uint8_t ValidateTokenOpret(CTransaction tx, int32_t v, uint256 tokenid, std::vec // goDeeper is true: the func also validates amounts of the passed transaction: // it should be either sum(cc vins) == sum(cc vouts) or the transaction is the 'tokenbase' ('c') tx // checkPubkeys is true: validates if the vout is token vout1 or token vout1of2. Should always be true! -int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, /*std::vector &vopretExtra,*/ const CTransaction& tx, int32_t v, uint256 reftokenid, std::vector vinPubkeys) +int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, /*std::vector &vopretExtra,*/ const CTransaction& tx, int32_t v, uint256 reftokenid, std::vector vinPubkeys000) { // this is just for log messages indentation fur debugging recursive calls: @@ -421,6 +424,9 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c } // maybe it is token change? + std::vector vinPubkeys; + ExtractTokensVinPubkeys(tx, vinPubkeys); + for(std::vector::iterator it = vinPubkeys.begin(); it != vinPubkeys.end(); it++) { CTxOut testVout = MakeTokensCC1vout(evalCodeInOpret, tx.vout[v].nValue, *it); @@ -450,7 +456,7 @@ bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t //int32_t flag; int64_t tokenoshis; // std::vector tmporigpubkey; int64_t tmpprice; - std::vector vinPubkeys, vinPubkeysEmpty; + std::vector vinPubkeys; int32_t numvins = tx.vin.size(); int32_t numvouts = tx.vout.size(); @@ -459,7 +465,7 @@ bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t // this is just for log messages indentation for debugging recursive calls: std::string indentStr = std::string().append(tokenValIndentSize, '.'); - ExtractVinPubkeys(cpTokens, tx, vinPubkeys); + ExtractTokensVinPubkeys(tx, vinPubkeys); for (int32_t i = 0; i int64_t Add1of2AddressInputs(struct CCcontract_info* cp, if (GetTransaction(txid, heirtx, hashBlock, false) != 0) { uint256 tokenid; uint256 fundingTxidInOpret; - uint8_t dummyHasHeirSpendingBegun; - uint8_t evalCodeTokens = 0; - std::vector vopretExtra; - std::vector voutPubkeys; + uint8_t hasHeirSpendingBegunDummy; + std::vector vinPubkeysEmpty; - CScript heirScript = heirtx.vout[heirtx.vout.size() - 1].scriptPubKey; - uint8_t funcId = DecodeTokenOpRet(heirScript, evalCodeTokens, tokenid, voutPubkeys, vopretExtra); - if (funcId != 0) { - heirScript = CScript(vopretExtra); - } - funcId = DecodeHeirOpRet(heirScript, fundingTxidInOpret, dummyHasHeirSpendingBegun, true); + CScript heirScript = (heirtx.vout.size() > 0) ? heirtx.vout[heirtx.vout.size() - 1].scriptPubKey : CScript(); + uint8_t funcId = DecodeHeirEitherOpRet(heirScript, tokenid, fundingTxidInOpret, hasHeirSpendingBegunDummy, false); if ((txid == fundingtxid || fundingTxidInOpret == fundingtxid) && funcId != 0 && isMyFuncId(funcId) && - // (typeid(Helper) == typeid(TokenHelper) && IsHeirvout(true, cp, nullptr, tokenid, vintx, voutIndex) > 0) && // deep validation for tokens - not used anymore + (typeid(Helper) == typeid(TokenHelper) && IsTokensvout(true, true, cp, nullptr, heirtx, voutIndex, tokenid, vinPubkeysEmpty) > 0) && // deep validation for tokens - not used anymore (voutValue = IsHeirFundingVout(cp, heirtx, voutIndex, ownerPubkey, heirPubkey)) > 0 && !myIsutxo_spentinmempool(txid, voutIndex)) { From dbae803774c362b6e1f903970aadbd8adb1844ed Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 14 Jan 2019 01:39:56 +0500 Subject: [PATCH 409/643] added loggin into isTokensVout --- src/cc/CCtokens.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 9b110992b..447bb96f6 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -353,7 +353,7 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c // this is just for log messages indentation fur debugging recursive calls: std::string indentStr = std::string().append(tokenValIndentSize, '.'); - //std::cerr << indentStr << "IsTokensvout() entered for txid=" << tx.GetHash().GetHex() << " v=" << v << " for tokenid=" << reftokenid.GetHex() << std::endl; + std::cerr << indentStr << "IsTokensvout() entered for txid=" << tx.GetHash().GetHex() << " v=" << v << " for tokenid=" << reftokenid.GetHex() << std::endl; //TODO: validate cc vouts are EVAL_TOKENS! @@ -456,7 +456,7 @@ bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t //int32_t flag; int64_t tokenoshis; // std::vector tmporigpubkey; int64_t tmpprice; - std::vector vinPubkeys; + std::vector vinPubkeys000; int32_t numvins = tx.vin.size(); int32_t numvouts = tx.vout.size(); @@ -465,7 +465,7 @@ bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t // this is just for log messages indentation for debugging recursive calls: std::string indentStr = std::string().append(tokenValIndentSize, '.'); - ExtractTokensVinPubkeys(tx, vinPubkeys); + //ExtractTokensVinPubkeys(tx, vinPubkeys); for (int32_t i = 0; iInvalid("always should find vin tx, but didnt"); - } else { tokenValIndentSize++; @@ -500,6 +501,7 @@ bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t tokenValIndentSize++; // Note: we pass in here 'false' because we don't need to call TokenExactAmounts() recursively from IsTokensvout // indeed, in this case we'll be checking this tx again + std::cerr << indentStr << "TokenExactAmounts() check vout i=" << i << " nValue=" << tx.vout[i].nValue << std::endl; tokenoshis = IsTokensvout(false, true /*<--exclude non-tokens vouts*/, cpTokens, eval,/* tmporigpubkey,*/ tx, i, tokenid, vinPubkeys000); tokenValIndentSize--; From d3c804c50c8e84e4ea1d1da0187f7a2272f09fe1 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 14 Jan 2019 13:10:18 +0500 Subject: [PATCH 411/643] corr DecodeHeirEitherOpRet call in LifeTimeHeirContractFund restores !ismempool.. check --- src/cc/heir.cpp | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index dff407aac..9b78f2584 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -593,14 +593,14 @@ template int64_t Add1of2AddressInputs(struct CCcontract_info* cp, uint8_t hasHeirSpendingBegunDummy; std::vector vinPubkeysEmpty; - CScript heirScript = (heirtx.vout.size() > 0) ? heirtx.vout[heirtx.vout.size() - 1].scriptPubKey : CScript(); + CScript heirScript = (heirtx.vout.size() > 0) ? heirtx.vout[heirtx.vout.size() - 1].scriptPubKey : CScript(); // check boundary uint8_t funcId = DecodeHeirEitherOpRet(heirScript, tokenid, fundingTxidInOpret, hasHeirSpendingBegunDummy, false); if ((txid == fundingtxid || fundingTxidInOpret == fundingtxid) && funcId != 0 && isMyFuncId(funcId) && - (typeid(Helper) == typeid(TokenHelper) && IsTokensvout(true, true, cp, nullptr, heirtx, voutIndex, tokenid, vinPubkeysEmpty) > 0) && // deep validation for tokens - not used anymore - (voutValue = IsHeirFundingVout(cp, heirtx, voutIndex, ownerPubkey, heirPubkey)) > 0 && + (typeid(Helper) != typeid(TokenHelper) || IsTokensvout(true, true, cp, nullptr, heirtx, voutIndex, tokenid, vinPubkeysEmpty) > 0) && // token validation logic + //(voutValue = IsHeirFundingVout(cp, heirtx, voutIndex, ownerPubkey, heirPubkey)) > 0 && // heir contract vout validation logic - not used since we moved to 2-eval vouts !myIsutxo_spentinmempool(txid, voutIndex)) { std::cerr << "Add1of2AddressInputs() voutValue=" << voutValue << " satoshis=" << it->second.satoshis << '\n'; @@ -633,28 +633,26 @@ template int64_t LifetimeHeirContractFunds(struct CCcontract_info for (std::vector>::const_iterator it = addressIndexes.begin(); it != addressIndexes.end(); it++) { uint256 hashBlock; uint256 txid = it->first.txhash; - CTransaction tx; + CTransaction heirtx; - if (GetTransaction(txid, tx, hashBlock, false) && tx.vout.size() > 0) { - uint8_t evalCodeTokens = 0; + // TODO: check all funding tx should contain unspendable markers + if (GetTransaction(txid, heirtx, hashBlock, false) && heirtx.vout.size() > 0) { uint256 tokenid; uint256 fundingTxidInOpret; - std::vector vopretExtra; - std::vector voutPubkeys; - uint8_t dummyHasHeirSpendingBegun; + uint8_t hasHeirSpendingBegunDummy; + std::vector vinPubkeysEmpty; const int32_t ivout = 0; - CScript heirScript = tx.vout[tx.vout.size() - 1].scriptPubKey; - uint8_t funcId = DecodeTokenOpRet(heirScript, evalCodeTokens, tokenid, voutPubkeys, vopretExtra); - if (funcId != 0) { - heirScript = CScript(vopretExtra); - } - funcId = DecodeHeirOpRet(heirScript, fundingTxidInOpret, dummyHasHeirSpendingBegun, true); + CScript heirScript = (heirtx.vout.size() > 0) ? heirtx.vout[heirtx.vout.size() - 1].scriptPubKey : CScript(); // check boundary + uint8_t funcId = DecodeHeirEitherOpRet(heirScript, tokenid, fundingTxidInOpret, hasHeirSpendingBegunDummy, false); //std::cerr << "LifetimeHeirContractFunds() found tx=" << txid.GetHex() << " vout[0].nValue=" << subtx.vout[ccVoutIdx].nValue << " opreturn=" << (char)funcId << '\n'; - if (funcId != 0 && (txid == fundingtxid || fundingTxidInOpret == fundingtxid) && isMyFuncId(funcId) && !isSpendingTx(funcId) - /* && !myIsutxo_spentinmempool(txid, ccVoutIdx) */) // include also tx in mempool + if (funcId != 0 && + (txid == fundingtxid || fundingTxidInOpret == fundingtxid) && + isMyFuncId(funcId) && !isSpendingTx(funcId) && + (typeid(Helper) != typeid(TokenHelper) || IsTokensvout(true, true, cp, nullptr, heirtx, ivout, tokenid, vinPubkeysEmpty) > 0) && + !myIsutxo_spentinmempool(txid, ivout)) // exclude tx in mempool { total += it->second; // dont do this: tx.vout[ivout].nValue; // in vin[0] always is the pay to 1of2 addr (funding or change) //std::cerr << "LifetimeHeirContractFunds() added tx=" << txid.GetHex() << " it->second=" << it->second << " vout[0].nValue=" << tx.vout[ivout].nValue << " opreturn=" << (char)funcId << '\n'; From 08c0a5a8c6238e2f6770b98bfa82ab2b64d73165 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 14 Jan 2019 13:23:08 +0500 Subject: [PATCH 412/643] corr "is token" check in HeirInfo --- src/cc/heir.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 9b78f2584..6fd98d545 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -603,7 +603,7 @@ template int64_t Add1of2AddressInputs(struct CCcontract_info* cp, //(voutValue = IsHeirFundingVout(cp, heirtx, voutIndex, ownerPubkey, heirPubkey)) > 0 && // heir contract vout validation logic - not used since we moved to 2-eval vouts !myIsutxo_spentinmempool(txid, voutIndex)) { - std::cerr << "Add1of2AddressInputs() voutValue=" << voutValue << " satoshis=" << it->second.satoshis << '\n'; + std::cerr << "Add1of2AddressInputs() satoshis=" << it->second.satoshis << std::endl; if (total != 0 && maxinputs != 0) mtx.vin.push_back(CTxIn(txid, voutIndex, CScript())); nValue = it->second.satoshis; @@ -1062,7 +1062,7 @@ UniValue HeirInfo(uint256 fundingtxid) stream.clear(); int64_t total; - if (tokenid != zeroid) + if (tokenid == zeroid) total = LifetimeHeirContractFunds(cp, fundingtxid, ownerPubkey, heirPubkey); else total = LifetimeHeirContractFunds(cp, fundingtxid, ownerPubkey, heirPubkey); From 1fb94e5a34c63ae306cc2741fe77a0314e03a9b8 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 14 Jan 2019 17:26:42 +0500 Subject: [PATCH 413/643] corr DecodeHeirEitherOpRet in validators added EVAL_TOKENS check in DecodeTokenOpRet --- src/cc/CCtokens.cpp | 3 ++ src/cc/heir.cpp | 100 ++++++++--------------------------------- src/cc/heir_validate.h | 94 +++++--------------------------------- 3 files changed, 33 insertions(+), 164 deletions(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index a95ef2dd8..242b0a38e 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -125,6 +125,9 @@ uint8_t DecodeTokenOpRet(const CScript scriptPubKey, uint8_t &evalCode, uint256 bool isEof = true; evalCode = script[0]; + if (evalCode != EVAL_TOKENS) + return (uint8_t)0; + funcId = script[1]; //fprintf(stderr,"decode.[%c]\n",funcId); diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 6fd98d545..c982fb193 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -125,23 +125,10 @@ bool HeirValidate(struct CCcontract_info* cpHeir, Eval* eval, const CTransaction uint256 fundingTxidInOpret = zeroid, latestTxid = zeroid, dummyTokenid, tokenid = zeroid; CScript fundingTxOpRetScript; - uint8_t hasHeirSpendingBegun = 0, dummyHasHeirSpendingBegun; + uint8_t hasHeirSpendingBegun = 0, hasHeirSpendingBegunDummy; - - uint8_t evalCodeTokens = 0; - std::vector voutPubkeys; - std::vector vopretExtra; - - CScript heirScript = tx.vout[tx.vout.size() - 1].scriptPubKey; - int32_t heirType = HEIR_COINS; - - uint8_t funcId = DecodeTokenOpRet(heirScript, evalCodeTokens, tokenid, voutPubkeys, vopretExtra); - if (funcId != 0) { - heirScript = CScript(vopretExtra); - heirType = HEIR_TOKENS; - } - funcId = DecodeHeirOpRet(heirScript, fundingTxidInOpret, dummyHasHeirSpendingBegun, true); - + CScript opret = (tx.vout.size() > 0) ? tx.vout[tx.vout.size() - 1].scriptPubKey : CScript(); // check boundary + uint8_t funcId = DecodeHeirEitherOpRet(opret, tokenid, fundingTxidInOpret, hasHeirSpendingBegunDummy, true); if (funcId == 0) return eval->Invalid("invalid opreturn format"); @@ -149,7 +136,7 @@ bool HeirValidate(struct CCcontract_info* cpHeir, Eval* eval, const CTransaction if (fundingTxidInOpret == zeroid) { return eval->Invalid("invalid tx opreturn format: no fundingtxid present"); } - if (heirType == HEIR_COINS) + if (tokenid == zeroid) latestTxid = FindLatestFundingTx(fundingTxidInOpret, dummyTokenid, fundingTxOpRetScript, hasHeirSpendingBegun); else latestTxid = FindLatestFundingTx(fundingTxidInOpret, tokenid, fundingTxOpRetScript, hasHeirSpendingBegun); @@ -159,7 +146,7 @@ bool HeirValidate(struct CCcontract_info* cpHeir, Eval* eval, const CTransaction } } else { - fundingTxOpRetScript = tx.vout[numvouts - 1].scriptPubKey; + fundingTxOpRetScript = opret; } std::cerr << "HeirValidate funcid=" << (char)funcId << " evalcode=" << (int)cpHeir->evalcode << std::endl; @@ -185,7 +172,7 @@ bool HeirValidate(struct CCcontract_info* cpHeir, Eval* eval, const CTransaction // vout.1: txfee for CC addr used as a marker // vout.2: normal change // vout.n-1: opreturn 't' tokenid 'F' ownerpk heirpk inactivitytime heirname tokenid - if (heirType == HEIR_TOKENS) + if (tokenid != zeroid) return RunValidationPlans(funcId, cpTokens, eval, tx, latestTxid, fundingTxOpRetScript, hasHeirSpendingBegun); else return eval->Invalid("unexpected HeirValidate for heirfund"); @@ -206,7 +193,7 @@ bool HeirValidate(struct CCcontract_info* cpHeir, Eval* eval, const CTransaction // vout.0: funding CC 1of2 addr for the owner and heir // vout.1: normal change // vout.n-1: opreturn 't' tokenid 'A' ownerpk heirpk inactivitytime fundingtx - if (heirType == HEIR_TOKENS) + if (tokenid != zeroid) return RunValidationPlans(funcId, cpTokens, eval, tx, latestTxid, fundingTxOpRetScript, hasHeirSpendingBegun); else return eval->Invalid("unexpected HeirValidate for heiradd"); @@ -230,7 +217,7 @@ bool HeirValidate(struct CCcontract_info* cpHeir, Eval* eval, const CTransaction // vout.1: change to CC 1of2 addr // vout.2: change to normal from txfee input if any // vout.n-1: opreturn 't' tokenid 'C' ownerpk heirpk inactivitytime fundingtx - if (heirType == HEIR_TOKENS) + if (tokenid != zeroid) return RunValidationPlans(funcId, cpTokens, eval, tx, latestTxid, fundingTxOpRetScript, hasHeirSpendingBegun); else return RunValidationPlans(funcId, cpHeir, eval, tx, latestTxid, fundingTxOpRetScript, hasHeirSpendingBegun); @@ -267,44 +254,6 @@ template int64_t IsHeirFundingVout(struct CCcontract_info* cp, co return (0); } -// not used -bool HeirExactAmounts(struct CCcontract_info* cp, Eval* eval, const CTransaction& tx, int32_t minage, uint64_t txfee) -{ - static uint256 zerohash; - CTransaction vinTx; - uint256 hashBlock, activehash; - int32_t i, numvins, numvouts; - int64_t inputs = 0, outputs = 0, assetoshis; - numvins = tx.vin.size(); - numvouts = tx.vout.size(); - for (i = 0; i < numvins; i++) { - //fprintf(stderr,"HeirExactAmounts() vini.%d\n",i); - if ((*cp->ismyvin)(tx.vin[i].scriptSig) != 0) { - //fprintf(stderr,"HeirExactAmounts() vini.%d check mempool\n",i); - if (eval->GetTxUnconfirmed(tx.vin[i].prevout.hash, vinTx, hashBlock) == 0) - return eval->Invalid("cant find vinTx"); - else { - //fprintf(stderr,"HeirExactAmounts() vini.%d check hash and vout\n",i); - if (hashBlock == zerohash) - return eval->Invalid("cant Heir from mempool"); - ////if ( (assetoshis= IsHeirCCvout(cp,vinTx,tx.vin[i].prevout.n)) != 0 ) - //// inputs += assetoshis; - } - } - } - for (i = 0; i < numvouts; i++) { - //fprintf(stderr,"i.%d of numvouts.%d\n",i,numvouts); - ////if ( (assetoshis= IsHeirvout(cp,tx,i)) != 0 ) - //// outputs += assetoshis; - } - if (inputs != outputs + txfee) { - fprintf(stderr, "HeirExactAmounts() inputs %llu vs outputs %llu\n", (long long)inputs, (long long)outputs); - return eval->Invalid("mismatched inputs != outputs + txfee"); - } - else - return (true); -} - // makes coin initial tx opret CScript EncodeHeirCreateOpRet(uint8_t funcid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName) { @@ -373,9 +322,8 @@ uint8_t _DecodeHeirOpRet(std::vector vopret, CPubKey& ownerPubkey, CPub return (uint8_t)0; } -/** -* overload for 'F' opret -*/ +/* not used, see DecodeHeirOpRet(vopret,...) +// overload for 'F' opret uint8_t DecodeHeirOpRet(CScript scriptPubKey, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging) { uint256 dummytxid; @@ -388,11 +336,11 @@ uint8_t DecodeHeirOpRet(CScript scriptPubKey, CPubKey& ownerPubkey, CPubKey& hei return (uint8_t)0; } return _DecodeHeirOpRet(vopret, ownerPubkey, heirPubkey, inactivityTime, heirName, dummytxid, dummyHasHeirSpendingBegun, noLogging); -} +}*/ -/** -* overload for A, C oprets and AddHeirContractInputs -*/ + +/* not used, see DecodeHeirOpRet(vopret,...) +// overload for A, C oprets and AddHeirContractInputs uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256& fundingtxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging) { CPubKey dummyOwnerPubkey, dummyHeirPubkey; @@ -407,7 +355,7 @@ uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256& fundingtxidInOpret, uint8 } return _DecodeHeirOpRet(vopret, dummyOwnerPubkey, dummyHeirPubkey, dummyInactivityTime, dummyHeirName, fundingtxidInOpret, hasHeirSpendingBegun, noLogging); -} +} */ // decode combined opret: uint8_t _DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging) @@ -473,8 +421,8 @@ template uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_ // get initial funding tx and set it as initial lasttx: if (myGetTransaction(fundingtxid, fundingtx, hashBlock) && fundingtx.vout.size()) { - CScript heirScript = (fundingtx.vout.size() > 0) ? fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey : CScript(); + CScript heirScript = (fundingtx.vout.size() > 0) ? fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey : CScript(); uint8_t funcId = DecodeHeirEitherOpRet(heirScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, true); if (funcId != 0) { // found at least funding tx! @@ -979,8 +927,6 @@ UniValue HeirClaimTokenCaller(uint256 fundingtxid, uint64_t txfee, int64_t amoun return HeirClaim(fundingtxid, txfee, amount); } - - /** * heirinfo rpc call implementation * returns some information about heir CC contract plan by a handle of initial fundingtxid: @@ -1160,23 +1106,15 @@ template void _HeirList(struct CCcontract_info *cp, UniValue &r //std::cerr << "HeirList() checking txid=" << txid.GetHex() << " vout=" << vout << '\n'; CTransaction fundingtx; - if (GetTransaction(txid, fundingtx, hashBlock, false) != 0 && (fundingtx.vout.size() - 1) > 0) { + if (GetTransaction(txid, fundingtx, hashBlock, false)) { CPubKey ownerPubkey, heirPubkey; std::string heirName; int64_t inactivityTimeSec; const bool noLogging = true; - - uint8_t evalCodeTokens = 0; uint256 tokenid; - std::vector vopretExtra; - std::vector voutPubkeys; - CScript heirScript = fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey; - uint8_t funcId = DecodeTokenOpRet(heirScript, evalCodeTokens, tokenid, voutPubkeys, vopretExtra); - if (funcId != 0) { - heirScript = CScript(vopretExtra); - } - funcId = DecodeHeirOpRet(heirScript, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, noLogging); + CScript opret = (fundingtx.vout.size() > 0) ? fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey : CScript(); + uint8_t funcId = DecodeHeirEitherOpRet(opret, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, true); // note: if it is not Heir token funcId would be equal to 0 if (funcId == 'F') { diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index 5f56514d5..2bcc96b9e 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -4,29 +4,21 @@ #include "CCinclude.h" #include "CCHeir.h" -#define NOT_HEIR (-1) -#define HEIR_COINS 1 -#define HEIR_TOKENS 2 #define IS_CHARINSTR(c, str) (std::string(str).find((char)(c)) != std::string::npos) - // makes coin initial tx opret CScript EncodeHeirCreateOpRet(uint8_t funcid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName); CScript EncodeHeirOpRet(uint8_t funcid, uint256 fundingtxid, uint8_t isHeirSpendingBegan); -// makes token opret -//CScript EncodeHeirTokensCreateOpRet(uint8_t funcid, uint256 tokenid, std::vector voutPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string hearName); -//CScript EncodeHeirTokensOpRet(uint8_t funcid, uint256 tokenid, std::vector voutPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan); template uint256 FindLatestFundingTx(uint256 fundingtxid, uint256 &tokenid, CScript& opRetScript, uint8_t &isHeirSpendingBegan); -uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256& fundingtxid, uint8_t &isHeirSpendingBegan, bool noLogging = false); -uint8_t DecodeHeirOpRet(CScript scriptPubKey, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging = false); -uint8_t DecodeHeirEitherOpret(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging = false); -uint8_t DecodeHeirEitherOpret(CScript scriptPubKey, uint256 &tokenid, uint256 &fundingTxidInOpret, uint8_t hasHeirSpendingBegun, bool noLogging = false); +//uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256& fundingtxid, uint8_t &isHeirSpendingBegan, bool noLogging = false); +//uint8_t DecodeHeirOpRet(CScript scriptPubKey, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging = false); +uint8_t DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging = false); +uint8_t DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, uint256 &fundingTxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging = false); inline static bool isMyFuncId(uint8_t funcid) { return IS_CHARINSTR(funcid, "FAC"); } inline static bool isSpendingTx(uint8_t funcid) { return (funcid == 'C'); } - // helper class to allow polymorphic behaviour for HeirXXX() functions in case of coins class CoinHelper { public: @@ -411,22 +403,7 @@ public: std::string heirName; uint256 tokenid; - uint8_t evalCodeTokens = 0; - std::vector vopretExtra; - std::vector dummyVoutPubkeys; - - CScript heirScript = m_fundingOpretScript; - if (typeid(Helper) == typeid(TokenHelper)) { - if (DecodeTokenOpRet(heirScript, evalCodeTokens, tokenid, dummyVoutPubkeys, vopretExtra) != 0) { - heirScript = CScript(vopretExtra); - } - else { - message = m_customMessage + std::string(" invalid token opreturn format"); - std::cerr << "CCC1of2AddressValidator::validateVout() exits with false: " << message << std::endl; - return false; - } - } - uint8_t funcId = DecodeHeirOpRet(heirScript, ownerPubkey, heirPubkey, inactivityTime, heirName, false); + uint8_t funcId = DecodeHeirEitherOpRet(m_fundingOpretScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, true); if (funcId == 0) { message = m_customMessage + std::string(" invalid opreturn format"); std::cerr << "CCC1of2AddressValidator::validateVout() exits with false: " << message << std::endl; @@ -481,28 +458,15 @@ public: ///std::cerr << "CMyPubkeyVoutValidator::validateVout() m_opRetScript=" << m_opRetScript.ToString() << std::endl; - uint8_t evalCodeTokens = 0; - std::vector vopretExtra; - std::vector dummyVoutPubkeys; - - CScript ownerScript; - CScript heirScript = m_fundingOpretScript; - if (typeid(Helper) == typeid(TokenHelper)) { - if (DecodeTokenOpRet(heirScript, evalCodeTokens, tokenid, dummyVoutPubkeys, vopretExtra) != 0) { - heirScript = CScript(vopretExtra); - } - else { - message = std::string("invalid token opreturn format"); - return false; - } - } // get both pubkeys: - uint8_t funcId = DecodeHeirOpRet(heirScript, ownerPubkey, heirPubkey, inactivityTime, heirName, false); + uint8_t funcId = DecodeHeirEitherOpRet(m_fundingOpretScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, true); if (funcId == 0) { message = std::string("invalid opreturn format"); return false; } + CScript ownerScript; + CScript heirScript; if (m_checkNormals) { ownerScript = CoinHelper::makeUserVout(vout.nValue, ownerPubkey).scriptPubKey; heirScript = CoinHelper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey; @@ -552,22 +516,8 @@ public: std::string heirName; uint256 tokenid; - uint8_t evalCodeTokens = 0; - std::vector vopretExtra; - std::vector dummyVoutPubkeys; - - CScript heirScript = m_fundingOpretScript; - if (typeid(Helper) == typeid(TokenHelper)) { - if (DecodeTokenOpRet(heirScript, evalCodeTokens, tokenid, dummyVoutPubkeys, vopretExtra) != 0) { - heirScript = CScript(vopretExtra); - } else { - message = std::string("invalid token opreturn format"); - return false; - } - } - // get heir pubkey: - uint8_t funcId = DecodeHeirOpRet(heirScript, ownerPubkey, heirPubkey, inactivityTime, heirName, false); + uint8_t funcId = DecodeHeirEitherOpRet(m_fundingOpretScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, true); if (funcId == 0) { message = std::string("invalid opreturn format"); return false; @@ -620,35 +570,13 @@ public: uint256 fundingTxidInOpret = zeroid, dummyTxid, tokenid = zeroid, initialTokenid = zeroid; uint8_t dummyIsHeirSpendingBegan; - uint8_t evalCodeTokens = 0; - std::vector vopretExtra; - std::vector dummyVoutPubkeys; - - CScript heirScript = vout.scriptPubKey; - if (typeid(Helper) == typeid(TokenHelper)) { - if (DecodeTokenOpRet(heirScript, evalCodeTokens, tokenid, dummyVoutPubkeys, vopretExtra) != 0) { - heirScript = CScript(vopretExtra); - } else { - message = std::string("invalid token opreturn format"); - return false; - } - } - uint8_t funcId = DecodeHeirOpRet(heirScript, fundingTxidInOpret, dummyIsHeirSpendingBegan); + uint8_t funcId = DecodeHeirEitherOpRet(vout.scriptPubKey, tokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan, true); if (funcId == 0) { message = std::string("invalid opreturn format"); return false; } - heirScript = m_fundingOpretScript; - if (typeid(Helper) == typeid(TokenHelper)) { - if (DecodeTokenOpRet(heirScript, evalCodeTokens, initialTokenid, dummyVoutPubkeys, vopretExtra) != 0) { - heirScript = CScript(vopretExtra); - } else { - message = std::string("invalid initial token opreturn format"); - return false; - } - } - uint8_t initialFuncId = DecodeHeirOpRet(heirScript, dummyTxid, dummyIsHeirSpendingBegan); + uint8_t initialFuncId = DecodeHeirEitherOpRet(m_fundingOpretScript, initialTokenid, dummyTxid, dummyIsHeirSpendingBegan, true); if (initialFuncId == 0) { message = std::string("invalid initial tx opreturn format"); return false; From fd0c4b89789cd99fc94b1e962291737607e4ef07 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 14 Jan 2019 21:42:37 +0500 Subject: [PATCH 414/643] corr CCinit in HeirAdd HeirClaim --- src/cc/heir.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index c982fb193..1ed652efd 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -640,12 +640,12 @@ template std::string HeirFund(uint64_t txfee, int64_t amount, int64_t inputs, change; if ((inputs=Helper::addOwnerInputs(cp, tokenid, mtx, myPubkey, amount, (int32_t)64)) > 0) { // 2 x txfee: 1st for marker vout, 2nd to miners - //mtx.vout.push_back(MakeCC1vout(EVAL_HEIR,amount,HeirCCpk)); - mtx.vout.push_back(MakeTokensCC1of2vout(/*Helper::getMyEval()*/EVAL_HEIR, amount, myPubkey, heirPubkey)); // add cryptocondition to spend amount for either pk + //mtx.vout.push_back(MakeTokensCC1of2vout(/*Helper::getMyEval()*/EVAL_HEIR, amount, myPubkey, heirPubkey)); // add cryptocondition to spend amount for either pk + mtx.vout.push_back(Helper::make1of2Vout(amount, myPubkey, heirPubkey)); // add a marker for finding all plans in HeirList() - CPubKey HeirContractPubKey = GetUnspendable(cp, 0); - mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(HeirContractPubKey)) << OP_CHECKSIG)); // TODO: do we need this marker? + CPubKey heirUnspendablePubKey = GetUnspendable(cp, 0); + mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(heirUnspendablePubKey)) << OP_CHECKSIG)); // TODO: do we need this marker? // calc and add change vout: if (inputs > amount) @@ -703,7 +703,7 @@ template UniValue HeirAdd(uint256 fundingtxid, uint64_t txfee, in uint8_t funcId; uint8_t hasHeirSpendingBegun = 0; - cp = CCinit(&C, EVAL_HEIR); + cp = CCinit(&C, Helper::getMyEval()); // for tokens shoud be EVAL_TOKENS to sign it correctly! if (txfee == 0) txfee = 10000; @@ -734,7 +734,7 @@ template UniValue HeirAdd(uint256 fundingtxid, uint64_t txfee, in std::cerr << "HeirAdd() adding markeraddr=" << markeraddr << '\n'; */ // add cryptocondition to spend this funded amount for either pk - mtx.vout.push_back(Helper::make1of2Vout(amount, ownerPubkey, heirPubkey)); // using always pubkeys from OP_RETURN in order to not mixing them up! + mtx.vout.push_back(Helper::make1of2Vout(amount, ownerPubkey, heirPubkey)); if (inputs > amount) change = (inputs - amount); // -txfee <-- txfee pays user @@ -807,8 +807,8 @@ template UniValue HeirClaim(uint256 fundingtxid, uint64_t txfee std::string heirName; uint8_t hasHeirSpendingBegun = 0; - cp = CCinit(&C, EVAL_HEIR); - if (txfee == 0) + cp = CCinit(&C, Helper::getMyEval()); + if (txfee == 0) txfee = 10000; if ((latesttxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun)) != zeroid) { @@ -882,11 +882,7 @@ template UniValue HeirClaim(uint256 fundingtxid, uint64_t txfee Helper::GetCoinsOrTokensCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); Myprivkey(myprivkey); - ////fprintf(stderr,"HeirClaim() before setting unspendable CC addr2= (%s) addr3= (%s)\n", cp->unspendableaddr2, cp->unspendableaddr3); - //CCaddr2set(cp, Helper::getMyEval(), ownerPubkey, myprivkey, coinaddr); - //CCaddr3set(cp, Helper::getMyEval(), heirPubkey, myprivkey, coinaddr); - ////fprintf(stderr, "HeirClaim() after setting unspendable CC addr2=(%s) addr3=(%s)\n", cp->unspendableaddr2, cp->unspendableaddr3); - + // set pubkeys for finding 1of2 cc in FinalizeCCtx to sign it: Helper::CCaddrCoinsOrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); // add 1of2 vout validation pubkeys (this is for tokens): From 99c5484b66643a047356df01ff1a36832b0f214f Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 14 Jan 2019 22:04:50 +0500 Subject: [PATCH 415/643] corr cp usage in helper funcs --- src/cc/heir.cpp | 18 +++++++++--------- src/cc/heir_validate.h | 32 +++++++++++++++++++++----------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 1ed652efd..97c89582f 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -517,7 +517,7 @@ template int64_t Add1of2AddressInputs(struct CCcontract_info* cp, std::vector> unspentOutputs; char coinaddr[64]; - Helper::GetCoinsOrTokensCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); // get address of cryptocondition '1 of 2 pubkeys' + Helper::GetCoinsOrTokensCCaddress1of2(coinaddr, ownerPubkey, heirPubkey); // get address of cryptocondition '1 of 2 pubkeys' SetCCunspents(unspentOutputs, coinaddr); // char markeraddr[64]; @@ -571,7 +571,7 @@ template int64_t Add1of2AddressInputs(struct CCcontract_info* cp, template int64_t LifetimeHeirContractFunds(struct CCcontract_info* cp, uint256 fundingtxid, CPubKey ownerPubkey, CPubKey heirPubkey) { char coinaddr[64]; - Helper::GetCoinsOrTokensCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); // get the address of cryptocondition '1 of 2 pubkeys' + Helper::GetCoinsOrTokensCCaddress1of2(coinaddr, ownerPubkey, heirPubkey); // get the address of cryptocondition '1 of 2 pubkeys' std::vector> addressIndexes; SetCCtxids(addressIndexes, coinaddr); @@ -639,7 +639,7 @@ template std::string HeirFund(uint64_t txfee, int64_t amount, if (AddNormalinputs(mtx, myPubkey, txfee, 3) > 0) { // txfee for miners int64_t inputs, change; - if ((inputs=Helper::addOwnerInputs(cp, tokenid, mtx, myPubkey, amount, (int32_t)64)) > 0) { // 2 x txfee: 1st for marker vout, 2nd to miners + if ((inputs=Helper::addOwnerInputs(tokenid, mtx, myPubkey, amount, (int32_t)64)) > 0) { // 2 x txfee: 1st for marker vout, 2nd to miners //mtx.vout.push_back(MakeTokensCC1of2vout(/*Helper::getMyEval()*/EVAL_HEIR, amount, myPubkey, heirPubkey)); // add cryptocondition to spend amount for either pk mtx.vout.push_back(Helper::make1of2Vout(amount, myPubkey, heirPubkey)); @@ -724,7 +724,7 @@ template UniValue HeirAdd(uint256 fundingtxid, uint64_t txfee, in int64_t inputs, change; - if ((inputs = Helper::addOwnerInputs(cp, tokenid, mtx, myPubkey, amount, 64)) > 0) { // TODO: why 64 max inputs? + if ((inputs = Helper::addOwnerInputs(tokenid, mtx, myPubkey, amount, 64)) > 0) { // TODO: why 64 max inputs? // we do not use markers anymore - storing data in opreturn is better // add marker vout: @@ -758,9 +758,9 @@ template UniValue HeirAdd(uint256 fundingtxid, uint64_t txfee, in result.push_back(Pair("hextx", rawhextx)); } else { - std::cerr << "HeirAdd cannot find owner inputs" << std::endl; + std::cerr << "HeirAdd cannot find owner cc inputs" << std::endl; result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "can't find owner inputs")); + result.push_back(Pair("error", "can't find owner cc inputs")); } } else { @@ -879,11 +879,11 @@ template UniValue HeirClaim(uint256 fundingtxid, uint64_t txfee uint8_t myprivkey[32]; char coinaddr[64]; // set priv key addresses in CC structure: - Helper::GetCoinsOrTokensCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); + Helper::GetCoinsOrTokensCCaddress1of2(coinaddr, ownerPubkey, heirPubkey); Myprivkey(myprivkey); // set pubkeys for finding 1of2 cc in FinalizeCCtx to sign it: - Helper::CCaddrCoinsOrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); + Helper::CCaddrCoinsOrTokens1of2set(ownerPubkey, heirPubkey, coinaddr); // add 1of2 vout validation pubkeys (this is for tokens): std::vector voutTokenPubkeys; @@ -1040,7 +1040,7 @@ UniValue HeirInfo(uint256 fundingtxid) stream.clear(); if (tokenid != zeroid) { - int64_t ownerInputs = TokenHelper::addOwnerInputs(cp, tokenid, mtx, ownerPubkey, 0, (int32_t)64); + int64_t ownerInputs = TokenHelper::addOwnerInputs(tokenid, mtx, ownerPubkey, 0, (int32_t)64); stream << ownerInputs; msg = "owner funding available in tokens"; result.push_back(Pair(msg, stream.str().c_str())); diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index 2bcc96b9e..8f08a1588 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -24,7 +24,7 @@ class CoinHelper { public: static uint8_t getMyEval() { return EVAL_HEIR; } - static int64_t addOwnerInputs(struct CCcontract_info* cp, uint256 dummyid, CMutableTransaction& mtx, CPubKey ownerPubkey, int64_t total, int32_t maxinputs) { + static int64_t addOwnerInputs(uint256 dummyid, CMutableTransaction& mtx, CPubKey ownerPubkey, int64_t total, int32_t maxinputs) { return AddNormalinputs(mtx, ownerPubkey, total, maxinputs); } @@ -46,11 +46,15 @@ public: static CTxOut makeClaimerVout(int64_t amount, CPubKey myPubkey) { return CTxOut(amount, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG); } - static bool GetCoinsOrTokensCCaddress1of2(struct CCcontract_info* cp, char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { - return GetCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); + static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { + struct CCcontract_info *cpHeir, heirC; + cpHeir = CCinit(&heirC, EVAL_HEIR); + return GetCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); } - static void CCaddrCoinsOrTokens1of2set(struct CCcontract_info* cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { - CCaddr1of2set(cp, ownerPubkey, heirPubkey, coinaddr); + static void CCaddrCoinsOrTokens1of2set(CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { + struct CCcontract_info *cpHeir, heirC; + cpHeir = CCinit(&heirC, EVAL_HEIR); + CCaddr1of2set(cpHeir, ownerPubkey, heirPubkey, coinaddr); } }; @@ -58,8 +62,10 @@ public: class TokenHelper { public: static uint8_t getMyEval() { return EVAL_TOKENS; } - static int64_t addOwnerInputs(struct CCcontract_info* cp, uint256 tokenid, CMutableTransaction& mtx, CPubKey ownerPubkey, int64_t total, int32_t maxinputs) { - return AddTokenCCInputs(cp, mtx, ownerPubkey, tokenid, total, maxinputs); + static int64_t addOwnerInputs(uint256 tokenid, CMutableTransaction& mtx, CPubKey ownerPubkey, int64_t total, int32_t maxinputs) { + struct CCcontract_info *cpHeir, heirC; + cpHeir = CCinit(&heirC, EVAL_HEIR); + return AddTokenCCInputs(cpHeir, mtx, ownerPubkey, tokenid, total, maxinputs); } static CScript makeCreateOpRet(uint256 tokenid, std::vector voutTokenPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName) { @@ -84,12 +90,16 @@ public: static CTxOut makeClaimerVout(int64_t amount, CPubKey myPubkey) { return MakeTokensCC1vout(EVAL_HEIR, amount, myPubkey); } - static bool GetCoinsOrTokensCCaddress1of2(struct CCcontract_info* cp, char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { - return GetTokensCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); + static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { + struct CCcontract_info *cpHeir, heirC; + cpHeir = CCinit(&heirC, EVAL_HEIR); + return GetTokensCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); } - static void CCaddrCoinsOrTokens1of2set(struct CCcontract_info* cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { - CCaddrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); + static void CCaddrCoinsOrTokens1of2set(CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { + struct CCcontract_info *cpHeir, heirC; + cpHeir = CCinit(&heirC, EVAL_HEIR); + CCaddrTokens1of2set(cpHeir, ownerPubkey, heirPubkey, coinaddr); } }; From 849d60f4d975b03641909489a0555f7771555d69 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 14 Jan 2019 22:11:24 +0500 Subject: [PATCH 416/643] eval changed back to EVAL_HEIR in CCinit in HeirAdd --- src/cc/heir.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 97c89582f..c87f8155d 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -437,6 +437,7 @@ template uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_ return zeroid; } + // TODO: correct cc addr: std::vector> unspentOutputs; struct CCcontract_info *cp, C; cp = CCinit(&C, EVAL_HEIR); @@ -703,7 +704,8 @@ template UniValue HeirAdd(uint256 fundingtxid, uint64_t txfee, in uint8_t funcId; uint8_t hasHeirSpendingBegun = 0; - cp = CCinit(&C, Helper::getMyEval()); // for tokens shoud be EVAL_TOKENS to sign it correctly! + //cp = CCinit(&C, Helper::getMyEval()); // for tokens shoud be EVAL_TOKENS to sign it correctly! + cp = CCinit(&C, EVAL_HEIR); // for tokens shoud be EVAL_TOKENS to sign it correctly! if (txfee == 0) txfee = 10000; From ec954480a871ce38801ad641d047764e51499c70 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 15 Jan 2019 11:59:53 +0500 Subject: [PATCH 417/643] added more variants checking vouts in IsTokenVout corr vouts1 in Heir.cpp to single-eval token changed result type for HeirFund --- src/cc/CCHeir.h | 4 +-- src/cc/CCinclude.h | 1 + src/cc/CCtokens.cpp | 66 ++++++++++++++++++++++++++++------------ src/cc/heir.cpp | 55 +++++++++++++++++++++++---------- src/cc/heir_validate.h | 24 +++++++-------- src/wallet/rpcwallet.cpp | 12 ++++---- 6 files changed, 106 insertions(+), 56 deletions(-) diff --git a/src/cc/CCHeir.h b/src/cc/CCHeir.h index 18d1f08bb..8399474a7 100644 --- a/src/cc/CCHeir.h +++ b/src/cc/CCHeir.h @@ -34,8 +34,8 @@ class TokenHelper; //template UniValue HeirAdd(uint256 fundingtxid, uint64_t txfee, int64_t amount); //template UniValue HeirClaim(uint256 fundingtxid, uint64_t txfee, int64_t nValue); -std::string HeirFundCoinCaller(uint64_t txfee, int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 assetid); -std::string HeirFundTokenCaller(uint64_t txfee, int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 assetid); +UniValue HeirFundCoinCaller(uint64_t txfee, int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 assetid); +UniValue HeirFundTokenCaller(uint64_t txfee, int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 assetid); UniValue HeirClaimCoinCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount); UniValue HeirClaimTokenCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount); UniValue HeirAddCoinCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount); diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index c42a4799e..14a500222 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -162,6 +162,7 @@ CScript EncodeAssetOpRet(uint8_t assetFuncId, uint256 tokenid, uint256 assetid2, bool DecodeAssetCreateOpRet(const CScript &scriptPubKey, std::vector &origpubkey, std::string &name, std::string &description); uint8_t DecodeAssetOpRet(const CScript &scriptPubKey, uint8_t &evalCodeInOpret, uint256 &tokenid, uint256 &assetid2, int64_t &price, std::vector &origpubkey); +CScript EncodeTokenOpRet(uint256 tokenid, std::vector voutPubkeys, CScript payload); CScript EncodeTokenOpRet(uint8_t tokenFuncId, uint8_t evalCodeInOpret, uint256 tokenid, std::vector voutPubkeys, CScript payload); uint8_t DecodeTokenCreateOpRet(const CScript &scriptPubKey, std::vector &origpubkey, std::string &name, std::string &description); uint8_t DecodeTokenOpRet(const CScript scriptPubKey, uint8_t &evalCode, uint256 &tokenid, std::vector &voutPubkeys, std::vector &vopretExtra); diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 242b0a38e..d1dcf0b1f 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -51,14 +51,11 @@ CScript EncodeTokenCreateOpRet(uint8_t funcid,std::vector origpubkey,st } // this is for other contracts which use tokens and build customized extra payloads to token's opret: -CScript EncodeTokenOpRet(uint8_t tokenFuncId, uint8_t evalCodeInOpret, uint256 tokenid, std::vector voutPubkeys, CScript payload) +CScript EncodeTokenOpRet(uint256 tokenid, std::vector voutPubkeys, CScript payload) { CScript opret; - - if (evalCodeInOpret != EVAL_TOKENS) { - std::cerr << "EncodeTokenOpRet() evalCode should be EVAL_TOKENS!" << std::endl; - return opret; // return empty - } + uint8_t tokenFuncId = 't'; + uint8_t evalCodeInOpret = EVAL_TOKENS; tokenid = revuint256(tokenid); @@ -93,6 +90,11 @@ CScript EncodeTokenOpRet(uint8_t tokenFuncId, uint8_t evalCodeInOpret, uint256 t return opret; } +// overload for compatibility +CScript EncodeTokenOpRet(uint8_t tokenFuncId, uint8_t evalCodeInOpret, uint256 tokenid, std::vector voutPubkeys, CScript payload) +{ + return EncodeTokenOpRet(tokenid, voutPubkeys, payload); +} uint8_t DecodeTokenCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description) { @@ -405,35 +407,59 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c std::cerr << "IsTokensvout() vopretExtra=" << HexStr(vopretExtra) << std::endl; //std::cerr << "IsTokensvout() vcontractOpret=" << HexStr(vcontractOpret) << std::endl;; - if (vopretExtra.size() < 2 /*|| vopretExtra.size() != vopretExtra.begin()[0]*/) { + uint8_t evalCodeInOpret; + if (vopretExtra.size() >= 2 /*|| vopretExtra.size() != vopretExtra.begin()[0] <-- shold we check this?*/) { std::cerr << "IsTokensvout() empty or incorrect contract opret" << std::endl; - return 0; + evalCodeInOpret = vopretExtra.begin()[1]; + } + else { + // if payload is empty maybe it is a claim to non-payload-one-token-eval vout? + evalCodeInOpret = EVAL_TOKENS; } - uint8_t evalCodeInOpret = vopretExtra.begin()[1]; - - if (voutPubkeys.size() >= 1 && voutPubkeys.size() <= 2) { - CTxOut testVout; + // maybe this is dual-eval 1 pubkey or 1of2 pubkey vout? + if (voutPubkeys.size() >= 1 && voutPubkeys.size() <= 2) { + CTxOut testDualVout; if (voutPubkeys.size() == 1) - testVout = MakeTokensCC1vout(evalCodeInOpret, tx.vout[v].nValue, voutPubkeys[0]); + testDualVout = MakeTokensCC1vout(evalCodeInOpret, tx.vout[v].nValue, voutPubkeys[0]); else // voutPubkeys.size() == 2 - testVout = MakeTokensCC1of2vout(evalCodeInOpret, tx.vout[v].nValue, voutPubkeys[0], voutPubkeys[1]); + testDualVout = MakeTokensCC1of2vout(evalCodeInOpret, tx.vout[v].nValue, voutPubkeys[0], voutPubkeys[1]); - if (tx.vout[v].scriptPubKey == testVout.scriptPubKey) { - std::cerr << indentStr << "IsTokensvout() vout is EVAL_TOKENS, returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; + if (tx.vout[v].scriptPubKey == testDualVout.scriptPubKey) { + if(voutPubkeys.size() == 1) + std::cerr << indentStr << "IsTokensvout() this is dual-eval token vout, eval2=" << evalCodeInOpret << ", returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; + else + std::cerr << indentStr << "IsTokensvout() this is dual-eval token 1of2 vout or change, eval2=" << evalCodeInOpret << ", returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; return tx.vout[v].nValue; } } - // maybe it is token change? + // maybe this is claim to single-eval token? + if (voutPubkeys.size() == 1) { + CTxOut testTokenVout1; + testTokenVout1 = MakeCC1vout(EVAL_TOKENS, tx.vout[v].nValue, voutPubkeys[0]); + + if (tx.vout[v].scriptPubKey == testTokenVout1.scriptPubKey) { + std::cerr << indentStr << "IsTokensvout() this is single-eval token vout, returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; + return tx.vout[v].nValue; + } + } + + // maybe it is single-eval or dual-eval token change? std::vector vinPubkeys; ExtractTokensVinPubkeys(tx, vinPubkeys); for(std::vector::iterator it = vinPubkeys.begin(); it != vinPubkeys.end(); it++) { - CTxOut testVout = MakeTokensCC1vout(evalCodeInOpret, tx.vout[v].nValue, *it); + CTxOut testTokenVout1 = MakeCC1vout(EVAL_TOKENS, tx.vout[v].nValue, *it); + CTxOut testDualVout1 = MakeTokensCC1vout(evalCodeInOpret, tx.vout[v].nValue, *it); - if (tx.vout[v].scriptPubKey == testVout.scriptPubKey) { - std::cerr << indentStr << "IsTokensvout() vout is EVAL_TOKENS change, returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; + if (tx.vout[v].scriptPubKey == testTokenVout1.scriptPubKey) { + std::cerr << indentStr << "IsTokensvout() this is single-eval token change, returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; + return tx.vout[v].nValue; + } + + if (tx.vout[v].scriptPubKey == testDualVout1.scriptPubKey) { + std::cerr << indentStr << "IsTokensvout() this is dual-eval token change, vout eval2=" << (int)evalCodeInOpret << ", returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; return tx.vout[v].nValue; } } diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index c87f8155d..a1f8adfd3 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -619,8 +619,9 @@ template int64_t LifetimeHeirContractFunds(struct CCcontract_info * and also for setting spending plan for the funds' owner and heir * @return fundingtxid handle for subsequent references to this heir funding plan */ -template std::string HeirFund(uint64_t txfee, int64_t amount, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid) +template UniValue HeirFund(uint64_t txfee, int64_t amount, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid) { + UniValue result(UniValue::VOBJ); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); struct CCcontract_info *cp, C; @@ -664,24 +665,38 @@ template std::string HeirFund(uint64_t txfee, int64_t amount, voutTokenPubkeys.push_back(heirPubkey); // add change for txfee and opreturn vouts and sign tx: - return (FinalizeCCTx(0, cp, mtx, myPubkey, txfee, - Helper::makeCreateOpRet(tokenid, voutTokenPubkeys, myPubkey, heirPubkey, inactivityTimeSec, heirName))); + std::string rawhextx = FinalizeCCTx(0, cp, mtx, myPubkey, txfee, + Helper::makeCreateOpRet(tokenid, voutTokenPubkeys, myPubkey, heirPubkey, inactivityTimeSec, heirName)); + if (!rawhextx.empty()) { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hextx", rawhextx)); + } + else { + std::cerr << "HeirAdd error in FinalizeCCtx" << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "sign error")); + } + } + else { // TODO: need result return unification with heiradd and claim + std::cerr << "HeirFund() could not find owner cc inputs" << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "could not find owner cc inputs")); } - else // TODO: need result return unification with heiradd and claim - std::cerr << "HeirFund() could not find owner inputs" << std::endl; - } - else + else { std::cerr << "HeirFund() could not find normal inputs" << std::endl; - return std::string(""); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "could not find normal inputs")); + } + return result; } // if no these callers - it could not link -std::string HeirFundCoinCaller(uint64_t txfee, int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid){ +UniValue HeirFundCoinCaller(uint64_t txfee, int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid){ return HeirFund(txfee, funds, heirName, heirPubkey, inactivityTimeSec, tokenid); } -std::string HeirFundTokenCaller(uint64_t txfee, int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid) { +UniValue HeirFundTokenCaller(uint64_t txfee, int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid) { return HeirFund(txfee, funds, heirName, heirPubkey, inactivityTimeSec, tokenid); } @@ -735,8 +750,8 @@ template UniValue HeirAdd(uint256 fundingtxid, uint64_t txfee, in mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(markerpubkey)) << OP_CHECKSIG)); // txfee 1, txfee 2 - for miners std::cerr << "HeirAdd() adding markeraddr=" << markeraddr << '\n'; */ - // add cryptocondition to spend this funded amount for either pk - mtx.vout.push_back(Helper::make1of2Vout(amount, ownerPubkey, heirPubkey)); + // add cryptocondition to spend this funded amount for either pk + mtx.vout.push_back(Helper::make1of2Vout(amount, ownerPubkey, heirPubkey)); if (inputs > amount) change = (inputs - amount); // -txfee <-- txfee pays user @@ -756,8 +771,16 @@ template UniValue HeirAdd(uint256 fundingtxid, uint64_t txfee, in std::string rawhextx = (FinalizeCCTx(0, cp, mtx, myPubkey, txfee, Helper::makeAddOpRet(tokenid, voutTokenPubkeys, fundingtxid, hasHeirSpendingBegun))); - result.push_back(Pair("result", "success")); - result.push_back(Pair("hextx", rawhextx)); + if (!rawhextx.empty()) { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hextx", rawhextx)); + } + else { + std::cerr << "HeirAdd error in FinalizeCCtx" << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "sign error")); + } + } else { std::cerr << "HeirAdd cannot find owner cc inputs" << std::endl; @@ -772,7 +795,7 @@ template UniValue HeirAdd(uint256 fundingtxid, uint64_t txfee, in } } else { - fprintf(stderr, "HeirAdd() can't find any heir CC funding tx's\n"); + fprintf(stderr, "HeirAdd can't find any heir CC funding tx's\n"); result.push_back(Pair("result", "error")); result.push_back(Pair("error", "can't find any heir CC funding transactions")); @@ -858,7 +881,7 @@ template UniValue HeirClaim(uint256 fundingtxid, uint64_t txfee }*/ // add vout with amount to claiming address - mtx.vout.push_back(Helper::makeClaimerVout(amount, myPubkey)); // vout[0] + mtx.vout.push_back(Helper::makeUserVout(amount, myPubkey)); // vout[0] // calc and add change vout: if (inputs > amount) diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index 8f08a1588..e9710a471 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -43,9 +43,9 @@ public: static CTxOut makeUserVout(int64_t amount, CPubKey myPubkey) { return CTxOut(amount, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG); } - static CTxOut makeClaimerVout(int64_t amount, CPubKey myPubkey) { +/* static CTxOut makeClaimerVout(int64_t amount, CPubKey myPubkey) { return CTxOut(amount, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG); - } + } */ static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { struct CCcontract_info *cpHeir, heirC; cpHeir = CCinit(&heirC, EVAL_HEIR); @@ -64,20 +64,20 @@ public: static uint8_t getMyEval() { return EVAL_TOKENS; } static int64_t addOwnerInputs(uint256 tokenid, CMutableTransaction& mtx, CPubKey ownerPubkey, int64_t total, int32_t maxinputs) { struct CCcontract_info *cpHeir, heirC; - cpHeir = CCinit(&heirC, EVAL_HEIR); + cpHeir = CCinit(&heirC, EVAL_TOKENS); return AddTokenCCInputs(cpHeir, mtx, ownerPubkey, tokenid, total, maxinputs); } static CScript makeCreateOpRet(uint256 tokenid, std::vector voutTokenPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName) { - return EncodeTokenOpRet((uint8_t)'t', EVAL_TOKENS, tokenid, voutTokenPubkeys, + return EncodeTokenOpRet(tokenid, voutTokenPubkeys, EncodeHeirCreateOpRet((uint8_t)'F', ownerPubkey, heirPubkey, inactivityTimeSec, heirName)); } static CScript makeAddOpRet(uint256 tokenid, std::vector voutTokenPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) { - return EncodeTokenOpRet((uint8_t)'t', EVAL_TOKENS, tokenid, voutTokenPubkeys, + return EncodeTokenOpRet(tokenid, voutTokenPubkeys, EncodeHeirOpRet((uint8_t)'A', fundingtxid, isHeirSpendingBegan)); } static CScript makeClaimOpRet(uint256 tokenid, std::vector voutTokenPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) { - return EncodeTokenOpRet((uint8_t)'t', EVAL_TOKENS, tokenid, voutTokenPubkeys, + return EncodeTokenOpRet(tokenid, voutTokenPubkeys, EncodeHeirOpRet((uint8_t)'C', fundingtxid, isHeirSpendingBegan)); } @@ -85,11 +85,11 @@ public: return MakeTokensCC1of2vout(EVAL_HEIR, amount, ownerPubkey, heirPubkey); } static CTxOut makeUserVout(int64_t amount, CPubKey myPubkey) { - return MakeTokensCC1vout(EVAL_HEIR, amount, myPubkey); - } - static CTxOut makeClaimerVout(int64_t amount, CPubKey myPubkey) { - return MakeTokensCC1vout(EVAL_HEIR, amount, myPubkey); + return MakeCC1vout(EVAL_TOKENS, amount, myPubkey); // yes EVAL_TOKENS } +/* static CTxOut makeClaimerVout(int64_t amount, CPubKey myPubkey) { + return MakeCC1vout(EVAL_TOKENS, amount, myPubkey); // yes EVAL_TOKENS + } */ static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { struct CCcontract_info *cpHeir, heirC; cpHeir = CCinit(&heirC, EVAL_HEIR); @@ -477,7 +477,7 @@ public: CScript ownerScript; CScript heirScript; - if (m_checkNormals) { + if (m_checkNormals) { //not used, incorrect check, too strict ownerScript = CoinHelper::makeUserVout(vout.nValue, ownerPubkey).scriptPubKey; heirScript = CoinHelper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey; std::cerr << "CMyPubkeyVoutValidator::validateVout() vout.scriptPubKey=" << vout.scriptPubKey.ToString() << " makeUserVout(coin,owner)=" << CoinHelper::makeUserVout(vout.nValue, ownerPubkey).scriptPubKey.ToString() << " makeUserVout(coin,heir)=" << CoinHelper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey.ToString() << std::endl; @@ -537,7 +537,7 @@ public: int64_t durationSec = CCduration(numblocks, m_latesttxid); // recreate scriptPubKey for heir and compare it with that of the vout: - if (vout.scriptPubKey == Helper::makeClaimerVout(vout.nValue, heirPubkey).scriptPubKey) { + if (vout.scriptPubKey == Helper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey) { // this is the heir is trying to spend if (!m_isHeirSpendingBegan && durationSec <= inactivityTime) { message = "heir is not allowed yet to spend funds"; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 847ddd921..82870c941 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -7454,13 +7454,13 @@ UniValue heirfund(const UniValue& params, bool fHelp) inactivitytime = atof((char*)params[4].get_str().c_str()); - hex = HeirFundCoinCaller(txfee, amount, name, pubkey2pk(pubkey), inactivitytime, zeroid); - if (hex.size() > 0) { + result = HeirFundCoinCaller(txfee, amount, name, pubkey2pk(pubkey), inactivitytime, zeroid); +/* if (hex.size() > 0) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); } else - ERR_RESULT("couldn't create heir fund"); + ERR_RESULT("couldn't create heir fund");*/ return result; } @@ -7573,13 +7573,13 @@ UniValue heirfundtokens(const UniValue& params, bool fHelp) assetid = Parseuint256((char*)params[5].get_str().c_str()); - hex = HeirFundTokenCaller(txfee, amount, name, pubkey2pk(pubkey), inactivitytime, assetid); - if (hex.size() > 0) { + result = HeirFundTokenCaller(txfee, amount, name, pubkey2pk(pubkey), inactivitytime, assetid); +/* if (hex.size() > 0) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); } else - ERR_RESULT("couldn't create heir fund"); + ERR_RESULT("couldn't create heir fund");*/ return result; From 9e7b0314666af5a18e3df54c7bb6604fc6ab7543 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 15 Jan 2019 12:25:21 +0500 Subject: [PATCH 418/643] corr ccinit in HeirAdd --- src/cc/heir.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index a1f8adfd3..f3a3913a3 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -719,8 +719,8 @@ template UniValue HeirAdd(uint256 fundingtxid, uint64_t txfee, in uint8_t funcId; uint8_t hasHeirSpendingBegun = 0; - //cp = CCinit(&C, Helper::getMyEval()); // for tokens shoud be EVAL_TOKENS to sign it correctly! - cp = CCinit(&C, EVAL_HEIR); // for tokens shoud be EVAL_TOKENS to sign it correctly! + cp = CCinit(&C, Helper::getMyEval()); // for tokens shoud be EVAL_TOKENS to sign it correctly! + //cp = CCinit(&C, EVAL_HEIR); // for tokens shoud be EVAL_TOKENS to sign it correctly! if (txfee == 0) txfee = 10000; From 46406f3c25e7649c20df82e5d7d5b1882025874b Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 15 Jan 2019 13:06:06 +0500 Subject: [PATCH 419/643] corr CCinit in HeirClaim --- src/cc/CCtokens.cpp | 4 ++-- src/cc/heir.cpp | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index d1dcf0b1f..e54919155 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -427,9 +427,9 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c if (tx.vout[v].scriptPubKey == testDualVout.scriptPubKey) { if(voutPubkeys.size() == 1) - std::cerr << indentStr << "IsTokensvout() this is dual-eval token vout, eval2=" << evalCodeInOpret << ", returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; + std::cerr << indentStr << "IsTokensvout() this is dual-eval token vout, eval2=" << (int)evalCodeInOpret << ", returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; else - std::cerr << indentStr << "IsTokensvout() this is dual-eval token 1of2 vout or change, eval2=" << evalCodeInOpret << ", returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; + std::cerr << indentStr << "IsTokensvout() this is dual-eval token 1of2 vout or change, eval2=" << (int)evalCodeInOpret << ", returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; return tx.vout[v].nValue; } } diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index f3a3913a3..8ee5d7e07 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -832,7 +832,8 @@ template UniValue HeirClaim(uint256 fundingtxid, uint64_t txfee std::string heirName; uint8_t hasHeirSpendingBegun = 0; - cp = CCinit(&C, Helper::getMyEval()); + //cp = CCinit(&C, Helper::getMyEval()); + cp = CCinit(&C, EVAL_HEIR); if (txfee == 0) txfee = 10000; @@ -919,8 +920,15 @@ template UniValue HeirClaim(uint256 fundingtxid, uint64_t txfee std::string rawhextx = FinalizeCCTx(0, cp, mtx, myPubkey, txfee, Helper::makeClaimOpRet(tokenid, voutTokenPubkeys, fundingtxid, (myPubkey == heirPubkey) ? 1 : hasHeirSpendingBegun)); // forward isHeirSpending to the next latest tx - result.push_back(Pair("result", "success")); - result.push_back(Pair("hextx", rawhextx)); + if (!rawhextx.empty()) { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hextx", rawhextx)); + } + else { + std::cerr << "HeirAdd error in FinalizeCCtx" << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "sign error")); + } } else { fprintf(stderr, "HeirClaim() cant find Heir CC inputs\n"); From 395fac417354e3e62bed3787a98c303743bcd908 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 15 Jan 2019 14:09:50 +0500 Subject: [PATCH 420/643] corr cp param to ...addr1of2set --- src/cc/heir.cpp | 2 +- src/cc/heir_validate.h | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 8ee5d7e07..9769f6f87 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -909,7 +909,7 @@ template UniValue HeirClaim(uint256 fundingtxid, uint64_t txfee Myprivkey(myprivkey); // set pubkeys for finding 1of2 cc in FinalizeCCtx to sign it: - Helper::CCaddrCoinsOrTokens1of2set(ownerPubkey, heirPubkey, coinaddr); + Helper::CCaddrCoinsOrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); // add 1of2 vout validation pubkeys (this is for tokens): std::vector voutTokenPubkeys; diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index e9710a471..2ad905808 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -51,10 +51,8 @@ public: cpHeir = CCinit(&heirC, EVAL_HEIR); return GetCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); } - static void CCaddrCoinsOrTokens1of2set(CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { - struct CCcontract_info *cpHeir, heirC; - cpHeir = CCinit(&heirC, EVAL_HEIR); - CCaddr1of2set(cpHeir, ownerPubkey, heirPubkey, coinaddr); + static void CCaddrCoinsOrTokens1of2set(struct CCcontract_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { + CCaddr1of2set(cp, ownerPubkey, heirPubkey, coinaddr); } }; @@ -96,10 +94,9 @@ public: return GetTokensCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); } - static void CCaddrCoinsOrTokens1of2set(CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { - struct CCcontract_info *cpHeir, heirC; - cpHeir = CCinit(&heirC, EVAL_HEIR); - CCaddrTokens1of2set(cpHeir, ownerPubkey, heirPubkey, coinaddr); + static void CCaddrCoinsOrTokens1of2set(struct CCcontract_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { + + CCaddrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); } }; From 96a653004460b16c8850e065bff0699e2fa230b2 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 15 Jan 2019 14:24:58 +0500 Subject: [PATCH 421/643] corr getting 1of2 addr in 1of2 validator --- src/cc/heir.cpp | 6 ++++-- src/cc/heir_validate.h | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 9769f6f87..9ec8729e3 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -902,10 +902,12 @@ template UniValue HeirClaim(uint256 fundingtxid, uint64_t txfee mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(markerpubkey)) << OP_CHECKSIG)); // txfee 1, txfee 2 - for miners std::cerr << "HeirClaim() adding markeraddr=" << markeraddr << '\n'; */ - uint8_t myprivkey[32]; + // get address of 1of2 cond char coinaddr[64]; - // set priv key addresses in CC structure: Helper::GetCoinsOrTokensCCaddress1of2(coinaddr, ownerPubkey, heirPubkey); + + // retrieve priv key addresses for FinalizeCCtx: + uint8_t myprivkey[32]; Myprivkey(myprivkey); // set pubkeys for finding 1of2 cc in FinalizeCCtx to sign it: diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index 2ad905808..f091e1381 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -419,7 +419,9 @@ public: char shouldBeAddr[65], ccAddr[65]; - GetCCaddress1of2(m_cp, shouldBeAddr, ownerPubkey, heirPubkey); + //GetCCaddress1of2(m_cp, shouldBeAddr, ownerPubkey, heirPubkey); + Helper::GetCoinsOrTokensCCaddress1of2(shouldBeAddr, ownerPubkey, heirPubkey); + if (vout.scriptPubKey.IsPayToCryptoCondition()) { if (Getscriptaddress(ccAddr, vout.scriptPubKey) && strcmp(shouldBeAddr, ccAddr) == 0) { //std::cerr << "CCC1of2AddressValidator::validateVout() exits with true" << std::endl; From 2d8027854d1e1523145d796020e119e4df0d943e Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 15 Jan 2019 16:22:14 +0500 Subject: [PATCH 422/643] first changes in assets for 2-eval vouts --- src/cc/CCassetsCore.cpp | 45 +++++++++++++---------------------------- src/cc/CCassetstx.cpp | 6 +++--- src/cc/CCinclude.h | 4 ++-- 3 files changed, 19 insertions(+), 36 deletions(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index 72404878d..09d0d8058 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -239,28 +239,23 @@ CScript EncodeAssetCreateOpRet(uint8_t funcid,std::vector origpubkey,st } */ -CScript EncodeAssetOpRet(uint8_t assetFuncId, uint256 tokenid, uint256 assetid2, int64_t price, std::vector voutPubkeys, std::vector origpubkey) +CScript EncodeAssetOpRet(uint8_t assetFuncId, uint256 assetid2, int64_t price, std::vector voutPubkeys, std::vector origpubkey) { CScript opret; uint8_t evalcode = EVAL_ASSETS; - uint8_t funcId = (uint8_t)'t'; - uint8_t ccType = 0; - if (voutPubkeys.size() >= 1 && voutPubkeys.size() <= 2) - ccType = voutPubkeys.size(); - tokenid = revuint256(tokenid); switch ( assetFuncId ) { //case 't': this cannot be here case 'x': case 'o': - opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcId << tokenid << ccType; if(ccType >= 1) ss << voutPubkeys[0]; if(ccType == 2) ss << voutPubkeys[1]; ss << assetFuncId); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << assetFuncId); break; case 's': case 'b': case 'S': case 'B': - opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcId << tokenid << ccType; if(ccType >= 1) ss << voutPubkeys[0]; if(ccType == 2) ss << voutPubkeys[1]; ss << assetFuncId << price << origpubkey); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << assetFuncId << price << origpubkey); break; case 'E': case 'e': assetid2 = revuint256(assetid2); - opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcId << tokenid << ccType; if(ccType >= 1) ss << voutPubkeys[0]; if(ccType == 2) ss << voutPubkeys[1]; ss << assetFuncId << assetid2 << price << origpubkey); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << assetFuncId << assetid2 << price << origpubkey); break; default: fprintf(stderr,"EncodeAssetOpRet: illegal funcid.%02x\n", assetFuncId); @@ -270,7 +265,7 @@ CScript EncodeAssetOpRet(uint8_t assetFuncId, uint256 tokenid, uint256 assetid2, return(opret); } -// it is for compatibility, do not use this for new contracts (use DecodeTokenCreateOpRet) +/* it is for compatibility, do not use this for new contracts (use DecodeTokenCreateOpRet) bool DecodeAssetCreateOpRet(const CScript &scriptPubKey, std::vector &origpubkey, std::string &name, std::string &description) { std::vector vopret; uint8_t evalcode,funcid,*script; @@ -282,9 +277,9 @@ bool DecodeAssetCreateOpRet(const CScript &scriptPubKey, std::vector &o return(true); } return(0); -} +} */ -uint8_t DecodeAssetOpRet(const CScript &scriptPubKey, uint8_t &evalCodeInOpret, uint256 &tokenid, uint256 &assetid2, int64_t &price, std::vector &origpubkey) +uint8_t DecodeAssetTokenOpRet(const CScript &scriptPubKey, uint8_t &evalCodeInOpret, uint256 &tokenid, uint256 &assetid2, int64_t &price, std::vector &origpubkey) { std::vector vopretExtra; uint8_t *script, funcId = 0, assetFuncId = 0, dummyEvalCode, dummyAssetFuncId; @@ -298,7 +293,6 @@ uint8_t DecodeAssetOpRet(const CScript &scriptPubKey, uint8_t &evalCodeInOpret, // First - decode token opret: funcId = DecodeTokenOpRet(scriptPubKey, evalCodeInOpret, tokenid, voutPubkeysDummy, vopretExtra); - /*GetOpReturnData(scriptPubKey, vopret); script = (uint8_t *)vopret.data(); if (script == 0) { @@ -308,14 +302,14 @@ uint8_t DecodeAssetOpRet(const CScript &scriptPubKey, uint8_t &evalCodeInOpret, //bool isEof = true; // NOTE: if parse error occures, parse might not be able to set error. It is safer to treat that it was eof if it is not set! //bool result = E_UNMARSHAL(vopret, ss >> evalCodeInOpret; ss >> funcId; ss >> tokenid; ss >> assetFuncId; isEof = ss.eof()); - if (funcId == 0 || vopretExtra.size() == 0) { + if (funcId == 0 || vopretExtra.size() < 2) { std::cerr << "DecodeAssetOpRet() incorrect opret or no asset's payload" << " funcId=" << (int)funcId << " vopretExtra.size()=" << vopretExtra.size() << std::endl; return (uint8_t)0; } ////tokenid = revuint256(tokenid); already done in DecodeToken! - - assetFuncId = vopretExtra.begin()[0]; + evalCodeInOpret = vopretExtra.begin()[0]; + assetFuncId = vopretExtra.begin()[1]; //std::cerr << "DecodeAssetOpRet() evalCodeInOpret=" << (int)evalCodeInOpret << " funcId=" << (char)(funcId ? funcId : ' ') << " assetFuncId=" << (char)(assetFuncId ? assetFuncId : ' ') << std::endl; @@ -324,17 +318,6 @@ uint8_t DecodeAssetOpRet(const CScript &scriptPubKey, uint8_t &evalCodeInOpret, //fprintf(stderr,"decode.[%c] assetFuncId.[%c]\n", funcId, assetFuncId); switch( assetFuncId ) { - /*case 'c': - return(funcid); - break; */ - /*case 't': - if (E_UNMARSHAL(vopret, ss >> evalCode; ss >> funcId; ss >> tokenid; isEof = ss.eof()) || !isEof) - { - assetid = revuint256(assetid); - return(funcid); - } - break; */ - case 'x': case 'o': if (vopretExtra.size() == 1) // no data after 'assetFuncId' allowed { @@ -369,7 +352,7 @@ bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CT { uint256 assetid,assetid2; uint8_t evalCode; - if ( tx.vout.size() > 0 && DecodeAssetOpRet(tx.vout[tx.vout.size()-1].scriptPubKey, evalCode, assetid, assetid2, price, origpubkey) != 0 ) + if ( tx.vout.size() > 0 && DecodeAssetTokenOpRet(tx.vout[tx.vout.size()-1].scriptPubKey, evalCode, assetid, assetid2, price, origpubkey) != 0 ) return(true); else return(false); @@ -382,7 +365,7 @@ bool GetAssetorigaddrs(struct CCcontract_info *cp,char *CCaddr,char *destaddr,co uint8_t evalCode; n = tx.vout.size(); - if ( n == 0 || (funcid= DecodeAssetOpRet(tx.vout[n-1].scriptPubKey, evalCode,assetid,assetid2,price,origpubkey)) == 0 ) + if ( n == 0 || (funcid= DecodeAssetTokenOpRet(tx.vout[n-1].scriptPubKey, evalCode,assetid,assetid2,price,origpubkey)) == 0 ) return(false); if ( GetCCaddress(cp, CCaddr, pubkey2pk(origpubkey)) != 0 && Getscriptaddress(destaddr, CScript() << origpubkey << OP_CHECKSIG) != 0 ) return(true); @@ -432,7 +415,7 @@ int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmppr return(0); else if ( vinTx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) return eval->Invalid("invalid normal vout0 for buyvin"); - else if ((funcid = DecodeAssetOpRet(vinTx.vout[vinTx.vout.size() - 1].scriptPubKey, evalCode, assetid, assetid2, tmpprice, tmporigpubkey)) == 'b' && vinTx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) // marker is only in 'b'? + else if ((funcid = DecodeAssetTokenOpRet(vinTx.vout[vinTx.vout.size() - 1].scriptPubKey, evalCode, assetid, assetid2, tmpprice, tmporigpubkey)) == 'b' && vinTx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) // marker is only in 'b'? return eval->Invalid("invalid normal vout1 for buyvin"); else { @@ -470,7 +453,7 @@ bool ValidateAssetOpret(CTransaction tx, int32_t v, uint256 assetid, int64_t &pr // this is just for log messages indentation fur debugging recursive calls: int32_t n = tx.vout.size(); - if ((funcid = DecodeAssetOpRet(tx.vout[n - 1].scriptPubKey, evalCode, assetidOpret, assetidOpret2, price, origpubkey)) == 0) + if ((funcid = DecodeAssetTokenOpRet(tx.vout[n - 1].scriptPubKey, evalCode, assetidOpret, assetidOpret2, price, origpubkey)) == 0) { std::cerr << "ValidateAssetOpret() DecodeOpret returned null for n-1=" << n - 1 << " txid=" << tx.GetHash().GetHex() << std::endl; return(false); diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 3047876f4..1531f6893 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -93,7 +93,7 @@ UniValue AssetOrders(uint256 refassetid) { // for logging: funcid = DecodeAssetOpRet(vintx.vout[vintx.vout.size() - 1].scriptPubKey, evalCode, assetid, assetid2, price, origpubkey); //std::cerr << "addOrders() vintx.vout.size()=" << vintx.vout.size() << " funcid=" << (char)(funcid ? funcid : ' ') << " assetid=" << assetid.GetHex() << std::endl; - if (vintx.vout.size() > 0 && (funcid = DecodeAssetOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey, evalCode, assetid, assetid2, price, origpubkey)) != 0) + if (vintx.vout.size() > 0 && (funcid = DecodeAssetTokenOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey, evalCode, assetid, assetid2, price, origpubkey)) != 0) { if (refassetid != zero && assetid != refassetid) { @@ -486,7 +486,7 @@ std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid) bidamount = vintx.vout[0].nValue; mtx.vin.push_back(CTxIn(bidtxid, 0, CScript())); // coins in Assets - if( DecodeAssetOpRet(vintx.vout[vintx.vout.size() - 1].scriptPubKey, dummyEvalCode, dummyAssetid, dummyAssetid2, dummyPrice, dummyOrigpubkey) == 'b') + if( DecodeAssetTokenOpRet(vintx.vout[vintx.vout.size() - 1].scriptPubKey, dummyEvalCode, dummyAssetid, dummyAssetid2, dummyPrice, dummyOrigpubkey) == 'b') mtx.vin.push_back(CTxIn(bidtxid, 1, CScript())); // spend marker if funcid='b' (not 'B') // TODO: spend it also in FillBuyOffer? @@ -526,7 +526,7 @@ std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) askamount = vintx.vout[0].nValue; mtx.vin.push_back(CTxIn(asktxid, 0, CScript())); - if (DecodeAssetOpRet(vintx.vout[vintx.vout.size() - 1].scriptPubKey, dummyEvalCode, dummyAssetid, dummyAssetid2, dummyPrice, dummyOrigpubkey) == 's') + if (DecodeAssetTokenOpRet(vintx.vout[vintx.vout.size() - 1].scriptPubKey, dummyEvalCode, dummyAssetid, dummyAssetid2, dummyPrice, dummyOrigpubkey) == 's') mtx.vin.push_back(CTxIn(asktxid, 1, CScript())); // marker if funcid='s' (not 'S') // TODO: spend it also in FillSell? diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 14a500222..b90e4ff6f 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -159,8 +159,8 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx); CScript EncodeAssetOpRet(uint8_t assetFuncId, uint256 tokenid, uint256 assetid2, int64_t price, std::vector voutPubkeys, std::vector origpubkey); -bool DecodeAssetCreateOpRet(const CScript &scriptPubKey, std::vector &origpubkey, std::string &name, std::string &description); -uint8_t DecodeAssetOpRet(const CScript &scriptPubKey, uint8_t &evalCodeInOpret, uint256 &tokenid, uint256 &assetid2, int64_t &price, std::vector &origpubkey); +//bool DecodeAssetCreateOpRet(const CScript &scriptPubKey, std::vector &origpubkey, std::string &name, std::string &description); +uint8_t DecodeAssetTokenOpRet(const CScript &scriptPubKey, uint8_t &evalCodeInOpret, uint256 &tokenid, uint256 &assetid2, int64_t &price, std::vector &origpubkey); CScript EncodeTokenOpRet(uint256 tokenid, std::vector voutPubkeys, CScript payload); CScript EncodeTokenOpRet(uint8_t tokenFuncId, uint8_t evalCodeInOpret, uint256 tokenid, std::vector voutPubkeys, CScript payload); From a7d7451c88da73a7da9e0da5473be99f5547c979 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 15 Jan 2019 16:28:39 +0500 Subject: [PATCH 423/643] corr call to DecodeAssetTokenOpRet --- src/cc/assets.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index ea44453ff..aab0a234f 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -150,7 +150,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti outputs = inputs = 0; preventCCvins = preventCCvouts = -1; - if((funcid = DecodeAssetOpRet(tx.vout[numvouts-1].scriptPubKey, evalCodeInOpret, assetid, assetid2, remaining_price, origpubkey)) == 0 ) + if((funcid = DecodeAssetTokenOpRet(tx.vout[numvouts-1].scriptPubKey, evalCodeInOpret, assetid, assetid2, remaining_price, origpubkey)) == 0 ) return eval->Invalid("AssetValidate: invalid opreturn payload"); // find token user cc addr From 41da2aed5f8d9071883c424730dd66ff089c163c Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 15 Jan 2019 16:54:36 +0500 Subject: [PATCH 424/643] corr call to EncodeAssetOpRet --- src/cc/CCassetstx.cpp | 16 ++++++++-------- src/cc/CCinclude.h | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 1531f6893..2661b1f29 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -328,7 +328,7 @@ std::string CreateBuyOffer(int64_t txfee, int64_t bidamount, uint256 assetid, in mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, txfee, mypk)); std::vector voutTokenPubkeys; // should be empty - no token vouts - return(FinalizeCCTx(0, cpAssets, mtx, mypk, txfee, EncodeAssetOpRet('b', assetid, zeroid, pricetotal, voutTokenPubkeys, Mypubkey()))); + return(FinalizeCCTx(0, cpAssets, mtx, mypk, txfee, EncodeAssetOpRet('b', zeroid, pricetotal, voutTokenPubkeys, Mypubkey()))); } CCerror = strprintf("no coins found to make buy offer"); return(""); @@ -380,7 +380,7 @@ std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t p std::vector voutTokenPubkeys; voutTokenPubkeys.push_back(unspendablePubkey); - opret = EncodeAssetOpRet('s',assetid, zeroid, pricetotal, voutTokenPubkeys, Mypubkey()); + opret = EncodeAssetOpRet('s', zeroid, pricetotal, voutTokenPubkeys, Mypubkey()); return(FinalizeCCTx(mask,cpTokens,mtx,mypk,txfee,opret)); } else { @@ -440,10 +440,10 @@ std::string CreateSwap(int64_t txfee,int64_t askamount,uint256 assetid,uint256 a std::vector voutTokenPubkeys; // should be empty - no token vouts if (assetid2 == zeroid) { - opret = EncodeAssetOpRet('s', assetid, zeroid, pricetotal, voutTokenPubkeys, Mypubkey()); + opret = EncodeAssetOpRet('s', zeroid, pricetotal, voutTokenPubkeys, Mypubkey()); } else { - opret = EncodeAssetOpRet('e', assetid, assetid2, pricetotal, voutTokenPubkeys, Mypubkey()); + opret = EncodeAssetOpRet('e', assetid2, pricetotal, voutTokenPubkeys, Mypubkey()); } return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,opret)); } @@ -495,7 +495,7 @@ std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid) std::vector voutTokenPubkeys; // should be empty, no tokens vout - return(FinalizeCCTx(mask, cpAssets, mtx, mypk, txfee, EncodeAssetOpRet('o', assetid, zeroid, 0, voutTokenPubkeys, Mypubkey()))); + return(FinalizeCCTx(mask, cpAssets, mtx, mypk, txfee, EncodeAssetOpRet('o', zeroid, 0, voutTokenPubkeys, Mypubkey()))); } } return(""); @@ -542,7 +542,7 @@ std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) GetCCaddress(cpAssets, myCCaddr, mypk); CCaddr2set(cpTokens, EVAL_ASSETS, mypk, myPrivkey, myCCaddr); //do we need this? Seems FinalizeCCTx can attach to any evalcode cc addr by calling Getscriptaddress - return(FinalizeCCTx(mask, cpTokens, mtx, mypk, txfee, EncodeAssetOpRet('x', assetid, zeroid, 0, voutTokenPubkeys, Mypubkey()))); + return(FinalizeCCTx(mask, cpTokens, mtx, mypk, txfee, EncodeAssetOpRet('x', zeroid, 0, voutTokenPubkeys, Mypubkey()))); } } return(""); @@ -620,7 +620,7 @@ std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t f std::vector voutTokenPubkeys; voutTokenPubkeys.push_back(pubkey2pk(origpubkey)); - return(FinalizeCCTx(mask,cpTokens,mtx,mypk,txfee, EncodeAssetOpRet('B', assetid, zeroid, remaining_required, voutTokenPubkeys, origpubkey))); + return(FinalizeCCTx(mask,cpTokens,mtx,mypk,txfee, EncodeAssetOpRet('B', zeroid, remaining_required, voutTokenPubkeys, origpubkey))); } else return("dont have any assets to fill bid"); } } @@ -722,7 +722,7 @@ std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 askt std::vector voutTokenPubkeys; voutTokenPubkeys.push_back(mypk); - return(FinalizeCCTx(mask,cpTokens,mtx,mypk,txfee,EncodeAssetOpRet(assetid2 != zeroid ? 'E' : 'S', assetid, assetid2, remaining_nValue, voutTokenPubkeys, origpubkey))); + return(FinalizeCCTx(mask,cpTokens,mtx,mypk,txfee,EncodeAssetOpRet(assetid2 != zeroid ? 'E' : 'S', assetid2, remaining_nValue, voutTokenPubkeys, origpubkey))); } else { CCerror = strprintf("filltx not enough utxos"); fprintf(stderr,"%s\n", CCerror.c_str()); diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index b90e4ff6f..170961340 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -158,7 +158,7 @@ int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, C int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, /*std::vector &origpubkey,*/ const CTransaction& tx, int32_t v, uint256 reftokenid, std::vector vinPubkeys); bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx); -CScript EncodeAssetOpRet(uint8_t assetFuncId, uint256 tokenid, uint256 assetid2, int64_t price, std::vector voutPubkeys, std::vector origpubkey); +CScript EncodeAssetOpRet(uint8_t assetFuncId, uint256 assetid2, int64_t price, std::vector voutPubkeys, std::vector origpubkey); //bool DecodeAssetCreateOpRet(const CScript &scriptPubKey, std::vector &origpubkey, std::string &name, std::string &description); uint8_t DecodeAssetTokenOpRet(const CScript &scriptPubKey, uint8_t &evalCodeInOpret, uint256 &tokenid, uint256 &assetid2, int64_t &price, std::vector &origpubkey); From 4379cffe74a0f19c078d4af9a865a27fcba84389 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 15 Jan 2019 17:01:42 +0500 Subject: [PATCH 425/643] corr call to EncodeAssetOpet in prices.cpp --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 9ba6d4a84..bda7248ea 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -328,7 +328,7 @@ std::string PricesAddFunding(uint64_t txfee,uint256 refbettoken,uint256 fundingt // add addr2 std::vector voutTokenPubkeysEmpty; //TODO: add token vout pubkeys - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('t',bettoken,zeroid,0, voutTokenPubkeysEmpty, Mypubkey()))); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('t',/*bettoken,*/zeroid,0, voutTokenPubkeysEmpty, Mypubkey()))); } else { From 8d8b253138bba7d1f5820b372bf56eab3a12a808 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 15 Jan 2019 20:55:26 +0500 Subject: [PATCH 426/643] first time changed eval usage and MakeTokenCCcond.. for assets --- src/cc/CCassetsCore.cpp | 2 +- src/cc/CCassetstx.cpp | 114 ++++++++++++++++++++++++---------------- src/cc/CCinclude.h | 2 +- src/cc/CCtx.cpp | 2 +- src/cc/heir.cpp | 1 + src/cc/prices.cpp | 4 +- 6 files changed, 77 insertions(+), 48 deletions(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index 09d0d8058..9bd17cef8 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -239,7 +239,7 @@ CScript EncodeAssetCreateOpRet(uint8_t funcid,std::vector origpubkey,st } */ -CScript EncodeAssetOpRet(uint8_t assetFuncId, uint256 assetid2, int64_t price, std::vector voutPubkeys, std::vector origpubkey) +CScript EncodeAssetOpRet(uint8_t assetFuncId, uint256 assetid2, int64_t price, std::vector origpubkey) { CScript opret; uint8_t evalcode = EVAL_ASSETS; diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 2661b1f29..8dcde6e12 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -328,7 +328,9 @@ std::string CreateBuyOffer(int64_t txfee, int64_t bidamount, uint256 assetid, in mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, txfee, mypk)); std::vector voutTokenPubkeys; // should be empty - no token vouts - return(FinalizeCCTx(0, cpAssets, mtx, mypk, txfee, EncodeAssetOpRet('b', zeroid, pricetotal, voutTokenPubkeys, Mypubkey()))); + return(FinalizeCCTx(0, cpAssets, mtx, mypk, txfee, + EncodeTokenOpRet(assetid, voutTokenPubkeys, + EncodeAssetOpRet('b', zeroid, pricetotal, Mypubkey())))); } CCerror = strprintf("no coins found to make buy offer"); return(""); @@ -342,7 +344,8 @@ std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t p uint64_t mask; int64_t inputs, CCchange; CScript opret; - struct CCcontract_info *cpTokens,C; + struct CCcontract_info *cpAssets, assetsC; + struct CCcontract_info *cpTokens, tokensC; //std::cerr << "CreateSell() askamount=" << askamount << " pricetotal=" << pricetotal << std::endl; @@ -351,8 +354,8 @@ std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t p return(""); } - cpTokens = CCinit(&C, EVAL_TOKENS); // NOTE: tokens is here - + cpAssets = CCinit(&assetsC, EVAL_ASSETS); // NOTE: this is for signing + if (txfee == 0) txfee = 10000; @@ -360,6 +363,8 @@ std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t p if (AddNormalinputs(mtx, mypk, 2*txfee, 3) > 0) { mask = ~((1LL << mtx.vin.size()) - 1); + // add single-eval tokens: + cpTokens = CCinit(&tokensC, EVAL_TOKENS); // NOTE: tokens is here if ((inputs = AddTokenCCInputs(cpTokens, mtx, mypk, assetid, askamount, 60)) > 0) { if (inputs < askamount) { @@ -369,19 +374,20 @@ std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t p return (""); } - CPubKey unspendablePubkey = GetUnspendable(cpTokens, 0); - mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, askamount, unspendablePubkey)); + CPubKey unspendablePubkey = GetUnspendable(cpAssets, NULL); + mtx.vout.push_back(MakeTokensCC1vout(EVAL_ASSETS, askamount, unspendablePubkey)); mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, txfee, mypk)); //marker if (inputs > askamount) CCchange = (inputs - askamount); if (CCchange != 0) - mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, CCchange, mypk)); + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, CCchange, mypk)); // change to single-eval token vout std::vector voutTokenPubkeys; voutTokenPubkeys.push_back(unspendablePubkey); - opret = EncodeAssetOpRet('s', zeroid, pricetotal, voutTokenPubkeys, Mypubkey()); - return(FinalizeCCTx(mask,cpTokens,mtx,mypk,txfee,opret)); + opret = EncodeTokenOpRet(assetid, voutTokenPubkeys, + EncodeAssetOpRet('s', zeroid, pricetotal, Mypubkey())); + return(FinalizeCCTx(mask,cpAssets, mtx, mypk, txfee, opret)); } else { fprintf(stderr, "need some tokens to place ask\n"); @@ -399,10 +405,10 @@ std::string CreateSwap(int64_t txfee,int64_t askamount,uint256 assetid,uint256 a CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CPubKey mypk; uint64_t mask; int64_t inputs,CCchange; CScript opret; struct CCcontract_info *cp,C; - ////////////////////////////////////////// + ////////////////////////// NOT IMPLEMENTED YET///////////////////////////////// fprintf(stderr,"asset swaps disabled\n"); return(""); - ////////////////////////////////////////// + ////////////////////////// NOT IMPLEMENTED YET///////////////////////////////// if ( askamount < 0 || pricetotal < 0 ) { @@ -413,7 +419,7 @@ std::string CreateSwap(int64_t txfee,int64_t askamount,uint256 assetid,uint256 a if ( txfee == 0 ) txfee = 10000; - + ////////////////////////// NOT IMPLEMENTED YET///////////////////////////////// mypk = pubkey2pk(Mypubkey()); if (AddNormalinputs(mtx, mypk, txfee, 3) > 0) @@ -421,13 +427,14 @@ std::string CreateSwap(int64_t txfee,int64_t askamount,uint256 assetid,uint256 a mask = ~((1LL << mtx.vin.size()) - 1); if ((inputs = AddAssetInputs(cp, mtx, mypk, assetid, askamount, 60)) > 0) { + ////////////////////////// NOT IMPLEMENTED YET///////////////////////////////// if (inputs < askamount) { //was: askamount = inputs; std::cerr << "CreateSwap(): insufficient tokens for ask" << std::endl; CCerror = strprintf("insufficient tokens for ask"); return (""); } - + ////////////////////////// NOT IMPLEMENTED YET///////////////////////////////// CPubKey unspendablePubkey = GetUnspendable(cp, 0); mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, askamount, unspendablePubkey)); @@ -436,15 +443,18 @@ std::string CreateSwap(int64_t txfee,int64_t askamount,uint256 assetid,uint256 a if (CCchange != 0) mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, CCchange, mypk)); - + ////////////////////////// NOT IMPLEMENTED YET///////////////////////////////// std::vector voutTokenPubkeys; // should be empty - no token vouts if (assetid2 == zeroid) { - opret = EncodeAssetOpRet('s', zeroid, pricetotal, voutTokenPubkeys, Mypubkey()); + opret = EncodeTokenOpRet(assetid, voutTokenPubkeys, + EncodeAssetOpRet('s', zeroid, pricetotal, Mypubkey())); } else { - opret = EncodeAssetOpRet('e', assetid2, pricetotal, voutTokenPubkeys, Mypubkey()); + opret = EncodeTokenOpRet(assetid, voutTokenPubkeys, + EncodeAssetOpRet('e', assetid2, pricetotal, Mypubkey())); } + ////////////////////////// NOT IMPLEMENTED YET///////////////////////////////// return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,opret)); } else { @@ -493,9 +503,11 @@ std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid) mtx.vout.push_back(CTxOut(bidamount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - std::vector voutTokenPubkeys; // should be empty, no tokens vout + std::vector voutTokenPubkeys; // should be empty, no token vouts - return(FinalizeCCTx(mask, cpAssets, mtx, mypk, txfee, EncodeAssetOpRet('o', zeroid, 0, voutTokenPubkeys, Mypubkey()))); + return(FinalizeCCTx(mask, cpAssets, mtx, mypk, txfee, + EncodeTokenOpRet(assetid, voutTokenPubkeys, + EncodeAssetOpRet('o', zeroid, 0, Mypubkey())))); } } return(""); @@ -505,13 +517,15 @@ std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid) std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction vintx; uint64_t mask; uint256 hashBlock; int64_t askamount; CPubKey mypk; - struct CCcontract_info *cpTokens,*cpAssets,C,assetsC; + CTransaction vintx; uint64_t mask; + uint256 hashBlock; + int64_t askamount; + CPubKey mypk; + struct CCcontract_info *cpTokens, *cpAssets, tokensC, assetsC; uint8_t dummyEvalCode; uint256 dummyAssetid, dummyAssetid2; int64_t dummyPrice; std::vector dummyOrigpubkey; - cpTokens = CCinit(&C, EVAL_TOKENS); - cpAssets = CCinit(&assetsC, EVAL_ASSETS); + cpTokens = CCinit(&tokensC, EVAL_TOKENS); if (txfee == 0) txfee = 10000; @@ -530,7 +544,7 @@ std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) mtx.vin.push_back(CTxIn(asktxid, 1, CScript())); // marker if funcid='s' (not 'S') // TODO: spend it also in FillSell? - mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, askamount, mypk)); + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, askamount, mypk)); // one-eval token vout mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); std::vector voutTokenPubkeys; @@ -539,10 +553,15 @@ std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) char myCCaddr[65]; uint8_t myPrivkey[32]; Myprivkey(myPrivkey); + cpAssets = CCinit(&assetsC, EVAL_ASSETS); GetCCaddress(cpAssets, myCCaddr, mypk); - CCaddr2set(cpTokens, EVAL_ASSETS, mypk, myPrivkey, myCCaddr); //do we need this? Seems FinalizeCCTx can attach to any evalcode cc addr by calling Getscriptaddress - return(FinalizeCCTx(mask, cpTokens, mtx, mypk, txfee, EncodeAssetOpRet('x', zeroid, 0, voutTokenPubkeys, Mypubkey()))); + // this is only for unspendable addresses: + //CCaddr2set(cpTokens, EVAL_ASSETS, mypk, myPrivkey, myCCaddr); //do we need this? Seems FinalizeCCTx can attach to any evalcode cc addr by calling Getscriptaddress + + return(FinalizeCCTx(mask, cpTokens, mtx, mypk, txfee, + EncodeTokenOpRet(assetid, voutTokenPubkeys, + EncodeAssetOpRet('x', zeroid, 0, Mypubkey())))); } } return(""); @@ -568,7 +587,6 @@ std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t f return(""); } cpTokens = CCinit(&tokensC, EVAL_TOKENS); - cpAssets = CCinit(&assetsC, EVAL_ASSETS); if (txfee == 0) txfee = 10000; @@ -598,21 +616,24 @@ std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t f if (inputs > fillamount) CCchange = (inputs - fillamount); - CPubKey unspendableTokensPk = GetUnspendable(cpTokens, NULL); + //CPubKey unspendableTokensPk = GetUnspendable(cpTokens, NULL); uint8_t unspendableAssetsPrivkey[32]; + cpTokens = CCinit(&assetsC, EVAL_ASSETS); CPubKey unspendableAssetsPk = GetUnspendable(cpAssets, unspendableAssetsPrivkey); - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, bidamount - paid_amount, unspendableAssetsPk)); // 0 coins remainder - mtx.vout.push_back(CTxOut(paid_amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); // 1 coins to normal - mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, fillamount, pubkey2pk(origpubkey))); // 2 tokens paid + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, bidamount - paid_amount, unspendableAssetsPk)); // vout0 coins remainder + mtx.vout.push_back(CTxOut(paid_amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); // vout1 coins to normal + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, fillamount, pubkey2pk(origpubkey))); // vout2 single-eval tokens paid if (CCchange != 0) - mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, CCchange, mypk)); // 3 change in tokens + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, CCchange, mypk)); // vout3 change in single-eval tokens - fprintf(stderr,"remaining %llu -> origpubkey\n", (long long)remaining_required); + fprintf(stderr,"FillBuyOffer remaining %llu -> origpubkey\n", (long long)remaining_required); char unspendableAssetsAddr[64]; + cpAssets = CCinit(&assetsC, EVAL_ASSETS); GetCCaddress(cpAssets, unspendableAssetsAddr, unspendableAssetsPk); + // add additional unspendable addr from Assets: CCaddr2set(cpTokens, EVAL_ASSETS, unspendableAssetsPk, unspendableAssetsPrivkey, unspendableAssetsAddr); @@ -620,7 +641,9 @@ std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t f std::vector voutTokenPubkeys; voutTokenPubkeys.push_back(pubkey2pk(origpubkey)); - return(FinalizeCCTx(mask,cpTokens,mtx,mypk,txfee, EncodeAssetOpRet('B', zeroid, remaining_required, voutTokenPubkeys, origpubkey))); + return(FinalizeCCTx(mask,cpTokens,mtx,mypk,txfee, + EncodeTokenOpRet(assetid, voutTokenPubkeys, + EncodeAssetOpRet('B', zeroid, remaining_required, origpubkey)))); } else return("dont have any assets to fill bid"); } } @@ -637,10 +660,10 @@ std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 askt CPubKey mypk; std::vector origpubkey; double dprice; - uint64_t mask; - int32_t askvout=0; + uint64_t mask = 0; + int32_t askvout = 0; int64_t received_assetoshis, total_nValue, orig_assetoshis, paid_nValue, remaining_nValue, inputs, CCchange=0; - struct CCcontract_info *cpTokens, tokensC; + //struct CCcontract_info *cpTokens, tokensC; struct CCcontract_info *cpAssets, assetsC; if (fillunits < 0) @@ -656,8 +679,7 @@ std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 askt return(""); } - cpTokens = CCinit(&tokensC, EVAL_TOKENS); - cpAssets = CCinit(&assetsC, EVAL_ASSETS); + cpAssets = CCinit(&assetsC, EVAL_ASSETS); if (txfee == 0) txfee = 10000; @@ -676,7 +698,7 @@ std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 askt mtx.vin.push_back(CTxIn(asktxid, askvout, CScript())); // NOTE: this is the reference to tokens -> send cpTokens for signing into FinalizeCCTx! if (assetid2 != zeroid) - inputs = AddAssetInputs(cpTokens, mtx, mypk, assetid2, paid_nValue, 60); // not implemented yet + inputs = AddAssetInputs(cpAssets, mtx, mypk, assetid2, paid_nValue, 60); // not implemented yet else { inputs = AddNormalinputs(mtx, mypk, paid_nValue, 60); @@ -698,14 +720,15 @@ std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 askt if (assetid2 != zeroid && inputs > paid_nValue) CCchange = (inputs - paid_nValue); - mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, orig_assetoshis - received_assetoshis, GetUnspendable(cpTokens, NULL))); // vout.0 tokens cc addr - ask remainder - mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, received_assetoshis, mypk)); //vout.1 tokens to self + mtx.vout.push_back(MakeTokensCC1vout(EVAL_ASSETS, orig_assetoshis - received_assetoshis, GetUnspendable(cpAssets, NULL))); // vout.0 tokens cc addr - ask remainder + mtx.vout.push_back(MakeTokensCC1vout(EVAL_ASSETS, received_assetoshis, mypk)); //vout.1 tokens to self // NOTE: no marker here if (assetid2 != zeroid) { std::cerr << "FillSell() WARNING: asset swap not implemented yet! (paid_nValue)" << std::endl; - mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, paid_nValue, origpubkey)); //vout.2 tokens... (swap is not implemented yet) + // TODO: change MakeCC1vout appropriately when implementing: + //mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, paid_nValue, origpubkey)); //vout.2 tokens... (swap is not implemented yet) } else { //std::cerr << "FillSell() paid_value=" << paid_nValue << " origpubkey=" << HexStr(pubkey2pk(origpubkey)) << std::endl; @@ -715,14 +738,17 @@ std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 askt // not implemented if (CCchange != 0) { std::cerr << "FillSell() WARNING: asset swap not implemented yet! (CCchange)" << std::endl; - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, CCchange, mypk)); //vout.3 coins in Assets cc addr + // TODO: change MakeCC1vout appropriately when implementing: + //mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, CCchange, mypk)); //vout.3 coins in Assets cc addr (swap not implemented) } // vout verification pubkeys: std::vector voutTokenPubkeys; voutTokenPubkeys.push_back(mypk); - return(FinalizeCCTx(mask,cpTokens,mtx,mypk,txfee,EncodeAssetOpRet(assetid2 != zeroid ? 'E' : 'S', assetid2, remaining_nValue, voutTokenPubkeys, origpubkey))); + return(FinalizeCCTx(mask, cpAssets, mtx, mypk, txfee, + EncodeTokenOpRet(assetid, voutTokenPubkeys, + EncodeAssetOpRet(assetid2 != zeroid ? 'E' : 'S', assetid2, remaining_nValue, origpubkey)))); } else { CCerror = strprintf("filltx not enough utxos"); fprintf(stderr,"%s\n", CCerror.c_str()); diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 170961340..03af2f92d 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -158,7 +158,7 @@ int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, C int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, /*std::vector &origpubkey,*/ const CTransaction& tx, int32_t v, uint256 reftokenid, std::vector vinPubkeys); bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx); -CScript EncodeAssetOpRet(uint8_t assetFuncId, uint256 assetid2, int64_t price, std::vector voutPubkeys, std::vector origpubkey); +CScript EncodeAssetOpRet(uint8_t assetFuncId, uint256 assetid2, int64_t price, std::vector origpubkey); //bool DecodeAssetCreateOpRet(const CScript &scriptPubKey, std::vector &origpubkey, std::string &name, std::string &description); uint8_t DecodeAssetTokenOpRet(const CScript &scriptPubKey, uint8_t &evalCodeInOpret, uint256 &tokenid, uint256 &assetid2, int64_t &price, std::vector &origpubkey); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 29e1fe0ab..630f37dca 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -65,7 +65,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran GetCCaddress(cp,myaddr,mypk); mycond = MakeCCcond1(cp->evalcode,mypk); - GetTokensCCaddress(cp, myaddr, mypk); + GetTokensCCaddress(cp, mytokensaddr, mypk); mytokenscond = MakeTokensCCcond1(cp->evalcode, mypk); unspendablepk = GetUnspendable(cp,unspendablepriv); diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 9ec8729e3..48dc543ab 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -646,6 +646,7 @@ template UniValue HeirFund(uint64_t txfee, int64_t amount, std mtx.vout.push_back(Helper::make1of2Vout(amount, myPubkey, heirPubkey)); // add a marker for finding all plans in HeirList() + // TODO: change marker either to cc or normal txidaddr unspendable CPubKey heirUnspendablePubKey = GetUnspendable(cp, 0); mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(heirUnspendablePubKey)) << OP_CHECKSIG)); // TODO: do we need this marker? diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index bda7248ea..369495b1a 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -328,7 +328,9 @@ std::string PricesAddFunding(uint64_t txfee,uint256 refbettoken,uint256 fundingt // add addr2 std::vector voutTokenPubkeysEmpty; //TODO: add token vout pubkeys - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('t',/*bettoken,*/zeroid,0, voutTokenPubkeysEmpty, Mypubkey()))); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee, + EncodeTokenOpRet(bettoken, voutTokenPubkeysEmpty, + EncodeAssetOpRet('t',/*bettoken,*/zeroid, 0, Mypubkey())))); } else { From ffba12b55b211edbececc3016e96a81d6c6ea5c2 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 15 Jan 2019 21:17:51 +0500 Subject: [PATCH 427/643] added single-eval token cond to FinalizeCCtx --- src/cc/CCtx.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 630f37dca..7640b35bb 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -43,10 +43,12 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); CTransaction vintx; std::string hex; uint256 hashBlock; uint64_t mask=0,nmask=0,vinimask=0; int64_t utxovalues[CC_MAXVINS],change,normalinputs=0,totaloutputs=0,normaloutputs=0,totalinputs=0,normalvins=0,ccvins=0; - int32_t i,utxovout,n,err = 0; char myaddr[64],destaddr[64],unspendable[64],mytokensaddr[64]; - uint8_t *privkey,myprivkey[32],unspendablepriv[32],*msg32 = 0; - CC *mycond=0, *othercond=0, *othercond2=0, *othercond3=0, *othercond1of2=NULL, *othercond1of2tokens = NULL, *cond, *mytokenscond = NULL; + int32_t i,utxovout,n,err = 0; + char myaddr[64], destaddr[64], unspendable[64], mytokensaddr[64], mysingletokensaddr[64]; + uint8_t *privkey, myprivkey[32], unspendablepriv[32], *msg32 = 0; + CC *mycond=0, *othercond=0, *othercond2=0, *othercond3=0, *othercond1of2=NULL, *othercond1of2tokens = NULL, *cond, *mytokenscond = NULL, *mysingletokenscond = NULL; CPubKey unspendablepk; + struct CCcontract_info *cpTokens, tokensC; n = mtx.vout.size(); for (i=0; ievalcode, mypk); + cpTokens = CCinit(&tokensC, EVAL_TOKENS); + GetCCaddress(cpTokens, mysingletokensaddr, mypk); + mysingletokenscond = MakeCCcond1(cpTokens->evalcode, mypk); + unspendablepk = GetUnspendable(cp,unspendablepriv); GetCCaddress(cp,unspendable,unspendablepk); othercond = MakeCCcond1(cp->evalcode,unspendablepk); @@ -149,6 +155,12 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran cond = mytokenscond; fprintf(stderr,"FinalizeCCTx() matched TokensCC1vout CC addr.(%s)\n",mytokensaddr); } + else if (strcmp(destaddr, mysingletokensaddr) == 0) // if this is TokensCC1vout + { + privkey = myprivkey; + cond = mysingletokenscond; + fprintf(stderr, "FinalizeCCTx() matched single-eval TokensCC1vout CC addr.(%s)\n", mytokensaddr); + } else if ( strcmp(destaddr,unspendable) == 0 ) { privkey = unspendablepriv; From 114d7779d6402403971ec04e056f3263c4b0a1ae Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 15 Jan 2019 23:23:49 +0500 Subject: [PATCH 428/643] added support for 2 check pubkeys in IsTokenVout --- src/cc/CCtokens.cpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index e54919155..7296beaf2 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -420,18 +420,28 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c // maybe this is dual-eval 1 pubkey or 1of2 pubkey vout? if (voutPubkeys.size() >= 1 && voutPubkeys.size() <= 2) { CTxOut testDualVout; - if (voutPubkeys.size() == 1) - testDualVout = MakeTokensCC1vout(evalCodeInOpret, tx.vout[v].nValue, voutPubkeys[0]); - else // voutPubkeys.size() == 2 - testDualVout = MakeTokensCC1of2vout(evalCodeInOpret, tx.vout[v].nValue, voutPubkeys[0], voutPubkeys[1]); - + // check dual-eval 1 pubkey vout with the first pubkey + testDualVout = MakeTokensCC1vout(evalCodeInOpret, tx.vout[v].nValue, voutPubkeys[0]); if (tx.vout[v].scriptPubKey == testDualVout.scriptPubKey) { - if(voutPubkeys.size() == 1) - std::cerr << indentStr << "IsTokensvout() this is dual-eval token vout, eval2=" << (int)evalCodeInOpret << ", returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; - else - std::cerr << indentStr << "IsTokensvout() this is dual-eval token 1of2 vout or change, eval2=" << (int)evalCodeInOpret << ", returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; + std::cerr << indentStr << "IsTokensvout() this is one-eval token vout (i=0), eval2=" << (int)evalCodeInOpret << ", returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; return tx.vout[v].nValue; } + + if(voutPubkeys.size() == 2) { + // check dual eval 1of2 pubkeys vout + testDualVout = MakeTokensCC1of2vout(evalCodeInOpret, tx.vout[v].nValue, voutPubkeys[0], voutPubkeys[1]); + if (tx.vout[v].scriptPubKey == testDualVout.scriptPubKey) { + std::cerr << indentStr << "IsTokensvout() this is dual-eval token 1of2 vout, eval2=" << (int)evalCodeInOpret << ", returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; + return tx.vout[v].nValue; + } + + // check dual eval 1 pubkey vout with the second pubkey + testDualVout = MakeTokensCC1vout(evalCodeInOpret, tx.vout[v].nValue, voutPubkeys[1]); + if (tx.vout[v].scriptPubKey == testDualVout.scriptPubKey) { + std::cerr << indentStr << "IsTokensvout() this is dual-eval token vout (i=1), eval2=" << (int)evalCodeInOpret << ", returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; + return tx.vout[v].nValue; + } + } } // maybe this is claim to single-eval token? From c66787ada63fee0274dcf14510f13faae4f65388 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 15 Jan 2019 23:39:04 +0500 Subject: [PATCH 429/643] added support for 2 check pubkeys for single-eval token vouts --- src/cc/CCtokens.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 7296beaf2..5d25bdbaa 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -442,17 +442,23 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c return tx.vout[v].nValue; } } - } + - // maybe this is claim to single-eval token? - if (voutPubkeys.size() == 1) { + // maybe this is claim to single-eval token? CTxOut testTokenVout1; testTokenVout1 = MakeCC1vout(EVAL_TOKENS, tx.vout[v].nValue, voutPubkeys[0]); - if (tx.vout[v].scriptPubKey == testTokenVout1.scriptPubKey) { - std::cerr << indentStr << "IsTokensvout() this is single-eval token vout, returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; + std::cerr << indentStr << "IsTokensvout() this is single-eval token vout (i=0), returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; return tx.vout[v].nValue; } + + if (voutPubkeys.size() == 2) { + testTokenVout1 = MakeCC1vout(EVAL_TOKENS, tx.vout[v].nValue, voutPubkeys[1]); + if (tx.vout[v].scriptPubKey == testTokenVout1.scriptPubKey) { + std::cerr << indentStr << "IsTokensvout() this is single-eval token vout (i=1), returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; + return tx.vout[v].nValue; + } + } } // maybe it is single-eval or dual-eval token change? From dddda4e32b7132f5354fd3e69788883ed05ef4c7 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 15 Jan 2019 23:44:13 +0500 Subject: [PATCH 430/643] corr logging in IsTokensVout --- src/cc/CCtokens.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 5d25bdbaa..48172971f 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -423,7 +423,7 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c // check dual-eval 1 pubkey vout with the first pubkey testDualVout = MakeTokensCC1vout(evalCodeInOpret, tx.vout[v].nValue, voutPubkeys[0]); if (tx.vout[v].scriptPubKey == testDualVout.scriptPubKey) { - std::cerr << indentStr << "IsTokensvout() this is one-eval token vout (i=0), eval2=" << (int)evalCodeInOpret << ", returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; + std::cerr << indentStr << "IsTokensvout() this is dual-eval token vout (i=0), eval2=" << (int)evalCodeInOpret << ", returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; return tx.vout[v].nValue; } From ee848abde90130b90823e90e9b2e666d26748469 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 16 Jan 2019 11:45:21 +0500 Subject: [PATCH 431/643] corr mysingletokenscond in FinalizeCCtx (corr err message in rpc call) --- src/cc/CCtx.cpp | 2 +- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 7640b35bb..e3688b3bf 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -72,7 +72,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran cpTokens = CCinit(&tokensC, EVAL_TOKENS); GetCCaddress(cpTokens, mysingletokensaddr, mypk); - mysingletokenscond = MakeCCcond1(cpTokens->evalcode, mypk); + mysingletokenscond = MakeCCcond1(EVAL_TOKENS, mypk); unspendablepk = GetUnspendable(cp,unspendablepriv); GetCCaddress(cp,unspendable,unspendablepk); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 82870c941..6bc267e0f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -7346,7 +7346,7 @@ UniValue tokenfillask(const UniValue& params, bool fHelp) result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); } else { - ERR_RESULT("couldnt fill bid"); + ERR_RESULT("couldnt fill ask"); } } else { ERR_RESULT("fillunits must be positive"); From a7833f272f420041f6fe2b331798410f6a9b23c8 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 16 Jan 2019 12:12:41 +0500 Subject: [PATCH 432/643] added othertokenscond to FinalizeCCtx --- src/cc/CCassetstx.cpp | 11 ++++++++++- src/cc/CCtx.cpp | 21 +++++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 8dcde6e12..69a1b0c6f 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -618,7 +618,7 @@ std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t f //CPubKey unspendableTokensPk = GetUnspendable(cpTokens, NULL); uint8_t unspendableAssetsPrivkey[32]; - cpTokens = CCinit(&assetsC, EVAL_ASSETS); + cpTokens = CCinit(&assetsC, EVAL_ASSETS); //??? CPubKey unspendableAssetsPk = GetUnspendable(cpAssets, unspendableAssetsPrivkey); mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, bidamount - paid_amount, unspendableAssetsPk)); // vout0 coins remainder @@ -742,6 +742,15 @@ std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 askt //mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, CCchange, mypk)); //vout.3 coins in Assets cc addr (swap not implemented) } + uint8_t unspendableAssetsPrivkey[32]; + char unspendableAssetsAddr[64]; + // init 'unspenable' privkey and pubkey + CPubKey unspendableAssetsPk = GetUnspendable(cpAssets, unspendableAssetsPrivkey); + GetCCaddress(cpAssets, unspendableAssetsAddr, unspendableAssetsPk); + + // add additional unspendable addr from Assets: + CCaddr2set(cpAssets, EVAL_ASSETS, unspendableAssetsPk, unspendableAssetsPrivkey, unspendableAssetsAddr); + // vout verification pubkeys: std::vector voutTokenPubkeys; voutTokenPubkeys.push_back(mypk); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index e3688b3bf..46395815e 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -44,9 +44,9 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran CTransaction vintx; std::string hex; uint256 hashBlock; uint64_t mask=0,nmask=0,vinimask=0; int64_t utxovalues[CC_MAXVINS],change,normalinputs=0,totaloutputs=0,normaloutputs=0,totalinputs=0,normalvins=0,ccvins=0; int32_t i,utxovout,n,err = 0; - char myaddr[64], destaddr[64], unspendable[64], mytokensaddr[64], mysingletokensaddr[64]; + char myaddr[64], destaddr[64], unspendable[64], mytokensaddr[64], mysingletokensaddr[64], tokensunspendable[64]; uint8_t *privkey, myprivkey[32], unspendablepriv[32], *msg32 = 0; - CC *mycond=0, *othercond=0, *othercond2=0, *othercond3=0, *othercond1of2=NULL, *othercond1of2tokens = NULL, *cond, *mytokenscond = NULL, *mysingletokenscond = NULL; + CC *mycond=0, *othercond=0, *othercond2=0, *othercond3=0, *othercond1of2=NULL, *othercond1of2tokens = NULL, *cond, *mytokenscond = NULL, *mysingletokenscond = NULL, *othertokenscond = NULL; CPubKey unspendablepk; struct CCcontract_info *cpTokens, tokensC; @@ -74,9 +74,12 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran GetCCaddress(cpTokens, mysingletokensaddr, mypk); mysingletokenscond = MakeCCcond1(EVAL_TOKENS, mypk); - unspendablepk = GetUnspendable(cp,unspendablepriv); - GetCCaddress(cp,unspendable,unspendablepk); - othercond = MakeCCcond1(cp->evalcode,unspendablepk); + unspendablepk = GetUnspendable(cp, unspendablepriv); + GetCCaddress(cp, unspendable, unspendablepk); + othercond = MakeCCcond1(cp->evalcode, unspendablepk); + + GetTokensCCaddress(cp, tokensunspendable, unspendablepk); + othertokenscond = MakeTokensCCcond1(cp->evalcode, unspendablepk); //Reorder vins so that for multiple normal vins all other except vin0 goes to the end //This is a must to avoid hardfork change of validation in every CC, because there could be maximum one normal vin at the begining with current validation. @@ -165,8 +168,14 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { privkey = unspendablepriv; cond = othercond; - //fprintf(stderr,"FinalizeCCTx() unspendable CC addr.(%s)\n",unspendable); + //fprintf(stderr,"FinalizeCCTx() matched unspendable CC addr.(%s)\n",unspendable); } + else if (strcmp(destaddr, tokensunspendable) == 0) + { + privkey = unspendablepriv; + cond = othertokenscond; + fprintf(stderr,"FinalizeCCTx() matched tokensunspendable CC addr.(%s)\n",unspendable); + } // check if this is the 2nd additional evalcode + 'unspendable' cc addr: else if ( strcmp(destaddr,cp->unspendableaddr2) == 0) { From 406fc539257e26d65206a66111538f189fc613a5 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 16 Jan 2019 12:17:35 +0500 Subject: [PATCH 433/643] removed extra CCaddr2set --- src/cc/CCassetstx.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 69a1b0c6f..fc026d158 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -742,14 +742,14 @@ std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 askt //mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, CCchange, mypk)); //vout.3 coins in Assets cc addr (swap not implemented) } - uint8_t unspendableAssetsPrivkey[32]; + /* uint8_t unspendableAssetsPrivkey[32]; char unspendableAssetsAddr[64]; // init 'unspenable' privkey and pubkey CPubKey unspendableAssetsPk = GetUnspendable(cpAssets, unspendableAssetsPrivkey); GetCCaddress(cpAssets, unspendableAssetsAddr, unspendableAssetsPk); // add additional unspendable addr from Assets: - CCaddr2set(cpAssets, EVAL_ASSETS, unspendableAssetsPk, unspendableAssetsPrivkey, unspendableAssetsAddr); + CCaddr2set(cpAssets, EVAL_ASSETS, unspendableAssetsPk, unspendableAssetsPrivkey, unspendableAssetsAddr);*/ // vout verification pubkeys: std::vector voutTokenPubkeys; From 4903298fc311fcacdca6f728e09a63ff21c8c013 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 16 Jan 2019 14:11:29 +0500 Subject: [PATCH 434/643] corr tokesnunspenable priv and pk --- src/cc/CCtx.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 46395815e..56cc8a9ef 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -45,9 +45,9 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran int64_t utxovalues[CC_MAXVINS],change,normalinputs=0,totaloutputs=0,normaloutputs=0,totalinputs=0,normalvins=0,ccvins=0; int32_t i,utxovout,n,err = 0; char myaddr[64], destaddr[64], unspendable[64], mytokensaddr[64], mysingletokensaddr[64], tokensunspendable[64]; - uint8_t *privkey, myprivkey[32], unspendablepriv[32], *msg32 = 0; + uint8_t *privkey, myprivkey[32], unspendablepriv[32], tokensunspendablepriv[32], *msg32 = 0; CC *mycond=0, *othercond=0, *othercond2=0, *othercond3=0, *othercond1of2=NULL, *othercond1of2tokens = NULL, *cond, *mytokenscond = NULL, *mysingletokenscond = NULL, *othertokenscond = NULL; - CPubKey unspendablepk; + CPubKey unspendablepk, tokensunspendablepk; struct CCcontract_info *cpTokens, tokensC; n = mtx.vout.size(); @@ -78,8 +78,9 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran GetCCaddress(cp, unspendable, unspendablepk); othercond = MakeCCcond1(cp->evalcode, unspendablepk); - GetTokensCCaddress(cp, tokensunspendable, unspendablepk); - othertokenscond = MakeTokensCCcond1(cp->evalcode, unspendablepk); + tokensunspendablepk = GetUnspendable(cpTokens, tokensunspendablepriv); + GetTokensCCaddress(cp, tokensunspendable, tokensunspendablepk); + othertokenscond = MakeTokensCCcond1(cp->evalcode, tokensunspendablepk); //Reorder vins so that for multiple normal vins all other except vin0 goes to the end //This is a must to avoid hardfork change of validation in every CC, because there could be maximum one normal vin at the begining with current validation. From a16e80dac45cfbcc7df7b1ed8f8458dba9d1dbaa Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 16 Jan 2019 14:22:23 +0500 Subject: [PATCH 435/643] more corr in tokensunspendable --- src/cc/CCtx.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 56cc8a9ef..0463bf7c3 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -79,7 +79,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran othercond = MakeCCcond1(cp->evalcode, unspendablepk); tokensunspendablepk = GetUnspendable(cpTokens, tokensunspendablepriv); - GetTokensCCaddress(cp, tokensunspendable, tokensunspendablepk); + GetCCaddress(cpTokens, tokensunspendable, tokensunspendablepk); othertokenscond = MakeTokensCCcond1(cp->evalcode, tokensunspendablepk); //Reorder vins so that for multiple normal vins all other except vin0 goes to the end From f67a849be0bfdb7f78116ab74f96a81ae016e1ba Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 16 Jan 2019 14:27:45 +0500 Subject: [PATCH 436/643] corr CCaddr2set for tokens support in FillSell --- src/cc/CCassetstx.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index fc026d158..39a58146b 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -742,14 +742,14 @@ std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 askt //mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, CCchange, mypk)); //vout.3 coins in Assets cc addr (swap not implemented) } - /* uint8_t unspendableAssetsPrivkey[32]; + uint8_t unspendableAssetsPrivkey[32]; char unspendableAssetsAddr[64]; // init 'unspenable' privkey and pubkey CPubKey unspendableAssetsPk = GetUnspendable(cpAssets, unspendableAssetsPrivkey); GetCCaddress(cpAssets, unspendableAssetsAddr, unspendableAssetsPk); - // add additional unspendable addr from Assets: - CCaddr2set(cpAssets, EVAL_ASSETS, unspendableAssetsPk, unspendableAssetsPrivkey, unspendableAssetsAddr);*/ + // add additional dual-eval (assets+tokens) unspendable assets address's privkey: + CCaddr2set(cpAssets, EVAL_TOKENS, unspendableAssetsPk, unspendableAssetsPrivkey, unspendableAssetsAddr); // vout verification pubkeys: std::vector voutTokenPubkeys; From 457b9aff54e581c4aaa24c305f37b535885dafec Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 16 Jan 2019 14:41:39 +0500 Subject: [PATCH 437/643] more corr othertokenscond, set cp->unspendable --- src/cc/CCtx.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 0463bf7c3..2959ba7d7 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -47,7 +47,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran char myaddr[64], destaddr[64], unspendable[64], mytokensaddr[64], mysingletokensaddr[64], tokensunspendable[64]; uint8_t *privkey, myprivkey[32], unspendablepriv[32], tokensunspendablepriv[32], *msg32 = 0; CC *mycond=0, *othercond=0, *othercond2=0, *othercond3=0, *othercond1of2=NULL, *othercond1of2tokens = NULL, *cond, *mytokenscond = NULL, *mysingletokenscond = NULL, *othertokenscond = NULL; - CPubKey unspendablepk, tokensunspendablepk; + CPubKey unspendablepk /*, tokensunspendablepk*/; struct CCcontract_info *cpTokens, tokensC; n = mtx.vout.size(); @@ -66,21 +66,27 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran GetCCaddress(cp,myaddr,mypk); mycond = MakeCCcond1(cp->evalcode,mypk); - + + // to spend from single-eval evalcode 'unspendable' + unspendablepk = GetUnspendable(cp, unspendablepriv); + GetCCaddress(cp, unspendable, unspendablepk); + othercond = MakeCCcond1(cp->evalcode, unspendablepk); + + // tokens support: + + // to spend from dual-eval mypk vout GetTokensCCaddress(cp, mytokensaddr, mypk); mytokenscond = MakeTokensCCcond1(cp->evalcode, mypk); + // to spend from single-eval EVAL_TOKENS mypk cpTokens = CCinit(&tokensC, EVAL_TOKENS); GetCCaddress(cpTokens, mysingletokensaddr, mypk); mysingletokenscond = MakeCCcond1(EVAL_TOKENS, mypk); - unspendablepk = GetUnspendable(cp, unspendablepriv); - GetCCaddress(cp, unspendable, unspendablepk); - othercond = MakeCCcond1(cp->evalcode, unspendablepk); - - tokensunspendablepk = GetUnspendable(cpTokens, tokensunspendablepriv); - GetCCaddress(cpTokens, tokensunspendable, tokensunspendablepk); - othertokenscond = MakeTokensCCcond1(cp->evalcode, tokensunspendablepk); + // to spend from dual-eval EVAL_TOKEN+evalcode 'unspendable' pk + //tokensunspendablepk = GetUnspendable(cpTokens, tokensunspendablepriv); + GetTokensCCaddress(cp, tokensunspendable, unspendablepk); + othertokenscond = MakeTokensCCcond1(cp->evalcode, unspendablepk); //Reorder vins so that for multiple normal vins all other except vin0 goes to the end //This is a must to avoid hardfork change of validation in every CC, because there could be maximum one normal vin at the begining with current validation. @@ -147,7 +153,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { Getscriptaddress(destaddr,vintx.vout[utxovout].scriptPubKey); //fprintf(stderr,"FinalizeCCTx() vin.%d is CC %.8f -> (%s)\n",i,(double)utxovalues[i]/COIN,destaddr); - std::cerr << "FinalizeCCtx() destaddr=" << destaddr << " myaddr=" << myaddr << std::endl; + std::cerr << "FinalizeCCtx() searching destaddr=" << destaddr << " myaddr=" << myaddr << std::endl; if( strcmp(destaddr,myaddr) == 0 ) { privkey = myprivkey; From 029d3af05aefdc04d8862ef8ea81afb0f1431638 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 16 Jan 2019 15:16:30 +0500 Subject: [PATCH 438/643] add logging origpubkey to FillSell --- src/cc/CCassetstx.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 39a58146b..5b21fc1b1 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -652,7 +652,7 @@ std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t f // send coins, receive tokens -std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 asktxid,int64_t fillunits) +std::string FillSell(int64_t txfee, uint256 assetid, uint256 assetid2, uint256 asktxid, int64_t fillunits) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CTransaction vintx,filltx; @@ -685,7 +685,7 @@ std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 askt txfee = 10000; mypk = pubkey2pk(Mypubkey()); - if (AddNormalinputs(mtx,mypk,txfee,3) > 0) + if (AddNormalinputs(mtx, mypk, txfee, 3) > 0) { mask = ~((1LL << mtx.vin.size()) - 1); if (GetTransaction(asktxid, vintx, hashBlock, false) != 0) @@ -731,7 +731,7 @@ std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 askt //mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, paid_nValue, origpubkey)); //vout.2 tokens... (swap is not implemented yet) } else { - //std::cerr << "FillSell() paid_value=" << paid_nValue << " origpubkey=" << HexStr(pubkey2pk(origpubkey)) << std::endl; + std::cerr << "FillSell() paid_value=" << paid_nValue << " origpubkey=" << HexStr(pubkey2pk(origpubkey)) << std::endl; mtx.vout.push_back(CTxOut(paid_nValue, CScript() << origpubkey << OP_CHECKSIG)); //vout.2 coins normal to whom who asked token } From b807d8eb29b8a0eb2b74e3bc2e32ba3456193c8e Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 16 Jan 2019 15:29:39 +0500 Subject: [PATCH 439/643] corr dummy evalcode in DecodeAssetTokenOpRet --- src/cc/CCassetsCore.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index 9bd17cef8..09806a96c 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -325,14 +325,14 @@ uint8_t DecodeAssetTokenOpRet(const CScript &scriptPubKey, uint8_t &evalCodeInOp } break; case 's': case 'b': case 'S': case 'B': - if (E_UNMARSHAL(vopretExtra, ss >> dummyAssetFuncId; ss >> price; ss >> origpubkey) != 0) + if (E_UNMARSHAL(vopretExtra, ss >> dummyEvalCode; ss >> dummyAssetFuncId; ss >> price; ss >> origpubkey) != 0) { //fprintf(stderr,"got price %llu\n",(long long)price); return(assetFuncId); } break; case 'E': case 'e': - if ( E_UNMARSHAL(vopretExtra, ss >> dummyAssetFuncId; ss >> assetid2; ss >> price; ss >> origpubkey) != 0 ) + if ( E_UNMARSHAL(vopretExtra, ss >> dummyEvalCode; ss >> dummyAssetFuncId; ss >> assetid2; ss >> price; ss >> origpubkey) != 0 ) { //fprintf(stderr,"got price %llu\n",(long long)price); assetid2 = revuint256(assetid2); From 830b54cf20fa8bd68436129a9128a2ed4079bff6 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 16 Jan 2019 17:45:32 +0500 Subject: [PATCH 440/643] corr unmarshal vopretStripped --- src/cc/CCassetsCore.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index 09806a96c..a7ca074db 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -281,7 +281,7 @@ bool DecodeAssetCreateOpRet(const CScript &scriptPubKey, std::vector &o uint8_t DecodeAssetTokenOpRet(const CScript &scriptPubKey, uint8_t &evalCodeInOpret, uint256 &tokenid, uint256 &assetid2, int64_t &price, std::vector &origpubkey) { - std::vector vopretExtra; + std::vector vopretExtra, vopretStripped; uint8_t *script, funcId = 0, assetFuncId = 0, dummyEvalCode, dummyAssetFuncId; uint256 dummyTokenid; std::vector voutPubkeysDummy; @@ -307,9 +307,14 @@ uint8_t DecodeAssetTokenOpRet(const CScript &scriptPubKey, uint8_t &evalCodeInOp return (uint8_t)0; } + if (!E_UNMARSHAL(vopretExtra, { ss >> vopretStripped; })) { //strip string size + std::cerr << "DecodeAssetTokenOpRet() could not unmarshal vopretStripped" << std::endl; + return (uint8_t)0; + } + ////tokenid = revuint256(tokenid); already done in DecodeToken! - evalCodeInOpret = vopretExtra.begin()[0]; - assetFuncId = vopretExtra.begin()[1]; + evalCodeInOpret = vopretStripped.begin()[0]; + assetFuncId = vopretStripped.begin()[1]; //std::cerr << "DecodeAssetOpRet() evalCodeInOpret=" << (int)evalCodeInOpret << " funcId=" << (char)(funcId ? funcId : ' ') << " assetFuncId=" << (char)(assetFuncId ? assetFuncId : ' ') << std::endl; @@ -319,7 +324,7 @@ uint8_t DecodeAssetTokenOpRet(const CScript &scriptPubKey, uint8_t &evalCodeInOp switch( assetFuncId ) { case 'x': case 'o': - if (vopretExtra.size() == 1) // no data after 'assetFuncId' allowed + if (vopretExtra.size() == 2) // no data after 'evalcode assetFuncId' allowed { return(assetFuncId); } @@ -327,20 +332,20 @@ uint8_t DecodeAssetTokenOpRet(const CScript &scriptPubKey, uint8_t &evalCodeInOp case 's': case 'b': case 'S': case 'B': if (E_UNMARSHAL(vopretExtra, ss >> dummyEvalCode; ss >> dummyAssetFuncId; ss >> price; ss >> origpubkey) != 0) { - //fprintf(stderr,"got price %llu\n",(long long)price); + //fprintf(stderr,"DecodeAssetTokenOpRet got price %llu\n",(long long)price); return(assetFuncId); } break; case 'E': case 'e': if ( E_UNMARSHAL(vopretExtra, ss >> dummyEvalCode; ss >> dummyAssetFuncId; ss >> assetid2; ss >> price; ss >> origpubkey) != 0 ) { - //fprintf(stderr,"got price %llu\n",(long long)price); + //fprintf(stderr,"DecodeAssetTokenOpRet got price %llu\n",(long long)price); assetid2 = revuint256(assetid2); return(assetFuncId); } break; default: - fprintf(stderr,"DecodeAssetOpRet: illegal assetFuncId.%02x\n", assetFuncId); + fprintf(stderr,"DecodeAssetTokenOpRet: illegal assetFuncId.%02x\n", assetFuncId); //funcId = 0; break; } From dae431eaa52a4ca76024c3f35d8ede098d20a24d Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 16 Jan 2019 17:58:46 +0500 Subject: [PATCH 441/643] corr vopretStripped use in DecodeAssetsTokenOpret --- src/cc/CCassetsCore.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index a7ca074db..7084b1483 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -324,20 +324,20 @@ uint8_t DecodeAssetTokenOpRet(const CScript &scriptPubKey, uint8_t &evalCodeInOp switch( assetFuncId ) { case 'x': case 'o': - if (vopretExtra.size() == 2) // no data after 'evalcode assetFuncId' allowed + if (vopretStripped.size() == 2) // no data after 'evalcode assetFuncId' allowed { return(assetFuncId); } break; case 's': case 'b': case 'S': case 'B': - if (E_UNMARSHAL(vopretExtra, ss >> dummyEvalCode; ss >> dummyAssetFuncId; ss >> price; ss >> origpubkey) != 0) + if (E_UNMARSHAL(vopretStripped, ss >> dummyEvalCode; ss >> dummyAssetFuncId; ss >> price; ss >> origpubkey) != 0) { //fprintf(stderr,"DecodeAssetTokenOpRet got price %llu\n",(long long)price); return(assetFuncId); } break; case 'E': case 'e': - if ( E_UNMARSHAL(vopretExtra, ss >> dummyEvalCode; ss >> dummyAssetFuncId; ss >> assetid2; ss >> price; ss >> origpubkey) != 0 ) + if ( E_UNMARSHAL(vopretStripped, ss >> dummyEvalCode; ss >> dummyAssetFuncId; ss >> assetid2; ss >> price; ss >> origpubkey) != 0 ) { //fprintf(stderr,"DecodeAssetTokenOpRet got price %llu\n",(long long)price); assetid2 = revuint256(assetid2); From e23073fff52725a941a4bd6da8c71a57fd968353 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Wed, 16 Jan 2019 14:05:54 +0100 Subject: [PATCH 442/643] Channels adaptation to TokensCC (#3) * Initial changes * ChannelsCC adaptation * Fix * Fix * Fix * Fix * Fix * Fix * Fix * Fix * Fix * Fix --- src/cc/CCchannels.h | 2 +- src/cc/CCinclude.h | 3 + src/cc/CCtokens.cpp | 8 +- src/cc/channels.cpp | 353 ++++++++++++++++++++++----------------- src/wallet/rpcwallet.cpp | 15 +- 5 files changed, 217 insertions(+), 164 deletions(-) diff --git a/src/cc/CCchannels.h b/src/cc/CCchannels.h index 49b4a7adf..10cb4d224 100644 --- a/src/cc/CCchannels.h +++ b/src/cc/CCchannels.h @@ -21,7 +21,7 @@ #define CHANNELS_MAXPAYMENTS 1000 bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); -std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64_t payment); +std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64_t payment,uint256 tokenid); std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint256 secret); std::string ChannelClose(uint64_t txfee,uint256 opentxid); std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid); diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 03af2f92d..d134d9037 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -59,6 +59,9 @@ extern std::string CCerror; #define CC_MAXVINS 1024 #define SMALLVAL 0.000000000000001 +#define SATOSHIDEN ((uint64_t)100000000L) +#define dstr(x) ((double)(x) / SATOSHIDEN) + #ifndef _BITS256 #define _BITS256 union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 48172971f..57aeb4369 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -714,10 +714,10 @@ int64_t GetTokenBalance(CPubKey pk, uint256 tokenid) CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CTransaction tokentx; - CCerror = strprintf("obsolete, cannot return correct value without eval"); - return 0; + // CCerror = strprintf("obsolete, cannot return correct value without eval"); + // return 0; -/* if (GetTransaction(tokenid, tokentx, hashBlock, false) == 0) + if (GetTransaction(tokenid, tokentx, hashBlock, false) == 0) { fprintf(stderr, "cant find tokenid\n"); CCerror = strprintf("cant find tokenid"); @@ -726,7 +726,7 @@ int64_t GetTokenBalance(CPubKey pk, uint256 tokenid) struct CCcontract_info *cp, C; cp = CCinit(&C, EVAL_TOKENS); - return(AddTokenCCInputs(cp, mtx, pk, tokenid, 0, 0)); */ + return(AddTokenCCInputs(cp, mtx, pk, tokenid, 0, 0)); } UniValue TokenInfo(uint256 tokenid) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index d516d0144..2a7ebc931 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -64,15 +64,16 @@ Possible third iteration: int64_t IsChannelsvout(struct CCcontract_info *cp,const CTransaction& tx,CPubKey srcpub, CPubKey destpub,int32_t v) { - char destaddr[65],channeladdr[65]; + char destaddr[65],channeladdr[65],tokenschanneladdr[65]; GetCCaddress1of2(cp,channeladdr,srcpub,destpub); + GetTokensCCaddress1of2(cp,tokenschanneladdr,srcpub,destpub); if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) { - if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && strcmp(destaddr,channeladdr) == 0 ) + if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && (strcmp(destaddr,channeladdr) == 0 || strcmp(destaddr,tokenschanneladdr) == 0)) return(tx.vout[v].nValue); } - return(0); + return(0); } int64_t IsChannelsMarkervout(struct CCcontract_info *cp,const CTransaction& tx,CPubKey pubkey,int32_t v) @@ -88,17 +89,31 @@ int64_t IsChannelsMarkervout(struct CCcontract_info *cp,const CTransaction& tx,C return(0); } -CScript EncodeChannelsOpRet(uint8_t funcid,uint256 opentxid,CPubKey srcpub,CPubKey destpub,int32_t numpayments,int64_t payment,uint256 hashchain) +CScript EncodeChannelsOpRet(uint8_t funcid,uint256 tokenid,uint256 opentxid,CPubKey srcpub,CPubKey destpub,int32_t numpayments,int64_t payment,uint256 hashchain) { CScript opret; uint8_t evalcode = EVAL_CHANNELS; + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << opentxid << srcpub << destpub << numpayments << payment << hashchain); + if (tokenid!=zeroid) + { + std::vector pks; + pks.push_back(srcpub); + pks.push_back(destpub); + return(EncodeTokenOpRet(tokenid,pks,opret)); + } return(opret); } -uint8_t DecodeChannelsOpRet(const CScript &scriptPubKey,uint256 &opentxid, CPubKey &srcpub,CPubKey &destpub,int32_t &numpayments,int64_t &payment,uint256 &hashchain) +uint8_t DecodeChannelsOpRet(const CScript &scriptPubKey, uint256 &tokenid, uint256 &opentxid, CPubKey &srcpub,CPubKey &destpub,int32_t &numpayments,int64_t &payment,uint256 &hashchain) { - std::vector vopret; uint8_t *script,e,f; - GetOpReturnData(scriptPubKey, vopret); + std::vector vopret; uint8_t *script,e,f,tokenevalcode; + std::vector pubkeys; std::vector vOpretExtra; + + if (DecodeTokenOpRet(scriptPubKey,tokenevalcode,tokenid,pubkeys,vOpretExtra)!=0 && tokenevalcode==EVAL_TOKENS && vOpretExtra.size()>0) + { + if (!E_UNMARSHAL(vOpretExtra, { ss >> vopret; })) return (0); + } + else GetOpReturnData(scriptPubKey, vopret); if ( vopret.size() > 2 ) { script = (uint8_t *)vopret.data(); @@ -115,46 +130,56 @@ uint8_t DecodeChannelsOpRet(const CScript &scriptPubKey,uint256 &opentxid, CPubK bool ChannelsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { - static uint256 zerohash; - uint256 txid,param3; + uint256 txid,param3,tokenid; CPubKey srcpub,destpub; - int32_t param1; int64_t param2; uint8_t funcid; - CTransaction vinTx; uint256 hashBlock; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; - numvins = tx.vin.size(); - numvouts = tx.vout.size(); + int32_t param1,numvouts; int64_t param2; uint8_t funcid; + CTransaction vinTx; uint256 hashBlock; int64_t inputs=0,outputs=0; - if ((numvouts=tx.vout.size()) > 0 && DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, param1, param2, param3)!=0) - { - for (i=0; i 0 && (funcid=DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey, tokenid, txid, srcpub, destpub, param1, param2, param3))!=0) + { + switch (funcid) { - if ( eval->GetTxUnconfirmed(tx.vin[i].prevout.hash,vinTx,hashBlock) == 0 ) - return eval->Invalid("cant find vinTx"); - else - { - inputs += vinTx.vout[tx.vin[i].prevout.n].nValue; - } + case 'O': + return (true); + case 'P': + if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) + return eval->Invalid("cant find vinTx"); + inputs = vinTx.vout[tx.vin[1].prevout.n].nValue; + outputs = tx.vout[0].nValue + tx.vout[3].nValue; + break; + case 'C': + if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) + return eval->Invalid("cant find vinTx"); + inputs = vinTx.vout[tx.vin[1].prevout.n].nValue; + outputs = tx.vout[0].nValue; + break; + case 'R': + if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) + return eval->Invalid("cant find vinTx"); + inputs = vinTx.vout[tx.vin[1].prevout.n].nValue; + outputs = tx.vout[2].nValue; + break; + default: + return (false); } + if ( inputs != outputs ) + { + fprintf(stderr,"inputs %llu vs outputs %llu\n",(long long)inputs,(long long)outputs); + return eval->Invalid("mismatched inputs != outputs"); + } + else return (true); } else { return eval->Invalid("invalid op_return data"); } - for (i=0; iInvalid("mismatched inputs != outputs + txfee"); - } - else return(true); + return(false); } bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numpayments,p1,param1; bool retval; - uint256 txid,hashblock,p3,param3,opentxid,tmp_txid,genhashchain,hashchain; + uint256 txid,hashblock,p3,param3,opentxid,tmp_txid,genhashchain,hashchain,tokenid; uint8_t funcid,hash[32],hashdest[32]; int64_t p2,param2,payment; CPubKey srcpub, destpub; @@ -169,15 +194,13 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & { if (ChannelsExactAmounts(cp,eval,tx,1,10000) == false ) { - fprintf(stderr,"Channelsget invalid amount\n"); - return false; + return eval->Invalid("invalid channel inputs vs. outputs!"); } else { txid = tx.GetHash(); memcpy(hash,&txid,sizeof(hash)); - - if ( (funcid = DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey, opentxid, srcpub, destpub, param1, param2, param3)) != 0) + if ( (funcid = DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey, tokenid, opentxid, srcpub, destpub, param1, param2, param3)) != 0) { switch ( funcid ) { @@ -213,9 +236,13 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return eval->Invalid("vout.1 is CC for channelPayment (marker to srcPub)!"); else if ( IsChannelsMarkervout(cp,tx,destpub,2)==0 ) return eval->Invalid("vout.2 is CC for channelPayment (marker to dstPub)!"); - else if ( tx.vout[3].scriptPubKey.IsPayToCryptoCondition() != 0 ) + else if ( tokenid!=zeroid && tx.vout[3].scriptPubKey.IsPayToCryptoCondition() == 0 ) + return eval->Invalid("vout.3 is CC for channelPayment!"); + else if ( tokenid==zeroid && tx.vout[3].scriptPubKey.IsPayToCryptoCondition() != 0 ) return eval->Invalid("vout.3 is normal for channelPayment!"); - else if ( tx.vout[3].scriptPubKey!=CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG) + else if ( tokenid!=zeroid && tx.vout[3].scriptPubKey!=MakeCC1vout(EVAL_TOKENS,tx.vout[3].nValue,destpub).scriptPubKey) + return eval->Invalid("payment funds do not go to receiver!"); + else if ( tokenid==zeroid && tx.vout[3].scriptPubKey!=CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG) return eval->Invalid("payment funds do not go to receiver!"); else if ( param1 > CHANNELS_MAXPAYMENTS) return eval->Invalid("too many payment increments!"); @@ -223,7 +250,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & { if (myGetTransaction(opentxid,channelOpenTx,hashblock) != 0) { - if ((numvouts=channelOpenTx.vout.size()) > 0 && (funcid=DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, numpayments, payment, hashchain)) != 0 && funcid!='O') + if ((numvouts=channelOpenTx.vout.size()) > 0 && (funcid=DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, tokenid, tmp_txid, srcpub, destpub, numpayments, payment, hashchain)) != 0 && funcid!='O') return eval->Invalid("invalid channelopen OP_RETURN data!"); endiancpy(hash, (uint8_t * ) & param3, 32); for (i = 0; i < numpayments-param1; i++) @@ -239,7 +266,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & } if (myGetTransaction(tx.vin[1].prevout.hash,prevTx,hashblock) != 0) { - if ((numvouts=prevTx.vout.size()) > 0 && DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, p1, p2, p3) == 0) + if ((numvouts=prevTx.vout.size()) > 0 && DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, tokenid, tmp_txid, srcpub, destpub, p1, p2, p3) == 0) return eval->Invalid("invalid previous tx OP_RETURN data!"); else if (tx.vout[1].scriptPubKey != prevTx.vout[1].scriptPubKey) return eval->Invalid("invalid destination for sender marker!"); @@ -279,13 +306,13 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return eval->Invalid("too many payment increments!"); else if (myGetTransaction(opentxid,channelOpenTx,hashblock) == 0) return eval->Invalid("invalid open txid!"); - else if ((numvouts=channelOpenTx.vout.size()) > 0 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, numpayments, payment, hashchain) != 'O') + else if ((numvouts=channelOpenTx.vout.size()) > 0 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, tokenid, tmp_txid, srcpub, destpub, numpayments, payment, hashchain) != 'O') return eval->Invalid("invalid channelopen OP_RETURN data!"); else if (tx.vout[0].nValue != param1*payment) return eval->Invalid("vout amount does not match number_of_payments*payment!"); else if (myGetTransaction(tx.vin[1].prevout.hash,prevTx,hashblock) != 0) { - if ((numvouts=prevTx.vout.size()) > 0 && DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, p1, p2, p3) == 0) + if ((numvouts=prevTx.vout.size()) > 0 && DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, tokenid, tmp_txid, srcpub, destpub, p1, p2, p3) == 0) return eval->Invalid("invalid previous tx OP_RETURN data!"); else if (tx.vout[1].scriptPubKey != prevTx.vout[1].scriptPubKey) return eval->Invalid("invalid destination for sender marker!"); @@ -318,19 +345,23 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return eval->Invalid("vout.0 is CC for channelRefund (marker to srcPub)!"); else if ( IsChannelsMarkervout(cp,tx,destpub,1)==0 ) return eval->Invalid("vout.1 is CC for channelRefund (marker to dstPub)!"); - else if ( tx.vout[2].scriptPubKey.IsPayToCryptoCondition() != 0 ) - return eval->Invalid("vout.2 is normal for channelRefund!"); - else if ( tx.vout[2].scriptPubKey!=CScript() << ParseHex(HexStr(srcpub)) << OP_CHECKSIG) + else if ( tokenid!=zeroid && tx.vout[2].scriptPubKey.IsPayToCryptoCondition() == 0 ) + return eval->Invalid("vout.2 is CC for channelPayment!"); + else if ( tokenid==zeroid && tx.vout[2].scriptPubKey.IsPayToCryptoCondition() != 0 ) + return eval->Invalid("vout.2 is normal for channelPayment!"); + else if ( tokenid!=zeroid && tx.vout[2].scriptPubKey!=MakeCC1vout(EVAL_TOKENS,tx.vout[2].nValue,srcpub).scriptPubKey) + return eval->Invalid("payment funds do not go to sender!"); + else if ( tokenid==zeroid && tx.vout[2].scriptPubKey!=CScript() << ParseHex(HexStr(srcpub)) << OP_CHECKSIG) return eval->Invalid("payment funds do not go to sender!"); else if ( param1 > CHANNELS_MAXPAYMENTS) return eval->Invalid("too many payment increments!"); else if (myGetTransaction(opentxid,channelOpenTx,hashblock) == 0) return eval->Invalid("invalid open txid!"); - else if ((numvouts=channelOpenTx.vout.size()) > 0 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, numpayments, payment, hashchain) != 'O') + else if ((numvouts=channelOpenTx.vout.size()) > 0 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, tokenid, tmp_txid, srcpub, destpub, numpayments, payment, hashchain) != 'O') return eval->Invalid("invalid channelopen OP_RETURN data!"); else if (myGetTransaction(param3,channelCloseTx,hashblock) == 0) return eval->Invalid("invalid close txid!"); - else if ((numvouts=channelCloseTx.vout.size()) > 0 && DecodeChannelsOpRet(channelCloseTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, param1, param2, param3) != 'C') + else if ((numvouts=channelCloseTx.vout.size()) > 0 && DecodeChannelsOpRet(channelCloseTx.vout[numvouts-1].scriptPubKey, tokenid, tmp_txid, srcpub, destpub, param1, param2, param3) != 'C') return eval->Invalid("invalid channelclose OP_RETURN data!"); else if (tmp_txid!=opentxid) return eval->Invalid("invalid close tx, opentxid do not match on close and refund!"); @@ -338,7 +369,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return eval->Invalid("vout amount does not match number_of_payments*payment!"); else if (myGetTransaction(tx.vin[1].prevout.hash,prevTx,hashblock) != 0) { - if ((numvouts=prevTx.vout.size()) > 0 && DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, p1, p2, p3) == 0) + if ((numvouts=prevTx.vout.size()) > 0 && DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, tokenid, tmp_txid, srcpub, destpub, p1, p2, p3) == 0) return eval->Invalid("invalid previous tx OP_RETURN data!"); else if (tx.vout[0].scriptPubKey != prevTx.vout[1].scriptPubKey) return eval->Invalid("invalid destination for sender marker!"); @@ -351,9 +382,9 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & default: fprintf(stderr,"illegal channels funcid.(%c)\n",funcid); return eval->Invalid("unexpected channels funcid"); - break; } - } else return eval->Invalid("unexpected channels missing funcid"); + } + else return eval->Invalid("unexpected channels missing funcid"); retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); if ( retval != 0 ) fprintf(stderr,"Channel tx validated\n"); @@ -368,14 +399,15 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, CTransaction openTx, uint256 &prevtxid, CPubKey mypk) { - char coinaddr[65]; int64_t param2,totalinputs = 0,numvouts; uint256 txid=zeroid,tmp_txid,hashBlock,param3; CTransaction tx; int32_t marker,param1; + char coinaddr[65]; int64_t param2,totalinputs = 0,numvouts; uint256 txid=zeroid,tmp_txid,hashBlock,param3,tokenid; CTransaction tx; int32_t marker,param1; std::vector > unspentOutputs; CPubKey srcpub,destpub; uint8_t myprivkey[32]; - if ((numvouts=openTx.vout.size()) > 0 && DecodeChannelsOpRet(openTx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)=='O') + if ((numvouts=openTx.vout.size()) > 0 && DecodeChannelsOpRet(openTx.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3)=='O') { - GetCCaddress1of2(cp,coinaddr,srcpub,destpub); + if (tokenid!=zeroid) GetTokensCCaddress1of2(cp,coinaddr,srcpub,destpub); + else GetCCaddress1of2(cp,coinaddr,srcpub,destpub); SetCCunspents(unspentOutputs,coinaddr); } else @@ -389,7 +421,7 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C { if ( (int32_t)it->first.index==0 && GetTransaction(it->first.txhash,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size()) > 0) { - if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)!=0 && + if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3)!=0 && (tmp_txid==openTx.GetHash() || tx.GetHash()==openTx.GetHash()) && (totalinputs=IsChannelsvout(cp,tx,srcpub,destpub,0)+IsChannelsMarkervout(cp,tx,srcpub,marker))>0) { @@ -407,7 +439,7 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C const CTransaction &txmempool = e.GetTx(); const uint256 &hash = txmempool.GetHash(); - if ((numvouts=txmempool.vout.size()) > 0 && DecodeChannelsOpRet(txmempool.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3) != 0 && + if ((numvouts=txmempool.vout.size()) > 0 && DecodeChannelsOpRet(txmempool.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3) != 0 && tmp_txid==openTx.GetHash() && param1 < mindepth) { txid=hash; @@ -421,19 +453,19 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C prevtxid=txid; mtx.vin.push_back(CTxIn(txid,0,CScript())); mtx.vin.push_back(CTxIn(txid,marker,CScript())); - Myprivkey(myprivkey); - CCaddr2set(cp,EVAL_CHANNELS,srcpub,myprivkey,coinaddr); - CCaddr3set(cp,EVAL_CHANNELS,destpub,myprivkey,coinaddr); + Myprivkey(myprivkey); + if (tokenid!=zeroid) CCaddrTokens1of2set(cp,srcpub,destpub,coinaddr); + else CCaddr1of2set(cp,srcpub,destpub,coinaddr); return totalinputs; } else return 0; } -std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64_t payment) +std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64_t payment, uint256 tokenid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - uint8_t hash[32],hashdest[32]; uint64_t funds; int32_t i; uint256 hashchain,entropy,hentropy; - CPubKey mypk; struct CCcontract_info *cp,C; + uint8_t hash[32],hashdest[32]; uint64_t amount,tokens=0,funds; int32_t i; uint256 hashchain,entropy,hentropy; + CPubKey mypk; struct CCcontract_info *cp,*cpTokens,C,CTokens; if ( numpayments <= 0 || payment <= 0 || numpayments > CHANNELS_MAXPAYMENTS ) { @@ -442,11 +474,18 @@ std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64 return(""); } cp = CCinit(&C,EVAL_CHANNELS); + cpTokens = CCinit(&CTokens,EVAL_TOKENS); if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); funds = numpayments * payment; - if ( AddNormalinputs(mtx,mypk,funds+3*txfee,64) > 0 ) + if (tokenid!=zeroid) + { + amount=AddNormalinputs(mtx,mypk,3*txfee,5); + tokens=AddTokenCCInputs(cpTokens, mtx, mypk, tokenid, funds, 64); + } + else amount=AddNormalinputs(mtx,mypk,funds+3*txfee,64); + if (amount+tokens >= funds+2*txfee) { hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash,mtx.vin[0].prevout.n,1); endiancpy(hash,(uint8_t *)&hentropy,32); @@ -456,10 +495,12 @@ std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64 memcpy(hash,hashdest,32); } endiancpy((uint8_t *)&hashchain,hashdest,32); - mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS,funds,mypk,destpub)); + if (tokenid!=zeroid) mtx.vout.push_back(MakeTokensCC1of2vout(EVAL_CHANNELS,funds,mypk,destpub)); + else mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS,funds,mypk,destpub)); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,destpub)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('O',zeroid,mypk,destpub,numpayments,payment,hashchain))); + if (tokenid!=zeroid && tokens>funds) mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS,tokens-funds,mypk)); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('O',tokenid,zeroid,mypk,destpub,numpayments,payment,hashchain))); } return(""); } @@ -467,7 +508,7 @@ std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64 std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint256 secret) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,srcpub,destpub; uint256 txid,hashchain,gensecret,hashblock,entropy,hentropy,prevtxid,param3; + CPubKey mypk,srcpub,destpub; uint256 txid,hashchain,gensecret,hashblock,entropy,hentropy,prevtxid,param3,tokenid; struct CCcontract_info *cp,C; int32_t i,funcid,prevdepth,numvouts,numpayments,totalnumpayments; int64_t payment,change,funds,param2; uint8_t hash[32],hashdest[32]; @@ -482,83 +523,85 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 fprintf(stderr, "invalid channel open txid\n"); return (""); } + if ((numvouts=channelOpenTx.vout.size()) > 0 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, tokenid, txid, srcpub, destpub, totalnumpayments, payment, hashchain)=='O') + { + if (mypk != srcpub && mypk != destpub) + { + fprintf(stderr,"this is not our channel\n"); + return(""); + } + else if (amount % payment != 0 || amount 0) { if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid,mypk)) !=0 && (change=funds-amount-txfee)>=0) - { - if ((numvouts=channelOpenTx.vout.size()) > 0 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, totalnumpayments, payment, hashchain)=='O') + { + numpayments=amount/payment; + if (GetTransaction(prevtxid,prevTx,hashblock,false) != 0 && (numvouts=prevTx.vout.size()) > 0 && + ((funcid = DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, tokenid, txid, srcpub, destpub, prevdepth, param2, param3)) != 0) && + (funcid == 'P' || funcid=='O')) { - if (mypk != srcpub && mypk != destpub) + if (numpayments > prevdepth) { - fprintf(stderr,"this is not our channel\n"); - return(""); - } - else if (amount % payment != 0 || amount 0 && - ((funcid = DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, prevdepth, param2, param3)) != 0) && - (funcid == 'P' || funcid=='O')) + if (secret!=zeroid) { - if (numpayments > prevdepth) + endiancpy(hash, (uint8_t * ) & secret, 32); + for (i = 0; i < totalnumpayments-(prevdepth-numpayments); i++) { - fprintf(stderr,"not enough funds in channel for that amount\n"); - return (""); - } else if (numpayments == 0) - { - fprintf(stderr,"invalid amount\n"); - return (""); + vcalc_sha256(0, hashdest, hash, 32); + memcpy(hash, hashdest, 32); } - if (secret!=zeroid) + endiancpy((uint8_t * ) & gensecret, hashdest, 32); + if (gensecret!=hashchain) { - endiancpy(hash, (uint8_t * ) & secret, 32); - for (i = 0; i < totalnumpayments-(prevdepth-numpayments); i++) - { - vcalc_sha256(0, hashdest, hash, 32); - memcpy(hash, hashdest, 32); - } - endiancpy((uint8_t * ) & gensecret, hashdest, 32); - if (gensecret!=hashchain) - { - fprintf(stderr,"invalid secret supplied\n"); - return(""); - } - } - else - { - hentropy = DiceHashEntropy(entropy,channelOpenTx.vin[0].prevout.hash,channelOpenTx.vin[0].prevout.n,1); - if (prevdepth-numpayments) - { - endiancpy(hash, (uint8_t * ) & hentropy, 32); - for (i = 0; i < prevdepth-numpayments; i++) - { - vcalc_sha256(0, hashdest, hash, 32); - memcpy(hash, hashdest, 32); - } - endiancpy((uint8_t * ) & secret, hashdest, 32); - } - else endiancpy((uint8_t * ) & secret, (uint8_t * ) & hentropy, 32); + fprintf(stderr,"invalid secret supplied\n"); + return(""); } } else { - fprintf(stderr,"invalid previous tx\n"); - return(""); + hentropy = DiceHashEntropy(entropy,channelOpenTx.vin[0].prevout.hash,channelOpenTx.vin[0].prevout.n,1); + if (prevdepth-numpayments) + { + endiancpy(hash, (uint8_t * ) & hentropy, 32); + for (i = 0; i < prevdepth-numpayments; i++) + { + vcalc_sha256(0, hashdest, hash, 32); + memcpy(hash, hashdest, 32); + } + endiancpy((uint8_t * ) & secret, hashdest, 32); + } + else endiancpy((uint8_t * ) & secret, (uint8_t * ) & hentropy, 32); } } else { - fprintf(stderr, "invalid channel open tx\n"); - return (""); - } - mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS, change, srcpub, destpub)); + fprintf(stderr,"invalid previous tx\n"); + return(""); + } + if (tokenid!=zeroid) mtx.vout.push_back(MakeTokensCC1of2vout(EVAL_CHANNELS, change, srcpub, destpub)); + else mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS, change, srcpub, destpub)); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,srcpub)); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,destpub)); - mtx.vout.push_back(CTxOut(amount, CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG)); - return (FinalizeCCTx(0, cp, mtx, mypk, txfee, EncodeChannelsOpRet('P', opentxid, srcpub, destpub, prevdepth-numpayments, numpayments, secret))); + if (tokenid!=zeroid) mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, amount, destpub)); + else mtx.vout.push_back(CTxOut(amount, CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG)); + return (FinalizeCCTx(0, cp, mtx, mypk, txfee, EncodeChannelsOpRet('P', tokenid, opentxid, srcpub, destpub, prevdepth-numpayments, numpayments, secret))); } else { @@ -575,7 +618,7 @@ std::string ChannelClose(uint64_t txfee,uint256 opentxid) CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CPubKey mypk,srcpub,destpub; struct CCcontract_info *cp,C; CTransaction channelOpenTx; - uint256 hashblock,tmp_txid,prevtxid,hashchain; + uint256 hashblock,tmp_txid,prevtxid,hashchain,tokenid; int32_t numvouts,numpayments; int64_t payment,funds; @@ -589,7 +632,7 @@ std::string ChannelClose(uint64_t txfee,uint256 opentxid) fprintf(stderr, "invalid channel open txid\n"); return (""); } - if ((numvouts=channelOpenTx.vout.size()) < 1 || DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,numpayments,payment,hashchain)!='O') + if ((numvouts=channelOpenTx.vout.size()) < 1 || DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,numpayments,payment,hashchain)!='O') { fprintf(stderr, "invalid channel open tx\n"); return (""); @@ -603,10 +646,11 @@ std::string ChannelClose(uint64_t txfee,uint256 opentxid) { if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid,mypk)) !=0 && funds-txfee>0) { - mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS, funds-txfee, mypk, destpub)); + if (tokenid!=zeroid) mtx.vout.push_back(MakeTokensCC1of2vout(EVAL_CHANNELS, funds-txfee, mypk, destpub)); + else mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS, funds-txfee, mypk, destpub)); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,destpub)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('C',opentxid,mypk,destpub,(funds-txfee)/payment,payment,zeroid))); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('C',tokenid,opentxid,mypk,destpub,(funds-txfee)/payment,payment,zeroid))); } else { @@ -623,10 +667,9 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CPubKey mypk; struct CCcontract_info *cp,C; int64_t funds,payment,param2; int32_t i,numpayments,numvouts,param1; - uint256 hashchain,hashblock,txid,prevtxid,param3,entropy,hentropy,secret; + uint256 hashchain,hashblock,txid,prevtxid,param3,tokenid; CTransaction channelOpenTx,channelCloseTx,prevTx; CPubKey srcpub,destpub; - uint8_t funcid,hash[32],hashdest[32];; // verify stoptxid and origtxid match and are mine cp = CCinit(&C,EVAL_CHANNELS); @@ -638,7 +681,7 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) fprintf(stderr, "invalid channel close txid\n"); return (""); } - if ((numvouts=channelCloseTx.vout.size()) < 1 || DecodeChannelsOpRet(channelCloseTx.vout[numvouts-1].scriptPubKey,txid,srcpub,destpub,param1,param2,param3)!='C') + if ((numvouts=channelCloseTx.vout.size()) < 1 || DecodeChannelsOpRet(channelCloseTx.vout[numvouts-1].scriptPubKey,tokenid,txid,srcpub,destpub,param1,param2,param3)!='C') { fprintf(stderr, "invalid channel close tx\n"); return (""); @@ -653,7 +696,7 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) fprintf(stderr, "invalid channel open txid\n"); return (""); } - if ((numvouts=channelOpenTx.vout.size()) < 1 || DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey,txid,srcpub,destpub,numpayments,payment,hashchain)!='O') + if ((numvouts=channelOpenTx.vout.size()) < 1 || DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey,tokenid,txid,srcpub,destpub,numpayments,payment,hashchain)!='O') { fprintf(stderr, "invalid channel open tx\n"); return (""); @@ -668,20 +711,13 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid,mypk)) !=0 && funds-txfee>0) { if ((GetTransaction(prevtxid,prevTx,hashblock,false) != 0) && (numvouts=prevTx.vout.size()) > 0 && - DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, param1, param2, param3) != 0) + DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, tokenid, txid, srcpub, destpub, param1, param2, param3) != 0) { - hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash, channelOpenTx.vin[0].prevout.n,1); - endiancpy(hash, (uint8_t * ) & hentropy, 32); - for (i = 0; i < param1; i++) - { - vcalc_sha256(0, hashdest, hash, 32); - memcpy(hash, hashdest, 32); - } - endiancpy((uint8_t * ) & secret, hashdest, 32); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,destpub)); - mtx.vout.push_back(CTxOut(funds-txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('R',opentxid,mypk,destpub,param1,payment,closetxid))); + if (tokenid!=zeroid) mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS,funds-txfee,mypk)); + else mtx.vout.push_back(CTxOut(funds-txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('R',tokenid,opentxid,mypk,destpub,param1,payment,closetxid))); } else { @@ -699,7 +735,7 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) } UniValue ChannelsList() { - UniValue result(UniValue::VOBJ); std::vector > txids; struct CCcontract_info *cp,C; uint256 txid,hashBlock,tmp_txid,param3; + UniValue result(UniValue::VOBJ); std::vector > txids; struct CCcontract_info *cp,C; uint256 txid,hashBlock,tmp_txid,param3,tokenid; CTransaction tx; char myCCaddr[65],addr[65],str[256]; CPubKey mypk,srcpub,destpub; int32_t vout,numvouts,param1; int64_t nValue,param2; @@ -716,7 +752,7 @@ UniValue ChannelsList() nValue = (int64_t)it->second; if ( (vout == 1 || vout == 2) && nValue == 10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) { - if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3) == 'O') + if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3) == 'O') { GetCCaddress1of2(cp,addr,srcpub,destpub); sprintf(str,"%s - %lld payments of %lld satoshi",addr,(long long)param1,(long long)param2); @@ -729,16 +765,16 @@ UniValue ChannelsList() UniValue ChannelsInfo(uint256 channeltxid) { - UniValue result(UniValue::VOBJ),array(UniValue::VARR); CTransaction tx,opentx; uint256 txid,tmp_txid,hashBlock,param3,opentxid,hashchain,prevtxid; + UniValue result(UniValue::VOBJ),array(UniValue::VARR); CTransaction tx,opentx; uint256 txid,tmp_txid,hashBlock,param3,opentxid,hashchain,prevtxid,tokenid; struct CCcontract_info *cp,C; char CCaddr[65],addr[65],str[512]; int32_t vout,numvouts,param1,numpayments; - int64_t nValue,param2,payment; CPubKey srcpub,destpub,mypk; + int64_t param2,payment; CPubKey srcpub,destpub,mypk; std::vector > addressIndex; std::vector txids; cp = CCinit(&C,EVAL_CHANNELS); mypk = pubkey2pk(Mypubkey()); if (GetTransaction(channeltxid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 && - (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'O')) + (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,opentxid,srcpub,destpub,param1,param2,param3) == 'O')) { GetCCaddress(cp,CCaddr,mypk); Getscriptaddress(addr,CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG); @@ -746,13 +782,22 @@ UniValue ChannelsInfo(uint256 channeltxid) result.push_back(Pair("Channel CC address",CCaddr)); result.push_back(Pair("Destination address",addr)); result.push_back(Pair("Number of payments",param1)); - result.push_back(Pair("Denomination",i64tostr(param2)+" satoshi")); - result.push_back(Pair("Amount",i64tostr(param1*param2)+" satoshi")); + if(tokenid!=zeroid) + { + result.push_back(Pair("Token id",tokenid.GetHex().data())); + result.push_back(Pair("Denomination (token satoshi)",i64tostr(param2))); + result.push_back(Pair("Amount (token satoshi)",i64tostr(param1*param2))); + } + else + { + result.push_back(Pair("Denomination (satoshi)",i64tostr(param2))); + result.push_back(Pair("Amount (satoshi)",i64tostr(param1*param2))); + } SetCCtxids(addressIndex,CCaddr); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) { if (GetTransaction(it->first.txhash,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) - if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)!=0 && (tmp_txid==channeltxid || tx.GetHash()==channeltxid)) + if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3)!=0 && (tmp_txid==channeltxid || tx.GetHash()==channeltxid)) txids.push_back(it->first.txhash); } BOOST_FOREACH(const CTxMemPoolEntry &e, mempool.mapTx) @@ -760,7 +805,7 @@ UniValue ChannelsInfo(uint256 channeltxid) const CTransaction &txmempool = e.GetTx(); const uint256 &hash = txmempool.GetHash(); - if ((numvouts=txmempool.vout.size()) > 0 && DecodeChannelsOpRet(txmempool.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3) == 'P' && tmp_txid==channeltxid) + if ((numvouts=txmempool.vout.size()) > 0 && DecodeChannelsOpRet(txmempool.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3) == 'P' && tmp_txid==channeltxid) txids.push_back(hash); } prevtxid=zeroid; @@ -770,14 +815,14 @@ UniValue ChannelsInfo(uint256 channeltxid) if (txid!=prevtxid && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) { UniValue obj(UniValue::VOBJ); - if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3) == 'O' && tx.GetHash()==channeltxid) + if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3) == 'O' && tx.GetHash()==channeltxid) { obj.push_back(Pair("Open",txid.GetHex().data())); } - else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'P' && opentxid==channeltxid) + else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,opentxid,srcpub,destpub,param1,param2,param3) == 'P' && opentxid==channeltxid) { if (GetTransaction(opentxid,opentx,hashBlock,false) != 0 && (numvouts=opentx.vout.size()) > 0 && - DecodeChannelsOpRet(opentx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,numpayments,payment,hashchain) == 'O') + DecodeChannelsOpRet(opentx.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,numpayments,payment,hashchain) == 'O') { Getscriptaddress(str,tx.vout[3].scriptPubKey); obj.push_back(Pair("Payment",txid.GetHex().data())); @@ -788,11 +833,11 @@ UniValue ChannelsInfo(uint256 channeltxid) obj.push_back(Pair("Payments left",param1)); } } - else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'C' && opentxid==channeltxid) + else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,opentxid,srcpub,destpub,param1,param2,param3) == 'C' && opentxid==channeltxid) { obj.push_back(Pair("Close",txid.GetHex().data())); } - else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'R' && opentxid==channeltxid) + else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,opentxid,srcpub,destpub,param1,param2,param3) == 'R' && opentxid==channeltxid) { Getscriptaddress(str,tx.vout[2].scriptPubKey); obj.push_back(Pair("Refund",txid.GetHex().data())); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6bc267e0f..6928f4361 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5840,8 +5840,10 @@ UniValue channelsinfo(const UniValue& params, bool fHelp) UniValue channelsopen(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); int32_t numpayments; int64_t payment; std::vector destpub; struct CCcontract_info *cp,C; std::string hex; + uint256 tokenid=zeroid; + cp = CCinit(&C,EVAL_CHANNELS); - if ( fHelp || params.size() != 3 ) + if ( fHelp || params.size() < 3 || params.size() > 4) throw runtime_error("channelsopen destpubkey numpayments payment\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); @@ -5865,7 +5867,11 @@ UniValue channelsopen(const UniValue& params, bool fHelp) ERR_RESULT("invalid payment amount, must be greater than 0"); return result; } - hex = ChannelOpen(0,pubkey2pk(destpub),numpayments,payment); + if (params.size()==4) + { + tokenid=Parseuint256((char *)params[3].get_str().c_str()); + } + hex = ChannelOpen(0,pubkey2pk(destpub),numpayments,payment,tokenid); if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); @@ -5878,7 +5884,7 @@ UniValue channelspayment(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 opentxid,secret=zeroid; int32_t n; int64_t amount; cp = CCinit(&C,EVAL_CHANNELS); - if ( fHelp || params.size() != 2 ) + if ( fHelp || params.size() < 2 || params.size() >3 ) throw runtime_error("channelspayment opentxid amount [secret]\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); @@ -6979,7 +6985,6 @@ UniValue tokenbalance(const UniValue& params, bool fHelp) UniValue result(UniValue::VOBJ); uint256 tokenid; uint64_t balance; std::vector pubkey; struct CCcontract_info *cp,C; CCerror.clear(); - cp = CCinit(&C,EVAL_ASSETS); if ( fHelp || params.size() > 2 ) throw runtime_error("tokenbalance tokenid [pubkey]\n"); if ( ensure_CCrequirements() < 0 ) @@ -6999,7 +7004,7 @@ UniValue tokenbalance(const UniValue& params, bool fHelp) char destaddr[64]; result.push_back(Pair("result", "success")); - + cp = CCinit(&C,EVAL_TOKENS); if (GetCCaddress(cp, destaddr, pubkey2pk(pubkey)) != 0) result.push_back(Pair("CCaddress", destaddr)); From 778bc04009daa6bda59498543f34b55a3c65cac6 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 16 Jan 2019 18:37:51 +0500 Subject: [PATCH 443/643] corr cpAssets use for 'S' in AssetValidate --- src/cc/CCassets.h | 2 +- src/cc/CCassetsCore.cpp | 11 ++++++----- src/cc/assets.cpp | 8 ++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/cc/CCassets.h b/src/cc/CCassets.h index 39644efc6..69fcfacbb 100644 --- a/src/cc/CCassets.h +++ b/src/cc/CCassets.h @@ -44,7 +44,7 @@ bool SetAskFillamounts(int64_t &paid,int64_t &remaining_price,int64_t orig_nValu bool SetSwapFillamounts(int64_t &paid,int64_t &remaining_price,int64_t orig_nValue,int64_t &received,int64_t totalprice); int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 refassetid); int64_t AssetValidateSellvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 assetid); -bool AssetExactAmounts(struct CCcontract_info *cpAssets, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 assetid); +bool AssetCalcAmounts(struct CCcontract_info *cpAssets, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 assetid); // CCassetstx //int64_t GetAssetBalance(CPubKey pk,uint256 tokenid); // --> GetTokenBalance() diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index 7084b1483..4ea025c10 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -389,13 +389,14 @@ int64_t AssetValidateCCvin(struct CCcontract_info *cp,Eval* eval,char *CCaddr,ch return eval->Invalid("vin1 needs to be buyvin.vout[0]"); else if ( eval->GetTxUnconfirmed(tx.vin[vini].prevout.hash,vinTx,hashBlock) == 0 ) { - int32_t z; + /* int32_t z; for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&tx.vin[vini].prevout.hash)[z]); - fprintf(stderr," vini.%d\n",vini); + fprintf(stderr," vini.%d\n",vini); */ + std::cerr << "AssetValidateCCvin cannot load vintx for vin=" << vini << " vintx id=" << tx.vin[vini].prevout.hash.GetHex() << std::endl; return eval->Invalid("always should find CCvin, but didnt"); } - else if ( Getscriptaddress(destaddr,vinTx.vout[tx.vin[vini].prevout.n].scriptPubKey) == 0 || strcmp(destaddr,(char *)cp->unspendableCCaddr) != 0 ) + else if ( Getscriptaddress(destaddr, vinTx.vout[tx.vin[vini].prevout.n].scriptPubKey) == 0 || strcmp(destaddr,(char *)cp->unspendableCCaddr) != 0 ) { fprintf(stderr,"AssetValidateCCvin cc addr %s is not evalcode 0x%02x unspendable %s\n", destaddr, (int)cp->evalcode, (char *)cp->unspendableCCaddr); return eval->Invalid("invalid vin AssetsCCaddr"); @@ -404,7 +405,7 @@ int64_t AssetValidateCCvin(struct CCcontract_info *cp,Eval* eval,char *CCaddr,ch // return eval->Invalid("invalid dust for buyvin"); else if ( GetAssetorigaddrs(cp,CCaddr,origaddr,vinTx) == 0 ) return eval->Invalid("couldnt get origaddr for buyvin"); - fprintf(stderr,"Got %.8f to origaddr.(%s)\n",(double)vinTx.vout[tx.vin[vini].prevout.n].nValue/COIN,origaddr); + fprintf(stderr,"AssetValidateCCvin got %.8f to origaddr.(%s)\n",(double)vinTx.vout[tx.vin[vini].prevout.n].nValue/COIN,origaddr); if ( vinTx.vout[0].nValue == 0 ) return eval->Invalid("null value CCvin"); return(vinTx.vout[0].nValue); @@ -533,7 +534,7 @@ int64_t IsAssetvout(struct CCcontract_info *cp, int64_t &price, std::vector tmporigpubkey; int64_t tmpprice; int32_t numvins = tx.vin.size(); diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index aab0a234f..4a5202c44 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -176,7 +176,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti if( assetid == zero ) return eval->Invalid("illegal assetid"); - else if (!AssetExactAmounts(cpAssets, inputs, outputs, eval, tx, assetid)) { // Only set inputs and outputs. NOTE: we do not need to check cc inputs == cc outputs + else if (!AssetCalcAmounts(cpAssets, inputs, outputs, eval, tx, assetid)) { // Only set inputs and outputs. NOTE: we do not need to check cc inputs == cc outputs return false; // returns false if some problems with reading vintxes } } @@ -334,7 +334,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti //'S'.vout.2: vin.2 value to original pubkey [origpubkey] //vout.3: normal output for change (if any) //'S'.vout.n-1: opreturn [EVAL_ASSETS] ['S'] [assetid] [amount of coin still required] [origpubkey] - if( (assetoshis = AssetValidateSellvin(cpTokens, eval, totalunits, tmporigpubkey, tokensCCaddr, origaddr, tx, assetid)) == 0 ) + if( (assetoshis = AssetValidateSellvin(cpAssets, eval, totalunits, tmporigpubkey, tokensCCaddr, origaddr, tx, assetid)) == 0 ) return(false); else if( numvouts < 3 ) return eval->Invalid("not enough vouts for fillask"); @@ -352,8 +352,8 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti return eval->Invalid("normal vout1 for fillask"); else if( remaining_price != 0 ) { - if ( ConstrainVout(tx.vout[0], 1, (char *)cpTokens->unspendableCCaddr,0) == 0 ) - return eval->Invalid("mismatched vout0 TokenCCaddr for fill"); + if ( ConstrainVout(tx.vout[0], 1, (char *)cpAssets->unspendableCCaddr, 0) == 0 ) + return eval->Invalid("mismatched vout0 assets unspendable CCaddr for fill sell"); } } fprintf(stderr,"fill validated\n"); From 401737d20804ee173c86df513d3054d9feeb609f Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 16 Jan 2019 18:52:38 +0500 Subject: [PATCH 444/643] corr dualevalUnspendableAddr in AssetValidateCCvin --- src/cc/CCassetsCore.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index 4ea025c10..ebb9ff262 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -381,8 +381,11 @@ bool GetAssetorigaddrs(struct CCcontract_info *cp,char *CCaddr,char *destaddr,co int64_t AssetValidateCCvin(struct CCcontract_info *cp,Eval* eval,char *CCaddr,char *origaddr,const CTransaction &tx,int32_t vini,CTransaction &vinTx) { - uint256 hashBlock; char destaddr[64]; + uint256 hashBlock; + char destaddr[64], dualEvalUnspendableAddr[64]; + origaddr[0] = destaddr[0] = CCaddr[0] = 0; + if ( tx.vin.size() < 2 ) return eval->Invalid("not enough for CC vins"); else if ( tx.vin[vini].prevout.n != 0 ) @@ -396,7 +399,9 @@ int64_t AssetValidateCCvin(struct CCcontract_info *cp,Eval* eval,char *CCaddr,ch std::cerr << "AssetValidateCCvin cannot load vintx for vin=" << vini << " vintx id=" << tx.vin[vini].prevout.hash.GetHex() << std::endl; return eval->Invalid("always should find CCvin, but didnt"); } - else if ( Getscriptaddress(destaddr, vinTx.vout[tx.vin[vini].prevout.n].scriptPubKey) == 0 || strcmp(destaddr,(char *)cp->unspendableCCaddr) != 0 ) + else if ( Getscriptaddress(destaddr, vinTx.vout[tx.vin[vini].prevout.n].scriptPubKey) == 0 || + !GetTokensCCaddress(cp, dualEvalUnspendableAddr, GetUnspendable(cp, NULL)) || + strcmp(destaddr, dualEvalUnspendableAddr) != 0 ) { fprintf(stderr,"AssetValidateCCvin cc addr %s is not evalcode 0x%02x unspendable %s\n", destaddr, (int)cp->evalcode, (char *)cp->unspendableCCaddr); return eval->Invalid("invalid vin AssetsCCaddr"); @@ -441,9 +446,9 @@ int64_t AssetValidateSellvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpp { CTransaction vinTx; int64_t nValue,assetoshis; //fprintf(stderr,"AssetValidateSellvin\n"); - if ( (nValue= AssetValidateCCvin(cp,eval,CCaddr,origaddr,tx,1,vinTx)) == 0 ) + if ( (nValue = AssetValidateCCvin(cp, eval, CCaddr, origaddr, tx, 1, vinTx)) == 0 ) return(0); - if ( (assetoshis= IsAssetvout(cp, tmpprice, tmporigpubkey,vinTx,0,assetid)) == 0 ) + if ( (assetoshis= IsAssetvout(cp, tmpprice, tmporigpubkey, vinTx, 0, assetid)) == 0 ) return eval->Invalid("invalid missing CC vout0 for sellvin"); else return(assetoshis); From 0588f5dc67a8c6de01690f48ac2960b72b41a527 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 16 Jan 2019 19:21:41 +0500 Subject: [PATCH 445/643] corr unspendable addr for 'S' --- src/cc/CCassetsCore.cpp | 17 +++++++++-------- src/cc/assets.cpp | 5 ++++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index ebb9ff262..34d773d28 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -365,14 +365,15 @@ bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CT bool GetAssetorigaddrs(struct CCcontract_info *cp,char *CCaddr,char *destaddr,const CTransaction& tx) { - uint256 assetid,assetid2; int64_t price,nValue=0; int32_t n; uint8_t funcid; std::vector origpubkey; + uint256 assetid,assetid2; int64_t price,nValue=0; int32_t n; uint8_t funcid; + std::vector origpubkey; CScript script; uint8_t evalCode; n = tx.vout.size(); - if ( n == 0 || (funcid= DecodeAssetTokenOpRet(tx.vout[n-1].scriptPubKey, evalCode,assetid,assetid2,price,origpubkey)) == 0 ) + if( n == 0 || (funcid= DecodeAssetTokenOpRet(tx.vout[n-1].scriptPubKey, evalCode, assetid, assetid2, price, origpubkey)) == 0 ) return(false); - if ( GetCCaddress(cp, CCaddr, pubkey2pk(origpubkey)) != 0 && Getscriptaddress(destaddr, CScript() << origpubkey << OP_CHECKSIG) != 0 ) + if( GetTokensCCaddress(cp, CCaddr, pubkey2pk(origpubkey)) != 0 && Getscriptaddress(destaddr, CScript() << origpubkey << OP_CHECKSIG) != 0 ) return(true); else return(false); @@ -386,11 +387,11 @@ int64_t AssetValidateCCvin(struct CCcontract_info *cp,Eval* eval,char *CCaddr,ch origaddr[0] = destaddr[0] = CCaddr[0] = 0; - if ( tx.vin.size() < 2 ) + if( tx.vin.size() < 2 ) return eval->Invalid("not enough for CC vins"); - else if ( tx.vin[vini].prevout.n != 0 ) + else if( tx.vin[vini].prevout.n != 0 ) return eval->Invalid("vin1 needs to be buyvin.vout[0]"); - else if ( eval->GetTxUnconfirmed(tx.vin[vini].prevout.hash,vinTx,hashBlock) == 0 ) + else if( eval->GetTxUnconfirmed(tx.vin[vini].prevout.hash, vinTx,hashBlock) == 0 ) { /* int32_t z; for (z=31; z>=0; z--) @@ -399,7 +400,7 @@ int64_t AssetValidateCCvin(struct CCcontract_info *cp,Eval* eval,char *CCaddr,ch std::cerr << "AssetValidateCCvin cannot load vintx for vin=" << vini << " vintx id=" << tx.vin[vini].prevout.hash.GetHex() << std::endl; return eval->Invalid("always should find CCvin, but didnt"); } - else if ( Getscriptaddress(destaddr, vinTx.vout[tx.vin[vini].prevout.n].scriptPubKey) == 0 || + else if( Getscriptaddress(destaddr, vinTx.vout[tx.vin[vini].prevout.n].scriptPubKey) == 0 || !GetTokensCCaddress(cp, dualEvalUnspendableAddr, GetUnspendable(cp, NULL)) || strcmp(destaddr, dualEvalUnspendableAddr) != 0 ) { @@ -408,7 +409,7 @@ int64_t AssetValidateCCvin(struct CCcontract_info *cp,Eval* eval,char *CCaddr,ch } //else if ( vinTx.vout[0].nValue < 10000 ) // return eval->Invalid("invalid dust for buyvin"); - else if ( GetAssetorigaddrs(cp,CCaddr,origaddr,vinTx) == 0 ) + else if( GetAssetorigaddrs(cp, CCaddr, origaddr, vinTx) == 0 ) return eval->Invalid("couldnt get origaddr for buyvin"); fprintf(stderr,"AssetValidateCCvin got %.8f to origaddr.(%s)\n",(double)vinTx.vout[tx.vin[vini].prevout.n].nValue/COIN,origaddr); if ( vinTx.vout[0].nValue == 0 ) diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index 4a5202c44..4efd555b7 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -334,6 +334,9 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti //'S'.vout.2: vin.2 value to original pubkey [origpubkey] //vout.3: normal output for change (if any) //'S'.vout.n-1: opreturn [EVAL_ASSETS] ['S'] [assetid] [amount of coin still required] [origpubkey] + char dualEvalUnspendableAddr[64]; + GetTokensCCaddress(cpAssets, dualEvalUnspendableAddr, GetUnspendable(cpAssets, NULL)); + if( (assetoshis = AssetValidateSellvin(cpAssets, eval, totalunits, tmporigpubkey, tokensCCaddr, origaddr, tx, assetid)) == 0 ) return(false); else if( numvouts < 3 ) @@ -352,7 +355,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti return eval->Invalid("normal vout1 for fillask"); else if( remaining_price != 0 ) { - if ( ConstrainVout(tx.vout[0], 1, (char *)cpAssets->unspendableCCaddr, 0) == 0 ) + if ( ConstrainVout(tx.vout[0], 1, dualEvalUnspendableAddr /*(char *)cpAssets->unspendableCCaddr*/, 0) == 0 ) return eval->Invalid("mismatched vout0 assets unspendable CCaddr for fill sell"); } } From 06e5d6fc6e2229867872ac536b4bc98c8038fec1 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 16 Jan 2019 19:39:56 +0500 Subject: [PATCH 446/643] corr dualUnspendable use in AssetOrders --- src/cc/CCassetstx.cpp | 5 ++++- src/cc/assets.cpp | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 5b21fc1b1..5246f3d79 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -165,7 +165,10 @@ UniValue AssetOrders(uint256 refassetid) SetCCunspents(unspentOutputsTokens, (char *)cpTokens->unspendableCCaddr); - SetCCunspents(unspentOutputsAssets, (char *)cpAssets->unspendableCCaddr); + + char dualEvalUnspendableAddr[64]; + GetTokensCCaddress(cpAssets, dualEvalUnspendableAddr, GetUnspendable(cpAssets, NULL)); + SetCCunspents(unspentOutputsAssets, dualEvalUnspendableAddr /*(char *)cpAssets->unspendableCCaddr*/); for (std::vector >::const_iterator itTokens = unspentOutputsTokens.begin(); itTokens != unspentOutputsTokens.end(); diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index 4efd555b7..d9e8ca7fb 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -356,12 +356,13 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti else if( remaining_price != 0 ) { if ( ConstrainVout(tx.vout[0], 1, dualEvalUnspendableAddr /*(char *)cpAssets->unspendableCCaddr*/, 0) == 0 ) - return eval->Invalid("mismatched vout0 assets unspendable CCaddr for fill sell"); + return eval->Invalid("mismatched vout0 assets dual unspendable CCaddr for fill sell"); } } fprintf(stderr,"fill validated\n"); break; case 'E': // fillexchange + ////////// not implemented yet //////////// return eval->Invalid("unexpected assets fillexchange funcid"); break; // disable asset swaps //vin.0: normal input @@ -377,6 +378,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti //if ( AssetExactAmounts(false, cp,inputs,outputs,eval,tx,assetid2) == false ) // eval->Invalid("asset2 inputs != outputs"); + ////////// not implemented yet //////////// if( (assetoshis= AssetValidateSellvin(cpTokens, eval, totalunits, tmporigpubkey, tokensCCaddr, origaddr, tx, assetid)) == 0 ) return(false); else if( numvouts < 3 ) @@ -412,6 +414,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti return eval->Invalid("mismatched vout0 AssetsCCaddr for fillex"); } } + ////////// not implemented yet //////////// fprintf(stderr,"fill validated\n"); break; From c18a655baf63c1037a147d46d2c51e3850a119ef Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 16 Jan 2019 21:14:36 +0500 Subject: [PATCH 447/643] corr uninited cpAssets var in FillBuyOffer --- src/cc/CCassetstx.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 5246f3d79..fb6b5b6db 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -621,12 +621,12 @@ std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t f //CPubKey unspendableTokensPk = GetUnspendable(cpTokens, NULL); uint8_t unspendableAssetsPrivkey[32]; - cpTokens = CCinit(&assetsC, EVAL_ASSETS); //??? + cpAssets = CCinit(&assetsC, EVAL_ASSETS); //??? CPubKey unspendableAssetsPk = GetUnspendable(cpAssets, unspendableAssetsPrivkey); mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, bidamount - paid_amount, unspendableAssetsPk)); // vout0 coins remainder mtx.vout.push_back(CTxOut(paid_amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); // vout1 coins to normal - mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, fillamount, pubkey2pk(origpubkey))); // vout2 single-eval tokens paid + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, fillamount, pubkey2pk(origpubkey))); // vout2 single-eval tokens sent to the buyer if (CCchange != 0) mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, CCchange, mypk)); // vout3 change in single-eval tokens From 9293af0f1b1774e99dc166f07c3a62a5ba0a9119 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 16 Jan 2019 22:10:25 +0500 Subject: [PATCH 448/643] added conditions for x S o B in AssetValidateCCvin --- src/cc/CCassetsCore.cpp | 57 ++++++++++++++++++++++++++++++----------- src/cc/assets.cpp | 6 +++-- 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index 34d773d28..0c01f52bb 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -371,7 +371,7 @@ bool GetAssetorigaddrs(struct CCcontract_info *cp,char *CCaddr,char *destaddr,co uint8_t evalCode; n = tx.vout.size(); - if( n == 0 || (funcid= DecodeAssetTokenOpRet(tx.vout[n-1].scriptPubKey, evalCode, assetid, assetid2, price, origpubkey)) == 0 ) + if( n == 0 || (funcid = DecodeAssetTokenOpRet(tx.vout[n-1].scriptPubKey, evalCode, assetid, assetid2, price, origpubkey)) == 0 ) return(false); if( GetTokensCCaddress(cp, CCaddr, pubkey2pk(origpubkey)) != 0 && Getscriptaddress(destaddr, CScript() << origpubkey << OP_CHECKSIG) != 0 ) return(true); @@ -382,11 +382,25 @@ bool GetAssetorigaddrs(struct CCcontract_info *cp,char *CCaddr,char *destaddr,co int64_t AssetValidateCCvin(struct CCcontract_info *cp,Eval* eval,char *CCaddr,char *origaddr,const CTransaction &tx,int32_t vini,CTransaction &vinTx) { - uint256 hashBlock; - char destaddr[64], dualEvalUnspendableAddr[64]; + uint256 hashBlock; + uint256 assetid, assetid2; + int64_t tmpprice; + std::vector tmporigpubkey; + uint8_t evalCode; + + char destaddr[64], unspendableAddr[64]; origaddr[0] = destaddr[0] = CCaddr[0] = 0; + uint8_t funcid = 0; + if (tx.vout.size() > 0) { + uint256 assetid, assetid2; + int64_t tmpprice; + std::vector tmporigpubkey; + uint8_t evalCode; + funcid = DecodeAssetTokenOpRet(tx.vout[tx.vout.size() - 1].scriptPubKey, evalCode, assetid, assetid2, tmpprice, tmporigpubkey); + } + if( tx.vin.size() < 2 ) return eval->Invalid("not enough for CC vins"); else if( tx.vin[vini].prevout.n != 0 ) @@ -400,13 +414,25 @@ int64_t AssetValidateCCvin(struct CCcontract_info *cp,Eval* eval,char *CCaddr,ch std::cerr << "AssetValidateCCvin cannot load vintx for vin=" << vini << " vintx id=" << tx.vin[vini].prevout.hash.GetHex() << std::endl; return eval->Invalid("always should find CCvin, but didnt"); } - else if( Getscriptaddress(destaddr, vinTx.vout[tx.vin[vini].prevout.n].scriptPubKey) == 0 || - !GetTokensCCaddress(cp, dualEvalUnspendableAddr, GetUnspendable(cp, NULL)) || - strcmp(destaddr, dualEvalUnspendableAddr) != 0 ) + // if fillSell or cancelSell --> to spend tokens from dual-eval token-assets unspendable addr + else if( (funcid == 'S' || funcid == 'x') && + (Getscriptaddress(destaddr, vinTx.vout[tx.vin[vini].prevout.n].scriptPubKey) == 0 || + !GetTokensCCaddress(cp, unspendableAddr, GetUnspendable(cp, NULL)) || + strcmp(destaddr, unspendableAddr) != 0)) { - fprintf(stderr,"AssetValidateCCvin cc addr %s is not evalcode 0x%02x unspendable %s\n", destaddr, (int)cp->evalcode, (char *)cp->unspendableCCaddr); + fprintf(stderr,"AssetValidateCCvin cc addr %s is not dual token-evalcode=0x%02x asset unspendable addr %s\n", destaddr, (int)cp->evalcode, unspendableAddr); return eval->Invalid("invalid vin AssetsCCaddr"); } + // if fillBuy or cancelBuy --> to spend coins from asset unspendable addr + else if ((funcid == 'B' || funcid == 'o') && + (Getscriptaddress(destaddr, vinTx.vout[tx.vin[vini].prevout.n].scriptPubKey) == 0 || + !GetCCaddress(cp, unspendableAddr, GetUnspendable(cp, NULL)) || + strcmp(destaddr, unspendableAddr) != 0)) + { + fprintf(stderr, "AssetValidateCCvin cc addr %s is not evalcode=0x%02x asset unspendable addr %s\n", destaddr, (int)cp->evalcode, unspendableAddr); + return eval->Invalid("invalid vin AssetsCCaddr"); + } + //else if ( vinTx.vout[0].nValue < 10000 ) // return eval->Invalid("invalid dust for buyvin"); else if( GetAssetorigaddrs(cp, CCaddr, origaddr, vinTx) == 0 ) @@ -423,11 +449,12 @@ int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmppr CCaddr[0] = origaddr[0] = 0; // validate locked coins on Assets vin[1] - if ( (nValue= AssetValidateCCvin(cp,eval,CCaddr,origaddr,tx,1,vinTx)) == 0 ) + if ( (nValue= AssetValidateCCvin(cp, eval, CCaddr, origaddr, tx, 1, vinTx)) == 0 ) return(0); else if ( vinTx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) return eval->Invalid("invalid normal vout0 for buyvin"); - else if ((funcid = DecodeAssetTokenOpRet(vinTx.vout[vinTx.vout.size() - 1].scriptPubKey, evalCode, assetid, assetid2, tmpprice, tmporigpubkey)) == 'b' && vinTx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) // marker is only in 'b'? + else if ((funcid = DecodeAssetTokenOpRet(vinTx.vout[vinTx.vout.size() - 1].scriptPubKey, evalCode, assetid, assetid2, tmpprice, tmporigpubkey)) == 'b' && + vinTx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) // marker is only in 'b'? return eval->Invalid("invalid normal vout1 for buyvin"); else { @@ -467,7 +494,7 @@ bool ValidateAssetOpret(CTransaction tx, int32_t v, uint256 assetid, int64_t &pr if ((funcid = DecodeAssetTokenOpRet(tx.vout[n - 1].scriptPubKey, evalCode, assetidOpret, assetidOpret2, price, origpubkey)) == 0) { - std::cerr << "ValidateAssetOpret() DecodeOpret returned null for n-1=" << n - 1 << " txid=" << tx.GetHash().GetHex() << std::endl; + std::cerr << "ValidateAssetOpret() DecodeAssetTokenOpRet returned null for the opret for txid=" << tx.GetHash().GetHex() << std::endl; return(false); } /* it is now on token level: @@ -559,7 +586,7 @@ bool AssetCalcAmounts(struct CCcontract_info *cpAssets, int64_t &inputs, int64_t // we are not inside the validation code -- dimxy if ((eval && eval->GetTxUnconfirmed(tx.vin[i].prevout.hash, vinTx, hashBlock) == 0) || (!eval && !myGetTransaction(tx.vin[i].prevout.hash, vinTx, hashBlock))) { - std::cerr << "AssetExactAmounts() cannot read vintx for i." << i << " numvins." << numvins << std::endl; + std::cerr << "AssetCalcAmounts() cannot read vintx for i." << i << " numvins." << numvins << std::endl; return (!eval) ? false : eval->Invalid("always should find vin tx, but didnt"); } else { @@ -573,7 +600,7 @@ bool AssetCalcAmounts(struct CCcontract_info *cpAssets, int64_t &inputs, int64_t assetoshis = IsTokensvout(false, false, cpTokens, NULL, /* vopretExtra,*/ vinTx, tx.vin[i].prevout.n, assetid, vinPubkeysEmpty); if (assetoshis != 0) { - std::cerr << "AssetExactAmounts() vin i=" << i << " assetoshis=" << assetoshis << std::endl; + std::cerr << "AssetCalcAmounts() vin i=" << i << " assetoshis=" << assetoshis << std::endl; inputs += assetoshis; } } @@ -595,18 +622,18 @@ bool AssetCalcAmounts(struct CCcontract_info *cpAssets, int64_t &inputs, int64_t if (assetoshis != 0) { - std::cerr << "AssetExactAmounts() vout i=" << i << " assetoshis=" << assetoshis << std::endl; + std::cerr << "AssetCalcAmounts() vout i=" << i << " assetoshis=" << assetoshis << std::endl; outputs += assetoshis; } } - std::cerr << "AssetExactAmounts() inputs=" << inputs << " outputs=" << outputs << " for txid=" << tx.GetHash().GetHex() << std::endl; + std::cerr << "AssetCalcAmounts() inputs=" << inputs << " outputs=" << outputs << " for txid=" << tx.GetHash().GetHex() << std::endl; /* we do not verify inputs == outputs here, it's done in Tokens: if (inputs != outputs) { if (tx.GetHash() != assetid) { - std::cerr << "AssetExactAmounts() unequal inputs=" << inputs << " vs outputs=" << outputs << " for txid=" << tx.GetHash().GetHex() << std::endl; + std::cerr << "AssetCalcAmounts() unequal inputs=" << inputs << " vs outputs=" << outputs << " for txid=" << tx.GetHash().GetHex() << std::endl; return (!eval) ? false : eval->Invalid("assets cc inputs != cc outputs"); } } */ diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index d9e8ca7fb..8d9b696e6 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -261,12 +261,12 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti return eval->Invalid("locked value doesnt match vout0+1 fillbuy"); else if( tx.vout[3].scriptPubKey.IsPayToCryptoCondition() != 0 ) { - if( ConstrainVout(tx.vout[2], 1, tokensCCaddr, 0) == 0 ) // tokens on user cc addr + if( ConstrainVout(tx.vout[2], 1, assetsCCaddr, 0) == 0 ) // tokens on user cc addr return eval->Invalid("vout2 doesnt go to origpubkey fillbuy"); else if ( inputs != tx.vout[2].nValue + tx.vout[3].nValue ) return eval->Invalid("asset inputs doesnt match vout2+3 fillbuy"); } - else if( ConstrainVout(tx.vout[2], 1, tokensCCaddr, inputs) == 0 ) // tokens on user cc addr + else if( ConstrainVout(tx.vout[2], 1, assetsCCaddr, inputs) == 0 ) // tokens on user cc addr return eval->Invalid("vout2 doesnt match inputs fillbuy"); else if( ConstrainVout(tx.vout[1],0,0,0) == 0 ) return eval->Invalid("vout1 is CC for fillbuy"); @@ -390,6 +390,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti if( assetoshis != tx.vout[0].nValue + tx.vout[1].nValue ) return eval->Invalid("locked value doesnt match vout0+1 fillex"); else if( tx.vout[3].scriptPubKey.IsPayToCryptoCondition() != 0 ) + ////////// not implemented yet //////////// { if( ConstrainVout(tx.vout[2], 1, tokensCCaddr, 0) == 0 ) return eval->Invalid("vout2 doesnt go to origpubkey fillex"); @@ -399,6 +400,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti return eval->Invalid("asset inputs doesnt match vout2+3 fillex"); } } + ////////// not implemented yet //////////// else if( ConstrainVout(tx.vout[2], 1, tokensCCaddr, inputs) == 0 ) return eval->Invalid("vout2 doesnt match inputs fillex"); else if( ConstrainVout(tx.vout[1], 0, 0, 0) == 0 ) From a99fd7502d6ed0a2779f2b36f7bc110630609fad Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 16 Jan 2019 22:39:21 +0500 Subject: [PATCH 449/643] added conds for ask/bid in GetAssetorigaddrs --- src/cc/CCassetsCore.cpp | 19 ++++++++++++++++--- src/cc/assets.cpp | 8 +++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index 0c01f52bb..9df24b94a 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -353,6 +353,7 @@ uint8_t DecodeAssetTokenOpRet(const CScript &scriptPubKey, uint8_t &evalCodeInOp return (uint8_t)0; } +// extract sell/buy owner's pubkey from the opret bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CTransaction &tx) { uint256 assetid,assetid2; @@ -362,8 +363,9 @@ bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CT else return(false); } - -bool GetAssetorigaddrs(struct CCcontract_info *cp,char *CCaddr,char *destaddr,const CTransaction& tx) + +// Calculate sell/buy owner's source token/asset address from ask/bid tx +bool GetAssetorigaddrs(struct CCcontract_info *cp, char *CCaddr, char *destaddr, const CTransaction& tx) { uint256 assetid,assetid2; int64_t price,nValue=0; int32_t n; uint8_t funcid; std::vector origpubkey; @@ -373,7 +375,18 @@ bool GetAssetorigaddrs(struct CCcontract_info *cp,char *CCaddr,char *destaddr,co n = tx.vout.size(); if( n == 0 || (funcid = DecodeAssetTokenOpRet(tx.vout[n-1].scriptPubKey, evalCode, assetid, assetid2, price, origpubkey)) == 0 ) return(false); - if( GetTokensCCaddress(cp, CCaddr, pubkey2pk(origpubkey)) != 0 && Getscriptaddress(destaddr, CScript() << origpubkey << OP_CHECKSIG) != 0 ) + + bool bGetCCaddr = false; + if (funcid == 's' || funcid == 'S') + bGetCCaddr = GetTokensCCaddress(cp, CCaddr, pubkey2pk(origpubkey)); + else if (funcid == 'b' || funcid == 'B') + bGetCCaddr = GetCCaddress(cp, CCaddr, pubkey2pk(origpubkey)); + else { + std::cerr << "GetAssetorigaddrs incorrect funcid=" << (char)(funcid?funcid:' ') << std::endl; + return false; + } + + if( bGetCCaddr && Getscriptaddress(destaddr, CScript() << origpubkey << OP_CHECKSIG)) return(true); else return(false); diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index 8d9b696e6..074c617cb 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -334,8 +334,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti //'S'.vout.2: vin.2 value to original pubkey [origpubkey] //vout.3: normal output for change (if any) //'S'.vout.n-1: opreturn [EVAL_ASSETS] ['S'] [assetid] [amount of coin still required] [origpubkey] - char dualEvalUnspendableAddr[64]; - GetTokensCCaddress(cpAssets, dualEvalUnspendableAddr, GetUnspendable(cpAssets, NULL)); + if( (assetoshis = AssetValidateSellvin(cpAssets, eval, totalunits, tmporigpubkey, tokensCCaddr, origaddr, tx, assetid)) == 0 ) return(false); @@ -355,7 +354,10 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti return eval->Invalid("normal vout1 for fillask"); else if( remaining_price != 0 ) { - if ( ConstrainVout(tx.vout[0], 1, dualEvalUnspendableAddr /*(char *)cpAssets->unspendableCCaddr*/, 0) == 0 ) + char tokensUnspendableAddr[64]; + GetTokensCCaddress(cpAssets, tokensUnspendableAddr, GetUnspendable(cpAssets, NULL)); + + if ( ConstrainVout(tx.vout[0], 1, tokensUnspendableAddr /*(char *)cpAssets->unspendableCCaddr*/, 0) == 0 ) return eval->Invalid("mismatched vout0 assets dual unspendable CCaddr for fill sell"); } } From 9584d6db7fd47a268d527f223f23b495b251e586 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 16 Jan 2019 22:56:30 +0500 Subject: [PATCH 450/643] corr cond (single tokens) for buy in GetAssetorigaddrs --- src/cc/CCassetsCore.cpp | 7 +++++-- src/cc/CCassetstx.cpp | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index 9df24b94a..5c48837a1 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -379,8 +379,11 @@ bool GetAssetorigaddrs(struct CCcontract_info *cp, char *CCaddr, char *destaddr, bool bGetCCaddr = false; if (funcid == 's' || funcid == 'S') bGetCCaddr = GetTokensCCaddress(cp, CCaddr, pubkey2pk(origpubkey)); - else if (funcid == 'b' || funcid == 'B') - bGetCCaddr = GetCCaddress(cp, CCaddr, pubkey2pk(origpubkey)); + else if (funcid == 'b' || funcid == 'B') { + struct CCcontract_info *cpTokens, tokensC; + cpTokens = CCinit(&tokensC, EVAL_TOKENS); + bGetCCaddr = GetCCaddress(cpTokens, CCaddr, pubkey2pk(origpubkey)); + } else { std::cerr << "GetAssetorigaddrs incorrect funcid=" << (char)(funcid?funcid:' ') << std::endl; return false; diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index fb6b5b6db..e60ebf3e6 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -723,8 +723,8 @@ std::string FillSell(int64_t txfee, uint256 assetid, uint256 assetid2, uint256 a if (assetid2 != zeroid && inputs > paid_nValue) CCchange = (inputs - paid_nValue); - mtx.vout.push_back(MakeTokensCC1vout(EVAL_ASSETS, orig_assetoshis - received_assetoshis, GetUnspendable(cpAssets, NULL))); // vout.0 tokens cc addr - ask remainder - mtx.vout.push_back(MakeTokensCC1vout(EVAL_ASSETS, received_assetoshis, mypk)); //vout.1 tokens to self + mtx.vout.push_back(MakeTokensCC1vout(EVAL_ASSETS, orig_assetoshis - received_assetoshis, GetUnspendable(cpAssets, NULL))); // vout.0 tokens remainder to unspendable cc addr + mtx.vout.push_back(MakeTokensCC1vout(EVAL_ASSETS, received_assetoshis, mypk)); //vout.1 purchased tokens to self // NOTE: no marker here @@ -735,7 +735,7 @@ std::string FillSell(int64_t txfee, uint256 assetid, uint256 assetid2, uint256 a } else { std::cerr << "FillSell() paid_value=" << paid_nValue << " origpubkey=" << HexStr(pubkey2pk(origpubkey)) << std::endl; - mtx.vout.push_back(CTxOut(paid_nValue, CScript() << origpubkey << OP_CHECKSIG)); //vout.2 coins normal to whom who asked token + mtx.vout.push_back(CTxOut(paid_nValue, CScript() << origpubkey << OP_CHECKSIG)); //vout.2 coins to tokens seller's normal addr } // not implemented From f79531a29a3e6f5272d4519eb94be8d78aa1d74b Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 16 Jan 2019 23:50:42 +0500 Subject: [PATCH 451/643] corr asset unspents addr in AssetOrders --- src/cc/CCassetstx.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index e60ebf3e6..39153f28f 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -164,11 +164,13 @@ UniValue AssetOrders(uint256 refassetid) }; - SetCCunspents(unspentOutputsTokens, (char *)cpTokens->unspendableCCaddr); + char assetsUnspendableAddr[64]; + GetCCaddress(cpAssets, assetsUnspendableAddr, GetUnspendable(cpAssets, NULL)); + SetCCunspents(unspentOutputsAssets, assetsUnspendableAddr /*(char *)cpTokens->unspendableCCaddr*/); - char dualEvalUnspendableAddr[64]; - GetTokensCCaddress(cpAssets, dualEvalUnspendableAddr, GetUnspendable(cpAssets, NULL)); - SetCCunspents(unspentOutputsAssets, dualEvalUnspendableAddr /*(char *)cpAssets->unspendableCCaddr*/); + char tokensUnspendableAddr[64]; + GetTokensCCaddress(cpAssets, tokensUnspendableAddr, GetUnspendable(cpAssets, NULL)); + SetCCunspents(unspentOutputsAssets, tokensUnspendableAddr /*(char *)cpAssets->unspendableCCaddr*/); for (std::vector >::const_iterator itTokens = unspentOutputsTokens.begin(); itTokens != unspentOutputsTokens.end(); From 9657b5ce43473d979e8157f71f2978605a470978 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 17 Jan 2019 00:19:33 +0500 Subject: [PATCH 452/643] added CCaddr2set to CancelSell --- src/cc/CCassetstx.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 39153f28f..6a66bfcb7 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -530,7 +530,7 @@ std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) uint8_t dummyEvalCode; uint256 dummyAssetid, dummyAssetid2; int64_t dummyPrice; std::vector dummyOrigpubkey; - cpTokens = CCinit(&tokensC, EVAL_TOKENS); + cpAssets = CCinit(&assetsC, EVAL_ASSETS); if (txfee == 0) txfee = 10000; @@ -555,16 +555,25 @@ std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) std::vector voutTokenPubkeys; voutTokenPubkeys.push_back(mypk); - char myCCaddr[65]; + /* char myCCaddr[65]; uint8_t myPrivkey[32]; Myprivkey(myPrivkey); cpAssets = CCinit(&assetsC, EVAL_ASSETS); - GetCCaddress(cpAssets, myCCaddr, mypk); + GetCCaddress(cpAssets, myCCaddr, mypk); */ // this is only for unspendable addresses: //CCaddr2set(cpTokens, EVAL_ASSETS, mypk, myPrivkey, myCCaddr); //do we need this? Seems FinalizeCCTx can attach to any evalcode cc addr by calling Getscriptaddress - return(FinalizeCCTx(mask, cpTokens, mtx, mypk, txfee, + uint8_t unspendableAssetsPrivkey[32]; + char unspendableAssetsAddr[64]; + // init assets 'unspendable' privkey and pubkey + CPubKey unspendableAssetsPk = GetUnspendable(cpAssets, unspendableAssetsPrivkey); + GetCCaddress(cpAssets, unspendableAssetsAddr, unspendableAssetsPk); + + // add additional eval-tokens unspendable assets privkey: + CCaddr2set(cpAssets, EVAL_TOKENS, unspendableAssetsPk, unspendableAssetsPrivkey, unspendableAssetsAddr); + + return(FinalizeCCTx(mask, cpAssets, mtx, mypk, txfee, EncodeTokenOpRet(assetid, voutTokenPubkeys, EncodeAssetOpRet('x', zeroid, 0, Mypubkey())))); } @@ -749,11 +758,11 @@ std::string FillSell(int64_t txfee, uint256 assetid, uint256 assetid2, uint256 a uint8_t unspendableAssetsPrivkey[32]; char unspendableAssetsAddr[64]; - // init 'unspenable' privkey and pubkey + // init assets 'unspendable' privkey and pubkey CPubKey unspendableAssetsPk = GetUnspendable(cpAssets, unspendableAssetsPrivkey); GetCCaddress(cpAssets, unspendableAssetsAddr, unspendableAssetsPk); - // add additional dual-eval (assets+tokens) unspendable assets address's privkey: + // add additional eval-tokens unspendable assets privkey: CCaddr2set(cpAssets, EVAL_TOKENS, unspendableAssetsPk, unspendableAssetsPrivkey, unspendableAssetsAddr); // vout verification pubkeys: From 29052b079061d07c1a4a53c8ed0ab4ea90e96f35 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 17 Jan 2019 12:46:01 +0500 Subject: [PATCH 453/643] corr 'x' validation code corr logging in FinalizeCCtx --- src/cc/CCtx.cpp | 10 +++++----- src/cc/assets.cpp | 20 ++++++++++++-------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 2959ba7d7..2116e350b 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -163,19 +163,19 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { privkey = myprivkey; cond = mytokenscond; - fprintf(stderr,"FinalizeCCTx() matched TokensCC1vout CC addr.(%s)\n",mytokensaddr); + fprintf(stderr,"FinalizeCCTx() matched dual-eval TokensCC1vout CC addr.(%s)\n",mytokensaddr); } else if (strcmp(destaddr, mysingletokensaddr) == 0) // if this is TokensCC1vout { privkey = myprivkey; cond = mysingletokenscond; - fprintf(stderr, "FinalizeCCTx() matched single-eval TokensCC1vout CC addr.(%s)\n", mytokensaddr); + fprintf(stderr, "FinalizeCCTx() matched single-eval token CC1vout CC addr.(%s)\n", mytokensaddr); } else if ( strcmp(destaddr,unspendable) == 0 ) { privkey = unspendablepriv; cond = othercond; - //fprintf(stderr,"FinalizeCCTx() matched unspendable CC addr.(%s)\n",unspendable); + fprintf(stderr,"FinalizeCCTx() matched unspendable CC addr.(%s)\n",unspendable); } else if (strcmp(destaddr, tokensunspendable) == 0) { @@ -186,7 +186,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran // check if this is the 2nd additional evalcode + 'unspendable' cc addr: else if ( strcmp(destaddr,cp->unspendableaddr2) == 0) { - //fprintf(stderr,"FinalizeCCTx() matched %s unspendable2!\n",cp->unspendableaddr2); + fprintf(stderr,"FinalizeCCTx() matched %s unspendable2!\n",cp->unspendableaddr2); privkey = cp->unspendablepriv2; if ( othercond2 == 0 ) othercond2 = MakeCCcond1(cp->evalcode2, cp->unspendablepk2); @@ -195,7 +195,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran // check if this is 3rd additional evalcode + 'unspendable' cc addr: else if ( strcmp(destaddr,cp->unspendableaddr3) == 0 ) { - //fprintf(stderr,"FinalizeCCTx() matched %s unspendable3!\n",cp->unspendableaddr3); + fprintf(stderr,"FinalizeCCTx() matched %s unspendable3!\n",cp->unspendableaddr3); privkey = cp->unspendablepriv3; if ( othercond3 == 0 ) othercond3 = MakeCCcond1(cp->evalcode3,cp->unspendablepk3); diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index 074c617cb..ec3266c71 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -153,7 +153,11 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti if((funcid = DecodeAssetTokenOpRet(tx.vout[numvouts-1].scriptPubKey, evalCodeInOpret, assetid, assetid2, remaining_price, origpubkey)) == 0 ) return eval->Invalid("AssetValidate: invalid opreturn payload"); - // find token user cc addr + // find dual-eval tokens unspendable addr: + char tokensUnspendableAddr[64]; + GetTokensCCaddress(cpAssets, tokensUnspendableAddr, GetUnspendable(cpAssets, NULL)); + + // find token user cc addr: GetCCaddress(cpTokens, tokensCCaddr, pubkey2pk(origpubkey)); fprintf(stderr,"AssetValidate (%c)\n",funcid); @@ -296,10 +300,10 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti return eval->Invalid("illegal null remaining_price for selloffer"); if ( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) return eval->Invalid("invalid normal vout1 for sellvin"); - if( tx.vout[2].scriptPubKey.IsPayToCryptoCondition() != 0 ) + if( tx.vout[2].scriptPubKey.IsPayToCryptoCondition() != 0 ) // cc change { preventCCvouts++; - if( ConstrainVout(tx.vout[0], 1, (char *)cpTokens->unspendableCCaddr, 0) == 0 ) // check also vout[0] + if( ConstrainVout(tx.vout[0], 1, (char *)cpTokens->unspendableCCaddr, 0) == 0 ) // check also cc vout[0] return eval->Invalid("mismatched vout0 TokensCCaddr for selloffer"); else if( tx.vout[0].nValue + tx.vout[2].nValue != inputs ) return eval->Invalid("mismatched vout0+vout2 total for selloffer"); @@ -317,7 +321,8 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti //vout.1: vin.2 back to users pubkey //vout.2: normal output for change (if any) //vout.n-1: opreturn [EVAL_ASSETS] ['x'] [assetid] - if( (assetoshis= AssetValidateSellvin(cpTokens, eval, tmpprice, tmporigpubkey, tokensCCaddr, origaddr, tx, assetid)) == 0 ) + + if( (assetoshis= AssetValidateSellvin(cpAssets, eval, tmpprice, tmporigpubkey, tokensCCaddr, origaddr, tx, assetid)) == 0 ) return(false); else if( ConstrainVout(tx.vout[0], 1, tokensCCaddr, assetoshis) == 0 ) return eval->Invalid("invalid vout for cancel"); @@ -335,7 +340,6 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti //vout.3: normal output for change (if any) //'S'.vout.n-1: opreturn [EVAL_ASSETS] ['S'] [assetid] [amount of coin still required] [origpubkey] - if( (assetoshis = AssetValidateSellvin(cpAssets, eval, totalunits, tmporigpubkey, tokensCCaddr, origaddr, tx, assetid)) == 0 ) return(false); else if( numvouts < 3 ) @@ -354,9 +358,8 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti return eval->Invalid("normal vout1 for fillask"); else if( remaining_price != 0 ) { - char tokensUnspendableAddr[64]; - GetTokensCCaddress(cpAssets, tokensUnspendableAddr, GetUnspendable(cpAssets, NULL)); - + //char tokensUnspendableAddr[64]; + //GetTokensCCaddress(cpAssets, tokensUnspendableAddr, GetUnspendable(cpAssets, NULL)); if ( ConstrainVout(tx.vout[0], 1, tokensUnspendableAddr /*(char *)cpAssets->unspendableCCaddr*/, 0) == 0 ) return eval->Invalid("mismatched vout0 assets dual unspendable CCaddr for fill sell"); } @@ -411,6 +414,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti if( ValidateSwapRemainder(remaining_price, tx.vout[0].nValue, assetoshis,tx.vout[1].nValue, tx.vout[2].nValue, totalunits) == false ) return eval->Invalid("mismatched remainder for fillex"); else if( ConstrainVout(tx.vout[1], 1, 0, 0) == 0 ) + ////////// not implemented yet //////////// return eval->Invalid("normal vout1 for fillex"); else if( remaining_price != 0 ) { From a645af7ee4efccaedd1f306b23904ccbe3987620 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 17 Jan 2019 13:14:03 +0500 Subject: [PATCH 454/643] corrected user cc addr for 'x' --- src/cc/assets.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index ec3266c71..33798196f 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -133,14 +133,10 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti int32_t i,starti,numvins,numvouts,preventCCvins,preventCCvouts; int64_t remaining_price,nValue,assetoshis,outputs,inputs,tmpprice,totalunits,ignore; std::vector origpubkey,tmporigpubkey,ignorepubkey; uint8_t funcid, evalCodeInOpret; - char destaddr[64], origaddr[64], assetsCCaddr[64], tokensCCaddr[64]; + char destaddr[64], origaddr[64], assetsCCaddr[64], tokensCCaddr[64], signleEvalTokensCCaddr[64]; //return true; - // we need this for validating tokens' vins/vous: - struct CCcontract_info *cpTokens, tokensC; - cpTokens = CCinit(&tokensC, EVAL_TOKENS); - //CPubKey unspendableTokensPk = GetUnspendable(cpTokens, NULL); //CPubKey unspendableAssetsPk = GetUnspendable(cpAssets, NULL); //GetCCaddress(cpTokens, tokensUnspendableCCaddr, unspendableTokensPk); @@ -157,8 +153,12 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti char tokensUnspendableAddr[64]; GetTokensCCaddress(cpAssets, tokensUnspendableAddr, GetUnspendable(cpAssets, NULL)); - // find token user cc addr: - GetCCaddress(cpTokens, tokensCCaddr, pubkey2pk(origpubkey)); + // we need this for validating single-eval tokens' vins/vous: + struct CCcontract_info *cpTokens, tokensC; + cpTokens = CCinit(&tokensC, EVAL_TOKENS); + + // find single-eval token user cc addr: + GetCCaddress(cpTokens, signleEvalTokensCCaddr, pubkey2pk(origpubkey)); fprintf(stderr,"AssetValidate (%c)\n",funcid); @@ -322,9 +322,9 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti //vout.2: normal output for change (if any) //vout.n-1: opreturn [EVAL_ASSETS] ['x'] [assetid] - if( (assetoshis= AssetValidateSellvin(cpAssets, eval, tmpprice, tmporigpubkey, tokensCCaddr, origaddr, tx, assetid)) == 0 ) + if( (assetoshis = AssetValidateSellvin(cpAssets, eval, tmpprice, tmporigpubkey, tokensCCaddr, origaddr, tx, assetid)) == 0 ) // NOTE: return(false); - else if( ConstrainVout(tx.vout[0], 1, tokensCCaddr, assetoshis) == 0 ) + else if( ConstrainVout(tx.vout[0], 1, signleEvalTokensCCaddr, assetoshis) == 0 ) return eval->Invalid("invalid vout for cancel"); preventCCvins = 3; preventCCvouts = 1; From 65dfecadf8c2125a5506b4426ac7444f0e87bc6f Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 17 Jan 2019 15:05:55 +0500 Subject: [PATCH 455/643] corr userCCaddr calc --- src/cc/CCassetsCore.cpp | 12 ++++++++---- src/cc/CCutils.cpp | 2 +- src/cc/assets.cpp | 17 ++++++++++------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index 5c48837a1..a99817d72 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -365,7 +365,7 @@ bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CT } // Calculate sell/buy owner's source token/asset address from ask/bid tx -bool GetAssetorigaddrs(struct CCcontract_info *cp, char *CCaddr, char *destaddr, const CTransaction& tx) +bool GetAssetorigaddrs(struct CCcontract_info *cp, char *userCCaddr, char *destaddr, const CTransaction& tx) { uint256 assetid,assetid2; int64_t price,nValue=0; int32_t n; uint8_t funcid; std::vector origpubkey; @@ -377,12 +377,16 @@ bool GetAssetorigaddrs(struct CCcontract_info *cp, char *CCaddr, char *destaddr, return(false); bool bGetCCaddr = false; - if (funcid == 's' || funcid == 'S') - bGetCCaddr = GetTokensCCaddress(cp, CCaddr, pubkey2pk(origpubkey)); + if (funcid == 's' || funcid == 'S') { + struct CCcontract_info *cpTokens, tokensC; + cpTokens = CCinit(&tokensC, EVAL_TOKENS); + bGetCCaddr = GetCCaddress(cpTokens, userCCaddr, pubkey2pk(origpubkey)); + //bGetCCaddr = GetTokensCCaddress(cp, CCaddr, pubkey2pk(origpubkey)); + } else if (funcid == 'b' || funcid == 'B') { struct CCcontract_info *cpTokens, tokensC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); - bGetCCaddr = GetCCaddress(cpTokens, CCaddr, pubkey2pk(origpubkey)); + bGetCCaddr = GetCCaddress(cpTokens, userCCaddr, pubkey2pk(origpubkey)); } else { std::cerr << "GetAssetorigaddrs incorrect funcid=" << (char)(funcid?funcid:' ') << std::endl; diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index ed02a779c..5d72b6b53 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -406,7 +406,7 @@ bool ConstrainVout(CTxOut vout, int32_t CCflag, char *cmpaddr, int64_t nValue) } else if ( cmpaddr != 0 && (Getscriptaddress(destaddr, vout.scriptPubKey) == 0 || strcmp(destaddr, cmpaddr) != 0) ) { - fprintf(stderr,"constrain vout error addr %s vs %s\n", cmpaddr!=0?cmpaddr:"", destaddr!=0?destaddr:""); + fprintf(stderr,"constrain vout error: check addr %s vs script addr %s\n", cmpaddr!=0?cmpaddr:"", destaddr!=0?destaddr:""); return(false); } else if ( nValue != 0 && nValue != vout.nValue ) //(nValue == 0 && vout.nValue < 10000) || ( diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index 33798196f..d2eaf39de 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -133,7 +133,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti int32_t i,starti,numvins,numvouts,preventCCvins,preventCCvouts; int64_t remaining_price,nValue,assetoshis,outputs,inputs,tmpprice,totalunits,ignore; std::vector origpubkey,tmporigpubkey,ignorepubkey; uint8_t funcid, evalCodeInOpret; - char destaddr[64], origaddr[64], assetsCCaddr[64], tokensCCaddr[64], signleEvalTokensCCaddr[64]; + char destaddr[64], origaddr[64], assetsCCaddr[64], userTokensCCaddr[64], signleEvalTokensCCaddr[64]; //return true; @@ -146,6 +146,9 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti outputs = inputs = 0; preventCCvins = preventCCvouts = -1; + if (numvouts == 0) + return eval->Invalid("AssetValidate: no vouts"); + if((funcid = DecodeAssetTokenOpRet(tx.vout[numvouts-1].scriptPubKey, evalCodeInOpret, assetid, assetid2, remaining_price, origpubkey)) == 0 ) return eval->Invalid("AssetValidate: invalid opreturn payload"); @@ -322,9 +325,9 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti //vout.2: normal output for change (if any) //vout.n-1: opreturn [EVAL_ASSETS] ['x'] [assetid] - if( (assetoshis = AssetValidateSellvin(cpAssets, eval, tmpprice, tmporigpubkey, tokensCCaddr, origaddr, tx, assetid)) == 0 ) // NOTE: + if( (assetoshis = AssetValidateSellvin(cpAssets, eval, tmpprice, tmporigpubkey, userTokensCCaddr, origaddr, tx, assetid)) == 0 ) // NOTE: return(false); - else if( ConstrainVout(tx.vout[0], 1, signleEvalTokensCCaddr, assetoshis) == 0 ) + else if( ConstrainVout(tx.vout[0], 1, userTokensCCaddr, assetoshis) == 0 ) return eval->Invalid("invalid vout for cancel"); preventCCvins = 3; preventCCvouts = 1; @@ -340,7 +343,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti //vout.3: normal output for change (if any) //'S'.vout.n-1: opreturn [EVAL_ASSETS] ['S'] [assetid] [amount of coin still required] [origpubkey] - if( (assetoshis = AssetValidateSellvin(cpAssets, eval, totalunits, tmporigpubkey, tokensCCaddr, origaddr, tx, assetid)) == 0 ) + if( (assetoshis = AssetValidateSellvin(cpAssets, eval, totalunits, tmporigpubkey, userTokensCCaddr, origaddr, tx, assetid)) == 0 ) return(false); else if( numvouts < 3 ) return eval->Invalid("not enough vouts for fillask"); @@ -384,7 +387,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti // eval->Invalid("asset2 inputs != outputs"); ////////// not implemented yet //////////// - if( (assetoshis= AssetValidateSellvin(cpTokens, eval, totalunits, tmporigpubkey, tokensCCaddr, origaddr, tx, assetid)) == 0 ) + if( (assetoshis= AssetValidateSellvin(cpTokens, eval, totalunits, tmporigpubkey, userTokensCCaddr, origaddr, tx, assetid)) == 0 ) return(false); else if( numvouts < 3 ) return eval->Invalid("not enough vouts for fillex"); @@ -397,7 +400,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti else if( tx.vout[3].scriptPubKey.IsPayToCryptoCondition() != 0 ) ////////// not implemented yet //////////// { - if( ConstrainVout(tx.vout[2], 1, tokensCCaddr, 0) == 0 ) + if( ConstrainVout(tx.vout[2], 1, userTokensCCaddr, 0) == 0 ) return eval->Invalid("vout2 doesnt go to origpubkey fillex"); else if( inputs != tx.vout[2].nValue + tx.vout[3].nValue ) { @@ -406,7 +409,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti } } ////////// not implemented yet //////////// - else if( ConstrainVout(tx.vout[2], 1, tokensCCaddr, inputs) == 0 ) + else if( ConstrainVout(tx.vout[2], 1, userTokensCCaddr, inputs) == 0 ) return eval->Invalid("vout2 doesnt match inputs fillex"); else if( ConstrainVout(tx.vout[1], 0, 0, 0) == 0 ) return eval->Invalid("vout1 is CC for fillex"); From c51e2394005e6a98da0b0cd084d90090f0190a05 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 17 Jan 2019 15:19:29 +0500 Subject: [PATCH 456/643] corr FillSell self now single-eval token addr --- src/cc/CCassetstx.cpp | 2 +- src/cc/assets.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 6a66bfcb7..ed5c28fd1 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -735,7 +735,7 @@ std::string FillSell(int64_t txfee, uint256 assetid, uint256 assetid2, uint256 a CCchange = (inputs - paid_nValue); mtx.vout.push_back(MakeTokensCC1vout(EVAL_ASSETS, orig_assetoshis - received_assetoshis, GetUnspendable(cpAssets, NULL))); // vout.0 tokens remainder to unspendable cc addr - mtx.vout.push_back(MakeTokensCC1vout(EVAL_ASSETS, received_assetoshis, mypk)); //vout.1 purchased tokens to self + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, received_assetoshis, mypk)); //vout.1 purchased tokens to self single-eval addr // NOTE: no marker here diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index d2eaf39de..3ccafa34f 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -133,7 +133,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti int32_t i,starti,numvins,numvouts,preventCCvins,preventCCvouts; int64_t remaining_price,nValue,assetoshis,outputs,inputs,tmpprice,totalunits,ignore; std::vector origpubkey,tmporigpubkey,ignorepubkey; uint8_t funcid, evalCodeInOpret; - char destaddr[64], origaddr[64], assetsCCaddr[64], userTokensCCaddr[64], signleEvalTokensCCaddr[64]; + char destaddr[64], origaddr[64], assetsCCaddr[64], userTokensCCaddr[64]; //, signleEvalTokensCCaddr[64]; //return true; @@ -161,7 +161,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti cpTokens = CCinit(&tokensC, EVAL_TOKENS); // find single-eval token user cc addr: - GetCCaddress(cpTokens, signleEvalTokensCCaddr, pubkey2pk(origpubkey)); + //GetCCaddress(cpTokens, signleEvalTokensCCaddr, pubkey2pk(origpubkey)); fprintf(stderr,"AssetValidate (%c)\n",funcid); From 7c16ba9ca21d6b85a015b8e044338dcda80b0f90 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 17 Jan 2019 18:36:03 +0500 Subject: [PATCH 457/643] some debug loggin removed --- src/cc/CCassetsCore.cpp | 13 +++---------- src/cc/CCtokens.cpp | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index a99817d72..f4293eb27 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -616,7 +616,7 @@ bool AssetCalcAmounts(struct CCcontract_info *cpAssets, int64_t &inputs, int64_t std::vector vopretExtra; std::vector vinPubkeysEmpty; - // TODO: why is IsTokensVout here?? + // TODO: maybe we do not need call to IsTokensVout here, cause we've already selected token vins assetoshis = IsTokensvout(false, false, cpTokens, NULL, /* vopretExtra,*/ vinTx, tx.vin[i].prevout.n, assetid, vinPubkeysEmpty); if (assetoshis != 0) { @@ -627,15 +627,8 @@ bool AssetCalcAmounts(struct CCcontract_info *cpAssets, int64_t &inputs, int64_t } } - // we do not use this flag anymore - //if ( DecodeAssetOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,id,id2,tmpprice,tmporigpubkey) == 't' && id == assetid ) - //flag = 1; - //else - //flag = 0; - - for (int32_t i = 0; i vinPubkeys; - if ((nValue = IsTokensvout(true, true/*<--add only checked uxtos */, cp, NULL, /*vopretExtra,*/ vintx, vout, tokenid, vinPubkeys)) > 0 && myIsutxo_spentinmempool(txid, vout) == 0) + if ((nValue = IsTokensvout(true, true/*<--add only checked token uxtos */, cp, NULL, vintx, vout, tokenid)) > 0 && myIsutxo_spentinmempool(txid, vout) == 0) { if (total != 0 && maxinputs != 0) mtx.vin.push_back(CTxIn(txid, vout, CScript())); diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 48dc543ab..2b882f95b 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -540,7 +540,6 @@ template int64_t Add1of2AddressInputs(struct CCcontract_info* cp, uint256 tokenid; uint256 fundingTxidInOpret; uint8_t hasHeirSpendingBegunDummy; - std::vector vinPubkeysEmpty; CScript heirScript = (heirtx.vout.size() > 0) ? heirtx.vout[heirtx.vout.size() - 1].scriptPubKey : CScript(); // check boundary uint8_t funcId = DecodeHeirEitherOpRet(heirScript, tokenid, fundingTxidInOpret, hasHeirSpendingBegunDummy, false); @@ -548,7 +547,7 @@ template int64_t Add1of2AddressInputs(struct CCcontract_info* cp, if ((txid == fundingtxid || fundingTxidInOpret == fundingtxid) && funcId != 0 && isMyFuncId(funcId) && - (typeid(Helper) != typeid(TokenHelper) || IsTokensvout(true, true, cp, nullptr, heirtx, voutIndex, tokenid, vinPubkeysEmpty) > 0) && // token validation logic + (typeid(Helper) != typeid(TokenHelper) || IsTokensvout(true, true, cp, nullptr, heirtx, voutIndex, tokenid) > 0) && // token validation logic //(voutValue = IsHeirFundingVout(cp, heirtx, voutIndex, ownerPubkey, heirPubkey)) > 0 && // heir contract vout validation logic - not used since we moved to 2-eval vouts !myIsutxo_spentinmempool(txid, voutIndex)) { From 9dc403f33153695810fc59b8b5899cab6e53030f Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 17 Jan 2019 19:42:02 +0500 Subject: [PATCH 459/643] corr call to IsTokenVout in heir --- src/cc/heir.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 2b882f95b..76b2e5537 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -588,7 +588,6 @@ template int64_t LifetimeHeirContractFunds(struct CCcontract_info uint256 tokenid; uint256 fundingTxidInOpret; uint8_t hasHeirSpendingBegunDummy; - std::vector vinPubkeysEmpty; const int32_t ivout = 0; CScript heirScript = (heirtx.vout.size() > 0) ? heirtx.vout[heirtx.vout.size() - 1].scriptPubKey : CScript(); // check boundary @@ -599,7 +598,7 @@ template int64_t LifetimeHeirContractFunds(struct CCcontract_info if (funcId != 0 && (txid == fundingtxid || fundingTxidInOpret == fundingtxid) && isMyFuncId(funcId) && !isSpendingTx(funcId) && - (typeid(Helper) != typeid(TokenHelper) || IsTokensvout(true, true, cp, nullptr, heirtx, ivout, tokenid, vinPubkeysEmpty) > 0) && + (typeid(Helper) != typeid(TokenHelper) || IsTokensvout(true, true, cp, nullptr, heirtx, ivout, tokenid) > 0) && !myIsutxo_spentinmempool(txid, ivout)) // exclude tx in mempool { total += it->second; // dont do this: tx.vout[ivout].nValue; // in vin[0] always is the pay to 1of2 addr (funding or change) From 4b71e625573aff67c2661fb240e1f6741efe7770 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 17 Jan 2019 20:27:19 +0500 Subject: [PATCH 460/643] disabled debug loggin in FinalizeCCtx --- src/cc/CCtx.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 2116e350b..1ca4fbf91 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -153,7 +153,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { Getscriptaddress(destaddr,vintx.vout[utxovout].scriptPubKey); //fprintf(stderr,"FinalizeCCTx() vin.%d is CC %.8f -> (%s)\n",i,(double)utxovalues[i]/COIN,destaddr); - std::cerr << "FinalizeCCtx() searching destaddr=" << destaddr << " myaddr=" << myaddr << std::endl; + //std::cerr << "FinalizeCCtx() searching destaddr=" << destaddr << " myaddr=" << myaddr << std::endl; if( strcmp(destaddr,myaddr) == 0 ) { privkey = myprivkey; @@ -163,30 +163,30 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { privkey = myprivkey; cond = mytokenscond; - fprintf(stderr,"FinalizeCCTx() matched dual-eval TokensCC1vout CC addr.(%s)\n",mytokensaddr); + //fprintf(stderr,"FinalizeCCTx() matched dual-eval TokensCC1vout CC addr.(%s)\n",mytokensaddr); } else if (strcmp(destaddr, mysingletokensaddr) == 0) // if this is TokensCC1vout { privkey = myprivkey; cond = mysingletokenscond; - fprintf(stderr, "FinalizeCCTx() matched single-eval token CC1vout CC addr.(%s)\n", mytokensaddr); + //fprintf(stderr, "FinalizeCCTx() matched single-eval token CC1vout CC addr.(%s)\n", mytokensaddr); } else if ( strcmp(destaddr,unspendable) == 0 ) { privkey = unspendablepriv; cond = othercond; - fprintf(stderr,"FinalizeCCTx() matched unspendable CC addr.(%s)\n",unspendable); + //fprintf(stderr,"FinalizeCCTx() matched unspendable CC addr.(%s)\n",unspendable); } else if (strcmp(destaddr, tokensunspendable) == 0) { privkey = unspendablepriv; cond = othertokenscond; - fprintf(stderr,"FinalizeCCTx() matched tokensunspendable CC addr.(%s)\n",unspendable); + //fprintf(stderr,"FinalizeCCTx() matched tokensunspendable CC addr.(%s)\n",unspendable); } // check if this is the 2nd additional evalcode + 'unspendable' cc addr: else if ( strcmp(destaddr,cp->unspendableaddr2) == 0) { - fprintf(stderr,"FinalizeCCTx() matched %s unspendable2!\n",cp->unspendableaddr2); + //fprintf(stderr,"FinalizeCCTx() matched %s unspendable2!\n",cp->unspendableaddr2); privkey = cp->unspendablepriv2; if ( othercond2 == 0 ) othercond2 = MakeCCcond1(cp->evalcode2, cp->unspendablepk2); @@ -195,7 +195,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran // check if this is 3rd additional evalcode + 'unspendable' cc addr: else if ( strcmp(destaddr,cp->unspendableaddr3) == 0 ) { - fprintf(stderr,"FinalizeCCTx() matched %s unspendable3!\n",cp->unspendableaddr3); + //fprintf(stderr,"FinalizeCCTx() matched %s unspendable3!\n",cp->unspendableaddr3); privkey = cp->unspendablepriv3; if ( othercond3 == 0 ) othercond3 = MakeCCcond1(cp->evalcode3,cp->unspendablepk3); @@ -204,7 +204,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran // check if this is spending from 1of2 cc coins addr: else if (strcmp(cp->coins1of2addr, destaddr) == 0) { - fprintf(stderr,"FinalizeCCTx() matched %s unspendable1of2!\n",cp->coins1of2addr); + //fprintf(stderr,"FinalizeCCTx() matched %s unspendable1of2!\n",cp->coins1of2addr); privkey = myprivkey; if (othercond1of2 == 0) othercond1of2 = MakeCCcond1of2(cp->evalcode, cp->coins1of2pk[0], cp->coins1of2pk[1]); @@ -213,7 +213,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran // check if this is spending from 1of2 cc tokens addr: else if (strcmp(cp->tokens1of2addr, destaddr) == 0) { - fprintf(stderr,"FinalizeCCTx() matched %s cp->tokens1of2addr!\n", cp->tokens1of2addr); + //fprintf(stderr,"FinalizeCCTx() matched %s cp->tokens1of2addr!\n", cp->tokens1of2addr); privkey = myprivkey; if (othercond1of2tokens == 0) othercond1of2tokens = MakeTokensCCcond1of2(cp->evalcode, cp->tokens1of2pk[0], cp->tokens1of2pk[1]); From 80a1ef04f2a2ffcddaa2712bedc49dd5c486894e Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 17 Jan 2019 20:41:18 +0500 Subject: [PATCH 461/643] added proc of incorrect tokenid to tokenorders --- src/wallet/rpcwallet.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6928f4361..0710bc698 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6974,9 +6974,13 @@ UniValue tokenorders(const UniValue& params, bool fHelp) throw runtime_error("tokenorders [tokenid]\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - if ( params.size() == 1 ) - tokenid = Parseuint256((char *)params[0].get_str().c_str()); - else memset(&tokenid,0,sizeof(tokenid)); + if (params.size() == 1) { + tokenid = Parseuint256((char *)params[0].get_str().c_str()); + if (tokenid == zeroid) + throw runtime_error("incorrect tokenid\n"); + } + else + memset(&tokenid,0,sizeof(tokenid)); return(AssetOrders(tokenid)); } From d63d43c8ef3d00c59871f7782dceee26099f029a Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 17 Jan 2019 22:20:11 +0500 Subject: [PATCH 462/643] heir funcs changed to one set --- src/cc/CCHeir.h | 17 +- src/cc/heir.cpp | 415 ++++++++++++++++++++------------------- src/cc/heir_validate.h | 2 +- src/rpc/server.cpp | 4 +- src/rpc/server.h | 3 - src/wallet/rpcwallet.cpp | 299 ++-------------------------- 6 files changed, 239 insertions(+), 501 deletions(-) diff --git a/src/cc/CCHeir.h b/src/cc/CCHeir.h index 8399474a7..ecaff9cdb 100644 --- a/src/cc/CCHeir.h +++ b/src/cc/CCHeir.h @@ -27,19 +27,10 @@ bool HeirValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, class CoinHelper; class TokenHelper; -// CCcustom - -// this would not link -//template std::string HeirFund(uint64_t txfee,int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 assetid); -//template UniValue HeirAdd(uint256 fundingtxid, uint64_t txfee, int64_t amount); -//template UniValue HeirClaim(uint256 fundingtxid, uint64_t txfee, int64_t nValue); - -UniValue HeirFundCoinCaller(uint64_t txfee, int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 assetid); -UniValue HeirFundTokenCaller(uint64_t txfee, int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 assetid); -UniValue HeirClaimCoinCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount); -UniValue HeirClaimTokenCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount); -UniValue HeirAddCoinCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount); -UniValue HeirAddTokenCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount); +UniValue HeirFundCoinCaller(uint64_t txfee, int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid); +UniValue HeirFundTokenCaller(uint64_t txfee, int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid); +UniValue HeirClaimCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount); +UniValue HeirAddCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount); UniValue HeirInfo(uint256 fundingtxid); UniValue HeirList(); diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 76b2e5537..4a78c69ac 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -14,8 +14,6 @@ ******************************************************************************/ #include "CCHeir.h" -#include "CCtokens.h" - #include "heir_validate.h" class CoinHelper; @@ -122,27 +120,27 @@ bool HeirValidate(struct CCcontract_info* cpHeir, Eval* eval, const CTransaction //if (chainActive.Height() < 741) // return true; - uint256 fundingTxidInOpret = zeroid, latestTxid = zeroid, dummyTokenid, tokenid = zeroid; + uint256 fundingTxidInOpret = zeroid, latestTxid = zeroid, dummyTokenid, tokenidThis, tokenid = zeroid; CScript fundingTxOpRetScript; uint8_t hasHeirSpendingBegun = 0, hasHeirSpendingBegunDummy; CScript opret = (tx.vout.size() > 0) ? tx.vout[tx.vout.size() - 1].scriptPubKey : CScript(); // check boundary - uint8_t funcId = DecodeHeirEitherOpRet(opret, tokenid, fundingTxidInOpret, hasHeirSpendingBegunDummy, true); + uint8_t funcId = DecodeHeirEitherOpRet(opret, tokenidThis, fundingTxidInOpret, hasHeirSpendingBegunDummy, true); if (funcId == 0) return eval->Invalid("invalid opreturn format"); if (funcId != 'F') { if (fundingTxidInOpret == zeroid) { - return eval->Invalid("invalid tx opreturn format: no fundingtxid present"); + return eval->Invalid("incorrect tx opreturn: no fundingtxid present"); } - if (tokenid == zeroid) - latestTxid = FindLatestFundingTx(fundingTxidInOpret, dummyTokenid, fundingTxOpRetScript, hasHeirSpendingBegun); - else - latestTxid = FindLatestFundingTx(fundingTxidInOpret, tokenid, fundingTxOpRetScript, hasHeirSpendingBegun); + latestTxid = FindLatestFundingTx(fundingTxidInOpret, tokenid, fundingTxOpRetScript, hasHeirSpendingBegun); + + if( tokenid != zeroid && tokenid != tokenidThis ) + return eval->Invalid("incorrect tx tokenid"); if (latestTxid == zeroid) { - return eval->Invalid("invalid heir transaction: no funding tx found"); + return eval->Invalid("no fundingtx found"); } } else { @@ -406,7 +404,7 @@ uint8_t DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, uint256 &f * find the latest funding tx: it may be the first F tx or one of A or C tx's * Note: this function is also called from validation code (use non-locking calls) */ -template uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, CScript& fundingOpretScript, uint8_t &hasHeirSpendingBegun) +uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, CScript& fundingOpretScript, uint8_t &hasHeirSpendingBegun) { CTransaction fundingtx; uint256 hashBlock; @@ -489,7 +487,7 @@ template uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_ } // overload for validation code -template uint256 FindLatestFundingTx(uint256 fundingtxid, uint256 &tokenid, CScript& opRetScript, uint8_t &hasHeirSpendingBegun) +uint256 FindLatestFundingTx(uint256 fundingtxid, uint256 &tokenid, CScript& opRetScript, uint8_t &hasHeirSpendingBegun) { uint8_t funcId; CPubKey ownerPubkey; @@ -497,15 +495,15 @@ template uint256 FindLatestFundingTx(uint256 fundingtxid, uint256 int64_t inactivityTime; std::string heirName; - return _FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, opRetScript, hasHeirSpendingBegun); + return _FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, opRetScript, hasHeirSpendingBegun); } // overload for transaction creation code -template uint256 FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint8_t &hasHeirSpendingBegun) +uint256 FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint8_t &hasHeirSpendingBegun) { CScript opRetScript; - return _FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, opRetScript, hasHeirSpendingBegun); + return _FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, opRetScript, hasHeirSpendingBegun); } // add inputs of 1 of 2 cc address @@ -704,111 +702,115 @@ UniValue HeirFundTokenCaller(uint64_t txfee, int64_t funds, std::string heirName * creates tx to add more funds to cryptocondition address for spending by either funds' owner or heir * @return result object with raw tx or error text */ -template UniValue HeirAdd(uint256 fundingtxid, uint64_t txfee, int64_t amount) +template UniValue _HeirAdd(uint256 fundingtxid, uint64_t txfee, int64_t amount, uint256 latesttxid, uint8_t funcId, uint256 tokenid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName, uint8_t hasHeirSpendingBegun) { - UniValue result(UniValue::VOBJ); //, a(UniValue::VARR); + UniValue result(UniValue::VOBJ); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey ownerPubkey, heirPubkey; int64_t inputs, CCchange = 0; - int64_t inactivityTimeSec; struct CCcontract_info *cp, C; std::string rawhex; - uint256 lasttxid, tokenid; - std::string heirName; - uint8_t funcId; - uint8_t hasHeirSpendingBegun = 0; cp = CCinit(&C, Helper::getMyEval()); // for tokens shoud be EVAL_TOKENS to sign it correctly! - //cp = CCinit(&C, EVAL_HEIR); // for tokens shoud be EVAL_TOKENS to sign it correctly! if (txfee == 0) txfee = 10000; - if ((lasttxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun)) != zeroid) { - int32_t numblocks; + CPubKey myPubkey = pubkey2pk(Mypubkey()); - CPubKey myPubkey = pubkey2pk(Mypubkey()); + // check if it is the owner + if (myPubkey != ownerPubkey) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "adding funds is only allowed for the owner of this contract")); + return result; + } - // check if it is the owner - if (myPubkey != ownerPubkey) { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "adding funds is only allowed for the owner of this contract")); - return result; - } + if (AddNormalinputs(mtx, myPubkey, txfee, 3) > 0) { // txfee for miners - if (AddNormalinputs(mtx, myPubkey, txfee, 3) > 0) { // txfee for miners + int64_t inputs, change; - int64_t inputs, change; + if ((inputs = Helper::addOwnerInputs(tokenid, mtx, myPubkey, amount, 64)) > 0) { // TODO: why 64 max inputs? - if ((inputs = Helper::addOwnerInputs(tokenid, mtx, myPubkey, amount, 64)) > 0) { // TODO: why 64 max inputs? + // we do not use markers anymore - storing data in opreturn is better + // add marker vout: + /* char markeraddr[64]; + CPubKey markerpubkey = CCtxidaddr(markeraddr, fundingtxid); + mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(markerpubkey)) << OP_CHECKSIG)); // txfee 1, txfee 2 - for miners + std::cerr << "HeirAdd() adding markeraddr=" << markeraddr << '\n'; */ - // we do not use markers anymore - storing data in opreturn is better - // add marker vout: - /* char markeraddr[64]; - CPubKey markerpubkey = CCtxidaddr(markeraddr, fundingtxid); - mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(markerpubkey)) << OP_CHECKSIG)); // txfee 1, txfee 2 - for miners - std::cerr << "HeirAdd() adding markeraddr=" << markeraddr << '\n'; */ + // add cryptocondition to spend this funded amount for either pk + mtx.vout.push_back(Helper::make1of2Vout(amount, ownerPubkey, heirPubkey)); - // add cryptocondition to spend this funded amount for either pk - mtx.vout.push_back(Helper::make1of2Vout(amount, ownerPubkey, heirPubkey)); + if (inputs > amount) + change = (inputs - amount); // -txfee <-- txfee pays user - if (inputs > amount) - change = (inputs - amount); // -txfee <-- txfee pays user + //std::cerr << "HeirAdd() inputs=" << inputs << " amount=" << amount << " txfee=" << txfee << " change=" << change << '\n'; - //std::cerr << "HeirAdd() inputs=" << inputs << " amount=" << amount << " txfee=" << txfee << " change=" << change << '\n'; - - if (change != 0) { // vout[1] - mtx.vout.push_back(Helper::makeUserVout(change, myPubkey)); - } - - // add 1of2 vout validation pubkeys - needed only for tokens: - std::vector voutTokenPubkeys; - voutTokenPubkeys.push_back(ownerPubkey); - voutTokenPubkeys.push_back(heirPubkey); - - // add opreturn 'A' and sign tx: // this txfee ignored - std::string rawhextx = (FinalizeCCTx(0, cp, mtx, myPubkey, txfee, - Helper::makeAddOpRet(tokenid, voutTokenPubkeys, fundingtxid, hasHeirSpendingBegun))); - - if (!rawhextx.empty()) { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hextx", rawhextx)); - } - else { - std::cerr << "HeirAdd error in FinalizeCCtx" << std::endl; - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "sign error")); - } - + if (change != 0) { // vout[1] + mtx.vout.push_back(Helper::makeUserVout(change, myPubkey)); } - else { - std::cerr << "HeirAdd cannot find owner cc inputs" << std::endl; + + // add 1of2 vout validation pubkeys - needed only for tokens: + std::vector voutTokenPubkeys; + voutTokenPubkeys.push_back(ownerPubkey); + voutTokenPubkeys.push_back(heirPubkey); + + // add opreturn 'A' and sign tx: // this txfee ignored + std::string rawhextx = (FinalizeCCTx(0, cp, mtx, myPubkey, txfee, + Helper::makeAddOpRet(tokenid, voutTokenPubkeys, fundingtxid, hasHeirSpendingBegun))); + + if (!rawhextx.empty()) { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hextx", rawhextx)); + } + else { + std::cerr << "HeirAdd error in FinalizeCCtx" << std::endl; result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "can't find owner cc inputs")); + result.push_back(Pair("error", "sign error")); } + } else { - std::cerr << "HeirAdd cannot find normal inputs for tx fee" << std::endl; + std::cerr << "HeirAdd cannot find owner cc inputs" << std::endl; result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "can't find normal inputs for tx fee")); + result.push_back(Pair("error", "can't find owner cc inputs")); } + } + else { + std::cerr << "HeirAdd cannot find normal inputs for tx fee" << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "can't find normal inputs for tx fee")); + } - } else { - fprintf(stderr, "HeirAdd can't find any heir CC funding tx's\n"); - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "can't find any heir CC funding transactions")); - } return result; } -UniValue HeirAddCoinCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount) { - return HeirAdd(fundingtxid, txfee, amount); -} -UniValue HeirAddTokenCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount) { - return HeirAdd(fundingtxid, txfee, amount); +UniValue HeirAddCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount) { + + CPubKey ownerPubkey, heirPubkey; + int64_t inactivityTimeSec; + + uint256 latesttxid, tokenid = zeroid; + uint8_t funcId; + std::string heirName; + uint8_t hasHeirSpendingBegun = 0; + + if ((latesttxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun)) != zeroid) { + if (tokenid == zeroid) + return _HeirAdd(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + else + return _HeirAdd(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + } + else { + UniValue result(UniValue::VOBJ); + + fprintf(stderr, "HeirAdd() can't find any heir CC funding tx's\n"); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "can't find any heir CC funding transactions")); + return result; + } } @@ -817,146 +819,155 @@ UniValue HeirAddTokenCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount) * creates tx to spend funds from cryptocondition address by either funds' owner or heir * @return result object with raw tx or error text */ -template UniValue HeirClaim(uint256 fundingtxid, uint64_t txfee, int64_t amount) +template UniValue _HeirClaim(uint256 fundingtxid, uint64_t txfee, int64_t amount, uint256 latesttxid, uint8_t funcId, uint256 tokenid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName, uint8_t hasHeirSpendingBegun) { - UniValue result(UniValue::VOBJ); //, a(UniValue::VARR); + UniValue result(UniValue::VOBJ); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey myPubkey, ownerPubkey, heirPubkey; + CPubKey myPubkey; int64_t inputs, change = 0; - int64_t inactivityTimeSec; struct CCcontract_info *cp, C; - uint256 latesttxid, tokenid; - uint8_t funcId; - std::string heirName; - uint8_t hasHeirSpendingBegun = 0; - - //cp = CCinit(&C, Helper::getMyEval()); cp = CCinit(&C, EVAL_HEIR); if (txfee == 0) txfee = 10000; - if ((latesttxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun)) != zeroid) { - int32_t numblocks; - uint64_t durationSec = 0; + int32_t numblocks; + uint64_t durationSec = 0; - // we do not need to find duration if spending already has begun - if (!hasHeirSpendingBegun) { - durationSec = CCduration(numblocks, latesttxid); - std::cerr << "HeirClaim() duration=" << durationSec << " inactivityTime=" << inactivityTimeSec << " numblocks=" << numblocks << std::endl; - } + // we do not need to find duration if spending already has begun + if (!hasHeirSpendingBegun) { + durationSec = CCduration(numblocks, latesttxid); + std::cerr << "HeirClaim() duration=" << durationSec << " inactivityTime=" << inactivityTimeSec << " numblocks=" << numblocks << std::endl; + } - // spending is allowed if there is already spending tx or inactivity time - //bool isAllowedToHeir = (funcId == 'C' || durationSec > inactivityTimeSec) ? true : false; - bool isAllowedToHeir = (hasHeirSpendingBegun || durationSec > inactivityTimeSec) ? true : false; - myPubkey = pubkey2pk(Mypubkey()); + // spending is allowed if there is already spending tx or inactivity time + //bool isAllowedToHeir = (funcId == 'C' || durationSec > inactivityTimeSec) ? true : false; + bool isAllowedToHeir = (hasHeirSpendingBegun || durationSec > inactivityTimeSec) ? true : false; + myPubkey = pubkey2pk(Mypubkey()); - // if it is the heir, check if spending not allowed to heir yet - if (myPubkey == heirPubkey && !isAllowedToHeir) { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "spending is not allowed yet for the heir")); - return result; - } + // if it is the heir, check if spending not allowed to heir yet + if (myPubkey == heirPubkey && !isAllowedToHeir) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "spending is not allowed yet for the heir")); + return result; + } + + // we do not use markers any more: + // we allow owner to spend funds at any time: + // if it is the owner, check if spending already allowed to heir + /* if (myPubkey == ownerPubkey && isAllowedToHeir) { + result.push_back(Pair("result", "spending is not already allowed for the owner")); + return result; + } */ + + // add spending txfee from the calling user + if (AddNormalinputs(mtx, myPubkey, txfee, 3) > 0) { + + // add spending from cc 1of2 address + if ((inputs = Add1of2AddressInputs(cp, fundingtxid, mtx, ownerPubkey, heirPubkey, amount, 60)) >= amount) // TODO: why only 60 inputs? + { + /*if (inputs < amount) { + std::cerr << "HeirClaim() cant find enough HeirCC 1of2 inputs, found=" << inputs << " required=" << amount << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "can't find heir CC funding")); - // we do not use markers any more: - // we allow owner to spend funds at any time: - // if it is the owner, check if spending already allowed to heir - /* if (myPubkey == ownerPubkey && isAllowedToHeir) { - result.push_back(Pair("result", "spending is not already allowed for the owner")); return result; - } */ + }*/ - // add spending txfee from the calling user - if (AddNormalinputs(mtx, myPubkey, txfee, 3) > 0) { + // add vout with amount to claiming address + mtx.vout.push_back(Helper::makeUserVout(amount, myPubkey)); // vout[0] - // add spending from cc 1of2 address - if ((inputs = Add1of2AddressInputs(cp, fundingtxid, mtx, ownerPubkey, heirPubkey, amount, 60)) >= amount) // TODO: why only 60 inputs? - { - /*if (inputs < amount) { - std::cerr << "HeirClaim() cant find enough HeirCC 1of2 inputs, found=" << inputs << " required=" << amount << std::endl; - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "can't find heir CC funding")); + // calc and add change vout: + if (inputs > amount) + change = (inputs - amount); // -txfee <-- txfee pays user - return result; - }*/ + //std::cerr << "HeirClaim() inputs=" << inputs << " amount=" << amount << " txfee=" << txfee << " change=" << change << '\n'; - // add vout with amount to claiming address - mtx.vout.push_back(Helper::makeUserVout(amount, myPubkey)); // vout[0] - - // calc and add change vout: - if (inputs > amount) - change = (inputs - amount); // -txfee <-- txfee pays user - - //std::cerr << "HeirClaim() inputs=" << inputs << " amount=" << amount << " txfee=" << txfee << " change=" << change << '\n'; - - // change to 1of2 funding addr: - if (change != 0) { // vout[1] - mtx.vout.push_back(Helper::make1of2Vout(change, ownerPubkey, heirPubkey)); // using always pubkeys from OP_RETURN in order to not mixing them up! - } - - // add marker vout: - /*char markeraddr[64]; - CPubKey markerpubkey = CCtxidaddr(markeraddr, fundingtxid); - // NOTE: amount = 0 is not working: causes error code: -26, error message : 64 : dust - mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(markerpubkey)) << OP_CHECKSIG)); // txfee 1, txfee 2 - for miners - std::cerr << "HeirClaim() adding markeraddr=" << markeraddr << '\n'; */ - - // get address of 1of2 cond - char coinaddr[64]; - Helper::GetCoinsOrTokensCCaddress1of2(coinaddr, ownerPubkey, heirPubkey); - - // retrieve priv key addresses for FinalizeCCtx: - uint8_t myprivkey[32]; - Myprivkey(myprivkey); - - // set pubkeys for finding 1of2 cc in FinalizeCCtx to sign it: - Helper::CCaddrCoinsOrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); - - // add 1of2 vout validation pubkeys (this is for tokens): - std::vector voutTokenPubkeys; - voutTokenPubkeys.push_back(ownerPubkey); - voutTokenPubkeys.push_back(heirPubkey); - - // add opreturn 'C' and sign tx: // this txfee will be ignored - std::string rawhextx = FinalizeCCTx(0, cp, mtx, myPubkey, txfee, - Helper::makeClaimOpRet(tokenid, voutTokenPubkeys, fundingtxid, (myPubkey == heirPubkey) ? 1 : hasHeirSpendingBegun)); // forward isHeirSpending to the next latest tx - - if (!rawhextx.empty()) { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hextx", rawhextx)); - } - else { - std::cerr << "HeirAdd error in FinalizeCCtx" << std::endl; - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "sign error")); - } - - } else { - fprintf(stderr, "HeirClaim() cant find Heir CC inputs\n"); - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "can't find heir CC funding")); + // change to 1of2 funding addr: + if (change != 0) { // vout[1] + mtx.vout.push_back(Helper::make1of2Vout(change, ownerPubkey, heirPubkey)); // using always pubkeys from OP_RETURN in order to not mixing them up! } + + // add marker vout: + /*char markeraddr[64]; + CPubKey markerpubkey = CCtxidaddr(markeraddr, fundingtxid); + // NOTE: amount = 0 is not working: causes error code: -26, error message : 64 : dust + mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(markerpubkey)) << OP_CHECKSIG)); // txfee 1, txfee 2 - for miners + std::cerr << "HeirClaim() adding markeraddr=" << markeraddr << '\n'; */ + + // get address of 1of2 cond + char coinaddr[64]; + Helper::GetCoinsOrTokensCCaddress1of2(coinaddr, ownerPubkey, heirPubkey); + + // retrieve priv key addresses for FinalizeCCtx: + uint8_t myprivkey[32]; + Myprivkey(myprivkey); + + // set pubkeys for finding 1of2 cc in FinalizeCCtx to sign it: + Helper::CCaddrCoinsOrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); + + // add 1of2 vout validation pubkeys (this is for tokens): + std::vector voutTokenPubkeys; + voutTokenPubkeys.push_back(ownerPubkey); + voutTokenPubkeys.push_back(heirPubkey); + + // add opreturn 'C' and sign tx: // this txfee will be ignored + std::string rawhextx = FinalizeCCTx(0, cp, mtx, myPubkey, txfee, + Helper::makeClaimOpRet(tokenid, voutTokenPubkeys, fundingtxid, (myPubkey == heirPubkey) ? 1 : hasHeirSpendingBegun)); // forward isHeirSpending to the next latest tx + + if (!rawhextx.empty()) { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hextx", rawhextx)); + } + else { + std::cerr << "HeirAdd error in FinalizeCCtx" << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "sign error")); + } + } else { - fprintf(stderr, "HeirClaim() cant find sufficient user inputs for tx fee\n"); + fprintf(stderr, "HeirClaim() cant find Heir CC inputs\n"); result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "can't find sufficient user inputs to pay transaction fee")); + result.push_back(Pair("error", "can't find heir CC funding")); } } else { - fprintf(stderr, "HeirClaim() can't find any heir CC funding tx's\n"); + fprintf(stderr, "HeirClaim() cant find sufficient user inputs for tx fee\n"); result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "can't find any heir CC funding transactions")); + result.push_back(Pair("error", "can't find sufficient user inputs to pay transaction fee")); } + return result; } -UniValue HeirClaimCoinCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount) { - return HeirClaim(fundingtxid, txfee, amount); -} -UniValue HeirClaimTokenCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount) { - return HeirClaim(fundingtxid, txfee, amount); +UniValue HeirClaimCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount) { + + CPubKey ownerPubkey, heirPubkey; + int64_t inactivityTimeSec; + + uint256 latesttxid, tokenid = zeroid; + uint8_t funcId; + std::string heirName; + uint8_t hasHeirSpendingBegun = 0; + + if ((latesttxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun)) != zeroid) { + if( tokenid == zeroid ) + return _HeirClaim(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + else + return _HeirClaim(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + + } + else { + UniValue result(UniValue::VOBJ); + + fprintf(stderr, "HeirClaim() can't find any heir CC funding tx's\n"); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "can't find any heir CC funding transactions")); + return result; + } } + /** * heirinfo rpc call implementation * returns some information about heir CC contract plan by a handle of initial fundingtxid: @@ -980,32 +991,28 @@ UniValue HeirInfo(uint256 fundingtxid) if (myGetTransaction(fundingtxid, fundingtx, hashBlock) && fundingtx.vout.size()) { CPubKey ownerPubkey, heirPubkey; - uint256 latestFundingTxid; uint256 dummyTokenid, tokenid = zeroid; // important to clear tokenid std::string heirName; int64_t inactivityTimeSec; const bool noLogging = false; + uint8_t funcId; - - CScript opret = fundingtx.vout.size() > 0 ? fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey : CScript(); + /*CScript opret = fundingtx.vout.size() > 0 ? fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey : CScript(); uint8_t funcId = DecodeHeirEitherOpRet(opret, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, true); if (funcId == 0) { std::cerr << "HeirInfo() this fundingtx is incorrect" << std::endl; result.push_back(Pair("result", "error")); result.push_back(Pair("error", "initial tx F not found")); return result; - } + }*/ struct CCcontract_info *cp, C; cp = CCinit(&C, EVAL_HEIR); uint8_t hasHeirSpendingBegun = 0; - if (tokenid == zeroid) // coins - latestFundingTxid = FindLatestFundingTx(fundingtxid, funcId, dummyTokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); - else // tokens - latestFundingTxid = FindLatestFundingTx(fundingtxid, funcId, tokenid /*<-verify for tokens*/, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); - + uint256 latestFundingTxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + if (latestFundingTxid != zeroid) { int32_t numblocks; uint64_t durationSec = 0; diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index f091e1381..88c02f239 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -10,7 +10,7 @@ CScript EncodeHeirCreateOpRet(uint8_t funcid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName); CScript EncodeHeirOpRet(uint8_t funcid, uint256 fundingtxid, uint8_t isHeirSpendingBegan); -template uint256 FindLatestFundingTx(uint256 fundingtxid, uint256 &tokenid, CScript& opRetScript, uint8_t &isHeirSpendingBegan); +uint256 FindLatestFundingTx(uint256 fundingtxid, uint256 &tokenid, CScript& opRetScript, uint8_t &isHeirSpendingBegan); //uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256& fundingtxid, uint8_t &isHeirSpendingBegan, bool noLogging = false); //uint8_t DecodeHeirOpRet(CScript scriptPubKey, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging = false); uint8_t DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging = false); diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 5c32b2f5a..5761b5bf7 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -411,9 +411,9 @@ static const CRPCCommand vRPCCommands[] = { "heir", "heirfund", &heirfund, true }, { "heir", "heiradd", &heiradd, true }, { "heir", "heirclaim", &heirclaim, true }, - { "heir", "heirfundtokens", &heirfundtokens, true }, +/* { "heir", "heirfundtokens", &heirfundtokens, true }, { "heir", "heiraddtokens", &heiraddtokens, true }, - { "heir", "heirclaimtokens", &heirclaimtokens, true }, + { "heir", "heirclaimtokens", &heirclaimtokens, true },*/ { "heir", "heirinfo", &heirinfo, true }, { "heir", "heirlist", &heirlist, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 7c85c43b6..99b7e8678 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -257,9 +257,6 @@ extern UniValue heiraddress(const UniValue& params, bool fHelp); extern UniValue heirfund(const UniValue& params, bool fHelp); extern UniValue heiradd(const UniValue& params, bool fHelp); extern UniValue heirclaim(const UniValue& params, bool fHelp); -extern UniValue heirfundtokens(const UniValue& params, bool fHelp); -extern UniValue heiraddtokens(const UniValue& params, bool fHelp); -extern UniValue heirclaimtokens(const UniValue& params, bool fHelp); extern UniValue heirinfo(const UniValue& params, bool fHelp); extern UniValue heirlist(const UniValue& params, bool fHelp); extern UniValue channelsaddress(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 0710bc698..538155331 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5417,7 +5417,6 @@ UniValue gatewaysaddress(const UniValue& params, bool fHelp) UniValue heiraddress(const UniValue& params, bool fHelp) { - /* struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_HEIR); if ( fHelp || params.size() > 1 ) @@ -5427,131 +5426,6 @@ UniValue heiraddress(const UniValue& params, bool fHelp) if ( params.size() == 1 ) pubkey = ParseHex(params[0].get_str().c_str()); return(CCaddress(cp,(char *)"Heir",pubkey)); - */ - - - // make fake token tx: - struct CCcontract_info *cp, C; - - if (fHelp || (params.size() < 1)) - throw runtime_error("heiraddress A|G|H|T|R assetid|destpubkey amountcoins [heirpubkey] [fundingtxid]\n"); - if (ensure_CCrequirements() < 0) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - - char badKind = ((char *)params[0].get_str().c_str())[0]; - - if (badKind == 'A') { - std::vector destPubkey; - if (params.size() == 2) { - cp = CCinit(&C, EVAL_HEIR); - destPubkey = ParseHex(params[1].get_str().c_str()); - return(CCaddress(cp, (char *)"Heir", destPubkey)); - } - else - return std::string("bad params for A"); - } - - CPubKey myPubkey = pubkey2pk(Mypubkey()); - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());; - - if (badKind != 'R') { - - if (badKind == 'G' && params.size() != 3) - return std::string("incorrect params for G"); - if (badKind == 'H' && params.size() != 5) - return std::string("incorrect params for H, = 5"); - if (badKind == 'T' && params.size() != 3) - return std::string("incorrect params for T, = 3"); - - - uint256 assetid = Parseuint256((char *)params[1].get_str().c_str()); - int64_t amount = atof(params[2].get_str().c_str()) * COIN; - - uint256 fundingtxid; - CPubKey heirPubkey; - - if (badKind == 'H') { - - std::vector heirPubkeyStr = ParseHex(params[3].get_str().c_str()); - heirPubkey = pubkey2pk(heirPubkeyStr); - - fundingtxid = Parseuint256((char *)params[4].get_str().c_str()); - } - - - - int64_t txfee = 10000; - - uint8_t evalCodeInOpret = (badKind == 'H') ? EVAL_HEIR : EVAL_GATEWAYS; - cp = CCinit(&C, EVAL_ASSETS); - - int64_t normalInputs = AddNormalinputs(mtx, myPubkey, txfee + amount, 60); - // int64_t ccInputs = 0; - - - if (badKind == 'T') { - // just empty fake token - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, amount, myPubkey)); //note you need destPubkey for sending to gateways - } - else if (badKind == 'H') { - // heir add funding tx - mtx.vout.push_back(MakeCC1of2vout(EVAL_ASSETS, amount, myPubkey, heirPubkey)); // add cryptocondition to spend amount for either pk - } - else { // if (badKind == 'G') - CPubKey gatewayContractPubKey = GetUnspendable(cp, 0); - mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(gatewayContractPubKey)) << OP_CHECKSIG)); - } - - int64_t change = (normalInputs - amount); - if (change != 0) { - mtx.vout.push_back(CTxOut(change, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG)); - } - std::cerr << "make fake token for contract=" << badKind << " added normalInputs=" << normalInputs << " change=" << change << std::endl; - - // note: it sets eval=EVAL_ASSETS in opreturn both for tokens and gateways cc addr - //script = EncodeAssetOpRet('t', assetid, zeroid, 0, (badKind == 'A' ? Mypubkey() : destPubkey)); // dimxy: are we sure about destPubkey here? it may be just pubkey of the author... - CScript opret; - assetid = revuint256(assetid); - fundingtxid = revuint256(fundingtxid); - if (badKind == 'T') - opret << OP_RETURN << E_MARSHAL(ss << (uint8_t)evalCodeInOpret << (uint8_t)'t' << assetid ); - else if (badKind == 'H') - opret << OP_RETURN << E_MARSHAL(ss << (uint8_t)evalCodeInOpret << (uint8_t)'t' << assetid << (uint8_t)'A' << myPubkey << heirPubkey << (int64_t)120 << fundingtxid); - else - opret << OP_RETURN << E_MARSHAL(ss << (uint8_t)evalCodeInOpret << (uint8_t)'t' << assetid); // EVAL_GATEWAYS - - return(FinalizeCCTx(0, cp, mtx, myPubkey, txfee, opret)); // normal change added here - } - else - { - // move vout from user cc addr to gateways unspendable - CTransaction srctx; - - uint256 hashBlock; - const bool allowSlow = false; - uint256 srctxid = Parseuint256((char *)params[1].get_str().c_str()); - - struct CCcontract_info *cp, C; - cp = CCinit(&C, EVAL_GATEWAYS); - - uint64_t txfee = 10000; - CPubKey gatewayspk = GetUnspendable(cp, 0); - - if (myGetTransaction(srctxid, srctx, hashBlock) && srctx.vout.size() > 0) { - - int64_t normalInputs = AddNormalinputs(mtx, myPubkey, 2 * txfee, 4); - - mtx.vin.push_back(CTxIn(srctxid, 2, CScript())); // repaired src tx - mtx.vout.push_back(MakeCC1vout(EVAL_GATEWAYS, srctx.vout[2].nValue, gatewayspk)); - - CScript script = srctx.vout[srctx.vout.size() - 1].scriptPubKey; - - //mtx.fOverwintered = true; - - return(FinalizeCCTx(0, cp, mtx, myPubkey, txfee, script)); // normal change added here - } - } - return std::string("there has been some error"); } @@ -7432,53 +7306,12 @@ UniValue getbalance64(const UniValue& params, bool fHelp) return ret; } -// heir contract functions for coins + +// heir contract functions for coins and tokens UniValue heirfund(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); - //uint256 txid; - int64_t txfee; - int64_t amount; - int64_t inactivitytime; - std::string hex; - std::vector pubkey; - std::string name; - - //TODO: do we need this? - if (!EnsureWalletIsAvailable(fHelp)) - return NullUniValue; - - if (fHelp || params.size() != 5) - throw runtime_error("heirfund fee funds heirname heirpubkey inactivitytime\n"); - if (ensure_CCrequirements() < 0) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); - - txfee = atof((char*)params[0].get_str().c_str()) * COIN; - amount = atof((char*)params[1].get_str().c_str()) * COIN; - name = params[2].get_str(); - pubkey = ParseHex(params[3].get_str().c_str()); - inactivitytime = atof((char*)params[4].get_str().c_str()); - - - result = HeirFundCoinCaller(txfee, amount, name, pubkey2pk(pubkey), inactivitytime, zeroid); -/* if (hex.size() > 0) { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } - else - ERR_RESULT("couldn't create heir fund");*/ - - return result; -} - - -UniValue heiradd(const UniValue& params, bool fHelp) -{ - UniValue result; // UniValue result(UniValue::VOBJ); - uint256 fundingtxid; + uint256 tokenid = zeroid; uint64_t txfee; int64_t amount; int64_t inactivitytime; @@ -7486,88 +7319,11 @@ UniValue heiradd(const UniValue& params, bool fHelp) std::vector pubkey; std::string name; - // TODO: do we need this? if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; - if (fHelp || params.size() != 3) - throw runtime_error("heiradd fee funds fundingtxid\n"); - if (ensure_CCrequirements() < 0) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); - - txfee = atof((char*)params[0].get_str().c_str()) * COIN; - amount = atof((char*)params[1].get_str().c_str()) * COIN; - fundingtxid = Parseuint256((char*)params[2].get_str().c_str()); - - result = HeirAddCoinCaller(fundingtxid, txfee, amount); - /* if ( hex.size() > 0 ) - { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldn't claim heir fund"); */ - - - return result; -} - -UniValue heirclaim(const UniValue& params, bool fHelp) -{ - UniValue result; // result(UniValue::VOBJ); - uint256 fundingtxid; - uint64_t txfee; - int64_t amount; - int64_t inactivitytime; - std::string hex; - std::vector pubkey; - std::string name; - - // do we need this? - if (!EnsureWalletIsAvailable(fHelp)) - return NullUniValue; - - if (fHelp || params.size() != 3) - throw runtime_error("heirclaim fee funds fundingtxid\n"); - if (ensure_CCrequirements() < 0) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); - - txfee = atof((char*)params[0].get_str().c_str()) * COIN; - amount = atof((char*)params[1].get_str().c_str()) * COIN; - fundingtxid = Parseuint256((char*)params[2].get_str().c_str()); - - result = HeirClaimCoinCaller(fundingtxid, txfee, amount); - /* if ( hex.size() > 0 ) - { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldn't claim heir fund"); */ - - return result; -} - -// same heir contract functions for tokens -UniValue heirfundtokens(const UniValue& params, bool fHelp) -{ - UniValue result(UniValue::VOBJ); - uint256 assetid; - uint64_t txfee; - int64_t amount; - int64_t inactivitytime; - std::string hex; - std::vector pubkey; - std::string name; - - //TODO: do we need this (dimxy)? - if (!EnsureWalletIsAvailable(fHelp)) - return NullUniValue; - - if (fHelp || params.size() != 6) - throw runtime_error("heirfundtokens fee funds heirname heirpubkey inactivitytime assetid\n"); + if (fHelp || params.size() != 5 && params.size() != 6) + throw runtime_error("heirfundtokens fee funds heirname heirpubkey inactivitytime [tokenid]\n"); if (ensure_CCrequirements() < 0) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); @@ -7578,26 +7334,27 @@ UniValue heirfundtokens(const UniValue& params, bool fHelp) amount = atoll((char*)params[1].get_str().c_str()); name = params[2].get_str(); pubkey = ParseHex(params[3].get_str().c_str()); + if( !pubkey2pk(pubkey).IsValid() ) + throw runtime_error("incorrect pubkey\n"); + inactivitytime = atof((char*)params[4].get_str().c_str()); - assetid = Parseuint256((char*)params[5].get_str().c_str()); - - - result = HeirFundTokenCaller(txfee, amount, name, pubkey2pk(pubkey), inactivitytime, assetid); -/* if (hex.size() > 0) { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); + if (params.size() == 6) { + tokenid = Parseuint256((char*)params[5].get_str().c_str()); + if(tokenid == zeroid) + throw runtime_error("incorrect tokenid\n"); } - else - ERR_RESULT("couldn't create heir fund");*/ + if( tokenid == zeroid ) + result = HeirFundCoinCaller(txfee, amount, name, pubkey2pk(pubkey), inactivitytime, zeroid); + else + result = HeirFundTokenCaller(txfee, amount, name, pubkey2pk(pubkey), inactivitytime, tokenid); return result; } - -UniValue heiraddtokens(const UniValue& params, bool fHelp) +UniValue heiradd(const UniValue& params, bool fHelp) { - UniValue result; // UniValue result(UniValue::VOBJ); + UniValue result; uint256 fundingtxid; uint64_t txfee; int64_t amount; @@ -7606,7 +7363,6 @@ UniValue heiraddtokens(const UniValue& params, bool fHelp) std::vector pubkey; std::string name; - // TODO: do we need this? if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -7622,18 +7378,11 @@ UniValue heiraddtokens(const UniValue& params, bool fHelp) amount = atoll((char*)params[1].get_str().c_str()); fundingtxid = Parseuint256((char*)params[2].get_str().c_str()); - result = HeirAddTokenCaller(fundingtxid, txfee, amount); - /* if ( hex.size() > 0 ) - { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldn't claim heir fund"); */ - - + result = HeirAddCaller(fundingtxid, txfee, amount); return result; } -UniValue heirclaimtokens(const UniValue& params, bool fHelp) +UniValue heirclaim(const UniValue& params, bool fHelp) { UniValue result; // result(UniValue::VOBJ); uint256 fundingtxid; @@ -7660,13 +7409,7 @@ UniValue heirclaimtokens(const UniValue& params, bool fHelp) amount = atoll((char*)params[1].get_str().c_str()); fundingtxid = Parseuint256((char*)params[2].get_str().c_str()); - result = HeirClaimTokenCaller(fundingtxid, txfee, amount); - /* if ( hex.size() > 0 ) - { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldn't claim heir fund"); */ - + result = HeirClaimCaller(fundingtxid, txfee, amount); return result; } From d9de6b7cde33e0ca3987857c73cd4bf74b9370c1 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 18 Jan 2019 00:47:01 +0500 Subject: [PATCH 463/643] extra logging disabled in validator --- src/cc/heir_validate.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index 88c02f239..d66777933 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -604,7 +604,7 @@ public: } } - std::cerr << "COpRetValidator::validateVout() exits with true" << std::endl; + //std::cerr << "COpRetValidator::validateVout() exits with true" << std::endl; return true; } virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } From 0b257f6dfac182abcf7b06490fbc2d19c1378867 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Jan 2019 21:49:55 -1100 Subject: [PATCH 464/643] Add 1of2 add and coin balances --- src/cc/marmara.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 4cf1a2a42..cf2382277 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -917,8 +917,16 @@ UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_ result.push_back(Pair("result","success")); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(Mypubkey())) << OP_CHECKSIG); result.push_back(Pair("myaddress",coinaddr)); + result.push_back(Pair("normal",ValueFromAmount(CCaddress_balance(coinaddr)))); + + GetCCaddress1of2(cp,coinaddr,Marmarapk,Mypubkey()); + result.push_back(Pair("myCCactivated",coinaddr)); + result.push_back(Pair("activated",ValueFromAmount(CCaddress_balance(coinaddr)))); + GetCCaddress(cp,coinaddr,Mypubkey()); result.push_back(Pair("myCCaddress",coinaddr)); + result.push_back(Pair("CCutxos",ValueFromAmount(CCaddress_balance(coinaddr)))); + if ( refpk.size() == 33 ) result.push_back(Pair("issuer",HexStr(refpk))); if ( currency.size() == 0 ) From 06ff993abd1f34ca8d9bc42d9a7f821679504541 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 18 Jan 2019 17:06:30 +0800 Subject: [PATCH 465/643] Fix rescan entire wallet when finding corrupt transaction on load. Now removes corrupt tx and re adds it with GetTransaction. --- src/wallet/walletdb.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 867bca08b..aae406de3 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -39,6 +39,7 @@ using namespace std; static uint64_t nAccountingEntryNumber = 0; +static list deadTxns; // // CWalletDB @@ -484,8 +485,11 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, CValidationState state; auto verifier = libzcash::ProofVerifier::Strict(); if (!(CheckTransaction(0,wtx, state, verifier) && (wtx.GetHash() == hash) && state.IsValid())) + { + fprintf(stderr, "Removing corrupt tx from wallet.%s\n", hash.ToString().c_str()); + deadTxns.push_back(hash); return false; - + } // Undo serialize changes in 31600 if (31404 <= wtx.fTimeReceivedIsTxTime && wtx.fTimeReceivedIsTxTime <= 31703) { @@ -933,9 +937,6 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet) { // Leave other errors alone, if we try to fix them we might make things worse. fNoncriticalErrors = true; // ... but do warn the user there is something wrong. - if (strType == "tx") - // Rescan if there is a bad transaction record: - SoftSetBoolArg("-rescan", true); } } if (!strErr.empty()) @@ -950,6 +951,24 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet) result = DB_CORRUPT; } + if (!deadTxns.empty()) + { + int32_t reAdded = 0; + BOOST_FOREACH (uint256& hash, deadTxns) { + if (!EraseTx(hash)) + fprintf(stderr, "could not delete tx.%s\n",hash.ToString().c_str()); + uint256 blockhash; CTransaction tx; + if (GetTransaction(hash,tx,blockhash,true)) + { + CWalletTx wtx(pwallet,tx); + pwallet->AddToWallet(wtx, true, NULL); + reAdded++; + } + } + fprintf(stderr, "Cleared %lu corrupted transactions from wallet. Readded %i known transactions.\n",deadTxns.size(),reAdded); + deadTxns.clear(); + } + if (fNoncriticalErrors && result == DB_LOAD_OK) result = DB_NONCRITICAL_ERROR; From e555995f194aa978e77ea65bd87427f3faf477af Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Jan 2019 22:46:56 -1100 Subject: [PATCH 466/643] Marmaralock --- src/cc/CCMarmara.h | 1 + src/cc/marmara.cpp | 43 ++++++++++++++++++++++++++++++++++------ src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/wallet/rpcwallet.cpp | 14 +++++++++++++ 5 files changed, 54 insertions(+), 6 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index fe9f7f30b..65269df77 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -31,6 +31,7 @@ int32_t MarmaraGetcreatetxid(uint256 &createtxid,uint256 txid); int32_t MarmaraGetbatontxid(std::vector &creditloop,uint256 &batontxid,uint256 txid); UniValue MarmaraCreditloop(uint256 txid); UniValue MarmaraSettlement(uint64_t txfee,uint256 batontxid); +UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height); UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...] UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 batontxid,bool automaticflag); diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index cf2382277..b57b156e1 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -395,6 +395,41 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, return(totalinputs); } +UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) +{ + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk; int64_t inputsum,change = 0; std::string rawtx,errorstr; + // scan all unlocked + // total capped at amount, change -> unlocked, if no change then scan all locked 'C' and 'P' for unlockht < refunlockht + if ( txfee == 0 ) + txfee = 10000; + cp = CCinit(&C,EVAL_MARMARA); + mypk = pubkey2pk(Mypubkey()); + Marmarapk = GetUnspendable(cp,0); + if ( (inputsum= AddNormalinputs(mtx,mypk,amount + txfee,1)) > 0 ) + { + if ( inputsum > amount+txfee ) + { + change = (inputsum - amount); + mtx.vout.push_back(CTxOut(change,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + } + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraCoinbaseOpret('L',height,mypk)); + if ( rawtx.size() == 0 ) + errorstr = (char *)"couldnt finalize CCtx"; + else + { + result.push_back(Pair("result",(char *)"success")); + result.push_back(Pair("rawtx",rawtx)); + return(result); + } + } + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",errorstr)); + return(result); +} + +// decide on what unlockht settlement change should have + UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); @@ -459,7 +494,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); if ( change > txfee ) mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,change,Marmarapk,pk)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,0,height,currency),pubkeys); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,0,unlockht,currency),pubkeys); result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); return(result); @@ -474,7 +509,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(CCtxidaddr(txidaddr,createtxid))) << OP_CHECKSIG)); // failure marker if ( refamount-remaining > 3*txfee ) mtx.vout.push_back(CTxOut(refamount-remaining-2*txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('D',createtxid,mypk,-remaining,height,currency),pubkeys); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('D',createtxid,mypk,-remaining,unlockht,currency),pubkeys); result.push_back(Pair("result",(char *)"error")); result.push_back(Pair("error",(char *)"insufficient funds")); result.push_back(Pair("rawtx",rawtx)); @@ -902,10 +937,6 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * return(result); } -// MarmaraLock(uint64_t txfee,int64_t amount,int32_t refunlockht) -// scan all unlocked -// total capped at amount, change -> unlocked, if no change then scan all locked 'C' and 'P' for unlockht < refunlockht - // get all tx, constrain by vout, issuances[] and closed[] UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,std::string currency) diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 5761b5bf7..90f8fd6db 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -458,6 +458,7 @@ static const CRPCCommand vRPCCommands[] = { "marmara", "marmarainfo", &marmara_info, true }, { "marmara", "marmaracreditloop", &marmara_creditloop, true }, { "marmara", "marmarasettlement", &marmara_settlement, true }, + { "marmara", "marmaralock", &marmara_lock, true }, // Payments { "payments", "paymentsaddress", &paymentsaddress, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 99b7e8678..d5ebb56ab 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -285,6 +285,7 @@ extern UniValue marmara_transfer(const UniValue& params, bool fHelp); extern UniValue marmara_info(const UniValue& params, bool fHelp); extern UniValue marmara_creditloop(const UniValue& params, bool fHelp); extern UniValue marmara_settlement(const UniValue& params, bool fHelp); +extern UniValue marmara_lock(const UniValue& params, bool fHelp); extern UniValue paymentsaddress(const UniValue& params, bool fHelp); extern UniValue gatewaysaddress(const UniValue& params, bool fHelp); extern UniValue gatewayslist(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a92cf4bf8..02cf85ee6 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5692,6 +5692,20 @@ UniValue marmara_settlement(const UniValue& params, bool fHelp) return(result); } +UniValue marmara_lock(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); int64_t amount; int32_t height; + if ( fHelp || params.size() > 2 || params.size() == 0 ) + { + throw runtime_error("marmaralock amount unlockht\n"); + } + amount = atof(params[0].get_str().c_str()) * COIN + 0.00000000499999; + if ( params.size() == 2 ) + height = atol(params[1].get_str().c_str()); + else height = chainActive.LastTip()->GetHeight() + 1; + return(MarmaraLock(0,amount,height)); +} + UniValue channelslist(const UniValue& params, bool fHelp) { if ( fHelp || params.size() > 0 ) From 6e4d54fb7b83bdd5c91332e7da9d1c08d8df243d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Jan 2019 22:48:50 -1100 Subject: [PATCH 467/643] Refunlockht --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index b57b156e1..8f5701553 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -494,7 +494,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); if ( change > txfee ) mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,change,Marmarapk,pk)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,0,unlockht,currency),pubkeys); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,0,refunlockht,currency),pubkeys); result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); return(result); @@ -509,7 +509,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(CCtxidaddr(txidaddr,createtxid))) << OP_CHECKSIG)); // failure marker if ( refamount-remaining > 3*txfee ) mtx.vout.push_back(CTxOut(refamount-remaining-2*txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('D',createtxid,mypk,-remaining,unlockht,currency),pubkeys); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('D',createtxid,mypk,-remaining,refunlockht,currency),pubkeys); result.push_back(Pair("result",(char *)"error")); result.push_back(Pair("error",(char *)"insufficient funds")); result.push_back(Pair("rawtx",rawtx)); From bc04276465a8ae9f57843a11903a87e7d2b57a45 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Jan 2019 22:49:41 -1100 Subject: [PATCH 468/643] refmatures --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 8f5701553..b43754cb3 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -494,7 +494,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); if ( change > txfee ) mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,change,Marmarapk,pk)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,0,refunlockht,currency),pubkeys); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,0,refmatures,currency),pubkeys); result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); return(result); @@ -509,7 +509,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(CCtxidaddr(txidaddr,createtxid))) << OP_CHECKSIG)); // failure marker if ( refamount-remaining > 3*txfee ) mtx.vout.push_back(CTxOut(refamount-remaining-2*txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('D',createtxid,mypk,-remaining,refunlockht,currency),pubkeys); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('D',createtxid,mypk,-remaining,refmatures,currency),pubkeys); result.push_back(Pair("result",(char *)"error")); result.push_back(Pair("error",(char *)"insufficient funds")); result.push_back(Pair("rawtx",rawtx)); From 68597fa670091864e017f0c07a118251822a60f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Jan 2019 22:56:06 -1100 Subject: [PATCH 469/643] Add CC out --- src/cc/marmara.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index b43754cb3..f095c5da3 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -408,6 +408,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) Marmarapk = GetUnspendable(cp,0); if ( (inputsum= AddNormalinputs(mtx,mypk,amount + txfee,1)) > 0 ) { + mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum > amount+txfee ) { change = (inputsum - amount); From 6915c400e38eac4d53022ccc0dc0f2ebb3d3576a Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Fri, 18 Jan 2019 11:14:40 +0100 Subject: [PATCH 470/643] Fix ChannelsPayment when destpub issues payment,add check_signing_pubkey --- src/cc/CCinclude.h | 1 + src/cc/CCutils.cpp | 31 +++++++++++++++++++++++++++++++ src/cc/channels.cpp | 9 +++++---- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 3f8d8f672..982f5aa77 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -222,6 +222,7 @@ std::vector Mypubkey(); bool Myprivkey(uint8_t myprivkey[]); int64_t CCduration(int32_t &numblocks,uint256 txid); bool komodo_txnotarizedconfirmed(uint256 txid); +CPubKey check_signing_pubkey(CScript scriptSig); // CCtx bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey); std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret); diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 5d72b6b53..e9c30acc1 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -599,3 +599,34 @@ bool komodo_txnotarizedconfirmed(uint256 txid) return (true); return (false); } + +CPubKey check_signing_pubkey(CScript scriptSig) +{ + + bool found = false; + CPubKey pubkey; + + auto findEval = [](CC *cond, struct CCVisitor _) { + bool r = false; + + if (cc_typeId(cond) == CC_Secp256k1) { + *(CPubKey*)_.context=buf2pk(cond->publicKey); + r = true; + } + // false for a match, true for continue + return r ? 0 : 1; + }; + + CC *cond = GetCryptoCondition(scriptSig); + + if (cond) { + CCVisitor visitor = { findEval, (uint8_t*)"", 0, &pubkey }; + bool out = !cc_visit(cond, visitor); + cc_free(cond); + + if (pubkey.IsValid()) { + return pubkey; + } + } + return CPubKey(); +} diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 2a7ebc931..824707520 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -222,6 +222,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & //vout.3: normal output of payment amount to receiver pubkey //vout.n-2: normal change //vout.n-1: opreturn - 'P' opentxid senderspubkey receiverspubkey depth numpayments secret + check_signing_pubkey(tx.vin[1].scriptSig); if (komodo_txnotarizedconfirmed(opentxid) == 0) return eval->Invalid("channelOpen is not yet confirmed(notarised)!"); else if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) @@ -422,8 +423,8 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C if ( (int32_t)it->first.index==0 && GetTransaction(it->first.txhash,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size()) > 0) { if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3)!=0 && - (tmp_txid==openTx.GetHash() || tx.GetHash()==openTx.GetHash()) && - (totalinputs=IsChannelsvout(cp,tx,srcpub,destpub,0)+IsChannelsMarkervout(cp,tx,srcpub,marker))>0) + (tmp_txid==openTx.GetHash() || tx.GetHash()==openTx.GetHash()) && IsChannelsMarkervout(cp,tx,marker==1?srcpub:destpub,marker)>0 && + (totalinputs=IsChannelsvout(cp,tx,srcpub,destpub,0))>0) { txid = it->first.txhash; break; @@ -443,7 +444,7 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C tmp_txid==openTx.GetHash() && param1 < mindepth) { txid=hash; - totalinputs=txmempool.vout[0].nValue+txmempool.vout[1].nValue; + totalinputs=txmempool.vout[0].nValue; mindepth=param1; } } @@ -543,7 +544,7 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 } if (AddNormalinputs(mtx,mypk,2*txfee,3) > 0) { - if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid,mypk)) !=0 && (change=funds-amount-txfee)>=0) + if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid,mypk)) !=0 && (change=funds-amount)>=0) { numpayments=amount/payment; if (GetTransaction(prevtxid,prevTx,hashblock,false) != 0 && (numvouts=prevTx.vout.size()) > 0 && From 6ab5254887ed1b88d82f1114d1b2a19498353caf Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Fri, 18 Jan 2019 11:18:38 +0100 Subject: [PATCH 471/643] Fix --- src/cc/channels.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 824707520..a375edbda 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -222,7 +222,6 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & //vout.3: normal output of payment amount to receiver pubkey //vout.n-2: normal change //vout.n-1: opreturn - 'P' opentxid senderspubkey receiverspubkey depth numpayments secret - check_signing_pubkey(tx.vin[1].scriptSig); if (komodo_txnotarizedconfirmed(opentxid) == 0) return eval->Invalid("channelOpen is not yet confirmed(notarised)!"); else if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) From 901c7952044aaf1a45f0d75f031bf9853024341d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Jan 2019 23:22:46 -1100 Subject: [PATCH 472/643] Test --- src/cc/marmara.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index f095c5da3..5260df2ae 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -398,15 +398,18 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk; int64_t inputsum,change = 0; std::string rawtx,errorstr; - // scan all unlocked - // total capped at amount, change -> unlocked, if no change then scan all locked 'C' and 'P' for unlockht < refunlockht + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk; int32_t unlockht; int64_t inputsum,change = 0; std::string rawtx,errorstr; if ( txfee == 0 ) txfee = 10000; cp = CCinit(&C,EVAL_MARMARA); mypk = pubkey2pk(Mypubkey()); Marmarapk = GetUnspendable(cp,0); - if ( (inputsum= AddNormalinputs(mtx,mypk,amount + txfee,1)) > 0 ) + inputsum = AddNormalinputs(mtx,mypk,amount + txfee,1); + if ( inputsum < amount+txfee ) + { + unlockht = MarmaraUnlockht(height); + } + if ( inputsum > 0 ) { mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum > amount+txfee ) From 5a4fd8b15eb6e69edc56884cf06622b7a50873d3 Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Fri, 18 Jan 2019 17:56:59 +0700 Subject: [PATCH 473/643] fixed token tests --- qa/rpc-tests/cryptoconditions_token.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions_token.py b/qa/rpc-tests/cryptoconditions_token.py index 630d8f6e3..254868670 100755 --- a/qa/rpc-tests/cryptoconditions_token.py +++ b/qa/rpc-tests/cryptoconditions_token.py @@ -18,18 +18,29 @@ class CryptoconditionsTokenTest(CryptoconditionsTestFramework): rpc = self.nodes[0] result = rpc.tokenaddress() assert_success(result) - for x in ['AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress']: + for x in ['TokensCCaddress', 'myCCaddress', 'Tokensmarker', 'myaddress']: assert_equal(result[x][0], 'R') result = rpc.tokenaddress(self.pubkey) assert_success(result) + for x in ['TokensCCaddress', 'myCCaddress', 'Tokensmarker', 'myaddress', 'CCaddress']: + assert_equal(result[x][0], 'R') + + result = rpc.assetsaddress() + assert_success(result) + for x in ['AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress']: + assert_equal(result[x][0], 'R') + + result = rpc.assetsaddress(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 + # trying to create token with negative supply result = rpc.tokencreate("NUKE", "-1987420", "no bueno supply") assert_error(result) @@ -50,12 +61,9 @@ class CryptoconditionsTokenTest(CryptoconditionsTestFramework): result = rpc.tokenorders() assert_equal(result, []) - # getting token balance for pubkey + # getting token balance for non existing tokenid result = rpc.tokenbalance(self.pubkey) - assert_success(result) - assert_equal(result['balance'], 0) - assert_equal(result['CCaddress'], 'RCRsm3VBXz8kKTsYaXKpy7pSEzrtNNQGJC') - assert_equal(result['tokenid'], self.pubkey) + assert_error(result) # get token balance for token with pubkey result = rpc.tokenbalance(tokenid, self.pubkey) From 619958c2a40844cda9807f6c41a0528ba4bef6cc Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 00:59:14 -1100 Subject: [PATCH 474/643] Merge earlier to expire locked funds --- src/cc/marmara.cpp | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 5260df2ae..ec41cc3e8 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -398,20 +398,51 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk; int32_t unlockht; int64_t inputsum,change = 0; std::string rawtx,errorstr; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk,pk; int32_t unlockht,refunlockht,ht,numvouts; int64_t nValue,inputsum,threshold,remains,change = 0; std::string rawtx,errorstr; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; uint8_t funcid; if ( txfee == 0 ) txfee = 10000; cp = CCinit(&C,EVAL_MARMARA); mypk = pubkey2pk(Mypubkey()); Marmarapk = GetUnspendable(cp,0); inputsum = AddNormalinputs(mtx,mypk,amount + txfee,1); + mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum < amount+txfee ) { - unlockht = MarmaraUnlockht(height); + remains = (amount + txfee) - inputsum; + std::vector > unspentOutputs; + GetCCaddress1of2(cp,coinaddr,Marmarapk,mypk); + SetCCunspents(unspentOutputs,coinaddr); + threshold = remains / 16; + refunlockht = MarmaraUnlockht(height); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + txid = it->first.txhash; + vout = (int32_t)it->first.index; + if ( (nValue= it->second.satoshis) < threshold ) + continue; + if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 && vout < numvouts && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + { + if ( (funcid= DecodeMaramaraCoinbaseOpRet(tx.vout[numvouts-1].scriptPubKey,pk,ht,unlockht)) == 'C' || funcid == 'P' || funcid == 'L' ) + { + if ( unlockht < refunlockht ) + { + mtx.vin.push_back(CTxIn(txid,vout,CScript())); + fprintf(stderr,"merge CC vout %s/v%d %.8f unlockht.%d < ref.%d\n",txid.GetHex().c_str(),vout,(double)nValue/COIN,unlockht,refunlockht); + inputsum += nValue; + remains -= nValue; + if ( inputsum >= amount + txfee ) + { + fprintf(stderr,"inputsum %.8f >= amount %.8f, update amount\n",(double)inputsum/COIN,(double)amount/COIN); + amount = inputsum; + break; + } + } + } + } + } } - if ( inputsum > 0 ) + if ( inputsum >= amount+txfee ) { - mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum > amount+txfee ) { change = (inputsum - amount); @@ -426,13 +457,13 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) result.push_back(Pair("rawtx",rawtx)); return(result); } - } + } else errorstr = (char *)"insufficient funds"; result.push_back(Pair("result",(char *)"error")); result.push_back(Pair("error",errorstr)); return(result); } -// decide on what unlockht settlement change should have +// jl777: decide on what unlockht settlement change should have UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) { From 9419e1034f922cd92af4940e82f13a83a5fb25f4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 01:02:06 -1100 Subject: [PATCH 475/643] top16 --- src/cc/marmara.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index ec41cc3e8..b943c1519 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -398,7 +398,7 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk,pk; int32_t unlockht,refunlockht,ht,numvouts; int64_t nValue,inputsum,threshold,remains,change = 0; std::string rawtx,errorstr; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; uint8_t funcid; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk,pk; int32_t unlockht,refunlockht,vout,ht,numvouts; int64_t nValue,inputsum,threshold,remains,change = 0; std::string rawtx,errorstr; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; uint8_t funcid; if ( txfee == 0 ) txfee = 10000; cp = CCinit(&C,EVAL_MARMARA); @@ -976,6 +976,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,std::string currency) { + CMutableTransaction mtx; std::vector pubkeys; UniValue result(UniValue::VOBJ),a(UniValue::VARR),b(UniValue::VARR); int32_t i,n,matches; int64_t totalclosed=0,totalamount=0; std::vector issuances,closed; char coinaddr[64]; CPubKey Marmarapk; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_MARMARA); @@ -988,6 +989,7 @@ UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_ GetCCaddress1of2(cp,coinaddr,Marmarapk,Mypubkey()); result.push_back(Pair("myCCactivated",coinaddr)); result.push_back(Pair("activated",ValueFromAmount(CCaddress_balance(coinaddr)))); + result.push_back(Pair("activated16",ValueFromAmount(AddMarmarainputs(mtx,pubkeys,coinaddr,1LL << 60,16)))); GetCCaddress(cp,coinaddr,Mypubkey()); result.push_back(Pair("myCCaddress",coinaddr)); From 64726e1e217c56bfd208458a3fbfdcbce247089a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 01:04:09 -1100 Subject: [PATCH 476/643] activated16 --- src/cc/marmara.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index b943c1519..af1d0e496 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -977,7 +977,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,std::string currency) { CMutableTransaction mtx; std::vector pubkeys; - UniValue result(UniValue::VOBJ),a(UniValue::VARR),b(UniValue::VARR); int32_t i,n,matches; int64_t totalclosed=0,totalamount=0; std::vector issuances,closed; char coinaddr[64]; + UniValue result(UniValue::VOBJ),a(UniValue::VARR),b(UniValue::VARR); int32_t i,n,matches; int64_t totalclosed=0,totalamount=0,val; std::vector issuances,closed; char coinaddr[64]; CPubKey Marmarapk; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_MARMARA); Marmarapk = GetUnspendable(cp,0); @@ -988,8 +988,9 @@ UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_ GetCCaddress1of2(cp,coinaddr,Marmarapk,Mypubkey()); result.push_back(Pair("myCCactivated",coinaddr)); - result.push_back(Pair("activated",ValueFromAmount(CCaddress_balance(coinaddr)))); - result.push_back(Pair("activated16",ValueFromAmount(AddMarmarainputs(mtx,pubkeys,coinaddr,1LL << 60,16)))); + val = CCaddress_balance(coinaddr); + result.push_back(Pair("activated",ValueFromAmount(val))); + result.push_back(Pair("activated16",ValueFromAmount(AddMarmarainputs(mtx,pubkeys,coinaddr,val,16)))); GetCCaddress(cp,coinaddr,Mypubkey()); result.push_back(Pair("myCCaddress",coinaddr)); From bb41418f23425e0478016bcffd110f625272dfba Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 01:06:25 -1100 Subject: [PATCH 477/643] Get total --- src/cc/marmara.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index af1d0e496..88f47be0b 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -977,7 +977,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,std::string currency) { CMutableTransaction mtx; std::vector pubkeys; - UniValue result(UniValue::VOBJ),a(UniValue::VARR),b(UniValue::VARR); int32_t i,n,matches; int64_t totalclosed=0,totalamount=0,val; std::vector issuances,closed; char coinaddr[64]; + UniValue result(UniValue::VOBJ),a(UniValue::VARR),b(UniValue::VARR); int32_t i,n,matches; int64_t totalclosed=0,totalamount=0; std::vector issuances,closed; char coinaddr[64]; CPubKey Marmarapk; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_MARMARA); Marmarapk = GetUnspendable(cp,0); @@ -988,9 +988,8 @@ UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_ GetCCaddress1of2(cp,coinaddr,Marmarapk,Mypubkey()); result.push_back(Pair("myCCactivated",coinaddr)); - val = CCaddress_balance(coinaddr); - result.push_back(Pair("activated",ValueFromAmount(val))); - result.push_back(Pair("activated16",ValueFromAmount(AddMarmarainputs(mtx,pubkeys,coinaddr,val,16)))); + result.push_back(Pair("activated",ValueFromAmount(CCaddress_balance(coinaddr)))); + result.push_back(Pair("activated16",ValueFromAmount(AddMarmarainputs(mtx,pubkeys,coinaddr,0,16)))); GetCCaddress(cp,coinaddr,Mypubkey()); result.push_back(Pair("myCCaddress",coinaddr)); From 951c9af6ffd6b99e4dd4aeb4fbe6e4b21d5b5d17 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 01:11:44 -1100 Subject: [PATCH 478/643] Test --- src/cc/marmara.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 88f47be0b..5c8bca482 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -373,6 +373,7 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, { txid = it->first.txhash; vout = (int32_t)it->first.index; + char str[64]; fprintf(stderr,"(%s) %s/v%d %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); if ( it->second.satoshis < threshold ) continue; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 && vout < numvouts && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) From 81df6aeabdca4f7cbcfbe77cbe054524ab38399e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 01:16:41 -1100 Subject: [PATCH 479/643] Sort utxo gals --- src/cc/marmara.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 5c8bca482..17d1aa6c8 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -365,7 +365,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys,char *coinaddr,int64_t total,int32_t maxinputs) { - uint64_t threshold,nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction tx; int32_t numvouts,ht,unlockht,vout,n = 0; uint8_t funcid; CPubKey pk; + uint64_t threshold,nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction tx; int32_t numvouts,ht,unlockht,vout,i,n = 0; uint8_t funcid; CPubKey pk; std::vector vals; std::vector > unspentOutputs; SetCCunspents(unspentOutputs,coinaddr); threshold = total/(maxinputs+1); @@ -373,7 +373,6 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, { txid = it->first.txhash; vout = (int32_t)it->first.index; - char str[64]; fprintf(stderr,"(%s) %s/v%d %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); if ( it->second.satoshis < threshold ) continue; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 && vout < numvouts && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) @@ -387,12 +386,20 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, pubkeys.push_back(pk); } totalinputs += it->second.satoshis; + vals.push_back(it->second.satoshis); n++; if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) break; } else fprintf(stderr,"null funcid\n"); } } + if ( maxinputs != 0 && total == 0 ) + { + std::sort(vals.begin(), vals.end()); + totalinputs = 0; + for (i=0; i Date: Fri, 18 Jan 2019 01:19:19 -1100 Subject: [PATCH 480/643] Continue in special case --- src/cc/marmara.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 17d1aa6c8..bf18c82aa 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -379,7 +379,7 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, { if ( (funcid= DecodeMaramaraCoinbaseOpRet(tx.vout[numvouts-1].scriptPubKey,pk,ht,unlockht)) == 'C' || funcid == 'P' || funcid == 'L' ) { - char str[64]; fprintf(stderr,"(%s) %s/v%d %.8f ht.%d unlockht.%d\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN,ht,unlockht); + //char str[64]; fprintf(stderr,"(%s) %s/v%d %.8f ht.%d unlockht.%d\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN,ht,unlockht); if ( total != 0 && maxinputs != 0 ) { mtx.vin.push_back(CTxIn(txid,vout,CScript())); @@ -388,6 +388,8 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, totalinputs += it->second.satoshis; vals.push_back(it->second.satoshis); n++; + if ( maxinputs != 0 && total == 0 ) + continue; if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) break; } else fprintf(stderr,"null funcid\n"); @@ -395,7 +397,7 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, } if ( maxinputs != 0 && total == 0 ) { - std::sort(vals.begin(), vals.end()); + std::sort(vals.begin(),vals.end()); totalinputs = 0; for (i=0; i Date: Fri, 18 Jan 2019 01:30:17 -1100 Subject: [PATCH 481/643] Test --- src/cc/marmara.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index bf18c82aa..d4e6fedd9 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -411,6 +411,8 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk,pk; int32_t unlockht,refunlockht,vout,ht,numvouts; int64_t nValue,inputsum,threshold,remains,change = 0; std::string rawtx,errorstr; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; uint8_t funcid; if ( txfee == 0 ) txfee = 10000; + if ( (height & 1) != 0 ) + height++; cp = CCinit(&C,EVAL_MARMARA); mypk = pubkey2pk(Mypubkey()); Marmarapk = GetUnspendable(cp,0); @@ -418,12 +420,14 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum < amount+txfee ) { + refunlockht = MarmaraUnlockht(height); + result.push_back(Pair("height",height)); + result.push_back(Pair("unlockht",refunlockht)); remains = (amount + txfee) - inputsum; std::vector > unspentOutputs; GetCCaddress1of2(cp,coinaddr,Marmarapk,mypk); SetCCunspents(unspentOutputs,coinaddr); - threshold = remains / 16; - refunlockht = MarmaraUnlockht(height); + threshold = remains / (MARMARA_VINS+1); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; @@ -443,7 +447,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) if ( inputsum >= amount + txfee ) { fprintf(stderr,"inputsum %.8f >= amount %.8f, update amount\n",(double)inputsum/COIN,(double)amount/COIN); - amount = inputsum; + amount = inputsum - txfee; break; } } From 22441d1ed66338a23085a8f4970700ca998b4485 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 01:31:10 -1100 Subject: [PATCH 482/643] Test --- src/cc/marmara.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index d4e6fedd9..8ac73189c 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -421,6 +421,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) if ( inputsum < amount+txfee ) { refunlockht = MarmaraUnlockht(height); + result.push_back(Pair("normalfunds",ValueFromAmount(inputsum))); result.push_back(Pair("height",height)); result.push_back(Pair("unlockht",refunlockht)); remains = (amount + txfee) - inputsum; From 810ae9fd08511d6e4e4b532b3b59ce2952707170 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 01:36:36 -1100 Subject: [PATCH 483/643] Add normal inputs --- src/cc/marmara.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 8ac73189c..298241039 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -408,7 +408,7 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk,pk; int32_t unlockht,refunlockht,vout,ht,numvouts; int64_t nValue,inputsum,threshold,remains,change = 0; std::string rawtx,errorstr; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; uint8_t funcid; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk,pk; int32_t unlockht,refunlockht,vout,ht,numvouts; int64_t nValue,val,inputsum,threshold,remains,change = 0; std::string rawtx,errorstr; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; uint8_t funcid; if ( txfee == 0 ) txfee = 10000; if ( (height & 1) != 0 ) @@ -416,7 +416,8 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) cp = CCinit(&C,EVAL_MARMARA); mypk = pubkey2pk(Mypubkey()); Marmarapk = GetUnspendable(cp,0); - inputsum = AddNormalinputs(mtx,mypk,amount + txfee,1); + val = AddNormalinputs(mtx,mypk,0,0); + inputsum = AddNormalinputs(mtx,mypk,val,MARMARA_VINS); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum < amount+txfee ) { From b5bfaaed0fb91e9de39e381a52d688987fdcee6d Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 01:39:59 -1100 Subject: [PATCH 484/643] Test --- src/cc/marmara.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 298241039..d139f2090 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -407,7 +407,7 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) { - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk,pk; int32_t unlockht,refunlockht,vout,ht,numvouts; int64_t nValue,val,inputsum,threshold,remains,change = 0; std::string rawtx,errorstr; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; uint8_t funcid; if ( txfee == 0 ) txfee = 10000; @@ -416,8 +416,9 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) cp = CCinit(&C,EVAL_MARMARA); mypk = pubkey2pk(Mypubkey()); Marmarapk = GetUnspendable(cp,0); - val = AddNormalinputs(mtx,mypk,0,0); - inputsum = AddNormalinputs(mtx,mypk,val,MARMARA_VINS); + val = AddNormalinputs(tmpmtx,mypk,0,0); + fprintf(stderr,"normal inputs %.8f numvins.%d\n",(double)val/COIN,(int32_t)tmpmtx.vin.size()); + inputsum = AddNormalinputs(mtx,mypk,val,tmpmtx.vin.size() < MARMARA_VINS ? tmpmtx.vin.size() : MARMARA_VINS); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum < amount+txfee ) { From d3a0c0e897ed35d288810dcfb5e36caed2ac452a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 01:43:10 -1100 Subject: [PATCH 485/643] Normalinputs2 --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index d139f2090..e99221a04 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -416,9 +416,9 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) cp = CCinit(&C,EVAL_MARMARA); mypk = pubkey2pk(Mypubkey()); Marmarapk = GetUnspendable(cp,0); - val = AddNormalinputs(tmpmtx,mypk,0,0); + val = AddNormalinputs2(tmpmtx,mypk,0,0); fprintf(stderr,"normal inputs %.8f numvins.%d\n",(double)val/COIN,(int32_t)tmpmtx.vin.size()); - inputsum = AddNormalinputs(mtx,mypk,val,tmpmtx.vin.size() < MARMARA_VINS ? tmpmtx.vin.size() : MARMARA_VINS); + inputsum = AddNormalinputs2(mtx,mypk,val,tmpmtx.vin.size() < MARMARA_VINS ? tmpmtx.vin.size() : MARMARA_VINS); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum < amount+txfee ) { From 5be35df3dfb452352ac6bb1b40ba1db33cbf6758 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 01:44:16 -1100 Subject: [PATCH 486/643] Test --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index e99221a04..2d99ae31f 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -416,9 +416,9 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) cp = CCinit(&C,EVAL_MARMARA); mypk = pubkey2pk(Mypubkey()); Marmarapk = GetUnspendable(cp,0); - val = AddNormalinputs2(tmpmtx,mypk,0,0); + val = AddNormalinputs2(tmpmtx,0,0); fprintf(stderr,"normal inputs %.8f numvins.%d\n",(double)val/COIN,(int32_t)tmpmtx.vin.size()); - inputsum = AddNormalinputs2(mtx,mypk,val,tmpmtx.vin.size() < MARMARA_VINS ? tmpmtx.vin.size() : MARMARA_VINS); + inputsum = AddNormalinputs2(mtx,val,tmpmtx.vin.size() < MARMARA_VINS ? tmpmtx.vin.size() : MARMARA_VINS); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum < amount+txfee ) { From baefcb30c165eb76cfb7021e93cf6e6e5ec82740 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 01:51:13 -1100 Subject: [PATCH 487/643] mypk --- src/cc/marmara.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 2d99ae31f..6085981e1 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -416,7 +416,8 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) cp = CCinit(&C,EVAL_MARMARA); mypk = pubkey2pk(Mypubkey()); Marmarapk = GetUnspendable(cp,0); - val = AddNormalinputs2(tmpmtx,0,0); + Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); + val = AddNormalinputs2(tmpmtx,CCaddressbalance(coinaddr),MARMARA_VINS); fprintf(stderr,"normal inputs %.8f numvins.%d\n",(double)val/COIN,(int32_t)tmpmtx.vin.size()); inputsum = AddNormalinputs2(mtx,val,tmpmtx.vin.size() < MARMARA_VINS ? tmpmtx.vin.size() : MARMARA_VINS); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); From dce284a1d18da00a07c4455a30309b91b75d2d9c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 01:52:05 -1100 Subject: [PATCH 488/643] _ --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 6085981e1..3109b5ee0 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -417,7 +417,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) mypk = pubkey2pk(Mypubkey()); Marmarapk = GetUnspendable(cp,0); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); - val = AddNormalinputs2(tmpmtx,CCaddressbalance(coinaddr),MARMARA_VINS); + val = AddNormalinputs2(tmpmtx,CCaddress_balance(coinaddr),MARMARA_VINS); fprintf(stderr,"normal inputs %.8f numvins.%d\n",(double)val/COIN,(int32_t)tmpmtx.vin.size()); inputsum = AddNormalinputs2(mtx,val,tmpmtx.vin.size() < MARMARA_VINS ? tmpmtx.vin.size() : MARMARA_VINS); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); From 5f1790817271d975a7e2ac86c0a88498b5d7e6dd Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 01:55:30 -1100 Subject: [PATCH 489/643] Revert --- src/cc/marmara.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 3109b5ee0..75fa385b4 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -417,9 +417,8 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) mypk = pubkey2pk(Mypubkey()); Marmarapk = GetUnspendable(cp,0); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); - val = AddNormalinputs2(tmpmtx,CCaddress_balance(coinaddr),MARMARA_VINS); - fprintf(stderr,"normal inputs %.8f numvins.%d\n",(double)val/COIN,(int32_t)tmpmtx.vin.size()); - inputsum = AddNormalinputs2(mtx,val,tmpmtx.vin.size() < MARMARA_VINS ? tmpmtx.vin.size() : MARMARA_VINS); + inputsum = AddNormalinputs2(mtx,amount,MARMARA_VINS); + fprintf(stderr,"normal inputs %.8f\n",(double)inputsum/COIN); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum < amount+txfee ) { From 04b11f66d4ed94af7cee7b16a465ebd971cffca4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 02:07:01 -1100 Subject: [PATCH 490/643] Test --- src/cc/marmara.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 75fa385b4..0a2a5e13b 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -408,7 +408,7 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) { CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk,pk; int32_t unlockht,refunlockht,vout,ht,numvouts; int64_t nValue,val,inputsum,threshold,remains,change = 0; std::string rawtx,errorstr; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; uint8_t funcid; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk,pk; int32_t unlockht,refunlockht,vout,ht,numvouts; int64_t nValue,val,inputsum=0,threshold,remains,change = 0; std::string rawtx,errorstr; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; uint8_t funcid; if ( txfee == 0 ) txfee = 10000; if ( (height & 1) != 0 ) @@ -417,8 +417,11 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) mypk = pubkey2pk(Mypubkey()); Marmarapk = GetUnspendable(cp,0); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); - inputsum = AddNormalinputs2(mtx,amount,MARMARA_VINS); - fprintf(stderr,"normal inputs %.8f\n",(double)inputsum/COIN); + if ( (val= CCaddress_balance(coinaddr)) < amount ) + val -= txfee; + if ( val > txfee ) + inputsum = AddNormalinputs2(mtx,val,MARMARA_VINS); + //fprintf(stderr,"normal inputs %.8f\n",(double)inputsum/COIN); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum < amount+txfee ) { From d099a1b607aad1f6d460f9bc279bc4cb53787138 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 02:08:29 -1100 Subject: [PATCH 491/643] Vals --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 0a2a5e13b..da6b7d9c2 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -421,7 +421,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) val -= txfee; if ( val > txfee ) inputsum = AddNormalinputs2(mtx,val,MARMARA_VINS); - //fprintf(stderr,"normal inputs %.8f\n",(double)inputsum/COIN); + fprintf(stderr,"normal inputs %.8f val %.8f\n",(double)inputsum/COIN,(double)val/COIN); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum < amount+txfee ) { From 0a669e79b2498ae0a0976f4943e5235d5fa715d1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 02:10:47 -1100 Subject: [PATCH 492/643] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index da6b7d9c2..8c848e3f0 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -418,7 +418,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) Marmarapk = GetUnspendable(cp,0); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); if ( (val= CCaddress_balance(coinaddr)) < amount ) - val -= txfee; + val = (amount - txfee) / 2; if ( val > txfee ) inputsum = AddNormalinputs2(mtx,val,MARMARA_VINS); fprintf(stderr,"normal inputs %.8f val %.8f\n",(double)inputsum/COIN,(double)val/COIN); From 220b23b70d09bec953ef09533642cd56bd784b93 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 02:13:19 -1100 Subject: [PATCH 493/643] Fix > case --- src/cc/marmara.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 8c848e3f0..eb313c587 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -419,9 +419,10 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); if ( (val= CCaddress_balance(coinaddr)) < amount ) val = (amount - txfee) / 2; + else val = amount; if ( val > txfee ) inputsum = AddNormalinputs2(mtx,val,MARMARA_VINS); - fprintf(stderr,"normal inputs %.8f val %.8f\n",(double)inputsum/COIN,(double)val/COIN); + //fprintf(stderr,"normal inputs %.8f val %.8f\n",(double)inputsum/COIN,(double)val/COIN); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum < amount+txfee ) { From d9b5673a14bc2e93b3527cf0bc2dcfe89e9df8a8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 02:18:30 -1100 Subject: [PATCH 494/643] CCaddr2 --- src/cc/marmara.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index eb313c587..4a6d799cc 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -435,6 +435,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) GetCCaddress1of2(cp,coinaddr,Marmarapk,mypk); SetCCunspents(unspentOutputs,coinaddr); threshold = remains / (MARMARA_VINS+1); + CCaddr2set(cp,EVAL_MARMARA,gatewayspk,cp->CCpriv,coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; @@ -448,12 +449,12 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) if ( unlockht < refunlockht ) { mtx.vin.push_back(CTxIn(txid,vout,CScript())); - fprintf(stderr,"merge CC vout %s/v%d %.8f unlockht.%d < ref.%d\n",txid.GetHex().c_str(),vout,(double)nValue/COIN,unlockht,refunlockht); + //fprintf(stderr,"merge CC vout %s/v%d %.8f unlockht.%d < ref.%d\n",txid.GetHex().c_str(),vout,(double)nValue/COIN,unlockht,refunlockht); inputsum += nValue; remains -= nValue; if ( inputsum >= amount + txfee ) { - fprintf(stderr,"inputsum %.8f >= amount %.8f, update amount\n",(double)inputsum/COIN,(double)amount/COIN); + //fprintf(stderr,"inputsum %.8f >= amount %.8f, update amount\n",(double)inputsum/COIN,(double)amount/COIN); amount = inputsum - txfee; break; } From 28154f6212398ccaf412c8f7ffd883068261147d Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 02:19:17 -1100 Subject: [PATCH 495/643] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 4a6d799cc..7eb1675d5 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -435,7 +435,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) GetCCaddress1of2(cp,coinaddr,Marmarapk,mypk); SetCCunspents(unspentOutputs,coinaddr); threshold = remains / (MARMARA_VINS+1); - CCaddr2set(cp,EVAL_MARMARA,gatewayspk,cp->CCpriv,coinaddr); + CCaddr2set(cp,EVAL_MARMARA,Marmarapk,cp->CCpriv,coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; From 4227647cc2ebdcbc14af01a0304a830c49655b04 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 02:22:03 -1100 Subject: [PATCH 496/643] CCaddrTokens1of2set --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 7eb1675d5..da0a5b5e3 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -435,7 +435,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) GetCCaddress1of2(cp,coinaddr,Marmarapk,mypk); SetCCunspents(unspentOutputs,coinaddr); threshold = remains / (MARMARA_VINS+1); - CCaddr2set(cp,EVAL_MARMARA,Marmarapk,cp->CCpriv,coinaddr); + CCaddrTokens1of2set(cp,Marmarapk,mypk,coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; From 96cd77ae65bf68ec24aec12d03f8b29a574035f3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 02:24:33 -1100 Subject: [PATCH 497/643] CCaddr1of2set --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index da0a5b5e3..8ac9b3094 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -435,7 +435,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) GetCCaddress1of2(cp,coinaddr,Marmarapk,mypk); SetCCunspents(unspentOutputs,coinaddr); threshold = remains / (MARMARA_VINS+1); - CCaddrTokens1of2set(cp,Marmarapk,mypk,coinaddr); + CCaddr1of2set(cp,Marmarapk,mypk,coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; From 71f6a35db9e3999f12037dc64e334724b5f76dda Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 02:27:08 -1100 Subject: [PATCH 498/643] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 8ac9b3094..208036cab 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -418,7 +418,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) Marmarapk = GetUnspendable(cp,0); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); if ( (val= CCaddress_balance(coinaddr)) < amount ) - val = (amount - txfee) / 2; + val = 9*(amount - txfee) / 10; else val = amount; if ( val > txfee ) inputsum = AddNormalinputs2(mtx,val,MARMARA_VINS); From 1bc00bf8223f11e9a97eff16adca900276a8956f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 02:28:55 -1100 Subject: [PATCH 499/643] 2/3 --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 208036cab..a46b67e29 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -418,7 +418,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) Marmarapk = GetUnspendable(cp,0); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); if ( (val= CCaddress_balance(coinaddr)) < amount ) - val = 9*(amount - txfee) / 10; + val = 2*(amount - txfee) / 3; else val = amount; if ( val > txfee ) inputsum = AddNormalinputs2(mtx,val,MARMARA_VINS); From 681177257d0a8868f2cac4cb2a9c4fc5ebb3a29e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 02:30:26 -1100 Subject: [PATCH 500/643] Test --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index a46b67e29..185e67d66 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -418,10 +418,10 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) Marmarapk = GetUnspendable(cp,0); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); if ( (val= CCaddress_balance(coinaddr)) < amount ) - val = 2*(amount - txfee) / 3; + val = 9*(amount - txfee) / 10; else val = amount; if ( val > txfee ) - inputsum = AddNormalinputs2(mtx,val,MARMARA_VINS); + inputsum = AddNormalinputs2(mtx,val,CC_MAXVINS/2); //fprintf(stderr,"normal inputs %.8f val %.8f\n",(double)inputsum/COIN,(double)val/COIN); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum < amount+txfee ) From 7d4824b53458e3b40394d75965a78ce2d01f1c50 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 02:32:06 -1100 Subject: [PATCH 501/643] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 185e67d66..d9efa583b 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -418,7 +418,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) Marmarapk = GetUnspendable(cp,0); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); if ( (val= CCaddress_balance(coinaddr)) < amount ) - val = 9*(amount - txfee) / 10; + val = 3*(amount - txfee) / 4; else val = amount; if ( val > txfee ) inputsum = AddNormalinputs2(mtx,val,CC_MAXVINS/2); From 3b0a779f0d44782e29dca0466abffd1b70f380b2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 02:35:10 -1100 Subject: [PATCH 502/643] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index d9efa583b..22962c94e 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -418,7 +418,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) Marmarapk = GetUnspendable(cp,0); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); if ( (val= CCaddress_balance(coinaddr)) < amount ) - val = 3*(amount - txfee) / 4; + val = 2*(amount - txfee) / 3; else val = amount; if ( val > txfee ) inputsum = AddNormalinputs2(mtx,val,CC_MAXVINS/2); From 21bd1c08e861d2dd690c9431f9d8f5c96c4007fb Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 02:36:53 -1100 Subject: [PATCH 503/643] Val -= txfee --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 22962c94e..795b95186 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -418,7 +418,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) Marmarapk = GetUnspendable(cp,0); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); if ( (val= CCaddress_balance(coinaddr)) < amount ) - val = 2*(amount - txfee) / 3; + val -= txfee; else val = amount; if ( val > txfee ) inputsum = AddNormalinputs2(mtx,val,CC_MAXVINS/2); From 2a7ecf6e03a5c788eea625a60ae607a7dcc7513e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 00:06:17 -1100 Subject: [PATCH 504/643] Comments --- src/komodo_bitcoind.h | 1 + src/miner.cpp | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 19a5f8103..d24492317 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2236,6 +2236,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } else { + // add opreturn // signSuccess = CCFinalizetx(...) } if (!signSuccess) diff --git a/src/miner.cpp b/src/miner.cpp index 3a163c637..c71bc2461 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -541,9 +541,6 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 txNew.vout[0].nValue += 5000; pblock->vtx[0] = txNew; - //fprintf(stderr,"ht.%d cmp.%d [%d %d %d %d %d]\n",nHeight,nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0,nHeight > 1,ASSETCHAINS_SYMBOL[0] != 0, (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1), ASSETCHAINS_COMMISSION != 0,(commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0); - // check if coinbase transactions must be time locked at current subsidy and prepend the time lock - // to transaction if so, cast for GTE operator if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) { char checkaddr[64]; From 539b6dd1a9228d8174dc8cb0de29aabfeb437afe Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 00:38:55 -1100 Subject: [PATCH 505/643] -ac_ccenable[] --- src/cc/CCinclude.h | 1 + src/cc/eval.cpp | 5 +++++ src/komodo_globals.h | 1 + src/komodo_utils.h | 19 ++++++++++++++++++- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index d103f408d..d3acbd5e6 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -55,6 +55,7 @@ extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE,KOMODO_DEALERNODE; extern uint32_t ASSETCHAINS_CC; extern char ASSETCHAINS_SYMBOL[]; extern std::string CCerror; +extern ASSETCHAINS_CCDISABLES[256]; #define CC_MAXVINS 1024 diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index 9161f2007..b98982ecd 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -65,6 +65,11 @@ bool Eval::Dispatch(const CC *cond, const CTransaction &txTo, unsigned int nIn) return Invalid("empty-eval"); uint8_t ecode = cond->code[0]; + if ( ASSETCHAINS_CCDISABLES[ecode] != 0 ) + { + fprintf(stderr,"%s evalcode.%d %02x\n",txTo.GetHash().GetHex().c_str(),ecode,ecode); + return Invalid("disabled-code, -ac_ccenables didnt include this ecode"); + } cp = &CCinfos[(int32_t)ecode]; if ( cp->didinit == 0 ) { diff --git a/src/komodo_globals.h b/src/komodo_globals.h index f434674b7..4e1d0ef8d 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -71,6 +71,7 @@ uint64_t ASSETCHAINS_TIMEUNLOCKFROM = 0, ASSETCHAINS_TIMEUNLOCKTO = 0; uint32_t ASSETCHAINS_LASTERA = 1; uint64_t ASSETCHAINS_ENDSUBSIDY[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_HALVING[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_DECAY[ASSETCHAINS_MAX_ERAS]; +uint8_t ASSETCHAINS_CCENABLE[256],ASSETCHAINS_CCDISABLES[256]; #define _ASSETCHAINS_EQUIHASH 0 uint32_t ASSETCHAINS_NUMALGOS = 2; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 017a17eff..163b1c43a 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1654,7 +1654,7 @@ extern int64_t MAX_MONEY; void komodo_args(char *argv0) { extern const char *Notaries_elected1[][2]; - std::string name,addn; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[8192],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,baseid,len,n,extralen = 0; + std::string name,addn; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[8192],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,nonz,baseid,len,n,extralen = 0; IS_KOMODO_NOTARY = GetBoolArg("-notary", false); if ( GetBoolArg("-gen", false) != 0 ) @@ -1779,6 +1779,23 @@ void komodo_args(char *argv0) ASSETCHAINS_BEAMPORT = GetArg("-ac_beam",0); ASSETCHAINS_CODAPORT = GetArg("-ac_coda",0); ASSETCHAINS_MARMARA = GetArg("-ac_marmara",0); + Split(GetArg("-ac_ccenable",""), ASSETCHAINS_CCENABLE, 0); + for (i=nonz=0; i<0x100; i++) + { + if ( ASSETCHAINS_CCENABLE[i] != 0 ) + { + nonz++; + fprintf(stderr,"%d ",ASSETCHAINS_CCENABLE[i]); + } + } + fprintf(stderr,"nonz.%d CCENABLES[]\n"); + if ( nonz > 0 ) + { + for (i=0; i<256; i++) + ASSETCHAINS_CCDISABLES[i] = 1; + for (i=0; i<256; i++) + ASSETCHAINS_CCDISABLES[ASSETCHAINS_CCENABLE[i]] = 0; + } if ( ASSETCHAINS_BEAMPORT != 0 && ASSETCHAINS_CODAPORT != 0 ) { fprintf(stderr,"can only have one of -ac_beam or -ac_coda\n"); From 6e40c81b942c63ad43684ee6765accb92e5a41de Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 00:39:53 -1100 Subject: [PATCH 506/643] uint8_t --- src/cc/CCinclude.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index d3acbd5e6..7541dc3a4 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -55,7 +55,7 @@ extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE,KOMODO_DEALERNODE; extern uint32_t ASSETCHAINS_CC; extern char ASSETCHAINS_SYMBOL[]; extern std::string CCerror; -extern ASSETCHAINS_CCDISABLES[256]; +extern uint8_t ASSETCHAINS_CCDISABLES[256]; #define CC_MAXVINS 1024 From 6e71c40201d247de410c7a12cb7f4e2ac87aa8c2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 00:48:53 -1100 Subject: [PATCH 507/643] Ccenables --- src/komodo_globals.h | 2 +- src/komodo_utils.h | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 4e1d0ef8d..ba5e84135 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -71,7 +71,7 @@ uint64_t ASSETCHAINS_TIMEUNLOCKFROM = 0, ASSETCHAINS_TIMEUNLOCKTO = 0; uint32_t ASSETCHAINS_LASTERA = 1; uint64_t ASSETCHAINS_ENDSUBSIDY[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_HALVING[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_DECAY[ASSETCHAINS_MAX_ERAS]; -uint8_t ASSETCHAINS_CCENABLE[256],ASSETCHAINS_CCDISABLES[256]; +uint8_t ASSETCHAINS_CCDISABLES[256]; #define _ASSETCHAINS_EQUIHASH 0 uint32_t ASSETCHAINS_NUMALGOS = 2; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 163b1c43a..e074bd4c0 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1654,9 +1654,10 @@ extern int64_t MAX_MONEY; void komodo_args(char *argv0) { extern const char *Notaries_elected1[][2]; - std::string name,addn; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[8192],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,nonz,baseid,len,n,extralen = 0; + std::string name,addn; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[8192],disablebits[32],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,nonz,baseid,len,n,extralen = 0; uint64_t ccenables[256]; IS_KOMODO_NOTARY = GetBoolArg("-notary", false); - + memset(ccenables,0,sizeof(ccenables)); + memset(disablebits,0,sizeof(disablebits)); if ( GetBoolArg("-gen", false) != 0 ) { KOMODO_MININGTHREADS = GetArg("-genproclimit",-1); @@ -1779,22 +1780,25 @@ void komodo_args(char *argv0) ASSETCHAINS_BEAMPORT = GetArg("-ac_beam",0); ASSETCHAINS_CODAPORT = GetArg("-ac_coda",0); ASSETCHAINS_MARMARA = GetArg("-ac_marmara",0); - Split(GetArg("-ac_ccenable",""), ASSETCHAINS_CCENABLE, 0); + Split(GetArg("-ac_ccenable",""), ccenables, 0); for (i=nonz=0; i<0x100; i++) { - if ( ASSETCHAINS_CCENABLE[i] != 0 ) + if ( ccenables[i] != 0 ) { nonz++; - fprintf(stderr,"%d ",ASSETCHAINS_CCENABLE[i]); + fprintf(stderr,"%d ",ccenables[i]); } } - fprintf(stderr,"nonz.%d CCENABLES[]\n"); + fprintf(stderr,"nonz.%d ccenables[]\n",nonz); if ( nonz > 0 ) { for (i=0; i<256; i++) ASSETCHAINS_CCDISABLES[i] = 1; for (i=0; i<256; i++) - ASSETCHAINS_CCDISABLES[ASSETCHAINS_CCENABLE[i]] = 0; + { + SETBIT(disablebits,i); + ASSETCHAINS_CCDISABLES[ccenables[i] & 0xff] = 0; + } } if ( ASSETCHAINS_BEAMPORT != 0 && ASSETCHAINS_CODAPORT != 0 ) { @@ -1880,7 +1884,7 @@ void komodo_args(char *argv0) fprintf(stderr,"-ac_script and -ac_marmara are mutually exclusive\n"); exit(0); } - if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 ) + if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 || nonz > 0 ) { fprintf(stderr,"perc %.4f%% ac_pub=[%02x%02x%02x...] acsize.%d\n",dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0],ASSETCHAINS_OVERRIDE_PUBKEY33[1],ASSETCHAINS_OVERRIDE_PUBKEY33[2],(int32_t)ASSETCHAINS_SCRIPTPUB.size()); extraptr = extrabuf; @@ -1956,6 +1960,11 @@ void komodo_args(char *argv0) extraptr[extralen++] = 'c'; if ( ASSETCHAINS_MARMARA != 0 ) extraptr[extralen++] = ASSETCHAINS_MARMARA; + if ( nonz > 0 ) + { + memcpy(&extraptr[extralen],disablebits,sizeof(disablebits)); + extralen += sizeof(disablebits); + } } addn = GetArg("-seednode",""); From 70fba21c4681a0d2a23166694ac4fc89f4f2db21 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 00:50:51 -1100 Subject: [PATCH 508/643] SETBIT --- src/komodo_defs.h | 4 ++++ src/komodo_utils.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index bd516be61..91fcadddb 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -30,6 +30,10 @@ #define KOMODO_SAPLING_DEADLINE 1550188800 // Feb 15th, 2019 #define _COINBASE_MATURITY 100 +#define SETBIT(bits,bitoffset) (((uint8_t *)bits)[(bitoffset) >> 3] |= (1 << ((bitoffset) & 7))) +#define GETBIT(bits,bitoffset) (((uint8_t *)bits)[(bitoffset) >> 3] & (1 << ((bitoffset) & 7))) +#define CLEARBIT(bits,bitoffset) (((uint8_t *)bits)[(bitoffset) >> 3] &= ~(1 << ((bitoffset) & 7))) + extern uint8_t ASSETCHAINS_TXPOW,ASSETCHAINS_PUBLIC; int32_t MAX_BLOCK_SIZE(int32_t height); diff --git a/src/komodo_utils.h b/src/komodo_utils.h index e074bd4c0..cb2ea7a1e 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1786,7 +1786,7 @@ void komodo_args(char *argv0) if ( ccenables[i] != 0 ) { nonz++; - fprintf(stderr,"%d ",ccenables[i]); + fprintf(stderr,"%d ",(uint8_t)(ccenables[i] & 0xff)); } } fprintf(stderr,"nonz.%d ccenables[]\n",nonz); From ac9bd541b4c32e8971d1a740813bda0ad08409d5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 00:57:55 -1100 Subject: [PATCH 509/643] Require cc for ccenable --- src/komodo_utils.h | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index cb2ea7a1e..1352c5bf7 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1780,24 +1780,27 @@ void komodo_args(char *argv0) ASSETCHAINS_BEAMPORT = GetArg("-ac_beam",0); ASSETCHAINS_CODAPORT = GetArg("-ac_coda",0); ASSETCHAINS_MARMARA = GetArg("-ac_marmara",0); - Split(GetArg("-ac_ccenable",""), ccenables, 0); - for (i=nonz=0; i<0x100; i++) + if ( ASSETCHAINS_CC != 0 ) { - if ( ccenables[i] != 0 ) + Split(GetArg("-ac_ccenable",""), ccenables, 0); + for (i=nonz=0; i<0x100; i++) { - nonz++; - fprintf(stderr,"%d ",(uint8_t)(ccenables[i] & 0xff)); + if ( ccenables[i] != 0 ) + { + nonz++; + fprintf(stderr,"%d ",(uint8_t)(ccenables[i] & 0xff)); + } } - } - fprintf(stderr,"nonz.%d ccenables[]\n",nonz); - if ( nonz > 0 ) - { - for (i=0; i<256; i++) - ASSETCHAINS_CCDISABLES[i] = 1; - for (i=0; i<256; i++) + fprintf(stderr,"nonz.%d ccenables[]\n",nonz); + if ( nonz > 0 ) { - SETBIT(disablebits,i); - ASSETCHAINS_CCDISABLES[ccenables[i] & 0xff] = 0; + for (i=0; i<256; i++) + ASSETCHAINS_CCDISABLES[i] = 1; + for (i=0; i<256; i++) + { + SETBIT(disablebits,i); + ASSETCHAINS_CCDISABLES[ccenables[i] & 0xff] = 0; + } } } if ( ASSETCHAINS_BEAMPORT != 0 && ASSETCHAINS_CODAPORT != 0 ) From 3ab60f65c75e8d3ef3681920e8a21b3ba20cf54f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 01:00:51 -1100 Subject: [PATCH 510/643] Fix disable bits --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 1352c5bf7..ea1741d5a 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1798,7 +1798,7 @@ void komodo_args(char *argv0) ASSETCHAINS_CCDISABLES[i] = 1; for (i=0; i<256; i++) { - SETBIT(disablebits,i); + SETBIT(disablebits,(ccenables[i] & 0xff)); ASSETCHAINS_CCDISABLES[ccenables[i] & 0xff] = 0; } } From 37019a6438e46c6f247a2ff0990725381a93d1eb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 01:02:53 -1100 Subject: [PATCH 511/643] Fix bits --- src/komodo_utils.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index ea1741d5a..eb6134ffe 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1795,10 +1795,13 @@ void komodo_args(char *argv0) if ( nonz > 0 ) { for (i=0; i<256; i++) + { ASSETCHAINS_CCDISABLES[i] = 1; + SETBIT(disablebits,i); + } for (i=0; i<256; i++) { - SETBIT(disablebits,(ccenables[i] & 0xff)); + CLEARBIT(disablebits,(ccenables[i] & 0xff)); ASSETCHAINS_CCDISABLES[ccenables[i] & 0xff] = 0; } } From c5dcd3f8282288b2af851712b7d047f32b2761b1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 01:20:27 -1100 Subject: [PATCH 512/643] cclib.so --- src/Makefile.am | 3 ++- src/cc/eval.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index 5e665cc3c..96ab3f1fa 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -571,7 +571,8 @@ komodod_LDADD += \ $(LIBBITCOIN_CRYPTO) \ $(LIBVERUS_CRYPTO) \ $(LIBVERUS_PORTABLE_CRYPTO) \ - $(LIBZCASH_LIBS) + $(LIBZCASH_LIBS) \ + cclib.so if ENABLE_PROTON komodod_LDADD += $(LIBBITCOIN_PROTON) $(PROTON_LIBS) diff --git a/src/cc/eval.h b/src/cc/eval.h index de1636ab8..be86629a0 100644 --- a/src/cc/eval.h +++ b/src/cc/eval.h @@ -59,6 +59,8 @@ EVAL(EVAL_TOKENS, 0xf2) +// evalcodes 0x10 to 0x7f are reserved for cclib dynamic CC + typedef uint8_t EvalCode; From 614c8a61d5c280dc6e76bef72cb6f475f7f46101 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 01:21:43 -1100 Subject: [PATCH 513/643] Win dll spot --- src/Makefile.am | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Makefile.am b/src/Makefile.am index 96ab3f1fa..327d32e3f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -572,7 +572,12 @@ komodod_LDADD += \ $(LIBVERUS_CRYPTO) \ $(LIBVERUS_PORTABLE_CRYPTO) \ $(LIBZCASH_LIBS) \ +if TARGET_WINDOWS + +# add .dll somehow +else cclib.so +endif if ENABLE_PROTON komodod_LDADD += $(LIBBITCOIN_PROTON) $(PROTON_LIBS) From f93a96af0741da186fb9bf7933289a16f0abdc8a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 01:22:54 -1100 Subject: [PATCH 514/643] -if --- src/Makefile.am | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 327d32e3f..b1e67cf2e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -572,12 +572,8 @@ komodod_LDADD += \ $(LIBVERUS_CRYPTO) \ $(LIBVERUS_PORTABLE_CRYPTO) \ $(LIBZCASH_LIBS) \ -if TARGET_WINDOWS - -# add .dll somehow -else cclib.so -endif + if ENABLE_PROTON komodod_LDADD += $(LIBBITCOIN_PROTON) $(PROTON_LIBS) From b22c190e3c8b87f6551b62b5a1eb97bfaa165ca6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 01:33:06 -1100 Subject: [PATCH 515/643] cclib.cpp --- src/Makefile.am | 3 +++ src/cc/cclib.cpp | 2 ++ src/cc/eval.h | 2 ++ 3 files changed, 7 insertions(+) create mode 100644 src/cc/cclib.cpp diff --git a/src/Makefile.am b/src/Makefile.am index b1e67cf2e..46e03dc83 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -559,6 +559,9 @@ if ENABLE_WALLET komodod_LDADD += $(LIBBITCOIN_WALLET) endif +cclib.so: cclib.cpp + gcc -o cclib.so -c cclib.cpp + komodod_LDADD += \ $(BOOST_LIBS) \ $(BDB_LIBS) \ diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp new file mode 100644 index 000000000..5cd56f9eb --- /dev/null +++ b/src/cc/cclib.cpp @@ -0,0 +1,2 @@ + +char *CClib_name() { return("stub"); } diff --git a/src/cc/eval.h b/src/cc/eval.h index be86629a0..a42bbdb2f 100644 --- a/src/cc/eval.h +++ b/src/cc/eval.h @@ -60,6 +60,8 @@ // evalcodes 0x10 to 0x7f are reserved for cclib dynamic CC +#define EVAL_FIRSTUSER 0x10 +#define EVAL_LASTUSER 0x7f typedef uint8_t EvalCode; From b693dfd93c8659596d4c19091a7535562f0400e8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 01:35:21 -1100 Subject: [PATCH 516/643] Test --- src/Makefile.am | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index 46e03dc83..7de831f3b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -560,7 +560,6 @@ komodod_LDADD += $(LIBBITCOIN_WALLET) endif cclib.so: cclib.cpp - gcc -o cclib.so -c cclib.cpp komodod_LDADD += \ $(BOOST_LIBS) \ From 32d407e84e1729e829aae95d392265a55457c570 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 01:37:20 -1100 Subject: [PATCH 517/643] Char * --- src/Makefile.am | 2 -- src/cc/cclib.cpp | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 7de831f3b..b1e67cf2e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -559,8 +559,6 @@ if ENABLE_WALLET komodod_LDADD += $(LIBBITCOIN_WALLET) endif -cclib.so: cclib.cpp - komodod_LDADD += \ $(BOOST_LIBS) \ $(BDB_LIBS) \ diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 5cd56f9eb..29ea4b787 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -1,2 +1,2 @@ -char *CClib_name() { return("stub"); } +char *CClib_name() { return((char *)"stub"); } From a22cc60e1a7c896d866f867cbc854076973310f5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 01:42:22 -1100 Subject: [PATCH 518/643] Make --- src/Makefile.am | 1 - src/cc/makecclib | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100755 src/cc/makecclib diff --git a/src/Makefile.am b/src/Makefile.am index b1e67cf2e..96ab3f1fa 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -574,7 +574,6 @@ komodod_LDADD += \ $(LIBZCASH_LIBS) \ cclib.so - if ENABLE_PROTON komodod_LDADD += $(LIBBITCOIN_PROTON) $(PROTON_LIBS) endif diff --git a/src/cc/makecclib b/src/cc/makecclib new file mode 100755 index 000000000..e90f0877b --- /dev/null +++ b/src/cc/makecclib @@ -0,0 +1 @@ +gcc -fPIC -shared -c -o ../cclib.so cclib.cpp From c310c7fa47e7048c98cb16b9e93beb93fd9e6975 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 02:05:51 -1100 Subject: [PATCH 519/643] CClib_Dispatch --- src/cc/cclib.cpp | 38 ++++++++++++++++++++++++++++++++++++++ src/cc/eval.cpp | 7 ++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 29ea4b787..f89301b34 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -1,2 +1,40 @@ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#include +#include + +#include "../primitives/block.h" +#include "../primitives/transaction.h" +#include "../script/cc.h" +#include "eval.h" +#include "utils.h" +#include "CCinclude.h" +#include "../main.h" +#include "../chain.h" +#include "../core_io.h" +#include "../crosschain.h" char *CClib_name() { return((char *)"stub"); } + +bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,const CTransaction &txTo,unsigned int nIn) +{ + uint8_t evalcode = cond->code[0]; + if ( evalcode >= EVAL_FIRSTUSER && evalcode <= EVAL_LASTUSER ) + { + + } + return eval->Invalid("cclib CC must have evalcode between 16 and 127"); +} diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index b98982ecd..e30ec263c 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -27,6 +27,7 @@ #include "core_io.h" #include "crosschain.h" +bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,const CTransaction &txTo,unsigned int nIn); Eval* EVAL_TEST = 0; struct CCcontract_info CCinfos[0x100]; @@ -70,13 +71,17 @@ bool Eval::Dispatch(const CC *cond, const CTransaction &txTo, unsigned int nIn) fprintf(stderr,"%s evalcode.%d %02x\n",txTo.GetHash().GetHex().c_str(),ecode,ecode); return Invalid("disabled-code, -ac_ccenables didnt include this ecode"); } + std::vector vparams(cond->code+1, cond->code+cond->codeLength); + if ( ecode >= EVAL_FIRSTUSER && ecode <= EVAL_LASTUSER ) + { + return CClib_Dispatch(cond,this,vparams,txTo,nIn); + } cp = &CCinfos[(int32_t)ecode]; if ( cp->didinit == 0 ) { CCinit(cp,ecode); cp->didinit = 1; } - std::vector vparams(cond->code+1, cond->code+cond->codeLength); switch ( ecode ) { case EVAL_IMPORTPAYOUT: From 5a4c3ce5b3004bf27da6a1bb20d99baf9fd0b7f0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 02:08:22 -1100 Subject: [PATCH 520/643] cryptoconditions.h --- src/cc/eval.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index e30ec263c..7c578c8c3 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -14,8 +14,8 @@ ******************************************************************************/ #include -#include +#include "../cryptoconditions/include/cryptoconditions.h" #include "primitives/block.h" #include "primitives/transaction.h" #include "script/cc.h" From 8420bb5e96288bda4e29f868f9dd67b6ec920d42 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 02:09:06 -1100 Subject: [PATCH 521/643] Fix --- src/cc/cclib.cpp | 4 ++-- src/cc/eval.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index f89301b34..cca7a812a 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -14,8 +14,8 @@ ******************************************************************************/ #include -#include - +//#include +#include "../cryptoconditions/include/cryptoconditions.h" #include "../primitives/block.h" #include "../primitives/transaction.h" #include "../script/cc.h" diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index 7c578c8c3..e30ec263c 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -14,8 +14,8 @@ ******************************************************************************/ #include +#include -#include "../cryptoconditions/include/cryptoconditions.h" #include "primitives/block.h" #include "primitives/transaction.h" #include "script/cc.h" From 05ffb90ab69cc52a65770af14644bccec2596251 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 02:10:35 -1100 Subject: [PATCH 522/643] Test --- src/cc/cclib.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index cca7a812a..d6e7a95fc 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -15,17 +15,17 @@ #include //#include -#include "../cryptoconditions/include/cryptoconditions.h" -#include "../primitives/block.h" -#include "../primitives/transaction.h" -#include "../script/cc.h" -#include "eval.h" -#include "utils.h" -#include "CCinclude.h" -#include "../main.h" -#include "../chain.h" -#include "../core_io.h" -#include "../crosschain.h" +#include "cryptoconditions/include/cryptoconditions.h" +#include "primitives/block.h" +#include "primitives/transaction.h" +#include "script/cc.h" +#include "cc/eval.h" +#include "cc/utils.h" +#include "cc/CCinclude.h" +#include "main.h" +#include "chain.h" +#include "core_io.h" +#include "crosschain.h" char *CClib_name() { return((char *)"stub"); } From afc693198f048820a3ec7af0200c8b1775f77632 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 02:14:25 -1100 Subject: [PATCH 523/643] Test --- src/cc/cclib.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index d6e7a95fc..bd66f5bda 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -15,7 +15,7 @@ #include //#include -#include "cryptoconditions/include/cryptoconditions.h" +#include "../cryptoconditions/include/cryptoconditions.h" #include "primitives/block.h" #include "primitives/transaction.h" #include "script/cc.h" From a761d97300566eff6f68bad80843c1e924a28629 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 02:24:31 -1100 Subject: [PATCH 524/643] Makecclib --- src/cc/cclib.cpp | 4 ++-- src/cc/makecclib | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index bd66f5bda..036971666 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -14,8 +14,8 @@ ******************************************************************************/ #include -//#include -#include "../cryptoconditions/include/cryptoconditions.h" +#include + #include "primitives/block.h" #include "primitives/transaction.h" #include "script/cc.h" diff --git a/src/cc/makecclib b/src/cc/makecclib index e90f0877b..47aec377d 100755 --- a/src/cc/makecclib +++ b/src/cc/makecclib @@ -1 +1 @@ -gcc -fPIC -shared -c -o ../cclib.so cclib.cpp +gcc -std=c++11 -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o ../cclib.so cclib.cpp From 33a2ac6e3bbeddabd72ea4da79facaa999d08eb7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 02:33:23 -1100 Subject: [PATCH 525/643] -ac_cclib --- src/cc/cclib.cpp | 15 ++++++++++++--- src/cc/eval.cpp | 4 +++- src/komodo_globals.h | 2 +- src/komodo_utils.h | 14 ++++++++++++-- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 036971666..24c6380bd 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -27,14 +27,23 @@ #include "core_io.h" #include "crosschain.h" -char *CClib_name() { return((char *)"stub"); } +#define MYCCLIBNAME ((char *)"stub") +extern std::string ASSETCHAINS_CCLIB; + +char *CClib_name() { return(MYCCLIBNAME); } bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,const CTransaction &txTo,unsigned int nIn) { - uint8_t evalcode = cond->code[0]; + uint8_t evalcode; + if ( ASSETCHAINS_CCLIB != MYCCLIBNAME ) + { + fprintf(stderr,"-ac_cclib=%s vs myname %s\n",ASSETCHAINS_CCLIB,MYCCLIBNAME); + return eval->Invalid("-ac_cclib name mismatches myname"); + } + evalcode = cond->code[0]; if ( evalcode >= EVAL_FIRSTUSER && evalcode <= EVAL_LASTUSER ) { - + return(true); } return eval->Invalid("cclib CC must have evalcode between 16 and 127"); } diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index e30ec263c..bd8c69a55 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -74,7 +74,9 @@ bool Eval::Dispatch(const CC *cond, const CTransaction &txTo, unsigned int nIn) std::vector vparams(cond->code+1, cond->code+cond->codeLength); if ( ecode >= EVAL_FIRSTUSER && ecode <= EVAL_LASTUSER ) { - return CClib_Dispatch(cond,this,vparams,txTo,nIn); + if ( ASSETCHAINS_CCLIB.size() > 0 && ASSETCHAINS_CCLIB == CClib_name() ) + return CClib_Dispatch(cond,this,vparams,txTo,nIn); + else return Invalid("mismatched -ac_cclib vs CClib_name"); } cp = &CCinfos[(int32_t)ecode]; if ( cp->didinit == 0 ) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index ba5e84135..79b56cbbb 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -48,7 +48,7 @@ unsigned int WITNESS_CACHE_SIZE = _COINBASE_MATURITY+10; int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1,KOMODO_DEALERNODE,KOMODO_EXTRASATOSHI,ASSETCHAINS_FOUNDERS; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1; -std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB,ASSETCHAINS_SELFIMPORT; +std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB,ASSETCHAINS_SELFIMPORT,ASSETCHAINS_CCLIB; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,ASSETCHAINS_MARMARA; bool VERUS_MINTBLOCKS; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index eb6134ffe..289a84d7c 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1782,6 +1782,7 @@ void komodo_args(char *argv0) ASSETCHAINS_MARMARA = GetArg("-ac_marmara",0); if ( ASSETCHAINS_CC != 0 ) { + ASSETCHAINS_CCLIB = GetArg("-ac_cclib",""); Split(GetArg("-ac_ccenable",""), ccenables, 0); for (i=nonz=0; i<0x100; i++) { @@ -1890,7 +1891,7 @@ void komodo_args(char *argv0) fprintf(stderr,"-ac_script and -ac_marmara are mutually exclusive\n"); exit(0); } - if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 || nonz > 0 ) + if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 || nonz > 0 || ASSETCHAINS_CCLIB.size() > 0 ) { fprintf(stderr,"perc %.4f%% ac_pub=[%02x%02x%02x...] acsize.%d\n",dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0],ASSETCHAINS_OVERRIDE_PUBKEY33[1],ASSETCHAINS_OVERRIDE_PUBKEY33[2],(int32_t)ASSETCHAINS_SCRIPTPUB.size()); extraptr = extrabuf; @@ -1971,8 +1972,17 @@ void komodo_args(char *argv0) memcpy(&extraptr[extralen],disablebits,sizeof(disablebits)); extralen += sizeof(disablebits); } + if ( ASSETCHAINS_CCLIB.size() > 1 ) + { + for (i=0; i 0 ) ASSETCHAINS_SEED = 1; From cc1d11914488a18b78cedd4a22f33b9d313f775a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 02:34:33 -1100 Subject: [PATCH 526/643] Test --- src/cc/CCinclude.h | 2 +- src/cc/cclib.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 7541dc3a4..680e4ca5c 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -54,7 +54,7 @@ one other technical note is that komodod has the insight-explorer extensions bui extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE,KOMODO_DEALERNODE; extern uint32_t ASSETCHAINS_CC; extern char ASSETCHAINS_SYMBOL[]; -extern std::string CCerror; +extern std::string CCerror,ASSETCHAINS_CCLIB; extern uint8_t ASSETCHAINS_CCDISABLES[256]; #define CC_MAXVINS 1024 diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 24c6380bd..9dc74e424 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -28,7 +28,6 @@ #include "crosschain.h" #define MYCCLIBNAME ((char *)"stub") -extern std::string ASSETCHAINS_CCLIB; char *CClib_name() { return(MYCCLIBNAME); } From 385c79357ff8204ead60d0d7b12887b18b85ecd2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 02:35:27 -1100 Subject: [PATCH 527/643] char *CClib_name() --- src/cc/eval.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index bd8c69a55..ca2703bff 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -28,6 +28,7 @@ #include "crosschain.h" bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,const CTransaction &txTo,unsigned int nIn); +char *CClib_name(); Eval* EVAL_TEST = 0; struct CCcontract_info CCinfos[0x100]; From f31416834ae86490fbfe855ee2435d8d9348f936 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 02:40:24 -1100 Subject: [PATCH 528/643] Char * --- src/cc/cclib.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 9dc74e424..10a289459 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -36,7 +36,7 @@ bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,co uint8_t evalcode; if ( ASSETCHAINS_CCLIB != MYCCLIBNAME ) { - fprintf(stderr,"-ac_cclib=%s vs myname %s\n",ASSETCHAINS_CCLIB,MYCCLIBNAME); + fprintf(stderr,"-ac_cclib=%s vs myname %s\n",ASSETCHAINS_CCLIB.c_str(),MYCCLIBNAME); return eval->Invalid("-ac_cclib name mismatches myname"); } evalcode = cond->code[0]; From c7002513e383907de706e1e6459370d6ac448afe Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 03:37:28 -1100 Subject: [PATCH 529/643] Height and from_mempool in club --- src/cc/cclib.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 10a289459..889c40d8c 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -33,12 +33,22 @@ char *CClib_name() { return(MYCCLIBNAME); } bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,const CTransaction &txTo,unsigned int nIn) { - uint8_t evalcode; + uint8_t evalcode; int32_t height,from_mempool; if ( ASSETCHAINS_CCLIB != MYCCLIBNAME ) { fprintf(stderr,"-ac_cclib=%s vs myname %s\n",ASSETCHAINS_CCLIB.c_str(),MYCCLIBNAME); return eval->Invalid("-ac_cclib name mismatches myname"); } + height = KOMODO_CONNECTING; + if ( KOMODO_CONNECTING < 0 ) // always comes back with > 0 for final confirmation + return(true); + if ( ASSETCHAINS_CC == 0 || (height & ~(1<<30)) < KOMODO_CCACTIVATE ) + return eval->Invalid("CC are disabled or not active yet"); + if ( (KOMODO_CONNECTING & (1<<30)) != 0 ) + { + from_mempool = 1; + height &= ((1<<30) - 1); + } evalcode = cond->code[0]; if ( evalcode >= EVAL_FIRSTUSER && evalcode <= EVAL_LASTUSER ) { From 6692b4b0c6a2fe677aced9a40e821a67df6ac2cf Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 04:06:59 -1100 Subject: [PATCH 530/643] Locked staking --- src/komodo_bitcoind.h | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d24492317..4ac20713b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2149,8 +2149,26 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } else { - // calc 1of2 address - // iterate all unspents not spent in mempool and komodo_addutxo + struct CCcontract_info *cp,C; uint256 txid; int32_t vout; CAmount nValue; char coinaddr[64]; CPubKey mypk,Marmarapk; + std::vector > unspentOutputs; + cp = CCinit(&C,EVAL_MARMARA); + mypk = pubkey2pk(Mypubkey()); + Marmarapk = GetUnspendable(cp,0); + GetCCaddress1of2(cp,coinaddr,Marmarapk,pk); + SetCCunspents(unspentOutputs,coinaddr); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + txid = it->first.txhash; + vout = (int32_t)it->first.index; + if ( (nValue= it->second.satoshis) < COIN ) + continue; + if ( GetTransaction(txid,tx,hashBlock,true) != 0 && (pindex= komodo_getblockindex(hashBlock)) != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + { + const CScript &scriptPubKey = tx.vout[vout].scriptPubKey; + array = komodo_addutxo(array,&numkp,&maxkp,(uint32_t)pindex->nTime,(uint64_t)nValue,txid,vout,coinaddr,hashbuf,(CScript)scriptPubKey); + fprintf(stderr,"addutxo %.8f numkp.%d vs max.%d\n",(double)nValue/COIN,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); From 66198b83f0407e5487dd893d361a9279186f8d82 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 04:07:41 -1100 Subject: [PATCH 531/643] Mypk --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 4ac20713b..fbd73f59f 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2154,7 +2154,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt cp = CCinit(&C,EVAL_MARMARA); mypk = pubkey2pk(Mypubkey()); Marmarapk = GetUnspendable(cp,0); - GetCCaddress1of2(cp,coinaddr,Marmarapk,pk); + GetCCaddress1of2(cp,coinaddr,Marmarapk,mypk); SetCCunspents(unspentOutputs,coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { From 240fdaa384fb247b2e352fb211916a51b24fead9 Mon Sep 17 00:00:00 2001 From: ca333 Date: Sun, 20 Jan 2019 03:11:54 +0100 Subject: [PATCH 532/643] add cclib to makefile --- zcutil/build.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/zcutil/build.sh b/zcutil/build.sh index 08517475c..68239e16e 100755 --- a/zcutil/build.sh +++ b/zcutil/build.sh @@ -101,6 +101,21 @@ eval "$MAKE" --version as --version ld -v +#BUILD CCLIB + +WD=$PWD +cd src/cc +echo $PWD + +if make "$@"; then + echo CCLIB BUILD SUCCESSFUL +else + echo CCLIB BUILD FAILED + exit 1 +fi + +cd $WD + HOST="$HOST" BUILD="$BUILD" NO_PROTON="$PROTON_ARG" "$MAKE" "$@" -C ./depends/ V=1 ./autogen.sh From 5fe3792aef1b662640e37d5c076e7793b3ac5445 Mon Sep 17 00:00:00 2001 From: ca333 Date: Sun, 20 Jan 2019 03:13:21 +0100 Subject: [PATCH 533/643] create cclib Makefile --- src/cc/Makefile | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/cc/Makefile diff --git a/src/cc/Makefile b/src/cc/Makefile new file mode 100644 index 000000000..5848d46dd --- /dev/null +++ b/src/cc/Makefile @@ -0,0 +1,19 @@ +SHELL = /bin/sh +CC = gcc +#CXXFLAGS = -std=c++11 -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c +CFLAGS = -std=c++11 -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c +DEBUGFLAGS = -O0 -D _DEBUG +RELEASEFLAGS = -O2 -D NDEBUG -combine -fwhole-program + +TARGET = ../cclib.so +SOURCES = cclib.cpp +#HEADERS = $(shell echo ../cryptoconditions/include/*.h) +all: $(TARGET) + +$(TARGET): $(SOURCES) + $(info Building cclib.so to src/) + $(CC) $(CFLAGS) $(DEBUGFLAGS) -o $(TARGET) $(SOURCES) + +clean: + rm -rf $(TARGET) + From 4357791ede3f46e63fab14dfd3b12a321ebff2c9 Mon Sep 17 00:00:00 2001 From: ca333 Date: Sun, 20 Jan 2019 05:04:14 +0100 Subject: [PATCH 534/643] [update] cclib multiOS Makefile --- src/cc/Makefile | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/cc/Makefile b/src/cc/Makefile index 5848d46dd..24d13690c 100644 --- a/src/cc/Makefile +++ b/src/cc/Makefile @@ -1,19 +1,32 @@ -SHELL = /bin/sh -CC = gcc -#CXXFLAGS = -std=c++11 -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -CFLAGS = -std=c++11 -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -DEBUGFLAGS = -O0 -D _DEBUG -RELEASEFLAGS = -O2 -D NDEBUG -combine -fwhole-program - +SHELL = /bin/sh +CC = gcc +CC_WIN = x86_64-w64-mingw32-gcc-posix +CFLAGS_DARWIN = -std=c++11 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c +CFLAGS = -std=c++11 -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c +CFLAGS_WIN = -std=c++11 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c +DEBUGFLAGS = -O0 -D _DEBUG +RELEASEFLAGS = -O2 -D NDEBUG -combine -fwhole-program +$(info $(OS)) +OS := $(shell uname -s) +$(info $(OS)) TARGET = ../cclib.so +TARGET_WIN = ../cclib.dll SOURCES = cclib.cpp #HEADERS = $(shell echo ../cryptoconditions/include/*.h) + all: $(TARGET) $(TARGET): $(SOURCES) $(info Building cclib.so to src/) +ifeq ($(OS),Darwin) + $(CC) $(CFLAGS_DARWIN) $(DEBUGFLAGS) -o $(TARGET) $(SOURCES) +else ifeq ($(OS),Linux) $(CC) $(CFLAGS) $(DEBUGFLAGS) -o $(TARGET) $(SOURCES) +#else ifeq ($(WIN_HOST),True) - todo: pass ENV var from build.sh if WIN host +else + $(info else) + #$(CC)_WIN $(CFLAGS_WIN) $(DEBUGFLAGS) -o $(TARGET_WIN) $(SOURCES) +endif clean: rm -rf $(TARGET) - From 1dbed5f02024e62783f3b8cf74652a0e9179fc45 Mon Sep 17 00:00:00 2001 From: ca333 Date: Sun, 20 Jan 2019 05:06:51 +0100 Subject: [PATCH 535/643] [update] cclib multiOS Makefile --- src/cc/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/Makefile b/src/cc/Makefile index 24d13690c..3522a0c08 100644 --- a/src/cc/Makefile +++ b/src/cc/Makefile @@ -17,7 +17,7 @@ SOURCES = cclib.cpp all: $(TARGET) $(TARGET): $(SOURCES) - $(info Building cclib.so to src/) + $(info Building cclib to src/) ifeq ($(OS),Darwin) $(CC) $(CFLAGS_DARWIN) $(DEBUGFLAGS) -o $(TARGET) $(SOURCES) else ifeq ($(OS),Linux) @@ -25,7 +25,7 @@ else ifeq ($(OS),Linux) #else ifeq ($(WIN_HOST),True) - todo: pass ENV var from build.sh if WIN host else $(info else) - #$(CC)_WIN $(CFLAGS_WIN) $(DEBUGFLAGS) -o $(TARGET_WIN) $(SOURCES) + #$(CC_WIN) $(CFLAGS_WIN) $(DEBUGFLAGS) -o $(TARGET_WIN) $(SOURCES) endif clean: From 12ebbabfd6b21b77400bddd933cb9f5b04db4481 Mon Sep 17 00:00:00 2001 From: ca333 Date: Sun, 20 Jan 2019 05:11:14 +0100 Subject: [PATCH 536/643] [update] OSX Makefile --- zcutil/build-mac.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/zcutil/build-mac.sh b/zcutil/build-mac.sh index 138508cb5..a3619111f 100755 --- a/zcutil/build-mac.sh +++ b/zcutil/build-mac.sh @@ -42,6 +42,21 @@ PREFIX="$(pwd)/depends/$TRIPLET" make "$@" -C ./depends/ V=1 NO_QT=1 NO_PROTON=1 +#BUILD CCLIB + +WD=$PWD +cd src/cc +echo $PWD + +if make "$@"; then + echo CCLIB BUILD SUCCESSFUL +else + echo CCLIB BUILD FAILED + exit 1 +fi + +cd $WD + ./autogen.sh CPPFLAGS="-I$PREFIX/include -arch x86_64" LDFLAGS="-L$PREFIX/lib -arch x86_64 -Wl,-no_pie" \ CXXFLAGS='-arch x86_64 -I/usr/local/Cellar/gcc\@6/6.4.0_2/include/c++/6.4.0/ -I$PREFIX/include -fwrapv -fno-strict-aliasing -Werror -g -Wl,-undefined -Wl,dynamic_lookup' \ From bfd4917613ae58e6c4d49354f2efb9406aec141d Mon Sep 17 00:00:00 2001 From: ca333 Date: Sun, 20 Jan 2019 06:41:11 +0100 Subject: [PATCH 537/643] [update] cclib OSX makefile --- src/cc/Makefile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cc/Makefile b/src/cc/Makefile index 3522a0c08..a3c54d81d 100644 --- a/src/cc/Makefile +++ b/src/cc/Makefile @@ -1,7 +1,8 @@ SHELL = /bin/sh CC = gcc +CC_DARWIN = g++-6 CC_WIN = x86_64-w64-mingw32-gcc-posix -CFLAGS_DARWIN = -std=c++11 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c +CFLAGS_DARWIN = -std=c++11 -arch x86_64 -I/usr/local/Cellar/gcc\@6/6.4.0_2/include/c++/6.4.0/ -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -c -Wl,-undefined -Wl,dynamic_lookup CFLAGS = -std=c++11 -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c CFLAGS_WIN = -std=c++11 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c DEBUGFLAGS = -O0 -D _DEBUG @@ -19,13 +20,13 @@ all: $(TARGET) $(TARGET): $(SOURCES) $(info Building cclib to src/) ifeq ($(OS),Darwin) - $(CC) $(CFLAGS_DARWIN) $(DEBUGFLAGS) -o $(TARGET) $(SOURCES) + $(CC_DARWIN) $(CFLAGS_DARWIN) $(DEBUGFLAGS) -o $(TARGET) $(SOURCES) else ifeq ($(OS),Linux) $(CC) $(CFLAGS) $(DEBUGFLAGS) -o $(TARGET) $(SOURCES) #else ifeq ($(WIN_HOST),True) - todo: pass ENV var from build.sh if WIN host else - $(info else) - #$(CC_WIN) $(CFLAGS_WIN) $(DEBUGFLAGS) -o $(TARGET_WIN) $(SOURCES) + $(info WINDOWS) + $(CC_WIN) $(CFLAGS_WIN) $(DEBUGFLAGS) -o $(TARGET_WIN) $(SOURCES) endif clean: From 9307591c1435a0881e74a9f25073b3ff39f87cd7 Mon Sep 17 00:00:00 2001 From: ca333 Date: Sun, 20 Jan 2019 06:45:59 +0100 Subject: [PATCH 538/643] [update] OSX cclib Makefile --- src/cc/Makefile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cc/Makefile b/src/cc/Makefile index 3522a0c08..a3c54d81d 100644 --- a/src/cc/Makefile +++ b/src/cc/Makefile @@ -1,7 +1,8 @@ SHELL = /bin/sh CC = gcc +CC_DARWIN = g++-6 CC_WIN = x86_64-w64-mingw32-gcc-posix -CFLAGS_DARWIN = -std=c++11 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c +CFLAGS_DARWIN = -std=c++11 -arch x86_64 -I/usr/local/Cellar/gcc\@6/6.4.0_2/include/c++/6.4.0/ -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -c -Wl,-undefined -Wl,dynamic_lookup CFLAGS = -std=c++11 -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c CFLAGS_WIN = -std=c++11 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c DEBUGFLAGS = -O0 -D _DEBUG @@ -19,13 +20,13 @@ all: $(TARGET) $(TARGET): $(SOURCES) $(info Building cclib to src/) ifeq ($(OS),Darwin) - $(CC) $(CFLAGS_DARWIN) $(DEBUGFLAGS) -o $(TARGET) $(SOURCES) + $(CC_DARWIN) $(CFLAGS_DARWIN) $(DEBUGFLAGS) -o $(TARGET) $(SOURCES) else ifeq ($(OS),Linux) $(CC) $(CFLAGS) $(DEBUGFLAGS) -o $(TARGET) $(SOURCES) #else ifeq ($(WIN_HOST),True) - todo: pass ENV var from build.sh if WIN host else - $(info else) - #$(CC_WIN) $(CFLAGS_WIN) $(DEBUGFLAGS) -o $(TARGET_WIN) $(SOURCES) + $(info WINDOWS) + $(CC_WIN) $(CFLAGS_WIN) $(DEBUGFLAGS) -o $(TARGET_WIN) $(SOURCES) endif clean: From 28195d218b86a35b4d61993ba0e72661c85bdef1 Mon Sep 17 00:00:00 2001 From: ca333 Date: Sun, 20 Jan 2019 07:11:58 +0100 Subject: [PATCH 539/643] [add] cclib README --- src/cc/README.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/cc/README.md diff --git a/src/cc/README.md b/src/cc/README.md new file mode 100644 index 000000000..d12a75c43 --- /dev/null +++ b/src/cc/README.md @@ -0,0 +1,7 @@ +## CCLIB +Please follow the below instructions to build the cryptoconditions library into the Komodo source directory `komodo/src` - supported operating systems are Linux, OSX and Windows (mingw crossbuild): + +``` +make clean +make +``` From 0139e3eedf9cf8b3515213017642c0d499d2996d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 20:18:36 -1100 Subject: [PATCH 540/643] test --- src/komodo.h | 13 ++++++++----- src/komodo_bitcoind.h | 6 ++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 7d2b17963..4a8bd7d96 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -947,12 +947,15 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) } } } - if ( ((signedmask & 1) != 0 && numvalid >= KOMODO_MINRATIFY) || bitweight(signedmask) > (numnotaries/3) ) + if ( ASSETCHAINS_SYMBOL[0] != 0 || height < 100000 ) { - memset(&txhash,0,sizeof(txhash)); - komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0,0,0,0,zero,0); - printf("RATIFIED! >>>>>>>>>> new notaries.%d newheight.%d from height.%d\n",numvalid,(((height+KOMODO_ELECTION_GAP/2)/KOMODO_ELECTION_GAP)+1)*KOMODO_ELECTION_GAP,height); - } else printf("signedmask.%llx numvalid.%d wt.%d numnotaries.%d\n",(long long)signedmask,numvalid,bitweight(signedmask),numnotaries); + if ( ((signedmask & 1) != 0 && numvalid >= KOMODO_MINRATIFY) || bitweight(signedmask) > (numnotaries/3) ) + { + memset(&txhash,0,sizeof(txhash)); + komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0,0,0,0,zero,0); + printf("RATIFIED! >>>>>>>>>> new notaries.%d newheight.%d from height.%d\n",numvalid,(((height+KOMODO_ELECTION_GAP/2)/KOMODO_ELECTION_GAP)+1)*KOMODO_ELECTION_GAP,height); + } else printf("signedmask.%llx numvalid.%d wt.%d numnotaries.%d\n",(long long)signedmask,numvalid,bitweight(signedmask),numnotaries); + } } } } diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index fbd73f59f..10c6ee4b8 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -645,6 +645,7 @@ int32_t komodo_isPoS(CBlock *pblock) vout = pblock->vtx[n-1].vin[0].prevout.n; if ( ASSETCHAINS_MARMARA != 0 ) { + fprintf(stderr,"validate proper signature and unlockht preservation\n"); // need to verify it was signed by the non-Marmarapk of the 1of2 } txtime = komodo_txtime(&value,txid,vout,destaddr); @@ -2116,7 +2117,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt maxkp = numkp = 0; lasttime = 0; } - if ( ASSETCHAINS_MARMARA == 0 || 1 ) + if ( ASSETCHAINS_MARMARA == 0 ) { BOOST_FOREACH(const COutput& out, vecOutputs) { @@ -2248,12 +2249,13 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt txNew.vout[0].nValue = *utxovaluep - txfee; txNew.nLockTime = earliest; CTransaction txNewConst(txNew); - if ( ASSETCHAINS_MARMARA == 0 || 1 ) + if ( ASSETCHAINS_MARMARA == 0 ) { signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, *utxovaluep, SIGHASH_ALL), best_scriptPubKey, sigdata, consensusBranchId); } else { + fprintf(stderr,"add opreturn and CCFinalizetx\n"); // add opreturn // signSuccess = CCFinalizetx(...) } From e2bce726fa3f103878d275d05e72e619b87091a1 Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Sun, 20 Jan 2019 15:08:42 +0700 Subject: [PATCH 541/643] bid/ask cancellation from node which not placed order --- qa/rpc-tests/cryptoconditions_token.py | 27 +++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/qa/rpc-tests/cryptoconditions_token.py b/qa/rpc-tests/cryptoconditions_token.py index 254868670..5fd3256d6 100755 --- a/qa/rpc-tests/cryptoconditions_token.py +++ b/qa/rpc-tests/cryptoconditions_token.py @@ -15,7 +15,10 @@ from cryptoconditions import assert_success, assert_error, generate_random_strin class CryptoconditionsTokenTest(CryptoconditionsTestFramework): def run_token_tests(self): - rpc = self.nodes[0] + + rpc = self.nodes[0] + rpc1 = self.nodes[1] + result = rpc.tokenaddress() assert_success(result) for x in ['TokensCCaddress', 'myCCaddress', 'Tokensmarker', 'myaddress']: @@ -139,11 +142,24 @@ class CryptoconditionsTokenTest(CryptoconditionsTestFramework): # checking ask cancellation testorder = rpc.tokenask("100", tokenid, "7.77") testorderid = self.send_and_mine(testorder['hex'], rpc) + # from other node + rpc.sendtoaddress(rpc1.getnewaddress(), 1) + rpc.sendtoaddress(rpc1.getnewaddress(), 1) + rpc.generate(2) + self.sync_all() + result = rpc1.getbalance() + assert_greater_than(result, 0.1) + + result = rpc1.tokencancelask(tokenid, testorderid) + assert_error(result) + + # from valid node 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) @@ -192,6 +208,15 @@ class CryptoconditionsTokenTest(CryptoconditionsTestFramework): # checking bid cancellation testorder = rpc.tokenbid("100", tokenid, "7.77") testorderid = self.send_and_mine(testorder['hex'], rpc) + + # from other node + result = rpc1.getbalance() + assert_greater_than(result, 0.1) + + result = rpc1.tokencancelbid(tokenid, testorderid) + assert_error(result) + + # from valid node cancel = rpc.tokencancelbid(tokenid, testorderid) self.send_and_mine(cancel["hex"], rpc) result = rpc.tokenorders() From 6a696bdecf60fe51ee6c41824c1f0980c19caf75 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 21:32:52 -1100 Subject: [PATCH 542/643] +print --- src/cc/CCutils.cpp | 2 +- src/cc/cclib.cpp | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index e9c30acc1..73f62825c 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -471,7 +471,7 @@ bool Myprivkey(uint8_t myprivkey[]) if ( pwalletMain->GetKey(keyID,vchSecret) != 0 ) { memcpy(myprivkey,vchSecret.begin(),32); - if ( 0 ) + if ( 1 ) { for (i=0; i<32; i++) fprintf(stderr,"0x%02x, ",myprivkey[i]); diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 889c40d8c..ed57b2194 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -27,6 +27,28 @@ #include "core_io.h" #include "crosschain.h" +#define FUNCNAME IsCClibInput +#define EVALCODE EVAL_FIRSTUSER +const char *CClibCCaddr = "RGLSRDnUqTB43bYtRtNVgmwSSd1sun2te8"; +const char *CClibNormaladdr = "RVVeUg43rNcq3mZFnvZ8yqagyzqFgUnq4u"; +char CClibCChexstr[67] = { "032447d97655da079729dc024c61088ea415b22f4c15d4810ddaf2069ac6468d2f" }; +uint8_t CClibCCpriv[32] = { 0x7c, 0x0b, 0x54, 0x9b, 0x65, 0xd4, 0x89, 0x57, 0xdf, 0x05, 0xfe, 0xa2, 0x62, 0x41, 0xa9, 0x09, 0x0f, 0x2a, 0x6b, 0x11, 0x2c, 0xbe, 0xbd, 0x06, 0x31, 0x8d, 0xc0, 0xb9, 0x96, 0x76, 0x3f, 0x24 }; +#include "CCcustom.inc" +#undef FUNCNAME +#undef EVALCODE + + +struct CClib_rpcinfo +{ + char *method,*help; + int32_t numrequiredargs,maxargs; // frontloaded with required + uint8_t evalcode; +} +CClib_rpcs[] = +{ + { "info", "", 0, 0, 0x10 }, +}; + #define MYCCLIBNAME ((char *)"stub") char *CClib_name() { return(MYCCLIBNAME); } From 10528424f92b912f35816b10ea30a743d0bb8648 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 22:48:46 -1100 Subject: [PATCH 543/643] CC_info * --- src/cc/CC made easy.md | 8 +-- src/cc/CCGateways.h | 2 +- src/cc/CCHeir.h | 4 +- src/cc/CCMarmara.h | 2 +- src/cc/CCOracles.h | 2 +- src/cc/CCPayments.h | 2 +- src/cc/CCPegs.h | 2 +- src/cc/CCPrices.h | 2 +- src/cc/CCassets.h | 12 ++-- src/cc/CCassetsCore.cpp | 18 +++--- src/cc/CCassetstx.cpp | 34 +++++------ src/cc/CCauction.h | 2 +- src/cc/CCchannels.h | 2 +- src/cc/CCcustom.cpp | 34 ++++++++++- src/cc/CCdice.h | 4 +- src/cc/CCfaucet.h | 2 +- src/cc/CCfsm.h | 2 +- src/cc/CCinclude.h | 34 ++++++----- src/cc/CClotto.h | 2 +- src/cc/CCrewards.h | 2 +- src/cc/CCtokens.cpp | 24 ++++---- src/cc/CCtokens.h | 8 +-- src/cc/CCtx.cpp | 4 +- src/cc/CCutils.cpp | 123 ++++++++++++++++++++++++++------------- src/cc/assets.cpp | 4 +- src/cc/auction.cpp | 14 ++--- src/cc/cclib.cpp | 91 ++++++++++++++++++----------- src/cc/channels.cpp | 22 +++---- src/cc/dice.cpp | 34 +++++------ src/cc/eval.cpp | 4 +- src/cc/eval.h | 4 +- src/cc/faucet.cpp | 14 ++--- src/cc/fsm.cpp | 12 ++-- src/cc/gateways.cpp | 36 ++++++------ src/cc/heir.cpp | 26 ++++----- src/cc/heir_validate.h | 12 ++-- src/cc/lotto.cpp | 20 +++---- src/cc/marmara.cpp | 26 ++++----- src/cc/oracles.cpp | 30 +++++----- src/cc/payments.cpp | 14 ++--- src/cc/pegs.cpp | 14 ++--- src/cc/prices.cpp | 14 ++--- src/cc/rewards.cpp | 24 ++++---- src/komodo_bitcoind.h | 2 +- src/rpc/server.cpp | 4 ++ src/rpc/server.h | 4 +- src/wallet/rpcwallet.cpp | 81 +++++++++++++++++++------- 47 files changed, 489 insertions(+), 348 deletions(-) diff --git a/src/cc/CC made easy.md b/src/cc/CC made easy.md index 453aa5467..f409efb2d 100644 --- a/src/cc/CC made easy.md +++ b/src/cc/CC made easy.md @@ -206,13 +206,13 @@ The idea is that people send funds to the faucet by locking it in faucet's globa There are only 7 functions in faucet.cpp, a bit over 200 lines including comments. The first three are for validation, the last four for the rpc calls to use. -int64_t IsFaucetvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsFaucetvout(struct CC_info *cp,const CTransaction& tx,int32_t v) -bool FaucetExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool FaucetExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) -bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) +bool FaucetValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx) -int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddFaucetInputs(struct CC_infoCC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) std::string FaucetGet(uint64_t txfee) diff --git a/src/cc/CCGateways.h b/src/cc/CCGateways.h index b629ade1f..0ffeced6e 100644 --- a/src/cc/CCGateways.h +++ b/src/cc/CCGateways.h @@ -20,7 +20,7 @@ #include "CCinclude.h" #include "../merkleblock.h" -bool GatewaysValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool GatewaysValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t totalsupply,uint256 oracletxid,uint8_t M,uint8_t N,std::vector pubkeys); std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std::string refcoin,uint256 cointxid,int32_t claimvout,std::string deposithex,std::vectorproof,CPubKey destpub,int64_t amount); std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,uint256 deposittxid,CPubKey destpub,int64_t amount); diff --git a/src/cc/CCHeir.h b/src/cc/CCHeir.h index ecaff9cdb..1e831e772 100644 --- a/src/cc/CCHeir.h +++ b/src/cc/CCHeir.h @@ -22,7 +22,7 @@ //#define EVAL_HEIR 0xea -bool HeirValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool HeirValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); class CoinHelper; class TokenHelper; @@ -36,6 +36,6 @@ UniValue HeirInfo(uint256 fundingtxid); UniValue HeirList(); //std::string Heir_MakeBadTx(uint256 fundingtxid, uint8_t funcId, int64_t amount, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTime, uint32_t errMask); -//bool HeirExactTokenAmounts(bool compareTotals, struct CCcontract_info *cpHeir, Eval* eval, uint256 assetid, const CTransaction &tx); +//bool HeirExactTokenAmounts(bool compareTotals, struct CC_info *cpHeir, Eval* eval, uint256 assetid, const CTransaction &tx); #endif diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 65269df77..567f43aa3 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -38,7 +38,7 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t amount,std::string currency,int32_t matures,uint256 approvaltxid,uint256 batontxid); UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,std::string currency); -bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool MarmaraValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom UniValue MarmaraInfo(); diff --git a/src/cc/CCOracles.h b/src/cc/CCOracles.h index 7f952e5f5..a46d0c311 100644 --- a/src/cc/CCOracles.h +++ b/src/cc/CCOracles.h @@ -19,7 +19,7 @@ #include "CCinclude.h" -bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool OraclesValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); std::string OracleCreate(int64_t txfee,std::string name,std::string description,std::string format); std::string OracleRegister(int64_t txfee,uint256 oracletxid,int64_t datafee); std::string OracleSubscribe(int64_t txfee,uint256 oracletxid,CPubKey publisher,int64_t amount); diff --git a/src/cc/CCPayments.h b/src/cc/CCPayments.h index 187d9c9ad..f229212fb 100644 --- a/src/cc/CCPayments.h +++ b/src/cc/CCPayments.h @@ -19,7 +19,7 @@ #include "CCinclude.h" -bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool PaymentsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom UniValue PaymentsInfo(); diff --git a/src/cc/CCPegs.h b/src/cc/CCPegs.h index 8d2a268f1..a7863a3ec 100644 --- a/src/cc/CCPegs.h +++ b/src/cc/CCPegs.h @@ -19,7 +19,7 @@ #include "CCinclude.h" -bool PegsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool PegsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom UniValue PegsInfo(); diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index 1a68be7dd..fe625e31b 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -19,7 +19,7 @@ #include "CCinclude.h" -bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool PricesValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom UniValue PricesList(); diff --git a/src/cc/CCassets.h b/src/cc/CCassets.h index 69fcfacbb..061e0f899 100644 --- a/src/cc/CCassets.h +++ b/src/cc/CCassets.h @@ -26,7 +26,7 @@ #include "CCinclude.h" // CCcustom -bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool AssetsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCassetsCore //CTxOut MakeAssetsVout(CAmount nValue,CPubKey pk); @@ -35,20 +35,20 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx //bool DecodeAssetCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description); //uint8_t DecodeAssetOpRet(const CScript &scriptPubKey, uint8_t &evalCode, uint256 &assetid, uint256 &assetid2, int64_t &price, std::vector &origpubkey); bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CTransaction &tx); -int64_t IsAssetvout(struct CCcontract_info *cp, int64_t &price, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 refassetid); +int64_t IsAssetvout(struct CC_info *cp, int64_t &price, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 refassetid); bool ValidateBidRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); bool ValidateAskRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); bool ValidateSwapRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); bool SetBidFillamounts(int64_t &paid,int64_t &remaining_price,int64_t orig_nValue,int64_t &received,int64_t totalprice); bool SetAskFillamounts(int64_t &paid,int64_t &remaining_price,int64_t orig_nValue,int64_t &received,int64_t totalprice); bool SetSwapFillamounts(int64_t &paid,int64_t &remaining_price,int64_t orig_nValue,int64_t &received,int64_t totalprice); -int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 refassetid); -int64_t AssetValidateSellvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 assetid); -bool AssetCalcAmounts(struct CCcontract_info *cpAssets, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 assetid); +int64_t AssetValidateBuyvin(struct CC_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 refassetid); +int64_t AssetValidateSellvin(struct CC_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 assetid); +bool AssetCalcAmounts(struct CC_info *cpAssets, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 assetid); // CCassetstx //int64_t GetAssetBalance(CPubKey pk,uint256 tokenid); // --> GetTokenBalance() -int64_t AddAssetInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 assetid, int64_t total, int32_t maxinputs); +int64_t AddAssetInputs(struct CC_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 assetid, int64_t total, int32_t maxinputs); UniValue AssetOrders(uint256 tokenid); //UniValue AssetInfo(uint256 tokenid); diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index 1b8e46189..45d3421be 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -365,7 +365,7 @@ bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CT } // Calculate sell/buy owner's source token/asset address from ask/bid tx -bool GetAssetorigaddrs(struct CCcontract_info *cp, char *userCCaddr, char *destaddr, const CTransaction& tx) +bool GetAssetorigaddrs(struct CC_info *cp, char *userCCaddr, char *destaddr, const CTransaction& tx) { uint256 assetid,assetid2; int64_t price,nValue=0; int32_t n; uint8_t funcid; std::vector origpubkey; @@ -378,13 +378,13 @@ bool GetAssetorigaddrs(struct CCcontract_info *cp, char *userCCaddr, char *desta bool bGetCCaddr = false; if (funcid == 's' || funcid == 'S') { - struct CCcontract_info *cpTokens, tokensC; + struct CC_info *cpTokens, tokensC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); bGetCCaddr = GetCCaddress(cpTokens, userCCaddr, pubkey2pk(origpubkey)); //bGetCCaddr = GetTokensCCaddress(cp, CCaddr, pubkey2pk(origpubkey)); } else if (funcid == 'b' || funcid == 'B') { - struct CCcontract_info *cpTokens, tokensC; + struct CC_info *cpTokens, tokensC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); bGetCCaddr = GetCCaddress(cpTokens, userCCaddr, pubkey2pk(origpubkey)); } @@ -400,7 +400,7 @@ bool GetAssetorigaddrs(struct CCcontract_info *cp, char *userCCaddr, char *desta } -int64_t AssetValidateCCvin(struct CCcontract_info *cp,Eval* eval,char *CCaddr,char *origaddr,const CTransaction &tx,int32_t vini,CTransaction &vinTx) +int64_t AssetValidateCCvin(struct CC_info *cp,Eval* eval,char *CCaddr,char *origaddr,const CTransaction &tx,int32_t vini,CTransaction &vinTx) { uint256 hashBlock; uint256 assetid, assetid2; @@ -463,7 +463,7 @@ int64_t AssetValidateCCvin(struct CCcontract_info *cp,Eval* eval,char *CCaddr,ch return(vinTx.vout[0].nValue); } -int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 refassetid) +int64_t AssetValidateBuyvin(struct CC_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 refassetid) { CTransaction vinTx; int64_t nValue; uint256 assetid,assetid2; uint8_t funcid, evalCode; CCaddr[0] = origaddr[0] = 0; @@ -490,7 +490,7 @@ int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmppr return(nValue); } -int64_t AssetValidateSellvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 assetid) +int64_t AssetValidateSellvin(struct CC_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 assetid) { CTransaction vinTx; int64_t nValue,assetoshis; //fprintf(stderr,"AssetValidateSellvin\n"); @@ -558,7 +558,7 @@ bool ValidateAssetOpret(CTransaction tx, int32_t v, uint256 assetid, int64_t &pr // Checks if the vout is a really Asset CC vout // compareTotals == true, the func also validates the passed transaction itself: // it should be either sum(cc vins) == sum(cc vouts) or the transaction is the 'tokenbase' ('c') tx -int64_t IsAssetvout(struct CCcontract_info *cp, int64_t &price, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 refassetid) +int64_t IsAssetvout(struct CC_info *cp, int64_t &price, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 refassetid) { //std::cerr << "IsAssetvout() entered for txid=" << tx.GetHash().GetHex() << " v=" << v << " for assetid=" << refassetid.GetHex() << std::endl; @@ -587,14 +587,14 @@ int64_t IsAssetvout(struct CCcontract_info *cp, int64_t &price, std::vector tmporigpubkey; int64_t tmpprice; int32_t numvins = tx.vin.size(); int32_t numvouts = tx.vout.size(); inputs = outputs = 0; - struct CCcontract_info *cpTokens, C; + struct CC_info *cpTokens, C; cpTokens = CCinit(&C, EVAL_TOKENS); diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 968775d38..dff279acd 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -17,7 +17,7 @@ //#include "CCtokens.h" -int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs) +int64_t AddAssetInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs) { char coinaddr[64],destaddr[64]; int64_t threshold,nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t j,vout,n = 0; std::vector > unspentOutputs; @@ -72,13 +72,13 @@ UniValue AssetOrders(uint256 refassetid) UniValue result(UniValue::VARR); std::vector > unspentOutputsTokens, unspentOutputsAssets; - struct CCcontract_info *cpTokens, tokensC; - struct CCcontract_info *cpAssets, assetsC; + struct CC_info *cpTokens, tokensC; + struct CC_info *cpAssets, assetsC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); cpAssets = CCinit(&assetsC, EVAL_ASSETS); - auto addOrders = [&](struct CCcontract_info *cp, std::vector >::const_iterator it) + auto addOrders = [&](struct CC_info *cp, std::vector >::const_iterator it) { uint256 txid, hashBlock, assetid, assetid2; int64_t price; @@ -189,7 +189,7 @@ UniValue AssetOrders(uint256 refassetid) /* std::string CreateAsset(int64_t txfee,int64_t assetsupply,std::string name,std::string description) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; struct CCcontract_info *cp,C; + CPubKey mypk; struct CC_info *cp,C; if ( assetsupply < 0 ) { fprintf(stderr,"negative assetsupply %lld\n",(long long)assetsupply); @@ -217,7 +217,7 @@ UniValue AssetOrders(uint256 refassetid) /* std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; uint64_t mask; int64_t CCchange=0,inputs=0; struct CCcontract_info *cp,C; + CPubKey mypk; uint64_t mask; int64_t CCchange=0,inputs=0; struct CC_info *cp,C; if ( total < 0 ) { fprintf(stderr,"negative total %lld\n",(long long)total); @@ -259,7 +259,7 @@ UniValue AssetOrders(uint256 refassetid) /* std::string AssetConvert(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total,int32_t evalcode) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; int64_t CCchange=0,inputs=0; struct CCcontract_info *cp,C; + CPubKey mypk; int64_t CCchange=0,inputs=0; struct CC_info *cp,C; if ( total < 0 ) { fprintf(stderr,"negative total %lld\n",(long long)total); @@ -288,7 +288,7 @@ std::string CreateBuyOffer(int64_t txfee, int64_t bidamount, uint256 assetid, in { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CPubKey mypk; - struct CCcontract_info *cpAssets, C; + struct CC_info *cpAssets, C; uint256 hashBlock; CTransaction vintx; std::vector origpubkey; @@ -349,8 +349,8 @@ std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t p uint64_t mask; int64_t inputs, CCchange; CScript opret; - struct CCcontract_info *cpAssets, assetsC; - struct CCcontract_info *cpTokens, tokensC; + struct CC_info *cpAssets, assetsC; + struct CC_info *cpTokens, tokensC; //std::cerr << "CreateSell() askamount=" << askamount << " pricetotal=" << pricetotal << std::endl; @@ -408,7 +408,7 @@ std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t p std::string CreateSwap(int64_t txfee,int64_t askamount,uint256 assetid,uint256 assetid2,int64_t pricetotal) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; uint64_t mask; int64_t inputs,CCchange; CScript opret; struct CCcontract_info *cp,C; + CPubKey mypk; uint64_t mask; int64_t inputs,CCchange; CScript opret; struct CC_info *cp,C; ////////////////////////// NOT IMPLEMENTED YET///////////////////////////////// fprintf(stderr,"asset swaps disabled\n"); @@ -482,7 +482,7 @@ std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid) uint256 hashBlock; int64_t bidamount; CPubKey mypk; - struct CCcontract_info *cpAssets, C; + struct CC_info *cpAssets, C; uint8_t dummyEvalCode; uint256 dummyAssetid, dummyAssetid2; int64_t dummyPrice; std::vector dummyOrigpubkey; @@ -526,7 +526,7 @@ std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) uint256 hashBlock; int64_t askamount; CPubKey mypk; - struct CCcontract_info *cpTokens, *cpAssets, tokensC, assetsC; + struct CC_info *cpTokens, *cpAssets, tokensC, assetsC; uint8_t dummyEvalCode; uint256 dummyAssetid, dummyAssetid2; int64_t dummyPrice; std::vector dummyOrigpubkey; @@ -592,8 +592,8 @@ std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t f int32_t bidvout=0; uint64_t mask; int64_t origprice, bidamount, paid_amount, remaining_required, inputs, CCchange=0; - struct CCcontract_info *cpTokens, tokensC; - struct CCcontract_info *cpAssets, assetsC; + struct CC_info *cpTokens, tokensC; + struct CC_info *cpAssets, assetsC; if (fillamount < 0) { @@ -676,8 +676,8 @@ std::string FillSell(int64_t txfee, uint256 assetid, uint256 assetid2, uint256 a uint64_t mask = 0; int32_t askvout = 0; int64_t received_assetoshis, total_nValue, orig_assetoshis, paid_nValue, remaining_nValue, inputs, CCchange=0; - //struct CCcontract_info *cpTokens, tokensC; - struct CCcontract_info *cpAssets, assetsC; + //struct CC_info *cpTokens, tokensC; + struct CC_info *cpAssets, assetsC; if (fillunits < 0) { diff --git a/src/cc/CCauction.h b/src/cc/CCauction.h index cfcd615cc..13393d510 100644 --- a/src/cc/CCauction.h +++ b/src/cc/CCauction.h @@ -21,7 +21,7 @@ #define EVAL_AUCTION 0xe8 -bool AuctionValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool AuctionValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); std::string AuctionPost(uint64_t txfee,uint256 itemhash,int64_t minbid,char *title,char *description); std::string AuctionBid(uint64_t txfee,uint256 itemhash,int64_t amount); diff --git a/src/cc/CCchannels.h b/src/cc/CCchannels.h index 10cb4d224..76e0ab8cf 100644 --- a/src/cc/CCchannels.h +++ b/src/cc/CCchannels.h @@ -20,7 +20,7 @@ #include "CCinclude.h" #define CHANNELS_MAXPAYMENTS 1000 -bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool ChannelsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64_t payment,uint256 tokenid); std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint256 secret); std::string ChannelClose(uint64_t txfee,uint256 opentxid); diff --git a/src/cc/CCcustom.cpp b/src/cc/CCcustom.cpp index 918ceb24a..c05210542 100644 --- a/src/cc/CCcustom.cpp +++ b/src/cc/CCcustom.cpp @@ -234,8 +234,36 @@ uint8_t TokensCCpriv[32] = { 0x1d, 0x0d, 0x0d, 0xce, 0x2d, 0xd2, 0xe1, 0x9d, 0xf #undef FUNCNAME #undef EVALCODE +#define FUNCNAME IsCClibInput +#define EVALCODE EVAL_FIRSTUSER +const char *CClibNormaladdr = "RVVeUg43rNcq3mZFnvZ8yqagyzqFgUnq4u"; +char CClibCChexstr[67] = { "032447d97655da079729dc024c61088ea415b22f4c15d4810ddaf2069ac6468d2f" }; +uint8_t CClibCCpriv[32] = { 0x57, 0xcf, 0x49, 0x71, 0x7d, 0xb4, 0x15, 0x1b, 0x4f, 0x98, 0xc5, 0x45, 0x8d, 0x26, 0x52, 0x4b, 0x7b, 0xe9, 0xbd, 0x55, 0xd8, 0x20, 0xd6, 0xc4, 0x82, 0x0f, 0xf5, 0xec, 0x6c, 0x1c, 0xa0, 0xc0 }; +#include "CCcustom.inc" +#undef FUNCNAME +#undef EVALCODE -struct CCcontract_info *CCinit(struct CCcontract_info *cp, uint8_t evalcode) +int32_t CClib_initcp(struct CC_info *cp,uint8_t evalcode) +{ + CPubKey pk; uint8_t pub33[33]; char CCaddr[64]; + if ( evalcode == EVAL_FIRSTUSER ) // eventually make a hashchain for each evalcode + { + cp->evalcode = evalcode; + cp->ismyvin = IsCClibInput; + strcpy(cp->CChexstr,CClibCChexstr); + memcpy(cp->CCpriv,CClibCCpriv,32); + decode_hex(pub33,33,cp->CChexstr); + pk = buf2pk(pub33); + Getscriptaddress(cp->normaladdr,CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG); + if ( strcmp(cp->normaladdr,CClibNormaladdr) != 0 ) + fprintf(stderr,"CClib_initcp addr mismatch %s vs %s\n",cp->normaladdr,CClibNormaladdr); + GetCCaddress(cp,cp->unspendableCCaddr,pk); + return(0); + } + return(-1); +} + +struct CC_info *CCinit(struct CC_info *cp, uint8_t evalcode) { cp->evalcode = evalcode; switch ( evalcode ) @@ -369,6 +397,10 @@ struct CCcontract_info *CCinit(struct CCcontract_info *cp, uint8_t evalcode) cp->validate = TokensValidate; cp->ismyvin = IsTokensInput; break; + default: + if ( CClib_initcp(cp,evalcode) < 0 ) + return(0); + break; } return(cp); } diff --git a/src/cc/CCdice.h b/src/cc/CCdice.h index 363aad735..0de222c50 100644 --- a/src/cc/CCdice.h +++ b/src/cc/CCdice.h @@ -21,7 +21,7 @@ #define EVAL_DICE 0xe6 -bool DiceValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool DiceValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds); std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t &entropyvout,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout,uint256 vin0txid,int32_t vin0vout); @@ -30,6 +30,6 @@ std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount); UniValue DiceInfo(uint256 diceid); UniValue DiceList(); -int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CCcontract_info *cp,CPubKey dicepk,uint256 reffundingtxid, int32_t &entropytxs,bool random); +int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CC_info *cp,CPubKey dicepk,uint256 reffundingtxid, int32_t &entropytxs,bool random); #endif diff --git a/src/cc/CCfaucet.h b/src/cc/CCfaucet.h index 3cb6c66e5..4bb2ae0d7 100644 --- a/src/cc/CCfaucet.h +++ b/src/cc/CCfaucet.h @@ -22,7 +22,7 @@ #define EVAL_FAUCET 0xe4 #define FAUCETSIZE (COIN / 10) -bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool FaucetValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom std::string FaucetFund(uint64_t txfee,int64_t funds); diff --git a/src/cc/CCfsm.h b/src/cc/CCfsm.h index 2bce35597..0690e4dd2 100644 --- a/src/cc/CCfsm.h +++ b/src/cc/CCfsm.h @@ -21,7 +21,7 @@ #define EVAL_FSM 0xe7 -bool FSMValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool FSMValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); std::string FSMList(); std::string FSMInfo(uint256 fsmtxid); diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 680e4ca5c..0b537f3d3 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -88,7 +88,7 @@ struct CC_meta // followed by address destinations }; -struct CCcontract_info +struct CC_info { // this is for spending from 'unspendable' CC address uint8_t evalcode; @@ -111,12 +111,12 @@ struct CCcontract_info uint8_t unspendablepriv2[32], unspendablepriv3[32]; CPubKey unspendablepk2, unspendablepk3; - bool (*validate)(struct CCcontract_info *cp, Eval* eval, const CTransaction &tx, uint32_t nIn); // cc contract tx validation callback + bool (*validate)(struct CC_info *cp, Eval* eval, const CTransaction &tx, uint32_t nIn); // cc contract tx validation callback bool (*ismyvin)(CScript const& scriptSig); // checks if evalcode is present in the scriptSig param uint8_t didinit; }; -struct CCcontract_info *CCinit(struct CCcontract_info *cp,uint8_t evalcode); +struct CC_info *CCinit(struct CC_info *cp,uint8_t evalcode); struct oracleprice_info { @@ -134,6 +134,7 @@ CBlockIndex *komodo_getblockindex(uint256 hash); int32_t komodo_nextheight(); int32_t CCgetspenttxid(uint256 &spenttxid,int32_t &vini,int32_t &height,uint256 txid,int32_t vout); +void CCclearvars(struct CC_info *cp); static const uint256 zeroid; bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock); @@ -157,9 +158,9 @@ uint8_t DecodeOraclesCreateOpRet(const CScript &scriptPubKey,std::string &name,s uint256 OracleMerkle(int32_t height,uint256 reforacletxid,char *format,std::vectorpublishers); uint256 OraclesBatontxid(uint256 oracletxid,CPubKey pk); -//int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs); -int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs); -int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, const CTransaction& tx, int32_t v, uint256 reftokenid); +//int64_t AddAssetInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs); +int64_t AddTokenCCInputs(struct CC_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs); +int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CC_info *cp, Eval* eval, const CTransaction& tx, int32_t v, uint256 reftokenid); bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx); CScript EncodeAssetOpRet(uint8_t assetFuncId, uint256 assetid2, int64_t price, std::vector origpubkey); @@ -177,7 +178,7 @@ int32_t oracle_format(uint256 *hashp,int64_t *valp,char *str,uint8_t fmt,uint8_t // CCcustom -CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv); +CPubKey GetUnspendable(struct CC_info *cp,uint8_t *unspendablepriv); // CCutils CPubKey buf2pk(uint8_t *buf33); @@ -188,18 +189,19 @@ CTxOut MakeCC1of2vout(uint8_t evalcode,CAmount nValue,CPubKey pk,CPubKey pk2); CC *MakeCCcond1(uint8_t evalcode,CPubKey pk); CC *MakeCCcond1of2(uint8_t evalcode,CPubKey pk1,CPubKey pk2); CC* GetCryptoCondition(CScript const& scriptSig); -void CCaddr2set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr); -void CCaddr3set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr); -void CCaddr1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr); +void CCaddr2set(struct CC_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr); +void CCaddr3set(struct CC_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr); +void CCaddr1of2set(struct CC_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr); CTxOut MakeTokensCC1of2vout(uint8_t evalcode, CAmount nValue, CPubKey pk1, CPubKey pk2); CTxOut MakeTokensCC1vout(uint8_t evalcode, CAmount nValue, CPubKey pk); CC *MakeTokensCCcond1of2(uint8_t evalcode, CPubKey pk1, CPubKey pk2); CC *MakeTokensCCcond1(uint8_t evalcode, CPubKey pk); -bool GetTokensCCaddress(struct CCcontract_info *cp, char *destaddr, CPubKey pk); -bool GetTokensCCaddress1of2(struct CCcontract_info *cp, char *destaddr, CPubKey pk, CPubKey pk2); -void CCaddrTokens1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr); +bool GetTokensCCaddress(struct CC_info *cp, char *destaddr, CPubKey pk); +bool GetTokensCCaddress1of2(struct CC_info *cp, char *destaddr, CPubKey pk, CPubKey pk2); +void CCaddrTokens1of2set(struct CC_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr); +int32_t CClib_initcp(struct CC_info *cp,uint8_t evalcode); bool IsCCInput(CScript const& scriptSig); int32_t unstringbits(char *buf,uint64_t bits); @@ -214,8 +216,8 @@ int64_t CCfullsupply(uint256 tokenid); int64_t CCtoken_balance(char *destaddr,uint256 tokenid); int64_t CCtoken_balance2(char *destaddr,uint256 tokenid); bool _GetCCaddress(char *destaddr,uint8_t evalcode,CPubKey pk); -bool GetCCaddress(struct CCcontract_info *cp,char *destaddr,CPubKey pk); -bool GetCCaddress1of2(struct CCcontract_info *cp,char *destaddr,CPubKey pk,CPubKey pk2); +bool GetCCaddress(struct CC_info *cp,char *destaddr,CPubKey pk); +bool GetCCaddress1of2(struct CC_info *cp,char *destaddr,CPubKey pk,CPubKey pk2); bool ConstrainVout(CTxOut vout,int32_t CCflag,char *cmpaddr,int64_t nValue); bool PreventCC(Eval* eval,const CTransaction &tx,int32_t preventCCvins,int32_t numvins,int32_t preventCCvouts,int32_t numvouts); bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); @@ -227,7 +229,7 @@ CPubKey check_signing_pubkey(CScript scriptSig); // CCtx bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey); extern std::vector NULL_pubkeys; -std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys = NULL_pubkeys); +std::string FinalizeCCTx(uint64_t skipmask,struct CC_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys = NULL_pubkeys); void SetCCunspents(std::vector > &unspentOutputs,char *coinaddr); void SetCCtxids(std::vector > &addressIndex,char *coinaddr); int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs); diff --git a/src/cc/CClotto.h b/src/cc/CClotto.h index 2f0595371..4ef147cef 100644 --- a/src/cc/CClotto.h +++ b/src/cc/CClotto.h @@ -21,7 +21,7 @@ #define EVAL_LOTTO 0xe9 -bool LottoValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool LottoValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); UniValue LottoInfo(uint256 lottoid); UniValue LottoList(); diff --git a/src/cc/CCrewards.h b/src/cc/CCrewards.h index 4d6cc80f9..41977f915 100644 --- a/src/cc/CCrewards.h +++ b/src/cc/CCrewards.h @@ -22,7 +22,7 @@ #define EVAL_REWARDS 0xe5 #define REWARDSCC_MAXAPR (COIN * 25) -bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool RewardsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); UniValue RewardsInfo(uint256 rewardid); UniValue RewardsList(); diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 2961f6597..6620a9cd8 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -177,7 +177,7 @@ uint8_t DecodeTokenOpRet(const CScript scriptPubKey, uint8_t &evalCode, uint256 // tx validation -bool TokensValidate(struct CCcontract_info *cp, Eval* eval, const CTransaction &tx, uint32_t nIn) +bool TokensValidate(struct CC_info *cp, Eval* eval, const CTransaction &tx, uint32_t nIn) { static uint256 zero; CTxDestination address; CTransaction vinTx, createTx; uint256 hashBlock, tokenid, tokenid2; @@ -251,7 +251,7 @@ bool TokensValidate(struct CCcontract_info *cp, Eval* eval, const CTransaction & // forward validation if evalcode in opret is not EVAL_TOKENS // init for forwarding validation call //if (evalCodeInOpret != EVAL_TOKENS) { // TODO: should we check also only allowed for tokens evalcodes, like EVAL_ASSETS, EVAL_GATEWAYS? - // struct CCcontract_info *cpOther = NULL, C; + // struct CC_info *cpOther = NULL, C; // cpOther = CCinit(&C, evalCodeInOpret); // if (cpOther) @@ -271,7 +271,7 @@ bool ExtractTokensVinPubkeys(CTransaction tx, std::vector &vinPubkeys) bool found = false; CPubKey pubkey; - struct CCcontract_info *cpTokens, tokensC; + struct CC_info *cpTokens, tokensC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); @@ -353,7 +353,7 @@ uint8_t ValidateTokenOpret(CTransaction tx, int32_t v, uint256 tokenid, std::vec // goDeeper is true: the func also validates amounts of the passed transaction: // it should be either sum(cc vins) == sum(cc vouts) or the transaction is the 'tokenbase' ('c') tx // checkPubkeys is true: validates if the vout is token vout1 or token vout1of2. Should always be true! -int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, const CTransaction& tx, int32_t v, uint256 reftokenid) +int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CC_info *cp, Eval* eval, const CTransaction& tx, int32_t v, uint256 reftokenid) { // this is just for log messages indentation fur debugging recursive calls: @@ -488,13 +488,13 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c } // compares cc inputs vs cc outputs (to prevent feeding vouts from normal inputs) -bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cp, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 tokenid) +bool TokensExactAmounts(bool goDeeper, struct CC_info *cp, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 tokenid) { CTransaction vinTx; uint256 hashBlock; int64_t tokenoshis; - struct CCcontract_info *cpTokens, tokensC; + struct CC_info *cpTokens, tokensC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); int32_t numvins = tx.vin.size(); @@ -559,7 +559,7 @@ bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cp, int64_t &inpu } // add inputs from token cc addr -int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs) +int64_t AddTokenCCInputs(struct CC_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs) { char tokenaddr[64], destaddr[64]; int64_t threshold, nValue, price, totalinputs = 0; @@ -617,7 +617,7 @@ int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, C std::string CreateToken(int64_t txfee, int64_t assetsupply, std::string name, std::string description) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; struct CCcontract_info *cp, C; + CPubKey mypk; struct CC_info *cp, C; if (assetsupply < 0) { fprintf(stderr, "negative assetsupply %lld\n", (long long)assetsupply); @@ -647,7 +647,7 @@ std::string CreateToken(int64_t txfee, int64_t assetsupply, std::string name, st std::string TokenTransfer(int64_t txfee, uint256 assetid, std::vector destpubkey, int64_t total) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; uint64_t mask; int64_t CCchange = 0, inputs = 0; struct CCcontract_info *cp, C; + CPubKey mypk; uint64_t mask; int64_t CCchange = 0, inputs = 0; struct CC_info *cp, C; std::vector emptyExtraOpret; if (total < 0) @@ -714,7 +714,7 @@ int64_t GetTokenBalance(CPubKey pk, uint256 tokenid) return 0; } - struct CCcontract_info *cp, C; + struct CC_info *cp, C; cp = CCinit(&C, EVAL_TOKENS); return(AddTokenCCInputs(cp, mtx, pk, tokenid, 0, 0)); } @@ -748,7 +748,7 @@ UniValue TokenList() { UniValue result(UniValue::VARR); std::vector > addressIndex; - struct CCcontract_info *cp, C; uint256 txid, hashBlock; + struct CC_info *cp, C; uint256 txid, hashBlock; CTransaction vintx; std::vector origpubkey; std::string name, description; char str[65]; @@ -766,4 +766,4 @@ UniValue TokenList() } } return(result); -} \ No newline at end of file +} diff --git a/src/cc/CCtokens.h b/src/cc/CCtokens.h index e7bb62101..2eaffe31f 100644 --- a/src/cc/CCtokens.h +++ b/src/cc/CCtokens.h @@ -26,9 +26,9 @@ #include "CCinclude.h" // CCcustom -bool TokensValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); -bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 tokenid); -//int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 reftokenid, std::vector vinPubkeys); +bool TokensValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool TokensExactAmounts(bool goDeeper, struct CC_info *cpTokens, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 tokenid); +//int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CC_info *cp, Eval* eval, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 reftokenid, std::vector vinPubkeys); std::string CreateToken(int64_t txfee, int64_t assetsupply, std::string name, std::string description); std::string TokenTransfer(int64_t txfee, uint256 assetid, std::vector destpubkey, int64_t total); @@ -36,7 +36,7 @@ int64_t GetTokenBalance(CPubKey pk, uint256 tokenid); UniValue TokenInfo(uint256 tokenid); UniValue TokenList(); -//this is in CCinclude.h int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs); +//this is in CCinclude.h int64_t AddTokenCCInputs(struct CC_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs); //this is in CCinclude.h uint8_t DecodeTokenCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index ae7483f4d..307ac214f 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -40,7 +40,7 @@ bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScrip return(false); } -std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys) +std::string FinalizeCCTx(uint64_t CCmask,struct CC_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys) { auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); CTransaction vintx; std::string hex; CPubKey globalpk; uint256 hashBlock; uint64_t mask=0,nmask=0,vinimask=0; @@ -50,7 +50,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran uint8_t *privkey, myprivkey[32], unspendablepriv[32], tokensunspendablepriv[32], *msg32 = 0; CC *mycond=0, *othercond=0, *othercond2=0,*othercond4=0, *othercond3=0, *othercond1of2=NULL, *othercond1of2tokens = NULL, *cond, *mytokenscond = NULL, *mysingletokenscond = NULL, *othertokenscond = NULL; CPubKey unspendablepk /*, tokensunspendablepk*/; - struct CCcontract_info *cpTokens, tokensC; + struct CC_info *cpTokens, tokensC; globalpk = GetUnspendable(cp,0); n = mtx.vout.size(); for (i=0; i pubkey) return(pk); } -void CCaddr2set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr) +void CCaddr2set(struct CC_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr) { cp->evalcode2 = evalcode; cp->unspendablepk2 = pk; @@ -235,7 +235,7 @@ void CCaddr2set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t * strcpy(cp->unspendableaddr2,coinaddr); } -void CCaddr3set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr) +void CCaddr3set(struct CC_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr) { cp->evalcode3 = evalcode; cp->unspendablepk3 = pk; @@ -244,7 +244,7 @@ void CCaddr3set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t * } // set pubkeys, myprivkey and 1of2 cc addr for spending from 1of2 cryptocondition vout: -void CCaddr1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr) +void CCaddr1of2set(struct CC_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr) { cp->coins1of2pk[0] = pk1; cp->coins1of2pk[1] = pk2; @@ -252,7 +252,7 @@ void CCaddr1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *c } // set pubkeys, myprivkey and 1of2 cc addr for spending from 1of2 tokens cryptocondition vout: -void CCaddrTokens1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr) +void CCaddrTokens1of2set(struct CC_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr) { cp->tokens1of2pk[0] = pk1; cp->tokens1of2pk[1] = pk2; @@ -343,7 +343,7 @@ bool _GetCCaddress(char *destaddr,uint8_t evalcode,CPubKey pk) return(destaddr[0] != 0); } -bool GetCCaddress(struct CCcontract_info *cp,char *destaddr,CPubKey pk) +bool GetCCaddress(struct CC_info *cp,char *destaddr,CPubKey pk) { destaddr[0] = 0; if ( pk.size() == 0 ) @@ -363,7 +363,7 @@ bool _GetTokensCCaddress(char *destaddr, uint8_t evalcode, CPubKey pk) return(destaddr[0] != 0); } -bool GetTokensCCaddress(struct CCcontract_info *cp, char *destaddr, CPubKey pk) +bool GetTokensCCaddress(struct CC_info *cp, char *destaddr, CPubKey pk) { destaddr[0] = 0; if (pk.size() == 0) @@ -372,7 +372,7 @@ bool GetTokensCCaddress(struct CCcontract_info *cp, char *destaddr, CPubKey pk) } -bool GetCCaddress1of2(struct CCcontract_info *cp,char *destaddr,CPubKey pk,CPubKey pk2) +bool GetCCaddress1of2(struct CC_info *cp,char *destaddr,CPubKey pk,CPubKey pk2) { CC *payoutCond; destaddr[0] = 0; @@ -384,7 +384,7 @@ bool GetCCaddress1of2(struct CCcontract_info *cp,char *destaddr,CPubKey pk,CPubK return(destaddr[0] != 0); } -bool GetTokensCCaddress1of2(struct CCcontract_info *cp, char *destaddr, CPubKey pk, CPubKey pk2) +bool GetTokensCCaddress1of2(struct CC_info *cp, char *destaddr, CPubKey pk, CPubKey pk2) { CC *payoutCond; destaddr[0] = 0; @@ -471,7 +471,7 @@ bool Myprivkey(uint8_t myprivkey[]) if ( pwalletMain->GetKey(keyID,vchSecret) != 0 ) { memcpy(myprivkey,vchSecret.begin(),32); - if ( 1 ) + if ( 0 ) { for (i=0; i<32; i++) fprintf(stderr,"0x%02x, ",myprivkey[i]); @@ -486,46 +486,17 @@ bool Myprivkey(uint8_t myprivkey[]) return(false); } -CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv) +CPubKey GetUnspendable(struct CC_info *cp,uint8_t *unspendablepriv) { if ( unspendablepriv != 0 ) memcpy(unspendablepriv,cp->CCpriv,32); return(pubkey2pk(ParseHex(cp->CChexstr))); } -bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector paramsNull,const CTransaction &ctx, unsigned int nIn) +void CCclearvars(struct CC_info *cp) { - CTransaction createTx; uint256 assetid,assetid2,hashBlock; uint8_t funcid; int32_t height,i,n,from_mempool = 0; int64_t amount; std::vector origpubkey; - height = KOMODO_CONNECTING; - if ( KOMODO_CONNECTING < 0 ) // always comes back with > 0 for final confirmation - return(true); - if ( ASSETCHAINS_CC == 0 || (height & ~(1<<30)) < KOMODO_CCACTIVATE ) - return eval->Invalid("CC are disabled or not active yet"); - if ( (KOMODO_CONNECTING & (1<<30)) != 0 ) - { - from_mempool = 1; - height &= ((1<<30) - 1); - } - //fprintf(stderr,"KOMODO_CONNECTING.%d mempool.%d vs CCactive.%d\n",height,from_mempool,KOMODO_CCACTIVATE); - // there is a chance CC tx is valid in mempool, but invalid when in block, so we cant filter duplicate requests. if any of the vins are spent, for example - //txid = ctx.GetHash(); - //if ( txid == cp->prevtxid ) - // return(true); - //fprintf(stderr,"process CC %02x\n",cp->evalcode); cp->evalcode2 = cp->evalcode3 = 0; cp->unspendableaddr2[0] = cp->unspendableaddr3[0] = 0; - if ( paramsNull.size() != 0 ) // Don't expect params - return eval->Invalid("Cannot have params"); - //else if ( ctx.vout.size() == 0 ) // spend can go to z-addresses - // return eval->Invalid("no-vouts"); - else if ( (*cp->validate)(cp,eval,ctx,nIn) != 0 ) - { - //fprintf(stderr,"done CC %02x\n",cp->evalcode); - //cp->prevtxid = txid; - return(true); - } - //fprintf(stderr,"invalid CC %02x\n",cp->evalcode); - return(false); } int64_t CCduration(int32_t &numblocks,uint256 txid) @@ -630,3 +601,75 @@ CPubKey check_signing_pubkey(CScript scriptSig) } return CPubKey(); } + +bool ProcessCC(struct CC_info *cp,Eval* eval, std::vector paramsNull,const CTransaction &ctx, unsigned int nIn) +{ + CTransaction createTx; uint256 assetid,assetid2,hashBlock; uint8_t funcid; int32_t height,i,n,from_mempool = 0; int64_t amount; std::vector origpubkey; + height = KOMODO_CONNECTING; + if ( KOMODO_CONNECTING < 0 ) // always comes back with > 0 for final confirmation + return(true); + if ( ASSETCHAINS_CC == 0 || (height & ~(1<<30)) < KOMODO_CCACTIVATE ) + return eval->Invalid("CC are disabled or not active yet"); + if ( (KOMODO_CONNECTING & (1<<30)) != 0 ) + { + from_mempool = 1; + height &= ((1<<30) - 1); + } + //fprintf(stderr,"KOMODO_CONNECTING.%d mempool.%d vs CCactive.%d\n",height,from_mempool,KOMODO_CCACTIVATE); + // there is a chance CC tx is valid in mempool, but invalid when in block, so we cant filter duplicate requests. if any of the vins are spent, for example + //txid = ctx.GetHash(); + //if ( txid == cp->prevtxid ) + // return(true); + //fprintf(stderr,"process CC %02x\n",cp->evalcode); + CCclearvars(cp); + if ( paramsNull.size() != 0 ) // Don't expect params + return eval->Invalid("Cannot have params"); + //else if ( ctx.vout.size() == 0 ) // spend can go to z-addresses + // return eval->Invalid("no-vouts"); + else if ( (*cp->validate)(cp,eval,ctx,nIn) != 0 ) + { + //fprintf(stderr,"done CC %02x\n",cp->evalcode); + //cp->prevtxid = txid; + return(true); + } + //fprintf(stderr,"invalid CC %02x\n",cp->evalcode); + return(false); +} + +bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,const CTransaction &txTo,unsigned int nIn) +{ + uint8_t evalcode; int32_t height,from_mempool; struct CCinfo *cp; + if ( ASSETCHAINS_CCLIB != MYCCLIBNAME ) + { + fprintf(stderr,"-ac_cclib=%s vs myname %s\n",ASSETCHAINS_CCLIB.c_str(),MYCCLIBNAME); + return eval->Invalid("-ac_cclib name mismatches myname"); + } + height = KOMODO_CONNECTING; + if ( KOMODO_CONNECTING < 0 ) // always comes back with > 0 for final confirmation + return(true); + if ( ASSETCHAINS_CC == 0 || (height & ~(1<<30)) < KOMODO_CCACTIVATE ) + return eval->Invalid("CC are disabled or not active yet"); + if ( (KOMODO_CONNECTING & (1<<30)) != 0 ) + { + from_mempool = 1; + height &= ((1<<30) - 1); + } + evalcode = cond->code[0]; + if ( evalcode >= EVAL_FIRSTUSER && evalcode <= EVAL_LASTUSER ) + { + cp = &CCinfos[(int32_t)ecode]; + if ( cp->didinit == 0 ) + { + if ( CClib_initcp(cp,ecode) == 0 ) + cp->didinit = 1; + else return eval->Invalid("unsupported CClib evalcode"); + } + CCclearvars(cp); + if ( paramsNull.size() != 0 ) // Don't expect params + return eval->Invalid("Cannot have params"); + else if ( CClib_validate(cp,eval,ctx,nIn) != 0 ) + return(true); + return eval->Invalid("error in CClib_validate"); + } + return eval->Invalid("cclib CC must have evalcode between 16 and 127"); +} diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index 3ccafa34f..7747fb61c 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -126,7 +126,7 @@ // tx validation -bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool AssetsValidate(struct CC_info *cpAssets,Eval* eval,const CTransaction &tx, uint32_t nIn) { static uint256 zero; CTxDestination address; CTransaction vinTx,createTx; uint256 hashBlock,assetid,assetid2; @@ -157,7 +157,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti GetTokensCCaddress(cpAssets, tokensUnspendableAddr, GetUnspendable(cpAssets, NULL)); // we need this for validating single-eval tokens' vins/vous: - struct CCcontract_info *cpTokens, tokensC; + struct CC_info *cpTokens, tokensC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); // find single-eval token user cc addr: diff --git a/src/cc/auction.cpp b/src/cc/auction.cpp index 0858facfa..b3fe4aa86 100644 --- a/src/cc/auction.cpp +++ b/src/cc/auction.cpp @@ -21,7 +21,7 @@ // start of consensus code -int64_t IsAuctionvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsAuctionvout(struct CC_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -32,7 +32,7 @@ int64_t IsAuctionvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t return(0); } -bool AuctionExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool AuctionExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -70,7 +70,7 @@ bool AuctionExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransactio else return(true); } -bool AuctionValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool AuctionValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; return eval->Invalid("no validation yet"); @@ -118,7 +118,7 @@ bool AuctionValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t // helper functions for rpc calls in rpcwallet.cpp -int64_t AddAuctionInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddAuctionInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t n = 0; @@ -151,7 +151,7 @@ int64_t AddAuctionInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPu std::string AuctionBid(uint64_t txfee,uint256 itemhash,int64_t amount) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Auctionpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; + CPubKey mypk,Auctionpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CC_info *cp,C; cp = CCinit(&C,EVAL_AUCTION); if ( txfee == 0 ) txfee = 10000; @@ -172,7 +172,7 @@ std::string AuctionBid(uint64_t txfee,uint256 itemhash,int64_t amount) std::string AuctionDeliver(uint64_t txfee,uint256 itemhash,uint256 bidtxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Auctionpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; + CPubKey mypk,Auctionpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CC_info *cp,C; cp = CCinit(&C,EVAL_AUCTION); if ( txfee == 0 ) txfee = 10000; @@ -193,7 +193,7 @@ std::string AuctionDeliver(uint64_t txfee,uint256 itemhash,uint256 bidtxid) std::string AuctionPost(uint64_t txfee,uint256 itemhash,int64_t minbid,char *title,char *description) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Auctionpk; int64_t funds = 0; CScript opret; struct CCcontract_info *cp,C; + CPubKey mypk,Auctionpk; int64_t funds = 0; CScript opret; struct CC_info *cp,C; cp = CCinit(&C,EVAL_AUCTION); if ( txfee == 0 ) txfee = 10000; diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index ed57b2194..c93d204df 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -27,54 +27,75 @@ #include "core_io.h" #include "crosschain.h" -#define FUNCNAME IsCClibInput -#define EVALCODE EVAL_FIRSTUSER -const char *CClibCCaddr = "RGLSRDnUqTB43bYtRtNVgmwSSd1sun2te8"; -const char *CClibNormaladdr = "RVVeUg43rNcq3mZFnvZ8yqagyzqFgUnq4u"; -char CClibCChexstr[67] = { "032447d97655da079729dc024c61088ea415b22f4c15d4810ddaf2069ac6468d2f" }; -uint8_t CClibCCpriv[32] = { 0x7c, 0x0b, 0x54, 0x9b, 0x65, 0xd4, 0x89, 0x57, 0xdf, 0x05, 0xfe, 0xa2, 0x62, 0x41, 0xa9, 0x09, 0x0f, 0x2a, 0x6b, 0x11, 0x2c, 0xbe, 0xbd, 0x06, 0x31, 0x8d, 0xc0, 0xb9, 0x96, 0x76, 0x3f, 0x24 }; -#include "CCcustom.inc" -#undef FUNCNAME -#undef EVALCODE - - struct CClib_rpcinfo { char *method,*help; int32_t numrequiredargs,maxargs; // frontloaded with required - uint8_t evalcode; + uint8_t funcid; } -CClib_rpcs[] = +CClib_methods[] = { - { "info", "", 0, 0, 0x10 }, + { "faucet2_get", "", 0, 0, 'G' }, }; #define MYCCLIBNAME ((char *)"stub") char *CClib_name() { return(MYCCLIBNAME); } -bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,const CTransaction &txTo,unsigned int nIn) +std::string CClib_rawtxgen(struct CC_info *cp,uint8_t funcid,cJSON *params); + +UniValue CClib_info(struct CC_info *cp) { - uint8_t evalcode; int32_t height,from_mempool; - if ( ASSETCHAINS_CCLIB != MYCCLIBNAME ) + UniValue result(UniValue::VOBJ),a(UniValue::VARR); int32_t i; char str[2]; + result.push_back(Pair("result","success")); + result.push_back(Pair("CClib",CClib_name())); + for (i=0; iInvalid("-ac_cclib name mismatches myname"); + UniValue obj(UniValue::VOBJ); + if ( CClib_methods[i].funcid < ' ' || CClib_methods[i].funcid >= 128 ) + obj.push_back(Pair("funcid",CClib_methods[i].funcid)); + else + { + str[0] = CClib_methods[i].funcid; + str[1] = 0; + obj.push_back(Pair("funcid",str)); + } + obj.push_back(Pair("name",CClib_methods[i].method)); + obj.push_back(Pair("help",CClib_methods[i].help)); + obj.push_back(Pair("params_required",CClib_methods[i].numrequiredargs)); + obj.push_back(Pair("params_max",CClib_methods[i].maxargs)); + a.push_back(obj)); } - height = KOMODO_CONNECTING; - if ( KOMODO_CONNECTING < 0 ) // always comes back with > 0 for final confirmation - return(true); - if ( ASSETCHAINS_CC == 0 || (height & ~(1<<30)) < KOMODO_CCACTIVATE ) - return eval->Invalid("CC are disabled or not active yet"); - if ( (KOMODO_CONNECTING & (1<<30)) != 0 ) - { - from_mempool = 1; - height &= ((1<<30) - 1); - } - evalcode = cond->code[0]; - if ( evalcode >= EVAL_FIRSTUSER && evalcode <= EVAL_LASTUSER ) - { - return(true); - } - return eval->Invalid("cclib CC must have evalcode between 16 and 127"); + result.push_back(Pair("methods",a)); + return(result); +} + +UniValue CClib(struct CC_info *cp,char *method,cJSON *params) +{ + UniValue result(UniValue::VOBJ); int32_t i; std::string rawtx; + for (i=0; i > unspentOutputs; @@ -465,7 +465,7 @@ std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64 { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); uint8_t hash[32],hashdest[32]; uint64_t amount,tokens=0,funds; int32_t i; uint256 hashchain,entropy,hentropy; - CPubKey mypk; struct CCcontract_info *cp,*cpTokens,C,CTokens; + CPubKey mypk; struct CC_info *cp,*cpTokens,C,CTokens; if ( numpayments <= 0 || payment <= 0 || numpayments > CHANNELS_MAXPAYMENTS ) { @@ -509,7 +509,7 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CPubKey mypk,srcpub,destpub; uint256 txid,hashchain,gensecret,hashblock,entropy,hentropy,prevtxid,param3,tokenid; - struct CCcontract_info *cp,C; int32_t i,funcid,prevdepth,numvouts,numpayments,totalnumpayments; + struct CC_info *cp,C; int32_t i,funcid,prevdepth,numvouts,numpayments,totalnumpayments; int64_t payment,change,funds,param2; uint8_t hash[32],hashdest[32]; CTransaction channelOpenTx,prevTx; @@ -616,7 +616,7 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 std::string ChannelClose(uint64_t txfee,uint256 opentxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,srcpub,destpub; struct CCcontract_info *cp,C; + CPubKey mypk,srcpub,destpub; struct CC_info *cp,C; CTransaction channelOpenTx; uint256 hashblock,tmp_txid,prevtxid,hashchain,tokenid; int32_t numvouts,numpayments; @@ -665,7 +665,7 @@ std::string ChannelClose(uint64_t txfee,uint256 opentxid) std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; struct CCcontract_info *cp,C; int64_t funds,payment,param2; + CPubKey mypk; struct CC_info *cp,C; int64_t funds,payment,param2; int32_t i,numpayments,numvouts,param1; uint256 hashchain,hashblock,txid,prevtxid,param3,tokenid; CTransaction channelOpenTx,channelCloseTx,prevTx; @@ -735,7 +735,7 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) } UniValue ChannelsList() { - UniValue result(UniValue::VOBJ); std::vector > txids; struct CCcontract_info *cp,C; uint256 txid,hashBlock,tmp_txid,param3,tokenid; + UniValue result(UniValue::VOBJ); std::vector > txids; struct CC_info *cp,C; uint256 txid,hashBlock,tmp_txid,param3,tokenid; CTransaction tx; char myCCaddr[65],addr[65],str[256]; CPubKey mypk,srcpub,destpub; int32_t vout,numvouts,param1; int64_t nValue,param2; @@ -766,7 +766,7 @@ UniValue ChannelsList() UniValue ChannelsInfo(uint256 channeltxid) { UniValue result(UniValue::VOBJ),array(UniValue::VARR); CTransaction tx,opentx; uint256 txid,tmp_txid,hashBlock,param3,opentxid,hashchain,prevtxid,tokenid; - struct CCcontract_info *cp,C; char CCaddr[65],addr[65],str[512]; int32_t vout,numvouts,param1,numpayments; + struct CC_info *cp,C; char CCaddr[65],addr[65],str[512]; int32_t vout,numvouts,param1,numpayments; int64_t param2,payment; CPubKey srcpub,destpub,mypk; std::vector > addressIndex; std::vector txids; diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 05dad9bf6..7a10913e7 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -322,7 +322,7 @@ void dicefinish_delete(struct dicefinish_info *ptr) void *dicefinish(void *_ptr) { - std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,newblock,entropyvout,numblocks,lastheight=0,vin0_needed,i,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; uint32_t now; struct dicefinish_utxo *utxos; uint256 hashBlock,entropyused; CPubKey dicepk; CTransaction betTx,finishTx,tx; + std::vector mypk; struct CC_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,newblock,entropyvout,numblocks,lastheight=0,vin0_needed,i,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; uint32_t now; struct dicefinish_utxo *utxos; uint256 hashBlock,entropyused; CPubKey dicepk; CTransaction betTx,finishTx,tx; mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); cp = CCinit(&C,EVAL_DICE); @@ -735,7 +735,7 @@ uint256 DiceGetEntropy(CTransaction tx,uint8_t reffuncid) else return(zeroid); } -uint64_t IsDicevout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v,uint64_t refsbits,uint256 reffundingtxid) +uint64_t IsDicevout(struct CC_info *cp,const CTransaction& tx,int32_t v,uint64_t refsbits,uint256 reffundingtxid) { char destaddr[64]; uint8_t funcid; int32_t numvouts; uint64_t sbits; uint256 fundingtxid,hash,proof; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -749,7 +749,7 @@ uint64_t IsDicevout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v, return(0); } -int64_t DiceAmounts(uint64_t &inputs,uint64_t &outputs,struct CCcontract_info *cp,Eval *eval,const CTransaction &tx,uint64_t refsbits,uint256 reffundingtxid) +int64_t DiceAmounts(uint64_t &inputs,uint64_t &outputs,struct CC_info *cp,Eval *eval,const CTransaction &tx,uint64_t refsbits,uint256 reffundingtxid) { CTransaction vinTx; uint256 hashBlock; int32_t i,numvins,numvouts; uint64_t assetoshis; numvins = tx.vin.size(); @@ -834,7 +834,7 @@ bool DiceVerifyTimeout(CTransaction &betTx,int32_t timeoutblocks) return(numblocks >= timeoutblocks); } -bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx, uint32_t nIn) +bool DiceValidate(struct CC_info *cp,Eval *eval,const CTransaction &tx, uint32_t nIn) { uint256 txid,fundingtxid,vinfundingtxid,vinhentropy,vinproof,hashBlock,hash,proof,entropy; int64_t minbet,maxbet,maxodds,timeoutblocks,odds,winnings; uint64_t vinsbits,refsbits=0,sbits,amount,inputs,outputs,txfee=10000; int32_t numvins,entropyvout,numvouts,preventCCvins,preventCCvouts,i,iswin; uint8_t funcid; CScript fundingPubKey; CTransaction fundingTx,vinTx,vinofvinTx; char CCaddr[64]; numvins = tx.vin.size(); @@ -1046,7 +1046,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx, return(true); } -uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) +uint64_t AddDiceInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) { char coinaddr[64],str[65]; uint64_t threshold,sbits,nValue,totalinputs = 0; uint256 txid,hash,proof,hashBlock,fundingtxid; CTransaction tx; int32_t j,vout,n = 0; uint8_t funcid; std::vector > unspentOutputs; @@ -1095,7 +1095,7 @@ uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK return(totalinputs); } -int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CCcontract_info *cp,CPubKey dicepk,uint256 reffundingtxid, int32_t &entropytxs,bool random) +int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CC_info *cp,CPubKey dicepk,uint256 reffundingtxid, int32_t &entropytxs,bool random) { char coinaddr[64],str[65]; uint64_t sbits; int64_t nValue,sum,totalinputs = 0; uint256 hash,txid,proof,hashBlock,fundingtxid; CScript fundingPubKey; CTransaction tx,vinTx; int32_t vout,first=0,n=0,i=0,pendingbets=0; uint8_t funcid; std::vector > unspentOutputs; @@ -1215,7 +1215,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit } } -bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CCcontract_info *cp,uint64_t refsbits,CPubKey dicepk,int64_t &minbet,int64_t &maxbet,int64_t &maxodds,int64_t &timeoutblocks) +bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CC_info *cp,uint64_t refsbits,CPubKey dicepk,int64_t &minbet,int64_t &maxbet,int64_t &maxodds,int64_t &timeoutblocks) { char CCaddr[64]; uint64_t sbits=0; uint256 txid,hashBlock; CTransaction tx; std::vector > txids; @@ -1256,9 +1256,9 @@ bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CCcontrac return(false); } -struct CCcontract_info *Diceinit(CScript &fundingPubKey,uint256 reffundingtxid,struct CCcontract_info *C,char *planstr,uint64_t &txfee,CPubKey &mypk,CPubKey &dicepk,uint64_t &sbits,int64_t &minbet,int64_t &maxbet,int64_t &maxodds,int64_t &timeoutblocks) +struct CC_info *Diceinit(CScript &fundingPubKey,uint256 reffundingtxid,struct CC_info *C,char *planstr,uint64_t &txfee,CPubKey &mypk,CPubKey &dicepk,uint64_t &sbits,int64_t &minbet,int64_t &maxbet,int64_t &maxodds,int64_t &timeoutblocks) { - struct CCcontract_info *cp; int32_t cmpflag; + struct CC_info *cp; int32_t cmpflag; cp = CCinit(C,EVAL_DICE); if ( txfee == 0 ) txfee = 10000; @@ -1278,7 +1278,7 @@ struct CCcontract_info *Diceinit(CScript &fundingPubKey,uint256 reffundingtxid,s UniValue DiceInfo(uint256 diceid) { - UniValue result(UniValue::VOBJ); CPubKey dicepk; uint256 hashBlock,entropytxid; CTransaction vintx; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits,funding,entropyval; char str[67],numstr[65]; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ); CPubKey dicepk; uint256 hashBlock,entropytxid; CTransaction vintx; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits,funding,entropyval; char str[67],numstr[65]; struct CC_info *cp,C; if ( myGetTransaction(diceid,vintx,hashBlock) == 0 ) { fprintf(stderr,"cant find fundingtxid\n"); @@ -1314,7 +1314,7 @@ UniValue DiceInfo(uint256 diceid) UniValue DiceList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock; CTransaction vintx; uint64_t sbits; int64_t minbet,maxbet,maxodds,timeoutblocks; char str[65]; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CC_info *cp,C; uint256 txid,hashBlock; CTransaction vintx; uint64_t sbits; int64_t minbet,maxbet,maxodds,timeoutblocks; char str[65]; cp = CCinit(&C,EVAL_DICE); SetCCtxids(addressIndex,cp->normaladdr); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) @@ -1334,7 +1334,7 @@ UniValue DiceList() std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - uint256 zero; CScript fundingPubKey; CPubKey mypk,dicepk; int64_t a,b,c,d; uint64_t sbits; struct CCcontract_info *cp,C; + uint256 zero; CScript fundingPubKey; CPubKey mypk,dicepk; int64_t a,b,c,d; uint64_t sbits; struct CC_info *cp,C; if ( funds < 0 || minbet < 0 || maxbet < 0 || maxodds < 1 || maxodds > 9999 || timeoutblocks < 0 || timeoutblocks > 1440 ) { CCerror = "invalid parameter error"; @@ -1369,7 +1369,7 @@ std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CScript fundingPubKey,scriptPubKey; uint256 entropy,hentropy; CPubKey mypk,dicepk; uint64_t sbits; struct CCcontract_info *cp,C; int64_t minbet,maxbet,maxodds,timeoutblocks; + CScript fundingPubKey,scriptPubKey; uint256 entropy,hentropy; CPubKey mypk,dicepk; uint64_t sbits; struct CC_info *cp,C; int64_t minbet,maxbet,maxodds,timeoutblocks; if ( amount < 0 ) { CCerror = "amount must be positive"; @@ -1413,7 +1413,7 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6 std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CScript fundingPubKey; CPubKey mypk,dicepk; uint64_t sbits,entropyval,entropyval2; int64_t funding,minbet,maxbet,maxodds,timeoutblocks; uint256 entropytxid,entropytxid2,entropy,hentropy; struct CCcontract_info *cp,C; + CScript fundingPubKey; CPubKey mypk,dicepk; uint64_t sbits,entropyval,entropyval2; int64_t funding,minbet,maxbet,maxodds,timeoutblocks; uint256 entropytxid,entropytxid2,entropy,hentropy; struct CC_info *cp,C; if ( bet < 0 ) { CCerror = "bet must be positive"; @@ -1472,7 +1472,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t &entropyvout,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout,uint256 vin0txid,int32_t vin0vout) { CMutableTransaction savemtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CScript scriptPubKey,fundingPubKey; CTransaction oldbetTx,betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy,oldbettxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; int32_t oldentropyvout,retval=0,iswin=0; uint64_t entropyval,sbits; + CScript scriptPubKey,fundingPubKey; CTransaction oldbetTx,betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy,oldbettxid; CPubKey mypk,dicepk,fundingpk; struct CC_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; int32_t oldentropyvout,retval=0,iswin=0; uint64_t entropyval,sbits; entropyused = zeroid; *resultp = 0; funcid = 0; @@ -1653,7 +1653,7 @@ static uint256 dealer0_fundingtxid; void *dealer0_loop(void *_arg) { char *planstr = (char *)_arg; - 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; + 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 CC_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"); @@ -1749,7 +1749,7 @@ void *dealer0_loop(void *_arg) double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid) { static int32_t didinit; static char _planstr[64]; - CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,entropyvout,flag,win,num,loss,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks,sum=0; uint64_t sbits,refsbits; char coinaddr[64]; std::string res; uint8_t funcid; + CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CC_info *cp,C; int32_t i,entropyvout,flag,win,num,loss,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks,sum=0; uint64_t sbits,refsbits; char coinaddr[64]; std::string res; uint8_t funcid; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,refsbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { CCerror = "Diceinit error in status, is your transaction confirmed?"; diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index ca2703bff..5239b0d5b 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -31,7 +31,7 @@ bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,co char *CClib_name(); Eval* EVAL_TEST = 0; -struct CCcontract_info CCinfos[0x100]; +struct CC_info CCinfos[0x100]; extern pthread_mutex_t KOMODO_CC_mutex; bool RunCCEval(const CC *cond, const CTransaction &tx, unsigned int nIn) @@ -62,7 +62,7 @@ bool RunCCEval(const CC *cond, const CTransaction &tx, unsigned int nIn) */ bool Eval::Dispatch(const CC *cond, const CTransaction &txTo, unsigned int nIn) { - struct CCcontract_info *cp; + struct CC_info *cp; if (cond->codeLength == 0) return Invalid("empty-eval"); diff --git a/src/cc/eval.h b/src/cc/eval.h index a42bbdb2f..61fdb892d 100644 --- a/src/cc/eval.h +++ b/src/cc/eval.h @@ -286,8 +286,8 @@ typedef std::pair TxProof; uint256 GetMerkleRoot(const std::vector& vLeaves); -struct CCcontract_info *CCinit(struct CCcontract_info *cp,uint8_t evalcode); -bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector paramsNull, const CTransaction &tx, unsigned int nIn); +struct CC_info *CCinit(struct CC_info *cp,uint8_t evalcode); +bool ProcessCC(struct CC_info *cp,Eval* eval, std::vector paramsNull, const CTransaction &tx, unsigned int nIn); #endif /* CC_EVAL_H */ diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 6e59b6c1a..be3ff8a2c 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -28,7 +28,7 @@ // start of consensus code -int64_t IsFaucetvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsFaucetvout(struct CC_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -39,7 +39,7 @@ int64_t IsFaucetvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v return(0); } -bool FaucetExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool FaucetExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -77,7 +77,7 @@ bool FaucetExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction else return(true); } -bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool FaucetValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; std::vector > txids; @@ -140,7 +140,7 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx // helper functions for rpc calls in rpcwallet.cpp -int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddFaucetInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { char coinaddr[64]; int64_t threshold,nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; @@ -175,7 +175,7 @@ int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub std::string FaucetGet(uint64_t txfee) { CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,faucetpk; int64_t inputs,CCchange=0,nValue=FAUCETSIZE; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; + CPubKey mypk,faucetpk; int64_t inputs,CCchange=0,nValue=FAUCETSIZE; struct CC_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; cp = CCinit(&C,EVAL_FAUCET); if ( txfee == 0 ) txfee = 10000; @@ -216,7 +216,7 @@ std::string FaucetGet(uint64_t txfee) std::string FaucetFund(uint64_t txfee,int64_t funds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,faucetpk; CScript opret; struct CCcontract_info *cp,C; + CPubKey mypk,faucetpk; CScript opret; struct CC_info *cp,C; cp = CCinit(&C,EVAL_FAUCET); if ( txfee == 0 ) txfee = 10000; @@ -234,7 +234,7 @@ UniValue FaucetInfo() { UniValue result(UniValue::VOBJ); char numstr[64]; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey faucetpk; struct CCcontract_info *cp,C; int64_t funding; + CPubKey faucetpk; struct CC_info *cp,C; int64_t funding; result.push_back(Pair("result","success")); result.push_back(Pair("name","Faucet")); cp = CCinit(&C,EVAL_FAUCET); diff --git a/src/cc/fsm.cpp b/src/cc/fsm.cpp index 0bcc61a1b..573299665 100644 --- a/src/cc/fsm.cpp +++ b/src/cc/fsm.cpp @@ -23,7 +23,7 @@ // start of consensus code -int64_t IsFSMvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsFSMvout(struct CC_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -34,7 +34,7 @@ int64_t IsFSMvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) return(0); } -bool FSMExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool FSMExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -72,7 +72,7 @@ bool FSMExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &t else return(true); } -bool FSMValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool FSMValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; return eval->Invalid("no validation yet"); @@ -120,7 +120,7 @@ bool FSMValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, u // helper functions for rpc calls in rpcwallet.cpp -int64_t AddFSMInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddFSMInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t n = 0; @@ -158,7 +158,7 @@ std::string FSMList() std::string FSMCreate(uint64_t txfee,std::string name,std::string states) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,fsmpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; + CPubKey mypk,fsmpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CC_info *cp,C; cp = CCinit(&C,EVAL_FSM); if ( txfee == 0 ) txfee = 10000; @@ -179,7 +179,7 @@ std::string FSMCreate(uint64_t txfee,std::string name,std::string states) std::string FSMInfo(uint256 fsmtxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,fsmpk; int64_t funds = 0; CScript opret; struct CCcontract_info *cp,C; + CPubKey mypk,fsmpk; int64_t funds = 0; CScript opret; struct CC_info *cp,C; cp = CCinit(&C,EVAL_FSM); mypk = pubkey2pk(Mypubkey()); fsmpk = GetUnspendable(cp,0); diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index c64d56b80..f00b1abfd 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -320,7 +320,7 @@ uint8_t DecodeGatewaysOpRet(const CScript &scriptPubKey) return(0); } -int64_t IsGatewaysvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsGatewaysvout(struct CC_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -331,7 +331,7 @@ int64_t IsGatewaysvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t return(0); } -bool GatewaysExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool GatewaysExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -429,7 +429,7 @@ uint256 GatewaysReverseScan(uint256 &txid,int32_t height,uint256 reforacletxid,u return(zeroid); } -int32_t GatewaysCointxidExists(struct CCcontract_info *cp,uint256 cointxid) // dont forget to check mempool! +int32_t GatewaysCointxidExists(struct CC_info *cp,uint256 cointxid) // dont forget to check mempool! { char txidaddr[64]; std::string coin; int32_t numvouts; uint256 hashBlock; std::vector > addressIndex; @@ -515,7 +515,7 @@ int64_t GatewaysDepositval(CTransaction tx,CPubKey mypk) return(0); } -bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx, uint32_t nIn) +bool GatewaysValidate(struct CC_info *cp,Eval *eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks,height,claimvout; bool retval; uint8_t funcid,hash[32],M,N,taddr,prefix,prefix2; char str[65],destaddr[64],depositaddr[65],validationError[512]; @@ -683,7 +683,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & // helper functions for rpc calls in rpcwallet.cpp -int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 reftokenid,int64_t total,int32_t maxinputs) +int64_t AddGatewaysInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 reftokenid,int64_t total,int32_t maxinputs) { char coinaddr[64],destaddr[64]; int64_t threshold,nValue,price,totalinputs = 0; uint256 tokenid,txid,hashBlock; std::vector origpubkey; std::vector vopret; CTransaction vintx; int32_t j,vout,n = 0; uint8_t evalcode,funcid; std::vector > unspentOutputs; @@ -730,7 +730,7 @@ int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP return(totalinputs); } -int32_t GatewaysBindExists(struct CCcontract_info *cp,CPubKey gatewayspk,uint256 reftokenid) // dont forget to check mempool! +int32_t GatewaysBindExists(struct CC_info *cp,CPubKey gatewayspk,uint256 reftokenid) // dont forget to check mempool! { char markeraddr[64],depositaddr[64]; std::string coin; int32_t numvouts; int64_t totalsupply; uint256 tokenid,oracletxid,hashBlock; uint8_t M,N,taddr,prefix,prefix2; std::vector pubkeys; CTransaction tx; std::vector > addressIndex; @@ -757,7 +757,7 @@ int32_t GatewaysBindExists(struct CCcontract_info *cp,CPubKey gatewayspk,uint256 std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t totalsupply,uint256 oracletxid,uint8_t M,uint8_t N,std::vector pubkeys) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction oracletx; uint8_t taddr,prefix,prefix2; CPubKey mypk,gatewayspk; CScript opret; uint256 hashBlock; struct CCcontract_info *cp,C; std::string name,description,format; int32_t i,numvouts; int64_t fullsupply; char destaddr[64],coinaddr[64],str[65],*fstr; + CTransaction oracletx; uint8_t taddr,prefix,prefix2; CPubKey mypk,gatewayspk; CScript opret; uint256 hashBlock; struct CC_info *cp,C; std::string name,description,format; int32_t i,numvouts; int64_t fullsupply; char destaddr[64],coinaddr[64],str[65],*fstr; cp = CCinit(&C,EVAL_GATEWAYS); if ( strcmp((char *)"KMD",coin.c_str()) == 0 ) { @@ -844,7 +844,7 @@ std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std:: { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CTransaction bindtx; CPubKey mypk,gatewayspk; uint256 oracletxid,merkleroot,mhash,hashBlock,tokenid,txid; - int64_t totalsupply; int32_t i,m,n,numvouts; uint8_t M,N,taddr,prefix,prefix2; std::string coin; struct CCcontract_info *cp,C; + int64_t totalsupply; int32_t i,m,n,numvouts; uint8_t M,N,taddr,prefix,prefix2; std::string coin; struct CC_info *cp,C; std::vector pubkeys,publishers; std::vectortxids; char str[67],depositaddr[64],txidaddr[64]; cp = CCinit(&C,EVAL_GATEWAYS); @@ -910,7 +910,7 @@ std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std:: std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,uint256 deposittxid,CPubKey destpub,int64_t amount) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction tx; CPubKey mypk,gatewayspk,tmpdestpub; struct CCcontract_info *cp,C; uint8_t M,N,taddr,prefix,prefix2; + CTransaction tx; CPubKey mypk,gatewayspk,tmpdestpub; struct CC_info *cp,C; uint8_t M,N,taddr,prefix,prefix2; std::string coin, deposithex; std::vector msigpubkeys,publishers; int64_t totalsupply,depositamount,tmpamount,inputs,CCchange=0; int32_t numvouts,claimvout,height; std::vector proof; uint256 hashBlock,tokenid,oracletxid,tmptxid,cointxid; char str[65],depositaddr[64],coinaddr[64],destaddr[64]; std::vector txids; @@ -985,8 +985,8 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin CPubKey mypk, gatewayspk; uint256 tokenid,hashBlock,oracletxid; int32_t numvouts; int64_t totalsupply,inputs,CCchange=0; uint8_t M,N,taddr,prefix,prefix2; std::string coin; std::vector msigpubkeys; char depositaddr[64],str[65],coinaddr[64]; - struct CCcontract_info *cpGateways, gatewaysC; - struct CCcontract_info *cpTokens, tokensC; + struct CC_info *cpGateways, gatewaysC; + struct CC_info *cpTokens, tokensC; cpGateways = CCinit(&gatewaysC, EVAL_GATEWAYS); cpTokens = CCinit(&tokensC, EVAL_TOKENS); @@ -1049,7 +1049,7 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin std::string GatewaysPartialSign(uint64_t txfee,uint256 txid,std::string refcoin, std::string hex) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,txidaddrpk,signerpk; struct CCcontract_info *cp,C; CTransaction tx; + CPubKey mypk,txidaddrpk,signerpk; struct CC_info *cp,C; CTransaction tx; std::vector > unspentOutputs; char txidaddr[65]; int32_t maxK,K=0; uint256 tmptxid,parttxid,hashBlock; cp = CCinit(&C,EVAL_GATEWAYS); @@ -1089,7 +1089,7 @@ std::string GatewaysPartialSign(uint64_t txfee,uint256 txid,std::string refcoin, std::string GatewaysCompleteSigning(uint64_t txfee,uint256 withdrawtxid,std::string refcoin,std::string hex) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,gatewayspk; struct CCcontract_info *cp,C; char txidaddr[65]; + CPubKey mypk,gatewayspk; struct CC_info *cp,C; char txidaddr[65]; cp = CCinit(&C,EVAL_GATEWAYS); mypk = pubkey2pk(Mypubkey()); gatewayspk = GetUnspendable(cp,0); @@ -1104,7 +1104,7 @@ std::string GatewaysCompleteSigning(uint64_t txfee,uint256 withdrawtxid,std::str std::string GatewaysMarkDone(uint64_t txfee,uint256 completetxid,std::string refcoin) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,gatewayspk; struct CCcontract_info *cp,C; char txidaddr[65]; + CPubKey mypk,gatewayspk; struct CC_info *cp,C; char txidaddr[65]; cp = CCinit(&C,EVAL_GATEWAYS); mypk = pubkey2pk(Mypubkey()); if ( txfee == 0 ) @@ -1118,7 +1118,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) UniValue result(UniValue::VOBJ),pending(UniValue::VARR); CTransaction tx; std::string tmprefcoin; CPubKey mypk,gatewayspk,withdrawpub; std::vector msigpubkeys; uint256 hashBlock,tokenid,txid,oracletxid; uint8_t M,N,taddr,prefix,prefix2; char depositaddr[64],coinaddr[64],destaddr[64],str[65],withaddr[64],numstr[32],txidaddr[64],cctxidaddr[64],signeraddr[64]; - int32_t i,n,numvouts,vout,queueflag; int64_t totalsupply,amount,nValue; struct CCcontract_info *cp,C; + int32_t i,n,numvouts,vout,queueflag; int64_t totalsupply,amount,nValue; struct CC_info *cp,C; std::vector > unspentOutputs; cp = CCinit(&C,EVAL_GATEWAYS); @@ -1186,7 +1186,7 @@ UniValue GatewaysProcessedWithdraws(uint256 bindtxid,std::string refcoin) UniValue result(UniValue::VOBJ),processed(UniValue::VARR); CTransaction tx; std::string tmprefcoin,hex; CPubKey mypk,gatewayspk,withdrawpub; std::vector msigpubkeys; uint256 withdrawtxid,hashBlock,txid,tokenid,oracletxid; uint8_t M,N,taddr,prefix,prefix2; char depositaddr[64],coinaddr[64],str[65],numstr[32],txidaddr[64],cctxidaddr[64],withaddr[64]; - int32_t i,n,numvouts,vout,queueflag; int64_t totalsupply,nValue,amount; struct CCcontract_info *cp,C; + int32_t i,n,numvouts,vout,queueflag; int64_t totalsupply,nValue,amount; struct CC_info *cp,C; std::vector > unspentOutputs; cp = CCinit(&C,EVAL_GATEWAYS); @@ -1278,7 +1278,7 @@ UniValue GatewaysMultisig(char *cctxidaddr) UniValue GatewaysList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock,oracletxid,tokenid; CTransaction vintx; std::string coin; int64_t totalsupply; char str[65],depositaddr[64]; uint8_t M,N,taddr,prefix,prefix2; std::vector pubkeys; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CC_info *cp,C; uint256 txid,hashBlock,oracletxid,tokenid; CTransaction vintx; std::string coin; int64_t totalsupply; char str[65],depositaddr[64]; uint8_t M,N,taddr,prefix,prefix2; std::vector pubkeys; cp = CCinit(&C,EVAL_GATEWAYS); SetCCtxids(addressIndex,cp->unspendableCCaddr); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) @@ -1298,7 +1298,7 @@ UniValue GatewaysList() UniValue GatewaysInfo(uint256 bindtxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::string coin; char str[67],numstr[65],depositaddr[64],gatewaysassets[64]; uint8_t M,N; std::vector pubkeys; uint8_t taddr,prefix,prefix2; uint256 tokenid,oracletxid,hashBlock; CTransaction tx; CPubKey Gatewayspk; struct CCcontract_info *cp,C; int32_t i; int64_t totalsupply,remaining; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::string coin; char str[67],numstr[65],depositaddr[64],gatewaysassets[64]; uint8_t M,N; std::vector pubkeys; uint8_t taddr,prefix,prefix2; uint256 tokenid,oracletxid,hashBlock; CTransaction tx; CPubKey Gatewayspk; struct CC_info *cp,C; int32_t i; int64_t totalsupply,remaining; result.push_back(Pair("result","success")); result.push_back(Pair("name","Gateways")); cp = CCinit(&C,EVAL_GATEWAYS); diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 4a78c69ac..499fb598d 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -34,7 +34,7 @@ class TokenHelper; // Plan validation runner, it may be called twice - for coins and tokens // (sadly we cannot have yet 'templatized' lambdas, if we could we could capture all these params inside HeirValidation()...) -template bool RunValidationPlans(uint8_t funcId, struct CCcontract_info* cp, Eval* eval, const CTransaction& tx, uint256 latestTxid, CScript fundingOpretScript, uint8_t hasHeirSpendingBegun) +template bool RunValidationPlans(uint8_t funcId, struct CC_info* cp, Eval* eval, const CTransaction& tx, uint256 latestTxid, CScript fundingOpretScript, uint8_t hasHeirSpendingBegun) { int32_t numvins = tx.vin.size(); int32_t numvouts = tx.vout.size(); @@ -104,14 +104,14 @@ template bool RunValidationPlans(uint8_t funcId, struct CCcont /** * Tx validation entry function */ -bool HeirValidate(struct CCcontract_info* cpHeir, Eval* eval, const CTransaction& tx, uint32_t nIn) +bool HeirValidate(struct CC_info* cpHeir, Eval* eval, const CTransaction& tx, uint32_t nIn) { int32_t numvins = tx.vin.size(); int32_t numvouts = tx.vout.size(); //int32_t preventCCvins = -1; //int32_t preventCCvouts = -1; - struct CCcontract_info *cpTokens, tokensC; + struct CC_info *cpTokens, tokensC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); if (numvouts < 1) @@ -237,7 +237,7 @@ bool HeirValidate(struct CCcontract_info* cpHeir, Eval* eval, const CTransaction * Checks if vout is to cryptocondition address * @return vout value in satoshis */ -template int64_t IsHeirFundingVout(struct CCcontract_info* cp, const CTransaction& tx, int32_t voutIndex, CPubKey ownerPubkey, CPubKey heirPubkey) +template int64_t IsHeirFundingVout(struct CC_info* cp, const CTransaction& tx, int32_t voutIndex, CPubKey ownerPubkey, CPubKey heirPubkey) { char destaddr[65], heirFundingAddr[65]; @@ -437,7 +437,7 @@ uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &toke // TODO: correct cc addr: std::vector> unspentOutputs; - struct CCcontract_info *cp, C; + struct CC_info *cp, C; cp = CCinit(&C, EVAL_HEIR); char coinaddr[64]; GetCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); // get the address of cryptocondition '1 of 2 pubkeys' @@ -507,7 +507,7 @@ uint256 FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &token } // add inputs of 1 of 2 cc address -template int64_t Add1of2AddressInputs(struct CCcontract_info* cp, uint256 fundingtxid, CMutableTransaction& mtx, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t total, int32_t maxinputs) +template int64_t Add1of2AddressInputs(struct CC_info* cp, uint256 fundingtxid, CMutableTransaction& mtx, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t total, int32_t maxinputs) { // TODO: add threshold check int64_t nValue, voutValue, totalinputs = 0; @@ -566,7 +566,7 @@ template int64_t Add1of2AddressInputs(struct CCcontract_info* cp, /** * enumerate all tx's sending to CCHeir 1of2address and calc total lifetime funds */ -template int64_t LifetimeHeirContractFunds(struct CCcontract_info* cp, uint256 fundingtxid, CPubKey ownerPubkey, CPubKey heirPubkey) +template int64_t LifetimeHeirContractFunds(struct CC_info* cp, uint256 fundingtxid, CPubKey ownerPubkey, CPubKey heirPubkey) { char coinaddr[64]; Helper::GetCoinsOrTokensCCaddress1of2(coinaddr, ownerPubkey, heirPubkey); // get the address of cryptocondition '1 of 2 pubkeys' @@ -619,7 +619,7 @@ template UniValue HeirFund(uint64_t txfee, int64_t amount, std { UniValue result(UniValue::VOBJ); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - struct CCcontract_info *cp, C; + struct CC_info *cp, C; cp = CCinit(&C, Helper::getMyEval()); if (txfee == 0) @@ -707,7 +707,7 @@ template UniValue _HeirAdd(uint256 fundingtxid, uint64_t txfee, i UniValue result(UniValue::VOBJ); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); int64_t inputs, CCchange = 0; - struct CCcontract_info *cp, C; + struct CC_info *cp, C; std::string rawhex; cp = CCinit(&C, Helper::getMyEval()); // for tokens shoud be EVAL_TOKENS to sign it correctly! @@ -825,7 +825,7 @@ template UniValue _HeirClaim(uint256 fundingtxid, uint64_t txfe CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CPubKey myPubkey; int64_t inputs, change = 0; - struct CCcontract_info *cp, C; + struct CC_info *cp, C; cp = CCinit(&C, EVAL_HEIR); if (txfee == 0) @@ -1006,7 +1006,7 @@ UniValue HeirInfo(uint256 fundingtxid) return result; }*/ - struct CCcontract_info *cp, C; + struct CC_info *cp, C; cp = CCinit(&C, EVAL_HEIR); uint8_t hasHeirSpendingBegun = 0; @@ -1123,7 +1123,7 @@ UniValue HeirInfo(uint256 fundingtxid) * @return list of heir plan handles (fundingtxid) */ -template void _HeirList(struct CCcontract_info *cp, UniValue &result) +template void _HeirList(struct CC_info *cp, UniValue &result) { std::vector> unspentOutputs; char coinaddr[64]; @@ -1174,7 +1174,7 @@ UniValue HeirList() UniValue result(UniValue::VOBJ); result.push_back(Pair("result", "success")); - struct CCcontract_info *cpHeir, *cpTokens, heirC, tokenC; // NOTE we must use a separate 'C' structure for each CCinit! + struct CC_info *cpHeir, *cpTokens, heirC, tokenC; // NOTE we must use a separate 'C' structure for each CCinit! cpHeir = CCinit(&heirC, EVAL_HEIR); cpTokens = CCinit(&tokenC, EVAL_TOKENS); diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index d66777933..39f6855ac 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -47,11 +47,11 @@ public: return CTxOut(amount, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG); } */ static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { - struct CCcontract_info *cpHeir, heirC; + struct CC_info *cpHeir, heirC; cpHeir = CCinit(&heirC, EVAL_HEIR); return GetCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); } - static void CCaddrCoinsOrTokens1of2set(struct CCcontract_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { + static void CCaddrCoinsOrTokens1of2set(struct CC_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { CCaddr1of2set(cp, ownerPubkey, heirPubkey, coinaddr); } }; @@ -61,7 +61,7 @@ class TokenHelper { public: static uint8_t getMyEval() { return EVAL_TOKENS; } static int64_t addOwnerInputs(uint256 tokenid, CMutableTransaction& mtx, CPubKey ownerPubkey, int64_t total, int32_t maxinputs) { - struct CCcontract_info *cpHeir, heirC; + struct CC_info *cpHeir, heirC; cpHeir = CCinit(&heirC, EVAL_TOKENS); return AddTokenCCInputs(cpHeir, mtx, ownerPubkey, tokenid, total, maxinputs); } @@ -89,12 +89,12 @@ public: return MakeCC1vout(EVAL_TOKENS, amount, myPubkey); // yes EVAL_TOKENS } */ static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { - struct CCcontract_info *cpHeir, heirC; + struct CC_info *cpHeir, heirC; cpHeir = CCinit(&heirC, EVAL_HEIR); return GetTokensCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); } - static void CCaddrCoinsOrTokens1of2set(struct CCcontract_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { + static void CCaddrCoinsOrTokens1of2set(struct CC_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { CCaddrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); } @@ -628,4 +628,4 @@ public: }; -#endif \ No newline at end of file +#endif diff --git a/src/cc/lotto.cpp b/src/cc/lotto.cpp index e9c263ff1..c52c9a072 100644 --- a/src/cc/lotto.cpp +++ b/src/cc/lotto.cpp @@ -63,7 +63,7 @@ It is possible to have a jackpot but miss out on it due to not claiming it. To m // start of consensus code -int64_t IsLottovout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsLottovout(struct CC_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -74,7 +74,7 @@ int64_t IsLottovout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) return(0); } -bool LottoExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool LottoExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -112,7 +112,7 @@ bool LottoExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction else return(true); } -bool LottoValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool LottoValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; return eval->Invalid("no validation yet"); @@ -160,7 +160,7 @@ bool LottoValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, // helper functions for rpc calls in rpcwallet.cpp -int64_t AddLottoInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddLottoInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t n = 0; @@ -203,7 +203,7 @@ uint8_t DecodeLottoFundingOpRet(const CScript &scriptPubKey,uint64_t &sbits,int3 return(0); } -int64_t LottoPlanFunds(uint64_t refsbits,struct CCcontract_info *cp,CPubKey pk,uint256 reffundingtxid) +int64_t LottoPlanFunds(uint64_t refsbits,struct CC_info *cp,CPubKey pk,uint256 reffundingtxid) { char coinaddr[64]; uint64_t sbits; int64_t nValue,lockedfunds; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t vout; uint8_t funcid; std::vector > unspentOutputs; @@ -232,7 +232,7 @@ int64_t LottoPlanFunds(uint64_t refsbits,struct CCcontract_info *cp,CPubKey pk,u UniValue LottoInfo(uint256 lottoid) { - UniValue result(UniValue::VOBJ); uint256 hashBlock,hentropy; CTransaction vintx; uint64_t lockedfunds,sbits; int32_t ticketsize,odds,firstheight,period; CPubKey lottopk; struct CCcontract_info *cp,C; char str[67],numstr[65]; + UniValue result(UniValue::VOBJ); uint256 hashBlock,hentropy; CTransaction vintx; uint64_t lockedfunds,sbits; int32_t ticketsize,odds,firstheight,period; CPubKey lottopk; struct CC_info *cp,C; char str[67],numstr[65]; if ( GetTransaction(lottoid,vintx,hashBlock,false) == 0 ) { fprintf(stderr,"cant find lottoid\n"); @@ -264,7 +264,7 @@ UniValue LottoInfo(uint256 lottoid) UniValue LottoList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock,hentropy; CTransaction vintx; uint64_t sbits; int32_t ticketsize,odds,firstheight,period; char str[65]; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CC_info *cp,C; uint256 txid,hashBlock,hentropy; CTransaction vintx; uint64_t sbits; int32_t ticketsize,odds,firstheight,period; char str[65]; cp = CCinit(&C,EVAL_LOTTO); SetCCtxids(addressIndex,cp->normaladdr); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) @@ -284,7 +284,7 @@ UniValue LottoList() std::string LottoCreate(uint64_t txfee,char *planstr,int64_t funding,int32_t ticketsize,int32_t odds,int32_t firstheight,int32_t period) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - uint256 entropy,hentropy; CPubKey mypk,lottopk; uint64_t sbits; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; + uint256 entropy,hentropy; CPubKey mypk,lottopk; uint64_t sbits; int64_t inputs,CCchange=0,nValue=COIN; struct CC_info *cp,C; cp = CCinit(&C,EVAL_LOTTO); if ( txfee == 0 ) txfee = 10000; @@ -303,7 +303,7 @@ std::string LottoCreate(uint64_t txfee,char *planstr,int64_t funding,int32_t tic std::string LottoTicket(uint64_t txfee,uint256 lottoid,int64_t numtickets) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,lottopk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; + CPubKey mypk,lottopk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CC_info *cp,C; cp = CCinit(&C,EVAL_LOTTO); if ( txfee == 0 ) txfee = 10000; @@ -324,7 +324,7 @@ std::string LottoTicket(uint64_t txfee,uint256 lottoid,int64_t numtickets) std::string LottoWinner(uint64_t txfee) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,lottopk; int64_t winnings = 0; CScript opret; struct CCcontract_info *cp,C; + CPubKey mypk,lottopk; int64_t winnings = 0; CScript opret; struct CC_info *cp,C; cp = CCinit(&C,EVAL_LOTTO); if ( txfee == 0 ) txfee = 10000; diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 795b95186..692c496b3 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -47,7 +47,7 @@ // start of consensus code -int64_t IsMarmaravout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsMarmaravout(struct CC_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -188,7 +188,7 @@ int32_t MarmaraGetbatontxid(std::vector &creditloop,uint256 &batontxid, CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) { - CTxOut ccvout; struct CCcontract_info *cp,C; CPubKey Marmarapk; + CTxOut ccvout; struct CC_info *cp,C; CPubKey Marmarapk; cp = CCinit(&C,EVAL_MARMARA); Marmarapk = GetUnspendable(cp,0); if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) @@ -212,7 +212,7 @@ CScript MarmaraCoinbaseOpret(uint8_t funcid,int32_t height,CPubKey pk) int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { - struct CCcontract_info *cp,C; CPubKey Marmarapk,pk; int32_t ht,unlockht; CTxOut ccvout; + struct CC_info *cp,C; CPubKey Marmarapk,pk; int32_t ht,unlockht; CTxOut ccvout; cp = CCinit(&C,EVAL_MARMARA); Marmarapk = GetUnspendable(cp,0); if ( 0 ) @@ -255,7 +255,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) return(-1); } -bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool MarmaraValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { std::vector vopret; CTransaction vinTx; uint256 hashBlock; int32_t numvins,numvouts,i,ht,unlockht,vht,vunlockht; uint8_t funcid,vfuncid,*script; CPubKey pk,vpk; if ( ASSETCHAINS_MARMARA == 0 ) @@ -326,7 +326,7 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t // helper functions for rpc calls in rpcwallet.cpp -int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx,int32_t firstheight,CPubKey poolpk,int32_t maxinputs) +int64_t AddMarmaraCoinbases(struct CC_info *cp,CMutableTransaction &mtx,int32_t firstheight,CPubKey poolpk,int32_t maxinputs) { char coinaddr[64]; CPubKey Marmarapk,pk; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction vintx; int32_t unlockht,ht,vout,unlocks,n = 0; std::vector > unspentOutputs; @@ -408,7 +408,7 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) { CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk,pk; int32_t unlockht,refunlockht,vout,ht,numvouts; int64_t nValue,val,inputsum=0,threshold,remains,change = 0; std::string rawtx,errorstr; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; uint8_t funcid; + UniValue result(UniValue::VOBJ); struct CC_info *cp,C; CPubKey Marmarapk,mypk,pk; int32_t unlockht,refunlockht,vout,ht,numvouts; int64_t nValue,val,inputsum=0,threshold,remains,change = 0; std::string rawtx,errorstr; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; uint8_t funcid; if ( txfee == 0 ) txfee = 10000; if ( (height & 1) != 0 ) @@ -490,7 +490,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures,height; int64_t amount,refamount,remaining,inputsum,change; CPubKey Marmarapk,mypk,pk; std::string currency,refcurrency,rawtx; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2],txidaddr[64]; std::vector pubkeys; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures,height; int64_t amount,refamount,remaining,inputsum,change; CPubKey Marmarapk,mypk,pk; std::string currency,refcurrency,rawtx; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2],txidaddr[64]; std::vector pubkeys; struct CC_info *cp,C; if ( txfee == 0 ) txfee = 10000; cp = CCinit(&C,EVAL_MARMARA); @@ -607,7 +607,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) return(result); } -int32_t MarmaraGetCreditloops(int64_t &totalamount,std::vector &issuances,int64_t &totalclosed,std::vector &closed,struct CCcontract_info *cp,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,CPubKey refpk,std::string refcurrency) +int32_t MarmaraGetCreditloops(int64_t &totalamount,std::vector &issuances,int64_t &totalclosed,std::vector &closed,struct CC_info *cp,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,CPubKey refpk,std::string refcurrency) { char coinaddr[64]; CPubKey Marmarapk,senderpk; int64_t amount; uint256 createtxid,txid,hashBlock; CTransaction tx; int32_t numvouts,vout,matures,n=0; std::string currency; std::vector > unspentOutputs; @@ -643,7 +643,7 @@ int32_t MarmaraGetCreditloops(int64_t &totalamount,std::vector &issuanc UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 batontxid,bool automaticflag) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); CPubKey mypk; struct CCcontract_info *cp,C; std::string rawtx; char *errorstr=0; uint256 createtxid; int64_t batonamount; int32_t needbaton = 0; + UniValue result(UniValue::VOBJ); CPubKey mypk; struct CC_info *cp,C; std::string rawtx; char *errorstr=0; uint256 createtxid; int64_t batonamount; int32_t needbaton = 0; cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; @@ -700,7 +700,7 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t amount,std::string currency,int32_t matures,uint256 approvaltxid,uint256 batontxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); CPubKey mypk,Marmarapk; struct CCcontract_info *cp,C; std::string rawtx; uint256 createtxid; char *errorstr=0; + UniValue result(UniValue::VOBJ); CPubKey mypk,Marmarapk; struct CC_info *cp,C; std::string rawtx; uint256 createtxid; char *errorstr=0; cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; @@ -757,7 +757,7 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a UniValue MarmaraCreditloop(uint256 txid) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey pk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2]; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey pk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2]; struct CC_info *cp,C; cp = CCinit(&C,EVAL_MARMARA); if ( (n= MarmaraGetbatontxid(creditloop,batontxid,txid)) > 0 ) { @@ -911,7 +911,7 @@ UniValue MarmaraCreditloop(uint256 txid) UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr) // [[pk0, shares0], [pk1, shares1], ...] { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ),a(UniValue::VARR); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk,poolpk; int64_t payout,poolfee=0,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk,poolpk; int64_t payout,poolfee=0,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CC_info *cp,C; poolpk = pubkey2pk(Mypubkey()); if ( txfee == 0 ) txfee = 10000; @@ -1000,7 +1000,7 @@ UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_ { CMutableTransaction mtx; std::vector pubkeys; UniValue result(UniValue::VOBJ),a(UniValue::VARR),b(UniValue::VARR); int32_t i,n,matches; int64_t totalclosed=0,totalamount=0; std::vector issuances,closed; char coinaddr[64]; - CPubKey Marmarapk; struct CCcontract_info *cp,C; + CPubKey Marmarapk; struct CC_info *cp,C; cp = CCinit(&C,EVAL_MARMARA); Marmarapk = GetUnspendable(cp,0); result.push_back(Pair("result","success")); diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 66c0e1b9a..a64f65a18 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -163,7 +163,7 @@ uint8_t DecodeOraclesData(const CScript &scriptPubKey,uint256 &oracletxid,uint25 return(0); } -CPubKey OracleBatonPk(char *batonaddr,struct CCcontract_info *cp) +CPubKey OracleBatonPk(char *batonaddr,struct CC_info *cp) { static secp256k1_context *ctx; size_t clen = CPubKey::PUBLIC_KEY_SIZE; @@ -256,7 +256,7 @@ static uint256 myIs_baton_spentinmempool(uint256 batontxid,int32_t batonvout) return(batontxid); } -uint256 OracleBatonUtxo(uint64_t txfee,struct CCcontract_info *cp,uint256 reforacletxid,char *batonaddr,CPubKey publisher,std::vector &dataarg) +uint256 OracleBatonUtxo(uint64_t txfee,struct CC_info *cp,uint256 reforacletxid,char *batonaddr,CPubKey publisher,std::vector &dataarg) { uint256 txid,oracletxid,hashBlock,btxid,batontxid = zeroid; int64_t dfee; int32_t dheight=0,vout,height,numvouts; CTransaction tx; CPubKey pk; uint8_t *ptr; std::vector vopret,data; std::vector > unspentOutputs; @@ -302,7 +302,7 @@ uint256 OracleBatonUtxo(uint64_t txfee,struct CCcontract_info *cp,uint256 refora uint256 OraclesBatontxid(uint256 reforacletxid,CPubKey refpk) { std::vector > unspentOutputs; - CTransaction regtx; uint256 hash,txid,batontxid,oracletxid; CPubKey pk; int32_t numvouts,height,maxheight=0; int64_t datafee; char markeraddr[64],batonaddr[64]; std::vector data; struct CCcontract_info *cp,C; + CTransaction regtx; uint256 hash,txid,batontxid,oracletxid; CPubKey pk; int32_t numvouts,height,maxheight=0; int64_t datafee; char markeraddr[64],batonaddr[64]; std::vector data; struct CC_info *cp,C; batontxid = zeroid; cp = CCinit(&C,EVAL_ORACLES); CCtxidaddr(markeraddr,reforacletxid); @@ -528,7 +528,7 @@ int32_t oracleprice_add(std::vector &publishers,CPubKey int64_t OraclePrice(int32_t height,uint256 reforacletxid,char *markeraddr,char *format) { std::vector > unspentOutputs; - CTransaction regtx; uint256 hash,txid,oracletxid,batontxid; CPubKey pk; int32_t i,ht,maxheight=0; int64_t datafee,price; char batonaddr[64]; std::vector data; struct CCcontract_info *cp,C; std::vector publishers; std::vector prices; + CTransaction regtx; uint256 hash,txid,oracletxid,batontxid; CPubKey pk; int32_t i,ht,maxheight=0; int64_t datafee,price; char batonaddr[64]; std::vector data; struct CC_info *cp,C; std::vector publishers; std::vector prices; if ( format[0] != 'L' ) return(0); cp = CCinit(&C,EVAL_ORACLES); @@ -564,7 +564,7 @@ int64_t OraclePrice(int32_t height,uint256 reforacletxid,char *markeraddr,char * return(0); } -int64_t IsOraclesvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsOraclesvout(struct CC_info *cp,const CTransaction& tx,int32_t v) { //char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -575,7 +575,7 @@ int64_t IsOraclesvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t return(0); } -bool OraclesDataValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,uint256 oracletxid,CPubKey publisher,int64_t datafee) +bool OraclesDataValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx,uint256 oracletxid,CPubKey publisher,int64_t datafee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; CScript scriptPubKey; @@ -633,7 +633,7 @@ bool OraclesDataValidate(struct CCcontract_info *cp,Eval* eval,const CTransactio else return(true); } -bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool OraclesValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { uint256 txid,oracletxid,batontxid; uint64_t txfee=10000; int32_t numvins,numvouts,preventCCvins,preventCCvouts; uint8_t *script; std::vector vopret,data; CScript scriptPubKey; CPubKey publisher; numvins = tx.vin.size(); @@ -703,7 +703,7 @@ bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t // helper functions for rpc calls in rpcwallet.cpp -int64_t AddOracleInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,uint256 oracletxid,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddOracleInputs(struct CC_info *cp,CMutableTransaction &mtx,uint256 oracletxid,CPubKey pk,int64_t total,int32_t maxinputs) { char coinaddr[64],funcid; int64_t nValue,price,totalinputs = 0; uint256 tmporacletxid,tmpbatontxid,txid,hashBlock; std::vector origpubkey,data; CTransaction vintx; int32_t numvouts,vout,n = 0; std::vector > unspentOutputs; CPubKey tmppk; int64_t tmpnum; @@ -741,7 +741,7 @@ int64_t AddOracleInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,uint return(totalinputs); } -int64_t LifetimeOraclesFunds(struct CCcontract_info *cp,uint256 oracletxid,CPubKey publisher) +int64_t LifetimeOraclesFunds(struct CC_info *cp,uint256 oracletxid,CPubKey publisher) { char coinaddr[64]; CPubKey pk; int64_t total=0,num; uint256 txid,hashBlock,subtxid; CTransaction subtx; std::vector > addressIndex; @@ -765,7 +765,7 @@ int64_t LifetimeOraclesFunds(struct CCcontract_info *cp,uint256 oracletxid,CPubK std::string OracleCreate(int64_t txfee,std::string name,std::string description,std::string format) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Oraclespk; struct CCcontract_info *cp,C; char fmt; + CPubKey mypk,Oraclespk; struct CC_info *cp,C; char fmt; cp = CCinit(&C,EVAL_ORACLES); if ( name.size() > 32 || description.size() > 4096 || format.size() > 4096 ) @@ -805,7 +805,7 @@ std::string OracleCreate(int64_t txfee,std::string name,std::string description, std::string OracleRegister(int64_t txfee,uint256 oracletxid,int64_t datafee) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,markerpubkey,batonpk; struct CCcontract_info *cp,C; char markeraddr[64],batonaddr[64]; + CPubKey mypk,markerpubkey,batonpk; struct CC_info *cp,C; char markeraddr[64],batonaddr[64]; cp = CCinit(&C,EVAL_ORACLES); if ( txfee == 0 ) txfee = 10000; @@ -832,7 +832,7 @@ std::string OracleRegister(int64_t txfee,uint256 oracletxid,int64_t datafee) std::string OracleSubscribe(int64_t txfee,uint256 oracletxid,CPubKey publisher,int64_t amount) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,markerpubkey; struct CCcontract_info *cp,C; char markeraddr[64]; + CPubKey mypk,markerpubkey; struct CC_info *cp,C; char markeraddr[64]; cp = CCinit(&C,EVAL_ORACLES); if ( txfee == 0 ) txfee = 10000; @@ -852,7 +852,7 @@ std::string OracleSubscribe(int64_t txfee,uint256 oracletxid,CPubKey publisher,i std::string OracleData(int64_t txfee,uint256 oracletxid,std::vector data) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CScript pubKey; CPubKey mypk,batonpk; int64_t offset,datafee,inputs,CCchange = 0; struct CCcontract_info *cp,C; uint256 batontxid,hashBlock; + CScript pubKey; CPubKey mypk,batonpk; int64_t offset,datafee,inputs,CCchange = 0; struct CC_info *cp,C; uint256 batontxid,hashBlock; char coinaddr[64],batonaddr[64]; std::vector prevdata; CTransaction tx; std::string name,description,format; int32_t len,numvouts; cp = CCinit(&C,EVAL_ORACLES); @@ -971,7 +971,7 @@ UniValue OracleInfo(uint256 origtxid) UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector > unspentOutputs; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction regtx,tx; std::string name,description,format; uint256 hashBlock,txid,oracletxid,batontxid; CPubKey pk; struct CCcontract_info *cp,C; int64_t datafee,funding; char str[67],markeraddr[64],numstr[64],batonaddr[64]; std::vector data; + CTransaction regtx,tx; std::string name,description,format; uint256 hashBlock,txid,oracletxid,batontxid; CPubKey pk; struct CC_info *cp,C; int64_t datafee,funding; char str[67],markeraddr[64],numstr[64],batonaddr[64]; std::vector data; cp = CCinit(&C,EVAL_ORACLES); CCtxidaddr(markeraddr,origtxid); if ( GetTransaction(origtxid,tx,hashBlock,false) == 0 ) @@ -1025,7 +1025,7 @@ UniValue OracleInfo(uint256 origtxid) UniValue OraclesList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock; CTransaction createtx; std::string name,description,format; char str[65]; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CC_info *cp,C; uint256 txid,hashBlock; CTransaction createtx; std::string name,description,format; char str[65]; cp = CCinit(&C,EVAL_ORACLES); SetCCtxids(addressIndex,cp->normaladdr); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 859a5ba3f..c25842ea3 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -23,7 +23,7 @@ // start of consensus code -int64_t IsPaymentsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsPaymentsvout(struct CC_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -34,7 +34,7 @@ int64_t IsPaymentsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t return(0); } -bool PaymentsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool PaymentsExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -72,7 +72,7 @@ bool PaymentsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransacti else return(true); } -bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool PaymentsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; return eval->Invalid("no validation yet"); @@ -113,7 +113,7 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & // helper functions for rpc calls in rpcwallet.cpp -int64_t AddPaymentsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddPaymentsInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; @@ -145,7 +145,7 @@ int64_t AddPaymentsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP std::string PaymentsGet(uint64_t txfee,int64_t nValue) { CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Paymentspk; int64_t inputs,CCchange=0; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; + CPubKey mypk,Paymentspk; int64_t inputs,CCchange=0; struct CC_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; cp = CCinit(&C,EVAL_PAYMENTS); if ( txfee == 0 ) txfee = 10000; @@ -186,7 +186,7 @@ std::string PaymentsGet(uint64_t txfee,int64_t nValue) std::string PaymentsFund(uint64_t txfee,int64_t funds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Paymentspk; CScript opret; struct CCcontract_info *cp,C; + CPubKey mypk,Paymentspk; CScript opret; struct CC_info *cp,C; cp = CCinit(&C,EVAL_PAYMENTS); if ( txfee == 0 ) txfee = 10000; @@ -204,7 +204,7 @@ UniValue PaymentsInfo() { UniValue result(UniValue::VOBJ); char numstr[64]; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey Paymentspk; struct CCcontract_info *cp,C; int64_t funding; + CPubKey Paymentspk; struct CC_info *cp,C; int64_t funding; result.push_back(Pair("result","success")); result.push_back(Pair("name","Payments")); cp = CCinit(&C,EVAL_PAYMENTS); diff --git a/src/cc/pegs.cpp b/src/cc/pegs.cpp index e2893bec8..d137778a6 100644 --- a/src/cc/pegs.cpp +++ b/src/cc/pegs.cpp @@ -30,7 +30,7 @@ // start of consensus code -int64_t IsPegsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsPegsvout(struct CC_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -41,7 +41,7 @@ int64_t IsPegsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) return(0); } -bool PegsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool PegsExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -79,7 +79,7 @@ bool PegsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction & else return(true); } -bool PegsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool PegsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; return eval->Invalid("no validation yet"); @@ -120,7 +120,7 @@ bool PegsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, // helper functions for rpc calls in rpcwallet.cpp -int64_t AddPegsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddPegsInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; @@ -152,7 +152,7 @@ int64_t AddPegsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKe std::string PegsGet(uint64_t txfee,int64_t nValue) { CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Pegspk; int64_t inputs,CCchange=0; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; + CPubKey mypk,Pegspk; int64_t inputs,CCchange=0; struct CC_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; cp = CCinit(&C,EVAL_PEGS); if ( txfee == 0 ) txfee = 10000; @@ -193,7 +193,7 @@ std::string PegsGet(uint64_t txfee,int64_t nValue) std::string PegsFund(uint64_t txfee,int64_t funds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Pegspk; CScript opret; struct CCcontract_info *cp,C; + CPubKey mypk,Pegspk; CScript opret; struct CC_info *cp,C; cp = CCinit(&C,EVAL_PEGS); if ( txfee == 0 ) txfee = 10000; @@ -211,7 +211,7 @@ UniValue PegsInfo() { UniValue result(UniValue::VOBJ); char numstr[64]; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey Pegspk; struct CCcontract_info *cp,C; int64_t funding; + CPubKey Pegspk; struct CC_info *cp,C; int64_t funding; result.push_back(Pair("result","success")); result.push_back(Pair("name","Pegs")); cp = CCinit(&C,EVAL_PEGS); diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 369495b1a..6171e73a8 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -86,7 +86,7 @@ uint8_t DecodePricesFundingOpRet(CScript scriptPubKey,CPubKey &planpk,uint256 &o return(0); } -bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool PricesValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; return eval->Invalid("no validation yet"); @@ -127,7 +127,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx // helper functions for rpc calls in rpcwallet.cpp -int64_t AddTokensInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,char *destaddr,uint256 tolenid,int64_t total,int32_t maxinputs) +int64_t AddTokensInputs(struct CC_info *cp,CMutableTransaction &mtx,char *destaddr,uint256 tolenid,int64_t total,int32_t maxinputs) { // add threshold check int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; @@ -158,7 +158,7 @@ int64_t AddTokensInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,char UniValue PricesList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint64_t mode; int32_t margin,maxleverage; std::vectorpubkeys; uint256 txid,hashBlock,oracletxid,longtoken,shorttoken,bettoken; CPubKey planpk,pricespk; char str[65]; CTransaction vintx; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CC_info *cp,C; uint64_t mode; int32_t margin,maxleverage; std::vectorpubkeys; uint256 txid,hashBlock,oracletxid,longtoken,shorttoken,bettoken; CPubKey planpk,pricespk; char str[65]; CTransaction vintx; cp = CCinit(&C,EVAL_PRICES); pricespk = GetUnspendable(cp,0); SetCCtxids(addressIndex,cp->normaladdr); @@ -183,7 +183,7 @@ UniValue PricesList() std::string PricesCreateFunding(uint64_t txfee,uint256 bettoken,uint256 oracletxid,uint64_t margin,uint64_t mode,uint256 longtoken,uint256 shorttoken,int32_t maxleverage,int64_t funding,std::vector pubkeys) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction oracletx; int64_t fullsupply,inputs,CCchange=0; uint256 hashBlock; char str[65],coinaddr[64],houseaddr[64]; CPubKey mypk,pricespk; int32_t i,N,numvouts; struct CCcontract_info *cp,C; + CTransaction oracletx; int64_t fullsupply,inputs,CCchange=0; uint256 hashBlock; char str[65],coinaddr[64],houseaddr[64]; CPubKey mypk,pricespk; int32_t i,N,numvouts; struct CC_info *cp,C; if ( funding < 100*COIN || maxleverage <= 0 || maxleverage > 10000 ) { CCerror = "invalid parameter error"; @@ -246,7 +246,7 @@ std::string PricesCreateFunding(uint64_t txfee,uint256 bettoken,uint256 oracletx UniValue PricesInfo(uint256 fundingtxid) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); CPubKey pricespk,planpk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction vintx; int64_t balance,supply,exposure; uint64_t funding,mode; int32_t i,margin,maxleverage; char numstr[65],houseaddr[64],exposureaddr[64],str[65]; std::vectorpubkeys; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); CPubKey pricespk,planpk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction vintx; int64_t balance,supply,exposure; uint64_t funding,mode; int32_t i,margin,maxleverage; char numstr[65],houseaddr[64],exposureaddr[64],str[65]; std::vectorpubkeys; struct CC_info *cp,C; cp = CCinit(&C,EVAL_PRICES); pricespk = GetUnspendable(cp,0); if ( GetTransaction(fundingtxid,vintx,hashBlock,false) == 0 ) @@ -295,7 +295,7 @@ UniValue PricesInfo(uint256 fundingtxid) std::string PricesAddFunding(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int64_t amount) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - struct CCcontract_info *cp,C; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,CCchange = 0; uint64_t funding,mode; int32_t margin,maxleverage; char houseaddr[64],myaddr[64]; std::vectorpubkeys; + struct CC_info *cp,C; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,CCchange = 0; uint64_t funding,mode; int32_t margin,maxleverage; char houseaddr[64],myaddr[64]; std::vectorpubkeys; if ( amount < 10000 ) { CCerror = "amount must be positive"; @@ -350,7 +350,7 @@ std::string PricesAddFunding(uint64_t txfee,uint256 refbettoken,uint256 fundingt std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int64_t amount,int32_t leverage) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - struct CCcontract_info *cp,C; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,tokenid,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,inputs2,longexposure,netexposure,shortexposure,CCchange = 0,CCchange2 = 0; uint64_t funding,mode; int32_t dir,margin,maxleverage; char houseaddr[64],myaddr[64],exposureaddr[64]; std::vectorpubkeys; + struct CC_info *cp,C; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,tokenid,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,inputs2,longexposure,netexposure,shortexposure,CCchange = 0,CCchange2 = 0; uint64_t funding,mode; int32_t dir,margin,maxleverage; char houseaddr[64],myaddr[64],exposureaddr[64]; std::vectorpubkeys; if ( amount < 0 ) { amount = -amount; diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index bd5a6d919..c47fcf1c2 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -141,7 +141,7 @@ uint8_t DecodeRewardsOpRet(uint256 txid,const CScript &scriptPubKey,uint64_t &sb return(0); } -int64_t IsRewardsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v,uint64_t refsbits,uint256 reffundingtxid) +int64_t IsRewardsvout(struct CC_info *cp,const CTransaction& tx,int32_t v,uint64_t refsbits,uint256 reffundingtxid) { char destaddr[64]; uint64_t sbits; uint256 fundingtxid,txid; uint8_t funcid; int32_t numvouts; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 && (numvouts= (int32_t)tx.vout.size()) > 0 ) @@ -157,7 +157,7 @@ int64_t IsRewardsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t return(0); } -bool RewardsExactAmounts(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx,uint64_t txfee,uint64_t refsbits,uint256 reffundingtxid) +bool RewardsExactAmounts(struct CC_info *cp,Eval *eval,const CTransaction &tx,uint64_t txfee,uint64_t refsbits,uint256 reffundingtxid) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -192,7 +192,7 @@ bool RewardsExactAmounts(struct CCcontract_info *cp,Eval *eval,const CTransactio else return(true); } -bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool RewardsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { uint256 txid,fundingtxid,hashBlock,vinfundingtxid; uint64_t vinsbits,sbits,APR,minseconds,maxseconds,mindeposit,amount,reward,txfee=10000; int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; uint8_t funcid; CScript scriptPubKey; CTransaction fundingTx,vinTx; numvins = tx.vin.size(); @@ -327,7 +327,7 @@ static uint64_t myIs_unlockedtx_inmempool(uint256 &txid,int32_t &vout,uint64_t r } // 'L' vs 'F' and 'A' -int64_t AddRewardsInputs(CScript &scriptPubKey,uint64_t maxseconds,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) +int64_t AddRewardsInputs(CScript &scriptPubKey,uint64_t maxseconds,struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) { char coinaddr[64],str[65]; uint64_t threshold,sbits,nValue,totalinputs = 0; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t numblocks,j,vout,n = 0; uint8_t funcid; std::vector > unspentOutputs; @@ -387,7 +387,7 @@ int64_t AddRewardsInputs(CScript &scriptPubKey,uint64_t maxseconds,struct CCcont return(totalinputs); } -int64_t RewardsPlanFunds(uint64_t &lockedfunds,uint64_t refsbits,struct CCcontract_info *cp,CPubKey pk,uint256 reffundingtxid) +int64_t RewardsPlanFunds(uint64_t &lockedfunds,uint64_t refsbits,struct CC_info *cp,CPubKey pk,uint256 reffundingtxid) { char coinaddr[64]; uint64_t sbits; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t vout; uint8_t funcid; std::vector > unspentOutputs; @@ -418,7 +418,7 @@ int64_t RewardsPlanFunds(uint64_t &lockedfunds,uint64_t refsbits,struct CCcontra return(totalinputs); } -bool RewardsPlanExists(struct CCcontract_info *cp,uint64_t refsbits,CPubKey rewardspk,uint64_t &APR,uint64_t &minseconds,uint64_t &maxseconds,uint64_t &mindeposit) +bool RewardsPlanExists(struct CC_info *cp,uint64_t refsbits,CPubKey rewardspk,uint64_t &APR,uint64_t &minseconds,uint64_t &maxseconds,uint64_t &mindeposit) { char CCaddr[64]; uint64_t sbits; uint256 txid,hashBlock; CTransaction tx; std::vector > txids; @@ -443,7 +443,7 @@ bool RewardsPlanExists(struct CCcontract_info *cp,uint64_t refsbits,CPubKey rewa UniValue RewardsInfo(uint256 rewardsid) { - UniValue result(UniValue::VOBJ); uint256 hashBlock; CTransaction vintx; uint64_t lockedfunds,APR,minseconds,maxseconds,mindeposit,sbits,funding; CPubKey rewardspk; struct CCcontract_info *cp,C; char str[67],numstr[65]; + UniValue result(UniValue::VOBJ); uint256 hashBlock; CTransaction vintx; uint64_t lockedfunds,APR,minseconds,maxseconds,mindeposit,sbits,funding; CPubKey rewardspk; struct CC_info *cp,C; char str[67],numstr[65]; if ( GetTransaction(rewardsid,vintx,hashBlock,false) == 0 ) { fprintf(stderr,"cant find fundingtxid\n"); @@ -481,7 +481,7 @@ UniValue RewardsInfo(uint256 rewardsid) UniValue RewardsList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock; CTransaction vintx; uint64_t sbits,APR,minseconds,maxseconds,mindeposit; char str[65]; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CC_info *cp,C; uint256 txid,hashBlock; CTransaction vintx; uint64_t sbits,APR,minseconds,maxseconds,mindeposit; char str[65]; cp = CCinit(&C,EVAL_REWARDS); SetCCtxids(addressIndex,cp->normaladdr); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) @@ -501,7 +501,7 @@ UniValue RewardsList() std::string RewardsCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t APR,int64_t minseconds,int64_t maxseconds,int64_t mindeposit) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,rewardspk; CScript opret; uint64_t sbits,a,b,c,d; struct CCcontract_info *cp,C; + CPubKey mypk,rewardspk; CScript opret; uint64_t sbits,a,b,c,d; struct CC_info *cp,C; if ( funds < COIN || mindeposit < 0 || minseconds < 0 || maxseconds < 0 ) { fprintf(stderr,"negative parameter error\n"); @@ -536,7 +536,7 @@ std::string RewardsCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int6 std::string RewardsAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,rewardspk; CScript opret; uint64_t sbits,a,b,c,d; struct CCcontract_info *cp,C; + CPubKey mypk,rewardspk; CScript opret; uint64_t sbits,a,b,c,d; struct CC_info *cp,C; if ( amount < 0 ) { fprintf(stderr,"negative parameter error\n"); @@ -571,7 +571,7 @@ std::string RewardsAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,i std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t deposit) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,rewardspk; CScript opret; uint64_t lockedfunds,sbits,funding,APR,minseconds,maxseconds,mindeposit; struct CCcontract_info *cp,C; + CPubKey mypk,rewardspk; CScript opret; uint64_t lockedfunds,sbits,funding,APR,minseconds,maxseconds,mindeposit; struct CC_info *cp,C; if ( deposit < txfee ) { CCerror = "deposit amount less than txfee"; @@ -615,7 +615,7 @@ std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 locktxid) { CMutableTransaction firstmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction tx; char coinaddr[64]; CPubKey mypk,rewardspk; CScript scriptPubKey,ignore; uint256 hashBlock; uint64_t sbits,APR,minseconds,maxseconds,mindeposit; int64_t funding,reward=0,amount=0,inputs,CCchange=0; struct CCcontract_info *cp,C; + CTransaction tx; char coinaddr[64]; CPubKey mypk,rewardspk; CScript scriptPubKey,ignore; uint256 hashBlock; uint64_t sbits,APR,minseconds,maxseconds,mindeposit; int64_t funding,reward=0,amount=0,inputs,CCchange=0; struct CC_info *cp,C; cp = CCinit(&C,EVAL_REWARDS); if ( txfee == 0 ) txfee = 10000; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 10c6ee4b8..51b31c5c7 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2150,7 +2150,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } else { - struct CCcontract_info *cp,C; uint256 txid; int32_t vout; CAmount nValue; char coinaddr[64]; CPubKey mypk,Marmarapk; + struct CC_info *cp,C; uint256 txid; int32_t vout; CAmount nValue; char coinaddr[64]; CPubKey mypk,Marmarapk; std::vector > unspentOutputs; cp = CCinit(&C,EVAL_MARMARA); mypk = pubkey2pk(Mypubkey()); diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 90f8fd6db..24f0c5f98 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -463,6 +463,10 @@ static const CRPCCommand vRPCCommands[] = // Payments { "payments", "paymentsaddress", &paymentsaddress, true }, + { "CClib", "cclibaddress", &cclibaddress, true }, + { "CClib", "cclibinfo", &cclibinfo, true }, + { "CClib", "cclib", &cclib, true }, + // Gateways { "gateways", "gatewaysaddress", &gatewaysaddress, true }, { "gateways", "gatewayslist", &gatewayslist, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index d5ebb56ab..92cbb5105 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -286,7 +286,9 @@ extern UniValue marmara_info(const UniValue& params, bool fHelp); extern UniValue marmara_creditloop(const UniValue& params, bool fHelp); extern UniValue marmara_settlement(const UniValue& params, bool fHelp); extern UniValue marmara_lock(const UniValue& params, bool fHelp); -extern UniValue paymentsaddress(const UniValue& params, bool fHelp); +extern UniValue cclibaddress(const UniValue& params, bool fHelp); +extern UniValue cclibinfo(const UniValue& params, bool fHelp); +extern UniValue cclib(const UniValue& params, bool fHelp); extern UniValue gatewaysaddress(const UniValue& params, bool fHelp); extern UniValue gatewayslist(const UniValue& params, bool fHelp); extern UniValue gatewaysinfo(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 02cf85ee6..588706a41 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5197,7 +5197,7 @@ int32_t ensure_CCrequirements() #include "../cc/CCHeir.h" #include "../cc/CCMarmara.h" -UniValue CCaddress(struct CCcontract_info *cp,char *name,std::vector &pubkey) +UniValue CCaddress(struct CC_info *cp,char *name,std::vector &pubkey) { UniValue result(UniValue::VOBJ); char destaddr[64],str[64]; CPubKey pk; pk = GetUnspendable(cp,0); @@ -5302,7 +5302,7 @@ UniValue setpubkey(const UniValue& params, bool fHelp) UniValue channelsaddress(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::vector destpubkey; CPubKey pk,pk2; char destaddr[64]; + UniValue result(UniValue::VOBJ); struct CC_info *cp,C; std::vector destpubkey; CPubKey pk,pk2; char destaddr[64]; cp = CCinit(&C,EVAL_CHANNELS); if ( fHelp || params.size() != 1 ) throw runtime_error("channelsaddress destpubkey\n"); @@ -5327,9 +5327,46 @@ UniValue channelsaddress(const UniValue& params, bool fHelp) return(result); } +UniValue cclibaddress(const UniValue& params, bool fHelp) +{ + struct CC_info *cp,C; std::vector pubkey; + cp = CCinit(&C,EVAL_FIRSTUSER); + if ( fHelp || params.size() > 1 ) + throw runtime_error("cclibaddress [pubkey]\n"); + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + if ( params.size() == 1 ) + pubkey = ParseHex(params[0].get_str().c_str()); + return(CCaddress(cp,(char *)"CClib",pubkey)); +} + +UniValue cclibinfo(const UniValue& params, bool fHelp) +{ + struct CC_info *cp,C; + cp = CCinit(&C,EVAL_FIRSTUSER); + if ( fHelp || params.size() > 0 ) + throw runtime_error("cclibinfo\n"); + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + return(CClib_info(cp)); +} + +UniValue cclib(const UniValue& params, bool fHelp) +{ + struct CC_info *cp,C; char *method; cJSON *params; + cp = CCinit(&C,EVAL_FIRSTUSER); + if ( fHelp || params.size() > 2 ) + throw runtime_error("cclib method [JSON params]\n"); + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + method = params[0].get_str().c_str(); + params = cJSON_Parse(params[1].get_str().c_str()); + return(CClib(cp,method,params)); +} + UniValue oraclesaddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector pubkey; + struct CC_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_ORACLES); if ( fHelp || params.size() > 1 ) throw runtime_error("oraclesaddress [pubkey]\n"); @@ -5342,7 +5379,7 @@ UniValue oraclesaddress(const UniValue& params, bool fHelp) UniValue pricesaddress(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C,*assetscp,C2; std::vector pubkey; CPubKey mypk,planpk,pricespk; char myaddr[64],houseaddr[64],exposureaddr[64]; + UniValue result(UniValue::VOBJ); struct CC_info *cp,C,*assetscp,C2; std::vector pubkey; CPubKey mypk,planpk,pricespk; char myaddr[64],houseaddr[64],exposureaddr[64]; cp = CCinit(&C,EVAL_PRICES); assetscp = CCinit(&C2,EVAL_PRICES); if ( fHelp || params.size() > 1 ) @@ -5365,7 +5402,7 @@ UniValue pricesaddress(const UniValue& params, bool fHelp) UniValue pegsaddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector pubkey; + struct CC_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_PEGS); if ( fHelp || params.size() > 1 ) throw runtime_error("pegssaddress [pubkey]\n"); @@ -5378,7 +5415,7 @@ UniValue pegsaddress(const UniValue& params, bool fHelp) UniValue marmaraaddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector pubkey; + struct CC_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_MARMARA); if ( fHelp || params.size() > 1 ) throw runtime_error("Marmaraaddress [pubkey]\n"); @@ -5391,7 +5428,7 @@ UniValue marmaraaddress(const UniValue& params, bool fHelp) UniValue paymentsaddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector pubkey; + struct CC_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_PAYMENTS); if ( fHelp || params.size() > 1 ) throw runtime_error("paymentsaddress [pubkey]\n"); @@ -5404,7 +5441,7 @@ UniValue paymentsaddress(const UniValue& params, bool fHelp) UniValue gatewaysaddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector pubkey; + struct CC_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_GATEWAYS); if ( fHelp || params.size() > 1 ) throw runtime_error("gatewaysaddress [pubkey]\n"); @@ -5417,7 +5454,7 @@ UniValue gatewaysaddress(const UniValue& params, bool fHelp) UniValue heiraddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector pubkey; + struct CC_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_HEIR); if ( fHelp || params.size() > 1 ) throw runtime_error("heiraddress [pubkey]\n"); @@ -5432,7 +5469,7 @@ UniValue heiraddress(const UniValue& params, bool fHelp) UniValue lottoaddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector pubkey; + struct CC_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_LOTTO); if ( fHelp || params.size() > 1 ) throw runtime_error("lottoaddress [pubkey]\n"); @@ -5445,7 +5482,7 @@ UniValue lottoaddress(const UniValue& params, bool fHelp) UniValue FSMaddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector pubkey; + struct CC_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_FSM); if ( fHelp || params.size() > 1 ) throw runtime_error("FSMaddress [pubkey]\n"); @@ -5458,7 +5495,7 @@ UniValue FSMaddress(const UniValue& params, bool fHelp) UniValue auctionaddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector pubkey; + struct CC_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_AUCTION); if ( fHelp || params.size() > 1 ) throw runtime_error("auctionaddress [pubkey]\n"); @@ -5471,7 +5508,7 @@ UniValue auctionaddress(const UniValue& params, bool fHelp) UniValue diceaddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector pubkey; + struct CC_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_DICE); if ( fHelp || params.size() > 1 ) throw runtime_error("diceaddress [pubkey]\n"); @@ -5484,7 +5521,7 @@ UniValue diceaddress(const UniValue& params, bool fHelp) UniValue faucetaddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector pubkey; + struct CC_info *cp,C; std::vector pubkey; int errno; cp = CCinit(&C,EVAL_FAUCET); if ( fHelp || params.size() > 1 ) @@ -5499,7 +5536,7 @@ UniValue faucetaddress(const UniValue& params, bool fHelp) UniValue rewardsaddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector pubkey; + struct CC_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_REWARDS); if ( fHelp || params.size() > 1 ) throw runtime_error("rewardsaddress [pubkey]\n"); @@ -5512,7 +5549,7 @@ UniValue rewardsaddress(const UniValue& params, bool fHelp) UniValue assetsaddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp, C; std::vector pubkey; + struct CC_info *cp, C; std::vector pubkey; cp = CCinit(&C, EVAL_ASSETS); if (fHelp || params.size() > 1) throw runtime_error("assetsaddress [pubkey]\n"); @@ -5525,7 +5562,7 @@ UniValue assetsaddress(const UniValue& params, bool fHelp) UniValue tokenaddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector pubkey; + struct CC_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_TOKENS); if ( fHelp || params.size() > 1 ) throw runtime_error("tokenaddress [pubkey]\n"); @@ -5730,7 +5767,7 @@ UniValue channelsinfo(const UniValue& params, bool fHelp) UniValue channelsopen(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); int32_t numpayments; int64_t payment; std::vector destpub; struct CCcontract_info *cp,C; std::string hex; + UniValue result(UniValue::VOBJ); int32_t numpayments; int64_t payment; std::vector destpub; struct CC_info *cp,C; std::string hex; uint256 tokenid=zeroid; cp = CCinit(&C,EVAL_CHANNELS); @@ -5773,7 +5810,7 @@ UniValue channelsopen(const UniValue& params, bool fHelp) UniValue channelspayment(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 opentxid,secret=zeroid; int32_t n; int64_t amount; + UniValue result(UniValue::VOBJ); struct CC_info *cp,C; std::string hex; uint256 opentxid,secret=zeroid; int32_t n; int64_t amount; cp = CCinit(&C,EVAL_CHANNELS); if ( fHelp || params.size() < 2 || params.size() >3 ) throw runtime_error("channelspayment opentxid amount [secret]\n"); @@ -5803,7 +5840,7 @@ UniValue channelspayment(const UniValue& params, bool fHelp) UniValue channelsclose(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 opentxid; + UniValue result(UniValue::VOBJ); struct CC_info *cp,C; std::string hex; uint256 opentxid; cp = CCinit(&C,EVAL_CHANNELS); if ( fHelp || params.size() != 1 ) throw runtime_error("channelsclose opentxid\n"); @@ -5823,7 +5860,7 @@ UniValue channelsclose(const UniValue& params, bool fHelp) UniValue channelsrefund(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 opentxid,closetxid; + UniValue result(UniValue::VOBJ); struct CC_info *cp,C; std::string hex; uint256 opentxid,closetxid; cp = CCinit(&C,EVAL_CHANNELS); if ( fHelp || params.size() != 2 ) throw runtime_error("channelsrefund opentxid closetxid\n"); @@ -6877,7 +6914,7 @@ UniValue tokenorders(const UniValue& params, bool fHelp) UniValue tokenbalance(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); uint256 tokenid; uint64_t balance; std::vector pubkey; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ); uint256 tokenid; uint64_t balance; std::vector pubkey; struct CC_info *cp,C; CCerror.clear(); if ( fHelp || params.size() > 2 ) From df2c10a6d7e0ca0add54826b9e6b97d63b2b175c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 22:50:26 -1100 Subject: [PATCH 544/643] CC_info --- src/cc/CCutils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index b61fef840..9d4567322 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -638,7 +638,7 @@ bool ProcessCC(struct CC_info *cp,Eval* eval, std::vector paramsNull,co bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,const CTransaction &txTo,unsigned int nIn) { - uint8_t evalcode; int32_t height,from_mempool; struct CCinfo *cp; + uint8_t evalcode; int32_t height,from_mempool; struct CC_info *cp; if ( ASSETCHAINS_CCLIB != MYCCLIBNAME ) { fprintf(stderr,"-ac_cclib=%s vs myname %s\n",ASSETCHAINS_CCLIB.c_str(),MYCCLIBNAME); From 0b911c18ac9efdebbc96c97c631889b4a24a61ca Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 22:52:13 -1100 Subject: [PATCH 545/643] Fix --- src/cc/CCutils.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 9d4567322..5a7ee53f0 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -636,6 +636,8 @@ bool ProcessCC(struct CC_info *cp,Eval* eval, std::vector paramsNull,co return(false); } +extern struct CC_info CCinfos[0x100]; + bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,const CTransaction &txTo,unsigned int nIn) { uint8_t evalcode; int32_t height,from_mempool; struct CC_info *cp; @@ -657,17 +659,17 @@ bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,co evalcode = cond->code[0]; if ( evalcode >= EVAL_FIRSTUSER && evalcode <= EVAL_LASTUSER ) { - cp = &CCinfos[(int32_t)ecode]; + cp = &CCinfos[(int32_t)evalcode]; if ( cp->didinit == 0 ) { - if ( CClib_initcp(cp,ecode) == 0 ) + if ( CClib_initcp(cp,evalcode) == 0 ) cp->didinit = 1; else return eval->Invalid("unsupported CClib evalcode"); } CCclearvars(cp); if ( paramsNull.size() != 0 ) // Don't expect params return eval->Invalid("Cannot have params"); - else if ( CClib_validate(cp,eval,ctx,nIn) != 0 ) + else if ( CClib_validate(cp,eval,txTo,nIn) != 0 ) return(true); return eval->Invalid("error in CClib_validate"); } From df02d14c651159937d65716b33fe22237e87fa08 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 22:53:15 -1100 Subject: [PATCH 546/643] Test --- src/cc/CCutils.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 5a7ee53f0..d4f7b32bc 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -637,6 +637,8 @@ bool ProcessCC(struct CC_info *cp,Eval* eval, std::vector paramsNull,co } extern struct CC_info CCinfos[0x100]; +extern std::string MYCCLIBNAME; +bool CClib_validate(struct CC_info *cp,Eval *eval,const CTransaction &txTo,unsigned int nIn); bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,const CTransaction &txTo,unsigned int nIn) { From b1ec7e5afa0887fbe117f02f014f6d9ac16d347a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 22:55:19 -1100 Subject: [PATCH 547/643] Test --- src/cc/CCutils.cpp | 2 +- src/cc/cclib.cpp | 2 +- src/cc/heir_validate.h | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index d4f7b32bc..aecca0dd7 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -645,7 +645,7 @@ bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,co uint8_t evalcode; int32_t height,from_mempool; struct CC_info *cp; if ( ASSETCHAINS_CCLIB != MYCCLIBNAME ) { - fprintf(stderr,"-ac_cclib=%s vs myname %s\n",ASSETCHAINS_CCLIB.c_str(),MYCCLIBNAME); + fprintf(stderr,"-ac_cclib=%s vs myname %s\n",ASSETCHAINS_CCLIB.c_str(),MYCCLIBNAME.c_str()); return eval->Invalid("-ac_cclib name mismatches myname"); } height = KOMODO_CONNECTING; diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index c93d204df..837a36024 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -38,7 +38,7 @@ CClib_methods[] = { "faucet2_get", "", 0, 0, 'G' }, }; -#define MYCCLIBNAME ((char *)"stub") +std::string MYCCLIBNAME = (char *)"stub"; char *CClib_name() { return(MYCCLIBNAME); } diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index 39f6855ac..481947fe2 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -47,11 +47,11 @@ public: return CTxOut(amount, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG); } */ static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { - struct CC_info *cpHeir, heirC; + struct CCcontract_info *cpHeir, heirC; cpHeir = CCinit(&heirC, EVAL_HEIR); return GetCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); } - static void CCaddrCoinsOrTokens1of2set(struct CC_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { + static void CCaddrCoinsOrTokens1of2set(struct CCcontract_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { CCaddr1of2set(cp, ownerPubkey, heirPubkey, coinaddr); } }; @@ -61,7 +61,7 @@ class TokenHelper { public: static uint8_t getMyEval() { return EVAL_TOKENS; } static int64_t addOwnerInputs(uint256 tokenid, CMutableTransaction& mtx, CPubKey ownerPubkey, int64_t total, int32_t maxinputs) { - struct CC_info *cpHeir, heirC; + struct CCcontract_info *cpHeir, heirC; cpHeir = CCinit(&heirC, EVAL_TOKENS); return AddTokenCCInputs(cpHeir, mtx, ownerPubkey, tokenid, total, maxinputs); } @@ -89,12 +89,12 @@ public: return MakeCC1vout(EVAL_TOKENS, amount, myPubkey); // yes EVAL_TOKENS } */ static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { - struct CC_info *cpHeir, heirC; + struct CCcontract_info *cpHeir, heirC; cpHeir = CCinit(&heirC, EVAL_HEIR); return GetTokensCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); } - static void CCaddrCoinsOrTokens1of2set(struct CC_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { + static void CCaddrCoinsOrTokens1of2set(struct CCcontract_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { CCaddrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); } From e1e740c18c988da13c6c1cf2d1339ba361d67a87 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 22:56:33 -1100 Subject: [PATCH 548/643] CC_info --- src/cc/heir_validate.h | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index 481947fe2..85f5b5c11 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -47,11 +47,11 @@ public: return CTxOut(amount, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG); } */ static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { - struct CCcontract_info *cpHeir, heirC; + struct CC_info *cpHeir, heirC; cpHeir = CCinit(&heirC, EVAL_HEIR); return GetCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); } - static void CCaddrCoinsOrTokens1of2set(struct CCcontract_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { + static void CCaddrCoinsOrTokens1of2set(struct CC_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { CCaddr1of2set(cp, ownerPubkey, heirPubkey, coinaddr); } }; @@ -61,7 +61,7 @@ class TokenHelper { public: static uint8_t getMyEval() { return EVAL_TOKENS; } static int64_t addOwnerInputs(uint256 tokenid, CMutableTransaction& mtx, CPubKey ownerPubkey, int64_t total, int32_t maxinputs) { - struct CCcontract_info *cpHeir, heirC; + struct CC_info *cpHeir, heirC; cpHeir = CCinit(&heirC, EVAL_TOKENS); return AddTokenCCInputs(cpHeir, mtx, ownerPubkey, tokenid, total, maxinputs); } @@ -89,12 +89,12 @@ public: return MakeCC1vout(EVAL_TOKENS, amount, myPubkey); // yes EVAL_TOKENS } */ static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { - struct CCcontract_info *cpHeir, heirC; + struct CC_info *cpHeir, heirC; cpHeir = CCinit(&heirC, EVAL_HEIR); return GetTokensCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); } - static void CCaddrCoinsOrTokens1of2set(struct CCcontract_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { + static void CCaddrCoinsOrTokens1of2set(struct CC_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { CCaddrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); } @@ -123,13 +123,13 @@ public: class CValidatorBase { public: - CValidatorBase(CCcontract_info* cp) : m_cp(cp) {} + CValidatorBase(CC_info* cp) : m_cp(cp) {} virtual bool isVinValidator() const = 0; virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const = 0; virtual bool validateVout(CTxOut vout, std::string& message) const = 0; protected: - CCcontract_info * m_cp; + CC_info * m_cp; }; /** @@ -138,11 +138,11 @@ protected: class CInputIdentifierBase { public: - CInputIdentifierBase(CCcontract_info* cp) : m_cp(cp) {} + CInputIdentifierBase(CC_info* cp) : m_cp(cp) {} virtual std::string inputName() const = 0; virtual bool identifyInput(CTxIn vin) const = 0; protected: - CCcontract_info * m_cp; + CC_info * m_cp; }; /** @@ -375,7 +375,7 @@ private: class CNormalInputIdentifier : CInputIdentifierBase { public: - CNormalInputIdentifier(CCcontract_info* cp) : CInputIdentifierBase(cp) {} + CNormalInputIdentifier(CC_info* cp) : CInputIdentifierBase(cp) {} virtual std::string inputName() const { return std::string("normal input"); } virtual bool identifyInput(CTxIn vin) const { return !IsCCInput(vin.scriptSig); @@ -384,7 +384,7 @@ public: class CCCInputIdentifier : CInputIdentifierBase { public: - CCCInputIdentifier(CCcontract_info* cp) : CInputIdentifierBase(cp) {} + CCCInputIdentifier(CC_info* cp) : CInputIdentifierBase(cp) {} virtual std::string inputName() const { return std::string("CC input"); } virtual bool identifyInput(CTxIn vin) const { return IsCCInput(vin.scriptSig); @@ -398,7 +398,7 @@ public: template class CCC1of2AddressValidator : CValidatorBase { public: - CCC1of2AddressValidator(CCcontract_info* cp, CScript opRetScript, std::string customMessage = "") : + CCC1of2AddressValidator(CC_info* cp, CScript opRetScript, std::string customMessage = "") : m_fundingOpretScript(opRetScript), m_customMessage(customMessage), CValidatorBase(cp) {} virtual bool isVinValidator() const { return false; } @@ -452,7 +452,7 @@ private: template class CMyPubkeyVoutValidator : CValidatorBase { public: - CMyPubkeyVoutValidator(CCcontract_info* cp, CScript opRetScript, bool checkNormals) + CMyPubkeyVoutValidator(CC_info* cp, CScript opRetScript, bool checkNormals) : m_fundingOpretScript(opRetScript), m_checkNormals(checkNormals), CValidatorBase(cp) { } virtual bool isVinValidator() const { return false; } @@ -512,7 +512,7 @@ private: template class CHeirSpendValidator : CValidatorBase { public: - CHeirSpendValidator(CCcontract_info* cp, CScript opRetScript, uint256 latesttxid, uint8_t isHeirSpendingBegan) + CHeirSpendValidator(CC_info* cp, CScript opRetScript, uint256 latesttxid, uint8_t isHeirSpendingBegan) : m_fundingOpretScript(opRetScript), m_latesttxid(latesttxid), m_isHeirSpendingBegan(isHeirSpendingBegan), CValidatorBase(cp) {} virtual bool isVinValidator() const { return false; } @@ -568,7 +568,7 @@ private: template class COpRetValidator : CValidatorBase { public: - COpRetValidator(CCcontract_info* cp, CScript opret) + COpRetValidator(CC_info* cp, CScript opret) : m_fundingOpretScript(opret), CValidatorBase(cp) {} virtual bool isVinValidator() const { return false; } @@ -619,7 +619,7 @@ private: template class CNullValidator : CValidatorBase { public: - CNullValidator(CCcontract_info* cp) + CNullValidator(CC_info* cp) : CValidatorBase(cp) { } virtual bool isVinValidator() const { return false; } From 016548281c628b73107d3ebbe5d0f71885b2552c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 23:00:53 -1100 Subject: [PATCH 549/643] Payments address define --- src/rpc/server.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpc/server.h b/src/rpc/server.h index 92cbb5105..0166bca41 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -286,6 +286,7 @@ extern UniValue marmara_info(const UniValue& params, bool fHelp); extern UniValue marmara_creditloop(const UniValue& params, bool fHelp); extern UniValue marmara_settlement(const UniValue& params, bool fHelp); extern UniValue marmara_lock(const UniValue& params, bool fHelp); +extern UniValue paymentsaddress(const UniValue& params, bool fHelp); extern UniValue cclibaddress(const UniValue& params, bool fHelp); extern UniValue cclibinfo(const UniValue& params, bool fHelp); extern UniValue cclib(const UniValue& params, bool fHelp); From 3962a18c334c8062ab437abf9c1becb65ed8ff3e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 23:04:59 -1100 Subject: [PATCH 550/643] CC --- src/script/sign.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index b90ceafb5..cf44786b7 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -136,7 +136,7 @@ std::vector &GetCryptoConditions() return vCC; } -bool GetCCByUnspendableAddress(struct CCcontract_info *cp, char *addrstr) +bool GetCCByUnspendableAddress(struct CC_info *cp, char *addrstr) { std::vector &vCC = GetCryptoConditions(); bool found = false; From 607f47588b79c404bdde9b06fda4886595388552 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 23:06:02 -1100 Subject: [PATCH 551/643] x --- src/script/sign.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index cf44786b7..641d0a4d2 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -153,7 +153,7 @@ bool GetCCByUnspendableAddress(struct CC_info *cp, char *addrstr) return found; } -bool CCinitLite(struct CCcontract_info *cp, uint8_t evalcode) +bool CCinitLite(struct CC_info *cp, uint8_t evalcode) { std::vector &vCC = GetCryptoConditions(); bool found = false; From 4223d927ad5f46cba54f64355e25cd006e9442ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 23:12:28 -1100 Subject: [PATCH 552/643] struct CC_info --- src/cc/heir_validate.h | 1028 ++++++++++++++++++++-------------------- src/script/sign.cpp | 327 ++++++------- 2 files changed, 678 insertions(+), 677 deletions(-) diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index 85f5b5c11..f8e66e3d5 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -22,100 +22,100 @@ inline static bool isSpendingTx(uint8_t funcid) { return (funcid == 'C'); } // helper class to allow polymorphic behaviour for HeirXXX() functions in case of coins class CoinHelper { public: - - static uint8_t getMyEval() { return EVAL_HEIR; } - static int64_t addOwnerInputs(uint256 dummyid, CMutableTransaction& mtx, CPubKey ownerPubkey, int64_t total, int32_t maxinputs) { - return AddNormalinputs(mtx, ownerPubkey, total, maxinputs); - } - - static CScript makeCreateOpRet(uint256 dummyid, std::vector dummyPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName) { - return EncodeHeirCreateOpRet((uint8_t)'F', ownerPubkey, heirPubkey, inactivityTimeSec, heirName); - } - static CScript makeAddOpRet(uint256 dummyid, std::vector dummyPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) { - return EncodeHeirOpRet((uint8_t)'A', fundingtxid, isHeirSpendingBegan); - } - static CScript makeClaimOpRet(uint256 dummyid, std::vector dummyPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) { - return EncodeHeirOpRet((uint8_t)'C', fundingtxid, isHeirSpendingBegan); - } - static CTxOut make1of2Vout(int64_t amount, CPubKey ownerPubkey, CPubKey heirPubkey) { - return MakeCC1of2vout(EVAL_HEIR, amount, ownerPubkey, heirPubkey); - } - static CTxOut makeUserVout(int64_t amount, CPubKey myPubkey) { - return CTxOut(amount, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG); - } -/* static CTxOut makeClaimerVout(int64_t amount, CPubKey myPubkey) { - return CTxOut(amount, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG); - } */ - static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { - struct CC_info *cpHeir, heirC; - cpHeir = CCinit(&heirC, EVAL_HEIR); - return GetCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); - } - static void CCaddrCoinsOrTokens1of2set(struct CC_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { - CCaddr1of2set(cp, ownerPubkey, heirPubkey, coinaddr); - } + + static uint8_t getMyEval() { return EVAL_HEIR; } + static int64_t addOwnerInputs(uint256 dummyid, CMutableTransaction& mtx, CPubKey ownerPubkey, int64_t total, int32_t maxinputs) { + return AddNormalinputs(mtx, ownerPubkey, total, maxinputs); + } + + static CScript makeCreateOpRet(uint256 dummyid, std::vector dummyPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName) { + return EncodeHeirCreateOpRet((uint8_t)'F', ownerPubkey, heirPubkey, inactivityTimeSec, heirName); + } + static CScript makeAddOpRet(uint256 dummyid, std::vector dummyPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) { + return EncodeHeirOpRet((uint8_t)'A', fundingtxid, isHeirSpendingBegan); + } + static CScript makeClaimOpRet(uint256 dummyid, std::vector dummyPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) { + return EncodeHeirOpRet((uint8_t)'C', fundingtxid, isHeirSpendingBegan); + } + static CTxOut make1of2Vout(int64_t amount, CPubKey ownerPubkey, CPubKey heirPubkey) { + return MakeCC1of2vout(EVAL_HEIR, amount, ownerPubkey, heirPubkey); + } + static CTxOut makeUserVout(int64_t amount, CPubKey myPubkey) { + return CTxOut(amount, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG); + } + /* static CTxOut makeClaimerVout(int64_t amount, CPubKey myPubkey) { + return CTxOut(amount, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG); + } */ + static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { + struct CC_info *cpHeir, heirC; + cpHeir = CCinit(&heirC, EVAL_HEIR); + return GetCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); + } + static void CCaddrCoinsOrTokens1of2set(struct CC_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { + CCaddr1of2set(cp, ownerPubkey, heirPubkey, coinaddr); + } }; // helper class to allow polymorphic behaviour for HeirXXX() functions in case of tokens class TokenHelper { public: - static uint8_t getMyEval() { return EVAL_TOKENS; } - static int64_t addOwnerInputs(uint256 tokenid, CMutableTransaction& mtx, CPubKey ownerPubkey, int64_t total, int32_t maxinputs) { - struct CC_info *cpHeir, heirC; - cpHeir = CCinit(&heirC, EVAL_TOKENS); - return AddTokenCCInputs(cpHeir, mtx, ownerPubkey, tokenid, total, maxinputs); - } - - static CScript makeCreateOpRet(uint256 tokenid, std::vector voutTokenPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName) { - return EncodeTokenOpRet(tokenid, voutTokenPubkeys, - EncodeHeirCreateOpRet((uint8_t)'F', ownerPubkey, heirPubkey, inactivityTimeSec, heirName)); - } - static CScript makeAddOpRet(uint256 tokenid, std::vector voutTokenPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) { - return EncodeTokenOpRet(tokenid, voutTokenPubkeys, - EncodeHeirOpRet((uint8_t)'A', fundingtxid, isHeirSpendingBegan)); - } - static CScript makeClaimOpRet(uint256 tokenid, std::vector voutTokenPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) { - return EncodeTokenOpRet(tokenid, voutTokenPubkeys, - EncodeHeirOpRet((uint8_t)'C', fundingtxid, isHeirSpendingBegan)); - } - - static CTxOut make1of2Vout(int64_t amount, CPubKey ownerPubkey, CPubKey heirPubkey) { - return MakeTokensCC1of2vout(EVAL_HEIR, amount, ownerPubkey, heirPubkey); - } - static CTxOut makeUserVout(int64_t amount, CPubKey myPubkey) { - return MakeCC1vout(EVAL_TOKENS, amount, myPubkey); // yes EVAL_TOKENS - } -/* static CTxOut makeClaimerVout(int64_t amount, CPubKey myPubkey) { - return MakeCC1vout(EVAL_TOKENS, amount, myPubkey); // yes EVAL_TOKENS - } */ - static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { - struct CC_info *cpHeir, heirC; - cpHeir = CCinit(&heirC, EVAL_HEIR); - return GetTokensCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); - } - - static void CCaddrCoinsOrTokens1of2set(struct CC_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { - - CCaddrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); - } + static uint8_t getMyEval() { return EVAL_TOKENS; } + static int64_t addOwnerInputs(uint256 tokenid, CMutableTransaction& mtx, CPubKey ownerPubkey, int64_t total, int32_t maxinputs) { + struct CC_info *cpHeir, heirC; + cpHeir = CCinit(&heirC, EVAL_TOKENS); + return AddTokenCCInputs(cpHeir, mtx, ownerPubkey, tokenid, total, maxinputs); + } + + static CScript makeCreateOpRet(uint256 tokenid, std::vector voutTokenPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName) { + return EncodeTokenOpRet(tokenid, voutTokenPubkeys, + EncodeHeirCreateOpRet((uint8_t)'F', ownerPubkey, heirPubkey, inactivityTimeSec, heirName)); + } + static CScript makeAddOpRet(uint256 tokenid, std::vector voutTokenPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) { + return EncodeTokenOpRet(tokenid, voutTokenPubkeys, + EncodeHeirOpRet((uint8_t)'A', fundingtxid, isHeirSpendingBegan)); + } + static CScript makeClaimOpRet(uint256 tokenid, std::vector voutTokenPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) { + return EncodeTokenOpRet(tokenid, voutTokenPubkeys, + EncodeHeirOpRet((uint8_t)'C', fundingtxid, isHeirSpendingBegan)); + } + + static CTxOut make1of2Vout(int64_t amount, CPubKey ownerPubkey, CPubKey heirPubkey) { + return MakeTokensCC1of2vout(EVAL_HEIR, amount, ownerPubkey, heirPubkey); + } + static CTxOut makeUserVout(int64_t amount, CPubKey myPubkey) { + return MakeCC1vout(EVAL_TOKENS, amount, myPubkey); // yes EVAL_TOKENS + } + /* static CTxOut makeClaimerVout(int64_t amount, CPubKey myPubkey) { + return MakeCC1vout(EVAL_TOKENS, amount, myPubkey); // yes EVAL_TOKENS + } */ + static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { + struct CC_info *cpHeir, heirC; + cpHeir = CCinit(&heirC, EVAL_HEIR); + return GetTokensCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); + } + + static void CCaddrCoinsOrTokens1of2set(struct CC_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { + + CCaddrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); + } }; /** -* Small framework for vins and vouts validation implementing a variation of 'chain of responsibility' pattern: -* It consists of two classes CInputValidationPlan and COutputValidationPlan which both are configured with an array of vectors of validators -* (These validators are derived from the class CValidatorBase). -* -* A example of a validator may verify for a vout if its public key corresponds to the public key which is stored in opreturn. -* Or, vin validator may check if this vin depicts correctly to the CC contract's address. -* -* For validating vins CInputValidator additionally is provided with an instance of a class derived from the CInputIdentifierBase class. -* this identifier class allows to select identical vins (for example, normal vins or cc input vins) and apply validators from the corresponding vector to it. -* Note: CInputValidator treats that at least one identified vin should be present, otherwise it returns eval->invalid() and false. -* -* For validating vouts COutputValidator is configured for each vector of validators with the vout index to which these validators are applied -* (see constructors of both CInputValidator and COutputValidator) -*/ + * Small framework for vins and vouts validation implementing a variation of 'chain of responsibility' pattern: + * It consists of two classes CInputValidationPlan and COutputValidationPlan which both are configured with an array of vectors of validators + * (These validators are derived from the class CValidatorBase). + * + * A example of a validator may verify for a vout if its public key corresponds to the public key which is stored in opreturn. + * Or, vin validator may check if this vin depicts correctly to the CC contract's address. + * + * For validating vins CInputValidator additionally is provided with an instance of a class derived from the CInputIdentifierBase class. + * this identifier class allows to select identical vins (for example, normal vins or cc input vins) and apply validators from the corresponding vector to it. + * Note: CInputValidator treats that at least one identified vin should be present, otherwise it returns eval->invalid() and false. + * + * For validating vouts COutputValidator is configured for each vector of validators with the vout index to which these validators are applied + * (see constructors of both CInputValidator and COutputValidator) + */ /** * base class for all validators @@ -123,13 +123,13 @@ public: class CValidatorBase { public: - CValidatorBase(CC_info* cp) : m_cp(cp) {} - virtual bool isVinValidator() const = 0; - virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const = 0; - virtual bool validateVout(CTxOut vout, std::string& message) const = 0; - + CValidatorBase(CCcontract_info* cp) : m_cp(cp) {} + virtual bool isVinValidator() const = 0; + virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const = 0; + virtual bool validateVout(CTxOut vout, std::string& message) const = 0; + protected: - CC_info * m_cp; + CCcontract_info * m_cp; }; /** @@ -138,493 +138,493 @@ protected: class CInputIdentifierBase { public: - CInputIdentifierBase(CC_info* cp) : m_cp(cp) {} - virtual std::string inputName() const = 0; - virtual bool identifyInput(CTxIn vin) const = 0; + CInputIdentifierBase(CCcontract_info* cp) : m_cp(cp) {} + virtual std::string inputName() const = 0; + virtual bool identifyInput(CTxIn vin) const = 0; protected: - CC_info * m_cp; + CCcontract_info * m_cp; }; /** -* Encapsulates an array containing rows of validators -* Each row is a vector of validators (zero is possible) for validating vins or prev tx's vouts -* this validation plan is used for validating tx inputs -*/ + * Encapsulates an array containing rows of validators + * Each row is a vector of validators (zero is possible) for validating vins or prev tx's vouts + * this validation plan is used for validating tx inputs + */ template class CInputValidationPlan { - using ValidatorsRow = std::vector; - + using ValidatorsRow = std::vector; + public: - - // Pushes a row of validators for validating a vin or vout - // @param CInputIdentifierBase* pointer to class-identifier which determines several identical adjacent vins (like in schema "vin.0+: normal inputs") - // @param pargs parameter pack of zero or more pointer to validator objects - // Why pointers? because we store the base class in validators' row and then call its virtual functions - template - void pushValidators(CInputIdentifierBase *identifier, ARGS*... pargs) // validators row passed as variadic arguments CValidatorX *val1, CValidatorY *val2 ... - { - ValidatorsRow vValidators({ (TValidatorBase*)pargs... }); - m_arrayValidators.push_back(std::make_pair(identifier, vValidators)); - } - - // validate tx inputs and corresponding prev tx vouts - bool validate(const CTransaction& tx, Eval* eval) - { - std::string message = ""; - //std::cerr << "CInputValidationPlan::validate() starting vins validation..." << std::endl; - - int32_t ival = 0; - int32_t iv = 0; - int32_t numv = tx.vin.size(); - int32_t numValidators = m_arrayValidators.size(); - - // run over vins: - while (iv < numv && ival < numValidators) { - - int32_t identifiedCount = 0; - CInputIdentifierBase *identifier = m_arrayValidators[ival].first; - // check if this is 'our' input: - while (iv < numv && identifier->identifyInput(tx.vin[iv])) { - - // get prev tx: - CTransaction prevTx, *pPrevTxOrNull = NULL; - uint256 hashBlock; - - if (!eval->GetTxUnconfirmed(tx.vin[iv].prevout.hash, prevTx, hashBlock)) { - std::ostringstream stream; - stream << "can't find vinTx for vin=" << iv << "."; - return eval->Invalid(stream.str().c_str()); - } - pPrevTxOrNull = &prevTx; // TODO: get prev tx only if it required (i.e. if vout validators are present) - - // exec 'validators' from validator row of ival index, for tx.vin[iv] - if (!execValidatorsInRow(&tx, pPrevTxOrNull, iv, ival, message)) { - std::ostringstream stream; - stream << "invalid tx vin[" << iv << "]:" << message; - return eval->Invalid(stream.str().c_str()); // ... if not, return 'invalid' - } - - identifiedCount++; // how many vins we identified - iv++; // advance to the next vin - } - - // CInputValidationPlan treats that there must be at least one identified vin for configured validators' row - // like in 'vin.0: normal input' - if (identifiedCount == 0) { - std::ostringstream stream; - stream << "can't find required vins for " << identifier->inputName() << "."; - return eval->Invalid(stream.str().c_str()); - } - - ival++; // advance to the next validator row - // and it will try the same vin with the new CInputIdentifierBase and validators row - } - - // validation is successful if all validators have been used (i.e. ival = numValidators) - if (ival < numValidators) { - std::cerr << "CInputValidationPlan::validate() incorrect tx" << " ival=" << ival << " numValidators=" << numValidators << std::endl; - return eval->Invalid("incorrect tx structure: not all required vins are present."); - } - - //std::cerr << "CInputValidationPlan::validate() returns with true" << std::endl; - return true; - } - + + // Pushes a row of validators for validating a vin or vout + // @param CInputIdentifierBase* pointer to class-identifier which determines several identical adjacent vins (like in schema "vin.0+: normal inputs") + // @param pargs parameter pack of zero or more pointer to validator objects + // Why pointers? because we store the base class in validators' row and then call its virtual functions + template + void pushValidators(CInputIdentifierBase *identifier, ARGS*... pargs) // validators row passed as variadic arguments CValidatorX *val1, CValidatorY *val2 ... + { + ValidatorsRow vValidators({ (TValidatorBase*)pargs... }); + m_arrayValidators.push_back(std::make_pair(identifier, vValidators)); + } + + // validate tx inputs and corresponding prev tx vouts + bool validate(const CTransaction& tx, Eval* eval) + { + std::string message = ""; + //std::cerr << "CInputValidationPlan::validate() starting vins validation..." << std::endl; + + int32_t ival = 0; + int32_t iv = 0; + int32_t numv = tx.vin.size(); + int32_t numValidators = m_arrayValidators.size(); + + // run over vins: + while (iv < numv && ival < numValidators) { + + int32_t identifiedCount = 0; + CInputIdentifierBase *identifier = m_arrayValidators[ival].first; + // check if this is 'our' input: + while (iv < numv && identifier->identifyInput(tx.vin[iv])) { + + // get prev tx: + CTransaction prevTx, *pPrevTxOrNull = NULL; + uint256 hashBlock; + + if (!eval->GetTxUnconfirmed(tx.vin[iv].prevout.hash, prevTx, hashBlock)) { + std::ostringstream stream; + stream << "can't find vinTx for vin=" << iv << "."; + return eval->Invalid(stream.str().c_str()); + } + pPrevTxOrNull = &prevTx; // TODO: get prev tx only if it required (i.e. if vout validators are present) + + // exec 'validators' from validator row of ival index, for tx.vin[iv] + if (!execValidatorsInRow(&tx, pPrevTxOrNull, iv, ival, message)) { + std::ostringstream stream; + stream << "invalid tx vin[" << iv << "]:" << message; + return eval->Invalid(stream.str().c_str()); // ... if not, return 'invalid' + } + + identifiedCount++; // how many vins we identified + iv++; // advance to the next vin + } + + // CInputValidationPlan treats that there must be at least one identified vin for configured validators' row + // like in 'vin.0: normal input' + if (identifiedCount == 0) { + std::ostringstream stream; + stream << "can't find required vins for " << identifier->inputName() << "."; + return eval->Invalid(stream.str().c_str()); + } + + ival++; // advance to the next validator row + // and it will try the same vin with the new CInputIdentifierBase and validators row + } + + // validation is successful if all validators have been used (i.e. ival = numValidators) + if (ival < numValidators) { + std::cerr << "CInputValidationPlan::validate() incorrect tx" << " ival=" << ival << " numValidators=" << numValidators << std::endl; + return eval->Invalid("incorrect tx structure: not all required vins are present."); + } + + //std::cerr << "CInputValidationPlan::validate() returns with true" << std::endl; + return true; + } + private: - // Executes validators from the requested row of validators (selected by iValidators) for selected vin or vout (selected by iv) - bool execValidatorsInRow(const CTransaction* pTx, const CTransaction* pPrevTx, int32_t iv, int32_t ival, std::string& refMessage) const - { - // check boundaries: - if (ival < 0 || ival >= m_arrayValidators.size()) { - std::cerr << "CInputValidationPlan::execValidatorsInRow() internal error: incorrect param ival=" << ival << " size=" << m_arrayValidators.size(); - refMessage = "internal error: incorrect param ival index"; - return false; - } - - if (iv < 0 || iv >= pTx->vin.size()) { - std::cerr << "CInputValidationPlan::execValidatorsInRow() internal error: incorrect param iv=" << iv << " size=" << m_arrayValidators.size(); - refMessage = "internal error: incorrect param iv index"; - return false; - } - - // get requested row of validators: - ValidatorsRow vValidators = m_arrayValidators[ival].second; - - //std::cerr << "CInputValidationPlan::execValidatorsInRow() calling validators" << " for vin iv=" << iv << " ival=" << ival << std::endl; - - for (auto v : vValidators) { - bool result; - - if (v->isVinValidator()) - // validate this vin and previous vout: - result = v->validateVin(pTx->vin[iv], pPrevTx->vout[pTx->vin[iv].prevout.n], refMessage); - else - // if it is vout validator pass the previous tx vout: - result = v->validateVout( pPrevTx->vout[pTx->vin[iv].prevout.n], refMessage); - if (!result) { - return result; - } - } - return true; // validation OK - } - - + // Executes validators from the requested row of validators (selected by iValidators) for selected vin or vout (selected by iv) + bool execValidatorsInRow(const CTransaction* pTx, const CTransaction* pPrevTx, int32_t iv, int32_t ival, std::string& refMessage) const + { + // check boundaries: + if (ival < 0 || ival >= m_arrayValidators.size()) { + std::cerr << "CInputValidationPlan::execValidatorsInRow() internal error: incorrect param ival=" << ival << " size=" << m_arrayValidators.size(); + refMessage = "internal error: incorrect param ival index"; + return false; + } + + if (iv < 0 || iv >= pTx->vin.size()) { + std::cerr << "CInputValidationPlan::execValidatorsInRow() internal error: incorrect param iv=" << iv << " size=" << m_arrayValidators.size(); + refMessage = "internal error: incorrect param iv index"; + return false; + } + + // get requested row of validators: + ValidatorsRow vValidators = m_arrayValidators[ival].second; + + //std::cerr << "CInputValidationPlan::execValidatorsInRow() calling validators" << " for vin iv=" << iv << " ival=" << ival << std::endl; + + for (auto v : vValidators) { + bool result; + + if (v->isVinValidator()) + // validate this vin and previous vout: + result = v->validateVin(pTx->vin[iv], pPrevTx->vout[pTx->vin[iv].prevout.n], refMessage); + else + // if it is vout validator pass the previous tx vout: + result = v->validateVout( pPrevTx->vout[pTx->vin[iv].prevout.n], refMessage); + if (!result) { + return result; + } + } + return true; // validation OK + } + + private: - //std::map m_arrayValidators; - std::vector< std::pair > m_arrayValidators; - + //std::map m_arrayValidators; + std::vector< std::pair > m_arrayValidators; + }; /** -* Encapsulates an array containing rows of validators -* Each row is a vector of validators (zero is possible) for validating vouts -* this validation plan is used for validating tx outputs -*/ + * Encapsulates an array containing rows of validators + * Each row is a vector of validators (zero is possible) for validating vouts + * this validation plan is used for validating tx outputs + */ template class COutputValidationPlan { - using ValidatorsRow = std::vector; - + using ValidatorsRow = std::vector; + public: - // Pushes a row of validators for validating a vout - // @param ivout index to vout to validate - // @param pargs parameter pack of zero or more pointer to validator objects - // Why pointers? because we store base class and call its virtual functions - - template - void pushValidators(int32_t ivout, ARGS*... pargs) // validators row passed as variadic arguments CValidatorX *val1, CValidatorY *val2 ... - { - ValidatorsRow vValidators({ (TValidatorBase*)pargs... }); - m_arrayValidators.push_back(std::make_pair(ivout, vValidators)); - } - - // validate tx outputs - bool validate(const CTransaction& tx, Eval* eval) - { - std::string message = ""; - //std::cerr << "COutputValidationPlan::validateOutputs() starting vouts validation..." << std::endl; - - int32_t ival = 0; - int32_t numVouts = tx.vout.size(); - int32_t numValidators = m_arrayValidators.size(); - - // run over vouts: - while (ival < numValidators) { - - int32_t ivout = m_arrayValidators[ival].first; - if (ivout >= numVouts) { - std::cerr << "COutputValidationPlan::validate() incorrect tx" << "for ival=" << ival << " in tx.vout no such ivout=" << ivout << std::endl; - return eval->Invalid("incorrect tx structure: not all required vouts are present."); - } - else - { - // exec 'validators' from validator row of ival index, for tx.vout[ivout] - if (!execValidatorsInRow(&tx, ivout, ival, message)) { - std::ostringstream stream; - stream << "invalid tx vout[" << ivout << "]:" << message; - return eval->Invalid(stream.str().c_str()); // ... if not, return 'invalid' - } - } - ival++; // advance to the next vout - } - //std::cerr << "COutputValidationPlan::validate() returns with true" << std::endl; - return true; - } - + // Pushes a row of validators for validating a vout + // @param ivout index to vout to validate + // @param pargs parameter pack of zero or more pointer to validator objects + // Why pointers? because we store base class and call its virtual functions + + template + void pushValidators(int32_t ivout, ARGS*... pargs) // validators row passed as variadic arguments CValidatorX *val1, CValidatorY *val2 ... + { + ValidatorsRow vValidators({ (TValidatorBase*)pargs... }); + m_arrayValidators.push_back(std::make_pair(ivout, vValidators)); + } + + // validate tx outputs + bool validate(const CTransaction& tx, Eval* eval) + { + std::string message = ""; + //std::cerr << "COutputValidationPlan::validateOutputs() starting vouts validation..." << std::endl; + + int32_t ival = 0; + int32_t numVouts = tx.vout.size(); + int32_t numValidators = m_arrayValidators.size(); + + // run over vouts: + while (ival < numValidators) { + + int32_t ivout = m_arrayValidators[ival].first; + if (ivout >= numVouts) { + std::cerr << "COutputValidationPlan::validate() incorrect tx" << "for ival=" << ival << " in tx.vout no such ivout=" << ivout << std::endl; + return eval->Invalid("incorrect tx structure: not all required vouts are present."); + } + else + { + // exec 'validators' from validator row of ival index, for tx.vout[ivout] + if (!execValidatorsInRow(&tx, ivout, ival, message)) { + std::ostringstream stream; + stream << "invalid tx vout[" << ivout << "]:" << message; + return eval->Invalid(stream.str().c_str()); // ... if not, return 'invalid' + } + } + ival++; // advance to the next vout + } + //std::cerr << "COutputValidationPlan::validate() returns with true" << std::endl; + return true; + } + private: - // Executes validators from the requested row of validators (selected by iValidators) for selected vin or vout (selected by iv) - bool execValidatorsInRow(const CTransaction* pTx, int32_t iv, int32_t ival, std::string& refMessage) const - { - // check boundaries: - if (ival < 0 || ival >= m_arrayValidators.size()) { - std::cerr << "COutputValidationPlan::execValidatorsInRow() internal error: incorrect param ival=" << ival << " size=" << m_arrayValidators.size(); - refMessage = "internal error: incorrect param ival index"; - return false; - } - - if (iv < 0 || iv >= pTx->vout.size()) { - std::cerr << "COutputValidationPlan::execValidatorsInRow() internal error: incorrect param iv=" << iv << " size=" << m_arrayValidators.size(); - refMessage = "internal error: incorrect param iv index"; - return false; - } - - // get requested row of validators: - ValidatorsRow vValidators = m_arrayValidators[ival].second; - - //std::cerr << "COutputValidationPlan::execRow() calling validators" << " for vout iv=" << iv << " ival=" << ival << std::endl; - - for (auto v : vValidators) { - - if (!v->isVinValidator()) { - // if this is a 'in' validation plan then pass the previous tx vout: - bool result = v->validateVout(pTx->vout[iv], refMessage); - if (!result) - return result; - } - } - return true; // validation OK - } - + // Executes validators from the requested row of validators (selected by iValidators) for selected vin or vout (selected by iv) + bool execValidatorsInRow(const CTransaction* pTx, int32_t iv, int32_t ival, std::string& refMessage) const + { + // check boundaries: + if (ival < 0 || ival >= m_arrayValidators.size()) { + std::cerr << "COutputValidationPlan::execValidatorsInRow() internal error: incorrect param ival=" << ival << " size=" << m_arrayValidators.size(); + refMessage = "internal error: incorrect param ival index"; + return false; + } + + if (iv < 0 || iv >= pTx->vout.size()) { + std::cerr << "COutputValidationPlan::execValidatorsInRow() internal error: incorrect param iv=" << iv << " size=" << m_arrayValidators.size(); + refMessage = "internal error: incorrect param iv index"; + return false; + } + + // get requested row of validators: + ValidatorsRow vValidators = m_arrayValidators[ival].second; + + //std::cerr << "COutputValidationPlan::execRow() calling validators" << " for vout iv=" << iv << " ival=" << ival << std::endl; + + for (auto v : vValidators) { + + if (!v->isVinValidator()) { + // if this is a 'in' validation plan then pass the previous tx vout: + bool result = v->validateVout(pTx->vout[iv], refMessage); + if (!result) + return result; + } + } + return true; // validation OK + } + private: - //std::map m_mapValidators; - std::vector< std::pair > m_arrayValidators; - + //std::map m_mapValidators; + std::vector< std::pair > m_arrayValidators; + }; class CNormalInputIdentifier : CInputIdentifierBase { public: - CNormalInputIdentifier(CC_info* cp) : CInputIdentifierBase(cp) {} - virtual std::string inputName() const { return std::string("normal input"); } - virtual bool identifyInput(CTxIn vin) const { - return !IsCCInput(vin.scriptSig); - } + CNormalInputIdentifier(CCcontract_info* cp) : CInputIdentifierBase(cp) {} + virtual std::string inputName() const { return std::string("normal input"); } + virtual bool identifyInput(CTxIn vin) const { + return !IsCCInput(vin.scriptSig); + } }; class CCCInputIdentifier : CInputIdentifierBase { public: - CCCInputIdentifier(CC_info* cp) : CInputIdentifierBase(cp) {} - virtual std::string inputName() const { return std::string("CC input"); } - virtual bool identifyInput(CTxIn vin) const { - return IsCCInput(vin.scriptSig); - } + CCCInputIdentifier(CCcontract_info* cp) : CInputIdentifierBase(cp) {} + virtual std::string inputName() const { return std::string("CC input"); } + virtual bool identifyInput(CTxIn vin) const { + return IsCCInput(vin.scriptSig); + } }; /** -* Validates 1of2address for vout (may be used for either this or prev tx) -*/ + * Validates 1of2address for vout (may be used for either this or prev tx) + */ template class CCC1of2AddressValidator : CValidatorBase { public: - CCC1of2AddressValidator(CC_info* cp, CScript opRetScript, std::string customMessage = "") : - m_fundingOpretScript(opRetScript), m_customMessage(customMessage), CValidatorBase(cp) {} - - virtual bool isVinValidator() const { return false; } - virtual bool validateVout(CTxOut vout, std::string& message) const - { - //std::cerr << "CCC1of2AddressValidator::validateVout() entered" << std::endl; - CPubKey ownerPubkey, heirPubkey; - int64_t inactivityTime; - std::string heirName; - uint256 tokenid; - - uint8_t funcId = DecodeHeirEitherOpRet(m_fundingOpretScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, true); - if (funcId == 0) { - message = m_customMessage + std::string(" invalid opreturn format"); - std::cerr << "CCC1of2AddressValidator::validateVout() exits with false: " << message << std::endl; - return false; - } - - char shouldBeAddr[65], ccAddr[65]; - - //GetCCaddress1of2(m_cp, shouldBeAddr, ownerPubkey, heirPubkey); - Helper::GetCoinsOrTokensCCaddress1of2(shouldBeAddr, ownerPubkey, heirPubkey); - - if (vout.scriptPubKey.IsPayToCryptoCondition()) { - if (Getscriptaddress(ccAddr, vout.scriptPubKey) && strcmp(shouldBeAddr, ccAddr) == 0) { - //std::cerr << "CCC1of2AddressValidator::validateVout() exits with true" << std::endl; - return true; - } - else { - message = m_customMessage + std::string(" incorrect heir funding address: incorrect pubkey(s)"); - } - } - else { - message = m_customMessage + std::string(" incorrect heir funding address: not a 1of2addr"); - } - - std::cerr << "CCC1of2AddressValidator::validateVout() exits with false: " << message << std::endl; - return false; - } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return false; } - + CCC1of2AddressValidator(CCcontract_info* cp, CScript opRetScript, std::string customMessage = "") : + m_fundingOpretScript(opRetScript), m_customMessage(customMessage), CValidatorBase(cp) {} + + virtual bool isVinValidator() const { return false; } + virtual bool validateVout(CTxOut vout, std::string& message) const + { + //std::cerr << "CCC1of2AddressValidator::validateVout() entered" << std::endl; + CPubKey ownerPubkey, heirPubkey; + int64_t inactivityTime; + std::string heirName; + uint256 tokenid; + + uint8_t funcId = DecodeHeirEitherOpRet(m_fundingOpretScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, true); + if (funcId == 0) { + message = m_customMessage + std::string(" invalid opreturn format"); + std::cerr << "CCC1of2AddressValidator::validateVout() exits with false: " << message << std::endl; + return false; + } + + char shouldBeAddr[65], ccAddr[65]; + + //GetCCaddress1of2(m_cp, shouldBeAddr, ownerPubkey, heirPubkey); + Helper::GetCoinsOrTokensCCaddress1of2(shouldBeAddr, ownerPubkey, heirPubkey); + + if (vout.scriptPubKey.IsPayToCryptoCondition()) { + if (Getscriptaddress(ccAddr, vout.scriptPubKey) && strcmp(shouldBeAddr, ccAddr) == 0) { + //std::cerr << "CCC1of2AddressValidator::validateVout() exits with true" << std::endl; + return true; + } + else { + message = m_customMessage + std::string(" incorrect heir funding address: incorrect pubkey(s)"); + } + } + else { + message = m_customMessage + std::string(" incorrect heir funding address: not a 1of2addr"); + } + + std::cerr << "CCC1of2AddressValidator::validateVout() exits with false: " << message << std::endl; + return false; + } + virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return false; } + private: - CScript m_fundingOpretScript; - std::string m_customMessage; + CScript m_fundingOpretScript; + std::string m_customMessage; }; /** -* Validates if this is vout to owner or heir from opret (funding or change) -*/ + * Validates if this is vout to owner or heir from opret (funding or change) + */ template class CMyPubkeyVoutValidator : CValidatorBase { public: - CMyPubkeyVoutValidator(CC_info* cp, CScript opRetScript, bool checkNormals) - : m_fundingOpretScript(opRetScript), m_checkNormals(checkNormals), CValidatorBase(cp) { } - - virtual bool isVinValidator() const { return false; } - virtual bool validateVout(CTxOut vout, std::string& message) const - { - //std::cerr << "CMyPubkeyVoutValidator::validateVout() entered" << std::endl; - - CPubKey ownerPubkey, heirPubkey; - int64_t inactivityTime; - std::string heirName; - uint256 tokenid; - - ///std::cerr << "CMyPubkeyVoutValidator::validateVout() m_opRetScript=" << m_opRetScript.ToString() << std::endl; - - // get both pubkeys: - uint8_t funcId = DecodeHeirEitherOpRet(m_fundingOpretScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, true); - if (funcId == 0) { - message = std::string("invalid opreturn format"); - return false; - } - - CScript ownerScript; - CScript heirScript; - if (m_checkNormals) { //not used, incorrect check, too strict - ownerScript = CoinHelper::makeUserVout(vout.nValue, ownerPubkey).scriptPubKey; - heirScript = CoinHelper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey; - std::cerr << "CMyPubkeyVoutValidator::validateVout() vout.scriptPubKey=" << vout.scriptPubKey.ToString() << " makeUserVout(coin,owner)=" << CoinHelper::makeUserVout(vout.nValue, ownerPubkey).scriptPubKey.ToString() << " makeUserVout(coin,heir)=" << CoinHelper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey.ToString() << std::endl; - } - else { - ownerScript = Helper::makeUserVout(vout.nValue, ownerPubkey).scriptPubKey; - heirScript = Helper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey; - std::cerr << "CMyPubkeyVoutValidator::validateVout() vout.scriptPubKey=" << vout.scriptPubKey.ToString() << " makeUserVout(owner)=" << Helper::makeUserVout(vout.nValue, ownerPubkey).scriptPubKey.ToString() << " makeUserVout(heir)=" << Helper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey.ToString() << std::endl; - } - - // recreate scriptPubKey for owner and heir and compare it with that of the vout to check: - if (vout.scriptPubKey == ownerScript || vout.scriptPubKey == heirScript) { - // this is vout to owner or heir addr: - //std::cerr << "CMyPubkeyVoutValidator::validateVout() exits with true" << std::endl; - return true; - } - - std::cerr << "CMyPubkeyVoutValidator::validateVout() exits with false (not the owner's or heir's addresses)" << std::endl; - message = std::string("invalid pubkey"); - return false; - } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } - + CMyPubkeyVoutValidator(CCcontract_info* cp, CScript opRetScript, bool checkNormals) + : m_fundingOpretScript(opRetScript), m_checkNormals(checkNormals), CValidatorBase(cp) { } + + virtual bool isVinValidator() const { return false; } + virtual bool validateVout(CTxOut vout, std::string& message) const + { + //std::cerr << "CMyPubkeyVoutValidator::validateVout() entered" << std::endl; + + CPubKey ownerPubkey, heirPubkey; + int64_t inactivityTime; + std::string heirName; + uint256 tokenid; + + ///std::cerr << "CMyPubkeyVoutValidator::validateVout() m_opRetScript=" << m_opRetScript.ToString() << std::endl; + + // get both pubkeys: + uint8_t funcId = DecodeHeirEitherOpRet(m_fundingOpretScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, true); + if (funcId == 0) { + message = std::string("invalid opreturn format"); + return false; + } + + CScript ownerScript; + CScript heirScript; + if (m_checkNormals) { //not used, incorrect check, too strict + ownerScript = CoinHelper::makeUserVout(vout.nValue, ownerPubkey).scriptPubKey; + heirScript = CoinHelper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey; + std::cerr << "CMyPubkeyVoutValidator::validateVout() vout.scriptPubKey=" << vout.scriptPubKey.ToString() << " makeUserVout(coin,owner)=" << CoinHelper::makeUserVout(vout.nValue, ownerPubkey).scriptPubKey.ToString() << " makeUserVout(coin,heir)=" << CoinHelper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey.ToString() << std::endl; + } + else { + ownerScript = Helper::makeUserVout(vout.nValue, ownerPubkey).scriptPubKey; + heirScript = Helper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey; + std::cerr << "CMyPubkeyVoutValidator::validateVout() vout.scriptPubKey=" << vout.scriptPubKey.ToString() << " makeUserVout(owner)=" << Helper::makeUserVout(vout.nValue, ownerPubkey).scriptPubKey.ToString() << " makeUserVout(heir)=" << Helper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey.ToString() << std::endl; + } + + // recreate scriptPubKey for owner and heir and compare it with that of the vout to check: + if (vout.scriptPubKey == ownerScript || vout.scriptPubKey == heirScript) { + // this is vout to owner or heir addr: + //std::cerr << "CMyPubkeyVoutValidator::validateVout() exits with true" << std::endl; + return true; + } + + std::cerr << "CMyPubkeyVoutValidator::validateVout() exits with false (not the owner's or heir's addresses)" << std::endl; + message = std::string("invalid pubkey"); + return false; + } + virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } + private: - CScript m_fundingOpretScript; - //uint256 m_lasttxid; - bool m_checkNormals; + CScript m_fundingOpretScript; + //uint256 m_lasttxid; + bool m_checkNormals; }; /** -* Check if the user is the heir and the heir is allowed to spend (duration > inactivityTime) -*/ + * Check if the user is the heir and the heir is allowed to spend (duration > inactivityTime) + */ template class CHeirSpendValidator : CValidatorBase { public: - CHeirSpendValidator(CC_info* cp, CScript opRetScript, uint256 latesttxid, uint8_t isHeirSpendingBegan) - : m_fundingOpretScript(opRetScript), m_latesttxid(latesttxid), m_isHeirSpendingBegan(isHeirSpendingBegan), CValidatorBase(cp) {} - - virtual bool isVinValidator() const { return false; } - virtual bool validateVout(CTxOut vout, std::string& message) const - { - //std::cerr << "CHeirSpendValidator::validateVout() entered" << std::endl; - - CPubKey ownerPubkey, heirPubkey; - int64_t inactivityTime; - std::string heirName; - uint256 tokenid; - - // get heir pubkey: - uint8_t funcId = DecodeHeirEitherOpRet(m_fundingOpretScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, true); - if (funcId == 0) { - message = std::string("invalid opreturn format"); - return false; - } - - int32_t numblocks; - int64_t durationSec = CCduration(numblocks, m_latesttxid); - - // recreate scriptPubKey for heir and compare it with that of the vout: - if (vout.scriptPubKey == Helper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey) { - // this is the heir is trying to spend - if (!m_isHeirSpendingBegan && durationSec <= inactivityTime) { - message = "heir is not allowed yet to spend funds"; - std::cerr << "CHeirSpendValidator::validateVout() heir is not allowed yet to spend funds" << std::endl; - return false; - } - else { - // heir is allowed to spend - return true; - } - } - - //std::cerr << "CHeirSpendValidator::validateVout() exits with true" << std::endl; - - // this is not heir: - return true; - } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } - + CHeirSpendValidator(CCcontract_info* cp, CScript opRetScript, uint256 latesttxid, uint8_t isHeirSpendingBegan) + : m_fundingOpretScript(opRetScript), m_latesttxid(latesttxid), m_isHeirSpendingBegan(isHeirSpendingBegan), CValidatorBase(cp) {} + + virtual bool isVinValidator() const { return false; } + virtual bool validateVout(CTxOut vout, std::string& message) const + { + //std::cerr << "CHeirSpendValidator::validateVout() entered" << std::endl; + + CPubKey ownerPubkey, heirPubkey; + int64_t inactivityTime; + std::string heirName; + uint256 tokenid; + + // get heir pubkey: + uint8_t funcId = DecodeHeirEitherOpRet(m_fundingOpretScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, true); + if (funcId == 0) { + message = std::string("invalid opreturn format"); + return false; + } + + int32_t numblocks; + int64_t durationSec = CCduration(numblocks, m_latesttxid); + + // recreate scriptPubKey for heir and compare it with that of the vout: + if (vout.scriptPubKey == Helper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey) { + // this is the heir is trying to spend + if (!m_isHeirSpendingBegan && durationSec <= inactivityTime) { + message = "heir is not allowed yet to spend funds"; + std::cerr << "CHeirSpendValidator::validateVout() heir is not allowed yet to spend funds" << std::endl; + return false; + } + else { + // heir is allowed to spend + return true; + } + } + + //std::cerr << "CHeirSpendValidator::validateVout() exits with true" << std::endl; + + // this is not heir: + return true; + } + virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } + private: - CScript m_fundingOpretScript; - uint256 m_latesttxid; - uint8_t m_isHeirSpendingBegan; + CScript m_fundingOpretScript; + uint256 m_latesttxid; + uint8_t m_isHeirSpendingBegan; }; /** -* Validates this opreturn and compares it with the opreturn from the previous tx -*/ + * Validates this opreturn and compares it with the opreturn from the previous tx + */ template class COpRetValidator : CValidatorBase { public: - COpRetValidator(CC_info* cp, CScript opret) - : m_fundingOpretScript(opret), CValidatorBase(cp) {} - - virtual bool isVinValidator() const { return false; } - virtual bool validateVout(CTxOut vout, std::string& message) const - { - //std::cerr << "COpRetValidator::validateVout() entered" << std::endl; - - uint256 fundingTxidInOpret = zeroid, dummyTxid, tokenid = zeroid, initialTokenid = zeroid; - uint8_t dummyIsHeirSpendingBegan; - - uint8_t funcId = DecodeHeirEitherOpRet(vout.scriptPubKey, tokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan, true); - if (funcId == 0) { - message = std::string("invalid opreturn format"); - return false; - } - - uint8_t initialFuncId = DecodeHeirEitherOpRet(m_fundingOpretScript, initialTokenid, dummyTxid, dummyIsHeirSpendingBegan, true); - if (initialFuncId == 0) { - message = std::string("invalid initial tx opreturn format"); - return false; - } - - // validation rules: - if (!isMyFuncId(funcId)) { - message = std::string("invalid funcid in opret"); - return false; - } - - if (typeid(Helper) == typeid(TokenHelper)) { - if (tokenid != initialTokenid) { - message = std::string("invalid tokenid in opret"); - return false; - } - } - - //std::cerr << "COpRetValidator::validateVout() exits with true" << std::endl; - return true; - } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } - + COpRetValidator(CCcontract_info* cp, CScript opret) + : m_fundingOpretScript(opret), CValidatorBase(cp) {} + + virtual bool isVinValidator() const { return false; } + virtual bool validateVout(CTxOut vout, std::string& message) const + { + //std::cerr << "COpRetValidator::validateVout() entered" << std::endl; + + uint256 fundingTxidInOpret = zeroid, dummyTxid, tokenid = zeroid, initialTokenid = zeroid; + uint8_t dummyIsHeirSpendingBegan; + + uint8_t funcId = DecodeHeirEitherOpRet(vout.scriptPubKey, tokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan, true); + if (funcId == 0) { + message = std::string("invalid opreturn format"); + return false; + } + + uint8_t initialFuncId = DecodeHeirEitherOpRet(m_fundingOpretScript, initialTokenid, dummyTxid, dummyIsHeirSpendingBegan, true); + if (initialFuncId == 0) { + message = std::string("invalid initial tx opreturn format"); + return false; + } + + // validation rules: + if (!isMyFuncId(funcId)) { + message = std::string("invalid funcid in opret"); + return false; + } + + if (typeid(Helper) == typeid(TokenHelper)) { + if (tokenid != initialTokenid) { + message = std::string("invalid tokenid in opret"); + return false; + } + } + + //std::cerr << "COpRetValidator::validateVout() exits with true" << std::endl; + return true; + } + virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } + private: - CScript m_fundingOpretScript; + CScript m_fundingOpretScript; }; /** -* empty validator always returns true -*/ + * empty validator always returns true + */ template class CNullValidator : CValidatorBase { public: - CNullValidator(CC_info* cp) - : CValidatorBase(cp) { } - - virtual bool isVinValidator() const { return false; } - virtual bool validateVout(CTxOut vout, std::string& message) const { return true; } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } + CNullValidator(CCcontract_info* cp) + : CValidatorBase(cp) { } + + virtual bool isVinValidator() const { return false; } + virtual bool validateVout(CTxOut vout, std::string& message) const { return true; } + virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } }; diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 641d0a4d2..f7f663db2 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -45,14 +45,14 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, key = *pprivKey; else if (!keystore || !keystore->GetKey(address, key)) return false; - + uint256 hash; try { hash = SignatureHash(scriptCode, *txTo, nIn, nHashType, amount, consensusBranchId); } catch (logic_error ex) { return false; } - + if (scriptCode.IsPayToCryptoCondition()) { CC *cc = (CC *)extraData; @@ -75,9 +75,9 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, return false; } } - + vchSig.push_back((unsigned char)nHashType); - + return true; } @@ -128,7 +128,7 @@ std::vector &GetCryptoConditions() static bool initialized = false; static std::vector vCC = std::vector(); CCcontract_info C; - + if (!initialized) { // this should initialize any desired auto-signed crypto-conditions @@ -140,7 +140,7 @@ bool GetCCByUnspendableAddress(struct CC_info *cp, char *addrstr) { std::vector &vCC = GetCryptoConditions(); bool found = false; - + for (int i = 0; i < vCC.size(); i++) { if (strcmp(addrstr, vCC[i].unspendableCCaddr) == 0) @@ -157,7 +157,7 @@ bool CCinitLite(struct CC_info *cp, uint8_t evalcode) { std::vector &vCC = GetCryptoConditions(); bool found = false; - + for (int i = 0; i < vCC.size(); i++) { if (vCC[i].evalcode == evalcode) @@ -172,7 +172,7 @@ bool CCinitLite(struct CC_info *cp, uint8_t evalcode) bool _Getscriptaddress(char *destaddr, const CScript &scriptPubKey) { - CTxDestination address; + CTxDestination address; txnouttype whichType; std::vector> vvch = std::vector>(); if (Solver(scriptPubKey, whichType, vvch) && vvch[0].size() == 20) @@ -199,10 +199,10 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip vector vPK; vector vParams = vector(); COptCCParams p; - + // get information to sign with CCcontract_info C; - + scriptPubKey.IsPayToCryptoCondition(&subScript, vParams); if (vParams.empty()) { @@ -219,12 +219,12 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip { p = COptCCParams(vParams[0]); } - + if (p.IsValid() && p.vKeys.size() >= p.n) { bool is1of2 = (p.m == 1 && p.n == 2); CKey privKey; - + // must be a valid cc eval code if (CCinitLite(&C, p.evalCode)) { @@ -232,7 +232,7 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip if (!is1of2) { bool havePriv = creator.KeyStore().GetKey(p.vKeys[0].GetID(), privKey); - + // if we don't have the private key, it must be the unspendable address if (!havePriv && (p.vKeys[0] == CPubKey(ParseHex(C.CChexstr)))) { @@ -240,9 +240,9 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip std::vector vch(&(C.CCpriv[0]), C.CCpriv + sizeof(C.CCpriv)); privKey.Set(vch.begin(), vch.end(), false); } - + CC *cc = CCcond1(p.evalCode, p.vKeys[0]); - + if (cc) { vector vch; @@ -254,7 +254,7 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip { fprintf(stderr,"vin has 1of1 CC signing error with address.(%s)\n", p.vKeys[0].GetID().ToString().c_str()); } - + cc_free(cc); return ret.size() != 0; } @@ -266,7 +266,7 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip { if (creator.IsKeystoreValid() && creator.KeyStore().GetKey(pk.GetID(), privKey) && privKey.IsValid()) break; - + if (pk == CPubKey(ParseHex(C.CChexstr))) { privKey = CKey(); @@ -275,12 +275,12 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip break; } } - + if (!privKey.IsValid()) return false; - + CC *cc = CCcond1of2(p.evalCode, p.vKeys[0], p.vKeys[1]); - + if (cc) { vector vch; @@ -292,7 +292,7 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip { fprintf(stderr,"vin has 1of2 CC signing error with addresses.(%s)\n(%s)\n", p.vKeys[0].GetID().ToString().c_str(), p.vKeys[1].GetID().ToString().c_str()); } - + cc_free(cc); return ret.size() != 0; } @@ -314,9 +314,9 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP CScript scriptRet; uint160 h160; ret.clear(); - + vector vSolutions; - + if (!Solver(scriptPubKey, whichTypeRet, vSolutions)) { // if this is a CLTV script, solve for the destination after CLTV @@ -324,10 +324,10 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP { uint8_t pushOp = scriptPubKey[0]; uint32_t scriptStart = pushOp + 3; - + // check post CLTV script CScript postfix = CScript(scriptPubKey.size() > scriptStart ? scriptPubKey.begin() + scriptStart : scriptPubKey.end(), scriptPubKey.end()); - + // check again with only postfix subscript if (!Solver(postfix, whichTypeRet, vSolutions)) return false; @@ -335,44 +335,44 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP else return false; } - + CKeyID keyID; - + switch (whichTypeRet) { - case TX_NONSTANDARD: - case TX_NULL_DATA: - return false; - case TX_PUBKEY: - keyID = CPubKey(vSolutions[0]).GetID(); - return Sign1(keyID, creator, scriptPubKey, ret, consensusBranchId); - case TX_PUBKEYHASH: - keyID = CKeyID(uint160(vSolutions[0])); - if (!Sign1(keyID, creator, scriptPubKey, ret, consensusBranchId)) + case TX_NONSTANDARD: + case TX_NULL_DATA: return false; - else - { - CPubKey vch; - creator.KeyStore().GetPubKey(keyID, vch); - ret.push_back(ToByteVector(vch)); - } - return true; - case TX_SCRIPTHASH: - if (creator.KeyStore().GetCScript(uint160(vSolutions[0]), scriptRet)) { - ret.push_back(std::vector(scriptRet.begin(), scriptRet.end())); + case TX_PUBKEY: + keyID = CPubKey(vSolutions[0]).GetID(); + return Sign1(keyID, creator, scriptPubKey, ret, consensusBranchId); + case TX_PUBKEYHASH: + keyID = CKeyID(uint160(vSolutions[0])); + if (!Sign1(keyID, creator, scriptPubKey, ret, consensusBranchId)) + return false; + else + { + CPubKey vch; + creator.KeyStore().GetPubKey(keyID, vch); + ret.push_back(ToByteVector(vch)); + } return true; - } - return false; - - case TX_CRYPTOCONDITION: - return SignStepCC(creator, scriptPubKey, vSolutions, ret, consensusBranchId); - - case TX_MULTISIG: - ret.push_back(valtype()); // workaround CHECKMULTISIG bug - return (SignN(vSolutions, creator, scriptPubKey, ret, consensusBranchId)); - - default: - return false; + case TX_SCRIPTHASH: + if (creator.KeyStore().GetCScript(uint160(vSolutions[0]), scriptRet)) { + ret.push_back(std::vector(scriptRet.begin(), scriptRet.end())); + return true; + } + return false; + + case TX_CRYPTOCONDITION: + return SignStepCC(creator, scriptPubKey, vSolutions, ret, consensusBranchId); + + case TX_MULTISIG: + ret.push_back(valtype()); // workaround CHECKMULTISIG bug + return (SignN(vSolutions, creator, scriptPubKey, ret, consensusBranchId)); + + default: + return false; } } @@ -399,7 +399,7 @@ bool ProduceSignature(const BaseSignatureCreator& creator, const CScript& fromPu txnouttype whichType; solved = SignStep(creator, script, result, whichType, consensusBranchId); CScript subscript; - + if (solved && whichType == TX_SCRIPTHASH) { // Solver returns the subscript that needs to be evaluated; @@ -409,9 +409,9 @@ bool ProduceSignature(const BaseSignatureCreator& creator, const CScript& fromPu solved = solved && SignStep(creator, script, result, whichType, consensusBranchId) && whichType != TX_SCRIPTHASH; result.push_back(std::vector(subscript.begin(), subscript.end())); } - + sigdata.scriptSig = PushAll(result); - + // Test solution return solved && VerifyScript(sigdata.scriptSig, fromPubKey, STANDARD_SCRIPT_VERIFY_FLAGS, creator.Checker(), consensusBranchId); } @@ -431,19 +431,19 @@ void UpdateTransaction(CMutableTransaction& tx, unsigned int nIn, const Signatur } bool SignSignature( - const CKeyStore &keystore, - const CScript& fromPubKey, - CMutableTransaction& txTo, - unsigned int nIn, - const CAmount& amount, - int nHashType, - uint32_t consensusBranchId) + const CKeyStore &keystore, + const CScript& fromPubKey, + CMutableTransaction& txTo, + unsigned int nIn, + const CAmount& amount, + int nHashType, + uint32_t consensusBranchId) { assert(nIn < txTo.vin.size()); - + CTransaction txToConst(txTo); TransactionSignatureCreator creator(&keystore, &txToConst, nIn, amount, nHashType); - + SignatureData sigdata; bool ret = ProduceSignature(creator, fromPubKey, sigdata, consensusBranchId); UpdateTransaction(txTo, nIn, sigdata); @@ -451,24 +451,24 @@ bool SignSignature( } bool SignSignature( - const CKeyStore &keystore, - const CTransaction& txFrom, - CMutableTransaction& txTo, - unsigned int nIn, - int nHashType, - uint32_t consensusBranchId) + const CKeyStore &keystore, + const CTransaction& txFrom, + CMutableTransaction& txTo, + unsigned int nIn, + int nHashType, + uint32_t consensusBranchId) { assert(nIn < txTo.vin.size()); CTxIn& txin = txTo.vin[nIn]; assert(txin.prevout.n < txFrom.vout.size()); const CTxOut& txout = txFrom.vout[txin.prevout.n]; - + return SignSignature(keystore, txout.scriptPubKey, txTo, nIn, txout.nValue, nHashType, consensusBranchId); } static vector CombineMultisig(const CScript& scriptPubKey, const BaseSignatureChecker& checker, - const vector& vSolutions, - const vector& sigs1, const vector& sigs2, uint32_t consensusBranchId) + const vector& vSolutions, + const vector& sigs1, const vector& sigs2, uint32_t consensusBranchId) { // Combine all the signatures we've got: set allsigs; @@ -482,7 +482,7 @@ static vector CombineMultisig(const CScript& scriptPubKey, const BaseSi if (!v.empty()) allsigs.insert(v); } - + // Build a map of pubkey -> signature by matching sigs to pubkeys: assert(vSolutions.size() > 1); unsigned int nSigsRequired = vSolutions.front()[0]; @@ -495,7 +495,7 @@ static vector CombineMultisig(const CScript& scriptPubKey, const BaseSi const valtype& pubkey = vSolutions[i+1]; if (sigs.count(pubkey)) continue; // Already got a sig for this pubkey - + if (checker.CheckSig(sig, pubkey, scriptPubKey, consensusBranchId)) { sigs[pubkey] = sig; @@ -517,108 +517,108 @@ static vector CombineMultisig(const CScript& scriptPubKey, const BaseSi // Fill any missing with OP_0: for (unsigned int i = nSigsHave; i < nSigsRequired; i++) result.push_back(valtype()); - + return result; } namespace { -struct Stacks -{ - std::vector script; - - Stacks() {} - explicit Stacks(const std::vector& scriptSigStack_) : script(scriptSigStack_) {} - explicit Stacks(const SignatureData& data, uint32_t consensusBranchId) { - EvalScript(script, data.scriptSig, SCRIPT_VERIFY_STRICTENC, BaseSignatureChecker(), consensusBranchId); - } - - SignatureData Output() const { - SignatureData result; - result.scriptSig = PushAll(script); - return result; - } -}; + struct Stacks + { + std::vector script; + + Stacks() {} + explicit Stacks(const std::vector& scriptSigStack_) : script(scriptSigStack_) {} + explicit Stacks(const SignatureData& data, uint32_t consensusBranchId) { + EvalScript(script, data.scriptSig, SCRIPT_VERIFY_STRICTENC, BaseSignatureChecker(), consensusBranchId); + } + + SignatureData Output() const { + SignatureData result; + result.scriptSig = PushAll(script); + return result; + } + }; } static Stacks CombineSignatures(const CScript& scriptPubKey, const BaseSignatureChecker& checker, - const txnouttype txType, const vector& vSolutions, - Stacks sigs1, Stacks sigs2, uint32_t consensusBranchId) + const txnouttype txType, const vector& vSolutions, + Stacks sigs1, Stacks sigs2, uint32_t consensusBranchId) { switch (txType) { - case TX_NONSTANDARD: - case TX_NULL_DATA: - // Don't know anything about this, assume bigger one is correct: - if (sigs1.script.size() >= sigs2.script.size()) - return sigs1; - return sigs2; - case TX_PUBKEY: - case TX_PUBKEYHASH: - case TX_CRYPTOCONDITION: - // Signatures are bigger than placeholders or empty scripts: - if (sigs1.script.empty() || sigs1.script[0].empty()) + case TX_NONSTANDARD: + case TX_NULL_DATA: + // Don't know anything about this, assume bigger one is correct: + if (sigs1.script.size() >= sigs2.script.size()) + return sigs1; return sigs2; - return sigs1; - case TX_SCRIPTHASH: - if (sigs1.script.empty() || sigs1.script.back().empty()) - return sigs2; - else if (sigs2.script.empty() || sigs2.script.back().empty()) + case TX_PUBKEY: + case TX_PUBKEYHASH: + case TX_CRYPTOCONDITION: + // Signatures are bigger than placeholders or empty scripts: + if (sigs1.script.empty() || sigs1.script[0].empty()) + return sigs2; return sigs1; - else - { - // Recur to combine: - valtype spk = sigs1.script.back(); - CScript pubKey2(spk.begin(), spk.end()); - - txnouttype txType2; - vector > vSolutions2; - Solver(pubKey2, txType2, vSolutions2); - sigs1.script.pop_back(); - sigs2.script.pop_back(); - Stacks result = CombineSignatures(pubKey2, checker, txType2, vSolutions2, sigs1, sigs2, consensusBranchId); - result.script.push_back(spk); - return result; - } - case TX_MULTISIG: - return Stacks(CombineMultisig(scriptPubKey, checker, vSolutions, sigs1.script, sigs2.script, consensusBranchId)); - default: - return Stacks(); + case TX_SCRIPTHASH: + if (sigs1.script.empty() || sigs1.script.back().empty()) + return sigs2; + else if (sigs2.script.empty() || sigs2.script.back().empty()) + return sigs1; + else + { + // Recur to combine: + valtype spk = sigs1.script.back(); + CScript pubKey2(spk.begin(), spk.end()); + + txnouttype txType2; + vector > vSolutions2; + Solver(pubKey2, txType2, vSolutions2); + sigs1.script.pop_back(); + sigs2.script.pop_back(); + Stacks result = CombineSignatures(pubKey2, checker, txType2, vSolutions2, sigs1, sigs2, consensusBranchId); + result.script.push_back(spk); + return result; + } + case TX_MULTISIG: + return Stacks(CombineMultisig(scriptPubKey, checker, vSolutions, sigs1.script, sigs2.script, consensusBranchId)); + default: + return Stacks(); } } SignatureData CombineSignatures(const CScript& scriptPubKey, const BaseSignatureChecker& checker, - const SignatureData& scriptSig1, const SignatureData& scriptSig2, - uint32_t consensusBranchId) + const SignatureData& scriptSig1, const SignatureData& scriptSig2, + uint32_t consensusBranchId) { txnouttype txType; vector > vSolutions; Solver(scriptPubKey, txType, vSolutions); - + return CombineSignatures( - scriptPubKey, checker, txType, vSolutions, - Stacks(scriptSig1, consensusBranchId), - Stacks(scriptSig2, consensusBranchId), - consensusBranchId).Output(); + scriptPubKey, checker, txType, vSolutions, + Stacks(scriptSig1, consensusBranchId), + Stacks(scriptSig2, consensusBranchId), + consensusBranchId).Output(); } namespace { -/** Dummy signature checker which accepts all signatures. */ -class DummySignatureChecker : public BaseSignatureChecker -{ -public: - DummySignatureChecker() {} - - bool CheckSig( - const std::vector& scriptSig, - const std::vector& vchPubKey, - const CScript& scriptCode, - uint32_t consensusBranchId) const + /** Dummy signature checker which accepts all signatures. */ + class DummySignatureChecker : public BaseSignatureChecker { - return true; - } -}; -const DummySignatureChecker dummyChecker; + public: + DummySignatureChecker() {} + + bool CheckSig( + const std::vector& scriptSig, + const std::vector& vchPubKey, + const CScript& scriptCode, + uint32_t consensusBranchId) const + { + return true; + } + }; + const DummySignatureChecker dummyChecker; } const BaseSignatureChecker& DummySignatureCreator::Checker() const @@ -627,12 +627,12 @@ const BaseSignatureChecker& DummySignatureCreator::Checker() const } bool DummySignatureCreator::CreateSig( - std::vector& vchSig, - const CKeyID& keyid, - const CScript& scriptCode, - uint32_t consensusBranchId, - CKey *key, - void *extraData) const + std::vector& vchSig, + const CKeyID& keyid, + const CScript& scriptCode, + uint32_t consensusBranchId, + CKey *key, + void *extraData) const { // Create a dummy signature that is a valid DER-encoding vchSig.assign(72, '\000'); @@ -647,3 +647,4 @@ bool DummySignatureCreator::CreateSig( vchSig[6 + 33 + 32] = SIGHASH_ALL; return true; } + From 4ad5879f56900e1fe9de6b26c60a11e2892d8da2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 23:13:59 -1100 Subject: [PATCH 553/643] struct CC_info --- src/cc/heir.cpp | 1611 ++++++++++++++++++++++++----------------------- 1 file changed, 806 insertions(+), 805 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 499fb598d..7867032b6 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -21,14 +21,14 @@ class TokenHelper; /* The idea of Heir CC is to allow crypto inheritance. - A special 1of2 CC address is created that is freely spendable by the creator (funds owner). + A special 1of2 CC address is created that is freely spendable by the creator (funds owner). The owner may add additional funds to this 1of2 address. - The heir is only allowed to spend after "the specified amount of idle blocks" (changed to "the owner inactivityTime"). - The idea is that if the address doesnt spend any funds for a year (or whatever amount set), then it is time to allow the heir to spend. + The heir is only allowed to spend after "the specified amount of idle blocks" (changed to "the owner inactivityTime"). + The idea is that if the address doesnt spend any funds for a year (or whatever amount set), then it is time to allow the heir to spend. "The design requires the heir to spend all the funds at once" (this requirement was changed to "after the inactivity time both the heir and owner may freely spend available funds") After the first heir spending a flag is set that spending is allowed for the heir whether the owner adds more funds or spends them. This Heir contract supports both coins and tokens. -*/ + */ // tx validation code @@ -36,69 +36,69 @@ class TokenHelper; // (sadly we cannot have yet 'templatized' lambdas, if we could we could capture all these params inside HeirValidation()...) template bool RunValidationPlans(uint8_t funcId, struct CC_info* cp, Eval* eval, const CTransaction& tx, uint256 latestTxid, CScript fundingOpretScript, uint8_t hasHeirSpendingBegun) { - int32_t numvins = tx.vin.size(); - int32_t numvouts = tx.vout.size(); - - // setup validation framework (please see its description in heir_validate.h): - // validation 'plans': - CInputValidationPlan vinPlan; - COutputValidationPlan voutPlan; - - // vin 'identifiers' - CNormalInputIdentifier normalInputIdentifier(cp); - CCCInputIdentifier ccInputIdentifier(cp); - - // vin and vout 'validators' - // not used, too strict for 2 pubkeys: CMyPubkeyVoutValidator normalInputValidator(cp, fundingOpretScript, true); // check normal input for this opret cause this is first tx - CCC1of2AddressValidator cc1of2ValidatorThis(cp, fundingOpretScript, "checking this tx opreturn:"); // 1of2add validator with pubkeys from this tx opreturn - CHeirSpendValidator heirSpendValidator(cp, fundingOpretScript, latestTxid, hasHeirSpendingBegun); // check if heir allowed to spend - - // only for tokens: - CMyPubkeyVoutValidator ownerCCaddrValidator(cp, fundingOpretScript, false); // check if this correct owner's cc user addr corresponding to opret - COpRetValidator opRetValidator(cp, fundingOpretScript); // compare opRets in this and last tx - CNullValidator nullValidator(cp); - - switch (funcId) { - case 'F': // fund tokens - // vin validation plan: - vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &nullValidator); // txfee vin - vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &ownerCCaddrValidator); // check cc owner addr - - // vout validation plan: - voutPlan.pushValidators(0, &cc1of2ValidatorThis); // check 1of2 addr funding - // do not check change at this time - // no checking for opret yet - break; - - case 'A': // add tokens - // vin validation plan: - vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &nullValidator); // txfee vin - vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &ownerCCaddrValidator); // check cc owner addr - - // vout validation plan: - voutPlan.pushValidators(0, &cc1of2ValidatorThis); // check 1of2 addr funding - // do not check change at this time - voutPlan.pushValidators(numvouts - 1, &opRetValidator); // opreturn check, NOTE: only for C or A: - break; - - case 'C': - // vin validation plan: - vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &nullValidator); // txfee vin - vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &cc1of2ValidatorThis); // cc1of2 funding addr - - // vout validation plan: - voutPlan.pushValidators(0, &heirSpendValidator); // check if heir is allowed to spend - voutPlan.pushValidators(numvouts - 1, &opRetValidator); // opreturn check, NOTE: only for C or A - break; - } - - // call vin/vout validation - if (!vinPlan.validate(tx, eval)) - return false; - if (!voutPlan.validate(tx, eval)) - return false; - - return true; + int32_t numvins = tx.vin.size(); + int32_t numvouts = tx.vout.size(); + + // setup validation framework (please see its description in heir_validate.h): + // validation 'plans': + CInputValidationPlan vinPlan; + COutputValidationPlan voutPlan; + + // vin 'identifiers' + CNormalInputIdentifier normalInputIdentifier(cp); + CCCInputIdentifier ccInputIdentifier(cp); + + // vin and vout 'validators' + // not used, too strict for 2 pubkeys: CMyPubkeyVoutValidator normalInputValidator(cp, fundingOpretScript, true); // check normal input for this opret cause this is first tx + CCC1of2AddressValidator cc1of2ValidatorThis(cp, fundingOpretScript, "checking this tx opreturn:"); // 1of2add validator with pubkeys from this tx opreturn + CHeirSpendValidator heirSpendValidator(cp, fundingOpretScript, latestTxid, hasHeirSpendingBegun); // check if heir allowed to spend + + // only for tokens: + CMyPubkeyVoutValidator ownerCCaddrValidator(cp, fundingOpretScript, false); // check if this correct owner's cc user addr corresponding to opret + COpRetValidator opRetValidator(cp, fundingOpretScript); // compare opRets in this and last tx + CNullValidator nullValidator(cp); + + switch (funcId) { + case 'F': // fund tokens + // vin validation plan: + vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &nullValidator); // txfee vin + vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &ownerCCaddrValidator); // check cc owner addr + + // vout validation plan: + voutPlan.pushValidators(0, &cc1of2ValidatorThis); // check 1of2 addr funding + // do not check change at this time + // no checking for opret yet + break; + + case 'A': // add tokens + // vin validation plan: + vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &nullValidator); // txfee vin + vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &ownerCCaddrValidator); // check cc owner addr + + // vout validation plan: + voutPlan.pushValidators(0, &cc1of2ValidatorThis); // check 1of2 addr funding + // do not check change at this time + voutPlan.pushValidators(numvouts - 1, &opRetValidator); // opreturn check, NOTE: only for C or A: + break; + + case 'C': + // vin validation plan: + vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &nullValidator); // txfee vin + vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &cc1of2ValidatorThis); // cc1of2 funding addr + + // vout validation plan: + voutPlan.pushValidators(0, &heirSpendValidator); // check if heir is allowed to spend + voutPlan.pushValidators(numvouts - 1, &opRetValidator); // opreturn check, NOTE: only for C or A + break; + } + + // call vin/vout validation + if (!vinPlan.validate(tx, eval)) + return false; + if (!voutPlan.validate(tx, eval)) + return false; + + return true; } /** @@ -110,121 +110,121 @@ bool HeirValidate(struct CC_info* cpHeir, Eval* eval, const CTransaction& tx, ui int32_t numvouts = tx.vout.size(); //int32_t preventCCvins = -1; //int32_t preventCCvouts = -1; - - struct CC_info *cpTokens, tokensC; - cpTokens = CCinit(&tokensC, EVAL_TOKENS); - + + struct CC_info *cpTokens, tokensC; + cpTokens = CCinit(&tokensC, EVAL_TOKENS); + if (numvouts < 1) return eval->Invalid("no vouts"); - - //if (chainActive.Height() < 741) - // return true; - + + //if (chainActive.Height() < 741) + // return true; + uint256 fundingTxidInOpret = zeroid, latestTxid = zeroid, dummyTokenid, tokenidThis, tokenid = zeroid; - CScript fundingTxOpRetScript; - uint8_t hasHeirSpendingBegun = 0, hasHeirSpendingBegunDummy; - - CScript opret = (tx.vout.size() > 0) ? tx.vout[tx.vout.size() - 1].scriptPubKey : CScript(); // check boundary - uint8_t funcId = DecodeHeirEitherOpRet(opret, tokenidThis, fundingTxidInOpret, hasHeirSpendingBegunDummy, true); - if (funcId == 0) + CScript fundingTxOpRetScript; + uint8_t hasHeirSpendingBegun = 0, hasHeirSpendingBegunDummy; + + CScript opret = (tx.vout.size() > 0) ? tx.vout[tx.vout.size() - 1].scriptPubKey : CScript(); // check boundary + uint8_t funcId = DecodeHeirEitherOpRet(opret, tokenidThis, fundingTxidInOpret, hasHeirSpendingBegunDummy, true); + if (funcId == 0) return eval->Invalid("invalid opreturn format"); - + if (funcId != 'F') { if (fundingTxidInOpret == zeroid) { return eval->Invalid("incorrect tx opreturn: no fundingtxid present"); } - latestTxid = FindLatestFundingTx(fundingTxidInOpret, tokenid, fundingTxOpRetScript, hasHeirSpendingBegun); - - if( tokenid != zeroid && tokenid != tokenidThis ) - return eval->Invalid("incorrect tx tokenid"); - - if (latestTxid == zeroid) { + latestTxid = FindLatestFundingTx(fundingTxidInOpret, tokenid, fundingTxOpRetScript, hasHeirSpendingBegun); + + if( tokenid != zeroid && tokenid != tokenidThis ) + return eval->Invalid("incorrect tx tokenid"); + + if (latestTxid == zeroid) { return eval->Invalid("no fundingtx found"); } - } - else { - fundingTxOpRetScript = opret; - } - - std::cerr << "HeirValidate funcid=" << (char)funcId << " evalcode=" << (int)cpHeir->evalcode << std::endl; - - //////////////// temp //////////////////////// - ///return true; - + } + else { + fundingTxOpRetScript = opret; + } + + std::cerr << "HeirValidate funcid=" << (char)funcId << " evalcode=" << (int)cpHeir->evalcode << std::endl; + + //////////////// temp //////////////////////// + ///return true; + switch (funcId) { - case 'F': - // fund coins: - // vins.*: normal inputs - // ----------------------------- - // vout.0: funding CC 1of2 addr for the owner and heir - // vout.1: txfee for CC addr used as a marker - // vout.2: normal change - // vout.n-1: opreturn 'F' ownerpk heirpk inactivitytime heirname - - // fund tokens: - // vin.0: normal inputs txfee - // vins.1+: user's CC addr inputs - // ----------------------- - // vout.0: funding heir CC 1of2 addr for the owner and heir - // vout.1: txfee for CC addr used as a marker - // vout.2: normal change - // vout.n-1: opreturn 't' tokenid 'F' ownerpk heirpk inactivitytime heirname tokenid - if (tokenid != zeroid) - return RunValidationPlans(funcId, cpTokens, eval, tx, latestTxid, fundingTxOpRetScript, hasHeirSpendingBegun); - else - return eval->Invalid("unexpected HeirValidate for heirfund"); - // break; - - case 'A': - // add funding coins: - // vins.*: normal inputs - // ------------------------ - // vout.0: funding CC 1of2 addr for the owner and heir - // vout.1: normal change - // vout.n-1: opreturn 'A' ownerpk heirpk inactivitytime fundingtx - - // add funding tokens: - // vins.0: normal inputs txfee - // vins.1+: user's CC addr inputs - // ------------------------ - // vout.0: funding CC 1of2 addr for the owner and heir - // vout.1: normal change - // vout.n-1: opreturn 't' tokenid 'A' ownerpk heirpk inactivitytime fundingtx - if (tokenid != zeroid) - return RunValidationPlans(funcId, cpTokens, eval, tx, latestTxid, fundingTxOpRetScript, hasHeirSpendingBegun); - else - return eval->Invalid("unexpected HeirValidate for heiradd"); - //break; - - case 'C': - // claim coins: - // vin.0: normal input txfee - // vin.1+: input from CC 1of2 addr - // ------------------------------------- - // vout.0: normal output to owner or heir address - // vout.1: change to CC 1of2 addr - // vout.2: change to user's addr from txfee input if any - // vout.n-1: opreturn 'C' ownerpk heirpk inactivitytime fundingtx - - // claim tokens: - // vin.0: normal input txfee - // vin.1+: input from CC 1of2 addr - // -------------------------------------------- - // vout.0: output to user's cc address - // vout.1: change to CC 1of2 addr - // vout.2: change to normal from txfee input if any - // vout.n-1: opreturn 't' tokenid 'C' ownerpk heirpk inactivitytime fundingtx - if (tokenid != zeroid) - return RunValidationPlans(funcId, cpTokens, eval, tx, latestTxid, fundingTxOpRetScript, hasHeirSpendingBegun); - else - return RunValidationPlans(funcId, cpHeir, eval, tx, latestTxid, fundingTxOpRetScript, hasHeirSpendingBegun); - // break; - - default: - std::cerr << "HeirValidate() illegal heir funcid=" << (char)funcId << std::endl; - return eval->Invalid("unexpected HeirValidate funcid"); - // break; + case 'F': + // fund coins: + // vins.*: normal inputs + // ----------------------------- + // vout.0: funding CC 1of2 addr for the owner and heir + // vout.1: txfee for CC addr used as a marker + // vout.2: normal change + // vout.n-1: opreturn 'F' ownerpk heirpk inactivitytime heirname + + // fund tokens: + // vin.0: normal inputs txfee + // vins.1+: user's CC addr inputs + // ----------------------- + // vout.0: funding heir CC 1of2 addr for the owner and heir + // vout.1: txfee for CC addr used as a marker + // vout.2: normal change + // vout.n-1: opreturn 't' tokenid 'F' ownerpk heirpk inactivitytime heirname tokenid + if (tokenid != zeroid) + return RunValidationPlans(funcId, cpTokens, eval, tx, latestTxid, fundingTxOpRetScript, hasHeirSpendingBegun); + else + return eval->Invalid("unexpected HeirValidate for heirfund"); + // break; + + case 'A': + // add funding coins: + // vins.*: normal inputs + // ------------------------ + // vout.0: funding CC 1of2 addr for the owner and heir + // vout.1: normal change + // vout.n-1: opreturn 'A' ownerpk heirpk inactivitytime fundingtx + + // add funding tokens: + // vins.0: normal inputs txfee + // vins.1+: user's CC addr inputs + // ------------------------ + // vout.0: funding CC 1of2 addr for the owner and heir + // vout.1: normal change + // vout.n-1: opreturn 't' tokenid 'A' ownerpk heirpk inactivitytime fundingtx + if (tokenid != zeroid) + return RunValidationPlans(funcId, cpTokens, eval, tx, latestTxid, fundingTxOpRetScript, hasHeirSpendingBegun); + else + return eval->Invalid("unexpected HeirValidate for heiradd"); + //break; + + case 'C': + // claim coins: + // vin.0: normal input txfee + // vin.1+: input from CC 1of2 addr + // ------------------------------------- + // vout.0: normal output to owner or heir address + // vout.1: change to CC 1of2 addr + // vout.2: change to user's addr from txfee input if any + // vout.n-1: opreturn 'C' ownerpk heirpk inactivitytime fundingtx + + // claim tokens: + // vin.0: normal input txfee + // vin.1+: input from CC 1of2 addr + // -------------------------------------------- + // vout.0: output to user's cc address + // vout.1: change to CC 1of2 addr + // vout.2: change to normal from txfee input if any + // vout.n-1: opreturn 't' tokenid 'C' ownerpk heirpk inactivitytime fundingtx + if (tokenid != zeroid) + return RunValidationPlans(funcId, cpTokens, eval, tx, latestTxid, fundingTxOpRetScript, hasHeirSpendingBegun); + else + return RunValidationPlans(funcId, cpHeir, eval, tx, latestTxid, fundingTxOpRetScript, hasHeirSpendingBegun); + // break; + + default: + std::cerr << "HeirValidate() illegal heir funcid=" << (char)funcId << std::endl; + return eval->Invalid("unexpected HeirValidate funcid"); + // break; } return eval->Invalid("unexpected"); // (PreventCC(eval, tx, preventCCvins, numvins, preventCCvouts, numvouts)); } @@ -234,194 +234,194 @@ bool HeirValidate(struct CC_info* cpHeir, Eval* eval, const CTransaction& tx, ui // helper functions used in implementations of rpc calls (in rpcwallet.cpp) or validation code /** -* Checks if vout is to cryptocondition address -* @return vout value in satoshis -*/ + * Checks if vout is to cryptocondition address + * @return vout value in satoshis + */ template int64_t IsHeirFundingVout(struct CC_info* cp, const CTransaction& tx, int32_t voutIndex, CPubKey ownerPubkey, CPubKey heirPubkey) { - char destaddr[65], heirFundingAddr[65]; - - Helper::GetCoinsOrTokensCCaddress1of2(cp, heirFundingAddr, ownerPubkey, heirPubkey); - if (tx.vout[voutIndex].scriptPubKey.IsPayToCryptoCondition() != 0) { - // NOTE: dimxy it was unsafe 'Getscriptaddress(destaddr,tx.vout[voutIndex].scriptPubKey) > 0' here: - if (Getscriptaddress(destaddr, tx.vout[voutIndex].scriptPubKey) && strcmp(destaddr, heirFundingAddr) == 0) - return (tx.vout[voutIndex].nValue); - else - std::cerr << "IsHeirFundingVout() heirFundingAddr=" << heirFundingAddr << " not equal to destaddr=" << destaddr << std::endl; - } - return (0); + char destaddr[65], heirFundingAddr[65]; + + Helper::GetCoinsOrTokensCCaddress1of2(cp, heirFundingAddr, ownerPubkey, heirPubkey); + if (tx.vout[voutIndex].scriptPubKey.IsPayToCryptoCondition() != 0) { + // NOTE: dimxy it was unsafe 'Getscriptaddress(destaddr,tx.vout[voutIndex].scriptPubKey) > 0' here: + if (Getscriptaddress(destaddr, tx.vout[voutIndex].scriptPubKey) && strcmp(destaddr, heirFundingAddr) == 0) + return (tx.vout[voutIndex].nValue); + else + std::cerr << "IsHeirFundingVout() heirFundingAddr=" << heirFundingAddr << " not equal to destaddr=" << destaddr << std::endl; + } + return (0); } // makes coin initial tx opret CScript EncodeHeirCreateOpRet(uint8_t funcid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName) { - uint8_t evalcode = EVAL_HEIR; - - return CScript() << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << ownerPubkey << heirPubkey << inactivityTimeSec << heirName); + uint8_t evalcode = EVAL_HEIR; + + return CScript() << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << ownerPubkey << heirPubkey << inactivityTimeSec << heirName); } // makes coin additional tx opret CScript EncodeHeirOpRet(uint8_t funcid, uint256 fundingtxid, uint8_t hasHeirSpendingBegun) { - uint8_t evalcode = EVAL_HEIR; - - fundingtxid = revuint256(fundingtxid); - return CScript() << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << fundingtxid << hasHeirSpendingBegun); + uint8_t evalcode = EVAL_HEIR; + + fundingtxid = revuint256(fundingtxid); + return CScript() << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << fundingtxid << hasHeirSpendingBegun); } // decode opret vout for Heir contract uint8_t _DecodeHeirOpRet(std::vector vopret, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging) { - uint8_t evalCodeInOpret = 0; - uint8_t heirFuncId = 0; - - fundingTxidInOpret = zeroid; //to init - - evalCodeInOpret = vopret.begin()[0]; - - if (vopret.size() > 1 && evalCodeInOpret == EVAL_HEIR) { - // NOTE: it unmarshals for all F, A and C - uint8_t heirFuncId = 0; - hasHeirSpendingBegun = 0; - - bool result = E_UNMARSHAL(vopret, { ss >> evalCodeInOpret; ss >> heirFuncId; \ - if (heirFuncId == 'F') { \ - ss >> ownerPubkey; ss >> heirPubkey; ss >> inactivityTime; ss >> heirName; \ - } \ - else { \ - ss >> fundingTxidInOpret >> hasHeirSpendingBegun; \ - } \ - }); - - if (!result) { - if (!noLogging) std::cerr << "_DecodeHeirOpRet() could not unmarshal opret, evalCode=" << (int)evalCodeInOpret << std::endl; - return (uint8_t)0; - } - - /* std::cerr << "DecodeHeirOpRet()" - << " heirFuncId=" << (char)(heirFuncId ? heirFuncId : ' ') - << " ownerPubkey=" << HexStr(ownerPubkey) - << " heirPubkey=" << HexStr(heirPubkey) - << " heirName=" << heirName << " inactivityTime=" << inactivityTime - << " hasHeirSpendingBegun=" << (int)hasHeirSpendingBegun << std::endl; */ - - if (isMyFuncId(heirFuncId)) { - fundingTxidInOpret = revuint256(fundingTxidInOpret); - return heirFuncId; - } - else { - if(!noLogging) std::cerr << "_DecodeHeirOpRet() unexpected opret type, heirFuncId=" << (char)(heirFuncId ? heirFuncId : ' ') << std::endl; - } - } - else { - if (!noLogging) std::cerr << "_DecodeHeirOpRet() not a heir opret, vopretExtra.size() == 0 or not EVAL_HEIR evalcode=" << (int)evalCodeInOpret << std::endl; - } - return (uint8_t)0; + uint8_t evalCodeInOpret = 0; + uint8_t heirFuncId = 0; + + fundingTxidInOpret = zeroid; //to init + + evalCodeInOpret = vopret.begin()[0]; + + if (vopret.size() > 1 && evalCodeInOpret == EVAL_HEIR) { + // NOTE: it unmarshals for all F, A and C + uint8_t heirFuncId = 0; + hasHeirSpendingBegun = 0; + + bool result = E_UNMARSHAL(vopret, { ss >> evalCodeInOpret; ss >> heirFuncId; \ + if (heirFuncId == 'F') { \ + ss >> ownerPubkey; ss >> heirPubkey; ss >> inactivityTime; ss >> heirName; \ + } \ + else { \ + ss >> fundingTxidInOpret >> hasHeirSpendingBegun; \ + } \ + }); + + if (!result) { + if (!noLogging) std::cerr << "_DecodeHeirOpRet() could not unmarshal opret, evalCode=" << (int)evalCodeInOpret << std::endl; + return (uint8_t)0; + } + + /* std::cerr << "DecodeHeirOpRet()" + << " heirFuncId=" << (char)(heirFuncId ? heirFuncId : ' ') + << " ownerPubkey=" << HexStr(ownerPubkey) + << " heirPubkey=" << HexStr(heirPubkey) + << " heirName=" << heirName << " inactivityTime=" << inactivityTime + << " hasHeirSpendingBegun=" << (int)hasHeirSpendingBegun << std::endl; */ + + if (isMyFuncId(heirFuncId)) { + fundingTxidInOpret = revuint256(fundingTxidInOpret); + return heirFuncId; + } + else { + if(!noLogging) std::cerr << "_DecodeHeirOpRet() unexpected opret type, heirFuncId=" << (char)(heirFuncId ? heirFuncId : ' ') << std::endl; + } + } + else { + if (!noLogging) std::cerr << "_DecodeHeirOpRet() not a heir opret, vopretExtra.size() == 0 or not EVAL_HEIR evalcode=" << (int)evalCodeInOpret << std::endl; + } + return (uint8_t)0; } /* not used, see DecodeHeirOpRet(vopret,...) -// overload for 'F' opret -uint8_t DecodeHeirOpRet(CScript scriptPubKey, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging) -{ + // overload for 'F' opret + uint8_t DecodeHeirOpRet(CScript scriptPubKey, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging) + { uint256 dummytxid; uint8_t dummyHasHeirSpendingBegun; std::vector vopret; - + GetOpReturnData(scriptPubKey, vopret); if (vopret.size() == 0) { - if (!noLogging) std::cerr << "DecodeHeirOpRet() warning: empty opret" << std::endl; - return (uint8_t)0; + if (!noLogging) std::cerr << "DecodeHeirOpRet() warning: empty opret" << std::endl; + return (uint8_t)0; } return _DecodeHeirOpRet(vopret, ownerPubkey, heirPubkey, inactivityTime, heirName, dummytxid, dummyHasHeirSpendingBegun, noLogging); -}*/ + }*/ /* not used, see DecodeHeirOpRet(vopret,...) -// overload for A, C oprets and AddHeirContractInputs -uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256& fundingtxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging) -{ + // overload for A, C oprets and AddHeirContractInputs + uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256& fundingtxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging) + { CPubKey dummyOwnerPubkey, dummyHeirPubkey; int64_t dummyInactivityTime; std::string dummyHeirName; std::vector vopret; - + GetOpReturnData(scriptPubKey, vopret); if (vopret.size() == 0) { - if (!noLogging) std::cerr << "DecodeHeirOpRet() warning: empty opret" << std::endl; - return (uint8_t)0; + if (!noLogging) std::cerr << "DecodeHeirOpRet() warning: empty opret" << std::endl; + return (uint8_t)0; } - + return _DecodeHeirOpRet(vopret, dummyOwnerPubkey, dummyHeirPubkey, dummyInactivityTime, dummyHeirName, fundingtxidInOpret, hasHeirSpendingBegun, noLogging); -} */ + } */ // decode combined opret: uint8_t _DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging) { - uint8_t evalCodeTokens = 0; - std::vector voutPubkeysDummy; - std::vector vopretExtra, vopretStripped; - - if (DecodeTokenOpRet(scriptPubKey, evalCodeTokens, tokenid, voutPubkeysDummy, vopretExtra) != 0) { - if (vopretExtra.size() > 1) { - // restore the second opret: - - if (!E_UNMARSHAL(vopretExtra, { ss >> vopretStripped; })) { //strip string size - if (!noLogging) std::cerr << "_DecodeHeirEitherOpret() could not unmarshal vopretStripped" << std::endl; - return (uint8_t)0; - } - } - else { - if (!noLogging) std::cerr << "_DecodeHeirEitherOpret() empty vopretExtra" << std::endl; - return (uint8_t)0; - } - } - else - GetOpReturnData(scriptPubKey, vopretStripped); - - return _DecodeHeirOpRet(vopretStripped, ownerPubkey, heirPubkey, inactivityTime, heirName, fundingTxidInOpret, hasHeirSpendingBegun, noLogging); - + uint8_t evalCodeTokens = 0; + std::vector voutPubkeysDummy; + std::vector vopretExtra, vopretStripped; + + if (DecodeTokenOpRet(scriptPubKey, evalCodeTokens, tokenid, voutPubkeysDummy, vopretExtra) != 0) { + if (vopretExtra.size() > 1) { + // restore the second opret: + + if (!E_UNMARSHAL(vopretExtra, { ss >> vopretStripped; })) { //strip string size + if (!noLogging) std::cerr << "_DecodeHeirEitherOpret() could not unmarshal vopretStripped" << std::endl; + return (uint8_t)0; + } + } + else { + if (!noLogging) std::cerr << "_DecodeHeirEitherOpret() empty vopretExtra" << std::endl; + return (uint8_t)0; + } + } + else + GetOpReturnData(scriptPubKey, vopretStripped); + + return _DecodeHeirOpRet(vopretStripped, ownerPubkey, heirPubkey, inactivityTime, heirName, fundingTxidInOpret, hasHeirSpendingBegun, noLogging); + } // overload to decode opret in fundingtxid: uint8_t DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging) { - uint256 dummyFundingTxidInOpret; - uint8_t dummyHasHeirSpendingBegun; - - return _DecodeHeirEitherOpRet(scriptPubKey, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, dummyFundingTxidInOpret, dummyHasHeirSpendingBegun, noLogging); + uint256 dummyFundingTxidInOpret; + uint8_t dummyHasHeirSpendingBegun; + + return _DecodeHeirEitherOpRet(scriptPubKey, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, dummyFundingTxidInOpret, dummyHasHeirSpendingBegun, noLogging); } // overload to decode opret in A and C heir tx: uint8_t DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, uint256 &fundingTxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging) { - CPubKey dummyOwnerPubkey, dummyHeirPubkey; - int64_t dummyInactivityTime; - std::string dummyHeirName; - - return _DecodeHeirEitherOpRet(scriptPubKey, tokenid, dummyOwnerPubkey, dummyHeirPubkey, dummyInactivityTime, dummyHeirName, fundingTxidInOpret, hasHeirSpendingBegun, noLogging); + CPubKey dummyOwnerPubkey, dummyHeirPubkey; + int64_t dummyInactivityTime; + std::string dummyHeirName; + + return _DecodeHeirEitherOpRet(scriptPubKey, tokenid, dummyOwnerPubkey, dummyHeirPubkey, dummyInactivityTime, dummyHeirName, fundingTxidInOpret, hasHeirSpendingBegun, noLogging); } /** - * find the latest funding tx: it may be the first F tx or one of A or C tx's - * Note: this function is also called from validation code (use non-locking calls) + * find the latest funding tx: it may be the first F tx or one of A or C tx's + * Note: this function is also called from validation code (use non-locking calls) */ uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, CScript& fundingOpretScript, uint8_t &hasHeirSpendingBegun) { - CTransaction fundingtx; - uint256 hashBlock; + CTransaction fundingtx; + uint256 hashBlock; const bool allowSlow = false; - + //char markeraddr[64]; //CCtxidaddr(markeraddr, fundingtxid); //SetCCunspents(unspentOutputs, markeraddr); - - hasHeirSpendingBegun = 0; - funcId = 0; - + + hasHeirSpendingBegun = 0; + funcId = 0; + // get initial funding tx and set it as initial lasttx: if (myGetTransaction(fundingtxid, fundingtx, hashBlock) && fundingtx.vout.size()) { - - CScript heirScript = (fundingtx.vout.size() > 0) ? fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey : CScript(); - uint8_t funcId = DecodeHeirEitherOpRet(heirScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, true); + + CScript heirScript = (fundingtx.vout.size() > 0) ? fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey : CScript(); + uint8_t funcId = DecodeHeirEitherOpRet(heirScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, true); if (funcId != 0) { // found at least funding tx! //std::cerr << "FindLatestFundingTx() lasttx currently is fundingtx, txid=" << fundingtxid.GetHex() << " opreturn type=" << (char)funcId << '\n'; @@ -434,55 +434,55 @@ uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &toke std::cerr << "FindLatestFundingTx() could not find funding tx for fundingtxid=" << fundingtxid.GetHex() << '\n'; return zeroid; } - - // TODO: correct cc addr: + + // TODO: correct cc addr: std::vector> unspentOutputs; struct CC_info *cp, C; cp = CCinit(&C, EVAL_HEIR); char coinaddr[64]; GetCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); // get the address of cryptocondition '1 of 2 pubkeys' - + SetCCunspents(unspentOutputs, coinaddr); // get vector with tx's with unspent vouts of 1of2pubkey address: //std::cerr << "FindLatestFundingTx() using 1of2address=" << coinaddr << " unspentOutputs.size()=" << unspentOutputs.size() << '\n'; - + int32_t maxBlockHeight = 0; // max block height uint256 latesttxid = fundingtxid; - + // try to find the last funding or spending tx by checking fundingtxid in 'opreturn': for (std::vector>::const_iterator it = unspentOutputs.begin(); it != unspentOutputs.end(); it++) { CTransaction regtx; uint256 hash; - + uint256 txid = it->first.txhash; //std::cerr << "FindLatestFundingTx() checking unspents for txid=" << txid.GetHex() << '\n'; - + int32_t blockHeight = (int32_t)it->second.blockHeight; - - //NOTE: maybe called from validation code: - if (myGetTransaction(txid, regtx, hash)) { - //std::cerr << "FindLatestFundingTx() found tx for txid=" << txid.GetHex() << " blockHeight=" << blockHeight << " maxBlockHeight=" << maxBlockHeight << '\n'; - uint256 fundingTxidInOpret; - uint256 tokenidInOpret; // not to contaminate the tokenid from the params! - uint8_t tmpFuncId; - uint8_t hasHeirSpendingBegunInOpret; - - CScript heirScript = (regtx.vout.size() > 0) ? regtx.vout[regtx.vout.size() - 1].scriptPubKey : CScript(); - tmpFuncId = DecodeHeirEitherOpRet(heirScript, tokenidInOpret, fundingTxidInOpret, hasHeirSpendingBegunInOpret, true); + + //NOTE: maybe called from validation code: + if (myGetTransaction(txid, regtx, hash)) { + //std::cerr << "FindLatestFundingTx() found tx for txid=" << txid.GetHex() << " blockHeight=" << blockHeight << " maxBlockHeight=" << maxBlockHeight << '\n'; + uint256 fundingTxidInOpret; + uint256 tokenidInOpret; // not to contaminate the tokenid from the params! + uint8_t tmpFuncId; + uint8_t hasHeirSpendingBegunInOpret; + + CScript heirScript = (regtx.vout.size() > 0) ? regtx.vout[regtx.vout.size() - 1].scriptPubKey : CScript(); + tmpFuncId = DecodeHeirEitherOpRet(heirScript, tokenidInOpret, fundingTxidInOpret, hasHeirSpendingBegunInOpret, true); if (tmpFuncId != 0 && fundingtxid == fundingTxidInOpret && (tokenid == zeroid || tokenid == tokenidInOpret)) { // check tokenid also - + if (blockHeight > maxBlockHeight) { maxBlockHeight = blockHeight; latesttxid = txid; - funcId = tmpFuncId; - hasHeirSpendingBegun = hasHeirSpendingBegunInOpret; - - //std::cerr << "FindLatestFundingTx() txid=" << latesttxid.GetHex() << " at blockHeight=" << maxBlockHeight - // << " opreturn type=" << (char)(funcId ? funcId : ' ') << " hasHeirSpendingBegun=" << (int)hasHeirSpendingBegun << " - set as current lasttxid" << '\n'; + funcId = tmpFuncId; + hasHeirSpendingBegun = hasHeirSpendingBegunInOpret; + + //std::cerr << "FindLatestFundingTx() txid=" << latesttxid.GetHex() << " at blockHeight=" << maxBlockHeight + // << " opreturn type=" << (char)(funcId ? funcId : ' ') << " hasHeirSpendingBegun=" << (int)hasHeirSpendingBegun << " - set as current lasttxid" << '\n'; } } } } - + return latesttxid; } @@ -494,7 +494,7 @@ uint256 FindLatestFundingTx(uint256 fundingtxid, uint256 &tokenid, CScript& opRe CPubKey heirPubkey; int64_t inactivityTime; std::string heirName; - + return _FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, opRetScript, hasHeirSpendingBegun); } @@ -502,7 +502,7 @@ uint256 FindLatestFundingTx(uint256 fundingtxid, uint256 &tokenid, CScript& opRe uint256 FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint8_t &hasHeirSpendingBegun) { CScript opRetScript; - + return _FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, opRetScript, hasHeirSpendingBegun); } @@ -514,41 +514,41 @@ template int64_t Add1of2AddressInputs(struct CC_info* cp, uint256 CTransaction heirtx; int32_t n = 0; std::vector> unspentOutputs; - + char coinaddr[64]; - Helper::GetCoinsOrTokensCCaddress1of2(coinaddr, ownerPubkey, heirPubkey); // get address of cryptocondition '1 of 2 pubkeys' + Helper::GetCoinsOrTokensCCaddress1of2(coinaddr, ownerPubkey, heirPubkey); // get address of cryptocondition '1 of 2 pubkeys' SetCCunspents(unspentOutputs, coinaddr); - + // char markeraddr[64]; // CCtxidaddr(markeraddr, fundingtxid); // SetCCunspents(unspentOutputs, markeraddr); - + std::cerr << "Add1of2AddressInputs() using 1of2addr=" << coinaddr << " unspentOutputs.size()=" << unspentOutputs.size() << std::endl; - + for (std::vector>::const_iterator it = unspentOutputs.begin(); it != unspentOutputs.end(); it++) { uint256 txid = it->first.txhash; uint256 hashBlock; int32_t voutIndex = (int32_t)it->first.index; // no need to prevent dup // dimxy: maybe it is good to put tx's in cache? - - std::cerr << "Add1of2AddressInputs() txid=" << txid.GetHex() << std::endl; - + + std::cerr << "Add1of2AddressInputs() txid=" << txid.GetHex() << std::endl; + if (GetTransaction(txid, heirtx, hashBlock, false) != 0) { - uint256 tokenid; + uint256 tokenid; uint256 fundingTxidInOpret; - uint8_t hasHeirSpendingBegunDummy; - - CScript heirScript = (heirtx.vout.size() > 0) ? heirtx.vout[heirtx.vout.size() - 1].scriptPubKey : CScript(); // check boundary - uint8_t funcId = DecodeHeirEitherOpRet(heirScript, tokenid, fundingTxidInOpret, hasHeirSpendingBegunDummy, false); - - if ((txid == fundingtxid || fundingTxidInOpret == fundingtxid) && - funcId != 0 && - isMyFuncId(funcId) && - (typeid(Helper) != typeid(TokenHelper) || IsTokensvout(true, true, cp, nullptr, heirtx, voutIndex, tokenid) > 0) && // token validation logic + uint8_t hasHeirSpendingBegunDummy; + + CScript heirScript = (heirtx.vout.size() > 0) ? heirtx.vout[heirtx.vout.size() - 1].scriptPubKey : CScript(); // check boundary + uint8_t funcId = DecodeHeirEitherOpRet(heirScript, tokenid, fundingTxidInOpret, hasHeirSpendingBegunDummy, false); + + if ((txid == fundingtxid || fundingTxidInOpret == fundingtxid) && + funcId != 0 && + isMyFuncId(funcId) && + (typeid(Helper) != typeid(TokenHelper) || IsTokensvout(true, true, cp, nullptr, heirtx, voutIndex, tokenid) > 0) && // token validation logic //(voutValue = IsHeirFundingVout(cp, heirtx, voutIndex, ownerPubkey, heirPubkey)) > 0 && // heir contract vout validation logic - not used since we moved to 2-eval vouts - !myIsutxo_spentinmempool(txid, voutIndex)) - { + !myIsutxo_spentinmempool(txid, voutIndex)) + { std::cerr << "Add1of2AddressInputs() satoshis=" << it->second.satoshis << std::endl; if (total != 0 && maxinputs != 0) mtx.vin.push_back(CTxIn(txid, voutIndex, CScript())); @@ -564,42 +564,42 @@ template int64_t Add1of2AddressInputs(struct CC_info* cp, uint256 } /** - * enumerate all tx's sending to CCHeir 1of2address and calc total lifetime funds + * enumerate all tx's sending to CCHeir 1of2address and calc total lifetime funds */ template int64_t LifetimeHeirContractFunds(struct CC_info* cp, uint256 fundingtxid, CPubKey ownerPubkey, CPubKey heirPubkey) { char coinaddr[64]; Helper::GetCoinsOrTokensCCaddress1of2(coinaddr, ownerPubkey, heirPubkey); // get the address of cryptocondition '1 of 2 pubkeys' - + std::vector> addressIndexes; SetCCtxids(addressIndexes, coinaddr); - + //fprintf(stderr,"LifetimeHeirContractFunds() scan lifetime of %s\n",coinaddr); int64_t total = 0; for (std::vector>::const_iterator it = addressIndexes.begin(); it != addressIndexes.end(); it++) { uint256 hashBlock; uint256 txid = it->first.txhash; CTransaction heirtx; - - // TODO: check all funding tx should contain unspendable markers + + // TODO: check all funding tx should contain unspendable markers if (GetTransaction(txid, heirtx, hashBlock, false) && heirtx.vout.size() > 0) { - uint256 tokenid; + uint256 tokenid; uint256 fundingTxidInOpret; - uint8_t hasHeirSpendingBegunDummy; + uint8_t hasHeirSpendingBegunDummy; const int32_t ivout = 0; - - CScript heirScript = (heirtx.vout.size() > 0) ? heirtx.vout[heirtx.vout.size() - 1].scriptPubKey : CScript(); // check boundary - uint8_t funcId = DecodeHeirEitherOpRet(heirScript, tokenid, fundingTxidInOpret, hasHeirSpendingBegunDummy, false); - + + CScript heirScript = (heirtx.vout.size() > 0) ? heirtx.vout[heirtx.vout.size() - 1].scriptPubKey : CScript(); // check boundary + uint8_t funcId = DecodeHeirEitherOpRet(heirScript, tokenid, fundingTxidInOpret, hasHeirSpendingBegunDummy, false); + //std::cerr << "LifetimeHeirContractFunds() found tx=" << txid.GetHex() << " vout[0].nValue=" << subtx.vout[ccVoutIdx].nValue << " opreturn=" << (char)funcId << '\n'; - - if (funcId != 0 && - (txid == fundingtxid || fundingTxidInOpret == fundingtxid) && - isMyFuncId(funcId) && !isSpendingTx(funcId) && - (typeid(Helper) != typeid(TokenHelper) || IsTokensvout(true, true, cp, nullptr, heirtx, ivout, tokenid) > 0) && - !myIsutxo_spentinmempool(txid, ivout)) // exclude tx in mempool + + if (funcId != 0 && + (txid == fundingtxid || fundingTxidInOpret == fundingtxid) && + isMyFuncId(funcId) && !isSpendingTx(funcId) && + (typeid(Helper) != typeid(TokenHelper) || IsTokensvout(true, true, cp, nullptr, heirtx, ivout, tokenid) > 0) && + !myIsutxo_spentinmempool(txid, ivout)) // exclude tx in mempool { - total += it->second; // dont do this: tx.vout[ivout].nValue; // in vin[0] always is the pay to 1of2 addr (funding or change) + total += it->second; // dont do this: tx.vout[ivout].nValue; // in vin[0] always is the pay to 1of2 addr (funding or change) //std::cerr << "LifetimeHeirContractFunds() added tx=" << txid.GetHex() << " it->second=" << it->second << " vout[0].nValue=" << tx.vout[ivout].nValue << " opreturn=" << (char)funcId << '\n'; } } @@ -611,90 +611,90 @@ template int64_t LifetimeHeirContractFunds(struct CC_info* cp, ui /** * heirfund rpc call implementation - * creates tx for initial funds deposit on cryptocondition address which locks funds for spending by either of address. + * creates tx for initial funds deposit on cryptocondition address which locks funds for spending by either of address. * and also for setting spending plan for the funds' owner and heir * @return fundingtxid handle for subsequent references to this heir funding plan */ template UniValue HeirFund(uint64_t txfee, int64_t amount, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid) { - UniValue result(UniValue::VOBJ); - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - struct CC_info *cp, C; - + UniValue result(UniValue::VOBJ); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + struct CC_info *cp, C; + cp = CCinit(&C, Helper::getMyEval()); if (txfee == 0) txfee = 10000; - + //std::cerr << "HeirFund() amount=" << amount << " txfee=" << txfee << " heirPubkey IsValid()=" << heirPubkey.IsValid() << " inactivityTime(sec)=" << inactivityTimeSec << " tokenid=" << tokenid.GetHex() << std::endl; - - if (!heirPubkey.IsValid()) { - std::cerr << "HeirFund() heirPubkey is not valid!" << std::endl; - return std::string(""); - } - + + if (!heirPubkey.IsValid()) { + std::cerr << "HeirFund() heirPubkey is not valid!" << std::endl; + return std::string(""); + } + CPubKey myPubkey = pubkey2pk(Mypubkey()); - - if (AddNormalinputs(mtx, myPubkey, txfee, 3) > 0) { // txfee for miners - int64_t inputs, change; - - if ((inputs=Helper::addOwnerInputs(tokenid, mtx, myPubkey, amount, (int32_t)64)) > 0) { // 2 x txfee: 1st for marker vout, 2nd to miners - //mtx.vout.push_back(MakeTokensCC1of2vout(/*Helper::getMyEval()*/EVAL_HEIR, amount, myPubkey, heirPubkey)); // add cryptocondition to spend amount for either pk - mtx.vout.push_back(Helper::make1of2Vout(amount, myPubkey, heirPubkey)); - - // add a marker for finding all plans in HeirList() - // TODO: change marker either to cc or normal txidaddr unspendable - CPubKey heirUnspendablePubKey = GetUnspendable(cp, 0); - mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(heirUnspendablePubKey)) << OP_CHECKSIG)); // TODO: do we need this marker? - - // calc and add change vout: - if (inputs > amount) - change = (inputs - amount); // -txfee <-- txfee pays user - - //std::cerr << "HeirFund() inputs=" << inputs << " amount=" << amount << " txfee=" << txfee << " change=" << change << '\n'; - - if (change != 0) { // vout[1] - mtx.vout.push_back(Helper::makeUserVout(change, myPubkey)); - } - - // add 1of2 vout validation pubkeys: - std::vector voutTokenPubkeys; - voutTokenPubkeys.push_back(myPubkey); - voutTokenPubkeys.push_back(heirPubkey); - - // add change for txfee and opreturn vouts and sign tx: - std::string rawhextx = FinalizeCCTx(0, cp, mtx, myPubkey, txfee, - Helper::makeCreateOpRet(tokenid, voutTokenPubkeys, myPubkey, heirPubkey, inactivityTimeSec, heirName)); - if (!rawhextx.empty()) { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hextx", rawhextx)); - } - else { - std::cerr << "HeirAdd error in FinalizeCCtx" << std::endl; - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "sign error")); - } - } - else { // TODO: need result return unification with heiradd and claim - std::cerr << "HeirFund() could not find owner cc inputs" << std::endl; - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "could not find owner cc inputs")); - } - } - else { - std::cerr << "HeirFund() could not find normal inputs" << std::endl; - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "could not find normal inputs")); - } + + if (AddNormalinputs(mtx, myPubkey, txfee, 3) > 0) { // txfee for miners + int64_t inputs, change; + + if ((inputs=Helper::addOwnerInputs(tokenid, mtx, myPubkey, amount, (int32_t)64)) > 0) { // 2 x txfee: 1st for marker vout, 2nd to miners + //mtx.vout.push_back(MakeTokensCC1of2vout(/*Helper::getMyEval()*/EVAL_HEIR, amount, myPubkey, heirPubkey)); // add cryptocondition to spend amount for either pk + mtx.vout.push_back(Helper::make1of2Vout(amount, myPubkey, heirPubkey)); + + // add a marker for finding all plans in HeirList() + // TODO: change marker either to cc or normal txidaddr unspendable + CPubKey heirUnspendablePubKey = GetUnspendable(cp, 0); + mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(heirUnspendablePubKey)) << OP_CHECKSIG)); // TODO: do we need this marker? + + // calc and add change vout: + if (inputs > amount) + change = (inputs - amount); // -txfee <-- txfee pays user + + //std::cerr << "HeirFund() inputs=" << inputs << " amount=" << amount << " txfee=" << txfee << " change=" << change << '\n'; + + if (change != 0) { // vout[1] + mtx.vout.push_back(Helper::makeUserVout(change, myPubkey)); + } + + // add 1of2 vout validation pubkeys: + std::vector voutTokenPubkeys; + voutTokenPubkeys.push_back(myPubkey); + voutTokenPubkeys.push_back(heirPubkey); + + // add change for txfee and opreturn vouts and sign tx: + std::string rawhextx = FinalizeCCTx(0, cp, mtx, myPubkey, txfee, + Helper::makeCreateOpRet(tokenid, voutTokenPubkeys, myPubkey, heirPubkey, inactivityTimeSec, heirName)); + if (!rawhextx.empty()) { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hextx", rawhextx)); + } + else { + std::cerr << "HeirAdd error in FinalizeCCtx" << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "sign error")); + } + } + else { // TODO: need result return unification with heiradd and claim + std::cerr << "HeirFund() could not find owner cc inputs" << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "could not find owner cc inputs")); + } + } + else { + std::cerr << "HeirFund() could not find normal inputs" << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "could not find normal inputs")); + } return result; } -// if no these callers - it could not link +// if no these callers - it could not link UniValue HeirFundCoinCaller(uint64_t txfee, int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid){ - return HeirFund(txfee, funds, heirName, heirPubkey, inactivityTimeSec, tokenid); + return HeirFund(txfee, funds, heirName, heirPubkey, inactivityTimeSec, tokenid); } UniValue HeirFundTokenCaller(uint64_t txfee, int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid) { - return HeirFund(txfee, funds, heirName, heirPubkey, inactivityTimeSec, tokenid); + return HeirFund(txfee, funds, heirName, heirPubkey, inactivityTimeSec, tokenid); } /** @@ -704,113 +704,113 @@ UniValue HeirFundTokenCaller(uint64_t txfee, int64_t funds, std::string heirName */ template UniValue _HeirAdd(uint256 fundingtxid, uint64_t txfee, int64_t amount, uint256 latesttxid, uint8_t funcId, uint256 tokenid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName, uint8_t hasHeirSpendingBegun) { - UniValue result(UniValue::VOBJ); - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + UniValue result(UniValue::VOBJ); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); int64_t inputs, CCchange = 0; struct CC_info *cp, C; std::string rawhex; - - cp = CCinit(&C, Helper::getMyEval()); // for tokens shoud be EVAL_TOKENS to sign it correctly! - + + cp = CCinit(&C, Helper::getMyEval()); // for tokens shoud be EVAL_TOKENS to sign it correctly! + if (txfee == 0) txfee = 10000; - + CPubKey myPubkey = pubkey2pk(Mypubkey()); - + // check if it is the owner if (myPubkey != ownerPubkey) { result.push_back(Pair("result", "error")); result.push_back(Pair("error", "adding funds is only allowed for the owner of this contract")); return result; } - - if (AddNormalinputs(mtx, myPubkey, txfee, 3) > 0) { // txfee for miners - - int64_t inputs, change; - - if ((inputs = Helper::addOwnerInputs(tokenid, mtx, myPubkey, amount, 64)) > 0) { // TODO: why 64 max inputs? - - // we do not use markers anymore - storing data in opreturn is better - // add marker vout: - /* char markeraddr[64]; - CPubKey markerpubkey = CCtxidaddr(markeraddr, fundingtxid); - mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(markerpubkey)) << OP_CHECKSIG)); // txfee 1, txfee 2 - for miners - std::cerr << "HeirAdd() adding markeraddr=" << markeraddr << '\n'; */ - - // add cryptocondition to spend this funded amount for either pk - mtx.vout.push_back(Helper::make1of2Vout(amount, ownerPubkey, heirPubkey)); - - if (inputs > amount) - change = (inputs - amount); // -txfee <-- txfee pays user - - //std::cerr << "HeirAdd() inputs=" << inputs << " amount=" << amount << " txfee=" << txfee << " change=" << change << '\n'; - - if (change != 0) { // vout[1] - mtx.vout.push_back(Helper::makeUserVout(change, myPubkey)); - } - - // add 1of2 vout validation pubkeys - needed only for tokens: - std::vector voutTokenPubkeys; - voutTokenPubkeys.push_back(ownerPubkey); - voutTokenPubkeys.push_back(heirPubkey); - - // add opreturn 'A' and sign tx: // this txfee ignored - std::string rawhextx = (FinalizeCCTx(0, cp, mtx, myPubkey, txfee, - Helper::makeAddOpRet(tokenid, voutTokenPubkeys, fundingtxid, hasHeirSpendingBegun))); - - if (!rawhextx.empty()) { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hextx", rawhextx)); - } - else { - std::cerr << "HeirAdd error in FinalizeCCtx" << std::endl; - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "sign error")); - } - - } - else { - std::cerr << "HeirAdd cannot find owner cc inputs" << std::endl; - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "can't find owner cc inputs")); - } - } - else { - std::cerr << "HeirAdd cannot find normal inputs for tx fee" << std::endl; - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "can't find normal inputs for tx fee")); - } - - - + + if (AddNormalinputs(mtx, myPubkey, txfee, 3) > 0) { // txfee for miners + + int64_t inputs, change; + + if ((inputs = Helper::addOwnerInputs(tokenid, mtx, myPubkey, amount, 64)) > 0) { // TODO: why 64 max inputs? + + // we do not use markers anymore - storing data in opreturn is better + // add marker vout: + /* char markeraddr[64]; + CPubKey markerpubkey = CCtxidaddr(markeraddr, fundingtxid); + mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(markerpubkey)) << OP_CHECKSIG)); // txfee 1, txfee 2 - for miners + std::cerr << "HeirAdd() adding markeraddr=" << markeraddr << '\n'; */ + + // add cryptocondition to spend this funded amount for either pk + mtx.vout.push_back(Helper::make1of2Vout(amount, ownerPubkey, heirPubkey)); + + if (inputs > amount) + change = (inputs - amount); // -txfee <-- txfee pays user + + //std::cerr << "HeirAdd() inputs=" << inputs << " amount=" << amount << " txfee=" << txfee << " change=" << change << '\n'; + + if (change != 0) { // vout[1] + mtx.vout.push_back(Helper::makeUserVout(change, myPubkey)); + } + + // add 1of2 vout validation pubkeys - needed only for tokens: + std::vector voutTokenPubkeys; + voutTokenPubkeys.push_back(ownerPubkey); + voutTokenPubkeys.push_back(heirPubkey); + + // add opreturn 'A' and sign tx: // this txfee ignored + std::string rawhextx = (FinalizeCCTx(0, cp, mtx, myPubkey, txfee, + Helper::makeAddOpRet(tokenid, voutTokenPubkeys, fundingtxid, hasHeirSpendingBegun))); + + if (!rawhextx.empty()) { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hextx", rawhextx)); + } + else { + std::cerr << "HeirAdd error in FinalizeCCtx" << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "sign error")); + } + + } + else { + std::cerr << "HeirAdd cannot find owner cc inputs" << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "can't find owner cc inputs")); + } + } + else { + std::cerr << "HeirAdd cannot find normal inputs for tx fee" << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "can't find normal inputs for tx fee")); + } + + + return result; } UniValue HeirAddCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount) { - - CPubKey ownerPubkey, heirPubkey; - int64_t inactivityTimeSec; - - uint256 latesttxid, tokenid = zeroid; - uint8_t funcId; - std::string heirName; - uint8_t hasHeirSpendingBegun = 0; - - if ((latesttxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun)) != zeroid) { - if (tokenid == zeroid) - return _HeirAdd(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); - else - return _HeirAdd(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); - } - else { - UniValue result(UniValue::VOBJ); - - fprintf(stderr, "HeirAdd() can't find any heir CC funding tx's\n"); - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "can't find any heir CC funding transactions")); - return result; - } + + CPubKey ownerPubkey, heirPubkey; + int64_t inactivityTimeSec; + + uint256 latesttxid, tokenid = zeroid; + uint8_t funcId; + std::string heirName; + uint8_t hasHeirSpendingBegun = 0; + + if ((latesttxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun)) != zeroid) { + if (tokenid == zeroid) + return _HeirAdd(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + else + return _HeirAdd(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + } + else { + UniValue result(UniValue::VOBJ); + + fprintf(stderr, "HeirAdd() can't find any heir CC funding tx's\n"); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "can't find any heir CC funding transactions")); + return result; + } } @@ -821,110 +821,110 @@ UniValue HeirAddCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount) { */ template UniValue _HeirClaim(uint256 fundingtxid, uint64_t txfee, int64_t amount, uint256 latesttxid, uint8_t funcId, uint256 tokenid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName, uint8_t hasHeirSpendingBegun) { - UniValue result(UniValue::VOBJ); - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey myPubkey; + UniValue result(UniValue::VOBJ); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + CPubKey myPubkey; int64_t inputs, change = 0; struct CC_info *cp, C; - - cp = CCinit(&C, EVAL_HEIR); - if (txfee == 0) + + cp = CCinit(&C, EVAL_HEIR); + if (txfee == 0) txfee = 10000; - + int32_t numblocks; uint64_t durationSec = 0; - - // we do not need to find duration if spending already has begun - if (!hasHeirSpendingBegun) { + + // we do not need to find duration if spending already has begun + if (!hasHeirSpendingBegun) { durationSec = CCduration(numblocks, latesttxid); std::cerr << "HeirClaim() duration=" << durationSec << " inactivityTime=" << inactivityTimeSec << " numblocks=" << numblocks << std::endl; } - + // spending is allowed if there is already spending tx or inactivity time //bool isAllowedToHeir = (funcId == 'C' || durationSec > inactivityTimeSec) ? true : false; - bool isAllowedToHeir = (hasHeirSpendingBegun || durationSec > inactivityTimeSec) ? true : false; + bool isAllowedToHeir = (hasHeirSpendingBegun || durationSec > inactivityTimeSec) ? true : false; myPubkey = pubkey2pk(Mypubkey()); - + // if it is the heir, check if spending not allowed to heir yet if (myPubkey == heirPubkey && !isAllowedToHeir) { result.push_back(Pair("result", "error")); result.push_back(Pair("error", "spending is not allowed yet for the heir")); return result; } - - // we do not use markers any more: - // we allow owner to spend funds at any time: - // if it is the owner, check if spending already allowed to heir - /* if (myPubkey == ownerPubkey && isAllowedToHeir) { - result.push_back(Pair("result", "spending is not already allowed for the owner")); - return result; - } */ - - // add spending txfee from the calling user + + // we do not use markers any more: + // we allow owner to spend funds at any time: + // if it is the owner, check if spending already allowed to heir + /* if (myPubkey == ownerPubkey && isAllowedToHeir) { + result.push_back(Pair("result", "spending is not already allowed for the owner")); + return result; + } */ + + // add spending txfee from the calling user if (AddNormalinputs(mtx, myPubkey, txfee, 3) > 0) { - - // add spending from cc 1of2 address - if ((inputs = Add1of2AddressInputs(cp, fundingtxid, mtx, ownerPubkey, heirPubkey, amount, 60)) >= amount) // TODO: why only 60 inputs? + + // add spending from cc 1of2 address + if ((inputs = Add1of2AddressInputs(cp, fundingtxid, mtx, ownerPubkey, heirPubkey, amount, 60)) >= amount) // TODO: why only 60 inputs? { - /*if (inputs < amount) { - std::cerr << "HeirClaim() cant find enough HeirCC 1of2 inputs, found=" << inputs << " required=" << amount << std::endl; - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "can't find heir CC funding")); - - return result; - }*/ - - // add vout with amount to claiming address - mtx.vout.push_back(Helper::makeUserVout(amount, myPubkey)); // vout[0] - + /*if (inputs < amount) { + std::cerr << "HeirClaim() cant find enough HeirCC 1of2 inputs, found=" << inputs << " required=" << amount << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "can't find heir CC funding")); + + return result; + }*/ + + // add vout with amount to claiming address + mtx.vout.push_back(Helper::makeUserVout(amount, myPubkey)); // vout[0] + // calc and add change vout: if (inputs > amount) - change = (inputs - amount); // -txfee <-- txfee pays user - + change = (inputs - amount); // -txfee <-- txfee pays user + //std::cerr << "HeirClaim() inputs=" << inputs << " amount=" << amount << " txfee=" << txfee << " change=" << change << '\n'; - - // change to 1of2 funding addr: + + // change to 1of2 funding addr: if (change != 0) { // vout[1] mtx.vout.push_back(Helper::make1of2Vout(change, ownerPubkey, heirPubkey)); // using always pubkeys from OP_RETURN in order to not mixing them up! } - + // add marker vout: /*char markeraddr[64]; - CPubKey markerpubkey = CCtxidaddr(markeraddr, fundingtxid); - // NOTE: amount = 0 is not working: causes error code: -26, error message : 64 : dust - mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(markerpubkey)) << OP_CHECKSIG)); // txfee 1, txfee 2 - for miners - std::cerr << "HeirClaim() adding markeraddr=" << markeraddr << '\n'; */ - - // get address of 1of2 cond + CPubKey markerpubkey = CCtxidaddr(markeraddr, fundingtxid); + // NOTE: amount = 0 is not working: causes error code: -26, error message : 64 : dust + mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(markerpubkey)) << OP_CHECKSIG)); // txfee 1, txfee 2 - for miners + std::cerr << "HeirClaim() adding markeraddr=" << markeraddr << '\n'; */ + + // get address of 1of2 cond char coinaddr[64]; Helper::GetCoinsOrTokensCCaddress1of2(coinaddr, ownerPubkey, heirPubkey); - - // retrieve priv key addresses for FinalizeCCtx: - uint8_t myprivkey[32]; + + // retrieve priv key addresses for FinalizeCCtx: + uint8_t myprivkey[32]; Myprivkey(myprivkey); - - // set pubkeys for finding 1of2 cc in FinalizeCCtx to sign it: - Helper::CCaddrCoinsOrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); - - // add 1of2 vout validation pubkeys (this is for tokens): - std::vector voutTokenPubkeys; - voutTokenPubkeys.push_back(ownerPubkey); - voutTokenPubkeys.push_back(heirPubkey); - + + // set pubkeys for finding 1of2 cc in FinalizeCCtx to sign it: + Helper::CCaddrCoinsOrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); + + // add 1of2 vout validation pubkeys (this is for tokens): + std::vector voutTokenPubkeys; + voutTokenPubkeys.push_back(ownerPubkey); + voutTokenPubkeys.push_back(heirPubkey); + // add opreturn 'C' and sign tx: // this txfee will be ignored - std::string rawhextx = FinalizeCCTx(0, cp, mtx, myPubkey, txfee, - Helper::makeClaimOpRet(tokenid, voutTokenPubkeys, fundingtxid, (myPubkey == heirPubkey) ? 1 : hasHeirSpendingBegun)); // forward isHeirSpending to the next latest tx - - if (!rawhextx.empty()) { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hextx", rawhextx)); - } - else { - std::cerr << "HeirAdd error in FinalizeCCtx" << std::endl; - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "sign error")); - } - + std::string rawhextx = FinalizeCCTx(0, cp, mtx, myPubkey, txfee, + Helper::makeClaimOpRet(tokenid, voutTokenPubkeys, fundingtxid, (myPubkey == heirPubkey) ? 1 : hasHeirSpendingBegun)); // forward isHeirSpending to the next latest tx + + if (!rawhextx.empty()) { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hextx", rawhextx)); + } + else { + std::cerr << "HeirAdd error in FinalizeCCtx" << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "sign error")); + } + } else { fprintf(stderr, "HeirClaim() cant find Heir CC inputs\n"); result.push_back(Pair("result", "error")); @@ -935,187 +935,187 @@ template UniValue _HeirClaim(uint256 fundingtxid, uint64_t txfe result.push_back(Pair("result", "error")); result.push_back(Pair("error", "can't find sufficient user inputs to pay transaction fee")); } - - + + return result; } UniValue HeirClaimCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount) { - - CPubKey ownerPubkey, heirPubkey; - int64_t inactivityTimeSec; - - uint256 latesttxid, tokenid = zeroid; - uint8_t funcId; - std::string heirName; - uint8_t hasHeirSpendingBegun = 0; - - if ((latesttxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun)) != zeroid) { - if( tokenid == zeroid ) - return _HeirClaim(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); - else - return _HeirClaim(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); - - } - else { - UniValue result(UniValue::VOBJ); - - fprintf(stderr, "HeirClaim() can't find any heir CC funding tx's\n"); - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "can't find any heir CC funding transactions")); - return result; - } + + CPubKey ownerPubkey, heirPubkey; + int64_t inactivityTimeSec; + + uint256 latesttxid, tokenid = zeroid; + uint8_t funcId; + std::string heirName; + uint8_t hasHeirSpendingBegun = 0; + + if ((latesttxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun)) != zeroid) { + if( tokenid == zeroid ) + return _HeirClaim(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + else + return _HeirClaim(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + + } + else { + UniValue result(UniValue::VOBJ); + + fprintf(stderr, "HeirClaim() can't find any heir CC funding tx's\n"); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "can't find any heir CC funding transactions")); + return result; + } } /** * heirinfo rpc call implementation - * returns some information about heir CC contract plan by a handle of initial fundingtxid: + * returns some information about heir CC contract plan by a handle of initial fundingtxid: * plan name, owner and heir pubkeys, funds deposited and available, flag if spending is enabled for the heir * @return heir info data */ UniValue HeirInfo(uint256 fundingtxid) { UniValue result(UniValue::VOBJ); - - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction fundingtx; - uint256 hashBlock; - const bool allowSlow = false; - - //char markeraddr[64]; - //CCtxidaddr(markeraddr, fundingtxid); - //SetCCunspents(unspentOutputs, markeraddr); - - // get initial funding tx and set it as initial lasttx: - if (myGetTransaction(fundingtxid, fundingtx, hashBlock) && fundingtx.vout.size()) { - - CPubKey ownerPubkey, heirPubkey; - uint256 dummyTokenid, tokenid = zeroid; // important to clear tokenid - std::string heirName; - int64_t inactivityTimeSec; - const bool noLogging = false; - uint8_t funcId; - - /*CScript opret = fundingtx.vout.size() > 0 ? fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey : CScript(); - uint8_t funcId = DecodeHeirEitherOpRet(opret, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, true); - if (funcId == 0) { - std::cerr << "HeirInfo() this fundingtx is incorrect" << std::endl; - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "initial tx F not found")); - return result; - }*/ - - struct CC_info *cp, C; - cp = CCinit(&C, EVAL_HEIR); - - uint8_t hasHeirSpendingBegun = 0; - - uint256 latestFundingTxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); - - if (latestFundingTxid != zeroid) { - int32_t numblocks; - uint64_t durationSec = 0; - - //std::cerr << "HeirInfo() latesttxid=" << latestFundingTxid.GetHex() << '\n'; - - std::ostringstream stream; - std::string msg; - - result.push_back(Pair("fundingtxid", fundingtxid.GetHex())); - result.push_back(Pair("name", heirName.c_str())); - - if (tokenid != zeroid) { // tokens - stream << tokenid.GetHex(); - msg = "tokenid"; - result.push_back(Pair(msg, stream.str().c_str())); - stream.str(""); - stream.clear(); - } - - char hexbuf[67]; - stream << pubkey33_str(hexbuf, (uint8_t*)ownerPubkey.begin()); - result.push_back(Pair("owner", stream.str().c_str())); - stream.str(""); - stream.clear(); - - stream << pubkey33_str(hexbuf, (uint8_t*)heirPubkey.begin()); - result.push_back(Pair("heir", stream.str().c_str())); - stream.str(""); - stream.clear(); - - int64_t total; - if (tokenid == zeroid) - total = LifetimeHeirContractFunds(cp, fundingtxid, ownerPubkey, heirPubkey); - else - total = LifetimeHeirContractFunds(cp, fundingtxid, ownerPubkey, heirPubkey); - - if (tokenid == zeroid) { - msg = "funding total in coins"; - stream << (double)total / COIN; - } - else { - msg = "funding total in tokens"; - stream << total; - } - result.push_back(Pair(msg, stream.str().c_str())); - stream.str(""); - stream.clear(); - - int64_t inputs; - if (tokenid == zeroid) - inputs = Add1of2AddressInputs(cp, fundingtxid, mtx, ownerPubkey, heirPubkey, 0, 60); //NOTE: amount = 0 means all unspent inputs - else - inputs = Add1of2AddressInputs(cp, fundingtxid, mtx, ownerPubkey, heirPubkey, 0, 60); - - if (tokenid == zeroid) { - msg = "funding available in coins"; - stream << (double)inputs / COIN; - } - else { - msg = "funding available in tokens"; - stream << inputs; - } - result.push_back(Pair(msg, stream.str().c_str())); - stream.str(""); - stream.clear(); - - if (tokenid != zeroid) { - int64_t ownerInputs = TokenHelper::addOwnerInputs(tokenid, mtx, ownerPubkey, 0, (int32_t)64); - stream << ownerInputs; - msg = "owner funding available in tokens"; - result.push_back(Pair(msg, stream.str().c_str())); - stream.str(""); - stream.clear(); - } - - stream << inactivityTimeSec; - result.push_back(Pair("inactivity time setting", stream.str().c_str())); - stream.str(""); - stream.clear(); - - if (!hasHeirSpendingBegun) { // we do not need find duration if the spending already has begun - durationSec = CCduration(numblocks, latestFundingTxid); - std::cerr << "HeirInfo() duration=" << durationSec << " inactivityTime=" << inactivityTimeSec << " numblocks=" << numblocks << '\n'; - } - - stream << std::boolalpha << (hasHeirSpendingBegun || durationSec > inactivityTimeSec); - result.push_back(Pair("spending allowed for the heir", stream.str().c_str())); - stream.str(""); - stream.clear(); - - result.push_back(Pair("result", "success")); - } - else { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "could not find heir cc plan for this txid")); - } - } - else { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "could not find heir cc plan for this txid (no initial tx)")); - } - return (result); + + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + CTransaction fundingtx; + uint256 hashBlock; + const bool allowSlow = false; + + //char markeraddr[64]; + //CCtxidaddr(markeraddr, fundingtxid); + //SetCCunspents(unspentOutputs, markeraddr); + + // get initial funding tx and set it as initial lasttx: + if (myGetTransaction(fundingtxid, fundingtx, hashBlock) && fundingtx.vout.size()) { + + CPubKey ownerPubkey, heirPubkey; + uint256 dummyTokenid, tokenid = zeroid; // important to clear tokenid + std::string heirName; + int64_t inactivityTimeSec; + const bool noLogging = false; + uint8_t funcId; + + /*CScript opret = fundingtx.vout.size() > 0 ? fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey : CScript(); + uint8_t funcId = DecodeHeirEitherOpRet(opret, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, true); + if (funcId == 0) { + std::cerr << "HeirInfo() this fundingtx is incorrect" << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "initial tx F not found")); + return result; + }*/ + + struct CC_info *cp, C; + cp = CCinit(&C, EVAL_HEIR); + + uint8_t hasHeirSpendingBegun = 0; + + uint256 latestFundingTxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + + if (latestFundingTxid != zeroid) { + int32_t numblocks; + uint64_t durationSec = 0; + + //std::cerr << "HeirInfo() latesttxid=" << latestFundingTxid.GetHex() << '\n'; + + std::ostringstream stream; + std::string msg; + + result.push_back(Pair("fundingtxid", fundingtxid.GetHex())); + result.push_back(Pair("name", heirName.c_str())); + + if (tokenid != zeroid) { // tokens + stream << tokenid.GetHex(); + msg = "tokenid"; + result.push_back(Pair(msg, stream.str().c_str())); + stream.str(""); + stream.clear(); + } + + char hexbuf[67]; + stream << pubkey33_str(hexbuf, (uint8_t*)ownerPubkey.begin()); + result.push_back(Pair("owner", stream.str().c_str())); + stream.str(""); + stream.clear(); + + stream << pubkey33_str(hexbuf, (uint8_t*)heirPubkey.begin()); + result.push_back(Pair("heir", stream.str().c_str())); + stream.str(""); + stream.clear(); + + int64_t total; + if (tokenid == zeroid) + total = LifetimeHeirContractFunds(cp, fundingtxid, ownerPubkey, heirPubkey); + else + total = LifetimeHeirContractFunds(cp, fundingtxid, ownerPubkey, heirPubkey); + + if (tokenid == zeroid) { + msg = "funding total in coins"; + stream << (double)total / COIN; + } + else { + msg = "funding total in tokens"; + stream << total; + } + result.push_back(Pair(msg, stream.str().c_str())); + stream.str(""); + stream.clear(); + + int64_t inputs; + if (tokenid == zeroid) + inputs = Add1of2AddressInputs(cp, fundingtxid, mtx, ownerPubkey, heirPubkey, 0, 60); //NOTE: amount = 0 means all unspent inputs + else + inputs = Add1of2AddressInputs(cp, fundingtxid, mtx, ownerPubkey, heirPubkey, 0, 60); + + if (tokenid == zeroid) { + msg = "funding available in coins"; + stream << (double)inputs / COIN; + } + else { + msg = "funding available in tokens"; + stream << inputs; + } + result.push_back(Pair(msg, stream.str().c_str())); + stream.str(""); + stream.clear(); + + if (tokenid != zeroid) { + int64_t ownerInputs = TokenHelper::addOwnerInputs(tokenid, mtx, ownerPubkey, 0, (int32_t)64); + stream << ownerInputs; + msg = "owner funding available in tokens"; + result.push_back(Pair(msg, stream.str().c_str())); + stream.str(""); + stream.clear(); + } + + stream << inactivityTimeSec; + result.push_back(Pair("inactivity time setting", stream.str().c_str())); + stream.str(""); + stream.clear(); + + if (!hasHeirSpendingBegun) { // we do not need find duration if the spending already has begun + durationSec = CCduration(numblocks, latestFundingTxid); + std::cerr << "HeirInfo() duration=" << durationSec << " inactivityTime=" << inactivityTimeSec << " numblocks=" << numblocks << '\n'; + } + + stream << std::boolalpha << (hasHeirSpendingBegun || durationSec > inactivityTimeSec); + result.push_back(Pair("spending allowed for the heir", stream.str().c_str())); + stream.str(""); + stream.clear(); + + result.push_back(Pair("result", "success")); + } + else { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "could not find heir cc plan for this txid")); + } + } + else { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "could not find heir cc plan for this txid (no initial tx)")); + } + return (result); } /** @@ -1125,47 +1125,47 @@ UniValue HeirInfo(uint256 fundingtxid) template void _HeirList(struct CC_info *cp, UniValue &result) { - std::vector> unspentOutputs; - char coinaddr[64]; - CPubKey ccPubKeyEmpty; - GetCCaddress(cp, coinaddr, ccPubKeyEmpty); - SetCCunspents(unspentOutputs, cp->normaladdr); - - //std::cerr << "HeirList() finding heir marker from Heir contract addr=" << cp->normaladdr << " unspentOutputs.size()=" << unspentOutputs.size() << '\n'; - - // TODO: move marker to special cc addr to prevent checking all tokens - for (std::vector>::const_iterator it = unspentOutputs.begin(); it != unspentOutputs.end(); it++) { - uint256 hashBlock; - uint256 txid = it->first.txhash; - uint256 tokenid; - int32_t vout = (int32_t)it->first.index; - - //std::cerr << "HeirList() checking txid=" << txid.GetHex() << " vout=" << vout << '\n'; - - CTransaction fundingtx; - if (GetTransaction(txid, fundingtx, hashBlock, false)) { - CPubKey ownerPubkey, heirPubkey; - std::string heirName; - int64_t inactivityTimeSec; - const bool noLogging = true; - uint256 tokenid; - - CScript opret = (fundingtx.vout.size() > 0) ? fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey : CScript(); - uint8_t funcId = DecodeHeirEitherOpRet(opret, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, true); - - // note: if it is not Heir token funcId would be equal to 0 - if (funcId == 'F') { - //result.push_back(Pair("fundingtxid kind name", txid.GetHex() + std::string(" ") + (typeid(Helper) == typeid(TokenHelper) ? std::string("token") : std::string("coin")) + std::string(" ") + heirName)); - result.push_back( Pair("fundingtxid", txid.GetHex()) ); - } - else { - std::cerr << "HeirList() this is not the initial F transaction=" << txid.GetHex() << std::endl; - } - } - else { - std::cerr << "HeirList() could not load transaction=" << txid.GetHex() << std::endl; - } - } + std::vector> unspentOutputs; + char coinaddr[64]; + CPubKey ccPubKeyEmpty; + GetCCaddress(cp, coinaddr, ccPubKeyEmpty); + SetCCunspents(unspentOutputs, cp->normaladdr); + + //std::cerr << "HeirList() finding heir marker from Heir contract addr=" << cp->normaladdr << " unspentOutputs.size()=" << unspentOutputs.size() << '\n'; + + // TODO: move marker to special cc addr to prevent checking all tokens + for (std::vector>::const_iterator it = unspentOutputs.begin(); it != unspentOutputs.end(); it++) { + uint256 hashBlock; + uint256 txid = it->first.txhash; + uint256 tokenid; + int32_t vout = (int32_t)it->first.index; + + //std::cerr << "HeirList() checking txid=" << txid.GetHex() << " vout=" << vout << '\n'; + + CTransaction fundingtx; + if (GetTransaction(txid, fundingtx, hashBlock, false)) { + CPubKey ownerPubkey, heirPubkey; + std::string heirName; + int64_t inactivityTimeSec; + const bool noLogging = true; + uint256 tokenid; + + CScript opret = (fundingtx.vout.size() > 0) ? fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey : CScript(); + uint8_t funcId = DecodeHeirEitherOpRet(opret, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, true); + + // note: if it is not Heir token funcId would be equal to 0 + if (funcId == 'F') { + //result.push_back(Pair("fundingtxid kind name", txid.GetHex() + std::string(" ") + (typeid(Helper) == typeid(TokenHelper) ? std::string("token") : std::string("coin")) + std::string(" ") + heirName)); + result.push_back( Pair("fundingtxid", txid.GetHex()) ); + } + else { + std::cerr << "HeirList() this is not the initial F transaction=" << txid.GetHex() << std::endl; + } + } + else { + std::cerr << "HeirList() could not load transaction=" << txid.GetHex() << std::endl; + } + } } @@ -1173,15 +1173,16 @@ UniValue HeirList() { UniValue result(UniValue::VOBJ); result.push_back(Pair("result", "success")); - + struct CC_info *cpHeir, *cpTokens, heirC, tokenC; // NOTE we must use a separate 'C' structure for each CCinit! - cpHeir = CCinit(&heirC, EVAL_HEIR); - cpTokens = CCinit(&tokenC, EVAL_TOKENS); - - _HeirList(cpHeir, result); - _HeirList(cpTokens, result); - - return result; + cpHeir = CCinit(&heirC, EVAL_HEIR); + cpTokens = CCinit(&tokenC, EVAL_TOKENS); + + _HeirList(cpHeir, result); + _HeirList(cpTokens, result); + + return result; } + From 557886b5914d6b39a1b5f3a34f0a1c3ae1f048c6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 23:16:38 -1100 Subject: [PATCH 554/643] CC_info --- src/cc/heir_validate.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index f8e66e3d5..c41c38c09 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -123,13 +123,13 @@ public: class CValidatorBase { public: - CValidatorBase(CCcontract_info* cp) : m_cp(cp) {} + CValidatorBase(CC_info* cp) : m_cp(cp) {} virtual bool isVinValidator() const = 0; virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const = 0; virtual bool validateVout(CTxOut vout, std::string& message) const = 0; protected: - CCcontract_info * m_cp; + CC_info * m_cp; }; /** @@ -138,11 +138,11 @@ protected: class CInputIdentifierBase { public: - CInputIdentifierBase(CCcontract_info* cp) : m_cp(cp) {} + CInputIdentifierBase(CC_info* cp) : m_cp(cp) {} virtual std::string inputName() const = 0; virtual bool identifyInput(CTxIn vin) const = 0; protected: - CCcontract_info * m_cp; + CC_info * m_cp; }; /** @@ -375,7 +375,7 @@ private: class CNormalInputIdentifier : CInputIdentifierBase { public: - CNormalInputIdentifier(CCcontract_info* cp) : CInputIdentifierBase(cp) {} + CNormalInputIdentifier(CC_info* cp) : CInputIdentifierBase(cp) {} virtual std::string inputName() const { return std::string("normal input"); } virtual bool identifyInput(CTxIn vin) const { return !IsCCInput(vin.scriptSig); @@ -384,7 +384,7 @@ public: class CCCInputIdentifier : CInputIdentifierBase { public: - CCCInputIdentifier(CCcontract_info* cp) : CInputIdentifierBase(cp) {} + CCCInputIdentifier(CC_info* cp) : CInputIdentifierBase(cp) {} virtual std::string inputName() const { return std::string("CC input"); } virtual bool identifyInput(CTxIn vin) const { return IsCCInput(vin.scriptSig); @@ -398,7 +398,7 @@ public: template class CCC1of2AddressValidator : CValidatorBase { public: - CCC1of2AddressValidator(CCcontract_info* cp, CScript opRetScript, std::string customMessage = "") : + CCC1of2AddressValidator(CC_info* cp, CScript opRetScript, std::string customMessage = "") : m_fundingOpretScript(opRetScript), m_customMessage(customMessage), CValidatorBase(cp) {} virtual bool isVinValidator() const { return false; } @@ -452,7 +452,7 @@ private: template class CMyPubkeyVoutValidator : CValidatorBase { public: - CMyPubkeyVoutValidator(CCcontract_info* cp, CScript opRetScript, bool checkNormals) + CMyPubkeyVoutValidator(CC_info* cp, CScript opRetScript, bool checkNormals) : m_fundingOpretScript(opRetScript), m_checkNormals(checkNormals), CValidatorBase(cp) { } virtual bool isVinValidator() const { return false; } @@ -512,7 +512,7 @@ private: template class CHeirSpendValidator : CValidatorBase { public: - CHeirSpendValidator(CCcontract_info* cp, CScript opRetScript, uint256 latesttxid, uint8_t isHeirSpendingBegan) + CHeirSpendValidator(CC_info* cp, CScript opRetScript, uint256 latesttxid, uint8_t isHeirSpendingBegan) : m_fundingOpretScript(opRetScript), m_latesttxid(latesttxid), m_isHeirSpendingBegan(isHeirSpendingBegan), CValidatorBase(cp) {} virtual bool isVinValidator() const { return false; } @@ -568,7 +568,7 @@ private: template class COpRetValidator : CValidatorBase { public: - COpRetValidator(CCcontract_info* cp, CScript opret) + COpRetValidator(CC_info* cp, CScript opret) : m_fundingOpretScript(opret), CValidatorBase(cp) {} virtual bool isVinValidator() const { return false; } @@ -619,7 +619,7 @@ private: template class CNullValidator : CValidatorBase { public: - CNullValidator(CCcontract_info* cp) + CNullValidator(CC_info* cp) : CValidatorBase(cp) { } virtual bool isVinValidator() const { return false; } From c4d932a318885e2163474e5f0850ef2a80021011 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 23:23:08 -1100 Subject: [PATCH 555/643] Partial revert --- src/cc/CCinclude.h | 1 + src/cc/heir.cpp | 27 +++++++++++++-------------- src/cc/heir_validate.h | 32 ++++++++++++++++---------------- src/script/sign.cpp | 4 ++-- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 0b537f3d3..eda543a66 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -116,6 +116,7 @@ struct CC_info uint8_t didinit; }; +typedef struct CC_info CCcontract_info; struct CC_info *CCinit(struct CC_info *cp,uint8_t evalcode); struct oracleprice_info diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 7867032b6..ccf9da1bf 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -34,7 +34,7 @@ class TokenHelper; // Plan validation runner, it may be called twice - for coins and tokens // (sadly we cannot have yet 'templatized' lambdas, if we could we could capture all these params inside HeirValidation()...) -template bool RunValidationPlans(uint8_t funcId, struct CC_info* cp, Eval* eval, const CTransaction& tx, uint256 latestTxid, CScript fundingOpretScript, uint8_t hasHeirSpendingBegun) +template bool RunValidationPlans(uint8_t funcId, struct CCcontract_info* cp, Eval* eval, const CTransaction& tx, uint256 latestTxid, CScript fundingOpretScript, uint8_t hasHeirSpendingBegun) { int32_t numvins = tx.vin.size(); int32_t numvouts = tx.vout.size(); @@ -104,14 +104,14 @@ template bool RunValidationPlans(uint8_t funcId, struct CC_inf /** * Tx validation entry function */ -bool HeirValidate(struct CC_info* cpHeir, Eval* eval, const CTransaction& tx, uint32_t nIn) +bool HeirValidate(struct CCcontract_info* cpHeir, Eval* eval, const CTransaction& tx, uint32_t nIn) { int32_t numvins = tx.vin.size(); int32_t numvouts = tx.vout.size(); //int32_t preventCCvins = -1; //int32_t preventCCvouts = -1; - struct CC_info *cpTokens, tokensC; + struct CCcontract_info *cpTokens, tokensC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); if (numvouts < 1) @@ -237,7 +237,7 @@ bool HeirValidate(struct CC_info* cpHeir, Eval* eval, const CTransaction& tx, ui * Checks if vout is to cryptocondition address * @return vout value in satoshis */ -template int64_t IsHeirFundingVout(struct CC_info* cp, const CTransaction& tx, int32_t voutIndex, CPubKey ownerPubkey, CPubKey heirPubkey) +template int64_t IsHeirFundingVout(struct CCcontract_info* cp, const CTransaction& tx, int32_t voutIndex, CPubKey ownerPubkey, CPubKey heirPubkey) { char destaddr[65], heirFundingAddr[65]; @@ -437,7 +437,7 @@ uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &toke // TODO: correct cc addr: std::vector> unspentOutputs; - struct CC_info *cp, C; + struct CCcontract_info *cp, C; cp = CCinit(&C, EVAL_HEIR); char coinaddr[64]; GetCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); // get the address of cryptocondition '1 of 2 pubkeys' @@ -507,7 +507,7 @@ uint256 FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &token } // add inputs of 1 of 2 cc address -template int64_t Add1of2AddressInputs(struct CC_info* cp, uint256 fundingtxid, CMutableTransaction& mtx, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t total, int32_t maxinputs) +template int64_t Add1of2AddressInputs(struct CCcontract_info* cp, uint256 fundingtxid, CMutableTransaction& mtx, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t total, int32_t maxinputs) { // TODO: add threshold check int64_t nValue, voutValue, totalinputs = 0; @@ -566,7 +566,7 @@ template int64_t Add1of2AddressInputs(struct CC_info* cp, uint256 /** * enumerate all tx's sending to CCHeir 1of2address and calc total lifetime funds */ -template int64_t LifetimeHeirContractFunds(struct CC_info* cp, uint256 fundingtxid, CPubKey ownerPubkey, CPubKey heirPubkey) +template int64_t LifetimeHeirContractFunds(struct CCcontract_info* cp, uint256 fundingtxid, CPubKey ownerPubkey, CPubKey heirPubkey) { char coinaddr[64]; Helper::GetCoinsOrTokensCCaddress1of2(coinaddr, ownerPubkey, heirPubkey); // get the address of cryptocondition '1 of 2 pubkeys' @@ -619,7 +619,7 @@ template UniValue HeirFund(uint64_t txfee, int64_t amount, std { UniValue result(UniValue::VOBJ); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - struct CC_info *cp, C; + struct CCcontract_info *cp, C; cp = CCinit(&C, Helper::getMyEval()); if (txfee == 0) @@ -707,7 +707,7 @@ template UniValue _HeirAdd(uint256 fundingtxid, uint64_t txfee, i UniValue result(UniValue::VOBJ); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); int64_t inputs, CCchange = 0; - struct CC_info *cp, C; + struct CCcontract_info *cp, C; std::string rawhex; cp = CCinit(&C, Helper::getMyEval()); // for tokens shoud be EVAL_TOKENS to sign it correctly! @@ -825,7 +825,7 @@ template UniValue _HeirClaim(uint256 fundingtxid, uint64_t txfe CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CPubKey myPubkey; int64_t inputs, change = 0; - struct CC_info *cp, C; + struct CCcontract_info *cp, C; cp = CCinit(&C, EVAL_HEIR); if (txfee == 0) @@ -1006,7 +1006,7 @@ UniValue HeirInfo(uint256 fundingtxid) return result; }*/ - struct CC_info *cp, C; + struct CCcontract_info *cp, C; cp = CCinit(&C, EVAL_HEIR); uint8_t hasHeirSpendingBegun = 0; @@ -1123,7 +1123,7 @@ UniValue HeirInfo(uint256 fundingtxid) * @return list of heir plan handles (fundingtxid) */ -template void _HeirList(struct CC_info *cp, UniValue &result) +template void _HeirList(struct CCcontract_info *cp, UniValue &result) { std::vector> unspentOutputs; char coinaddr[64]; @@ -1174,7 +1174,7 @@ UniValue HeirList() UniValue result(UniValue::VOBJ); result.push_back(Pair("result", "success")); - struct CC_info *cpHeir, *cpTokens, heirC, tokenC; // NOTE we must use a separate 'C' structure for each CCinit! + struct CCcontract_info *cpHeir, *cpTokens, heirC, tokenC; // NOTE we must use a separate 'C' structure for each CCinit! cpHeir = CCinit(&heirC, EVAL_HEIR); cpTokens = CCinit(&tokenC, EVAL_TOKENS); @@ -1185,4 +1185,3 @@ UniValue HeirList() return result; } - diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index c41c38c09..c4bb7ea60 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -47,11 +47,11 @@ public: return CTxOut(amount, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG); } */ static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { - struct CC_info *cpHeir, heirC; + struct CCcontract_info *cpHeir, heirC; cpHeir = CCinit(&heirC, EVAL_HEIR); return GetCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); } - static void CCaddrCoinsOrTokens1of2set(struct CC_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { + static void CCaddrCoinsOrTokens1of2set(struct CCcontract_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { CCaddr1of2set(cp, ownerPubkey, heirPubkey, coinaddr); } }; @@ -61,7 +61,7 @@ class TokenHelper { public: static uint8_t getMyEval() { return EVAL_TOKENS; } static int64_t addOwnerInputs(uint256 tokenid, CMutableTransaction& mtx, CPubKey ownerPubkey, int64_t total, int32_t maxinputs) { - struct CC_info *cpHeir, heirC; + struct CCcontract_info *cpHeir, heirC; cpHeir = CCinit(&heirC, EVAL_TOKENS); return AddTokenCCInputs(cpHeir, mtx, ownerPubkey, tokenid, total, maxinputs); } @@ -89,12 +89,12 @@ public: return MakeCC1vout(EVAL_TOKENS, amount, myPubkey); // yes EVAL_TOKENS } */ static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { - struct CC_info *cpHeir, heirC; + struct CCcontract_info *cpHeir, heirC; cpHeir = CCinit(&heirC, EVAL_HEIR); return GetTokensCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); } - static void CCaddrCoinsOrTokens1of2set(struct CC_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { + static void CCaddrCoinsOrTokens1of2set(struct CCcontract_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { CCaddrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); } @@ -123,13 +123,13 @@ public: class CValidatorBase { public: - CValidatorBase(CC_info* cp) : m_cp(cp) {} + CValidatorBase(CCcontract_info* cp) : m_cp(cp) {} virtual bool isVinValidator() const = 0; virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const = 0; virtual bool validateVout(CTxOut vout, std::string& message) const = 0; protected: - CC_info * m_cp; + CCcontract_info * m_cp; }; /** @@ -138,11 +138,11 @@ protected: class CInputIdentifierBase { public: - CInputIdentifierBase(CC_info* cp) : m_cp(cp) {} + CInputIdentifierBase(CCcontract_info* cp) : m_cp(cp) {} virtual std::string inputName() const = 0; virtual bool identifyInput(CTxIn vin) const = 0; protected: - CC_info * m_cp; + CCcontract_info * m_cp; }; /** @@ -375,7 +375,7 @@ private: class CNormalInputIdentifier : CInputIdentifierBase { public: - CNormalInputIdentifier(CC_info* cp) : CInputIdentifierBase(cp) {} + CNormalInputIdentifier(CCcontract_info* cp) : CInputIdentifierBase(cp) {} virtual std::string inputName() const { return std::string("normal input"); } virtual bool identifyInput(CTxIn vin) const { return !IsCCInput(vin.scriptSig); @@ -384,7 +384,7 @@ public: class CCCInputIdentifier : CInputIdentifierBase { public: - CCCInputIdentifier(CC_info* cp) : CInputIdentifierBase(cp) {} + CCCInputIdentifier(CCcontract_info* cp) : CInputIdentifierBase(cp) {} virtual std::string inputName() const { return std::string("CC input"); } virtual bool identifyInput(CTxIn vin) const { return IsCCInput(vin.scriptSig); @@ -398,7 +398,7 @@ public: template class CCC1of2AddressValidator : CValidatorBase { public: - CCC1of2AddressValidator(CC_info* cp, CScript opRetScript, std::string customMessage = "") : + CCC1of2AddressValidator(CCcontract_info* cp, CScript opRetScript, std::string customMessage = "") : m_fundingOpretScript(opRetScript), m_customMessage(customMessage), CValidatorBase(cp) {} virtual bool isVinValidator() const { return false; } @@ -452,7 +452,7 @@ private: template class CMyPubkeyVoutValidator : CValidatorBase { public: - CMyPubkeyVoutValidator(CC_info* cp, CScript opRetScript, bool checkNormals) + CMyPubkeyVoutValidator(CCcontract_info* cp, CScript opRetScript, bool checkNormals) : m_fundingOpretScript(opRetScript), m_checkNormals(checkNormals), CValidatorBase(cp) { } virtual bool isVinValidator() const { return false; } @@ -512,7 +512,7 @@ private: template class CHeirSpendValidator : CValidatorBase { public: - CHeirSpendValidator(CC_info* cp, CScript opRetScript, uint256 latesttxid, uint8_t isHeirSpendingBegan) + CHeirSpendValidator(CCcontract_info* cp, CScript opRetScript, uint256 latesttxid, uint8_t isHeirSpendingBegan) : m_fundingOpretScript(opRetScript), m_latesttxid(latesttxid), m_isHeirSpendingBegan(isHeirSpendingBegan), CValidatorBase(cp) {} virtual bool isVinValidator() const { return false; } @@ -568,7 +568,7 @@ private: template class COpRetValidator : CValidatorBase { public: - COpRetValidator(CC_info* cp, CScript opret) + COpRetValidator(CCcontract_info* cp, CScript opret) : m_fundingOpretScript(opret), CValidatorBase(cp) {} virtual bool isVinValidator() const { return false; } @@ -619,7 +619,7 @@ private: template class CNullValidator : CValidatorBase { public: - CNullValidator(CC_info* cp) + CNullValidator(CCcontract_info* cp) : CValidatorBase(cp) { } virtual bool isVinValidator() const { return false; } diff --git a/src/script/sign.cpp b/src/script/sign.cpp index f7f663db2..685018828 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -136,7 +136,7 @@ std::vector &GetCryptoConditions() return vCC; } -bool GetCCByUnspendableAddress(struct CC_info *cp, char *addrstr) +bool GetCCByUnspendableAddress(struct CCcontract_info *cp, char *addrstr) { std::vector &vCC = GetCryptoConditions(); bool found = false; @@ -153,7 +153,7 @@ bool GetCCByUnspendableAddress(struct CC_info *cp, char *addrstr) return found; } -bool CCinitLite(struct CC_info *cp, uint8_t evalcode) +bool CCinitLite(struct CCcontract_info *cp, uint8_t evalcode) { std::vector &vCC = GetCryptoConditions(); bool found = false; From 62322eb58954690d645b1006849f282384691af4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 23:31:12 -1100 Subject: [PATCH 556/643] struct CCcontract_info --- src/cc/CC made easy.md | 8 +++---- src/cc/CCGateways.h | 2 +- src/cc/CCHeir.h | 4 ++-- src/cc/CCMarmara.h | 2 +- src/cc/CCOracles.h | 2 +- src/cc/CCPayments.h | 2 +- src/cc/CCPegs.h | 2 +- src/cc/CCPrices.h | 2 +- src/cc/CCassets.h | 12 +++++----- src/cc/CCassetsCore.cpp | 18 +++++++-------- src/cc/CCassetstx.cpp | 34 +++++++++++++-------------- src/cc/CCauction.h | 2 +- src/cc/CCchannels.h | 2 +- src/cc/CCcustom.cpp | 4 ++-- src/cc/CCdice.h | 4 ++-- src/cc/CCfaucet.h | 2 +- src/cc/CCfsm.h | 2 +- src/cc/CCinclude.h | 37 +++++++++++++++-------------- src/cc/CClotto.h | 2 +- src/cc/CCrewards.h | 2 +- src/cc/CCtokens.cpp | 22 +++++++++--------- src/cc/CCtokens.h | 8 +++---- src/cc/CCtx.cpp | 4 ++-- src/cc/CCutils.cpp | 28 +++++++++++----------- src/cc/assets.cpp | 4 ++-- src/cc/auction.cpp | 14 +++++------ src/cc/cclib.cpp | 10 ++++---- src/cc/channels.cpp | 22 +++++++++--------- src/cc/dice.cpp | 34 +++++++++++++-------------- src/cc/eval.cpp | 4 ++-- src/cc/eval.h | 4 ++-- src/cc/faucet.cpp | 14 +++++------ src/cc/fsm.cpp | 12 +++++----- src/cc/gateways.cpp | 36 ++++++++++++++--------------- src/cc/lotto.cpp | 20 ++++++++-------- src/cc/marmara.cpp | 26 ++++++++++----------- src/cc/oracles.cpp | 30 ++++++++++++------------ src/cc/payments.cpp | 14 +++++------ src/cc/pegs.cpp | 14 +++++------ src/cc/prices.cpp | 14 +++++------ src/cc/rewards.cpp | 24 +++++++++---------- src/komodo_bitcoind.h | 2 +- src/wallet/rpcwallet.cpp | 50 ++++++++++++++++++++-------------------- 43 files changed, 277 insertions(+), 278 deletions(-) diff --git a/src/cc/CC made easy.md b/src/cc/CC made easy.md index f409efb2d..2d1081003 100644 --- a/src/cc/CC made easy.md +++ b/src/cc/CC made easy.md @@ -206,13 +206,13 @@ The idea is that people send funds to the faucet by locking it in faucet's globa There are only 7 functions in faucet.cpp, a bit over 200 lines including comments. The first three are for validation, the last four for the rpc calls to use. -int64_t IsFaucetvout(struct CC_info *cp,const CTransaction& tx,int32_t v) +int64_t IsFaucetvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) -bool FaucetExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool FaucetExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) -bool FaucetValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx) +bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) -int64_t AddFaucetInputs(struct CC_infoCC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddFaucetInputs(struct CCcontract_infoCC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) std::string FaucetGet(uint64_t txfee) diff --git a/src/cc/CCGateways.h b/src/cc/CCGateways.h index 0ffeced6e..b629ade1f 100644 --- a/src/cc/CCGateways.h +++ b/src/cc/CCGateways.h @@ -20,7 +20,7 @@ #include "CCinclude.h" #include "../merkleblock.h" -bool GatewaysValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool GatewaysValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t totalsupply,uint256 oracletxid,uint8_t M,uint8_t N,std::vector pubkeys); std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std::string refcoin,uint256 cointxid,int32_t claimvout,std::string deposithex,std::vectorproof,CPubKey destpub,int64_t amount); std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,uint256 deposittxid,CPubKey destpub,int64_t amount); diff --git a/src/cc/CCHeir.h b/src/cc/CCHeir.h index 1e831e772..ecaff9cdb 100644 --- a/src/cc/CCHeir.h +++ b/src/cc/CCHeir.h @@ -22,7 +22,7 @@ //#define EVAL_HEIR 0xea -bool HeirValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool HeirValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); class CoinHelper; class TokenHelper; @@ -36,6 +36,6 @@ UniValue HeirInfo(uint256 fundingtxid); UniValue HeirList(); //std::string Heir_MakeBadTx(uint256 fundingtxid, uint8_t funcId, int64_t amount, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTime, uint32_t errMask); -//bool HeirExactTokenAmounts(bool compareTotals, struct CC_info *cpHeir, Eval* eval, uint256 assetid, const CTransaction &tx); +//bool HeirExactTokenAmounts(bool compareTotals, struct CCcontract_info *cpHeir, Eval* eval, uint256 assetid, const CTransaction &tx); #endif diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 567f43aa3..65269df77 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -38,7 +38,7 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t amount,std::string currency,int32_t matures,uint256 approvaltxid,uint256 batontxid); UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,std::string currency); -bool MarmaraValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom UniValue MarmaraInfo(); diff --git a/src/cc/CCOracles.h b/src/cc/CCOracles.h index a46d0c311..7f952e5f5 100644 --- a/src/cc/CCOracles.h +++ b/src/cc/CCOracles.h @@ -19,7 +19,7 @@ #include "CCinclude.h" -bool OraclesValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); std::string OracleCreate(int64_t txfee,std::string name,std::string description,std::string format); std::string OracleRegister(int64_t txfee,uint256 oracletxid,int64_t datafee); std::string OracleSubscribe(int64_t txfee,uint256 oracletxid,CPubKey publisher,int64_t amount); diff --git a/src/cc/CCPayments.h b/src/cc/CCPayments.h index f229212fb..187d9c9ad 100644 --- a/src/cc/CCPayments.h +++ b/src/cc/CCPayments.h @@ -19,7 +19,7 @@ #include "CCinclude.h" -bool PaymentsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom UniValue PaymentsInfo(); diff --git a/src/cc/CCPegs.h b/src/cc/CCPegs.h index a7863a3ec..8d2a268f1 100644 --- a/src/cc/CCPegs.h +++ b/src/cc/CCPegs.h @@ -19,7 +19,7 @@ #include "CCinclude.h" -bool PegsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool PegsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom UniValue PegsInfo(); diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index fe625e31b..1a68be7dd 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -19,7 +19,7 @@ #include "CCinclude.h" -bool PricesValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom UniValue PricesList(); diff --git a/src/cc/CCassets.h b/src/cc/CCassets.h index 061e0f899..69fcfacbb 100644 --- a/src/cc/CCassets.h +++ b/src/cc/CCassets.h @@ -26,7 +26,7 @@ #include "CCinclude.h" // CCcustom -bool AssetsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCassetsCore //CTxOut MakeAssetsVout(CAmount nValue,CPubKey pk); @@ -35,20 +35,20 @@ bool AssetsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32 //bool DecodeAssetCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description); //uint8_t DecodeAssetOpRet(const CScript &scriptPubKey, uint8_t &evalCode, uint256 &assetid, uint256 &assetid2, int64_t &price, std::vector &origpubkey); bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CTransaction &tx); -int64_t IsAssetvout(struct CC_info *cp, int64_t &price, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 refassetid); +int64_t IsAssetvout(struct CCcontract_info *cp, int64_t &price, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 refassetid); bool ValidateBidRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); bool ValidateAskRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); bool ValidateSwapRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); bool SetBidFillamounts(int64_t &paid,int64_t &remaining_price,int64_t orig_nValue,int64_t &received,int64_t totalprice); bool SetAskFillamounts(int64_t &paid,int64_t &remaining_price,int64_t orig_nValue,int64_t &received,int64_t totalprice); bool SetSwapFillamounts(int64_t &paid,int64_t &remaining_price,int64_t orig_nValue,int64_t &received,int64_t totalprice); -int64_t AssetValidateBuyvin(struct CC_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 refassetid); -int64_t AssetValidateSellvin(struct CC_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 assetid); -bool AssetCalcAmounts(struct CC_info *cpAssets, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 assetid); +int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 refassetid); +int64_t AssetValidateSellvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 assetid); +bool AssetCalcAmounts(struct CCcontract_info *cpAssets, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 assetid); // CCassetstx //int64_t GetAssetBalance(CPubKey pk,uint256 tokenid); // --> GetTokenBalance() -int64_t AddAssetInputs(struct CC_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 assetid, int64_t total, int32_t maxinputs); +int64_t AddAssetInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 assetid, int64_t total, int32_t maxinputs); UniValue AssetOrders(uint256 tokenid); //UniValue AssetInfo(uint256 tokenid); diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index 45d3421be..1b8e46189 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -365,7 +365,7 @@ bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CT } // Calculate sell/buy owner's source token/asset address from ask/bid tx -bool GetAssetorigaddrs(struct CC_info *cp, char *userCCaddr, char *destaddr, const CTransaction& tx) +bool GetAssetorigaddrs(struct CCcontract_info *cp, char *userCCaddr, char *destaddr, const CTransaction& tx) { uint256 assetid,assetid2; int64_t price,nValue=0; int32_t n; uint8_t funcid; std::vector origpubkey; @@ -378,13 +378,13 @@ bool GetAssetorigaddrs(struct CC_info *cp, char *userCCaddr, char *destaddr, con bool bGetCCaddr = false; if (funcid == 's' || funcid == 'S') { - struct CC_info *cpTokens, tokensC; + struct CCcontract_info *cpTokens, tokensC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); bGetCCaddr = GetCCaddress(cpTokens, userCCaddr, pubkey2pk(origpubkey)); //bGetCCaddr = GetTokensCCaddress(cp, CCaddr, pubkey2pk(origpubkey)); } else if (funcid == 'b' || funcid == 'B') { - struct CC_info *cpTokens, tokensC; + struct CCcontract_info *cpTokens, tokensC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); bGetCCaddr = GetCCaddress(cpTokens, userCCaddr, pubkey2pk(origpubkey)); } @@ -400,7 +400,7 @@ bool GetAssetorigaddrs(struct CC_info *cp, char *userCCaddr, char *destaddr, con } -int64_t AssetValidateCCvin(struct CC_info *cp,Eval* eval,char *CCaddr,char *origaddr,const CTransaction &tx,int32_t vini,CTransaction &vinTx) +int64_t AssetValidateCCvin(struct CCcontract_info *cp,Eval* eval,char *CCaddr,char *origaddr,const CTransaction &tx,int32_t vini,CTransaction &vinTx) { uint256 hashBlock; uint256 assetid, assetid2; @@ -463,7 +463,7 @@ int64_t AssetValidateCCvin(struct CC_info *cp,Eval* eval,char *CCaddr,char *orig return(vinTx.vout[0].nValue); } -int64_t AssetValidateBuyvin(struct CC_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 refassetid) +int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 refassetid) { CTransaction vinTx; int64_t nValue; uint256 assetid,assetid2; uint8_t funcid, evalCode; CCaddr[0] = origaddr[0] = 0; @@ -490,7 +490,7 @@ int64_t AssetValidateBuyvin(struct CC_info *cp,Eval* eval,int64_t &tmpprice,std: return(nValue); } -int64_t AssetValidateSellvin(struct CC_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 assetid) +int64_t AssetValidateSellvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 assetid) { CTransaction vinTx; int64_t nValue,assetoshis; //fprintf(stderr,"AssetValidateSellvin\n"); @@ -558,7 +558,7 @@ bool ValidateAssetOpret(CTransaction tx, int32_t v, uint256 assetid, int64_t &pr // Checks if the vout is a really Asset CC vout // compareTotals == true, the func also validates the passed transaction itself: // it should be either sum(cc vins) == sum(cc vouts) or the transaction is the 'tokenbase' ('c') tx -int64_t IsAssetvout(struct CC_info *cp, int64_t &price, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 refassetid) +int64_t IsAssetvout(struct CCcontract_info *cp, int64_t &price, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 refassetid) { //std::cerr << "IsAssetvout() entered for txid=" << tx.GetHash().GetHex() << " v=" << v << " for assetid=" << refassetid.GetHex() << std::endl; @@ -587,14 +587,14 @@ int64_t IsAssetvout(struct CC_info *cp, int64_t &price, std::vector &or } // sets cc inputs vs cc outputs and ensures they are equal: -bool AssetCalcAmounts(struct CC_info *cpAssets, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 assetid) +bool AssetCalcAmounts(struct CCcontract_info *cpAssets, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 assetid) { CTransaction vinTx; uint256 hashBlock, id, id2; int32_t flag; int64_t assetoshis; std::vector tmporigpubkey; int64_t tmpprice; int32_t numvins = tx.vin.size(); int32_t numvouts = tx.vout.size(); inputs = outputs = 0; - struct CC_info *cpTokens, C; + struct CCcontract_info *cpTokens, C; cpTokens = CCinit(&C, EVAL_TOKENS); diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index dff279acd..968775d38 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -17,7 +17,7 @@ //#include "CCtokens.h" -int64_t AddAssetInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs) +int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs) { char coinaddr[64],destaddr[64]; int64_t threshold,nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t j,vout,n = 0; std::vector > unspentOutputs; @@ -72,13 +72,13 @@ UniValue AssetOrders(uint256 refassetid) UniValue result(UniValue::VARR); std::vector > unspentOutputsTokens, unspentOutputsAssets; - struct CC_info *cpTokens, tokensC; - struct CC_info *cpAssets, assetsC; + struct CCcontract_info *cpTokens, tokensC; + struct CCcontract_info *cpAssets, assetsC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); cpAssets = CCinit(&assetsC, EVAL_ASSETS); - auto addOrders = [&](struct CC_info *cp, std::vector >::const_iterator it) + auto addOrders = [&](struct CCcontract_info *cp, std::vector >::const_iterator it) { uint256 txid, hashBlock, assetid, assetid2; int64_t price; @@ -189,7 +189,7 @@ UniValue AssetOrders(uint256 refassetid) /* std::string CreateAsset(int64_t txfee,int64_t assetsupply,std::string name,std::string description) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; struct CC_info *cp,C; + CPubKey mypk; struct CCcontract_info *cp,C; if ( assetsupply < 0 ) { fprintf(stderr,"negative assetsupply %lld\n",(long long)assetsupply); @@ -217,7 +217,7 @@ UniValue AssetOrders(uint256 refassetid) /* std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; uint64_t mask; int64_t CCchange=0,inputs=0; struct CC_info *cp,C; + CPubKey mypk; uint64_t mask; int64_t CCchange=0,inputs=0; struct CCcontract_info *cp,C; if ( total < 0 ) { fprintf(stderr,"negative total %lld\n",(long long)total); @@ -259,7 +259,7 @@ UniValue AssetOrders(uint256 refassetid) /* std::string AssetConvert(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total,int32_t evalcode) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; int64_t CCchange=0,inputs=0; struct CC_info *cp,C; + CPubKey mypk; int64_t CCchange=0,inputs=0; struct CCcontract_info *cp,C; if ( total < 0 ) { fprintf(stderr,"negative total %lld\n",(long long)total); @@ -288,7 +288,7 @@ std::string CreateBuyOffer(int64_t txfee, int64_t bidamount, uint256 assetid, in { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CPubKey mypk; - struct CC_info *cpAssets, C; + struct CCcontract_info *cpAssets, C; uint256 hashBlock; CTransaction vintx; std::vector origpubkey; @@ -349,8 +349,8 @@ std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t p uint64_t mask; int64_t inputs, CCchange; CScript opret; - struct CC_info *cpAssets, assetsC; - struct CC_info *cpTokens, tokensC; + struct CCcontract_info *cpAssets, assetsC; + struct CCcontract_info *cpTokens, tokensC; //std::cerr << "CreateSell() askamount=" << askamount << " pricetotal=" << pricetotal << std::endl; @@ -408,7 +408,7 @@ std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t p std::string CreateSwap(int64_t txfee,int64_t askamount,uint256 assetid,uint256 assetid2,int64_t pricetotal) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; uint64_t mask; int64_t inputs,CCchange; CScript opret; struct CC_info *cp,C; + CPubKey mypk; uint64_t mask; int64_t inputs,CCchange; CScript opret; struct CCcontract_info *cp,C; ////////////////////////// NOT IMPLEMENTED YET///////////////////////////////// fprintf(stderr,"asset swaps disabled\n"); @@ -482,7 +482,7 @@ std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid) uint256 hashBlock; int64_t bidamount; CPubKey mypk; - struct CC_info *cpAssets, C; + struct CCcontract_info *cpAssets, C; uint8_t dummyEvalCode; uint256 dummyAssetid, dummyAssetid2; int64_t dummyPrice; std::vector dummyOrigpubkey; @@ -526,7 +526,7 @@ std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) uint256 hashBlock; int64_t askamount; CPubKey mypk; - struct CC_info *cpTokens, *cpAssets, tokensC, assetsC; + struct CCcontract_info *cpTokens, *cpAssets, tokensC, assetsC; uint8_t dummyEvalCode; uint256 dummyAssetid, dummyAssetid2; int64_t dummyPrice; std::vector dummyOrigpubkey; @@ -592,8 +592,8 @@ std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t f int32_t bidvout=0; uint64_t mask; int64_t origprice, bidamount, paid_amount, remaining_required, inputs, CCchange=0; - struct CC_info *cpTokens, tokensC; - struct CC_info *cpAssets, assetsC; + struct CCcontract_info *cpTokens, tokensC; + struct CCcontract_info *cpAssets, assetsC; if (fillamount < 0) { @@ -676,8 +676,8 @@ std::string FillSell(int64_t txfee, uint256 assetid, uint256 assetid2, uint256 a uint64_t mask = 0; int32_t askvout = 0; int64_t received_assetoshis, total_nValue, orig_assetoshis, paid_nValue, remaining_nValue, inputs, CCchange=0; - //struct CC_info *cpTokens, tokensC; - struct CC_info *cpAssets, assetsC; + //struct CCcontract_info *cpTokens, tokensC; + struct CCcontract_info *cpAssets, assetsC; if (fillunits < 0) { diff --git a/src/cc/CCauction.h b/src/cc/CCauction.h index 13393d510..cfcd615cc 100644 --- a/src/cc/CCauction.h +++ b/src/cc/CCauction.h @@ -21,7 +21,7 @@ #define EVAL_AUCTION 0xe8 -bool AuctionValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool AuctionValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); std::string AuctionPost(uint64_t txfee,uint256 itemhash,int64_t minbid,char *title,char *description); std::string AuctionBid(uint64_t txfee,uint256 itemhash,int64_t amount); diff --git a/src/cc/CCchannels.h b/src/cc/CCchannels.h index 76e0ab8cf..10cb4d224 100644 --- a/src/cc/CCchannels.h +++ b/src/cc/CCchannels.h @@ -20,7 +20,7 @@ #include "CCinclude.h" #define CHANNELS_MAXPAYMENTS 1000 -bool ChannelsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64_t payment,uint256 tokenid); std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint256 secret); std::string ChannelClose(uint64_t txfee,uint256 opentxid); diff --git a/src/cc/CCcustom.cpp b/src/cc/CCcustom.cpp index c05210542..577332b63 100644 --- a/src/cc/CCcustom.cpp +++ b/src/cc/CCcustom.cpp @@ -243,7 +243,7 @@ uint8_t CClibCCpriv[32] = { 0x57, 0xcf, 0x49, 0x71, 0x7d, 0xb4, 0x15, 0x1b, 0x4f #undef FUNCNAME #undef EVALCODE -int32_t CClib_initcp(struct CC_info *cp,uint8_t evalcode) +int32_t CClib_initcp(struct CCcontract_info *cp,uint8_t evalcode) { CPubKey pk; uint8_t pub33[33]; char CCaddr[64]; if ( evalcode == EVAL_FIRSTUSER ) // eventually make a hashchain for each evalcode @@ -263,7 +263,7 @@ int32_t CClib_initcp(struct CC_info *cp,uint8_t evalcode) return(-1); } -struct CC_info *CCinit(struct CC_info *cp, uint8_t evalcode) +struct CCcontract_info *CCinit(struct CCcontract_info *cp, uint8_t evalcode) { cp->evalcode = evalcode; switch ( evalcode ) diff --git a/src/cc/CCdice.h b/src/cc/CCdice.h index 0de222c50..363aad735 100644 --- a/src/cc/CCdice.h +++ b/src/cc/CCdice.h @@ -21,7 +21,7 @@ #define EVAL_DICE 0xe6 -bool DiceValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool DiceValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds); std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t &entropyvout,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout,uint256 vin0txid,int32_t vin0vout); @@ -30,6 +30,6 @@ std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount); UniValue DiceInfo(uint256 diceid); UniValue DiceList(); -int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CC_info *cp,CPubKey dicepk,uint256 reffundingtxid, int32_t &entropytxs,bool random); +int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CCcontract_info *cp,CPubKey dicepk,uint256 reffundingtxid, int32_t &entropytxs,bool random); #endif diff --git a/src/cc/CCfaucet.h b/src/cc/CCfaucet.h index 4bb2ae0d7..3cb6c66e5 100644 --- a/src/cc/CCfaucet.h +++ b/src/cc/CCfaucet.h @@ -22,7 +22,7 @@ #define EVAL_FAUCET 0xe4 #define FAUCETSIZE (COIN / 10) -bool FaucetValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom std::string FaucetFund(uint64_t txfee,int64_t funds); diff --git a/src/cc/CCfsm.h b/src/cc/CCfsm.h index 0690e4dd2..2bce35597 100644 --- a/src/cc/CCfsm.h +++ b/src/cc/CCfsm.h @@ -21,7 +21,7 @@ #define EVAL_FSM 0xe7 -bool FSMValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool FSMValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); std::string FSMList(); std::string FSMInfo(uint256 fsmtxid); diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index eda543a66..82c9484d5 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -88,7 +88,7 @@ struct CC_meta // followed by address destinations }; -struct CC_info +struct CCcontract_info { // this is for spending from 'unspendable' CC address uint8_t evalcode; @@ -111,13 +111,12 @@ struct CC_info uint8_t unspendablepriv2[32], unspendablepriv3[32]; CPubKey unspendablepk2, unspendablepk3; - bool (*validate)(struct CC_info *cp, Eval* eval, const CTransaction &tx, uint32_t nIn); // cc contract tx validation callback + bool (*validate)(struct CCcontract_info *cp, Eval* eval, const CTransaction &tx, uint32_t nIn); // cc contract tx validation callback bool (*ismyvin)(CScript const& scriptSig); // checks if evalcode is present in the scriptSig param uint8_t didinit; }; -typedef struct CC_info CCcontract_info; -struct CC_info *CCinit(struct CC_info *cp,uint8_t evalcode); +struct CCcontract_info *CCinit(struct CCcontract_info *cp,uint8_t evalcode); struct oracleprice_info { @@ -135,7 +134,7 @@ CBlockIndex *komodo_getblockindex(uint256 hash); int32_t komodo_nextheight(); int32_t CCgetspenttxid(uint256 &spenttxid,int32_t &vini,int32_t &height,uint256 txid,int32_t vout); -void CCclearvars(struct CC_info *cp); +void CCclearvars(struct CCcontract_info *cp); static const uint256 zeroid; bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock); @@ -159,9 +158,9 @@ uint8_t DecodeOraclesCreateOpRet(const CScript &scriptPubKey,std::string &name,s uint256 OracleMerkle(int32_t height,uint256 reforacletxid,char *format,std::vectorpublishers); uint256 OraclesBatontxid(uint256 oracletxid,CPubKey pk); -//int64_t AddAssetInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs); -int64_t AddTokenCCInputs(struct CC_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs); -int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CC_info *cp, Eval* eval, const CTransaction& tx, int32_t v, uint256 reftokenid); +//int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs); +int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs); +int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, const CTransaction& tx, int32_t v, uint256 reftokenid); bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx); CScript EncodeAssetOpRet(uint8_t assetFuncId, uint256 assetid2, int64_t price, std::vector origpubkey); @@ -179,7 +178,7 @@ int32_t oracle_format(uint256 *hashp,int64_t *valp,char *str,uint8_t fmt,uint8_t // CCcustom -CPubKey GetUnspendable(struct CC_info *cp,uint8_t *unspendablepriv); +CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv); // CCutils CPubKey buf2pk(uint8_t *buf33); @@ -190,19 +189,19 @@ CTxOut MakeCC1of2vout(uint8_t evalcode,CAmount nValue,CPubKey pk,CPubKey pk2); CC *MakeCCcond1(uint8_t evalcode,CPubKey pk); CC *MakeCCcond1of2(uint8_t evalcode,CPubKey pk1,CPubKey pk2); CC* GetCryptoCondition(CScript const& scriptSig); -void CCaddr2set(struct CC_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr); -void CCaddr3set(struct CC_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr); -void CCaddr1of2set(struct CC_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr); +void CCaddr2set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr); +void CCaddr3set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr); +void CCaddr1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr); CTxOut MakeTokensCC1of2vout(uint8_t evalcode, CAmount nValue, CPubKey pk1, CPubKey pk2); CTxOut MakeTokensCC1vout(uint8_t evalcode, CAmount nValue, CPubKey pk); CC *MakeTokensCCcond1of2(uint8_t evalcode, CPubKey pk1, CPubKey pk2); CC *MakeTokensCCcond1(uint8_t evalcode, CPubKey pk); -bool GetTokensCCaddress(struct CC_info *cp, char *destaddr, CPubKey pk); -bool GetTokensCCaddress1of2(struct CC_info *cp, char *destaddr, CPubKey pk, CPubKey pk2); -void CCaddrTokens1of2set(struct CC_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr); -int32_t CClib_initcp(struct CC_info *cp,uint8_t evalcode); +bool GetTokensCCaddress(struct CCcontract_info *cp, char *destaddr, CPubKey pk); +bool GetTokensCCaddress1of2(struct CCcontract_info *cp, char *destaddr, CPubKey pk, CPubKey pk2); +void CCaddrTokens1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr); +int32_t CClib_initcp(struct CCcontract_info *cp,uint8_t evalcode); bool IsCCInput(CScript const& scriptSig); int32_t unstringbits(char *buf,uint64_t bits); @@ -217,8 +216,8 @@ int64_t CCfullsupply(uint256 tokenid); int64_t CCtoken_balance(char *destaddr,uint256 tokenid); int64_t CCtoken_balance2(char *destaddr,uint256 tokenid); bool _GetCCaddress(char *destaddr,uint8_t evalcode,CPubKey pk); -bool GetCCaddress(struct CC_info *cp,char *destaddr,CPubKey pk); -bool GetCCaddress1of2(struct CC_info *cp,char *destaddr,CPubKey pk,CPubKey pk2); +bool GetCCaddress(struct CCcontract_info *cp,char *destaddr,CPubKey pk); +bool GetCCaddress1of2(struct CCcontract_info *cp,char *destaddr,CPubKey pk,CPubKey pk2); bool ConstrainVout(CTxOut vout,int32_t CCflag,char *cmpaddr,int64_t nValue); bool PreventCC(Eval* eval,const CTransaction &tx,int32_t preventCCvins,int32_t numvins,int32_t preventCCvouts,int32_t numvouts); bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); @@ -230,7 +229,7 @@ CPubKey check_signing_pubkey(CScript scriptSig); // CCtx bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey); extern std::vector NULL_pubkeys; -std::string FinalizeCCTx(uint64_t skipmask,struct CC_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys = NULL_pubkeys); +std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys = NULL_pubkeys); void SetCCunspents(std::vector > &unspentOutputs,char *coinaddr); void SetCCtxids(std::vector > &addressIndex,char *coinaddr); int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs); diff --git a/src/cc/CClotto.h b/src/cc/CClotto.h index 4ef147cef..2f0595371 100644 --- a/src/cc/CClotto.h +++ b/src/cc/CClotto.h @@ -21,7 +21,7 @@ #define EVAL_LOTTO 0xe9 -bool LottoValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool LottoValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); UniValue LottoInfo(uint256 lottoid); UniValue LottoList(); diff --git a/src/cc/CCrewards.h b/src/cc/CCrewards.h index 41977f915..4d6cc80f9 100644 --- a/src/cc/CCrewards.h +++ b/src/cc/CCrewards.h @@ -22,7 +22,7 @@ #define EVAL_REWARDS 0xe5 #define REWARDSCC_MAXAPR (COIN * 25) -bool RewardsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); UniValue RewardsInfo(uint256 rewardid); UniValue RewardsList(); diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 6620a9cd8..bdb710afb 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -177,7 +177,7 @@ uint8_t DecodeTokenOpRet(const CScript scriptPubKey, uint8_t &evalCode, uint256 // tx validation -bool TokensValidate(struct CC_info *cp, Eval* eval, const CTransaction &tx, uint32_t nIn) +bool TokensValidate(struct CCcontract_info *cp, Eval* eval, const CTransaction &tx, uint32_t nIn) { static uint256 zero; CTxDestination address; CTransaction vinTx, createTx; uint256 hashBlock, tokenid, tokenid2; @@ -251,7 +251,7 @@ bool TokensValidate(struct CC_info *cp, Eval* eval, const CTransaction &tx, uint // forward validation if evalcode in opret is not EVAL_TOKENS // init for forwarding validation call //if (evalCodeInOpret != EVAL_TOKENS) { // TODO: should we check also only allowed for tokens evalcodes, like EVAL_ASSETS, EVAL_GATEWAYS? - // struct CC_info *cpOther = NULL, C; + // struct CCcontract_info *cpOther = NULL, C; // cpOther = CCinit(&C, evalCodeInOpret); // if (cpOther) @@ -271,7 +271,7 @@ bool ExtractTokensVinPubkeys(CTransaction tx, std::vector &vinPubkeys) bool found = false; CPubKey pubkey; - struct CC_info *cpTokens, tokensC; + struct CCcontract_info *cpTokens, tokensC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); @@ -353,7 +353,7 @@ uint8_t ValidateTokenOpret(CTransaction tx, int32_t v, uint256 tokenid, std::vec // goDeeper is true: the func also validates amounts of the passed transaction: // it should be either sum(cc vins) == sum(cc vouts) or the transaction is the 'tokenbase' ('c') tx // checkPubkeys is true: validates if the vout is token vout1 or token vout1of2. Should always be true! -int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CC_info *cp, Eval* eval, const CTransaction& tx, int32_t v, uint256 reftokenid) +int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, const CTransaction& tx, int32_t v, uint256 reftokenid) { // this is just for log messages indentation fur debugging recursive calls: @@ -488,13 +488,13 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CC_info *cp, Eval* } // compares cc inputs vs cc outputs (to prevent feeding vouts from normal inputs) -bool TokensExactAmounts(bool goDeeper, struct CC_info *cp, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 tokenid) +bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cp, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 tokenid) { CTransaction vinTx; uint256 hashBlock; int64_t tokenoshis; - struct CC_info *cpTokens, tokensC; + struct CCcontract_info *cpTokens, tokensC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); int32_t numvins = tx.vin.size(); @@ -559,7 +559,7 @@ bool TokensExactAmounts(bool goDeeper, struct CC_info *cp, int64_t &inputs, int6 } // add inputs from token cc addr -int64_t AddTokenCCInputs(struct CC_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs) +int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs) { char tokenaddr[64], destaddr[64]; int64_t threshold, nValue, price, totalinputs = 0; @@ -617,7 +617,7 @@ int64_t AddTokenCCInputs(struct CC_info *cp, CMutableTransaction &mtx, CPubKey p std::string CreateToken(int64_t txfee, int64_t assetsupply, std::string name, std::string description) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; struct CC_info *cp, C; + CPubKey mypk; struct CCcontract_info *cp, C; if (assetsupply < 0) { fprintf(stderr, "negative assetsupply %lld\n", (long long)assetsupply); @@ -647,7 +647,7 @@ std::string CreateToken(int64_t txfee, int64_t assetsupply, std::string name, st std::string TokenTransfer(int64_t txfee, uint256 assetid, std::vector destpubkey, int64_t total) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; uint64_t mask; int64_t CCchange = 0, inputs = 0; struct CC_info *cp, C; + CPubKey mypk; uint64_t mask; int64_t CCchange = 0, inputs = 0; struct CCcontract_info *cp, C; std::vector emptyExtraOpret; if (total < 0) @@ -714,7 +714,7 @@ int64_t GetTokenBalance(CPubKey pk, uint256 tokenid) return 0; } - struct CC_info *cp, C; + struct CCcontract_info *cp, C; cp = CCinit(&C, EVAL_TOKENS); return(AddTokenCCInputs(cp, mtx, pk, tokenid, 0, 0)); } @@ -748,7 +748,7 @@ UniValue TokenList() { UniValue result(UniValue::VARR); std::vector > addressIndex; - struct CC_info *cp, C; uint256 txid, hashBlock; + struct CCcontract_info *cp, C; uint256 txid, hashBlock; CTransaction vintx; std::vector origpubkey; std::string name, description; char str[65]; diff --git a/src/cc/CCtokens.h b/src/cc/CCtokens.h index 2eaffe31f..e7bb62101 100644 --- a/src/cc/CCtokens.h +++ b/src/cc/CCtokens.h @@ -26,9 +26,9 @@ #include "CCinclude.h" // CCcustom -bool TokensValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); -bool TokensExactAmounts(bool goDeeper, struct CC_info *cpTokens, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 tokenid); -//int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CC_info *cp, Eval* eval, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 reftokenid, std::vector vinPubkeys); +bool TokensValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 tokenid); +//int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 reftokenid, std::vector vinPubkeys); std::string CreateToken(int64_t txfee, int64_t assetsupply, std::string name, std::string description); std::string TokenTransfer(int64_t txfee, uint256 assetid, std::vector destpubkey, int64_t total); @@ -36,7 +36,7 @@ int64_t GetTokenBalance(CPubKey pk, uint256 tokenid); UniValue TokenInfo(uint256 tokenid); UniValue TokenList(); -//this is in CCinclude.h int64_t AddTokenCCInputs(struct CC_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs); +//this is in CCinclude.h int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs); //this is in CCinclude.h uint8_t DecodeTokenCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 307ac214f..ae7483f4d 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -40,7 +40,7 @@ bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScrip return(false); } -std::string FinalizeCCTx(uint64_t CCmask,struct CC_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys) +std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys) { auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); CTransaction vintx; std::string hex; CPubKey globalpk; uint256 hashBlock; uint64_t mask=0,nmask=0,vinimask=0; @@ -50,7 +50,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CC_info *cp,CMutableTransaction uint8_t *privkey, myprivkey[32], unspendablepriv[32], tokensunspendablepriv[32], *msg32 = 0; CC *mycond=0, *othercond=0, *othercond2=0,*othercond4=0, *othercond3=0, *othercond1of2=NULL, *othercond1of2tokens = NULL, *cond, *mytokenscond = NULL, *mysingletokenscond = NULL, *othertokenscond = NULL; CPubKey unspendablepk /*, tokensunspendablepk*/; - struct CC_info *cpTokens, tokensC; + struct CCcontract_info *cpTokens, tokensC; globalpk = GetUnspendable(cp,0); n = mtx.vout.size(); for (i=0; i pubkey) return(pk); } -void CCaddr2set(struct CC_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr) +void CCaddr2set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr) { cp->evalcode2 = evalcode; cp->unspendablepk2 = pk; @@ -235,7 +235,7 @@ void CCaddr2set(struct CC_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,cha strcpy(cp->unspendableaddr2,coinaddr); } -void CCaddr3set(struct CC_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr) +void CCaddr3set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr) { cp->evalcode3 = evalcode; cp->unspendablepk3 = pk; @@ -244,7 +244,7 @@ void CCaddr3set(struct CC_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,cha } // set pubkeys, myprivkey and 1of2 cc addr for spending from 1of2 cryptocondition vout: -void CCaddr1of2set(struct CC_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr) +void CCaddr1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr) { cp->coins1of2pk[0] = pk1; cp->coins1of2pk[1] = pk2; @@ -252,7 +252,7 @@ void CCaddr1of2set(struct CC_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr) } // set pubkeys, myprivkey and 1of2 cc addr for spending from 1of2 tokens cryptocondition vout: -void CCaddrTokens1of2set(struct CC_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr) +void CCaddrTokens1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr) { cp->tokens1of2pk[0] = pk1; cp->tokens1of2pk[1] = pk2; @@ -343,7 +343,7 @@ bool _GetCCaddress(char *destaddr,uint8_t evalcode,CPubKey pk) return(destaddr[0] != 0); } -bool GetCCaddress(struct CC_info *cp,char *destaddr,CPubKey pk) +bool GetCCaddress(struct CCcontract_info *cp,char *destaddr,CPubKey pk) { destaddr[0] = 0; if ( pk.size() == 0 ) @@ -363,7 +363,7 @@ bool _GetTokensCCaddress(char *destaddr, uint8_t evalcode, CPubKey pk) return(destaddr[0] != 0); } -bool GetTokensCCaddress(struct CC_info *cp, char *destaddr, CPubKey pk) +bool GetTokensCCaddress(struct CCcontract_info *cp, char *destaddr, CPubKey pk) { destaddr[0] = 0; if (pk.size() == 0) @@ -372,7 +372,7 @@ bool GetTokensCCaddress(struct CC_info *cp, char *destaddr, CPubKey pk) } -bool GetCCaddress1of2(struct CC_info *cp,char *destaddr,CPubKey pk,CPubKey pk2) +bool GetCCaddress1of2(struct CCcontract_info *cp,char *destaddr,CPubKey pk,CPubKey pk2) { CC *payoutCond; destaddr[0] = 0; @@ -384,7 +384,7 @@ bool GetCCaddress1of2(struct CC_info *cp,char *destaddr,CPubKey pk,CPubKey pk2) return(destaddr[0] != 0); } -bool GetTokensCCaddress1of2(struct CC_info *cp, char *destaddr, CPubKey pk, CPubKey pk2) +bool GetTokensCCaddress1of2(struct CCcontract_info *cp, char *destaddr, CPubKey pk, CPubKey pk2) { CC *payoutCond; destaddr[0] = 0; @@ -486,14 +486,14 @@ bool Myprivkey(uint8_t myprivkey[]) return(false); } -CPubKey GetUnspendable(struct CC_info *cp,uint8_t *unspendablepriv) +CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv) { if ( unspendablepriv != 0 ) memcpy(unspendablepriv,cp->CCpriv,32); return(pubkey2pk(ParseHex(cp->CChexstr))); } -void CCclearvars(struct CC_info *cp) +void CCclearvars(struct CCcontract_info *cp) { cp->evalcode2 = cp->evalcode3 = 0; cp->unspendableaddr2[0] = cp->unspendableaddr3[0] = 0; @@ -602,7 +602,7 @@ CPubKey check_signing_pubkey(CScript scriptSig) return CPubKey(); } -bool ProcessCC(struct CC_info *cp,Eval* eval, std::vector paramsNull,const CTransaction &ctx, unsigned int nIn) +bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector paramsNull,const CTransaction &ctx, unsigned int nIn) { CTransaction createTx; uint256 assetid,assetid2,hashBlock; uint8_t funcid; int32_t height,i,n,from_mempool = 0; int64_t amount; std::vector origpubkey; height = KOMODO_CONNECTING; @@ -636,13 +636,13 @@ bool ProcessCC(struct CC_info *cp,Eval* eval, std::vector paramsNull,co return(false); } -extern struct CC_info CCinfos[0x100]; +extern struct CCcontract_info CCinfos[0x100]; extern std::string MYCCLIBNAME; -bool CClib_validate(struct CC_info *cp,Eval *eval,const CTransaction &txTo,unsigned int nIn); +bool CClib_validate(struct CCcontract_info *cp,Eval *eval,const CTransaction &txTo,unsigned int nIn); bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,const CTransaction &txTo,unsigned int nIn) { - uint8_t evalcode; int32_t height,from_mempool; struct CC_info *cp; + uint8_t evalcode; int32_t height,from_mempool; struct CCcontract_info *cp; if ( ASSETCHAINS_CCLIB != MYCCLIBNAME ) { fprintf(stderr,"-ac_cclib=%s vs myname %s\n",ASSETCHAINS_CCLIB.c_str(),MYCCLIBNAME.c_str()); diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index 7747fb61c..3ccafa34f 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -126,7 +126,7 @@ // tx validation -bool AssetsValidate(struct CC_info *cpAssets,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransaction &tx, uint32_t nIn) { static uint256 zero; CTxDestination address; CTransaction vinTx,createTx; uint256 hashBlock,assetid,assetid2; @@ -157,7 +157,7 @@ bool AssetsValidate(struct CC_info *cpAssets,Eval* eval,const CTransaction &tx, GetTokensCCaddress(cpAssets, tokensUnspendableAddr, GetUnspendable(cpAssets, NULL)); // we need this for validating single-eval tokens' vins/vous: - struct CC_info *cpTokens, tokensC; + struct CCcontract_info *cpTokens, tokensC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); // find single-eval token user cc addr: diff --git a/src/cc/auction.cpp b/src/cc/auction.cpp index b3fe4aa86..0858facfa 100644 --- a/src/cc/auction.cpp +++ b/src/cc/auction.cpp @@ -21,7 +21,7 @@ // start of consensus code -int64_t IsAuctionvout(struct CC_info *cp,const CTransaction& tx,int32_t v) +int64_t IsAuctionvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -32,7 +32,7 @@ int64_t IsAuctionvout(struct CC_info *cp,const CTransaction& tx,int32_t v) return(0); } -bool AuctionExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool AuctionExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -70,7 +70,7 @@ bool AuctionExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,in else return(true); } -bool AuctionValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool AuctionValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; return eval->Invalid("no validation yet"); @@ -118,7 +118,7 @@ bool AuctionValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint3 // helper functions for rpc calls in rpcwallet.cpp -int64_t AddAuctionInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddAuctionInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t n = 0; @@ -151,7 +151,7 @@ int64_t AddAuctionInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk, std::string AuctionBid(uint64_t txfee,uint256 itemhash,int64_t amount) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Auctionpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CC_info *cp,C; + CPubKey mypk,Auctionpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_AUCTION); if ( txfee == 0 ) txfee = 10000; @@ -172,7 +172,7 @@ std::string AuctionBid(uint64_t txfee,uint256 itemhash,int64_t amount) std::string AuctionDeliver(uint64_t txfee,uint256 itemhash,uint256 bidtxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Auctionpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CC_info *cp,C; + CPubKey mypk,Auctionpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_AUCTION); if ( txfee == 0 ) txfee = 10000; @@ -193,7 +193,7 @@ std::string AuctionDeliver(uint64_t txfee,uint256 itemhash,uint256 bidtxid) std::string AuctionPost(uint64_t txfee,uint256 itemhash,int64_t minbid,char *title,char *description) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Auctionpk; int64_t funds = 0; CScript opret; struct CC_info *cp,C; + CPubKey mypk,Auctionpk; int64_t funds = 0; CScript opret; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_AUCTION); if ( txfee == 0 ) txfee = 10000; diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 837a36024..0f201acc4 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -42,9 +42,9 @@ std::string MYCCLIBNAME = (char *)"stub"; char *CClib_name() { return(MYCCLIBNAME); } -std::string CClib_rawtxgen(struct CC_info *cp,uint8_t funcid,cJSON *params); +std::string CClib_rawtxgen(struct CCcontract_info *cp,uint8_t funcid,cJSON *params); -UniValue CClib_info(struct CC_info *cp) +UniValue CClib_info(struct CCcontract_info *cp) { UniValue result(UniValue::VOBJ),a(UniValue::VARR); int32_t i; char str[2]; result.push_back(Pair("result","success")); @@ -70,7 +70,7 @@ UniValue CClib_info(struct CC_info *cp) return(result); } -UniValue CClib(struct CC_info *cp,char *method,cJSON *params) +UniValue CClib(struct CCcontract_info *cp,char *method,cJSON *params) { UniValue result(UniValue::VOBJ); int32_t i; std::string rawtx; for (i=0; i > unspentOutputs; @@ -465,7 +465,7 @@ std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64 { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); uint8_t hash[32],hashdest[32]; uint64_t amount,tokens=0,funds; int32_t i; uint256 hashchain,entropy,hentropy; - CPubKey mypk; struct CC_info *cp,*cpTokens,C,CTokens; + CPubKey mypk; struct CCcontract_info *cp,*cpTokens,C,CTokens; if ( numpayments <= 0 || payment <= 0 || numpayments > CHANNELS_MAXPAYMENTS ) { @@ -509,7 +509,7 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CPubKey mypk,srcpub,destpub; uint256 txid,hashchain,gensecret,hashblock,entropy,hentropy,prevtxid,param3,tokenid; - struct CC_info *cp,C; int32_t i,funcid,prevdepth,numvouts,numpayments,totalnumpayments; + struct CCcontract_info *cp,C; int32_t i,funcid,prevdepth,numvouts,numpayments,totalnumpayments; int64_t payment,change,funds,param2; uint8_t hash[32],hashdest[32]; CTransaction channelOpenTx,prevTx; @@ -616,7 +616,7 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 std::string ChannelClose(uint64_t txfee,uint256 opentxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,srcpub,destpub; struct CC_info *cp,C; + CPubKey mypk,srcpub,destpub; struct CCcontract_info *cp,C; CTransaction channelOpenTx; uint256 hashblock,tmp_txid,prevtxid,hashchain,tokenid; int32_t numvouts,numpayments; @@ -665,7 +665,7 @@ std::string ChannelClose(uint64_t txfee,uint256 opentxid) std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; struct CC_info *cp,C; int64_t funds,payment,param2; + CPubKey mypk; struct CCcontract_info *cp,C; int64_t funds,payment,param2; int32_t i,numpayments,numvouts,param1; uint256 hashchain,hashblock,txid,prevtxid,param3,tokenid; CTransaction channelOpenTx,channelCloseTx,prevTx; @@ -735,7 +735,7 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) } UniValue ChannelsList() { - UniValue result(UniValue::VOBJ); std::vector > txids; struct CC_info *cp,C; uint256 txid,hashBlock,tmp_txid,param3,tokenid; + UniValue result(UniValue::VOBJ); std::vector > txids; struct CCcontract_info *cp,C; uint256 txid,hashBlock,tmp_txid,param3,tokenid; CTransaction tx; char myCCaddr[65],addr[65],str[256]; CPubKey mypk,srcpub,destpub; int32_t vout,numvouts,param1; int64_t nValue,param2; @@ -766,7 +766,7 @@ UniValue ChannelsList() UniValue ChannelsInfo(uint256 channeltxid) { UniValue result(UniValue::VOBJ),array(UniValue::VARR); CTransaction tx,opentx; uint256 txid,tmp_txid,hashBlock,param3,opentxid,hashchain,prevtxid,tokenid; - struct CC_info *cp,C; char CCaddr[65],addr[65],str[512]; int32_t vout,numvouts,param1,numpayments; + struct CCcontract_info *cp,C; char CCaddr[65],addr[65],str[512]; int32_t vout,numvouts,param1,numpayments; int64_t param2,payment; CPubKey srcpub,destpub,mypk; std::vector > addressIndex; std::vector txids; diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 7a10913e7..05dad9bf6 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -322,7 +322,7 @@ void dicefinish_delete(struct dicefinish_info *ptr) void *dicefinish(void *_ptr) { - std::vector mypk; struct CC_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,newblock,entropyvout,numblocks,lastheight=0,vin0_needed,i,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; uint32_t now; struct dicefinish_utxo *utxos; uint256 hashBlock,entropyused; CPubKey dicepk; CTransaction betTx,finishTx,tx; + std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,newblock,entropyvout,numblocks,lastheight=0,vin0_needed,i,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; uint32_t now; struct dicefinish_utxo *utxos; uint256 hashBlock,entropyused; CPubKey dicepk; CTransaction betTx,finishTx,tx; mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); cp = CCinit(&C,EVAL_DICE); @@ -735,7 +735,7 @@ uint256 DiceGetEntropy(CTransaction tx,uint8_t reffuncid) else return(zeroid); } -uint64_t IsDicevout(struct CC_info *cp,const CTransaction& tx,int32_t v,uint64_t refsbits,uint256 reffundingtxid) +uint64_t IsDicevout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v,uint64_t refsbits,uint256 reffundingtxid) { char destaddr[64]; uint8_t funcid; int32_t numvouts; uint64_t sbits; uint256 fundingtxid,hash,proof; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -749,7 +749,7 @@ uint64_t IsDicevout(struct CC_info *cp,const CTransaction& tx,int32_t v,uint64_t return(0); } -int64_t DiceAmounts(uint64_t &inputs,uint64_t &outputs,struct CC_info *cp,Eval *eval,const CTransaction &tx,uint64_t refsbits,uint256 reffundingtxid) +int64_t DiceAmounts(uint64_t &inputs,uint64_t &outputs,struct CCcontract_info *cp,Eval *eval,const CTransaction &tx,uint64_t refsbits,uint256 reffundingtxid) { CTransaction vinTx; uint256 hashBlock; int32_t i,numvins,numvouts; uint64_t assetoshis; numvins = tx.vin.size(); @@ -834,7 +834,7 @@ bool DiceVerifyTimeout(CTransaction &betTx,int32_t timeoutblocks) return(numblocks >= timeoutblocks); } -bool DiceValidate(struct CC_info *cp,Eval *eval,const CTransaction &tx, uint32_t nIn) +bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx, uint32_t nIn) { uint256 txid,fundingtxid,vinfundingtxid,vinhentropy,vinproof,hashBlock,hash,proof,entropy; int64_t minbet,maxbet,maxodds,timeoutblocks,odds,winnings; uint64_t vinsbits,refsbits=0,sbits,amount,inputs,outputs,txfee=10000; int32_t numvins,entropyvout,numvouts,preventCCvins,preventCCvouts,i,iswin; uint8_t funcid; CScript fundingPubKey; CTransaction fundingTx,vinTx,vinofvinTx; char CCaddr[64]; numvins = tx.vin.size(); @@ -1046,7 +1046,7 @@ bool DiceValidate(struct CC_info *cp,Eval *eval,const CTransaction &tx, uint32_t return(true); } -uint64_t AddDiceInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) +uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) { char coinaddr[64],str[65]; uint64_t threshold,sbits,nValue,totalinputs = 0; uint256 txid,hash,proof,hashBlock,fundingtxid; CTransaction tx; int32_t j,vout,n = 0; uint8_t funcid; std::vector > unspentOutputs; @@ -1095,7 +1095,7 @@ uint64_t AddDiceInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,ui return(totalinputs); } -int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CC_info *cp,CPubKey dicepk,uint256 reffundingtxid, int32_t &entropytxs,bool random) +int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CCcontract_info *cp,CPubKey dicepk,uint256 reffundingtxid, int32_t &entropytxs,bool random) { char coinaddr[64],str[65]; uint64_t sbits; int64_t nValue,sum,totalinputs = 0; uint256 hash,txid,proof,hashBlock,fundingtxid; CScript fundingPubKey; CTransaction tx,vinTx; int32_t vout,first=0,n=0,i=0,pendingbets=0; uint8_t funcid; std::vector > unspentOutputs; @@ -1215,7 +1215,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit } } -bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CC_info *cp,uint64_t refsbits,CPubKey dicepk,int64_t &minbet,int64_t &maxbet,int64_t &maxodds,int64_t &timeoutblocks) +bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CCcontract_info *cp,uint64_t refsbits,CPubKey dicepk,int64_t &minbet,int64_t &maxbet,int64_t &maxodds,int64_t &timeoutblocks) { char CCaddr[64]; uint64_t sbits=0; uint256 txid,hashBlock; CTransaction tx; std::vector > txids; @@ -1256,9 +1256,9 @@ bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CC_info * return(false); } -struct CC_info *Diceinit(CScript &fundingPubKey,uint256 reffundingtxid,struct CC_info *C,char *planstr,uint64_t &txfee,CPubKey &mypk,CPubKey &dicepk,uint64_t &sbits,int64_t &minbet,int64_t &maxbet,int64_t &maxodds,int64_t &timeoutblocks) +struct CCcontract_info *Diceinit(CScript &fundingPubKey,uint256 reffundingtxid,struct CCcontract_info *C,char *planstr,uint64_t &txfee,CPubKey &mypk,CPubKey &dicepk,uint64_t &sbits,int64_t &minbet,int64_t &maxbet,int64_t &maxodds,int64_t &timeoutblocks) { - struct CC_info *cp; int32_t cmpflag; + struct CCcontract_info *cp; int32_t cmpflag; cp = CCinit(C,EVAL_DICE); if ( txfee == 0 ) txfee = 10000; @@ -1278,7 +1278,7 @@ struct CC_info *Diceinit(CScript &fundingPubKey,uint256 reffundingtxid,struct CC UniValue DiceInfo(uint256 diceid) { - UniValue result(UniValue::VOBJ); CPubKey dicepk; uint256 hashBlock,entropytxid; CTransaction vintx; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits,funding,entropyval; char str[67],numstr[65]; struct CC_info *cp,C; + UniValue result(UniValue::VOBJ); CPubKey dicepk; uint256 hashBlock,entropytxid; CTransaction vintx; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits,funding,entropyval; char str[67],numstr[65]; struct CCcontract_info *cp,C; if ( myGetTransaction(diceid,vintx,hashBlock) == 0 ) { fprintf(stderr,"cant find fundingtxid\n"); @@ -1314,7 +1314,7 @@ UniValue DiceInfo(uint256 diceid) UniValue DiceList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CC_info *cp,C; uint256 txid,hashBlock; CTransaction vintx; uint64_t sbits; int64_t minbet,maxbet,maxodds,timeoutblocks; char str[65]; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock; CTransaction vintx; uint64_t sbits; int64_t minbet,maxbet,maxodds,timeoutblocks; char str[65]; cp = CCinit(&C,EVAL_DICE); SetCCtxids(addressIndex,cp->normaladdr); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) @@ -1334,7 +1334,7 @@ UniValue DiceList() std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - uint256 zero; CScript fundingPubKey; CPubKey mypk,dicepk; int64_t a,b,c,d; uint64_t sbits; struct CC_info *cp,C; + uint256 zero; CScript fundingPubKey; CPubKey mypk,dicepk; int64_t a,b,c,d; uint64_t sbits; struct CCcontract_info *cp,C; if ( funds < 0 || minbet < 0 || maxbet < 0 || maxodds < 1 || maxodds > 9999 || timeoutblocks < 0 || timeoutblocks > 1440 ) { CCerror = "invalid parameter error"; @@ -1369,7 +1369,7 @@ std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CScript fundingPubKey,scriptPubKey; uint256 entropy,hentropy; CPubKey mypk,dicepk; uint64_t sbits; struct CC_info *cp,C; int64_t minbet,maxbet,maxodds,timeoutblocks; + CScript fundingPubKey,scriptPubKey; uint256 entropy,hentropy; CPubKey mypk,dicepk; uint64_t sbits; struct CCcontract_info *cp,C; int64_t minbet,maxbet,maxodds,timeoutblocks; if ( amount < 0 ) { CCerror = "amount must be positive"; @@ -1413,7 +1413,7 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6 std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CScript fundingPubKey; CPubKey mypk,dicepk; uint64_t sbits,entropyval,entropyval2; int64_t funding,minbet,maxbet,maxodds,timeoutblocks; uint256 entropytxid,entropytxid2,entropy,hentropy; struct CC_info *cp,C; + CScript fundingPubKey; CPubKey mypk,dicepk; uint64_t sbits,entropyval,entropyval2; int64_t funding,minbet,maxbet,maxodds,timeoutblocks; uint256 entropytxid,entropytxid2,entropy,hentropy; struct CCcontract_info *cp,C; if ( bet < 0 ) { CCerror = "bet must be positive"; @@ -1472,7 +1472,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t &entropyvout,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout,uint256 vin0txid,int32_t vin0vout) { CMutableTransaction savemtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CScript scriptPubKey,fundingPubKey; CTransaction oldbetTx,betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy,oldbettxid; CPubKey mypk,dicepk,fundingpk; struct CC_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; int32_t oldentropyvout,retval=0,iswin=0; uint64_t entropyval,sbits; + CScript scriptPubKey,fundingPubKey; CTransaction oldbetTx,betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy,oldbettxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; int32_t oldentropyvout,retval=0,iswin=0; uint64_t entropyval,sbits; entropyused = zeroid; *resultp = 0; funcid = 0; @@ -1653,7 +1653,7 @@ static uint256 dealer0_fundingtxid; void *dealer0_loop(void *_arg) { char *planstr = (char *)_arg; - 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 CC_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"); @@ -1749,7 +1749,7 @@ void *dealer0_loop(void *_arg) double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid) { static int32_t didinit; static char _planstr[64]; - CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CC_info *cp,C; int32_t i,entropyvout,flag,win,num,loss,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks,sum=0; uint64_t sbits,refsbits; char coinaddr[64]; std::string res; uint8_t funcid; + CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,entropyvout,flag,win,num,loss,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks,sum=0; uint64_t sbits,refsbits; char coinaddr[64]; std::string res; uint8_t funcid; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,refsbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { CCerror = "Diceinit error in status, is your transaction confirmed?"; diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index 5239b0d5b..ca2703bff 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -31,7 +31,7 @@ bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,co char *CClib_name(); Eval* EVAL_TEST = 0; -struct CC_info CCinfos[0x100]; +struct CCcontract_info CCinfos[0x100]; extern pthread_mutex_t KOMODO_CC_mutex; bool RunCCEval(const CC *cond, const CTransaction &tx, unsigned int nIn) @@ -62,7 +62,7 @@ bool RunCCEval(const CC *cond, const CTransaction &tx, unsigned int nIn) */ bool Eval::Dispatch(const CC *cond, const CTransaction &txTo, unsigned int nIn) { - struct CC_info *cp; + struct CCcontract_info *cp; if (cond->codeLength == 0) return Invalid("empty-eval"); diff --git a/src/cc/eval.h b/src/cc/eval.h index 61fdb892d..a42bbdb2f 100644 --- a/src/cc/eval.h +++ b/src/cc/eval.h @@ -286,8 +286,8 @@ typedef std::pair TxProof; uint256 GetMerkleRoot(const std::vector& vLeaves); -struct CC_info *CCinit(struct CC_info *cp,uint8_t evalcode); -bool ProcessCC(struct CC_info *cp,Eval* eval, std::vector paramsNull, const CTransaction &tx, unsigned int nIn); +struct CCcontract_info *CCinit(struct CCcontract_info *cp,uint8_t evalcode); +bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector paramsNull, const CTransaction &tx, unsigned int nIn); #endif /* CC_EVAL_H */ diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index be3ff8a2c..6e59b6c1a 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -28,7 +28,7 @@ // start of consensus code -int64_t IsFaucetvout(struct CC_info *cp,const CTransaction& tx,int32_t v) +int64_t IsFaucetvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -39,7 +39,7 @@ int64_t IsFaucetvout(struct CC_info *cp,const CTransaction& tx,int32_t v) return(0); } -bool FaucetExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool FaucetExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -77,7 +77,7 @@ bool FaucetExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int else return(true); } -bool FaucetValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; std::vector > txids; @@ -140,7 +140,7 @@ bool FaucetValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32 // helper functions for rpc calls in rpcwallet.cpp -int64_t AddFaucetInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { char coinaddr[64]; int64_t threshold,nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; @@ -175,7 +175,7 @@ int64_t AddFaucetInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,i std::string FaucetGet(uint64_t txfee) { CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,faucetpk; int64_t inputs,CCchange=0,nValue=FAUCETSIZE; struct CC_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; + CPubKey mypk,faucetpk; int64_t inputs,CCchange=0,nValue=FAUCETSIZE; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; cp = CCinit(&C,EVAL_FAUCET); if ( txfee == 0 ) txfee = 10000; @@ -216,7 +216,7 @@ std::string FaucetGet(uint64_t txfee) std::string FaucetFund(uint64_t txfee,int64_t funds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,faucetpk; CScript opret; struct CC_info *cp,C; + CPubKey mypk,faucetpk; CScript opret; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_FAUCET); if ( txfee == 0 ) txfee = 10000; @@ -234,7 +234,7 @@ UniValue FaucetInfo() { UniValue result(UniValue::VOBJ); char numstr[64]; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey faucetpk; struct CC_info *cp,C; int64_t funding; + CPubKey faucetpk; struct CCcontract_info *cp,C; int64_t funding; result.push_back(Pair("result","success")); result.push_back(Pair("name","Faucet")); cp = CCinit(&C,EVAL_FAUCET); diff --git a/src/cc/fsm.cpp b/src/cc/fsm.cpp index 573299665..0bcc61a1b 100644 --- a/src/cc/fsm.cpp +++ b/src/cc/fsm.cpp @@ -23,7 +23,7 @@ // start of consensus code -int64_t IsFSMvout(struct CC_info *cp,const CTransaction& tx,int32_t v) +int64_t IsFSMvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -34,7 +34,7 @@ int64_t IsFSMvout(struct CC_info *cp,const CTransaction& tx,int32_t v) return(0); } -bool FSMExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool FSMExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -72,7 +72,7 @@ bool FSMExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_ else return(true); } -bool FSMValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool FSMValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; return eval->Invalid("no validation yet"); @@ -120,7 +120,7 @@ bool FSMValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t // helper functions for rpc calls in rpcwallet.cpp -int64_t AddFSMInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddFSMInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t n = 0; @@ -158,7 +158,7 @@ std::string FSMList() std::string FSMCreate(uint64_t txfee,std::string name,std::string states) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,fsmpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CC_info *cp,C; + CPubKey mypk,fsmpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_FSM); if ( txfee == 0 ) txfee = 10000; @@ -179,7 +179,7 @@ std::string FSMCreate(uint64_t txfee,std::string name,std::string states) std::string FSMInfo(uint256 fsmtxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,fsmpk; int64_t funds = 0; CScript opret; struct CC_info *cp,C; + CPubKey mypk,fsmpk; int64_t funds = 0; CScript opret; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_FSM); mypk = pubkey2pk(Mypubkey()); fsmpk = GetUnspendable(cp,0); diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index f00b1abfd..c64d56b80 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -320,7 +320,7 @@ uint8_t DecodeGatewaysOpRet(const CScript &scriptPubKey) return(0); } -int64_t IsGatewaysvout(struct CC_info *cp,const CTransaction& tx,int32_t v) +int64_t IsGatewaysvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -331,7 +331,7 @@ int64_t IsGatewaysvout(struct CC_info *cp,const CTransaction& tx,int32_t v) return(0); } -bool GatewaysExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool GatewaysExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -429,7 +429,7 @@ uint256 GatewaysReverseScan(uint256 &txid,int32_t height,uint256 reforacletxid,u return(zeroid); } -int32_t GatewaysCointxidExists(struct CC_info *cp,uint256 cointxid) // dont forget to check mempool! +int32_t GatewaysCointxidExists(struct CCcontract_info *cp,uint256 cointxid) // dont forget to check mempool! { char txidaddr[64]; std::string coin; int32_t numvouts; uint256 hashBlock; std::vector > addressIndex; @@ -515,7 +515,7 @@ int64_t GatewaysDepositval(CTransaction tx,CPubKey mypk) return(0); } -bool GatewaysValidate(struct CC_info *cp,Eval *eval,const CTransaction &tx, uint32_t nIn) +bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks,height,claimvout; bool retval; uint8_t funcid,hash[32],M,N,taddr,prefix,prefix2; char str[65],destaddr[64],depositaddr[65],validationError[512]; @@ -683,7 +683,7 @@ bool GatewaysValidate(struct CC_info *cp,Eval *eval,const CTransaction &tx, uint // helper functions for rpc calls in rpcwallet.cpp -int64_t AddGatewaysInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 reftokenid,int64_t total,int32_t maxinputs) +int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 reftokenid,int64_t total,int32_t maxinputs) { char coinaddr[64],destaddr[64]; int64_t threshold,nValue,price,totalinputs = 0; uint256 tokenid,txid,hashBlock; std::vector origpubkey; std::vector vopret; CTransaction vintx; int32_t j,vout,n = 0; uint8_t evalcode,funcid; std::vector > unspentOutputs; @@ -730,7 +730,7 @@ int64_t AddGatewaysInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk return(totalinputs); } -int32_t GatewaysBindExists(struct CC_info *cp,CPubKey gatewayspk,uint256 reftokenid) // dont forget to check mempool! +int32_t GatewaysBindExists(struct CCcontract_info *cp,CPubKey gatewayspk,uint256 reftokenid) // dont forget to check mempool! { char markeraddr[64],depositaddr[64]; std::string coin; int32_t numvouts; int64_t totalsupply; uint256 tokenid,oracletxid,hashBlock; uint8_t M,N,taddr,prefix,prefix2; std::vector pubkeys; CTransaction tx; std::vector > addressIndex; @@ -757,7 +757,7 @@ int32_t GatewaysBindExists(struct CC_info *cp,CPubKey gatewayspk,uint256 reftoke std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t totalsupply,uint256 oracletxid,uint8_t M,uint8_t N,std::vector pubkeys) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction oracletx; uint8_t taddr,prefix,prefix2; CPubKey mypk,gatewayspk; CScript opret; uint256 hashBlock; struct CC_info *cp,C; std::string name,description,format; int32_t i,numvouts; int64_t fullsupply; char destaddr[64],coinaddr[64],str[65],*fstr; + CTransaction oracletx; uint8_t taddr,prefix,prefix2; CPubKey mypk,gatewayspk; CScript opret; uint256 hashBlock; struct CCcontract_info *cp,C; std::string name,description,format; int32_t i,numvouts; int64_t fullsupply; char destaddr[64],coinaddr[64],str[65],*fstr; cp = CCinit(&C,EVAL_GATEWAYS); if ( strcmp((char *)"KMD",coin.c_str()) == 0 ) { @@ -844,7 +844,7 @@ std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std:: { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CTransaction bindtx; CPubKey mypk,gatewayspk; uint256 oracletxid,merkleroot,mhash,hashBlock,tokenid,txid; - int64_t totalsupply; int32_t i,m,n,numvouts; uint8_t M,N,taddr,prefix,prefix2; std::string coin; struct CC_info *cp,C; + int64_t totalsupply; int32_t i,m,n,numvouts; uint8_t M,N,taddr,prefix,prefix2; std::string coin; struct CCcontract_info *cp,C; std::vector pubkeys,publishers; std::vectortxids; char str[67],depositaddr[64],txidaddr[64]; cp = CCinit(&C,EVAL_GATEWAYS); @@ -910,7 +910,7 @@ std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std:: std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,uint256 deposittxid,CPubKey destpub,int64_t amount) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction tx; CPubKey mypk,gatewayspk,tmpdestpub; struct CC_info *cp,C; uint8_t M,N,taddr,prefix,prefix2; + CTransaction tx; CPubKey mypk,gatewayspk,tmpdestpub; struct CCcontract_info *cp,C; uint8_t M,N,taddr,prefix,prefix2; std::string coin, deposithex; std::vector msigpubkeys,publishers; int64_t totalsupply,depositamount,tmpamount,inputs,CCchange=0; int32_t numvouts,claimvout,height; std::vector proof; uint256 hashBlock,tokenid,oracletxid,tmptxid,cointxid; char str[65],depositaddr[64],coinaddr[64],destaddr[64]; std::vector txids; @@ -985,8 +985,8 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin CPubKey mypk, gatewayspk; uint256 tokenid,hashBlock,oracletxid; int32_t numvouts; int64_t totalsupply,inputs,CCchange=0; uint8_t M,N,taddr,prefix,prefix2; std::string coin; std::vector msigpubkeys; char depositaddr[64],str[65],coinaddr[64]; - struct CC_info *cpGateways, gatewaysC; - struct CC_info *cpTokens, tokensC; + struct CCcontract_info *cpGateways, gatewaysC; + struct CCcontract_info *cpTokens, tokensC; cpGateways = CCinit(&gatewaysC, EVAL_GATEWAYS); cpTokens = CCinit(&tokensC, EVAL_TOKENS); @@ -1049,7 +1049,7 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin std::string GatewaysPartialSign(uint64_t txfee,uint256 txid,std::string refcoin, std::string hex) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,txidaddrpk,signerpk; struct CC_info *cp,C; CTransaction tx; + CPubKey mypk,txidaddrpk,signerpk; struct CCcontract_info *cp,C; CTransaction tx; std::vector > unspentOutputs; char txidaddr[65]; int32_t maxK,K=0; uint256 tmptxid,parttxid,hashBlock; cp = CCinit(&C,EVAL_GATEWAYS); @@ -1089,7 +1089,7 @@ std::string GatewaysPartialSign(uint64_t txfee,uint256 txid,std::string refcoin, std::string GatewaysCompleteSigning(uint64_t txfee,uint256 withdrawtxid,std::string refcoin,std::string hex) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,gatewayspk; struct CC_info *cp,C; char txidaddr[65]; + CPubKey mypk,gatewayspk; struct CCcontract_info *cp,C; char txidaddr[65]; cp = CCinit(&C,EVAL_GATEWAYS); mypk = pubkey2pk(Mypubkey()); gatewayspk = GetUnspendable(cp,0); @@ -1104,7 +1104,7 @@ std::string GatewaysCompleteSigning(uint64_t txfee,uint256 withdrawtxid,std::str std::string GatewaysMarkDone(uint64_t txfee,uint256 completetxid,std::string refcoin) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,gatewayspk; struct CC_info *cp,C; char txidaddr[65]; + CPubKey mypk,gatewayspk; struct CCcontract_info *cp,C; char txidaddr[65]; cp = CCinit(&C,EVAL_GATEWAYS); mypk = pubkey2pk(Mypubkey()); if ( txfee == 0 ) @@ -1118,7 +1118,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) UniValue result(UniValue::VOBJ),pending(UniValue::VARR); CTransaction tx; std::string tmprefcoin; CPubKey mypk,gatewayspk,withdrawpub; std::vector msigpubkeys; uint256 hashBlock,tokenid,txid,oracletxid; uint8_t M,N,taddr,prefix,prefix2; char depositaddr[64],coinaddr[64],destaddr[64],str[65],withaddr[64],numstr[32],txidaddr[64],cctxidaddr[64],signeraddr[64]; - int32_t i,n,numvouts,vout,queueflag; int64_t totalsupply,amount,nValue; struct CC_info *cp,C; + int32_t i,n,numvouts,vout,queueflag; int64_t totalsupply,amount,nValue; struct CCcontract_info *cp,C; std::vector > unspentOutputs; cp = CCinit(&C,EVAL_GATEWAYS); @@ -1186,7 +1186,7 @@ UniValue GatewaysProcessedWithdraws(uint256 bindtxid,std::string refcoin) UniValue result(UniValue::VOBJ),processed(UniValue::VARR); CTransaction tx; std::string tmprefcoin,hex; CPubKey mypk,gatewayspk,withdrawpub; std::vector msigpubkeys; uint256 withdrawtxid,hashBlock,txid,tokenid,oracletxid; uint8_t M,N,taddr,prefix,prefix2; char depositaddr[64],coinaddr[64],str[65],numstr[32],txidaddr[64],cctxidaddr[64],withaddr[64]; - int32_t i,n,numvouts,vout,queueflag; int64_t totalsupply,nValue,amount; struct CC_info *cp,C; + int32_t i,n,numvouts,vout,queueflag; int64_t totalsupply,nValue,amount; struct CCcontract_info *cp,C; std::vector > unspentOutputs; cp = CCinit(&C,EVAL_GATEWAYS); @@ -1278,7 +1278,7 @@ UniValue GatewaysMultisig(char *cctxidaddr) UniValue GatewaysList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CC_info *cp,C; uint256 txid,hashBlock,oracletxid,tokenid; CTransaction vintx; std::string coin; int64_t totalsupply; char str[65],depositaddr[64]; uint8_t M,N,taddr,prefix,prefix2; std::vector pubkeys; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock,oracletxid,tokenid; CTransaction vintx; std::string coin; int64_t totalsupply; char str[65],depositaddr[64]; uint8_t M,N,taddr,prefix,prefix2; std::vector pubkeys; cp = CCinit(&C,EVAL_GATEWAYS); SetCCtxids(addressIndex,cp->unspendableCCaddr); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) @@ -1298,7 +1298,7 @@ UniValue GatewaysList() UniValue GatewaysInfo(uint256 bindtxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::string coin; char str[67],numstr[65],depositaddr[64],gatewaysassets[64]; uint8_t M,N; std::vector pubkeys; uint8_t taddr,prefix,prefix2; uint256 tokenid,oracletxid,hashBlock; CTransaction tx; CPubKey Gatewayspk; struct CC_info *cp,C; int32_t i; int64_t totalsupply,remaining; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::string coin; char str[67],numstr[65],depositaddr[64],gatewaysassets[64]; uint8_t M,N; std::vector pubkeys; uint8_t taddr,prefix,prefix2; uint256 tokenid,oracletxid,hashBlock; CTransaction tx; CPubKey Gatewayspk; struct CCcontract_info *cp,C; int32_t i; int64_t totalsupply,remaining; result.push_back(Pair("result","success")); result.push_back(Pair("name","Gateways")); cp = CCinit(&C,EVAL_GATEWAYS); diff --git a/src/cc/lotto.cpp b/src/cc/lotto.cpp index c52c9a072..e9c263ff1 100644 --- a/src/cc/lotto.cpp +++ b/src/cc/lotto.cpp @@ -63,7 +63,7 @@ It is possible to have a jackpot but miss out on it due to not claiming it. To m // start of consensus code -int64_t IsLottovout(struct CC_info *cp,const CTransaction& tx,int32_t v) +int64_t IsLottovout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -74,7 +74,7 @@ int64_t IsLottovout(struct CC_info *cp,const CTransaction& tx,int32_t v) return(0); } -bool LottoExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool LottoExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -112,7 +112,7 @@ bool LottoExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int3 else return(true); } -bool LottoValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool LottoValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; return eval->Invalid("no validation yet"); @@ -160,7 +160,7 @@ bool LottoValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_ // helper functions for rpc calls in rpcwallet.cpp -int64_t AddLottoInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddLottoInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t n = 0; @@ -203,7 +203,7 @@ uint8_t DecodeLottoFundingOpRet(const CScript &scriptPubKey,uint64_t &sbits,int3 return(0); } -int64_t LottoPlanFunds(uint64_t refsbits,struct CC_info *cp,CPubKey pk,uint256 reffundingtxid) +int64_t LottoPlanFunds(uint64_t refsbits,struct CCcontract_info *cp,CPubKey pk,uint256 reffundingtxid) { char coinaddr[64]; uint64_t sbits; int64_t nValue,lockedfunds; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t vout; uint8_t funcid; std::vector > unspentOutputs; @@ -232,7 +232,7 @@ int64_t LottoPlanFunds(uint64_t refsbits,struct CC_info *cp,CPubKey pk,uint256 r UniValue LottoInfo(uint256 lottoid) { - UniValue result(UniValue::VOBJ); uint256 hashBlock,hentropy; CTransaction vintx; uint64_t lockedfunds,sbits; int32_t ticketsize,odds,firstheight,period; CPubKey lottopk; struct CC_info *cp,C; char str[67],numstr[65]; + UniValue result(UniValue::VOBJ); uint256 hashBlock,hentropy; CTransaction vintx; uint64_t lockedfunds,sbits; int32_t ticketsize,odds,firstheight,period; CPubKey lottopk; struct CCcontract_info *cp,C; char str[67],numstr[65]; if ( GetTransaction(lottoid,vintx,hashBlock,false) == 0 ) { fprintf(stderr,"cant find lottoid\n"); @@ -264,7 +264,7 @@ UniValue LottoInfo(uint256 lottoid) UniValue LottoList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CC_info *cp,C; uint256 txid,hashBlock,hentropy; CTransaction vintx; uint64_t sbits; int32_t ticketsize,odds,firstheight,period; char str[65]; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock,hentropy; CTransaction vintx; uint64_t sbits; int32_t ticketsize,odds,firstheight,period; char str[65]; cp = CCinit(&C,EVAL_LOTTO); SetCCtxids(addressIndex,cp->normaladdr); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) @@ -284,7 +284,7 @@ UniValue LottoList() std::string LottoCreate(uint64_t txfee,char *planstr,int64_t funding,int32_t ticketsize,int32_t odds,int32_t firstheight,int32_t period) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - uint256 entropy,hentropy; CPubKey mypk,lottopk; uint64_t sbits; int64_t inputs,CCchange=0,nValue=COIN; struct CC_info *cp,C; + uint256 entropy,hentropy; CPubKey mypk,lottopk; uint64_t sbits; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_LOTTO); if ( txfee == 0 ) txfee = 10000; @@ -303,7 +303,7 @@ std::string LottoCreate(uint64_t txfee,char *planstr,int64_t funding,int32_t tic std::string LottoTicket(uint64_t txfee,uint256 lottoid,int64_t numtickets) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,lottopk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CC_info *cp,C; + CPubKey mypk,lottopk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_LOTTO); if ( txfee == 0 ) txfee = 10000; @@ -324,7 +324,7 @@ std::string LottoTicket(uint64_t txfee,uint256 lottoid,int64_t numtickets) std::string LottoWinner(uint64_t txfee) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,lottopk; int64_t winnings = 0; CScript opret; struct CC_info *cp,C; + CPubKey mypk,lottopk; int64_t winnings = 0; CScript opret; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_LOTTO); if ( txfee == 0 ) txfee = 10000; diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 692c496b3..795b95186 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -47,7 +47,7 @@ // start of consensus code -int64_t IsMarmaravout(struct CC_info *cp,const CTransaction& tx,int32_t v) +int64_t IsMarmaravout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -188,7 +188,7 @@ int32_t MarmaraGetbatontxid(std::vector &creditloop,uint256 &batontxid, CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) { - CTxOut ccvout; struct CC_info *cp,C; CPubKey Marmarapk; + CTxOut ccvout; struct CCcontract_info *cp,C; CPubKey Marmarapk; cp = CCinit(&C,EVAL_MARMARA); Marmarapk = GetUnspendable(cp,0); if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) @@ -212,7 +212,7 @@ CScript MarmaraCoinbaseOpret(uint8_t funcid,int32_t height,CPubKey pk) int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { - struct CC_info *cp,C; CPubKey Marmarapk,pk; int32_t ht,unlockht; CTxOut ccvout; + struct CCcontract_info *cp,C; CPubKey Marmarapk,pk; int32_t ht,unlockht; CTxOut ccvout; cp = CCinit(&C,EVAL_MARMARA); Marmarapk = GetUnspendable(cp,0); if ( 0 ) @@ -255,7 +255,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) return(-1); } -bool MarmaraValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { std::vector vopret; CTransaction vinTx; uint256 hashBlock; int32_t numvins,numvouts,i,ht,unlockht,vht,vunlockht; uint8_t funcid,vfuncid,*script; CPubKey pk,vpk; if ( ASSETCHAINS_MARMARA == 0 ) @@ -326,7 +326,7 @@ bool MarmaraValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint3 // helper functions for rpc calls in rpcwallet.cpp -int64_t AddMarmaraCoinbases(struct CC_info *cp,CMutableTransaction &mtx,int32_t firstheight,CPubKey poolpk,int32_t maxinputs) +int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx,int32_t firstheight,CPubKey poolpk,int32_t maxinputs) { char coinaddr[64]; CPubKey Marmarapk,pk; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction vintx; int32_t unlockht,ht,vout,unlocks,n = 0; std::vector > unspentOutputs; @@ -408,7 +408,7 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) { CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); struct CC_info *cp,C; CPubKey Marmarapk,mypk,pk; int32_t unlockht,refunlockht,vout,ht,numvouts; int64_t nValue,val,inputsum=0,threshold,remains,change = 0; std::string rawtx,errorstr; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; uint8_t funcid; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk,pk; int32_t unlockht,refunlockht,vout,ht,numvouts; int64_t nValue,val,inputsum=0,threshold,remains,change = 0; std::string rawtx,errorstr; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; uint8_t funcid; if ( txfee == 0 ) txfee = 10000; if ( (height & 1) != 0 ) @@ -490,7 +490,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures,height; int64_t amount,refamount,remaining,inputsum,change; CPubKey Marmarapk,mypk,pk; std::string currency,refcurrency,rawtx; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2],txidaddr[64]; std::vector pubkeys; struct CC_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures,height; int64_t amount,refamount,remaining,inputsum,change; CPubKey Marmarapk,mypk,pk; std::string currency,refcurrency,rawtx; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2],txidaddr[64]; std::vector pubkeys; struct CCcontract_info *cp,C; if ( txfee == 0 ) txfee = 10000; cp = CCinit(&C,EVAL_MARMARA); @@ -607,7 +607,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) return(result); } -int32_t MarmaraGetCreditloops(int64_t &totalamount,std::vector &issuances,int64_t &totalclosed,std::vector &closed,struct CC_info *cp,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,CPubKey refpk,std::string refcurrency) +int32_t MarmaraGetCreditloops(int64_t &totalamount,std::vector &issuances,int64_t &totalclosed,std::vector &closed,struct CCcontract_info *cp,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,CPubKey refpk,std::string refcurrency) { char coinaddr[64]; CPubKey Marmarapk,senderpk; int64_t amount; uint256 createtxid,txid,hashBlock; CTransaction tx; int32_t numvouts,vout,matures,n=0; std::string currency; std::vector > unspentOutputs; @@ -643,7 +643,7 @@ int32_t MarmaraGetCreditloops(int64_t &totalamount,std::vector &issuanc UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 batontxid,bool automaticflag) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); CPubKey mypk; struct CC_info *cp,C; std::string rawtx; char *errorstr=0; uint256 createtxid; int64_t batonamount; int32_t needbaton = 0; + UniValue result(UniValue::VOBJ); CPubKey mypk; struct CCcontract_info *cp,C; std::string rawtx; char *errorstr=0; uint256 createtxid; int64_t batonamount; int32_t needbaton = 0; cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; @@ -700,7 +700,7 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t amount,std::string currency,int32_t matures,uint256 approvaltxid,uint256 batontxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); CPubKey mypk,Marmarapk; struct CC_info *cp,C; std::string rawtx; uint256 createtxid; char *errorstr=0; + UniValue result(UniValue::VOBJ); CPubKey mypk,Marmarapk; struct CCcontract_info *cp,C; std::string rawtx; uint256 createtxid; char *errorstr=0; cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; @@ -757,7 +757,7 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a UniValue MarmaraCreditloop(uint256 txid) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey pk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2]; struct CC_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey pk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2]; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_MARMARA); if ( (n= MarmaraGetbatontxid(creditloop,batontxid,txid)) > 0 ) { @@ -911,7 +911,7 @@ UniValue MarmaraCreditloop(uint256 txid) UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr) // [[pk0, shares0], [pk1, shares1], ...] { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ),a(UniValue::VARR); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk,poolpk; int64_t payout,poolfee=0,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CC_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk,poolpk; int64_t payout,poolfee=0,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; poolpk = pubkey2pk(Mypubkey()); if ( txfee == 0 ) txfee = 10000; @@ -1000,7 +1000,7 @@ UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_ { CMutableTransaction mtx; std::vector pubkeys; UniValue result(UniValue::VOBJ),a(UniValue::VARR),b(UniValue::VARR); int32_t i,n,matches; int64_t totalclosed=0,totalamount=0; std::vector issuances,closed; char coinaddr[64]; - CPubKey Marmarapk; struct CC_info *cp,C; + CPubKey Marmarapk; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_MARMARA); Marmarapk = GetUnspendable(cp,0); result.push_back(Pair("result","success")); diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index a64f65a18..66c0e1b9a 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -163,7 +163,7 @@ uint8_t DecodeOraclesData(const CScript &scriptPubKey,uint256 &oracletxid,uint25 return(0); } -CPubKey OracleBatonPk(char *batonaddr,struct CC_info *cp) +CPubKey OracleBatonPk(char *batonaddr,struct CCcontract_info *cp) { static secp256k1_context *ctx; size_t clen = CPubKey::PUBLIC_KEY_SIZE; @@ -256,7 +256,7 @@ static uint256 myIs_baton_spentinmempool(uint256 batontxid,int32_t batonvout) return(batontxid); } -uint256 OracleBatonUtxo(uint64_t txfee,struct CC_info *cp,uint256 reforacletxid,char *batonaddr,CPubKey publisher,std::vector &dataarg) +uint256 OracleBatonUtxo(uint64_t txfee,struct CCcontract_info *cp,uint256 reforacletxid,char *batonaddr,CPubKey publisher,std::vector &dataarg) { uint256 txid,oracletxid,hashBlock,btxid,batontxid = zeroid; int64_t dfee; int32_t dheight=0,vout,height,numvouts; CTransaction tx; CPubKey pk; uint8_t *ptr; std::vector vopret,data; std::vector > unspentOutputs; @@ -302,7 +302,7 @@ uint256 OracleBatonUtxo(uint64_t txfee,struct CC_info *cp,uint256 reforacletxid, uint256 OraclesBatontxid(uint256 reforacletxid,CPubKey refpk) { std::vector > unspentOutputs; - CTransaction regtx; uint256 hash,txid,batontxid,oracletxid; CPubKey pk; int32_t numvouts,height,maxheight=0; int64_t datafee; char markeraddr[64],batonaddr[64]; std::vector data; struct CC_info *cp,C; + CTransaction regtx; uint256 hash,txid,batontxid,oracletxid; CPubKey pk; int32_t numvouts,height,maxheight=0; int64_t datafee; char markeraddr[64],batonaddr[64]; std::vector data; struct CCcontract_info *cp,C; batontxid = zeroid; cp = CCinit(&C,EVAL_ORACLES); CCtxidaddr(markeraddr,reforacletxid); @@ -528,7 +528,7 @@ int32_t oracleprice_add(std::vector &publishers,CPubKey int64_t OraclePrice(int32_t height,uint256 reforacletxid,char *markeraddr,char *format) { std::vector > unspentOutputs; - CTransaction regtx; uint256 hash,txid,oracletxid,batontxid; CPubKey pk; int32_t i,ht,maxheight=0; int64_t datafee,price; char batonaddr[64]; std::vector data; struct CC_info *cp,C; std::vector publishers; std::vector prices; + CTransaction regtx; uint256 hash,txid,oracletxid,batontxid; CPubKey pk; int32_t i,ht,maxheight=0; int64_t datafee,price; char batonaddr[64]; std::vector data; struct CCcontract_info *cp,C; std::vector publishers; std::vector prices; if ( format[0] != 'L' ) return(0); cp = CCinit(&C,EVAL_ORACLES); @@ -564,7 +564,7 @@ int64_t OraclePrice(int32_t height,uint256 reforacletxid,char *markeraddr,char * return(0); } -int64_t IsOraclesvout(struct CC_info *cp,const CTransaction& tx,int32_t v) +int64_t IsOraclesvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { //char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -575,7 +575,7 @@ int64_t IsOraclesvout(struct CC_info *cp,const CTransaction& tx,int32_t v) return(0); } -bool OraclesDataValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx,uint256 oracletxid,CPubKey publisher,int64_t datafee) +bool OraclesDataValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,uint256 oracletxid,CPubKey publisher,int64_t datafee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; CScript scriptPubKey; @@ -633,7 +633,7 @@ bool OraclesDataValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx,ui else return(true); } -bool OraclesValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { uint256 txid,oracletxid,batontxid; uint64_t txfee=10000; int32_t numvins,numvouts,preventCCvins,preventCCvouts; uint8_t *script; std::vector vopret,data; CScript scriptPubKey; CPubKey publisher; numvins = tx.vin.size(); @@ -703,7 +703,7 @@ bool OraclesValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint3 // helper functions for rpc calls in rpcwallet.cpp -int64_t AddOracleInputs(struct CC_info *cp,CMutableTransaction &mtx,uint256 oracletxid,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddOracleInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,uint256 oracletxid,CPubKey pk,int64_t total,int32_t maxinputs) { char coinaddr[64],funcid; int64_t nValue,price,totalinputs = 0; uint256 tmporacletxid,tmpbatontxid,txid,hashBlock; std::vector origpubkey,data; CTransaction vintx; int32_t numvouts,vout,n = 0; std::vector > unspentOutputs; CPubKey tmppk; int64_t tmpnum; @@ -741,7 +741,7 @@ int64_t AddOracleInputs(struct CC_info *cp,CMutableTransaction &mtx,uint256 orac return(totalinputs); } -int64_t LifetimeOraclesFunds(struct CC_info *cp,uint256 oracletxid,CPubKey publisher) +int64_t LifetimeOraclesFunds(struct CCcontract_info *cp,uint256 oracletxid,CPubKey publisher) { char coinaddr[64]; CPubKey pk; int64_t total=0,num; uint256 txid,hashBlock,subtxid; CTransaction subtx; std::vector > addressIndex; @@ -765,7 +765,7 @@ int64_t LifetimeOraclesFunds(struct CC_info *cp,uint256 oracletxid,CPubKey publi std::string OracleCreate(int64_t txfee,std::string name,std::string description,std::string format) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Oraclespk; struct CC_info *cp,C; char fmt; + CPubKey mypk,Oraclespk; struct CCcontract_info *cp,C; char fmt; cp = CCinit(&C,EVAL_ORACLES); if ( name.size() > 32 || description.size() > 4096 || format.size() > 4096 ) @@ -805,7 +805,7 @@ std::string OracleCreate(int64_t txfee,std::string name,std::string description, std::string OracleRegister(int64_t txfee,uint256 oracletxid,int64_t datafee) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,markerpubkey,batonpk; struct CC_info *cp,C; char markeraddr[64],batonaddr[64]; + CPubKey mypk,markerpubkey,batonpk; struct CCcontract_info *cp,C; char markeraddr[64],batonaddr[64]; cp = CCinit(&C,EVAL_ORACLES); if ( txfee == 0 ) txfee = 10000; @@ -832,7 +832,7 @@ std::string OracleRegister(int64_t txfee,uint256 oracletxid,int64_t datafee) std::string OracleSubscribe(int64_t txfee,uint256 oracletxid,CPubKey publisher,int64_t amount) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,markerpubkey; struct CC_info *cp,C; char markeraddr[64]; + CPubKey mypk,markerpubkey; struct CCcontract_info *cp,C; char markeraddr[64]; cp = CCinit(&C,EVAL_ORACLES); if ( txfee == 0 ) txfee = 10000; @@ -852,7 +852,7 @@ std::string OracleSubscribe(int64_t txfee,uint256 oracletxid,CPubKey publisher,i std::string OracleData(int64_t txfee,uint256 oracletxid,std::vector data) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CScript pubKey; CPubKey mypk,batonpk; int64_t offset,datafee,inputs,CCchange = 0; struct CC_info *cp,C; uint256 batontxid,hashBlock; + CScript pubKey; CPubKey mypk,batonpk; int64_t offset,datafee,inputs,CCchange = 0; struct CCcontract_info *cp,C; uint256 batontxid,hashBlock; char coinaddr[64],batonaddr[64]; std::vector prevdata; CTransaction tx; std::string name,description,format; int32_t len,numvouts; cp = CCinit(&C,EVAL_ORACLES); @@ -971,7 +971,7 @@ UniValue OracleInfo(uint256 origtxid) UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector > unspentOutputs; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction regtx,tx; std::string name,description,format; uint256 hashBlock,txid,oracletxid,batontxid; CPubKey pk; struct CC_info *cp,C; int64_t datafee,funding; char str[67],markeraddr[64],numstr[64],batonaddr[64]; std::vector data; + CTransaction regtx,tx; std::string name,description,format; uint256 hashBlock,txid,oracletxid,batontxid; CPubKey pk; struct CCcontract_info *cp,C; int64_t datafee,funding; char str[67],markeraddr[64],numstr[64],batonaddr[64]; std::vector data; cp = CCinit(&C,EVAL_ORACLES); CCtxidaddr(markeraddr,origtxid); if ( GetTransaction(origtxid,tx,hashBlock,false) == 0 ) @@ -1025,7 +1025,7 @@ UniValue OracleInfo(uint256 origtxid) UniValue OraclesList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CC_info *cp,C; uint256 txid,hashBlock; CTransaction createtx; std::string name,description,format; char str[65]; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock; CTransaction createtx; std::string name,description,format; char str[65]; cp = CCinit(&C,EVAL_ORACLES); SetCCtxids(addressIndex,cp->normaladdr); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index c25842ea3..859a5ba3f 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -23,7 +23,7 @@ // start of consensus code -int64_t IsPaymentsvout(struct CC_info *cp,const CTransaction& tx,int32_t v) +int64_t IsPaymentsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -34,7 +34,7 @@ int64_t IsPaymentsvout(struct CC_info *cp,const CTransaction& tx,int32_t v) return(0); } -bool PaymentsExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool PaymentsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -72,7 +72,7 @@ bool PaymentsExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,i else return(true); } -bool PaymentsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; return eval->Invalid("no validation yet"); @@ -113,7 +113,7 @@ bool PaymentsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint // helper functions for rpc calls in rpcwallet.cpp -int64_t AddPaymentsInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddPaymentsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; @@ -145,7 +145,7 @@ int64_t AddPaymentsInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk std::string PaymentsGet(uint64_t txfee,int64_t nValue) { CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Paymentspk; int64_t inputs,CCchange=0; struct CC_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; + CPubKey mypk,Paymentspk; int64_t inputs,CCchange=0; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; cp = CCinit(&C,EVAL_PAYMENTS); if ( txfee == 0 ) txfee = 10000; @@ -186,7 +186,7 @@ std::string PaymentsGet(uint64_t txfee,int64_t nValue) std::string PaymentsFund(uint64_t txfee,int64_t funds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Paymentspk; CScript opret; struct CC_info *cp,C; + CPubKey mypk,Paymentspk; CScript opret; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_PAYMENTS); if ( txfee == 0 ) txfee = 10000; @@ -204,7 +204,7 @@ UniValue PaymentsInfo() { UniValue result(UniValue::VOBJ); char numstr[64]; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey Paymentspk; struct CC_info *cp,C; int64_t funding; + CPubKey Paymentspk; struct CCcontract_info *cp,C; int64_t funding; result.push_back(Pair("result","success")); result.push_back(Pair("name","Payments")); cp = CCinit(&C,EVAL_PAYMENTS); diff --git a/src/cc/pegs.cpp b/src/cc/pegs.cpp index d137778a6..e2893bec8 100644 --- a/src/cc/pegs.cpp +++ b/src/cc/pegs.cpp @@ -30,7 +30,7 @@ // start of consensus code -int64_t IsPegsvout(struct CC_info *cp,const CTransaction& tx,int32_t v) +int64_t IsPegsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -41,7 +41,7 @@ int64_t IsPegsvout(struct CC_info *cp,const CTransaction& tx,int32_t v) return(0); } -bool PegsExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool PegsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -79,7 +79,7 @@ bool PegsExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32 else return(true); } -bool PegsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool PegsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; return eval->Invalid("no validation yet"); @@ -120,7 +120,7 @@ bool PegsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t // helper functions for rpc calls in rpcwallet.cpp -int64_t AddPegsInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddPegsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; @@ -152,7 +152,7 @@ int64_t AddPegsInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int std::string PegsGet(uint64_t txfee,int64_t nValue) { CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Pegspk; int64_t inputs,CCchange=0; struct CC_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; + CPubKey mypk,Pegspk; int64_t inputs,CCchange=0; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; cp = CCinit(&C,EVAL_PEGS); if ( txfee == 0 ) txfee = 10000; @@ -193,7 +193,7 @@ std::string PegsGet(uint64_t txfee,int64_t nValue) std::string PegsFund(uint64_t txfee,int64_t funds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Pegspk; CScript opret; struct CC_info *cp,C; + CPubKey mypk,Pegspk; CScript opret; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_PEGS); if ( txfee == 0 ) txfee = 10000; @@ -211,7 +211,7 @@ UniValue PegsInfo() { UniValue result(UniValue::VOBJ); char numstr[64]; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey Pegspk; struct CC_info *cp,C; int64_t funding; + CPubKey Pegspk; struct CCcontract_info *cp,C; int64_t funding; result.push_back(Pair("result","success")); result.push_back(Pair("name","Pegs")); cp = CCinit(&C,EVAL_PEGS); diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 6171e73a8..369495b1a 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -86,7 +86,7 @@ uint8_t DecodePricesFundingOpRet(CScript scriptPubKey,CPubKey &planpk,uint256 &o return(0); } -bool PricesValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; return eval->Invalid("no validation yet"); @@ -127,7 +127,7 @@ bool PricesValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32 // helper functions for rpc calls in rpcwallet.cpp -int64_t AddTokensInputs(struct CC_info *cp,CMutableTransaction &mtx,char *destaddr,uint256 tolenid,int64_t total,int32_t maxinputs) +int64_t AddTokensInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,char *destaddr,uint256 tolenid,int64_t total,int32_t maxinputs) { // add threshold check int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; @@ -158,7 +158,7 @@ int64_t AddTokensInputs(struct CC_info *cp,CMutableTransaction &mtx,char *destad UniValue PricesList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CC_info *cp,C; uint64_t mode; int32_t margin,maxleverage; std::vectorpubkeys; uint256 txid,hashBlock,oracletxid,longtoken,shorttoken,bettoken; CPubKey planpk,pricespk; char str[65]; CTransaction vintx; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint64_t mode; int32_t margin,maxleverage; std::vectorpubkeys; uint256 txid,hashBlock,oracletxid,longtoken,shorttoken,bettoken; CPubKey planpk,pricespk; char str[65]; CTransaction vintx; cp = CCinit(&C,EVAL_PRICES); pricespk = GetUnspendable(cp,0); SetCCtxids(addressIndex,cp->normaladdr); @@ -183,7 +183,7 @@ UniValue PricesList() std::string PricesCreateFunding(uint64_t txfee,uint256 bettoken,uint256 oracletxid,uint64_t margin,uint64_t mode,uint256 longtoken,uint256 shorttoken,int32_t maxleverage,int64_t funding,std::vector pubkeys) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction oracletx; int64_t fullsupply,inputs,CCchange=0; uint256 hashBlock; char str[65],coinaddr[64],houseaddr[64]; CPubKey mypk,pricespk; int32_t i,N,numvouts; struct CC_info *cp,C; + CTransaction oracletx; int64_t fullsupply,inputs,CCchange=0; uint256 hashBlock; char str[65],coinaddr[64],houseaddr[64]; CPubKey mypk,pricespk; int32_t i,N,numvouts; struct CCcontract_info *cp,C; if ( funding < 100*COIN || maxleverage <= 0 || maxleverage > 10000 ) { CCerror = "invalid parameter error"; @@ -246,7 +246,7 @@ std::string PricesCreateFunding(uint64_t txfee,uint256 bettoken,uint256 oracletx UniValue PricesInfo(uint256 fundingtxid) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); CPubKey pricespk,planpk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction vintx; int64_t balance,supply,exposure; uint64_t funding,mode; int32_t i,margin,maxleverage; char numstr[65],houseaddr[64],exposureaddr[64],str[65]; std::vectorpubkeys; struct CC_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); CPubKey pricespk,planpk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction vintx; int64_t balance,supply,exposure; uint64_t funding,mode; int32_t i,margin,maxleverage; char numstr[65],houseaddr[64],exposureaddr[64],str[65]; std::vectorpubkeys; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_PRICES); pricespk = GetUnspendable(cp,0); if ( GetTransaction(fundingtxid,vintx,hashBlock,false) == 0 ) @@ -295,7 +295,7 @@ UniValue PricesInfo(uint256 fundingtxid) std::string PricesAddFunding(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int64_t amount) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - struct CC_info *cp,C; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,CCchange = 0; uint64_t funding,mode; int32_t margin,maxleverage; char houseaddr[64],myaddr[64]; std::vectorpubkeys; + struct CCcontract_info *cp,C; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,CCchange = 0; uint64_t funding,mode; int32_t margin,maxleverage; char houseaddr[64],myaddr[64]; std::vectorpubkeys; if ( amount < 10000 ) { CCerror = "amount must be positive"; @@ -350,7 +350,7 @@ std::string PricesAddFunding(uint64_t txfee,uint256 refbettoken,uint256 fundingt std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int64_t amount,int32_t leverage) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - struct CC_info *cp,C; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,tokenid,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,inputs2,longexposure,netexposure,shortexposure,CCchange = 0,CCchange2 = 0; uint64_t funding,mode; int32_t dir,margin,maxleverage; char houseaddr[64],myaddr[64],exposureaddr[64]; std::vectorpubkeys; + struct CCcontract_info *cp,C; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,tokenid,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,inputs2,longexposure,netexposure,shortexposure,CCchange = 0,CCchange2 = 0; uint64_t funding,mode; int32_t dir,margin,maxleverage; char houseaddr[64],myaddr[64],exposureaddr[64]; std::vectorpubkeys; if ( amount < 0 ) { amount = -amount; diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index c47fcf1c2..bd5a6d919 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -141,7 +141,7 @@ uint8_t DecodeRewardsOpRet(uint256 txid,const CScript &scriptPubKey,uint64_t &sb return(0); } -int64_t IsRewardsvout(struct CC_info *cp,const CTransaction& tx,int32_t v,uint64_t refsbits,uint256 reffundingtxid) +int64_t IsRewardsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v,uint64_t refsbits,uint256 reffundingtxid) { char destaddr[64]; uint64_t sbits; uint256 fundingtxid,txid; uint8_t funcid; int32_t numvouts; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 && (numvouts= (int32_t)tx.vout.size()) > 0 ) @@ -157,7 +157,7 @@ int64_t IsRewardsvout(struct CC_info *cp,const CTransaction& tx,int32_t v,uint64 return(0); } -bool RewardsExactAmounts(struct CC_info *cp,Eval *eval,const CTransaction &tx,uint64_t txfee,uint64_t refsbits,uint256 reffundingtxid) +bool RewardsExactAmounts(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx,uint64_t txfee,uint64_t refsbits,uint256 reffundingtxid) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -192,7 +192,7 @@ bool RewardsExactAmounts(struct CC_info *cp,Eval *eval,const CTransaction &tx,ui else return(true); } -bool RewardsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { uint256 txid,fundingtxid,hashBlock,vinfundingtxid; uint64_t vinsbits,sbits,APR,minseconds,maxseconds,mindeposit,amount,reward,txfee=10000; int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; uint8_t funcid; CScript scriptPubKey; CTransaction fundingTx,vinTx; numvins = tx.vin.size(); @@ -327,7 +327,7 @@ static uint64_t myIs_unlockedtx_inmempool(uint256 &txid,int32_t &vout,uint64_t r } // 'L' vs 'F' and 'A' -int64_t AddRewardsInputs(CScript &scriptPubKey,uint64_t maxseconds,struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) +int64_t AddRewardsInputs(CScript &scriptPubKey,uint64_t maxseconds,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) { char coinaddr[64],str[65]; uint64_t threshold,sbits,nValue,totalinputs = 0; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t numblocks,j,vout,n = 0; uint8_t funcid; std::vector > unspentOutputs; @@ -387,7 +387,7 @@ int64_t AddRewardsInputs(CScript &scriptPubKey,uint64_t maxseconds,struct CC_inf return(totalinputs); } -int64_t RewardsPlanFunds(uint64_t &lockedfunds,uint64_t refsbits,struct CC_info *cp,CPubKey pk,uint256 reffundingtxid) +int64_t RewardsPlanFunds(uint64_t &lockedfunds,uint64_t refsbits,struct CCcontract_info *cp,CPubKey pk,uint256 reffundingtxid) { char coinaddr[64]; uint64_t sbits; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t vout; uint8_t funcid; std::vector > unspentOutputs; @@ -418,7 +418,7 @@ int64_t RewardsPlanFunds(uint64_t &lockedfunds,uint64_t refsbits,struct CC_info return(totalinputs); } -bool RewardsPlanExists(struct CC_info *cp,uint64_t refsbits,CPubKey rewardspk,uint64_t &APR,uint64_t &minseconds,uint64_t &maxseconds,uint64_t &mindeposit) +bool RewardsPlanExists(struct CCcontract_info *cp,uint64_t refsbits,CPubKey rewardspk,uint64_t &APR,uint64_t &minseconds,uint64_t &maxseconds,uint64_t &mindeposit) { char CCaddr[64]; uint64_t sbits; uint256 txid,hashBlock; CTransaction tx; std::vector > txids; @@ -443,7 +443,7 @@ bool RewardsPlanExists(struct CC_info *cp,uint64_t refsbits,CPubKey rewardspk,ui UniValue RewardsInfo(uint256 rewardsid) { - UniValue result(UniValue::VOBJ); uint256 hashBlock; CTransaction vintx; uint64_t lockedfunds,APR,minseconds,maxseconds,mindeposit,sbits,funding; CPubKey rewardspk; struct CC_info *cp,C; char str[67],numstr[65]; + UniValue result(UniValue::VOBJ); uint256 hashBlock; CTransaction vintx; uint64_t lockedfunds,APR,minseconds,maxseconds,mindeposit,sbits,funding; CPubKey rewardspk; struct CCcontract_info *cp,C; char str[67],numstr[65]; if ( GetTransaction(rewardsid,vintx,hashBlock,false) == 0 ) { fprintf(stderr,"cant find fundingtxid\n"); @@ -481,7 +481,7 @@ UniValue RewardsInfo(uint256 rewardsid) UniValue RewardsList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CC_info *cp,C; uint256 txid,hashBlock; CTransaction vintx; uint64_t sbits,APR,minseconds,maxseconds,mindeposit; char str[65]; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock; CTransaction vintx; uint64_t sbits,APR,minseconds,maxseconds,mindeposit; char str[65]; cp = CCinit(&C,EVAL_REWARDS); SetCCtxids(addressIndex,cp->normaladdr); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) @@ -501,7 +501,7 @@ UniValue RewardsList() std::string RewardsCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t APR,int64_t minseconds,int64_t maxseconds,int64_t mindeposit) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,rewardspk; CScript opret; uint64_t sbits,a,b,c,d; struct CC_info *cp,C; + CPubKey mypk,rewardspk; CScript opret; uint64_t sbits,a,b,c,d; struct CCcontract_info *cp,C; if ( funds < COIN || mindeposit < 0 || minseconds < 0 || maxseconds < 0 ) { fprintf(stderr,"negative parameter error\n"); @@ -536,7 +536,7 @@ std::string RewardsCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int6 std::string RewardsAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,rewardspk; CScript opret; uint64_t sbits,a,b,c,d; struct CC_info *cp,C; + CPubKey mypk,rewardspk; CScript opret; uint64_t sbits,a,b,c,d; struct CCcontract_info *cp,C; if ( amount < 0 ) { fprintf(stderr,"negative parameter error\n"); @@ -571,7 +571,7 @@ std::string RewardsAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,i std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t deposit) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,rewardspk; CScript opret; uint64_t lockedfunds,sbits,funding,APR,minseconds,maxseconds,mindeposit; struct CC_info *cp,C; + CPubKey mypk,rewardspk; CScript opret; uint64_t lockedfunds,sbits,funding,APR,minseconds,maxseconds,mindeposit; struct CCcontract_info *cp,C; if ( deposit < txfee ) { CCerror = "deposit amount less than txfee"; @@ -615,7 +615,7 @@ std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 locktxid) { CMutableTransaction firstmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction tx; char coinaddr[64]; CPubKey mypk,rewardspk; CScript scriptPubKey,ignore; uint256 hashBlock; uint64_t sbits,APR,minseconds,maxseconds,mindeposit; int64_t funding,reward=0,amount=0,inputs,CCchange=0; struct CC_info *cp,C; + CTransaction tx; char coinaddr[64]; CPubKey mypk,rewardspk; CScript scriptPubKey,ignore; uint256 hashBlock; uint64_t sbits,APR,minseconds,maxseconds,mindeposit; int64_t funding,reward=0,amount=0,inputs,CCchange=0; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_REWARDS); if ( txfee == 0 ) txfee = 10000; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 51b31c5c7..10c6ee4b8 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2150,7 +2150,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } else { - struct CC_info *cp,C; uint256 txid; int32_t vout; CAmount nValue; char coinaddr[64]; CPubKey mypk,Marmarapk; + struct CCcontract_info *cp,C; uint256 txid; int32_t vout; CAmount nValue; char coinaddr[64]; CPubKey mypk,Marmarapk; std::vector > unspentOutputs; cp = CCinit(&C,EVAL_MARMARA); mypk = pubkey2pk(Mypubkey()); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 588706a41..2db63d83a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5197,7 +5197,7 @@ int32_t ensure_CCrequirements() #include "../cc/CCHeir.h" #include "../cc/CCMarmara.h" -UniValue CCaddress(struct CC_info *cp,char *name,std::vector &pubkey) +UniValue CCaddress(struct CCcontract_info *cp,char *name,std::vector &pubkey) { UniValue result(UniValue::VOBJ); char destaddr[64],str[64]; CPubKey pk; pk = GetUnspendable(cp,0); @@ -5302,7 +5302,7 @@ UniValue setpubkey(const UniValue& params, bool fHelp) UniValue channelsaddress(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); struct CC_info *cp,C; std::vector destpubkey; CPubKey pk,pk2; char destaddr[64]; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::vector destpubkey; CPubKey pk,pk2; char destaddr[64]; cp = CCinit(&C,EVAL_CHANNELS); if ( fHelp || params.size() != 1 ) throw runtime_error("channelsaddress destpubkey\n"); @@ -5329,7 +5329,7 @@ UniValue channelsaddress(const UniValue& params, bool fHelp) UniValue cclibaddress(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; std::vector pubkey; + struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_FIRSTUSER); if ( fHelp || params.size() > 1 ) throw runtime_error("cclibaddress [pubkey]\n"); @@ -5342,7 +5342,7 @@ UniValue cclibaddress(const UniValue& params, bool fHelp) UniValue cclibinfo(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; + struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_FIRSTUSER); if ( fHelp || params.size() > 0 ) throw runtime_error("cclibinfo\n"); @@ -5353,7 +5353,7 @@ UniValue cclibinfo(const UniValue& params, bool fHelp) UniValue cclib(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; char *method; cJSON *params; + struct CCcontract_info *cp,C; char *method; cJSON *params; cp = CCinit(&C,EVAL_FIRSTUSER); if ( fHelp || params.size() > 2 ) throw runtime_error("cclib method [JSON params]\n"); @@ -5366,7 +5366,7 @@ UniValue cclib(const UniValue& params, bool fHelp) UniValue oraclesaddress(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; std::vector pubkey; + struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_ORACLES); if ( fHelp || params.size() > 1 ) throw runtime_error("oraclesaddress [pubkey]\n"); @@ -5379,7 +5379,7 @@ UniValue oraclesaddress(const UniValue& params, bool fHelp) UniValue pricesaddress(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); struct CC_info *cp,C,*assetscp,C2; std::vector pubkey; CPubKey mypk,planpk,pricespk; char myaddr[64],houseaddr[64],exposureaddr[64]; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C,*assetscp,C2; std::vector pubkey; CPubKey mypk,planpk,pricespk; char myaddr[64],houseaddr[64],exposureaddr[64]; cp = CCinit(&C,EVAL_PRICES); assetscp = CCinit(&C2,EVAL_PRICES); if ( fHelp || params.size() > 1 ) @@ -5402,7 +5402,7 @@ UniValue pricesaddress(const UniValue& params, bool fHelp) UniValue pegsaddress(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; std::vector pubkey; + struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_PEGS); if ( fHelp || params.size() > 1 ) throw runtime_error("pegssaddress [pubkey]\n"); @@ -5415,7 +5415,7 @@ UniValue pegsaddress(const UniValue& params, bool fHelp) UniValue marmaraaddress(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; std::vector pubkey; + struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_MARMARA); if ( fHelp || params.size() > 1 ) throw runtime_error("Marmaraaddress [pubkey]\n"); @@ -5428,7 +5428,7 @@ UniValue marmaraaddress(const UniValue& params, bool fHelp) UniValue paymentsaddress(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; std::vector pubkey; + struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_PAYMENTS); if ( fHelp || params.size() > 1 ) throw runtime_error("paymentsaddress [pubkey]\n"); @@ -5441,7 +5441,7 @@ UniValue paymentsaddress(const UniValue& params, bool fHelp) UniValue gatewaysaddress(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; std::vector pubkey; + struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_GATEWAYS); if ( fHelp || params.size() > 1 ) throw runtime_error("gatewaysaddress [pubkey]\n"); @@ -5454,7 +5454,7 @@ UniValue gatewaysaddress(const UniValue& params, bool fHelp) UniValue heiraddress(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; std::vector pubkey; + struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_HEIR); if ( fHelp || params.size() > 1 ) throw runtime_error("heiraddress [pubkey]\n"); @@ -5469,7 +5469,7 @@ UniValue heiraddress(const UniValue& params, bool fHelp) UniValue lottoaddress(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; std::vector pubkey; + struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_LOTTO); if ( fHelp || params.size() > 1 ) throw runtime_error("lottoaddress [pubkey]\n"); @@ -5482,7 +5482,7 @@ UniValue lottoaddress(const UniValue& params, bool fHelp) UniValue FSMaddress(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; std::vector pubkey; + struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_FSM); if ( fHelp || params.size() > 1 ) throw runtime_error("FSMaddress [pubkey]\n"); @@ -5495,7 +5495,7 @@ UniValue FSMaddress(const UniValue& params, bool fHelp) UniValue auctionaddress(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; std::vector pubkey; + struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_AUCTION); if ( fHelp || params.size() > 1 ) throw runtime_error("auctionaddress [pubkey]\n"); @@ -5508,7 +5508,7 @@ UniValue auctionaddress(const UniValue& params, bool fHelp) UniValue diceaddress(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; std::vector pubkey; + struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_DICE); if ( fHelp || params.size() > 1 ) throw runtime_error("diceaddress [pubkey]\n"); @@ -5521,7 +5521,7 @@ UniValue diceaddress(const UniValue& params, bool fHelp) UniValue faucetaddress(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; std::vector pubkey; + struct CCcontract_info *cp,C; std::vector pubkey; int errno; cp = CCinit(&C,EVAL_FAUCET); if ( fHelp || params.size() > 1 ) @@ -5536,7 +5536,7 @@ UniValue faucetaddress(const UniValue& params, bool fHelp) UniValue rewardsaddress(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; std::vector pubkey; + struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_REWARDS); if ( fHelp || params.size() > 1 ) throw runtime_error("rewardsaddress [pubkey]\n"); @@ -5549,7 +5549,7 @@ UniValue rewardsaddress(const UniValue& params, bool fHelp) UniValue assetsaddress(const UniValue& params, bool fHelp) { - struct CC_info *cp, C; std::vector pubkey; + struct CCcontract_info *cp, C; std::vector pubkey; cp = CCinit(&C, EVAL_ASSETS); if (fHelp || params.size() > 1) throw runtime_error("assetsaddress [pubkey]\n"); @@ -5562,7 +5562,7 @@ UniValue assetsaddress(const UniValue& params, bool fHelp) UniValue tokenaddress(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; std::vector pubkey; + struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_TOKENS); if ( fHelp || params.size() > 1 ) throw runtime_error("tokenaddress [pubkey]\n"); @@ -5767,7 +5767,7 @@ UniValue channelsinfo(const UniValue& params, bool fHelp) UniValue channelsopen(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); int32_t numpayments; int64_t payment; std::vector destpub; struct CC_info *cp,C; std::string hex; + UniValue result(UniValue::VOBJ); int32_t numpayments; int64_t payment; std::vector destpub; struct CCcontract_info *cp,C; std::string hex; uint256 tokenid=zeroid; cp = CCinit(&C,EVAL_CHANNELS); @@ -5810,7 +5810,7 @@ UniValue channelsopen(const UniValue& params, bool fHelp) UniValue channelspayment(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); struct CC_info *cp,C; std::string hex; uint256 opentxid,secret=zeroid; int32_t n; int64_t amount; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 opentxid,secret=zeroid; int32_t n; int64_t amount; cp = CCinit(&C,EVAL_CHANNELS); if ( fHelp || params.size() < 2 || params.size() >3 ) throw runtime_error("channelspayment opentxid amount [secret]\n"); @@ -5840,7 +5840,7 @@ UniValue channelspayment(const UniValue& params, bool fHelp) UniValue channelsclose(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); struct CC_info *cp,C; std::string hex; uint256 opentxid; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 opentxid; cp = CCinit(&C,EVAL_CHANNELS); if ( fHelp || params.size() != 1 ) throw runtime_error("channelsclose opentxid\n"); @@ -5860,7 +5860,7 @@ UniValue channelsclose(const UniValue& params, bool fHelp) UniValue channelsrefund(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); struct CC_info *cp,C; std::string hex; uint256 opentxid,closetxid; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 opentxid,closetxid; cp = CCinit(&C,EVAL_CHANNELS); if ( fHelp || params.size() != 2 ) throw runtime_error("channelsrefund opentxid closetxid\n"); @@ -6914,7 +6914,7 @@ UniValue tokenorders(const UniValue& params, bool fHelp) UniValue tokenbalance(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); uint256 tokenid; uint64_t balance; std::vector pubkey; struct CC_info *cp,C; + UniValue result(UniValue::VOBJ); uint256 tokenid; uint64_t balance; std::vector pubkey; struct CCcontract_info *cp,C; CCerror.clear(); if ( fHelp || params.size() > 2 ) From 5f0b70615fa80550e6304988706e4be360e0e6d9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 23:37:48 -1100 Subject: [PATCH 557/643] Jsonparams --- src/wallet/rpcwallet.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 2db63d83a..5231dae27 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5353,15 +5353,15 @@ UniValue cclibinfo(const UniValue& params, bool fHelp) UniValue cclib(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; char *method; cJSON *params; + struct CCcontract_info *cp,C; char *method; cJSON *jsonparams; cp = CCinit(&C,EVAL_FIRSTUSER); if ( fHelp || params.size() > 2 ) throw runtime_error("cclib method [JSON params]\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); method = params[0].get_str().c_str(); - params = cJSON_Parse(params[1].get_str().c_str()); - return(CClib(cp,method,params)); + jsonparams = cJSON_Parse(params[1].get_str().c_str()); + return(CClib(cp,method,jsonparams)); } UniValue oraclesaddress(const UniValue& params, bool fHelp) From 01d2fa36a2997d57f30089bc4b46854b36cd023d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 23:38:48 -1100 Subject: [PATCH 558/643] UniValue CClib_info(struct CCcontract_info *cp) --- src/cc/CCinclude.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 82c9484d5..258d8b95b 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -135,6 +135,8 @@ int32_t komodo_nextheight(); int32_t CCgetspenttxid(uint256 &spenttxid,int32_t &vini,int32_t &height,uint256 txid,int32_t vout); void CCclearvars(struct CCcontract_info *cp); +UniValue CClib(struct CCcontract_info *cp,char *method,cJSON *params); +UniValue CClib_info(struct CCcontract_info *cp); static const uint256 zeroid; bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock); From b4e0b6bca4676407145b640f48101846ade1ee57 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 23:54:51 -1100 Subject: [PATCH 559/643] Faucet2 --- src/cc/cclib.cpp | 220 ++++++++++++++++++++++++++++++++++++++- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 219 insertions(+), 3 deletions(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 0f201acc4..23f3d81c9 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -27,6 +27,8 @@ #include "core_io.h" #include "crosschain.h" +#define FAUCET2SIZE COIN + struct CClib_rpcinfo { char *method,*help; @@ -35,6 +37,7 @@ struct CClib_rpcinfo } CClib_methods[] = { + { "faucet2_fund", "amount", 1, 1, 'F' }, { "faucet2_get", "", 0, 0, 'G' }, }; @@ -90,12 +93,225 @@ UniValue CClib(struct CCcontract_info *cp,char *method,cJSON *params) return(result); } +int64_t IsCClibvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +{ + char destaddr[64]; + if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) + { + if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && strcmp(destaddr,cp->unspendableCCaddr) == 0 ) + return(tx.vout[v].nValue); + } + return(0); +} + +bool CClibExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +{ + static uint256 zerohash; + CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; + numvins = tx.vin.size(); + numvouts = tx.vout.size(); + for (i=0; iismyvin)(tx.vin[i].scriptSig) != 0 ) + { + //fprintf(stderr,"vini.%d check mempool\n",i); + if ( eval->GetTxUnconfirmed(tx.vin[i].prevout.hash,vinTx,hashBlock) == 0 ) + return eval->Invalid("cant find vinTx"); + else + { + //fprintf(stderr,"vini.%d check hash and vout\n",i); + if ( hashBlock == zerohash ) + return eval->Invalid("cant faucet2 from mempool"); + if ( (assetoshis= IsCClibvout(cp,vinTx,tx.vin[i].prevout.n)) != 0 ) + inputs += assetoshis; + } + } + } + for (i=0; iInvalid("mismatched inputs != outputs + FAUCET2SIZE + txfee"); + } + else return(true); +} + bool CClib_validate(struct CCcontract_info *cp,Eval *eval,const CTransaction &txTo,unsigned int nIn) { - return(true); // for now + int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; + std::vector > txids; + numvins = tx.vin.size(); + numvouts = tx.vout.size(); + preventCCvins = preventCCvouts = -1; + if ( numvouts < 1 ) + return eval->Invalid("no vouts"); + else + { + for (i=0; iInvalid("illegal normal vini"); + } + } + //fprintf(stderr,"check amounts\n"); + if ( CClibExactAmounts(cp,eval,tx,1,10000) == false ) + { + fprintf(stderr,"faucetget invalid amount\n"); + return false; + } + else + { + preventCCvouts = 1; + if ( IsFaucetvout(cp,tx,0) != 0 ) + { + preventCCvouts++; + i = 1; + } else i = 0; + txid = tx.GetHash(); + memcpy(hash,&txid,sizeof(hash)); + fprintf(stderr,"check faucetget txid %s %02x/%02x\n",uint256_str(str,txid),hash[0],hash[31]); + if ( tx.vout[i].nValue != FAUCET2SIZE ) + return eval->Invalid("invalid faucet output"); + else if ( (hash[0] & 0xff) != 0 || (hash[31] & 0xff) != 0 ) + return eval->Invalid("invalid faucetget txid"); + Getscriptaddress(destaddr,tx.vout[i].scriptPubKey); + SetCCtxids(txids,destaddr); + for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) + { + //int height = it->first.blockHeight; + if ( CCduration(numblocks,it->first.txhash) > 0 && numblocks > 3 ) + { + //fprintf(stderr,"would return error %s numblocks.%d ago\n",uint256_str(str,it->first.txhash),numblocks); + return eval->Invalid("faucet2 is only for brand new addresses"); + } + } + retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); + if ( retval != 0 ) + fprintf(stderr,"faucet2get validated\n"); + else fprintf(stderr,"faucet2get invalid\n"); + return(retval); + } + } +} + +int64_t AddCClibInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +{ + char coinaddr[64]; int64_t threshold,nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; + std::vector > unspentOutputs; + GetCCaddress(cp,coinaddr,pk); + SetCCunspents(unspentOutputs,coinaddr); + threshold = total/(maxinputs+1); + for (std::vector >::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; + //char str[65]; fprintf(stderr,"check %s/v%d %.8f`\n",uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); + // no need to prevent dup + if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + { + if ( (nValue= IsCClibvout(cp,vintx,vout)) > 1000000 && myIsutxo_spentinmempool(txid,vout) == 0 ) + { + if ( total != 0 && maxinputs != 0 ) + mtx.vin.push_back(CTxIn(txid,vout,CScript())); + nValue = it->second.satoshis; + totalinputs += nValue; + n++; + if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) + break; + } else fprintf(stderr,"nValue too small or already spent in mempool\n"); + } else fprintf(stderr,"couldnt get tx\n"); + } + return(totalinputs); +} + + +std::string Faucet2Fund(struct CCcontract_info *cp,uint64_t txfee,int64_t funds) +{ + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + CPubKey mypk,cclibpk; CScript opret; + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + cclibpk = GetUnspendable(cp,0); + if ( AddNormalinputs(mtx,mypk,funds+txfee,64) > 0 ) + { + mtx.vout.push_back(MakeCC1vout(cp->evalcode,funds,cclibpk)); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); + } + return(""); +} + +UniValue FaucetInfo() +{ + UniValue result(UniValue::VOBJ); char numstr[64]; + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + CPubKey faucetpk; struct CCcontract_info *cp,C; int64_t funding; + result.push_back(Pair("result","success")); + result.push_back(Pair("name","Faucet")); + cp = CCinit(&C,EVAL_FAUCET); + faucetpk = GetUnspendable(cp,0); + funding = AddFaucetInputs(cp,mtx,faucetpk,0,0); + sprintf(numstr,"%.8f",(double)funding/COIN); + result.push_back(Pair("funding",numstr)); + return(result); } std::string CClib_rawtxgen(struct CCcontract_info *cp,uint8_t funcid,cJSON *params) { - return((char *)"deadbeef"); + CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + CPubKey mypk,cclibpk; int64_t funds,txfee=0,inputs,CCchange=0,nValue=FAUCET2SIZE; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; + if ( txfee == 0 ) + txfee = 10000; + if ( funcid == 'F' ) + { + if ( cJSON_GetArraySize(params) > 0 ) + { + funds = (int64_t)jdouble(jarrayi(params,0))*COIN + 0.0000000049; + return(Faucet2Fund(cp,0,funds)); + } else return(""); + } + else if ( funcid != 'G' ) + return(""); + cclibpk = GetUnspendable(cp,0); + mypk = pubkey2pk(Mypubkey()); + if ( (inputs= AddCClibInputs(cp,mtx,cclibpk,nValue+txfee,60)) > 0 ) + { + if ( inputs > nValue ) + CCchange = (inputs - nValue - txfee); + if ( CCchange != 0 ) + mtx.vout.push_back(MakeCC1vout(EVAL_FIRSTUSER,CCchange,cclibpk)); + mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + fprintf(stderr,"start at %u\n",(uint32_t)time(NULL)); + j = rand() & 0xfffffff; + for (i=0; i<1000000; i++,j++) + { + tmpmtx = mtx; + rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_FIRSTUSER << (uint8_t)'G' << j)); + if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 ) + { + len >>= 1; + decode_hex(buf,len,(char *)rawhex.c_str()); + hash = bits256_doublesha256(0,buf,len); + if ( (hash.bytes[0] & 0xff) == 0 && (hash.bytes[31] & 0xff) == 0 ) + { + fprintf(stderr,"found valid txid after %d iterations %u\n",i,(uint32_t)time(NULL)); + return(rawhex); + } + //fprintf(stderr,"%02x%02x ",hash.bytes[0],hash.bytes[31]); + } + } + fprintf(stderr,"couldnt generate valid txid %u\n",(uint32_t)time(NULL)); + return(""); + } else fprintf(stderr,"cant find faucet inputs\n"); + return(""); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5231dae27..174f447f0 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5359,7 +5359,7 @@ UniValue cclib(const UniValue& params, bool fHelp) throw runtime_error("cclib method [JSON params]\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - method = params[0].get_str().c_str(); + method = (char *)params[0].get_str().c_str(); jsonparams = cJSON_Parse(params[1].get_str().c_str()); return(CClib(cp,method,jsonparams)); } From 1cf8cec01899d993380d9c9631db3b63102d43a4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 23:58:36 -1100 Subject: [PATCH 560/643] Item --- src/cc/CCutils.cpp | 2 +- src/cc/cclib.cpp | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 3670859cc..67ee7d5db 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -638,7 +638,7 @@ bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector param extern struct CCcontract_info CCinfos[0x100]; extern std::string MYCCLIBNAME; -bool CClib_validate(struct CCcontract_info *cp,Eval *eval,const CTransaction &txTo,unsigned int nIn); +bool CClib_validate(struct CCcontract_info *cp,Eval *eval,const CTransaction tx,unsigned int nIn); bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,const CTransaction &txTo,unsigned int nIn) { diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 23f3d81c9..d727dd8cd 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -37,13 +37,13 @@ struct CClib_rpcinfo } CClib_methods[] = { - { "faucet2_fund", "amount", 1, 1, 'F' }, - { "faucet2_get", "", 0, 0, 'G' }, + { (char *)"faucet2_fund", (char *)"amount", 1, 1, 'F' }, + { (char *)"faucet2_get", (char *)"", 0, 0, 'G' }, }; -std::string MYCCLIBNAME = (char *)"stub"; +std::string MYCCLIBNAME = (char *)"faucet2"; -char *CClib_name() { return(MYCCLIBNAME); } +char *CClib_name() { return(MYCCLIBNAME.c_str()); } std::string CClib_rawtxgen(struct CCcontract_info *cp,uint8_t funcid,cJSON *params); @@ -67,7 +67,7 @@ UniValue CClib_info(struct CCcontract_info *cp) obj.push_back(Pair("help",CClib_methods[i].help)); obj.push_back(Pair("params_required",CClib_methods[i].numrequiredargs)); obj.push_back(Pair("params_max",CClib_methods[i].maxargs)); - a.push_back(obj)); + a.push_back(obj); } result.push_back(Pair("methods",a)); return(result); @@ -134,7 +134,7 @@ bool CClibExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction if ( (assetoshis= IsCClibvout(cp,tx,i)) != 0 ) outputs += assetoshis; } - if ( inputs != outputs+FAUCETSIZE+txfee ) + if ( inputs != outputs+FAUCET2SIZE+txfee ) { fprintf(stderr,"inputs %llu vs outputs %llu\n",(long long)inputs,(long long)outputs); return eval->Invalid("mismatched inputs != outputs + FAUCET2SIZE + txfee"); @@ -142,7 +142,7 @@ bool CClibExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction else return(true); } -bool CClib_validate(struct CCcontract_info *cp,Eval *eval,const CTransaction &txTo,unsigned int nIn) +bool CClib_validate(struct CCcontract_info *cp,Eval *eval,const CTransaction tx,unsigned int nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; std::vector > txids; @@ -276,7 +276,7 @@ std::string CClib_rawtxgen(struct CCcontract_info *cp,uint8_t funcid,cJSON *para { if ( cJSON_GetArraySize(params) > 0 ) { - funds = (int64_t)jdouble(jarrayi(params,0))*COIN + 0.0000000049; + funds = (int64_t)jdouble(jitem(params,0))*COIN + 0.0000000049; return(Faucet2Fund(cp,0,funds)); } else return(""); } From 887f6cb2ab2ab3b3f9d76bb47136241c9b906908 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 20 Jan 2019 00:00:51 -1100 Subject: [PATCH 561/643] Test --- src/cc/CCinclude.h | 1 + src/cc/cclib.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 258d8b95b..451b87dd9 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -50,6 +50,7 @@ one other technical note is that komodod has the insight-explorer extensions bui #include "../komodo_defs.h" #include "../utlist.h" #include "../uthash.h" +#include "../cJSON.h" extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE,KOMODO_DEALERNODE; extern uint32_t ASSETCHAINS_CC; diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index d727dd8cd..7202dd7c6 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -43,7 +43,7 @@ CClib_methods[] = std::string MYCCLIBNAME = (char *)"faucet2"; -char *CClib_name() { return(MYCCLIBNAME.c_str()); } +char *CClib_name() { return((char *)MYCCLIBNAME.c_str()); } std::string CClib_rawtxgen(struct CCcontract_info *cp,uint8_t funcid,cJSON *params); @@ -170,7 +170,7 @@ bool CClib_validate(struct CCcontract_info *cp,Eval *eval,const CTransaction tx, else { preventCCvouts = 1; - if ( IsFaucetvout(cp,tx,0) != 0 ) + if ( IsCClibvout(cp,tx,0) != 0 ) { preventCCvouts++; i = 1; @@ -251,7 +251,7 @@ std::string Faucet2Fund(struct CCcontract_info *cp,uint64_t txfee,int64_t funds) return(""); } -UniValue FaucetInfo() +/*UniValue FaucetInfo() { UniValue result(UniValue::VOBJ); char numstr[64]; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); @@ -264,12 +264,12 @@ UniValue FaucetInfo() sprintf(numstr,"%.8f",(double)funding/COIN); result.push_back(Pair("funding",numstr)); return(result); -} +}*/ std::string CClib_rawtxgen(struct CCcontract_info *cp,uint8_t funcid,cJSON *params) { CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,cclibpk; int64_t funds,txfee=0,inputs,CCchange=0,nValue=FAUCET2SIZE; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; + CPubKey mypk,cclibpk; int64_t funds,txfee=0,inputs,CCchange=0,nValue=FAUCET2SIZE; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; if ( txfee == 0 ) txfee = 10000; if ( funcid == 'F' ) From 0ceca4c74546eea83ee528dec75542f8b7f1afc2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 20 Jan 2019 00:01:18 -1100 Subject: [PATCH 562/643] komodo_cJSON.h --- src/cc/CCinclude.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 451b87dd9..4cb658681 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -50,7 +50,7 @@ one other technical note is that komodod has the insight-explorer extensions bui #include "../komodo_defs.h" #include "../utlist.h" #include "../uthash.h" -#include "../cJSON.h" +#include "../komodo_cJSON.h" extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE,KOMODO_DEALERNODE; extern uint32_t ASSETCHAINS_CC; From 53b2d35da7d084ee3c28a8aa144183bd91a6f2af Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 20 Jan 2019 00:03:36 -1100 Subject: [PATCH 563/643] Bit256 --- src/cc/CCinclude.h | 2 +- src/cc/cclib.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 4cb658681..1953fad34 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -50,7 +50,6 @@ one other technical note is that komodod has the insight-explorer extensions bui #include "../komodo_defs.h" #include "../utlist.h" #include "../uthash.h" -#include "../komodo_cJSON.h" extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE,KOMODO_DEALERNODE; extern uint32_t ASSETCHAINS_CC; @@ -70,6 +69,7 @@ extern uint8_t ASSETCHAINS_CCDISABLES[256]; typedef union _bits256 bits256; #endif +#include "../komodo_cJSON.h" struct CC_utxo { diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 7202dd7c6..5a9c3b4af 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -276,7 +276,7 @@ std::string CClib_rawtxgen(struct CCcontract_info *cp,uint8_t funcid,cJSON *para { if ( cJSON_GetArraySize(params) > 0 ) { - funds = (int64_t)jdouble(jitem(params,0))*COIN + 0.0000000049; + funds = (int64_t)jdouble(jitem(params,0),0)*COIN + 0.0000000049; return(Faucet2Fund(cp,0,funds)); } else return(""); } From fc506524584f7fa722fdce60f58d4855f6aec1fd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 20 Jan 2019 06:24:55 -1100 Subject: [PATCH 564/643] Change error handling --- src/cc/CCutils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 67ee7d5db..58496333a 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -673,7 +673,7 @@ bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,co return eval->Invalid("Cannot have params"); else if ( CClib_validate(cp,eval,txTo,nIn) != 0 ) return(true); - return eval->Invalid("error in CClib_validate"); + return(false); //eval->Invalid("error in CClib_validate"); } return eval->Invalid("cclib CC must have evalcode between 16 and 127"); } From 7bf38b4fdb2b9313c74c9866cf6844dc4b84368c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 20 Jan 2019 06:54:59 -1100 Subject: [PATCH 565/643] Pass in height to cclib_validate --- src/cc/CCutils.cpp | 4 ++-- src/cc/cclib.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 58496333a..4eb6fbbc1 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -638,7 +638,7 @@ bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector param extern struct CCcontract_info CCinfos[0x100]; extern std::string MYCCLIBNAME; -bool CClib_validate(struct CCcontract_info *cp,Eval *eval,const CTransaction tx,unsigned int nIn); +bool CClib_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx,unsigned int nIn); bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,const CTransaction &txTo,unsigned int nIn) { @@ -671,7 +671,7 @@ bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,co CCclearvars(cp); if ( paramsNull.size() != 0 ) // Don't expect params return eval->Invalid("Cannot have params"); - else if ( CClib_validate(cp,eval,txTo,nIn) != 0 ) + else if ( CClib_validate(cp,height,eval,txTo,nIn) != 0 ) return(true); return(false); //eval->Invalid("error in CClib_validate"); } diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 5a9c3b4af..971258d90 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -142,7 +142,7 @@ bool CClibExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction else return(true); } -bool CClib_validate(struct CCcontract_info *cp,Eval *eval,const CTransaction tx,unsigned int nIn) +bool CClib_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx,unsigned int nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; std::vector > txids; From 0cea4b2d11058e61de123cabfb87dd657af54a7f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 20 Jan 2019 21:13:19 -1100 Subject: [PATCH 566/643] +print --- src/komodo_bitcoind.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 10c6ee4b8..d35683c93 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -643,15 +643,15 @@ int32_t komodo_isPoS(CBlock *pblock) { txid = pblock->vtx[n-1].vin[0].prevout.hash; vout = pblock->vtx[n-1].vin[0].prevout.n; - if ( ASSETCHAINS_MARMARA != 0 ) - { - fprintf(stderr,"validate proper signature and unlockht preservation\n"); - // need to verify it was signed by the non-Marmarapk of the 1of2 - } txtime = komodo_txtime(&value,txid,vout,destaddr); if ( ExtractDestination(pblock->vtx[n-1].vout[0].scriptPubKey,voutaddress) ) { strcpy(voutaddr,CBitcoinAddress(voutaddress).ToString().c_str()); + if ( ASSETCHAINS_MARMARA != 0 ) + { + fprintf(stderr,"validate proper %s %s signature and unlockht preservation\n",voutaddr,destaddr); + // need to verify it was signed by the non-Marmarapk of the 1of2 + } if ( strcmp(destaddr,voutaddr) == 0 && pblock->vtx[n-1].vout[0].nValue == value ) { //fprintf(stderr,"is PoS block!\n"); From c9a44be0b1276cda887df1a6ccb200d73c3d1b59 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 20 Jan 2019 21:58:23 -1100 Subject: [PATCH 567/643] Marmara PoS check --- src/cc/marmara.cpp | 15 ++++++++++++++ src/komodo_bitcoind.h | 47 +++++++++++++++++++++++++------------------ src/main.cpp | 6 +++--- 3 files changed, 45 insertions(+), 23 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 795b95186..98e805c38 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -255,6 +255,21 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) return(-1); } +bool MarmaraPoScheck(char *destaddr,CScript opret,CScript scriptPubKey) +{ + CPubKey pk; int32_t height,unlockht; uint8_t funcid; char coinaddr[64]; struct CCcontract_info *cp,C; + if ( opret == scriptPubKey ) + { + cp = CCinit(&C,EVAL_MARMARA); + funcid = DecodeMaramaraCoinbaseOpRet(opret,pk,height,unlockht); + Marmarapk = GetUnspendable(cp,0); + GetCCaddress1of2(cp,coinaddr,Marmarapk,pk); + fprintf(stderr,"matched opret! funcid.%c ht.%d unlock.%d %s\n",funcid,height,unlockht,coinaddr); + return(strcmp(destaddr,coinaddr)); + } + return(0); +} + bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { std::vector vopret; CTransaction vinTx; uint256 hashBlock; int32_t numvins,numvouts,i,ht,unlockht,vht,vunlockht; uint8_t funcid,vfuncid,*script; CPubKey pk,vpk; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d35683c93..67900ea27 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -557,9 +557,9 @@ uint64_t komodo_seed(int32_t height) return(seed); } -uint32_t komodo_txtime(uint64_t *valuep,uint256 hash, int32_t n, char *destaddr) +uint32_t komodo_txtime(CScript &opret,uint64_t *valuep,uint256 hash, int32_t n, char *destaddr) { - CTxDestination address; CTransaction tx; uint256 hashBlock; + CTxDestination address; CTransaction tx; uint256 hashBlock; int32_t numvouts; *valuep = 0; if (!GetTransaction(hash, tx, #ifndef KOMODO_ZCASH @@ -570,10 +570,12 @@ uint32_t komodo_txtime(uint64_t *valuep,uint256 hash, int32_t n, char *destaddr) //fprintf(stderr,"ERROR: %s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); return(0); } + numvouts = tx.vout.size(); //fprintf(stderr,"%s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); - if ( n < tx.vout.size() ) + if ( n < numvouts ) { *valuep = tx.vout[n].nValue; + opret = tx.vout[numvouts-1].scriptPubKey; if (ExtractDestination(tx.vout[n].scriptPubKey, address)) strcpy(destaddr,CBitcoinAddress(address).ToString().c_str()); } @@ -614,12 +616,12 @@ uint32_t komodo_txtime2(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr) int32_t komodo_WhoStaked(CBlock *pblock, CTxDestination &addressout) { - int32_t n,vout; uint32_t txtime; uint64_t value; char voutaddr[64],destaddr[64]; CTxDestination voutaddress; uint256 txid; + int32_t n,vout; uint32_t txtime; uint64_t value; char voutaddr[64],destaddr[64]; CTxDestination voutaddress; uint256 txid; CScript opret; if ( (n= pblock->vtx.size()) > 1 && pblock->vtx[n-1].vin.size() == 1 && pblock->vtx[n-1].vout.size() == 1 ) { txid = pblock->vtx[n-1].vin[0].prevout.hash; vout = pblock->vtx[n-1].vin[0].prevout.n; - txtime = komodo_txtime(&value,txid,vout,destaddr); + txtime = komodo_txtime(opret,&value,txid,vout,destaddr); if ( ExtractDestination(pblock->vtx[n-1].vout[0].scriptPubKey,voutaddress) ) { strcpy(voutaddr,CBitcoinAddress(voutaddress).ToString().c_str()); @@ -634,28 +636,33 @@ int32_t komodo_WhoStaked(CBlock *pblock, CTxDestination &addressout) return(0); } -int32_t komodo_isPoS(CBlock *pblock) +bool MarmaraPoScheck(char *destaddr,CScript opret,CScript scriptPubKey); + +int32_t komodo_isPoS(CBlock *pblock,int32_t height) { - int32_t n,vout; uint32_t txtime; uint64_t value; char voutaddr[64],destaddr[64]; CTxDestination voutaddress; uint256 txid; + int32_t n,vout,numvouts; uint32_t txtime; uint64_t value; char voutaddr[64],destaddr[64]; CTxDestination voutaddress; uint256 txid; CScript opret; if ( ASSETCHAINS_STAKED != 0 ) { if ( (n= pblock->vtx.size()) > 1 && pblock->vtx[n-1].vin.size() == 1 && pblock->vtx[n-1].vout.size() == 1 ) { txid = pblock->vtx[n-1].vin[0].prevout.hash; vout = pblock->vtx[n-1].vin[0].prevout.n; - txtime = komodo_txtime(&value,txid,vout,destaddr); + txtime = komodo_txtime(opret,&value,txid,vout,destaddr); if ( ExtractDestination(pblock->vtx[n-1].vout[0].scriptPubKey,voutaddress) ) { strcpy(voutaddr,CBitcoinAddress(voutaddress).ToString().c_str()); - if ( ASSETCHAINS_MARMARA != 0 ) + if ( pblock->vtx[n-1].vout[0].nValue == value && strcmp(destaddr,voutaddr) == 0 ) { - fprintf(stderr,"validate proper %s %s signature and unlockht preservation\n",voutaddr,destaddr); - // need to verify it was signed by the non-Marmarapk of the 1of2 - } - if ( strcmp(destaddr,voutaddr) == 0 && pblock->vtx[n-1].vout[0].nValue == value ) - { - //fprintf(stderr,"is PoS block!\n"); - return(1); + if ( ASSETCHAINS_MARMARA == 0 ) + return(1); + else + { + if ( pblock->vtx[n-1].vout[0].scriptPubKey.IsPayToCryptoCondition() != 0 && (numvouts= pblock->vtx[n-1].vout.size()) > 1 ) + { +fprintf(stderr,"validate proper %s %s signature and unlockht preservation\n",voutaddr,destaddr); + return(MarmaraPoScheck(destaddr,opret,pblock->vtx[n-1].vout[numvouts-1].scriptPubKey)); + } + } } } } @@ -1195,7 +1202,7 @@ uint32_t komodo_segid32(char *coinaddr) int8_t komodo_segid(int32_t nocache,int32_t height) { - CTxDestination voutaddress; CBlock block; CBlockIndex *pindex; uint64_t value; uint32_t txtime; char voutaddr[64],destaddr[64]; int32_t txn_count,vout; uint256 txid; int8_t segid = -1; + CTxDestination voutaddress; CBlock block; CBlockIndex *pindex; uint64_t value; uint32_t txtime; char voutaddr[64],destaddr[64]; int32_t txn_count,vout; uint256 txid; CScript opret; int8_t segid = -1; if ( height > 0 && (pindex= komodo_chainactive(height)) != 0 ) { if ( nocache == 0 && pindex->segid >= -1 ) @@ -1207,7 +1214,7 @@ int8_t komodo_segid(int32_t nocache,int32_t height) { txid = block.vtx[txn_count-1].vin[0].prevout.hash; vout = block.vtx[txn_count-1].vin[0].prevout.n; - txtime = komodo_txtime(&value,txid,vout,destaddr); + txtime = komodo_txtime(opret,&value,txid,vout,destaddr); if ( ExtractDestination(block.vtx[txn_count-1].vout[0].scriptPubKey,voutaddress) ) { strcpy(voutaddr,CBitcoinAddress(voutaddress).ToString().c_str()); @@ -1464,7 +1471,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ vout = pblock->vtx[txn_count-1].vin[0].prevout.n; if ( prevtime != 0 ) { - if ( komodo_isPoS(pblock) != 0 ) + if ( komodo_isPoS(pblock,height) != 0 ) { eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime+27,(char *)""); } @@ -1500,7 +1507,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ } if ( slowflag == 0 && isPoS == 0 ) // maybe previous block is not seen yet, do the best approx { - if ( komodo_isPoS(pblock) != 0 ) + if ( komodo_isPoS(pblock,height) != 0 ) isPoS = 1; } if ( slowflag != 0 && isPoS != 0 ) diff --git a/src/main.cpp b/src/main.cpp index 21b6b4eb0..614f13d44 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3806,7 +3806,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { CValidationState stateDummy; // don't keep staking or invalid transactions - if (tx.IsCoinBase() || ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED && komodo_isPoS((CBlock *)&block) != 0)) || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL)) + if (tx.IsCoinBase() || ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED && komodo_isPoS((CBlock *)&block,pindexDelete->GetHeight()) != 0)) || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL)) { mempool.remove(tx, removed, true); } @@ -3837,7 +3837,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { { CTransaction &tx = block.vtx[i]; //if ((i == (block.vtx.size() - 1)) && ((ASSETCHAINS_LWMAPOS && block.IsVerusPOSBlock()) || (ASSETCHAINS_STAKED != 0 && (komodo_isPoS((CBlock *)&block) != 0)))) - if ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED != 0 && (komodo_isPoS((CBlock *)&block) != 0))) + if ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED != 0 && (komodo_isPoS((CBlock *)&block,pindexDelete->GetHeight()) != 0))) { EraseFromWallets(tx.GetHash()); } @@ -4734,7 +4734,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C CValidationState state; CTransaction Tx; const CTransaction &tx = (CTransaction)block.vtx[i]; - if (tx.IsCoinBase() || !tx.vjoinsplit.empty() || !tx.vShieldedSpend.empty() || ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED && komodo_isPoS((CBlock *)&block) != 0))) + if (tx.IsCoinBase() || !tx.vjoinsplit.empty() || !tx.vShieldedSpend.empty() || ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED && komodo_isPoS((CBlock *)&block,height) != 0))) continue; Tx = tx; if ( myAddtomempool(Tx, &state, true) == false ) // happens with out of order tx in block on resync From 2aa12aad792dde6868db3fa4b46f3c4357ef2580 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 20 Jan 2019 21:59:03 -1100 Subject: [PATCH 568/643] Marmarapk --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 98e805c38..ca216069a 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -257,7 +257,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) bool MarmaraPoScheck(char *destaddr,CScript opret,CScript scriptPubKey) { - CPubKey pk; int32_t height,unlockht; uint8_t funcid; char coinaddr[64]; struct CCcontract_info *cp,C; + CPubKey Marmarapk,pk; int32_t height,unlockht; uint8_t funcid; char coinaddr[64]; struct CCcontract_info *cp,C; if ( opret == scriptPubKey ) { cp = CCinit(&C,EVAL_MARMARA); From 9ff5e8de93d73f99f1d3380492412c122e9b4861 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 20 Jan 2019 22:03:15 -1100 Subject: [PATCH 569/643] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 67900ea27..877a192f3 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -661,7 +661,7 @@ int32_t komodo_isPoS(CBlock *pblock,int32_t height) { fprintf(stderr,"validate proper %s %s signature and unlockht preservation\n",voutaddr,destaddr); return(MarmaraPoScheck(destaddr,opret,pblock->vtx[n-1].vout[numvouts-1].scriptPubKey)); - } + } else fprintf(stderr,"reject ht.%d PoS block\n",height); } } } From 00151d02b037aaf9f6202fd7b5c90cf8c04b722e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 20 Jan 2019 23:08:38 -1100 Subject: [PATCH 570/643] Allow old style --- src/komodo_bitcoind.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 877a192f3..77dfbf6ad 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -661,7 +661,12 @@ int32_t komodo_isPoS(CBlock *pblock,int32_t height) { fprintf(stderr,"validate proper %s %s signature and unlockht preservation\n",voutaddr,destaddr); return(MarmaraPoScheck(destaddr,opret,pblock->vtx[n-1].vout[numvouts-1].scriptPubKey)); - } else fprintf(stderr,"reject ht.%d PoS block\n",height); + } + else + { + fprintf(stderr,"reject ht.%d PoS block\n",height); + return(1); // allow until MTST3 + } } } } @@ -2174,7 +2179,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { const CScript &scriptPubKey = tx.vout[vout].scriptPubKey; array = komodo_addutxo(array,&numkp,&maxkp,(uint32_t)pindex->nTime,(uint64_t)nValue,txid,vout,coinaddr,hashbuf,(CScript)scriptPubKey); - fprintf(stderr,"addutxo %.8f numkp.%d vs max.%d\n",(double)nValue/COIN,numkp,maxkp); + //fprintf(stderr,"addutxo %.8f numkp.%d vs max.%d\n",(double)nValue/COIN,numkp,maxkp); } } } From 0a84522ad08ffdd67f44ce5b5d39dd42d1a26d3a Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Mon, 21 Jan 2019 11:08:59 +0100 Subject: [PATCH 571/643] Channel close fix. Adding CCError print to all RPCs. --- src/cc/channels.cpp | 92 +++++++++++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 32 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index a375edbda..6cd379eed 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -502,6 +502,8 @@ std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64 if (tokenid!=zeroid && tokens>funds) mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS,tokens-funds,mypk)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('O',tokenid,zeroid,mypk,destpub,numpayments,payment,hashchain))); } + CCerror = strprintf("error adding funds"); + fprintf(stderr,"%s\n",CCerror.c_str()); return(""); } @@ -520,25 +522,29 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 mypk = pubkey2pk(Mypubkey()); if (GetTransaction(opentxid,channelOpenTx,hashblock,false) == 0) { - fprintf(stderr, "invalid channel open txid\n"); - return (""); + CCerror = strprintf("invalid channel open txid"); + fprintf(stderr,"%s\n",CCerror.c_str()); + return(""); } if ((numvouts=channelOpenTx.vout.size()) > 0 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, tokenid, txid, srcpub, destpub, totalnumpayments, payment, hashchain)=='O') { if (mypk != srcpub && mypk != destpub) { - fprintf(stderr,"this is not our channel\n"); + CCerror = strprintf("this is not our channel"); + fprintf(stderr,"%s\n",CCerror.c_str()); return(""); } else if (amount % payment != 0 || amount 0) @@ -552,11 +558,13 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 { if (numpayments > prevdepth) { - fprintf(stderr,"not enough funds in channel for that amount\n"); + CCerror = strprintf("not enough funds in channel for that amount"); + fprintf(stderr,"%s\n",CCerror.c_str()); return (""); } else if (numpayments == 0) { - fprintf(stderr,"invalid amount\n"); + CCerror = strprintf("invalid amount"); + fprintf(stderr,"%s\n",CCerror.c_str()); return (""); } if (secret!=zeroid) @@ -570,7 +578,8 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 endiancpy((uint8_t * ) & gensecret, hashdest, 32); if (gensecret!=hashchain) { - fprintf(stderr,"invalid secret supplied\n"); + CCerror = strprintf("invalid secret supplied"); + fprintf(stderr,"%s\n",CCerror.c_str()); return(""); } } @@ -592,7 +601,8 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 } else { - fprintf(stderr,"invalid previous tx\n"); + CCerror = strprintf("invalid previous tx"); + fprintf(stderr,"%s\n",CCerror.c_str()); return(""); } if (tokenid!=zeroid) mtx.vout.push_back(MakeTokensCC1of2vout(EVAL_CHANNELS, change, srcpub, destpub)); @@ -605,11 +615,13 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 } else { - fprintf(stderr,"error adding CC inputs\n"); + CCerror = strprintf("error adding CC inputs"); + fprintf(stderr,"%s\n",CCerror.c_str()); return(""); } } - fprintf(stderr,"error adding normal inputs\n"); + CCerror = strprintf("error adding normal inputs"); + fprintf(stderr,"%s\n",CCerror.c_str()); return(""); } @@ -629,36 +641,41 @@ std::string ChannelClose(uint64_t txfee,uint256 opentxid) mypk = pubkey2pk(Mypubkey()); if (GetTransaction(opentxid,channelOpenTx,hashblock,false) == 0) { - fprintf(stderr, "invalid channel open txid\n"); + CCerror = strprintf("invalid channel open txid"); + fprintf(stderr,"%s\n",CCerror.c_str()); return (""); } if ((numvouts=channelOpenTx.vout.size()) < 1 || DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,numpayments,payment,hashchain)!='O') { - fprintf(stderr, "invalid channel open tx\n"); + CCerror = strprintf("invalid channel open tx"); + fprintf(stderr,"%s\n",CCerror.c_str()); return (""); } if (mypk != srcpub) { - fprintf(stderr,"cannot close, you are not channel owner\n"); + CCerror = strprintf("cannot close, you are not channel owner"); + fprintf(stderr,"%s\n",CCerror.c_str()); return(""); } if ( AddNormalinputs(mtx,mypk,2*txfee,3) > 0 ) { - if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid,mypk)) !=0 && funds-txfee>0) + if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid,mypk)) !=0 && funds>0) { - if (tokenid!=zeroid) mtx.vout.push_back(MakeTokensCC1of2vout(EVAL_CHANNELS, funds-txfee, mypk, destpub)); - else mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS, funds-txfee, mypk, destpub)); + if (tokenid!=zeroid) mtx.vout.push_back(MakeTokensCC1of2vout(EVAL_CHANNELS, funds, mypk, destpub)); + else mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS, funds, mypk, destpub)); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,destpub)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('C',tokenid,opentxid,mypk,destpub,(funds-txfee)/payment,payment,zeroid))); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('C',tokenid,opentxid,mypk,destpub,funds/payment,payment,zeroid))); } else { - fprintf(stderr,"error adding CC inputs\n"); + CCerror = strprintf("error adding CC inputs"); + fprintf(stderr,"%s\n",CCerror.c_str()); return(""); } } - fprintf(stderr,"error adding normal inputs\n"); + CCerror = strprintf("error adding normal inputs"); + fprintf(stderr,"%s\n",CCerror.c_str()); return(""); } @@ -678,61 +695,72 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) mypk = pubkey2pk(Mypubkey()); if (GetTransaction(closetxid,channelCloseTx,hashblock,false) == 0) { - fprintf(stderr, "invalid channel close txid\n"); + CCerror = strprintf("invalid channel close txid"); + fprintf(stderr,"%s\n",CCerror.c_str()); return (""); } if ((numvouts=channelCloseTx.vout.size()) < 1 || DecodeChannelsOpRet(channelCloseTx.vout[numvouts-1].scriptPubKey,tokenid,txid,srcpub,destpub,param1,param2,param3)!='C') { - fprintf(stderr, "invalid channel close tx\n"); + CCerror = strprintf("invalid channel close tx"); + fprintf(stderr,"%s\n",CCerror.c_str()); return (""); } if (txid!=opentxid) { - fprintf(stderr, "open and close txid are not from same channel\n"); + CCerror = strprintf("open and close txid are not from same channel"); + fprintf(stderr,"%s\n",CCerror.c_str()); return (""); } if (GetTransaction(opentxid,channelOpenTx,hashblock,false) == 0) { - fprintf(stderr, "invalid channel open txid\n"); + CCerror = strprintf("invalid channel open txid"); + fprintf(stderr,"%s\n",CCerror.c_str()); return (""); } if ((numvouts=channelOpenTx.vout.size()) < 1 || DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey,tokenid,txid,srcpub,destpub,numpayments,payment,hashchain)!='O') { - fprintf(stderr, "invalid channel open tx\n"); + CCerror = strprintf("invalid channel open tx"); + fprintf(stderr,"%s\n",CCerror.c_str()); return (""); } if (mypk != srcpub) { - fprintf(stderr,"cannot refund, you are not the channel owenr\n"); + CCerror = strprintf("cannot refund, you are not the channel owner"); + fprintf(stderr,"%s\n",CCerror.c_str()); return(""); } if ( AddNormalinputs(mtx,mypk,2*txfee,3) > 0 ) { - if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid,mypk)) !=0 && funds-txfee>0) + if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid,mypk)) !=0 && funds>0) { if ((GetTransaction(prevtxid,prevTx,hashblock,false) != 0) && (numvouts=prevTx.vout.size()) > 0 && DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, tokenid, txid, srcpub, destpub, param1, param2, param3) != 0) { mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,destpub)); - if (tokenid!=zeroid) mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS,funds-txfee,mypk)); - else mtx.vout.push_back(CTxOut(funds-txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('R',tokenid,opentxid,mypk,destpub,param1,payment,closetxid))); + if (tokenid!=zeroid) mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS,funds,mypk)); + else mtx.vout.push_back(CTxOut(funds,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('R',tokenid,opentxid,mypk,destpub,funds/payment,payment,closetxid))); } else { - fprintf(stderr,"previous tx is invalid\n"); + CCerror = strprintf("previous tx is invalid"); + fprintf(stderr,"%s\n",CCerror.c_str()); return(""); } } else { - fprintf(stderr,"error adding CC inputs\n"); + CCerror = strprintf("error adding CC inputs"); + fprintf(stderr,"%s\n",CCerror.c_str()); return(""); } } + CCerror = strprintf("error adding normal inputs"); + fprintf(stderr,"%s\n",CCerror.c_str()); return(""); } + UniValue ChannelsList() { UniValue result(UniValue::VOBJ); std::vector > txids; struct CCcontract_info *cp,C; uint256 txid,hashBlock,tmp_txid,param3,tokenid; From 824325ac281b969cf3c70bdd0c719882be57d524 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 20 Jan 2019 23:31:30 -1100 Subject: [PATCH 572/643] MarmaraSignature --- src/cc/marmara.cpp | 29 ++++++++++++++++++++++++++++- src/komodo_bitcoind.h | 23 ++++++++++++----------- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index ca216069a..906d268be 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -500,7 +500,34 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) return(result); } -// jl777: decide on what unlockht settlement change should have +int32_t MarmaraSignature(uint8_t *utxosig,CMutableTransaction &txNew); +{ + uint256 txid,hashBlock; uint8_t *ptr; int32_t i,siglen,vout,numvouts; CTransaction tx; std::string rawtx; CPubKey mypk; std::vector pubkeys; struct CCcontract_info *cp,C; uint64_t txfee + txfee = 10000; + vout = txNew.vin[0].prevout.n; + if ( GetTransaction(txNew.vin[0].prevout.hash,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 1 && vout < numvouts ) + { + cp = CCinit(&C,EVAL_MARMARA); + mypk = pubkey2pk(Mypubkey()); + mtx.vout.resize(2); + mtx.vout[1].scriptPubKey = tx.vout[numvouts - 1].scriptPubKey; + mtx.vout[1].nValue = 0; + pubkeys.push_back(mypk); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,tx.vout[numvouts - 1].scriptPubKey,pubkeys); + if ( rawtx.size() > 0 ) + { + siglen = mtx.vin[0].scriptSig.size(); + ptr = mtx.vin[0].scriptSig.data(); + for (i=0; i from utxo making change UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) { diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 77dfbf6ad..383f4bf40 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2081,6 +2081,8 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod return(0); } +int32_t MarmaraSignature(uint8_t *utxosig,CMutableTransaction &txNew); + int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { static struct komodo_staking *array; static int32_t numkp,maxkp; static uint32_t lasttime; @@ -2264,22 +2266,21 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt if ( ASSETCHAINS_MARMARA == 0 ) { signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, *utxovaluep, SIGHASH_ALL), best_scriptPubKey, sigdata, consensusBranchId); - } - else - { - fprintf(stderr,"add opreturn and CCFinalizetx\n"); - // add opreturn - // signSuccess = CCFinalizetx(...) - } - if (!signSuccess) - fprintf(stderr,"failed to create signature\n"); - else - { UpdateTransaction(txNew,0,sigdata); ptr = (uint8_t *)&sigdata.scriptSig[0]; siglen = sigdata.scriptSig.size(); for (i=0; i Date: Sun, 20 Jan 2019 23:32:13 -1100 Subject: [PATCH 573/643] -; --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 906d268be..30e4add97 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -500,7 +500,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) return(result); } -int32_t MarmaraSignature(uint8_t *utxosig,CMutableTransaction &txNew); +int32_t MarmaraSignature(uint8_t *utxosig,CMutableTransaction &txNew) { uint256 txid,hashBlock; uint8_t *ptr; int32_t i,siglen,vout,numvouts; CTransaction tx; std::string rawtx; CPubKey mypk; std::vector pubkeys; struct CCcontract_info *cp,C; uint64_t txfee txfee = 10000; From 493b808298267b6be6b8f8aa89e88fb9d122222c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 20 Jan 2019 23:33:00 -1100 Subject: [PATCH 574/643] syntax --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 30e4add97..f8934e406 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -500,9 +500,9 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) return(result); } -int32_t MarmaraSignature(uint8_t *utxosig,CMutableTransaction &txNew) +int32_t MarmaraSignature(uint8_t *utxosig,CMutableTransaction &mtx) { - uint256 txid,hashBlock; uint8_t *ptr; int32_t i,siglen,vout,numvouts; CTransaction tx; std::string rawtx; CPubKey mypk; std::vector pubkeys; struct CCcontract_info *cp,C; uint64_t txfee + uint256 txid,hashBlock; uint8_t *ptr; int32_t i,siglen,vout,numvouts; CTransaction tx; std::string rawtx; CPubKey mypk; std::vector pubkeys; struct CCcontract_info *cp,C; uint64_t txfee; txfee = 10000; vout = txNew.vin[0].prevout.n; if ( GetTransaction(txNew.vin[0].prevout.hash,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 1 && vout < numvouts ) From 84b6f664cbd11a904767629a27b18581f0a0eb55 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 20 Jan 2019 23:34:03 -1100 Subject: [PATCH 575/643] Test --- src/cc/marmara.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index f8934e406..872f3d69f 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -504,8 +504,8 @@ int32_t MarmaraSignature(uint8_t *utxosig,CMutableTransaction &mtx) { uint256 txid,hashBlock; uint8_t *ptr; int32_t i,siglen,vout,numvouts; CTransaction tx; std::string rawtx; CPubKey mypk; std::vector pubkeys; struct CCcontract_info *cp,C; uint64_t txfee; txfee = 10000; - vout = txNew.vin[0].prevout.n; - if ( GetTransaction(txNew.vin[0].prevout.hash,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 1 && vout < numvouts ) + vout = mtx.vin[0].prevout.n; + if ( GetTransaction(mtx.vin[0].prevout.hash,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 1 && vout < numvouts ) { cp = CCinit(&C,EVAL_MARMARA); mypk = pubkey2pk(Mypubkey()); @@ -517,7 +517,7 @@ int32_t MarmaraSignature(uint8_t *utxosig,CMutableTransaction &mtx) if ( rawtx.size() > 0 ) { siglen = mtx.vin[0].scriptSig.size(); - ptr = mtx.vin[0].scriptSig.data(); + ptr = mtx.vin[0].scriptSig.ptr(); for (i=0; i Date: Sun, 20 Jan 2019 23:35:30 -1100 Subject: [PATCH 576/643] Print --- src/cc/marmara.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 872f3d69f..f3e715796 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -517,10 +517,13 @@ int32_t MarmaraSignature(uint8_t *utxosig,CMutableTransaction &mtx) if ( rawtx.size() > 0 ) { siglen = mtx.vin[0].scriptSig.size(); - ptr = mtx.vin[0].scriptSig.ptr(); + ptr = &(uint8_t *)&mtx.vin[0].scriptSig; for (i=0; i Date: Sun, 20 Jan 2019 23:37:07 -1100 Subject: [PATCH 577/643] Begin --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index f3e715796..9d1a3fd9a 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -517,7 +517,7 @@ int32_t MarmaraSignature(uint8_t *utxosig,CMutableTransaction &mtx) if ( rawtx.size() > 0 ) { siglen = mtx.vin[0].scriptSig.size(); - ptr = &(uint8_t *)&mtx.vin[0].scriptSig; + ptr = mtx.vin[0].scriptSig.begin(); for (i=0; i Date: Sun, 20 Jan 2019 23:41:03 -1100 Subject: [PATCH 578/643] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 9d1a3fd9a..d743746b2 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -517,7 +517,7 @@ int32_t MarmaraSignature(uint8_t *utxosig,CMutableTransaction &mtx) if ( rawtx.size() > 0 ) { siglen = mtx.vin[0].scriptSig.size(); - ptr = mtx.vin[0].scriptSig.begin(); + ptr = &mtx.vin[0].scriptSig[0]; for (i=0; i Date: Sun, 20 Jan 2019 23:44:24 -1100 Subject: [PATCH 579/643] Bigger utxosig --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index c71bc2461..f8fb8ba5f 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -487,7 +487,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 { LEAVE_CRITICAL_SECTION(cs_main); LEAVE_CRITICAL_SECTION(mempool.cs); - uint64_t txfees,utxovalue; uint32_t txtime; uint256 utxotxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[128],*ptr; + uint64_t txfees,utxovalue; uint32_t txtime; uint256 utxotxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[512],*ptr; CMutableTransaction txStaked = CreateNewContextualCMutableTransaction(Params().GetConsensus(), stakeHeight); if (ASSETCHAINS_LWMAPOS != 0) From b1f30fb7def9337d05a929efa63d7d9ed079d187 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 20 Jan 2019 23:46:25 -1100 Subject: [PATCH 580/643] signSuccess --- src/cc/marmara.cpp | 4 ++-- src/komodo_bitcoind.h | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index d743746b2..97febf8e5 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -521,9 +521,9 @@ int32_t MarmaraSignature(uint8_t *utxosig,CMutableTransaction &mtx) for (i=0; i 0 ) + signSuccess = true; + else signSuccess = false; } if (!signSuccess) fprintf(stderr,"failed to create signature\n"); From 6b3ce154c037e668236ef1d9efedde60396c5c43 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 20 Jan 2019 23:47:14 -1100 Subject: [PATCH 581/643] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9a17a71a2..cf2ae585f 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2275,7 +2275,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt else { siglen = MarmaraSignature(utxosig,txNew); - if ( signlen > 0 ) + if ( siglen > 0 ) signSuccess = true; else signSuccess = false; } From fe139f33637747c501fd7cd869db385f9359f0c6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 20 Jan 2019 23:50:32 -1100 Subject: [PATCH 582/643] +print --- src/cc/marmara.cpp | 2 +- src/komodo_bitcoind.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 97febf8e5..7fefb9eb6 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -523,7 +523,7 @@ int32_t MarmaraSignature(uint8_t *utxosig,CMutableTransaction &mtx) utxosig[i] = ptr[i]; //fprintf(stderr,"%02x",ptr[i]); } - //fprintf(stderr," got signed rawtx.%s siglen.%d\n",rawtx.c_str(),siglen); + fprintf(stderr," got signed rawtx.%s siglen.%d\n",rawtx.c_str(),siglen); return(siglen); } } diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index cf2ae585f..1d3926139 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -651,6 +651,7 @@ int32_t komodo_isPoS(CBlock *pblock,int32_t height) if ( ExtractDestination(pblock->vtx[n-1].vout[0].scriptPubKey,voutaddress) ) { strcpy(voutaddr,CBitcoinAddress(voutaddress).ToString().c_str()); + fprintf(stderr,"voutaddr.%s vs destaddr.%s\n",voutaddr,destaddr); if ( pblock->vtx[n-1].vout[0].nValue == value && strcmp(destaddr,voutaddr) == 0 ) { if ( ASSETCHAINS_MARMARA == 0 ) From f8ca9c22b709c9eb64205665eb54a6aa3080e458 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 20 Jan 2019 23:54:16 -1100 Subject: [PATCH 583/643] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1d3926139..df1a99a5d 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -643,7 +643,7 @@ int32_t komodo_isPoS(CBlock *pblock,int32_t height) int32_t n,vout,numvouts; uint32_t txtime; uint64_t value; char voutaddr[64],destaddr[64]; CTxDestination voutaddress; uint256 txid; CScript opret; if ( ASSETCHAINS_STAKED != 0 ) { - if ( (n= pblock->vtx.size()) > 1 && pblock->vtx[n-1].vin.size() == 1 && pblock->vtx[n-1].vout.size() == 1 ) + if ( (n= pblock->vtx.size()) > 1 && pblock->vtx[n-1].vin.size() == 1 && pblock->vtx[n-1].vout.size() == 1+(ASSETCHAINS_MARMARA!=0) ) { txid = pblock->vtx[n-1].vin[0].prevout.hash; vout = pblock->vtx[n-1].vin[0].prevout.n; From a34fc260986882b86830afd2919c705a68f7e2d1 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Mon, 21 Jan 2019 11:57:52 +0100 Subject: [PATCH 584/643] Fix canceling partially filled orders by anyone. (#11) * Fix * Fix --- src/cc/CCassetstx.cpp | 46 +++++++++++++++++++++---------------------- src/cc/CCutils.cpp | 1 - src/cc/assets.cpp | 15 +++++++++----- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 968775d38..9d83beb2c 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -477,14 +477,10 @@ std::string CreateSwap(int64_t txfee,int64_t askamount,uint256 assetid,uint256 a std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction vintx; - uint64_t mask; - uint256 hashBlock; - int64_t bidamount; - CPubKey mypk; - struct CCcontract_info *cpAssets, C; - - uint8_t dummyEvalCode; uint256 dummyAssetid, dummyAssetid2; int64_t dummyPrice; std::vector dummyOrigpubkey; + CTransaction vintx; uint64_t mask; + uint256 hashBlock; int64_t bidamount; + CPubKey mypk; struct CCcontract_info *cpAssets, C; + uint8_t funcid,dummyEvalCode; uint256 dummyAssetid, dummyAssetid2; int64_t dummyPrice; std::vector dummyOrigpubkey; cpAssets = CCinit(&C, EVAL_ASSETS); @@ -501,9 +497,12 @@ std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid) bidamount = vintx.vout[0].nValue; mtx.vin.push_back(CTxIn(bidtxid, 0, CScript())); // coins in Assets - if( DecodeAssetTokenOpRet(vintx.vout[vintx.vout.size() - 1].scriptPubKey, dummyEvalCode, dummyAssetid, dummyAssetid2, dummyPrice, dummyOrigpubkey) == 'b') - mtx.vin.push_back(CTxIn(bidtxid, 1, CScript())); // spend marker if funcid='b' (not 'B') - // TODO: spend it also in FillBuyOffer? + if((funcid=DecodeAssetTokenOpRet(vintx.vout[vintx.vout.size() - 1].scriptPubKey, dummyEvalCode, dummyAssetid, dummyAssetid2, dummyPrice, dummyOrigpubkey))!=0) + { + + if (funcid == 's') mtx.vin.push_back(CTxIn(bidtxid, 1, CScript())); // spend marker if funcid='b' + else if (funcid=='S') mtx.vin.push_back(CTxIn(bidtxid, 3, CScript())); // spend marker if funcid='B' + } mtx.vout.push_back(CTxOut(bidamount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); @@ -523,12 +522,9 @@ std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CTransaction vintx; uint64_t mask; - uint256 hashBlock; - int64_t askamount; - CPubKey mypk; - struct CCcontract_info *cpTokens, *cpAssets, tokensC, assetsC; - - uint8_t dummyEvalCode; uint256 dummyAssetid, dummyAssetid2; int64_t dummyPrice; std::vector dummyOrigpubkey; + uint256 hashBlock; int64_t askamount; + CPubKey mypk; struct CCcontract_info *cpTokens, *cpAssets, tokensC, assetsC; + uint8_t funcid,dummyEvalCode; uint256 dummyAssetid, dummyAssetid2; int64_t dummyPrice; std::vector dummyOrigpubkey; cpAssets = CCinit(&assetsC, EVAL_ASSETS); @@ -545,9 +541,11 @@ std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) askamount = vintx.vout[0].nValue; mtx.vin.push_back(CTxIn(asktxid, 0, CScript())); - if (DecodeAssetTokenOpRet(vintx.vout[vintx.vout.size() - 1].scriptPubKey, dummyEvalCode, dummyAssetid, dummyAssetid2, dummyPrice, dummyOrigpubkey) == 's') - mtx.vin.push_back(CTxIn(asktxid, 1, CScript())); // marker if funcid='s' (not 'S') - // TODO: spend it also in FillSell? + if ((funcid=DecodeAssetTokenOpRet(vintx.vout[vintx.vout.size() - 1].scriptPubKey, dummyEvalCode, dummyAssetid, dummyAssetid2, dummyPrice, dummyOrigpubkey))!=0) + { + if (funcid == 's') mtx.vin.push_back(CTxIn(asktxid, 1, CScript())); // marker if funcid='s' + else if (funcid=='S') mtx.vin.push_back(CTxIn(asktxid, 3, CScript())); // marker if funcid='S' + } mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, askamount, mypk)); // one-eval token vout mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); @@ -607,7 +605,7 @@ std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t f mypk = pubkey2pk(Mypubkey()); - if (AddNormalinputs(mtx, mypk, txfee, 3) > 0) + if (AddNormalinputs(mtx, mypk, 2*txfee, 3) > 0) { mask = ~((1LL << mtx.vin.size()) - 1); if (GetTransaction(bidtxid, vintx, hashBlock, false) != 0) @@ -637,9 +635,10 @@ std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t f mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, bidamount - paid_amount, unspendableAssetsPk)); // vout0 coins remainder mtx.vout.push_back(CTxOut(paid_amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); // vout1 coins to normal mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, fillamount, pubkey2pk(origpubkey))); // vout2 single-eval tokens sent to the buyer + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,txfee,origpubkey)); // vout3 marker to origpubkey if (CCchange != 0) - mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, CCchange, mypk)); // vout3 change in single-eval tokens + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, CCchange, mypk)); // vout4 change in single-eval tokens fprintf(stderr,"FillBuyOffer remaining %llu -> origpubkey\n", (long long)remaining_required); @@ -698,7 +697,7 @@ std::string FillSell(int64_t txfee, uint256 assetid, uint256 assetid2, uint256 a txfee = 10000; mypk = pubkey2pk(Mypubkey()); - if (AddNormalinputs(mtx, mypk, txfee, 3) > 0) + if (AddNormalinputs(mtx, mypk, 2*txfee, 3) > 0) { mask = ~((1LL << mtx.vin.size()) - 1); if (GetTransaction(asktxid, vintx, hashBlock, false) != 0) @@ -747,6 +746,7 @@ std::string FillSell(int64_t txfee, uint256 assetid, uint256 assetid2, uint256 a //std::cerr << "FillSell() paid_value=" << paid_nValue << " origpubkey=" << HexStr(pubkey2pk(origpubkey)) << std::endl; mtx.vout.push_back(CTxOut(paid_nValue, CScript() << origpubkey << OP_CHECKSIG)); //vout.2 coins to tokens seller's normal addr } + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,txfee,origpubkey)); //vout.3 marker to origpubkey // not implemented if (CCchange != 0) { diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index e9c30acc1..07ce11154 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -602,7 +602,6 @@ bool komodo_txnotarizedconfirmed(uint256 txid) CPubKey check_signing_pubkey(CScript scriptSig) { - bool found = false; CPubKey pubkey; diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index 3ccafa34f..2433473b9 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -153,8 +153,9 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti return eval->Invalid("AssetValidate: invalid opreturn payload"); // find dual-eval tokens unspendable addr: - char tokensUnspendableAddr[64]; + char tokensUnspendableAddr[64],origpubkeyCCaddr[64]; GetTokensCCaddress(cpAssets, tokensUnspendableAddr, GetUnspendable(cpAssets, NULL)); + GetCCaddress(cpAssets, origpubkeyCCaddr, origpubkey); // we need this for validating single-eval tokens' vins/vous: struct CCcontract_info *cpTokens, tokensC; @@ -258,7 +259,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti if( (nValue = AssetValidateBuyvin(cpAssets, eval, totalunits, tmporigpubkey, assetsCCaddr, origaddr, tx, assetid)) == 0 ) return(false); - else if( numvouts < 3 ) + else if( numvouts < 4 ) return eval->Invalid("not enough vouts for fillbuy"); else if( tmporigpubkey != origpubkey ) return eval->Invalid("mismatched origpubkeys for fillbuy"); @@ -266,17 +267,19 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti { if( nValue != tx.vout[0].nValue + tx.vout[1].nValue ) return eval->Invalid("locked value doesnt match vout0+1 fillbuy"); - else if( tx.vout[3].scriptPubKey.IsPayToCryptoCondition() != 0 ) + else if( tx.vout[4].scriptPubKey.IsPayToCryptoCondition() != 0 ) { if( ConstrainVout(tx.vout[2], 1, assetsCCaddr, 0) == 0 ) // tokens on user cc addr return eval->Invalid("vout2 doesnt go to origpubkey fillbuy"); - else if ( inputs != tx.vout[2].nValue + tx.vout[3].nValue ) + else if ( inputs != tx.vout[2].nValue + tx.vout[4].nValue ) return eval->Invalid("asset inputs doesnt match vout2+3 fillbuy"); } else if( ConstrainVout(tx.vout[2], 1, assetsCCaddr, inputs) == 0 ) // tokens on user cc addr return eval->Invalid("vout2 doesnt match inputs fillbuy"); else if( ConstrainVout(tx.vout[1],0,0,0) == 0 ) return eval->Invalid("vout1 is CC for fillbuy"); + else if( ConstrainVout(tx.vout[3], 1, origpubkeyCCaddr, 10000) == 0 ) + return eval->Invalid("invalid marker for original pubkey"); else if( ValidateBidRemainder(remaining_price, tx.vout[0].nValue, nValue, tx.vout[1].nValue, tx.vout[2].nValue, totalunits) == false ) return eval->Invalid("mismatched remainder for fillbuy"); else if( remaining_price != 0 ) @@ -345,7 +348,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti if( (assetoshis = AssetValidateSellvin(cpAssets, eval, totalunits, tmporigpubkey, userTokensCCaddr, origaddr, tx, assetid)) == 0 ) return(false); - else if( numvouts < 3 ) + else if( numvouts < 4 ) return eval->Invalid("not enough vouts for fillask"); else if( tmporigpubkey != origpubkey ) return eval->Invalid("mismatched origpubkeys for fillask"); @@ -359,6 +362,8 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti return eval->Invalid("normal vout1 for fillask"); else if( ConstrainVout(tx.vout[2], 0, origaddr, 0) == 0 ) return eval->Invalid("normal vout1 for fillask"); + else if( ConstrainVout(tx.vout[3], 1, origpubkeyCCaddr, 10000) == 0 ) + return eval->Invalid("invalid marker for original pubkey"); else if( remaining_price != 0 ) { //char tokensUnspendableAddr[64]; From 0e7de7412cc16af55cbc33ef5b5d360b853d5479 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 00:00:04 -1100 Subject: [PATCH 585/643] +print --- src/komodo_bitcoind.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index df1a99a5d..195267a78 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -643,7 +643,9 @@ int32_t komodo_isPoS(CBlock *pblock,int32_t height) int32_t n,vout,numvouts; uint32_t txtime; uint64_t value; char voutaddr[64],destaddr[64]; CTxDestination voutaddress; uint256 txid; CScript opret; if ( ASSETCHAINS_STAKED != 0 ) { - if ( (n= pblock->vtx.size()) > 1 && pblock->vtx[n-1].vin.size() == 1 && pblock->vtx[n-1].vout.size() == 1+(ASSETCHAINS_MARMARA!=0) ) + n = pblock->vtx.size(); + fprintf(stderr,"ht.%d check for PoS numtx.%d numvins.%d numvouts.%d\n",height,n,pblock->vtx[n-1].vin.size(),pblock->vtx[n-1].vout.size()); + if ( n > 1 && pblock->vtx[n-1].vin.size() == 1 && pblock->vtx[n-1].vout.size() == 1+(ASSETCHAINS_MARMARA!=0) ) { txid = pblock->vtx[n-1].vin[0].prevout.hash; vout = pblock->vtx[n-1].vin[0].prevout.n; From f4861bdf77e5fd28aa20d9e555f3525cbd5d4e87 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 00:08:07 -1100 Subject: [PATCH 586/643] +print --- src/komodo_bitcoind.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 195267a78..d40baaf00 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1464,12 +1464,13 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ pindex = it != mapBlockIndex.end() ? it->second : NULL; if ( pindex != 0 && pindex->segid >= -1 ) { + fprintf(stderr,"isPoSblock segid.%d\n",pindex->segid); if ( pindex->segid == -1 ) return(0); else return(1); } txn_count = pblock->vtx.size(); - if ( txn_count > 1 && pblock->vtx[txn_count-1].vin.size() == 1 && pblock->vtx[txn_count-1].vout.size() == 1 ) + if ( txn_count > 1 && pblock->vtx[txn_count-1].vin.size() == 1 && pblock->vtx[txn_count-1].vout.size() == 1 + (ASSETCHAINS_MARMARA!=0) ) { it = mapBlockIndex.find(pblock->hashPrevBlock); if ( it != mapBlockIndex.end() && (previndex = it->second) != NULL ) @@ -1784,6 +1785,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); bhash = UintToArith256(hash); possible = komodo_block2pubkey33(pubkey33,pblock); +fprintf(stderr,"checkPoW ht.%d\n",height); if ( height == 0 ) { if ( slowflag != 0 ) @@ -1828,6 +1830,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); } } + fprintf(stderr,"ASSETCHAINS_STAKED.%d ht.%d\n",ASSETCHAINS_STAKED,height); if ( ASSETCHAINS_STAKED != 0 && height >= 2 ) // must PoS or have at least 16x better PoW { if ( (is_PoSblock= komodo_is_PoSblock(slowflag,height,pblock,bnTarget,bhash)) == 0 ) From e8fd52a2b5adf4356056654bfcf1c0d54617f0b1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 00:12:17 -1100 Subject: [PATCH 587/643] Test --- src/komodo_bitcoind.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d40baaf00..5e1ec7f66 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1470,6 +1470,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ else return(1); } txn_count = pblock->vtx.size(); + fprintf(stderr,"checkblock n.%d vins.%d vouts.%d\n",txn_count,pblock->vtx[txn_count-1].vin.size(),pblock->vtx[txn_count-1].vout.size()); if ( txn_count > 1 && pblock->vtx[txn_count-1].vin.size() == 1 && pblock->vtx[txn_count-1].vout.size() == 1 + (ASSETCHAINS_MARMARA!=0) ) { it = mapBlockIndex.find(pblock->hashPrevBlock); From 7cfb6293c6b820426ed7184d4ee12c6cd8152d40 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 00:31:14 -1100 Subject: [PATCH 588/643] komodo_defs a lot more --- src/cc/CCinclude.h | 5 ----- src/chainparams.cpp | 5 ----- src/komodo_bitcoind.h | 2 +- src/komodo_defs.h | 40 ++++++++++++++++++++++++++++++++++++++++ src/metrics.cpp | 3 +-- src/miner.cpp | 9 --------- src/pow.cpp | 5 ++--- src/primitives/block.cpp | 2 +- src/rpc/mining.cpp | 6 ++---- src/rpc/misc.cpp | 3 ++- src/wallet/rpcwallet.cpp | 3 +-- src/wallet/wallet.cpp | 6 ------ 12 files changed, 50 insertions(+), 39 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 1953fad34..66c001969 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -51,11 +51,6 @@ one other technical note is that komodod has the insight-explorer extensions bui #include "../utlist.h" #include "../uthash.h" -extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE,KOMODO_DEALERNODE; -extern uint32_t ASSETCHAINS_CC; -extern char ASSETCHAINS_SYMBOL[]; -extern std::string CCerror,ASSETCHAINS_CCLIB; -extern uint8_t ASSETCHAINS_CCDISABLES[256]; #define CC_MAXVINS 1024 diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 47f4d48a8..c7232761b 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -92,11 +92,6 @@ static CBlock CreateGenesisBlock(uint32_t nTime, const uint256& nNonce, const st void *chainparams_commandline(void *ptr); #include "komodo_defs.h" -extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; -extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; -extern uint32_t ASSETCHAIN_INIT, ASSETCHAINS_MAGIC; -extern int32_t VERUS_BLOCK_POSUNITS, ASSETCHAINS_LWMAPOS, ASSETCHAINS_SAPLING, ASSETCHAINS_OVERWINTER; -extern uint64_t ASSETCHAINS_SUPPLY, ASSETCHAINS_ALGO, ASSETCHAINS_EQUIHASH, ASSETCHAINS_VERUSHASH; const arith_uint256 maxUint = UintToArith256(uint256S("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 5e1ec7f66..9d0ea3228 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1470,7 +1470,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ else return(1); } txn_count = pblock->vtx.size(); - fprintf(stderr,"checkblock n.%d vins.%d vouts.%d\n",txn_count,pblock->vtx[txn_count-1].vin.size(),pblock->vtx[txn_count-1].vout.size()); + fprintf(stderr,"checkblock n.%d vins.%d vouts.%d %.8f %.8f\n",txn_count,pblock->vtx[txn_count-1].vin.size(),pblock->vtx[txn_count-1].vout.size(),(double)pblock->vtx[txn_count-1].vout[0].nValue/COIN,(doube)pblock->vtx[txn_count-1].vout[1].nValue/COIN); if ( txn_count > 1 && pblock->vtx[txn_count-1].vin.size() == 1 && pblock->vtx[txn_count-1].vout.size() == 1 + (ASSETCHAINS_MARMARA!=0) ) { it = mapBlockIndex.find(pblock->hashPrevBlock); diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 91fcadddb..47916d5c4 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -36,5 +36,45 @@ extern uint8_t ASSETCHAINS_TXPOW,ASSETCHAINS_PUBLIC; int32_t MAX_BLOCK_SIZE(int32_t height); +extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; +extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; +extern uint32_t ASSETCHAIN_INIT, ASSETCHAINS_MAGIC; +extern int32_t VERUS_BLOCK_POSUNITS, ASSETCHAINS_LWMAPOS, ASSETCHAINS_SAPLING, ASSETCHAINS_OVERWINTER; +extern uint64_t ASSETCHAINS_SUPPLY; + +extern uint64_t ASSETCHAINS_TIMELOCKGTE; +extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_VERUSHASH,ASSETCHAINS_EQUIHASH; + +extern int32_t KOMODO_MININGTHREADS,KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE; +extern uint64_t ASSETCHAINS_COMMISSION, ASSETCHAINS_STAKED; +extern bool VERUS_MINTBLOCKS; +extern uint64_t ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_TIMELOCKGTE, ASSETCHAINS_NONCEMASK[]; +extern const char *ASSETCHAINS_ALGORITHMS[]; +extern int32_t VERUS_MIN_STAKEAGE, ASSETCHAINS_ALGO, ASSETCHAINS_EQUIHASH; +extern uint32_t ASSETCHAINS_VERUSHASH, ASSETCHAINS_LASTERA, ASSETCHAINS_LWMAPOS, ASSETCHAINS_NONCESHIFT[], ASSETCHAINS_HASHESPERROUND[]; +extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; +extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY,ASSETCHAINS_SCRIPTPUB; +extern uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_MARMARA; + +extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_EQUIHASH, ASSETCHAINS_STAKED; +extern char ASSETCHAINS_SYMBOL[65]; +extern int32_t ASSETCHAINS_LWMAPOS,VERUS_BLOCK_POSUNITS, VERUS_CONSECUTIVE_POS_THRESHOLD, VERUS_NOPOS_THRESHHOLD; + +extern int32_t ASSETCHAINS_EQUIHASH, ASSETCHAINS_LWMAPOS; + +extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE,KOMODO_DEALERNODE; +extern uint32_t ASSETCHAINS_CC; +extern char ASSETCHAINS_SYMBOL[]; +extern std::string CCerror,ASSETCHAINS_CCLIB; +extern uint8_t ASSETCHAINS_CCDISABLES[256]; + +extern int32_t USE_EXTERNAL_PUBKEY; +extern std::string NOTARY_PUBKEY; +extern int32_t KOMODO_EXCHANGEWALLET; +extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; +extern int32_t VERUS_MIN_STAKEAGE; +extern std::string DONATION_PUBKEY; +extern uint8_t ASSETCHAINS_PRIVATE; +extern int32_t USE_EXTERNAL_PUBKEY; #endif diff --git a/src/metrics.cpp b/src/metrics.cpp index a01d381a1..6b387f7dc 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -39,8 +39,7 @@ #endif #include -extern uint64_t ASSETCHAINS_TIMELOCKGTE; -extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_VERUSHASH; +#include "komodo_defs.h" int64_t komodo_block_unlocktime(uint32_t nHeight); void AtomicTimer::start() diff --git a/src/miner.cpp b/src/miner.cpp index f8fb8ba5f..78eb84e7b 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -132,17 +132,8 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, #include "komodo_defs.h" extern CCriticalSection cs_metrics; -extern int32_t KOMODO_MININGTHREADS,KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE; -extern uint64_t ASSETCHAINS_COMMISSION, ASSETCHAINS_STAKED; -extern bool VERUS_MINTBLOCKS; -extern uint64_t ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_TIMELOCKGTE, ASSETCHAINS_NONCEMASK[]; -extern const char *ASSETCHAINS_ALGORITHMS[]; -extern int32_t VERUS_MIN_STAKEAGE, ASSETCHAINS_ALGO, ASSETCHAINS_EQUIHASH, ASSETCHAINS_VERUSHASH, ASSETCHAINS_LASTERA, ASSETCHAINS_LWMAPOS, ASSETCHAINS_NONCESHIFT[], ASSETCHAINS_HASHESPERROUND[]; -extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; -extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY,ASSETCHAINS_SCRIPTPUB; void vcalc_sha256(char deprecated[(256 >> 3) * 2 + 1],uint8_t hash[256 >> 3],uint8_t *src,int32_t len); -extern uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_MARMARA; uint32_t Mining_start,Mining_height; int32_t My_notaryid = -1; int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp); diff --git a/src/pow.cpp b/src/pow.cpp index b69c4fce6..cc2b0b7c2 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -37,9 +37,8 @@ #endif // ENABLE_RUST uint32_t komodo_chainactive_timestamp(); -extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_EQUIHASH, ASSETCHAINS_STAKED; -extern char ASSETCHAINS_SYMBOL[65]; -extern int32_t ASSETCHAINS_LWMAPOS,VERUS_BLOCK_POSUNITS, VERUS_CONSECUTIVE_POS_THRESHOLD, VERUS_NOPOS_THRESHHOLD; +#include "komodo_defs.h" + unsigned int lwmaGetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params); unsigned int lwmaCalculateNextWorkRequired(const CBlockIndex* pindexLast, const Consensus::Params& params); diff --git a/src/primitives/block.cpp b/src/primitives/block.cpp index 00fc8cee9..bb3314760 100644 --- a/src/primitives/block.cpp +++ b/src/primitives/block.cpp @@ -24,8 +24,8 @@ #include "tinyformat.h" #include "utilstrencodings.h" #include "crypto/common.h" +#include "komodo_defs.h" -extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_VERUSHASH; // default hash algorithm for block uint256 (CBlockHeader::*CBlockHeader::hashFunction)() const = &CBlockHeader::GetSHA256DHash; diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index a0643528d..ff9b1b4c4 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -48,10 +48,8 @@ using namespace std; -extern int32_t ASSETCHAINS_ALGO, ASSETCHAINS_EQUIHASH, ASSETCHAINS_LWMAPOS; -extern uint64_t ASSETCHAINS_STAKED; -extern int32_t KOMODO_MININGTHREADS; -extern bool VERUS_MINTBLOCKS; +#include "komodo_defs.h" + arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc); /** diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 0ebfa7b25..2491055d1 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -77,7 +77,8 @@ int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heig extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; extern uint32_t ASSETCHAINS_CC; extern uint32_t ASSETCHAINS_MAGIC; -extern uint64_t ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED,ASSETCHAINS_SUPPLY,ASSETCHAINS_LASTERA; +extern uint64_t ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED,ASSETCHAINS_SUPPLY; +extern uint32_t ASSETCHAINS_LASTERA; extern int32_t ASSETCHAINS_LWMAPOS,ASSETCHAINS_SAPLING; extern uint64_t ASSETCHAINS_ENDSUBSIDY[],ASSETCHAINS_REWARD[],ASSETCHAINS_HALVING[],ASSETCHAINS_DECAY[]; extern std::string NOTARY_PUBKEY; extern uint8_t NOTARY_PUBKEY33[]; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 174f447f0..3acee9c1f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -57,6 +57,7 @@ #include +#include "komodo_defs.h" using namespace std; @@ -67,8 +68,6 @@ const std::string ADDR_TYPE_SPROUT = "sprout"; const std::string ADDR_TYPE_SAPLING = "sapling"; extern UniValue TxJoinSplitToJSON(const CTransaction& tx); -extern uint8_t ASSETCHAINS_PRIVATE; -extern int32_t USE_EXTERNAL_PUBKEY; uint32_t komodo_segid32(char *coinaddr); int32_t komodo_dpowconfs(int32_t height,int32_t numconfs); int32_t komodo_isnotaryvout(char *coinaddr); // from ac_private chains only diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 0000f8d42..d171812c4 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -59,13 +59,7 @@ bool fSendFreeTransactions = false; bool fPayAtLeastCustomFee = true; #include "komodo_defs.h" -extern int32_t USE_EXTERNAL_PUBKEY; -extern std::string NOTARY_PUBKEY; -extern int32_t KOMODO_EXCHANGEWALLET; -extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; -extern int32_t VERUS_MIN_STAKEAGE; CBlockIndex *komodo_chainactive(int32_t height); -extern std::string DONATION_PUBKEY; /** * Fees smaller than this (in satoshi) are considered zero fee (for transaction creation) From 2cb2b335d7d7826f508ab09991cfc97d0ceeaf60 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 00:34:19 -1100 Subject: [PATCH 589/643] Prune inconsistent refs --- src/komodo_defs.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 47916d5c4..bfb49a973 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -45,22 +45,21 @@ extern uint64_t ASSETCHAINS_SUPPLY; extern uint64_t ASSETCHAINS_TIMELOCKGTE; extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_VERUSHASH,ASSETCHAINS_EQUIHASH; -extern int32_t KOMODO_MININGTHREADS,KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE; +extern int32_t KOMODO_MININGTHREADS,KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE; extern uint64_t ASSETCHAINS_COMMISSION, ASSETCHAINS_STAKED; extern bool VERUS_MINTBLOCKS; extern uint64_t ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_TIMELOCKGTE, ASSETCHAINS_NONCEMASK[]; extern const char *ASSETCHAINS_ALGORITHMS[]; -extern int32_t VERUS_MIN_STAKEAGE, ASSETCHAINS_ALGO, ASSETCHAINS_EQUIHASH; -extern uint32_t ASSETCHAINS_VERUSHASH, ASSETCHAINS_LASTERA, ASSETCHAINS_LWMAPOS, ASSETCHAINS_NONCESHIFT[], ASSETCHAINS_HASHESPERROUND[]; +extern int32_t VERUS_MIN_STAKEAGE, ASSETCHAINS_ALGO; +extern uint32_t ASSETCHAINS_VERUSHASH, ASSETCHAINS_LASTERA, ASSETCHAINS_NONCESHIFT[], ASSETCHAINS_HASHESPERROUND[]; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY,ASSETCHAINS_SCRIPTPUB; extern uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_MARMARA; -extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_EQUIHASH, ASSETCHAINS_STAKED; +extern uint32_t ASSETCHAINS_ALGO; extern char ASSETCHAINS_SYMBOL[65]; -extern int32_t ASSETCHAINS_LWMAPOS,VERUS_BLOCK_POSUNITS, VERUS_CONSECUTIVE_POS_THRESHOLD, VERUS_NOPOS_THRESHHOLD; +extern int32_t VERUS_BLOCK_POSUNITS, VERUS_CONSECUTIVE_POS_THRESHOLD, VERUS_NOPOS_THRESHHOLD; -extern int32_t ASSETCHAINS_EQUIHASH, ASSETCHAINS_LWMAPOS; extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE,KOMODO_DEALERNODE; extern uint32_t ASSETCHAINS_CC; From f22c02d1fddb9fed236c9750379724acc1b482a5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 00:36:06 -1100 Subject: [PATCH 590/643] Test --- src/bitcoind.cpp | 3 ++- src/komodo_defs.h | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 86d3165cf..b2fa534a1 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -94,7 +94,8 @@ void WaitForShutdown(boost::thread_group* threadGroup) // // Start // -extern int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,ASSETCHAIN_INIT; +extern int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY; +extern uint32_t ASSETCHAIN_INIT; extern std::string NOTARY_PUBKEY; int32_t komodo_is_issuer(); void komodo_passport_iteration(); diff --git a/src/komodo_defs.h b/src/komodo_defs.h index bfb49a973..b22b6279e 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -50,13 +50,12 @@ extern uint64_t ASSETCHAINS_COMMISSION, ASSETCHAINS_STAKED; extern bool VERUS_MINTBLOCKS; extern uint64_t ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_TIMELOCKGTE, ASSETCHAINS_NONCEMASK[]; extern const char *ASSETCHAINS_ALGORITHMS[]; -extern int32_t VERUS_MIN_STAKEAGE, ASSETCHAINS_ALGO; +extern int32_t VERUS_MIN_STAKEAGE; extern uint32_t ASSETCHAINS_VERUSHASH, ASSETCHAINS_LASTERA, ASSETCHAINS_NONCESHIFT[], ASSETCHAINS_HASHESPERROUND[]; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY,ASSETCHAINS_SCRIPTPUB; extern uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_MARMARA; -extern uint32_t ASSETCHAINS_ALGO; extern char ASSETCHAINS_SYMBOL[65]; extern int32_t VERUS_BLOCK_POSUNITS, VERUS_CONSECUTIVE_POS_THRESHOLD, VERUS_NOPOS_THRESHHOLD; From 51a6360f57b8a33e58284d319f6e24ef1c8c4df8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 00:41:59 -1100 Subject: [PATCH 591/643] Fix --- src/komodo_bitcoind.h | 6 +++--- src/komodo_defs.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9d0ea3228..cd12bb255 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -644,7 +644,7 @@ int32_t komodo_isPoS(CBlock *pblock,int32_t height) if ( ASSETCHAINS_STAKED != 0 ) { n = pblock->vtx.size(); - fprintf(stderr,"ht.%d check for PoS numtx.%d numvins.%d numvouts.%d\n",height,n,pblock->vtx[n-1].vin.size(),pblock->vtx[n-1].vout.size()); + fprintf(stderr,"ht.%d check for PoS numtx.%d numvins.%d numvouts.%d\n",height,n,(int32_t)pblock->vtx[n-1].vin.size(),(int32_t)pblock->vtx[n-1].vout.size()); if ( n > 1 && pblock->vtx[n-1].vin.size() == 1 && pblock->vtx[n-1].vout.size() == 1+(ASSETCHAINS_MARMARA!=0) ) { txid = pblock->vtx[n-1].vin[0].prevout.hash; @@ -1470,7 +1470,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ else return(1); } txn_count = pblock->vtx.size(); - fprintf(stderr,"checkblock n.%d vins.%d vouts.%d %.8f %.8f\n",txn_count,pblock->vtx[txn_count-1].vin.size(),pblock->vtx[txn_count-1].vout.size(),(double)pblock->vtx[txn_count-1].vout[0].nValue/COIN,(doube)pblock->vtx[txn_count-1].vout[1].nValue/COIN); + fprintf(stderr,"checkblock n.%d vins.%d vouts.%d %.8f %.8f\n",txn_count,pblock->vtx[txn_count-1].vin.size(),pblock->vtx[txn_count-1].vout.size(),(double)pblock->vtx[txn_count-1].vout[0].nValue/COIN,(double)pblock->vtx[txn_count-1].vout[1].nValue/COIN); if ( txn_count > 1 && pblock->vtx[txn_count-1].vin.size() == 1 && pblock->vtx[txn_count-1].vout.size() == 1 + (ASSETCHAINS_MARMARA!=0) ) { it = mapBlockIndex.find(pblock->hashPrevBlock); @@ -1831,7 +1831,7 @@ fprintf(stderr,"checkPoW ht.%d\n",height); return(-1); } } - fprintf(stderr,"ASSETCHAINS_STAKED.%d ht.%d\n",ASSETCHAINS_STAKED,height); + fprintf(stderr,"ASSETCHAINS_STAKED.%d ht.%d\n",(int32_t)ASSETCHAINS_STAKED,height); if ( ASSETCHAINS_STAKED != 0 && height >= 2 ) // must PoS or have at least 16x better PoW { if ( (is_PoSblock= komodo_is_PoSblock(slowflag,height,pblock,bnTarget,bhash)) == 0 ) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index b22b6279e..0ea97d6db 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -43,9 +43,9 @@ extern int32_t VERUS_BLOCK_POSUNITS, ASSETCHAINS_LWMAPOS, ASSETCHAINS_SAPLING, A extern uint64_t ASSETCHAINS_SUPPLY; extern uint64_t ASSETCHAINS_TIMELOCKGTE; -extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_VERUSHASH,ASSETCHAINS_EQUIHASH; +extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_VERUSHASH,ASSETCHAINS_EQUIHASH,KOMODO_INITDONE; -extern int32_t KOMODO_MININGTHREADS,KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE; +extern int32_t KOMODO_MININGTHREADS,KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,KOMODO_ON_DEMAND,KOMODO_PASSPORT_INITDONE; extern uint64_t ASSETCHAINS_COMMISSION, ASSETCHAINS_STAKED; extern bool VERUS_MINTBLOCKS; extern uint64_t ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_TIMELOCKGTE, ASSETCHAINS_NONCEMASK[]; From 92cf6d266736a5f37af3550167fd3f84cb891d4d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 00:47:55 -1100 Subject: [PATCH 592/643] Fixes --- src/komodo_bitcoind.h | 2 +- src/rpc/misc.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index cd12bb255..eb033f96a 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1470,7 +1470,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ else return(1); } txn_count = pblock->vtx.size(); - fprintf(stderr,"checkblock n.%d vins.%d vouts.%d %.8f %.8f\n",txn_count,pblock->vtx[txn_count-1].vin.size(),pblock->vtx[txn_count-1].vout.size(),(double)pblock->vtx[txn_count-1].vout[0].nValue/COIN,(double)pblock->vtx[txn_count-1].vout[1].nValue/COIN); + fprintf(stderr,"checkblock n.%d vins.%d vouts.%d %.8f %.8f\n",txn_count,(int32_t)pblock->vtx[txn_count-1].vin.size(),(int32_t)pblock->vtx[txn_count-1].vout.size(),(double)pblock->vtx[txn_count-1].vout[0].nValue/COIN,(double)pblock->vtx[txn_count-1].vout[1].nValue/COIN); if ( txn_count > 1 && pblock->vtx[txn_count-1].vin.size() == 1 && pblock->vtx[txn_count-1].vout.size() == 1 + (ASSETCHAINS_MARMARA!=0) ) { it = mapBlockIndex.find(pblock->hashPrevBlock); diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 2491055d1..e6d8025b1 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -225,7 +225,7 @@ UniValue getinfo(const UniValue& params, bool fHelp) } } if (ASSETCHAINS_LASTERA > 0) - obj.push_back(Pair("eras", ASSETCHAINS_LASTERA + 1)); + obj.push_back(Pair("eras", (int64_t)(ASSETCHAINS_LASTERA + 1))); obj.push_back(Pair("reward", acReward)); obj.push_back(Pair("halving", acHalving)); obj.push_back(Pair("decay", acDecay)); From 8caf315c91473a627e614b863dce2f9f0d201b1b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 00:51:31 -1100 Subject: [PATCH 593/643] Test --- src/wallet/rpcwallet.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 3acee9c1f..a47c18356 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5171,7 +5171,6 @@ int32_t verus_staked(CBlock *pBlock, CMutableTransaction &txNew, uint32_t &nBits int32_t ensure_CCrequirements() { - extern uint8_t NOTARY_PUBKEY33[]; CCerror = ""; if ( NOTARY_PUBKEY33[0] == 0 ) return(-1); From e02762dfaad6847918991238b83f6b532b683957 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 00:52:36 -1100 Subject: [PATCH 594/643] Test --- src/wallet/rpcwallet.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a47c18356..8180c9239 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5260,8 +5260,6 @@ UniValue setpubkey(const UniValue& params, bool fHelp) char Raddress[18]; uint8_t pubkey33[33]; - extern uint8_t NOTARY_PUBKEY33[]; - extern std::string NOTARY_PUBKEY; if ( NOTARY_PUBKEY33[0] == 0 ) { if (strlen(params[0].get_str().c_str()) == 66) { decode_hex(pubkey33,33,(char *)params[0].get_str().c_str()); From 089d2114466eb8543235c033688f7a661615ed01 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 01:03:54 -1100 Subject: [PATCH 595/643] Test --- src/cc/marmara.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 7fefb9eb6..def21763a 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -509,9 +509,6 @@ int32_t MarmaraSignature(uint8_t *utxosig,CMutableTransaction &mtx) { cp = CCinit(&C,EVAL_MARMARA); mypk = pubkey2pk(Mypubkey()); - mtx.vout.resize(2); - mtx.vout[1].scriptPubKey = tx.vout[numvouts - 1].scriptPubKey; - mtx.vout[1].nValue = 0; pubkeys.push_back(mypk); rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,tx.vout[numvouts - 1].scriptPubKey,pubkeys); if ( rawtx.size() > 0 ) From 923b87a6ecf93b294522207f668d3a3be5be75fc Mon Sep 17 00:00:00 2001 From: ca333 Date: Mon, 21 Jan 2019 13:04:18 +0100 Subject: [PATCH 596/643] [add] dylib --- src/cc/Makefile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cc/Makefile b/src/cc/Makefile index a3c54d81d..92fbe0da9 100644 --- a/src/cc/Makefile +++ b/src/cc/Makefile @@ -2,7 +2,7 @@ SHELL = /bin/sh CC = gcc CC_DARWIN = g++-6 CC_WIN = x86_64-w64-mingw32-gcc-posix -CFLAGS_DARWIN = -std=c++11 -arch x86_64 -I/usr/local/Cellar/gcc\@6/6.4.0_2/include/c++/6.4.0/ -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -c -Wl,-undefined -Wl,dynamic_lookup +CFLAGS_DARWIN = -std=c++11 -arch x86_64 -I/usr/local/Cellar/gcc\@6/6.4.0_2/include/c++/6.4.0/ -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -c -Wl,-undefined -Wl,dynamic_lookup -dynamiclib CFLAGS = -std=c++11 -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c CFLAGS_WIN = -std=c++11 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c DEBUGFLAGS = -O0 -D _DEBUG @@ -10,8 +10,9 @@ RELEASEFLAGS = -O2 -D NDEBUG -combine -fwhole-program $(info $(OS)) OS := $(shell uname -s) $(info $(OS)) -TARGET = ../cclib.so -TARGET_WIN = ../cclib.dll +TARGET = ../libcc.so +TARGET_DARWIN = ../libcc.dylib +TARGET_WIN = ../libcc.dll SOURCES = cclib.cpp #HEADERS = $(shell echo ../cryptoconditions/include/*.h) @@ -20,7 +21,7 @@ all: $(TARGET) $(TARGET): $(SOURCES) $(info Building cclib to src/) ifeq ($(OS),Darwin) - $(CC_DARWIN) $(CFLAGS_DARWIN) $(DEBUGFLAGS) -o $(TARGET) $(SOURCES) + $(CC_DARWIN) $(CFLAGS_DARWIN) $(DEBUGFLAGS) -o $(TARGET_DARWIN) $(SOURCES) else ifeq ($(OS),Linux) $(CC) $(CFLAGS) $(DEBUGFLAGS) -o $(TARGET) $(SOURCES) #else ifeq ($(WIN_HOST),True) - todo: pass ENV var from build.sh if WIN host From b516423fed2daea7f9ccd9166deffe274f6c5c9e Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 01:07:50 -1100 Subject: [PATCH 597/643] -print --- src/cc/marmara.cpp | 2 +- src/komodo_bitcoind.h | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index def21763a..db794c33b 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -265,7 +265,7 @@ bool MarmaraPoScheck(char *destaddr,CScript opret,CScript scriptPubKey) Marmarapk = GetUnspendable(cp,0); GetCCaddress1of2(cp,coinaddr,Marmarapk,pk); fprintf(stderr,"matched opret! funcid.%c ht.%d unlock.%d %s\n",funcid,height,unlockht,coinaddr); - return(strcmp(destaddr,coinaddr)); + return(strcmp(destaddr,coinaddr) == 0); } return(0); } diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index eb033f96a..c2d2716c1 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -644,7 +644,7 @@ int32_t komodo_isPoS(CBlock *pblock,int32_t height) if ( ASSETCHAINS_STAKED != 0 ) { n = pblock->vtx.size(); - fprintf(stderr,"ht.%d check for PoS numtx.%d numvins.%d numvouts.%d\n",height,n,(int32_t)pblock->vtx[n-1].vin.size(),(int32_t)pblock->vtx[n-1].vout.size()); + //fprintf(stderr,"ht.%d check for PoS numtx.%d numvins.%d numvouts.%d\n",height,n,(int32_t)pblock->vtx[n-1].vin.size(),(int32_t)pblock->vtx[n-1].vout.size()); if ( n > 1 && pblock->vtx[n-1].vin.size() == 1 && pblock->vtx[n-1].vout.size() == 1+(ASSETCHAINS_MARMARA!=0) ) { txid = pblock->vtx[n-1].vin[0].prevout.hash; @@ -662,7 +662,7 @@ int32_t komodo_isPoS(CBlock *pblock,int32_t height) { if ( pblock->vtx[n-1].vout[0].scriptPubKey.IsPayToCryptoCondition() != 0 && (numvouts= pblock->vtx[n-1].vout.size()) > 1 ) { -fprintf(stderr,"validate proper %s %s signature and unlockht preservation\n",voutaddr,destaddr); +//fprintf(stderr,"validate proper %s %s signature and unlockht preservation\n",voutaddr,destaddr); return(MarmaraPoScheck(destaddr,opret,pblock->vtx[n-1].vout[numvouts-1].scriptPubKey)); } else @@ -1464,13 +1464,13 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ pindex = it != mapBlockIndex.end() ? it->second : NULL; if ( pindex != 0 && pindex->segid >= -1 ) { - fprintf(stderr,"isPoSblock segid.%d\n",pindex->segid); + //fprintf(stderr,"isPoSblock segid.%d\n",pindex->segid); if ( pindex->segid == -1 ) return(0); else return(1); } txn_count = pblock->vtx.size(); - fprintf(stderr,"checkblock n.%d vins.%d vouts.%d %.8f %.8f\n",txn_count,(int32_t)pblock->vtx[txn_count-1].vin.size(),(int32_t)pblock->vtx[txn_count-1].vout.size(),(double)pblock->vtx[txn_count-1].vout[0].nValue/COIN,(double)pblock->vtx[txn_count-1].vout[1].nValue/COIN); + //fprintf(stderr,"checkblock n.%d vins.%d vouts.%d %.8f %.8f\n",txn_count,(int32_t)pblock->vtx[txn_count-1].vin.size(),(int32_t)pblock->vtx[txn_count-1].vout.size(),(double)pblock->vtx[txn_count-1].vout[0].nValue/COIN,(double)pblock->vtx[txn_count-1].vout[1].nValue/COIN); if ( txn_count > 1 && pblock->vtx[txn_count-1].vin.size() == 1 && pblock->vtx[txn_count-1].vout.size() == 1 + (ASSETCHAINS_MARMARA!=0) ) { it = mapBlockIndex.find(pblock->hashPrevBlock); @@ -1786,7 +1786,6 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); bhash = UintToArith256(hash); possible = komodo_block2pubkey33(pubkey33,pblock); -fprintf(stderr,"checkPoW ht.%d\n",height); if ( height == 0 ) { if ( slowflag != 0 ) @@ -1831,7 +1830,7 @@ fprintf(stderr,"checkPoW ht.%d\n",height); return(-1); } } - fprintf(stderr,"ASSETCHAINS_STAKED.%d ht.%d\n",(int32_t)ASSETCHAINS_STAKED,height); + //fprintf(stderr,"ASSETCHAINS_STAKED.%d ht.%d\n",(int32_t)ASSETCHAINS_STAKED,height); if ( ASSETCHAINS_STAKED != 0 && height >= 2 ) // must PoS or have at least 16x better PoW { if ( (is_PoSblock= komodo_is_PoSblock(slowflag,height,pblock,bnTarget,bhash)) == 0 ) From 7422ae2038221259712d378b976d979bbad0f788 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 01:24:16 -1100 Subject: [PATCH 598/643] +print --- src/cc/marmara.cpp | 7 +++++-- src/komodo_bitcoind.h | 8 ++++---- src/miner.cpp | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index db794c33b..3ddbac581 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -255,10 +255,13 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) return(-1); } -bool MarmaraPoScheck(char *destaddr,CScript opret,CScript scriptPubKey) +bool MarmaraPoScheck(char *destaddr,CScript opret,CTransaction staketx) { CPubKey Marmarapk,pk; int32_t height,unlockht; uint8_t funcid; char coinaddr[64]; struct CCcontract_info *cp,C; - if ( opret == scriptPubKey ) + UniValue result(UniValue::VOBJ); + TxToJSON(tx, uint256(), result); + fprintf(stderr,"%s\n",result.ToString()); + if ( staketx.vout.size() == 2 && opret == staketx.vout[1].scriptPubKey ) { cp = CCinit(&C,EVAL_MARMARA); funcid = DecodeMaramaraCoinbaseOpRet(opret,pk,height,unlockht); diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index c2d2716c1..bdcad8d7b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -636,7 +636,7 @@ int32_t komodo_WhoStaked(CBlock *pblock, CTxDestination &addressout) return(0); } -bool MarmaraPoScheck(char *destaddr,CScript opret,CScript scriptPubKey); +bool MarmaraPoScheck(char *destaddr,CScript opret,CTransaction staketx); int32_t komodo_isPoS(CBlock *pblock,int32_t height) { @@ -653,17 +653,17 @@ int32_t komodo_isPoS(CBlock *pblock,int32_t height) if ( ExtractDestination(pblock->vtx[n-1].vout[0].scriptPubKey,voutaddress) ) { strcpy(voutaddr,CBitcoinAddress(voutaddress).ToString().c_str()); - fprintf(stderr,"voutaddr.%s vs destaddr.%s\n",voutaddr,destaddr); + //fprintf(stderr,"voutaddr.%s vs destaddr.%s\n",voutaddr,destaddr); if ( pblock->vtx[n-1].vout[0].nValue == value && strcmp(destaddr,voutaddr) == 0 ) { if ( ASSETCHAINS_MARMARA == 0 ) return(1); else { - if ( pblock->vtx[n-1].vout[0].scriptPubKey.IsPayToCryptoCondition() != 0 && (numvouts= pblock->vtx[n-1].vout.size()) > 1 ) + if ( pblock->vtx[n-1].vout[0].scriptPubKey.IsPayToCryptoCondition() != 0 && (numvouts= pblock->vtx[n-1].vout.size()) == 2 ) { //fprintf(stderr,"validate proper %s %s signature and unlockht preservation\n",voutaddr,destaddr); - return(MarmaraPoScheck(destaddr,opret,pblock->vtx[n-1].vout[numvouts-1].scriptPubKey)); + return(MarmaraPoScheck(destaddr,opret,pblock->vtx[n-1])); } else { diff --git a/src/miner.cpp b/src/miner.cpp index 78eb84e7b..01ff9da0c 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -512,7 +512,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txStaked)); nFees += txfees; pblock->nTime = blocktime; - //printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.LastTip()->GetHeight()+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13))); +printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.LastTip()->GetHeight()+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13))); } else return(0); //fprintf(stderr,"no utxos eligible for staking\n"); } // Create coinbase tx From dbb103571e4c4a463dbf9abb74a16a42d23e51fd Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 01:26:37 -1100 Subject: [PATCH 599/643] Test --- src/cc/marmara.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 3ddbac581..40d8b1efb 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -258,9 +258,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) bool MarmaraPoScheck(char *destaddr,CScript opret,CTransaction staketx) { CPubKey Marmarapk,pk; int32_t height,unlockht; uint8_t funcid; char coinaddr[64]; struct CCcontract_info *cp,C; - UniValue result(UniValue::VOBJ); - TxToJSON(tx, uint256(), result); - fprintf(stderr,"%s\n",result.ToString()); + fprintf(stderr,"numvins.%d numvouts.%d\n",(int32_t)statketx.vin.size(),(int32_t)statketx.vout.size(),(double),(int32_t)statketx.vout[0].nValue/COIN); if ( staketx.vout.size() == 2 && opret == staketx.vout[1].scriptPubKey ) { cp = CCinit(&C,EVAL_MARMARA); From aa2ebd7fc41e9b1334bc9d14a0840c608f22910e Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 01:27:19 -1100 Subject: [PATCH 600/643] staketx --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 40d8b1efb..c739a9203 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -258,7 +258,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) bool MarmaraPoScheck(char *destaddr,CScript opret,CTransaction staketx) { CPubKey Marmarapk,pk; int32_t height,unlockht; uint8_t funcid; char coinaddr[64]; struct CCcontract_info *cp,C; - fprintf(stderr,"numvins.%d numvouts.%d\n",(int32_t)statketx.vin.size(),(int32_t)statketx.vout.size(),(double),(int32_t)statketx.vout[0].nValue/COIN); + fprintf(stderr,"numvins.%d numvouts.%d\n",(int32_t)staketx.vin.size(),(int32_t)staketx.vout.size(),(double),(int32_t)staketx.vout[0].nValue/COIN); if ( staketx.vout.size() == 2 && opret == staketx.vout[1].scriptPubKey ) { cp = CCinit(&C,EVAL_MARMARA); From ee69d8f4f8d5a8f374899e0cf48470bde734fccb Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 01:28:31 -1100 Subject: [PATCH 601/643] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index c739a9203..8a5ead91b 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -258,7 +258,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) bool MarmaraPoScheck(char *destaddr,CScript opret,CTransaction staketx) { CPubKey Marmarapk,pk; int32_t height,unlockht; uint8_t funcid; char coinaddr[64]; struct CCcontract_info *cp,C; - fprintf(stderr,"numvins.%d numvouts.%d\n",(int32_t)staketx.vin.size(),(int32_t)staketx.vout.size(),(double),(int32_t)staketx.vout[0].nValue/COIN); + fprintf(stderr,"numvins.%d numvouts.%d\n",(int32_t)staketx.vin.size(),(int32_t)staketx.vout.size(),(double)staketx.vout[0].nValue/COIN); if ( staketx.vout.size() == 2 && opret == staketx.vout[1].scriptPubKey ) { cp = CCinit(&C,EVAL_MARMARA); From 3c5385e0402551eb0c6732063a120ca4f8b322b3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 01:29:19 -1100 Subject: [PATCH 602/643] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 8a5ead91b..de6018972 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -258,7 +258,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) bool MarmaraPoScheck(char *destaddr,CScript opret,CTransaction staketx) { CPubKey Marmarapk,pk; int32_t height,unlockht; uint8_t funcid; char coinaddr[64]; struct CCcontract_info *cp,C; - fprintf(stderr,"numvins.%d numvouts.%d\n",(int32_t)staketx.vin.size(),(int32_t)staketx.vout.size(),(double)staketx.vout[0].nValue/COIN); + fprintf(stderr,"numvins.%d numvouts.%d %.8f\n",(int32_t)staketx.vin.size(),(int32_t)staketx.vout.size(),(double)staketx.vout[0].nValue/COIN); if ( staketx.vout.size() == 2 && opret == staketx.vout[1].scriptPubKey ) { cp = CCinit(&C,EVAL_MARMARA); From cae100974056d84a1c9845fc6fcc293d15b049b5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 01:33:27 -1100 Subject: [PATCH 603/643] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index de6018972..5adc12d43 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -258,7 +258,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) bool MarmaraPoScheck(char *destaddr,CScript opret,CTransaction staketx) { CPubKey Marmarapk,pk; int32_t height,unlockht; uint8_t funcid; char coinaddr[64]; struct CCcontract_info *cp,C; - fprintf(stderr,"numvins.%d numvouts.%d %.8f\n",(int32_t)staketx.vin.size(),(int32_t)staketx.vout.size(),(double)staketx.vout[0].nValue/COIN); + fprintf(stderr,"%s numvins.%d numvouts.%d %.8f opret[%d]\n",staketx.GetHash().ToString().c_str(),(int32_t)staketx.vin.size(),(int32_t)staketx.vout.size(),(double)staketx.vout[0].nValue/COIN,(int32_t)opret.size()); if ( staketx.vout.size() == 2 && opret == staketx.vout[1].scriptPubKey ) { cp = CCinit(&C,EVAL_MARMARA); From d4520254969223ecc78cb02599f5d4b5d5c77902 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 01:39:45 -1100 Subject: [PATCH 604/643] Filter staking utxo --- src/komodo_bitcoind.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index bdcad8d7b..39b905e86 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2170,7 +2170,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } else { - struct CCcontract_info *cp,C; uint256 txid; int32_t vout; CAmount nValue; char coinaddr[64]; CPubKey mypk,Marmarapk; + struct CCcontract_info *cp,C; uint256 txid; int32_t vout,ht,unlockht; CAmount nValue; char coinaddr[64]; CPubKey mypk,Marmarapk,pk; std::vector > unspentOutputs; cp = CCinit(&C,EVAL_MARMARA); mypk = pubkey2pk(Mypubkey()); @@ -2186,8 +2186,12 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt if ( GetTransaction(txid,tx,hashBlock,true) != 0 && (pindex= komodo_getblockindex(hashBlock)) != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { const CScript &scriptPubKey = tx.vout[vout].scriptPubKey; - array = komodo_addutxo(array,&numkp,&maxkp,(uint32_t)pindex->nTime,(uint64_t)nValue,txid,vout,coinaddr,hashbuf,(CScript)scriptPubKey); - //fprintf(stderr,"addutxo %.8f numkp.%d vs max.%d\n",(double)nValue/COIN,numkp,maxkp); + if ( DecodeMaramaraCoinbaseOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,pk,ht,unlockht) != 0 && pk == mypk ) + { + array = komodo_addutxo(array,&numkp,&maxkp,(uint32_t)pindex->nTime,(uint64_t)nValue,txid,vout,coinaddr,hashbuf,(CScript)scriptPubKey); + } + else + fprintf(stderr,"SKIP addutxo %.8f numkp.%d vs max.%d\n",(double)nValue/COIN,numkp,maxkp); } } } From 3dcea8bd51c323806123600f81af07bff993f654 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 01:40:51 -1100 Subject: [PATCH 605/643] Test --- src/komodo_bitcoind.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 39b905e86..09bc4b9fa 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2088,6 +2088,7 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod } int32_t MarmaraSignature(uint8_t *utxosig,CMutableTransaction &txNew); +uint8_t DecodeMaramaraCoinbaseOpRet(const CScript scriptPubKey,CPubKey &pk,int32_t &height,int32_t &unlockht); int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { From c2e1da32786660f780c9f905ec36d7cb81e1a0e5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 01:44:31 -1100 Subject: [PATCH 606/643] Allow coinbase spending --- src/cc/marmara.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 5adc12d43..9062ab2b8 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -334,6 +334,10 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t { return(true); } + else if ( funcid == 'C' ) // coinbase + { + return(true); + } // staking only for locked utxo } return eval->Invalid("fall through error"); From b9f15395d7fafeaf690672ad1445d14e86f134fd Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 01:46:48 -1100 Subject: [PATCH 607/643] -print --- src/cc/marmara.cpp | 8 ++++---- src/komodo_bitcoind.h | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 9062ab2b8..8f8de12e2 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -94,7 +94,7 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript scriptPubKey,CPubKey &pk,int32 { return(script[1]); } else fprintf(stderr,"DecodeMaramaraCoinbaseOpRet unmarshal error for %c\n",script[1]); - } else fprintf(stderr,"script[1] is %d != 'C' %d or 'P' %d or 'L' %d\n",script[1],'C','P','L'); + } //else fprintf(stderr,"script[1] is %d != 'C' %d or 'P' %d or 'L' %d\n",script[1],'C','P','L'); } else fprintf(stderr,"vopret.size() is %d\n",(int32_t)vopret.size()); return(0); } @@ -258,14 +258,14 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) bool MarmaraPoScheck(char *destaddr,CScript opret,CTransaction staketx) { CPubKey Marmarapk,pk; int32_t height,unlockht; uint8_t funcid; char coinaddr[64]; struct CCcontract_info *cp,C; - fprintf(stderr,"%s numvins.%d numvouts.%d %.8f opret[%d]\n",staketx.GetHash().ToString().c_str(),(int32_t)staketx.vin.size(),(int32_t)staketx.vout.size(),(double)staketx.vout[0].nValue/COIN,(int32_t)opret.size()); + //fprintf(stderr,"%s numvins.%d numvouts.%d %.8f opret[%d]\n",staketx.GetHash().ToString().c_str(),(int32_t)staketx.vin.size(),(int32_t)staketx.vout.size(),(double)staketx.vout[0].nValue/COIN,(int32_t)opret.size()); if ( staketx.vout.size() == 2 && opret == staketx.vout[1].scriptPubKey ) { cp = CCinit(&C,EVAL_MARMARA); funcid = DecodeMaramaraCoinbaseOpRet(opret,pk,height,unlockht); Marmarapk = GetUnspendable(cp,0); GetCCaddress1of2(cp,coinaddr,Marmarapk,pk); - fprintf(stderr,"matched opret! funcid.%c ht.%d unlock.%d %s\n",funcid,height,unlockht,coinaddr); + //fprintf(stderr,"matched opret! funcid.%c ht.%d unlock.%d %s\n",funcid,height,unlockht,coinaddr); return(strcmp(destaddr,coinaddr) == 0); } return(0); @@ -525,7 +525,7 @@ int32_t MarmaraSignature(uint8_t *utxosig,CMutableTransaction &mtx) utxosig[i] = ptr[i]; //fprintf(stderr,"%02x",ptr[i]); } - fprintf(stderr," got signed rawtx.%s siglen.%d\n",rawtx.c_str(),siglen); + //fprintf(stderr," got signed rawtx.%s siglen.%d\n",rawtx.c_str(),siglen); return(siglen); } } diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 09bc4b9fa..19ec0546b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2191,8 +2191,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { array = komodo_addutxo(array,&numkp,&maxkp,(uint32_t)pindex->nTime,(uint64_t)nValue,txid,vout,coinaddr,hashbuf,(CScript)scriptPubKey); } - else - fprintf(stderr,"SKIP addutxo %.8f numkp.%d vs max.%d\n",(double)nValue/COIN,numkp,maxkp); + // else fprintf(stderr,"SKIP addutxo %.8f numkp.%d vs max.%d\n",(double)nValue/COIN,numkp,maxkp); } } } From 7966cef9ec5805aab066420ab08154032c680353 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 01:55:29 -1100 Subject: [PATCH 608/643] MTST2 exemption --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 19ec0546b..c9a91d289 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -668,7 +668,7 @@ int32_t komodo_isPoS(CBlock *pblock,int32_t height) else { fprintf(stderr,"reject ht.%d PoS block\n",height); - return(1); // allow until MTST3 + return(strcmp(ASSETCHAINS_SYMBOL,"MTST2") == 0); // allow until MTST3 } } } From e9083421a8f9a2ba7d355f9b862670638a439d2f Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Mon, 21 Jan 2019 22:00:35 +0700 Subject: [PATCH 609/643] checking channelspayment case when opening node revealed secret in offline --- qa/rpc-tests/cryptoconditions_channels.py | 70 +++++++++++++++++++++++ qa/rpc-tests/cryptoconditions_token.py | 4 +- 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/qa/rpc-tests/cryptoconditions_channels.py b/qa/rpc-tests/cryptoconditions_channels.py index cec45687f..115c2228f 100755 --- a/qa/rpc-tests/cryptoconditions_channels.py +++ b/qa/rpc-tests/cryptoconditions_channels.py @@ -4,6 +4,7 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. +import time from test_framework.test_framework import CryptoconditionsTestFramework from test_framework.authproxy import JSONRPCException from test_framework.util import assert_equal, assert_greater_than, \ @@ -71,6 +72,32 @@ class CryptoconditionsChannelsTest(CryptoconditionsTestFramework): result = rpc.channelsinfo(channel_txid) assert_equal(result["Transactions"][1]["Payment"], payment_tx_id) + # TODO: check if payment value really transferred + # TODO: check if information in channelinfo changed correct + + # TODO: try to drain channel (10 payment by 100000 satoshies in total) + + # have to check that second node have coins to cover txfee at least + rpc.sendtoaddress(rpc1.getnewaddress(), 1) + rpc.sendtoaddress(rpc1.getnewaddress(), 1) + rpc.generate(2) + self.sync_all() + result = rpc1.getbalance() + assert_greater_than(result, 0.1) + + # trying to initiate channels payment from node B without any secret + # TODO: have to add RPC validation + payment_hex = rpc1.channelspayment(channel_txid, "100000") + try: + result = rpc1.sendrawtransaction(payment_hex["hex"]) + except Exception as e: + pass + + # trying to initiate channels payment from node B with secret from previous payment + result = rpc1.channelspayment(channel_txid, "100000", rpc1.channelsinfo(channel_txid)["Transactions"][1]["Secret"]) + #result = rpc1.sendrawtransaction(payment_hex["hex"]) + assert_error(result) + # executing channel close result = rpc.channelsclose(channel_txid) assert_success(result) @@ -90,6 +117,49 @@ class CryptoconditionsChannelsTest(CryptoconditionsTestFramework): refund_txid = self.send_and_mine(result["hex"], rpc) assert refund_txid, "got txid" + # TODO: check if it really refunded + + # creating new channel to test the case when node B initiate payment when node A revealed secret but + # secret revealing transaction not mined + # 10 payments, 100000 sat denomination channel opening with second node pubkey + new_channel_hex2 = rpc.channelsopen(self.pubkey1, "10", "100000") + assert_success(new_channel_hex) + channel2_txid = self.send_and_mine(new_channel_hex2["hex"], rpc) + assert channel2_txid, "got channel txid" + + rpc.generate(2) + self.sync_all() + + # disconnecting first node from network + rpc.setban("127.0.0.0/24","add") + assert_equal(rpc.getinfo()["connections"], 0) + + # sending one payment to mempool to reveal the secret but not mine it + payment_hex = rpc.channelspayment(channel2_txid, "100000") + result = rpc.sendrawtransaction(payment_hex["hex"]) + assert result, "got payment txid" + + secret = rpc.channelsinfo(channel2_txid)["Transactions"][1]["Secret"] + assert secret, "Secret revealed" + + # secret shouldn't be available for node B + secret_not_revealed = None + try: + rpc1.channelsinfo(channel2_txid)["Transactions"][1]["Secret"] + except Exception: + secret_not_revealed = True + assert_equal(secret_not_revealed, True) + + # trying to initiate payment from second node with revealed secret + assert_equal(rpc1.getinfo()["connections"], 0) + dc_payment_hex = rpc1.channelspayment(channel2_txid, "100000", secret) + assert_success(dc_payment_hex) + result = rpc1.sendrawtransaction(dc_payment_hex["hex"]) + assert result, "got channelspayment transaction id" + + + # TODO: have to connect nodes back to not corrupt other tests + def run_test(self): print("Mining blocks...") rpc = self.nodes[0] diff --git a/qa/rpc-tests/cryptoconditions_token.py b/qa/rpc-tests/cryptoconditions_token.py index 5fd3256d6..97ed86f8d 100755 --- a/qa/rpc-tests/cryptoconditions_token.py +++ b/qa/rpc-tests/cryptoconditions_token.py @@ -142,7 +142,8 @@ class CryptoconditionsTokenTest(CryptoconditionsTestFramework): # checking ask cancellation testorder = rpc.tokenask("100", tokenid, "7.77") testorderid = self.send_and_mine(testorder['hex'], rpc) - # from other node + # from other node (ensuring that second node have enough balance to cover txfee + # to get the actual error - not "not enough balance" one rpc.sendtoaddress(rpc1.getnewaddress(), 1) rpc.sendtoaddress(rpc1.getnewaddress(), 1) rpc.generate(2) @@ -253,5 +254,6 @@ class CryptoconditionsTokenTest(CryptoconditionsTestFramework): rpc1.importprivkey(self.privkey1) self.run_token_tests() + if __name__ == '__main__': CryptoconditionsTokenTest().main() From 3f64474f85ab93dee257c0182c870e4daa33e07e Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Tue, 22 Jan 2019 15:03:52 +0700 Subject: [PATCH 610/643] more channels tests --- qa/pull-tester/cc-tests.sh | 3 +- qa/rpc-tests/cryptoconditions_channels.py | 87 ++++++++++++++++++++--- 2 files changed, 80 insertions(+), 10 deletions(-) diff --git a/qa/pull-tester/cc-tests.sh b/qa/pull-tester/cc-tests.sh index f2abde883..9bc8c155d 100755 --- a/qa/pull-tester/cc-tests.sh +++ b/qa/pull-tester/cc-tests.sh @@ -13,12 +13,13 @@ export BITCOIND=${REAL_BITCOIND} testScripts=( 'cryptoconditions_faucet.py' - 'cryptoconditions_channels.py' 'cryptoconditions_dice.py' 'cryptoconditions_oracles.py' 'cryptoconditions_rewards.py' 'cryptoconditions_token.py' #'cryptoconditions_gateways.py' + # TODO: cant reconnect nodes back in channels test because of crash (seems regtest only specific) + 'cryptoconditions_channels.py' ); extArg="-extended" diff --git a/qa/rpc-tests/cryptoconditions_channels.py b/qa/rpc-tests/cryptoconditions_channels.py index 115c2228f..b2a49b477 100755 --- a/qa/rpc-tests/cryptoconditions_channels.py +++ b/qa/rpc-tests/cryptoconditions_channels.py @@ -72,10 +72,36 @@ class CryptoconditionsChannelsTest(CryptoconditionsTestFramework): result = rpc.channelsinfo(channel_txid) assert_equal(result["Transactions"][1]["Payment"], payment_tx_id) - # TODO: check if payment value really transferred - # TODO: check if information in channelinfo changed correct + # number of payments should be equal 1 (one denomination used) + result = rpc.channelsinfo(channel_txid)["Transactions"][1]["Number of payments"] + assert_equal(result, 1) + # payments left param should reduce 1 and be equal 9 now ( 10 - 1 = 9 ) + result = rpc.channelsinfo(channel_txid)["Transactions"][1]["Payments left"] + assert_equal(result, 9) - # TODO: try to drain channel (10 payment by 100000 satoshies in total) + # lets try payment with x2 amount to ensure that counters works correct + result = rpc.channelspayment(channel_txid, "200000") + assert_success(result) + payment_tx_id = self.send_and_mine(result["hex"], rpc) + assert payment_tx_id, "got txid" + + result = rpc.channelsinfo(channel_txid) + assert_equal(result["Transactions"][2]["Payment"], payment_tx_id) + + result = rpc.channelsinfo(channel_txid)["Transactions"][2]["Number of payments"] + assert_equal(result, 2) + + result = rpc.channelsinfo(channel_txid)["Transactions"][2]["Payments left"] + assert_equal(result, 7) + + # check if payment value really transferred + raw_transaction = rpc.getrawtransaction(payment_tx_id, 1) + + result = raw_transaction["vout"][3]["valueSat"] + assert_equal(result, 200000) + + result = rpc1.validateaddress(raw_transaction["vout"][3]["scriptPubKey"]["addresses"][0])["ismine"] + assert_equal(result, True) # have to check that second node have coins to cover txfee at least rpc.sendtoaddress(rpc1.getnewaddress(), 1) @@ -109,7 +135,7 @@ class CryptoconditionsChannelsTest(CryptoconditionsTestFramework): # now in channelinfo closed flag should appear result = rpc.channelsinfo(channel_txid) - assert_equal(result["Transactions"][2]["Close"], channel_close_txid) + assert_equal(result["Transactions"][3]["Close"], channel_close_txid) # executing channel refund result = rpc.channelsrefund(channel_txid, channel_close_txid) @@ -117,10 +143,41 @@ class CryptoconditionsChannelsTest(CryptoconditionsTestFramework): refund_txid = self.send_and_mine(result["hex"], rpc) assert refund_txid, "got txid" - # TODO: check if it really refunded + # TODO: check if it refunded to opener address + raw_transaction = rpc.getrawtransaction(refund_txid, 1) - # creating new channel to test the case when node B initiate payment when node A revealed secret but - # secret revealing transaction not mined + result = raw_transaction["vout"][2]["valueSat"] + assert_equal(result, 700000) + + result = rpc.validateaddress(raw_transaction["vout"][2]["scriptPubKey"]["addresses"][0])["ismine"] + assert_equal(result, True) + + + # creating and draining channel (10 payment by 100000 satoshies in total to fit full capacity) + new_channel_hex1 = rpc.channelsopen(self.pubkey1, "10", "100000") + assert_success(new_channel_hex1) + channel1_txid = self.send_and_mine(new_channel_hex1["hex"], rpc) + assert channel1_txid, "got channel txid" + + # need to have 2+ confirmations in the test mode + rpc.generate(2) + self.sync_all() + + for i in range(10): + result = rpc.channelspayment(channel1_txid, "100000") + assert_success(result) + payment_tx_id = self.send_and_mine(result["hex"], rpc) + assert payment_tx_id, "got txid" + + # last payment should indicate that 0 payments left + result = rpc.channelsinfo(channel1_txid)["Transactions"][10]["Payments left"] + assert_equal(result, 0) + + # no more payments possible + result = rpc.channelspayment(channel1_txid, "100000") + assert_error(result) + + # creating new channel to test the case when node B initiate payment when node A revealed secret in offline # 10 payments, 100000 sat denomination channel opening with second node pubkey new_channel_hex2 = rpc.channelsopen(self.pubkey1, "10", "100000") assert_success(new_channel_hex) @@ -133,6 +190,9 @@ class CryptoconditionsChannelsTest(CryptoconditionsTestFramework): # disconnecting first node from network rpc.setban("127.0.0.0/24","add") assert_equal(rpc.getinfo()["connections"], 0) + assert_equal(rpc1.getinfo()["connections"], 0) + + rpc1.generate(1) # sending one payment to mempool to reveal the secret but not mine it payment_hex = rpc.channelspayment(channel2_txid, "100000") @@ -157,8 +217,17 @@ class CryptoconditionsChannelsTest(CryptoconditionsTestFramework): result = rpc1.sendrawtransaction(dc_payment_hex["hex"]) assert result, "got channelspayment transaction id" - - # TODO: have to connect nodes back to not corrupt other tests + # TODO: it crash first node after block generating on mempools merging + # # restoring connection between nodes + # rpc.setban("127.0.0.0/24","remove") + # #rpc.generate(1) + # #rpc1.generate(1) + # sync_blocks(self.nodes) + # rpc.generate(1) + # sync_blocks(self.nodes) + # sync_mempools(self.nodes) + # assert_equal(rpc.getinfo()["connections"], 1) + # assert_equal(rpc1.getinfo()["connections"], 1) def run_test(self): print("Mining blocks...") From d8289cd12813f6f440559541e5f04d62ddfc8ae5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 23:13:58 -1100 Subject: [PATCH 611/643] Test --- src/miner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/miner.cpp b/src/miner.cpp index 01ff9da0c..ab0a770c1 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1707,6 +1707,7 @@ void static BitcoinMiner() for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&h)[z]); fprintf(stderr," Invalid block mined, try again\n"); + break; return(false); } KOMODO_CHOSEN_ONE = 1; From ba46fa56d9734204ee7ae748980960130d504810 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 23:18:38 -1100 Subject: [PATCH 612/643] Got invalid --- src/miner.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index ab0a770c1..05d324075 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1604,16 +1604,12 @@ void static BitcoinMiner() fprintf(stderr," PoW for staked coin PoS %d%% vs target %d%% ht.%d\n",percPoS,(int32_t)ASSETCHAINS_STAKED,Mining_height); } } + int32_t gotinvalid = 0; while (true) { - /*if ( KOMODO_INSYNC == 0 ) - { - KOMODO_LONGESTCHAIN = komodo_longestchain(); - fprintf(stderr,"Mining when blockchain might not be in sync longest.%d vs %d\n",KOMODO_LONGESTCHAIN,Mining_height); - if ( KOMODO_LONGESTCHAIN != 0 && Mining_height >= KOMODO_LONGESTCHAIN ) - KOMODO_INSYNC = Mining_height; - sleep(3); - }*/ + fprintf(stderr,"gotinvalid.%d\n",gotinvalid); + if ( gotinvalid != 0 ) + break; komodo_longestchain(); // Hash state KOMODO_CHOSEN_ONE = 0; @@ -1707,7 +1703,7 @@ void static BitcoinMiner() for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&h)[z]); fprintf(stderr," Invalid block mined, try again\n"); - break; + gotinvalid = 1; return(false); } KOMODO_CHOSEN_ONE = 1; From 8706511de79c1fe073f023390f03397562fd7507 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 23:19:29 -1100 Subject: [PATCH 613/643] Static --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 05d324075..9db051d78 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1604,7 +1604,7 @@ void static BitcoinMiner() fprintf(stderr," PoW for staked coin PoS %d%% vs target %d%% ht.%d\n",percPoS,(int32_t)ASSETCHAINS_STAKED,Mining_height); } } - int32_t gotinvalid = 0; + static int32_t gotinvalid = 0; while (true) { fprintf(stderr,"gotinvalid.%d\n",gotinvalid); From c2d4129409d7c1de25d085372392ebb83e26b7c1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 23:36:41 -1100 Subject: [PATCH 614/643] Got invalid as global --- src/miner.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 9db051d78..a6ef345bb 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1396,6 +1396,8 @@ void static BitcoinMiner_noeq() miningTimer.stop(); } +int32_t gotinvalid; + #ifdef ENABLE_WALLET void static BitcoinMiner(CWallet *pwallet) #else @@ -1604,7 +1606,7 @@ void static BitcoinMiner() fprintf(stderr," PoW for staked coin PoS %d%% vs target %d%% ht.%d\n",percPoS,(int32_t)ASSETCHAINS_STAKED,Mining_height); } } - static int32_t gotinvalid = 0; + gotinvalid = 0; while (true) { fprintf(stderr,"gotinvalid.%d\n",gotinvalid); From 6bfe8357db2a8d8c2d119b6cb07932d51115e4d3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 23:40:36 -1100 Subject: [PATCH 615/643] -print --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index a6ef345bb..7ffcaebc2 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1609,7 +1609,7 @@ void static BitcoinMiner() gotinvalid = 0; while (true) { - fprintf(stderr,"gotinvalid.%d\n",gotinvalid); + //fprintf(stderr,"gotinvalid.%d\n",gotinvalid); if ( gotinvalid != 0 ) break; komodo_longestchain(); From a84a48e48ffcc6d13998b91296949a52fdc1a63f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 23:43:01 -1100 Subject: [PATCH 616/643] Reset staker for marmara --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index c9a91d289..1fe6af409 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2120,7 +2120,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { CBlockIndex* pblockindex = chainActive[tipindex->GetHeight()]; CBlock block; CTxDestination addressout; - if( ReadBlockFromDisk(block, pblockindex, 1) && komodo_WhoStaked(&block, addressout) != 0 && IsMine(*pwalletMain,addressout) != 0 ) + if( ASSETCHAINS_MARMARA != 0 || ReadBlockFromDisk(block, pblockindex, 1) && komodo_WhoStaked(&block, addressout) != 0 && IsMine(*pwalletMain,addressout) != 0 ) { resetstaker = true; fprintf(stderr, "Reset ram staker after mining a block!\n"); From 7e6d9ff0650c24c7d7a672a83defd934aba2edf5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 23:43:38 -1100 Subject: [PATCH 617/643] () --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1fe6af409..26f010d1d 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2120,7 +2120,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { CBlockIndex* pblockindex = chainActive[tipindex->GetHeight()]; CBlock block; CTxDestination addressout; - if( ASSETCHAINS_MARMARA != 0 || ReadBlockFromDisk(block, pblockindex, 1) && komodo_WhoStaked(&block, addressout) != 0 && IsMine(*pwalletMain,addressout) != 0 ) + if( ASSETCHAINS_MARMARA != 0 || (ReadBlockFromDisk(block, pblockindex, 1) && komodo_WhoStaked(&block, addressout) != 0 && IsMine(*pwalletMain,addressout) != 0) ) { resetstaker = true; fprintf(stderr, "Reset ram staker after mining a block!\n"); From 8496dc63a4909ff47032ae227830c32284e5c773 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 23:44:38 -1100 Subject: [PATCH 618/643] -print --- src/komodo_bitcoind.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 26f010d1d..c530db4fb 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2120,7 +2120,9 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { CBlockIndex* pblockindex = chainActive[tipindex->GetHeight()]; CBlock block; CTxDestination addressout; - if( ASSETCHAINS_MARMARA != 0 || (ReadBlockFromDisk(block, pblockindex, 1) && komodo_WhoStaked(&block, addressout) != 0 && IsMine(*pwalletMain,addressout) != 0) ) + if ( ASSETCHAINS_MARMARA != 0 ) + resetstaker = true; + else if( ReadBlockFromDisk(block, pblockindex, 1) && komodo_WhoStaked(&block, addressout) != 0 && IsMine(*pwalletMain,addressout) != 0 ) { resetstaker = true; fprintf(stderr, "Reset ram staker after mining a block!\n"); From 50b9f4fe83b5c9c088b85a168bee7ef6f51d88f5 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 21 Jan 2019 14:01:25 +0500 Subject: [PATCH 619/643] test_ac added --- src/rpc/server.cpp | 2 ++ src/rpc/server.h | 2 ++ src/wallet/rpcwallet.cpp | 45 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 24f0c5f98..1eaabdbde 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -537,6 +537,8 @@ static const CRPCCommand vRPCCommands[] = { "util", "reconsiderblock", &reconsiderblock, true }, /* Not shown in help */ { "hidden", "setmocktime", &setmocktime, true }, + { "hidden", "test_ac", &test_ac, true }, + #ifdef ENABLE_WALLET /* Wallet */ { "wallet", "resendwallettransactions", &resendwallettransactions, true}, diff --git a/src/rpc/server.h b/src/rpc/server.h index 0166bca41..53bbd4c21 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -471,4 +471,6 @@ extern UniValue paxprices(const UniValue& params, bool fHelp); extern UniValue paxdeposit(const UniValue& params, bool fHelp); extern UniValue paxwithdraw(const UniValue& params, bool fHelp); +extern UniValue test_ac(const UniValue& params, bool fHelp); + #endif // BITCOIN_RPCSERVER_H diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 8180c9239..8e304c167 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -7581,3 +7581,48 @@ void RegisterWalletRPCCommands(CRPCTable &tableRPC) for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) tableRPC.appendCommand(commands[vcidx].name, &commands[vcidx]); } + +UniValue test_ac(const UniValue& params, bool fHelp) +{ + // make fake token tx: + struct CCcontract_info *cp, C; + + if (fHelp || (params.size() != 4)) + throw runtime_error("incorrect params\n"); + if (ensure_CCrequirements() < 0) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + + std::vector pubkey1; + std::vector pubkey2; + + pubkey1 = ParseHex(params[0].get_str().c_str()); + pubkey2 = ParseHex(params[1].get_str().c_str()); + + CPubKey pk1 = pubkey2pk(pubkey1); + CPubKey pk2 = pubkey2pk(pubkey2); + + if(!pk1.IsValid() || !pk2.IsValid()) + throw runtime_error("invalid pubkey\n"); + + int64_t txfee = 10000; + int64_t amount = atoll(params[2].get_str().c_str()) * COIN; + uint256 fundingtxid = Parseuint256((char *)params[3].get_str().c_str()); + + CPubKey myPubkey = pubkey2pk(Mypubkey()); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + + int64_t normalInputs = AddNormalinputs(mtx, myPubkey, txfee + amount, 60); + + if( normalInputs < txfee + amount) + throw runtime_error("not enough normals\n"); + + mtx.vout.push_back(MakeCC1of2vout(EVAL_HEIR, amount, pk1, pk2)); + + CScript opret; + fundingtxid = revuint256(fundingtxid); + + opret << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_HEIR << (uint8_t)'A' << fundingtxid << (uint8_t)0); + + cp = CCinit(&C, EVAL_HEIR); + return(FinalizeCCTx(0, cp, mtx, myPubkey, txfee, opret)); +} \ No newline at end of file From 9c526cce7d780ff18ec158e277553b162e3cfdff Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 21 Jan 2019 21:04:56 +0500 Subject: [PATCH 620/643] corr heir rpc coins -> satoshi conversion --- src/cc/CCHeir.h | 8 ++--- src/cc/heir.cpp | 72 +++++++++++++++++++++++++++++----------- src/wallet/rpcwallet.cpp | 46 ++++++++++++++++--------- 3 files changed, 87 insertions(+), 39 deletions(-) diff --git a/src/cc/CCHeir.h b/src/cc/CCHeir.h index ecaff9cdb..30334f6e1 100644 --- a/src/cc/CCHeir.h +++ b/src/cc/CCHeir.h @@ -27,10 +27,10 @@ bool HeirValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, class CoinHelper; class TokenHelper; -UniValue HeirFundCoinCaller(uint64_t txfee, int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid); -UniValue HeirFundTokenCaller(uint64_t txfee, int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid); -UniValue HeirClaimCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount); -UniValue HeirAddCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount); +UniValue HeirFundCoinCaller(int64_t txfee, int64_t satoshis, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid); +UniValue HeirFundTokenCaller(int64_t txfee, int64_t satoshis, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid); +UniValue HeirClaimCaller(uint256 fundingtxid, int64_t txfee, std::string amount); +UniValue HeirAddCaller(uint256 fundingtxid, int64_t txfee, std::string amount); UniValue HeirInfo(uint256 fundingtxid); UniValue HeirList(); diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index ccf9da1bf..4ef143271 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -615,7 +615,7 @@ template int64_t LifetimeHeirContractFunds(struct CCcontract_info * and also for setting spending plan for the funds' owner and heir * @return fundingtxid handle for subsequent references to this heir funding plan */ -template UniValue HeirFund(uint64_t txfee, int64_t amount, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid) +template UniValue HeirFund(int64_t txfee, int64_t amount, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid) { UniValue result(UniValue::VOBJ); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); @@ -629,7 +629,8 @@ template UniValue HeirFund(uint64_t txfee, int64_t amount, std if (!heirPubkey.IsValid()) { std::cerr << "HeirFund() heirPubkey is not valid!" << std::endl; - return std::string(""); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "invalid heir pubkey")); } CPubKey myPubkey = pubkey2pk(Mypubkey()); @@ -689,12 +690,12 @@ template UniValue HeirFund(uint64_t txfee, int64_t amount, std } // if no these callers - it could not link -UniValue HeirFundCoinCaller(uint64_t txfee, int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid){ - return HeirFund(txfee, funds, heirName, heirPubkey, inactivityTimeSec, tokenid); +UniValue HeirFundCoinCaller(int64_t txfee, int64_t satoshis, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid){ + return HeirFund(txfee, satoshis, heirName, heirPubkey, inactivityTimeSec, tokenid); } -UniValue HeirFundTokenCaller(uint64_t txfee, int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid) { - return HeirFund(txfee, funds, heirName, heirPubkey, inactivityTimeSec, tokenid); +UniValue HeirFundTokenCaller(int64_t txfee, int64_t satoshis, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid) { + return HeirFund(txfee, satoshis, heirName, heirPubkey, inactivityTimeSec, tokenid); } /** @@ -702,7 +703,7 @@ UniValue HeirFundTokenCaller(uint64_t txfee, int64_t funds, std::string heirName * creates tx to add more funds to cryptocondition address for spending by either funds' owner or heir * @return result object with raw tx or error text */ -template UniValue _HeirAdd(uint256 fundingtxid, uint64_t txfee, int64_t amount, uint256 latesttxid, uint8_t funcId, uint256 tokenid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName, uint8_t hasHeirSpendingBegun) +template UniValue _HeirAdd(uint256 fundingtxid, int64_t txfee, int64_t amount, uint256 latesttxid, uint8_t funcId, uint256 tokenid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName, uint8_t hasHeirSpendingBegun) { UniValue result(UniValue::VOBJ); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); @@ -781,13 +782,11 @@ template UniValue _HeirAdd(uint256 fundingtxid, uint64_t txfee, i result.push_back(Pair("error", "can't find normal inputs for tx fee")); } - - return result; } -UniValue HeirAddCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount) { +UniValue HeirAddCaller(uint256 fundingtxid, int64_t txfee, std::string strAmount) { CPubKey ownerPubkey, heirPubkey; int64_t inactivityTimeSec; @@ -798,10 +797,27 @@ UniValue HeirAddCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount) { uint8_t hasHeirSpendingBegun = 0; if ((latesttxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun)) != zeroid) { - if (tokenid == zeroid) - return _HeirAdd(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); - else - return _HeirAdd(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + if (tokenid == zeroid) { + int64_t amount = (int64_t)(atof(strAmount.c_str()) * COIN); + if (amount <= 0) { + UniValue result(UniValue::VOBJ); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "invalid amount")); + return result; + } + + return _HeirAdd(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + } + else { + int64_t amount = atoll(strAmount.c_str()); + if (amount <= 0) { + UniValue result(UniValue::VOBJ); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "invalid amount")); + return result; + } + return _HeirAdd(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + } } else { UniValue result(UniValue::VOBJ); @@ -819,7 +835,7 @@ UniValue HeirAddCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount) { * creates tx to spend funds from cryptocondition address by either funds' owner or heir * @return result object with raw tx or error text */ -template UniValue _HeirClaim(uint256 fundingtxid, uint64_t txfee, int64_t amount, uint256 latesttxid, uint8_t funcId, uint256 tokenid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName, uint8_t hasHeirSpendingBegun) +template UniValue _HeirClaim(uint256 fundingtxid, int64_t txfee, int64_t amount, uint256 latesttxid, uint8_t funcId, uint256 tokenid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName, uint8_t hasHeirSpendingBegun) { UniValue result(UniValue::VOBJ); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); @@ -940,7 +956,7 @@ template UniValue _HeirClaim(uint256 fundingtxid, uint64_t txfe return result; } -UniValue HeirClaimCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount) { +UniValue HeirClaimCaller(uint256 fundingtxid, int64_t txfee, std::string strAmount) { CPubKey ownerPubkey, heirPubkey; int64_t inactivityTimeSec; @@ -951,10 +967,26 @@ UniValue HeirClaimCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount) { uint8_t hasHeirSpendingBegun = 0; if ((latesttxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun)) != zeroid) { - if( tokenid == zeroid ) - return _HeirClaim(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); - else - return _HeirClaim(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + if (tokenid == zeroid) { + int64_t amount = (int64_t)(atof(strAmount.c_str()) * COIN); + if (amount < 0) { + UniValue result(UniValue::VOBJ); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "invalid amount")); + return result; + } + return _HeirClaim(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + } + else { + int64_t amount = atoll(strAmount.c_str()); + if (amount <= 0) { + UniValue result(UniValue::VOBJ); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "invalid amount")); + return result; + } + return _HeirClaim(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + } } else { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 8e304c167..35325e1e0 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -7362,7 +7362,7 @@ UniValue heirfund(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); uint256 tokenid = zeroid; - uint64_t txfee; + int64_t txfee; int64_t amount; int64_t inactivitytime; std::string hex; @@ -7373,21 +7373,34 @@ UniValue heirfund(const UniValue& params, bool fHelp) return NullUniValue; if (fHelp || params.size() != 5 && params.size() != 6) - throw runtime_error("heirfundtokens fee funds heirname heirpubkey inactivitytime [tokenid]\n"); + throw runtime_error("heirfund txfee funds heirname heirpubkey inactivitytime [tokenid]\n"); if (ensure_CCrequirements() < 0) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); - txfee = atoll((char*)params[0].get_str().c_str()); - amount = atoll((char*)params[1].get_str().c_str()); + txfee = atoll(params[0].get_str().c_str()); + if (txfee < 0) + throw runtime_error("incorrect txfee param\n"); + + if(params.size() == 6) // tokens in satoshis: + amount = atoll(params[1].get_str().c_str()); + else // coins: + amount = atof(params[1].get_str().c_str()) * COIN; + + if( amount <= 0 ) + throw runtime_error("incorrect amount\n"); + name = params[2].get_str(); pubkey = ParseHex(params[3].get_str().c_str()); if( !pubkey2pk(pubkey).IsValid() ) throw runtime_error("incorrect pubkey\n"); - inactivitytime = atof((char*)params[4].get_str().c_str()); + inactivitytime = atoll(params[4].get_str().c_str()); + if (inactivitytime <= 0) + throw runtime_error("incorrect inactivity time param\n"); + if (params.size() == 6) { tokenid = Parseuint256((char*)params[5].get_str().c_str()); if(tokenid == zeroid) @@ -7406,7 +7419,7 @@ UniValue heiradd(const UniValue& params, bool fHelp) { UniValue result; uint256 fundingtxid; - uint64_t txfee; + int64_t txfee; int64_t amount; int64_t inactivitytime; std::string hex; @@ -7417,18 +7430,20 @@ UniValue heiradd(const UniValue& params, bool fHelp) return NullUniValue; if (fHelp || params.size() != 3) - throw runtime_error("heiraddtokens fee funds fundingtxid\n"); + throw runtime_error("heiradd txfee funds fundingtxid\n"); if (ensure_CCrequirements() < 0) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); - txfee = atoll((char*)params[0].get_str().c_str()); - amount = atoll((char*)params[1].get_str().c_str()); + txfee = atoll(params[0].get_str().c_str()); + if (txfee < 0) + throw runtime_error("incorrect txfee param\n"); + fundingtxid = Parseuint256((char*)params[2].get_str().c_str()); - result = HeirAddCaller(fundingtxid, txfee, amount); + result = HeirAddCaller(fundingtxid, txfee, params[1].get_str()); return result; } @@ -7437,7 +7452,6 @@ UniValue heirclaim(const UniValue& params, bool fHelp) UniValue result; // result(UniValue::VOBJ); uint256 fundingtxid; int64_t txfee; - int64_t amount; int64_t inactivitytime; std::string hex; std::vector pubkey; @@ -7448,18 +7462,20 @@ UniValue heirclaim(const UniValue& params, bool fHelp) return NullUniValue; if (fHelp || params.size() != 3) - throw runtime_error("heirclaimtokens fee funds fundingtxid\n"); + throw runtime_error("heirclaim txfee funds fundingtxid\n"); if (ensure_CCrequirements() < 0) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); - txfee = atoll((char*)params[0].get_str().c_str()); - amount = atoll((char*)params[1].get_str().c_str()); + txfee = atoll(params[0].get_str().c_str()); + if (txfee < 0) + throw runtime_error("incorrect txfee param\n"); + fundingtxid = Parseuint256((char*)params[2].get_str().c_str()); - result = HeirClaimCaller(fundingtxid, txfee, amount); + result = HeirClaimCaller(fundingtxid, txfee, params[1].get_str()); return result; } From 21ad10ac1591779052b89d96bffd6b0db24c1051 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 21 Jan 2019 22:33:50 +0500 Subject: [PATCH 621/643] check of vin's owner pubkeys added --- src/cc/heir.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 7 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 4ef143271..3891a34f4 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -400,6 +400,7 @@ uint8_t DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, uint256 &f return _DecodeHeirEitherOpRet(scriptPubKey, tokenid, dummyOwnerPubkey, dummyHeirPubkey, dummyInactivityTime, dummyHeirName, fundingTxidInOpret, hasHeirSpendingBegun, noLogging); } + /** * find the latest funding tx: it may be the first F tx or one of A or C tx's * Note: this function is also called from validation code (use non-locking calls) @@ -471,10 +472,24 @@ uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &toke if (tmpFuncId != 0 && fundingtxid == fundingTxidInOpret && (tokenid == zeroid || tokenid == tokenidInOpret)) { // check tokenid also if (blockHeight > maxBlockHeight) { - maxBlockHeight = blockHeight; - latesttxid = txid; - funcId = tmpFuncId; - hasHeirSpendingBegun = hasHeirSpendingBegunInOpret; + + // check owner pubkey in vins + bool hasVinOwner = false; + for (auto vin : regtx.vin) { + CPubKey vinPubkey = check_signing_pubkey(vin.scriptSig); + if (vinPubkey.IsValid() && vinPubkey == ownerPubkey) { + hasVinOwner = true; + break; + } + } + + // we ignore 'donations' tx (non-owner fundings) for calculating if heir is allowed to spend: + if (hasVinOwner) { + hasHeirSpendingBegun = hasHeirSpendingBegunInOpret; + maxBlockHeight = blockHeight; + latesttxid = txid; + funcId = tmpFuncId; + } //std::cerr << "FindLatestFundingTx() txid=" << latesttxid.GetHex() << " at blockHeight=" << maxBlockHeight // << " opreturn type=" << (char)(funcId ? funcId : ' ') << " hasHeirSpendingBegun=" << (int)hasHeirSpendingBegun << " - set as current lasttxid" << '\n'; @@ -615,7 +630,7 @@ template int64_t LifetimeHeirContractFunds(struct CCcontract_info * and also for setting spending plan for the funds' owner and heir * @return fundingtxid handle for subsequent references to this heir funding plan */ -template UniValue HeirFund(int64_t txfee, int64_t amount, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid) +template UniValue _HeirFund(int64_t txfee, int64_t amount, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid) { UniValue result(UniValue::VOBJ); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); @@ -656,6 +671,23 @@ template UniValue HeirFund(int64_t txfee, int64_t amount, std: if (change != 0) { // vout[1] mtx.vout.push_back(Helper::makeUserVout(change, myPubkey)); } + + // check my pubkey in vins + bool notMypubkey = false; + for (auto vin : mtx.vin) { + CPubKey vinPubkey = check_signing_pubkey(vin.scriptSig); + if (vinPubkey.IsValid() && vinPubkey != myPubkey) { + notMypubkey = true; + break; + } + } + // do not allow to sign non-owner vin: + if (notMypubkey) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "not the owner's key in the wallet")); + return result; + } + // add 1of2 vout validation pubkeys: std::vector voutTokenPubkeys; @@ -691,11 +723,11 @@ template UniValue HeirFund(int64_t txfee, int64_t amount, std: // if no these callers - it could not link UniValue HeirFundCoinCaller(int64_t txfee, int64_t satoshis, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid){ - return HeirFund(txfee, satoshis, heirName, heirPubkey, inactivityTimeSec, tokenid); + return _HeirFund(txfee, satoshis, heirName, heirPubkey, inactivityTimeSec, tokenid); } UniValue HeirFundTokenCaller(int64_t txfee, int64_t satoshis, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid) { - return HeirFund(txfee, satoshis, heirName, heirPubkey, inactivityTimeSec, tokenid); + return _HeirFund(txfee, satoshis, heirName, heirPubkey, inactivityTimeSec, tokenid); } /** @@ -749,6 +781,22 @@ template UniValue _HeirAdd(uint256 fundingtxid, int64_t txfee, in if (change != 0) { // vout[1] mtx.vout.push_back(Helper::makeUserVout(change, myPubkey)); } + + // check my pubkey in vins + bool notMypubkey = false; + for (auto vin : mtx.vin) { + CPubKey vinPubkey = check_signing_pubkey(vin.scriptSig); + if (vinPubkey.IsValid() && vinPubkey != myPubkey) { + notMypubkey = true; + break; + } + } + // do not allow to sign non-owner vin: + if (notMypubkey) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "not the owner's key in the wallet")); + return result; + } // add 1of2 vout validation pubkeys - needed only for tokens: std::vector voutTokenPubkeys; From 56d68d816638321b562f4bfe940fb894929b93aa Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 13:11:09 +0500 Subject: [PATCH 622/643] corr checking for owner pubkey in vins (is owner's or is other's) --- src/cc/heir.cpp | 86 ++++++++++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 36 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 3891a34f4..2ebf4b490 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -400,6 +400,22 @@ uint8_t DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, uint256 &f return _DecodeHeirEitherOpRet(scriptPubKey, tokenid, dummyOwnerPubkey, dummyHeirPubkey, dummyInactivityTime, dummyHeirName, fundingTxidInOpret, hasHeirSpendingBegun, noLogging); } +// check if pubkey is in vins +void CheckVinPubkey(std::vector vins, CPubKey pubkey, bool &hasPubkey, bool &hasOtherPubkey) { + + hasPubkey = false; + hasOtherPubkey = false; + + for (auto vin : vins) { + CPubKey vinPubkey = check_signing_pubkey(vin.scriptSig); + if (vinPubkey.IsValid()) { + if (vinPubkey == pubkey) + hasPubkey = true; + if (vinPubkey != pubkey) + hasOtherPubkey = true; + } + } +} /** * find the latest funding tx: it may be the first F tx or one of A or C tx's @@ -474,17 +490,13 @@ uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &toke if (blockHeight > maxBlockHeight) { // check owner pubkey in vins - bool hasVinOwner = false; - for (auto vin : regtx.vin) { - CPubKey vinPubkey = check_signing_pubkey(vin.scriptSig); - if (vinPubkey.IsValid() && vinPubkey == ownerPubkey) { - hasVinOwner = true; - break; - } - } + bool isOwner = false; + bool isNonOwner = false; - // we ignore 'donations' tx (non-owner fundings) for calculating if heir is allowed to spend: - if (hasVinOwner) { + CheckVinPubkey(regtx.vin, ownerPubkey, isOwner, isNonOwner); + + // we ignore 'donations' tx (with non-owner inputs) for calculating if heir is allowed to spend: + if (isOwner && !isNonOwner) { hasHeirSpendingBegun = hasHeirSpendingBegunInOpret; maxBlockHeight = blockHeight; latesttxid = txid; @@ -672,23 +684,19 @@ template UniValue _HeirFund(int64_t txfee, int64_t amount, std mtx.vout.push_back(Helper::makeUserVout(change, myPubkey)); } - // check my pubkey in vins - bool notMypubkey = false; - for (auto vin : mtx.vin) { - CPubKey vinPubkey = check_signing_pubkey(vin.scriptSig); - if (vinPubkey.IsValid() && vinPubkey != myPubkey) { - notMypubkey = true; - break; - } - } - // do not allow to sign non-owner vin: - if (notMypubkey) { + // check owner pubkey in vins + bool isMypubkey = false; + bool isNotMypubkey = false; + + CheckVinPubkey(mtx.vin, myPubkey, isMypubkey, isNotMypubkey); + + // for initial funding do not allow to sign by non-owner key: + if (isNotMypubkey) { result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "not the owner's key in the wallet")); + result.push_back(Pair("error", "using non-owner inputs not allowed")); return result; } - // add 1of2 vout validation pubkeys: std::vector voutTokenPubkeys; voutTokenPubkeys.push_back(myPubkey); @@ -782,22 +790,28 @@ template UniValue _HeirAdd(uint256 fundingtxid, int64_t txfee, in mtx.vout.push_back(Helper::makeUserVout(change, myPubkey)); } - // check my pubkey in vins - bool notMypubkey = false; - for (auto vin : mtx.vin) { - CPubKey vinPubkey = check_signing_pubkey(vin.scriptSig); - if (vinPubkey.IsValid() && vinPubkey != myPubkey) { - notMypubkey = true; - break; - } - } - // do not allow to sign non-owner vin: - if (notMypubkey) { + // check owner pubkey in vins + bool isMypubkey = false; + bool isNotMypubkey = false; + + CheckVinPubkey(mtx.vin, myPubkey, isMypubkey, isNotMypubkey); + + // for additional funding do not allow to sign by both owner and non-owner keys (is this a donation or not?): + if (isMypubkey && isNotMypubkey) { result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "not the owner's key in the wallet")); + result.push_back(Pair("error", "using both owner and non-owner inputs is not allowed")); return result; } + // warn the user he's making a donation if this is all non-owner keys: + if (isNotMypubkey) { + result.push_back(Pair("result", "warning")); + result.push_back(Pair("warning", "you are about to make a donation to heir fund")); + } + else { + result.push_back(Pair("result", "success")); + } + // add 1of2 vout validation pubkeys - needed only for tokens: std::vector voutTokenPubkeys; voutTokenPubkeys.push_back(ownerPubkey); @@ -808,11 +822,11 @@ template UniValue _HeirAdd(uint256 fundingtxid, int64_t txfee, in Helper::makeAddOpRet(tokenid, voutTokenPubkeys, fundingtxid, hasHeirSpendingBegun))); if (!rawhextx.empty()) { - result.push_back(Pair("result", "success")); result.push_back(Pair("hextx", rawhextx)); } else { std::cerr << "HeirAdd error in FinalizeCCtx" << std::endl; + result.clear(); result.push_back(Pair("result", "error")); result.push_back(Pair("error", "sign error")); } From e6f41e085ed727e9103816ed4b07d3e358973f5a Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 13:49:34 +0500 Subject: [PATCH 623/643] added real owner inactivity time in heirinfo --- src/cc/heir.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 2ebf4b490..bbc54e232 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -1197,6 +1197,14 @@ UniValue HeirInfo(uint256 fundingtxid) result.push_back(Pair("spending allowed for the heir", stream.str().c_str())); stream.str(""); stream.clear(); + + // adding owner current inactivity time: + if (!hasHeirSpendingBegun && durationSec <= inactivityTimeSec) { + stream << durationSec; + result.push_back(Pair("owner inactivity time", stream.str().c_str())); + stream.str(""); + stream.clear(); + } result.push_back(Pair("result", "success")); } From bd2903762880424cb523d0340a1e852e085d1c24 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 13:59:39 +0500 Subject: [PATCH 624/643] string "sec" (seconds) added to heirinfo --- src/cc/heir.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index bbc54e232..ff8d77209 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -1184,13 +1184,13 @@ UniValue HeirInfo(uint256 fundingtxid) } stream << inactivityTimeSec; - result.push_back(Pair("inactivity time setting", stream.str().c_str())); + result.push_back(Pair("inactivity time setting, sec", stream.str().c_str())); stream.str(""); stream.clear(); if (!hasHeirSpendingBegun) { // we do not need find duration if the spending already has begun durationSec = CCduration(numblocks, latestFundingTxid); - std::cerr << "HeirInfo() duration=" << durationSec << " inactivityTime=" << inactivityTimeSec << " numblocks=" << numblocks << '\n'; + std::cerr << "HeirInfo() duration (sec)=" << durationSec << " inactivityTime (sec)=" << inactivityTimeSec << " numblocks=" << numblocks << '\n'; } stream << std::boolalpha << (hasHeirSpendingBegun || durationSec > inactivityTimeSec); @@ -1201,7 +1201,7 @@ UniValue HeirInfo(uint256 fundingtxid) // adding owner current inactivity time: if (!hasHeirSpendingBegun && durationSec <= inactivityTimeSec) { stream << durationSec; - result.push_back(Pair("owner inactivity time", stream.str().c_str())); + result.push_back(Pair("owner inactivity time, sec", stream.str().c_str())); stream.str(""); stream.clear(); } From a87816f5513a9bb52c7e8b1549ad2022cd144734 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 14:20:33 +0500 Subject: [PATCH 625/643] test rpc serialization Sleep added --- src/cc/heir.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index ff8d77209..c0f0c8124 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -1116,6 +1116,8 @@ UniValue HeirInfo(uint256 fundingtxid) std::ostringstream stream; std::string msg; + Sleep(10000); + result.push_back(Pair("fundingtxid", fundingtxid.GetHex())); result.push_back(Pair("name", heirName.c_str())); From 92ab8dd7d8798bd054786070590e485a9f0b8590 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 14:25:17 +0500 Subject: [PATCH 626/643] linux sleep added --- src/cc/heir.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index c0f0c8124..32e4195dc 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -16,6 +16,8 @@ #include "CCHeir.h" #include "heir_validate.h" +#include + class CoinHelper; class TokenHelper; @@ -1116,7 +1118,7 @@ UniValue HeirInfo(uint256 fundingtxid) std::ostringstream stream; std::string msg; - Sleep(10000); + sleep(10); result.push_back(Pair("fundingtxid", fundingtxid.GetHex())); result.push_back(Pair("name", heirName.c_str())); From 2d20276606de621c280333882bc171a0a9e7eef5 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 15:03:52 +0500 Subject: [PATCH 627/643] better var naming for check vin's pubkey algo --- src/cc/heir.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 32e4195dc..ffa07e2f5 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -687,13 +687,13 @@ template UniValue _HeirFund(int64_t txfee, int64_t amount, std } // check owner pubkey in vins - bool isMypubkey = false; - bool isNotMypubkey = false; + bool hasMypubkey = false; + bool hasNotMypubkey = false; - CheckVinPubkey(mtx.vin, myPubkey, isMypubkey, isNotMypubkey); + CheckVinPubkey(mtx.vin, myPubkey, hasMypubkey, hasNotMypubkey); // for initial funding do not allow to sign by non-owner key: - if (isNotMypubkey) { + if (hasNotMypubkey) { result.push_back(Pair("result", "error")); result.push_back(Pair("error", "using non-owner inputs not allowed")); return result; @@ -793,20 +793,20 @@ template UniValue _HeirAdd(uint256 fundingtxid, int64_t txfee, in } // check owner pubkey in vins - bool isMypubkey = false; - bool isNotMypubkey = false; + bool hasMypubkey = false; + bool hasNotMypubkey = false; - CheckVinPubkey(mtx.vin, myPubkey, isMypubkey, isNotMypubkey); + CheckVinPubkey(mtx.vin, myPubkey, hasMypubkey, hasNotMypubkey); // for additional funding do not allow to sign by both owner and non-owner keys (is this a donation or not?): - if (isMypubkey && isNotMypubkey) { + if (hasMypubkey && hasNotMypubkey) { result.push_back(Pair("result", "error")); result.push_back(Pair("error", "using both owner and non-owner inputs is not allowed")); return result; } // warn the user he's making a donation if this is all non-owner keys: - if (isNotMypubkey) { + if (hasNotMypubkey) { result.push_back(Pair("result", "warning")); result.push_back(Pair("warning", "you are about to make a donation to heir fund")); } @@ -1118,7 +1118,7 @@ UniValue HeirInfo(uint256 fundingtxid) std::ostringstream stream; std::string msg; - sleep(10); + //sleep(10); result.push_back(Pair("fundingtxid", fundingtxid.GetHex())); result.push_back(Pair("name", heirName.c_str())); From 98c5280e6b95b37f2a704a6d5433533366dad263 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 18:31:03 +0500 Subject: [PATCH 628/643] corr marker to cc unspendable for F, added validation to prevent its spending added marker to prevent archiving for A --- src/cc/heir.cpp | 33 +++++++++++++---------- src/cc/heir_validate.h | 60 +++++++++++++++++++++++++++++++----------- 2 files changed, 64 insertions(+), 29 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index ffa07e2f5..883b11da2 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -16,8 +16,6 @@ #include "CCHeir.h" #include "heir_validate.h" -#include - class CoinHelper; class TokenHelper; @@ -653,6 +651,8 @@ template UniValue _HeirFund(int64_t txfee, int64_t amount, std cp = CCinit(&C, Helper::getMyEval()); if (txfee == 0) txfee = 10000; + + int64_t markerfee = 10000; //std::cerr << "HeirFund() amount=" << amount << " txfee=" << txfee << " heirPubkey IsValid()=" << heirPubkey.IsValid() << " inactivityTime(sec)=" << inactivityTimeSec << " tokenid=" << tokenid.GetHex() << std::endl; @@ -664,17 +664,18 @@ template UniValue _HeirFund(int64_t txfee, int64_t amount, std CPubKey myPubkey = pubkey2pk(Mypubkey()); - if (AddNormalinputs(mtx, myPubkey, txfee, 3) > 0) { // txfee for miners + if (AddNormalinputs(mtx, myPubkey, markerfee, 3) > 0) { int64_t inputs, change; - if ((inputs=Helper::addOwnerInputs(tokenid, mtx, myPubkey, amount, (int32_t)64)) > 0) { // 2 x txfee: 1st for marker vout, 2nd to miners - //mtx.vout.push_back(MakeTokensCC1of2vout(/*Helper::getMyEval()*/EVAL_HEIR, amount, myPubkey, heirPubkey)); // add cryptocondition to spend amount for either pk - mtx.vout.push_back(Helper::make1of2Vout(amount, myPubkey, heirPubkey)); + if ((inputs=Helper::addOwnerInputs(tokenid, mtx, myPubkey, amount, (int32_t)64)) > 0) { + + mtx.vout.push_back(Helper::make1of2Vout(amount, myPubkey, heirPubkey)); // add a marker for finding all plans in HeirList() // TODO: change marker either to cc or normal txidaddr unspendable CPubKey heirUnspendablePubKey = GetUnspendable(cp, 0); - mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(heirUnspendablePubKey)) << OP_CHECKSIG)); // TODO: do we need this marker? + // mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(heirUnspendablePubKey)) << OP_CHECKSIG)); <-- bad marker cause it was spendable by anyone + MakeCC1vout(EVAL_HEIR, txfee, heirUnspendablePubKey); // this marker spending is disabled in the validation code // calc and add change vout: if (inputs > amount) @@ -782,7 +783,11 @@ template UniValue _HeirAdd(uint256 fundingtxid, int64_t txfee, in // add cryptocondition to spend this funded amount for either pk mtx.vout.push_back(Helper::make1of2Vout(amount, ownerPubkey, heirPubkey)); - + + char markeraddr[64]; + CPubKey markerPubkey = CCtxidaddr(markeraddr, fundingtxid); + mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(markerPubkey)) << OP_CHECKSIG)); // marker to prevent archiving of the funds add vouts + if (inputs > amount) change = (inputs - amount); // -txfee <-- txfee pays user @@ -1232,10 +1237,10 @@ UniValue HeirInfo(uint256 fundingtxid) template void _HeirList(struct CCcontract_info *cp, UniValue &result) { std::vector> unspentOutputs; - char coinaddr[64]; - CPubKey ccPubKeyEmpty; - GetCCaddress(cp, coinaddr, ccPubKeyEmpty); - SetCCunspents(unspentOutputs, cp->normaladdr); + char markeraddr[64]; + + GetCCaddress(cp, markeraddr, GetUnspendable(cp, NULL)); + SetCCunspents(unspentOutputs, markeraddr); //std::cerr << "HeirList() finding heir marker from Heir contract addr=" << cp->normaladdr << " unspentOutputs.size()=" << unspentOutputs.size() << '\n'; @@ -1283,10 +1288,10 @@ UniValue HeirList() struct CCcontract_info *cpHeir, *cpTokens, heirC, tokenC; // NOTE we must use a separate 'C' structure for each CCinit! cpHeir = CCinit(&heirC, EVAL_HEIR); - cpTokens = CCinit(&tokenC, EVAL_TOKENS); + //cpTokens = CCinit(&tokenC, EVAL_TOKENS); _HeirList(cpHeir, result); - _HeirList(cpTokens, result); + //_HeirList(cpTokens, result); not used anymore return result; } diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index c4bb7ea60..7dd09a427 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -125,8 +125,8 @@ class CValidatorBase public: CValidatorBase(CCcontract_info* cp) : m_cp(cp) {} virtual bool isVinValidator() const = 0; - virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const = 0; - virtual bool validateVout(CTxOut vout, std::string& message) const = 0; + virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const = 0; + virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const = 0; protected: CCcontract_info * m_cp; @@ -258,10 +258,10 @@ private: if (v->isVinValidator()) // validate this vin and previous vout: - result = v->validateVin(pTx->vin[iv], pPrevTx->vout[pTx->vin[iv].prevout.n], refMessage); + result = v->validateVin(pTx->vin[iv], pPrevTx->vout[pTx->vin[iv].prevout.n], pTx->vin[iv].prevout.n, refMessage); else // if it is vout validator pass the previous tx vout: - result = v->validateVout( pPrevTx->vout[pTx->vin[iv].prevout.n], refMessage); + result = v->validateVout( pPrevTx->vout[pTx->vin[iv].prevout.n], pTx->vin[iv].prevout.n, refMessage); if (!result) { return result; } @@ -359,7 +359,7 @@ private: if (!v->isVinValidator()) { // if this is a 'in' validation plan then pass the previous tx vout: - bool result = v->validateVout(pTx->vout[iv], refMessage); + bool result = v->validateVout(pTx->vout[iv], iv, refMessage); if (!result) return result; } @@ -402,7 +402,7 @@ public: m_fundingOpretScript(opRetScript), m_customMessage(customMessage), CValidatorBase(cp) {} virtual bool isVinValidator() const { return false; } - virtual bool validateVout(CTxOut vout, std::string& message) const + virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const { //std::cerr << "CCC1of2AddressValidator::validateVout() entered" << std::endl; CPubKey ownerPubkey, heirPubkey; @@ -438,7 +438,7 @@ public: std::cerr << "CCC1of2AddressValidator::validateVout() exits with false: " << message << std::endl; return false; } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return false; } + virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return false; } private: CScript m_fundingOpretScript; @@ -456,7 +456,7 @@ public: : m_fundingOpretScript(opRetScript), m_checkNormals(checkNormals), CValidatorBase(cp) { } virtual bool isVinValidator() const { return false; } - virtual bool validateVout(CTxOut vout, std::string& message) const + virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const { //std::cerr << "CMyPubkeyVoutValidator::validateVout() entered" << std::endl; @@ -498,7 +498,7 @@ public: message = std::string("invalid pubkey"); return false; } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } + virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; } private: CScript m_fundingOpretScript; @@ -516,7 +516,7 @@ public: : m_fundingOpretScript(opRetScript), m_latesttxid(latesttxid), m_isHeirSpendingBegan(isHeirSpendingBegan), CValidatorBase(cp) {} virtual bool isVinValidator() const { return false; } - virtual bool validateVout(CTxOut vout, std::string& message) const + virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const { //std::cerr << "CHeirSpendValidator::validateVout() entered" << std::endl; @@ -554,7 +554,7 @@ public: // this is not heir: return true; } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } + virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; } private: CScript m_fundingOpretScript; @@ -572,7 +572,7 @@ public: : m_fundingOpretScript(opret), CValidatorBase(cp) {} virtual bool isVinValidator() const { return false; } - virtual bool validateVout(CTxOut vout, std::string& message) const + virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const { //std::cerr << "COpRetValidator::validateVout() entered" << std::endl; @@ -607,12 +607,42 @@ public: //std::cerr << "COpRetValidator::validateVout() exits with true" << std::endl; return true; } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } + virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; } private: CScript m_fundingOpretScript; }; + +/* +** marker spending prevention validator, +** returns false if for tx with funcid=F vout.1 is being tried to spend +*/ +template class CMarkerValidator : CValidatorBase +{ +public: + CMarkerValidator(CCcontract_info* cp) + : CValidatorBase(cp) { } + + virtual bool isVinValidator() const { return false; } // this is vout validator + virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const { + + uint256 fundingTxidInOpret = zeroid, dummyTxid, tokenid = zeroid, initialTokenid = zeroid; + uint8_t dummyIsHeirSpendingBegan; + + uint8_t funcId = DecodeHeirEitherOpRet(m_opret, tokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan, true); + + if( funcId == 'F' && vout_n == 1 ) + return false; + + return true; + } + virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; } + +private: + CScript m_fundingOpretScript; +}; + /** * empty validator always returns true */ @@ -623,8 +653,8 @@ public: : CValidatorBase(cp) { } virtual bool isVinValidator() const { return false; } - virtual bool validateVout(CTxOut vout, std::string& message) const { return true; } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } + virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const { return true; } + virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; } }; From 426aa32dd50e7010eb1465032317b4b146dc5f3b Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 19:25:25 +0500 Subject: [PATCH 629/643] corr F tx marker protection validation code --- src/cc/heir.cpp | 1 + src/cc/heir_validate.h | 42 +++++++++++++++++++++--------------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 883b11da2..69bf1a757 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -56,6 +56,7 @@ template bool RunValidationPlans(uint8_t funcId, struct CCcont // only for tokens: CMyPubkeyVoutValidator ownerCCaddrValidator(cp, fundingOpretScript, false); // check if this correct owner's cc user addr corresponding to opret COpRetValidator opRetValidator(cp, fundingOpretScript); // compare opRets in this and last tx + CMarkerValidator markerValidator(cp); // initial tx marker spending protection CNullValidator nullValidator(cp); switch (funcId) { diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index 7dd09a427..14e608bc2 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -125,7 +125,7 @@ class CValidatorBase public: CValidatorBase(CCcontract_info* cp) : m_cp(cp) {} virtual bool isVinValidator() const = 0; - virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const = 0; + virtual bool validateVin(CTxIn vin, std::vector prevVout, int32_t prevN, std::string& message) const = 0; virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const = 0; protected: @@ -258,7 +258,7 @@ private: if (v->isVinValidator()) // validate this vin and previous vout: - result = v->validateVin(pTx->vin[iv], pPrevTx->vout[pTx->vin[iv].prevout.n], pTx->vin[iv].prevout.n, refMessage); + result = v->validateVin(pTx->vin[iv], pPrevTx->vout, pTx->vin[iv].prevout.n, refMessage); else // if it is vout validator pass the previous tx vout: result = v->validateVout( pPrevTx->vout[pTx->vin[iv].prevout.n], pTx->vin[iv].prevout.n, refMessage); @@ -438,7 +438,7 @@ public: std::cerr << "CCC1of2AddressValidator::validateVout() exits with false: " << message << std::endl; return false; } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return false; } + virtual bool validateVin(CTxIn vin, std::vector prevVout, int32_t prevN, std::string& message) const { return false; } private: CScript m_fundingOpretScript; @@ -498,7 +498,7 @@ public: message = std::string("invalid pubkey"); return false; } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; } + virtual bool validateVin(CTxIn vin, std::vector prevVout, int32_t prevN, std::string& message) const { return true; } private: CScript m_fundingOpretScript; @@ -554,7 +554,7 @@ public: // this is not heir: return true; } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; } + virtual bool validateVin(CTxIn vin, std::vector prevVout, int32_t prevN, std::string& message) const { return true; } private: CScript m_fundingOpretScript; @@ -607,17 +607,17 @@ public: //std::cerr << "COpRetValidator::validateVout() exits with true" << std::endl; return true; } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; } + virtual bool validateVin(CTxIn vin, std::vector prevVout, int32_t prevN, std::string& message) const { return true; } private: CScript m_fundingOpretScript; }; -/* -** marker spending prevention validator, -** returns false if for tx with funcid=F vout.1 is being tried to spend -*/ +/** + * marker spending prevention validator, + * returns false if for tx with funcid=F vout.1 is being tried to spend + */ template class CMarkerValidator : CValidatorBase { public: @@ -625,22 +625,22 @@ public: : CValidatorBase(cp) { } virtual bool isVinValidator() const { return false; } // this is vout validator - virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const { + virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const { return true; } + virtual bool validateVin(CTxIn vin, std::vector prevVout, int32_t prevN, std::string& message) const { uint256 fundingTxidInOpret = zeroid, dummyTxid, tokenid = zeroid, initialTokenid = zeroid; uint8_t dummyIsHeirSpendingBegan; - uint8_t funcId = DecodeHeirEitherOpRet(m_opret, tokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan, true); + if (prevVout.size() > 0) { - if( funcId == 'F' && vout_n == 1 ) - return false; - - return true; + // get funcId for prev tx: + uint8_t funcId = DecodeHeirEitherOpRet(prevVout[prevVout.size()-1].scriptPubKey, tokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan, true); + if (funcId == 'F' && prevN == 1) // do not allow to spend 'F' marker's vout + return false; + } + + return true; } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; } - -private: - CScript m_fundingOpretScript; }; /** @@ -654,7 +654,7 @@ public: virtual bool isVinValidator() const { return false; } virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const { return true; } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; } + virtual bool validateVin(CTxIn vin, std::vector prevVout, int32_t prevN, std::string& message) const { return true; } }; From 6c26e91376209daf8ff0b92ce57b3e658585186b Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 19:48:24 +0500 Subject: [PATCH 630/643] corr cpHeir init in _heirFund for marker enabled logging --- src/cc/heir.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 69bf1a757..a5533c0c1 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -674,7 +674,9 @@ template UniValue _HeirFund(int64_t txfee, int64_t amount, std // add a marker for finding all plans in HeirList() // TODO: change marker either to cc or normal txidaddr unspendable - CPubKey heirUnspendablePubKey = GetUnspendable(cp, 0); + struct CCcontract_info *cpHeir, heirC; + cpHeir = CCinit(&heirC, EVAL_HEIR); + CPubKey heirUnspendablePubKey = GetUnspendable(cpHeir, 0); // mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(heirUnspendablePubKey)) << OP_CHECKSIG)); <-- bad marker cause it was spendable by anyone MakeCC1vout(EVAL_HEIR, txfee, heirUnspendablePubKey); // this marker spending is disabled in the validation code @@ -1235,7 +1237,7 @@ UniValue HeirInfo(uint256 fundingtxid) * @return list of heir plan handles (fundingtxid) */ -template void _HeirList(struct CCcontract_info *cp, UniValue &result) +void _HeirList(struct CCcontract_info *cp, UniValue &result) { std::vector> unspentOutputs; char markeraddr[64]; @@ -1243,7 +1245,7 @@ template void _HeirList(struct CCcontract_info *cp, UniValue &r GetCCaddress(cp, markeraddr, GetUnspendable(cp, NULL)); SetCCunspents(unspentOutputs, markeraddr); - //std::cerr << "HeirList() finding heir marker from Heir contract addr=" << cp->normaladdr << " unspentOutputs.size()=" << unspentOutputs.size() << '\n'; + std::cerr << "HeirList() finding heir marker from unspendable addr=" << markeraddr << " unspentOutputs.size()=" << unspentOutputs.size() << '\n'; // TODO: move marker to special cc addr to prevent checking all tokens for (std::vector>::const_iterator it = unspentOutputs.begin(); it != unspentOutputs.end(); it++) { @@ -1252,7 +1254,7 @@ template void _HeirList(struct CCcontract_info *cp, UniValue &r uint256 tokenid; int32_t vout = (int32_t)it->first.index; - //std::cerr << "HeirList() checking txid=" << txid.GetHex() << " vout=" << vout << '\n'; + std::cerr << "HeirList() checking txid=" << txid.GetHex() << " vout=" << vout << '\n'; CTransaction fundingtx; if (GetTransaction(txid, fundingtx, hashBlock, false)) { @@ -1291,7 +1293,7 @@ UniValue HeirList() cpHeir = CCinit(&heirC, EVAL_HEIR); //cpTokens = CCinit(&tokenC, EVAL_TOKENS); - _HeirList(cpHeir, result); + _HeirList(cpHeir, result); //_HeirList(cpTokens, result); not used anymore return result; From 28d090c05ea324444184a1e03b3f29151894782e Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 20:02:20 +0500 Subject: [PATCH 631/643] corr adding marker vout for F --- src/cc/heir.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index a5533c0c1..993c7bb5b 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -678,7 +678,7 @@ template UniValue _HeirFund(int64_t txfee, int64_t amount, std cpHeir = CCinit(&heirC, EVAL_HEIR); CPubKey heirUnspendablePubKey = GetUnspendable(cpHeir, 0); // mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(heirUnspendablePubKey)) << OP_CHECKSIG)); <-- bad marker cause it was spendable by anyone - MakeCC1vout(EVAL_HEIR, txfee, heirUnspendablePubKey); // this marker spending is disabled in the validation code + mtx.vout.push_back(MakeCC1vout(EVAL_HEIR, markerfee, heirUnspendablePubKey)); // this marker spending is disabled in the validation code // calc and add change vout: if (inputs > amount) @@ -762,6 +762,8 @@ template UniValue _HeirAdd(uint256 fundingtxid, int64_t txfee, in if (txfee == 0) txfee = 10000; + int64_t markerfee = 10000; + CPubKey myPubkey = pubkey2pk(Mypubkey()); // check if it is the owner @@ -771,7 +773,7 @@ template UniValue _HeirAdd(uint256 fundingtxid, int64_t txfee, in return result; } - if (AddNormalinputs(mtx, myPubkey, txfee, 3) > 0) { // txfee for miners + if (AddNormalinputs(mtx, myPubkey, markerfee, 3) > 0) { // some for marker int64_t inputs, change; @@ -789,7 +791,7 @@ template UniValue _HeirAdd(uint256 fundingtxid, int64_t txfee, in char markeraddr[64]; CPubKey markerPubkey = CCtxidaddr(markeraddr, fundingtxid); - mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(markerPubkey)) << OP_CHECKSIG)); // marker to prevent archiving of the funds add vouts + mtx.vout.push_back(CTxOut(markerfee, CScript() << ParseHex(HexStr(markerPubkey)) << OP_CHECKSIG)); // marker to prevent archiving of the funds add vouts if (inputs > amount) change = (inputs - amount); // -txfee <-- txfee pays user From 3865cae643c701742cdb57c667bbd02248f8c85c Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 20:21:45 +0500 Subject: [PATCH 632/643] added test to try to spend heir marker F --- src/rpc/server.cpp | 1 + src/rpc/server.h | 2 ++ src/wallet/rpcwallet.cpp | 27 +++++++++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 1eaabdbde..82a400e71 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -538,6 +538,7 @@ static const CRPCCommand vRPCCommands[] = /* Not shown in help */ { "hidden", "setmocktime", &setmocktime, true }, { "hidden", "test_ac", &test_ac, true }, + { "hidden", "test_heirmarker", &test_heirmarker, true }, #ifdef ENABLE_WALLET /* Wallet */ diff --git a/src/rpc/server.h b/src/rpc/server.h index 53bbd4c21..3edc85ebf 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -471,6 +471,8 @@ extern UniValue paxprices(const UniValue& params, bool fHelp); extern UniValue paxdeposit(const UniValue& params, bool fHelp); extern UniValue paxwithdraw(const UniValue& params, bool fHelp); +// test rpc: extern UniValue test_ac(const UniValue& params, bool fHelp); +extern UniValue test_heirmarker(const UniValue& params, bool fHelp); #endif // BITCOIN_RPCSERVER_H diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 35325e1e0..76ca2cf8d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -7641,4 +7641,31 @@ UniValue test_ac(const UniValue& params, bool fHelp) cp = CCinit(&C, EVAL_HEIR); return(FinalizeCCTx(0, cp, mtx, myPubkey, txfee, opret)); +} + +UniValue test_heirmarker(const UniValue& params, bool fHelp) +{ + // make fake token tx: + struct CCcontract_info *cp, C; + + if (fHelp || (params.size() != 4)) + throw runtime_error("incorrect params\n"); + if (ensure_CCrequirements() < 0) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + + uint256 fundingtxid = Parseuint256((char *)params[3].get_str().c_str()); + + CPubKey myPubkey = pubkey2pk(Mypubkey()); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + + mtx.vin.push_back(CTxIn(fundingtxid, 1)); + mtx.vout.push_back(MakeCC1vout(EVAL_HEIR, 10000, myPubkey)); + + CScript opret; + fundingtxid = revuint256(fundingtxid); + + opret << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_HEIR << (uint8_t)'C' << fundingtxid << (uint8_t)0); + + cp = CCinit(&C, EVAL_HEIR); + return(FinalizeCCTx(0, cp, mtx, myPubkey, 10000, opret)); } \ No newline at end of file From 098ba877fb3a0d90cc83082bf20802d7aec7b402 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 20:37:41 +0500 Subject: [PATCH 633/643] corr test code for spending marker F --- src/cc/heir_validate.h | 5 +++-- src/wallet/rpcwallet.cpp | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index 14e608bc2..fd414461e 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -635,10 +635,11 @@ public: // get funcId for prev tx: uint8_t funcId = DecodeHeirEitherOpRet(prevVout[prevVout.size()-1].scriptPubKey, tokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan, true); - if (funcId == 'F' && prevN == 1) // do not allow to spend 'F' marker's vout + if (funcId == 'F' && prevN == 1) { // do not allow to spend 'F' marker's vout + message = std::string("spending marker not allowed"); return false; + } } - return true; } }; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 76ca2cf8d..c1cf25b41 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -7648,16 +7648,20 @@ UniValue test_heirmarker(const UniValue& params, bool fHelp) // make fake token tx: struct CCcontract_info *cp, C; - if (fHelp || (params.size() != 4)) + if (fHelp || (params.size() != 1)) throw runtime_error("incorrect params\n"); if (ensure_CCrequirements() < 0) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - uint256 fundingtxid = Parseuint256((char *)params[3].get_str().c_str()); + uint256 fundingtxid = Parseuint256((char *)params[0].get_str().c_str()); CPubKey myPubkey = pubkey2pk(Mypubkey()); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + int64_t normalInputs = AddNormalinputs(mtx, myPubkey, 10000, 60); + if (normalInputs < 10000) + throw runtime_error("not enough normals\n"); + mtx.vin.push_back(CTxIn(fundingtxid, 1)); mtx.vout.push_back(MakeCC1vout(EVAL_HEIR, 10000, myPubkey)); From 8a15610e445b1bc9db91bff96ae1807cf30eae3d Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 21:03:08 +0500 Subject: [PATCH 634/643] corr marker validator --- src/cc/heir.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 993c7bb5b..3070ed9ef 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -60,10 +60,10 @@ template bool RunValidationPlans(uint8_t funcId, struct CCcont CNullValidator nullValidator(cp); switch (funcId) { - case 'F': // fund tokens + case 'F': // fund tokens (only for tokens) // vin validation plan: vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &nullValidator); // txfee vin - vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &ownerCCaddrValidator); // check cc owner addr + vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &markerValidator, &ownerCCaddrValidator); // check cc owner addr // vout validation plan: voutPlan.pushValidators(0, &cc1of2ValidatorThis); // check 1of2 addr funding @@ -71,10 +71,10 @@ template bool RunValidationPlans(uint8_t funcId, struct CCcont // no checking for opret yet break; - case 'A': // add tokens + case 'A': // add tokens (only for tokens) // vin validation plan: vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &nullValidator); // txfee vin - vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &ownerCCaddrValidator); // check cc owner addr + vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &markerValidator, &ownerCCaddrValidator); // check cc owner addr // vout validation plan: voutPlan.pushValidators(0, &cc1of2ValidatorThis); // check 1of2 addr funding @@ -82,10 +82,10 @@ template bool RunValidationPlans(uint8_t funcId, struct CCcont voutPlan.pushValidators(numvouts - 1, &opRetValidator); // opreturn check, NOTE: only for C or A: break; - case 'C': + case 'C': // spend coins or tokens // vin validation plan: vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &nullValidator); // txfee vin - vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &cc1of2ValidatorThis); // cc1of2 funding addr + vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &markerValidator, &cc1of2ValidatorThis); // cc1of2 funding addr // vout validation plan: voutPlan.pushValidators(0, &heirSpendValidator); // check if heir is allowed to spend From 61f1d8771deeafd0fcc3855b153052910de4bbae Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 21:07:44 +0500 Subject: [PATCH 635/643] removed 1of2 validator for test marker spending --- src/cc/heir.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 3070ed9ef..ce0445975 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -85,7 +85,7 @@ template bool RunValidationPlans(uint8_t funcId, struct CCcont case 'C': // spend coins or tokens // vin validation plan: vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &nullValidator); // txfee vin - vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &markerValidator, &cc1of2ValidatorThis); // cc1of2 funding addr + vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &markerValidator/*, &cc1of2ValidatorThis*/); // cc1of2 funding addr // vout validation plan: voutPlan.pushValidators(0, &heirSpendValidator); // check if heir is allowed to spend From fb69b514b2d61d127635d8b021061a5a60373cb0 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 21:36:57 +0500 Subject: [PATCH 636/643] added logging to marker validator --- src/cc/heir_validate.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index fd414461e..0e4a04868 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -631,15 +631,21 @@ public: uint256 fundingTxidInOpret = zeroid, dummyTxid, tokenid = zeroid, initialTokenid = zeroid; uint8_t dummyIsHeirSpendingBegan; + std::cerr << "CMarkerValidator::validateVin() prevVout.size()=" << prevVout.size() << " prevN=" << prevN << std::endl; + if (prevVout.size() > 0) { // get funcId for prev tx: uint8_t funcId = DecodeHeirEitherOpRet(prevVout[prevVout.size()-1].scriptPubKey, tokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan, true); + + std::cerr << "CMarkerValidator::validateVin() funcId=" << (funcId?funcId:' ') << std::endl; + if (funcId == 'F' && prevN == 1) { // do not allow to spend 'F' marker's vout message = std::string("spending marker not allowed"); return false; } } + std::cerr << "CMarkerValidator::validateVin() exits with true" << std::endl; return true; } }; From da00a3d0217f4c7ea6c1dc5b35ac5a1dc111b008 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 21:47:31 +0500 Subject: [PATCH 637/643] isVinValidator flag corrected = true --- src/cc/heir_validate.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index 0e4a04868..6e4049896 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -624,7 +624,7 @@ public: CMarkerValidator(CCcontract_info* cp) : CValidatorBase(cp) { } - virtual bool isVinValidator() const { return false; } // this is vout validator + virtual bool isVinValidator() const { return true; } // this is vin validator virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const { return true; } virtual bool validateVin(CTxIn vin, std::vector prevVout, int32_t prevN, std::string& message) const { From de8af6cc93d198ce2db3c18ca26efad349e8f0a5 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 21:54:47 +0500 Subject: [PATCH 638/643] debug logging disabled --- src/cc/heir.cpp | 4 ++-- src/cc/heir_validate.h | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index ce0445975..93a59f95f 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -1247,7 +1247,7 @@ void _HeirList(struct CCcontract_info *cp, UniValue &result) GetCCaddress(cp, markeraddr, GetUnspendable(cp, NULL)); SetCCunspents(unspentOutputs, markeraddr); - std::cerr << "HeirList() finding heir marker from unspendable addr=" << markeraddr << " unspentOutputs.size()=" << unspentOutputs.size() << '\n'; + //std::cerr << "HeirList() finding heir marker from unspendable addr=" << markeraddr << " unspentOutputs.size()=" << unspentOutputs.size() << '\n'; // TODO: move marker to special cc addr to prevent checking all tokens for (std::vector>::const_iterator it = unspentOutputs.begin(); it != unspentOutputs.end(); it++) { @@ -1256,7 +1256,7 @@ void _HeirList(struct CCcontract_info *cp, UniValue &result) uint256 tokenid; int32_t vout = (int32_t)it->first.index; - std::cerr << "HeirList() checking txid=" << txid.GetHex() << " vout=" << vout << '\n'; + //std::cerr << "HeirList() checking txid=" << txid.GetHex() << " vout=" << vout << '\n'; CTransaction fundingtx; if (GetTransaction(txid, fundingtx, hashBlock, false)) { diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index 6e4049896..df58e3bf1 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -631,21 +631,20 @@ public: uint256 fundingTxidInOpret = zeroid, dummyTxid, tokenid = zeroid, initialTokenid = zeroid; uint8_t dummyIsHeirSpendingBegan; - std::cerr << "CMarkerValidator::validateVin() prevVout.size()=" << prevVout.size() << " prevN=" << prevN << std::endl; - + //std::cerr << "CMarkerValidator::validateVin() prevVout.size()=" << prevVout.size() << " prevN=" << prevN << std::endl; if (prevVout.size() > 0) { // get funcId for prev tx: uint8_t funcId = DecodeHeirEitherOpRet(prevVout[prevVout.size()-1].scriptPubKey, tokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan, true); - std::cerr << "CMarkerValidator::validateVin() funcId=" << (funcId?funcId:' ') << std::endl; + //std::cerr << "CMarkerValidator::validateVin() funcId=" << (funcId?funcId:' ') << std::endl; if (funcId == 'F' && prevN == 1) { // do not allow to spend 'F' marker's vout message = std::string("spending marker not allowed"); return false; } } - std::cerr << "CMarkerValidator::validateVin() exits with true" << std::endl; + //std::cerr << "CMarkerValidator::validateVin() exits with true" << std::endl; return true; } }; From 6481576883e63756c37142f886868b8a1b67009a Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 22:02:43 +0500 Subject: [PATCH 639/643] restored 1of2 validator for C (was off to test markerValidator) --- src/cc/heir.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 93a59f95f..71ec9b040 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -85,7 +85,7 @@ template bool RunValidationPlans(uint8_t funcId, struct CCcont case 'C': // spend coins or tokens // vin validation plan: vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &nullValidator); // txfee vin - vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &markerValidator/*, &cc1of2ValidatorThis*/); // cc1of2 funding addr + vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &markerValidator, &cc1of2ValidatorThis); // cc1of2 funding addr // vout validation plan: voutPlan.pushValidators(0, &heirSpendValidator); // check if heir is allowed to spend From 81fc7ca05bd0f8e4b21f0eed6c9d4bb29694fc3b Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 23 Jan 2019 11:36:56 +0500 Subject: [PATCH 640/643] set fixed precision for coins for heirinfo --- src/cc/heir.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 71ec9b040..0ba1d3d33 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -15,6 +15,7 @@ #include "CCHeir.h" #include "heir_validate.h" +#include class CoinHelper; class TokenHelper; @@ -1178,7 +1179,7 @@ UniValue HeirInfo(uint256 fundingtxid) if (tokenid == zeroid) { msg = "funding available in coins"; - stream << (double)inputs / COIN; + stream << std::fixed << std::setprecision(8) << (double)inputs / COIN; } else { msg = "funding available in tokens"; From 5f116e5d131c160f6ab390098f1df60cc9a98950 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 23 Jan 2019 11:38:56 +0500 Subject: [PATCH 641/643] removed incorrect debug logging in IsTokensvout --- src/cc/CCtokens.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index bdb710afb..d7db32b99 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -404,7 +404,6 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c uint8_t evalCodeInOpret; if (vopretExtra.size() >= 2 /*|| vopretExtra.size() != vopretExtra.begin()[0] <-- shold we check this?*/) { - std::cerr << "IsTokensvout() empty or incorrect contract opret" << std::endl; evalCodeInOpret = vopretExtra.begin()[1]; } else { From defe854383e3b1268157ddf3288e0dd3a9bb5b0b Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 23 Jan 2019 11:49:07 +0500 Subject: [PATCH 642/643] set fixed precision for total funds, too --- src/cc/heir.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 0ba1d3d33..d00cab795 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -1161,7 +1161,7 @@ UniValue HeirInfo(uint256 fundingtxid) if (tokenid == zeroid) { msg = "funding total in coins"; - stream << (double)total / COIN; + stream << std::fixed << std::setprecision(8) << (double)total / COIN; } else { msg = "funding total in tokens"; From 088ea2bfb49f19ab83c8bd5ecc66f138f73d988e Mon Sep 17 00:00:00 2001 From: ca333 Date: Wed, 23 Jan 2019 19:02:05 +0100 Subject: [PATCH 643/643] update cclib to match autotools/libtools naming convention --- src/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index 96ab3f1fa..ad9842f09 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -572,7 +572,7 @@ komodod_LDADD += \ $(LIBVERUS_CRYPTO) \ $(LIBVERUS_PORTABLE_CRYPTO) \ $(LIBZCASH_LIBS) \ - cclib.so + libcc.so if ENABLE_PROTON komodod_LDADD += $(LIBBITCOIN_PROTON) $(PROTON_LIBS)