forked from neo-project/neo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into change_consensus_timespan_strategy
- Loading branch information
Showing
29 changed files
with
184 additions
and
222 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
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
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
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
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 |
---|---|---|
@@ -1,37 +1,48 @@ | ||
using Neo.IO; | ||
using Neo.IO.Caching; | ||
using Neo.IO.Json; | ||
using System; | ||
using System.IO; | ||
|
||
namespace Neo.Network.P2P.Payloads | ||
{ | ||
public class TransactionAttribute : ISerializable | ||
public abstract class TransactionAttribute : ISerializable | ||
{ | ||
public TransactionAttributeUsage Usage; | ||
public byte[] Data; | ||
public abstract TransactionAttributeType Type { get; } | ||
public virtual int Size => sizeof(TransactionAttributeType); | ||
|
||
public int Size => sizeof(TransactionAttributeUsage) + Data.GetVarSize(); | ||
public void Deserialize(BinaryReader reader) | ||
{ | ||
if (reader.ReadByte() != (byte)Type) | ||
throw new FormatException(); | ||
DeserializeWithoutType(reader); | ||
} | ||
|
||
void ISerializable.Deserialize(BinaryReader reader) | ||
public static TransactionAttribute DeserializeFrom(BinaryReader reader) | ||
{ | ||
Usage = (TransactionAttributeUsage)reader.ReadByte(); | ||
if (!Enum.IsDefined(typeof(TransactionAttributeUsage), Usage)) | ||
TransactionAttributeType type = (TransactionAttributeType)reader.ReadByte(); | ||
if (!(ReflectionCache<TransactionAttributeType>.CreateInstance(type) is TransactionAttribute attribute)) | ||
throw new FormatException(); | ||
Data = reader.ReadVarBytes(252); | ||
attribute.DeserializeWithoutType(reader); | ||
return attribute; | ||
} | ||
|
||
void ISerializable.Serialize(BinaryWriter writer) | ||
protected abstract void DeserializeWithoutType(BinaryReader reader); | ||
|
||
public virtual JObject ToJson() | ||
{ | ||
writer.Write((byte)Usage); | ||
writer.WriteVarBytes(Data); | ||
return new JObject | ||
{ | ||
["type"] = Type | ||
}; | ||
} | ||
|
||
public JObject ToJson() | ||
public void Serialize(BinaryWriter writer) | ||
{ | ||
JObject json = new JObject(); | ||
json["usage"] = Usage; | ||
json["data"] = Convert.ToBase64String(Data); | ||
return json; | ||
writer.Write((byte)Type); | ||
SerializeWithoutType(writer); | ||
} | ||
|
||
protected abstract void SerializeWithoutType(BinaryWriter writer); | ||
} | ||
} |
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,10 @@ | ||
using Neo.IO.Caching; | ||
|
||
namespace Neo.Network.P2P.Payloads | ||
{ | ||
public enum TransactionAttributeType : byte | ||
{ | ||
[ReflectionCache(typeof(Cosigner))] | ||
Cosigner = 0x01 | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.