From 4400060fc6841343d778697ece58ce33225e6f1a Mon Sep 17 00:00:00 2001 From: Fernando Diaz Toledano Date: Mon, 5 Jun 2023 11:49:00 +0200 Subject: [PATCH 1/7] Reserved attribute --- .../Network/P2P/Payloads/ReservedAttribute.cs | 45 +++++++++++++++++++ .../P2P/Payloads/TransactionAttributeType.cs | 8 +++- 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/Neo/Network/P2P/Payloads/ReservedAttribute.cs diff --git a/src/Neo/Network/P2P/Payloads/ReservedAttribute.cs b/src/Neo/Network/P2P/Payloads/ReservedAttribute.cs new file mode 100644 index 0000000000..46e4828194 --- /dev/null +++ b/src/Neo/Network/P2P/Payloads/ReservedAttribute.cs @@ -0,0 +1,45 @@ +// Copyright (C) 2015-2023 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 System; +using System.IO; +using Neo.IO; +using Neo.Json; + +namespace Neo.Network.P2P.Payloads +{ + /// + /// Reserved attribute for dApps. + /// + public class ReservedAttribute : TransactionAttribute + { + private byte[] _reserved; + + public override bool AllowMultiple => true; + public override TransactionAttributeType Type => TransactionAttributeType.ReservedAttribute; + + protected override void DeserializeWithoutType(ref MemoryReader reader) + { + _reserved = reader.ReadVarMemory(ushort.MaxValue).ToArray(); + } + + protected override void SerializeWithoutType(BinaryWriter writer) + { + writer.WriteVarBytes(_reserved); + } + + public override JObject ToJson() + { + var json = base.ToJson(); + json["value"] = Convert.ToBase64String(_reserved); + return json; + } + } +} diff --git a/src/Neo/Network/P2P/Payloads/TransactionAttributeType.cs b/src/Neo/Network/P2P/Payloads/TransactionAttributeType.cs index 41c69b507d..1feb8e91a6 100644 --- a/src/Neo/Network/P2P/Payloads/TransactionAttributeType.cs +++ b/src/Neo/Network/P2P/Payloads/TransactionAttributeType.cs @@ -33,6 +33,12 @@ public enum TransactionAttributeType : byte /// Indicates that the transaction is not valid before . /// [ReflectionCache(typeof(NotValidBefore))] - NotValidBefore = 0x20 + NotValidBefore = 0x20, + + /// + /// Indicates that the transaction is a reserved attribute. + /// + [ReflectionCache(typeof(ReservedAttribute))] + ReservedAttribute = 0xFF } } From 8af39ebd7814a4c70643f4d02d737d5435cb5292 Mon Sep 17 00:00:00 2001 From: Fernando Diaz Toledano Date: Mon, 5 Jun 2023 11:50:25 +0200 Subject: [PATCH 2/7] Fix ut --- .../Network/P2P/Payloads/UT_HighPriorityAttribute.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_HighPriorityAttribute.cs b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_HighPriorityAttribute.cs index 8a41aa0135..2f543bc18a 100644 --- a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_HighPriorityAttribute.cs +++ b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_HighPriorityAttribute.cs @@ -42,7 +42,7 @@ public void DeserializeAndSerialize() // Wrong type - buffer[0] = 0xff; + buffer[0] = 0xfe; reader = new MemoryReader(buffer); try { From ef661408440cdfa8e5fd7ff6796afee06608c3c1 Mon Sep 17 00:00:00 2001 From: Fernando Diaz Toledano Date: Mon, 5 Jun 2023 12:17:42 +0200 Subject: [PATCH 3/7] Fix ut --- tests/Neo.UnitTests/Network/P2P/Payloads/UT_NotValidBefore.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_NotValidBefore.cs b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_NotValidBefore.cs index e47159d9ff..dd45109ce7 100644 --- a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_NotValidBefore.cs +++ b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_NotValidBefore.cs @@ -43,7 +43,7 @@ public void DeserializeAndSerialize() // Wrong type - buffer[0] = 0xff; + buffer[0] = 0xfe; reader = new MemoryReader(buffer); try { From 44decd5d1019be87d5c20a67fd1c8f97537046e8 Mon Sep 17 00:00:00 2001 From: Shargon Date: Mon, 5 Jun 2023 05:12:37 -0700 Subject: [PATCH 4/7] Update TransactionAttributeType.cs --- src/Neo/Network/P2P/Payloads/TransactionAttributeType.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Neo/Network/P2P/Payloads/TransactionAttributeType.cs b/src/Neo/Network/P2P/Payloads/TransactionAttributeType.cs index 1feb8e91a6..c402d5a9b6 100644 --- a/src/Neo/Network/P2P/Payloads/TransactionAttributeType.cs +++ b/src/Neo/Network/P2P/Payloads/TransactionAttributeType.cs @@ -39,6 +39,6 @@ public enum TransactionAttributeType : byte /// Indicates that the transaction is a reserved attribute. /// [ReflectionCache(typeof(ReservedAttribute))] - ReservedAttribute = 0xFF + ReservedAttribute = 0x31 } } From 8f2fe0c09411c7b62a610910c3988e7500f940fa Mon Sep 17 00:00:00 2001 From: Shargon Date: Mon, 5 Jun 2023 05:13:14 -0700 Subject: [PATCH 5/7] Update UT_HighPriorityAttribute.cs --- .../Network/P2P/Payloads/UT_HighPriorityAttribute.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_HighPriorityAttribute.cs b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_HighPriorityAttribute.cs index 2f543bc18a..8a41aa0135 100644 --- a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_HighPriorityAttribute.cs +++ b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_HighPriorityAttribute.cs @@ -42,7 +42,7 @@ public void DeserializeAndSerialize() // Wrong type - buffer[0] = 0xfe; + buffer[0] = 0xff; reader = new MemoryReader(buffer); try { From d0e587d5761c4d6dba2a4dc425e7f2bbac305765 Mon Sep 17 00:00:00 2001 From: Shargon Date: Mon, 5 Jun 2023 05:13:26 -0700 Subject: [PATCH 6/7] Update UT_NotValidBefore.cs --- tests/Neo.UnitTests/Network/P2P/Payloads/UT_NotValidBefore.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_NotValidBefore.cs b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_NotValidBefore.cs index dd45109ce7..e47159d9ff 100644 --- a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_NotValidBefore.cs +++ b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_NotValidBefore.cs @@ -43,7 +43,7 @@ public void DeserializeAndSerialize() // Wrong type - buffer[0] = 0xfe; + buffer[0] = 0xff; reader = new MemoryReader(buffer); try { From 2c2109f14cf2801ab2b7ca1a0656dcccda781de9 Mon Sep 17 00:00:00 2001 From: Shargon Date: Mon, 5 Jun 2023 05:18:34 -0700 Subject: [PATCH 7/7] Update TransactionAttributeType.cs --- src/Neo/Network/P2P/Payloads/TransactionAttributeType.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Neo/Network/P2P/Payloads/TransactionAttributeType.cs b/src/Neo/Network/P2P/Payloads/TransactionAttributeType.cs index c402d5a9b6..e3a728b19e 100644 --- a/src/Neo/Network/P2P/Payloads/TransactionAttributeType.cs +++ b/src/Neo/Network/P2P/Payloads/TransactionAttributeType.cs @@ -39,6 +39,6 @@ public enum TransactionAttributeType : byte /// Indicates that the transaction is a reserved attribute. /// [ReflectionCache(typeof(ReservedAttribute))] - ReservedAttribute = 0x31 + ReservedAttribute = 0xf0 } }