Skip to content

Commit

Permalink
update to v3.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashuaidehao committed Jun 6, 2022
1 parent 1c7d4df commit 8e8cf7f
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 31 deletions.
2 changes: 1 addition & 1 deletion neo
Submodule neo updated 292 files
18 changes: 15 additions & 3 deletions neo3-gui/neo3-gui/Common/Analyzers/ExecuteResultLogTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,25 @@
namespace Neo.Common.Analyzers
{

public class ExecuteResultLogTracker : Plugin, IPersistencePlugin
public class ExecuteResultLogTracker : Plugin
{
private readonly LevelDbContext _levelDb = new LevelDbContext();

private readonly HashSet<UInt160> _cachedAssets = new HashSet<UInt160>();

void IPersistencePlugin.OnPersist(NeoSystem system, Block block, DataCache snapshot, IReadOnlyList<Blockchain.ApplicationExecuted> applicationExecutedList)
public ExecuteResultLogTracker()
{
Blockchain.Committing += OnCommitting;
Blockchain.Committed += OnCommitted;
}

public override void Dispose()
{
Blockchain.Committing -= OnCommitting;
Blockchain.Committed -= OnCommitted;
}

void OnCommitting(NeoSystem system, Block block, DataCache snapshot, IReadOnlyList<Blockchain.ApplicationExecuted> applicationExecutedList)
{
Header header = snapshot.GetCurrentHeader();
var analyzer = new BlockAnalyzer(snapshot, header, applicationExecutedList);
Expand Down Expand Up @@ -59,7 +71,7 @@ void IPersistencePlugin.OnPersist(NeoSystem system, Block block, DataCache snaps
}


void IPersistencePlugin.OnCommit(NeoSystem system, Block block, DataCache snapshot)
void OnCommitted(NeoSystem system, Block block)
{
_levelDb.Commit();
}
Expand Down
8 changes: 3 additions & 5 deletions neo3-gui/neo3-gui/Common/Consoles/MainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ public void CreateWallet(string path, string password)
break;
case ".json":
{
NEP6Wallet wallet = new NEP6Wallet(path, CliSettings.Default.Protocol);
wallet.Unlock(password);
NEP6Wallet wallet = new NEP6Wallet(path, password, CliSettings.Default.Protocol);
WalletAccount account = wallet.CreateAccount();
wallet.Save();
Console.WriteLine($"address: {account.Address}");
Expand Down Expand Up @@ -306,7 +305,7 @@ private bool OnInvokeCommand(string[] args)
{
scriptBuilder.EmitDynamicCall(scriptHash, args[2], contractParameters.ToArray());
tx.Script = scriptBuilder.ToArray();
Console.WriteLine($"Invoking script with: '{tx.Script.ToHexString()}'");
Console.WriteLine($"Invoking script with: '{tx.Script.ToArray().ToHexString()}'");
}

using (ApplicationEngine engine = tx.Script.RunTestMode(null, tx))
Expand Down Expand Up @@ -1261,8 +1260,7 @@ public void OpenWallet(string path, string password)
}
else
{
NEP6Wallet nep6wallet = new NEP6Wallet(path, CliSettings.Default.Protocol);
nep6wallet.Unlock(password);
NEP6Wallet nep6wallet = new NEP6Wallet(path, password, CliSettings.Default.Protocol);
CurrentWallet = nep6wallet;
}
}
Expand Down
13 changes: 10 additions & 3 deletions neo3-gui/neo3-gui/Common/Utility/OpCodeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class OpCodeConverter
static OpCodeConverter()
{
//初始化所有 InteropService Method
_interopServiceMap = ApplicationEngine.Services.ToDictionary(s=>s.Key,s=>s.Value.Name);
_interopServiceMap = ApplicationEngine.Services.ToDictionary(s => s.Key, s => s.Value.Name);
//初始化所有 OpCode OperandSize
foreach (FieldInfo field in typeof(OpCode).GetFields(BindingFlags.Public | BindingFlags.Static))
{
Expand All @@ -39,6 +39,13 @@ public static string ToAsciiString(byte[] byteArray)
if (output.Any(p => p < '0' || p > 'z')) return byteArray.ToHexString();
return output;
}


public static List<InstructionInfo> Parse(ReadOnlyMemory<byte> scripts)
{
return Parse(scripts.ToArray());
}

public static List<InstructionInfo> Parse(byte[] scripts)
{
var result = new List<InstructionInfo>();
Expand All @@ -50,7 +57,7 @@ public static List<InstructionInfo> Parse(byte[] scripts)
var instruction = s.GetInstruction(ip);

var instructionInfo = new InstructionInfo()
{OpCode = instruction.OpCode, Position = ip, OpData = instruction.Operand.ToArray()};
{ OpCode = instruction.OpCode, Position = ip, OpData = instruction.Operand.ToArray() };

if (instruction.OpCode == OpCode.SYSCALL)
{
Expand All @@ -68,7 +75,7 @@ public static List<InstructionInfo> Parse(byte[] scripts)
{
Console.WriteLine($"{scripts.ToHexString()}:{e}");
}

return result;
}

Expand Down
52 changes: 50 additions & 2 deletions neo3-gui/neo3-gui/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
using VmArray = Neo.VM.Types.Array;
using JsonSerializer = System.Text.Json.JsonSerializer;
using Pointer = Neo.VM.Types.Pointer;
using Neo.SmartContract.Iterators;

namespace Neo
{
Expand All @@ -55,7 +56,7 @@ public static class Helpers
public static readonly JsonSerializerOptions SerializeOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
IgnoreNullValues = true,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
PropertyNameCaseInsensitive = true,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
Converters =
Expand Down Expand Up @@ -628,7 +629,7 @@ public static AccountType GetAccountType(this WalletAccount account, DataCache s
{
if (account.Contract != null)
{
if (account.Contract.Script.IsMultiSigContract(out _, out int _))
if (account.Contract.Script.IsMultiSigContract())
{
return AccountType.MultiSignature;
}
Expand Down Expand Up @@ -1179,6 +1180,12 @@ public static NotificationInfo ToNotificationInfo(this NotifyEventArgs notify)
return notification;
}

public static ApplicationEngine RunTestMode(this ReadOnlyMemory<byte> script, DataCache snapshot, IVerifiable container = null)
{
return ApplicationEngine.Run(script, snapshot ?? GetDefaultSnapshot(), container, settings: CliSettings.Default.Protocol, gas: Constant.TestMode);
}


public static ApplicationEngine RunTestMode(this byte[] script, DataCache snapshot, IVerifiable container = null)
{
return ApplicationEngine.Run(script, snapshot ?? GetDefaultSnapshot(), container, settings: CliSettings.Default.Protocol, gas: Constant.TestMode);
Expand Down Expand Up @@ -1427,5 +1434,46 @@ public static string ToBase64String(this ReadOnlySpan<byte> data)
{
return data.ToArray().ToBase64String();
}

public static string ToBase64String(this Memory<byte> data)
{
return data.ToArray().ToBase64String();
}


public static bool IsSignatureContract(this byte[] script)
{
return Neo.SmartContract.Helper.IsSignatureContract(script);
}

public static bool IsMultiSigContract(this byte[] script)
{
return Neo.SmartContract.Helper.IsMultiSigContract(script);
}


public static (ECPoint PublicKey, BigInteger Votes)[] GetCandidates(this DataCache snapshot)
{
var sb = new ScriptBuilder();
sb.EmitDynamicCall(NativeContract.NEO.Hash, "getCandidates");
var engine = sb.ToArray().RunTestMode(snapshot);
var array = engine.ResultStack.Pop() as VmArray;
var list = new List<(ECPoint PublicKey, BigInteger Votes)>();
if (array.Count > 0)
{
foreach (Struct item in array)
{
list.Add((ECPoint.FromBytes(item[0].GetSpan().ToArray(), ECCurve.Secp256r1), item[1].GetInteger()));
}

}
//var iterator = iop.GetInterface<IIterator>();
//var first = iterator.Value;
//while (iterator.Next())
//{
// var val = iterator.Value;
//}
return list.ToArray();
}
}
}
2 changes: 1 addition & 1 deletion neo3-gui/neo3-gui/Models/Contracts/ContractModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ContractModel
public ContractModel(ContractState contract)
{
ContractId = contract.Id;
Script = contract.Script;
Script = contract.Script.ToArray();
Manifest = new ManifestModel(contract.Manifest);
}

Expand Down
6 changes: 3 additions & 3 deletions neo3-gui/neo3-gui/Models/Transactions/TransactionModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public TransactionModel(Transaction tx)
TxId = tx.Hash;
NetworkFee = new BigDecimal((BigInteger)tx.NetworkFee, NativeContract.GAS.Decimals);
Nonce = tx.Nonce;
Script = tx.Script;
Script = tx.Script.ToArray();

Sender = tx.Sender;
SystemFee = new BigDecimal((BigInteger)tx.SystemFee, NativeContract.GAS.Decimals);
ValidUntilBlock = tx.ValidUntilBlock;
Expand All @@ -34,7 +34,7 @@ public TransactionModel(Transaction tx)
Witnesses = tx.Witnesses?.Select(w => new WitnessModel(w)
).ToList();

if (tx.Script != null)
if (tx.Script.Length > 0)
{
ScriptCode = OpCodeConverter.Parse(tx.Script);
}
Expand Down
4 changes: 2 additions & 2 deletions neo3-gui/neo3-gui/Models/Transactions/WitnessModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public WitnessModel(Witness witness)
{
if (witness != null)
{
InvocationScript = witness.InvocationScript;
VerificationScript = witness.VerificationScript;
InvocationScript = witness.InvocationScript.ToArray();
VerificationScript = witness.VerificationScript.ToArray();
ScriptHash = witness.ScriptHash;
InvocationOpCode = OpCodeConverter.Parse(witness.InvocationScript);
VerificationOpCode = OpCodeConverter.Parse(witness.VerificationScript);
Expand Down
Binary file modified neo3-gui/neo3-gui/Plugins/LevelDBStore.dll
Binary file not shown.
13 changes: 8 additions & 5 deletions neo3-gui/neo3-gui/Services/ApiServices/ContractApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public async Task<object> DeployContract(string nefPath, string manifestPath = n
// Read manifest
ContractManifest manifest = ReadManifestFile(manifestPath);
// Basic script checks
await CheckBadOpcode(nefFile.Script);
await CheckBadOpcode(nefFile.Script.ToArray());

// Build script
using ScriptBuilder sb = new ScriptBuilder();
Expand Down Expand Up @@ -168,7 +168,7 @@ public async Task<object> UpdateContract(UInt160 contractHash, string nefPath, s
// Read manifest
ContractManifest manifest = ReadManifestFile(manifestPath);
// Basic script checks
await CheckBadOpcode(nefFile.Script);
await CheckBadOpcode(nefFile.Script.ToArray());

// Build script
using ScriptBuilder sb = new ScriptBuilder();
Expand Down Expand Up @@ -456,7 +456,8 @@ public async Task<object> GetValidators()
{
var snapshot = Helpers.GetDefaultSnapshot();
var validators = NativeContract.NEO.GetCommittee(snapshot);
var candidates = NativeContract.NEO.GetCandidates(snapshot);
//var candidates = NativeContract.NEO.GetCandidates(snapshot);
var candidates = snapshot.GetCandidates();
return candidates.OrderByDescending(v => v.Votes).Select(p => new ValidatorModel
{
Publickey = p.PublicKey.ToString(),
Expand All @@ -468,6 +469,7 @@ public async Task<object> GetValidators()




/// <summary>
/// apply for new validator
/// </summary>
Expand All @@ -493,7 +495,8 @@ public async Task<object> ApplyForValidator(string pubkey)
return Error(ErrorCode.InvalidPara);
}
var snapshot = Helpers.GetDefaultSnapshot();
var candidates = NativeContract.NEO.GetCandidates(snapshot);
//var candidates = NativeContract.NEO.GetCandidates(snapshot);
var candidates = snapshot.GetCandidates();
if (candidates.Any(v => v.PublicKey.Equals(publicKey)))
{
return Error(ErrorCode.ValidatorAlreadyExist);
Expand Down Expand Up @@ -573,7 +576,7 @@ private NefFile ReadNefFile(string nefPath)
{
throw new WsException(ErrorCode.ExceedMaxTransactionSize);
}
using var stream = new BinaryReader(File.OpenRead(nefPath), Encoding.UTF8, false);
var stream = new MemoryReader(File.ReadAllBytes(nefPath));
try
{
return stream.ReadSerializable<NefFile>();
Expand Down
3 changes: 1 addition & 2 deletions neo3-gui/neo3-gui/Services/ApiServices/WalletApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ public async Task<object> CreateWallet(string path, string password, string priv
break;
case ".json":
{
NEP6Wallet wallet = new NEP6Wallet(path, CliSettings.Default.Protocol);
wallet.Unlock(password);
NEP6Wallet wallet = new NEP6Wallet(path, password, CliSettings.Default.Protocol);
var account = hexPrivateKey.NotEmpty() ? wallet.CreateAccount(hexPrivateKey) : wallet.CreateAccount();
wallet.Save();
result.Accounts.Add(new AccountModel()
Expand Down
4 changes: 2 additions & 2 deletions neo3-gui/neo3-gui/config.private.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"Storage": {
"Engine": "LevelDBStore",
"Path": "Data_LevelDB_4444"
"Path": "Data_LevelDB_330"
},
"P2P": {
"Port": 30333,
Expand All @@ -16,7 +16,7 @@
"PluginURL": "https://github.com/neo-project/neo-modules/releases/download/v{1}/{0}.zip"
},
"ProtocolConfiguration": {
"Network": 4444,
"Network": 330,
"MillisecondsPerBlock": 15000,
"MaxTraceableBlocks": 2102400,
"ValidatorsCount": 1,
Expand Down
4 changes: 2 additions & 2 deletions neo3-gui/neo3-gui/neo3-gui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@

<ItemGroup>
<PackageReference Include="EFCore.BulkExtensions" Version="3.1.1" />
<PackageReference Include="Neo" Version="3.1.0" />
<!--<PackageReference Include="Neo" Version="3.1.0" />-->
<PackageReference Include="Neo.LevelDb.Dev" Version="3.0.0-pre4" />
<PackageReference Include="System.ServiceProcess.ServiceController" Version="4.6.0" />
</ItemGroup>

<ItemGroup>
<!--<ProjectReference Include="..\..\neo\src\neo\neo.csproj" />-->
<ProjectReference Include="..\..\neo\src\neo\neo.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 8e8cf7f

Please sign in to comment.