-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
891 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (C) 2015-2021 The Neo Project. | ||
// | ||
// The neo is free software distributed under the MIT software license, | ||
// see the accompanying file LICENSE in the main directory of the | ||
// project or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using Neo.IO; | ||
using Neo.IO.Json; | ||
using Neo.SmartContract; | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace Neo.Network.P2P.Payloads.Conditions | ||
{ | ||
/// <summary> | ||
/// Represents the condition that all conditions must be met. | ||
/// </summary> | ||
public class AndCondition : WitnessCondition | ||
{ | ||
/// <summary> | ||
/// The expressions of the condition. | ||
/// </summary> | ||
public WitnessCondition[] Expressions; | ||
|
||
public override int Size => base.Size + Expressions.GetVarSize(); | ||
public override WitnessConditionType Type => WitnessConditionType.And; | ||
|
||
protected override void DeserializeWithoutType(BinaryReader reader, int maxNestDepth) | ||
{ | ||
if (maxNestDepth <= 0) throw new FormatException(); | ||
Expressions = DeserializeConditions(reader, maxNestDepth - 1); | ||
if (Expressions.Length == 0) throw new FormatException(); | ||
} | ||
|
||
public override bool Match(ApplicationEngine engine) | ||
{ | ||
return Expressions.All(p => p.Match(engine)); | ||
} | ||
|
||
protected override void SerializeWithoutType(BinaryWriter writer) | ||
{ | ||
writer.Write(Expressions); | ||
} | ||
|
||
public override JObject ToJson() | ||
{ | ||
JObject json = base.ToJson(); | ||
json["expressions"] = Expressions.Select(p => p.ToJson()).ToArray(); | ||
return json; | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/neo/Network/P2P/Payloads/Conditions/BooleanCondition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (C) 2015-2021 The Neo Project. | ||
// | ||
// The neo is free software distributed under the MIT software license, | ||
// see the accompanying file LICENSE in the main directory of the | ||
// project or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using Neo.IO.Json; | ||
using Neo.SmartContract; | ||
using System.IO; | ||
|
||
namespace Neo.Network.P2P.Payloads.Conditions | ||
{ | ||
public class BooleanCondition : WitnessCondition | ||
{ | ||
/// <summary> | ||
/// The expression of the <see cref="BooleanCondition"/>. | ||
/// </summary> | ||
public bool Expression; | ||
|
||
public override int Size => base.Size + sizeof(bool); | ||
public override WitnessConditionType Type => WitnessConditionType.Boolean; | ||
|
||
protected override void DeserializeWithoutType(BinaryReader reader, int maxNestDepth) | ||
{ | ||
Expression = reader.ReadBoolean(); | ||
} | ||
|
||
public override bool Match(ApplicationEngine engine) | ||
{ | ||
return Expression; | ||
} | ||
|
||
protected override void SerializeWithoutType(BinaryWriter writer) | ||
{ | ||
writer.Write(Expression); | ||
} | ||
|
||
public override JObject ToJson() | ||
{ | ||
JObject json = base.ToJson(); | ||
json["expression"] = Expression; | ||
return json; | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/neo/Network/P2P/Payloads/Conditions/CalledByContractCondition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (C) 2015-2021 The Neo Project. | ||
// | ||
// The neo is free software distributed under the MIT software license, | ||
// see the accompanying file LICENSE in the main directory of the | ||
// project or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using Neo.IO; | ||
using Neo.IO.Json; | ||
using Neo.SmartContract; | ||
using System.IO; | ||
|
||
namespace Neo.Network.P2P.Payloads.Conditions | ||
{ | ||
public class CalledByContractCondition : WitnessCondition | ||
{ | ||
/// <summary> | ||
/// The script hash to be checked. | ||
/// </summary> | ||
public UInt160 Hash; | ||
|
||
public override int Size => base.Size + UInt160.Length; | ||
public override WitnessConditionType Type => WitnessConditionType.CalledByContract; | ||
|
||
protected override void DeserializeWithoutType(BinaryReader reader, int maxNestDepth) | ||
{ | ||
Hash = reader.ReadSerializable<UInt160>(); | ||
} | ||
|
||
public override bool Match(ApplicationEngine engine) | ||
{ | ||
return engine.CallingScriptHash == Hash; | ||
} | ||
|
||
protected override void SerializeWithoutType(BinaryWriter writer) | ||
{ | ||
writer.Write(Hash); | ||
} | ||
|
||
public override JObject ToJson() | ||
{ | ||
JObject json = base.ToJson(); | ||
json["hash"] = Hash.ToString(); | ||
return json; | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/neo/Network/P2P/Payloads/Conditions/CalledByEntryCondition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (C) 2015-2021 The Neo Project. | ||
// | ||
// The neo is free software distributed under the MIT software license, | ||
// see the accompanying file LICENSE in the main directory of the | ||
// project or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using Neo.SmartContract; | ||
using System.IO; | ||
|
||
namespace Neo.Network.P2P.Payloads.Conditions | ||
{ | ||
public class CalledByEntryCondition : WitnessCondition | ||
{ | ||
public override WitnessConditionType Type => WitnessConditionType.CalledByEntry; | ||
|
||
protected override void DeserializeWithoutType(BinaryReader reader, int maxNestDepth) | ||
{ | ||
} | ||
|
||
public override bool Match(ApplicationEngine engine) | ||
{ | ||
return engine.CallingScriptHash is null || engine.CallingScriptHash == engine.EntryScriptHash; | ||
} | ||
|
||
protected override void SerializeWithoutType(BinaryWriter writer) | ||
{ | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/neo/Network/P2P/Payloads/Conditions/CalledByGroupCondition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (C) 2015-2021 The Neo Project. | ||
// | ||
// The neo is free software distributed under the MIT software license, | ||
// see the accompanying file LICENSE in the main directory of the | ||
// project or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using Neo.Cryptography.ECC; | ||
using Neo.IO; | ||
using Neo.IO.Json; | ||
using Neo.SmartContract; | ||
using Neo.SmartContract.Native; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace Neo.Network.P2P.Payloads.Conditions | ||
{ | ||
public class CalledByGroupCondition : WitnessCondition | ||
{ | ||
/// <summary> | ||
/// The group to be checked. | ||
/// </summary> | ||
public ECPoint Group; | ||
|
||
public override int Size => base.Size + Group.Size; | ||
public override WitnessConditionType Type => WitnessConditionType.CalledByGroup; | ||
|
||
protected override void DeserializeWithoutType(BinaryReader reader, int maxNestDepth) | ||
{ | ||
Group = reader.ReadSerializable<ECPoint>(); | ||
} | ||
|
||
public override bool Match(ApplicationEngine engine) | ||
{ | ||
engine.ValidateCallFlags(CallFlags.ReadStates); | ||
ContractState contract = NativeContract.ContractManagement.GetContract(engine.Snapshot, engine.CallingScriptHash); | ||
return contract is not null && contract.Manifest.Groups.Any(p => p.PubKey.Equals(Group)); | ||
} | ||
|
||
protected override void SerializeWithoutType(BinaryWriter writer) | ||
{ | ||
writer.Write(Group); | ||
} | ||
|
||
public override JObject ToJson() | ||
{ | ||
JObject json = base.ToJson(); | ||
json["group"] = Group.ToString(); | ||
return json; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (C) 2015-2021 The Neo Project. | ||
// | ||
// The neo is free software distributed under the MIT software license, | ||
// see the accompanying file LICENSE in the main directory of the | ||
// project or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using Neo.Cryptography.ECC; | ||
using Neo.IO; | ||
using Neo.IO.Json; | ||
using Neo.SmartContract; | ||
using Neo.SmartContract.Native; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace Neo.Network.P2P.Payloads.Conditions | ||
{ | ||
public class GroupCondition : WitnessCondition | ||
{ | ||
/// <summary> | ||
/// The group to be checked. | ||
/// </summary> | ||
public ECPoint Group; | ||
|
||
public override int Size => base.Size + Group.Size; | ||
public override WitnessConditionType Type => WitnessConditionType.Group; | ||
|
||
protected override void DeserializeWithoutType(BinaryReader reader, int maxNestDepth) | ||
{ | ||
Group = reader.ReadSerializable<ECPoint>(); | ||
} | ||
|
||
public override bool Match(ApplicationEngine engine) | ||
{ | ||
engine.ValidateCallFlags(CallFlags.ReadStates); | ||
ContractState contract = NativeContract.ContractManagement.GetContract(engine.Snapshot, engine.CurrentScriptHash); | ||
return contract is not null && contract.Manifest.Groups.Any(p => p.PubKey.Equals(Group)); | ||
} | ||
|
||
protected override void SerializeWithoutType(BinaryWriter writer) | ||
{ | ||
writer.Write(Group); | ||
} | ||
|
||
public override JObject ToJson() | ||
{ | ||
JObject json = base.ToJson(); | ||
json["group"] = Group.ToString(); | ||
return json; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (C) 2015-2021 The Neo Project. | ||
// | ||
// The neo is free software distributed under the MIT software license, | ||
// see the accompanying file LICENSE in the main directory of the | ||
// project or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using Neo.IO; | ||
using Neo.IO.Json; | ||
using Neo.SmartContract; | ||
using System; | ||
using System.IO; | ||
|
||
namespace Neo.Network.P2P.Payloads.Conditions | ||
{ | ||
/// <summary> | ||
/// Reverse another condition. | ||
/// </summary> | ||
public class NotCondition : WitnessCondition | ||
{ | ||
/// <summary> | ||
/// The expression of the condition to be reversed. | ||
/// </summary> | ||
public WitnessCondition Expression; | ||
|
||
public override int Size => base.Size + Expression.Size; | ||
public override WitnessConditionType Type => WitnessConditionType.Not; | ||
|
||
protected override void DeserializeWithoutType(BinaryReader reader, int maxNestDepth) | ||
{ | ||
if (maxNestDepth <= 0) throw new FormatException(); | ||
Expression = DeserializeFrom(reader, maxNestDepth - 1); | ||
} | ||
|
||
public override bool Match(ApplicationEngine engine) | ||
{ | ||
return !Expression.Match(engine); | ||
} | ||
|
||
protected override void SerializeWithoutType(BinaryWriter writer) | ||
{ | ||
writer.Write(Expression); | ||
} | ||
|
||
public override JObject ToJson() | ||
{ | ||
JObject json = base.ToJson(); | ||
json["expression"] = Expression.ToJson(); | ||
return json; | ||
} | ||
} | ||
} |
Oops, something went wrong.