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

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon committed Nov 15, 2023
1 parent 08a3904 commit 8b735c6
Showing 1 changed file with 38 additions and 21 deletions.
59 changes: 38 additions & 21 deletions neo-cli/CLI/MainService.Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private void OnExportBlocksStartCountCommand(uint start, uint count = uint.MaxVa
}

[ConsoleCommand("show block", Category = "Blockchain Commands")]
private void OnPrintBlockCommand(string indexOrHash)
private void OnShowBlockCommand(string indexOrHash)
{
Block block = null;

Expand All @@ -63,7 +63,7 @@ private void OnPrintBlockCommand(string indexOrHash)
return;
}

if (block == null)
if (block is null)
{
ConsoleHelper.Error($"Block {indexOrHash} doesn't exist.");
return;
Expand All @@ -85,32 +85,37 @@ private void OnPrintBlockCommand(string indexOrHash)
ConsoleHelper.Info("", " Version: ", $"{block.Version}");
ConsoleHelper.Info("", " Size: ", $"{block.Size} Byte(s)");
ConsoleHelper.Info();

ConsoleHelper.Info("", "-------------", "Witness", "-------------");
ConsoleHelper.Info();
ConsoleHelper.Info("", " Invocation Script: ", $"{Convert.ToBase64String(block.Witness.InvocationScript.Span)}");
ConsoleHelper.Info("", " Verification Script: ", $"{Convert.ToBase64String(block.Witness.VerificationScript.Span)}");
ConsoleHelper.Info("", " ScriptHash: ", $"{block.Witness.ScriptHash}");
ConsoleHelper.Info("", " Size: ", $"{block.Witness.Size} Byte(s)");
ConsoleHelper.Info();

ConsoleHelper.Info("", "-------------", "Transactions", "-------------");
ConsoleHelper.Info();

if (block.Transactions.Length == 0)
{
ConsoleHelper.Info("", " No Transaction(s)");

foreach (var tx in block.Transactions)
ConsoleHelper.Info($" {tx.Hash}");
}
else
{
foreach (var tx in block.Transactions)
ConsoleHelper.Info($" {tx.Hash}");
}
ConsoleHelper.Info();
ConsoleHelper.Info("", "--------------------------------------");

}

[ConsoleCommand("show tx", Category = "Blockchain Commands")]
public void OnPrintTransactionCommand(UInt256 hash)
public void OnShowTransactionCommand(UInt256 hash)
{
var tx = NativeContract.Ledger.GetTransactionState(_neoSystem.StoreView, hash);

if (tx == null)
if (tx is null)
{
ConsoleHelper.Error($"Transaction {hash} doesn't exist.");
return;
Expand All @@ -137,8 +142,10 @@ public void OnPrintTransactionCommand(UInt256 hash)
ConsoleHelper.Info("", " BlockHash: ", $"{block.Hash}");
ConsoleHelper.Info("", " Size: ", $"{tx.Transaction.Size} Byte(s)");
ConsoleHelper.Info();

ConsoleHelper.Info("", "-------------", "Signers", "-------------");
ConsoleHelper.Info();

foreach (var signer in tx.Transaction.Signers)
{
if (signer.Rules.Length == 0)
Expand All @@ -158,6 +165,7 @@ public void OnPrintTransactionCommand(UInt256 hash)
ConsoleHelper.Info("", " Size: ", $"{signer.Size} Byte(s)");
ConsoleHelper.Info();
}

ConsoleHelper.Info("", "-------------", "Witnesses", "-------------");
ConsoleHelper.Info();
foreach (var witness in tx.Transaction.Witnesses)
Expand All @@ -168,25 +176,28 @@ public void OnPrintTransactionCommand(UInt256 hash)
ConsoleHelper.Info("", " Size: ", $"{witness.Size} Byte(s)");
ConsoleHelper.Info();
}

ConsoleHelper.Info("", "-------------", "Attributes", "-------------");
ConsoleHelper.Info();
if (tx.Transaction.Attributes.Length == 0)
{
ConsoleHelper.Info("", " No Attribute(s).");
ConsoleHelper.Info();
}
foreach (var attribute in tx.Transaction.Attributes)
else
{
ConsoleHelper.Info("", " Type: ", $"{attribute.Type}");
ConsoleHelper.Info("", " AllowMultiple: ", $"{attribute.AllowMultiple}");
ConsoleHelper.Info("", " Size: ", $"{attribute.Size} Byte(s)");
ConsoleHelper.Info();
foreach (var attribute in tx.Transaction.Attributes)
{
ConsoleHelper.Info("", " Type: ", $"{attribute.Type}");
ConsoleHelper.Info("", " AllowMultiple: ", $"{attribute.AllowMultiple}");
ConsoleHelper.Info("", " Size: ", $"{attribute.Size} Byte(s)");
}
}
ConsoleHelper.Info();
ConsoleHelper.Info("", "--------------------------------------");
}

[ConsoleCommand("show contract", Category = "Blockchain Commands")]
public void OnPrintContractCommand(string nameOrHash)
public void OnShowContractCommand(string nameOrHash)
{
ContractState contract = null;

Expand All @@ -200,7 +211,7 @@ public void OnPrintContractCommand(string nameOrHash)
contract = NativeContract.ContractManagement.GetContract(_neoSystem.StoreView, nativeContract.Hash);
}

if (contract == null)
if (contract is null)
{
ConsoleHelper.Error($"Contract {nameOrHash} doesn't exist.");
return;
Expand All @@ -225,19 +236,23 @@ public void OnPrintContractCommand(string nameOrHash)
}
}
ConsoleHelper.Info();

ConsoleHelper.Info("", "-------------", "Groups", "-------------");
ConsoleHelper.Info();
if (contract.Manifest.Groups.Length == 0)
{
ConsoleHelper.Info("", " No Group(s).");
ConsoleHelper.Info();
}
foreach (var group in contract.Manifest.Groups)
else
{
ConsoleHelper.Info("", " PubKey: ", $"{group.PubKey}");
ConsoleHelper.Info("", " Signature: ", $"{Convert.ToBase64String(group.Signature)}");
ConsoleHelper.Info();
foreach (var group in contract.Manifest.Groups)
{
ConsoleHelper.Info("", " PubKey: ", $"{group.PubKey}");
ConsoleHelper.Info("", " Signature: ", $"{Convert.ToBase64String(group.Signature)}");
}
}
ConsoleHelper.Info();

ConsoleHelper.Info("", "-------------", "Permissions", "-------------");
ConsoleHelper.Info();
foreach (var permission in contract.Manifest.Permissions)
Expand All @@ -249,6 +264,7 @@ public void OnPrintContractCommand(string nameOrHash)
ConsoleHelper.Info("", " Methods: ", $"{string.Join(", ", permission.Methods)}");
ConsoleHelper.Info();
}

ConsoleHelper.Info("", "-------------", "Methods", "-------------");
ConsoleHelper.Info();
foreach (var method in contract.Manifest.Abi.Methods)
Expand All @@ -260,6 +276,7 @@ public void OnPrintContractCommand(string nameOrHash)
ConsoleHelper.Info("", " ReturnType: ", $"{method.ReturnType}");
ConsoleHelper.Info();
}

ConsoleHelper.Info("", "-------------", "Script", "-------------");
ConsoleHelper.Info();
ConsoleHelper.Info($" {Convert.ToBase64String(contract.Nef.Script.Span)}");
Expand Down

0 comments on commit 8b735c6

Please sign in to comment.