Skip to content
26 changes: 13 additions & 13 deletions src/Plugins/StateService/Network/StateRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using Neo.Cryptography.ECC;
using Neo.Extensions;
using Neo.IO;
using Neo.Json;
Expand Down Expand Up @@ -49,7 +48,7 @@ Witness[] IVerifiable.Witnesses
{
get
{
return new[] { Witness };
return [Witness];
}
set
{
Expand All @@ -70,12 +69,12 @@ Witness[] IVerifiable.Witnesses
void ISerializable.Deserialize(ref MemoryReader reader)
{
DeserializeUnsigned(ref reader);
Witness[] witnesses = reader.ReadSerializableArray<Witness>(1);
var witnesses = reader.ReadSerializableArray<Witness>(1);
Witness = witnesses.Length switch
{
0 => null,
1 => witnesses[0],
_ => throw new FormatException(),
_ => throw new FormatException($"Expected 1 witness, got {witnesses.Length}."),
};
}

Expand All @@ -92,7 +91,7 @@ void ISerializable.Serialize(BinaryWriter writer)
if (Witness is null)
writer.WriteVarInt(0);
else
writer.Write(new[] { Witness });
writer.Write([Witness]);
}

public void SerializeUnsigned(BinaryWriter writer)
Expand All @@ -109,19 +108,20 @@ public bool Verify(ProtocolSettings settings, DataCache snapshot)

public UInt160[] GetScriptHashesForVerifying(DataCache snapshot)
{
ECPoint[] validators = NativeContract.RoleManagement.GetDesignatedByRole(snapshot, Role.StateValidator, Index);
var validators = NativeContract.RoleManagement.GetDesignatedByRole(snapshot, Role.StateValidator, Index);
if (validators.Length < 1) throw new InvalidOperationException("No script hash for state root verifying");
return new UInt160[] { Contract.GetBFTAddress(validators) };
return [Contract.GetBFTAddress(validators)];
}

public JObject ToJson()
{
var json = new JObject();
json["version"] = Version;
json["index"] = Index;
json["roothash"] = RootHash.ToString();
json["witnesses"] = Witness is null ? new JArray() : new JArray(Witness.ToJson());
return json;
return new()
{
["version"] = Version,
["index"] = Index,
["roothash"] = RootHash.ToString(),
["witnesses"] = Witness is null ? new JArray() : new JArray(Witness.ToJson()),
};
}
}
}
Loading