protected void OnWalletMigrateCommand(string[] args)
        {
            BigInteger minFee = new BigInteger(_cli.Settings.Node.MinimumFee);

            WalletModule.Migrate(args, _cli.NexusAPI, minFee);

            if (_cli.Mempool != null)
            {
                _cli.Mempool.SetKeys(WalletModule.Keys);
            }
        }
Example #2
0
        private void SetupCommands(CommandDispatcher dispatcher)
        {
            dispatcher.RegisterCommand("quit", "Stops the node and exits", (args) => Terminate());

            if (gui != null)
            {
                dispatcher.RegisterCommand("gui.log", "Switches the gui to log view", (args) => gui.ShowLog(args));
                dispatcher.RegisterCommand("gui.graph", "Switches the gui to graph view", (args) => gui.ShowGraph(args));
            }

            dispatcher.RegisterCommand("help", "Lists available commands", (args) => dispatcher.Commands.ToList().ForEach(x => logger.Message($"{x.Name}\t{x.Description}")));

            foreach (var method in api.Methods)
            {
                dispatcher.RegisterCommand("api." + method.Name, "API CALL", (args) => ExecuteAPI(method.Name, args));
            }

            dispatcher.RegisterCommand("script.assemble", "Assembles a .asm file into Phantasma VM script format",
                                       (args) => ScriptModule.AssembleFile(args));

            dispatcher.RegisterCommand("script.disassemble", $"Disassembles a {ScriptFormat.Extension} file into readable Phantasma assembly",
                                       (args) => ScriptModule.DisassembleFile(args));

            dispatcher.RegisterCommand("script.compile", "Compiles a .sol file into Phantasma VM script format",
                                       (args) => ScriptModule.CompileFile(args));

            dispatcher.RegisterCommand("wallet.balance", "Shows the current wallet balance",
                                       (args) => WalletModule.Balance(node.Address, api, logger, args));

            dispatcher.RegisterCommand("wallet.transfer", "Generates a new transfer transaction",
                                       (args) => WalletModule.Transfer(node.Keys, api, logger, args));

            dispatcher.RegisterCommand("wallet.stake", $"Stakes {Nexus.StakingTokenSymbol}",
                                       (args) => WalletModule.Stake(node.Keys, api, logger, args));

            dispatcher.RegisterCommand("file.upload", "Uploads a file into Phantasma",
                                       (args) => FileModule.Upload(node.Keys, api, logger, args));
        }
        protected void OnWalletScriptCommand(string[] args)
        {
            BigInteger minFee = new BigInteger(_cli.Settings.Node.MinimumFee);

            WalletModule.ExecuteScript(args, _cli.NexusAPI, minFee);
        }
        protected void OnWalletUpgradeCommand(string[] args)
        {
            BigInteger minFee = new BigInteger(_cli.Settings.Node.MinimumFee);

            WalletModule.Upgrade(args, _cli.NexusAPI, minFee);
        }
        protected void OnWalletStakeCommand(string[] args)
        {
            BigInteger minFee = new BigInteger(_cli.Settings.Node.MinimumFee);

            WalletModule.Stake(_cli.NexusAPI, minFee, args);
        }
        protected void OnWalletTransferCommand(string[] args)
        {
            BigInteger minFee = new BigInteger(_cli.Settings.Node.MinimumFee);

            WalletModule.Transfer(_cli.NexusAPI, minFee, _cli.NeoAPI, args);
        }
 protected void OnWalletBalanceCommand(string[] args)
 {
     WalletModule.Balance(_cli.NexusAPI, _cli.Settings.Node.RestPort, _cli.NeoScanAPI, args);
 }
Example #8
0
 private void ConfigureIoC(IServiceCollection services)
 {
     var module = new WalletModule(services, Configuration);
 }
Example #9
0
        private void SetupCommands(CommandDispatcher dispatcher)
        {
            ModuleLogger.Init(logger, gui);

            var minimumFee = this.mempool != null ? mempool.MinimumFee : 1;

            dispatcher.RegisterCommand("quit", "Stops the node and exits", (args) => Terminate());

            if (gui != null)
            {
                dispatcher.RegisterCommand("gui.log", "Switches the gui to log view", (args) => gui.ShowLog(args));
                dispatcher.RegisterCommand("gui.graph", "Switches the gui to graph view", (args) => gui.ShowGraph(args));
            }

            dispatcher.RegisterCommand("help", "Lists available commands", (args) => dispatcher.Commands.ToList().ForEach(x => logger.Message($"{x.Name}\t{x.Description}")));

            foreach (var method in nexusApi.Methods)
            {
                dispatcher.RegisterCommand("api." + method.Name, "API CALL", (args) => ExecuteAPI(method.Name, args));
            }

            dispatcher.RegisterCommand("script.assemble", "Assembles a .asm file into Phantasma VM script format",
                                       (args) => ScriptModule.AssembleFile(args));

            dispatcher.RegisterCommand("script.disassemble", $"Disassembles a {ScriptFormat.Extension} file into readable Phantasma assembly",
                                       (args) => ScriptModule.DisassembleFile(args));

            dispatcher.RegisterCommand("script.compile", "Compiles a .sol file into Phantasma VM script format",
                                       (args) => ScriptModule.CompileFile(args));

            dispatcher.RegisterCommand("wallet.open", "Opens a wallet from a WIF key",
                                       (args) => WalletModule.Open(args));

            dispatcher.RegisterCommand("wallet.create", "Creates new a wallet",
                                       (args) => WalletModule.Create(args));

            dispatcher.RegisterCommand("wallet.balance", "Shows the current wallet balance",
                                       (args) => WalletModule.Balance(nexusApi, restPort, neoScanAPI, args));

            dispatcher.RegisterCommand("wallet.transfer", "Generates a new transfer transaction",
                                       (args) => WalletModule.Transfer(nexusApi, minimumFee, neoAPI, args));

            dispatcher.RegisterCommand("wallet.stake", $"Stakes {DomainSettings.StakingTokenSymbol}",
                                       (args) => WalletModule.Stake(nexusApi, args));

            dispatcher.RegisterCommand("wallet.airdrop", "Does a batch transfer from a .csv",
                                       (args) => WalletModule.Airdrop(args, nexusApi, minimumFee));

            dispatcher.RegisterCommand("wallet.migrate", "Migrates a validator to another address ",
                                       (args) =>
            {
                WalletModule.Migrate(args, nexusApi, minimumFee);
                if (mempool != null)
                {
                    mempool.SetKeys(WalletModule.Keys);
                }
            });

            dispatcher.RegisterCommand("file.upload", "Uploads a file into Phantasma",
                                       (args) => FileModule.Upload(WalletModule.Keys, nexusApi, args));

            dispatcher.RegisterCommand("oracle.read", "Read transaction from oracle",
                                       (args) =>
            {
                var hash   = Hash.Parse(args[0]);
                var reader = nexus.CreateOracleReader();
                var tx     = reader.ReadTransaction("neo", "neo", hash);
                logger.Message(tx.Transfers[0].interopAddress.Text);
            });

            if (mempool != null)
            {
                dispatcher.RegisterCommand("mempool.list", "Shows mempool pending transaction list",
                                           (args) =>
                {
                    var txs = mempool.GetTransactions();
                    foreach (var tx in txs)
                    {
                        logger.Message(tx.ToString());
                    }
                });
            }

            dispatcher.RegisterCommand("neo.deploy", "Deploys a contract into NEO",
                                       (args) =>
            {
                if (args.Length != 2)
                {
                    throw new CommandException("Expected: WIF avm_path");
                }
                var avmPath = args[1];
                if (!File.Exists(avmPath))
                {
                    throw new CommandException("path for avm not found");
                }

                var keys       = Neo.Core.NeoKeys.FromWIF(args[0]);
                var script     = File.ReadAllBytes(avmPath);
                var scriptHash = Neo.Utils.CryptoUtils.ToScriptHash(script);
                logger.Message("Deploying contract " + scriptHash);

                try
                {
                    var tx = neoAPI.DeployContract(keys, script, Base16.Decode("0710"), 0x05, Neo.Core.ContractProperties.HasStorage | Neo.Core.ContractProperties.Payable, "Contract", "1.0", "Author", "*****@*****.**", "Description");
                    logger.Success("Deployed contract via transaction: " + tx.Hash);
                }
                catch (Exception e)
                {
                    logger.Error("Failed to deploy contract: " + e.Message);
                }
            });

            dispatcher.RegisterCommand("exit", "Terminates the node", (args) =>
            {
                this.Terminate();
            });

            if (useSimulator)
            {
                dispatcher.RegisterCommand("simulator.timeskip", $"Skips minutse in simulator",
                                           (args) =>
                {
                    if (args.Length != 1)
                    {
                        throw new CommandException("Expected: minutes");
                    }
                    var minutes            = int.Parse(args[0]);
                    simulator.CurrentTime += TimeSpan.FromMinutes(minutes);
                    logger.Success($"Simulator time advanced by {minutes}");
                });
            }
        }