diff --git a/Lib9c.Policy/AccessControlService/IAccessControlService.cs b/Lib9c.Policy/AccessControlService/IAccessControlService.cs new file mode 100644 index 0000000000..42e7dc1208 --- /dev/null +++ b/Lib9c.Policy/AccessControlService/IAccessControlService.cs @@ -0,0 +1,9 @@ +using Libplanet.Crypto; + +namespace Nekoyume.Blockchain +{ + public interface IAccessControlService + { + public int? GetTxQuota(Address address); + } +} diff --git a/Lib9c.Policy/NCStagePolicy.cs b/Lib9c.Policy/NCStagePolicy.cs new file mode 100644 index 0000000000..0dbd00c1f5 --- /dev/null +++ b/Lib9c.Policy/NCStagePolicy.cs @@ -0,0 +1,140 @@ +namespace Nekoyume.Blockchain +{ + using System; + using System.Collections.Concurrent; + using System.Collections.Generic; + using System.Collections.Immutable; + using System.Linq; + using Libplanet.Blockchain; + using Libplanet.Blockchain.Policies; + using Libplanet.Crypto; + using Libplanet.Types.Tx; + + public class NCStagePolicy : IStagePolicy + { + private readonly VolatileStagePolicy _impl; + private readonly ConcurrentDictionary
> _txs; + private readonly int _quotaPerSigner; + private IAccessControlService? _accessControlService; + + public NCStagePolicy(TimeSpan txLifeTime, int quotaPerSigner, IAccessControlService? accessControlService = null) + { + if (quotaPerSigner < 1) + { + throw new ArgumentOutOfRangeException( + $"{nameof(quotaPerSigner)} must be positive: ${quotaPerSigner}"); + } + + _txs = new ConcurrentDictionary>(); + _quotaPerSigner = quotaPerSigner; + _impl = (txLifeTime == default) + ? new VolatileStagePolicy() + : new VolatileStagePolicy(txLifeTime); + + _accessControlService = accessControlService; + } + + public Transaction Get(BlockChain blockChain, TxId id, bool filtered = true) + => _impl.Get(blockChain, id, filtered); + + public long GetNextTxNonce(BlockChain blockChain, Address address) + => _impl.GetNextTxNonce(blockChain, address); + + public void Ignore(BlockChain blockChain, TxId id) + => _impl.Ignore(blockChain, id); + + public bool Ignores(BlockChain blockChain, TxId id) + => _impl.Ignores(blockChain, id); + + public IEnumerable