示例#1
0
        public static Hash SendTransfer(JSONRPC_Client rpc, Logger logger, string nexusName, string host, PhantasmaKeys from, Address to, BigInteger amount)
        {
            Throw.IfNull(rpc, nameof(rpc));
            Throw.IfNull(logger, nameof(logger));

            var script = ScriptUtils.BeginScript().AllowGas(from.Address, Address.Null, 1, 9999).TransferTokens("SOUL", from.Address, to, amount).SpendGas(from.Address).EndScript();

            var tx = new Phantasma.Blockchain.Transaction(nexusName, "main", script, Timestamp.Now + TimeSpan.FromMinutes(30));

            tx.Sign(from);

            var bytes = tx.ToByteArray(true);

            //log.Debug("RAW: " + Base16.Encode(bytes));

            var response = rpc.SendRequest(logger, host, "sendRawTransaction", Base16.Encode(bytes));

            if (response == null)
            {
                logger.Error($"Error sending {amount} {DomainSettings.FuelTokenSymbol} from {from.Address} to {to}...");
                return(Hash.Null);
            }

            if (response.HasNode("error"))
            {
                var error = response.GetString("error");
                logger.Error("Error: " + error);
                return(Hash.Null);
            }

            var hash = response.Value;

            return(Hash.Parse(hash));
        }
示例#2
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}");
        }
示例#3
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}");
        }
示例#4
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.");
            }
        }
示例#5
0
        protected void OnWalletRelayCommand(string[] args)
        {
            var script = Base16.Decode(args[0]);
            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.Sign(WalletModule.Keys);

            if (_cli.Mempool != null)
            {
                _cli.Mempool.Submit(tx);
            }
            else
            {
                throw new CommandException("no mempool available");
            }
        }
示例#6
0
        protected void OnCreatePlatformToken(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 symbol = args[0];

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

            var platform = args[1];

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

            Transaction tx = null;

            if (platform == DomainSettings.PlatformName)
            {
                //TODO phantasma token creation
            }
            else
            {
                var hashStr = args[2];
                if (string.IsNullOrEmpty(hashStr))
                {
                    Console.WriteLine("Hash has to be set!");
                    return;
                }

                if (hashStr.StartsWith("0x"))
                {
                    hashStr = hashStr.Substring(2);
                }

                Hash hash;

                try
                {
                    hash = Hash.FromUnpaddedHex(hashStr);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Parsing hash failed: " + e.Message);
                    return;
                }

                var script = ScriptUtils.BeginScript()
                             .AllowGas(_cli.NodeKeys.Address, Address.Null, 100000, 1500)
                             .CallInterop("Nexus.SetPlatformTokenHash", symbol.ToUpper(), platform, hash)
                             .SpendGas(_cli.NodeKeys.Address).EndScript();

                var expire = Timestamp.Now + TimeSpan.FromMinutes(2);
                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($"Token {symbol}/{platform} created.");
            }
        }