From 7097d754cbb86033900408cb834008a3cc8bddef Mon Sep 17 00:00:00 2001 From: Don Kackman Date: Fri, 15 Dec 2023 16:23:12 -0600 Subject: [PATCH 1/3] convert to .net 8 --- src/chia-dotnet.tests/chia-dotnet.tests.csproj | 2 +- src/chia-dotnet/chia-dotnet.csproj | 2 +- src/docfx/docfx.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/chia-dotnet.tests/chia-dotnet.tests.csproj b/src/chia-dotnet.tests/chia-dotnet.tests.csproj index 2e6d9ee9..88f43c59 100644 --- a/src/chia-dotnet.tests/chia-dotnet.tests.csproj +++ b/src/chia-dotnet.tests/chia-dotnet.tests.csproj @@ -1,7 +1,7 @@ - net7.0 + net8.0 false chia.dotnet.tests chia.dotnet.tests diff --git a/src/chia-dotnet/chia-dotnet.csproj b/src/chia-dotnet/chia-dotnet.csproj index a34775c2..054e692e 100644 --- a/src/chia-dotnet/chia-dotnet.csproj +++ b/src/chia-dotnet/chia-dotnet.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 chia.dotnet true true diff --git a/src/docfx/docfx.csproj b/src/docfx/docfx.csproj index d351ec58..cbb58edc 100644 --- a/src/docfx/docfx.csproj +++ b/src/docfx/docfx.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 OnOutputUpdated From 27d49ff7fa8536925ec8a70bc16e4d41dd14f634 Mon Sep 17 00:00:00 2001 From: Don Kackman Date: Fri, 15 Dec 2023 16:43:26 -0600 Subject: [PATCH 2/3] UInt128 --- README.md | 2 +- src/chia-dotnet/ChiaTypes/BlockRecord.cs | 5 ++- src/chia-dotnet/ChiaTypes/BlockchainState.cs | 6 ++-- src/chia-dotnet/ChiaTypes/Coin.cs | 2 +- src/chia-dotnet/ChiaTypes/RewardChainBlock.cs | 8 ++--- .../ChiaTypes/RewardChainBlockUnfinished.cs | 6 ++-- src/chia-dotnet/ChiaTypes/WalletBalance.cs | 10 +++--- src/chia-dotnet/DAOWallet.cs | 2 +- src/chia-dotnet/Extensions.cs | 33 +++++++++++++++++-- src/chia-dotnet/FullNodeProxy.cs | 20 +++++------ src/chia-dotnet/chia-dotnet.csproj | 9 ++--- 11 files changed, 60 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index 58210d21..978012cf 100644 --- a/README.md +++ b/README.md @@ -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` 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`](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1?view=net-5.0). diff --git a/src/chia-dotnet/ChiaTypes/BlockRecord.cs b/src/chia-dotnet/ChiaTypes/BlockRecord.cs index f8089161..dbfaa2d6 100644 --- a/src/chia-dotnet/ChiaTypes/BlockRecord.cs +++ b/src/chia-dotnet/ChiaTypes/BlockRecord.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Numerics; using Newtonsoft.Json; @@ -91,11 +90,11 @@ public record BlockRecord /// /// Total number of VDF iterations since genesis, including this block /// - public BigInteger TotalIters { get; init; } + public UInt128 TotalIters { get; init; } /// /// Total cumulative difficulty of all ancestor blocks since genesis /// - public BigInteger Weight { get; init; } + public UInt128 Weight { get; init; } [JsonIgnore] public DateTime? DateTimestamp => Timestamp.ToDateTime(); [JsonIgnore] diff --git a/src/chia-dotnet/ChiaTypes/BlockchainState.cs b/src/chia-dotnet/ChiaTypes/BlockchainState.cs index 15848fc3..730ecb92 100644 --- a/src/chia-dotnet/ChiaTypes/BlockchainState.cs +++ b/src/chia-dotnet/ChiaTypes/BlockchainState.cs @@ -1,6 +1,4 @@ -using System.Numerics; - -namespace chia.dotnet +namespace chia.dotnet { /// /// The node's view of the blockchain. @@ -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; } diff --git a/src/chia-dotnet/ChiaTypes/Coin.cs b/src/chia-dotnet/ChiaTypes/Coin.cs index 9a04af8d..addc1223 100644 --- a/src/chia-dotnet/ChiaTypes/Coin.cs +++ b/src/chia-dotnet/ChiaTypes/Coin.cs @@ -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; } /// /// The as a hex string diff --git a/src/chia-dotnet/ChiaTypes/RewardChainBlock.cs b/src/chia-dotnet/ChiaTypes/RewardChainBlock.cs index 2cfe1a1f..4efd561b 100644 --- a/src/chia-dotnet/ChiaTypes/RewardChainBlock.cs +++ b/src/chia-dotnet/ChiaTypes/RewardChainBlock.cs @@ -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(); diff --git a/src/chia-dotnet/ChiaTypes/RewardChainBlockUnfinished.cs b/src/chia-dotnet/ChiaTypes/RewardChainBlockUnfinished.cs index cce22bc5..160086ec 100644 --- a/src/chia-dotnet/ChiaTypes/RewardChainBlockUnfinished.cs +++ b/src/chia-dotnet/ChiaTypes/RewardChainBlockUnfinished.cs @@ -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(); diff --git a/src/chia-dotnet/ChiaTypes/WalletBalance.cs b/src/chia-dotnet/ChiaTypes/WalletBalance.cs index a808c7a1..17e353b0 100644 --- a/src/chia-dotnet/ChiaTypes/WalletBalance.cs +++ b/src/chia-dotnet/ChiaTypes/WalletBalance.cs @@ -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; } diff --git a/src/chia-dotnet/DAOWallet.cs b/src/chia-dotnet/DAOWallet.cs index 2f90d6dd..46aa4796 100644 --- a/src/chia-dotnet/DAOWallet.cs +++ b/src/chia-dotnet/DAOWallet.cs @@ -106,7 +106,7 @@ public async Task> ParseProposal(string proposalId, /// /// A token to allow the call to be cancelled /// - public async Task> GetTreasuryBalance(CancellationToken cancellationToken = default) + public async Task> GetTreasuryBalance(CancellationToken cancellationToken = default) { dynamic data = CreateWalletDataObject(); return await WalletProxy.SendMessage>("dao_get_treasury_balance", data, cancellationToken).ConfigureAwait(false); diff --git a/src/chia-dotnet/Extensions.cs b/src/chia-dotnet/Extensions.cs index e8737172..a55302f9 100644 --- a/src/chia-dotnet/Extensions.cs +++ b/src/chia-dotnet/Extensions.cs @@ -86,7 +86,7 @@ public static string AsChia(this ulong mojo, string? format, IFormatProvider? pr /// Adapted from https://stackoverflow.com/questions/281640/how-do-i-get-a-human-readable-file-size-in-bytes-abbreviation-using-net public static string ToBytesString(this BigInteger byteCount, string format = "N3") { - string[] suffixes = { "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "YiB" }; + string[] suffixes = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "YiB"]; if (byteCount.IsZero) { return $"{0.0.ToString(format)} {suffixes[0]}"; @@ -104,6 +104,33 @@ public static string ToBytesString(this BigInteger byteCount, string format = "N return $"{num.ToString(format)} {suffixes[place]}"; } + /// + /// Format a number of bytes in human readable format + /// + /// The number of bytes + /// Return string culture format + /// A human readable string + /// Adapted from https://stackoverflow.com/questions/281640/how-do-i-get-a-human-readable-file-size-in-bytes-abbreviation-using-net + public static string ToBytesString(this UInt128 byteCount, string format = "N3") + { + string[] suffixes = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "YiB"]; + if (byteCount == 0) + { + return $"{0.0.ToString(format)} {suffixes[0]}"; + } + + var abs = BigInteger.Abs(byteCount); // in case byteCount is negative + var place = Convert.ToInt32(Math.Floor(BigInteger.Log(abs, 1024))); + var pow = Math.Pow(1024, place); + + // since we need to do this with integer math, get the quotient and remainder + var quotient = BigInteger.DivRem(abs, new BigInteger(pow), out var remainder); + // convert the remainder to a ratio and add both back together as doubles, putting the sign back + var num = UInt128.Sign(byteCount) * (Math.Floor((double)quotient) + ((double)remainder / pow)); + + return $"{num.ToString(format)} {suffixes[place]}"; + } + /// /// Format a number of bytes in human readable format /// @@ -113,7 +140,7 @@ public static string ToBytesString(this BigInteger byteCount, string format = "N /// Adapted from https://stackoverflow.com/questions/281640/how-do-i-get-a-human-readable-file-size-in-bytes-abbreviation-using-net public static string ToBytesString(this ulong byteCount, string format = "N3") { - string[] suffixes = { "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "YiB" }; + string[] suffixes = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "YiB"]; if (byteCount == 0) { return $"{0.0.ToString(format)} {suffixes[0]}"; @@ -166,7 +193,7 @@ public static string ToBytesString(this long byteCount, string format = "N3") /// A human readable string public static string ToBytesString(this double byteCount, string format = "N3") { - string[] suffixes = { "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "YiB" }; + string[] suffixes = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "YiB"]; if (byteCount == 0) { return $"{0.0.ToString(format)} {suffixes[0]}"; diff --git a/src/chia-dotnet/FullNodeProxy.cs b/src/chia-dotnet/FullNodeProxy.cs index 247132a2..2dbba089 100644 --- a/src/chia-dotnet/FullNodeProxy.cs +++ b/src/chia-dotnet/FullNodeProxy.cs @@ -12,17 +12,13 @@ namespace chia.dotnet /// /// Proxy that communicates with the full node /// - public sealed class FullNodeProxy : ServiceProxy + /// + /// ctor + /// + /// instance to use for rpc communication + /// + public sealed class FullNodeProxy(IRpcClient rpcClient, string originService) : ServiceProxy(rpcClient, ServiceNames.FullNode, originService) { - /// - /// ctor - /// - /// instance to use for rpc communication - /// - public FullNodeProxy(IRpcClient rpcClient, string originService) - : base(rpcClient, ServiceNames.FullNode, originService) - { - } /// /// Will wait until indicates @@ -492,8 +488,8 @@ public async Task> GetMemmpoolItemsByCoinName(string co /// /// /// A token to allow the call to be cancelled - /// of network space in bytes - public async Task GetNetworkSpace(string newerBlockHeaderhash, string olderBlockHeaderhash, CancellationToken cancellationToken = default) + /// of network space in bytes + public async Task GetNetworkSpace(string newerBlockHeaderhash, string olderBlockHeaderhash, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(newerBlockHeaderhash)) { diff --git a/src/chia-dotnet/chia-dotnet.csproj b/src/chia-dotnet/chia-dotnet.csproj index 054e692e..5e31e694 100644 --- a/src/chia-dotnet/chia-dotnet.csproj +++ b/src/chia-dotnet/chia-dotnet.csproj @@ -7,7 +7,7 @@ true $(NoWarn);CS1591 true - 2.2.1 + 3.0.0 dkackman dkackman A .net client library for chia™ RPC interfaces that runs on linux and windows. @@ -18,11 +18,12 @@ https://github.com/dkackman/chia-dotnet git chia, 2.1.2 - Add Dao Wallet + .NET 8 +UInt 128 chia-leaf-logo-384x384.png - 2.2.1.0 - 2.2.1.0 + 3.0.0.0 + 3.0.0.0 enable chia.dotnet README.md From 276ebcfec23859b88b9eb857104709dc6aa47105 Mon Sep 17 00:00:00 2001 From: Don Kackman Date: Mon, 25 Dec 2023 16:02:37 -0600 Subject: [PATCH 3/3] initial --- src/chia-dotnet/CATWallet.cs | 16 ++--- src/chia-dotnet/CRCATWallet.cs | 16 ++--- src/chia-dotnet/ChiaTypes/Announcement.cs | 2 +- .../ChiaTypes/AutoClaimSettings.cs | 2 +- .../ChiaTypes/BlockSpendWithConditions.cs | 2 +- src/chia-dotnet/ChiaTypes/CoinAnnouncement.cs | 2 +- src/chia-dotnet/ChiaTypes/Condition.cs | 2 +- .../ChiaTypes/ConditionConverter.cs | 4 +- .../ChiaTypes/ConditionValidTimes.cs | 14 ++++ ...ditionWithArgs.cs => ConditionWithVars.cs} | 2 +- .../ChiaTypes/PuzzleAnnouncement.cs | 2 +- .../ChiaTypes/TransactionRecord.cs | 1 + .../ChiaTypes/TransactionTypeFilter.cs | 11 ++-- src/chia-dotnet/CrawlerProxy.cs | 16 ++--- src/chia-dotnet/DAOWallet.cs | 16 ++--- src/chia-dotnet/DIDWallet.cs | 31 +++------ src/chia-dotnet/DaemonProxy.cs | 18 ++---- src/chia-dotnet/DataLayerProxy.cs | 16 ++--- src/chia-dotnet/DataLayerWallet.cs | 16 ++--- src/chia-dotnet/FarmerProxy.cs | 18 ++---- src/chia-dotnet/FullNodeProxy.cs | 21 ++---- src/chia-dotnet/HarvesterProxy.cs | 16 ++--- src/chia-dotnet/NFTWallet.cs | 16 ++--- src/chia-dotnet/PlotterProxy.cs | 23 +++---- src/chia-dotnet/PoolWallet.cs | 16 ++--- src/chia-dotnet/ResponseException.cs | 22 +++---- src/chia-dotnet/TradeManager.cs | 14 +--- src/chia-dotnet/VerifiedCredentialManager.cs | 9 +-- src/chia-dotnet/Wallet.cs | 26 +++----- src/chia-dotnet/WalletProxy.cs | 64 ++++--------------- src/chia-dotnet/bech32/Bech32M.cs | 23 +++---- src/chia-dotnet/bech32/HexBytes.cs | 30 ++++----- 32 files changed, 175 insertions(+), 312 deletions(-) create mode 100644 src/chia-dotnet/ChiaTypes/ConditionValidTimes.cs rename src/chia-dotnet/ChiaTypes/{ConditionWithArgs.cs => ConditionWithVars.cs} (91%) diff --git a/src/chia-dotnet/CATWallet.cs b/src/chia-dotnet/CATWallet.cs index e89b4ddc..176590da 100644 --- a/src/chia-dotnet/CATWallet.cs +++ b/src/chia-dotnet/CATWallet.cs @@ -9,17 +9,13 @@ namespace chia.dotnet /// /// Wraps a CAT wallet /// - public sealed class CATWallet : Wallet + /// + /// ctor + /// + /// The wallet_id to wrap + /// Wallet RPC proxy to use for communication + public sealed class CATWallet(uint walletId, WalletProxy walletProxy) : Wallet(walletId, walletProxy) { - /// - /// ctor - /// - /// The wallet_id to wrap - /// Wallet RPC proxy to use for communication - public CATWallet(uint walletId, WalletProxy walletProxy) - : base(walletId, walletProxy) - { - } /// /// Validates that is a diff --git a/src/chia-dotnet/CRCATWallet.cs b/src/chia-dotnet/CRCATWallet.cs index 4bde1320..8fb02086 100644 --- a/src/chia-dotnet/CRCATWallet.cs +++ b/src/chia-dotnet/CRCATWallet.cs @@ -7,17 +7,13 @@ namespace chia.dotnet /// /// Wraps a CRCAT Wallet /// - public sealed class CRCATWallet : Wallet + /// + /// ctor + /// + /// The wallet_id to wrap + /// Wallet RPC proxy to use for communication + public sealed class CRCATWallet(uint walletId, WalletProxy walletProxy) : Wallet(walletId, walletProxy) { - /// - /// ctor - /// - /// The wallet_id to wrap - /// Wallet RPC proxy to use for communication - public CRCATWallet(uint walletId, WalletProxy walletProxy) - : base(walletId, walletProxy) - { - } /// /// Validates that is a diff --git a/src/chia-dotnet/ChiaTypes/Announcement.cs b/src/chia-dotnet/ChiaTypes/Announcement.cs index 91fe0a42..e7b4c023 100644 --- a/src/chia-dotnet/ChiaTypes/Announcement.cs +++ b/src/chia-dotnet/ChiaTypes/Announcement.cs @@ -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; } } } diff --git a/src/chia-dotnet/ChiaTypes/AutoClaimSettings.cs b/src/chia-dotnet/ChiaTypes/AutoClaimSettings.cs index f9aecf0a..0d16b828 100644 --- a/src/chia-dotnet/ChiaTypes/AutoClaimSettings.cs +++ b/src/chia-dotnet/ChiaTypes/AutoClaimSettings.cs @@ -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; } } diff --git a/src/chia-dotnet/ChiaTypes/BlockSpendWithConditions.cs b/src/chia-dotnet/ChiaTypes/BlockSpendWithConditions.cs index a8133671..5b15e7df 100644 --- a/src/chia-dotnet/ChiaTypes/BlockSpendWithConditions.cs +++ b/src/chia-dotnet/ChiaTypes/BlockSpendWithConditions.cs @@ -5,6 +5,6 @@ namespace chia.dotnet public record BlockSpendWithConditions { public CoinSpend CoinSpend { get; init; } = new(); - public IEnumerable Conditions { get; init; } = new List(); + public IEnumerable Conditions { get; init; } = new List(); } } diff --git a/src/chia-dotnet/ChiaTypes/CoinAnnouncement.cs b/src/chia-dotnet/ChiaTypes/CoinAnnouncement.cs index 8515a99a..d3a644af 100644 --- a/src/chia-dotnet/ChiaTypes/CoinAnnouncement.cs +++ b/src/chia-dotnet/ChiaTypes/CoinAnnouncement.cs @@ -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; } } } diff --git a/src/chia-dotnet/ChiaTypes/Condition.cs b/src/chia-dotnet/ChiaTypes/Condition.cs index 8860dc74..e5885c40 100644 --- a/src/chia-dotnet/ChiaTypes/Condition.cs +++ b/src/chia-dotnet/ChiaTypes/Condition.cs @@ -14,6 +14,6 @@ namespace chia.dotnet public record Condition { public string ConditionOpcode { get; init; } = string.Empty; - public IEnumerable Args { get; init; } = new List(); + public IEnumerable Args { get; init; } = new List(); } } diff --git a/src/chia-dotnet/ChiaTypes/ConditionConverter.cs b/src/chia-dotnet/ChiaTypes/ConditionConverter.cs index 2563e9c2..36d41ab3 100644 --- a/src/chia-dotnet/ChiaTypes/ConditionConverter.cs +++ b/src/chia-dotnet/ChiaTypes/ConditionConverter.cs @@ -16,13 +16,13 @@ internal sealed class ConditionConverter : JsonConverter 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>(reader); + var args = serializer.Deserialize>(reader); _ = reader.Read(); return new Condition() { ConditionOpcode = opcode ?? string.Empty, - Args = args ?? new List() + Args = args ?? new List() }; } diff --git a/src/chia-dotnet/ChiaTypes/ConditionValidTimes.cs b/src/chia-dotnet/ChiaTypes/ConditionValidTimes.cs new file mode 100644 index 00000000..559fc9d5 --- /dev/null +++ b/src/chia-dotnet/ChiaTypes/ConditionValidTimes.cs @@ -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; } + } +} diff --git a/src/chia-dotnet/ChiaTypes/ConditionWithArgs.cs b/src/chia-dotnet/ChiaTypes/ConditionWithVars.cs similarity index 91% rename from src/chia-dotnet/ChiaTypes/ConditionWithArgs.cs rename to src/chia-dotnet/ChiaTypes/ConditionWithVars.cs index 7d02fa63..91138386 100644 --- a/src/chia-dotnet/ChiaTypes/ConditionWithArgs.cs +++ b/src/chia-dotnet/ChiaTypes/ConditionWithVars.cs @@ -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) /// - public record ConditionWithArgs + public record ConditionWithVars { public ushort Opcode { get; init; } public IEnumerable Vars { get; init; } = new List(); diff --git a/src/chia-dotnet/ChiaTypes/PuzzleAnnouncement.cs b/src/chia-dotnet/ChiaTypes/PuzzleAnnouncement.cs index eec1d74c..c9c53a94 100644 --- a/src/chia-dotnet/ChiaTypes/PuzzleAnnouncement.cs +++ b/src/chia-dotnet/ChiaTypes/PuzzleAnnouncement.cs @@ -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; } } } diff --git a/src/chia-dotnet/ChiaTypes/TransactionRecord.cs b/src/chia-dotnet/ChiaTypes/TransactionRecord.cs index 188b4591..ad3f022f 100644 --- a/src/chia-dotnet/ChiaTypes/TransactionRecord.cs +++ b/src/chia-dotnet/ChiaTypes/TransactionRecord.cs @@ -46,5 +46,6 @@ public record TransactionRecord public uint WalletId { get; init; } [JsonIgnore] public DateTime CreatedAtDateTime => CreatedAtTime.ToDateTime(); + public ConditionValidTimes ValidTimes { get; init; } = new(); } } diff --git a/src/chia-dotnet/ChiaTypes/TransactionTypeFilter.cs b/src/chia-dotnet/ChiaTypes/TransactionTypeFilter.cs index 849624bc..e777b086 100644 --- a/src/chia-dotnet/ChiaTypes/TransactionTypeFilter.cs +++ b/src/chia-dotnet/ChiaTypes/TransactionTypeFilter.cs @@ -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 Values { get; init; } = new List(); + + public FilterMode Mode { get; init; } = FilterMode.Exlude; } } diff --git a/src/chia-dotnet/CrawlerProxy.cs b/src/chia-dotnet/CrawlerProxy.cs index 15af2cad..814f7878 100644 --- a/src/chia-dotnet/CrawlerProxy.cs +++ b/src/chia-dotnet/CrawlerProxy.cs @@ -9,17 +9,13 @@ namespace chia.dotnet /// /// Proxy that communicates with the crawler /// - public sealed class CrawlerProxy : ServiceProxy + /// + /// ctor + /// + /// instance to use for rpc communication + /// + public sealed class CrawlerProxy(IRpcClient rpcClient, string originService) : ServiceProxy(rpcClient, ServiceNames.Crawler, originService) { - /// - /// ctor - /// - /// instance to use for rpc communication - /// - public CrawlerProxy(IRpcClient rpcClient, string originService) - : base(rpcClient, ServiceNames.Crawler, originService) - { - } /// /// Retrieves aggregate information about peers diff --git a/src/chia-dotnet/DAOWallet.cs b/src/chia-dotnet/DAOWallet.cs index 46aa4796..933b1dfa 100644 --- a/src/chia-dotnet/DAOWallet.cs +++ b/src/chia-dotnet/DAOWallet.cs @@ -7,17 +7,13 @@ namespace chia.dotnet /// /// Wraps a DAO Wallet /// - public sealed class DAOWallet : Wallet + /// + /// ctor + /// + /// The wallet_id to wrap + /// Wallet RPC proxy to use for communication + public sealed class DAOWallet(uint walletId, WalletProxy walletProxy) : Wallet(walletId, walletProxy) { - /// - /// ctor - /// - /// The wallet_id to wrap - /// Wallet RPC proxy to use for communication - public DAOWallet(uint walletId, WalletProxy walletProxy) - : base(walletId, walletProxy) - { - } /// /// Validates that is a diff --git a/src/chia-dotnet/DIDWallet.cs b/src/chia-dotnet/DIDWallet.cs index 5ec5a4d5..02b7f10f 100644 --- a/src/chia-dotnet/DIDWallet.cs +++ b/src/chia-dotnet/DIDWallet.cs @@ -9,17 +9,13 @@ namespace chia.dotnet /// /// Wraps a Distributed Identity Wallet /// - public sealed class DIDWallet : Wallet + /// + /// ctor + /// + /// The wallet_id to wrap + /// Wallet RPC proxy to use for communication + public sealed class DIDWallet(uint walletId, WalletProxy walletProxy) : Wallet(walletId, walletProxy) { - /// - /// ctor - /// - /// The wallet_id to wrap - /// Wallet RPC proxy to use for communication - public DIDWallet(uint walletId, WalletProxy walletProxy) - : base(walletId, walletProxy) - { - } /// /// Validates that is a @@ -40,10 +36,7 @@ public override async Task Validate(CancellationToken cancellationToken = defaul /// An awaitable public async Task UpdateRecoveryIds(IEnumerable 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(); @@ -62,10 +55,7 @@ public async Task UpdateRecoveryIds(IEnumerable newList, ulong? numVerif /// An awaitable public async Task UpdateRecoveryIds(IEnumerable 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(); @@ -212,10 +202,7 @@ public async Task UpdateMetadata(string metadata, bool? reusePuzhas /// An awaitable public async Task RecoverySpend(IEnumerable 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(); diff --git a/src/chia-dotnet/DaemonProxy.cs b/src/chia-dotnet/DaemonProxy.cs index 24d63dcf..95ca5051 100644 --- a/src/chia-dotnet/DaemonProxy.cs +++ b/src/chia-dotnet/DaemonProxy.cs @@ -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 and having it's own procedures /// - public sealed class DaemonProxy : ServiceProxy + /// + /// ctor + /// + /// instance to use for rpc communication + /// + public sealed class DaemonProxy(WebSocketRpcClient rpcClient, string originService) : ServiceProxy(rpcClient, ServiceNames.Daemon, originService) { - /// - /// ctor - /// - /// instance to use for rpc communication - /// - public DaemonProxy(WebSocketRpcClient rpcClient, string originService) - : base(rpcClient, ServiceNames.Daemon, originService) - { - } /// /// Sends ping message to the service @@ -42,7 +38,7 @@ public async Task Ping(CancellationToken cancellationToken = default) /// This only works for daemons because they can forward messages to other services through their public T CreateProxyFrom() 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; diff --git a/src/chia-dotnet/DataLayerProxy.cs b/src/chia-dotnet/DataLayerProxy.cs index b1ce9bc8..4482982d 100644 --- a/src/chia-dotnet/DataLayerProxy.cs +++ b/src/chia-dotnet/DataLayerProxy.cs @@ -10,17 +10,13 @@ namespace chia.dotnet /// /// Proxy that communicates with the Data Layer /// - public sealed class DataLayerProxy : ServiceProxy + /// + /// ctor + /// + /// instance to use for rpc communication + /// + public sealed class DataLayerProxy(IRpcClient rpcClient, string originService) : ServiceProxy(rpcClient, ServiceNames.DataLayer, originService) { - /// - /// ctor - /// - /// instance to use for rpc communication - /// - public DataLayerProxy(IRpcClient rpcClient, string originService) - : base(rpcClient, ServiceNames.DataLayer, originService) - { - } /// /// Adds a mirror diff --git a/src/chia-dotnet/DataLayerWallet.cs b/src/chia-dotnet/DataLayerWallet.cs index ba3afc40..cb64b9fc 100644 --- a/src/chia-dotnet/DataLayerWallet.cs +++ b/src/chia-dotnet/DataLayerWallet.cs @@ -9,17 +9,13 @@ namespace chia.dotnet /// /// Wraps a Data Layer Wallet /// - public sealed class DataLayerWallet : Wallet + /// + /// ctor + /// + /// The wallet_id to wrap + /// Wallet RPC proxy to use for communication + public sealed class DataLayerWallet(uint walletId, WalletProxy walletProxy) : Wallet(walletId, walletProxy) { - /// - /// ctor - /// - /// The wallet_id to wrap - /// Wallet RPC proxy to use for communication - public DataLayerWallet(uint walletId, WalletProxy walletProxy) - : base(walletId, walletProxy) - { - } /// /// Validates that is a diff --git a/src/chia-dotnet/FarmerProxy.cs b/src/chia-dotnet/FarmerProxy.cs index f44aad2f..a9948440 100644 --- a/src/chia-dotnet/FarmerProxy.cs +++ b/src/chia-dotnet/FarmerProxy.cs @@ -10,17 +10,13 @@ namespace chia.dotnet /// /// Proxy that communicates with the farmer /// - public sealed class FarmerProxy : ServiceProxy + /// + /// ctor + /// + /// instance to use for rpc communication + /// + public sealed class FarmerProxy(IRpcClient rpcClient, string originService) : ServiceProxy(rpcClient, ServiceNames.Farmer, originService) { - /// - /// ctor - /// - /// instance to use for rpc communication - /// - public FarmerProxy(IRpcClient rpcClient, string originService) - : base(rpcClient, ServiceNames.Farmer, originService) - { - } /// /// Get the farm and pool reward targets @@ -56,7 +52,7 @@ public FarmerProxy(IRpcClient rpcClient, string originService) /// The farm and pool reward targets 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); } /// diff --git a/src/chia-dotnet/FullNodeProxy.cs b/src/chia-dotnet/FullNodeProxy.cs index 2dbba089..c8d94a21 100644 --- a/src/chia-dotnet/FullNodeProxy.cs +++ b/src/chia-dotnet/FullNodeProxy.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Dynamic; using System.Linq; -using System.Numerics; using System.Threading; using System.Threading.Tasks; using Newtonsoft.Json; @@ -286,10 +285,7 @@ public async Task> GetCoinRecordsByPuzzleHash(string puz /// A list of s public async Task> GetCoinRecordsByNames(IEnumerable names, bool includeSpentCoins, uint? startHeight = null, uint? endHeight = null, CancellationToken cancellationToken = default) { - if (names is null) - { - throw new ArgumentNullException(nameof(names)); - } + ArgumentNullException.ThrowIfNull(names); dynamic data = new ExpandoObject(); data.names = names.ToList(); @@ -311,10 +307,7 @@ public async Task> GetCoinRecordsByNames(IEnumerableA list of s public async Task> GetCoinRecordsByPuzzleHashes(IEnumerable puzzlehashes, bool includeSpentCoins, uint? startHeight = null, uint? endHeight = null, CancellationToken cancellationToken = default) { - if (puzzlehashes is null) - { - throw new ArgumentNullException(nameof(puzzlehashes)); - } + ArgumentNullException.ThrowIfNull(puzzlehashes); dynamic data = new ExpandoObject(); data.puzzle_hashes = puzzlehashes.ToList(); @@ -337,10 +330,7 @@ public async Task> GetCoinRecordsByPuzzleHashes(IEnumera /// A list of s public async Task> GetCoinRecordsByParentIds(IEnumerable parentIds, bool includeSpentCoins, uint? startHeight = null, uint? endHeight = null, CancellationToken cancellationToken = default) { - if (parentIds is null) - { - throw new ArgumentNullException(nameof(parentIds)); - } + ArgumentNullException.ThrowIfNull(parentIds); dynamic data = new ExpandoObject(); data.parent_ids = parentIds.ToList(); @@ -531,10 +521,7 @@ public async Task GetNetworkSpace(string newerBlockHeaderhash, string o /// Indicator of whether the spend bundle was successfully included in the mempool public async Task PushTx(SpendBundle spendBundle, CancellationToken cancellationToken = default) { - if (spendBundle is null) - { - throw new ArgumentNullException(nameof(spendBundle)); - } + ArgumentNullException.ThrowIfNull(spendBundle); dynamic data = new ExpandoObject(); data.spend_bundle = spendBundle; diff --git a/src/chia-dotnet/HarvesterProxy.cs b/src/chia-dotnet/HarvesterProxy.cs index 0f119dbd..c7702491 100644 --- a/src/chia-dotnet/HarvesterProxy.cs +++ b/src/chia-dotnet/HarvesterProxy.cs @@ -9,17 +9,13 @@ namespace chia.dotnet /// /// Proxy that communicates with the harvester /// - public sealed class HarvesterProxy : ServiceProxy + /// + /// ctor + /// + /// instance to use for rpc communication + /// + public sealed class HarvesterProxy(IRpcClient rpcClient, string originService) : ServiceProxy(rpcClient, ServiceNames.Harvester, originService) { - /// - /// ctor - /// - /// instance to use for rpc communication - /// - public HarvesterProxy(IRpcClient rpcClient, string originService) - : base(rpcClient, ServiceNames.Harvester, originService) - { - } /// /// Gets harvester configuration. diff --git a/src/chia-dotnet/NFTWallet.cs b/src/chia-dotnet/NFTWallet.cs index 5a20ddeb..3ab9a91b 100644 --- a/src/chia-dotnet/NFTWallet.cs +++ b/src/chia-dotnet/NFTWallet.cs @@ -8,17 +8,13 @@ namespace chia.dotnet /// /// Wraps an NFT wallet /// - public sealed class NFTWallet : Wallet + /// + /// ctor + /// + /// The wallet_id to wrap + /// Wallet RPC proxy to use for communication + public sealed class NFTWallet(uint walletId, WalletProxy walletProxy) : Wallet(walletId, walletProxy) { - /// - /// ctor - /// - /// The wallet_id to wrap - /// Wallet RPC proxy to use for communication - public NFTWallet(uint walletId, WalletProxy walletProxy) - : base(walletId, walletProxy) - { - } /// /// Validates that is a diff --git a/src/chia-dotnet/PlotterProxy.cs b/src/chia-dotnet/PlotterProxy.cs index f11d1cc4..3fc3ab1d 100644 --- a/src/chia-dotnet/PlotterProxy.cs +++ b/src/chia-dotnet/PlotterProxy.cs @@ -10,18 +10,14 @@ namespace chia.dotnet /// /// Class to manage plotting /// - public sealed class PlotterProxy : ServiceProxy + /// + /// ctor + /// + /// instance to use for rpc communication + /// + /// The daemon endpoint handles plotting commands, so the rpc client has to us a websocket client and dameon endpoint + public sealed class PlotterProxy(WebSocketRpcClient rpcClient, string originService) : ServiceProxy(rpcClient, ServiceNames.Daemon, originService) { - /// - /// ctor - /// - /// instance to use for rpc communication - /// - /// The daemon endpoint handles plotting commands, so the rpc client has to us a websocket client and dameon endpoint - public PlotterProxy(WebSocketRpcClient rpcClient, string originService) - : base(rpcClient, ServiceNames.Daemon, originService) - { - } /// /// Registers this instance as a plotter and retreives the plot queue @@ -44,10 +40,7 @@ public async Task> RegisterPlotter(CancellationToken /// An awaitable public async Task> StartPlotting(PlotterConfig config, CancellationToken cancellationToken = default) { - if (config == null) - { - throw new ArgumentNullException(nameof(config)); - } + ArgumentNullException.ThrowIfNull(config); dynamic data = config.PrepareForSerialization(); return await SendMessage>("start_plotting", data, "ids", cancellationToken).ConfigureAwait(false); diff --git a/src/chia-dotnet/PoolWallet.cs b/src/chia-dotnet/PoolWallet.cs index 9cd87b6c..0135f4d2 100644 --- a/src/chia-dotnet/PoolWallet.cs +++ b/src/chia-dotnet/PoolWallet.cs @@ -8,17 +8,13 @@ namespace chia.dotnet /// /// Wraps a Pool Wallet /// - public sealed class PoolWallet : Wallet + /// + /// ctor + /// + /// The wallet_id to wrap + /// Wallet RPC proxy to use for communication + public sealed class PoolWallet(uint walletId, WalletProxy walletProxy) : Wallet(walletId, walletProxy) { - /// - /// ctor - /// - /// The wallet_id to wrap - /// Wallet RPC proxy to use for communication - public PoolWallet(uint walletId, WalletProxy walletProxy) - : base(walletId, walletProxy) - { - } /// /// Validates that is a diff --git a/src/chia-dotnet/ResponseException.cs b/src/chia-dotnet/ResponseException.cs index e6cba38f..693c66a8 100644 --- a/src/chia-dotnet/ResponseException.cs +++ b/src/chia-dotnet/ResponseException.cs @@ -6,7 +6,13 @@ namespace chia.dotnet /// Exception thrown when the RPC endpoint returns a response but Data.success is false /// oro there is a communication error on the websocket of http channgel /// - public sealed class ResponseException : Exception + /// + /// ctor + /// + /// The request sent to the service + /// + /// + public sealed class ResponseException(Message request, string message, Exception? innerException) : Exception(message, innerException) { /// /// ctor @@ -27,21 +33,9 @@ public ResponseException(Message request, string message) { } - /// - /// ctor - /// - /// The request sent to the service - /// - /// - public ResponseException(Message request, string message, Exception? innerException) - : base(message, innerException) - { - Request = request; - } - /// /// The request sent to the service /// - public Message Request { get; init; } + public Message Request { get; init; } = request; } } diff --git a/src/chia-dotnet/TradeManager.cs b/src/chia-dotnet/TradeManager.cs index 54137419..c48393d7 100644 --- a/src/chia-dotnet/TradeManager.cs +++ b/src/chia-dotnet/TradeManager.cs @@ -10,14 +10,9 @@ namespace chia.dotnet /// /// API wrapper for those wallet RPC methods dealing with trades and offers /// - public sealed class TradeManager + public sealed class TradeManager(WalletProxy walletProxy) { - public WalletProxy WalletProxy { get; init; } - - public TradeManager(WalletProxy walletProxy) - { - WalletProxy = walletProxy ?? throw new ArgumentNullException(nameof(walletProxy)); - } + public WalletProxy WalletProxy { get; init; } = walletProxy ?? throw new ArgumentNullException(nameof(walletProxy)); /// /// Retrieves the number of offers. @@ -271,10 +266,7 @@ public async Task GetOfferSummary(string offer, bool advanced = fa /// An awaitable public async Task CreateOffer(IDictionary walletIdsAndMojoAmounts, ulong minCoinAmount = 0, ulong maxCoinAmount = 0, bool validateOnly = false, IDictionary? driver = null, IDictionary? solver = null, bool? reusePuzhash = null, ulong fee = 0, CancellationToken cancellationToken = default) { - if (walletIdsAndMojoAmounts is null) - { - throw new ArgumentNullException(nameof(walletIdsAndMojoAmounts)); - } + ArgumentNullException.ThrowIfNull(walletIdsAndMojoAmounts); dynamic data = new ExpandoObject(); data.offer = walletIdsAndMojoAmounts; diff --git a/src/chia-dotnet/VerifiedCredentialManager.cs b/src/chia-dotnet/VerifiedCredentialManager.cs index 6024b838..ce52d866 100644 --- a/src/chia-dotnet/VerifiedCredentialManager.cs +++ b/src/chia-dotnet/VerifiedCredentialManager.cs @@ -9,14 +9,9 @@ namespace chia.dotnet /// /// API wrapper for those wallet RPC methods dealing with verified credentials /// - public sealed class VerifiedCredentialManager + public sealed class VerifiedCredentialManager(WalletProxy walletProxy) { - public WalletProxy WalletProxy { get; init; } - - public VerifiedCredentialManager(WalletProxy walletProxy) - { - WalletProxy = walletProxy ?? throw new ArgumentNullException(nameof(walletProxy)); - } + public WalletProxy WalletProxy { get; init; } = walletProxy ?? throw new ArgumentNullException(nameof(walletProxy)); /// /// Given a launcher ID get the verified credential. diff --git a/src/chia-dotnet/Wallet.cs b/src/chia-dotnet/Wallet.cs index 18422883..3c8deeac 100644 --- a/src/chia-dotnet/Wallet.cs +++ b/src/chia-dotnet/Wallet.cs @@ -11,28 +11,23 @@ namespace chia.dotnet /// Base class representing a specific wallet (i.e. anything with a WalletID) /// /// When not dervied from this represents a - public class Wallet + /// + /// ctor + /// + /// The wallet_id to wrap + /// Wallet RPC proxy to use for communication + public class Wallet(uint walletId, WalletProxy walletProxy) { - /// - /// ctor - /// - /// The wallet_id to wrap - /// Wallet RPC proxy to use for communication - public Wallet(uint walletId, WalletProxy walletProxy) - { - WalletId = walletId; - WalletProxy = walletProxy ?? throw new ArgumentNullException(nameof(walletProxy)); - } /// /// The id of the wallet /// - public uint WalletId { get; init; } + public uint WalletId { get; init; } = walletId; /// /// Wallet RPC proxy for communication /// - public WalletProxy WalletProxy { get; init; } + public WalletProxy WalletProxy { get; init; } = walletProxy ?? throw new ArgumentNullException(nameof(walletProxy)); /// /// Creates a dynamic object and sets its wallet_id property to @@ -294,10 +289,7 @@ public async Task SendTransaction(string address, /// The public async Task SendTransactionMulti(IEnumerable additions, IEnumerable? coins = null, ulong fee = 0, CancellationToken cancellationToken = default) { - if (additions is null) - { - throw new ArgumentNullException(nameof(additions)); - } + ArgumentNullException.ThrowIfNull(additions); dynamic data = CreateWalletDataObject(); data.additions = additions.ToList(); diff --git a/src/chia-dotnet/WalletProxy.cs b/src/chia-dotnet/WalletProxy.cs index f62ff973..677fe248 100644 --- a/src/chia-dotnet/WalletProxy.cs +++ b/src/chia-dotnet/WalletProxy.cs @@ -11,17 +11,13 @@ namespace chia.dotnet /// /// Proxy that communicates with the wallet endpoint /// - public sealed class WalletProxy : ServiceProxy + /// + /// ctor + /// + /// instance to use for rpc communication + /// + public sealed class WalletProxy(IRpcClient rpcClient, string originService) : ServiceProxy(rpcClient, ServiceNames.Wallet, originService) { - /// - /// ctor - /// - /// instance to use for rpc communication - /// - public WalletProxy(IRpcClient rpcClient, string originService) - : base(rpcClient, ServiceNames.Wallet, originService) - { - } /// /// Gets basic info about a pool that is used for pool wallet creation @@ -240,10 +236,7 @@ public async Task GetTransaction(string transactionId, Cancel /// Indicator of whether the spend bundle was successfully included in the mempool public async Task PushTx(SpendBundle spendBundle, CancellationToken cancellationToken = default) { - if (spendBundle is null) - { - throw new ArgumentNullException(nameof(spendBundle)); - } + ArgumentNullException.ThrowIfNull(spendBundle); dynamic data = new ExpandoObject(); data.spend_bundle = spendBundle; @@ -261,10 +254,7 @@ public async Task PushTx(SpendBundle spendBundle, CancellationToken cancel /// An awaitable task public async Task PushTransactions(IEnumerable transactions, CancellationToken cancellationToken = default) { - if (transactions is null) - { - throw new ArgumentNullException(nameof(transactions)); - } + ArgumentNullException.ThrowIfNull(transactions); dynamic data = new ExpandoObject(); data.transactions = transactions.ToList(); @@ -280,10 +270,7 @@ public async Task PushTransactions(IEnumerable transactions, /// The new key's fingerprint public async Task AddKey(IEnumerable mnemonic, CancellationToken cancellationToken = default) { - if (mnemonic is null) - { - throw new ArgumentNullException(nameof(mnemonic)); - } + ArgumentNullException.ThrowIfNull(mnemonic); dynamic data = new ExpandoObject(); data.mnemonic = mnemonic.ToList(); @@ -505,10 +492,7 @@ public async Task GetNFTInfo(string coinId, bool latest = true, bool ig /// Information about the wallet public async Task<(WalletType Type, string myDID, uint walletId)> CreateDIDWallet(IEnumerable backupDIDs, ulong numOfBackupIdsNeeded, string name, IDictionary? metaData = null, ulong fee = 0, CancellationToken cancellationToken = default) { - if (backupDIDs is null) - { - throw new ArgumentNullException(nameof(backupDIDs)); - } + ArgumentNullException.ThrowIfNull(backupDIDs); dynamic data = new ExpandoObject(); data.wallet_type = "did_wallet"; @@ -585,10 +569,7 @@ public async Task GetNFTInfo(string coinId, bool latest = true, bool ig public async Task<(TransactionRecord transaction, string launcherId, string p2SingletonHash)> CreatePoolWallet(PoolState initialTargetState, ulong? p2SingletonDelayTime = null, string? p2SingletonDelayedPH = null, CancellationToken cancellationToken = default) { - if (initialTargetState is null) - { - throw new ArgumentNullException(nameof(initialTargetState)); - } + ArgumentNullException.ThrowIfNull(initialTargetState); dynamic data = new ExpandoObject(); data.wallet_type = "pool_wallet"; @@ -657,10 +638,7 @@ public async Task GetNFTInfo(string coinId, bool latest = true, bool ig ulong fee = 0, CancellationToken cancellationToken = default) { - if (additions is null) - { - throw new ArgumentNullException(nameof(additions)); - } + ArgumentNullException.ThrowIfNull(additions); dynamic data = new ExpandoObject(); data.additions = additions.ToList(); @@ -695,19 +673,6 @@ public async Task GetNFTInfo(string coinId, bool latest = true, bool ig ); } - /// - /// Create but do not send a transaction - /// - /// Additions to the block chain - /// Fee amount (in units of mojos) - /// A token to allow the call to be cancelled - /// The signed - public async Task CreateSignedTransaction(IEnumerable additions, ulong fee = 0, CancellationToken cancellationToken = default) - { - return await CreateSignedTransaction(additions, fee: fee, cancellationToken).ConfigureAwait(false); - } - - /// /// Retrieves the coins for given coin IDs /// @@ -719,10 +684,7 @@ public async Task CreateSignedTransaction(IEnumerable a /// A list of s public async Task> GetCoinRecordsByNames(IEnumerable names, bool includeSpentCoins, uint? startHeight = null, uint? endHeight = null, CancellationToken cancellationToken = default) { - if (names is null) - { - throw new ArgumentNullException(nameof(names)); - } + ArgumentNullException.ThrowIfNull(names); dynamic data = new ExpandoObject(); data.names = names.ToList(); diff --git a/src/chia-dotnet/bech32/Bech32M.cs b/src/chia-dotnet/bech32/Bech32M.cs index 13be7240..ee93aaed 100644 --- a/src/chia-dotnet/bech32/Bech32M.cs +++ b/src/chia-dotnet/bech32/Bech32M.cs @@ -12,25 +12,20 @@ namespace chia.dotnet.bech32 /// Bech32M implementation for encoding addresses /// /// adapted from https://github.com/Playwo/ChiaRPC.Net/blob/master/ChiaRPC.Net/Utils/Bech32M.cs - public class Bech32M + /// + /// ctor + /// + /// Address prefix + public class Bech32M(string prefix = "xch") { /// /// Address prefix to use /// /// xch - public string AddressPrefix { get; init; } = "xch"; + public string AddressPrefix { get; init; } = prefix; private const string Charset = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"; private const int M = 0x2BC830A3; - private static readonly int[] Generator = new int[] { 0x3B6A57B2, 0x26508E6D, 0x1EA119FA, 0x3D4233DD, 0x2A1462B3 }; - - /// - /// ctor - /// - /// Address prefix - public Bech32M(string prefix = "xch") - { - AddressPrefix = prefix; - } + private static readonly int[] Generator = [0x3B6A57B2, 0x26508E6D, 0x1EA119FA, 0x3D4233DD, 0x2A1462B3]; /// /// Converts a puzzle hash to an address using @@ -199,7 +194,7 @@ private static string Encode(string hrp, List data) /// private static (string?, List?) Decode(string bech) { - if (bech.ToLower() != bech && bech.ToUpper() != bech) + if (!bech.Equals(bech, StringComparison.OrdinalIgnoreCase) && !bech.Equals(bech, StringComparison.OrdinalIgnoreCase)) { return (null, null); } @@ -213,7 +208,7 @@ private static (string?, List?) Decode(string bech) } bech = bech.ToLower(); - var lastOnePosition = bech.LastIndexOf("1"); + var lastOnePosition = bech.LastIndexOf('1'); if (lastOnePosition < 1 || lastOnePosition + 7 > bech.Length || bech.Length > 90) { diff --git a/src/chia-dotnet/bech32/HexBytes.cs b/src/chia-dotnet/bech32/HexBytes.cs index e38ae1b9..d6df6ab1 100644 --- a/src/chia-dotnet/bech32/HexBytes.cs +++ b/src/chia-dotnet/bech32/HexBytes.cs @@ -8,34 +8,28 @@ namespace chia.dotnet.bech32 /// Utility to perform operations on an array of bytes and represent them as a Hex string /// /// adapted from https://github.com/Playwo/ChiaRPC.Net/blob/master/ChiaRPC.Net/Utils/Bech32M.cs - public readonly struct HexBytes + /// + /// ctor + /// + /// + /// + public readonly struct HexBytes(string hex, byte[] bytes) { /// /// hex string representation /// - public string Hex { get; init; } + public string Hex { get; init; } = hex ?? string.Empty; /// /// The array of bytes /// - public byte[] Bytes { get; init; } + public byte[] Bytes { get; init; } = bytes ?? []; /// /// FLag indicating that the array is empty /// public bool IsEmpty => string.IsNullOrWhiteSpace(Hex); - /// - /// ctor - /// - /// - /// - public HexBytes(string hex, byte[] bytes) - { - Hex = hex ?? string.Empty; - Bytes = bytes ?? Array.Empty(); - } - /// /// SHA256 encoded copy /// @@ -50,7 +44,7 @@ public HexBytes Sha256() public override bool Equals(object? obj) { - return obj is HexBytes other && Hex.ToUpperInvariant() == other.Hex.ToUpperInvariant(); + return obj is HexBytes other && Hex.Equals(other.Hex, StringComparison.OrdinalIgnoreCase); } public override int GetHashCode() @@ -91,12 +85,12 @@ public override string ToString() public static bool operator ==(HexBytes a, HexBytes b) { - return a.Hex.ToUpperInvariant() == b.Hex.ToUpperInvariant(); + return a.Hex.Equals(b.Hex, StringComparison.OrdinalIgnoreCase); } public static bool operator !=(HexBytes a, HexBytes b) { - return a.Hex.ToUpperInvariant() != b.Hex.ToUpperInvariant(); + return !a.Hex.Equals(b.Hex, StringComparison.OrdinalIgnoreCase); } public static HexBytes FromHex(string hex) @@ -136,6 +130,6 @@ public static HexBytes FromBytes(byte[] bytes) /// /// /// - public static HexBytes Empty => new(string.Empty, Array.Empty()); + public static HexBytes Empty => new(string.Empty, []); } }