Skip to content

Commit

Permalink
T4 testnet compatible with 3.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon committed May 4, 2022
1 parent 421fa27 commit 15bea61
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/neo/Hardfork.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2015-2021 The Neo Project.
// Copyright (C) 2015-2022 The Neo Project.
//
// The neo is free software distributed under the MIT software license,
// see the accompanying file LICENSE in the main directory of the
Expand All @@ -12,6 +12,7 @@ namespace Neo
{
public enum Hardfork : byte
{
HF_2712_FixSyscallFees
HF_2712_FixSyscallFees,
HF_2653_DeployUpdateCallFlags
}
}
2 changes: 1 addition & 1 deletion src/neo/SmartContract/ApplicationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ public void SetState<T>(T state)
states[typeof(T)] = state;
}

private bool IsHardforkEnabled(Hardfork hardfork)
internal bool IsHardforkEnabled(Hardfork hardfork)
{
if (PersistingBlock is null)
return true;
Expand Down
25 changes: 21 additions & 4 deletions src/neo/SmartContract/Native/ContractManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Neo.Network.P2P.Payloads;
using Neo.Persistence;
using Neo.SmartContract.Manifest;
using Neo.VM;
using Neo.VM.Types;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -154,15 +155,23 @@ public IEnumerable<ContractState> ListContracts(DataCache snapshot)
return snapshot.Find(listContractsPrefix).Select(kvp => kvp.Value.GetInteroperable<ContractState>());
}

[ContractMethod(RequiredCallFlags = CallFlags.All)]
[ContractMethod(RequiredCallFlags = CallFlags.None)]
private ContractTask<ContractState> Deploy(ApplicationEngine engine, byte[] nefFile, byte[] manifest)
{
return Deploy(engine, nefFile, manifest, StackItem.Null);
}

[ContractMethod(RequiredCallFlags = CallFlags.All)]
[ContractMethod(RequiredCallFlags = CallFlags.None)]
private async ContractTask<ContractState> Deploy(ApplicationEngine engine, byte[] nefFile, byte[] manifest, StackItem data)
{
CallFlags requiredCallFlags = engine.IsHardforkEnabled(Hardfork.HF_2653_DeployUpdateCallFlags)
? CallFlags.All
: CallFlags.States | CallFlags.AllowNotify;

ExecutionContextState state = engine.CurrentContext.GetState<ExecutionContextState>();
if (!state.CallFlags.HasFlag(requiredCallFlags))
throw new InvalidOperationException($"Cannot call this method with the flag {state.CallFlags}.");

if (engine.ScriptContainer is not Transaction tx)
throw new InvalidOperationException();
if (nefFile.Length == 0)
Expand Down Expand Up @@ -204,15 +213,23 @@ private async ContractTask<ContractState> Deploy(ApplicationEngine engine, byte[
return contract;
}

[ContractMethod(RequiredCallFlags = CallFlags.All)]
[ContractMethod(RequiredCallFlags = CallFlags.None)]
private ContractTask Update(ApplicationEngine engine, byte[] nefFile, byte[] manifest)
{
return Update(engine, nefFile, manifest, StackItem.Null);
}

[ContractMethod(RequiredCallFlags = CallFlags.All)]
[ContractMethod(RequiredCallFlags = CallFlags.None)]
private ContractTask Update(ApplicationEngine engine, byte[] nefFile, byte[] manifest, StackItem data)
{
CallFlags requiredCallFlags = engine.IsHardforkEnabled(Hardfork.HF_2653_DeployUpdateCallFlags)
? CallFlags.All
: CallFlags.States | CallFlags.AllowNotify;

ExecutionContextState state = engine.CurrentContext.GetState<ExecutionContextState>();
if (!state.CallFlags.HasFlag(requiredCallFlags))
throw new InvalidOperationException($"Cannot call this method with the flag {state.CallFlags}.");

if (nefFile is null && manifest is null) throw new ArgumentException();

engine.AddGas(engine.StoragePrice * ((nefFile?.Length ?? 0) + (manifest?.Length ?? 0)));
Expand Down

0 comments on commit 15bea61

Please sign in to comment.