public void LoadSpace() { using var reader = new StateReader(Store); using var logger = new LoggingStateReader(reader, TextWriter.Null); Space.Load(logger); }
public async Task Can_ask_about_storage_in_parallel() { StorageCell storageCell = new StorageCell(_address1, UInt256.One); IReleaseSpec spec = MuirGlacier.Instance; MemDb stateDb = new MemDb(); TrieStore trieStore = new TrieStore(stateDb, Logger); StateProvider provider = new StateProvider(trieStore, new MemDb(), Logger); StorageProvider storageProvider = new StorageProvider(trieStore, provider, Logger); void UpdateStorageValue(byte[] newValue) { storageProvider.Set(storageCell, newValue); } void AddOneToBalance() { provider.AddToBalance(_address1, 1, spec); } void CommitEverything() { storageProvider.Commit(); storageProvider.CommitTrees(0); provider.Commit(spec); provider.CommitTree(0); } provider.CreateAccount(_address1, 1); CommitEverything(); AddOneToBalance(); UpdateStorageValue(new byte[] { 1 }); CommitEverything(); Keccak stateRoot0 = provider.StateRoot; AddOneToBalance(); UpdateStorageValue(new byte[] { 2 }); CommitEverything(); Keccak stateRoot1 = provider.StateRoot; AddOneToBalance(); UpdateStorageValue(new byte[] { 3 }); CommitEverything(); Keccak stateRoot2 = provider.StateRoot; AddOneToBalance(); UpdateStorageValue(new byte[] { 4 }); CommitEverything(); Keccak stateRoot3 = provider.StateRoot; StateReader reader = new StateReader(new TrieStore(stateDb, LimboLogs.Instance), Substitute.For <IDb>(), Logger); Task a = StartStorageTask(reader, stateRoot0, storageCell, new byte[] { 1 }); Task b = StartStorageTask(reader, stateRoot1, storageCell, new byte[] { 2 }); Task c = StartStorageTask(reader, stateRoot2, storageCell, new byte[] { 3 }); Task d = StartStorageTask(reader, stateRoot3, storageCell, new byte[] { 4 }); await Task.WhenAll(a, b, c, d); }
public static INdmBlockchainBridge BuildABridge() { IDbProvider memDbProvider = TestMemDbProvider.Init(); StateReader stateReader = new StateReader(memDbProvider.StateDb, memDbProvider.CodeDb, LimboLogs.Instance); StateProvider stateProvider = new StateProvider(memDbProvider.StateDb, memDbProvider.CodeDb, LimboLogs.Instance); IEthereumEcdsa ecdsa = new EthereumEcdsa(ChainId.Mainnet, LimboLogs.Instance); ITxPool txPool = new TxPool.TxPool(new InMemoryTxStorage(), ecdsa, MainnetSpecProvider.Instance, new TxPoolConfig(), stateProvider, LimboLogs.Instance); BlockTree blockTree = Build.A.BlockTree().OfChainLength(1).TestObject; IWallet wallet = new DevWallet(new WalletConfig(), LimboLogs.Instance); ReceiptsRecovery receiptsRecovery = new ReceiptsRecovery(ecdsa, MainnetSpecProvider.Instance); LogFinder logFinder = new LogFinder(blockTree, new InMemoryReceiptStorage(), NullBloomStorage.Instance, LimboLogs.Instance, receiptsRecovery, 1024); ReadOnlyTxProcessingEnv processingEnv = new ReadOnlyTxProcessingEnv( new ReadOnlyDbProvider(memDbProvider, false), new ReadOnlyBlockTree(blockTree), MainnetSpecProvider.Instance, LimboLogs.Instance); BlockchainBridge blockchainBridge = new BlockchainBridge( processingEnv, txPool, new InMemoryReceiptStorage(), NullFilterStore.Instance, NullFilterManager.Instance, ecdsa, Timestamper.Default, logFinder, false, false); WalletTxSigner txSigner = new WalletTxSigner(wallet, ChainId.Mainnet); ITxSealer txSealer0 = new TxSealer(txSigner, Timestamper.Default); ITxSealer txSealer1 = new NonceReservingTxSealer(txSigner, Timestamper.Default, txPool); ITxSender txSender = new TxPoolSender(txPool, txSealer0, txSealer1); return(new NdmBlockchainBridge(blockchainBridge, blockTree, stateReader, txSender)); }
public void GlobalSetup() { ISnapshotableDb codeDb = new StateDb(); ISnapshotableDb stateDb = new StateDb(); IDb blockInfoDb = new MemDb(10, 5); ISpecProvider specProvider = MainNetSpecProvider.Instance; IReleaseSpec spec = MainNetSpecProvider.Instance.GenesisSpec; StateProvider stateProvider = new StateProvider(stateDb, codeDb, LimboLogs.Instance); stateProvider.CreateAccount(Address.Zero, 1000.Ether()); stateProvider.Commit(spec); StorageProvider storageProvider = new StorageProvider(stateDb, stateProvider, LimboLogs.Instance); StateReader stateReader = new StateReader(stateDb, codeDb, LimboLogs.Instance); ChainLevelInfoRepository chainLevelInfoRepository = new ChainLevelInfoRepository(blockInfoDb); BlockTree blockTree = new BlockTree(new MemDb(), new MemDb(), blockInfoDb, chainLevelInfoRepository, specProvider, NullTxPool.Instance, LimboLogs.Instance); _blockhashProvider = new BlockhashProvider(blockTree, LimboLogs.Instance); _virtualMachine = new VirtualMachine(stateProvider, storageProvider, _blockhashProvider, specProvider, LimboLogs.Instance); Block genesisBlock = Build.A.Block.Genesis.TestObject; blockTree.SuggestBlock(genesisBlock); Block block1 = Build.A.Block.WithParent(genesisBlock).WithNumber(1).TestObject; blockTree.SuggestBlock(block1); TransactionProcessor transactionProcessor = new TransactionProcessor(MainNetSpecProvider.Instance, stateProvider, storageProvider, _virtualMachine, LimboLogs.Instance); BlockProcessor blockProcessor = new BlockProcessor(specProvider, AlwaysValidBlockValidator.Instance, new RewardCalculator(specProvider), transactionProcessor, stateDb, codeDb, new MemDb(), stateProvider, storageProvider, NullTxPool.Instance, NullReceiptStorage.Instance, LimboLogs.Instance); BlockchainProcessor blockchainProcessor = new BlockchainProcessor( blockTree, blockProcessor, new TxSignaturesRecoveryStep(new EthereumEcdsa(specProvider, LimboLogs.Instance), NullTxPool.Instance, LimboLogs.Instance), LimboLogs.Instance, false, false); blockchainProcessor.Process(genesisBlock, ProcessingOptions.None, NullBlockTracer.Instance); blockchainProcessor.Process(block1, ProcessingOptions.None, NullBlockTracer.Instance); BlockchainBridge bridge = new BlockchainBridge( stateReader, stateProvider, storageProvider, blockTree, NullTxPool.Instance, NullReceiptStorage.Instance, NullFilterStore.Instance, NullFilterManager.Instance, new DevWallet(new WalletConfig(), LimboLogs.Instance), transactionProcessor, new EthereumEcdsa(MainNetSpecProvider.Instance, LimboLogs.Instance)); _ethModule = new EthModule(LimboLogs.Instance, bridge); }
public static GameState GetGameState(FileSystemEntry entry, Game game) { using (var stream = entry.Open()) { var reader = new StateReader(stream, game); while (true) { var chunkName = ""; reader.PersistAsciiString(ref chunkName); reader.BeginSegment(chunkName); if (chunkName == "CHUNK_GameState") { var gameState = new GameState(); gameState.Persist(reader); return(gameState); } reader.EndSegment(); } } throw new InvalidStateException(); }
/// <summary> /// This method fetches a 'List<State>' object. /// This method uses the 'States_FetchAll' procedure. /// </summary> /// <returns>A 'List<State>'</returns> /// </summary> public List <State> FetchAllStates(FetchAllStatesStoredProcedure fetchAllStatesProc, DataConnector databaseConnector) { // Initial Value List <State> stateCollection = null; // Verify database connection is connected if ((databaseConnector != null) && (databaseConnector.Connected)) { // First Get Dataset DataSet allStatesDataSet = this.DataHelper.LoadDataSet(fetchAllStatesProc, databaseConnector); // Verify DataSet Exists if (allStatesDataSet != null) { // Get DataTable From DataSet DataTable table = this.DataHelper.ReturnFirstTable(allStatesDataSet); // if table exists if (table != null) { // Load Collection stateCollection = StateReader.LoadCollection(table); } } } // return value return(stateCollection); }
/// <summary> /// This method finds a 'State' object. /// This method uses the 'State_Find' procedure. /// </summary> /// <returns>A 'State' object.</returns> /// </summary> public State FindState(FindStateStoredProcedure findStateProc, DataConnector databaseConnector) { // Initial Value State state = null; // Verify database connection is connected if ((databaseConnector != null) && (databaseConnector.Connected)) { // First Get Dataset DataSet stateDataSet = this.DataHelper.LoadDataSet(findStateProc, databaseConnector); // Verify DataSet Exists if (stateDataSet != null) { // Get DataTable From DataSet DataRow row = this.DataHelper.ReturnFirstRow(stateDataSet); // if row exists if (row != null) { // Load State state = StateReader.Load(row); } } } // return value return(state); }
private bool VerifyReceivingScripts() { foreach (UInt160 hash in Outputs.Select(p => p.ScriptHash).Distinct()) { ContractState contract = Blockchain.Default.GetContract(hash); if (contract == null) { continue; } using (StateReader service = new StateReader()) { ApplicationEngine engine = new ApplicationEngine(TriggerType.VerificationR, this, Blockchain.Default, service, Fixed8.Zero); engine.LoadScript(contract.Script, false); using (ScriptBuilder sb = new ScriptBuilder()) { sb.EmitPush(0); sb.Emit(OpCode.PACK); sb.EmitPush("receiving"); engine.LoadScript(sb.ToArray(), false); } if (!engine.Execute()) { return(false); } if (engine.EvaluationStack.Count != 1 || !engine.EvaluationStack.Pop().GetBoolean()) { return(false); } } } return(true); }
protected void AddTransformRecords() { EnqueueRecords( StateReader.GetChangedTransFormRecordsWithTag( "Character", _lastPos, _lastRot, _lastScale )); }
public Task Execute(CancellationToken cancellationToken) { ILogger logger = _api.LogManager.GetClassLogger(); IInitConfig initConfig = _api.Config <IInitConfig>(); switch (initConfig.DiagnosticMode) { case DiagnosticMode.VerifySupply: { logger.Info("Genesis supply:"); SupplyVerifier supplyVerifier = new SupplyVerifier(logger); StateDb stateDb = new StateDb(_api.DbProvider !.StateDb.Innermost); StateDb codeDb = new StateDb(_api.DbProvider.StateDb.Innermost); StateReader stateReader = new StateReader(stateDb, codeDb, _api.LogManager); stateReader.RunTreeVisitor(supplyVerifier, _api.BlockTree !.Genesis.StateRoot); Block head = _api.BlockTree !.Head; logger.Info($"Head ({head.Number}) block supply:"); supplyVerifier = new SupplyVerifier(logger); stateReader.RunTreeVisitor(supplyVerifier, head.StateRoot); break; } case DiagnosticMode.VerifyRewards: _api.BlockTree !.Accept(new RewardsVerifier(_api.LogManager), cancellationToken); break; } return(Task.CompletedTask); }
public ReadOnlyTxProcessingEnv( IReadOnlyDbProvider?readOnlyDbProvider, IReadOnlyTrieStore?readOnlyTrieStore, IReadOnlyBlockTree?readOnlyBlockTree, ISpecProvider?specProvider, ILogManager?logManager) { if (specProvider == null) { throw new ArgumentNullException(nameof(specProvider)); } DbProvider = readOnlyDbProvider ?? throw new ArgumentNullException(nameof(readOnlyDbProvider)); _codeDb = readOnlyDbProvider.CodeDb.AsReadOnly(true); StateReader = new StateReader(readOnlyTrieStore, _codeDb, logManager); StateProvider = new StateProvider(readOnlyTrieStore, _codeDb, logManager); StorageProvider = new StorageProvider(readOnlyTrieStore, StateProvider, logManager); IWorldState worldState = new WorldState(StateProvider, StorageProvider); BlockTree = readOnlyBlockTree ?? throw new ArgumentNullException(nameof(readOnlyBlockTree)); BlockhashProvider = new BlockhashProvider(BlockTree, logManager); Machine = new VirtualMachine(BlockhashProvider, specProvider, logManager); TransactionProcessor = new TransactionProcessor(specProvider, worldState, Machine, logManager); }
public void Non_existing() { StorageCell storageCell = new StorageCell(_address1, UInt256.One); IReleaseSpec spec = MuirGlacier.Instance; MemDb stateDb = new MemDb(); TrieStore trieStore = new TrieStore(stateDb, Logger); StateProvider provider = new StateProvider(trieStore, new MemDb(), Logger); StorageProvider storageProvider = new StorageProvider(trieStore, provider, Logger); void CommitEverything() { storageProvider.Commit(); storageProvider.CommitTrees(0); provider.Commit(spec); provider.CommitTree(0); } provider.CreateAccount(_address1, 1); storageProvider.Set(storageCell, new byte[] { 1 }); CommitEverything(); Keccak stateRoot0 = provider.StateRoot; StateReader reader = new StateReader(new TrieStore(stateDb, LimboLogs.Instance), Substitute.For <IDb>(), Logger); Keccak storageRoot = reader.GetStorageRoot(stateRoot0, _address1); reader.GetStorage(storageRoot, storageCell.Index + 1).Should().BeEquivalentTo(new byte[] { 0 }); reader.GetStorage(Keccak.EmptyTreeHash, storageCell.Index + 1).Should().BeEquivalentTo(new byte[] { 0 }); }
public CssResolver() { rsComment = ReadComment; rsStyleName = ReadStyleName; rsPropertyName = ReadPropertyName; rsPropertyText = ReadPropertyText; rsStyleText = ReadStyleText; }
public void ExtractData_HasName() { var reader = new StateReader(); var states = reader.ExtractData(FileText); states.ShouldNotContain(s => string.IsNullOrEmpty(s.Name)); }
public DelimitedFieldEnumerator(StreamReader reader, ParserSettings settings) { _reader = reader; _buffer = new char[1024]; _length = 0; INITIAL_STATE = new InitialState(settings.FieldDelimiter, settings.TextQualifier); _currentState = INITIAL_STATE; }
public void ExtractData_RejectedEmptyTransitions() { var reader = new StateReader(); var rejected = reader.ExtractData(FileText) .Single(m => m.Name.Equals("Rejected")); rejected.Transitions.ShouldBeEmpty(); }
public void ExtractData_ValidAcceptedAssignToExpression() { var reader = new StateReader(); var accepted = reader.ExtractData(FileText) .Single(m => m.Name.Equals("Accepted")); accepted.AssignToExpression.ShouldBe("return null;"); }
public void ExtractData_ValidInitialAssignToExpression() { var reader = new StateReader(); var initial = reader.ExtractData(FileText) .Single(m => m.Name.Equals("Initial")); initial.AssignToExpression.ShouldBe("return null;"); }
public void ExtractData_ValidInitialHasBehaviours() { var reader = new StateReader(); var initial = reader.ExtractData(FileText) .Single(m => m.Name.Equals("Initial")); initial.Behaviours.Count.ShouldBe(2); }
public void ExtractData_InitialHasDraftTransition() { var reader = new StateReader(); var initial = reader.ExtractData(FileText) .Single(m => m.Name.Equals("Initial")); initial.Transitions.ShouldContain(t => t.Name.Equals("Draft")); }
public void ExtractData_Successfully() { var reader = new StateReader(); var states = reader.ExtractData(FileText); states.ShouldNotBeNull(); states.Count.ShouldBe(3); }
protected void AddGroundrecord() { IRecord rec = StateReader.GetGroundRecord(_lastGroundSize); if (rec != null) { Pending.Enqueue(rec); } }
public void ExtractData_InitialHasTransitions() { var reader = new StateReader(); var initial = reader.ExtractData(FileText) .Single(m => m.Name.Equals("Initial")); initial.Transitions.ShouldNotBeEmpty(); initial.Transitions.Count.ShouldBe(3); }
public void ExtractData_ValidInitialBehaviourOut() { var reader = new StateReader(); var initial = reader.ExtractData(FileText) .Single(m => m.Name.Equals("Initial")); initial.Behaviours.ShouldContain(b => b.Name.Equals("OnInitialOut") && b.Type.Equals("Out")); initial.Behaviours.Single(b => b.Name.Equals("OnInitialOut")).Expression.ShouldBe("this._name = \"Initial Out Name\";"); }
private static IPruningContext CopyDb(IPruningContext pruningContext, MemDb trieDb, MemDb clonedDb) { LimboLogs logManager = LimboLogs.Instance; PatriciaTree trie = Build.A.Trie(trieDb).WithAccountsByIndex(0, 100).TestObject; IStateReader stateReader = new StateReader(new TrieStore(trieDb, logManager), new MemDb(), logManager); using CopyTreeVisitor copyTreeVisitor = new(pruningContext, logManager); stateReader.RunTreeVisitor(copyTreeVisitor, trie.RootHash); return(pruningContext); }
public void ExtractData_ValidConfirmExpression() { var reader = new StateReader(); var confirm = reader.ExtractData(FileText) .Single(m => m.Name.Equals("Initial")) .Transitions.Single(t => t.Name.Equals("Confirm")); confirm.Expression.ShouldBe("var test = \"tst\";\r\n\t\t\tthis._name = \"Confirmation\";\r\n\t\t\treturn true;"); }
public void ExtractData_ValidDraftExpression() { var reader = new StateReader(); var draft = reader.ExtractData(FileText) .Single(m => m.Name.Equals("Initial")) .Transitions.Single(t => t.Name.Equals("Draft")); draft.Expression.ShouldBe("return true;"); }
public void Reset() { if (_reader.BaseStream.CanSeek) { _reader.BaseStream.Seek(0, SeekOrigin.Begin); _currentState = INITIAL_STATE; _length = 0; _buffer = new char[1024]; } }
public void ReadDelimiterCharTest() { char[] buffer = new char[1]; int bufferPosition = 0; DelimiterState target = new DelimiterState(',', new EndState()); StateReader resultState = target.ReadChar(',', ref buffer, ref bufferPosition); Assert.AreNotEqual(',', buffer[0]); Assert.IsTrue(resultState is EndState); }
public void PositiveReadTest() { char[] buffer = new char[1]; int bufferPosition = 0; InitialState returnToState = new InitialState(',', '"'); EndNewLinePatternState target = new EndNewLinePatternState('\n', returnToState); StateReader actualNextState = target.ReadChar((int)'\n', ref buffer, ref bufferPosition); Assert.ReferenceEquals(target, actualNextState); }
private List <StateTree> GenerateStateTreesFromFile(string filename) { List <State> lst_states = StateReader.ReadStatesFromFile(filename); List <StateTree> lst_statetrees = new List <StateTree>(); foreach (State s in lst_states) { lst_statetrees.Add(new StateTree(s)); } return(lst_statetrees); }
/// <summary> /// Reset context variables /// </summary> public void Reset() { this.Styles.Clear(); this.styleName.Clear(); this.properties.Clear(); this.propertyName.Clear(); this.propertyText.Clear(); this.PreviousState = null; this.successDetector = null; IgnoreSpace = true; IgnoreProperty = false; IsComment = false; position = 0; propertyTextPosition = 0; styleLineNumber = 1; lineNumber = 1; }