Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
dkackman committed Dec 25, 2023
1 parent 27d49ff commit 276ebcf
Show file tree
Hide file tree
Showing 32 changed files with 175 additions and 312 deletions.
16 changes: 6 additions & 10 deletions src/chia-dotnet/CATWallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ namespace chia.dotnet
/// <summary>
/// Wraps a CAT wallet
/// </summary>
public sealed class CATWallet : Wallet
/// <remarks>
/// ctor
/// </remarks>
/// <param name="walletId">The wallet_id to wrap</param>
/// <param name="walletProxy">Wallet RPC proxy to use for communication</param>
public sealed class CATWallet(uint walletId, WalletProxy walletProxy) : Wallet(walletId, walletProxy)
{
/// <summary>
/// ctor
/// </summary>
/// <param name="walletId">The wallet_id to wrap</param>
/// <param name="walletProxy">Wallet RPC proxy to use for communication</param>
public CATWallet(uint walletId, WalletProxy walletProxy)
: base(walletId, walletProxy)
{
}

/// <summary>
/// Validates that <see cref="Wallet.WalletId"/> is a <see cref="WalletType.CAT"/>
Expand Down
16 changes: 6 additions & 10 deletions src/chia-dotnet/CRCATWallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@ namespace chia.dotnet
/// <summary>
/// Wraps a CRCAT Wallet
/// </summary>
public sealed class CRCATWallet : Wallet
/// <remarks>
/// ctor
/// </remarks>
/// <param name="walletId">The wallet_id to wrap</param>
/// <param name="walletProxy">Wallet RPC proxy to use for communication</param>
public sealed class CRCATWallet(uint walletId, WalletProxy walletProxy) : Wallet(walletId, walletProxy)
{
/// <summary>
/// ctor
/// </summary>
/// <param name="walletId">The wallet_id to wrap</param>
/// <param name="walletProxy">Wallet RPC proxy to use for communication</param>
public CRCATWallet(uint walletId, WalletProxy walletProxy)
: base(walletId, walletProxy)
{
}

/// <summary>
/// Validates that <see cref="Wallet.WalletId"/> is a <see cref="WalletType.CRCAT"/>
Expand Down
2 changes: 1 addition & 1 deletion src/chia-dotnet/ChiaTypes/Announcement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public record Announcement
{
public string OriginInfo { get; init; } = string.Empty;
public string Message { get; init; } = string.Empty;
public string MorphBytes { get; init; } = string.Empty;
public string? MorphBytes { get; init; }
}
}
2 changes: 1 addition & 1 deletion src/chia-dotnet/ChiaTypes/AutoClaimSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ public record AutoClaimSettings
public bool Enabled { get; init; }
public ulong TxFee { get; init; }
public ulong MinAmount { get; init; }
public ushort BatchSize { get; init; }
public ushort BatchSize { get; init; } = 50;
}
}
2 changes: 1 addition & 1 deletion src/chia-dotnet/ChiaTypes/BlockSpendWithConditions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace chia.dotnet
public record BlockSpendWithConditions
{
public CoinSpend CoinSpend { get; init; } = new();
public IEnumerable<ConditionWithArgs> Conditions { get; init; } = new List<ConditionWithArgs>();
public IEnumerable<ConditionWithVars> Conditions { get; init; } = new List<ConditionWithVars>();
}
}
2 changes: 1 addition & 1 deletion src/chia-dotnet/ChiaTypes/CoinAnnouncement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public record CoinAnnouncement
{
public string CoinId { get; init; } = string.Empty;
public string Message { get; init; } = string.Empty;
public string MorphBytes { get; init; } = string.Empty;
public string? MorphBytes { get; init; }
}
}
2 changes: 1 addition & 1 deletion src/chia-dotnet/ChiaTypes/Condition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ namespace chia.dotnet
public record Condition
{
public string ConditionOpcode { get; init; } = string.Empty;
public IEnumerable<ConditionWithArgs> Args { get; init; } = new List<ConditionWithArgs>();
public IEnumerable<ConditionWithVars> Args { get; init; } = new List<ConditionWithVars>();
}
}
4 changes: 2 additions & 2 deletions src/chia-dotnet/ChiaTypes/ConditionConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ internal sealed class ConditionConverter : JsonConverter<Condition>

var opcode = reader.ReadAsString(); // the opcode is stored without a name (as part of an unnamed tuple (aka array in json))
_ = reader.Read(); // move ahead to the start of the collection
var args = serializer.Deserialize<IEnumerable<ConditionWithArgs>>(reader);
var args = serializer.Deserialize<IEnumerable<ConditionWithVars>>(reader);
_ = reader.Read();

return new Condition()
{
ConditionOpcode = opcode ?? string.Empty,
Args = args ?? new List<ConditionWithArgs>()
Args = args ?? new List<ConditionWithVars>()
};
}

Expand Down
14 changes: 14 additions & 0 deletions src/chia-dotnet/ChiaTypes/ConditionValidTimes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace chia.dotnet
{
public record ConditionValidTimes
{
public ulong? MinSecsSinceCreated { get; init; }
public ulong? MinTime { get; init; }
public ulong? MinBlocksSinceCreated { get; init; }
public uint? MinHeight { get; init; }
public ulong? MaxSecAfterCreated { get; init; }
public ulong? MaxTime { get; init; }
public uint? MaxBlocksAfterCreated { get; init; }
public uint? MaxHeight { get; init; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace chia.dotnet
/// This structure is used to store parsed CLVM conditions
/// Conditions in CLVM have either format of(opcode, var1) or(opcode, var1, var2)
/// </summary>
public record ConditionWithArgs
public record ConditionWithVars
{
public ushort Opcode { get; init; }
public IEnumerable<string> Vars { get; init; } = new List<string>();
Expand Down
2 changes: 1 addition & 1 deletion src/chia-dotnet/ChiaTypes/PuzzleAnnouncement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public record PuzzleAnnouncement
{
public string PuzzleHash { get; init; } = string.Empty;
public string Message { get; init; } = string.Empty;
public string MorphBytes { get; init; } = string.Empty;
public string? MorphBytes { get; init; }
}
}
1 change: 1 addition & 0 deletions src/chia-dotnet/ChiaTypes/TransactionRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ public record TransactionRecord
public uint WalletId { get; init; }
[JsonIgnore]
public DateTime CreatedAtDateTime => CreatedAtTime.ToDateTime();
public ConditionValidTimes ValidTimes { get; init; } = new();
}
}
11 changes: 6 additions & 5 deletions src/chia-dotnet/ChiaTypes/TransactionTypeFilter.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
namespace chia.dotnet
using System.Collections.Generic;

namespace chia.dotnet
{
public record TransactionTypeFilter
{
public string AssetId { get; init; } = string.Empty;
public string Name { get; init; } = string.Empty;
public uint FirstSeenHeight { get; init; }
public string SenderPuzzleHash { get; init; } = string.Empty;
public IEnumerable<byte> Values { get; init; } = new List<byte>();

public FilterMode Mode { get; init; } = FilterMode.Exlude;
}
}
16 changes: 6 additions & 10 deletions src/chia-dotnet/CrawlerProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ namespace chia.dotnet
/// <summary>
/// Proxy that communicates with the crawler
/// </summary>
public sealed class CrawlerProxy : ServiceProxy
/// <remarks>
/// ctor
/// </remarks>
/// <param name="rpcClient"><see cref="IRpcClient"/> instance to use for rpc communication</param>
/// <param name="originService"><see cref="Message.Origin"/></param>
public sealed class CrawlerProxy(IRpcClient rpcClient, string originService) : ServiceProxy(rpcClient, ServiceNames.Crawler, originService)
{
/// <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 CrawlerProxy(IRpcClient rpcClient, string originService)
: base(rpcClient, ServiceNames.Crawler, originService)
{
}

/// <summary>
/// Retrieves aggregate information about peers
Expand Down
16 changes: 6 additions & 10 deletions src/chia-dotnet/DAOWallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@ namespace chia.dotnet
/// <summary>
/// Wraps a DAO Wallet
/// </summary>
public sealed class DAOWallet : Wallet
/// <remarks>
/// ctor
/// </remarks>
/// <param name="walletId">The wallet_id to wrap</param>
/// <param name="walletProxy">Wallet RPC proxy to use for communication</param>
public sealed class DAOWallet(uint walletId, WalletProxy walletProxy) : Wallet(walletId, walletProxy)
{
/// <summary>
/// ctor
/// </summary>
/// <param name="walletId">The wallet_id to wrap</param>
/// <param name="walletProxy">Wallet RPC proxy to use for communication</param>
public DAOWallet(uint walletId, WalletProxy walletProxy)
: base(walletId, walletProxy)
{
}

/// <summary>
/// Validates that <see cref="Wallet.WalletId"/> is a <see cref="WalletType.DAO"/>
Expand Down
31 changes: 9 additions & 22 deletions src/chia-dotnet/DIDWallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ namespace chia.dotnet
/// <summary>
/// Wraps a Distributed Identity Wallet
/// </summary>
public sealed class DIDWallet : Wallet
/// <remarks>
/// ctor
/// </remarks>
/// <param name="walletId">The wallet_id to wrap</param>
/// <param name="walletProxy">Wallet RPC proxy to use for communication</param>
public sealed class DIDWallet(uint walletId, WalletProxy walletProxy) : Wallet(walletId, walletProxy)
{
/// <summary>
/// ctor
/// </summary>
/// <param name="walletId">The wallet_id to wrap</param>
/// <param name="walletProxy">Wallet RPC proxy to use for communication</param>
public DIDWallet(uint walletId, WalletProxy walletProxy)
: base(walletId, walletProxy)
{
}

/// <summary>
/// Validates that <see cref="Wallet.WalletId"/> is a <see cref="WalletType.DISTRIBUTED_ID"/>
Expand All @@ -40,10 +36,7 @@ public override async Task Validate(CancellationToken cancellationToken = defaul
/// <returns>An awaitable <see cref="Task"/></returns>
public async Task UpdateRecoveryIds(IEnumerable<string> newList, ulong? numVerificationsRequired = null, bool? reusePuzhash = null, CancellationToken cancellationToken = default)
{
if (newList is null)
{
throw new ArgumentNullException(nameof(newList));
}
ArgumentNullException.ThrowIfNull(newList);

dynamic data = CreateWalletDataObject();
data.new_list = newList.ToList();
Expand All @@ -62,10 +55,7 @@ public async Task UpdateRecoveryIds(IEnumerable<string> newList, ulong? numVerif
/// <returns>An awaitable <see cref="Task"/></returns>
public async Task UpdateRecoveryIds(IEnumerable<string> newList, ulong numVerificationsRequired, CancellationToken cancellationToken = default)
{
if (newList is null)
{
throw new ArgumentNullException(nameof(newList));
}
ArgumentNullException.ThrowIfNull(newList);

dynamic data = CreateWalletDataObject();
data.new_list = newList.ToList();
Expand Down Expand Up @@ -212,10 +202,7 @@ public async Task<SpendBundle> UpdateMetadata(string metadata, bool? reusePuzhas
/// <returns>An awaitable <see cref="Task"/></returns>
public async Task RecoverySpend(IEnumerable<string> attestData, string? pubkey, string? puzzlehash, CancellationToken cancellationToken = default)
{
if (attestData is null)
{
throw new ArgumentNullException(nameof(attestData));
}
ArgumentNullException.ThrowIfNull(attestData);

dynamic data = CreateWalletDataObject();
data.attest_data = attestData.ToList();
Expand Down
18 changes: 7 additions & 11 deletions src/chia-dotnet/DaemonProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@ namespace chia.dotnet
/// The daemon can be used to proxy messages to and from other chia services as well
/// as controlling the <see cref="PlotterProxy"/> and having it's own procedures
/// </summary>
public sealed class DaemonProxy : ServiceProxy
/// <remarks>
/// ctor
/// </remarks>
/// <param name="rpcClient"><see cref="IRpcClient"/> instance to use for rpc communication</param>
/// <param name="originService"><see cref="Message.Origin"/></param>
public sealed class DaemonProxy(WebSocketRpcClient rpcClient, string originService) : ServiceProxy(rpcClient, ServiceNames.Daemon, originService)
{
/// <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 DaemonProxy(WebSocketRpcClient rpcClient, string originService)
: base(rpcClient, ServiceNames.Daemon, originService)
{
}

/// <summary>
/// Sends ping message to the service
Expand All @@ -42,7 +38,7 @@ public async Task Ping(CancellationToken cancellationToken = default)
/// <remarks>This only works for daemons because they can forward messages to other services through their <see cref="WebSocketRpcClient"/></remarks>
public T CreateProxyFrom<T>() where T : ServiceProxy
{
var constructor = typeof(T).GetConstructor(new Type[] { typeof(IRpcClient), typeof(string) });
var constructor = typeof(T).GetConstructor([typeof(IRpcClient), typeof(string)]);
return constructor is null || constructor.Invoke(new object[] { RpcClient, OriginService }) is not T proxy
? throw new InvalidOperationException($"Cannot create a {typeof(T).Name}")
: proxy;
Expand Down
16 changes: 6 additions & 10 deletions src/chia-dotnet/DataLayerProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ namespace chia.dotnet
/// <summary>
/// Proxy that communicates with the Data Layer
/// </summary>
public sealed class DataLayerProxy : ServiceProxy
/// <remarks>
/// ctor
/// </remarks>
/// <param name="rpcClient"><see cref="IRpcClient"/> instance to use for rpc communication</param>
/// <param name="originService"><see cref="Message.Origin"/></param>
public sealed class DataLayerProxy(IRpcClient rpcClient, string originService) : ServiceProxy(rpcClient, ServiceNames.DataLayer, originService)
{
/// <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 a mirror
Expand Down
16 changes: 6 additions & 10 deletions src/chia-dotnet/DataLayerWallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ namespace chia.dotnet
/// <summary>
/// Wraps a Data Layer Wallet
/// </summary>
public sealed class DataLayerWallet : Wallet
/// <remarks>
/// ctor
/// </remarks>
/// <param name="walletId">The wallet_id to wrap</param>
/// <param name="walletProxy">Wallet RPC proxy to use for communication</param>
public sealed class DataLayerWallet(uint walletId, WalletProxy walletProxy) : Wallet(walletId, walletProxy)
{
/// <summary>
/// ctor
/// </summary>
/// <param name="walletId">The wallet_id to wrap</param>
/// <param name="walletProxy">Wallet RPC proxy to use for communication</param>
public DataLayerWallet(uint walletId, WalletProxy walletProxy)
: base(walletId, walletProxy)
{
}

/// <summary>
/// Validates that <see cref="Wallet.WalletId"/> is a <see cref="WalletType.DATA_LAYER"/>
Expand Down
18 changes: 7 additions & 11 deletions src/chia-dotnet/FarmerProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ namespace chia.dotnet
/// <summary>
/// Proxy that communicates with the farmer
/// </summary>
public sealed class FarmerProxy : ServiceProxy
/// <remarks>
/// ctor
/// </remarks>
/// <param name="rpcClient"><see cref="IRpcClient"/> instance to use for rpc communication</param>
/// <param name="originService"><see cref="Message.Origin"/></param>
public sealed class FarmerProxy(IRpcClient rpcClient, string originService) : ServiceProxy(rpcClient, ServiceNames.Farmer, originService)
{
/// <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 FarmerProxy(IRpcClient rpcClient, string originService)
: base(rpcClient, ServiceNames.Farmer, originService)
{
}

/// <summary>
/// Get the farm and pool reward targets
Expand Down Expand Up @@ -56,7 +52,7 @@ public FarmerProxy(IRpcClient rpcClient, string originService)
/// <returns>The farm and pool reward targets</returns>
public async Task<(string FarmerTarget, string PoolTarget, bool HaveFarmerSk, bool HavePoolSk)> GetRewardTargetsIncludingPrivateKey(CancellationToken cancellationToken = default)
{
return await GetRewardTargetsIncludingPrivateKey(cancellationToken: cancellationToken).ConfigureAwait(false);
return await GetRewardTargetsIncludingPrivateKey(500, cancellationToken: cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand Down
Loading

0 comments on commit 276ebcf

Please sign in to comment.