diff --git a/src/neo/SmartContract/ContractParameter.cs b/src/neo/SmartContract/ContractParameter.cs index c739d9af7e..21318be7da 100644 --- a/src/neo/SmartContract/ContractParameter.cs +++ b/src/neo/SmartContract/ContractParameter.cs @@ -18,41 +18,21 @@ public ContractParameter() { } public ContractParameter(ContractParameterType type) { this.Type = type; - switch (type) + this.Value = type switch { - case ContractParameterType.Signature: - this.Value = new byte[64]; - break; - case ContractParameterType.Boolean: - this.Value = false; - break; - case ContractParameterType.Integer: - this.Value = 0; - break; - case ContractParameterType.Hash160: - this.Value = new UInt160(); - break; - case ContractParameterType.Hash256: - this.Value = new UInt256(); - break; - case ContractParameterType.ByteArray: - this.Value = Array.Empty(); - break; - case ContractParameterType.PublicKey: - this.Value = ECCurve.Secp256r1.G; - break; - case ContractParameterType.String: - this.Value = ""; - break; - case ContractParameterType.Array: - this.Value = new List(); - break; - case ContractParameterType.Map: - this.Value = new List>(); - break; - default: - throw new ArgumentException(); - } + ContractParameterType.Any => null, + ContractParameterType.Signature => new byte[64], + ContractParameterType.Boolean => false, + ContractParameterType.Integer => 0, + ContractParameterType.Hash160 => new UInt160(), + ContractParameterType.Hash256 => new UInt256(), + ContractParameterType.ByteArray => Array.Empty(), + ContractParameterType.PublicKey => ECCurve.Secp256r1.G, + ContractParameterType.String => "", + ContractParameterType.Array => new List(), + ContractParameterType.Map => new List>(), + _ => throw new ArgumentException(), + }; } public static ContractParameter FromJson(JObject json) diff --git a/src/neo/VM/Helper.cs b/src/neo/VM/Helper.cs index 6437b75118..7e73eff3be 100644 --- a/src/neo/VM/Helper.cs +++ b/src/neo/VM/Helper.cs @@ -63,45 +63,48 @@ public static ScriptBuilder EmitPush(this ScriptBuilder sb, ISerializable data) public static ScriptBuilder EmitPush(this ScriptBuilder sb, ContractParameter parameter) { - switch (parameter.Type) - { - case ContractParameterType.Signature: - case ContractParameterType.ByteArray: - sb.EmitPush((byte[])parameter.Value); - break; - case ContractParameterType.Boolean: - sb.EmitPush((bool)parameter.Value); - break; - case ContractParameterType.Integer: - if (parameter.Value is BigInteger bi) - sb.EmitPush(bi); - else - sb.EmitPush((BigInteger)typeof(BigInteger).GetConstructor(new[] { parameter.Value.GetType() }).Invoke(new[] { parameter.Value })); - break; - case ContractParameterType.Hash160: - sb.EmitPush((UInt160)parameter.Value); - break; - case ContractParameterType.Hash256: - sb.EmitPush((UInt256)parameter.Value); - break; - case ContractParameterType.PublicKey: - sb.EmitPush((ECPoint)parameter.Value); - break; - case ContractParameterType.String: - sb.EmitPush((string)parameter.Value); - break; - case ContractParameterType.Array: - { - IList parameters = (IList)parameter.Value; - for (int i = parameters.Count - 1; i >= 0; i--) - sb.EmitPush(parameters[i]); - sb.EmitPush(parameters.Count); - sb.Emit(OpCode.PACK); - } - break; - default: - throw new ArgumentException(); - } + if (parameter.Value is null) + sb.Emit(OpCode.PUSHNULL); + else + switch (parameter.Type) + { + case ContractParameterType.Signature: + case ContractParameterType.ByteArray: + sb.EmitPush((byte[])parameter.Value); + break; + case ContractParameterType.Boolean: + sb.EmitPush((bool)parameter.Value); + break; + case ContractParameterType.Integer: + if (parameter.Value is BigInteger bi) + sb.EmitPush(bi); + else + sb.EmitPush((BigInteger)typeof(BigInteger).GetConstructor(new[] { parameter.Value.GetType() }).Invoke(new[] { parameter.Value })); + break; + case ContractParameterType.Hash160: + sb.EmitPush((UInt160)parameter.Value); + break; + case ContractParameterType.Hash256: + sb.EmitPush((UInt256)parameter.Value); + break; + case ContractParameterType.PublicKey: + sb.EmitPush((ECPoint)parameter.Value); + break; + case ContractParameterType.String: + sb.EmitPush((string)parameter.Value); + break; + case ContractParameterType.Array: + { + IList parameters = (IList)parameter.Value; + for (int i = parameters.Count - 1; i >= 0; i--) + sb.EmitPush(parameters[i]); + sb.EmitPush(parameters.Count); + sb.Emit(OpCode.PACK); + } + break; + default: + throw new ArgumentException(); + } return sb; }