diff --git a/CHANGELOG.md b/CHANGELOG.md index d28a51829..1b68fbf3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 1.0.5 +* bugfixes + +## 1.0.4 +* bugfixes + ## 1.0.3 * bugfixes diff --git a/devops/Makefile b/devops/Makefile index 45b3786b4..2f428bab4 100644 --- a/devops/Makefile +++ b/devops/Makefile @@ -45,7 +45,7 @@ FPM_P_VENDOR := Sovrin FPM_P_DESCRIPTION := libsovtoken written in Rust FPM_P_NAME = $(PACKAGE_NAME) FPM_P_VERSION ?= $(SRC_VERSION) -FPM_P_DEPENDS = libindy(>=1.12.0~96) +FPM_P_DEPENDS = libindy(>=1.16.0) FPM_P_OUTPUT_DIR = $(LIB_TARGET_DIR) FPM_ARGS = $(LIB_DYNAMIC)=/usr/lib/ diff --git a/devops/aws-codebuild/Jenkinsfile.cd b/devops/aws-codebuild/Jenkinsfile.cd index d2084c3a9..f33a3df0c 100644 --- a/devops/aws-codebuild/Jenkinsfile.cd +++ b/devops/aws-codebuild/Jenkinsfile.cd @@ -15,12 +15,12 @@ String srcVersion gitHubUserCredId = env.GITHUB_BOT_USER ?: 'sovbot-github' sovrinPackagingRepo = env.SOVRIN_PACKAGING_REPO ?: 'https://github.com/sovrin-foundation/sovrin-packaging' sovrinPackagingBranch = env.SOVRIN_PACKAGING_BRANCH ?: 'master' -LIBINDY_STREAM = "rc" -LIBINDY_VERSION = "1.12.0-96" +LIBINDY_STREAM = 'stable' +LIBINDY_VERSION = '1.16.0' def downloadPackagingUtils() { git branch: sovrinPackagingBranch, credentialsId: gitHubUserCredId, url: sovrinPackagingRepo - sh "pip3 install -U plumbum==1.6.7 deb-pkg-tools six==1.12.0" + sh 'pip3 install -U plumbum==1.6.7 deb-pkg-tools six==1.12.0' } // TODO set proper labels @@ -106,7 +106,7 @@ def codeBuildPipelines = { onArtifacts = { this.stage("$prTag: Archive logs") { - this.utils.archiveArtifacts("logs/*.log*") { + this.utils.archiveArtifacts('logs/*.log*') { truncate = true allowEmptyArchive = true truncateFileSuffix = 'trunc.log' @@ -161,18 +161,18 @@ def codeBuildPipelines = { // } stage('Set release parameters') { - logger.info("Finding Release version") -// def releaseVersion = env.BRANCH_NAME == 'stable' ? '' : "${lastRevision ? lastRevision[0] + 1: 1}.$BUILD_NUMBER" + logger.info('Finding Release version') + // def releaseVersion = env.BRANCH_NAME == 'stable' ? '' : "${lastRevision ? lastRevision[0] + 1: 1}.$BUILD_NUMBER" def releaseVersion = env.BRANCH_NAME == 'stable' ? '' : "$BUILD_NUMBER" logger.info("Release version for sovrin repo: $releaseVersion") -// debPVersion = utils.packageVersion('deb', srcVersion, releaseVersion, env.BRANCH_NAME == 'master') + // debPVersion = utils.packageVersion('deb', srcVersion, releaseVersion, env.BRANCH_NAME == 'master') debPVersion = env.BRANCH_NAME == 'stable' ? "$srcVersion" : "$srcVersion~$releaseVersion" logger.info("Package version for sovrin repo: $debPVersion") - // TODO crate and rpm - //cratePVersion = utils.packageVersion('crate', srcVersion, releaseVersion) - //logger.info("Package version for rust registry: $cratePVersion") + // TODO crate and rpm + //cratePVersion = utils.packageVersion('crate', srcVersion, releaseVersion) + //logger.info("Package version for rust registry: $cratePVersion") } stage("$prTag: Resolve image tag") { @@ -205,12 +205,12 @@ def codeBuildPipelines = { [name: 'ARTIFACTS', value: "libsovtoken/target/release/${packageName}*.*"], [name: 'PACKAGE_NAME', value: packageName], [name: 'FPM_P_VERSION', value: debPVersion], - // [name: 'CRATE_P_VERSION', value: cratePVersion], + // [name: 'CRATE_P_VERSION', value: cratePVersion], ] onArtifacts = { this.stage("$prTag: Archive logs") { - this.utils.archiveArtifacts("logs/*.log*") { + this.utils.archiveArtifacts('logs/*.log*') { truncate = true allowEmptyArchive = true truncateFileSuffix = 'trunc.log' @@ -223,7 +223,7 @@ def codeBuildPipelines = { String debName dir("${awsCBHelper.buildCtx.projects[prTag].artifactsDir}") { - dir("sovrin-packaging") { + dir('sovrin-packaging') { downloadPackagingUtils() } debName = utils.shStdout("ls $packageName*$debPVersion*.deb") @@ -264,20 +264,20 @@ def codeBuildPipelines = { ] builds.failFast = false - stage("CodeBuild Build") { + stage('CodeBuild Build') { utils.parallel builds } } def macOSPipeline = { - stage("MacOS Build") { + stage('MacOS Build') { def packageName = 'libsovtoken' def xcodeMinVersion = '9.0' def RUST_PATH = '~/.cargo/bin' - + WORK_DIR = '/Users/jenkins' stage('Checks') { - echo "===================== Checks for XCode and Rust environment ========================" + echo '===================== Checks for XCode and Rust environment ========================' INSTALLED_XCODE_VERSION = sh(script: '''xcodebuild -version | head -1 | cut -d' ' -f2''', returnStdout: true) echo "INSTALLED_XCODE_VERSION = ${INSTALLED_XCODE_VERSION} and xcodeMinVersion = ${xcodeMinVersion}" if (INSTALLED_XCODE_VERSION <= xcodeMinVersion) { @@ -317,33 +317,31 @@ def macOSPipeline = { withEnv([ "PATH+RUST=${RUST_PATH}", - "PATH+BREW=/usr/local/bin", - "PATH+CURL=/usr/local/opt/curl/bin" + 'PATH+BREW=/usr/local/bin', + 'PATH+CURL=/usr/local/opt/curl/bin' ]) { - dir('libsovtoken/build_scripts/ios/mac/') { - stage('mac.01.libindy.setup') { sh './mac.01.env.setup.sh' } stage('mac.14.libsovtoken.build.sh') { - sh "./mac.14.libsovtoken.build.sh" + sh './mac.14.libsovtoken.build.sh' } } dir('libsovtoken') { pkgName = utils.shStdout("ls ${packageName}*.zip") - stash includes: pkgName, name: "iosArtifact" + stash includes: pkgName, name: 'iosArtifact' } } } } def macosUpload = { - String packageName = "libsovtoken" + String packageName = 'libsovtoken' stage('Upload libsovtoken universal package to Sovrin repo') { - unstash name: "iosArtifact" + unstash name: 'iosArtifact' String pkgName = utils.shStdout("ls ${packageName}*.zip") logger.info("Uploading libsovtoken package '$pkgName' to sovrin repo") @@ -358,7 +356,7 @@ def macosUpload = { } def windowsOSPipeline = { - stage("Windows Testing") { + stage('Windows Testing') { def ws_path = "workspace/${env.JOB_NAME}".replace(' ', '_') ws(ws_path) { try { @@ -384,24 +382,24 @@ def windowsOSPipeline = { stage('Testing') { dir('libsovtoken') { - echo "Libsovtoken Testing: Build" + echo 'Libsovtoken Testing: Build' withEnv([ "OPENSSL_DIR=$WORKSPACE\\prebuilt", "SODIUM_LIB_DIR=$WORKSPACE\\prebuilt\\lib", "LIBINDY_DIR=$WORKSPACE\\indy\\lib", "PATH=$WORKSPACE\\prebuilt\\lib;$WORKSPACE\\indy\\lib;$PATH", - "RUST_BACKTRACE=1" + 'RUST_BACKTRACE=1' ]) { - bat "cargo build --release" - bat "cargo test --release --no-run" + bat 'cargo build --release' + bat 'cargo test --release --no-run' - echo "Libsovtoken Testing: Run tests" + echo 'Libsovtoken Testing: Run tests' withEnv([ - "RUST_TEST_THREADS=1", - "RUST_LOG=debug", + 'RUST_TEST_THREADS=1', + 'RUST_LOG=debug', "TEST_POOL_IP=$INDY_SDK_SERVER_IP" ]) { - bat "cargo test --release" + bat 'cargo test --release' } } @@ -426,7 +424,6 @@ def windowsOSPipeline = { def windowsUpload = { stage('Upload libsovtoken package to Sovrin repo') { - if (!srcVersion) { stage('Resolve current source version') { srcVersion = utils.srcVersion(projectType: 'rust') @@ -436,7 +433,7 @@ def windowsUpload = { sh 'chmod -R 777 devops/windows' - unstash name: "windowsArtifact" + unstash name: 'windowsArtifact' withCredentials([file(credentialsId: 'SovrinRepoSSHKey', variable: 'repo_key')]) { withEnv([ @@ -453,13 +450,12 @@ def getSuffix() { if (env.BRANCH_NAME == 'master') { return "-$env.BUILD_NUMBER" } else if (env.BRANCH_NAME == 'stable') { - return "" + return '' } else { error "Invalid branch ${env.BRANCH_NAME}" } } - pipelineWrapper({ //put code build containers inside a vpc under our dev account env.USE_VPC_CONFIG = true @@ -480,7 +476,7 @@ pipelineWrapper({ ] builds.failFast = false - stage("Build") { + stage('Build') { utils.parallel builds } @@ -499,17 +495,17 @@ pipelineWrapper({ utils.parallel publish } }, { err -> - stage("Pipeline finalizing") { + stage('Pipeline finalizing') { if (err) { logger.error("Pipeline failed with the error $err") } - stage("Build result notification") { + stage('Build result notification') { notifier.email() } } }) def setupRust() { - shell("rustup default 1.32.0") + shell('rustup default 1.51.0') } diff --git a/devops/aws-codebuild/Jenkinsfile.ci b/devops/aws-codebuild/Jenkinsfile.ci index 4c7d82106..1d014efb2 100644 --- a/devops/aws-codebuild/Jenkinsfile.ci +++ b/devops/aws-codebuild/Jenkinsfile.ci @@ -7,8 +7,8 @@ def sovLibrary = library(identifier: 'sovrin-aws-codebuild@master', retriever: m logger = sovLibrary.Logger.new(this) notifier = sovLibrary.Notifier.new(this) logger.setGlobalLevel('TRACE') -LIBINDY_STREAM = "rc" -LIBINDY_VERSION = "1.12.0-96" +LIBINDY_STREAM = 'stable' +LIBINDY_VERSION = '1.16.0' def nodeLabels = [ codeBuild: env.LIBSOVTOKEN_CODEBUILD_NODE_LABEL ?: 'codebuild', @@ -17,7 +17,7 @@ def nodeLabels = [ ] def windowsOSPipeline = { - stage("Windows Testing") { + stage('Windows Testing') { def ws_path = "workspace/${env.JOB_NAME}".replace(' ', '_') ws(ws_path) { try { @@ -25,7 +25,7 @@ def windowsOSPipeline = { checkout scm } - stage('Setup dependencies'){ + stage('Setup dependencies') { setupRust() bat 'wget -O prebuilt.zip "https://repo.sovrin.org/windows/libindy/deps/indy-sdk-deps.zip"' @@ -41,26 +41,26 @@ def windowsOSPipeline = { bat "docker -H $INDY_SDK_SERVER_IP run -d --network host --name indy_pool -p 9701-9708:9701-9708 indy_pool" } - stage('Testing'){ + stage('Testing') { dir('libsovtoken') { - echo "Libsovtoken Testing: Build" + echo 'Libsovtoken Testing: Build' withEnv([ "OPENSSL_DIR=$WORKSPACE\\prebuilt", "SODIUM_LIB_DIR=$WORKSPACE\\prebuilt\\lib", "LIBINDY_DIR=$WORKSPACE\\indy\\lib", "PATH=$WORKSPACE\\prebuilt\\lib;$WORKSPACE\\indy\\lib;$PATH", - "RUST_BACKTRACE=1" + 'RUST_BACKTRACE=1' ]) { - bat "cargo build" - bat "cargo test --no-run" + bat 'cargo build' + bat 'cargo test --no-run' - echo "Libsovtoken Testing: Run tests" + echo 'Libsovtoken Testing: Run tests' withEnv([ - "RUST_TEST_THREADS=1", - "RUST_LOG=debug", + 'RUST_TEST_THREADS=1', + 'RUST_LOG=debug', "TEST_POOL_IP=$INDY_SDK_SERVER_IP" ]) { - bat "cargo test" + bat 'cargo test' } } } @@ -91,7 +91,7 @@ pipelineWrapper({ ] List osnames = [ 'xenial', - //'centos7' + //'centos7' ] List goals = ['test_dry', 'test'] @@ -114,8 +114,8 @@ pipelineWrapper({ Map builds = osnames.collectEntries { osname -> [(osname): [ - "nodeLabel": nodeLabels.codeBuild, - "build" : { + 'nodeLabel': nodeLabels.codeBuild, + 'build' : { def buildImageTag def prTag = "ci-$osname" @@ -130,8 +130,8 @@ pipelineWrapper({ // debian package version: + // debian package name: - def sovtoken_deb_version = "0.9.5" - def sovtokenfees_deb_version = "0.9.5" + def sovtoken_deb_version = '0.9.5' + def sovtokenfees_deb_version = '0.9.5' sh """ cd ./devops/docker/ci/xenial/ @@ -177,13 +177,13 @@ pipelineWrapper({ onArtifacts = { this.stage("$osname: Archive artifacts") { // make targets' logs - utils.archiveArtifacts("logs/*.log*") { + utils.archiveArtifacts('logs/*.log*') { truncate = true allowEmptyArchive = true truncateFileSuffix = 'trunc.log' } // nodes' logs and validators info - utils.archiveArtifacts("logs/pool/*") { + utils.archiveArtifacts('logs/pool/*') { truncate = false allowEmptyArchive = true } @@ -192,13 +192,13 @@ pipelineWrapper({ } }]] } - + builds.put('windows', [ build: windowsOSPipeline, nodeLabel: "$nodeLabels.windows" ]) - stage("Build and test") { + stage('Build and test') { builds.failFast = false utils.parallel builds } @@ -208,11 +208,11 @@ pipelineWrapper({ logger.error("Pipeline failed with the error $err") } - stage("Build result notification") { + stage('Build result notification') { notifier.email() } }) def setupRust() { - shell("rustup default 1.32.0") + shell('rustup default 1.46.0') } diff --git a/devops/docker/android_build/xenial/Dockerfile b/devops/docker/android_build/xenial/Dockerfile index 57ee2db41..c55faf986 100644 --- a/devops/docker/android_build/xenial/Dockerfile +++ b/devops/docker/android_build/xenial/Dockerfile @@ -1,6 +1,6 @@ ARG ANDROID_PREBUILT_DIR=/tmp/android/libsovtoken_prebuilt -FROM sovrin/libsovtoken:android_ndk-xenial-0.7.0 +FROM sovrin/libsovtoken:android_ndk-xenial-0.8.0 # TODO LABEL maintainer="Name " ARG ANDROID_PREBUILT_DIR @@ -12,7 +12,7 @@ RUN chmod -R 777 ${ANDROID_PREBUILT_DIR} ############################################ -FROM sovrin/libsovtoken:android_ndk-xenial-0.7.0 +FROM sovrin/libsovtoken:android_ndk-xenial-0.8.0 # TODO LABEL maintainer="Name " ARG u_id=1000 @@ -23,7 +23,7 @@ ARG ANDROID_PREBUILT_DIR ARG RUST_TARGETS RUN if [ "$u_id" != "0" ]; then \ - useradd -ms /bin/bash -u $u_id $u_name; \ + useradd -ms /bin/bash -u $u_id $u_name; \ fi ENV TEST_USER_UID=$u_id @@ -50,4 +50,4 @@ ENV RUST_TARGETS=${RUST_TARGETS:-"arm-linux-androideabi armv7-linux-androideabi # TODO some entrypoint -ENV LIBSOVTOKEN_ANDROID_BUILD_ENV_VERSION=0.7.0 +ENV LIBSOVTOKEN_ANDROID_BUILD_ENV_VERSION=0.8.0 diff --git a/devops/docker/android_ndk/xenial/Dockerfile b/devops/docker/android_ndk/xenial/Dockerfile index 225bdad5f..ec2acfdfb 100644 --- a/devops/docker/android_ndk/xenial/Dockerfile +++ b/devops/docker/android_ndk/xenial/Dockerfile @@ -1,7 +1,7 @@ ARG ANDROID_NDK_DIR=/tmp/android/android_ndk ARG ANDROID_NDK_VERSION=r20 -FROM sovrin/dockerbase:rust-xenial-0.12.0 +FROM sovrin/dockerbase:rust-xenial-0.13.0 # TODO LABEL maintainer="Name " ARG ANDROID_NDK_VERSION @@ -14,7 +14,7 @@ RUN chmod -R 777 ${ANDROID_NDK_DIR} ############################################ -FROM sovrin/dockerbase:rust-xenial-0.12.0 +FROM sovrin/dockerbase:rust-xenial-0.13.0 # TODO LABEL maintainer="Name " ARG PYTHON3_VERSION @@ -24,8 +24,8 @@ ARG ANDROID_NDK_DIR # python3 ENV PYTHON3_VERSION=${PYTHON3_VERSION:-3.5} RUN apt-get update && apt-get install -y --no-install-recommends \ - python${PYTHON3_VERSION} \ - python3-pip \ + python${PYTHON3_VERSION} \ + python3-pip \ && rm -rf /var/lib/apt/lists/* # android ndk @@ -40,4 +40,4 @@ RUN chmod +x /usr/local/bin/android-ndk-install # TODO CMD ENTRYPOINT ... -ENV LIBSOVTOKEN_ANDROID_NDK_ENV_VERSION=0.7.0 +ENV LIBSOVTOKEN_ANDROID_NDK_ENV_VERSION=0.8.0 diff --git a/devops/docker/base/centos7/Dockerfile b/devops/docker/base/centos7/Dockerfile index e640c1682..5f3a8cef9 100644 --- a/devops/docker/base/centos7/Dockerfile +++ b/devops/docker/base/centos7/Dockerfile @@ -19,7 +19,7 @@ RUN yum install -y \ # install recent libsodium version from the sources ENV LIBSODIUM_VERSION=1.0.14 RUN cd /tmp && \ - curl https://download.libsodium.org/libsodium/releases/libsodium-${LIBSODIUM_VERSION}.tar.gz | tar -xz && \ + curl https://download.libsodium.org/libsodium/releases/old/unsupported/libsodium-${LIBSODIUM_VERSION}.tar.gz | tar -xz && \ cd /tmp/libsodium-${LIBSODIUM_VERSION} && \ ./configure --prefix=/usr/local/ && make && make install && \ rm -rf /tmp/libsodium-${LIBSODIUM_VERSION} diff --git a/devops/docker/base/xenial/Dockerfile b/devops/docker/base/xenial/Dockerfile index afce20614..d98119fee 100644 --- a/devops/docker/base/xenial/Dockerfile +++ b/devops/docker/base/xenial/Dockerfile @@ -1,4 +1,4 @@ -FROM sovrin/dockerbase:rust-xenial-0.12.0 +FROM sovrin/dockerbase:rust-xenial-0.13.0 # TODO LABEL maintainer="Name " ARG u_id=1000 @@ -11,7 +11,7 @@ ENV LIBSODIUM_LIB_DIR=/usr/lib ENV LIBSODIUM_INC_DIR=/usr/include # install libsodium from the sources -ENV LIBSODIUM_VERSION=1.0.14 +ENV LIBSODIUM_VERSION=1.0.16 RUN cd /tmp \ && curl https://download.libsodium.org/libsodium/releases/old/libsodium-${LIBSODIUM_VERSION}.tar.gz | tar -xz \ && cd /tmp/libsodium-${LIBSODIUM_VERSION} \ @@ -21,17 +21,34 @@ RUN cd /tmp \ # need for libsodium to be reachable via pkg-config (sodiumoxide uses it) ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:$PKG_CONFIG_PATH # TODO ??? is it really needed -ENV LIBINDY_VERSION=1.12.0~96 +ENV LIBINDY_VERSION=1.16.0-bionic RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 68DB5E88 \ - && echo "deb https://repo.sovrin.org/sdk/deb xenial rc" >> /etc/apt/sources.list \ + && echo "deb https://repo.sovrin.org/sdk/deb xenial stable" >> /etc/apt/sources.list \ + && echo "deb https://repo.sovrin.org/sdk/deb bionic stable" >> /etc/apt/sources.list \ + && echo "deb https://repo.sovrin.org/deb xenial master" >> /etc/apt/sources.list \ + && echo "deb http://archive.ubuntu.com/ubuntu bionic main" >> /etc/apt/sources.list \ + && echo "deb http://archive.ubuntu.com/ubuntu xenial main" >> /etc/apt/sources.list \ && apt-get update && apt-get install -y --no-install-recommends \ - libssl-dev \ - libindy=${LIBINDY_VERSION} \ + libssl-dev \ + libssl1.1 \ + libsodium23 \ + libindy=${LIBINDY_VERSION} \ + python3-ujson=1.33-1build1 \ + python3-pygments=2.2.0 \ + python3-leveldb \ + python3-six=1.11.0 \ + python3-msgpack=0.4.6-1build1 \ + python3-dateutil=2.6.1 \ + python3-rocksdb=0.6.9 \ + python3-setuptools=38.5.2 \ + python3-orderedset=2.0 \ + python3-psutil=5.4.3 \ + python3-pympler=0.5 \ && rm -rf /var/lib/apt/lists/* RUN if [ "$u_id" != "0" ]; then \ - useradd -ms /bin/bash -u $u_id $u_name; \ + useradd -ms /bin/bash -u $u_id $u_name; \ fi ENV TEST_USER_UID=$u_id @@ -47,4 +64,4 @@ RUN cd /tmp/libsovtoken \ # TODO CMD ENTRYPOINT ... -ENV LIBSOVTOKEN_BASE_ENV_VERSION=0.39.0 +ENV LIBSOVTOKEN_BASE_ENV_VERSION=0.43.0 diff --git a/devops/docker/ci/xenial/Dockerfile b/devops/docker/ci/xenial/Dockerfile index 2a105b636..4164baeb8 100644 --- a/devops/docker/ci/xenial/Dockerfile +++ b/devops/docker/ci/xenial/Dockerfile @@ -1,4 +1,4 @@ -FROM sovrin/libsovtoken:base-xenial-0.39.0 +FROM sovrin/libsovtoken:base-xenial-0.43.0 # TODO LABEL maintainer="Name " ARG LIBINDY_CRYPTO_VERSION @@ -13,14 +13,14 @@ USER root # python env necessary for indy-node RUN apt-get update && apt-get install -y --no-install-recommends \ - supervisor \ - python3.5 \ - python3-pip \ - python-setuptools \ + supervisor \ + python3.5 \ + python3-pip \ + python-setuptools \ && pip3 install -U \ - setuptools \ - 'pip<10.0.0' \ - setuptools \ + setuptools \ + 'pip<10.0.0' \ + setuptools \ && rm -rf /var/lib/apt/lists/* @@ -35,19 +35,19 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ # or python3-rocksdb are not specified here) ENV LIBINDY_CRYPTO_VERSION ${LIBINDY_CRYPTO_VERSION:-0.4.5} ENV PYTHON3_INDY_CRYPTO_VERSION ${PYTHON3_INDY_CRYPTO_VERSION:-0.4.5} -ENV INDY_PLENUM_VERSION ${INDY_PLENUM_VERSION:-1.10.0~rc1} -ENV INDY_NODE_VERSION ${INDY_NODE_VERSION:-1.10.0~rc1} -ENV TOKEN_VER ${TOKEN_VER:-1.0.3~rc20} +ENV INDY_PLENUM_VERSION ${INDY_PLENUM_VERSION:-1.12.0} +ENV INDY_NODE_VERSION ${INDY_NODE_VERSION:-1.12.0} +ENV TOKEN_VER ${TOKEN_VER:-1.0.5} RUN echo "deb https://repo.sovrin.org/sdk/deb xenial master" >> /etc/apt/sources.list -RUN echo "deb https://repo.sovrin.org/deb xenial rc" >> /etc/apt/sources.list \ +RUN echo "deb https://repo.sovrin.org/deb xenial stable" >> /etc/apt/sources.list \ && apt-get update && apt-get install -y --no-install-recommends \ - libindy-crypto=${LIBINDY_CRYPTO_VERSION} \ - python3-indy-crypto=${PYTHON3_INDY_CRYPTO_VERSION} \ - python3-pyzmq=18.1.0 \ - indy-plenum=${INDY_PLENUM_VERSION} \ - indy-node=${INDY_NODE_VERSION} \ - sovtoken=${TOKEN_VER} \ - sovtokenfees=${TOKEN_VER} \ + libindy-crypto=${LIBINDY_CRYPTO_VERSION} \ + python3-indy-crypto=${PYTHON3_INDY_CRYPTO_VERSION} \ + python3-pyzmq=18.1.0 \ + indy-plenum=${INDY_PLENUM_VERSION} \ + indy-node=${INDY_NODE_VERSION} \ + sovtoken=${TOKEN_VER} \ + sovtokenfees=${TOKEN_VER} \ && rm -rf /var/lib/apt/lists/* COPY supervisord.conf /etc/supervisord.conf @@ -67,4 +67,4 @@ COPY libsovtoken-ci-entrypoint.sh /usr/local/bin/ RUN chmod +x /usr/local/bin/libsovtoken-ci-entrypoint.sh ENTRYPOINT ["libsovtoken-ci-entrypoint.sh"] -ENV LIBSOVTOKEN_CI_ENV_VERSION=0.732.0 +ENV LIBSOVTOKEN_CI_ENV_VERSION=0.736.0 diff --git a/devops/ext/docker/base/xenial/Dockerfile.0.8.0 b/devops/ext/docker/base/xenial/Dockerfile.0.8.0 index a37e53de1..f9ff86146 100644 --- a/devops/ext/docker/base/xenial/Dockerfile.0.8.0 +++ b/devops/ext/docker/base/xenial/Dockerfile.0.8.0 @@ -3,36 +3,37 @@ FROM ubuntu:xenial # generally useful packages RUN apt-get update && apt-get install -y --no-install-recommends \ - ca-certificates \ - apt-transport-https \ - curl \ - wget \ - vim \ - git \ - procps \ - autoconf \ - automake \ - g++ \ - gcc \ - make \ - pkg-config \ - zip \ - unzip \ + ca-certificates \ + software-properties-common \ + apt-transport-https \ + curl \ + wget \ + vim \ + git \ + procps \ + autoconf \ + automake \ + g++ \ + gcc \ + make \ + pkg-config \ + zip \ + unzip \ && rm -rf /var/lib/apt/lists/* # install fpm ENV FPM_VERSION=1.9.3 -RUN apt-get update && apt-get install -y --no-install-recommends \ - ruby \ - ruby-dev \ - rubygems \ - build-essential \ - autoconf \ - libtool \ - rpm \ +RUN apt-add-repository ppa:brightbox/ruby-ng \ + && apt-get update && apt-get install -y --no-install-recommends \ + ruby2.4 \ + ruby2.4-dev \ + build-essential \ + autoconf \ + libtool \ + rpm \ && gem install rake \ - && gem install --no-ri --no-rdoc fpm -v $FPM_VERSION \ + && gem install --no-document fpm -v $FPM_VERSION \ && rm -rf /var/lib/apt/lists/* @@ -44,9 +45,9 @@ RUN set -x \ && wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \ && export GNUPGHOME="$(mktemp -d)" \ && (gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \ - || gpg --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \ - || gpg --keyserver pgp.mit.edu --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \ - || gpg --keyserver keyserver.pgp.com --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4) \ + || gpg --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \ + || gpg --keyserver pgp.mit.edu --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \ + || gpg --keyserver keyserver.pgp.com --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4) \ && gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \ && rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc \ && chmod +x /usr/local/bin/gosu \ diff --git a/devops/ext/docker/rust/xenial/Dockerfile.0.12.0 b/devops/ext/docker/rust/xenial/Dockerfile.0.12.0 index 227113234..eedfc5713 100644 --- a/devops/ext/docker/rust/xenial/Dockerfile.0.12.0 +++ b/devops/ext/docker/rust/xenial/Dockerfile.0.12.0 @@ -3,7 +3,7 @@ FROM sovrin/dockerbase:base-xenial-0.8.0 ARG RUST_VERSION -ENV RUST_VERSION=${RUST_VERSION:-1.32.0} +ENV RUST_VERSION=${RUST_VERSION:-1.51.0} ENV RUSTUP_HOME=/usr/local/rustup \ CARGO_HOME=/usr/local/cargo \ PATH=/usr/local/cargo/bin:$PATH diff --git a/devops/ext/docker/rust/xenial/Dockerfile.0.13.0 b/devops/ext/docker/rust/xenial/Dockerfile.0.13.0 new file mode 100644 index 000000000..9f16110b9 --- /dev/null +++ b/devops/ext/docker/rust/xenial/Dockerfile.0.13.0 @@ -0,0 +1,18 @@ +FROM sovrin/dockerbase:base-xenial-0.8.0 +# TODO LABEL maintainer="Name " + +ARG RUST_VERSION + +ENV RUST_VERSION=${RUST_VERSION:-1.51.0} +ENV RUSTUP_HOME=/usr/local/rustup \ + CARGO_HOME=/usr/local/cargo \ + PATH=/usr/local/cargo/bin:$PATH +RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --no-modify-path --default-toolchain $RUST_VERSION \ + && chmod -R a+w $RUSTUP_HOME $CARGO_HOME \ + && rustup --version \ + && cargo --version \ + && rustc --version + +# TODO CMD ENTRYPOINT ... + +ENV RUST_ENV_VERSION=0.13.0 diff --git a/devops/indy-pool/Dockerfile b/devops/indy-pool/Dockerfile index a5805b9a2..a212a4569 100644 --- a/devops/indy-pool/Dockerfile +++ b/devops/indy-pool/Dockerfile @@ -19,15 +19,15 @@ FROM camparra/ubuntu16.04-rocksdb ARG uid=1000 -ARG indy_stream=rc +ARG indy_stream=stable -ARG indy_plenum_ver=1.10.0~rc1 -ARG indy_node_ver=1.10.0~rc1 +ARG indy_plenum_ver=1.12.0 +ARG indy_node_ver=1.12.0 ARG python3_indy_crypto_ver=0.4.5 ARG indy_crypto_ver=0.4.5 -ARG token_ver=1.0.3~rc20 -ARG fees_ver=1.0.3~rc20 +ARG token_ver=1.0.5 +ARG fees_ver=1.0.5 # Install environment RUN apt-get update -y && apt-get install -y \ diff --git a/devops/setup.android.env.sh b/devops/setup.android.env.sh index 0d4bd4b79..3c6d0983d 100644 --- a/devops/setup.android.env.sh +++ b/devops/setup.android.env.sh @@ -64,35 +64,6 @@ generate_arch_flags(){ } -download_and_unzip_if_missed() { - target_dir=$1 - url_pref=$2 - fname=$3 - url="${url_pref}${fname}" - if [ ! -d "${target_dir}" ] ; then - echo "${GREEN}Downloading ${fname}${RESET}" - curl -sSLO ${url} - unzip -qq ${fname} - rm ${fname} - echo "${GREEN}Done!${RESET}" - else - echo "${BLUE}Skipping download ${fname}${RESET}" - fi -} - -download_and_unzip_dependencies_for_all_architectures(){ - mkdir -p ${ANDROID_BUILD_FOLDER} - - pushd ${ANDROID_BUILD_FOLDER} - download_and_unzip_if_missed "openssl_${TARGET_ARCH}" "https://repo.sovrin.org/android/libindy/deps-libc++/openssl/" "openssl_${TARGET_ARCH}.zip" - download_and_unzip_if_missed "libsodium_${TARGET_ARCH}" "https://repo.sovrin.org/android/libindy/deps-libc++/sodium/" "libsodium_${TARGET_ARCH}.zip" - download_and_unzip_if_missed "libzmq_${TARGET_ARCH}" "https://repo.sovrin.org/android/libindy/deps-libc++/zmq/" "libzmq_${TARGET_ARCH}.zip" - - export OPENSSL_DIR=${ANDROID_BUILD_FOLDER}/openssl_${TARGET_ARCH} - export SODIUM_DIR=${ANDROID_BUILD_FOLDER}/libsodium_${TARGET_ARCH} - export LIBZMQ_DIR=${ANDROID_BUILD_FOLDER}/libzmq_${TARGET_ARCH} - popd -} create_cargo_config(){ mkdir -p ${SOVTOKEN_DIR}/.cargo cat << EOF > ${SOVTOKEN_DIR}/.cargo/config diff --git a/libsovtoken/Cargo.toml b/libsovtoken/Cargo.toml index 78c32694a..a1cacf6b3 100644 --- a/libsovtoken/Cargo.toml +++ b/libsovtoken/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "libsovtoken" -version = "1.0.2" +version = "1.0.5" authors = [ "Matt Raffel /dev/null || brew install pkg-config + brew list libsodium &>/dev/null || brew install ${INSTALL_LIBSODIUM} + brew list automake &>/dev/null || brew install automake + brew list autoconf &>/dev/null || brew install autoconf + brew list cmake &>/dev/null || brew install cmake + brew list openssl &>/dev/null || brew install openssl + brew list zmq &>/dev/null || brew install zmq + brew list wget &>/dev/null || brew install wget + brew list truncate &>/dev/null || brew install truncate + brew list libzip &>/dev/null || brew install libzip + # brew list python3 &>/dev/null || brew install python3 fi diff --git a/libsovtoken/build_scripts/ios/mac/mac.03.libindy.build.sh b/libsovtoken/build_scripts/ios/mac/mac.03.libindy.build.sh index 1a8dc6296..18f1ed75f 100755 --- a/libsovtoken/build_scripts/ios/mac/mac.03.libindy.build.sh +++ b/libsovtoken/build_scripts/ios/mac/mac.03.libindy.build.sh @@ -39,7 +39,7 @@ if [ ! -z "$1" ]; then DEBUG_SYMBOLS=$1 fi -IOS_TARGETS="aarch64-apple-ios,armv7-apple-ios,armv7s-apple-ios,i386-apple-ios,x86_64-apple-ios" +IOS_TARGETS="aarch64-apple-ios,x86_64-apple-ios" if [ ! -z "$2" ]; then IOS_TARGETS=$2 fi diff --git a/libsovtoken/build_scripts/ios/mac/mac.14.libsovtoken.build.sh b/libsovtoken/build_scripts/ios/mac/mac.14.libsovtoken.build.sh index a4e300087..e362acb36 100755 --- a/libsovtoken/build_scripts/ios/mac/mac.14.libsovtoken.build.sh +++ b/libsovtoken/build_scripts/ios/mac/mac.14.libsovtoken.build.sh @@ -1,84 +1,140 @@ #!/bin/sh +set -xev + +export PKG_CONFIG_ALLOW_CROSS=1 +export CARGO_INCREMENTAL=1 +export RUST_LOG=indy=trace +export RUST_TEST_THREADS=1 +export INDY_VERSION=v1.16.0 +export IOS_TARGETS="aarch64-apple-ios x86_64-apple-ios" +export WORK_DIR="${PWD}/../../../.macosbuild" +export LIBSOV_DIR="${PWD}/../../.." +export INDY_SDK_DIR=$WORK_DIR/sovtoken-indy-sdk +export LIBS_DIR=$WORK_DIR/libs +export OPENSSL_TARGETS="ios-sim-cross-x86_64 ios64-cross-arm64" -set -xv -function extract_target() { +mkdir -p ${WORK_DIR} +mkdir -p ${LIBS_DIR} + +prepare_openssl_dir() { + OPENSSL_BASE_DIR=$(brew --cellar openssl) + for f in $(ls -t "$OPENSSL_BASE_DIR"); do + local ABSOLUTE_FILE_PATH="${OPENSSL_BASE_DIR}/${f}" + if [ -d "$ABSOLUTE_FILE_PATH" ] && [ -d "$ABSOLUTE_FILE_PATH/lib" ]; then + export OPENSSL_VERSION=$f + export OPENSSL_DIR=$ABSOLUTE_FILE_PATH + break + fi + done + if [ -z "$OPENSSL_VERSION" ]; then + echo >&2 "Error: Failed to find an OpenSSL installation in $OPENSSL_BASE_DIR" + exit 1 + else + echo "Found OpenSSL version $OPENSSL_VERSION" + fi +} + +extract_arch() { case $1 in aarch64-apple-ios) echo "arm64" ;; - armv7-apple-ios) echo "armv7" ;; - armv7s-apple-ios) echo "armv7s" ;; - i386-apple-ios) echo "i386" ;; x86_64-apple-ios) echo "x86_64" ;; + ios-sim-cross-x86_64) echo "x86_64" ;; + ios64-cross-arm64) echo "arm64" ;; \?) exit 1 esac } -source ./shared.functions.sh +build_crypto() { + if [ ! -d $WORK_DIR/OpenSSL-for-iPhone ]; then + git clone https://github.com/x2on/OpenSSL-for-iPhone.git $WORK_DIR/OpenSSL-for-iPhone + fi + + if [ ! -d $WORK_DIR/OpenSSL-for-iPhone/lib ]; then + pushd $WORK_DIR/OpenSSL-for-iPhone + ./build-libssl.sh --version=$OPENSSL_VERSION --targets="$OPENSSL_TARGETS" --verbose-on-error + # export OPENSSL_LOCAL_CONFIG_DIR="$PWD/config" + popd + fi + for TARGET in ${IOS_TARGETS[*]}; do + pushd $WORK_DIR/OpenSSL-for-iPhone + ARCH=$(extract_arch $TARGET) + mkdir -p $LIBS_DIR/openssl/$ARCH/lib + lipo -thin $ARCH -o $LIBS_DIR/openssl/$ARCH/lib/libssl.a ./lib/libssl.a + lipo -thin $ARCH -o $LIBS_DIR/openssl/$ARCH/lib/libcrypto.a ./lib/libcrypto.a + cp -r bin include $LIBS_DIR/openssl/$ARCH + popd + done +} -START_DIR=${PWD} -WORK_DIR=$(get_work_dir) -mkdir -p ${WORK_DIR} +checkout_indy_sdk() { + if [ ! -d $INDY_SDK_DIR ]; then + git clone https://github.com/hyperledger/indy-sdk $INDY_SDK_DIR + fi -source ./mac.02.libindy.env.sh + pushd $INDY_SDK_DIR + git fetch --all + git checkout $INDY_VERSION + popd +} -mkdir -p ${WORK_DIR}/sovtoken-indy-sdk +build_libindy() { + pushd $INDY_SDK_DIR/libindy + for TARGET in ${IOS_TARGETS[*]} + do + ARCH=$(extract_arch $TARGET) + mkdir -p $LIBS_DIR/indy/$ARCH -if [ ! -f "${WORK_DIR}/sovtoken-indy-sdk/libindy.a" ] ; then - command pushd ${WORK_DIR}/sovtoken-indy-sdk > /dev/null - curl -sSLO ${LIBINDY_IOS_BUILD_URL} - tar -xf ${LIBINDY_FILE} - command popd > /dev/null - fi + export OPENSSL_DIR=$LIBS_DIR/openssl/$ARCH + cargo lipo --release --targets=$TARGET + + cp -v $INDY_SDK_DIR/libindy/target/$TARGET/release/libindy.a $LIBS_DIR/indy/$ARCH/libindy.a + done + popd +} + +copy_libindy_architectures() { + for TARGET in ${IOS_TARGETS[*]}; do + ARCH=$(extract_arch $TARGET) + mkdir -p $LIBS_DIR/indy/$ARCH + cp -v $INDY_SDK_DIR/libindy/target/$TARGET/release/libindy.a $LIBS_DIR/indy/$ARCH/libindy.a + done +} + +build_libsovtoken() { + pushd $LIBSOV_DIR + to_combine="" + for TARGET in ${IOS_TARGETS[*]} + do + ARCH=$(extract_arch $TARGET) + export LIBINDY_DIR=${LIBS_DIR}/indy/$ARCH + export OPENSSL_DIR=$LIBS_DIR/openssl/$ARCH + cargo lipo --release --verbose --targets="${TARGET}" + + mv ./target/$TARGET/release/libsovtoken.a ./target/$TARGET/libsovtoken-unstripped.a + strip -S -x -o ./target/$TARGET/libsovtoken.a -r ./target/$TARGET/libsovtoken-unstripped.a + + to_combine="${to_combine} ./target/${TARGET}/libsovtoken.a" + + mkdir -p ./target/universal/release + lipo -create $to_combine -o ./target/universal/release/libsovtoken.a + cp ./target/universal/release/libsovtoken.a ./target/universal/libsovtoken-unstripped.a + strip -S -x -o ./target/universal/libsovtoken.a -r ./target/universal/libsovtoken-unstripped.a + + BUILD_TIME=$(date -u "+%Y%m%d%H%M") + GIT_REV=$(git rev-parse --short HEAD) + LIBSOVTOKEN_VER=$(grep ^version Cargo.toml | head -n 1 | cut -d '"' -f 2) + mv target libsovtoken + zip -qq "libsovtoken_${LIBSOVTOKEN_VER}-${BUILD_TIME}-${GIT_REV}_all.zip" `find libsovtoken -type f -name "libsovtoken.a" | egrep '(ios|universal)' | egrep -v 'deps|debug|release'` + mv libsovtoken target + done + popd +} + +prepare_openssl_dir +build_crypto + +checkout_indy_sdk +build_libindy +copy_libindy_architectures -if [ ! -d "${WORK_DIR}/sovtoken-indy-sdk" ]; then - echo STDERR "Unable to find ${WORK_DIR}/sovtoken-indy-sdk directory" - exit 1 -fi - -IOS_TARGETS="aarch64-apple-ios,armv7-apple-ios,armv7s-apple-ios,i386-apple-ios,x86_64-apple-ios" -if [ ! -z "$2" ]; then - IOS_TARGETS=$2 -fi - -######################################################################################################################### -# Now build libsovtoken -######################################################################################################################### -cd $(get_sovtoken_dir) - -if [ "$DEBUG_SYMBOLS" = "debuginfo" ]; then - cat $START_DIR/cargo.toml.add.debug.txt >> Cargo.toml -fi - -bkpIFS="$IFS" -IFS=',()][' read -r -a targets <<<"${IOS_TARGETS}" -echo "Building targets: ${targets[@]}" -IFS="$bkpIFS" - -to_combine="" -for target in ${targets[*]} -do - LIBINDY=${WORK_DIR}/sovtoken-indy-sdk - export LIBINDY_DIR=${LIBINDY}/${target} - mkdir -p ${LIBINDY_DIR} - etarget=$(extract_target $target) - - echo "LIBINDY_DIR=${LIBINDY_DIR}" - lipo -thin $etarget $LIBINDY/libindy.a -o $LIBINDY_DIR/libindy.a - cargo lipo --release --verbose --targets="${target}" - mv ./target/$target/release/libsovtoken.a ./target/$target/libsovtoken-unstripped.a - strip -S -x -o ./target/$target/libsovtoken.a -r ./target/$target/libsovtoken-unstripped.a - - to_combine="${to_combine} ./target/${target}/libsovtoken.a" - -done - -mkdir -p ./target/universal/release -lipo -create $to_combine -o ./target/universal/release/libsovtoken.a -cp ./target/universal/release/libsovtoken.a ./target/universal/libsovtoken-unstripped.a -strip -S -x -o ./target/universal/libsovtoken.a -r ./target/universal/libsovtoken-unstripped.a - -BUILD_TIME=$(date -u "+%Y%m%d%H%M") -GIT_REV=$(git rev-parse --short HEAD) -LIBSOVTOKEN_VER=$(grep ^version Cargo.toml | head -n 1 | cut -d '"' -f 2) -mv target libsovtoken -zip -qq "libsovtoken_${LIBSOVTOKEN_VER}-${BUILD_TIME}-${GIT_REV}_all.zip" `find libsovtoken -type f -name "libsovtoken.a" | egrep '(ios|universal)' | egrep -v 'deps|debug|release'` -mv libsovtoken target +build_libsovtoken diff --git a/libsovtoken/build_scripts/ios/mac/shared.functions.sh b/libsovtoken/build_scripts/ios/mac/shared.functions.sh index 9daa86798..4c4338fc1 100644 --- a/libsovtoken/build_scripts/ios/mac/shared.functions.sh +++ b/libsovtoken/build_scripts/ios/mac/shared.functions.sh @@ -1,6 +1,6 @@ #!/bin/sh -export LIBINDY_IOS_BUILD_URL="https://repo.sovrin.org/ios/libindy/rc/libindy-core/1.12.0-96/libindy.tar.gz" +export LIBINDY_IOS_BUILD_URL="https://repo.sovrin.org/ios/libindy/stable/libindy-core/1.16.0/libindy.tar.gz" export LIBINDY_FILE=$(basename ${LIBINDY_IOS_BUILD_URL}) export LIBINDY_VERSION=$(basename $(dirname ${LIBINDY_IOS_BUILD_URL})) export BUILD_CACHE=~/.build_libvxc/ioscache diff --git a/libsovtoken/dev/ubuntu/Dockerfile b/libsovtoken/dev/ubuntu/Dockerfile index a26da5476..c5229f903 100644 --- a/libsovtoken/dev/ubuntu/Dockerfile +++ b/libsovtoken/dev/ubuntu/Dockerfile @@ -11,7 +11,7 @@ RUN apt-get -qq update -y && apt-get -qq install -y sudo zip unzip cmake autocon && useradd -m -d /home/token_user -s /bin/bash -p $(openssl passwd -1 "token") token_user \ && usermod -aG sudo token_user \ && cd /tmp \ - && curl https://download.libsodium.org/libsodium/releases/libsodium-1.0.14.tar.gz | tar -xz \ + && curl https://download.libsodium.org/libsodium/releases/old/unsupported/libsodium-1.0.14.tar.gz | tar -xz \ && cd libsodium-1.0.14 \ && ./autogen.sh \ && ./configure \ diff --git a/libsovtoken/src/api/mod.rs b/libsovtoken/src/api/mod.rs index 91abd85a6..bcd2bc539 100644 --- a/libsovtoken/src/api/mod.rs +++ b/libsovtoken/src/api/mod.rs @@ -79,7 +79,7 @@ use utils::constants::general::JsonI64Callback; #[no_mangle] pub extern "C" fn create_payment_address_handler( command_handle: i32, - wallet_handle: i32, + wallet_handle: indy_sys::WalletHandle, config_str: *const c_char, cb: JsonCallback ) -> i32 { @@ -184,8 +184,8 @@ pub extern "C" fn create_payment_address_handler( #[no_mangle] pub extern "C" fn add_request_fees_handler( command_handle: i32, - wallet_handle: i32, - did: *const c_char, // TODO: Need to remove. + wallet_handle: indy_sys::WalletHandle, + _did: *const c_char, // TODO: Need to remove. req_json: *const c_char, inputs_json: *const c_char, outputs_json: *const c_char, @@ -193,7 +193,7 @@ pub extern "C" fn add_request_fees_handler( cb: JsonCallback ) -> i32 { - trace!("api::add_request_fees_handler called did (address) >> {:?}", secret!(&did)); + trace!("api::add_request_fees_handler called did (address) >> {:?}", secret!(&_did)); let (inputs, outputs, extra, request_json_map, cb) = match add_request_fees::deserialize_inputs(req_json, inputs_json, outputs_json, extra, cb) { Ok(tup) => tup, Err(error_code) => { @@ -354,7 +354,7 @@ pub extern "C" fn parse_response_with_fees_handler( #[no_mangle] pub extern "C" fn build_payment_req_handler( command_handle: i32, - wallet_handle: i32, + wallet_handle: indy_sys::WalletHandle, submitter_did: *const c_char, inputs_json: *const c_char, outputs_json: *const c_char, @@ -470,7 +470,7 @@ pub extern "C" fn parse_payment_response_handler( /// description of errors #[no_mangle] pub extern "C" fn build_get_utxo_request_handler(command_handle: i32, - wallet_handle: i32, + wallet_handle: indy_sys::WalletHandle, _submitter_did: *const c_char, payment_address: *const c_char, from: i64, @@ -595,13 +595,13 @@ pub extern "C" fn parse_get_utxo_response_handler( #[no_mangle] pub extern "C" fn build_set_txn_fees_handler( command_handle: i32, - wallet_handle: i32, + wallet_handle: indy_sys::WalletHandle, submitter_did: *const c_char, fees_json: *const c_char, cb: JsonCallback ) -> i32 { - trace!("api::build_set_txn_fees_handler called >> wallet_handle {}", wallet_handle); + trace!("api::build_set_txn_fees_handler called >> wallet_handle {:?}", wallet_handle); let (did, set_fees, cb) = match set_fees::deserialize_inputs( submitter_did, fees_json, @@ -648,7 +648,7 @@ pub extern "C" fn build_set_txn_fees_handler( #[no_mangle] pub extern "C" fn build_get_txn_fees_handler( command_handle: i32, - wallet_handle: i32, + wallet_handle: indy_sys::WalletHandle, submitter_did: *const c_char, cb: JsonCallback ) -> i32 { @@ -768,14 +768,14 @@ pub extern "C" fn parse_get_txn_fees_response_handler( #[no_mangle] pub extern "C" fn build_mint_txn_handler( command_handle: i32, - wallet_handle: i32, + wallet_handle: indy_sys::WalletHandle, submitter_did: *const c_char, outputs_json: *const c_char, extra: *const c_char, cb: JsonCallback ) -> i32 { - trace!("api::build_mint_txn_handle called >> wallet_handle {}", wallet_handle); + trace!("api::build_mint_txn_handle called >> wallet_handle {:?}", wallet_handle); let (did, outputs, extra, cb) = match minting::deserialize_inputs( submitter_did, outputs_json, @@ -818,12 +818,12 @@ pub extern "C" fn build_mint_txn_handler( #[no_mangle] pub extern "C" fn build_verify_req_handler( command_handle: i32, - wallet_handle: i32, + wallet_handle: indy_sys::WalletHandle, did: *const c_char, txo: *const c_char, cb: JsonCallback ) -> i32 { - trace!("api::build_verify_req called >> wallet_handle {}", wallet_handle); + trace!("api::build_verify_req called >> wallet_handle {:?}", wallet_handle); let (did, txo, cb) = match verify::deserialize(did, txo, cb) { Ok(a) => a, @@ -949,7 +949,7 @@ pub extern fn free_parsed_state_proof(sp: *const c_char) -> i32 { #[no_mangle] pub extern "C" fn sign_with_address_handler( command_handle: i32, - wallet_handle: i32, + wallet_handle: indy_sys::WalletHandle, address: *const c_char, message_raw: *const u8, message_len: u32, diff --git a/libsovtoken/src/lib.rs b/libsovtoken/src/lib.rs index f7a7f62ae..63de2f34b 100644 --- a/libsovtoken/src/lib.rs +++ b/libsovtoken/src/lib.rs @@ -16,6 +16,7 @@ extern crate rand; extern crate serde; extern crate sha2; extern crate time; +extern crate regex; // ------------------------------------------ // crates from crate.io etc that require macro // ------------------------------------------ diff --git a/libsovtoken/src/logic/api_internals/add_request_fees.rs b/libsovtoken/src/logic/api_internals/add_request_fees.rs index 79ff25c65..8177350e4 100644 --- a/libsovtoken/src/logic/api_internals/add_request_fees.rs +++ b/libsovtoken/src/logic/api_internals/add_request_fees.rs @@ -8,6 +8,7 @@ use logic::output::Outputs; use serde_json; use utils::ffi_support::{string_from_char_ptr, c_pointer_from_string, c_pointer_from_str}; use logic::indy_sdk_api::crypto_api::CryptoSdk; +use indy_sys; use utils::constants::txn_types::XFER_PUBLIC; use utils::constants::txn_fields::FEES; use utils::constants::general::JsonCallbackUnwrapped; @@ -90,12 +91,12 @@ pub fn validate_type_not_transfer(request_json_map: &SerdeMap) -> Result<(), Err } pub fn add_fees_to_request_and_serialize( - wallet_handle: i32, + wallet_handle: indy_sys::WalletHandle, inputs: Inputs, outputs: Outputs, extra: Option, request_json_map: SerdeMap, - cb: Box) + Send + Sync> + cb: Box) + Send + Sync> ) -> Result<(), ErrorCode> { trace!("logic::add_request_fees::add_fees_to_request_and_serialize >> wallet_handle: {:?}, inputs: {:?}, outputs: {:?}, request_json_map: {:?}", wallet_handle, secret!(&inputs), secret!(&outputs), secret!(&request_json_map)); let res = add_fees(wallet_handle, inputs, outputs, extra, request_json_map, Box::new(move |request_json_map_updated|{ @@ -129,7 +130,7 @@ pub fn closure_cb_response(command_handle: i32, cb: JsonCallbackUnwrapped) -> im KEEP all public methods above */ -fn add_fees(wallet_handle: i32, inputs: Inputs, outputs: Outputs, extra: Option, request_json_map: SerdeMap, cb: Box) + Send + Sync>) -> Result<(), ErrorCode> { +fn add_fees(wallet_handle: indy_sys::WalletHandle, inputs: Inputs, outputs: Outputs, extra: Option, request_json_map: SerdeMap, cb: Box) + Send + Sync>) -> Result<(), ErrorCode> { let txn_serialized = serialize_signature(request_json_map.clone().into())?; let mut hasher = Sha256::default(); hasher.input(txn_serialized.as_bytes()); @@ -160,7 +161,7 @@ fn serialize_request_with_fees(request_json_map_with_fees: SerdeMap) -> Result, txn_digest: &Option, cb: Box), ErrorCode>) + Send + Sync>) -> Result<(), ErrorCode> { +fn signed_fees(wallet_handle: indy_sys::WalletHandle, inputs: Inputs, outputs: Outputs, extra: Option, txn_digest: &Option, cb: Box), ErrorCode>) + Send + Sync>) -> Result<(), ErrorCode> { let fees = XferPayload::new(inputs, outputs, extra); fees.sign_fees(&CryptoSdk{}, wallet_handle, txn_digest, cb)?; Ok(()) diff --git a/libsovtoken/src/logic/build_payment.rs b/libsovtoken/src/logic/build_payment.rs index c32274bef..ca25b8ead 100644 --- a/libsovtoken/src/logic/build_payment.rs +++ b/libsovtoken/src/logic/build_payment.rs @@ -89,12 +89,13 @@ fn build_payment_request_pointer( return Err(ErrorCode::CommonInvalidStructure); } - let identifier = match identifier.map(String::from) { + let identifier = match identifier { Some(idr) => idr, None => { let addr = signed_payload.inputs[0].address.clone(); let idr = addr.as_bytes().from_base58_check(); - idr.map(|s| s.into_base58()).map_err(|_| ErrorCode::CommonInvalidStructure)? + let idr = idr.map(|s| s.into_base58()).map_err(|_| ErrorCode::CommonInvalidStructure)?; + Did::new(idr) } }; @@ -242,6 +243,6 @@ mod test_handle_signing { .get(0).unwrap().as_object().unwrap() .get("address").unwrap().as_str().unwrap() ); - assert_eq!(Some("7LSfLv2S6K7zMPrgmJDkZoJNhWvWRzpU7qt9uMR5yz8G".to_string()), request.identifier); + assert_eq!(Some(Did::new("7LSfLv2S6K7zMPrgmJDkZoJNhWvWRzpU7qt9uMR5yz8G".to_string())), request.identifier); } } \ No newline at end of file diff --git a/libsovtoken/src/logic/config/get_fees_config.rs b/libsovtoken/src/logic/config/get_fees_config.rs index dd0547546..53d8aca8c 100644 --- a/libsovtoken/src/logic/config/get_fees_config.rs +++ b/libsovtoken/src/logic/config/get_fees_config.rs @@ -50,7 +50,7 @@ impl GetFeesRequest { [`Request`]: ../../request/struct.Request.html */ pub fn as_request(self, identifier: Option) -> Request { - return Request::new(self, identifier.map(String::from)); + return Request::new(self, identifier); } } diff --git a/libsovtoken/src/logic/config/get_utxo_config.rs b/libsovtoken/src/logic/config/get_utxo_config.rs index f853b5ea1..9509824f4 100644 --- a/libsovtoken/src/logic/config/get_utxo_config.rs +++ b/libsovtoken/src/logic/config/get_utxo_config.rs @@ -9,6 +9,7 @@ use logic::address::strip_qualifier_from_address; use logic::request::Request; use utils::constants::txn_types::GET_UTXO; use logic::address::verkey_from_unqualified_address; +use logic::did::Did; /** * Json config to customize [`build_get_utxo_txn_handler`] @@ -28,6 +29,7 @@ impl GetUtxoOperationRequest { pub fn new(address : String, from: Option) -> Request { let unqualified_address: String = strip_qualifier_from_address(&address); let identifier = verkey_from_unqualified_address(&unqualified_address).ok(); + let identifier = identifier.map(|identifier_| Did::new(identifier_)); let req = GetUtxoOperationRequest { address : unqualified_address, req_type : GET_UTXO.to_string(), diff --git a/libsovtoken/src/logic/config/output_mint_config.rs b/libsovtoken/src/logic/config/output_mint_config.rs index 97e598d2a..9bb0d17ff 100644 --- a/libsovtoken/src/logic/config/output_mint_config.rs +++ b/libsovtoken/src/logic/config/output_mint_config.rs @@ -20,7 +20,7 @@ use logic::output::Outputs; pub struct MintRequest { #[serde(rename = "type")] txn_type: String, - outputs: Vec<(Output)>, + outputs: Vec, #[serde(skip_serializing_if = "Option::is_none")] extra: Option, } @@ -37,7 +37,7 @@ impl MintRequest { extra, }; - return Request::new(mint, identifier.map(String::from)); + return Request::new(mint, identifier); } /** diff --git a/libsovtoken/src/logic/config/payment_config.rs b/libsovtoken/src/logic/config/payment_config.rs index 77912c1ef..1d6360b4d 100644 --- a/libsovtoken/src/logic/config/payment_config.rs +++ b/libsovtoken/src/logic/config/payment_config.rs @@ -8,6 +8,7 @@ use logic::request::Request; use utils::constants::txn_types::XFER_PUBLIC; use logic::xfer_payload::XferPayload; +use logic::did::Did; /** Struct for [`build_payment_req_handler`] @@ -25,11 +26,12 @@ use logic::xfer_payload::XferPayload; use sovtoken::logic::input::Input; use sovtoken::logic::output::Output; use sovtoken::logic::xfer_payload::XferPayload; + use sovtoken::logic::did::Did; sovtoken::api::sovtoken_init(); // let wallet = utils::wallet::Wallet::new().unwrap(); - let identifier = String::from("hgrhyNXqW4KNTz4wwiV8v"); + let identifier = Did(String::from("hgrhyNXqW4KNTz4wwiV8v")); let address1 = String::from("pay:sov:TKe9eXtchV71J2qXX5HwP8rbkTBStnEEkMwQkHie265VtRSbs"); let address2 = String::from("pay:sov:2FKYJkgXRZtjhFpTMHhuyfc17BHZWcFPyF2MWy2SZMBaSo64fb"); let address3 = String::from("pay:sov:E9LNHk8shQ6xe2RfydzXDSsyhWC6vJaUeKE2mmc6mWraDfmKm"); @@ -83,7 +85,7 @@ impl PaymentRequest { [`Request`]: ../../request/struct.Request.html */ - pub fn as_request(self, identifier: String) -> Request { + pub fn as_request(self, identifier: Did) -> Request { return Request::new(self, Some(identifier)); } } @@ -100,7 +102,7 @@ mod payment_request_test { use utils::random::rand_string; fn initial_xfer_request() -> Request { - let identifier: String = rand_string(21); + let identifier: Did = Did::new(rand_string(21)); let output = Output::new(String::from("a8QAXMjRwEGoGLmMFEc5sTcntZxEF1BpqAs8GoKFa9Ck81fo7"), 10); let input = Input::new(String::from("E9LNHk8shQ6xe2RfydzXDSsyhWC6vJaUeKE2mmc6mWraDfmKm"),30); diff --git a/libsovtoken/src/logic/config/set_fees_config.rs b/libsovtoken/src/logic/config/set_fees_config.rs index c9262cf88..404f6cb1f 100644 --- a/libsovtoken/src/logic/config/set_fees_config.rs +++ b/libsovtoken/src/logic/config/set_fees_config.rs @@ -83,7 +83,7 @@ impl SetFees { // of signing and being consistent with MINT. // More details here https://docs.google.com/document/d/15m3XPEUfwhI5GPWh3kuMj6rML52ydWTLsBiurHKfmnU/edit pub fn as_request(self, identifier: Option) -> Request { - return Request::new(self, identifier.map(String::from)); + return Request::new(self, identifier); } /** diff --git a/libsovtoken/src/logic/did.rs b/libsovtoken/src/logic/did.rs index fb46b6ed7..ef4057253 100644 --- a/libsovtoken/src/logic/did.rs +++ b/libsovtoken/src/logic/did.rs @@ -4,11 +4,16 @@ use libc::c_char; use std::char; +use regex::Regex; use bs58::decode::DecodeError; use utils::ffi_support::str_from_char_ptr; use utils::base58::{FromBase58}; +// Fully qualified DID pattern +lazy_static! { + pub static ref REGEX: Regex = Regex::new("^did:([a-z0-9]+:)([a-zA-Z0-9:.-_]*)").unwrap(); +} /** Enum which holds possible errors with the did. @@ -29,10 +34,11 @@ pub enum DidError { The did needs to be between 20 and 21 characters and contain only alphanumeric characters. */ -#[derive(Debug, PartialEq, Eq, Clone)] -pub struct Did(String); +#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] +pub struct Did(pub String); impl Did { + const METHOD: &'static str = "sov"; pub fn new(did_string: String) -> Self { return Did(did_string); @@ -42,6 +48,25 @@ impl Did { return str_from_char_ptr(pointer).map(|st| st.to_string()).map(Self::new); } + pub fn unqualify(self) -> Did { + match REGEX.captures(&self.0.clone()) { + Some(caps) => { + let method = caps.get(1).map(|m| m.as_str().to_string()).unwrap_or_default(); + if method.starts_with(Did::METHOD) { + caps.get(2).map(|m| Did::new(m.as_str().to_string())).unwrap_or(self) + } + else { + self + } + }, + None => self, + } + } + + pub fn is_fully_qualified(&self) -> bool { + REGEX.is_match(&self.0) + } + /** Validate the did @@ -61,6 +86,9 @@ impl Did { ``` */ pub fn validate(self) -> Result { + if self.is_fully_qualified(){ + return Ok(self) + } let (res_did, len) = { let did_string = &self.0; diff --git a/libsovtoken/src/logic/indy_sdk_api/crypto.rs b/libsovtoken/src/logic/indy_sdk_api/crypto.rs index 170489a0e..2477e2bc6 100644 --- a/libsovtoken/src/logic/indy_sdk_api/crypto.rs +++ b/libsovtoken/src/logic/indy_sdk_api/crypto.rs @@ -5,6 +5,7 @@ use std::ffi::CString; use indy_sys::crypto; use indy_sys::{ResponseStringCB, ResponseSliceCB}; +use indy_sys; use utils::results::ResultHandler; use utils::callbacks::ClosureHandler; @@ -26,7 +27,7 @@ impl Key { /// } /// # Returns /// verkey of generated key pair, also used as key identifier - pub fn create(wallet_handle: IndyHandle, my_key_json: Option<&str>) -> Result { + pub fn create(wallet_handle: indy_sys::WalletHandle, my_key_json: Option<&str>) -> Result { let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string(); let err = Key::_create(command_handle, wallet_handle, my_key_json, cb); @@ -49,13 +50,13 @@ impl Key { /// } /// # Returns /// errorcode from calling ffi function. The closure receives the return result - pub fn create_async(wallet_handle: IndyHandle, my_key_json: Option<&str>, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send { + pub fn create_async(wallet_handle: indy_sys::WalletHandle, my_key_json: Option<&str>, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send { let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure)); Key::_create(command_handle, wallet_handle, my_key_json, cb) } - fn _create(command_handle: IndyHandle, wallet_handle: IndyHandle, my_key_json: Option<&str>, cb: Option) -> ErrorCode { + fn _create(command_handle: IndyHandle, wallet_handle: indy_sys::WalletHandle, my_key_json: Option<&str>, cb: Option) -> ErrorCode { let my_key_json = opt_c_str_json!(my_key_json); ErrorCode::from(unsafe { crypto::indy_create_key(command_handle, wallet_handle, my_key_json.as_ptr(), cb) }) @@ -72,7 +73,7 @@ impl Crypto { /// * `message` - the data to be signed /// # Returns /// the signature - pub fn sign(wallet_handle: IndyHandle, signer_vk: &str, message: &[u8]) -> Result, ErrorCode> { + pub fn sign(wallet_handle: indy_sys::WalletHandle, signer_vk: &str, message: &[u8]) -> Result, ErrorCode> { let (receiver, command_handle, cb) = ClosureHandler::cb_ec_slice(); let err = Crypto::_sign(command_handle, wallet_handle, signer_vk, message, cb); @@ -88,13 +89,13 @@ impl Crypto { /// * `closure` - The closure that is called when finished /// # Returns /// errorcode from calling ffi function - pub fn sign_async(wallet_handle: IndyHandle, signer_vk: &str, message: &[u8], closure: F) -> ErrorCode where F: FnMut(ErrorCode, Vec) + Send { + pub fn sign_async(wallet_handle: indy_sys::WalletHandle, signer_vk: &str, message: &[u8], closure: F) -> ErrorCode where F: FnMut(ErrorCode, Vec) + Send { let (command_handle, cb) = ClosureHandler::convert_cb_ec_slice(Box::new(closure)); Crypto::_sign(command_handle, wallet_handle, signer_vk, message, cb) } - fn _sign(command_handle: IndyHandle, wallet_handle: IndyHandle, signer_vk: &str, message: &[u8], cb: Option) -> ErrorCode { + fn _sign(command_handle: IndyHandle, wallet_handle: indy_sys::WalletHandle, signer_vk: &str, message: &[u8], cb: Option) -> ErrorCode { let signer_vk = c_str!(signer_vk); ErrorCode::from(unsafe { crypto::indy_crypto_sign(command_handle, wallet_handle, signer_vk.as_ptr(), diff --git a/libsovtoken/src/logic/indy_sdk_api/crypto_api.rs b/libsovtoken/src/logic/indy_sdk_api/crypto_api.rs index 619fa2bfc..4836c6b2d 100644 --- a/libsovtoken/src/logic/indy_sdk_api/crypto_api.rs +++ b/libsovtoken/src/logic/indy_sdk_api/crypto_api.rs @@ -3,7 +3,8 @@ use logic::indy_sdk_api::crypto::{Key, Crypto}; use logic::config::payment_address_config::PaymentAddressConfig; use utils::base58::serialize_bytes; use utils::json_conversion::JsonSerialize; -use {ErrorCode, IndyHandle}; +use ErrorCode; +use indy_sys; /** This defines the interfaces for INDY SDK crypto apis, which can be replaced with different implementations @@ -12,9 +13,9 @@ use {ErrorCode, IndyHandle}; modeling: master/libindy/src/api/crypto.rs */ pub trait CryptoAPI { - fn indy_create_key(&self, wallet_id: i32, config: PaymentAddressConfig) -> Result; - fn indy_create_key_async(&self, wallet_id: i32, config: PaymentAddressConfig, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send; - fn indy_crypto_sign) + 'static + Send>(&self, wallet_handle: i32, verkey: String, message: String, cb: F) -> ErrorCode; + fn indy_create_key(&self, wallet_id: indy_sys::WalletHandle, config: PaymentAddressConfig) -> Result; + fn indy_create_key_async(&self, wallet_id: indy_sys::WalletHandle, config: PaymentAddressConfig, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send; + fn indy_crypto_sign) + 'static + Send>(&self, wallet_handle: indy_sys::WalletHandle, verkey: String, message: String, cb: F) -> ErrorCode; } // ------------------------------------------------------------------ @@ -34,7 +35,7 @@ impl CryptoAPI for CryptoSdk { the format of the return is: pay:sov:{32 byte address}{4 byte checksum} */ - fn indy_create_key(&self, wallet_id: IndyHandle, config: PaymentAddressConfig) -> Result { + fn indy_create_key(&self, wallet_id: indy_sys::WalletHandle, config: PaymentAddressConfig) -> Result { trace!("create_payment_address calling indy_create_key"); let mut config_json: String = config.to_json().unwrap(); @@ -51,7 +52,7 @@ impl CryptoAPI for CryptoSdk { /** for consumers that cannot have blocking calls, this method indy_create_key asynchronously */ - fn indy_create_key_async(&self, wallet_id: i32, config: PaymentAddressConfig, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send { + fn indy_create_key_async(&self, wallet_id: indy_sys::WalletHandle, config: PaymentAddressConfig, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send { trace!("create_payment_address calling indy_create_key"); let mut config_json: String = config.to_json().unwrap(); @@ -67,7 +68,7 @@ impl CryptoAPI for CryptoSdk { fn indy_crypto_sign) + 'static + Send>( &self, - wallet_handle: IndyHandle, + wallet_handle: indy_sys::WalletHandle, verkey: String, message: String, mut cb: F diff --git a/libsovtoken/src/logic/indy_sdk_api/ledger.rs b/libsovtoken/src/logic/indy_sdk_api/ledger.rs index 271878015..de4298f34 100644 --- a/libsovtoken/src/logic/indy_sdk_api/ledger.rs +++ b/libsovtoken/src/logic/indy_sdk_api/ledger.rs @@ -5,6 +5,7 @@ use std::ptr::null; use indy_sys::ledger; use indy_sys::ResponseStringCB; +use indy_sys; use utils::results::ResultHandler; use utils::callbacks::ClosureHandler; @@ -70,7 +71,7 @@ impl Ledger { /// /// # Returns /// Signed request json. - pub fn multi_sign_request(wallet_handle: IndyHandle, submitter_did: &str, request_json: &str) -> Result { + pub fn multi_sign_request(wallet_handle: indy_sys::WalletHandle, submitter_did: &str, request_json: &str) -> Result { let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string(); let err = Ledger::_multi_sign_request(command_handle, wallet_handle, submitter_did, request_json, cb); @@ -91,13 +92,13 @@ impl Ledger { /// /// # Returns /// Signed request json. - pub fn multi_sign_request_async(wallet_handle: IndyHandle, submitter_did: &str, request_json: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send { + pub fn multi_sign_request_async(wallet_handle: indy_sys::WalletHandle, submitter_did: &str, request_json: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send { let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure)); Ledger::_multi_sign_request(command_handle, wallet_handle, submitter_did, request_json, cb) } - fn _multi_sign_request(command_handle: IndyHandle, wallet_handle: IndyHandle, submitter_did: &str, request_json: &str, cb: Option) -> ErrorCode { + fn _multi_sign_request(command_handle: IndyHandle, wallet_handle: indy_sys::WalletHandle, submitter_did: &str, request_json: &str, cb: Option) -> ErrorCode { let submitter_did = c_str!(submitter_did); let request_json = c_str!(request_json); diff --git a/libsovtoken/src/logic/payments.rs b/libsovtoken/src/logic/payments.rs index 6deec115e..a40cc2b99 100644 --- a/libsovtoken/src/logic/payments.rs +++ b/libsovtoken/src/logic/payments.rs @@ -4,6 +4,7 @@ use ErrorCode; use logic::config::payment_address_config::PaymentAddressConfig; use logic::indy_sdk_api::crypto_api::{CryptoAPI}; use logic::address; +use indy_sys; // ------------------------------------------------------------------ @@ -31,7 +32,7 @@ impl CreatePaymentHandler { the format of the return is: pay:sov:{32 byte address}{4 byte checksum} */ - pub fn create_payment_address(&self, wallet_id: i32, config: PaymentAddressConfig) -> Result { + pub fn create_payment_address(&self, wallet_id: indy_sys::WalletHandle, config: PaymentAddressConfig) -> Result { trace!("calling self.injected_api.indy_create_key"); let verkey = self.injected_api.indy_create_key(wallet_id, config)?; @@ -45,7 +46,7 @@ impl CreatePaymentHandler { pay:sov:{32 byte address}{4 byte checksum} */ pub fn create_payment_address_async(&self, - wallet_id: i32, + wallet_id: indy_sys::WalletHandle, config: PaymentAddressConfig, mut cb: F) -> ErrorCode where F: FnMut(String, ErrorCode) + Send { @@ -95,22 +96,22 @@ mod payments_tests { struct CreatePaymentSDKMockHandler {} impl CryptoAPI for CreatePaymentSDKMockHandler { - fn indy_create_key(&self, _wallet_id: i32, _config: PaymentAddressConfig) -> Result { + fn indy_create_key(&self, _wallet_id: indy_sys::WalletHandle, _config: PaymentAddressConfig) -> Result { return Ok(gen_random_base58_verkey()); } - fn indy_crypto_sign(&self, _: i32, _: String, _: String, _: F) -> ErrorCode { + fn indy_crypto_sign(&self, _: indy_sys::WalletHandle, _: String, _: String, _: F) -> ErrorCode { return ErrorCode::CommonInvalidState; } - fn indy_create_key_async(&self, _wallet_id: i32, _config: PaymentAddressConfig, mut closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send { + fn indy_create_key_async(&self, _wallet_id: indy_sys::WalletHandle, _config: PaymentAddressConfig, mut closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send { closure(ErrorCode::Success, gen_random_base58_verkey()); return ErrorCode::Success; } } - static WALLET_ID: i32 = 10; + static WALLET_ID: indy_sys::WalletHandle = indy_sys::WalletHandle(10); fn validate_address(address: String) { // got our result, if its correct, it will look something like this: diff --git a/libsovtoken/src/logic/request.rs b/libsovtoken/src/logic/request.rs index e821254db..cf9e80832 100644 --- a/libsovtoken/src/logic/request.rs +++ b/libsovtoken/src/logic/request.rs @@ -7,11 +7,13 @@ use std::ffi::CString; use time; use logic::type_aliases::{ProtocolVersion, ReqId}; -use {IndyHandle, ErrorCode}; +use ErrorCode; +use indy_sys; use utils::constants::general::PROTOCOL_VERSION; use utils::ffi_support::{cstring_from_str, c_pointer_from_string}; use utils::json_conversion::JsonSerialize; use utils::txn_author_agreement::TaaAcceptance; +use logic::did::Did; use logic::indy_sdk_api::ledger; @@ -26,7 +28,7 @@ pub struct Request pub req_id: ReqId, pub protocol_version: ProtocolVersion, #[serde(skip_serializing_if = "Option::is_none")] - pub identifier : Option, + pub identifier : Option, #[serde(skip_serializing_if = "Option::is_none")] pub taa_acceptance: Option } @@ -34,8 +36,9 @@ pub struct Request impl Request where T: Serialize { - pub fn new(operation: T, identifier: Option) -> Self { + pub fn new(operation: T, identifier: Option) -> Self { let req_id = time::get_time().sec as u64 * (1e9 as u64) + time::get_time().nsec as u64; + let identifier = identifier.map(|identifier_| identifier_.unqualify()); return Request { operation, protocol_version: PROTOCOL_VERSION, @@ -63,7 +66,7 @@ impl Request .map(|string| c_pointer_from_string(string)); } - pub fn multi_sign_request(wallet_handle: IndyHandle, req: &str, dids: Vec<&str>) -> Result { + pub fn multi_sign_request(wallet_handle: indy_sys::WalletHandle, req: &str, dids: Vec<&str>) -> Result { let mut signed_req: String = req.to_string(); for did in dids { diff --git a/libsovtoken/src/logic/xfer_payload.rs b/libsovtoken/src/logic/xfer_payload.rs index f8bd9a2b2..14d2d58f1 100644 --- a/libsovtoken/src/logic/xfer_payload.rs +++ b/libsovtoken/src/logic/xfer_payload.rs @@ -14,8 +14,8 @@ use std::sync::Arc; use std::sync::Mutex; use std::collections::HashMap; -use IndyHandle; use ErrorCode; +use indy_sys; use logic::address; use logic::indy_sdk_api::crypto_api::CryptoAPI; @@ -43,7 +43,7 @@ use utils::txn_author_agreement::{TaaAcceptance, extract_taa_acceptance_from_ext * use sovtoken::logic::indy_sdk_api::crypto_api::CryptoSdk; * * // Need an actual wallet_handle - * let wallet_handle = 1; + * let wallet_handle: indy_sys::WalletHandle = indy_sys::WalletHandle(1); * let address_input = String::from("pay:sov:SBD8oNfQNm1aEGE6KkYI1khYEGqG5zmEqrEw7maqKitIs121"); * let address_output = String::from("pay:sov:FekbDoBkdsj3nH2a2nNhhedoPju2UmyKrr1ZzMZGT0KENbvp"); * let inputs = vec![Input::new(address_input, 1)]; @@ -89,7 +89,7 @@ impl XferPayload { } // TODO: Add request hash to include while signature - pub fn sign_fees(self, crypto_api: &'static A, wallet_handle: IndyHandle, txn_digest: &Option, cb: Box), ErrorCode>) + Send + Sync>) -> Result<(), ErrorCode> { + pub fn sign_fees(self, crypto_api: &'static A, wallet_handle: indy_sys::WalletHandle, txn_digest: &Option, cb: Box), ErrorCode>) + Send + Sync>) -> Result<(), ErrorCode> { trace!("logic::xfer_payload::xfer_payload::sign_fees >> wallet_handle: {:?}", wallet_handle); if self.inputs.len() < 1 { return Err(ErrorCode::CommonInvalidStructure); @@ -107,7 +107,7 @@ impl XferPayload { * [`Input`]: Input * [`Inputs`]: Inputs */ - pub fn sign_transfer(self, crypto_api: &'static A, wallet_handle: IndyHandle, cb: Box), ErrorCode>) + Send + Sync>) -> Result<(), ErrorCode> { + pub fn sign_transfer(self, crypto_api: &'static A, wallet_handle: indy_sys::WalletHandle, cb: Box), ErrorCode>) + Send + Sync>) -> Result<(), ErrorCode> { trace!("logic::xfer_payload::xfer_payload::sign >> wallet_handle: {:?}", wallet_handle); if self.outputs.len() < 1 || self.inputs.len() < 1 { return Err(ErrorCode::CommonInvalidStructure); @@ -115,7 +115,7 @@ impl XferPayload { self.sign(crypto_api, wallet_handle, &None, cb) } - fn sign(mut self, crypto_api: &'static A, wallet_handle: IndyHandle, txn_digest: &Option, cb: Box), ErrorCode>) + Send + Sync>) -> Result<(), ErrorCode> { + fn sign(mut self, crypto_api: &'static A, wallet_handle: indy_sys::WalletHandle, txn_digest: &Option, cb: Box), ErrorCode>) + Send + Sync>) -> Result<(), ErrorCode> { for output in &mut self.outputs { output.recipient = address::unqualified_address_from_address(&output.recipient)?; } @@ -167,7 +167,7 @@ impl XferPayload { } trait InputSigner { - fn sign_inputs(crypto_api: &'static A, wallet_handle: IndyHandle, inputs: &Inputs, outputs: &Outputs, txn_digest: &Option, extra: &Option, taa_acceptance: &Option, cb: Box, ErrorCode>) + Send + Sync>) + fn sign_inputs(crypto_api: &'static A, wallet_handle: indy_sys::WalletHandle, inputs: &Inputs, outputs: &Outputs, txn_digest: &Option, extra: &Option, taa_acceptance: &Option, cb: Box, ErrorCode>) + Send + Sync>) -> Result<(), ErrorCode> { let inputs_result: Arc>> = Default::default(); @@ -208,13 +208,13 @@ trait InputSigner { */ fn sign_input( crypto_api: &'static A, - wallet_handle: IndyHandle, + wallet_handle: indy_sys::WalletHandle, input: &Input, outputs: &Outputs, txn_digest: &Option, extra: &Option, taa_acceptance: &Option, - cb: Box, String) + Send + Sync>>, + cb: Box, String) + Send + Sync>>, ) -> Result<(), ErrorCode> { trace!("logic::xfer_payload::input_signer::sign_input >> input: {:?}, outputs: {:?}, wallet_handle {:?}", secret!(&input), secret!(&outputs), wallet_handle); @@ -318,16 +318,16 @@ mod test_xfer_payload { struct CryptoApiHandler {} impl CryptoAPI for CryptoApiHandler { - fn indy_create_key(&self, _: IndyHandle, _: PaymentAddressConfig) -> Result { + fn indy_create_key(&self, _: indy_sys::WalletHandle, _: PaymentAddressConfig) -> Result { return Err(ErrorCode::CommonInvalidState); } - fn indy_crypto_sign) + 'static + Send>(&self, _wallet_handle: IndyHandle, verkey: String, _message: String, mut cb: F) -> ErrorCode { + fn indy_crypto_sign) + 'static + Send>(&self, _wallet_handle: indy_sys::WalletHandle, verkey: String, _message: String, mut cb: F) -> ErrorCode { cb(Ok(verkey + "signed")); return ErrorCode::Success; } - fn indy_create_key_async(&self, _wallet_id: i32, _config: PaymentAddressConfig, _closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send { + fn indy_create_key_async(&self, _wallet_id: indy_sys::WalletHandle, _config: PaymentAddressConfig, _closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send { return ErrorCode::CommonInvalidState; } } @@ -355,7 +355,7 @@ mod test_xfer_payload { } fn sign_input_sync(input: &Input, outputs: &Outputs, extra: &Option) -> Result { - let wallet_handle = 1; + let wallet_handle: indy_sys::WalletHandle = indy_sys::WalletHandle(1); let (sender, receiver) = channel(); let sender = Mutex::new(sender); let cb = move |result, _| { @@ -376,7 +376,7 @@ mod test_xfer_payload { } fn sign_inputs_sync(inputs: &Inputs, outputs: &Outputs) -> Result, ErrorCode> { - let wallet_handle = 1; + let wallet_handle: indy_sys::WalletHandle = indy_sys::WalletHandle(1); let (sender, receiver) = channel(); let sender = Mutex::new(sender); let cb = move |result| { sender.lock().unwrap().send(result).unwrap(); }; @@ -424,7 +424,7 @@ mod test_xfer_payload { #[test] fn sign_payload_invalid_output_address() { - let wallet_handle = 1; + let wallet_handle: indy_sys::WalletHandle = indy_sys::WalletHandle(1); let (inputs, mut outputs) = inputs_outputs_valid_qualified(); String::remove(&mut outputs[0].recipient, 5); @@ -439,7 +439,7 @@ mod test_xfer_payload { #[test] fn sign_payload_invalid_input_address() { - let wallet_handle = 1; + let wallet_handle: indy_sys::WalletHandle = indy_sys::WalletHandle(1); let (mut inputs, outputs) = inputs_outputs_valid_qualified(); String::remove(&mut inputs[0].address, 13); @@ -453,7 +453,7 @@ mod test_xfer_payload { #[test] fn sign_payload_invalid_empty_inputs() { - let wallet_handle = 1; + let wallet_handle: indy_sys::WalletHandle = indy_sys::WalletHandle(1); let (_, outputs) = inputs_outputs_valid_qualified(); let (sender, _receiver) = channel(); @@ -466,7 +466,7 @@ mod test_xfer_payload { #[test] fn sign_payload_invalid_empty_outputs() { - let wallet_handle = 1; + let wallet_handle: indy_sys::WalletHandle = indy_sys::WalletHandle(1); let (inputs, _) = inputs_outputs_valid_qualified(); let (sender, _receiver) = channel(); @@ -479,7 +479,7 @@ mod test_xfer_payload { #[test] fn sign_fees_valid_empty_outputs() { - let wallet_handle = 1; + let wallet_handle: indy_sys::WalletHandle = indy_sys::WalletHandle(1); let (inputs, _) = inputs_outputs_valid_qualified(); let (sender, _receiver) = channel(); @@ -492,7 +492,7 @@ mod test_xfer_payload { #[test] fn sign_fees_valid_non_empty_outputs() { - let wallet_handle = 1; + let wallet_handle: indy_sys::WalletHandle = indy_sys::WalletHandle(1); let (inputs, outputs) = inputs_outputs_valid_qualified(); let (sender, _receiver) = channel(); @@ -505,7 +505,7 @@ mod test_xfer_payload { #[test] fn sign_fees_invalid_empty_inputs() { - let wallet_handle = 1; + let wallet_handle: indy_sys::WalletHandle = indy_sys::WalletHandle(1); let (_, outputs) = inputs_outputs_valid_qualified(); let (sender, _receiver) = channel(); @@ -518,7 +518,7 @@ mod test_xfer_payload { #[test] fn sign_address_inputs_valid() { - let wallet_handle = 1; + let wallet_handle: indy_sys::WalletHandle = indy_sys::WalletHandle(1); let (inputs, outputs) = inputs_outputs_valid_qualified(); // Question: Why are signatures dummy values? @@ -554,7 +554,7 @@ mod test_xfer_payload { #[test] fn sign_multi_input_preserve_ordering() { let attempts = 5; - let wallet_handle = 1; + let wallet_handle: indy_sys::WalletHandle = indy_sys::WalletHandle(1); let (mut inputs, outputs) = inputs_outputs_valid_qualified(); inputs.reverse(); diff --git a/libsovtoken/src/utils/callbacks.rs b/libsovtoken/src/utils/callbacks.rs index dbcf0b947..c31c0d858 100644 --- a/libsovtoken/src/utils/callbacks.rs +++ b/libsovtoken/src/utils/callbacks.rs @@ -34,9 +34,9 @@ impl ClosureHandler { (receiver, command_handle, cb) } - pub fn convert_cb_ec(closure: Box) -> (IndyHandle, Option) { + pub fn convert_cb_ec(closure: Box) -> (IndyHandle, Option) { lazy_static! { - static ref CALLBACKS: Mutex>> = Default::default(); + static ref CALLBACKS: Mutex>> = Default::default(); } extern "C" fn _callback(command_handle: IndyHandle, err: i32) { let mut callbacks = CALLBACKS.lock().unwrap(); @@ -63,9 +63,9 @@ impl ClosureHandler { (receiver, command_handle, cb) } - pub fn convert_cb_ec_string(closure: Box) -> (IndyHandle, Option) { + pub fn convert_cb_ec_string(closure: Box) -> (IndyHandle, Option) { lazy_static! { - static ref CALLBACKS: Mutex>> = Default::default(); + static ref CALLBACKS: Mutex>> = Default::default(); } extern "C" fn _callback(command_handle: IndyHandle, err: i32, c_str: *const c_char) { @@ -94,9 +94,9 @@ impl ClosureHandler { (receiver, command_handle, cb) } - pub fn convert_cb_ec_slice(closure: Box) + Send>) -> (IndyHandle, Option) { + pub fn convert_cb_ec_slice(closure: Box) + Send>) -> (IndyHandle, Option) { lazy_static! { - static ref CALLBACKS: Mutex) + Send>>> = Default::default(); + static ref CALLBACKS: Mutex) + Send>>> = Default::default(); } extern "C" fn _callback(command_handle: IndyHandle, err: i32, raw: *const u8, len: u32) { diff --git a/libsovtoken/src/utils/test/callbacks.rs b/libsovtoken/src/utils/test/callbacks.rs index bdc768311..b39f548e0 100644 --- a/libsovtoken/src/utils/test/callbacks.rs +++ b/libsovtoken/src/utils/test/callbacks.rs @@ -20,7 +20,7 @@ macro_rules! closure_cb { ($closure:ident, $($name:ident : $ntype:ty),*) => {{ lazy_static! { static ref COMMAND_HANDLE_COUNTER: AtomicUsize = AtomicUsize::new(4); - static ref CALLBACKS: Callbacks = Default::default(); + static ref CALLBACKS: Callbacks = Default::default(); } let mut callbacks = CALLBACKS.lock().unwrap(); diff --git a/libsovtoken/tests/add_fees_for_attrib_test.rs b/libsovtoken/tests/add_fees_for_attrib_test.rs index 124e43060..a85c65253 100644 --- a/libsovtoken/tests/add_fees_for_attrib_test.rs +++ b/libsovtoken/tests/add_fees_for_attrib_test.rs @@ -3,6 +3,7 @@ #[macro_use] extern crate lazy_static; extern crate indyrs as indy; extern crate sovtoken; +extern crate indy_sys; use indy::future::Future; @@ -200,7 +201,7 @@ pub fn build_and_submit_attrib_with_fees_double_spend() { assert_eq!(parsed_err.error_code, ErrorCode::PaymentSourceDoesNotExistError); } -fn _send_attrib_with_fees(did: &str, data: Option<&str>, wallet_handle: i32, pool_handle: i32, inputs: &str, outputs: &str) -> Result { +fn _send_attrib_with_fees(did: &str, data: Option<&str>, wallet_handle: indy_sys::WalletHandle, pool_handle: i32, inputs: &str, outputs: &str) -> Result { let attrib_req = indy::ledger::build_attrib_request(did, did, None, data, None).wait().unwrap(); let attrib_req_signed = indy::ledger::sign_request(wallet_handle, did, &attrib_req).wait().unwrap(); let (attrib_req_with_fees, pm) = indy::payments::add_request_fees(wallet_handle, Some(did), &attrib_req_signed, inputs, outputs, None).wait().unwrap(); diff --git a/libsovtoken/tests/add_fees_for_cred_def_test.rs b/libsovtoken/tests/add_fees_for_cred_def_test.rs index 6a18d4a72..fac8a2338 100644 --- a/libsovtoken/tests/add_fees_for_cred_def_test.rs +++ b/libsovtoken/tests/add_fees_for_cred_def_test.rs @@ -6,6 +6,7 @@ extern crate serde_derive; extern crate lazy_static; extern crate indyrs as indy; extern crate sovtoken; +extern crate indy_sys; use std::{thread, time}; use std::collections::HashMap; @@ -22,7 +23,7 @@ fn send_cred_def_with_fees(did: &str, name: &str, version: &str, attrs: &str, - wallet_handle: i32, + wallet_handle: indy_sys::WalletHandle, pool_handle: i32, inputs_json: &str, outputs_json: &str, @@ -59,7 +60,7 @@ fn create_schema_json(did: &str, name: &str, version: &str, attrs: &str, - wallet_handle: i32, + wallet_handle: indy_sys::WalletHandle, pool_handle: i32) -> String { let (schema_id, schema_json) = indy::anoncreds::issuer_create_schema(did, name, version, attrs).wait().unwrap(); let schema_req = indy::ledger::build_schema_request(did, &schema_json).wait().unwrap(); diff --git a/libsovtoken/tests/add_fees_for_revoke_reg_def.rs b/libsovtoken/tests/add_fees_for_revoke_reg_def.rs index 5352b9a5a..5cbea2d19 100644 --- a/libsovtoken/tests/add_fees_for_revoke_reg_def.rs +++ b/libsovtoken/tests/add_fees_for_revoke_reg_def.rs @@ -6,6 +6,7 @@ extern crate serde_derive; extern crate lazy_static; extern crate sovtoken; extern crate indyrs as indy; +extern crate indy_sys; use std::{thread, time}; use std::collections::HashMap; @@ -29,7 +30,7 @@ fn send_revoc_reg_def_with_fees(issuer_did: &str, inputs_json: &str, outputs_json: &str, extra: Option<&str>, - wallet_handle: i32, + wallet_handle: indy_sys::WalletHandle, pool_handle: i32, cred_def_id: Option) -> Result { let cred_def_id = cred_def_id.unwrap_or_else(|| { @@ -73,7 +74,7 @@ fn create_cred_def(did: &str, name: &str, version: &str, attrs: &str, - wallet_handle: i32, + wallet_handle: indy_sys::WalletHandle, pool_handle: i32, schema: Option) -> (String, String, String) { let schema = schema.unwrap_or_else(|| create_schema_json(did, name, version, attrs, wallet_handle, pool_handle)); @@ -99,7 +100,7 @@ fn create_schema_json(did: &str, name: &str, version: &str, attrs: &str, - wallet_handle: i32, + wallet_handle: indy_sys::WalletHandle, pool_handle: i32) -> String { let (schema_id, schema_json) = indy::anoncreds::issuer_create_schema(did, name, version, attrs).wait().unwrap(); let schema_req = indy::ledger::build_schema_request(did, &schema_json).wait().unwrap(); diff --git a/libsovtoken/tests/add_fees_for_schema_test.rs b/libsovtoken/tests/add_fees_for_schema_test.rs index 1b6b7fb3e..bba78c615 100644 --- a/libsovtoken/tests/add_fees_for_schema_test.rs +++ b/libsovtoken/tests/add_fees_for_schema_test.rs @@ -3,6 +3,7 @@ #[macro_use] extern crate lazy_static; extern crate indyrs as indy; extern crate sovtoken; +extern crate indy_sys; use std::{thread, time}; use std::collections::HashMap; @@ -19,7 +20,7 @@ fn send_schema_with_fees(did: &str, name: &str, version: &str, attrs: &str, - wallet_handle: i32, + wallet_handle: indy_sys::WalletHandle, pool_handle: i32, inputs_json: &str, outputs_json: &str, diff --git a/libsovtoken/tests/add_request_fees_handler_test.rs b/libsovtoken/tests/add_request_fees_handler_test.rs index 7d21fe9b3..80dbd66fb 100644 --- a/libsovtoken/tests/add_request_fees_handler_test.rs +++ b/libsovtoken/tests/add_request_fees_handler_test.rs @@ -6,6 +6,7 @@ extern crate sovtoken; extern crate indyrs as indy; #[macro_use] extern crate lazy_static; +extern crate indy_sys; pub mod utils; @@ -14,11 +15,11 @@ use sovtoken::utils::test::callbacks; use sovtoken::logic::parsers::common::TXO; use sovtoken::utils::ffi_support::c_pointer_from_string; use sovtoken::utils::ffi_support::c_pointer_from_str; -use sovtoken::{ErrorCode, IndyHandle}; +use sovtoken::ErrorCode; use utils::wallet::Wallet; -fn call_add_request_fees(wallet_handle: IndyHandle, inputs: String, outputs: String, extra: Option, request: String) -> Result { +fn call_add_request_fees(wallet_handle: indy_sys::WalletHandle, inputs: String, outputs: String, extra: Option, request: String) -> Result { let (receiver, command_handle, cb) = callbacks::cb_ec_string(); let did = "mydid1"; diff --git a/libsovtoken/tests/build_fees_txn_handler_test.rs b/libsovtoken/tests/build_fees_txn_handler_test.rs index d309d115a..3b99b9926 100644 --- a/libsovtoken/tests/build_fees_txn_handler_test.rs +++ b/libsovtoken/tests/build_fees_txn_handler_test.rs @@ -5,7 +5,7 @@ extern crate libc; extern crate sovtoken; extern crate indyrs as indy; // lib-sdk project extern crate bs58; - +extern crate indy_sys; use libc::c_char; use std::ffi::CString; @@ -23,7 +23,7 @@ use utils::wallet::Wallet; use utils::payment::fees; // ***** HELPER METHODS ***** -fn build_set_fees(wallet_handle: i32, did: Option<&str>, fees_json: &str) -> Result { +fn build_set_fees(wallet_handle: indy_sys::WalletHandle, did: Option<&str>, fees_json: &str) -> Result { let (receiver, command_handle, cb) = callbacks::cb_ec_string(); let did = did.map(ffi_support::c_pointer_from_str).unwrap_or(std::ptr::null()); @@ -34,7 +34,7 @@ fn build_set_fees(wallet_handle: i32, did: Option<&str>, fees_json: &str) -> Res return ResultHandler::one(ErrorCode::from(ec), receiver); } -fn build_get_fees(wallet_handle: i32, did: Option<&str>) -> Result { +fn build_get_fees(wallet_handle: indy_sys::WalletHandle, did: Option<&str>) -> Result { let (receiver, command_handle, cb) = callbacks::cb_ec_string(); let did = did.map(ffi_support::c_pointer_from_str).unwrap_or(std::ptr::null()); @@ -46,10 +46,12 @@ fn build_get_fees(wallet_handle: i32, did: Option<&str>) -> Result i32> = Some(utils::callbacks::empty_callback); static FAKE_DID: &'static str = "Enfru5LNlA2CnA5n4Hfze"; +static DID: &'static str = "VsKV7grR1BUE29mG2Fm2kX"; +static FULLY_QUALIFIED_DID: &'static str = "did:sov:VsKV7grR1BUE29mG2Fm2kX"; // the build_fees_txn_handler requires a callback and this test ensures that we @@ -114,6 +116,25 @@ fn add_fees_json() { assert_eq!(&expected_operation, request_value.get("operation").unwrap()); } +#[test] +fn add_fees_fully_qualified_did_json() { + let fees = json!({ + "3": 6, + "20001": 12 + }); + let expected_operation = json!({ + "type": "20000", + "fees": fees, + }); + + let fees_request = build_set_fees(WALLET_ID, Some(FULLY_QUALIFIED_DID), &fees.to_string()).unwrap(); + + let request_value: serde_json::value::Value = serde_json::from_str(&fees_request).unwrap(); + + assert_eq!(&expected_operation, request_value.get("operation").unwrap()); + assert_eq!(DID, request_value["identifier"].as_str().unwrap()); +} + #[test] fn build_get_fees_req() { let expected_operation = json!({ @@ -128,6 +149,20 @@ fn build_get_fees_req() { assert_eq!(&expected_operation, request_value.get("operation").unwrap()); } +#[test] +fn build_get_fees_req_for_fully_qualified_did() { + let expected_operation = json!({ + "type": "20001", + }); + + let get_fees_request = build_get_fees(WALLET_ID, Some(FULLY_QUALIFIED_DID)).unwrap(); + + let request_value: serde_json::value::Value = serde_json::from_str(&get_fees_request).unwrap(); + + assert_eq!(&expected_operation, request_value.get("operation").unwrap()); + assert_eq!(DID, request_value["identifier"].as_str().unwrap()); +} + #[test] fn add_fees_json_for_any_key() { sovtoken::api::sovtoken_init(); diff --git a/libsovtoken/tests/build_get_utxo_request_handler_test.rs b/libsovtoken/tests/build_get_utxo_request_handler_test.rs index 6555944c4..62d9c0b8b 100644 --- a/libsovtoken/tests/build_get_utxo_request_handler_test.rs +++ b/libsovtoken/tests/build_get_utxo_request_handler_test.rs @@ -5,6 +5,7 @@ extern crate sovtoken; extern crate indyrs as indy; extern crate libc; extern crate bs58; +extern crate indy_sys; use libc::c_char; use std::ptr; @@ -20,10 +21,10 @@ use sovtoken::logic::address::verkey_from_unqualified_address; use sovtoken::utils::results::ResultHandler; use sovtoken::utils::test::callbacks; use sovtoken::utils::ffi_support::c_pointer_from_str; -use sovtoken::{ErrorCode, IndyHandle}; +use sovtoken::ErrorCode; // ***** HELPER METHODS ***** -fn build_get_payment_sources_request(wallet_handle: IndyHandle, did: &str, payment_address: &str, from:Option) -> Result { +fn build_get_payment_sources_request(wallet_handle: indy_sys::WalletHandle, did: &str, payment_address: &str, from:Option) -> Result { let (receiver, command_handle, cb) = callbacks::cb_ec_string(); let error_code = sovtoken::api::build_get_utxo_request_handler( @@ -53,7 +54,7 @@ fn parse_get_payment_sources_response(res: &str) -> Result<(String, Option) // ***** HELPER TEST DATA ***** const COMMAND_HANDLE: i32 = 10; -const WALLET_ID: i32 = 10; +const WALLET_ID: indy_sys::WalletHandle = indy_sys::WalletHandle(10); const CB: Option i32> = Some(utils::callbacks::empty_callback); const ADDRESS: &str = "pay:sov:dctKSXBbv2My3TGGUgTFjkxu1A9JM3Sscd5FydY4dkxnfwA7q"; diff --git a/libsovtoken/tests/build_mint_txn_handler_test.rs b/libsovtoken/tests/build_mint_txn_handler_test.rs index bc7c39c99..acbc1525e 100644 --- a/libsovtoken/tests/build_mint_txn_handler_test.rs +++ b/libsovtoken/tests/build_mint_txn_handler_test.rs @@ -10,6 +10,7 @@ extern crate serde_json; extern crate log; #[macro_use] extern crate lazy_static; +extern crate indy_sys; use libc::c_char; use std::ptr; @@ -17,7 +18,7 @@ use std::ffi::CString; use indy::future::Future; -use sovtoken::{ErrorCode, IndyHandle}; +use sovtoken::ErrorCode; use sovtoken::utils::ffi_support::{str_from_char_ptr, c_pointer_from_str}; use sovtoken::utils::constants::txn_types::MINT_PUBLIC; use sovtoken::utils::constants::txn_fields::OUTPUTS; @@ -35,7 +36,7 @@ use utils::parse_mint_response::ParseMintResponse; use utils::setup::{Setup, SetupConfig}; // ***** HELPER METHODS ***** -fn build_mint_req(wallet_handle: IndyHandle, did: Option<&str>, outputs: &str, extra: Option<&str>) -> Result { +fn build_mint_req(wallet_handle: indy_sys::WalletHandle, did: Option<&str>, outputs: &str, extra: Option<&str>) -> Result { let (receiver, command_handle, cb) = callbacks::cb_ec_string(); let did = did.map(c_pointer_from_str).unwrap_or(std::ptr::null()); @@ -65,7 +66,7 @@ static VALID_OUTPUT_JSON: &'static str = r#"[{"recipient":"pay:sov:dctKSXBbv2My3 // receive an error when no callback is provided #[test] fn errors_with_no_call_back() { - let return_error = sovtoken::api::build_mint_txn_handler(COMMAND_HANDLE, 1, ptr::null(), ptr::null(), ptr::null(), None); + let return_error = sovtoken::api::build_mint_txn_handler(COMMAND_HANDLE, indy_sys::WalletHandle(1), ptr::null(), ptr::null(), ptr::null(), None); assert_eq!(return_error, ErrorCode::CommonInvalidStructure as i32, "Expecting Callback for 'build_mint_txn_handler'"); } @@ -80,7 +81,7 @@ fn errors_with_no_outputs_json() { return ErrorCode::Success as i32; } - let return_error = sovtoken::api::build_mint_txn_handler(COMMAND_HANDLE, 1, ptr::null(), ptr::null(), ptr::null(), Some(cb_no_json)); + let return_error = sovtoken::api::build_mint_txn_handler(COMMAND_HANDLE, indy_sys::WalletHandle(1), ptr::null(), ptr::null(), ptr::null(), Some(cb_no_json)); assert_eq!(return_error, ErrorCode::CommonInvalidStructure as i32, "Expecting outputs_json for 'build_mint_txn_handler'"); unsafe { assert!(!CALLBACK_CALLED) } } @@ -98,7 +99,7 @@ fn errors_with_invalid_outputs_json() { let outputs_str = CString::new(INVALID_OUTPUT_JSON).unwrap(); let outputs_str_ptr = outputs_str.as_ptr(); - let return_error = sovtoken::api::build_mint_txn_handler(COMMAND_HANDLE, 1, ptr::null(), outputs_str_ptr, ptr::null(), Some(cb_invalid_json)); + let return_error = sovtoken::api::build_mint_txn_handler(COMMAND_HANDLE, indy_sys::WalletHandle(1), ptr::null(), outputs_str_ptr, ptr::null(), Some(cb_invalid_json)); assert_eq!(return_error, ErrorCode::CommonInvalidStructure as i32, "Expecting Valid JSON for 'build_mint_txn_handler'"); unsafe { assert!(!CALLBACK_CALLED) } } @@ -135,7 +136,7 @@ fn valid_output_json() { let outputs_str_ptr = outputs_str.as_ptr(); let return_error = sovtoken::api::build_mint_txn_handler( COMMAND_HANDLE, - 1, + indy_sys::WalletHandle(1), did, outputs_str_ptr, ptr::null(), @@ -148,6 +149,44 @@ fn valid_output_json() { } } +#[test] +pub fn build_mint_txn_works_for_sov_fully_qualified_did() { + let wallet = Wallet::new(); + + let expected_operation = json!({ + "type": "10000", + "outputs": [{ + "address": "dctKSXBbv2My3TGGUgTFjkxu1A9JM3Sscd5FydY4dkxnfwA7q", + "amount":10 + }], + }); + + let mint_req = build_mint_req(wallet.handle, Some("did:sov:VsKV7grR1BUE29mG2Fm2kX"), VALID_OUTPUT_JSON, None, ).unwrap(); + + let request_value: serde_json::value::Value = serde_json::from_str(&mint_req).unwrap(); + assert_eq!(&expected_operation, request_value.get("operation").unwrap()); + assert_eq!("VsKV7grR1BUE29mG2Fm2kX", request_value["identifier"].as_str().unwrap()); +} + +#[test] +pub fn build_mint_txn_works_for_other_fully_qualified_did() { + let wallet = Wallet::new(); + + let expected_operation = json!({ + "type": "10000", + "outputs": [{ + "address": "dctKSXBbv2My3TGGUgTFjkxu1A9JM3Sscd5FydY4dkxnfwA7q", + "amount":10 + }], + }); + + let mint_req = build_mint_req(wallet.handle, Some("did:other:VsKV7grR1BUE29mG2Fm2kX"), VALID_OUTPUT_JSON, None, ).unwrap(); + + let request_value: serde_json::value::Value = serde_json::from_str(&mint_req).unwrap(); + assert_eq!(&expected_operation, request_value.get("operation").unwrap()); + assert_eq!("did:other:VsKV7grR1BUE29mG2Fm2kX", request_value["identifier"].as_str().unwrap()); +} + #[test] pub fn build_and_submit_mint_txn_works() { let wallet = Wallet::new(); diff --git a/libsovtoken/tests/build_payment_req_handler_test.rs b/libsovtoken/tests/build_payment_req_handler_test.rs index 5744827db..fa7c1d828 100644 --- a/libsovtoken/tests/build_payment_req_handler_test.rs +++ b/libsovtoken/tests/build_payment_req_handler_test.rs @@ -2,6 +2,7 @@ extern crate libc; extern crate sovtoken; extern crate indyrs as indy; // lib-sdk project extern crate bs58; +extern crate indy_sys; #[macro_use] extern crate log; #[macro_use] extern crate serde_json; @@ -16,7 +17,7 @@ use indy::future::Future; use sovtoken::logic::address; use sovtoken::logic::parsers::common::TXO; -use sovtoken::{ErrorCode, IndyHandle}; +use sovtoken::ErrorCode; use sovtoken::utils::constants::txn_types::XFER_PUBLIC; use sovtoken::utils::results::ResultHandler; use sovtoken::utils::ffi_support::{c_pointer_from_string, c_pointer_from_str}; @@ -32,11 +33,11 @@ use utils::setup::{SetupConfig, Setup}; const COMMAND_HANDLE:i32 = 10; static INVALID_OUTPUT_JSON: &'static str = r#"{"totally" : "Not a Number", "bobby" : "DROP ALL TABLES"}"#; static VALID_OUTPUT_JSON: &'static str = r#"{"outputs":[["AesjahdahudgaiuNotARealAKeyygigfuigraiudgfasfhja",10]]}"#; -const WALLET_HANDLE:i32 = 0; +const WALLET_HANDLE:indy_sys::WalletHandle = indy_sys::WalletHandle(0); const CB : Option i32 > = Some(utils::callbacks::empty_callback); // ***** HELPER METHODS ***** -fn build_payment_req(wallet_handle: IndyHandle, did: &str, inputs: &str, outputs: &str, extra: Option) -> Result { +fn build_payment_req(wallet_handle: indy_sys::WalletHandle, did: &str, inputs: &str, outputs: &str, extra: Option) -> Result { let (receiver, command_handle, cb) = callbacks::cb_ec_string(); let extra = extra.map(c_pointer_from_string).unwrap_or(std::ptr::null()); @@ -89,7 +90,7 @@ fn generate_payment_addresses(wallet: &Wallet) -> (Vec, Vec) { return (payment_addresses, addresses); } -fn get_resp_for_payment_req(pool_handle: i32, wallet_handle: i32, did: &str, +fn get_resp_for_payment_req(pool_handle: i32, wallet_handle: indy_sys::WalletHandle, did: &str, inputs: &str, outputs: &str, extra: Option) -> Result { let req = build_payment_req(wallet_handle, did, inputs, outputs, extra).unwrap(); let res = indy::ledger::submit_request(pool_handle, &req).wait().unwrap(); @@ -224,7 +225,7 @@ fn success_signed_request() { } -#[test] // TODO: look carefully on changes +#[test] fn success_signed_request_from_libindy_no_identifier() { sovtoken::api::sovtoken_init(); diff --git a/libsovtoken/tests/build_verify_req_test.rs b/libsovtoken/tests/build_verify_req_test.rs index 7e92cb498..5e509651e 100644 --- a/libsovtoken/tests/build_verify_req_test.rs +++ b/libsovtoken/tests/build_verify_req_test.rs @@ -3,6 +3,7 @@ #[macro_use] extern crate lazy_static; extern crate sovtoken; extern crate indyrs as indy; +extern crate indy_sys; use std::{thread, time}; @@ -10,7 +11,7 @@ use indy::future::Future; mod utils; -use sovtoken::{ErrorCode, IndyHandle}; +use sovtoken::ErrorCode; use sovtoken::logic::parsers::common::TXO; use sovtoken::utils::results::ResultHandler; use sovtoken::utils::test::callbacks; @@ -24,7 +25,7 @@ fn sleep(msec: u64) { thread::sleep(ms); } -fn build_verify_payment_req(wallet_handle: IndyHandle, did: Option<&str>, txo: &str) -> Result { +fn build_verify_payment_req(wallet_handle: indy_sys::WalletHandle, did: Option<&str>, txo: &str) -> Result { let (receiver, command_handle, cb) = callbacks::cb_ec_string(); let did = did.map(c_pointer_from_str).unwrap_or(std::ptr::null()); @@ -61,17 +62,34 @@ fn build_verify_payment_request() { "data": 28 }); - let request = build_verify_payment_req(1, None, txo).unwrap(); + let request = build_verify_payment_req(indy_sys::WalletHandle(1), None, txo).unwrap(); let request_value: serde_json::value::Value = serde_json::from_str(&request).unwrap(); assert_eq!(&expected_operation, request_value.get("operation").unwrap()); } +#[test] +fn build_verify_payment_request_for_fully_qualified_did() { + let txo = "txo:sov:3x42qH8UkJac1BuorqjSEvuVjvYkXk8sUAqoVPn1fGCwjLPquu4CndzBHBQ5hX6RSmDVnXGdMPrnWDUN5S1ty4YQP87hW8ubMSzu9M56z1FbAQV6aMSX5h"; + let expected_operation = json!({ + "type": "3", + "ledgerId": 1001, + "data": 28 + }); + + let request = build_verify_payment_req(indy_sys::WalletHandle(1), Some("did:sov:VsKV7grR1BUE29mG2Fm2kX"), txo).unwrap(); + + let request_value: serde_json::value::Value = serde_json::from_str(&request).unwrap(); + + assert_eq!(&expected_operation, request_value.get("operation").unwrap()); + assert_eq!("VsKV7grR1BUE29mG2Fm2kX", request_value["identifier"].as_str().unwrap()); +} + #[test] fn build_verify_payment_for_invalid_txo() { let txo = "txo:sov:3x42qH8"; - let res = build_verify_payment_req(1, None, txo).unwrap_err(); + let res = build_verify_payment_req(indy_sys::WalletHandle(1), None, txo).unwrap_err(); assert_eq!(ErrorCode::CommonInvalidStructure, res); } diff --git a/libsovtoken/tests/create_payment_addres_handler_tests.rs b/libsovtoken/tests/create_payment_addres_handler_tests.rs index b748c814c..52b3c81f7 100644 --- a/libsovtoken/tests/create_payment_addres_handler_tests.rs +++ b/libsovtoken/tests/create_payment_addres_handler_tests.rs @@ -12,6 +12,7 @@ extern crate libc; extern crate indyrs as indy; // lib-sdk project extern crate sovtoken; +extern crate indy_sys; use std::ptr; use std::ffi::CString; @@ -25,7 +26,7 @@ use sovtoken::ErrorCode; mod utils; // ***** HELPER TEST DATA ***** -const WALLET_ID: i32 = 99; +const WALLET_ID: indy_sys::WalletHandle = indy_sys::WalletHandle(99); const COMMAND_HANDLE: i32 = 1; const TIMEOUT_SECONDS: u64 = 20; static INVALID_CONFIG_JSON: &'static str = r#"{ "horrible" : "only on tuedays"}"#; diff --git a/libsovtoken/tests/create_payment_tests.rs b/libsovtoken/tests/create_payment_tests.rs index af794072a..c84611211 100644 --- a/libsovtoken/tests/create_payment_tests.rs +++ b/libsovtoken/tests/create_payment_tests.rs @@ -13,6 +13,7 @@ extern crate rand; extern crate indyrs as indy; // lib-sdk project extern crate sovtoken; +extern crate indy_sys; use libc::c_char; use rand::Rng; @@ -29,7 +30,7 @@ use sovtoken::ErrorCode; mod utils; // ***** HELPER TEST DATA ***** -const WALLET_ID: i32 = 99; +const WALLET_ID: indy_sys::WalletHandle = indy_sys::WalletHandle(99); const COMMAND_HANDLE: i32 = 1; const TIMEOUT_SECONDS: u64 = 20; static VALID_SEED_LEN: usize = 32; diff --git a/libsovtoken/tests/payment_chaos_tests.rs b/libsovtoken/tests/payment_chaos_tests.rs index 7bf931c0e..9995a8c6e 100644 --- a/libsovtoken/tests/payment_chaos_tests.rs +++ b/libsovtoken/tests/payment_chaos_tests.rs @@ -1,6 +1,7 @@ extern crate libc; extern crate sovtoken; extern crate indyrs as indy; // lib-sdk project +extern crate indy_sys; #[macro_use] extern crate serde_derive; #[macro_use] extern crate serde_json; diff --git a/libsovtoken/tests/utils/did.rs b/libsovtoken/tests/utils/did.rs index 3e4912d8c..a8dae6ae2 100644 --- a/libsovtoken/tests/utils/did.rs +++ b/libsovtoken/tests/utils/did.rs @@ -1,5 +1,6 @@ extern crate indyrs as indy; extern crate sovtoken; +extern crate indy_sys; use indy::future::Future; @@ -35,7 +36,7 @@ impl NymRole Generate a did and send a nym request for it. */ pub fn create_nym( - wallet_handle: i32, + wallet_handle: indy_sys::WalletHandle, pool_handle: i32, did_trustee: &str, role: NymRole @@ -59,7 +60,7 @@ pub fn create_nym( Creates multiple dids and corresponding nym requests. */ pub fn create_multiple_nym( - wallet_handle: i32, + wallet_handle: indy_sys::WalletHandle, pool_handle: i32, did_trustee: &str, n: u8, @@ -79,7 +80,7 @@ Create and store the initial dids of trustees. Includes the initial trustee. */ -pub fn initial_trustees(num_trustees: u8, wallet_handle: i32, pool_handle: i32) -> Vec { +pub fn initial_trustees(num_trustees: u8, wallet_handle: indy_sys::WalletHandle, pool_handle: i32) -> Vec { let first = initial_trustee(wallet_handle); let mut trustees = create_multiple_nym( @@ -97,7 +98,7 @@ pub fn initial_trustees(num_trustees: u8, wallet_handle: i32, pool_handle: i32) /** Store the did of the intial trustee */ -pub fn initial_trustee(wallet_handle: i32) -> DidAndVerKey { +pub fn initial_trustee(wallet_handle: indy_sys::WalletHandle) -> DidAndVerKey { let first_json_seed = json!({ "seed":"000000000000000000000000Trustee1" }).to_string(); diff --git a/libsovtoken/tests/utils/mint.rs b/libsovtoken/tests/utils/mint.rs index 2bac40837..7a57200df 100644 --- a/libsovtoken/tests/utils/mint.rs +++ b/libsovtoken/tests/utils/mint.rs @@ -1,5 +1,6 @@ extern crate indyrs as indy; extern crate serde_json; +extern crate indy_sys; use std::collections::HashMap; use std::str::FromStr; @@ -13,7 +14,7 @@ use utils; use indy::future::Future; -pub fn mint_tokens(cfg: HashMap, pool_handle: i32, wallet_handle: i32, trustee_dids: &Vec<&str>) -> Result { +pub fn mint_tokens(cfg: HashMap, pool_handle: i32, wallet_handle: indy_sys::WalletHandle, trustee_dids: &Vec<&str>) -> Result { let vec_outputs:Vec> = cfg.iter().map(|(pa, am)| { let mut map = HashMap::new(); map.insert("recipient", serde_json::Value::String(pa.clone())); diff --git a/libsovtoken/tests/utils/payment/fees.rs b/libsovtoken/tests/utils/payment/fees.rs index dfe35d7df..d2bf80d9d 100644 --- a/libsovtoken/tests/utils/payment/fees.rs +++ b/libsovtoken/tests/utils/payment/fees.rs @@ -1,3 +1,5 @@ +extern crate indy_sys; + use sovtoken::utils::constants::general::PAYMENT_METHOD_NAME; use sovtoken::logic::config::set_fees_config::SetFees; use sovtoken::logic::request::Request; @@ -5,7 +7,7 @@ use utils::wallet::Wallet; use indy::future::Future; -use std::sync::{Once, ONCE_INIT}; +use std::sync::Once; use std::sync::Mutex; use std::collections::HashMap; @@ -121,7 +123,7 @@ pub struct AuthRule { constraint: Constraint } -pub fn set_fees(pool_handle: i32, wallet_handle: i32, payment_method: &str, fees: &str, dids: &Vec<&str>, submitter_did: Option<&str>) { +pub fn set_fees(pool_handle: i32, wallet_handle: indy_sys::WalletHandle, payment_method: &str, fees: &str, dids: &Vec<&str>, submitter_did: Option<&str>) { let set_fees_req = ::indy::payments::build_set_txn_fees_req(wallet_handle, submitter_did, payment_method, &fees).wait().unwrap(); let set_fees_req = Request::::multi_sign_request(wallet_handle, &set_fees_req, dids.to_vec()).unwrap(); ::indy::ledger::submit_request(pool_handle, &set_fees_req).wait().unwrap(); @@ -136,7 +138,7 @@ pub fn set_fees(pool_handle: i32, wallet_handle: i32, payment_method: &str, fees } // Helper to set fee alias for auth rules -pub fn set_auth_rules_fee(pool_handle: i32, wallet_handle: i32, submitter_did: &str, txn_fees: &str) { +pub fn set_auth_rules_fee(pool_handle: i32, wallet_handle: indy_sys::WalletHandle, submitter_did: &str, txn_fees: &str) { _get_default_ledger_auth_rules(pool_handle); let auth_rules = AUTH_RULES.lock().unwrap(); @@ -156,7 +158,7 @@ pub fn set_auth_rules_fee(pool_handle: i32, wallet_handle: i32, submitter_did: & _send_auth_rules(pool_handle, wallet_handle, submitter_did, &auth_rules) } -fn _send_auth_rules(pool_handle: i32, wallet_handle: i32, submitter_did: &str, data: &Vec) { +fn _send_auth_rules(pool_handle: i32, wallet_handle: indy_sys::WalletHandle, submitter_did: &str, data: &Vec) { let data = ::serde_json::to_string(&data).unwrap(); let auth_rules_request = ::indy::ledger::build_auth_rules_request(submitter_did, &data).wait().unwrap(); @@ -169,7 +171,7 @@ fn _send_auth_rules(pool_handle: i32, wallet_handle: i32, submitter_did: &str, d fn _get_default_ledger_auth_rules(pool_handle: i32) { lazy_static! { - static ref GET_DEFAULT_AUTH_CONSTRAINTS: Once = ONCE_INIT; + static ref GET_DEFAULT_AUTH_CONSTRAINTS: Once = Once::new(); } diff --git a/libsovtoken/tests/utils/wallet.rs b/libsovtoken/tests/utils/wallet.rs index 6b5b3661a..f30f206cc 100644 --- a/libsovtoken/tests/utils/wallet.rs +++ b/libsovtoken/tests/utils/wallet.rs @@ -4,6 +4,7 @@ extern crate indyrs as indy; extern crate sovtoken; +extern crate indy_sys; use self::indy::wallet; use self::sovtoken::utils::random::rand_string; @@ -37,14 +38,14 @@ assert!(wallet.handle > 0); */ pub struct Wallet { name: String, - pub handle: i32, + pub handle: indy_sys::WalletHandle, } impl Wallet { /* constructors */ pub fn new() -> Wallet { let wallet_name: String = rand_string(20); - let mut wallet = Wallet { name: wallet_name, handle: -1 }; + let mut wallet = Wallet { name: wallet_name, handle: indy_sys::WalletHandle(-1) }; wallet.create(); wallet.open(); @@ -52,7 +53,7 @@ impl Wallet { } pub fn from_name(name: &str) -> Wallet { - let mut wallet = Wallet { name: name.to_string(), handle: -1 }; + let mut wallet = Wallet { name: name.to_string(), handle: indy_sys::WalletHandle(-1) }; wallet.create(); wallet.open(); @@ -67,7 +68,7 @@ impl Wallet { /* private instance methods for open/create/etc...*/ - fn open(&mut self) -> i32 { + fn open(&mut self) -> indy_sys::WalletHandle { let config: String = Wallet::create_wallet_config(&self.name); let handle = wallet::open_wallet(&config, USEFUL_CREDENTIALS).wait().unwrap(); self.handle = handle;