diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 0b1edcc17..43e80c85b 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -15,11 +15,11 @@ jobs:
with:
dotnet-version: ${{ matrix.dotnet }}
- - name: Run tests (BouncyCastle)
+ - name: Run tests (Portability)
# we want to run only once.
if: startsWith(matrix.os, 'ubuntu-18')
run: |
- dotnet build tests/DotNetLightning.Core.Tests -p:BouncyCastle=True
+ dotnet build tests/DotNetLightning.Core.Tests -p:Portability=True
dotnet run --no-build --project tests/DotNetLightning.Core.Tests
- name: Clean to prepare for NSec build
@@ -40,6 +40,6 @@ jobs:
run: |
DEBIAN_FRONTEND=noninteractive sudo apt install -y msbuild fsharp
- dotnet restore -p:BouncyCastle=True DotNetLightning.sln
- msbuild src/DotNetLightning.Core/DotNetLightning.Core.fsproj -p:BouncyCastle=True -p:TargetFramework=netstandard2.0
+ dotnet restore -p:Portability=True DotNetLightning.sln
+ msbuild src/DotNetLightning.Core/DotNetLightning.Core.fsproj -p:Portability=True -p:TargetFramework=netstandard2.0
diff --git a/.github/workflows/publish_master.yml b/.github/workflows/publish_master.yml
index cd769e0c4..7eb82fee1 100644
--- a/.github/workflows/publish_master.yml
+++ b/.github/workflows/publish_master.yml
@@ -29,8 +29,8 @@ jobs:
with:
dotnet-version: '3.1.200'
- - name: Upload nuget packages (BouncyCastle)
+ - name: Upload nuget packages (Portability)
if: startsWith(matrix.os, 'ubuntu')
run: |
- dotnet pack ./src/DotNetLightning.Core -p:Configuration=Release --version-suffix date`date +%Y%m%d-%H%M`-git-`echo $GITHUB_SHA | head -c 7` -p:BouncyCastle=True
+ dotnet pack ./src/DotNetLightning.Core -p:Configuration=Release --version-suffix date`date +%Y%m%d-%H%M`-git-`echo $GITHUB_SHA | head -c 7` -p:Portability=True
dotnet nuget push ./src/DotNetLightning.Core/bin/Release/DotNetLightning.Kiss.1*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json
diff --git a/Directory.Build.props b/Directory.Build.props
index e35bfe723..d83fbb9be 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -8,22 +8,22 @@
Since NBitcoin.Secp256k1 does not support netstandard 2.0, we will fallback to BouncyCastle build<-->
- True
+ True
-
+
- $(OtherFlags) -d:BouncyCastle
- $(DefineConstants);BouncyCastle
+ $(OtherFlags) -d:NoDUsAsStructs -d:BouncyCastle
+ $(DefineConstants);NoDUsAsStructs;BouncyCastle
-
+
diff --git a/src/DotNetLightning.Core/Channel/Channel.fs b/src/DotNetLightning.Core/Channel/Channel.fs
index f00387f8c..12f5ec9c2 100644
--- a/src/DotNetLightning.Core/Channel/Channel.fs
+++ b/src/DotNetLightning.Core/Channel/Channel.fs
@@ -1,7 +1,5 @@
namespace DotNetLightning.Channel
-open ResultUtils
-
open DotNetLightning.Utils
open DotNetLightning.Utils.NBitcoinExtensions
open DotNetLightning.Utils.Aether
@@ -12,6 +10,9 @@ open DotNetLightning.Serialization.Msgs
open NBitcoin
open System
+open ResultUtils
+open ResultUtils.Portability
+
type ProvideFundingTx = IDestination * Money * FeeRatePerKw -> Result
type Channel = {
diff --git a/src/DotNetLightning.Core/Channel/ChannelError.fs b/src/DotNetLightning.Core/Channel/ChannelError.fs
index 31c3628ff..0f1b0bde8 100644
--- a/src/DotNetLightning.Core/Channel/ChannelError.fs
+++ b/src/DotNetLightning.Core/Channel/ChannelError.fs
@@ -1,6 +1,5 @@
namespace DotNetLightning.Channel
-open ResultUtils
open DotNetLightning.Utils
open NBitcoinExtensions
open DotNetLightning.Utils.OnionError
@@ -11,6 +10,9 @@ open DotNetLightning.Transactions
open NBitcoin
+open ResultUtils
+open ResultUtils.Portability
+
type ChannelError =
| CryptoError of CryptoError
| TransactionRelatedErrors of TransactionError list
diff --git a/src/DotNetLightning.Core/Channel/ChannelOperations.fs b/src/DotNetLightning.Core/Channel/ChannelOperations.fs
index 31a97ade9..892aab85e 100644
--- a/src/DotNetLightning.Core/Channel/ChannelOperations.fs
+++ b/src/DotNetLightning.Core/Channel/ChannelOperations.fs
@@ -1,6 +1,5 @@
namespace DotNetLightning.Channel
-open ResultUtils
open DotNetLightning.Utils
open DotNetLightning.Utils.NBitcoinExtensions
open DotNetLightning.Utils.OnionError
@@ -13,6 +12,9 @@ open DotNetLightning.Serialization
open NBitcoin
+open ResultUtils
+open ResultUtils.Portability
+
type OperationMonoHopUnidirectionalPayment = {
Amount: LNMoney
}
diff --git a/src/DotNetLightning.Core/Channel/ChannelValidation.fs b/src/DotNetLightning.Core/Channel/ChannelValidation.fs
index 18001ae09..71b0fb3d3 100644
--- a/src/DotNetLightning.Core/Channel/ChannelValidation.fs
+++ b/src/DotNetLightning.Core/Channel/ChannelValidation.fs
@@ -1,6 +1,5 @@
namespace DotNetLightning.Channel
-open ResultUtils
open NBitcoin
open DotNetLightning.Chain
@@ -10,6 +9,9 @@ open DotNetLightning.Utils.NBitcoinExtensions
open DotNetLightning.Serialization.Msgs
open DotNetLightning.Transactions
+open ResultUtils
+open ResultUtils.Portability
+
exception ChannelException of ChannelError
module internal ChannelHelpers =
diff --git a/src/DotNetLightning.Core/Channel/CommitmentsModule.fs b/src/DotNetLightning.Core/Channel/CommitmentsModule.fs
index ba076a64c..fa9bc90b2 100644
--- a/src/DotNetLightning.Core/Channel/CommitmentsModule.fs
+++ b/src/DotNetLightning.Core/Channel/CommitmentsModule.fs
@@ -2,14 +2,15 @@ namespace DotNetLightning.Channel
open NBitcoin
-open ResultUtils
-
open DotNetLightning.Utils
open DotNetLightning.Transactions
open DotNetLightning.Crypto
open DotNetLightning.Chain
open DotNetLightning.Serialization.Msgs
+open ResultUtils
+open ResultUtils.Portability
+
[]
module internal Commitments =
module private Helpers =
diff --git a/src/DotNetLightning.Core/Crypto/Sphinx.fs b/src/DotNetLightning.Core/Crypto/Sphinx.fs
index 5b85074db..9940a6d21 100644
--- a/src/DotNetLightning.Core/Crypto/Sphinx.fs
+++ b/src/DotNetLightning.Core/Crypto/Sphinx.fs
@@ -3,12 +3,13 @@ namespace DotNetLightning.Crypto
open System
open NBitcoin
-open ResultUtils
-
open DotNetLightning.Utils
open DotNetLightning.Serialization
open DotNetLightning.Serialization.Msgs
+open ResultUtils
+open ResultUtils.Portability
+
module Sphinx =
open NBitcoin.Crypto
diff --git a/src/DotNetLightning.Core/DotNetLightning.Core.fsproj b/src/DotNetLightning.Core/DotNetLightning.Core.fsproj
index 9dc059e04..45650fc31 100644
--- a/src/DotNetLightning.Core/DotNetLightning.Core.fsproj
+++ b/src/DotNetLightning.Core/DotNetLightning.Core.fsproj
@@ -6,7 +6,7 @@
-
+
DotNetLightning.Kiss
@@ -19,7 +19,7 @@
-
+
@@ -98,7 +98,7 @@
-
+
diff --git a/src/DotNetLightning.Core/Payment/LSAT/Satisfier.fs b/src/DotNetLightning.Core/Payment/LSAT/Satisfier.fs
index 7c7f660da..e706544c4 100644
--- a/src/DotNetLightning.Core/Payment/LSAT/Satisfier.fs
+++ b/src/DotNetLightning.Core/Payment/LSAT/Satisfier.fs
@@ -1,12 +1,14 @@
namespace DotNetLightning.Payment.LSAT
-open ResultUtils
open DotNetLightning.Utils
open Macaroons
open System.Collections.Generic
open System.Runtime.CompilerServices
open NBitcoin
+open ResultUtils
+open ResultUtils.Portability
+
/// When we verify a macaroon for its caveats, usually it check each caveats independently.
/// In case of LSAT, this does not work since the validity of a caveat depends on a previous caveat
/// (more specifically, if there were two caveats with a same Condition, we usually check that whether the restriction
diff --git a/src/DotNetLightning.Core/Payment/LSAT/Service.fs b/src/DotNetLightning.Core/Payment/LSAT/Service.fs
index 51b54286e..0e69770dc 100644
--- a/src/DotNetLightning.Core/Payment/LSAT/Service.fs
+++ b/src/DotNetLightning.Core/Payment/LSAT/Service.fs
@@ -4,11 +4,13 @@ open System
open System.Collections.Generic
open Macaroons
-open ResultUtils
open System.Text
open DotNetLightning.Utils
+open ResultUtils
+open ResultUtils.Portability
+
/// See: https://github.com/lightninglabs/LSAT/blob/master/macaroons.md#target-services
type Service = {
Name: string
diff --git a/src/DotNetLightning.Core/Payment/PaymentRequest.fs b/src/DotNetLightning.Core/Payment/PaymentRequest.fs
index 6d0de07bd..397b7afc0 100644
--- a/src/DotNetLightning.Core/Payment/PaymentRequest.fs
+++ b/src/DotNetLightning.Core/Payment/PaymentRequest.fs
@@ -6,8 +6,6 @@ open System.Text
open System.Collections
open System.Diagnostics
-open ResultUtils
-
open DotNetLightning.Utils
open DotNetLightning.Core.Utils.Extensions
open DotNetLightning.Serialization
@@ -16,6 +14,8 @@ open NBitcoin
open NBitcoin.Crypto
open NBitcoin.DataEncoders
+open ResultUtils
+open ResultUtils.Portability
module private Helpers =
let base58check = Base58CheckEncoder()
diff --git a/src/DotNetLightning.Core/Peer/Peer.fs b/src/DotNetLightning.Core/Peer/Peer.fs
index d8a45eae0..7e95f3236 100644
--- a/src/DotNetLightning.Core/Peer/Peer.fs
+++ b/src/DotNetLightning.Core/Peer/Peer.fs
@@ -2,14 +2,15 @@ namespace DotNetLightning.Peer
open NBitcoin
-open ResultUtils
-
open DotNetLightning.Serialization
open System.Collections
open DotNetLightning.Utils
open DotNetLightning.Serialization.Msgs
open DotNetLightning.Utils.Aether
+open ResultUtils
+open ResultUtils.Portability
+
type PeerHandleError = {
/// Used to indicate that we probably can't make any future connections to this peer, implying
/// we should go ahead and force-close any channels we have with it.
diff --git a/src/DotNetLightning.Core/Peer/PeerChannelEncryptor.fs b/src/DotNetLightning.Core/Peer/PeerChannelEncryptor.fs
index e597711a3..238e1b8e0 100644
--- a/src/DotNetLightning.Core/Peer/PeerChannelEncryptor.fs
+++ b/src/DotNetLightning.Core/Peer/PeerChannelEncryptor.fs
@@ -5,13 +5,13 @@ open System
open NBitcoin
open NBitcoin.Crypto
-open ResultUtils
-
open DotNetLightning.Utils
open DotNetLightning.Utils.Aether
open DotNetLightning.Utils.Aether.Operators
open DotNetLightning.Crypto
+open ResultUtils
+open ResultUtils.Portability
[]
module PeerChannelEncryptor =
diff --git a/src/DotNetLightning.Core/Routing/NetworkStats.fs b/src/DotNetLightning.Core/Routing/NetworkStats.fs
index 7dae84c03..96fb42882 100644
--- a/src/DotNetLightning.Core/Routing/NetworkStats.fs
+++ b/src/DotNetLightning.Core/Routing/NetworkStats.fs
@@ -4,6 +4,9 @@ open DotNetLightning.Utils
open DotNetLightning.Utils.Primitives
open NBitcoin
+open ResultUtils
+open ResultUtils.Portability
+
type Stats<'T> = {
Median: 'T
Percentile5: 'T
diff --git a/src/DotNetLightning.Core/Routing/Router.fs b/src/DotNetLightning.Core/Routing/Router.fs
index 852c34557..088b0b9c5 100644
--- a/src/DotNetLightning.Core/Routing/Router.fs
+++ b/src/DotNetLightning.Core/Routing/Router.fs
@@ -1,6 +1,5 @@
namespace DotNetLightning.Routing
-open ResultUtils
open DotNetLightning.Utils.Primitives
open DotNetLightning.Utils
@@ -11,6 +10,9 @@ open DotNetLightning.Payment
open DotNetLightning.Routing.Graph
open NBitcoin
+open ResultUtils
+open ResultUtils.Portability
+
module Routing =
/// This method is used after a payment failed, and we want to exclude some nodes that we know are failing
diff --git a/src/DotNetLightning.Core/Routing/RouterPrimitives.fs b/src/DotNetLightning.Core/Routing/RouterPrimitives.fs
index 79c775523..8b0dce6ac 100644
--- a/src/DotNetLightning.Core/Routing/RouterPrimitives.fs
+++ b/src/DotNetLightning.Core/Routing/RouterPrimitives.fs
@@ -3,11 +3,13 @@ namespace DotNetLightning.Routing
open DotNetLightning.Payment
open System
open NBitcoin
-open ResultUtils
open DotNetLightning.Utils
open DotNetLightning.Serialization.Msgs
open Graph
+open ResultUtils
+open ResultUtils.Portability
+
[]
module RouterPrimitives =
let checkUpdate(x: ChannelUpdateMsg option, msg ) =
diff --git a/src/DotNetLightning.Core/Routing/RouterState.fs b/src/DotNetLightning.Core/Routing/RouterState.fs
index 8e58b04ec..0d42830e0 100644
--- a/src/DotNetLightning.Core/Routing/RouterState.fs
+++ b/src/DotNetLightning.Core/Routing/RouterState.fs
@@ -1,13 +1,14 @@
namespace DotNetLightning.Routing
-open ResultUtils
open System.Collections.Generic
open DotNetLightning.Payment
open DotNetLightning.Serialization.Msgs
open DotNetLightning.Utils
open Graph
-
+open ResultUtils
+open ResultUtils.Portability
+
type RouteParams = {
Randomize: bool
MaxFeeBase: LNMoney
diff --git a/src/DotNetLightning.Core/Routing/RouterTypes.fs b/src/DotNetLightning.Core/Routing/RouterTypes.fs
index c9550f899..83c0949de 100644
--- a/src/DotNetLightning.Core/Routing/RouterTypes.fs
+++ b/src/DotNetLightning.Core/Routing/RouterTypes.fs
@@ -8,7 +8,9 @@ open System.Collections.Generic
open DotNetLightning.Utils
open DotNetLightning.Serialization.Msgs
open NBitcoin
+
open ResultUtils
+open ResultUtils.Portability
type NetworkEvent =
diff --git a/src/DotNetLightning.Core/Serialization/Encoding.fs b/src/DotNetLightning.Core/Serialization/Encoding.fs
index e46553abb..8249dbeb1 100644
--- a/src/DotNetLightning.Core/Serialization/Encoding.fs
+++ b/src/DotNetLightning.Core/Serialization/Encoding.fs
@@ -5,11 +5,13 @@ namespace DotNetLightning.Serialization
open DotNetLightning.Core.Utils.Extensions
open DotNetLightning.Utils.Primitives
-open ResultUtils
open System
open System.IO
open System.IO.Compression
+open ResultUtils
+open ResultUtils.Portability
+
module Decoder =
let private tryDecode (encodingType: EncodingType) (bytes : byte[]) =
diff --git a/src/DotNetLightning.Core/Serialization/Features.fs b/src/DotNetLightning.Core/Serialization/Features.fs
index c8eb3c6fb..c01137e26 100644
--- a/src/DotNetLightning.Core/Serialization/Features.fs
+++ b/src/DotNetLightning.Core/Serialization/Features.fs
@@ -2,12 +2,13 @@ namespace DotNetLightning.Serialization
open System.Collections
-open ResultUtils
-
open System
open System.Text
open DotNetLightning.Core.Utils.Extensions
+open ResultUtils
+open ResultUtils.Portability
+
type FeaturesSupport =
| Mandatory
| Optional
diff --git a/src/DotNetLightning.Core/Serialization/GenericTLV.fs b/src/DotNetLightning.Core/Serialization/GenericTLV.fs
index ad6886f2b..116db7d8d 100644
--- a/src/DotNetLightning.Core/Serialization/GenericTLV.fs
+++ b/src/DotNetLightning.Core/Serialization/GenericTLV.fs
@@ -1,9 +1,11 @@
namespace DotNetLightning.Serialization
open System
-open ResultUtils
open DotNetLightning.Core.Utils.Extensions
+open ResultUtils
+open ResultUtils.Portability
+
type GenericTLV = {
Type: uint64
Value: byte[]
diff --git a/src/DotNetLightning.Core/Serialization/OnionPayload.fs b/src/DotNetLightning.Core/Serialization/OnionPayload.fs
index c6b876d24..78cd6d214 100644
--- a/src/DotNetLightning.Core/Serialization/OnionPayload.fs
+++ b/src/DotNetLightning.Core/Serialization/OnionPayload.fs
@@ -1,11 +1,13 @@
namespace DotNetLightning.Serialization
open System
-open ResultUtils
open NBitcoin
open DotNetLightning.Utils
open DotNetLightning.Core.Utils.Extensions
+open ResultUtils
+open ResultUtils.Portability
+
type OnionRealm0HopData = {
ShortChannelId: ShortChannelId
AmtToForward: LNMoney
diff --git a/src/DotNetLightning.Core/Transactions/CommitmentSpec.fs b/src/DotNetLightning.Core/Transactions/CommitmentSpec.fs
index 95ed553f4..0052b892d 100644
--- a/src/DotNetLightning.Core/Transactions/CommitmentSpec.fs
+++ b/src/DotNetLightning.Core/Transactions/CommitmentSpec.fs
@@ -1,12 +1,13 @@
namespace DotNetLightning.Transactions
-open ResultUtils
-
open DotNetLightning.Serialization.Msgs
open DotNetLightning.Utils.Primitives
open DotNetLightning.Utils
open DotNetLightning.Utils.Aether
+open ResultUtils
+open ResultUtils.Portability
+
type internal Direction =
| In
| Out
diff --git a/src/DotNetLightning.Core/Transactions/Transactions.fs b/src/DotNetLightning.Core/Transactions/Transactions.fs
index 91451343b..012d8d4a2 100644
--- a/src/DotNetLightning.Core/Transactions/Transactions.fs
+++ b/src/DotNetLightning.Core/Transactions/Transactions.fs
@@ -6,8 +6,6 @@ open System.Linq
open NBitcoin
-open ResultUtils
-
open DotNetLightning.Utils.Primitives
open DotNetLightning.Utils
open DotNetLightning.Core.Utils.Extensions
@@ -15,6 +13,9 @@ open DotNetLightning.Utils.Aether
open DotNetLightning.Crypto
open DotNetLightning.Serialization.Msgs
+open ResultUtils
+open ResultUtils.Portability
+
/// We define all possible txs here.
/// internal representation is psbt. But this is just for convenience since
/// in current spec we don't have to send PSBT with each other node in case of Lightning.
diff --git a/src/DotNetLightning.Core/Utils/Errors.fs b/src/DotNetLightning.Core/Utils/Errors.fs
index de32736d6..568068971 100644
--- a/src/DotNetLightning.Core/Utils/Errors.fs
+++ b/src/DotNetLightning.Core/Utils/Errors.fs
@@ -101,7 +101,9 @@ module OnionError =
let CHANNEL_DISABLED = UPDATE ||| 20us
[]
+#if !NoDUsAsStructs
[]
+#endif
type FailureCode = | FailureCode of uint16 with
member this.Value = let (FailureCode v) = this in v
diff --git a/src/DotNetLightning.Core/Utils/Keys.fs b/src/DotNetLightning.Core/Utils/Keys.fs
index 0655a5d6b..c86474c6e 100644
--- a/src/DotNetLightning.Core/Utils/Keys.fs
+++ b/src/DotNetLightning.Core/Utils/Keys.fs
@@ -260,7 +260,10 @@ type PerCommitmentPoint =
member this.ToBytes(): array =
this.RawPubKey().ToBytes()
-type [] CommitmentNumber =
+#if !NoDUsAsStructs
+[]
+#endif
+type CommitmentNumber =
| CommitmentNumber of UInt48
with
member this.Index() =
@@ -282,7 +285,10 @@ type [] CommitmentNumber =
member this.NextCommitment(): CommitmentNumber =
CommitmentNumber(this.Index() - UInt48.One)
-type [] ObscuredCommitmentNumber =
+#if !NoDUsAsStructs
+[]
+#endif
+type ObscuredCommitmentNumber =
| ObscuredCommitmentNumber of UInt48
with
member this.ObscuredIndex(): UInt48 =
diff --git a/src/DotNetLightning.Core/Utils/LNMoney.fs b/src/DotNetLightning.Core/Utils/LNMoney.fs
index dfe470f3c..dfcef90ae 100644
--- a/src/DotNetLightning.Core/Utils/LNMoney.fs
+++ b/src/DotNetLightning.Core/Utils/LNMoney.fs
@@ -20,7 +20,9 @@ type LNMoneyUnit =
/// Why not use the package directly? because it might cause circular dependency in the future.
/// (i.e. We might want to support this package in BTCPayServer.Lightning)
/// refs: https://github.com/btcpayserver/BTCPayServer.Lightning/blob/f65a883a63bf607176a3b7b0baa94527ac592f5e/src/BTCPayServer.Lightning.Common/LightMoney.cs
+#if !NoDUsAsStructs
[]
+#endif
type LNMoney = | LNMoney of int64 with
static member private BitcoinStyle =
diff --git a/src/DotNetLightning.Core/Utils/Primitives.fs b/src/DotNetLightning.Core/Utils/Primitives.fs
index 2b5544c82..16afc5b9b 100644
--- a/src/DotNetLightning.Core/Utils/Primitives.fs
+++ b/src/DotNetLightning.Core/Utils/Primitives.fs
@@ -9,7 +9,9 @@ open System.Linq
open System.Diagnostics
open DotNetLightning.Core.Utils.Extensions
+
open ResultUtils
+open ResultUtils.Portability
[]
module Primitives =
@@ -32,7 +34,9 @@ module Primitives =
output
/// Absolute block height
+#if !NoDUsAsStructs
[]
+#endif
type BlockHeight = | BlockHeight of uint32 with
static member Zero = 0u |> BlockHeight
static member One = 1u |> BlockHeight
@@ -58,7 +62,11 @@ module Primitives =
/// 16bit relative block height used for `OP_CSV` locks,
/// Since OP_CSV allow only block number of 0 ~ 65535, it is safe
/// to restrict into the range smaller than BlockHeight
- and [] BlockHeightOffset16 = | BlockHeightOffset16 of uint16 with
+ and
+#if !NoDUsAsStructs
+ []
+#endif
+ BlockHeightOffset16 = | BlockHeightOffset16 of uint16 with
member x.Value = let (BlockHeightOffset16 v) = x in v
static member ofBlockHeightOffset32(bho32: BlockHeightOffset32) =
@@ -77,7 +85,11 @@ module Primitives =
///
/// 32bit relative block height. For `OP_CSV` locks, BlockHeightOffset16
/// should be used instead.
- and [] BlockHeightOffset32 = | BlockHeightOffset32 of uint32 with
+ and
+#if !NoDUsAsStructs
+ []
+#endif
+ BlockHeightOffset32 = | BlockHeightOffset32 of uint32 with
member x.Value = let (BlockHeightOffset32 v) = x in v
static member ofBlockHeightOffset16(bho16: BlockHeightOffset16) =
@@ -336,23 +348,32 @@ module Primitives =
type BlockId = | BlockId of uint256 with
member x.Value = let (BlockId v) = x in v
+#if !NoDUsAsStructs
[]
+#endif
type HTLCId = | HTLCId of uint64 with
static member Zero = HTLCId(0UL)
member x.Value = let (HTLCId v) = x in v
static member (+) (a: HTLCId, b: uint64) = (a.Value + b) |> HTLCId
+#if !NoDUsAsStructs
[]
+#endif
type TxOutIndex = | TxOutIndex of uint16 with
member x.Value = let (TxOutIndex v) = x in v
+#if !NoDUsAsStructs
[]
+#endif
type TxIndexInBlock = | TxIndexInBlock of uint32 with
member x.Value = let (TxIndexInBlock v) = x in v
-
+#if !NoDUsAsStructs
[]
+#else
+ []
+#endif
type ShortChannelId = {
BlockHeight: BlockHeight
BlockIndex: TxIndexInBlock
diff --git a/src/DotNetLightning.Core/Utils/UInt48.fs b/src/DotNetLightning.Core/Utils/UInt48.fs
index 622e7e90a..85b466f5e 100644
--- a/src/DotNetLightning.Core/Utils/UInt48.fs
+++ b/src/DotNetLightning.Core/Utils/UInt48.fs
@@ -3,7 +3,9 @@ namespace DotNetLightning.Utils
open System
open DotNetLightning.Core.Utils.Extensions
+#if !NoDUsAsStructs
[]
+#endif
type UInt48 = {
UInt64: uint64
} with
diff --git a/src/ResultUtils/Result.fs b/src/ResultUtils/Result.fs
index 6e787bad0..9720a7c53 100644
--- a/src/ResultUtils/Result.fs
+++ b/src/ResultUtils/Result.fs
@@ -1,8 +1,30 @@
+namespace ResultUtils.Portability
+
+#if NoDUsAsStructs
+[]
+[]
+type Result<'T,'TError> =
+ | Ok of ResultValue: 'T
+ | Error of ErrorValue: 'TError
+#endif
+
+
namespace ResultUtils
+open ResultUtils.Portability
+
[]
module Result =
+ let ToFSharpCoreResult res =
+#if NoDUsAsStructs
+ match res with
+ | Ok o -> FSharp.Core.Result.Ok o
+ | Error e -> FSharp.Core.Result.Error e
+#else
+ res
+#endif
+
let isOk x =
match x with
| Ok _ -> true
@@ -17,11 +39,20 @@ module Result =
| Error err -> errorF err
let eitherMap okF errorF x =
- either (okF >> Result.Ok) (errorF >> Result.Error) x
+ either (okF >> Ok) (errorF >> Error) x
+
+ let bind binder result =
+ match result with Error e -> Error e | Ok x -> binder x
+
+ let map mapping result =
+ match result with Error e -> Error e | Ok x -> Ok (mapping x)
+
+ let mapError mapping result =
+ match result with Error x -> Error (mapping x) | Ok v -> Ok v
let apply f x =
- Result.bind (fun f' ->
- Result.bind (fun x' -> Ok (f' x')) x) f
+ bind (fun f' ->
+ bind (fun x' -> Ok (f' x')) x) f
let map2 f x y =
(apply (apply (Ok f) x) y)
@@ -43,11 +74,11 @@ module Result =
let tryCreate' x =
(^b : (static member TryCreate : 'a -> Result< ^b, 'c>) x)
tryCreate' x
- |> Result.mapError (fun z -> (fieldName, z))
+ |> mapError (fun z -> (fieldName, z))
/// Replaces the wrapped value with unit
let ignore result =
- result |> Result.map ignore
+ result |> map ignore
/// Returns the specified error if the value is false.
let requireTrue error value =
@@ -104,12 +135,12 @@ module Result =
/// Replaces an error value with a custom error value.
let setError error result =
- result |> Result.mapError (fun _ -> error)
+ result |> mapError (fun _ -> error)
/// Replaces a unit error value with a custom error value. Safer than setError
/// since you're not losing any information.
let withError error result =
- result |> Result.mapError (fun () -> error)
+ result |> mapError (fun () -> error)
/// Returns the contained value if Ok, otherwise returns ifError.
let defaultValue ifError result =
diff --git a/src/ResultUtils/ResultUtils.fsproj b/src/ResultUtils/ResultUtils.fsproj
index ef3ce69a2..409d5b895 100644
--- a/src/ResultUtils/ResultUtils.fsproj
+++ b/src/ResultUtils/ResultUtils.fsproj
@@ -2,6 +2,11 @@
netstandard2.0
+
+
+ $(OtherFlags) -d:NoDUsAsStructs -d:BouncyCastle
+
+
diff --git a/src/TaskUtils/Result.fs b/src/TaskUtils/Result.fs
index 282aa7ad6..2977b8efe 100644
--- a/src/TaskUtils/Result.fs
+++ b/src/TaskUtils/Result.fs
@@ -2,7 +2,9 @@ namespace TaskUtils
open System.Threading.Tasks
open FSharp.Control.Tasks
+
open ResultUtils
+open ResultUtils.Portability
[]
module Result =
diff --git a/tests/DotNetLightning.Core.Tests/LSATTests.fs b/tests/DotNetLightning.Core.Tests/LSATTests.fs
index b1aec7563..302b3f224 100644
--- a/tests/DotNetLightning.Core.Tests/LSATTests.fs
+++ b/tests/DotNetLightning.Core.Tests/LSATTests.fs
@@ -5,31 +5,33 @@ open System.Linq
open Expecto
open DotNetLightning.Payment.LSAT
open Macaroons
+
open ResultUtils
+open ResultUtils.Portability
[]
let lsatTests =
testList "LSAT tests" [
testCase "service decode tests" <| fun _ ->
let r = Service.ParseMany("a:0")
- Expect.isOk r "can parse single service"
+ Expect.isOk (Result.ToFSharpCoreResult r) "can parse single service"
Expect.equal 1 (r |> Result.deref).Count ""
Expect.equal "a" (r |> Result.deref).[0].Name ""
let r = Service.ParseMany("a:0,b:1,c:0")
- Expect.isOk r "can parse multiple service"
+ Expect.isOk (Result.ToFSharpCoreResult r) "can parse multiple service"
Expect.equal 3 (r |> Result.deref).Count ""
Expect.equal "c" (r |> Result.deref).[2].Name ""
Expect.equal 0uy (r |> Result.deref).[2].ServiceTier ""
let r = Service.ParseMany ""
- Expect.isError r "can not parse empty service"
+ Expect.isError (Result.ToFSharpCoreResult r) "can not parse empty service"
let r = Service.ParseMany ":a"
- Expect.isError r "can not parse service missing name"
+ Expect.isError (Result.ToFSharpCoreResult r) "can not parse service missing name"
let r = Service.ParseMany "a"
- Expect.isError r "can not parse service missing tier"
+ Expect.isError (Result.ToFSharpCoreResult r) "can not parse service missing tier"
let r = Service.ParseMany "a:"
- Expect.isError r "can not parse service with empty tier"
+ Expect.isError (Result.ToFSharpCoreResult r) "can not parse service with empty tier"
let r = Service.ParseMany ",,"
- Expect.isError r "can not parse empty services"
+ Expect.isError (Result.ToFSharpCoreResult r) "can not parse empty services"
()
testList "check macaroon verification works in LSAT compliant way" [
diff --git a/tests/DotNetLightning.Core.Tests/PaymentTests.fs b/tests/DotNetLightning.Core.Tests/PaymentTests.fs
index cae3d77ac..b87d356d5 100644
--- a/tests/DotNetLightning.Core.Tests/PaymentTests.fs
+++ b/tests/DotNetLightning.Core.Tests/PaymentTests.fs
@@ -6,11 +6,13 @@ open DotNetLightning.Payment
open DotNetLightning.Utils
open DotNetLightning.Serialization
-open ResultUtils
open Expecto
open NBitcoin
open NBitcoin.Crypto
+open ResultUtils
+open ResultUtils.Portability
+
[]
let tests =
let hex = NBitcoin.DataEncoders.HexEncoder()
@@ -184,7 +186,7 @@ let tests =
testCase "Same, but adding invalid unknown feature 100" <| fun _ ->
let data = "lnbc25m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5vdhkven9v5sxyetpdeessp5zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zygs9q4psqqqqqqqqqqqqqqqpqsqq40wa3khl49yue3zsgm26jrepqr2eghqlx86rttutve3ugd05em86nsefzh4pfurpd9ek9w2vp95zxqnfe2u7ckudyahsa52q66tgzcp6t2dyk"
let pr = PaymentRequest.Parse(data)
- Expect.isError(pr) ""
+ Expect.isError (Result.ToFSharpCoreResult pr) ""
]
[]
@@ -218,12 +220,12 @@ let unitTest =
with
member this.SignMessage(data) = nodeSecret.SignCompact(data, false) }
let r = PaymentRequest.TryCreate("lnbc", None, DateTimeOffset.UnixEpoch, nodeId, taggedFields, msgSigner)
- Expect.isOk r ""
+ Expect.isOk (Result.ToFSharpCoreResult r) ""
let r2 = PaymentRequest.Parse(r |> Result.deref |> fun x -> x.ToString())
- Expect.isOk r2 ""
+ Expect.isOk (Result.ToFSharpCoreResult r2) ""
Expect.equal r r2 "Should not change by de/serializing it"
let r3 = PaymentRequest.TryCreate("lnbc", None, DateTimeOffset.UnixEpoch, nodeId, {Fields = [dht; dt]}, msgSigner)
- Expect.isError r3 "Field contains both description and description hash! this must be invalid"
+ Expect.isError (Result.ToFSharpCoreResult r3) "Field contains both description and description hash! this must be invalid"
testCase "PaymentSecret can get correct PaymentHash by its .Hash field" <| fun _ ->
let p = Primitives.PaymentPreimage.Create(hex.DecodeData "60ba77a7f0174a3dd0f4fc8c1b28cda6aa9fab0e87c87e936af40b34cca40883")
let h = p.Hash
diff --git a/tests/DotNetLightning.Core.Tests/PeerChannelEncryptorTests.fs b/tests/DotNetLightning.Core.Tests/PeerChannelEncryptorTests.fs
index 15f07003d..712524316 100644
--- a/tests/DotNetLightning.Core.Tests/PeerChannelEncryptorTests.fs
+++ b/tests/DotNetLightning.Core.Tests/PeerChannelEncryptorTests.fs
@@ -1,7 +1,5 @@
module PeerChannelEncryptorTests
-open ResultUtils
-
open Expecto
open Expecto.Logging
open NBitcoin
@@ -9,6 +7,9 @@ open DotNetLightning.Utils.Aether
open DotNetLightning.Utils
open DotNetLightning.Peer
+open ResultUtils
+open ResultUtils.Portability
+
let hex = NBitcoin.DataEncoders.HexEncoder()
let logger = Log.create "PeerChannelEncryptor tests"
@@ -37,7 +38,7 @@ let peerChannelEncryptorTests =
let outboundPeer = getOutBoundPeerForInitiatorTestVectors()
let actTwo = hex.DecodeData("0002466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730ae")
let res = outboundPeer |> PeerChannelEncryptor.processActTwo actTwo ourNodeId
- Expect.isOk (res) ""
+ Expect.isOk (Result.ToFSharpCoreResult res) ""
let (actual, _nodeid), nextPCE = res |> Result.deref
let expected = "0x00b9e3a702e93e3a9948c2ed6e5fd7590a6e1c3a0344cfc9d5b57357049aa22355361aa02e55a8fc28fef5bd6d71ad0c38228dc68b1c466263b47fdf31e560e139ba"
@@ -67,7 +68,7 @@ let peerChannelEncryptorTests =
let testCase3() =
let outboundPeer = getOutBoundPeerForInitiatorTestVectors()
let actTwo = hex.DecodeData("0102466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730ae")
- Expect.isError (outboundPeer |> PeerChannelEncryptor.processActTwo actTwo ourNodeId) ""
+ Expect.isError (Result.ToFSharpCoreResult (outboundPeer |> PeerChannelEncryptor.processActTwo actTwo ourNodeId)) ""
testCase3()
@@ -75,14 +76,14 @@ let peerChannelEncryptorTests =
let testCase4() =
let outboundPeer = getOutBoundPeerForInitiatorTestVectors()
let actTwo = hex.DecodeData("0004466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730ae")
- Expect.isError (outboundPeer |> PeerChannelEncryptor.processActTwo actTwo ourNodeId) ""
+ Expect.isError (Result.ToFSharpCoreResult (outboundPeer |> PeerChannelEncryptor.processActTwo actTwo ourNodeId)) ""
testCase4()
/// transport-initiator act2 bad MAC test
let testCase5() =
let outboundPeer = getOutBoundPeerForInitiatorTestVectors()
let actTwo = hex.DecodeData("0002466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730af")
- Expect.isError(outboundPeer |> PeerChannelEncryptor.processActTwo actTwo ourNodeId) ""
+ Expect.isError(Result.ToFSharpCoreResult (outboundPeer |> PeerChannelEncryptor.processActTwo actTwo ourNodeId)) ""
testCase5()
testCase "noise responder test vectors" <| fun _ ->
@@ -95,14 +96,14 @@ let peerChannelEncryptorTests =
let actOne = hex.DecodeData("00036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f70df6086551151f58b8afe6c195782c6a")
let actTwoExpected = hex.DecodeData("0002466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276e2470b93aac583c9ef6eafca3f730ae")
let actualR = inboundPeer1 |> PeerChannelEncryptor.processActOneWithEphemeralKey actOne ourNodeSecret ourEphemeral
- Expect.isOk (actualR) ""
+ Expect.isOk (Result.ToFSharpCoreResult actualR) ""
let actual, inboundPeer2 = actualR |> Result.deref
Expect.equal (actual) (actTwoExpected) ""
let actThree = hex.DecodeData("00b9e3a702e93e3a9948c2ed6e5fd7590a6e1c3a0344cfc9d5b57357049aa22355361aa02e55a8fc28fef5bd6d71ad0c38228dc68b1c466263b47fdf31e560e139ba")
let theirNodeIdExpected = hex.DecodeData("034f355bdcb7cc0af728ef3cceb9615d90684bb5b2ca5f859ab0f0b704075871aa") |> PubKey |> NodeId
let actualRR = inboundPeer2 |> PeerChannelEncryptor.processActThree(actThree)
- Expect.isOk (actualRR) ""
+ Expect.isOk (Result.ToFSharpCoreResult actualRR) ""
let actual, nextState = actualRR |> Result.deref
Expect.equal (actual) (theirNodeIdExpected) ""
match nextState.NoiseState with
@@ -126,21 +127,21 @@ let peerChannelEncryptorTests =
let inboundPeer = PeerChannelEncryptor.newInBound( ourNodeSecret)
let actOne = "01036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f70df6086551151f58b8afe6c195782c6a" |> hex.DecodeData
let actualR = inboundPeer |> PeerChannelEncryptor.processActOneWithEphemeralKey actOne ourNodeSecret ourEphemeral
- Expect.isError (actualR) ""
+ Expect.isError (Result.ToFSharpCoreResult actualR) ""
/// Transport responder act1 babd key serialization test
let _testCase4 =
let inboundPeer = ourNodeSecret |> PeerChannelEncryptor.newInBound
let actOne = hex.DecodeData("00046360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f70df6086551151f58b8afe6c195782c6a")
let actualR = inboundPeer |> PeerChannelEncryptor.processActOneWithEphemeralKey actOne ourNodeSecret ourEphemeral
- Expect.isError (actualR) ""
+ Expect.isError (Result.ToFSharpCoreResult actualR) ""
/// Transport-responder act1 bad MAC test
let _testCase5 =
let inboundPeer = ourNodeSecret |> PeerChannelEncryptor.newInBound
let actOne = hex.DecodeData("00036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f70df6086551151f58b8afe6c195782c6b")
let actualRR = inboundPeer |> PeerChannelEncryptor.processActOneWithEphemeralKey actOne ourNodeSecret ourEphemeral
- Expect.isError (actualRR) ""
+ Expect.isError (Result.ToFSharpCoreResult actualRR) ""
/// Transport responder act3 bad version test
let _testCase6 =
@@ -150,7 +151,7 @@ let peerChannelEncryptorTests =
let actThree = hex.DecodeData("01b9e3a702e93e3a9948c2ed6e5fd7590a6e1c3a0344cfc9d5b57357049aa22355361aa02e55a8fc28fef5bd6d71ad0c38228dc68b1c466263b47fdf31e560e139ba")
let actualR = inboundPeer2 |> PeerChannelEncryptor.processActThree actThree
- Expect.isError (actualR) ""
+ Expect.isError (Result.ToFSharpCoreResult actualR) ""
/// Transport responder act3 short read test
let _testCase7 =
@@ -171,7 +172,7 @@ let peerChannelEncryptorTests =
Expect.equal actualActOneResult expectedActOneResult ""
let actThree = hex.DecodeData("00c9e3a702e93e3a9948c2ed6e5fd7590a6e1c3a0344cfc9d5b57357049aa22355361aa02e55a8fc28fef5bd6d71ad0c38228dc68b1c466263b47fdf31e560e139ba")
let r = PeerChannelEncryptor.processActThree actThree inboundPeer2
- Expect.isError r ""
+ Expect.isError (Result.ToFSharpCoreResult r) ""
/// transport-responder act3 bad rx
let _testCase9 =
@@ -183,7 +184,7 @@ let peerChannelEncryptorTests =
let actThree = hex.DecodeData("00bfe3a702e93e3a9948c2ed6e5fd7590a6e1c3a0344cfc9d5b57357049aa2235536ad09a8ee351870c2bb7f78b754a26c6cef79a98d25139c856d7efd252c2ae73c")
let r = PeerChannelEncryptor.processActThree actThree inboundPeer2
- Expect.isError r ""
+ Expect.isError (Result.ToFSharpCoreResult r) ""
/// transport-responder act3 abd MAC text
let _testCase10 =
@@ -195,7 +196,7 @@ let peerChannelEncryptorTests =
let actThree = hex.DecodeData("00b9e3a702e93e3a9948c2ed6e5fd7590a6e1c3a0344cfc9d5b57357049aa22355361aa02e55a8fc28fef5bd6d71ad0c38228dc68b1c466263b47fdf31e560e139bb")
let r = PeerChannelEncryptor.processActThree actThree inboundPeer2
- Expect.isError (r) ""
+ Expect.isError (Result.ToFSharpCoreResult r) ""
()
testCase "message encryption decryption test vectors" <| fun _ ->
@@ -268,7 +269,7 @@ let peerChannelEncryptorTests =
return header
}
runP instruction localInbound
- Expect.isOk (actualLengthR) ""
+ Expect.isOk (Result.ToFSharpCoreResult actualLengthR) ""
let actualLength, inbound2 = actualLengthR |> Result.deref
log (sprintf "new inbound is %A" inbound2)
let expectedLength = uint16 msg.Length
diff --git a/tests/DotNetLightning.Core.Tests/RouteCalculationTests.fs b/tests/DotNetLightning.Core.Tests/RouteCalculationTests.fs
index 0cfa81389..807a1e032 100644
--- a/tests/DotNetLightning.Core.Tests/RouteCalculationTests.fs
+++ b/tests/DotNetLightning.Core.Tests/RouteCalculationTests.fs
@@ -3,7 +3,6 @@ module RouteCalculationTests
open NBitcoin
open NBitcoin.DataEncoders
open Expecto
-open ResultUtils
open DotNetLightning.Utils
open DotNetLightning.Serialization.Msgs
@@ -16,6 +15,9 @@ open Generators
open GraphTests
open GraphTests.Constants
+open ResultUtils
+open ResultUtils.Portability
+
let hex = Encoders.Hex
let fsCheckConfig =
@@ -149,7 +151,7 @@ let tests = testList "Route Calculation" [
let route2 =
Routing.findRoute(graphWithRemovedEdge) a e DEFAULT_AMOUNT_MSAT 1 (Set.empty) (Set.empty)(Set.empty)DEFAULT_ROUTE_PARAMS (BlockHeight(400000u))
- Expect.isError (route2) ""
+ Expect.isError (Result.ToFSharpCoreResult route2) ""
testCase "calculate the shortest path (select direct channel)" <| fun _ ->
let updates = [
@@ -189,7 +191,7 @@ let tests = testList "Route Calculation" [
let graph = DirectedLNGraph.Create().AddEdges(updates)
let route =
Routing.findRoute graph f i DEFAULT_AMOUNT_MSAT 1 (Set.empty)(Set.empty)(Set.empty) DEFAULT_ROUTE_PARAMS (BlockHeight(400000u))
- Expect.isError (route) ""
+ Expect.isError (Result.ToFSharpCoreResult route) ""
testCase "if there are multiple channels between the same node, select the cheapest" <| fun _ ->
let updates = [
@@ -225,7 +227,7 @@ let tests = testList "Route Calculation" [
let g = DirectedLNGraph.Create().AddEdges(updates)
let route = Routing.findRoute(g) a e DEFAULT_AMOUNT_MSAT 1 (Set.empty)(Set.empty)(Set.empty) DEFAULT_ROUTE_PARAMS (BlockHeight(400000u))
- Expect.isError route ""
+ Expect.isError (Result.ToFSharpCoreResult route) ""
testCase "route not found (source OR target node not connected)" <| fun _ ->
let updates = [
@@ -233,8 +235,8 @@ let tests = testList "Route Calculation" [
makeUpdateSimple(4UL, c, d)
]
let g = DirectedLNGraph.Create().AddEdges(updates).AddVertex(a).AddVertex(e)
- Expect.isError(Routing.findRoute g a d DEFAULT_AMOUNT_MSAT 1 (Set.empty)(Set.empty)(Set.empty) DEFAULT_ROUTE_PARAMS (BlockHeight(400000u))) ""
- Expect.isError(Routing.findRoute g b e DEFAULT_AMOUNT_MSAT 1 (Set.empty)(Set.empty)(Set.empty) DEFAULT_ROUTE_PARAMS (BlockHeight(400000u))) ""
+ Expect.isError (Result.ToFSharpCoreResult (Routing.findRoute g a d DEFAULT_AMOUNT_MSAT 1 (Set.empty)(Set.empty)(Set.empty) DEFAULT_ROUTE_PARAMS (BlockHeight(400000u)))) ""
+ Expect.isError (Result.ToFSharpCoreResult (Routing.findRoute g b e DEFAULT_AMOUNT_MSAT 1 (Set.empty)(Set.empty)(Set.empty) DEFAULT_ROUTE_PARAMS (BlockHeight(400000u)))) ""
testCase "route not found (amount too high OR too low)" <| fun _ ->
let highAmount = DEFAULT_AMOUNT_MSAT * 10
@@ -253,8 +255,8 @@ let tests = testList "Route Calculation" [
let gHigh = DirectedLNGraph.Create().AddEdges(updatesHi)
let gLow = DirectedLNGraph.Create().AddEdges(updatesLow)
- Expect.isError (Routing.findRoute gHigh a d highAmount 1 (Set.empty)(Set.empty)(Set.empty) DEFAULT_ROUTE_PARAMS (BlockHeight(400000u))) ""
- Expect.isError (Routing.findRoute gLow a d lowAmount 1 (Set.empty)(Set.empty)(Set.empty) DEFAULT_ROUTE_PARAMS (BlockHeight(400000u))) ""
+ Expect.isError (Result.ToFSharpCoreResult (Routing.findRoute gHigh a d highAmount 1 (Set.empty)(Set.empty)(Set.empty) DEFAULT_ROUTE_PARAMS (BlockHeight(400000u)))) ""
+ Expect.isError (Result.ToFSharpCoreResult (Routing.findRoute gLow a d lowAmount 1 (Set.empty)(Set.empty)(Set.empty) DEFAULT_ROUTE_PARAMS (BlockHeight(400000u)))) ""
testCase "route to self" <| fun _ ->
let updates = [
@@ -266,7 +268,7 @@ let tests = testList "Route Calculation" [
let g = DirectedLNGraph.Create().AddEdges(updates)
let route =
Routing.findRoute g a a DEFAULT_AMOUNT_MSAT 1 (Set.empty)(Set.empty)(Set.empty) DEFAULT_ROUTE_PARAMS (BlockHeight(400000u))
- Expect.isError route ""
+ Expect.isError (Result.ToFSharpCoreResult route) ""
testCase "route to immediate neighbor" <| fun _ ->
let updates = [
@@ -298,7 +300,7 @@ let tests = testList "Route Calculation" [
Expect.sequenceEqual (hops2Ids(route1)) [1UL; 2UL; 3UL; 4UL] ""
let route2 =
Routing.findRoute g e e DEFAULT_AMOUNT_MSAT 1 (Set.empty)(Set.empty)(Set.empty) DEFAULT_ROUTE_PARAMS (BlockHeight(400000u))
- Expect.isError route2 ""
+ Expect.isError (Result.ToFSharpCoreResult route2) ""
testCase "calculate route and return metadata" <| fun _ ->
let uab =
@@ -451,7 +453,7 @@ let tests = testList "Route Calculation" [
let g = DirectedLNGraph.Create().AddEdges(updates)
let ignoredE = Set.singleton({ ShortChannelId = ShortChannelId.FromUInt64(3UL); A = c; B = d })
let route1 = Routing.findRoute(g) a e DEFAULT_AMOUNT_MSAT 1 (Set.empty) (ignoredE) (Set.empty) DEFAULT_ROUTE_PARAMS (BlockHeight(400000u))
- Expect.isError (route1) ""
+ Expect.isError (Result.ToFSharpCoreResult route1) ""
// verify that we left the graph untouched
Expect.isTrue(g.ContainsEdge(makeUpdateSimple(3UL, c, d) |> fst)) ""
@@ -473,7 +475,7 @@ let tests = testList "Route Calculation" [
let g = DirectedLNGraph.Create().AddEdges(updates)
let route =
Routing.findRoute(g) a e DEFAULT_AMOUNT_MSAT 1 (Set.empty)(Set.empty)(Set.empty) DEFAULT_ROUTE_PARAMS (BlockHeight(400000u))
- Expect.isError(route) "there should be no e node in the graph"
+ Expect.isError (Result.ToFSharpCoreResult route) "there should be no e node in the graph"
// now we add the missing edge to reach the destination
let (extraDesc, extraUpdate) = makeUpdate(4UL, d, e, LNMoney.MilliSatoshis(5L), 5u, None, None, None)
@@ -567,7 +569,7 @@ let tests = testList "Route Calculation" [
Expect.sequenceEqual (hops2Ids(r20)) [ for i in 0..19 -> (uint64 i) ] ""
let r21 =
(Routing.findRoute g (nodes.[0]) nodes.[21] DEFAULT_AMOUNT_MSAT 1 (Set.empty) (Set.empty) (Set.empty) DEFAULT_ROUTE_PARAMS (BlockHeight(400000u)))
- Expect.isError(r21) ""
+ Expect.isError (Result.ToFSharpCoreResult r21) ""
testCase "ignore cheaper route when it has more than 20 hops" <| fun _ ->
let nodes = [ for _ in 0..50 -> (new Key()).PubKey |> NodeId ]
@@ -740,7 +742,7 @@ let tests = testList "Route Calculation" [
let strictFeeParams = { DEFAULT_ROUTE_PARAMS with MaxFeeBase = LNMoney.MilliSatoshis(7); MaxFeePCT = 0. }
for _ in 0..10 do
let r = Routing.findRoute graph a d DEFAULT_AMOUNT_MSAT 3 (Set.empty) (Set.empty) (Set.empty) strictFeeParams (BlockHeight(400000u))
- Expect.isOk r ""
+ Expect.isOk (Result.ToFSharpCoreResult r) ""
let someRoute = r |> Result.deref
let routeCost =
(Graph.pathWeight (hops2Edges(someRoute)) DEFAULT_AMOUNT_MSAT false (BlockHeight 0u) None).Cost - DEFAULT_AMOUNT_MSAT
diff --git a/tests/DotNetLightning.Core.Tests/Serialization.fs b/tests/DotNetLightning.Core.Tests/Serialization.fs
index 1db46be19..c14f933d1 100644
--- a/tests/DotNetLightning.Core.Tests/Serialization.fs
+++ b/tests/DotNetLightning.Core.Tests/Serialization.fs
@@ -1,6 +1,5 @@
module Serialization
-open ResultUtils
open DotNetLightning.Utils
open DotNetLightning.Core.Utils.Extensions
open DotNetLightning.Serialization.Msgs
@@ -13,6 +12,9 @@ open System
open System.Collections
open FsCheck
+open ResultUtils
+open ResultUtils.Portability
+
module SerializationTest =
open Utils
@@ -798,9 +800,9 @@ module SerializationTest =
let ba = testCase |> parseBitArray
let result = Feature.validateFeatureGraph (ba)
if valid then
- Expect.isOk(result) (testCase)
+ Expect.isOk (Result.ToFSharpCoreResult result) (testCase)
else
- Expect.isError(result) (testCase)
+ Expect.isError (Result.ToFSharpCoreResult result) (testCase)
)
testCase "features compatibility (in int64)" <| fun _ ->
diff --git a/tests/DotNetLightning.Core.Tests/SphinxTests.fs b/tests/DotNetLightning.Core.Tests/SphinxTests.fs
index bf4cfa07a..663a319a2 100644
--- a/tests/DotNetLightning.Core.Tests/SphinxTests.fs
+++ b/tests/DotNetLightning.Core.Tests/SphinxTests.fs
@@ -82,7 +82,7 @@ let bolt4Tests1 =
let { Payload = payload0; NextPacket = nextPacket0; SharedSecret = _ss0 }: ParsedPacket =
Sphinx.parsePacket (privKeys.[0]) (associatedData) (onion.ToBytes())
|> fun rr ->
- Expect.isOk(rr) ""
+ Expect.isOk (Result.ToFSharpCoreResult rr) ""
Result.defaultWith (fun _ -> failwith "Unreachable") rr
let { Payload = payload1; NextPacket = nextPacket1; }: ParsedPacket =
Sphinx.parsePacket (privKeys.[1]) (associatedData) (nextPacket0.ToBytes())
@@ -113,7 +113,7 @@ let bolt4Tests1 =
let { NextPacket = packet1; SharedSecret = ss0 }: ParsedPacket =
Sphinx.parsePacket (privKeys.[0]) (associatedData) (onion.ToBytes())
|> fun r ->
- Expect.isOk(r) ""
+ Expect.isOk (Result.ToFSharpCoreResult r) ""
Result.defaultWith(fun _ -> failwith "Fail: bolt4 last node replies with err msg defaultClosure0") r
let { NextPacket = packet2; SharedSecret = ss1 }: ParsedPacket =
Sphinx.parsePacket (privKeys.[1]) (associatedData) (packet1.ToBytes())