Skip to content

Commit

Permalink
added initial get-block-spends (#83)
Browse files Browse the repository at this point in the history
* added initial get-block-spends

* Recommended PR changes

---------

Co-authored-by: kev <kev@darkhorse>
Co-authored-by: Don Kackman <[email protected]>
  • Loading branch information
3 people authored Aug 1, 2023
1 parent c3dc824 commit 414620f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/chia-dotnet.tests/Factory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace chia.dotnet.tests
internal static class Factory
{
// this is the ip address of the chia node
private const string NodeHostAddress = "former";
private const string NodeHostAddress = "127.0.0.1";

public static HttpRpcClient CreateDirectRpcClientFromHardcodedLocation(int port, string endpointName)
{
Expand All @@ -20,8 +20,8 @@ public static HttpRpcClient CreateDirectRpcClientFromHardcodedLocation(int port,
//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 = $@"C:\Users\dkack\.rchia\certs\{NodeHostAddress}\private_{endpointName}.crt",
KeyPath = $@"C:\Users\dkack\.rchia\certs\{NodeHostAddress}\private_{endpointName}.key",
// CertPath = $@"/home/kev/.chia/mainnet/config/ssl/daemon/private_{endpointName}.crt",
// KeyPath = $@"/home/kev/.chia/mainnet/config/ssl/daemon/private_{endpointName}.key",
//CertPath = @"C:\Users\dkack\.rchia\certs\chiapas\private_full_node.crt",
//KeyPath = @"C:\Users\dkack\.rchia\certs\chiapas\private_full_node.key",
};
Expand All @@ -43,8 +43,8 @@ public static WebSocketRpcClient CreateWebsocketClient()
var endpoint = new EndpointInfo()
{
Uri = new Uri($"wss://{NodeHostAddress}:55400"),
CertPath = $@"C:\Users\dkack\.rchia\certs\{NodeHostAddress}\private_daemon.crt",
KeyPath = $@"C:\Users\dkack\.rchia\certs\{NodeHostAddress}\private_daemon.key",
// CertPath = $@"/home/kev/.chia/mainnet/config/ssl/daemon/private_daemon.crt",
// KeyPath = $@"/home/kev/.chia/mainnet/config/ssl/daemon/private_daemon.key",
//CertPath = @"\\wsl$\Ubuntu-20.04\home\don\.chia\mainnet\config\ssl\daemon\private_daemon.crt",
//KeyPath = @"\\wsl$\Ubuntu-20.04\home\don\.chia\mainnet\config\ssl\daemon\private_daemon.key",
//CertPath = @"\\wsl.localhost\Ubuntu\home\don\.chia\mainnet\config\ssl\daemon\private_daemon.crt",
Expand Down
15 changes: 15 additions & 0 deletions src/chia-dotnet.tests/FullNodeProxyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,21 @@ public async Task GetAdditionsAndRemovals()

Assert.IsNotNull(additionsAndRemovals);
}


[TestMethod()]
public async Task GetBlockSpends()
{
// Arrange
var header = "0xaa8425c198253b96a15c40e32ef4c1fd36e751f0ff9a90199e8751df381eac71"; //hash from today

// Act
using var cts = new CancellationTokenSource(15000);
var spends = await _theFullNode.GetBlockSpends(header, cts.Token);

// Assert
Assert.IsNotNull(spends);
}

[TestMethod()]
public async Task GetAllMempoolItems()
Expand Down
18 changes: 18 additions & 0 deletions src/chia-dotnet/ChiaTypes/BlockSpend.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;

namespace chia.dotnet
{
public record BlockSpend
{
public string PuzzleReveal { get; init; } = string.Empty;
public string Solution { get; init; } = string.Empty;
public BlockCoinSpend Coin { get; init; } = new();
}

public record BlockCoinSpend
{
public Int64 Amount { get; init; }
public string ParentCoinInfo { get; init; } = string.Empty;
public string PuzzleHash { get; init; } = string.Empty;
}
}
12 changes: 12 additions & 0 deletions src/chia-dotnet/FullNodeProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,18 @@ public async Task<IEnumerable<CoinRecord>> GetCoinRecordsByHint(string hint, boo
);
}

public async Task<IEnumerable<BlockSpend>> GetBlockSpends(string headerhash, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(headerhash))
{
throw new ArgumentNullException(nameof(headerhash));
}
dynamic data = new ExpandoObject();
data.header_hash = headerhash;

return await SendMessage<IEnumerable<BlockSpend>>("get_block_spends", data, "block_spends", cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// Returns all items in the mempool.
/// </summary>
Expand Down

0 comments on commit 414620f

Please sign in to comment.