diff --git a/neo-cli/Settings.cs b/neo-cli/Settings.cs index 8b6ff326e..7e6e0c621 100644 --- a/neo-cli/Settings.cs +++ b/neo-cli/Settings.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.Configuration; using Neo.Network.P2P; +using Neo.SmartContract.Native; using System.Net; namespace Neo @@ -37,8 +38,8 @@ internal class PathsSettings public PathsSettings(IConfigurationSection section) { - this.Chain = string.Format(section.GetSection("Chain").Value, Message.Magic.ToString("X8")); - this.Index = string.Format(section.GetSection("Index").Value, Message.Magic.ToString("X8")); + this.Chain = string.Format(section.GetSection("Chain").Value, ProtocolSettings.Default.Magic.ToString("X8")); + this.Index = string.Format(section.GetSection("Index").Value, ProtocolSettings.Default.Magic.ToString("X8")); } } @@ -66,7 +67,7 @@ internal class RPCSettings public ushort Port { get; } public string SslCert { get; } public string SslCertPassword { get; } - public Fixed8 MaxGasInvoke { get; } + public long MaxGasInvoke { get; } public RPCSettings(IConfigurationSection section) { @@ -74,7 +75,7 @@ public RPCSettings(IConfigurationSection section) this.Port = ushort.Parse(section.GetSection("Port").Value); this.SslCert = section.GetSection("SslCert").Value; this.SslCertPassword = section.GetSection("SslCertPassword").Value; - this.MaxGasInvoke = Fixed8.Parse(section.GetValue("MaxGasInvoke", "0")); + this.MaxGasInvoke = (long)BigDecimal.Parse(section.GetValue("MaxGasInvoke", "0"), NativeContract.GAS.Decimals).Value; } } diff --git a/neo-cli/Shell/Coins.cs b/neo-cli/Shell/Coins.cs deleted file mode 100644 index bc9a12a8a..000000000 --- a/neo-cli/Shell/Coins.cs +++ /dev/null @@ -1,194 +0,0 @@ -using Akka.Actor; -using Neo.Ledger; -using Neo.Network.P2P.Payloads; -using Neo.Persistence; -using Neo.SmartContract; -using Neo.Wallets; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Neo.Shell -{ - - public class Coins - { - private Wallet current_wallet; - private NeoSystem system; - public static int MAX_CLAIMS_AMOUNT = 50; - - public Coins(Wallet wallet, NeoSystem system) - { - this.current_wallet = wallet; - this.system = system; - } - - public Fixed8 UnavailableBonus() - { - using (Snapshot snapshot = Blockchain.Singleton.GetSnapshot()) - { - uint height = snapshot.Height + 1; - Fixed8 unavailable; - - try - { - unavailable = snapshot.CalculateBonus(current_wallet.FindUnspentCoins().Where(p => p.Output.AssetId.Equals(Blockchain.GoverningToken.Hash)).Select(p => p.Reference), height); - } - catch (Exception) - { - unavailable = Fixed8.Zero; - } - - return unavailable; - } - } - - - public Fixed8 AvailableBonus() - { - using (Snapshot snapshot = Blockchain.Singleton.GetSnapshot()) - { - return snapshot.CalculateBonus(current_wallet.GetUnclaimedCoins().Select(p => p.Reference)); - } - } - - public ClaimTransaction Claim(UInt160 change_address = null) - { - - if (this.AvailableBonus() == Fixed8.Zero) - { - Console.WriteLine($"no gas to claim"); - return null; - } - - CoinReference[] claims = current_wallet.GetUnclaimedCoins().Select(p => p.Reference).ToArray(); - if (claims.Length == 0) return null; - - using (Snapshot snapshot = Blockchain.Singleton.GetSnapshot()) - { - ClaimTransaction tx = new ClaimTransaction - { - Claims = claims.Take(MAX_CLAIMS_AMOUNT).ToArray(), - Attributes = new TransactionAttribute[0], - Inputs = new CoinReference[0], - Outputs = new[] - { - new TransactionOutput - { - AssetId = Blockchain.UtilityToken.Hash, - Value = snapshot.CalculateBonus(claims.Take(MAX_CLAIMS_AMOUNT)), - ScriptHash = change_address ?? current_wallet.GetChangeAddress() - } - } - - }; - - return (ClaimTransaction)SignTransaction(tx); - } - } - - - public ClaimTransaction[] ClaimAll(UInt160 change_address = null) - { - - if (this.AvailableBonus() == Fixed8.Zero) - { - Console.WriteLine($"no gas to claim"); - return null; - } - - CoinReference[] claims = current_wallet.GetUnclaimedCoins().Select(p => p.Reference).ToArray(); - if (claims.Length == 0) return null; - - using (Snapshot snapshot = Blockchain.Singleton.GetSnapshot()) - { - int claim_count = (claims.Length - 1) / MAX_CLAIMS_AMOUNT + 1; - List txs = new List(); - if (claim_count > 1) - { - Console.WriteLine($"total claims: {claims.Length}, processing(0/{claim_count})..."); - } - for (int i = 0; i < claim_count; i++) - { - if (i > 0) - { - Console.WriteLine($"{i * MAX_CLAIMS_AMOUNT} claims processed({i}/{claim_count})..."); - } - ClaimTransaction tx = new ClaimTransaction - { - Claims = claims.Skip(i * MAX_CLAIMS_AMOUNT).Take(MAX_CLAIMS_AMOUNT).ToArray(), - Attributes = new TransactionAttribute[0], - Inputs = new CoinReference[0], - Outputs = new[] - { - new TransactionOutput - { - AssetId = Blockchain.UtilityToken.Hash, - Value = snapshot.CalculateBonus(claims.Skip(i * MAX_CLAIMS_AMOUNT).Take(MAX_CLAIMS_AMOUNT)), - ScriptHash = change_address ?? current_wallet.GetChangeAddress() - } - } - }; - - if ((tx = (ClaimTransaction)SignTransaction(tx)) != null) - { - txs.Add(tx); - } - else - { - break; - } - } - - return txs.ToArray(); - } - } - - - private Transaction SignTransaction(Transaction tx) - { - if (tx == null) - { - Console.WriteLine($"no transaction specified"); - return null; - } - ContractParametersContext context; - - try - { - context = new ContractParametersContext(tx); - } - catch (InvalidOperationException) - { - Console.WriteLine($"unsynchronized block"); - - return null; - } - - current_wallet.Sign(context); - - if (context.Completed) - { - tx.Witnesses = context.GetWitnesses(); - current_wallet.ApplyTransaction(tx); - - bool relay_result = system.Blockchain.Ask(tx).Result == RelayResultReason.Succeed; - - if (relay_result) - { - return tx; - } - else - { - Console.WriteLine($"Local Node could not relay transaction: {tx.Hash.ToString()}"); - } - } - else - { - Console.WriteLine($"Incomplete Signature: {context.ToString()}"); - } - - return null; - } - } -} diff --git a/neo-cli/Shell/MainService.cs b/neo-cli/Shell/MainService.cs index cae19fb92..e166edf45 100644 --- a/neo-cli/Shell/MainService.cs +++ b/neo-cli/Shell/MainService.cs @@ -4,12 +4,14 @@ using Neo.IO.Json; using Neo.Ledger; using Neo.Network.P2P; +using Neo.Network.P2P.Capabilities; using Neo.Network.P2P.Payloads; using Neo.Persistence; using Neo.Persistence.LevelDB; using Neo.Plugins; using Neo.Services; using Neo.SmartContract; +using Neo.SmartContract.Native; using Neo.VM; using Neo.Wallets; using Neo.Wallets.NEP6; @@ -20,8 +22,8 @@ using System.IO.Compression; using System.Linq; using System.Net; +using System.Numerics; using System.Security.Cryptography; -using System.Text; using System.Threading.Tasks; using ECCurve = Neo.Cryptography.ECC.ECCurve; using ECPoint = Neo.Cryptography.ECC.ECPoint; @@ -76,8 +78,6 @@ protected override bool OnCommand(string[] args) return OnImportCommand(args); case "list": return OnListCommand(args); - case "claim": - return OnClaimCommand(args); case "open": return OnOpenCommand(args); case "close": @@ -107,28 +107,32 @@ protected override bool OnCommand(string[] args) private bool OnBroadcastCommand(string[] args) { - string command = args[1].ToLower(); + if (!Enum.TryParse(args[1], true, out MessageCommand command)) + { + Console.WriteLine($"Command \"{args[1]}\" is not supported."); + return true; + } ISerializable payload = null; switch (command) { - case "addr": - payload = AddrPayload.Create(NetworkAddressWithTime.Create(new IPEndPoint(IPAddress.Parse(args[2]), ushort.Parse(args[3])), NetworkAddressWithTime.NODE_NETWORK, DateTime.UtcNow.ToTimestamp())); + case MessageCommand.Addr: + payload = AddrPayload.Create(NetworkAddressWithTime.Create(IPAddress.Parse(args[2]), DateTime.UtcNow.ToTimestamp(), new FullNodeCapability(), new ServerCapability(NodeCapabilityType.TcpServer, ushort.Parse(args[3])))); break; - case "block": + case MessageCommand.Block: if (args[2].Length == 64 || args[2].Length == 66) payload = Blockchain.Singleton.GetBlock(UInt256.Parse(args[2])); else payload = Blockchain.Singleton.Store.GetBlock(uint.Parse(args[2])); break; - case "getblocks": - case "getheaders": + case MessageCommand.GetBlocks: + case MessageCommand.GetHeaders: payload = GetBlocksPayload.Create(UInt256.Parse(args[2])); break; - case "getdata": - case "inv": + case MessageCommand.GetData: + case MessageCommand.Inv: payload = InvPayload.Create(Enum.Parse(args[2], true), args.Skip(3).Select(UInt256.Parse).ToArray()); break; - case "tx": + case MessageCommand.Transaction: payload = Blockchain.Singleton.GetTransaction(UInt256.Parse(args[2])); break; default: @@ -142,44 +146,27 @@ private bool OnBroadcastCommand(string[] args) private bool OnDeployCommand(string[] args) { if (NoWallet()) return true; - var tx = LoadScriptTransaction( + byte[] script = LoadDeploymentScript( /* filePath */ args[1], - /* paramTypes */ args[2], - /* returnType */ args[3], - /* hasStorage */ args[4].ToBool(), - /* hasDynamicInvoke */ args[5].ToBool(), - /* isPayable */ args[6].ToBool(), - /* contractName */ args[7], - /* contractVersion */ args[8], - /* contractAuthor */ args[9], - /* contractEmail */ args[10], - /* contractDescription */ args[11], + /* hasStorage */ args[2].ToBool(), + /* isPayable */ args[3].ToBool(), /* scriptHash */ out var scriptHash); - tx.Version = 1; - if (tx.Attributes == null) tx.Attributes = new TransactionAttribute[0]; - if (tx.Inputs == null) tx.Inputs = new CoinReference[0]; - if (tx.Outputs == null) tx.Outputs = new TransactionOutput[0]; - if (tx.Witnesses == null) tx.Witnesses = new Witness[0]; - ApplicationEngine engine = ApplicationEngine.Run(tx.Script, tx, null, true); - StringBuilder sb = new StringBuilder(); - sb.AppendLine($"Script hash: {scriptHash.ToString()}"); - sb.AppendLine($"VM State: {engine.State}"); - sb.AppendLine($"Gas Consumed: {engine.GasConsumed}"); - sb.AppendLine( - $"Evaluation Stack: {new JArray(engine.ResultStack.Select(p => p.ToParameter().ToJson()))}"); - Console.WriteLine(sb.ToString()); - if (engine.State.HasFlag(VMState.FAULT)) + Transaction tx = new Transaction { Script = script }; + try + { + Program.Wallet.FillTransaction(tx); + } + catch (InvalidOperationException) { Console.WriteLine("Engine faulted."); return true; } + Console.WriteLine($"Script hash: {scriptHash.ToString()}"); + Console.WriteLine($"Gas: {tx.Gas}"); + Console.WriteLine(); - tx.Gas = engine.GasConsumed - Fixed8.FromDecimal(10); - if (tx.Gas < Fixed8.Zero) tx.Gas = Fixed8.Zero; - tx.Gas = tx.Gas.Ceiling(); - - tx = DecorateInvocationTransaction(tx); + DecorateInvocationTransaction(tx); return SignAndSendTx(tx); } @@ -199,53 +186,42 @@ private bool OnInvokeCommand(string[] args) }); } - ContractParameter[] parameters = + Transaction tx = new Transaction { - new ContractParameter - { - Type = ContractParameterType.String, - Value = args[2] - }, - new ContractParameter - { - Type = ContractParameterType.Array, - Value = contractParameters.ToArray() - } + Sender = UInt160.Zero, + Attributes = new TransactionAttribute[0], + Witnesses = new Witness[0] }; - var tx = new InvocationTransaction(); - using (ScriptBuilder scriptBuilder = new ScriptBuilder()) { - scriptBuilder.EmitAppCall(scriptHash, parameters); - Console.WriteLine($"Invoking script with: '{scriptBuilder.ToArray().ToHexString()}'"); + scriptBuilder.EmitAppCall(scriptHash, args[2], contractParameters.ToArray()); tx.Script = scriptBuilder.ToArray(); + Console.WriteLine($"Invoking script with: '{tx.Script.ToHexString()}'"); } - if (tx.Attributes == null) tx.Attributes = new TransactionAttribute[0]; - if (tx.Inputs == null) tx.Inputs = new CoinReference[0]; - if (tx.Outputs == null) tx.Outputs = new TransactionOutput[0]; - if (tx.Witnesses == null) tx.Witnesses = new Witness[0]; ApplicationEngine engine = ApplicationEngine.Run(tx.Script, tx); - StringBuilder sb = new StringBuilder(); - sb.AppendLine($"VM State: {engine.State}"); - sb.AppendLine($"Gas Consumed: {engine.GasConsumed}"); - sb.AppendLine( - $"Evaluation Stack: {new JArray(engine.ResultStack.Select(p => p.ToParameter().ToJson()))}"); - Console.WriteLine(sb.ToString()); + Console.WriteLine($"VM State: {engine.State}"); + Console.WriteLine($"Gas Consumed: {engine.GasConsumed}"); + Console.WriteLine($"Evaluation Stack: {new JArray(engine.ResultStack.Select(p => p.ToParameter().ToJson()))}"); + Console.WriteLine(); if (engine.State.HasFlag(VMState.FAULT)) { Console.WriteLine("Engine faulted."); return true; } if (NoWallet()) return true; - tx = DecorateInvocationTransaction(tx); - if (tx == null) + try + { + Program.Wallet.FillTransaction(tx); + } + catch (InvalidOperationException) { Console.WriteLine("error: insufficient balance."); return true; } + DecorateInvocationTransaction(tx); if (ReadUserInput("relay tx(no|yes)") != "yes") { return true; @@ -253,55 +229,31 @@ private bool OnInvokeCommand(string[] args) return SignAndSendTx(tx); } - public InvocationTransaction LoadScriptTransaction( - string avmFilePath, string paramTypes, string returnTypeHexString, - bool hasStorage, bool hasDynamicInvoke, bool isPayable, - string contractName, string contractVersion, string contractAuthor, - string contractEmail, string contractDescription, out UInt160 scriptHash) + private byte[] LoadDeploymentScript(string avmFilePath, bool hasStorage, bool isPayable, out UInt160 scriptHash) { byte[] script = File.ReadAllBytes(avmFilePath); - // See ContractParameterType Enum - byte[] parameterList = paramTypes.HexToBytes(); - ContractParameterType returnType = returnTypeHexString.HexToBytes() - .Select(p => (ContractParameterType?)p).FirstOrDefault() ?? ContractParameterType.Void; + scriptHash = script.ToScriptHash(); ContractPropertyState properties = ContractPropertyState.NoProperty; if (hasStorage) properties |= ContractPropertyState.HasStorage; - if (hasDynamicInvoke) properties |= ContractPropertyState.HasDynamicInvoke; if (isPayable) properties |= ContractPropertyState.Payable; using (ScriptBuilder sb = new ScriptBuilder()) { - scriptHash = script.ToScriptHash(); - - sb.EmitSysCall("Neo.Contract.Create", script, parameterList, returnType, properties, - contractName, contractVersion, contractAuthor, contractEmail, contractDescription); - return new InvocationTransaction - { - Script = sb.ToArray() - }; + sb.EmitSysCall(InteropService.Neo_Contract_Create, script, properties); + return sb.ToArray(); } } - public InvocationTransaction DecorateInvocationTransaction(InvocationTransaction tx) + public void DecorateInvocationTransaction(Transaction tx) { - Fixed8 fee = Fixed8.FromDecimal(0.001m); + tx.NetworkFee = 100000; if (tx.Size > 1024) { - fee += Fixed8.FromDecimal(tx.Size * 0.00001m); + tx.NetworkFee += tx.Size * 1000; } - - return Program.Wallet.MakeTransaction(new InvocationTransaction - { - Version = tx.Version, - Script = tx.Script, - Gas = tx.Gas, - Attributes = tx.Attributes, - Inputs = tx.Inputs, - Outputs = tx.Outputs - }, fee: fee); } - public bool SignAndSendTx(InvocationTransaction tx) + public bool SignAndSendTx(Transaction tx) { ContractParametersContext context; try @@ -603,17 +555,15 @@ private bool OnHelpCommand(string[] args) "\tlist address\n" + "\tlist asset\n" + "\tlist key\n" + - "\tshow utxo [id|alias]\n" + "\tshow gas\n" + - "\tclaim gas [all] [changeAddress]\n" + "\tcreate address [n=1]\n" + "\timport key \n" + "\texport key [address] [path]\n" + "\timport multisigaddress m pubkeys...\n" + - "\tsend
|all [fee=0]\n" + + "\tsend
[fee=0]\n" + "\tsign \n" + "Contract Commands:\n" + - "\tdeploy \n" + + "\tdeploy [optionally quoted params separated by space]\n" + "Node Commands:\n" + "\tshow state\n" + @@ -745,50 +695,16 @@ private bool OnListCommand(string[] args) } } - private bool OnClaimCommand(string[] args) + private bool OnShowGasCommand(string[] args) { - if (args.Length < 2 || args.Length > 4 || !args[1].Equals("gas", StringComparison.OrdinalIgnoreCase)) - return base.OnCommand(args); - if (NoWallet()) return true; - - bool all = args.Length > 2 && args[2].Equals("all", StringComparison.OrdinalIgnoreCase); - bool useChangeAddress = (all && args.Length == 4) || (!all && args.Length == 3); - UInt160 changeAddress = useChangeAddress ? args[args.Length - 1].ToScriptHash() : null; - - if (useChangeAddress) - { - string password = ReadUserInput("password", true); - if (password.Length == 0) - { - Console.WriteLine("cancelled"); - return true; - } - if (!Program.Wallet.VerifyPassword(password)) + BigInteger gas = BigInteger.Zero; + using (Snapshot snapshot = Blockchain.Singleton.GetSnapshot()) + foreach (UInt160 account in Program.Wallet.GetAccounts().Select(p => p.ScriptHash)) { - Console.WriteLine("Incorrect password"); - return true; + gas += NativeContract.NEO.UnclaimedGas(snapshot, account, snapshot.Height + 1); } - } - - Coins coins = new Coins(Program.Wallet, system); - ClaimTransaction[] txs = all - ? coins.ClaimAll(changeAddress) - : new[] { coins.Claim(changeAddress) }; - if (txs is null) return true; - foreach (ClaimTransaction tx in txs) - if (tx != null) - Console.WriteLine($"Transaction Succeeded: {tx.Hash}"); - return true; - } - - private bool OnShowGasCommand(string[] args) - { - if (NoWallet()) return true; - - Coins coins = new Coins(Program.Wallet, system); - Console.WriteLine($"unavailable: {coins.UnavailableBonus().ToString()}"); - Console.WriteLine($" available: {coins.AvailableBonus().ToString()}"); + Console.WriteLine($"unclaimed gas: {new BigDecimal(gas, NativeContract.GAS.Decimals)}"); return true; } @@ -815,19 +731,8 @@ private bool OnListAddressCommand(string[] args) private bool OnListAssetCommand(string[] args) { if (NoWallet()) return true; - foreach (var item in Program.Wallet.GetCoins().Where(p => !p.State.HasFlag(CoinState.Spent)).GroupBy(p => p.Output.AssetId, (k, g) => new - { - Asset = Blockchain.Singleton.Store.GetAssets().TryGet(k), - Balance = g.Sum(p => p.Output.Value), - Confirmed = g.Where(p => p.State.HasFlag(CoinState.Confirmed)).Sum(p => p.Output.Value) - })) - { - Console.WriteLine($" id:{item.Asset.AssetId}"); - Console.WriteLine($" name:{item.Asset.GetName()}"); - Console.WriteLine($" balance:{item.Balance}"); - Console.WriteLine($"confirmed:{item.Confirmed}"); - Console.WriteLine(); - } + Console.WriteLine($"NEO: {Program.Wallet.GetAvailable(NativeContract.NEO.Hash)}"); + Console.WriteLine($"GAS: {Program.Wallet.GetAvailable(NativeContract.GAS.Hash)}"); return true; } @@ -952,130 +857,73 @@ private bool OnSendCommand(string[] args) Console.WriteLine("Incorrect password"); return true; } - UIntBase assetId; + UInt160 assetId; switch (args[1].ToLower()) { case "neo": - case "ans": - assetId = Blockchain.GoverningToken.Hash; + assetId = NativeContract.NEO.Hash; break; case "gas": - case "anc": - assetId = Blockchain.UtilityToken.Hash; + assetId = NativeContract.GAS.Hash; break; default: - assetId = UIntBase.Parse(args[1]); + assetId = UInt160.Parse(args[1]); break; } - UInt160 scriptHash = args[2].ToScriptHash(); - bool isSendAll = string.Equals(args[3], "all", StringComparison.OrdinalIgnoreCase); + UInt160 to = args[2].ToScriptHash(); Transaction tx; - if (isSendAll) + AssetDescriptor descriptor = new AssetDescriptor(assetId); + if (!BigDecimal.TryParse(args[3], descriptor.Decimals, out BigDecimal amount) || amount.Sign <= 0) { - Coin[] coins = Program.Wallet.FindUnspentCoins().Where(p => p.Output.AssetId.Equals(assetId)).ToArray(); - tx = new ContractTransaction - { - Attributes = new TransactionAttribute[0], - Inputs = coins.Select(p => p.Reference).ToArray(), - Outputs = new[] - { - new TransactionOutput - { - AssetId = (UInt256)assetId, - Value = coins.Sum(p => p.Output.Value), - ScriptHash = scriptHash - } - } - }; - ContractParametersContext context = new ContractParametersContext(tx); - Program.Wallet.Sign(context); - if (context.Completed) - { - tx.Witnesses = context.GetWitnesses(); - Program.Wallet.ApplyTransaction(tx); - system.LocalNode.Tell(new LocalNode.Relay { Inventory = tx }); - Console.WriteLine($"TXID: {tx.Hash}"); - } - else - { - Console.WriteLine("SignatureContext:"); - Console.WriteLine(context.ToString()); - } + Console.WriteLine("Incorrect Amount Format"); + return true; } - else + long fee = 0; + if (args.Length >= 5) { - AssetDescriptor descriptor = new AssetDescriptor(assetId); - if (!BigDecimal.TryParse(args[3], descriptor.Decimals, out BigDecimal amount) || amount.Sign <= 0) + if (!BigDecimal.TryParse(args[4], NativeContract.GAS.Decimals, out BigDecimal f) || f.Sign < 0) { - Console.WriteLine("Incorrect Amount Format"); + Console.WriteLine("Incorrect Fee Format"); return true; } - Fixed8 fee = Fixed8.Zero; + fee = (long)f.Value; + } - if (args.Length >= 5) + tx = Program.Wallet.MakeTransaction(null, new[] + { + new TransferOutput { - if (!Fixed8.TryParse(args[4], out fee) || fee < Fixed8.Zero) - { - Console.WriteLine("Incorrect Fee Format"); - return true; - } + AssetId = assetId, + Value = amount, + ScriptHash = to } + }, net_fee: fee); - tx = Program.Wallet.MakeTransaction(null, new[] - { - new TransferOutput - { - AssetId = assetId, - Value = amount, - ScriptHash = scriptHash - } - }, fee: fee); - - if (tx == null) - { - Console.WriteLine("Insufficient funds"); - return true; - } + if (tx == null) + { + Console.WriteLine("Insufficient funds"); + return true; + } - ContractParametersContext context = new ContractParametersContext(tx); - Program.Wallet.Sign(context); - if (context.Completed) - { - tx.Witnesses = context.GetWitnesses(); - if (tx.Size > 1024) - { - Fixed8 calFee = Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m); - if (fee < calFee) - { - fee = calFee; - tx = Program.Wallet.MakeTransaction(null, new[] - { - new TransferOutput - { - AssetId = assetId, - Value = amount, - ScriptHash = scriptHash - } - }, fee: fee); - if (tx == null) - { - Console.WriteLine("Insufficient funds"); - return true; - } - context = new ContractParametersContext(tx); - Program.Wallet.Sign(context); - tx.Witnesses = context.GetWitnesses(); - } - } - Program.Wallet.ApplyTransaction(tx); - system.LocalNode.Tell(new LocalNode.Relay { Inventory = tx }); - Console.WriteLine($"TXID: {tx.Hash}"); - } - else + ContractParametersContext context = new ContractParametersContext(tx); + Program.Wallet.Sign(context); + if (context.Completed) + { + tx.Witnesses = context.GetWitnesses(); + if (tx.Size > 1024) { - Console.WriteLine("SignatureContext:"); - Console.WriteLine(context.ToString()); + long calFee = tx.Size * 1000 + 100000; + if (tx.NetworkFee < calFee) + tx.NetworkFee = calFee; } + Program.Wallet.ApplyTransaction(tx); + system.LocalNode.Tell(new LocalNode.Relay { Inventory = tx }); + Console.WriteLine($"TXID: {tx.Hash}"); + } + else + { + Console.WriteLine("SignatureContext:"); + Console.WriteLine(context.ToString()); } return true; @@ -1091,8 +939,6 @@ private bool OnShowCommand(string[] args) return OnShowPoolCommand(args); case "state": return OnShowStateCommand(args); - case "utxo": - return OnShowUtxoCommand(args); default: return base.OnCommand(args); } @@ -1136,7 +982,7 @@ private bool OnShowStateCommand(string[] args) foreach (RemoteNode node in LocalNode.Singleton.GetRemoteNodes().Take(Console.WindowHeight - 2).ToArray()) { WriteLineWithoutFlicker( - $" ip: {node.Remote.Address}\tport: {node.Remote.Port}\tlisten: {node.ListenerPort}\theight: {node.LastBlockIndex}"); + $" ip: {node.Remote.Address}\tport: {node.Remote.Port}\tlisten: {node.ListenerTcpPort}\theight: {node.LastBlockIndex}"); linesWritten++; } @@ -1153,39 +999,6 @@ private bool OnShowStateCommand(string[] args) return true; } - private bool OnShowUtxoCommand(string[] args) - { - if (NoWallet()) return true; - IEnumerable coins = Program.Wallet.FindUnspentCoins(); - if (args.Length >= 3) - { - UInt256 assetId; - switch (args[2].ToLower()) - { - case "neo": - case "ans": - assetId = Blockchain.GoverningToken.Hash; - break; - case "gas": - case "anc": - assetId = Blockchain.UtilityToken.Hash; - break; - default: - assetId = UInt256.Parse(args[2]); - break; - } - coins = coins.Where(p => p.Output.AssetId.Equals(assetId)); - } - Coin[] coins_array = coins.ToArray(); - const int MAX_SHOW = 100; - for (int i = 0; i < coins_array.Length && i < MAX_SHOW; i++) - Console.WriteLine($"{coins_array[i].Reference.PrevHash}:{coins_array[i].Reference.PrevIndex}"); - if (coins_array.Length > MAX_SHOW) - Console.WriteLine($"({coins_array.Length - MAX_SHOW} more)"); - Console.WriteLine($"total: {coins_array.Length} UTXOs"); - return true; - } - protected internal override void OnStart(string[] args) { bool useRPC = false; @@ -1200,12 +1013,14 @@ protected internal override void OnStart(string[] args) } store = new LevelDBStore(Path.GetFullPath(Settings.Default.Paths.Chain)); system = new NeoSystem(store); - system.StartNode( - port: Settings.Default.P2P.Port, - wsPort: Settings.Default.P2P.WsPort, - minDesiredConnections: Settings.Default.P2P.MinDesiredConnections, - maxConnections: Settings.Default.P2P.MaxConnections, - maxConnectionsPerAddress: Settings.Default.P2P.MaxConnectionsPerAddress); + system.StartNode(new ChannelsConfig + { + Tcp = new IPEndPoint(IPAddress.Any, Settings.Default.P2P.Port), + WebSocket = new IPEndPoint(IPAddress.Any, Settings.Default.P2P.WsPort), + MinDesiredConnections = Settings.Default.P2P.MinDesiredConnections, + MaxConnections = Settings.Default.P2P.MaxConnections, + MaxConnectionsPerAddress = Settings.Default.P2P.MaxConnectionsPerAddress + }); if (Settings.Default.UnlockWallet.IsActive) { try diff --git a/neo-cli/neo-cli.csproj b/neo-cli/neo-cli.csproj index 8fffbf63e..72d2a7c0a 100644 --- a/neo-cli/neo-cli.csproj +++ b/neo-cli/neo-cli.csproj @@ -28,7 +28,7 @@ - + diff --git a/neo-cli/protocol.json b/neo-cli/protocol.json index c37ec0400..0f73e299f 100644 --- a/neo-cli/protocol.json +++ b/neo-cli/protocol.json @@ -1,6 +1,6 @@ { "ProtocolConfiguration": { - "Magic": 7630401, + "Magic": 5195086, "AddressVersion": 23, "SecondsPerBlock": 15, "LowPriorityThreshold": 0.001, @@ -29,12 +29,6 @@ "seed3.neo.org:10333", "seed4.neo.org:10333", "seed5.neo.org:10333" - ], - "SystemFee": { - "EnrollmentTransaction": 1000, - "IssueTransaction": 500, - "PublishTransaction": 500, - "RegisterTransaction": 10000 - } + ] } } diff --git a/neo-cli/protocol.mainnet.json b/neo-cli/protocol.mainnet.json index c37ec0400..0f73e299f 100644 --- a/neo-cli/protocol.mainnet.json +++ b/neo-cli/protocol.mainnet.json @@ -1,6 +1,6 @@ { "ProtocolConfiguration": { - "Magic": 7630401, + "Magic": 5195086, "AddressVersion": 23, "SecondsPerBlock": 15, "LowPriorityThreshold": 0.001, @@ -29,12 +29,6 @@ "seed3.neo.org:10333", "seed4.neo.org:10333", "seed5.neo.org:10333" - ], - "SystemFee": { - "EnrollmentTransaction": 1000, - "IssueTransaction": 500, - "PublishTransaction": 500, - "RegisterTransaction": 10000 - } + ] } } diff --git a/neo-cli/protocol.testnet.json b/neo-cli/protocol.testnet.json index 9384d0b7c..b55ed05ce 100644 --- a/neo-cli/protocol.testnet.json +++ b/neo-cli/protocol.testnet.json @@ -1,6 +1,6 @@ { "ProtocolConfiguration": { - "Magic": 1953787457, + "Magic": 1414481230, "AddressVersion": 23, "SecondsPerBlock": 15, "LowPriorityThreshold": 0, @@ -29,12 +29,6 @@ "seed3.neo.org:20333", "seed4.neo.org:20333", "seed5.neo.org:20333" - ], - "SystemFee": { - "EnrollmentTransaction": 10, - "IssueTransaction": 5, - "PublishTransaction": 5, - "RegisterTransaction": 100 - } + ] } }