Skip to content

Commit

Permalink
Move to Manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon committed Jul 8, 2020
1 parent b5dea52 commit 50ffaac
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/neo/Ledger/ContractState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public JObject ToJson()

public StackItem ToStackItem(ReferenceCounter referenceCounter)
{
return new Array(referenceCounter, new StackItem[] { Script, HasStorage, Payable });
return new Array(referenceCounter, new StackItem[] { Script, Manifest.ToString(), HasStorage, Payable });
}
}
}
9 changes: 0 additions & 9 deletions src/neo/SmartContract/ApplicationEngine.Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ partial class ApplicationEngine
{
public const int MaxContractLength = 1024 * 1024;

public static readonly InteropDescriptor System_Contract_Abi = Register("System.Contract.GetAbi", nameof(GetAbi), 0, TriggerType.Application, CallFlags.AllowStates, true);
public static readonly InteropDescriptor System_Contract_Create = Register("System.Contract.Create", nameof(CreateContract), 0, TriggerType.Application, CallFlags.AllowModifyStates, false);
public static readonly InteropDescriptor System_Contract_Update = Register("System.Contract.Update", nameof(UpdateContract), 0, TriggerType.Application, CallFlags.AllowModifyStates, false);
public static readonly InteropDescriptor System_Contract_Destroy = Register("System.Contract.Destroy", nameof(DestroyContract), 0_01000000, TriggerType.Application, CallFlags.AllowModifyStates, false);
Expand All @@ -28,14 +27,6 @@ partial class ApplicationEngine
/// </summary>
public static readonly InteropDescriptor System_Contract_CreateStandardAccount = Register("System.Contract.CreateStandardAccount", nameof(CreateStandardAccount), 0_00010000, TriggerType.All, CallFlags.None, true);

internal string GetAbi(UInt160 hash)
{
ContractState contract = Snapshot.Contracts.TryGet(hash);
if (contract == null) return null;

return contract.Manifest.Abi.ToJson().ToString();
}

internal ContractState CreateContract(byte[] script, byte[] manifest)
{
if (script.Length == 0 || script.Length > MaxContractLength || manifest.Length == 0 || manifest.Length > ContractManifest.MaxLength)
Expand Down
8 changes: 0 additions & 8 deletions src/neo/SmartContract/Manifest/ContractAbi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,13 @@ public class ContractAbi
/// </summary>
public ContractEventDescriptor[] Events { get; set; }

/// <summary>
/// NEP10 - SupportedStandards
/// </summary>
public string[] SupportedStandards { get; set; }

public ContractAbi Clone()
{
return new ContractAbi
{
Hash = Hash,
Methods = Methods.Select(p => p.Clone()).ToArray(),
Events = Events.Select(p => p.Clone()).ToArray(),
SupportedStandards = SupportedStandards.Select(p => p).ToArray()
};
}

Expand All @@ -54,7 +48,6 @@ public static ContractAbi FromJson(JObject json)
Hash = UInt160.Parse(json["hash"].AsString()),
Methods = ((JArray)json["methods"]).Select(u => ContractMethodDescriptor.FromJson(u)).ToArray(),
Events = ((JArray)json["events"]).Select(u => ContractEventDescriptor.FromJson(u)).ToArray(),
SupportedStandards = ((JArray)json["supportedstandards"]).Select(u => u.AsString()).ToArray()
};
}

Expand All @@ -71,7 +64,6 @@ public JObject ToJson()
json["hash"] = Hash.ToString();
json["methods"] = new JArray(Methods.Select(u => u.ToJson()).ToArray());
json["events"] = new JArray(Events.Select(u => u.ToJson()).ToArray());
json["supportedstandards"] = new JArray(SupportedStandards.Select(u => new JString(u)).ToArray());
return json;
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/neo/SmartContract/Manifest/ContractManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public class ContractManifest : ISerializable
/// </summary>
public JObject Extra { get; set; }

/// <summary>
/// NEP10 - SupportedStandards
/// </summary>
public string[] SupportedStandards { get; set; }

/// <summary>
/// Return true if is allowed
/// </summary>
Expand Down Expand Up @@ -113,6 +118,7 @@ public JObject ToJson()
json["trusts"] = Trusts.ToJson();
json["safemethods"] = SafeMethods.ToJson();
json["extra"] = Extra;
json["supportedstandards"] = new JArray(SupportedStandards.Select(u => new JString(u)).ToArray());

return json;
}
Expand All @@ -131,7 +137,8 @@ public ContractManifest Clone()
Permissions = Permissions.Select(p => p.Clone()).ToArray(),
Trusts = Trusts,
SafeMethods = SafeMethods,
Extra = Extra?.Clone()
Extra = Extra?.Clone(),
SupportedStandards = SupportedStandards.Select(p => p).ToArray()
};
}

Expand Down Expand Up @@ -160,6 +167,7 @@ private void DeserializeFromJson(JObject json)
Trusts = WildcardContainer<UInt160>.FromJson(json["trusts"], u => UInt160.Parse(u.AsString()));
SafeMethods = WildcardContainer<string>.FromJson(json["safemethods"], u => u.AsString());
Extra = json["extra"];
SupportedStandards = ((JArray)json["supportedstandards"]).Select(u => u.AsString()).ToArray();
if (json["features"]["storage"].AsBoolean()) Features |= ContractFeatures.HasStorage;
if (json["features"]["payable"].AsBoolean()) Features |= ContractFeatures.Payable;
}
Expand Down

0 comments on commit 50ffaac

Please sign in to comment.