diff --git a/CHANGES.md b/CHANGES.md index d473bc3cf8f..020ec8e1091 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,10 +15,15 @@ To be released. now one can choose its representation format. [[#3560]] - (Libplanet.Explorer) Added `HelperQuery`, a collection of utility like queries. [[#3561]] + - (Libplanet.Explorer) Removed `IRichStore.StoreUpdatedAddressReferences()` + and `IterateUpdatedAddressReferences()` interface methods. [[#3562]] + - (Libplanet.Explorer) Removed `involvedAddress` argument from all + `TransactionQuery` query methods. [[#3562]] [#3559]: https://github.com/planetarium/libplanet/pull/3559 [#3560]: https://github.com/planetarium/libplanet/pull/3560 [#3561]: https://github.com/planetarium/libplanet/pull/3561 +[#3562]: https://github.com/planetarium/libplanet/pull/3562 Version 3.9.2 diff --git a/Libplanet.Explorer.Tests/Queries/TransactionQueryGeneratedTest.cs b/Libplanet.Explorer.Tests/Queries/TransactionQueryGeneratedTest.cs index 93d8a4d42b3..329eec61cea 100644 --- a/Libplanet.Explorer.Tests/Queries/TransactionQueryGeneratedTest.cs +++ b/Libplanet.Explorer.Tests/Queries/TransactionQueryGeneratedTest.cs @@ -112,100 +112,88 @@ private async Task AssertTransactionsQueryPermutation( Address? involvedAddress) { await AssertAgainstTransactionsQuery( - blocksToTest, signer, involvedAddress, false, null, null); + blocksToTest, signer, false, null, null); await AssertAgainstTransactionsQuery( - blocksToTest, signer, involvedAddress, true, null, null); + blocksToTest, signer, true, null, null); await AssertAgainstTransactionsQuery( - blocksToTest, signer, involvedAddress, false, blocksToTest.Length / 4, null); + blocksToTest, signer, false, blocksToTest.Length / 4, null); await AssertAgainstTransactionsQuery( blocksToTest, signer, - involvedAddress, false, blocksToTest.Length / 4 - blocksToTest.Length, null); Assert.Equal>( await ExecuteTransactionsQueryAsync( - signer, involvedAddress, false, blocksToTest.Length / 4, null), + signer, false, blocksToTest.Length / 4, null), await ExecuteTransactionsQueryAsync( signer, - involvedAddress, false, blocksToTest.Length / 4 - blocksToTest.Length, null)); await AssertAgainstTransactionsQuery( - blocksToTest, signer, involvedAddress, true, blocksToTest.Length / 4, null); + blocksToTest, signer, true, blocksToTest.Length / 4, null); await AssertAgainstTransactionsQuery( blocksToTest, signer, - involvedAddress, true, blocksToTest.Length / 4 - blocksToTest.Length, null); Assert.Equal>( await ExecuteTransactionsQueryAsync( - signer, involvedAddress, true, blocksToTest.Length / 4, null), + signer, true, blocksToTest.Length / 4, null), await ExecuteTransactionsQueryAsync( signer, - involvedAddress, true, blocksToTest.Length / 4 - blocksToTest.Length, null)); await AssertAgainstTransactionsQuery( - blocksToTest, signer, involvedAddress, false, null, blocksToTest.Length / 4); + blocksToTest, signer, false, null, blocksToTest.Length / 4); await AssertAgainstTransactionsQuery( - blocksToTest, signer, involvedAddress, true, null, blocksToTest.Length / 4); + blocksToTest, signer, true, null, blocksToTest.Length / 4); await AssertAgainstTransactionsQuery( blocksToTest, signer, - involvedAddress, false, blocksToTest.Length / 3, blocksToTest.Length / 4); await AssertAgainstTransactionsQuery( blocksToTest, signer, - involvedAddress, false, blocksToTest.Length / 3 - blocksToTest.Length, blocksToTest.Length / 4); Assert.Equal>( await ExecuteTransactionsQueryAsync( signer, - involvedAddress, false, blocksToTest.Length / 3, blocksToTest.Length / 4), await ExecuteTransactionsQueryAsync( signer, - involvedAddress, false, blocksToTest.Length / 3 - blocksToTest.Length, blocksToTest.Length / 4)); await AssertAgainstTransactionsQuery( blocksToTest, signer, - involvedAddress, true, blocksToTest.Length / 3, blocksToTest.Length / 4); await AssertAgainstTransactionsQuery( blocksToTest, signer, - involvedAddress, true, blocksToTest.Length / 3 - blocksToTest.Length, blocksToTest.Length / 4); Assert.Equal>( await ExecuteTransactionsQueryAsync( signer, - involvedAddress, true, blocksToTest.Length / 3, blocksToTest.Length / 4), await ExecuteTransactionsQueryAsync( signer, - involvedAddress, true, blocksToTest.Length / 3 - blocksToTest.Length, blocksToTest.Length / 4)); @@ -214,7 +202,6 @@ await ExecuteTransactionsQueryAsync( private async Task AssertAgainstTransactionsQuery( IReadOnlyList blocksToTest, Address? signer, - Address? involvedAddress, bool desc, int? offset, int? limit) @@ -237,10 +224,6 @@ private async Task AssertAgainstTransactionsQuery( { txs = txs.Where(tx => tx.Signer.Equals(signerVal)); } - else if (involvedAddress is { } involvedAddressVal) - { - txs = txs.Where(tx => tx.UpdatedAddresses.Contains(involvedAddressVal)); - } if (limit is { } limitVal) { @@ -249,7 +232,7 @@ private async Task AssertAgainstTransactionsQuery( var expected = txs.ToImmutableArray(); var actual = - await ExecuteTransactionsQueryAsync(signer, involvedAddress, desc, offset, limit); + await ExecuteTransactionsQueryAsync(signer, desc, offset, limit); foreach (var i in Enumerable.Range(0, actual.Length)) { @@ -269,7 +252,6 @@ await Source.Index.GetContainedBlockHashByTxIdAsync(expected[i].Id) private async Task> ExecuteTransactionsQueryAsync( Address? signer, - Address? involvedAddress, bool desc, int? offset, int? limit) @@ -278,7 +260,6 @@ await Source.Index.GetContainedBlockHashByTxIdAsync(expected[i].Id) {{ transactions( {(signer is { } signerVal ? @$"signer: ""{signerVal}""" : "")} - {(involvedAddress is { } invVal ? @$"involvedAddress: ""{invVal}""" : "")} desc: {(desc ? "true" : "false")} offset: {offset?.ToString(CultureInfo.InvariantCulture) ?? "0"} {(limit is { } limitVal ? $"limit: {limitVal}" : "")} diff --git a/Libplanet.Explorer/Queries/ExplorerQuery.cs b/Libplanet.Explorer/Queries/ExplorerQuery.cs index bf210edcae7..c2bad992b30 100644 --- a/Libplanet.Explorer/Queries/ExplorerQuery.cs +++ b/Libplanet.Explorer/Queries/ExplorerQuery.cs @@ -97,7 +97,7 @@ internal static IEnumerable ListBlocks( } internal static IEnumerable ListTransactions( - Address? signer, Address? involved, bool desc, long offset, int? limit) + Address? signer, bool desc, long offset, int? limit) { Block tip = Chain.Tip; long tipIndex = tip.Index; @@ -121,12 +121,6 @@ internal static IEnumerable ListTransactions( .IterateSignerReferences( (Address)signer, desc, (int)offset, limit ?? int.MaxValue); } - else if (!(involved is null)) - { - txIds = richStore - .IterateUpdatedAddressReferences( - (Address)involved, desc, (int)offset, limit ?? int.MaxValue); - } else { txIds = richStore @@ -149,7 +143,7 @@ internal static IEnumerable ListTransactions( { foreach (var tx in desc ? block.Transactions.Reverse() : block.Transactions) { - if (IsValidTransaction(tx, signer, involved)) + if (IsValidTransaction(tx, signer)) { yield return tx; limit--; @@ -165,7 +159,7 @@ internal static IEnumerable ListTransactions( } internal static IEnumerable ListStagedTransactions( - Address? signer, Address? involved, bool desc, int offset, int? limit) + Address? signer, bool desc, int offset, int? limit) { if (offset < 0) { @@ -175,7 +169,7 @@ internal static IEnumerable ListStagedTransactions( } var stagedTxs = Chain.StagePolicy.Iterate(Chain) - .Where(tx => IsValidTransaction(tx, signer, involved)) + .Where(tx => IsValidTransaction(tx, signer)) .Skip(offset); stagedTxs = desc ? stagedTxs.OrderByDescending(tx => tx.Timestamp) @@ -208,19 +202,13 @@ private static Block GetNextBlock(Block block, bool desc) private static bool IsValidTransaction( Transaction tx, - Address? signer, - Address? involved) + Address? signer) { if (signer is { } signerVal) { return tx.Signer.Equals(signerVal); } - if (involved is { } involvedVal) - { - return tx.UpdatedAddresses.Contains(involvedVal); - } - return true; } } diff --git a/Libplanet.Explorer/Queries/TransactionQuery.cs b/Libplanet.Explorer/Queries/TransactionQuery.cs index 5d3c3abf166..0d4ee3a4944 100644 --- a/Libplanet.Explorer/Queries/TransactionQuery.cs +++ b/Libplanet.Explorer/Queries/TransactionQuery.cs @@ -36,11 +36,6 @@ public TransactionQuery(IBlockChainContext context) Name = "signer", DefaultValue = null, }, - new QueryArgument - { - Name = "involvedAddress", - DefaultValue = null, - }, new QueryArgument { Name = "desc", @@ -56,12 +51,11 @@ public TransactionQuery(IBlockChainContext context) resolve: context => { var signer = context.GetArgument("signer"); - var involved = context.GetArgument("involvedAddress"); bool desc = context.GetArgument("desc"); long offset = context.GetArgument("offset"); int? limit = context.GetArgument("limit"); - return ExplorerQuery.ListTransactions(signer, involved, desc, offset, limit); + return ExplorerQuery.ListTransactions(signer, desc, offset, limit); } ); @@ -73,11 +67,6 @@ public TransactionQuery(IBlockChainContext context) Name = "signer", DefaultValue = null, }, - new QueryArgument - { - Name = "involvedAddress", - DefaultValue = null, - }, new QueryArgument { Name = "desc", @@ -93,14 +82,12 @@ public TransactionQuery(IBlockChainContext context) resolve: context => { var signer = context.GetArgument("signer"); - var involved = context.GetArgument("involvedAddress"); bool desc = context.GetArgument("desc"); int offset = context.GetArgument("offset"); int? limit = context.GetArgument("limit", null); return ExplorerQuery.ListStagedTransactions( signer, - involved, desc, offset, limit diff --git a/Libplanet.Explorer/Store/IRichStore.cs b/Libplanet.Explorer/Store/IRichStore.cs index 495fe97a87b..d84fc936093 100644 --- a/Libplanet.Explorer/Store/IRichStore.cs +++ b/Libplanet.Explorer/Store/IRichStore.cs @@ -24,16 +24,5 @@ IEnumerable IterateSignerReferences( bool desc, int offset = 0, int limit = int.MaxValue); - - void StoreUpdatedAddressReferences( - TxId txId, - long txNonce, - Address updatedAddress); - - IEnumerable IterateUpdatedAddressReferences( - Address updatedAddress, - bool desc, - int offset = 0, - int limit = int.MaxValue); } } diff --git a/Libplanet.Explorer/Store/LiteDBRichStore.cs b/Libplanet.Explorer/Store/LiteDBRichStore.cs index f2001263837..3e0f21151f0 100644 --- a/Libplanet.Explorer/Store/LiteDBRichStore.cs +++ b/Libplanet.Explorer/Store/LiteDBRichStore.cs @@ -19,7 +19,6 @@ public class LiteDBRichStore : IRichStore { private const string TxRefCollectionName = "block_ref"; private const string SignerRefCollectionName = "signer_ref"; - private const string UpdatedAddressRefCollectionName = "updated_address_ref"; private readonly MemoryStream _memoryStream; private readonly LiteDatabase _db; @@ -298,10 +297,6 @@ public void PutTransaction(Transaction tx) { _store.PutTransaction(tx); StoreSignerReferences(tx.Id, tx.Nonce, tx.Signer); - foreach (var updatedAddress in tx.UpdatedAddresses) - { - StoreUpdatedAddressReferences(tx.Id, tx.Nonce, updatedAddress); - } } public void StoreTxReferences(TxId txId, in BlockHash blockHash, long blockIndex) @@ -364,36 +359,6 @@ public IEnumerable IterateSignerReferences( return collection.Find(query, offset, limit).Select(doc => doc.TxId); } - public void StoreUpdatedAddressReferences( - TxId txId, - long txNonce, - Address updatedAddress) - { - var collection = UpdatedAddressRefCollection(); - collection.Upsert(new AddressRefDoc - { - Address = updatedAddress, TxNonce = txNonce, TxId = txId, - }); - collection.EnsureIndex(nameof(AddressRefDoc.AddressString)); - collection.EnsureIndex(nameof(AddressRefDoc.TxNonce)); - } - - public IEnumerable IterateUpdatedAddressReferences( - Address updatedAddress, - bool desc, - int offset = 0, - int limit = int.MaxValue) - { - var collection = UpdatedAddressRefCollection(); - var order = desc ? Query.Descending : Query.Ascending; - var addressString = updatedAddress.ToHex().ToLowerInvariant(); - var query = Query.And( - Query.All(nameof(AddressRefDoc.TxNonce), order), - Query.EQ(nameof(AddressRefDoc.AddressString), addressString) - ); - return collection.Find(query, offset, limit).Select(doc => doc.TxId); - } - public void Dispose() { if (!_disposed) @@ -410,8 +375,5 @@ private LiteCollection TxRefCollection() => private LiteCollection SignerRefCollection() => _db.GetCollection(SignerRefCollectionName); - - private LiteCollection UpdatedAddressRefCollection() => - _db.GetCollection(UpdatedAddressRefCollectionName); } } diff --git a/Libplanet.Explorer/Store/MySQLRichStore.cs b/Libplanet.Explorer/Store/MySQLRichStore.cs index e51cdf18555..671f7609cb4 100644 --- a/Libplanet.Explorer/Store/MySQLRichStore.cs +++ b/Libplanet.Explorer/Store/MySQLRichStore.cs @@ -20,7 +20,6 @@ public class MySQLRichStore : IRichStore { private const string TxRefDbName = "block_ref"; private const string SignerRefDbName = "signer_ref"; - private const string UpdatedAddressRefDbName = "updated_address_ref"; private readonly LruCache _blockCache; @@ -259,14 +258,6 @@ public void PutTransaction(Transaction tx) { _store.PutTransaction(tx); StoreSignerReferences(tx.Id, tx.Nonce, tx.Signer); - InsertMany( - "updated_address_references", - new[] { "updated_address", "tx_id", "tx_nonce" }, - tx.UpdatedAddresses.Select( - addr => new object[] - { - addr.ToByteArray(), tx.Id.ToByteArray(), tx.Nonce, - })); } public void StoreTxReferences(TxId txId, in BlockHash blockHash, long txNonce) @@ -326,37 +317,6 @@ public IEnumerable IterateSignerReferences( .Select(bytes => new TxId(bytes)); } - public void StoreUpdatedAddressReferences( - TxId txId, - long txNonce, - Address updatedAddress) - { - Insert("updated_address_references", new Dictionary - { - ["updated_address"] = updatedAddress.ToByteArray(), - ["tx_id"] = txId.ToByteArray(), - ["tx_nonce"] = txNonce, - }); - } - - public IEnumerable IterateUpdatedAddressReferences( - Address updatedAddress, - bool desc, - int offset = 0, - int limit = int.MaxValue) - { - using QueryFactory db = OpenDB(); - var query = db.Query("updated_address_references") - .Where("updated_address", updatedAddress.ToByteArray()) - .Offset(offset) - .Limit(limit) - .Select("tx_id"); - query = desc ? query.OrderByDesc("tx_nonce") : query.OrderBy("tx_nonce"); - return query.OrderBy("tx_nonce") - .Get() - .Select(bytes => new TxId(bytes)); - } - public void Dispose() { if (!_disposed)