public override void Deserialize(BinaryReader reader) { Version = reader.ReadUInt32(); Inputs = reader.ReadSerializableArray<TransactionInput>(); for (int i = 1; i < Inputs.Length; i++) for (int j = 0; j < i; j++) if (Inputs[i].PrevHash == Inputs[j].PrevHash && Inputs[i].PrevIndex == Inputs[j].PrevIndex) throw new FormatException(); Outputs = reader.ReadSerializableArray<TransactionOutput>(); LockTime = reader.ReadUInt32(); }
protected override void DeserializeExclusiveData(BinaryReader reader) { this.Enrollments = reader.ReadSerializableArray<UInt256>(); if (Enrollments.Length == 0 || Enrollments.Length > 1024) throw new FormatException(); if (Enrollments.Length != Enrollments.Distinct().Count()) throw new FormatException(); }
void ISignable.FromUnsignedArray(byte[] value) { using (MemoryStream ms = new MemoryStream(value, false)) using (BinaryReader reader = new BinaryReader(ms)) { this.AssetId = reader.ReadSerializable<UInt256>(); this.ValueAssetId = reader.ReadSerializable<UInt256>(); this.Agent = reader.ReadSerializable<UInt160>(); this.Amount = reader.ReadSerializable<Fixed8>(); this.Price = reader.ReadSerializable<Fixed8>(); this.Client = reader.ReadSerializable<UInt160>(); this.Inputs = reader.ReadSerializableArray<TransactionInput>(); } }
private void DeserializeUnsignedInternal(BinaryReader reader, UInt256 asset_id, UInt256 value_asset_id, UInt160 agent) { AssetId = asset_id; ValueAssetId = value_asset_id; Agent = agent; Amount = reader.ReadSerializable<Fixed8>(); if (Amount == Fixed8.Zero) throw new FormatException(); if (Amount.GetData() % 10000 != 0) throw new FormatException(); Price = reader.ReadSerializable<Fixed8>(); if (Price <= Fixed8.Zero) throw new FormatException(); if (Price.GetData() % 10000 != 0) throw new FormatException(); Client = reader.ReadSerializable<UInt160>(); Inputs = reader.ReadSerializableArray<TransactionInput>(); if (Inputs.Distinct().Count() != Inputs.Length) throw new FormatException(); }
void ISignable.DeserializeUnsigned(BinaryReader reader) { PrevHash = reader.ReadSerializable<UInt256>(); Miner = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1); IV = reader.ReadBytes(16); NoncePieces.Clear(); int count = (int)reader.ReadVarInt(); for (int i = 0; i < count; i++) { ECPoint key = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1); if (key == Miner) throw new FormatException(); byte[] value = reader.ReadBytes((int)reader.ReadVarInt()); NoncePieces.Add(key, value); } NonceHash = reader.ReadSerializable<UInt256>(); TransactionHashes = reader.ReadSerializableArray<UInt256>(); }
public override void Deserialize(BinaryReader reader) { this.PrevHash = reader.ReadSerializable<UInt256>(); this.Miner = Secp256r1Point.DeserializeFrom(reader); this.NoncePieces.Clear(); int count = (int)reader.ReadVarInt(); for (int i = 0; i < count; i++) { Secp256r1Point key = Secp256r1Point.DeserializeFrom(reader); if (key == Miner) throw new FormatException(); byte[] value = reader.ReadBytes((int)reader.ReadVarInt()); NoncePieces.Add(key, value); } this.NonceHash = reader.ReadSerializable<UInt256>(); this.TransactionHashes = reader.ReadSerializableArray<UInt256>(); this.Script = reader.ReadBytes((int)reader.ReadVarInt()); }
private void DeserializeWithoutType(BinaryReader reader) { DeserializeExclusiveData(reader); this.Inputs = reader.ReadSerializableArray<TransactionInput>(); if (GetAllInputs().Distinct().Count() != GetAllInputs().Count()) throw new FormatException(); this.Outputs = reader.ReadSerializableArray<TransactionOutput>(); if (Outputs.Any(p => p.Value == Fixed8.Zero)) throw new FormatException(); this.Scripts = reader.ReadBytesArray(); }
void ISignable.FromUnsignedArray(byte[] value) { using (MemoryStream ms = new MemoryStream(value, false)) using (BinaryReader reader = new BinaryReader(ms)) { if ((TransactionType)reader.ReadByte() != Type) throw new FormatException(); DeserializeExclusiveData(reader); this.Inputs = reader.ReadSerializableArray<TransactionInput>(); this.Outputs = reader.ReadSerializableArray<TransactionOutput>(); } }
protected override void DeserializeExclusiveData(BinaryReader reader) { this.Attributes = reader.ReadSerializableArray<TransactionAttribute>(); }
internal static Transaction DeserializeFrom(BinaryReader reader) { TransactionType type = (TransactionType)reader.ReadByte(); string typeName = string.Format("{0}.{1}", typeof(Transaction).Namespace, type); Transaction transaction = typeof(Transaction).Assembly.CreateInstance(typeName) as Transaction; if (transaction == null) throw new FormatException(); transaction.DeserializeUnsignedWithoutType(reader); transaction.Scripts = reader.ReadSerializableArray<Script>(); return transaction; }
private void DeserializeUnsignedWithoutType(BinaryReader reader) { DeserializeExclusiveData(reader); Attributes = reader.ReadSerializableArray<TransactionAttribute>(); Inputs = reader.ReadSerializableArray<TransactionInput>(); TransactionInput[] inputs = GetAllInputs().ToArray(); for (int i = 1; i < inputs.Length; i++) for (int j = 0; j < i; j++) if (inputs[i].PrevHash == inputs[j].PrevHash && inputs[i].PrevIndex == inputs[j].PrevIndex) throw new FormatException(); Outputs = reader.ReadSerializableArray<TransactionOutput>(); if (Outputs.Length > ushort.MaxValue + 1) throw new FormatException(); }
void ISignable.FromUnsignedArray(byte[] value) { using (MemoryStream ms = new MemoryStream(value, false)) using (BinaryReader reader = new BinaryReader(ms)) { this.PrevHash = reader.ReadSerializable<UInt256>(); this.Miner = Secp256r1Point.DeserializeFrom(reader); this.NoncePieces.Clear(); int count = (int)reader.ReadVarInt(); for (int i = 0; i < count; i++) { Secp256r1Point key = Secp256r1Point.DeserializeFrom(reader); if (key == Miner) throw new FormatException(); value = reader.ReadBytes((int)reader.ReadVarInt()); NoncePieces.Add(key, value); } this.NonceHash = reader.ReadSerializable<UInt256>(); this.TransactionHashes = reader.ReadSerializableArray<UInt256>(); } }
internal void DeserializeInTransaction(BinaryReader reader, AgencyTransaction tx) { DeserializeUnsignedInternal(reader, tx.AssetId, tx.ValueAssetId, tx.Agent); Scripts = reader.ReadSerializableArray<Script>(); }
void ISerializable.Deserialize(BinaryReader reader) { this.Headers = reader.ReadSerializableArray<BlockHeader>(); }
void ISerializable.Deserialize(BinaryReader reader) { this.Version = reader.ReadUInt32(); this.HashStart = reader.ReadSerializableArray<UInt256>(); this.HashStop = reader.ReadSerializable<UInt256>(); }
public LevelDBBlockchain(string path) { header_index.Add(GenesisBlock.Hash); Version version; Slice value; db = DB.Open(path, new Options { CreateIfMissing = true }); if (db.TryGet(ReadOptions.Default, SliceBuilder.Begin(DataEntryPrefix.CFG_Version), out value) && Version.TryParse(value.ToString(), out version) && version >= Version.Parse("0.4")) { ReadOptions options = new ReadOptions { FillCache = false }; value = db.Get(options, SliceBuilder.Begin(DataEntryPrefix.SYS_CurrentBlock)); this.current_block_hash = new UInt256(value.ToArray().Take(32).ToArray()); this.current_block_height = BitConverter.ToUInt32(value.ToArray(), 32); foreach (Block header in db.Find(options, SliceBuilder.Begin(DataEntryPrefix.DATA_HeaderList), (k, v) => { using (MemoryStream ms = new MemoryStream(v.ToArray(), false)) using (BinaryReader r = new BinaryReader(ms)) { return new { Index = BitConverter.ToUInt32(k.ToArray(), 1), Headers = r.ReadSerializableArray<Block>() }; } }).OrderBy(p => p.Index).SelectMany(p => p.Headers).ToArray()) { if (header.Hash != GenesisBlock.Hash) { header_chain.Add(header.Hash, header, header.PrevBlock); header_index.Add(header.Hash); } stored_header_count++; } if (stored_header_count == 0) { Dictionary<UInt256, Block> table = db.Find(options, SliceBuilder.Begin(DataEntryPrefix.DATA_Block), (k, v) => Block.FromTrimmedData(v.ToArray(), 0)).ToDictionary(p => p.PrevBlock); for (UInt256 hash = GenesisBlock.Hash; hash != current_block_hash;) { Block header = table[hash]; header_chain.Add(header.Hash, header, header.PrevBlock); header_index.Add(header.Hash); hash = header.Hash; } } else if (current_block_height >= stored_header_count) { List<Block> list = new List<Block>(); for (UInt256 hash = current_block_hash; hash != header_index[(int)stored_header_count - 1];) { Block header = Block.FromTrimmedData(db.Get(options, SliceBuilder.Begin(DataEntryPrefix.DATA_Block).Add(hash)).ToArray(), 0); list.Add(header); header_index.Insert((int)stored_header_count, hash); hash = header.PrevBlock; } for (int i = list.Count - 1; i >= 0; i--) { header_chain.Add(list[i].Hash, list[i], list[i].PrevBlock); } } this.current_header_hash = header_index[header_index.Count - 1]; } else { WriteBatch batch = new WriteBatch(); ReadOptions options = new ReadOptions { FillCache = false }; using (Iterator it = db.NewIterator(options)) { for (it.SeekToFirst(); it.Valid(); it.Next()) { batch.Delete(it.Key()); } } db.Write(WriteOptions.Default, batch); Persist(GenesisBlock); db.Put(WriteOptions.Default, SliceBuilder.Begin(DataEntryPrefix.CFG_Version), Assembly.GetExecutingAssembly().GetName().Version.ToString()); } thread_persistence = new Thread(PersistBlocks); thread_persistence.Name = "LevelDBBlockchain.PersistBlocks"; thread_persistence.Start(); AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit; }
void ISerializable.Deserialize(BinaryReader reader) { HashStart = reader.ReadSerializableArray<UInt256>(); HashStop = reader.ReadSerializable<UInt256>(); }
public override void Deserialize(BinaryReader reader) { ((ISignable)this).DeserializeUnsigned(reader); Scripts = reader.ReadSerializableArray<Script>(); }
void ISerializable.Deserialize(BinaryReader reader) { this.Headers = reader.ReadSerializableArray<Block>(); if (Headers.Any(p => !p.IsHeader)) throw new FormatException(); }
void ISerializable.Deserialize(BinaryReader reader) { this.AddressList = reader.ReadSerializableArray<NetworkAddressWithTime>(); }
void ISerializable.Deserialize(BinaryReader reader) { Inventories = reader.ReadSerializableArray<InventoryVector>(); }