Skip to content

Commit

Permalink
Backend,Tests: Update NBitcoin to v6.0.17
Browse files Browse the repository at this point in the history
We want to update nbitcoin because we want to use
the feature implemented in [1], some changes were
necessary as mentioned in [2] due to couple of
removed methods.

[1] MetacoSA/NBitcoin#1067
[2] MetacoSA/NBitcoin#1068
  • Loading branch information
aarani committed Nov 7, 2021
1 parent a37d2bd commit a16ef64
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/GWallet.Backend.Tests/GWallet.Backend.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@
<HintPath>..\..\packages\FSharp.Core.4.7.0\lib\net45\FSharp.Core.dll</HintPath>
</Reference>
<Reference Include="NBitcoin.Altcoins">
<HintPath>..\..\packages\NBitcoin.Altcoins.2.0.5.1\lib\net452\NBitcoin.Altcoins.dll</HintPath>
<HintPath>..\..\packages\NBitcoin.Altcoins.3.0.8\lib\net452\NBitcoin.Altcoins.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Logging.Abstractions">
<HintPath>..\..\packages\Microsoft.Extensions.Logging.Abstractions.1.0.2\lib\netstandard1.1\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
</Reference>
<Reference Include="NBitcoin">
<HintPath>..\..\packages\NBitcoin.5.0.13\lib\net461\NBitcoin.dll</HintPath>
<HintPath>..\..\packages\NBitcoin.6.0.17\lib\net461\NBitcoin.dll</HintPath>
</Reference>
<Reference Include="System.Runtime">
<HintPath>..\..\packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll</HintPath>
Expand Down
4 changes: 2 additions & 2 deletions src/GWallet.Backend.Tests/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<packages>
<package id="FSharp.Core" version="4.7.0" targetFramework="net461" />
<package id="Microsoft.Extensions.Logging.Abstractions" version="1.0.2" targetFramework="net46" />
<package id="NBitcoin" version="5.0.13" targetFramework="net471" />
<package id="NBitcoin.Altcoins" version="2.0.5.1" targetFramework="net452" />
<package id="NBitcoin" version="6.0.17" targetFramework="net471" />
<package id="NBitcoin.Altcoins" version="3.0.8" targetFramework="net452" />
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net46" />
<package id="NUnit" version="2.6.4" targetFramework="net46" />
<package id="NUnitTestAdapter" version="2.1.1" targetFramework="net46" />
Expand Down
4 changes: 2 additions & 2 deletions src/GWallet.Backend/GWallet.Backend.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@
</Reference>
<Reference Include="System.Net.Http" />
<Reference Include="NBitcoin.Altcoins">
<HintPath>..\..\packages\NBitcoin.Altcoins.2.0.5.1\lib\net452\NBitcoin.Altcoins.dll</HintPath>
<HintPath>..\..\packages\NBitcoin.Altcoins.3.0.8\lib\net452\NBitcoin.Altcoins.dll</HintPath>
</Reference>
<Reference Include="NBitcoin">
<HintPath>..\..\packages\NBitcoin.5.0.13\lib\net461\NBitcoin.dll</HintPath>
<HintPath>..\..\packages\NBitcoin.6.0.17\lib\net461\NBitcoin.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions">
<HintPath>..\..\packages\System.Threading.Tasks.Extensions.4.5.1\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
Expand Down
18 changes: 10 additions & 8 deletions src/GWallet.Backend/UtxoCoin/UtxoCoinAccount.fs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ module Account =
BitcoinAddress.Create(publicAddress, GetNetwork currency) |> GetElectrumScriptHashFromAddress

let internal GetPublicAddressFromPublicKey currency (publicKey: PubKey) =
(publicKey.GetSegwitAddress (GetNetwork currency)).GetScriptAddress().ToString()
publicKey
.GetScriptPubKey(ScriptPubKeyType.Segwit)
.Hash
.GetAddress(GetNetwork currency)
.ToString()

let internal GetPublicAddressFromNormalAccountFile (currency: Currency) (accountFile: FileRepresentation): string =
let pubKey = PubKey(accountFile.Name)
Expand Down Expand Up @@ -451,7 +455,7 @@ module Account =

let internal Create currency (password: string) (seed: array<byte>): Async<FileRepresentation> =
async {
let privKey = Key seed
use privKey = new Key (seed)
let network = GetNetwork currency
let secret = privKey.GetBitcoinSecret network
let encryptedSecret = secret.PrivateKey.GetEncryptedBitcoinSecret(password, network)
Expand Down Expand Up @@ -540,9 +544,8 @@ module Account =
let matchOriginToAccount(account: ReadOnlyUtxoAccount): bool =
let accountAddress = (account :> IAccount).PublicAddress
let bitcoinAddress = BitcoinAddress.Create(accountAddress, network)
let bitcoinScriptAddress = bitcoinAddress.GetScriptAddress()
let scriptAddressHash = bitcoinScriptAddress.Hash
(scriptAddressHash :> IDestination) = origin
let destination = bitcoinAddress.ScriptPubKey.GetDestination()
(destination :> IDestination) = origin

let account =
let accountOpt =
Expand All @@ -566,9 +569,8 @@ module Account =
let filterChangeTxOuts(txOut: TxOut): Option<BitcoinAddress * Money> =
let scriptPubKey = txOut.ScriptPubKey
let destinationAddress = scriptPubKey.GetDestinationAddress network
let destinationScriptAddress = destinationAddress.GetScriptAddress()
let destinationScriptAddressHash = destinationScriptAddress.Hash
if (destinationScriptAddressHash :> IDestination) = origin then
let destination = destinationAddress.ScriptPubKey.GetDestination()
if (destination :> IDestination) = origin then
None
else
Some (destinationAddress, txOut.Value)
Expand Down
4 changes: 2 additions & 2 deletions src/GWallet.Backend/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<package id="Microsoft.Extensions.Logging.Abstractions" version="1.0.2" targetFramework="net46" />
<package id="Microsoft.NETCore.Platforms" version="1.1.0" targetFramework="net46" />
<package id="Microsoft.Win32.Primitives" version="4.3.0" targetFramework="net46" />
<package id="NBitcoin" version="5.0.13" targetFramework="net471" />
<package id="NBitcoin.Altcoins" version="2.0.5.1" targetFramework="net452" />
<package id="NBitcoin" version="6.0.17" targetFramework="net471" />
<package id="NBitcoin.Altcoins" version="3.0.8" targetFramework="net452" />
<package id="Nethereum" version="0.95.0--date20210125-0551.git-05a29e9" targetFramework="net461" />
<package id="NETStandard.Library" version="1.6.1" targetFramework="net46" />
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net46" />
Expand Down

0 comments on commit a16ef64

Please sign in to comment.