示例#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
        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();
        }
        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();
            }
        }