Skip to content

Commit

Permalink
1.6.2 (#90)
Browse files Browse the repository at this point in the history
* use environment to find home

* is_running

* dep updates

* dep updates and lint

* add data layer, AddMissingFiles, BatchUpdate

* CreateDataStore

* GetBlockSpends

* get_fee_estimate

* comment

* new properties

* PushTransactions

* GetCoinRecordsByNames

* GetSpendableCoins

* NFTInfo fix (#76)

* NFTInfo fix

* Adding Id parameter and fix Infos for GetOfferSummary

---------

Co-authored-by: Enache Dragos <[email protected]>

* remove RLWallet add DL

* update from main (#89)

* Bump YamlDotNet from 11.2.1 to 12.3.1 in /src/chia-dotnet (#65)

Bumps [YamlDotNet](https://github.com/aaubry/YamlDotNet) from 11.2.1 to 12.3.1.
- [Release notes](https://github.com/aaubry/YamlDotNet/releases)
- [Commits](aaubry/YamlDotNet@v11.2.1...v12.3.1)

---
updated-dependencies:
- dependency-name: YamlDotNet
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump Newtonsoft.Json from 13.0.1 to 13.0.2 in /src/chia-dotnet (#60)

Bumps [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json) from 13.0.1 to 13.0.2.
- [Release notes](https://github.com/JamesNK/Newtonsoft.Json/releases)
- [Commits](JamesNK/Newtonsoft.Json@13.0.1...13.0.2)

---
updated-dependencies:
- dependency-name: Newtonsoft.Json
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Update README.md (#77)

* Bump YamlDotNet from 12.3.1 to 13.1.1 in /src/chia-dotnet (#79)

Bumps [YamlDotNet](https://github.com/aaubry/YamlDotNet) from 12.3.1 to 13.1.1.
- [Release notes](https://github.com/aaubry/YamlDotNet/releases)
- [Commits](aaubry/YamlDotNet@v12.3.1...v13.1.1)

---
updated-dependencies:
- dependency-name: YamlDotNet
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* remove rate limited wallet types and methods (#81)

* Update dependabot.yml (#82)

* Update codeql-analysis.yml to v2

* Update README.md (#84)

* Ignore jetbrains .idea folder https://rider-support.jetbrains.com/hc/en-us/articles/207097529-What-is-the-idea-folder- (#85)

Co-authored-by: kev <kev@darkhorse>

* added initial get-block-spends (#83)

* added initial get-block-spends

* Recommended PR changes

---------

Co-authored-by: kev <kev@darkhorse>
Co-authored-by: Don Kackman <[email protected]>

* Dto (#86)

* up through Mirror

* first pass done

* Remove blockspend.cs and use existing model CoinSpend (#87)

Co-authored-by: kev <kev@darkhorse>

* Key management (#88)

* get_key

* get_keys

* set_label

* delete_label

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: KevinOnFrontEnd <[email protected]>
Co-authored-by: kev <kev@darkhorse>

* remove duplicated GetBlockSpends

* add new includePending

* missing param

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Blackcode <[email protected]>
Co-authored-by: Enache Dragos <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: KevinOnFrontEnd <[email protected]>
Co-authored-by: kev <kev@darkhorse>
  • Loading branch information
6 people authored Aug 3, 2023
1 parent 56e1dd4 commit 9c5ba0d
Show file tree
Hide file tree
Showing 16 changed files with 354 additions and 21 deletions.
9 changes: 9 additions & 0 deletions src/chia-dotnet.tests/DaemonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ public async Task GetVersion()
Assert.IsFalse(string.IsNullOrEmpty(version));
}

[TestMethod]
public async Task IsRunning()
{
using var cts = new CancellationTokenSource(15000);

var running = await _theDaemon.IsRunning(ServiceNames.FullNode, cts.Token);
Assert.IsTrue(running);
}

[TestMethod]
public async Task GetKeyringStatus()
{
Expand Down
44 changes: 44 additions & 0 deletions src/chia-dotnet.tests/DataLayerProxyTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Threading;
using System.Threading.Tasks;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace chia.dotnet.tests
{
[TestClass]
[TestCategory("Integration")]
public class DataLayerProxyTest
{
private static DataLayerProxy _theDataLayer;

[ClassInitialize]
public static async Task Initialize(TestContext context)
{
using var cts = new CancellationTokenSource(2000);
var rpcClient = Factory.CreateWebsocketClient();
await rpcClient.Connect(cts.Token);

var daemon = new DaemonProxy(rpcClient, "unit_tests");
await daemon.RegisterService(cts.Token);

_theDataLayer = new DataLayerProxy(rpcClient, "unit_tests");
}

[ClassCleanup()]
public static void ClassCleanup()
{
_theDataLayer.RpcClient?.Dispose();
}

[TestMethod()]
[TestCategory("CAUTION")]
public async Task CreateDataStore()
{
using var cts = new CancellationTokenSource(150000);

var result = await _theDataLayer.CreateDataStore(5, cts.Token);

Assert.IsNotNull(result);
}
}
}
5 changes: 5 additions & 0 deletions src/chia-dotnet.tests/Factory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ internal static class Factory

public static HttpRpcClient CreateDirectRpcClientFromHardcodedLocation(int port, string endpointName)
{
//
// these are paths to cert for various test nodes
// modify
//
var endpoint = new EndpointInfo()
{
Uri = new Uri($"https://{NodeHostAddress}:{port}"),
//CertPath = @"\\wsl$/Ubuntu-20.04/home/don/.chia/mainnet/config/ssl/full_node/private_full_node.crt",
//KeyPath = @"\\wsl$/Ubuntu-20.04/home/don/.chia/mainnet/config/ssl/full_node/private_full_node.key",

//CertPath = @"C:\Users\dkack\.rchia\certs\chiapas\private_daemon.crt",
//KeyPath = @"C:\Users\dkack\.rchia\certs\chiapas\private_daemon.key",
// CertPath = $@"/home/kev/.chia/mainnet/config/ssl/daemon/private_{endpointName}.crt",
Expand Down
4 changes: 2 additions & 2 deletions src/chia-dotnet.tests/FullNodeProxyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public async Task GetMemmpooItemByTxId()
Assert.IsNotNull(ids);
Assert.IsTrue(ids.Any());

var item = await _theFullNode.GetMemmpooItemByTxId(ids.First(), cts.Token);
var item = await _theFullNode.GetMemmpooItemByTxId(ids.First(), false, cts.Token);

Assert.IsNotNull(item);
}
Expand Down Expand Up @@ -332,7 +332,7 @@ public async Task GetPuzzleAndSolution()

var coinRecord = await _theFullNode.GetCoinRecordByName(npc.CoinName, cts.Token);
Assert.IsNotNull(coinRecord);
Assert.AreNotEqual(coinRecord.SpentBlockIndex, 0);
Assert.AreNotEqual<uint>(coinRecord.SpentBlockIndex, 0);

var ps = await _theFullNode.GetPuzzleAndSolution(npc.CoinName, coinRecord.SpentBlockIndex, cts.Token);

Expand Down
8 changes: 4 additions & 4 deletions src/chia-dotnet.tests/chia-dotnet.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.2" />
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
1 change: 1 addition & 0 deletions src/chia-dotnet/ChiaTypes/OfferSummary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace chia.dotnet
{
public record OfferSummary
{
public string Id { get; init; } = string.Empty;
public IDictionary<string, ulong> Offered { get; init; } = new Dictionary<string, ulong>();
public IDictionary<string, ulong> Requested { get; init; } = new Dictionary<string, ulong>();
public ulong Fees { get; init; } = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/chia-dotnet/CrawlerProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace chia.dotnet
{
/// <summary>
/// Proxy that communicates with the harvester
/// Proxy that communicates with the crawler
/// </summary>
public sealed class CrawlerProxy : ServiceProxy
{
Expand Down
10 changes: 10 additions & 0 deletions src/chia-dotnet/DaemonProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,16 @@ public async Task DeleteLabel(uint fingerprint, CancellationToken cancellationTo
_ = await SendMessage("delete_label", data, cancellationToken).ConfigureAwait(false);
}

/// Determines if the named service is running.
/// </summary>
/// <param name="service">The service name</param>
/// <param name="cancellationToken">A token to allow the call to be cancelled</param>
/// <returns>Boolean indicator as to wheteher the service is running</returns>
public async Task<bool> IsRunning(string service, CancellationToken cancellationToken = default)
{
return await SendMessage<bool>("is_running", CreateDataObject(service), "is_running", cancellationToken).ConfigureAwait(false);
}

private static object CreateDataObject(string service)
{
if (string.IsNullOrEmpty(service))
Expand Down
88 changes: 88 additions & 0 deletions src/chia-dotnet/DataLayerProxy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Threading;
using System.Threading.Tasks;

namespace chia.dotnet
{
/// <summary>
/// Proxy that communicates with the Data Layer
/// </summary>
public sealed class DataLayerProxy : ServiceProxy
{
/// <summary>
/// ctor
/// </summary>
/// <param name="rpcClient"><see cref="IRpcClient"/> instance to use for rpc communication</param>
/// <param name="originService"><see cref="Message.Origin"/></param>
public DataLayerProxy(IRpcClient rpcClient, string originService)
: base(rpcClient, ServiceNames.DataLayer, originService)
{
}

/// <summary>
/// Adds missing files
/// </summary>
/// <param name="ids">List of file id's</param>
/// <param name="foldername">The folder name</param>
/// <param name="overwrite">Indicator whetehr to overwrite files</param>
/// <param name="cancellationToken">A token to allow the call to be cancelled</param>
/// <returns>An awaitable Task</returns>
public async Task AddMissingFiles(string[] ids, string foldername, bool overwrite = false, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(foldername))
{
throw new ArgumentNullException(nameof(foldername));
}
dynamic data = new ExpandoObject();
data.ids = ids;
data.foldername = foldername;
data.overwrite = overwrite;

await SendMessage("get_peer_counts", "data", cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// Applies a batch of updates.
/// </summary>
/// <param name="id">Id</param>
/// <param name="changeList">Name value pairs of changes</param>
/// <param name="cancellationToken">A token to allow the call to be cancelled</param>
/// <returns>Transaction id</returns>
public async Task<string> BatchUpdate(string id, IDictionary<string, string> changeList, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(id))
{
throw new ArgumentNullException(nameof(id));
}

dynamic data = new ExpandoObject();
data.id = id;
data.changelist = changeList;

var response = await SendMessage("batch_update", data, cancellationToken).ConfigureAwait(false);

return response.tx_id;
}

/// <summary>
/// Creates a data store.
/// </summary>
/// <param name="fee">Fee amount (in units of mojos)</param>
/// <param name="cancellationToken">A token to allow the call to be cancelled</param>
/// <returns>The tree id and list of transactions</returns>
public async Task<(string id, IEnumerable<TransactionRecord> txs)> CreateDataStore(ulong fee, CancellationToken cancellationToken = default)
{
dynamic data = new ExpandoObject();
data.fee = fee;

var response = await SendMessage("create_data_store", data, cancellationToken).ConfigureAwait(false);

return (
response.id,
response.txs
);
}
}
}
78 changes: 77 additions & 1 deletion src/chia-dotnet/FullNodeProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,80 @@ public async Task<IEnumerable<FullBlock>> GetBlocks(uint start, uint end, bool?
return await SendMessage<IEnumerable<FullBlock>>("get_blocks", data, "blocks", cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// Estimate a spend fee
/// </summary>
/// <param name="spendBundle">The spend bundle to esimtate</param>
/// <param name="targetTimes">Array of target times</param>
/// <param name="cancellationToken">A token to allow the call to be cancelled</param>
/// <returns>Fee estimate details</returns>
public async Task<(IEnumerable<int> estimates,
IEnumerable<int> targetTimes,
ulong currentFeeRate,
ulong mempoolSize,
ulong mempoolMaxSize,
bool synced,
ulong peakHeight,
ulong lastPeakTimestamp,
ulong utcTimestamp
)> GetFeeEstimate(SpendBundle spendBundle, IEnumerable<int> targetTimes, CancellationToken cancellationToken = default)
{
dynamic data = new ExpandoObject();
data.spend_bundle = spendBundle;
data.target_times = targetTimes.ToList();

var response = await SendMessage("get_fee_estimate", data, cancellationToken).ConfigureAwait(false);

return (
response.estimates,
response.target_times,
response.current_fee_rate,
response.mempool_size,
response.mempool_max_size,
response.full_node_synced,
response.peak_height,
response.last_peak_timestamp,
response.node_time_utc
);
}

/// <summary>
/// Estimate a spend fee
/// </summary>
/// <param name="spendBundle">The spend bundle to esimtate</param>
/// <param name="targetTimes">Array of target times</param>
/// <param name="cancellationToken">A token to allow the call to be cancelled</param>
/// <returns>Fee estimate details</returns>
public async Task<(IEnumerable<int> estimates,
IEnumerable<int> targetTimes,
ulong currentFeeRate,
ulong mempoolSize,
ulong mempoolMaxSize,
bool synced,
ulong peakHeight,
ulong lastPeakTimestamp,
ulong utcTimestamp
)> GetFeeEstimate(ulong cost, IEnumerable<int> targetTimes, CancellationToken cancellationToken = default)
{
dynamic data = new ExpandoObject();
data.cost = cost;
data.target_times = targetTimes.ToList();

var response = await SendMessage("get_fee_estimate", data, cancellationToken).ConfigureAwait(false);

return (
response.estimates,
response.target_times,
response.current_fee_rate,
response.mempool_size,
response.mempool_max_size,
response.full_node_synced,
response.peak_height,
response.last_peak_timestamp,
response.node_time_utc
);
}

/// <summary>
/// Get a block record by a header hash
/// </summary>
Expand Down Expand Up @@ -403,9 +477,10 @@ public async Task<IEnumerable<string>> GetAllMemmpoolTxIds(CancellationToken can
/// Gets a mempool item by tx id.
/// </summary>
/// <param name="txId">Transaction id</param>
/// <param name="includePending">Including pending transactions</param>
/// <param name="cancellationToken">A token to allow the call to be cancelled</param>
/// <returns>The <see cref="MempoolItem"/></returns>
public async Task<MempoolItem> GetMemmpooItemByTxId(string txId, CancellationToken cancellationToken = default)
public async Task<MempoolItem> GetMemmpooItemByTxId(string txId, bool includePending = false, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(txId))
{
Expand All @@ -414,6 +489,7 @@ public async Task<MempoolItem> GetMemmpooItemByTxId(string txId, CancellationTok

dynamic data = new ExpandoObject();
data.tx_id = txId;
data.include_pending = includePending;

return await SendMessage<MempoolItem>("get_mempool_item_by_tx_id", data, "mempool_item", cancellationToken).ConfigureAwait(false);
}
Expand Down
1 change: 1 addition & 0 deletions src/chia-dotnet/ServiceNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public struct ServiceNames
public const string Plotter = "chia_plotter";
public const string Daemon = "daemon";
public const string Crawler = "chia_crawler";
public const string DataLayer = "chia_data_layer";
}
}
3 changes: 2 additions & 1 deletion src/chia-dotnet/TradeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,11 @@ public async Task<OfferSummary> GetOfferSummary(string offer, CancellationToken

return new OfferSummary()
{
Id = response.id,
Offered = Converters.ToObject<IDictionary<string, ulong>>(response.summary.offered),
Requested = Converters.ToObject<IDictionary<string, ulong>>(response.summary.requested),
Fees = response.summary.fees,
Infos = Converters.ToObject<IDictionary<string, object>>(response.summary.requested),
Infos = Converters.ToObject<IDictionary<string, object>>(response.summary.infos),
};
}

Expand Down
Loading

0 comments on commit 9c5ba0d

Please sign in to comment.