From fddb3f7cb7dc026f77adb6ec8f8becfceb54d217 Mon Sep 17 00:00:00 2001 From: Don Kackman Date: Fri, 27 Aug 2021 14:54:15 -0500 Subject: [PATCH] add GetCoinRecrodsBy names and parent ids --- src/chia-dotnet.tests/FullNodeProxyTests.cs | 2 +- src/chia-dotnet/FullNodeProxy.cs | 102 ++++++++++++++++---- 2 files changed, 83 insertions(+), 21 deletions(-) diff --git a/src/chia-dotnet.tests/FullNodeProxyTests.cs b/src/chia-dotnet.tests/FullNodeProxyTests.cs index 205f0934..9734bc05 100644 --- a/src/chia-dotnet.tests/FullNodeProxyTests.cs +++ b/src/chia-dotnet.tests/FullNodeProxyTests.cs @@ -170,7 +170,7 @@ public async Task GetCoinRecordsByPuzzleHash() var state = await _theFullNode.GetBlockchainState(cts.Token); Assert.IsNotNull(state.Peak, "peak not retreived yet"); - var records = await _theFullNode.GetCoinRecordsByPuzzleHash(state.Peak.FarmerPuzzleHash, true, cts.Token); + var records = await _theFullNode.GetCoinRecordsByPuzzleHash(state.Peak.FarmerPuzzleHash, true, null, null, cts.Token); Assert.IsNotNull(records); } diff --git a/src/chia-dotnet/FullNodeProxy.cs b/src/chia-dotnet/FullNodeProxy.cs index 1099711d..f07c650e 100644 --- a/src/chia-dotnet/FullNodeProxy.cs +++ b/src/chia-dotnet/FullNodeProxy.cs @@ -130,13 +130,15 @@ public async Task> GetUnfinishedBlockHeaders( } /// - /// Retrieves the coins for a given puzzlehash, by default returns unspent coins. + /// Retrieves the coins for a given puzzlehash /// + /// whether to include spent coins too, instead of just unspent /// The puzzle hash - /// whether to include spent coins too, instead of just unspent + /// confirmation start height for search + /// confirmation end height for search /// /// A list of s - public async Task> GetCoinRecordsByPuzzleHash(string puzzlehash, bool includeSpendCoins, CancellationToken cancellationToken = default) + public async Task> GetCoinRecordsByPuzzleHash(string puzzlehash, bool includeSpentCoins, int? startHeight, int? endHeight, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(puzzlehash)) { @@ -145,46 +147,64 @@ public async Task> GetCoinRecordsByPuzzleHash(string puz dynamic data = new ExpandoObject(); data.puzzle_hash = puzzlehash; - data.include_spend_coins = includeSpendCoins; + data.include_spent_coins = includeSpentCoins; + + if (startHeight.HasValue) + { + data.start_height = startHeight.Value; + } + + if (endHeight.HasValue) + { + data.end_height = endHeight.Value; + } return await SendMessage>("get_coin_records_by_puzzle_hash", data, "coin_records", cancellationToken); } /// - /// Retrieves the coins for a given puzzlehash, by default returns unspent coins. + /// Retrieves the coins for given coin IDs /// - /// The puzzle hash + /// The coin names + /// Flag indicating whether to include spent coins or not /// confirmation start height for search /// confirmation end height for search - /// whether to include spent coins too, instead of just unspent /// /// A list of s - public async Task> GetCoinRecordsByPuzzleHash(string puzzlehash, uint startHeight, uint endHeight, bool includeSpendCoins, CancellationToken cancellationToken = default) + public async Task> GetCoinRecordsByNames(IEnumerable names, bool includeSpentCoins, int? startHeight = null, int? endHeight = null, CancellationToken cancellationToken = default) { - if (string.IsNullOrEmpty(puzzlehash)) + if (names is null) { - throw new ArgumentNullException(nameof(puzzlehash)); + throw new ArgumentNullException(nameof(names)); } dynamic data = new ExpandoObject(); - data.puzzle_hash = puzzlehash; - data.start_height = startHeight; - data.end_height = endHeight; - data.include_spend_coins = includeSpendCoins; + data.names = names.ToList(); + data.include_spent_coins = includeSpentCoins; - return await SendMessage>("get_coin_records_by_puzzle_hash", data, "coin_records", cancellationToken); + if (startHeight.HasValue) + { + data.start_height = startHeight.Value; + } + + if (endHeight.HasValue) + { + data.end_height = endHeight.Value; + } + + return await SendMessage>("get_coin_records_by_names", data, "coin_records", cancellationToken); } /// /// Retrieves the coins for a given list of puzzlehashes, by default returns unspent coins. /// /// The list of puzzle hashes + /// whether to include spent coins too, instead of just unspent /// confirmation start height for search /// confirmation end height for search - /// whether to include spent coins too, instead of just unspent /// /// A list of s - public async Task> GetCoinRecordsByPuzzleHashes(IEnumerable puzzlehashes, uint startHeight, uint endHeight, bool includeSpendCoins, CancellationToken cancellationToken = default) + public async Task> GetCoinRecordsByPuzzleHashes(IEnumerable puzzlehashes, bool includeSpentCoins, int? startHeight, int? endHeight, CancellationToken cancellationToken = default) { if (puzzlehashes is null) { @@ -193,13 +213,55 @@ public async Task> GetCoinRecordsByPuzzleHashes(IEnumera dynamic data = new ExpandoObject(); data.puzzle_hash = puzzlehashes.ToList(); - data.start_height = startHeight; - data.end_height = endHeight; - data.include_spend_coins = includeSpendCoins; + data.include_spent_coins = includeSpentCoins; + + if (startHeight.HasValue) + { + data.start_height = startHeight.Value; + } + + if (endHeight.HasValue) + { + data.end_height = endHeight.Value; + } return await SendMessage>("get_coin_records_by_puzzle_hashes", data, "coin_records", cancellationToken); } + + /// + /// Retrieves the coins for a given list of parent ids + /// + /// The list of parent ids hashes + /// whether to include spent coins too, instead of just unspent + /// confirmation start height for search + /// confirmation end height for search + /// + /// A list of s + public async Task> GetCoinRecordsByParentIds(IEnumerable parentIds, bool includeSpentCoins, int? startHeight, int? endHeight, CancellationToken cancellationToken = default) + { + if (parentIds is null) + { + throw new ArgumentNullException(nameof(parentIds)); + } + + dynamic data = new ExpandoObject(); + data.parent_ids = parentIds.ToList(); + data.include_spent_coins = includeSpentCoins; + + if (startHeight.HasValue) + { + data.start_height = startHeight.Value; + } + + if (endHeight.HasValue) + { + data.end_height = endHeight.Value; + } + + return await SendMessage>("get_coin_records_by_parent_ids", data, "coin_records", cancellationToken); + } + /// /// Retrieves a coin record by its name/id. ///