internal static void LoadPlugins(KronaSystem 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(KronaSystem 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))); }
protected internal override void OnStart(string[] args) { store = new LevelDBStore(Path.GetFullPath(Settings.Default.Paths.Chain)); system = new KronaSystem(store); system.StartNode( port: Settings.Default.P2P.Port, wsPort: Settings.Default.P2P.WsPort, minDesiredConnections: Settings.Default.P2P.MinDesiredConnections, maxConnections: Settings.Default.P2P.MaxConnections, maxConnectionsPerAddress: Settings.Default.P2P.MaxConnectionsPerAddress); if (Settings.Default.UnlockWallet.IsActive) { try { if (!File.Exists(Settings.Default.UnlockWallet.Path)) { throw new CryptographicException(); } Program.Wallet = OpenWallet(GetIndexer(), Settings.Default.UnlockWallet.Path, Settings.Default.UnlockWallet.Password); } catch (CryptographicException) { Console.WriteLine($"failed to open file \"{Settings.Default.UnlockWallet.Path}\""); } if (Settings.Default.UnlockWallet.StartConsensus && Program.Wallet != null) { OnStartConsensusCommand(null); } } bool useRPC = false; for (int i = 0; i < args.Length; i++) { switch (args[i]) { case "/rpc": case "--rpc": case "-r": useRPC = true; break; case "/noninteractive": case "--noninteractive": case "-noninteractive": PreRun(); break; } } if (useRPC) { system.StartRpc(Settings.Default.RPC.BindAddress, Settings.Default.RPC.Port, wallet: Program.Wallet, sslCert: Settings.Default.RPC.SslCert, password: Settings.Default.RPC.SslCertPassword, maxConcurrentConnections: Settings.Default.RPC.MaxConcurrentConnections); } }
public static KronaSystem InitializeMockKronaSystem() { if (TheKronaSystem == 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.StateRoots).Returns(new TestDataCache <UInt32Wrapper, StateRootState>()); 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>()); mockSnapshot.SetupGet(p => p.StateRootHashIndex).Returns(new TestMetaDataCache <RootHashIndex>()); 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.GetStateRoots()).Returns(new TestDataCache <UInt32Wrapper, StateRootState>()); 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.GetStateRootHashIndex()).Returns(new TestMetaDataCache <RootHashIndex>()); mockStore.Setup(p => p.GetSnapshot()).Returns(mockSnapshot.Object); mockStore.Setup(p => p.Get(It.IsAny <byte>(), It.IsAny <byte[]>())).Returns(UInt256.Zero.ToArray()); Console.WriteLine("initialize KronaSystem"); TheKronaSystem = new KronaSystem(mockStore.Object); } return(TheKronaSystem); }
public LocalNode(KronaSystem system) { lock (lockObj) { if (singleton != null) { throw new InvalidOperationException(); } this.system = system; singleton = this; } }
public void TestSetup() { // protect against external changes on TimeProvider TimeProvider.ResetToDefault(); KronaSystem TheKronaSystem = TestBlockchain.InitializeMockKronaSystem(); // Create a MemoryPool with capacity of 100 _unit = new MemoryPool(TheKronaSystem, 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(KronaSystem 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; } }
public RpcServer(KronaSystem system, Wallet wallet = null) { this.system = system; this.Wallet = wallet; }
public TaskManager(KronaSystem system) { this.system = system; }
public static Props Props(KronaSystem system) { return(Akka.Actor.Props.Create(() => new TaskManager(system)).WithMailbox("task-manager-mailbox")); }
public static Props Props(KronaSystem system) { return(Akka.Actor.Props.Create(() => new LocalNode(system))); }
internal static Props Props(KronaSystem system, object connection, IPEndPoint remote, IPEndPoint local) { return(Akka.Actor.Props.Create(() => new RemoteNode(system, connection, remote, local)).WithMailbox("remote-node-mailbox")); }
public Coins(Wallet wallet, KronaSystem system) { this.current_wallet = wallet; this.system = system; }
public MemoryPool(KronaSystem system, int capacity) { _system = system; Capacity = capacity; LoadMaxTxLimitsFromPolicyPlugins(); }
public static Props Props(KronaSystem system, Store store) { return(Akka.Actor.Props.Create(() => new Blockchain(system, store)).WithMailbox("blockchain-mailbox")); }