internal static void LoadPlugins(CamSystem system) { System = system; if (!Directory.Exists(pluginsPath)) { return; } foreach (string filename in Directory.EnumerateFiles(pluginsPath, "*.dll", SearchOption.TopDirectoryOnly)) { var file = File.ReadAllBytes(filename); Assembly assembly = Assembly.Load(file); foreach (Type type in assembly.ExportedTypes) { if (!type.IsSubclassOf(typeof(Plugin))) { continue; } if (type.IsAbstract) { continue; } ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes); try { constructor?.Invoke(null); } catch (Exception ex) { Log(nameof(Plugin), LogLevel.Error, $"Failed to initialize plugin: {ex.Message}"); } } } }
public RemoteNode(CamSystem system, object connection, IPEndPoint remote, IPEndPoint local) : base(connection, remote, local) { this.system = system; this.protocol = Context.ActorOf(ProtocolHandler.Props(system)); LocalNode.Singleton.RemoteNodes.TryAdd(Self, this); SendMessage(Message.Create("version", VersionPayload.Create(LocalNode.Singleton.ListenerPort, LocalNode.Nonce, LocalNode.UserAgent, Blockchain.Singleton.Height))); }
public LocalNode(CamSystem system) { lock (lockObj) { if (singleton != null) { throw new InvalidOperationException(); } this.system = system; singleton = this; } }
public static CamSystem InitializeMockCamSystem() { if (TheCamSystem == null) { var mockSnapshot = new Mock <Snapshot>(); mockSnapshot.SetupGet(p => p.Blocks).Returns(new TestDataCache <UInt256, BlockState>()); mockSnapshot.SetupGet(p => p.Transactions).Returns(new TestDataCache <UInt256, TransactionState>()); mockSnapshot.SetupGet(p => p.Accounts).Returns(new TestDataCache <UInt160, AccountState>()); mockSnapshot.SetupGet(p => p.UnspentCoins).Returns(new TestDataCache <UInt256, UnspentCoinState>()); mockSnapshot.SetupGet(p => p.SpentCoins).Returns(new TestDataCache <UInt256, SpentCoinState>()); mockSnapshot.SetupGet(p => p.Validators).Returns(new TestDataCache <ECPoint, ValidatorState>()); mockSnapshot.SetupGet(p => p.Assets).Returns(new TestDataCache <UInt256, AssetState>()); mockSnapshot.SetupGet(p => p.Contracts).Returns(new TestDataCache <UInt160, ContractState>()); mockSnapshot.SetupGet(p => p.Storages).Returns(new TestDataCache <StorageKey, StorageItem>()); mockSnapshot.SetupGet(p => p.HeaderHashList) .Returns(new TestDataCache <UInt32Wrapper, HeaderHashList>()); mockSnapshot.SetupGet(p => p.ValidatorsCount).Returns(new TestMetaDataCache <ValidatorsCountState>()); mockSnapshot.SetupGet(p => p.BlockHashIndex).Returns(new TestMetaDataCache <HashIndexState>()); mockSnapshot.SetupGet(p => p.HeaderHashIndex).Returns(new TestMetaDataCache <HashIndexState>()); var mockStore = new Mock <Store>(); var defaultTx = TestUtils.CreateRandomHashInvocationMockTransaction().Object; mockStore.Setup(p => p.GetBlocks()).Returns(new TestDataCache <UInt256, BlockState>()); mockStore.Setup(p => p.GetTransactions()).Returns(new TestDataCache <UInt256, TransactionState>( new TransactionState { BlockIndex = 1, Transaction = defaultTx })); mockStore.Setup(p => p.GetAccounts()).Returns(new TestDataCache <UInt160, AccountState>()); mockStore.Setup(p => p.GetUnspentCoins()).Returns(new TestDataCache <UInt256, UnspentCoinState>()); mockStore.Setup(p => p.GetSpentCoins()).Returns(new TestDataCache <UInt256, SpentCoinState>()); mockStore.Setup(p => p.GetValidators()).Returns(new TestDataCache <ECPoint, ValidatorState>()); mockStore.Setup(p => p.GetAssets()).Returns(new TestDataCache <UInt256, AssetState>()); mockStore.Setup(p => p.GetContracts()).Returns(new TestDataCache <UInt160, ContractState>()); mockStore.Setup(p => p.GetStorages()).Returns(new TestDataCache <StorageKey, StorageItem>()); mockStore.Setup(p => p.GetHeaderHashList()).Returns(new TestDataCache <UInt32Wrapper, HeaderHashList>()); mockStore.Setup(p => p.GetValidatorsCount()).Returns(new TestMetaDataCache <ValidatorsCountState>()); mockStore.Setup(p => p.GetBlockHashIndex()).Returns(new TestMetaDataCache <HashIndexState>()); mockStore.Setup(p => p.GetHeaderHashIndex()).Returns(new TestMetaDataCache <HashIndexState>()); mockStore.Setup(p => p.GetSnapshot()).Returns(mockSnapshot.Object); Console.WriteLine("initialize CamSystem"); TheCamSystem = new CamSystem(mockStore.Object); // new Mock<CamSystem>(mockStore.Object); } return(TheCamSystem); }
public void TestSetup() { // protect against external changes on TimeProvider TimeProvider.ResetToDefault(); CamSystem TheCamSystem = TestBlockchain.InitializeMockCamSystem(); // Create a MemoryPool with capacity of 100 _unit = new MemoryPool(TheCamSystem, 100); // Verify capacity equals the amount specified _unit.Capacity.ShouldBeEquivalentTo(100); _unit.VerifiedCount.ShouldBeEquivalentTo(0); _unit.UnVerifiedCount.ShouldBeEquivalentTo(0); _unit.Count.ShouldBeEquivalentTo(0); }
public Blockchain(CamSystem system, Store store) { this.system = system; this.MemPool = new MemoryPool(system, MemoryPoolMaxTransactions); this.Store = store; lock (lockObj) { if (singleton != null) { throw new InvalidOperationException(); } header_index.AddRange(store.GetHeaderHashList().Find().OrderBy(p => (uint)p.Key).SelectMany(p => p.Value.Hashes)); stored_header_count += (uint)header_index.Count; if (stored_header_count == 0) { header_index.AddRange(store.GetBlocks().Find().OrderBy(p => p.Value.TrimmedBlock.Index).Select(p => p.Key)); } else { HashIndexState hashIndex = store.GetHeaderHashIndex().Get(); if (hashIndex.Index >= stored_header_count) { DataCache <UInt256, BlockState> cache = store.GetBlocks(); for (UInt256 hash = hashIndex.Hash; hash != header_index[(int)stored_header_count - 1];) { header_index.Insert((int)stored_header_count, hash); hash = cache[hash].TrimmedBlock.PrevHash; } } } if (header_index.Count == 0) { Persist(GenesisBlock); } else { UpdateCurrentSnapshot(); } singleton = this; } }
internal static Props Props(CamSystem system, object connection, IPEndPoint remote, IPEndPoint local) { return(Akka.Actor.Props.Create(() => new RemoteNode(system, connection, remote, local)).WithMailbox("remote-node-mailbox")); }
public static Props Props(CamSystem system) { return(Akka.Actor.Props.Create(() => new LocalNode(system))); }
public Coins(Wallet wallet, CamSystem system) { this.current_wallet = wallet; this.system = system; }
public RpcServer(CamSystem system, Wallet wallet = null, Fixed8 maxGasInvoke = default(Fixed8)) { this.system = system; this.Wallet = wallet; this.MaxGasInvoke = maxGasInvoke; }
public TaskManager(CamSystem system) { this.system = system; }
public static Props Props(CamSystem system) { return(Akka.Actor.Props.Create(() => new TaskManager(system)).WithMailbox("task-manager-mailbox")); }
public static Props Props(CamSystem system) { return(Akka.Actor.Props.Create(() => new ProtocolHandler(system)).WithMailbox("protocol-handler-mailbox")); }
public ProtocolHandler(CamSystem system) { this.system = system; this.knownHashes = new FIFOSet <UInt256>(Blockchain.Singleton.MemPool.Capacity * 2); this.sentHashes = new FIFOSet <UInt256>(Blockchain.Singleton.MemPool.Capacity * 2); }
public static Props Props(CamSystem system, Store store) { return(Akka.Actor.Props.Create(() => new Blockchain(system, store)).WithMailbox("blockchain-mailbox")); }
public MemoryPool(CamSystem system, int capacity) { _system = system; Capacity = capacity; LoadMaxTxLimitsFromPolicyPlugins(); }