Skip to content

Commit

Permalink
Move NBitcoin to core (#212)
Browse files Browse the repository at this point in the history
* Delete bloom filters

* Delete colored address

* Delete empty files

* Removing Stealth addresses

* Move all NBitcon code to blockcore project including tests

* Rename folders to NBitcoin

* Moving types from NBitcoin to respective folders

* Moving types Block and Transaction to respective folders
  • Loading branch information
dangershony authored Oct 6, 2020
1 parent 734324a commit ceea5a1
Show file tree
Hide file tree
Showing 455 changed files with 423 additions and 5,308 deletions.
16 changes: 1 addition & 15 deletions src/Blockcore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Features", "Features", "{15
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blockcore.Features.NodeHost", "Features\Blockcore.Features.NodeHost\Blockcore.Features.NodeHost.csproj", "{FB78D861-F3DF-412D-8A3D-D1756ADA39D4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NBitcoin", "External\NBitcoin\NBitcoin.csproj", "{2051FCAC-D4C7-498D-B935-2E9E6DEA0C29}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NBitcoin.Tests", "External\NBitcoin.Tests\NBitcoin.Tests.csproj", "{D97693D7-6A83-4143-83D8-621AC545D961}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blockcore.Features.Miner.Tests", "Tests\Blockcore.Features.Miner.Tests\Blockcore.Features.Miner.Tests.csproj", "{59F274B7-0FC5-4AD6-A8AE-27BF6F15CC12}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blockcore.Features.Dns", "Features\Blockcore.Features.Dns\Blockcore.Features.Dns.csproj", "{6181B889-81B0-4A1E-A29F-E20DCD8BFC1F}"
Expand Down Expand Up @@ -208,14 +204,6 @@ Global
{FB78D861-F3DF-412D-8A3D-D1756ADA39D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB78D861-F3DF-412D-8A3D-D1756ADA39D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB78D861-F3DF-412D-8A3D-D1756ADA39D4}.Release|Any CPU.Build.0 = Release|Any CPU
{2051FCAC-D4C7-498D-B935-2E9E6DEA0C29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2051FCAC-D4C7-498D-B935-2E9E6DEA0C29}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2051FCAC-D4C7-498D-B935-2E9E6DEA0C29}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2051FCAC-D4C7-498D-B935-2E9E6DEA0C29}.Release|Any CPU.Build.0 = Release|Any CPU
{D97693D7-6A83-4143-83D8-621AC545D961}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D97693D7-6A83-4143-83D8-621AC545D961}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D97693D7-6A83-4143-83D8-621AC545D961}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D97693D7-6A83-4143-83D8-621AC545D961}.Release|Any CPU.Build.0 = Release|Any CPU
{59F274B7-0FC5-4AD6-A8AE-27BF6F15CC12}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{59F274B7-0FC5-4AD6-A8AE-27BF6F15CC12}.Debug|Any CPU.Build.0 = Debug|Any CPU
{59F274B7-0FC5-4AD6-A8AE-27BF6F15CC12}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -368,8 +356,6 @@ Global
{75C364C1-0785-4EDD-9DB8-B0B21F27573C} = {15D29FFD-6142-4DC5-AFFD-10BA0CA55C45}
{84433C94-9CB7-4D6F-B2C1-C16B6F7F277C} = {EAE139C2-B19C-4905-9117-8A4068ABD3D2}
{FB78D861-F3DF-412D-8A3D-D1756ADA39D4} = {15D29FFD-6142-4DC5-AFFD-10BA0CA55C45}
{2051FCAC-D4C7-498D-B935-2E9E6DEA0C29} = {1B9A916F-DDAC-4675-B424-EDEDC1A58231}
{D97693D7-6A83-4143-83D8-621AC545D961} = {1B9A916F-DDAC-4675-B424-EDEDC1A58231}
{59F274B7-0FC5-4AD6-A8AE-27BF6F15CC12} = {EAE139C2-B19C-4905-9117-8A4068ABD3D2}
{6181B889-81B0-4A1E-A29F-E20DCD8BFC1F} = {15D29FFD-6142-4DC5-AFFD-10BA0CA55C45}
{CB7A2800-8E98-4CD5-A88A-832E03AF7ABF} = {EAE139C2-B19C-4905-9117-8A4068ABD3D2}
Expand Down Expand Up @@ -400,11 +386,11 @@ Global
{36CE71D7-812A-40D7-96B7-8220E8E86643} = {88A9A633-DA22-412B-A04C-2A3405D3E2C8}
{8E17F166-F15A-42F7-9407-06CE2A4AA0AF} = {88A9A633-DA22-412B-A04C-2A3405D3E2C8}
{D0A183FE-C913-4F8F-92EC-BD4502745140} = {8820C3A5-74B4-45AB-B80C-2495DFBA4A2B}
{50759380-AF62-11EA-BC6D-7563ABA8C5CA} = {3B56C02B-4468-4268-B797-851562789FCC}
{B3D4208F-797A-4893-BC33-BAB77508DFEE} = {15D29FFD-6142-4DC5-AFFD-10BA0CA55C45}
{EADB5247-F704-4B87-8B0E-606730B8517A} = {EAE139C2-B19C-4905-9117-8A4068ABD3D2}
{F64554A3-EC9A-4DBF-9AD6-25C78176C74E} = {15D29FFD-6142-4DC5-AFFD-10BA0CA55C45}
{53DA5042-1325-48A0-815A-C586590EC2EB} = {EAE139C2-B19C-4905-9117-8A4068ABD3D2}
{50759380-AF62-11EA-BC6D-7563ABA8C5CA} = {3B56C02B-4468-4268-B797-851562789FCC}
{EECEF785-EC8C-4037-9BF9-1DACABDE0E3D} = {50759380-AF62-11EA-BC6D-7563ABA8C5CA}
{271E03B3-5DD6-4A16-A54A-1E72AF9B4902} = {50759380-AF62-11EA-BC6D-7563ABA8C5CA}
{4F3C67B3-D96D-46A6-9BBC-19EB0A1A8712} = {4B0889C8-78BE-41C2-BB7B-7E82B3B83753}
Expand Down
File renamed without changes.
13 changes: 9 additions & 4 deletions src/Blockcore/Blockcore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
<None Remove="NBitcoin\icon.png" />
</ItemGroup>

<ItemGroup>
<AdditionalFiles Include="..\stylecop.json" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="NBitcoin\icon.png" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="ConcurrentHashSet" Version="1.1.0" />
<PackageReference Include="DBreeze" Version="1.95.0" />
Expand All @@ -40,10 +48,7 @@
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.4" />
<PackageReference Include="LevelDB.Standard" Version="2.1.6.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\External\NBitcoin\NBitcoin.csproj" />
<PackageReference Include="NStratis.HashLib" Version="1.0.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,5 @@ public MerkleBlock Filter(params uint256[] txIds)
{
return new MerkleBlock(this, txIds);
}

public MerkleBlock Filter(BloomFilter filter)
{
return new MerkleBlock(this, filter);
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@ public PrecomputedTransactionData(Transaction tx)
this.HashSequence = Script.GetHashSequence(tx);
this.HashPrevouts = Script.GetHashPrevouts(tx);
}

public uint256 HashPrevouts
{
get;
set;
}

public uint256 HashSequence
{
get;
set;
}

public uint256 HashOutputs
{
get;
set;
}
}
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using NBitcoin.Crypto;
using NBitcoin.OpenAsset;
using NBitcoin.Policy;
using NBitcoin.Stealth;
using Builder = System.Func<NBitcoin.TransactionBuilder.TransactionBuildingContext, NBitcoin.IMoney>;

namespace NBitcoin
Expand Down Expand Up @@ -984,25 +983,6 @@ private void AssertOpReturn(string name)
}
}

public TransactionBuilder Send(BitcoinStealthAddress address, Money amount, Key ephemKey = null)
{
if (amount < Money.Zero)
throw new ArgumentOutOfRangeException("amount", "amount can't be negative");

if (this._OpReturnUser == null)
this._OpReturnUser = "Stealth Payment";
else
throw new InvalidOperationException("Op return already used for " + this._OpReturnUser);

this.CurrentGroup.Builders.Add(ctx =>
{
StealthPayment payment = address.CreatePayment(ephemKey);
payment.AddToTransaction(ctx.Transaction, amount);
return amount;
});
return this;
}

public TransactionBuilder IssueAsset(IDestination destination, AssetMoney asset)
{
return IssueAsset(destination.ScriptPubKey, asset);
Expand Down Expand Up @@ -1361,7 +1341,7 @@ public ICoin FindSignableCoin(IndexedTxIn txIn)
if (coin is IColoredCoin)
coin = ((IColoredCoin)coin).Bearer;

if (coin == null || coin is ScriptCoin || coin is StealthCoin)
if (coin == null || coin is ScriptCoin)
return coin;

TxDestination hash = ScriptCoin.GetRedeemHash(this.Network, coin.TxOut.ScriptPubKey);
Expand Down Expand Up @@ -1695,19 +1675,6 @@ public Money EstimateFees(Transaction tx, FeeRate feeRate)
private void Sign(TransactionSigningContext ctx, ICoin coin, IndexedTxIn txIn)
{
TxIn input = txIn.TxIn;
if (coin is StealthCoin)
{
var stealthCoin = (StealthCoin)coin;
Key scanKey = FindKey(ctx, stealthCoin.Address.ScanPubKey.ScriptPubKey);
if (scanKey == null)
throw new KeyNotFoundException("Scan key for decrypting StealthCoin not found");
Key[] spendKeys = stealthCoin.Address.SpendPubKeys.Select(p => FindKey(ctx, p.ScriptPubKey)).Where(p => p != null).ToArray();
ctx.AdditionalKeys.AddRange(stealthCoin.Uncover(spendKeys, scanKey));
var normalCoin = new Coin(coin.Outpoint, coin.TxOut);
if (stealthCoin.Redeem != null)
normalCoin = normalCoin.ToScriptCoin(stealthCoin.Redeem);
coin = normalCoin;
}
Script scriptSig = CreateScriptSig(ctx, coin, txIn);
if (scriptSig == null)
return;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace NBitcoin
internal class BitReader
{
private BitArray array;

public BitReader(byte[] data, int bitCount)
{
var writer = new BitWriter();
Expand All @@ -18,7 +19,7 @@ public BitReader(byte[] data, int bitCount)
public BitReader(BitArray array)
{
this.array = new BitArray(array.Length);
for(int i = 0; i < array.Length; i++)
for (int i = 0; i < array.Length; i++)
this.array.Set(i, array.Get(i));
}

Expand All @@ -38,7 +39,7 @@ public int Position
public uint ReadUInt(int bitCount)
{
uint value = 0;
for(int i = 0; i < bitCount; i++)
for (int i = 0; i < bitCount; i++)
{
uint v = Read() ? 1U : 0U;
value += (v << i);
Expand All @@ -57,7 +58,7 @@ public int Count
public BitArray ToBitArray()
{
var result = new BitArray(this.array.Length);
for(int i = 0; i < this.array.Length; i++)
for (int i = 0; i < this.array.Length; i++)
result.Set(i, this.array.Get(i));
return result;
}
Expand All @@ -76,11 +77,11 @@ public void Consume(int count)

public bool Same(BitReader b)
{
while(this.Position != this.Count && b.Position != b.Count)
while (this.Position != this.Count && b.Position != b.Count)
{
bool valuea = Read();
bool valueb = b.Read();
if(valuea != valueb)
if (valuea != valueb)
return false;
}
return true;
Expand All @@ -89,9 +90,9 @@ public bool Same(BitReader b)
public override string ToString()
{
var builder = new StringBuilder(this.array.Length);
for(int i = 0; i < this.Count; i++)
for (int i = 0; i < this.Count; i++)
{
if(i != 0 && i % 8 == 0)
if (i != 0 && i % 8 == 0)
builder.Append(' ');
builder.Append(this.array.Get(i) ? "1" : "0");
}
Expand All @@ -102,13 +103,15 @@ public override string ToString()
internal class BitWriter
{
private List<bool> values = new List<bool>();

public int Count
{
get
{
return this.values.Count;
}
}

public void Write(bool value)
{
this.values.Insert(this.Position, value);
Expand Down Expand Up @@ -140,11 +143,11 @@ public byte[] ToBytes()
private static byte[] ToByteArray(BitArray bits)
{
int arrayLength = bits.Length / 8;
if(bits.Length % 8 != 0)
if (bits.Length % 8 != 0)
arrayLength++;
var array = new byte[arrayLength];

for(int i = 0; i < bits.Length; i++)
for (int i = 0; i < bits.Length; i++)
{
int b = i / 8;
int offset = i % 8;
Expand All @@ -153,7 +156,6 @@ private static byte[] ToByteArray(BitArray bits)
return array;
}


public BitArray ToBitArray()
{
return new BitArray(this.values.ToArray());
Expand All @@ -165,14 +167,13 @@ public int[] ToIntegers()
return Wordlist.ToIntegers(array);
}


private static byte[] SwapEndianBytes(byte[] bytes)
{
var output = new byte[bytes.Length];
for(int i = 0; i < output.Length; i++)
for (int i = 0; i < output.Length; i++)
{
byte newByte = 0;
for(int ib = 0; ib < 8; ib++)
for (int ib = 0; ib < 8; ib++)
{
newByte += (byte)(((bytes[i] >> ib) & 1) << (7 - ib));
}
Expand All @@ -181,18 +182,17 @@ private static byte[] SwapEndianBytes(byte[] bytes)
return output;
}



public void Write(uint value, int bitCount)
{
for(int i = 0; i < bitCount; i++)
for (int i = 0; i < bitCount; i++)
{
Write((value & 1) == 1);
value = value >> 1;
}
}

private int _Position;

public int Position
{
get
Expand All @@ -207,7 +207,7 @@ public int Position

internal void Write(BitReader reader, int bitCount)
{
for(int i = 0; i < bitCount; i++)
for (int i = 0; i < bitCount; i++)
{
Write(reader.Read());
}
Expand All @@ -217,9 +217,10 @@ public void Write(BitArray bitArray)
{
Write(bitArray, bitArray.Length);
}

public void Write(BitArray bitArray, int bitCount)
{
for(int i = 0; i < bitCount; i++)
for (int i = 0; i < bitCount; i++)
{
Write(bitArray.Get(i));
}
Expand All @@ -238,14 +239,13 @@ public BitReader ToReader()
public override string ToString()
{
var builder = new StringBuilder(this.values.Count);
for(int i = 0; i < this.Count; i++)
for (int i = 0; i < this.Count; i++)
{
if(i != 0 && i % 8 == 0)
if (i != 0 && i % 8 == 0)
builder.Append(' ');
builder.Append(this.values[i] ? "1" : "0");
}
return builder.ToString();
}
}

}
}
Loading

0 comments on commit ceea5a1

Please sign in to comment.