From 50f5565cfa1a9499d3a47eeed36f3d40c66aac4c Mon Sep 17 00:00:00 2001 From: k-matsuzawa <49718559+ko-matsu@users.noreply.github.com> Date: Wed, 2 Dec 2020 16:53:35 +0900 Subject: [PATCH] update to v0.2.2 (#16) * update from cryptogarageinc v0.2.5 Co-authored-by: k-matsuzawa --- .github/workflows/check_pre-merge.yml | 62 +++++ .github/workflows/check_pre-merge_develop.yml | 38 --- .github/workflows/check_pre-merge_master.yml | 38 --- .github/workflows/check_pre-merge_sprint.yml | 43 ---- .github/workflows/code_scanner.yml | 11 +- .../workflows/create_release-and-upload.yml | 18 +- .../CfdCsharpProject.CliTests.csproj | 2 +- .../CfdCsharpProject.xTests.csproj | 2 +- .../CfdCsharpProject/CfdCsharpProject.csproj | 2 +- external/CMakeLists.txt | 2 +- src/ConfidentialTransaction.cs | 236 +++++++++++++++++- src/internal/NativeMethods.cs | 15 ++ test/CoinSelectionUtilTest.cs | 2 +- test/ConfidentialTransactionTest.cs | 21 +- tools/build.bat | 9 + tools/build.sh | 6 +- tools/build_core3.bat | 9 +- tools/build_core3.sh | 24 ++ tools/clitest_debug.bat | 2 +- tools/test.bat | 6 +- tools/test.sh | 6 +- tools/test_core3.bat | 6 +- tools/test_core3.sh | 14 ++ tools/test_direct.bat | 4 +- tools/test_direct.sh | 4 +- tools/test_direct_3.1.bat | 11 + tools/test_direct_3.1.sh | 9 + 27 files changed, 440 insertions(+), 162 deletions(-) create mode 100644 .github/workflows/check_pre-merge.yml delete mode 100644 .github/workflows/check_pre-merge_develop.yml delete mode 100644 .github/workflows/check_pre-merge_master.yml delete mode 100644 .github/workflows/check_pre-merge_sprint.yml create mode 100755 tools/build_core3.sh create mode 100755 tools/test_core3.sh create mode 100644 tools/test_direct_3.1.bat create mode 100755 tools/test_direct_3.1.sh diff --git a/.github/workflows/check_pre-merge.yml b/.github/workflows/check_pre-merge.yml new file mode 100644 index 0000000..b1ed61f --- /dev/null +++ b/.github/workflows/check_pre-merge.yml @@ -0,0 +1,62 @@ +name: pre-merge check + +on: + push: + branches: + - master + - develop + - features/sprint* + pull_request: + branches: + - master + - develop + - features/sprint* + +jobs: + test-dotnet5: + name: dotnet 5.0 + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [macos-10.15, macos-11.0, windows-2019, ubuntu-20.04, ubuntu-18.04] + + steps: + - name: setup dotnet + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 5.0.x + - uses: actions/checkout@v2 + - name: build and test + if: runner.os != 'Windows' + run: | + ./tools/build.sh + ./tools/test.sh + - name: build and test on win + if: runner.os == 'Windows' + run: | + ./tools/build.bat + ./tools/test.bat + + test-dotnet3: + name: dotnet 3.1 + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [macos-10.15, windows-2019, ubuntu-20.04, ubuntu-18.04] + + steps: + - name: setup dotnet + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 3.1.x + - uses: actions/checkout@v2 + - name: build and test + if: runner.os != 'Windows' + run: | + ./tools/build_core3.sh + ./tools/test_core3.sh + - name: build and test on win + if: runner.os == 'Windows' + run: | + ./tools/build_core3.bat + ./tools/test_core3.bat diff --git a/.github/workflows/check_pre-merge_develop.yml b/.github/workflows/check_pre-merge_develop.yml deleted file mode 100644 index 4d98181..0000000 --- a/.github/workflows/check_pre-merge_develop.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: develop pre-merge check - -on: - push: - branches: - - develop - pull_request: - branches: - - develop - -env: - CMAKE_VERSION: 3.17.2 - -jobs: - cmake-build: - name: cmake build - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [macos-latest, windows-latest, ubuntu-latest] - dotnet: [3.1.200] - - steps: - - name: setup dotnet - uses: actions/setup-dotnet@v1 - with: - dotnet-version: ${{ matrix.dotnet }} - - uses: actions/checkout@v2 - - name: build and test - if: matrix.os != 'windows-latest' - run: | - ./tools/build.sh - ./tools/test.sh - - name: build and test on win - if: matrix.os == 'windows-latest' - run: | - ./tools/build_core3.bat - ./tools/test_core3.bat diff --git a/.github/workflows/check_pre-merge_master.yml b/.github/workflows/check_pre-merge_master.yml deleted file mode 100644 index 1722e2d..0000000 --- a/.github/workflows/check_pre-merge_master.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: master pre-merge check - -on: - push: - branches: - - master - pull_request: - branches: - - master - -env: - CMAKE_VERSION: 3.17.2 - -jobs: - cmake-build: - name: cmake build - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [macos-latest, windows-latest, ubuntu-latest] - dotnet: [3.1.200] - - steps: - - name: setup dotnet - uses: actions/setup-dotnet@v1 - with: - dotnet-version: ${{ matrix.dotnet }} - - uses: actions/checkout@v2 - - name: build and test - if: matrix.os != 'windows-latest' - run: | - ./tools/build.sh - ./tools/test.sh - - name: build and test on win - if: matrix.os == 'windows-latest' - run: | - ./tools/build_core3.bat - ./tools/test_core3.bat diff --git a/.github/workflows/check_pre-merge_sprint.yml b/.github/workflows/check_pre-merge_sprint.yml deleted file mode 100644 index 15a700e..0000000 --- a/.github/workflows/check_pre-merge_sprint.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: sprint pre-merge check - -on: - push: - branches: - - features/sprint* - pull_request: - branches: - - features/sprint* - -env: - CMAKE_VERSION: 3.17.2 - -jobs: - cmake-build: - name: cmake build - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [macos-latest, windows-latest, ubuntu-latest] - dotnet: [3.1.200] - - steps: - - name: setup dotnet - uses: actions/setup-dotnet@v1 - with: - dotnet-version: ${{ matrix.dotnet }} - - uses: actions/checkout@v2 - - name: build and test on ubuntu - if: matrix.os == 'ubuntu-latest' - run: | - ./tools/build.sh - ./tools/test.sh - - name: build and test on mac - if: matrix.os == 'macos-latest' - run: | - ./tools/build.sh - ./tools/test.sh - - name: build and test on windows - if: matrix.os == 'windows-latest' - run: | - .\tools\build.bat - .\tools\test.bat diff --git a/.github/workflows/code_scanner.yml b/.github/workflows/code_scanner.yml index 6e5c362..79fc7a9 100644 --- a/.github/workflows/code_scanner.yml +++ b/.github/workflows/code_scanner.yml @@ -7,6 +7,10 @@ on: - develop - features/sprint* - feature/code_scanning + paths: + - '**.cs' + - '**/code_scanner.yml' + - '**/external_project_local_setting.config' pull_request: branches: - master @@ -16,7 +20,7 @@ on: jobs: analyze-CodeQL: name: CodeQL - runs-on: ubuntu-latest + runs-on: ubuntu-18.04 strategy: fail-fast: false @@ -34,6 +38,11 @@ jobs: # We must fetch at least the immediate parents so that if this is a pull request then we can checkout the head. fetch-depth: 2 + - name: setup dotnet + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 5.0.x + # If this run was triggered by a pull request event, then checkout the head of the pull request instead of the merge commit. - run: git checkout HEAD^2 if: ${{ github.event_name == 'pull_request' }} diff --git a/.github/workflows/create_release-and-upload.yml b/.github/workflows/create_release-and-upload.yml index 504e47a..3d59f3e 100644 --- a/.github/workflows/create_release-and-upload.yml +++ b/.github/workflows/create_release-and-upload.yml @@ -12,7 +12,7 @@ env: jobs: create_releases: name: create-releases - runs-on: ubuntu-latest + runs-on: ubuntu-18.04 outputs: release_url: ${{ steps.output_url.outputs.upload_url }} @@ -48,7 +48,7 @@ jobs: upload-object-windows: name: upload-object-win needs: create_releases - runs-on: windows-latest + runs-on: windows-2019 steps: - name: setup dotnet @@ -71,8 +71,8 @@ jobs: shell: bash - name: cmake-build run: | - .\tools\build.bat - .\tools\test.bat + .\tools\build_core3.bat + .\tools\test_core3.bat timeout-minutes: 20 - name: cmake-install shell: cmd @@ -119,10 +119,10 @@ jobs: run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} - name: cmake-build run: | - ./tools/build.sh + ./tools/build_core3.sh - name: test run: | - ./tools/test.sh + ./tools/test_core3.sh - name: create archive file run: | mkdir dist @@ -148,7 +148,7 @@ jobs: upload-object-macos: name: upload-object-macos needs: create_releases - runs-on: macos-latest + runs-on: macos-10.15 steps: - name: setup dotnet @@ -166,10 +166,10 @@ jobs: run: xcodebuild -version - name: cmake-build run: | - ./tools/build.sh + ./tools/build_core3.sh - name: test run: | - ./tools/test.sh + ./tools/test_core3.sh - name: create archive file run: | mkdir dist diff --git a/dotnet_project/CfdCsharpProject.CliTests/CfdCsharpProject.CliTests.csproj b/dotnet_project/CfdCsharpProject.CliTests/CfdCsharpProject.CliTests.csproj index 6bbdbf9..494fe05 100644 --- a/dotnet_project/CfdCsharpProject.CliTests/CfdCsharpProject.CliTests.csproj +++ b/dotnet_project/CfdCsharpProject.CliTests/CfdCsharpProject.CliTests.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.0 + net5.0;netcoreapp3.1 Cfd.Tests.Cli.CfdCliTestMain cfdcs_test cfdcs_test diff --git a/dotnet_project/CfdCsharpProject.xTests/CfdCsharpProject.xTests.csproj b/dotnet_project/CfdCsharpProject.xTests/CfdCsharpProject.xTests.csproj index 454fdb7..028bad8 100644 --- a/dotnet_project/CfdCsharpProject.xTests/CfdCsharpProject.xTests.csproj +++ b/dotnet_project/CfdCsharpProject.xTests/CfdCsharpProject.xTests.csproj @@ -1,7 +1,7 @@ - netcoreapp3.0 + net5.0;netcoreapp3.1 false diff --git a/dotnet_project/CfdCsharpProject/CfdCsharpProject.csproj b/dotnet_project/CfdCsharpProject/CfdCsharpProject.csproj index a9d1d09..38272dd 100644 --- a/dotnet_project/CfdCsharpProject/CfdCsharpProject.csproj +++ b/dotnet_project/CfdCsharpProject/CfdCsharpProject.csproj @@ -1,7 +1,7 @@ - netstandard2.1 + net5.0;netstandard2.1 cfdcs x64 diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 2375a8b..4ebcc93 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -43,7 +43,7 @@ if(CFD_TARGET_VERSION) set(CFD_TARGET_TAG ${CFD_TARGET_VERSION}) message(STATUS "[external project local] cfd target=${CFD_TARGET_VERSION}") else() -set(CFD_TARGET_TAG v0.2.0) +set(CFD_TARGET_TAG v0.2.2) endif() if(CFD_TARGET_URL) set(CFD_TARGET_REP ${CFD_TARGET_URL}) diff --git a/src/ConfidentialTransaction.cs b/src/ConfidentialTransaction.cs index f129f52..c09bc9d 100644 --- a/src/ConfidentialTransaction.cs +++ b/src/ConfidentialTransaction.cs @@ -11,6 +11,7 @@ public enum CfdBlindOption MinimumRangeValue = 1, //!< minRangeValue Exponent = 2, //!< exponent MinimumBits = 3, //!< minBits + CollectBlinder = 4, //!< collect blinder data } /// @@ -21,12 +22,46 @@ public struct CfdBlindOptionData : IEquatable public long MinimumRangeValue { get; } public int Exponent { get; } public int MinimumBits { get; } + public bool CollectBlinder { get; } + + public CfdBlindOptionData(bool collectBlinder) + { + MinimumRangeValue = 1; + Exponent = 0; + MinimumBits = ConfidentialTransaction.defaultMinimumBits; + CollectBlinder = collectBlinder; + } + + public CfdBlindOptionData(int minimumBits) + { + MinimumRangeValue = 1; + Exponent = 0; + MinimumBits = minimumBits; + CollectBlinder = false; + } + + public CfdBlindOptionData(int minimumBits, bool collectBlinder) + { + MinimumRangeValue = 1; + Exponent = 0; + MinimumBits = minimumBits; + CollectBlinder = collectBlinder; + } public CfdBlindOptionData(long minimumRangeValue, int exponent, int minimumBits) { MinimumRangeValue = minimumRangeValue; Exponent = exponent; MinimumBits = minimumBits; + CollectBlinder = false; + } + + public CfdBlindOptionData(long minimumRangeValue, int exponent, int minimumBits, bool collectBlinder) + { + MinimumRangeValue = minimumRangeValue; + Exponent = exponent; + MinimumBits = minimumBits; + CollectBlinder = collectBlinder; } public bool Equals(CfdBlindOptionData other) @@ -61,6 +96,82 @@ public override int GetHashCode() } } + /// + /// Blind data. + /// + public struct CfdBlindData : IEquatable + { + public uint Vout { get; } + public string Asset { get; } + public long SatoshiValue { get; } + public BlindFactor AssetBlindFactor { get; } + public BlindFactor AmountBlindFactor { get; } + public OutPoint IssuanceOutPoint { get; } + public bool IsIssuanceAsset { get; } + public bool IsIssuanceToken { get; } + + public CfdBlindData(uint vout, string asset, long amount, string assetBlinder, + string amountBlinder, string issuanceTxid, uint issuanceVout, + bool isIssuanceAsset, bool isIssuanceToken) + { + Vout = vout; + Asset = asset; + SatoshiValue = amount; + AssetBlindFactor = new BlindFactor(assetBlinder); + AmountBlindFactor = new BlindFactor(amountBlinder); + if (String.IsNullOrEmpty(issuanceTxid)) + { + IssuanceOutPoint = new OutPoint(); + } + else + { + IssuanceOutPoint = new OutPoint(issuanceTxid, issuanceVout); + } + IsIssuanceAsset = isIssuanceAsset; + IsIssuanceToken = isIssuanceToken; + } + + public bool IsIssuance() + { + return IsIssuanceAsset || IsIssuanceToken; + } + + public bool Equals(CfdBlindData other) + { + return Vout.Equals(other.Vout) && SatoshiValue.Equals(other.SatoshiValue) && + Asset.Equals(other.Asset, StringComparison.Ordinal) && + IssuanceOutPoint.Equals(other.IssuanceOutPoint) && + IsIssuanceAsset.Equals(other.IsIssuanceAsset) && + IsIssuanceToken.Equals(other.IsIssuanceToken); + } + + public override bool Equals(object obj) + { + if (obj is CfdBlindData) + { + return Equals((CfdBlindData)obj); + } + return false; + } + + public override int GetHashCode() + { + return Vout.GetHashCode() + Asset.GetHashCode(StringComparison.Ordinal) + + SatoshiValue.GetHashCode() + IssuanceOutPoint.GetHashCode() + + IsIssuanceAsset.GetHashCode() + IsIssuanceToken.GetHashCode(); + } + + public static bool operator ==(CfdBlindData left, CfdBlindData right) + { + return left.Equals(right); + } + + public static bool operator !=(CfdBlindData left, CfdBlindData right) + { + return !(left == right); + } + } + /// /// asset and amountValue data struct. /// @@ -932,11 +1043,25 @@ public void AddTxOutList(ConfidentialTxOut[] txoutList) /// /// txin utxo list /// txout confidential key list + /// txout confidential key list public void BlindTxOut(IDictionary utxos, IDictionary confidentialKeys) { - BlindTransaction(utxos, new Dictionary(), - confidentialKeys); + BlindTxOut(utxos, confidentialKeys, false); + } + + /// + /// Blind transction txout only. + /// + /// txin utxo list + /// txout confidential key list + /// blinder collect flag + /// blinder list + public CfdBlindData[] BlindTxOut(IDictionary utxos, + IDictionary confidentialKeys, bool collectBlinder) + { + return BlindTransaction(utxos, new Dictionary(), + confidentialKeys, collectBlinder); } /// @@ -948,6 +1073,20 @@ public void BlindTxOut(IDictionary utxos, public void BlindTransaction(IDictionary utxos, IDictionary issuanceKeys, IDictionary confidentialKeys) + { + BlindTransaction(utxos, issuanceKeys, confidentialKeys, false); + } + + /// + /// Blind transction. + /// + /// txin utxo list + /// issuance blinding key list + /// txout confidential key list + /// blinder list + public CfdBlindData[] BlindTransaction(IDictionary utxos, + IDictionary issuanceKeys, + IDictionary confidentialKeys, bool collectBlinder) { if (issuanceKeys is null) { @@ -1016,6 +1155,15 @@ public void BlindTransaction(IDictionary utxos, { handle.ThrowError(ret); } + if (collectBlinder) + { + ret = NativeMethods.CfdSetBlindTxOption( + handle.GetHandle(), blindHandle, (int)CfdBlindOption.CollectBlinder, 1); + if (ret != CfdErrorCode.Success) + { + handle.ThrowError(ret); + } + } ret = NativeMethods.CfdFinalizeBlindTx( handle.GetHandle(), blindHandle, tx, @@ -1025,6 +1173,42 @@ public void BlindTransaction(IDictionary utxos, handle.ThrowError(ret); } tx = CCommon.ConvertToString(txHexString); + + CfdBlindData[] blinderList; + if (collectBlinder) + { + List list = new List(); + for (uint index = 0; index < uint.MaxValue; ++index) + { + ret = NativeMethods.CfdGetBlindTxBlindData( + handle.GetHandle(), blindHandle, index, + out uint vout, out IntPtr asset, out long valueSatoshi, + out IntPtr assetBlindFactor, out IntPtr valueBlindFactor, + out IntPtr issuanceTxid, out uint issuanceVout, + out bool isIssuanceAsset, out bool isIssuanceToken); + if (ret == CfdErrorCode.OutOfRangeError) + { + break; + } + else if (ret != CfdErrorCode.Success) + { + handle.ThrowError(ret); + } + var assetStr = CCommon.ConvertToString(asset); + var abf = CCommon.ConvertToString(assetBlindFactor); + var vbf = CCommon.ConvertToString(valueBlindFactor); + var txid = CCommon.ConvertToString(issuanceTxid); + list.Add(new CfdBlindData( + vout, assetStr, valueSatoshi, abf, vbf, txid, issuanceVout, + isIssuanceAsset, isIssuanceToken)); + } + blinderList = list.ToArray(); + } + else + { + blinderList = Array.Empty(); + } + return blinderList; } finally { @@ -1054,7 +1238,8 @@ public void BlindTransaction(ElementsUtxoData[] utxos, /// issuance blinding keys /// txout's confidential address list /// blind option - public void BlindTransaction(ElementsUtxoData[] utxos, + /// blinder list + public CfdBlindData[] BlindTransaction(ElementsUtxoData[] utxos, IDictionary issuanceKeys, ConfidentialAddress[] confidentialAddresses, CfdBlindOptionData option) { @@ -1101,6 +1286,15 @@ public void BlindTransaction(ElementsUtxoData[] utxos, { handle.ThrowError(ret); } + if (option.CollectBlinder) + { + ret = NativeMethods.CfdSetBlindTxOption( + handle.GetHandle(), blindHandle, (int)CfdBlindOption.CollectBlinder, 1); + if (ret != CfdErrorCode.Success) + { + handle.ThrowError(ret); + } + } foreach (var utxo in utxos) { @@ -1148,6 +1342,42 @@ public void BlindTransaction(ElementsUtxoData[] utxos, handle.ThrowError(ret); } tx = CCommon.ConvertToString(txHexString); + + CfdBlindData[] blinderList; + if (option.CollectBlinder) + { + List list = new List(); + for (uint index = 0; index < uint.MaxValue; ++index) + { + ret = NativeMethods.CfdGetBlindTxBlindData( + handle.GetHandle(), blindHandle, index, + out uint vout, out IntPtr asset, out long valueSatoshi, + out IntPtr assetBlindFactor, out IntPtr valueBlindFactor, + out IntPtr issuanceTxid, out uint issuanceVout, + out bool isIssuanceAsset, out bool isIssuanceToken); + if (ret == CfdErrorCode.OutOfRangeError) + { + break; + } + else if (ret != CfdErrorCode.Success) + { + handle.ThrowError(ret); + } + var assetStr = CCommon.ConvertToString(asset); + var abf = CCommon.ConvertToString(assetBlindFactor); + var vbf = CCommon.ConvertToString(valueBlindFactor); + var txid = CCommon.ConvertToString(issuanceTxid); + list.Add(new CfdBlindData( + vout, assetStr, valueSatoshi, abf, vbf, txid, issuanceVout, + isIssuanceAsset, isIssuanceToken)); + } + blinderList = list.ToArray(); + } + else + { + blinderList = Array.Empty(); + } + return blinderList; } finally { diff --git a/src/internal/NativeMethods.cs b/src/internal/NativeMethods.cs index e47910b..ccfd7d2 100644 --- a/src/internal/NativeMethods.cs +++ b/src/internal/NativeMethods.cs @@ -599,6 +599,21 @@ internal static extern CfdErrorCode CfdFinalizeBlindTx( [In] string txHexString, [Out] out IntPtr txString); + [DllImport("cfd", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] + internal static extern CfdErrorCode CfdGetBlindTxBlindData( + [In] IntPtr handle, + [In] IntPtr blindHandle, + [In] uint index, + [Out] out uint vout, + [Out] out IntPtr asset, + [Out] out long valueSatoshi, + [Out] out IntPtr assetBlindFactor, + [Out] out IntPtr valueBlindFactor, + [Out] out IntPtr issuanceTxid, + [Out] out uint issuanceVout, + [Out] out bool isIssuanceAsset, + [Out] out bool isIssuanceToken); + [DllImport("cfd", CallingConvention = CallingConvention.StdCall)] internal static extern CfdErrorCode CfdFreeBlindHandle( [In] IntPtr handle, diff --git a/test/CoinSelectionUtilTest.cs b/test/CoinSelectionUtilTest.cs index ed56c01..5d9f134 100644 --- a/test/CoinSelectionUtilTest.cs +++ b/test/CoinSelectionUtilTest.cs @@ -231,7 +231,7 @@ public void SelectCoinsTest13() public void SelectCoinsErrorTest01() { CoinSelectionUtil util = new CoinSelectionUtil(); - UtxoData[] utxos = new UtxoData[0]; + UtxoData[] utxos = Array.Empty(); try { util.SelectCoins(utxos, 1500, 100000000, 20.0); diff --git a/test/ConfidentialTransactionTest.cs b/test/ConfidentialTransactionTest.cs index 2eb9aa2..a373fb7 100644 --- a/test/ConfidentialTransactionTest.cs +++ b/test/ConfidentialTransactionTest.cs @@ -250,7 +250,7 @@ public void BlindTxTest() confidentialKeys.Add( 3, new Pubkey("03ce4c4eac09fe317f365e45c00ffcf2e9639bc0fd792c10f72cdc173c4e5ed879")); - tx.BlindTransaction(utxos, issuanceKeys, confidentialKeys); + var blinderList = tx.BlindTransaction(utxos, issuanceKeys, confidentialKeys, true); // Console.WriteLine(" - txid = " + tx.GetTxid().ToHexString()); // Console.WriteLine(" - wtxid = " + tx.GetWtxid().ToHexString()); // Console.WriteLine(" - witHash = " + tx.GetWitHash()); @@ -263,6 +263,7 @@ public void BlindTxTest() Assert.Equal(19537, tx.GetWeight()); // at randomize size Assert.Equal(2, tx.GetVersion()); Assert.Equal(0, tx.GetLockTime()); + Assert.Equal(4, blinderList.Length); Console.WriteLine("UnblindTransaction"); UnblindIssuanceData reissueData = tx.UnblindIssuance(1, issuanceBlindingKey, issuanceBlindingKey); @@ -277,21 +278,35 @@ public void BlindTxTest() Assert.Equal(600000000, reissueData.AssetData.SatoshiValue); Assert.Equal("0000000000000000000000000000000000000000000000000000000000000000", reissueData.AssetData.AssetBlindFactor.ToHexString()); Assert.NotEqual("0000000000000000000000000000000000000000000000000000000000000000", reissueData.AssetData.AmountBlindFactor.ToHexString()); + Assert.Equal(reissueData.AssetData.SatoshiValue, blinderList[0].SatoshiValue); + Assert.Equal(reissueData.AssetData.AmountBlindFactor.ToHexString(), blinderList[0].AmountBlindFactor.ToHexString()); Assert.Equal("186c7f955149a5274b39e24b6a50d1d6479f552f6522d91f3a97d771f1c18179", vout0.Asset); Assert.Equal(999587680, vout0.SatoshiValue); Assert.NotEqual("0000000000000000000000000000000000000000000000000000000000000000", vout0.AssetBlindFactor.ToHexString()); Assert.NotEqual("0000000000000000000000000000000000000000000000000000000000000000", vout0.AmountBlindFactor.ToHexString()); + Assert.Equal(vout0.Asset, blinderList[1].Asset); + Assert.Equal(vout0.SatoshiValue, blinderList[1].SatoshiValue); + Assert.Equal(vout0.AssetBlindFactor.ToHexString(), blinderList[1].AssetBlindFactor.ToHexString()); + Assert.Equal(vout0.AmountBlindFactor.ToHexString(), blinderList[1].AmountBlindFactor.ToHexString()); Assert.Equal("ed6927df918c89b5e3d8b5062acab2c749a3291bb7451d4267c7daaf1b52ad0b", vout1.Asset); Assert.Equal(700000000, vout1.SatoshiValue); Assert.NotEqual("0000000000000000000000000000000000000000000000000000000000000000", vout1.AssetBlindFactor.ToHexString()); Assert.NotEqual("0000000000000000000000000000000000000000000000000000000000000000", vout1.AmountBlindFactor.ToHexString()); + Assert.Equal(vout1.Asset, blinderList[2].Asset); + Assert.Equal(vout1.SatoshiValue, blinderList[2].SatoshiValue); + Assert.Equal(vout1.AssetBlindFactor.ToHexString(), blinderList[2].AssetBlindFactor.ToHexString()); + Assert.Equal(vout1.AmountBlindFactor.ToHexString(), blinderList[2].AmountBlindFactor.ToHexString()); Assert.Equal("accb7354c07974e00b32e4e5eef55078490141675592ac3610e6101831edb0cd", vout3.Asset); Assert.Equal(600000000, vout3.SatoshiValue); Assert.NotEqual("0000000000000000000000000000000000000000000000000000000000000000", vout3.AssetBlindFactor.ToHexString()); Assert.NotEqual("0000000000000000000000000000000000000000000000000000000000000000", vout3.AmountBlindFactor.ToHexString()); + Assert.Equal(vout3.Asset, blinderList[3].Asset); + Assert.Equal(vout3.SatoshiValue, blinderList[3].SatoshiValue); + Assert.Equal(vout3.AssetBlindFactor.ToHexString(), blinderList[3].AssetBlindFactor.ToHexString()); + Assert.Equal(vout3.AmountBlindFactor.ToHexString(), blinderList[3].AmountBlindFactor.ToHexString()); } [Fact] @@ -342,7 +357,8 @@ public void BlindTxAndOptionTest() new Address("2dodsWJgP3pTWWidK5hDxuYHqC1U4CEnT3n"), new Pubkey("03ce4c4eac09fe317f365e45c00ffcf2e9639bc0fd792c10f72cdc173c4e5ed879")); - tx.BlindTransaction(utxos, issuanceKeys, new[] { ctAddr1, ctAddr2, ctAddr4 }); + CfdBlindOptionData opt = new CfdBlindOptionData(true); + var blinderList = tx.BlindTransaction(utxos, issuanceKeys, new[] { ctAddr1, ctAddr2, ctAddr4 }, opt); // Console.WriteLine(" - txid = " + tx.GetTxid().ToHexString()); // Console.WriteLine(" - wtxid = " + tx.GetWtxid().ToHexString()); // Console.WriteLine(" - witHash = " + tx.GetWitHash()); @@ -355,6 +371,7 @@ public void BlindTxAndOptionTest() Assert.Equal(19537, tx.GetWeight()); // at randomize size Assert.Equal(2, tx.GetVersion()); Assert.Equal(0, tx.GetLockTime()); + Assert.Equal(4, blinderList.Length); } private string ConvertRangeProof(byte[] data) diff --git a/tools/build.bat b/tools/build.bat index 6d9f4db..20ba492 100644 --- a/tools/build.bat +++ b/tools/build.bat @@ -1,3 +1,4 @@ +setlocal @echo off if exist "build.bat" ( cd .. @@ -13,6 +14,14 @@ if not %ERRORLEVEL% == 0 ( exit 1 ) +cd dotnet_project/CfdCsharpProject +CALL dotnet build -c Release +if not %ERRORLEVEL% == 0 ( + cd ../.. + exit 1 +) +cd ../.. + cd dotnet_project/CfdCsharpProject.xTests CALL dotnet build -c Release if not %ERRORLEVEL% == 0 ( diff --git a/tools/build.sh b/tools/build.sh index 5c7d7ca..22a2147 100755 --- a/tools/build.sh +++ b/tools/build.sh @@ -1,14 +1,14 @@ #!/bin/sh cd `git rev-parse --show-toplevel` -cmake -S . -B build -DENABLE_SHARED=on -DENABLE_JS_WRAPPER=off -DENABLE_CAPI=on -DENABLE_TESTS=off -DCMAKE_BUILD_TYPE=Release -DTARGET_RPATH="./bin/Release/netcoreapp3.0;./build/Release" +cmake -S . -B build -DENABLE_SHARED=on -DENABLE_JS_WRAPPER=off -DENABLE_CAPI=on -DENABLE_TESTS=off -DCMAKE_BUILD_TYPE=Release -DTARGET_RPATH="./bin/Release/net5.0;./bin/Release/netcoreapp3.1;./build/Release" cmake --build build --parallel 2 --config Release if [ $? -gt 0 ]; then exit 1 fi cd dotnet_project/CfdCsharpProject -dotnet build -c Release +dotnet build -f net5.0 -c Release if [ $? -gt 0 ]; then cd ../.. exit 1 @@ -16,7 +16,7 @@ fi cd ../.. cd dotnet_project/CfdCsharpProject.xTests -dotnet build -c Release +dotnet build -f net5.0 -c Release if [ $? -gt 0 ]; then cd ../.. exit 1 diff --git a/tools/build_core3.bat b/tools/build_core3.bat index be4e39c..a281b07 100644 --- a/tools/build_core3.bat +++ b/tools/build_core3.bat @@ -4,10 +4,7 @@ if exist "build_core3.bat" ( cd .. ) -REM set PATH=%PATH:C:\Program Files\Git\usr\bin;=% -REM set PATH=%PATH:C:\Program Files (x86)\Git\usr\bin;=% - -CALL cmake -S . -B build -A x64 -DENABLE_CSHARP=off -DENABLE_SHARED=on -DENABLE_JS_WRAPPER=off -DENABLE_CAPI=on -DENABLE_TESTS=off -DCMAKE_BUILD_TYPE=Release +CALL cmake -S . -B build -A x64 -DENABLE_SHARED=on -DENABLE_JS_WRAPPER=off -DENABLE_CAPI=on -DENABLE_TESTS=off -DCMAKE_BUILD_TYPE=Release if not %ERRORLEVEL% == 0 ( exit 1 ) @@ -18,7 +15,7 @@ if not %ERRORLEVEL% == 0 ( ) cd dotnet_project/CfdCsharpProject -CALL dotnet build -c Release +CALL dotnet build -f netstandard2.1 -c Release if not %ERRORLEVEL% == 0 ( cd ../.. exit 1 @@ -26,7 +23,7 @@ if not %ERRORLEVEL% == 0 ( cd ../.. cd dotnet_project/CfdCsharpProject.xTests -CALL dotnet build -c Release +CALL dotnet build -f netcoreapp3.1 -c Release if not %ERRORLEVEL% == 0 ( cd ../.. exit 1 diff --git a/tools/build_core3.sh b/tools/build_core3.sh new file mode 100755 index 0000000..451efa8 --- /dev/null +++ b/tools/build_core3.sh @@ -0,0 +1,24 @@ +#!/bin/sh +cd `git rev-parse --show-toplevel` + +cmake -S . -B build -DENABLE_SHARED=on -DENABLE_JS_WRAPPER=off -DENABLE_CAPI=on -DENABLE_TESTS=off -DCMAKE_BUILD_TYPE=Release -DTARGET_RPATH="./bin/Release/netcoreapp3.1;./build/Release" +cmake --build build --parallel 2 --config Release +if [ $? -gt 0 ]; then + exit 1 +fi + +cd dotnet_project/CfdCsharpProject +dotnet build -f netstandard2.1 -c Release +if [ $? -gt 0 ]; then + cd ../.. + exit 1 +fi +cd ../.. + +cd dotnet_project/CfdCsharpProject.xTests +dotnet build -f netcoreapp3.1 -c Release +if [ $? -gt 0 ]; then + cd ../.. + exit 1 +fi +cd ../.. diff --git a/tools/clitest_debug.bat b/tools/clitest_debug.bat index db96f2f..7c68ab5 100644 --- a/tools/clitest_debug.bat +++ b/tools/clitest_debug.bat @@ -3,7 +3,7 @@ if exist "clitest.bat" ( cd .. ) -cd dotnet_project\CfdCsharpProject.CliTests\bin\Debug\netcoreapp3.0 +cd dotnet_project\CfdCsharpProject.CliTests\bin\Debug\net5.0 .\cfdcs_test.exe diff --git a/tools/test.bat b/tools/test.bat index 490e6fa..a650423 100644 --- a/tools/test.bat +++ b/tools/test.bat @@ -3,11 +3,11 @@ if exist "test.bat" ( cd .. ) -COPY /Y /B dotnet_project\CfdCsharpProject\bin\Release\netstandard2.1\cfdcs.* dotnet_project\CfdCsharpProject.xTests\bin\Release\netcoreapp3.0 -COPY /Y /B build\Release\* dotnet_project\CfdCsharpProject.xTests\bin\Release\netcoreapp3.0 +COPY /Y /B dotnet_project\CfdCsharpProject\bin\Release\net5.0\cfdcs.* dotnet_project\CfdCsharpProject.xTests\bin\Release\net5.0 +COPY /Y /B build\Release\* dotnet_project\CfdCsharpProject.xTests\bin\Release\net5.0 cd dotnet_project/CfdCsharpProject.xTests -CALL dotnet test -c Release --no-build +CALL dotnet test -f net5.0 -c Release --no-build if not %ERRORLEVEL% == 0 ( cd ../.. exit 1 diff --git a/tools/test.sh b/tools/test.sh index 3ebff2f..e9f78a6 100755 --- a/tools/test.sh +++ b/tools/test.sh @@ -1,11 +1,11 @@ #!/bin/sh cd `git rev-parse --show-toplevel` -cp -rp dotnet_project/CfdCsharpProject/bin/Release/netstandard2.1/cfdcs.* dotnet_project/CfdCsharpProject.xTests/bin/Release/netcoreapp3.0 -cp -rp build/Release/* dotnet_project/CfdCsharpProject.xTests/bin/Release/netcoreapp3.0 +cp -rp dotnet_project/CfdCsharpProject/bin/Release/net5.0/cfdcs.* dotnet_project/CfdCsharpProject.xTests/bin/Release/net5.0 +cp -rp build/Release/* dotnet_project/CfdCsharpProject.xTests/bin/Release/net5.0 cd dotnet_project/CfdCsharpProject.xTests -dotnet test -c Release --no-build +dotnet test -f net5.0 -c Release --no-build if [ $? -gt 0 ]; then cd ../.. exit 1 diff --git a/tools/test_core3.bat b/tools/test_core3.bat index b96d4c5..bfa42f2 100644 --- a/tools/test_core3.bat +++ b/tools/test_core3.bat @@ -3,11 +3,11 @@ if exist "test_core3.bat" ( cd .. ) -COPY /Y /B dotnet_project\CfdCsharpProject\bin\Release\netstandard2.1\cfdcs.* dotnet_project\CfdCsharpProject.xTests\bin\Release\netcoreapp3.0 -COPY /Y /B build\Release\* dotnet_project\CfdCsharpProject.xTests\bin\Release\netcoreapp3.0 +COPY /Y /B dotnet_project\CfdCsharpProject\bin\Release\netstandard2.1\cfdcs.* dotnet_project\CfdCsharpProject.xTests\bin\Release\netcoreapp3.1 +COPY /Y /B build\Release\* dotnet_project\CfdCsharpProject.xTests\bin\Release\netcoreapp3.1 cd dotnet_project/CfdCsharpProject.xTests -CALL dotnet test -c Release --no-build +CALL dotnet test -f netcoreapp3.1 -c Release --no-build if not %ERRORLEVEL% == 0 ( cd ../.. exit 1 diff --git a/tools/test_core3.sh b/tools/test_core3.sh new file mode 100755 index 0000000..45353d7 --- /dev/null +++ b/tools/test_core3.sh @@ -0,0 +1,14 @@ +#!/bin/sh +cd `git rev-parse --show-toplevel` + +cp -rp dotnet_project/CfdCsharpProject/bin/Release/netstandard2.1/cfdcs.* dotnet_project/CfdCsharpProject.xTests/bin/Release/netcoreapp3.1 +cp -rp build/Release/* dotnet_project/CfdCsharpProject.xTests/bin/Release/netcoreapp3.1 + +cd dotnet_project/CfdCsharpProject.xTests +dotnet test -f netcoreapp3.1 -c Release --no-build +if [ $? -gt 0 ]; then + cd ../.. + exit 1 +fi + +cd ../.. diff --git a/tools/test_direct.bat b/tools/test_direct.bat index 471a579..9fef2bc 100644 --- a/tools/test_direct.bat +++ b/tools/test_direct.bat @@ -3,9 +3,9 @@ if exist "test_direct.bat" ( cd .. ) -COPY /Y /B dotnet_project\CfdCsharpProject\bin\Release\netstandard2.1\cfdcs.* dotnet_project\CfdCsharpProject.xTests\bin\Release\netcoreapp3.0 +COPY /Y /B dotnet_project\CfdCsharpProject\bin\Release\net5.0\cfdcs.* dotnet_project\CfdCsharpProject.xTests\bin\Release\net5.0 cd dotnet_project/CfdCsharpProject.xTests -CALL dotnet test -c Release --no-build +CALL dotnet test -f net5.0 -c Release --no-build cd ../.. diff --git a/tools/test_direct.sh b/tools/test_direct.sh index 7e143fe..afc7598 100755 --- a/tools/test_direct.sh +++ b/tools/test_direct.sh @@ -1,9 +1,9 @@ #!/bin/sh cd `git rev-parse --show-toplevel` -cp -rp dotnet_project/CfdCsharpProject/bin/Release/netstandard2.1/cfdcs.* dotnet_project/CfdCsharpProject.xTests/bin/Release/netcoreapp3.0 +cp -rp dotnet_project/CfdCsharpProject/bin/Release/net5.0/cfdcs.* dotnet_project/CfdCsharpProject.xTests/bin/Release/net5.0 cd dotnet_project/CfdCsharpProject.xTests -dotnet test -c Release --no-build +dotnet test -f net5.0 -c Release --no-build cd ../.. diff --git a/tools/test_direct_3.1.bat b/tools/test_direct_3.1.bat new file mode 100644 index 0000000..c43f8ee --- /dev/null +++ b/tools/test_direct_3.1.bat @@ -0,0 +1,11 @@ +@echo off +if exist "test_direct.bat" ( + cd .. +) + +COPY /Y /B dotnet_project\CfdCsharpProject\bin\Release\netstandard2.1\cfdcs.* dotnet_project\CfdCsharpProject.xTests\bin\Release\netcoreapp3.1 + +cd dotnet_project/CfdCsharpProject.xTests +CALL dotnet test -f netcoreapp3.1 -c Release --no-build + +cd ../.. diff --git a/tools/test_direct_3.1.sh b/tools/test_direct_3.1.sh new file mode 100755 index 0000000..09cf941 --- /dev/null +++ b/tools/test_direct_3.1.sh @@ -0,0 +1,9 @@ +#!/bin/sh +cd `git rev-parse --show-toplevel` + +cp -rp dotnet_project/CfdCsharpProject/bin/Release/netstandard2.1/cfdcs.* dotnet_project/CfdCsharpProject.xTests/bin/Release/netcoreapp3.1 + +cd dotnet_project/CfdCsharpProject.xTests +dotnet test -f netcoreapp3.1 -c Release --no-build + +cd ../..