diff --git a/CHANGES.md b/CHANGES.md index cc1ee9cce74..38c3b0f218f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -29,6 +29,8 @@ To be released. to `IReadOnlyList`. [[#3949]] - (Libplanet.Net) Changed `ActionExecutionState` and `BlockVerificationState` to be `Obsolete`. [[#3943]] + - (Libplanet.Action) Export `IPolicyActionsRegistry` interface + from `PolicyActionsRegistry`. [[#3960]] ### Backward-incompatible network protocol changes @@ -66,6 +68,7 @@ To be released. [#3948]: https://github.com/planetarium/libplanet/pull/3948 [#3949]: https://github.com/planetarium/libplanet/pull/3949 [#3950]: https://github.com/planetarium/libplanet/pull/3950 +[#3960]: https://github.com/planetarium/libplanet/pull/3960 Version 5.2.2 diff --git a/src/Libplanet.Action/ActionEvaluator.cs b/src/Libplanet.Action/ActionEvaluator.cs index 8d6eda0bbb7..a27967b4ac4 100644 --- a/src/Libplanet.Action/ActionEvaluator.cs +++ b/src/Libplanet.Action/ActionEvaluator.cs @@ -24,7 +24,7 @@ namespace Libplanet.Action public class ActionEvaluator : IActionEvaluator { private readonly ILogger _logger; - private readonly PolicyActionsRegistry _policyActionsRegistry; + private readonly IPolicyActionsRegistry _policyActionsRegistry; private readonly IStateStore _stateStore; private readonly IActionLoader _actionLoader; @@ -40,7 +40,7 @@ public class ActionEvaluator : IActionEvaluator /// A implementation using /// action type lookup. public ActionEvaluator( - PolicyActionsRegistry policyActionsRegistry, + IPolicyActionsRegistry policyActionsRegistry, IStateStore stateStore, IActionLoader actionTypeLoader) { diff --git a/src/Libplanet.Action/IPolicyActionsRegistry.cs b/src/Libplanet.Action/IPolicyActionsRegistry.cs new file mode 100644 index 00000000000..545340d41d0 --- /dev/null +++ b/src/Libplanet.Action/IPolicyActionsRegistry.cs @@ -0,0 +1,36 @@ +using System.Collections.Immutable; + +namespace Libplanet.Action +{ + public interface IPolicyActionsRegistry + { + /// + /// An array of to execute and be rendered at the beginning + /// for every block, if any. + ImmutableArray BeginBlockActions + { + get; + } + /// + /// An array of to execute and be rendered at the end + /// for every block, if any. + ImmutableArray EndBlockActions + { + get; + } + /// + /// An array of to execute and be rendered at the beginning + /// for every transaction, if any. + ImmutableArray BeginTxActions + { + get; + } + /// + /// An array of to execute and be rendered at the end + /// for every transaction, if any. + ImmutableArray EndTxActions + { + get; + } + } +} diff --git a/src/Libplanet.Action/PolicyActionsRegistry.cs b/src/Libplanet.Action/PolicyActionsRegistry.cs index e9793899bd6..fb25d957127 100644 --- a/src/Libplanet.Action/PolicyActionsRegistry.cs +++ b/src/Libplanet.Action/PolicyActionsRegistry.cs @@ -4,7 +4,7 @@ namespace Libplanet.Action { - public class PolicyActionsRegistry + public class PolicyActionsRegistry : IPolicyActionsRegistry { /// /// A class containing policy actions to evaluate at each situation. diff --git a/src/Libplanet/Blockchain/Policies/BlockPolicy.cs b/src/Libplanet/Blockchain/Policies/BlockPolicy.cs index 63366847532..63b1f24196a 100644 --- a/src/Libplanet/Blockchain/Policies/BlockPolicy.cs +++ b/src/Libplanet/Blockchain/Policies/BlockPolicy.cs @@ -22,7 +22,7 @@ public class BlockPolicy : IBlockPolicy private readonly Func _validateNextBlock; - private readonly PolicyActionsRegistry _policyActionsRegistry; + private readonly IPolicyActionsRegistry _policyActionsRegistry; private readonly Func _getMaxTransactionsBytes; private readonly Func _getMinTransactionsPerBlock; private readonly Func _getMaxTransactionsPerBlock; @@ -73,7 +73,7 @@ public class BlockPolicy : IBlockPolicy /// Goes to . Set to a constant function /// of 10 by default. public BlockPolicy( - PolicyActionsRegistry? policyActionsRegistry = null, + IPolicyActionsRegistry? policyActionsRegistry = null, TimeSpan? blockInterval = null, Func? validateNextBlockTx = null, @@ -169,7 +169,7 @@ public BlockPolicy( } } - public PolicyActionsRegistry PolicyActionsRegistry => _policyActionsRegistry; + public IPolicyActionsRegistry PolicyActionsRegistry => _policyActionsRegistry; /// /// Targeted time interval between two consecutive s. diff --git a/src/Libplanet/Blockchain/Policies/IBlockPolicy.cs b/src/Libplanet/Blockchain/Policies/IBlockPolicy.cs index 7de700e2680..ba97914b349 100644 --- a/src/Libplanet/Blockchain/Policies/IBlockPolicy.cs +++ b/src/Libplanet/Blockchain/Policies/IBlockPolicy.cs @@ -24,7 +24,7 @@ public interface IBlockPolicy /// /// A set of policy s to evaluate at each situation. /// - PolicyActionsRegistry PolicyActionsRegistry { get; } + IPolicyActionsRegistry PolicyActionsRegistry { get; } /// /// Checks if a can be included in a yet to be mined diff --git a/src/Libplanet/Blockchain/Policies/NullBlockPolicy.cs b/src/Libplanet/Blockchain/Policies/NullBlockPolicy.cs index 8e679648b36..19a28fea5d4 100644 --- a/src/Libplanet/Blockchain/Policies/NullBlockPolicy.cs +++ b/src/Libplanet/Blockchain/Policies/NullBlockPolicy.cs @@ -21,7 +21,7 @@ public NullBlockPolicy( public ISet
BlockedMiners { get; } = new HashSet
(); - public PolicyActionsRegistry PolicyActionsRegistry => new PolicyActionsRegistry(); + public IPolicyActionsRegistry PolicyActionsRegistry => new PolicyActionsRegistry(); public ImmutableArray BeginBlockActions => ImmutableArray.Empty; diff --git a/test/Libplanet.RocksDBStore.Tests/RocksDBStoreBlockChainTest.cs b/test/Libplanet.RocksDBStore.Tests/RocksDBStoreBlockChainTest.cs index 56936ac6b81..531c19a09c9 100644 --- a/test/Libplanet.RocksDBStore.Tests/RocksDBStoreBlockChainTest.cs +++ b/test/Libplanet.RocksDBStore.Tests/RocksDBStoreBlockChainTest.cs @@ -15,7 +15,7 @@ public RocksDBStoreBlockChainTest(ITestOutputHelper output) } protected override StoreFixture GetStoreFixture( - PolicyActionsRegistry policyActionsRegistry = null) + IPolicyActionsRegistry policyActionsRegistry = null) { try { diff --git a/test/Libplanet.RocksDBStore.Tests/RocksDBStoreFixture.cs b/test/Libplanet.RocksDBStore.Tests/RocksDBStoreFixture.cs index 3cebd2c96a6..d3f8771086d 100644 --- a/test/Libplanet.RocksDBStore.Tests/RocksDBStoreFixture.cs +++ b/test/Libplanet.RocksDBStore.Tests/RocksDBStoreFixture.cs @@ -10,7 +10,7 @@ namespace Libplanet.RocksDBStore.Tests public class RocksDBStoreFixture : StoreFixture { public RocksDBStoreFixture( - PolicyActionsRegistry policyActionsRegistry = null) + IPolicyActionsRegistry policyActionsRegistry = null) : base(policyActionsRegistry) { Path = System.IO.Path.Combine( diff --git a/test/Libplanet.Tests/Blockchain/BlockChainTest.cs b/test/Libplanet.Tests/Blockchain/BlockChainTest.cs index fdcc14c771f..852c98ca30c 100644 --- a/test/Libplanet.Tests/Blockchain/BlockChainTest.cs +++ b/test/Libplanet.Tests/Blockchain/BlockChainTest.cs @@ -1294,7 +1294,7 @@ void BuildIndex(Guid id, Block block) /// The policy block actions to use. /// The store fixture that every test in this class depends on. protected virtual StoreFixture GetStoreFixture( - PolicyActionsRegistry policyActionsRegistry = null) + IPolicyActionsRegistry policyActionsRegistry = null) => new MemoryStoreFixture(policyActionsRegistry); private (Address[], Transaction[]) MakeFixturesForAppendTests( diff --git a/test/Libplanet.Tests/Blockchain/DefaultStoreBlockChainTest.cs b/test/Libplanet.Tests/Blockchain/DefaultStoreBlockChainTest.cs index 928fb755172..d078cbb6cdc 100644 --- a/test/Libplanet.Tests/Blockchain/DefaultStoreBlockChainTest.cs +++ b/test/Libplanet.Tests/Blockchain/DefaultStoreBlockChainTest.cs @@ -12,7 +12,7 @@ public DefaultStoreBlockChainTest(ITestOutputHelper output) } protected override StoreFixture GetStoreFixture( - PolicyActionsRegistry policyActionsRegistry = null) => + IPolicyActionsRegistry policyActionsRegistry = null) => new DefaultStoreFixture(policyActionsRegistry: policyActionsRegistry); } } diff --git a/test/Libplanet.Tests/Store/DefaultStoreFixture.cs b/test/Libplanet.Tests/Store/DefaultStoreFixture.cs index 882bd6b4fb6..04a95ae4e38 100644 --- a/test/Libplanet.Tests/Store/DefaultStoreFixture.cs +++ b/test/Libplanet.Tests/Store/DefaultStoreFixture.cs @@ -10,7 +10,7 @@ public class DefaultStoreFixture : StoreFixture, IDisposable { public DefaultStoreFixture( bool memory = true, - PolicyActionsRegistry policyActionsRegistry = null) + IPolicyActionsRegistry policyActionsRegistry = null) : base(policyActionsRegistry) { if (memory) diff --git a/test/Libplanet.Tests/Store/MemoryStoreFixture.cs b/test/Libplanet.Tests/Store/MemoryStoreFixture.cs index 59b5908d8c3..2481f127be8 100644 --- a/test/Libplanet.Tests/Store/MemoryStoreFixture.cs +++ b/test/Libplanet.Tests/Store/MemoryStoreFixture.cs @@ -7,7 +7,7 @@ namespace Libplanet.Tests.Store public class MemoryStoreFixture : StoreFixture { public MemoryStoreFixture( - PolicyActionsRegistry policyActionsRegistry = null) + IPolicyActionsRegistry policyActionsRegistry = null) : base(policyActionsRegistry) { Store = new MemoryStore(); diff --git a/test/Libplanet.Tests/Store/StoreFixture.cs b/test/Libplanet.Tests/Store/StoreFixture.cs index 0c480826495..6f5f9d21b5c 100644 --- a/test/Libplanet.Tests/Store/StoreFixture.cs +++ b/test/Libplanet.Tests/Store/StoreFixture.cs @@ -17,7 +17,7 @@ namespace Libplanet.Tests.Store { public abstract class StoreFixture : IDisposable { - protected StoreFixture(PolicyActionsRegistry policyActionsRegistry = null) + protected StoreFixture(IPolicyActionsRegistry policyActionsRegistry = null) { Path = null; diff --git a/tools/Libplanet.Explorer.Cocona/Libplanet.Explorer.Cocona.csproj b/tools/Libplanet.Explorer.Cocona/Libplanet.Explorer.Cocona.csproj index a27ab87a0b5..81a82a9e0f4 100644 --- a/tools/Libplanet.Explorer.Cocona/Libplanet.Explorer.Cocona.csproj +++ b/tools/Libplanet.Explorer.Cocona/Libplanet.Explorer.Cocona.csproj @@ -8,7 +8,6 @@ - diff --git a/tools/Libplanet.Explorer.Executable/Program.cs b/tools/Libplanet.Explorer.Executable/Program.cs index 2c852312405..d3c2126f30a 100644 --- a/tools/Libplanet.Explorer.Executable/Program.cs +++ b/tools/Libplanet.Explorer.Executable/Program.cs @@ -378,7 +378,7 @@ public DumbBlockPolicy(BlockPolicy blockPolicy) _impl = blockPolicy; } - public PolicyActionsRegistry PolicyActionsRegistry => _impl.PolicyActionsRegistry; + public IPolicyActionsRegistry PolicyActionsRegistry => _impl.PolicyActionsRegistry; public int GetMinTransactionsPerBlock(long index) => _impl.GetMinTransactionsPerBlock(index);