-
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.
Merge branch 'testnet' into testnet-coreclr
- Loading branch information
Showing
18 changed files
with
146 additions
and
98 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
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,35 +1,37 @@ | ||
using AntShares.IO; | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace AntShares.Network.Payloads | ||
{ | ||
internal class InvPayload : ISerializable | ||
{ | ||
public InventoryType Type; | ||
public UInt256[] Hashes; | ||
public InventoryVector[] Inventories; | ||
|
||
public static InvPayload Create(InventoryVector[] vectors) | ||
{ | ||
return new InvPayload | ||
{ | ||
Inventories = vectors | ||
}; | ||
} | ||
|
||
public static InvPayload Create(InventoryType type, params UInt256[] hashes) | ||
{ | ||
return new InvPayload | ||
{ | ||
Type = type, | ||
Hashes = hashes | ||
Inventories = hashes.Select(p => new InventoryVector { Type = type, Hash = p }).ToArray() | ||
}; | ||
} | ||
|
||
void ISerializable.Deserialize(BinaryReader reader) | ||
{ | ||
Type = (InventoryType)reader.ReadByte(); | ||
if (!Enum.IsDefined(typeof(InventoryType), Type)) | ||
throw new FormatException(); | ||
Hashes = reader.ReadSerializableArray<UInt256>(); | ||
Inventories = reader.ReadSerializableArray<InventoryVector>(); | ||
} | ||
|
||
void ISerializable.Serialize(BinaryWriter writer) | ||
{ | ||
writer.Write((byte)Type); | ||
writer.Write(Hashes); | ||
writer.Write(Inventories); | ||
} | ||
} | ||
} |
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,44 @@ | ||
using AntShares.IO; | ||
using System; | ||
using System.IO; | ||
|
||
namespace AntShares.Network.Payloads | ||
{ | ||
internal class InventoryVector : IEquatable<InventoryVector>, ISerializable | ||
{ | ||
public InventoryType Type; | ||
public UInt256 Hash; | ||
|
||
void ISerializable.Deserialize(BinaryReader reader) | ||
{ | ||
Type = (InventoryType)reader.ReadUInt32(); | ||
if (!Enum.IsDefined(typeof(InventoryType), Type)) | ||
throw new FormatException(); | ||
Hash = reader.ReadSerializable<UInt256>(); | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
if (!(obj is InventoryVector)) return false; | ||
return Equals((InventoryVector)obj); | ||
} | ||
|
||
public bool Equals(InventoryVector other) | ||
{ | ||
if (ReferenceEquals(other, null)) return false; | ||
if (ReferenceEquals(this, other)) return true; | ||
return Hash == other.Hash; | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return Hash.GetHashCode(); | ||
} | ||
|
||
void ISerializable.Serialize(BinaryWriter writer) | ||
{ | ||
writer.Write((uint)Type); | ||
writer.Write(Hash); | ||
} | ||
} | ||
} |
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.