Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LiteDBStore #269

Merged
merged 5 commits into from Jun 11, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -10,6 +10,8 @@ To be released.

### Added interfaces

- Added `LiteDBStore` backend that uses [LiteDB] under the hood. [[#269]]

### Behavioral changes

- `BlockChain<T>.GetNonce()` became to count staged transactions too during
@@ -28,6 +30,8 @@ To be released.
- Fixed a bug that `Swarm` didn't stop properly during `Swarm.Preload()`.
[[#275]]

[LiteDB]: https://www.litedb.org/
[#269]: https://github.com/planetarium/libplanet/pull/269
[#270]: https://github.com/planetarium/libplanet/pull/270
[#273]: https://github.com/planetarium/libplanet/issues/273
[#275]: https://github.com/planetarium/libplanet/pull/275
@@ -16,6 +16,10 @@
<PackageReference Include="Menees.Analyzers.2017" Version="2.0.3">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.DotNet.Analyzers.Compatibility" Version="0.2.12-alpha">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.1-beta.61">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
@@ -43,7 +43,11 @@ public class TurnClient : IStunContext, IDisposable
_relayedClients = new List<TcpClient>();

_control = new TcpClient();

// TODO Should investigate about PC001 on TcpClient.Connect().
#pragma warning disable PC001 // API not supported on all platforms
_control.Connect(_host, _port);
#pragma warning restore PC001

_connectionAttempts =
new AsyncProducerConsumerQueue<ConnectionAttempt>();
@@ -1,144 +1,27 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Security.Cryptography;
using Libplanet.Blocks;
using Libplanet.Crypto;
using Libplanet.Store;
using Libplanet.Tests.Common.Action;
using Libplanet.Tx;

namespace Libplanet.Tests.Store
{
public class FileStoreFixture : IDisposable
public class FileStoreFixture : StoreFixture, IDisposable
{
public FileStoreFixture()
{
string postfix = Guid.NewGuid().ToString();
Path = System.IO.Path.Combine(
System.IO.Path.GetTempPath(), $"filestore_test_{postfix}");
Store = new FileStore(Path);
StoreNamespace = Guid.NewGuid().ToString();

Address1 = new Address(new byte[]
{
0x45, 0xa2, 0x21, 0x87, 0xe2, 0xd8, 0x85, 0x0b, 0xb3, 0x57,
0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0xcc,
});
Address2 = new Address(new byte[]
{
0x55, 0xa2, 0x21, 0x87, 0xe2, 0xd8, 0x85, 0x0b, 0xb3, 0x57,
0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0xdd,
});
TxId1 = new TxId(new byte[]
{
0x45, 0xa2, 0x21, 0x87, 0xe2, 0xd8, 0x85, 0x0b, 0xb3, 0x57,
0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0xcc,
0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0xcc,
0x9c, 0xcc,
});
TxId2 = new TxId(new byte[]
{
0x45, 0xa2, 0x21, 0x87, 0xe2, 0xd8, 0x85, 0x0b, 0xb3, 0x57,
0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0xcc,
0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0xcc,
0x9c, 0xdd,
});
TxId3 = new TxId(new byte[]
{
0x45, 0xa2, 0x21, 0x87, 0xe2, 0xd8, 0x85, 0x0b, 0xb3, 0x57,
0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0xcc,
0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0xcc,
0x9c, 0xee,
});
Hash1 = new HashDigest<SHA256>(new byte[]
{
0x45, 0xa2, 0x21, 0x87, 0xe2, 0xd8, 0x85, 0x0b, 0xb3, 0x57,
0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0xcc,
0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0xcc,
0x9c, 0xcc,
});
Hash2 = new HashDigest<SHA256>(new byte[]
{
0x45, 0xa2, 0x21, 0x87, 0xe2, 0xd8, 0x85, 0x0b, 0xb3, 0x57,
0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0xcc,
0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0xcc,
0x9c, 0xdd,
});
Hash3 = new HashDigest<SHA256>(new byte[]
{
0x45, 0xa2, 0x21, 0x87, 0xe2, 0xd8, 0x85, 0x0b, 0xb3, 0x57,
0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0xcc,
0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0xcc,
0x9c, 0xee,
});

Block1 = TestUtils.MineGenesis<DumbAction>();
Block2 = TestUtils.MineNext(Block1);
Block3 = TestUtils.MineNext(Block2);

Transaction1 = MakeTransaction(new List<DumbAction>(), ImmutableHashSet<Address>.Empty);
Transaction2 = MakeTransaction(new List<DumbAction>(), ImmutableHashSet<Address>.Empty);
}

public string Path { get; }

public FileStore Store { get; }

public string StoreNamespace { get; }

public Address Address1 { get; }

public Address Address2 { get; }

public TxId TxId1 { get; }

public TxId TxId2 { get; }

public TxId TxId3 { get; }

public HashDigest<SHA256> Hash1 { get; }

public HashDigest<SHA256> Hash2 { get; }

public HashDigest<SHA256> Hash3 { get; }

public Block<DumbAction> Block1 { get; }

public Block<DumbAction> Block2 { get; }

public Block<DumbAction> Block3 { get; }

public Transaction<DumbAction> Transaction1 { get; }

public Transaction<DumbAction> Transaction2 { get; }

public void Dispose()
{
if (Directory.Exists(Path))
{
Directory.Delete(Path, true);
}
}

public Transaction<DumbAction> MakeTransaction(
IEnumerable<DumbAction> actions = null,
ImmutableHashSet<Address> updatedAddresses = null,
long nonce = 0,
PrivateKey privateKey = null
)
{
privateKey = privateKey ?? new PrivateKey();
var timestamp =
new DateTimeOffset(2018, 11, 21, 0, 0, 0, TimeSpan.Zero);
return Transaction<DumbAction>.Create(
nonce,
privateKey,
actions ?? new DumbAction[0],
updatedAddresses,
timestamp
);
}
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.