Пример #1
0
        protected void OnSetValue(string[] args)
        {
            var chain     = _cli.Nexus.GetChainByName(_cli.Nexus.RootChain.Name);
            var fuelToken = _cli.Nexus.GetTokenInfo(_cli.Nexus.RootStorage, DomainSettings.FuelTokenSymbol);
            var balance   = chain.GetTokenBalance(chain.Storage, fuelToken, _cli.NodeKeys.Address);

            if (balance == 0)
            {
                Console.WriteLine("Node wallet needs gas to create a platform token!");
                return;
            }

            var key = args[0];

            if (string.IsNullOrEmpty(key))
            {
                Console.WriteLine("Key has to be set!");
                return;
            }

            Phantasma.Numerics.BigInteger value;
            try
            {
                value = Phantasma.Numerics.BigInteger.Parse(args[1]);
            }
            catch
            {
                Console.WriteLine("Value has to be set!");
                return;
            }

            var script = ScriptUtils.BeginScript()
                         .AllowGas(_cli.NodeKeys.Address, Address.Null, 100000, 15000)
                         .CallContract("governance", "SetValue", key, value)
                         .SpendGas(_cli.NodeKeys.Address).EndScript();

            var expire = Timestamp.Now + TimeSpan.FromMinutes(2);
            var tx     = new Phantasma.Blockchain.Transaction(_cli.Nexus.Name, _cli.Nexus.RootChain.Name, script, expire, Spook.TxIdentifier);

            tx.Mine((int)ProofOfWork.Minimal);
            tx.Sign(_cli.NodeKeys);

            if (_cli.Mempool != null)
            {
                _cli.Mempool.Submit(tx);
                Console.WriteLine($"Transaction {tx.Hash} submitted to mempool.");
            }
            else
            {
                Console.WriteLine("No mempool available");
                return;
            }

            Console.WriteLine($"SetValue {key}:{value} ts: {tx.Hash}");
        }
Пример #2
0
        protected void OnPlatformAddressAdd(string[] args)
        {
            var platform        = args[0];
            var externalAddress = args[1];

            Address localAddress;

            switch (platform)
            {
            case NeoWallet.NeoPlatform:
                localAddress = NeoWallet.EncodeAddress(externalAddress);
                break;

            case EthereumWallet.EthereumPlatform:
                localAddress = EthereumWallet.EncodeAddress(externalAddress);
                break;

            case BSCWallet.BSCPlatform:
                localAddress = BSCWallet.EncodeAddress(externalAddress);
                break;

            default:
                throw new Exception("Unknown platform: " + platform);
            }

            var minimumFee = _cli.Settings.Node.MinimumFee;
            var script     = ScriptUtils.BeginScript()
                             .AllowGas(_cli.NodeKeys.Address, Address.Null, minimumFee, 1500)
                             .CallContract("interop", nameof(InteropContract.RegisterAddress), _cli.NodeKeys.Address, platform, localAddress, externalAddress)
                             .SpendGas(_cli.NodeKeys.Address).EndScript();

            var expire = Timestamp.Now + TimeSpan.FromMinutes(2);
            var tx     = new Phantasma.Blockchain.Transaction(_cli.Nexus.Name, _cli.Nexus.RootChain.Name, script, expire, Spook.TxIdentifier);

            tx.Mine((int)ProofOfWork.Minimal);
            tx.Sign(_cli.NodeKeys);

            if (_cli.Mempool != null)
            {
                _cli.Mempool.Submit(tx);
                Console.WriteLine($"Transaction {tx.Hash} submitted to mempool.");
            }
            else
            {
                Console.WriteLine("No mempool available");
                return;
            }
            Console.WriteLine($"Added address {externalAddress} to {platform}");
            Spook.Logger.Message($"Added address {externalAddress} to {platform}");
        }
Пример #3
0
        protected void OnCreatePlatform(string[] args)
        {
            var platform = args[0];

            if (string.IsNullOrEmpty(platform))
            {
                Console.WriteLine("platform has to be set!");
                return;
            }

            var nativeCurrency = args[1];

            if (string.IsNullOrEmpty(nativeCurrency))
            {
                Console.WriteLine("Native currency has to be set!");
                return;
            }

            var platformKeys    = InteropUtils.GenerateInteropKeys(_cli.NodeKeys, _cli.Nexus.GetGenesisHash(_cli.Nexus.RootStorage), platform);
            var platformText    = Phantasma.Ethereum.EthereumKey.FromWIF(platformKeys.ToWIF()).Address;
            var platformAddress = Phantasma.Pay.Chains.BSCWallet.EncodeAddress(platformText);

            var script = ScriptUtils.BeginScript()
                         .AllowGas(_cli.NodeKeys.Address, Address.Null, 100000, 9999)
                         .CallInterop("Nexus.CreatePlatform", _cli.NodeKeys.Address, platform, platformText, platformAddress, nativeCurrency.ToUpper())
                         .SpendGas(_cli.NodeKeys.Address).EndScript();

            var expire = Timestamp.Now + TimeSpan.FromMinutes(2);
            var tx     = new Phantasma.Blockchain.Transaction(_cli.Nexus.Name, _cli.Nexus.RootChain.Name, script, expire, Spook.TxIdentifier);

            if (tx != null)
            {
                tx.Mine((int)ProofOfWork.Minimal);
                tx.Sign(_cli.NodeKeys);

                if (_cli.Mempool != null)
                {
                    _cli.Mempool.Submit(tx);
                }
                else
                {
                    Console.WriteLine("No mempool available");
                    return;
                }

                Console.WriteLine($"Platform \"{platform}\" created.");
            }
        }