コード例 #1
0
 public IValue GetState(
     string stateKey,
     HashDigest <SHA256>?blockHash = null,
     Guid?chainId = null)
 {
     Log(nameof(GetState), stateKey, blockHash, chainId);
     return(_stateStore.GetState(stateKey, blockHash, chainId));
 }
コード例 #2
0
ファイル: TestUtils.cs プロジェクト: Chaleeshadow/libplanet
        public static Block <T> AttachStateRootHash <T>(
            this Block <T> block, IStateStore stateStore, IAction blockAction)
            where T : IAction, new()
        {
            IValue StateGetter(
                Address address, HashDigest <SHA256>?blockHash, StateCompleter <T> stateCompleter) =>
            blockHash is null
                    ? null
                    : stateStore.GetState(ToStateKey(address), blockHash.Value);

            FungibleAssetValue FungibleAssetValueGetter(
                Address address,
                Currency currency,
                HashDigest <SHA256>?blockHash,
                FungibleAssetStateCompleter <T> stateCompleter)
            {
                if (blockHash is null)
                {
                    return(FungibleAssetValue.FromRawValue(currency, 0));
                }

                IValue value = stateStore.GetState(
                    ToFungibleAssetKey(address, currency), blockHash.Value);

                return(FungibleAssetValue.FromRawValue(
                           currency,
                           value is Bencodex.Types.Integer i ? i.Value : 0));
            }

            var blockEvaluator = new BlockEvaluator <T>(
                blockAction, StateGetter, FungibleAssetValueGetter, null);
            var actionEvaluationResult = blockEvaluator
                                         .EvaluateActions(block, StateCompleterSet <T> .Reject)
                                         .GetTotalDelta(ToStateKey, ToFungibleAssetKey);

            stateStore.SetStates(block, actionEvaluationResult);
            if (stateStore is TrieStateStore trieStateStore)
            {
                block = new Block <T>(block, trieStateStore.GetRootHash(block.Hash));
                stateStore.SetStates(block, actionEvaluationResult);
            }

            return(block);
        }
コード例 #3
0
        public void RestoreState_WhenStateStoreReturnsNull_ShouldNotReturnNull()
        {
            IStateStore        stateStore = Substitute.For <IStateStore>();
            IStateStoreService svc        = new StateStoreService(stateStore);

            stateStore.GetState().ReturnsNull();

            MaintenanceState state = svc.GetState();

            state.ShouldNotBeNull();
        }
コード例 #4
0
        private void RestoreState()
        {
            StorableMaintenanceState restored = _stateStore.GetState();

            if (restored != null)
            {
                OptionCollection restoredOptions = null;
                if (restored.MiddlewareOptions != null)
                {
                    restoredOptions = new OptionCollection(
                        restored.MiddlewareOptions
                        .Select(o => RestoreOption(o)));
                }

                _state = new MaintenanceState(restored.ExpirationDate,
                                              restored.IsMaintenanceOn,
                                              restoredOptions);
            }
            else
            {
                _state = new MaintenanceState();
            }
        }