void ISerializable.Deserialize(BinaryReader reader) { Usage = (TransactionAttributeUsage)reader.ReadByte(); if (Usage == TransactionAttributeUsage.ContractHash || Usage == TransactionAttributeUsage.Vote || (Usage >= TransactionAttributeUsage.Hash1 && Usage <= TransactionAttributeUsage.Hash15)) { Data = reader.ReadBytes(32); } else if (Usage == TransactionAttributeUsage.ECDH02 || Usage == TransactionAttributeUsage.ECDH03) { Data = new[] { (byte)Usage }.Concat(reader.ReadBytes(32)).ToArray(); } else if (Usage == TransactionAttributeUsage.Script) { Data = reader.ReadBytes(20); } else if (Usage == TransactionAttributeUsage.DescriptionUrl) { Data = reader.ReadBytes(reader.ReadByte()); } else if (Usage == TransactionAttributeUsage.Description || Usage >= TransactionAttributeUsage.Remark) { Data = reader.ReadVarBytes(ushort.MaxValue); } else { throw new FormatException(); } }
public bool IsValidAttributeType(TransactionAttributeUsage usage) { return(usage == TransactionAttributeUsage.Nonce || usage == TransactionAttributeUsage.Script || usage == TransactionAttributeUsage.Description || usage == TransactionAttributeUsage.DescriptionUrl); }
void ISerializable.Deserialize(BinaryReader reader) { this.Usage = (TransactionAttributeUsage)reader.ReadByte(); if (!Enum.IsDefined(typeof(TransactionAttributeUsage), Usage)) throw new FormatException(); int length; switch (Usage) { case TransactionAttributeUsage.ContractHash: case TransactionAttributeUsage.ECDH02: case TransactionAttributeUsage.ECDH03: length = 32; break; case TransactionAttributeUsage.LockAfter: case TransactionAttributeUsage.LockBefore: length = 4; break; default: if (Usage >= TransactionAttributeUsage.Remark) length = reader.ReadByte(); else throw new FormatException(); break; } this.Data = reader.ReadBytes(length); }
void ISerializable.Deserialize(BinaryReader reader) { this.Usage = (TransactionAttributeUsage)reader.ReadByte(); if (!Enum.IsDefined(typeof(TransactionAttributeUsage), Usage)) { throw new FormatException(); } int length; switch (Usage) { case TransactionAttributeUsage.ContractHash: case TransactionAttributeUsage.ECDH02: case TransactionAttributeUsage.ECDH03: length = 32; break; case TransactionAttributeUsage.LockAfter: case TransactionAttributeUsage.LockBefore: length = 4; break; default: if (Usage >= TransactionAttributeUsage.Remark) { length = reader.ReadByte(); } else { throw new FormatException(); } break; } this.Data = reader.ReadBytes(length); }
public void Size_Get_Hash() { for (TransactionAttributeUsage i = TransactionAttributeUsage.Hash1; i <= TransactionAttributeUsage.Hash15; i++) { uut.Usage = i; uut.Size.Should().Be(33); // 1 + 32 } }
void ISerializable.Deserialize(BinaryReader reader) { Usage = (TransactionAttributeUsage)reader.ReadByte(); if (!Enum.IsDefined(typeof(TransactionAttributeUsage), Usage)) { throw new FormatException(); } Data = reader.ReadVarBytes(252); }
private byte[] GetAttributeByUsage(TransactionState tx, TransactionAttributeUsage u) { var v = tx.Transaction.Attributes.Where(x => x.Usage == u).FirstOrDefault(); if (v == null) { return(null); } return(v.Data); }
void ISerializable.Deserialize(BinaryReader reader) { Usage = (TransactionAttributeUsage)reader.ReadByte(); if (Usage == TransactionAttributeUsage.ContractHash || Usage == TransactionAttributeUsage.Vote || (Usage >= TransactionAttributeUsage.Hash1 && Usage <= TransactionAttributeUsage.Hash15)) { Data = reader.ReadBytes(32); } else if (Usage == TransactionAttributeUsage.ECDH02 || Usage == TransactionAttributeUsage.ECDH03) { Data = new[] { (byte)Usage } }
public static bool IsContainAttributeUsage(this Transaction tx, TransactionAttributeUsage usage) { if (tx.Attributes == default || tx.Attributes.Length == 0) { return(false); } foreach (var attr in tx.Attributes) { if (attr.Usage == usage) { return(true); } } return(false); }
void ISerializable.Deserialize(BinaryReader reader) { Usage = (TransactionAttributeUsage)reader.ReadByte(); if (Usage == TransactionAttributeUsage.Cosigner) { Data = reader.ReadBytes(20); } else if (Usage == TransactionAttributeUsage.Url) { Data = reader.ReadVarBytes(252); } else { throw new FormatException(); } }
void ISerializable.Deserialize(BinaryReader reader) { Usage = (TransactionAttributeUsage)reader.ReadByte(); int length; switch (Usage) { case TransactionAttributeUsage.ContractHash: case TransactionAttributeUsage.ECDH02: case TransactionAttributeUsage.ECDH03: length = 32; break; case TransactionAttributeUsage.Remark: case TransactionAttributeUsage.Script: length = reader.ReadByte(); break; default: throw new FormatException(); } Data = reader.ReadBytes(length); }
public TransactionAttribute(TransactionAttributeUsage usage, byte[] data) { Usage = usage; Data = data; }