Skip to content

Commit

Permalink
Shargon's Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon committed Nov 3, 2020
1 parent 94965aa commit 70fb527
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/neo/Ledger/ContractState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,20 @@ public JObject ToJson()
{
JObject json = new JObject();
json["id"] = Id;

if (Id < 0)
{
foreach (var native in NativeContract.Contracts)
var native = NativeContract.GetContract(Id);
if (native != null) json["name"] = native.Name;
}
else
{
if (Manifest.Extra != null && Manifest.Extra["name"] != null)
{
if (Id == native.Id)
{
json["name"] = native.Name;
break;
}
json["name"] = Manifest.Extra["name"];
}
}

json["hash"] = ScriptHash.ToString();
json["script"] = Convert.ToBase64String(Script);
json["manifest"] = Manifest.ToJson();
Expand Down
8 changes: 8 additions & 0 deletions src/neo/SmartContract/Native/NativeContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace Neo.SmartContract.Native
public abstract class NativeContract
{
private static readonly List<NativeContract> contractsList = new List<NativeContract>();
private static readonly Dictionary<int, NativeContract> contractsIdDictionary = new Dictionary<int, NativeContract>();
private static readonly Dictionary<string, NativeContract> contractsNameDictionary = new Dictionary<string, NativeContract>();
private static readonly Dictionary<UInt160, NativeContract> contractsHashDictionary = new Dictionary<UInt160, NativeContract>();
private readonly Dictionary<string, ContractMethodMetadata> methods = new Dictionary<string, ContractMethodMetadata>();
Expand Down Expand Up @@ -77,6 +78,7 @@ protected NativeContract()
Extra = null
};
contractsList.Add(this);
contractsIdDictionary.Add(Id, this);
contractsNameDictionary.Add(Name, this);
contractsHashDictionary.Add(Hash, this);
}
Expand Down Expand Up @@ -104,6 +106,12 @@ public static NativeContract GetContract(string name)
return contract;
}

public static NativeContract GetContract(int id)
{
contractsIdDictionary.TryGetValue(id, out var contract);
return contract;
}

internal void Invoke(ApplicationEngine engine)
{
if (!engine.CurrentScriptHash.Equals(Hash))
Expand Down

0 comments on commit 70fb527

Please sign in to comment.