Esempio n. 1
0
        public async Task Wallet_SignHash_Failed()
        {
            var chain = await _blockchainService.GetChainAsync();

            var walletStorePath = Path.Combine(ApplicationHelper.AppDataPath, "rpc-managed-wallet");
            var store           = new AElfKeyStore(walletStorePath);
            var keyPair         = await store.CreateAsync("123", chain.Id.ToString());

            var addressString = Address.FromPublicKey(keyPair.PublicKey).GetFormatted();

            var response = await JsonCallAsJObject("/wallet", "SignHash",
                                                   new { address = addressString, password = "******", hash = Hash.Generate().ToHex() });

            response.ShouldNotBeNull();
            response["error"]["code"].To <long>().ShouldBe(Wallet.Error.WrongPassword);
            response["error"]["message"].ToString().ShouldBe(Wallet.Error.Message[Wallet.Error.WrongPassword]);

            response = await JsonCallAsJObject("/wallet", "SignHash",
                                               new { address = addressString + "test", password = "******", hash = Hash.Generate().ToHex() });

            response.ShouldNotBeNull();
            response["error"]["code"].To <long>().ShouldBe(Wallet.Error.AccountNotExist);
            response["error"]["message"].ToString().ShouldBe(Wallet.Error.Message[Wallet.Error.AccountNotExist]);

            Directory.Delete(walletStorePath, true);
        }
Esempio n. 2
0
        public CliHelper(string rpcUrl)
        {
            _keyStore           = new AElfKeyStore(ApplicationHelpers.GetDefaultDataDir());
            _accountManager     = new AccountManager(_keyStore);
            _transactionManager = new TransactionManager(_keyStore);
            _requestManager     = new RpcRequestManager(rpcUrl);
            _loadedModules      = new Dictionary <string, Module>();

            CommandList = new List <CommandInfo>();
        }
        public CliHelper(string rpcUrl, string keyPath = "")
        {
            _rpcAddress         = rpcUrl;
            _keyStore           = new AElfKeyStore(keyPath == ""? ApplicationHelper.GetDefaultDataDir() : keyPath);
            _accountManager     = new AccountManager(_keyStore);
            _transactionManager = new TransactionManager(_keyStore);
            _requestManager     = new RpcRequestManager(rpcUrl);
            _loadedModules      = new Dictionary <string, Module>();

            CommandList = new List <CommandInfo>();
        }
Esempio n. 4
0
        private Dictionary <string, string> GetAndCreateAccountKey(DeployArg arg)
        {
            if (string.IsNullOrWhiteSpace(arg.ChainAccount))
            {
                var keyStore = new AElfKeyStore(ApplicationHelpers.ConfigPath);
                var key      = keyStore.Create(arg.AccountPassword);
                arg.ChainAccount = key.GetAddressHex();
            }

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

            return(new Dictionary <string, string> {
                { fileName, keyContent }
            });
        }
Esempio n. 5
0
        public async Task Wallet_SignHash_Success()
        {
            var chain = await _blockchainService.GetChainAsync();

            var walletStorePath = Path.Combine(ApplicationHelper.AppDataPath, "rpc-managed-wallet");
            var store           = new AElfKeyStore(walletStorePath);
            var keyPair         = await store.CreateAsync("123", chain.Id.ToString());

            var addressString = Address.FromPublicKey(keyPair.PublicKey).GetFormatted();

            var response = await JsonCallAsJObject("/wallet", "SignHash",
                                                   new { address = addressString, password = "******", hash = Hash.Generate().ToHex() });

            response.ShouldNotBeNull();
            response["result"].ToString().ShouldNotBeEmpty();

            Directory.Delete(walletStorePath, true);
        }
Esempio n. 6
0
        public async Task Wallet_ListAccounts()
        {
            var chain = await _blockchainService.GetChainAsync();

            var walletStorePath = Path.Combine(ApplicationHelper.AppDataPath, "rpc-managed-wallet");
            var store           = new AElfKeyStore(walletStorePath);
            var keyPair         = await store.CreateAsync("123", chain.Id.ToString());

            var addressString = Address.FromPublicKey(keyPair.PublicKey).GetFormatted();

            var response = await JsonCallAsJObject("/wallet", "ListAccounts");

            response.ShouldNotBeNull();
            response["result"].ToList().Count.ShouldBeGreaterThanOrEqualTo(1);
            response["result"].ToList().Contains(addressString).ShouldBeTrue();

            Directory.Delete(walletStorePath, true);
        }
Esempio n. 7
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. 8
0
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            var configuration = context.Services.GetConfiguration();

            context.Services.AddAssemblyOf <OSAElfModule>();

            context.Services.AddSingleton <PeerConnectedEventHandler>();
            context.Services.AddTransient <BlockSyncJob>();

            //TODO: make ApplicationHelper as a provider, inject it into key store
            var keyStore = new AElfKeyStore(ApplicationHelper.AppDataPath);

            context.Services.AddSingleton <IKeyStore>(keyStore);

            Configure <AccountOptions>(option =>
            {
                configuration.GetSection("Account").Bind(option);

                if (string.IsNullOrWhiteSpace(option.NodeAccount))
                {
                    AsyncHelper.RunSync(async() =>
                    {
                        var accountList = await keyStore.ListAccountsAsync();

                        option.NodeAccountPassword = string.Empty;
                        if (accountList.Count == 0)
                        {
                            var blockChainService = context.Services.GetRequiredServiceLazy <IBlockchainService>().Value;
                            var chainId           = blockChainService.GetChainId();
                            var keyPair           = await keyStore.CreateAsync(option.NodeAccountPassword, chainId.ToString());
                            option.NodeAccount    = Address.FromPublicKey(keyPair.PublicKey).GetFormatted();
                        }
                        else
                        {
                            option.NodeAccount = accountList.First();
                        }
                    });
                }
            });
        }
Esempio n. 9
0
        public static void InitCliCommand(string rpcUrl)
        {
            ScreenManager screenManager = new ScreenManager();
            CommandParser parser        = new CommandParser();

            AElfKeyStore   kstore  = new AElfKeyStore(ApplicationHelpers.GetDefaultDataDir());
            AccountManager manager = new AccountManager(kstore, screenManager);

            CliInstance = new AElfCliProgram(screenManager, parser, manager, rpcUrl);
            // Register local commands
            RegisterAccountCommands(CliInstance);
            RegisterNetworkCommands(CliInstance);

            CliInstance.RegisterCommand(new GetIncrementCmd());
            CliInstance.RegisterCommand(new SendTransactionCmd());
            CliInstance.RegisterCommand(new LoadContractAbiCmd());
            CliInstance.RegisterCommand(new DeployContractCommand());
            CliInstance.RegisterCommand(new GetTxResultCmd());
            CliInstance.RegisterCommand(new GetGenesisContractAddressCmd());
            CliInstance.RegisterCommand(new GetDeserializedResultCmd());
            CliInstance.RegisterCommand(new GetBlockHeightCmd());
        }
Esempio n. 10
0
        private async Task <Dictionary <string, string> > GetAndCreateAccountKey(DeployArg arg)
        {
            if (string.IsNullOrWhiteSpace(arg.ChainAccount))
            {
                var keyStore = new AElfKeyStore(ApplicationHelper.AppDataPath);

                var chainPrefixBase58 = Base58CheckEncoding.Encode(ByteArrayHelpers.FromHexString(arg.SideChainId));
                var chainPrefix       = chainPrefixBase58.Substring(0, 4);

                var key = await keyStore.CreateAsync(arg.AccountPassword, chainPrefix);

                // todo clean
                //arg.ChainAccount = "ELF_" + chainPrefix + "_" + key.GetEncodedPublicKey();
            }

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

            return(new Dictionary <string, string> {
                { fileName, keyContent }
            });
        }
Esempio n. 11
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());
        }
 public TransactionManager(AElfKeyStore keyStore)
 {
     _keyStore = keyStore;
 }
Esempio n. 13
0
 public TransactionManager(AElfKeyStore keyStore)
 {
     _keyStore       = keyStore;
     _accountManager = new AccountManager(keyStore);
 }
Esempio n. 14
0
 public AccountManager(AElfKeyStore keyStore)
 {
     _keyStore = keyStore;
 }
Esempio n. 15
0
 private void InitKeyStore()
 {
     _keyStore = new AElfKeyStore("/tmp");
 }
Esempio n. 16
0
 public AccountManager(AElfKeyStore keyStore, ScreenManager screenManager)
 {
     _screenManager = screenManager;
     _keyStore      = keyStore;
 }
 public TransactionManager(AElfKeyStore keyStore, CommandInfo ci)
 {
     _keyStore = keyStore;
     _cmdInfo  = ci;
 }