Esempio n. 1
0
        public void Action(DeployArg arg)
        {
            // Todo temp solution
            ApiKeyConfig.Instance.ChainKeys.Add(arg.SideChainId, arg.ApiKey);
            var configJson = JsonSerializer.Instance.Serialize(ApiKeyConfig.Instance);

            File.WriteAllText(Path.Combine(ApplicationHelpers.GetDefaultConfigPath(), "config", "api-key.json"), configJson);
        }
Esempio n. 2
0
        static FileWatcher()
        {
            _fileNames    = new HashSet <string>();
            _pendingFiles = new HashSet <string>();
            var configPath = Path.Combine(ApplicationHelpers.GetDefaultConfigPath(), "config");

            if (!Directory.Exists(configPath))
            {
                Directory.CreateDirectory(configPath);
            }

            InitWatcher(configPath);
        }
Esempio n. 3
0
        private Dictionary <string, string> GetAndCreateAccountKey(DeployArg arg)
        {
            if (string.IsNullOrWhiteSpace(arg.ChainAccount))
            {
                var keyStore = new AElfKeyStore(ApplicationHelpers.GetDefaultConfigPath());
                var key      = keyStore.Create(arg.AccountPassword);
                arg.ChainAccount = key.GetAddressHex();
            }

            var fileName   = arg.ChainAccount + ".ak";
            var filePath   = Path.Combine(ApplicationHelpers.GetDefaultConfigPath(), "keys", fileName);
            var keyContent = File.ReadAllText(filePath);

            return(new Dictionary <string, string> {
                { fileName, keyContent }
            });
        }
Esempio n. 4
0
        private void GenerateCertificate(string chainId, string ip)
        {
            var keyPair  = _certificateStore.WriteKeyAndCertificate(chainId, ip);
            var certPath = Path.Combine(ApplicationHelpers.GetDefaultConfigPath(), _certificateStore.FolderName,
                                        chainId + _certificateStore.CertExtension);

            if (File.Exists(certPath))
            {
                _screenManager.PrintLine("[Certificate] " + certPath);
            }
            var keyPath = Path.Combine(ApplicationHelpers.GetDefaultConfigPath(), _certificateStore.FolderName,
                                       chainId + _certificateStore.KeyExtension);

            if (File.Exists(keyPath))
            {
                _screenManager.PrintLine("[Key] " + keyPath);
            }
        }
Esempio n. 5
0
        public static void Main(string[] args)
        {
            CommandParser parser     = new CommandParser();
            var           cmdOptions = new CommandLineOptions();

            Parser.Default.ParseArguments <CommandLineOptions>(args).WithNotParsed(err =>
            {
                Environment.Exit(1);
            }
                                                                                   ).WithParsed(
                result => { cmdOptions = result; });

            ApplicationHelpers.SetConfigPath(cmdOptions.ConfigPath);

            ScreenManager screenManager = new ScreenManager();

            AElfKeyStore      kstore            = new AElfKeyStore(ApplicationHelpers.GetDefaultConfigPath());
            AccountManager    accountManager    = new AccountManager(kstore, screenManager);
            CertificatManager certificatManager = new CertificatManager(screenManager);

            AElfCliProgram program = new AElfCliProgram(screenManager, parser, accountManager, certificatManager,
                                                        cmdOptions.ServerAddr);

            // Register local commands
            RegisterAccountCommands(program);
            RegisterNetworkCommands(program);

            program.RegisterCommand(new GetIncrementCmd());
            program.RegisterCommand(new SendTransactionCmd());
            program.RegisterCommand(new LoadContractAbiCmd());
            program.RegisterCommand(new DeployContractCommand());
            program.RegisterCommand(new GetTxResultCmd());
            program.RegisterCommand(new GetGenesisContractAddressCmd());
            program.RegisterCommand(new GetDeserializedResultCmd());
            program.RegisterCommand(new GetBlockHeightCmd());
            program.RegisterCommand(new GetBlockInfoCmd());
            program.RegisterCommand(new CallReadOnlyCmd());
            program.RegisterCommand(new GetMerklePathCmd());
            program.RegisterCommand(new CertificateCmd());

            // Start the CLI
            program.StartRepl();
        }
Esempio n. 6
0
        public void Action(DeployArg arg)
        {
            CreateGrpcKey(arg);
            var certFileName = arg.SideChainId + ".cert.pem";
            var cert         = File.ReadAllText(Path.Combine(ApplicationHelpers.GetDefaultConfigPath(), "certs", certFileName));
            var keyFileName  = arg.SideChainId + ".key.pem";
            var key          = File.ReadAllText(Path.Combine(ApplicationHelpers.GetDefaultConfigPath(), "certs", keyFileName));

            var configMapData = new Dictionary <string, string> {
                { certFileName, cert }, { keyFileName, key }
            };

            if (!arg.IsDeployMainChain)
            {
                var certMainChain = K8SRequestHelper.GetClient().ReadNamespacedConfigMap(GlobalSetting.CertsConfigName, arg.MainChainId).Data;
                var certName      = arg.MainChainId + ".cert.pem";
                configMapData.Add(certName, certMainChain[certName]);

                certMainChain.Add(certFileName, cert);
                var patch = new JsonPatchDocument <V1ConfigMap>();
                patch.Replace(e => e.Data, certMainChain);

                K8SRequestHelper.GetClient().PatchNamespacedConfigMap(new V1Patch(patch), GlobalSetting.CertsConfigName, arg.MainChainId);
            }


            var body = new V1ConfigMap
            {
                ApiVersion = V1ConfigMap.KubeApiVersion,
                Kind       = V1ConfigMap.KubeKind,
                Metadata   = new V1ObjectMeta
                {
                    Name = GlobalSetting.CertsConfigName,
                    NamespaceProperty = arg.SideChainId
                },
                Data = configMapData
            };

            K8SRequestHelper.GetClient().CreateNamespacedConfigMap(body, arg.SideChainId);
        }
Esempio n. 7
0
        public void Init(ContainerBuilder builder)
        {
            var minerConfig = MinerConfig.Default;

            if (NodeConfig.Instance.IsMiner)
            {
                minerConfig = new MinerConfig
                {
                    CoinBase = Address.LoadHex(NodeConfig.Instance.NodeAccount)
                };
            }
            minerConfig.ChainId = new Hash()
            {
                Value = ByteString.CopyFrom(ByteArrayHelpers.FromHexString(ChainConfig.Instance.ChainId))
            };
            builder.RegisterModule(new MinerRpcAutofacModule());

            builder.RegisterType <ClientManager>().SingleInstance().OnActivated(mc =>
            {
                mc.Instance.Init(dir: ApplicationHelpers.GetDefaultConfigPath());
            }
                                                                                );
            builder.RegisterType <ServerManager>().SingleInstance().OnActivated(mc =>
            {
                mc.Instance.Init(ApplicationHelpers.GetDefaultConfigPath());
            }
                                                                                );
            builder.RegisterModule(new MinerAutofacModule(minerConfig));

            var txPoolConfig = TxPoolConfig.Default;

            txPoolConfig.FeeThreshold  = 0;
            txPoolConfig.PoolLimitSize = TransactionPoolConfig.Instance.PoolLimitSize;
            txPoolConfig.Maximal       = TransactionPoolConfig.Instance.Maximal;
            txPoolConfig.EcKeyPair     = TransactionPoolConfig.Instance.EcKeyPair;
            builder.RegisterInstance(txPoolConfig).As <ITxPoolConfig>();
        }
Esempio n. 8
0
        public void Init(ContainerBuilder builder)
        {
            ECKeyPair nodeKey = null;

            if (!string.IsNullOrWhiteSpace(NodeConfig.Instance.NodeAccount))
            {
                try
                {
                    var ks = new AElfKeyStore(ApplicationHelpers.GetDefaultConfigPath());

                    var pass = string.IsNullOrWhiteSpace(NodeConfig.Instance.NodeAccountPassword)
                        ? AskInvisible(NodeConfig.Instance.NodeAccount)
                        : NodeConfig.Instance.NodeAccountPassword;

                    ks.OpenAsync(NodeConfig.Instance.NodeAccount, pass, false);

                    NodeConfig.Instance.NodeAccountPassword = pass;

                    nodeKey = ks.GetAccountKeyPair(NodeConfig.Instance.NodeAccount);

                    if (nodeKey == null)
                    {
                        Console.WriteLine("Load keystore failed");
                    }
                }
                catch (Exception e)
                {
                    throw new Exception("Load keystore failed");
                }
            }

            TransactionPoolConfig.Instance.EcKeyPair = nodeKey;
            NetworkConfig.Instance.EcKeyPair         = nodeKey;

            builder.RegisterModule(new NodeAutofacModule());
        }
Esempio n. 9
0
        private void CreateGrpcKey(DeployArg arg)
        {
            var certificateStore = new CertificateStore(ApplicationHelpers.GetDefaultConfigPath());

            certificateStore.WriteKeyAndCertificate(arg.SideChainId, arg.LauncherArg.ClusterIp);
        }
Esempio n. 10
0
        private static void SaveConfigToFile()
        {
            var configJson = JsonSerializer.Instance.Serialize(ServiceUrlConfig.Instance);

            File.WriteAllText(Path.Combine(ApplicationHelpers.GetDefaultConfigPath(), "config", "service-url.json"), configJson);
        }
Esempio n. 11
0
 public SmartContractReader()
 {
     _dataDirectory = ApplicationHelpers.GetDefaultConfigPath();
 }