Пример #1
0
        internal static void LoadPlugins(TrustEDUNetwork system)
        {
            System = system;
            string path = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Plugins");

            if (!Directory.Exists(path))
            {
                return;
            }
            foreach (string filename in Directory.EnumerateFiles(path, "*.dll", SearchOption.TopDirectoryOnly))
            {
                Assembly assembly = Assembly.LoadFile(filename);
                foreach (Type type in assembly.ExportedTypes)
                {
                    if (!type.IsSubclassOf(typeof(Plugin)))
                    {
                        continue;
                    }
                    if (type.IsAbstract)
                    {
                        continue;
                    }
                    ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes);
                    if (constructor == null)
                    {
                        continue;
                    }
                    constructor.Invoke(null);
                }
            }
        }
Пример #2
0
 public RemoteNode(TrustEDUNetwork 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)));
 }
Пример #3
0
 public LocalNode(TrustEDUNetwork system)
 {
     lock (GetType())
     {
         if (singleton != null)
         {
             throw new InvalidOperationException();
         }
         this.system = system;
         singleton   = this;
     }
 }
Пример #4
0
        /// <summary>
        /// TODO: Need to refactor to use CommandLineParser lib
        /// </summary>
        /// <param name="args">Arguments.</param>
        protected internal override void OnStart(string[] args)
        {
            bool useRPC = false;

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "/rpc":
                case "--rpc":
                case "-r":
                    useRPC = true;
                    break;
                }
            }
            store  = new LevelDBStore(Path.GetFullPath(Configs.Default.Paths.Chain));
            system = new TrustEDUNetwork(store);
            system.StartNode(Configs.Default.P2P.Port, Configs.Default.P2P.WsPort);
            if (Configs.Default.UnlockWallet.IsActive)
            {
                try
                {
                    Program.Wallet = OpenWallet(GetIndexer(), Configs.Default.UnlockWallet.Path, Configs.Default.UnlockWallet.Password);
                }
                catch (CryptographicException)
                {
                    Console.WriteLine($"failed to open file \"{Configs.Default.UnlockWallet.Path}\"");
                }
                if (Configs.Default.UnlockWallet.StartConsensus && Program.Wallet != null)
                {
                    OnStartConsensusCommand(null);
                }
            }
            if (useRPC)
            {
                system.StartRpc(IPAddress.Parse("127.0.0.1"), Configs.Default.RPC.Port,
                                wallet: Program.Wallet,
                                sslCert: Configs.Default.RPC.SslCert,
                                password: Configs.Default.RPC.SslCertPassword);
            }
        }
Пример #5
0
 public Blockchain(TrustEDUNetwork system, Store store)
 {
     this.system = system;
     this.Store  = store;
     lock (GetType())
     {
         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)
             {
                 CacheItem <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;
     }
 }
Пример #6
0
 public static Props Props(TrustEDUNetwork system)
 {
     return(Akka.Actor.Props.Create(() => new ProtocolHandler(system)).WithMailbox("protocol-handler-mailbox"));
 }
Пример #7
0
 public ProtocolHandler(TrustEDUNetwork system)
 {
     this.system = system;
 }
Пример #8
0
 public RpcServer(TrustEDUNetwork system, Wallet wallet = null)
 {
     this.system = system;
     this.wallet = wallet;
 }
Пример #9
0
 public static Props Props(TrustEDUNetwork system, Wallet wallet)
 {
     return(Akka.Actor.Props.Create(() => new ConsensusService(system, wallet)).WithMailbox("consensus-service-mailbox"));
 }
Пример #10
0
 public ConsensusService(TrustEDUNetwork system, Wallet wallet)
 {
     this._system = system;
     this._wallet = wallet;
 }
Пример #11
0
 public EducationAssets(Wallet wallet, TrustEDUNetwork system)
 {
     this.currentWallet = wallet;
     this.system        = system;
 }
Пример #12
0
 internal static Props Props(TrustEDUNetwork system, object connection, IPEndPoint remote, IPEndPoint local)
 {
     return(Akka.Actor.Props.Create(() => new RemoteNode(system, connection, remote, local)).WithMailbox("remote-node-mailbox"));
 }
Пример #13
0
 public static Props Props(TrustEDUNetwork system, Store store)
 {
     return(Akka.Actor.Props.Create(() => new Blockchain(system, store)).WithMailbox("blockchain-mailbox"));
 }
Пример #14
0
 public static Props Props(TrustEDUNetwork system)
 {
     return(Akka.Actor.Props.Create(() => new LocalNode(system)));
 }
Пример #15
0
 public TaskManager(TrustEDUNetwork system)
 {
     this.system = system;
 }
Пример #16
0
 public static Props Props(TrustEDUNetwork system)
 {
     return(Akka.Actor.Props.Create(() => new TaskManager(system)).WithMailbox("task-manager-mailbox"));
 }