Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call _deploy during deploy and update #1933

Merged
merged 17 commits into from
Sep 21, 2020
28 changes: 28 additions & 0 deletions src/neo/SmartContract/ApplicationEngine.Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,34 @@ protected internal ContractState CreateContract(byte[] script, byte[] manifest)
if (!contract.Manifest.IsValid(hash)) throw new InvalidOperationException($"Invalid Manifest Hash: {hash}");

Snapshot.Contracts.Add(hash, contract);

// Execute _deploy

ContractMethodDescriptor md = contract.Manifest.Abi.GetMethod("_deploy");
shargon marked this conversation as resolved.
Show resolved Hide resolved
if (md is null) return contract;

if (invocationCounter.TryGetValue(contract.ScriptHash, out var counter))
{
invocationCounter[contract.ScriptHash] = counter + 1;
}
else
{
invocationCounter[contract.ScriptHash] = 1;
}

GetInvocationState(CurrentContext).NeedCheckReturnValue = true;
ExecutionContextState state = CurrentContext.GetState<ExecutionContextState>();
UInt160 callingScriptHash = state.ScriptHash;
CallFlags callingFlags = state.CallFlags;

ExecutionContext context_new = LoadScript(contract.Script, md.Offset);
state = context_new.GetState<ExecutionContextState>();
state.CallingScriptHash = callingScriptHash;
state.CallFlags = callingFlags;

md = contract.Manifest.Abi.GetMethod("_initialize");
if (md != null) LoadContext(context_new.Clone(md.Offset));

return contract;
erikzhang marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down