Skip to content

Commit

Permalink
Merge pull request #21 from kauxam/feature/checkconsistency
Browse files Browse the repository at this point in the history
Feature/checkconsistency
  • Loading branch information
Felandil committed May 15, 2018
2 parents ccd92d9 + 8876ee7 commit 36119ca
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<Compile Include="..\..\Tangle.Net\Tangle.Net\Repository\Client\RestIotaClient.cs" Link="Repository\Client\RestIotaClient.cs" />
<Compile Include="..\..\Tangle.Net\Tangle.Net\Repository\CommandType.cs" Link="Repository\CommandType.cs" />
<Compile Include="..\..\Tangle.Net\Tangle.Net\Repository\DataTransfer\AddressWithBalances.cs" Link="Repository\DataTransfer\AddressWithBalances.cs" />
<Compile Include="..\..\Tangle.Net\Tangle.Net\Repository\DataTransfer\ConsistencyInfo.cs" Link="Repository\DataTransfer\ConsistencyInfo.cs" />
<Compile Include="..\..\Tangle.Net\Tangle.Net\Repository\DataTransfer\InclusionStates.cs" Link="Repository\DataTransfer\InclusionStates.cs" />
<Compile Include="..\..\Tangle.Net\Tangle.Net\Repository\DataTransfer\Neighbor.cs" Link="Repository\DataTransfer\Neighbor.cs" />
<Compile Include="..\..\Tangle.Net\Tangle.Net\Repository\DataTransfer\NeighborList.cs" Link="Repository\DataTransfer\NeighborList.cs" />
Expand All @@ -83,6 +84,7 @@
<Compile Include="..\..\Tangle.Net\Tangle.Net\Repository\InvalidBundleException.cs" Link="Repository\InvalidBundleException.cs" />
<Compile Include="..\..\Tangle.Net\Tangle.Net\Repository\Responses\AddNeighborsResponse.cs" Link="Repository\Responses\AddNeighborsResponse.cs" />
<Compile Include="..\..\Tangle.Net\Tangle.Net\Repository\Responses\AttachToTangleResponse.cs" Link="Repository\Responses\AttachToTangleResponse.cs" />
<Compile Include="..\..\Tangle.Net\Tangle.Net\Repository\Responses\CheckConsistencyResponse.cs" Link="Repository\Responses\CheckConsistencyResponse.cs" />
<Compile Include="..\..\Tangle.Net\Tangle.Net\Repository\Responses\FindUsedAddressesResponse.cs" Link="Repository\Responses\FindUsedAddressesResponse.cs" />
<Compile Include="..\..\Tangle.Net\Tangle.Net\Repository\Responses\GetAccountDataResponse.cs" Link="Repository\Responses\GetAccountDataResponse.cs" />
<Compile Include="..\..\Tangle.Net\Tangle.Net\Repository\Responses\GetBalanceResponse.cs" Link="Repository\Responses\GetBalanceResponse.cs" />
Expand Down
5 changes: 5 additions & 0 deletions Tangle.Net/Tangle.Net/Repository/CommandType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ public static class CommandType
/// </summary>
public const string WereAddressesSpentFrom = "wereAddressesSpentFrom";

/// <summary>
/// The check consistency.
/// </summary>
public const string CheckConsistency = "checkConsistency";

#endregion
}
}
27 changes: 27 additions & 0 deletions Tangle.Net/Tangle.Net/Repository/DataTransfer/ConsistencyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace Tangle.Net.Repository.DataTransfer
{
/// <summary>
/// The consistency info.
/// </summary>
public class ConsistencyInfo
{
#region Public Properties

/// <summary>
/// Gets or sets the duration.
/// </summary>
public int Duration { get; set; }

/// <summary>
/// Gets or sets the state.
/// </summary>
public bool State { get; set; }

/// <summary>
/// Gets or sets the info.
/// </summary>
public string Info { get; set; }

#endregion
}
}
22 changes: 22 additions & 0 deletions Tangle.Net/Tangle.Net/Repository/IIotaCoreRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,28 @@ public interface IIotaCoreRepository
/// </returns>
Task<List<Address>> WereAddressesSpentFromAsync(List<Address> addresses);

/// <summary>
/// The check consistency.
/// </summary>
/// <param name="tailHashes">
/// The tail hashes.
/// </param>
/// <returns>
/// The <see cref="ConsistencyInfo"/>.
/// </returns>
ConsistencyInfo CheckConsistency(List<Hash> tailHashes);

/// <summary>
/// The check consistency async.
/// </summary>
/// <param name="tailHashes">
/// The tail hashes.
/// </param>
/// <returns>
/// The <see cref="Task"/>.
/// </returns>
Task<ConsistencyInfo> CheckConsistencyAsync(List<Hash> tailHashes);

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Tangle.Net.Repository.Responses
{
public class CheckConsistencyResponse
{
public int Duration { get; set; }
public bool State { get; set; }
public string Info { get; set; }
}
}
96 changes: 66 additions & 30 deletions Tangle.Net/Tangle.Net/Repository/RestIotaCoreRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,13 @@ public AddressWithBalances GetBalances(List<Address> addresses, int threshold =
}

return new AddressWithBalances
{
Addresses = addresses,
Duration = result.Duration,
MilestoneIndex = result.MilestoneIndex,
References =
{
Addresses = addresses,
Duration = result.Duration,
MilestoneIndex = result.MilestoneIndex,
References =
result.References.ConvertAll(reference => new TryteString(reference))
};
};
}

/// <inheritdoc />
Expand All @@ -226,13 +226,13 @@ public async Task<AddressWithBalances> GetBalancesAsync(List<Address> addresses,
}

return new AddressWithBalances
{
Addresses = addresses,
Duration = result.Duration,
MilestoneIndex = result.MilestoneIndex,
References =
{
Addresses = addresses,
Duration = result.Duration,
MilestoneIndex = result.MilestoneIndex,
References =
result.References.ConvertAll(reference => new TryteString(reference))
};
};
}

/// <inheritdoc />
Expand Down Expand Up @@ -281,10 +281,10 @@ public TipHashList GetTips()
var response = this.Client.ExecuteParameterlessCommand<GetTipsResponse>(CommandType.GetTips);

return new TipHashList
{
Duration = response.Duration,
Hashes = response.Hashes.Select(h => new Hash(h)).ToList()
};
{
Duration = response.Duration,
Hashes = response.Hashes.Select(h => new Hash(h)).ToList()
};
}

/// <inheritdoc />
Expand All @@ -293,10 +293,10 @@ public async Task<TipHashList> GetTipsAsync()
var response = await this.Client.ExecuteParameterlessCommandAsync<GetTipsResponse>(CommandType.GetTips);

return new TipHashList
{
Duration = response.Duration,
Hashes = response.Hashes.Select(h => new Hash(h)).ToList()
};
{
Duration = response.Duration,
Hashes = response.Hashes.Select(h => new Hash(h)).ToList()
};
}

/// <inheritdoc />
Expand All @@ -306,11 +306,11 @@ public TransactionsToApprove GetTransactionsToApprove(int depth = 27)
new Dictionary<string, object> { { "command", CommandType.GetTransactionsToApprove }, { "depth", depth } });

return new TransactionsToApprove
{
BranchTransaction = new Hash(result.BranchTransaction),
TrunkTransaction = new Hash(result.TrunkTransaction),
Duration = result.Duration
};
{
BranchTransaction = new Hash(result.BranchTransaction),
TrunkTransaction = new Hash(result.TrunkTransaction),
Duration = result.Duration
};
}

/// <inheritdoc />
Expand All @@ -320,11 +320,11 @@ public async Task<TransactionsToApprove> GetTransactionsToApproveAsync(int depth
new Dictionary<string, object> { { "command", CommandType.GetTransactionsToApprove }, { "depth", depth } });

return new TransactionsToApprove
{
BranchTransaction = new Hash(result.BranchTransaction),
TrunkTransaction = new Hash(result.TrunkTransaction),
Duration = result.Duration
};
{
BranchTransaction = new Hash(result.BranchTransaction),
TrunkTransaction = new Hash(result.TrunkTransaction),
Duration = result.Duration
};
}

/// <inheritdoc />
Expand Down Expand Up @@ -444,6 +444,42 @@ public async Task<List<Address>> WereAddressesSpentFromAsync(List<Address> addre
return addresses;
}

/// <inheritdoc />
public ConsistencyInfo CheckConsistency(List<Hash> tailHashes)
{
var response = Client.ExecuteParameterizedCommand<CheckConsistencyResponse>(
new Dictionary<string, object>
{
{ "command", CommandType.CheckConsistency },
{ "tails", tailHashes.Select(h => h.Value).ToList() }
});

return new ConsistencyInfo
{
Duration = response.Duration,
State = response.State,
Info = response.Info
};
}

/// <inheritdoc />
public async Task<ConsistencyInfo> CheckConsistencyAsync(List<Hash> tailHashes)
{
var response = await Client.ExecuteParameterizedCommandAsync<CheckConsistencyResponse>(
new Dictionary<string, object>
{
{ "command", CommandType.CheckConsistency },
{ "tails", tailHashes.Select(h => h.Value).ToList() }
});

return new ConsistencyInfo
{
Duration = response.Duration,
State = response.State,
Info = response.Info
};
}

/// <summary>
/// The create find transactions parameters.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions Tangle.Net/Tangle.Net/Tangle.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
<Compile Include="ProofOfWork\Utils\TrinaryDemultiplexer.cs" />
<Compile Include="Repository\Client\IIotaClient.cs" />
<Compile Include="Repository\Client\RestIotaClient.cs" />
<Compile Include="Repository\DataTransfer\ConsistencyInfo.cs" />
<Compile Include="Repository\DataTransfer\InclusionStates.cs" />
<Compile Include="Repository\DataTransfer\TipHashList.cs" />
<Compile Include="Repository\DataTransfer\TransactionHashList.cs" />
Expand Down Expand Up @@ -130,6 +131,7 @@
<Compile Include="Repository\Responses\GetTrytesResponse.cs" />
<Compile Include="Repository\Responses\RemoveNeighborsResponse.cs" />
<Compile Include="Repository\Responses\WereAddressesSpentFromResponse.cs" />
<Compile Include="Repository\Responses\CheckConsistencyResponse.cs" />
<Compile Include="Repository\RestIotaCoreRepository.cs" />
<Compile Include="Repository\RestIotaNodeRepository.cs" />
<Compile Include="Repository\RestIotaExtendedRepository.cs" />
Expand Down

0 comments on commit 36119ca

Please sign in to comment.