Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
Rebase + fix rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Thacryba committed Mar 31, 2020
1 parent a1535a1 commit 8ebb90c
Show file tree
Hide file tree
Showing 17 changed files with 181 additions and 1,187 deletions.
16 changes: 9 additions & 7 deletions neo-cli/CLI/MainService.Blockchain.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Neo.CommandParser;
using Neo.ConsoleService;
using Neo.Ledger;
using System;

Expand All @@ -12,10 +12,14 @@ partial class MainService
/// <param name="start">Start</param>
/// <param name="count">Number of blocks</param>
/// <param name="path">Path</param>
[ConsoleCommand("export", "blocks", HelpCategory = "Blockchain Commands")]
private void OnExportBlocksStartCountCommand(uint start, uint count, string path = null)
[ConsoleCommand("export blocks", Category = "Blockchain Commands")]
private void OnExportBlocksStartCountCommand(uint start, uint count = uint.MaxValue, string path = null)
{
if (Blockchain.Singleton.Height < start) return;
if (Blockchain.Singleton.Height < start)
{
Console.WriteLine("error: invalid start height.");
return;
}

count = Math.Min(count, Blockchain.Singleton.Height - start + 1);

Expand All @@ -24,9 +28,7 @@ private void OnExportBlocksStartCountCommand(uint start, uint count, string path
path = $"chain.{start}.acc";
}

var writeStart = true;

WriteBlocks(start, count, path, writeStart);
WriteBlocks(start, count, path, true);
}
}
}
15 changes: 2 additions & 13 deletions neo-cli/CLI/MainService.Consensus.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
using Akka.Actor;
using Neo.CommandParser;
using Neo.Consensus;
using Neo.ConsoleService;

namespace Neo.CLI
{
partial class MainService
{
/// <summary>
/// Process "change view" command
/// </summary>
[ConsoleCommand("change", "view", HelpCategory = "Consensus Commands")]
private void OnChangeViewCommand(byte viewnumber)
{
NeoSystem.Consensus?.Tell(new ConsensusService.SetViewNumber { ViewNumber = viewnumber });
}

/// <summary>
/// Process "start consensus" command
/// </summary>
[ConsoleCommand("start", "consensus", HelpCategory = "Consensus Commands")]
[ConsoleCommand("start consensus", Category = "Consensus Commands")]
private void OnStartConsensusCommand()
{
if (NoWallet()) return;
Expand Down
52 changes: 42 additions & 10 deletions neo-cli/CLI/MainService.Contracts.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using Neo.CommandParser;
using Neo.ConsoleService;
using Neo.IO.Json;
using Neo.Ledger;
using Neo.Network.P2P.Payloads;
using Neo.Persistence;
using Neo.SmartContract;
using Neo.SmartContract.Native;
using Neo.VM;
using System;
using System.Collections.Generic;
Expand All @@ -16,7 +19,7 @@ partial class MainService
/// </summary>
/// <param name="filePath">File path</param>
/// <param name="manifestPath">Manifest path</param>
[ConsoleCommand("deploy", HelpCategory = "Contract Commands")]
[ConsoleCommand("deploy", Category = "Contract Commands")]
private void OnDeployCommand(string filePath, string manifestPath = null)
{
if (NoWallet()) return;
Expand All @@ -33,7 +36,7 @@ private void OnDeployCommand(string filePath, string manifestPath = null)
return;
}
Console.WriteLine($"Script hash: {scriptHash.ToString()}");
Console.WriteLine($"Gas: {tx.SystemFee}");
Console.WriteLine($"Gas: {new BigDecimal(tx.SystemFee, NativeContract.GAS.Decimals)}");
Console.WriteLine();
SignAndSendTx(tx);
}
Expand All @@ -44,21 +47,50 @@ private void OnDeployCommand(string filePath, string manifestPath = null)
/// <param name="scriptHash">Script hash</param>
/// <param name="operation">Operation</param>
/// <param name="contractParameters">Contract parameters</param>
[ConsoleCommand("invoke", HelpCategory = "Contract Commands")]
private void OnInvokeCommand(UInt160 scriptHash, string operation, [CaptureWholeArgument] JArray contractParameters)
/// <param name="witnessAddress">Witness address</param>
[ConsoleCommand("invoke", Category = "Contract Commands")]
private void OnInvokeCommand(UInt160 scriptHash, string operation, JArray contractParameters = null, UInt160[] witnessAddress = null)
{
List<ContractParameter> parameters = new List<ContractParameter>();
foreach (var contractParameter in contractParameters)
List<Cosigner> signCollection = new List<Cosigner>();

if (!NoWallet() && witnessAddress != null)
{
using (SnapshotView snapshot = Blockchain.Singleton.GetSnapshot())
{
UInt160[] accounts = CurrentWallet.GetAccounts().Where(p => !p.Lock && !p.WatchOnly).Select(p => p.ScriptHash).Where(p => NativeContract.GAS.BalanceOf(snapshot, p).Sign > 0).ToArray();
foreach (var signAccount in accounts)
{
if (witnessAddress is null)
{
break;
}
foreach (var witness in witnessAddress)
{
if (witness.Equals(signAccount))
{
signCollection.Add(new Cosigner() { Account = signAccount });
break;
}
}
}
}
}

if (contractParameters != null)
{
parameters.Add(ContractParameter.FromJson(contractParameter));
foreach (var contractParameter in contractParameters)
{
parameters.Add(ContractParameter.FromJson(contractParameter));
}
}

Transaction tx = new Transaction
{
Sender = UInt160.Zero,
Attributes = Array.Empty<TransactionAttribute>(),
Witnesses = Array.Empty<Witness>(),
Cosigners = Array.Empty<Cosigner>()
Cosigners = signCollection.ToArray()
};

using (ScriptBuilder scriptBuilder = new ScriptBuilder())
Expand All @@ -71,7 +103,7 @@ private void OnInvokeCommand(UInt160 scriptHash, string operation, [CaptureWhole
using (ApplicationEngine engine = ApplicationEngine.Run(tx.Script, tx, testMode: true))
{
Console.WriteLine($"VM State: {engine.State}");
Console.WriteLine($"Gas Consumed: {engine.GasConsumed}");
Console.WriteLine($"Gas Consumed: {new BigDecimal(engine.GasConsumed, NativeContract.GAS.Decimals)}");
Console.WriteLine($"Evaluation Stack: {new JArray(engine.ResultStack.Select(p => p.ToParameter().ToJson()))}");
Console.WriteLine();
if (engine.State.HasFlag(VMState.FAULT))
Expand All @@ -84,7 +116,7 @@ private void OnInvokeCommand(UInt160 scriptHash, string operation, [CaptureWhole
if (NoWallet()) return;
try
{
tx = CurrentWallet.MakeTransaction(tx.Script);
tx = CurrentWallet.MakeTransaction(tx.Script, null, tx.Attributes, tx.Cosigners);
}
catch (InvalidOperationException)
{
Expand Down
28 changes: 14 additions & 14 deletions neo-cli/CLI/MainService.Network.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Akka.Actor;
using Neo.CommandParser;
using Neo.ConsoleService;
using Neo.IO;
using Neo.IO.Json;
using Neo.Ledger;
Expand All @@ -19,7 +19,7 @@ partial class MainService
/// </summary>
/// <param name="payload">Payload</param>
/// <param name="port">Port</param>
[ConsoleCommand("broadcast", "addr", HelpCategory = "Network Commands")]
[ConsoleCommand("broadcast addr", Category = "Network Commands")]
private void OnBroadcastAddressCommand(IPAddress payload, ushort port)
{
if (payload == null)
Expand All @@ -41,7 +41,7 @@ private void OnBroadcastAddressCommand(IPAddress payload, ushort port)
/// Process "broadcast block" command
/// </summary>
/// <param name="hash">Hash</param>
[ConsoleCommand("broadcast", "block", HelpCategory = "Network Commands")]
[ConsoleCommand("broadcast block", Category = "Network Commands")]
private void OnBroadcastGetBlocksByHashCommand(UInt256 hash)
{
OnBroadcastCommand(MessageCommand.Block, Blockchain.Singleton.GetBlock(hash));
Expand All @@ -50,18 +50,18 @@ private void OnBroadcastGetBlocksByHashCommand(UInt256 hash)
/// <summary>
/// Process "broadcast block" command
/// </summary>
/// <param name="block">Block</param>
[ConsoleCommand("broadcast", "block", HelpCategory = "Network Commands")]
private void OnBroadcastGetBlocksByHeightCommand(uint block)
/// <param name="height">Block index</param>
[ConsoleCommand("broadcast block", Category = "Network Commands")]
private void OnBroadcastGetBlocksByHeightCommand(uint height)
{
OnBroadcastCommand(MessageCommand.Block, Blockchain.Singleton.GetBlock(block));
OnBroadcastCommand(MessageCommand.Block, Blockchain.Singleton.GetBlock(height));
}

/// <summary>
/// Process "broadcast getblocks" command
/// </summary>
/// <param name="hash">Hash</param>
[ConsoleCommand("broadcast", "getblocks", HelpCategory = "Network Commands")]
[ConsoleCommand("broadcast getblocks", Category = "Network Commands")]
private void OnBroadcastGetBlocksCommand(UInt256 hash)
{
OnBroadcastCommand(MessageCommand.GetBlocks, GetBlocksPayload.Create(hash));
Expand All @@ -71,7 +71,7 @@ private void OnBroadcastGetBlocksCommand(UInt256 hash)
/// Process "broadcast getheaders" command
/// </summary>
/// <param name="hash">Hash</param>
[ConsoleCommand("broadcast", "getheaders", HelpCategory = "Network Commands")]
[ConsoleCommand("broadcast getheaders", Category = "Network Commands")]
private void OnBroadcastGetHeadersCommand(UInt256 hash)
{
OnBroadcastCommand(MessageCommand.GetHeaders, GetBlocksPayload.Create(hash));
Expand All @@ -82,7 +82,7 @@ private void OnBroadcastGetHeadersCommand(UInt256 hash)
/// </summary>
/// <param name="type">Type</param>
/// <param name="payload">Payload</param>
[ConsoleCommand("broadcast", "getdata", HelpCategory = "Network Commands")]
[ConsoleCommand("broadcast getdata", Category = "Network Commands")]
private void OnBroadcastGetDataCommand(InventoryType type, UInt256[] payload)
{
OnBroadcastCommand(MessageCommand.GetData, InvPayload.Create(type, payload));
Expand All @@ -93,7 +93,7 @@ private void OnBroadcastGetDataCommand(InventoryType type, UInt256[] payload)
/// </summary>
/// <param name="type">Type</param>
/// <param name="payload">Payload</param>
[ConsoleCommand("broadcast", "inv", HelpCategory = "Network Commands")]
[ConsoleCommand("broadcast inv", Category = "Network Commands")]
private void OnBroadcastInvCommand(InventoryType type, UInt256[] payload)
{
OnBroadcastCommand(MessageCommand.Inv, InvPayload.Create(type, payload));
Expand All @@ -103,7 +103,7 @@ private void OnBroadcastInvCommand(InventoryType type, UInt256[] payload)
/// Process "broadcast transaction" command
/// </summary>
/// <param name="hash">Hash</param>
[ConsoleCommand("broadcast", "transaction", HelpCategory = "Network Commands")]
[ConsoleCommand("broadcast transaction", Category = "Network Commands")]
private void OnBroadcastTransactionCommand(UInt256 hash)
{
OnBroadcastCommand(MessageCommand.Transaction, Blockchain.Singleton.GetTransaction(hash));
Expand All @@ -118,8 +118,8 @@ private void OnBroadcastCommand(MessageCommand command, ISerializable ret)
/// Process "relay" command
/// </summary>
/// <param name="jsonObjectToRelay">Json object</param>
[ConsoleCommand("relay", HelpCategory = "Network Commands")]
private void OnRelayCommand([CaptureWholeArgument] JObject jsonObjectToRelay)
[ConsoleCommand("relay", Category = "Network Commands")]
private void OnRelayCommand(JObject jsonObjectToRelay)
{
if (jsonObjectToRelay == null)
{
Expand Down
6 changes: 3 additions & 3 deletions neo-cli/CLI/MainService.Node.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Akka.Actor;
using Neo.CommandParser;
using Neo.ConsoleService;
using Neo.Ledger;
using Neo.Network.P2P;
using Neo.Network.P2P.Payloads;
Expand All @@ -16,7 +16,7 @@ partial class MainService
/// <summary>
/// Process "show pool" command
/// </summary>
[ConsoleCommand("show", "pool", HelpCategory = "Node Commands", HelpMessage = "Show the current state of the mempool")]
[ConsoleCommand("show pool", Category = "Node Commands", Description = "Show the current state of the mempool")]
private void OnShowPoolCommand(bool verbose = false)
{
if (verbose)
Expand All @@ -37,7 +37,7 @@ private void OnShowPoolCommand(bool verbose = false)
/// <summary>
/// Process "show state" command
/// </summary>
[ConsoleCommand("show", "state", HelpCategory = "Node Commands", HelpMessage = "Show the current state of the node")]
[ConsoleCommand("show state", Category = "Node Commands", Description = "Show the current state of the node")]
private void OnShowStateCommand()
{
var cancel = new CancellationTokenSource();
Expand Down
8 changes: 4 additions & 4 deletions neo-cli/CLI/MainService.Plugins.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Neo.CommandParser;
using Neo.ConsoleService;
using Neo.Plugins;
using System;
using System.IO;
Expand All @@ -14,7 +14,7 @@ partial class MainService
/// Process "install" command
/// </summary>
/// <param name="pluginName">Plugin name</param>
[ConsoleCommand("install", HelpCategory = "Plugin Commands")]
[ConsoleCommand("install", Category = "Plugin Commands")]
private void OnInstallCommand(string pluginName)
{
bool isTemp;
Expand Down Expand Up @@ -68,7 +68,7 @@ private void OnInstallCommand(string pluginName)
/// Process "uninstall" command
/// </summary>
/// <param name="pluginName">Plugin name</param>
[ConsoleCommand("uninstall", HelpCategory = "Plugin Commands")]
[ConsoleCommand("uninstall", Category = "Plugin Commands")]
private void OnUnInstallCommand(string pluginName)
{
var plugin = Plugin.Plugins.FirstOrDefault(p => p.Name == pluginName);
Expand All @@ -93,7 +93,7 @@ private void OnUnInstallCommand(string pluginName)
/// <summary>
/// Process "plugins" command
/// </summary>
[ConsoleCommand("plugins", HelpCategory = "Plugin Commands")]
[ConsoleCommand("plugins", Category = "Plugin Commands")]
private void OnPluginsCommand()
{
if (Plugin.Plugins.Count > 0)
Expand Down
10 changes: 5 additions & 5 deletions neo-cli/CLI/MainService.Show.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using Neo.CommandParser;
using Neo.ConsoleService;
using Neo.Ledger;
using Neo.Network.P2P.Payloads;
using Neo.SmartContract;
Expand All @@ -16,7 +16,7 @@ partial class MainService
/// </summary>
/// <param name="desiredCount"></param>
/// <returns></returns>
[ConsoleCommand("show", "last-transactions", HelpCategory = "Show Commands")]
[ConsoleCommand("show last-transactions", Category = "Show Commands")]
private void OnShowLastTransactions(uint desiredCount)
{
if (desiredCount < 1)
Expand Down Expand Up @@ -71,7 +71,7 @@ private void OnShowLastTransactions(uint desiredCount)
/// </summary>
/// <param name="contractHash"></param>
/// <returns></returns>
[ConsoleCommand("show", "contract", HelpCategory = "Show Commands")]
[ConsoleCommand("show contract", Category = "Show Commands")]
private void OnShowContract(string contractHash)
{
if (knownSmartContracts.ContainsKey(contractHash))
Expand Down Expand Up @@ -148,7 +148,7 @@ private string ToCLIString(ContractState c)
/// </summary>
/// <param name="transactionHash"></param>
/// <returns></returns>
[ConsoleCommand("show", "transaction", HelpCategory = "Show Commands")]
[ConsoleCommand("show transaction", Category = "Show Commands")]
private void OnShowTransaction(UInt256 transactionHash)
{
using (var snapshot = Blockchain.Singleton.GetSnapshot())
Expand Down Expand Up @@ -200,7 +200,7 @@ private string ToCLIString(Transaction t, ulong blockTimestamp = 0)
/// </summary>
/// <param name="blockHashOrId"></param>
/// <returns></returns>
[ConsoleCommand("show", "block", HelpCategory = "Show Commands")]
[ConsoleCommand("show block", Category = "Show Commands")]
private void OnShowBlock(string blockHashOrId)
{
if (UInt256.TryParse(blockHashOrId, out var blockHash))
Expand Down
Loading

0 comments on commit 8ebb90c

Please sign in to comment.