Skip to content

Commit

Permalink
Merge branch 'release/1.3.0.0' into SidechainMasternode
Browse files Browse the repository at this point in the history
  • Loading branch information
fassadlr committed Jun 10, 2022
2 parents db4c3fc + da0079b commit 0370679
Show file tree
Hide file tree
Showing 257 changed files with 6,145 additions and 1,639 deletions.
4 changes: 4 additions & 0 deletions PushNuget.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ rm "src\Stratis.Bitcoin.Features.ColdStaking\bin\Release\" -Recurse -Force
dotnet pack src\Stratis.Bitcoin.Features.ColdStaking --configuration Release --include-source --include-symbols
dotnet nuget push "src\Stratis.Bitcoin.Features.ColdStaking\bin\Release\*.symbols.nupkg" -k "" --source "https://api.nuget.org/v3/index.json"

rm "src\Stratis.Interop.Contracts\bin\Release\" -Recurse -Force
dotnet pack src\Stratis.Interop.Contracts --configuration Release --include-source --include-symbols
dotnet nuget push "src\Stratis.Interop.Contracts\bin\Release\*.symbols.nupkg" -k "" --source "https://api.nuget.org/v3/index.json"

# TEST PROJECTS

rm "src\Stratis.Bitcoin.Tests.Common\bin\Release\" -Recurse -Force
Expand Down
92 changes: 77 additions & 15 deletions Scripts/LaunchSidechainMasternode.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,17 @@ if ( $NodeType -eq "50K" )
""
Start-Sleep 10

if ($ethAddress -notmatch '^0x[a-fA-F0-9]{40}$')
{
Write-Host (Get-TimeStamp) "ERROR: Invalid ETH Address Loaded.. Is GETH already running?" -ForegroundColor Red
Start-Sleep 30
Exit
}

#Launching GETH
$API = $gethAPIPort
Write-Host (Get-TimeStamp) "Starting GETH Masternode" -ForegroundColor Cyan
$StartNode = Start-Process 'geth.exe' -ArgumentList "--syncmode fast --http --http.corsdomain=* --http.api web3,eth,debug,personal,net --datadir=$ethDataDir" -PassThru
$StartNode = Start-Process 'geth.exe' -ArgumentList "--syncmode snap --http --http.corsdomain=* --http.api web3,eth,debug,personal,net --datadir=$ethDataDir" -PassThru

While ( -not ( Test-Connection -TargetName 127.0.0.1 -TCPPort $API ) )
{
Expand Down Expand Up @@ -433,11 +440,11 @@ $API = $mainChainAPIPort
Write-Host (Get-TimeStamp) "Starting Mainchain Masternode" -ForegroundColor Cyan
if ( $NodeType -eq "50K" )
{
$StartNode = Start-Process dotnet -ArgumentList "run -c Release -- -mainchain -addressindex=1 -apiport=$mainChainAPIPort -counterchainapiport=$sideChainAPIPort -redeemscript=""$redeemscript"" -publickey=$multiSigPublicKey -federationips=$federationIPs" -PassThru
$StartNode = Start-Process dotnet -ArgumentList "run -c Release -- -mainchain -addressindex=1 -compactionthreshold=150 -apiport=$mainChainAPIPort -counterchainapiport=$sideChainAPIPort -redeemscript=""$redeemscript"" -publickey=$multiSigPublicKey -federationips=$federationIPs" -PassThru
}
Else
{
$StartNode = Start-Process dotnet -ArgumentList "run -c Release -- -mainchain -addressindex=1 -apiport=$mainChainAPIPort" -PassThru
$StartNode = Start-Process dotnet -ArgumentList "run -c Release -- -mainchain -addressindex=1 -compactionthreshold=150 -apiport=$mainChainAPIPort" -PassThru
}

#Wait for API
Expand Down Expand Up @@ -498,8 +505,7 @@ if ( $NodeType -eq "50K" )
{
if ( $ethGasPrice )
{
$StartNode = Start-Process dotnet -ArgumentList "run -c Release -- -sidechain -apiport=$sideChainAPIPort -counterchainapiport=$mainChainAPIPort -redeemscript=""$redeemscript"" -publickey=$multiSigPublicKey -federationips=$federationIPs -eth_interopenabled=1 -eth_account=$ethAddress -eth_passphrase=$ethPassword -eth_multisigwalletcontractaddress=$ethMultiSigContract -eth_wrappedstraxcontractaddress=$ethWrappedStraxContract -eth_gasprice=$ethGasPrice -eth_gas=$ethGasLimit" -PassThru
}
$StartNode = Start-Process dotnet -ArgumentList "run -c Release -- -sidechain -apiport=$sideChainAPIPort -counterchainapiport=$mainChainAPIPort -redeemscript=""$redeemscript"" -publickey=$multiSigPublicKey -federationips=$federationIPs -eth_interopenabled=1 -ethereumgaspricetracking -pricetracking -eth_account=$ethAddress -eth_passphrase=$ethPassword -eth_multisigwalletcontractaddress=$ethMultiSigContract -eth_wrappedstraxcontractaddress=$ethWrappedStraxContract -eth_keyvaluestorecontractaddress=$ethKeyValueStoreContractAddress -eth_gasprice=$ethGasPrice -eth_gas=$ethGasLimit -cirrusmultisigcontractaddress=$cirrusMultiSigContract -cirrussmartcontractactiveaddress=$miningWalletAddress -eth_watcherc20=$Token1 -eth_watcherc20=$Token2 -eth_watcherc20=$Token3 -eth_watcherc20=$Token4 -eth_watcherc20=$Token5 -eth_watcherc20=$Token6 -ethereummultisigwalletquorum=7" -PassThru }
Else
{
$StartNode = Start-Process dotnet -ArgumentList "run -c Release -- -sidechain -apiport=$sideChainAPIPort -counterchainapiport=$mainChainAPIPort -redeemscript=""$redeemscript"" -publickey=$multiSigPublicKey -federationips=$federationIPs -eth_interopenabled=1 -eth_account=$ethAddress -eth_passphrase=$ethPassword -eth_multisigwalletcontractaddress=$ethMultiSigContract -eth_wrappedstraxcontractaddress=$ethWrappedStraxContract" -PassThru
Expand Down Expand Up @@ -628,6 +634,62 @@ if ( $WalletNames -eq $null )
}
if ( $NodeType -eq "50K" )
{
#Initialize InterFlux
Write-Host (Get-TimeStamp) "Initializing InterFlux" -ForegroundColor Cyan

if ( $miningWalletPassword.GetType().Name -eq "SecureString" )
{
$requestBody = ConvertTo-Json @{

name = $miningWalletName
password = ConvertFrom-SecureString -SecureString $miningWalletPassword -AsPlainText
}
}
Else {
$requestBody = ConvertTo-Json @{

name = $miningWalletName
password = $miningWalletPassword
}
}

Invoke-RestMethod -Uri http://localhost:$sideChainAPIPort/api/Wallet/load -Method Post -Body $requestBody -ContentType "application/json-patch+json" -UseBasicParsing -ErrorVariable loadWallet

if ( $loadWallet )
{
Write-Host (Get-TimeStamp) "ERROR: Wallet could not be loaded. Please launch again" -ForegroundColor Red
Shutdown-SidechainNode
Shutdown-MainchainNode
Start-Sleep 30
Exit
}

if ( $miningWalletPassword.GetType().Name -eq "SecureString" )
{
$requestBody = ConvertTo-Json @{

walletName = $miningWalletName
walletPassword = ConvertFrom-SecureString -SecureString $miningWalletPassword -AsPlainText
accountName = "account 0"
}
}
Else {
$requestBody = ConvertTo-Json @{

walletName = $miningWalletName
walletPassword = $miningWalletPassword
accountName = "account 0"
}
}

$initializeInterFlux = Invoke-RestMethod -Uri http://localhost:$API/api/Interop/initializeinterflux -Method Post -Body $requestBody -ContentType "application/json-patch+json"
if ( $initializeInterFlux -ne $true )
{
Write-Host (Get-TimeStamp) "ERROR: Something went wrong. Cannot Initialize InterFlux! Please contact support in Discord" -ForegroundColor Red
Start-Sleep 30
Exit
}

#Enable Federation
Write-Host (Get-TimeStamp) "Enabling Federation" -ForegroundColor Cyan

Expand Down Expand Up @@ -704,8 +766,8 @@ Exit
# SIG # Begin signature block
# MIIO+gYJKoZIhvcNAQcCoIIO6zCCDucCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQU1EaWDGpoaK7k4e2zBPDkuV6j
# 5umgggxCMIIFfjCCBGagAwIBAgIQCrk836uc/wPyOiuycqPb5zANBgkqhkiG9w0B
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUejsUZ0JLxas+Jqi18Wly5q0+
# JuugggxCMIIFfjCCBGagAwIBAgIQCrk836uc/wPyOiuycqPb5zANBgkqhkiG9w0B
# AQsFADBsMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYD
# VQQLExB3d3cuZGlnaWNlcnQuY29tMSswKQYDVQQDEyJEaWdpQ2VydCBFViBDb2Rl
# IFNpZ25pbmcgQ0EgKFNIQTIpMB4XDTIxMDQyMjAwMDAwMFoXDTI0MDcxOTIzNTk1
Expand Down Expand Up @@ -775,11 +837,11 @@ Exit
# ZXJ0LmNvbTErMCkGA1UEAxMiRGlnaUNlcn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GxWPgEEB/Ic4oqiQC0sDG14SiWJ1mK3FuKbn1w==
# SIG # End signature block
2 changes: 1 addition & 1 deletion src/FederationSetup/FederationSetup.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>1.2.1.0</Version>
<Version>1.3.0.0</Version>
<Authors>Stratis Group Ltd.</Authors>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/FodyNlogAdapter/FodyNlogAdapter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyName>FodyNlogAdapter</AssemblyName>
<Version>1.2.1.0</Version>
<Version>1.3.0.0</Version>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<Authors>Stratis Group Ltd.</Authors>
<PackageId>Stratis.Utils.FodyNlogAdapter</PackageId>
Expand Down
16 changes: 8 additions & 8 deletions src/NBitcoin.Tests/pos_transaction_tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ public void CanExtractTxOutDestinationEasily()
var secret = new BitcoinSecret(privateKey, this.stratisMain);

Transaction tx = this.stratisMain.CreateTransaction();
var p2pkh = new TxOut(new Money((UInt64)45000000), secret.GetAddress());
var p2pk = new TxOut(new Money((UInt64)80000000), secret.PrivateKey.PubKey);
var p2pkh = new TxOut(new Money((ulong)45000000), secret.GetAddress());
var p2pk = new TxOut(new Money((ulong)80000000), secret.PrivateKey.PubKey);

tx.AddOutput(p2pkh);
tx.AddOutput(p2pk);
Expand Down Expand Up @@ -1340,10 +1340,10 @@ public void CanCheckSegwitPubkey()

foreach (int pushSize in new[] { 2, 10, 20, 32 })
{
a = new Script("1 " + String.Concat(Enumerable.Range(0, pushSize * 2).Select(_ => "0").ToArray()));
a = new Script("1 " + string.Concat(Enumerable.Range(0, pushSize * 2).Select(_ => "0").ToArray()));
Assert.True(PayToWitTemplate.Instance.CheckScriptPubKey(a));
}
a = new Script("1 " + String.Concat(Enumerable.Range(0, 33 * 2).Select(_ => "0").ToArray()));
a = new Script("1 " + string.Concat(Enumerable.Range(0, 33 * 2).Select(_ => "0").ToArray()));
Assert.False(PayToWitTemplate.Instance.CheckScriptPubKey(a));
}

Expand Down Expand Up @@ -1458,7 +1458,7 @@ public void CanBuildTransaction()
Assert.Equal(4, tx.Outputs.Count); //+ Change

txBuilder.Send(destinations[4], Money.Parse("1"));
var ex = Assert.Throws<NotEnoughFundsException>(() => txBuilder.BuildTransaction(true));
NotEnoughFundsException ex = Assert.Throws<NotEnoughFundsException>(() => txBuilder.BuildTransaction(true));
Assert.True(ex.Group == "test");
Assert.True((Money)ex.Missing == Money.Parse("0.9999"));
//Can sign partially
Expand Down Expand Up @@ -2338,7 +2338,7 @@ public void TestSigHashes()
}
else if (transactions.Count == 2 && modification == HashModification.Invalid)
{
string changes = String.Join(", ", invalidChanges);
string changes = string.Join(", ", invalidChanges);
output.Append(" (" + changes + ")");
}

Expand Down Expand Up @@ -2389,13 +2389,13 @@ private static void WriteTest(StringBuilder output, List<Coin> knownCoins, Trans
}
scriptParts.Add(scriptOutput.ToString());
}
coinOutput.Append(String.Join(" ", scriptParts));
coinOutput.Append(string.Join(" ", scriptParts));
coinOutput.Append("\", ");
coinOutput.Append(coin.Amount.Satoshi);
coinOutput.Append("]");
coinParts.Add(coinOutput.ToString());
}
output.Append(String.Join(",\n", coinParts));
output.Append(string.Join(",\n", coinParts));
output.Append("],\n\"");
output.Append(result.ToHex());
output.Append("\", \"P2SH,WITNESS\"],\n\n");
Expand Down
24 changes: 23 additions & 1 deletion src/NBitcoin.Tests/uint256_tests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using NBitcoin.BouncyCastle.Math;
using Stratis.Bitcoin.Tests.Common;
using Xunit;

Expand Down Expand Up @@ -58,11 +60,31 @@ public void uintTests()
Assert.Equal(0x00, v.GetByte(31));
Assert.Equal(0x39, new uint256("39000001ffffffffffffffffffffffffffffffffffffffffffffffffffffffff").GetByte(31));
Assert.Throws<ArgumentOutOfRangeException>(() => v.GetByte(32));

// Test conversions between uint256 and BigInteger
var a = System.Numerics.BigInteger.Parse("00010000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff", NumberStyles.AllowHexSpecifier);
var b = new uint256("00010000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff").ToBytes();

// Conversion from the uint256 byte representation to BigInteger can be done directly.
var c = new System.Numerics.BigInteger(b);

Assert.True(a == c);

var a1 = new uint256("00010000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
var b1 = System.Numerics.BigInteger.Parse("00010000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff", NumberStyles.AllowHexSpecifier).ToByteArray();

// The uint256 constructor requires a 256 bit array, so we have to right-pad the BigInteger byte array representation.
var newArray = new byte[32];
Array.Copy(b1, 0, newArray, 0, b1.Length);

var c1 = new uint256(newArray);

Assert.True(a1 == c1);
}

[Fact]
[Trait("UnitTest", "UnitTest")]
public void uitnSerializationTests()
public void uintSerializationTests()
{
var ms = new MemoryStream();
var stream = new BitcoinStream(ms, true);
Expand Down
2 changes: 1 addition & 1 deletion src/NBitcoin/BouncyCastle/asn1/DerObjectIdentifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public override string ToString()
}

private static bool IsValidBranchID(
String branchID, int start)
string branchID, int start)
{
bool periodAllowed = false;

Expand Down
10 changes: 5 additions & 5 deletions src/NBitcoin/BouncyCastle/math/BigInteger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public class BigInteger
* They are calculated according to the expected savings in multiplications.
* Some squares will also be saved on average, but we offset these against the extra storage costs.
*/
private static readonly int[] ExpWindowThresholds = { 7, 25, 81, 241, 673, 1793, 4609, Int32.MaxValue };
private static readonly int[] ExpWindowThresholds = { 7, 25, 81, 241, 673, 1793, 4609, int.MaxValue };

private const int BitsPerByte = 8;
private const int BitsPerInt = 32;
Expand Down Expand Up @@ -356,7 +356,7 @@ internal static BigInteger Arbitrary(int sizeInBits)
}

// strip leading zeros from the string str
while(index < str.Length && Int32.Parse(str[index].ToString(), style) == 0)
while(index < str.Length && int.Parse(str[index].ToString(), style) == 0)
{
index++;
}
Expand Down Expand Up @@ -2544,7 +2544,7 @@ public BigInteger Pow(int exp)
if(QuickPow2Check())
{
long powOf2 = (long)exp * (this.BitLength - 1);
if(powOf2 > Int32.MaxValue)
if(powOf2 > int.MaxValue)
{
throw new ArithmeticException("Result too large");
}
Expand Down Expand Up @@ -2763,7 +2763,7 @@ public BigInteger Pow(int exp)
int excessBits = (numWords << 5) - n;
if(excessBits > 0)
{
result[0] &= (int)(UInt32.MaxValue >> excessBits);
result[0] &= (int)(uint.MaxValue >> excessBits);
}

return result;
Expand Down Expand Up @@ -3275,7 +3275,7 @@ public string ToString(int radix)

// Work out the largest power of 'rdx' that is a positive 64-bit integer
// TODO possibly cache power/exponent against radix?
long limit = Int64.MaxValue / radix;
long limit = long.MaxValue / radix;
long power = radix;
int exponent = 1;
while(power <= limit)
Expand Down
16 changes: 16 additions & 0 deletions src/NBitcoin/IBitcoinSerializable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,21 @@ public static byte[] ToArrayEfficient(this MemoryStream ms)
return ms.ToArray();
#endif
}

public static void ReadWriteNullIntField(this BitcoinStream stream, ref int nullField)
{
if (stream.Serializing)
stream.ReadWrite(ref nullField);
else
{
try
{
stream.ReadWrite(ref nullField);
}
catch (Exception)
{
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/NBitcoin/NBitcoin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<PropertyGroup>
<Version>4.0.0.84</Version>
<Version>4.0.0.85</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/NBitcoin/Policy/StandardTransactionPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public TransactionPolicyError[] Check(Transaction transaction, ICoin[] spentCoin
{
if (this.ScriptVerify != null)
{
var script = (blockHeight < 0) ? coin.TxOut.ScriptPubKey : new ScriptAtHeight(coin.TxOut.ScriptPubKey, blockHeight, blockHash);
Script script = (blockHeight < 0) ? coin.TxOut.ScriptPubKey : new ScriptAtHeight(coin.TxOut.ScriptPubKey, blockHeight, blockHash);

if (!input.VerifyScript(this.Network, script, coin.TxOut.Value, this.ScriptVerify.Value, out ScriptError error))
{
Expand Down
2 changes: 1 addition & 1 deletion src/NBitcoin/Script.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ public static ScriptSigs CombineSignatures(Network network, Script scriptPubKey,

Script scriptSig1 = input1.ScriptSig;
Script scriptSig2 = input2.ScriptSig;
var hashVersion = HashVersion.Original;
HashVersion hashVersion = HashVersion.Original;
bool isWitness = input1.WitSig != WitScript.Empty || input2.WitSig != WitScript.Empty;
if (isWitness)
{
Expand Down
19 changes: 19 additions & 0 deletions src/NBitcoin/UInt256Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Numerics;

namespace NBitcoin
{
public static class UInt256Extensions
{
public static string FormatAsFractionalValue(this uint256 amount, int decimals = 18)
{
var amountAsBigInteger = new BigInteger(amount.ToBytes());

decimal scaledAmount = (decimal)amountAsBigInteger / ((long)Math.Pow(10, decimals));

string formatted = $"{scaledAmount:F18}";

return formatted;
}
}
}
Loading

0 comments on commit 0370679

Please sign in to comment.