Skip to content

Commit

Permalink
Merge branch '3.0.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
dkackman authored Dec 26, 2023
2 parents 1c885b1 + 276ebcf commit 8729b9c
Show file tree
Hide file tree
Showing 43 changed files with 238 additions and 358 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ In addition to static vs dynamic typing, C# and Python have very different conve
- Parameter names are `camelCased`.
- The chia RPC uses unsigned integers where dotnet might use signed. In cases where chia expects an unsigned number, it is unsigned on the dotnet side.
- `ulong` is used for the python 64 bit unsigned int.
- `BigInteger` is used for the python 128 bit unsigned int.
- `System.UInt128` is used for the python 128 bit unsigned int.
- Where the RPC return a scalar value, the dotnet code will as well. If it is optional in python it will be `Nullable<T>` in dotnet
- Where the RPC returns a list of named scalar values, they are returned as a Tuple with named fields.
- Lists of things are returned as [`IEnumberable<T>`](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1?view=net-5.0).
Expand Down
2 changes: 1 addition & 1 deletion src/chia-dotnet.tests/chia-dotnet.tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
<RootNamespace>chia.dotnet.tests</RootNamespace>
<UserSecretsId>chia.dotnet.tests</UserSecretsId>
Expand Down
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;
}
}
5 changes: 2 additions & 3 deletions src/chia-dotnet/ChiaTypes/BlockRecord.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Numerics;

using Newtonsoft.Json;

Expand Down Expand Up @@ -91,11 +90,11 @@ public record BlockRecord
/// <summary>
/// Total number of VDF iterations since genesis, including this block
/// </summary>
public BigInteger TotalIters { get; init; }
public UInt128 TotalIters { get; init; }
/// <summary>
/// Total cumulative difficulty of all ancestor blocks since genesis
/// </summary>
public BigInteger Weight { get; init; }
public UInt128 Weight { get; init; }
[JsonIgnore]
public DateTime? DateTimestamp => Timestamp.ToDateTime();
[JsonIgnore]
Expand Down
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>();
}
}
6 changes: 2 additions & 4 deletions src/chia-dotnet/ChiaTypes/BlockchainState.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Numerics;

namespace chia.dotnet
namespace chia.dotnet
{
/// <summary>
/// The node's view of the blockchain.
Expand All @@ -17,7 +15,7 @@ public record BlockchainState
public long MempoolMaxTotalCost { get; init; }
public long BlockMaxCost { get; init; }
public BlockRecord? Peak { get; init; }
public BigInteger Space { get; init; }
public System.UInt128 Space { get; init; }
public ulong SubSlotIters { get; init; }
public SyncState Sync { get; init; } = new();
public uint AverageBlockTime { get; init; }
Expand Down
2 changes: 1 addition & 1 deletion src/chia-dotnet/ChiaTypes/Coin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public record Coin
{
public string ParentCoinInfo { get; init; } = string.Empty;
public string PuzzleHash { get; init; } = string.Empty;
public ulong Amount { get; init; }
public System.UInt128 Amount { get; init; }

/// <summary>
/// The <see cref="Amount"/> as a hex string
Expand Down
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; }
}
}
8 changes: 3 additions & 5 deletions src/chia-dotnet/ChiaTypes/RewardChainBlock.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System.Numerics;

namespace chia.dotnet
namespace chia.dotnet
{
public record RewardChainBlock
{
public BigInteger Weight { get; init; }
public System.UInt128 Weight { get; init; }
public uint Height { get; init; }
public BigInteger TotalIters { get; init; }
public System.UInt128 TotalIters { get; init; }
public byte SignagePointIndex { get; init; }
public string PosSsCcChallengeHash { get; init; } = string.Empty;
public ProofOfSpace ProofOfSpace { get; init; } = new();
Expand Down
6 changes: 2 additions & 4 deletions src/chia-dotnet/ChiaTypes/RewardChainBlockUnfinished.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System.Numerics;

namespace chia.dotnet
namespace chia.dotnet
{
public record RewardChainBlockUnfinished
{
public BigInteger TotalIters { get; init; }
public System.UInt128 TotalIters { get; init; }
public byte SignagePointIndex { get; init; }
public string PosSsCcChallengeHash { get; init; } = string.Empty;
public ProofOfSpace ProofOfSpace { get; init; } = new();
Expand Down
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;
}
}
10 changes: 5 additions & 5 deletions src/chia-dotnet/ChiaTypes/WalletBalance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
{
public record WalletBalance
{
public ulong ConfirmedWalletBalance { get; init; }
public ulong UnconfirmedWalletBalance { get; init; }
public ulong SpendableBalance { get; init; }
public ulong PendingChange { get; init; }
public ulong MaxSendAmount { get; init; }
public System.UInt128 ConfirmedWalletBalance { get; init; }
public System.UInt128 UnconfirmedWalletBalance { get; init; }
public System.UInt128 SpendableBalance { get; init; }
public System.UInt128 PendingChange { get; init; }
public System.UInt128 MaxSendAmount { get; init; }
public int UnspentCoinCount { get; init; }
public int PendingCoinRemovalCount { get; init; }
public WalletType WalletType { get; init; }
Expand Down
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
18 changes: 7 additions & 11 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 Expand Up @@ -106,7 +102,7 @@ public async Task<IDictionary<string, object>> ParseProposal(string proposalId,
/// </summary>
/// <param name="cancellationToken">A token to allow the call to be cancelled</param>
/// <returns></returns>
public async Task<IDictionary<string, ulong>> GetTreasuryBalance(CancellationToken cancellationToken = default)
public async Task<IDictionary<string, System.UInt128>> GetTreasuryBalance(CancellationToken cancellationToken = default)
{
dynamic data = CreateWalletDataObject();
return await WalletProxy.SendMessage<IDictionary<string, ulong>>("dao_get_treasury_balance", data, cancellationToken).ConfigureAwait(false);
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
Loading

0 comments on commit 8729b9c

Please sign in to comment.