Example #1
0
 public void Write(BinaryWriter writer)
 {
     writer.Write(NumberOfPeels);
     writer.Write(PerformedFirstPeel);
     writer.Write(AvgTimeBetweenPeels);
     writer.Write(NumberOfDumps);
     writer.Write(AvgTimeBetweenDumps);
     writer.Write(IsWinner);
     writer.WriteList(RawGameData);
 }
Example #2
0
 public static void EncodeBlockSpentTxes(BinaryWriter writer, BlockSpentTxes blockSpentTxes)
 {
     writer.WriteList(blockSpentTxes, spentTx => EncodeSpentTx(writer, spentTx));
 }
Example #3
0
 public static void EncodeUnmintedTxList(BinaryWriter writer, IImmutableList<UnmintedTx> unmintedTxes)
 {
     writer.WriteList(unmintedTxes, unmintedTx => EncodeUnmintedTx(writer, unmintedTx));
 }
Example #4
0
 public static void EncodeBlock(BinaryWriter writer, Block block)
 {
     EncodeBlockHeader(writer, block.Header);
     writer.WriteList(block.BlockTxes, tx => writer.WriteBytes(tx.TxBytes.ToArray()));
 }
Example #5
0
 public static void EncodePrevTxOutputList(BinaryWriter writer, ImmutableArray<PrevTxOutput> txOutputs)
 {
     writer.WriteList(txOutputs, output => EncodePrevTxOutput(writer, output));
 }
Example #6
0
        private async Task WriteItemsToDisk(IList<ReaderItem> items, SourceProvider source)
        {
            var filename = GetFileName(GetCacheFile(source));

            using (var file = await _storage.Local.CreateFileAsync(filename))
            {
                using (var writer = new BinaryWriter(file))
                {
                    writer.WriteList(items);
                }
            }

            await SetSinceDate(source, DateTime.Now).ConfigureAwait(false);
        }
Example #7
0
        public bool TryAddBlockSpentTxes(int blockIndex, BlockSpentTxes spentTxes)
        {
            CheckWriteTransaction();

            try
            {
                using (SetSessionContext())
                using (var jetUpdate = this.jetSession.BeginUpdate(this.spentTxTableId, JET_prep.Insert))
                {
                    byte[] spentTxesBytes;
                    using (var stream = new MemoryStream())
                    using (var writer = new BinaryWriter(stream))
                    {
                        writer.WriteList<SpentTx>(spentTxes, spentTx => DataEncoder.EncodeSpentTx(writer, spentTx));
                        spentTxesBytes = stream.ToArray();
                    }

                    Api.SetColumns(this.jetSession, this.spentTxTableId,
                        new Int32ColumnValue { Columnid = this.spentSpentBlockIndexColumnId, Value = blockIndex },
                        new BytesColumnValue { Columnid = this.spentDataColumnId, Value = spentTxesBytes });

                    jetUpdate.Save();
                }

                return true;
            }
            catch (EsentKeyDuplicateException)
            {
                return false;
            }
        }
Example #8
0
 public static void EncodeAddressPayload(BinaryWriter writer, AddressPayload addressPayload)
 {
     writer.WriteList(addressPayload.NetworkAddresses, networkAddress => EncodeNetworkAddressWithTime(writer, networkAddress));
 }
        public bool TryAddBlockUnmintedTxes(UInt256 blockHash, IImmutableList<UnmintedTx> unmintedTxes)
        {
            CheckWriteTransaction();

            var key = DbEncoder.EncodeUInt256(blockHash);
            if (!this.txn.ContainsKey(blockUnmintedTxesTableId, key))
            {
                byte[] unmintedTxesBytes;
                using (var stream = new MemoryStream())
                using (var writer = new BinaryWriter(stream))
                {
                    writer.WriteList(unmintedTxes, unmintedTx => DataEncoder.EncodeUnmintedTx(writer, unmintedTx));
                    unmintedTxesBytes = stream.ToArray();
                }

                this.txn.Put(blockUnmintedTxesTableId, key, unmintedTxesBytes);

                return true;
            }
            else
            {
                return false;
            }
        }
        public bool TryAddBlockSpentTxes(int blockIndex, BlockSpentTxes spentTxes)
        {
            CheckWriteTransaction();

            var key = DbEncoder.EncodeInt32(blockIndex);
            if (!this.txn.ContainsKey(blockSpentTxesTableId, key))
            {
                byte[] spentTxesBytes;
                using (var stream = new MemoryStream())
                using (var writer = new BinaryWriter(stream))
                {
                    writer.WriteList(spentTxes, spentTx => DataEncoder.EncodeSpentTx(writer, spentTx));
                    spentTxesBytes = stream.ToArray();
                }

                this.txn.Put(blockSpentTxesTableId, key, spentTxesBytes);

                return true;
            }
            else
            {
                return false;
            }
        }
Example #11
0
 public void Write(BinaryWriter writer)
 {
     writer.WriteList(_GameData);
 }
Example #12
0
 public void Write(BinaryWriter writer)
 {
     writer.WriteList(Friends);
 }
Example #13
0
 public static void EncodeUnmintedTx(BinaryWriter writer, UnmintedTx unmintedTx)
 {
     writer.WriteUInt256(unmintedTx.TxHash);
     writer.WriteList(unmintedTx.PrevOutputTxKeys, x => EncodeTxLookupKey(writer, x));
 }
Example #14
0
        public static byte[] EncodeTransaction(UInt32 Version, ImmutableArray<TxInput> Inputs, ImmutableArray<TxOutput> Outputs, UInt32 LockTime)
        {
            using (var stream = new MemoryStream())
            using (var writer = new BinaryWriter(stream))
            {
                writer.WriteUInt32(Version);
                writer.WriteList(Inputs, input => EncodeTxInput(writer, input));
                writer.WriteList(Outputs, output => EncodeTxOutput(writer, output));
                writer.WriteUInt32(LockTime);

                return stream.ToArray();
            }
        }
Example #15
0
 public static void EncodeBlock(BinaryWriter writer, Block block)
 {
     EncodeBlockHeader(writer, block.Header);
     writer.WriteList(block.Transactions, tx => EncodeTransaction(writer, tx));
 }
Example #16
0
        public void Write(BinaryWriter writer)
        {
            writer.Write((byte)PacketType);
            writer.Write(Sender);
            writer.WriteList(Recipients);

            var type = DataPacket.PacketTypeMap[PacketType];

            if (type == typeof (string))
            {
                var stringData = Data as string;
                if (null != stringData)
                {
                    writer.Write(stringData);
                }
            }
            else
            {
                var binaryData = Data as IBinarySerializable;
                if (null != binaryData)
                {
                    writer.Write(binaryData);
                }
            }
        }
Example #17
0
 public static void EncodeInventoryPayload(BinaryWriter writer, InventoryPayload invPayload)
 {
     writer.WriteList(invPayload.InventoryVectors, invVector => EncodeInventoryVector(writer, invVector));
 }
Example #18
0
 public static void EncodeTransaction(BinaryWriter writer, Transaction tx)
 {
     writer.WriteUInt32(tx.Version);
     writer.WriteList(tx.Inputs, input => EncodeTxInput(writer, input));
     writer.WriteList(tx.Outputs, output => EncodeTxOutput(writer, output));
     writer.WriteUInt32(tx.LockTime);
 }
Example #19
0
 public static void EncodeGetBlocksPayload(BinaryWriter writer, GetBlocksPayload getBlocksPayload)
 {
     writer.WriteUInt32(getBlocksPayload.Version);
     writer.WriteList(getBlocksPayload.BlockLocatorHashes, locatorHash => writer.WriteUInt256(locatorHash));
     writer.WriteUInt256(getBlocksPayload.HashStop);
 }
Example #20
0
        public static DecodedTx EncodeTransaction(UInt32 Version, ImmutableArray<TxInput> Inputs, ImmutableArray<TxOutput> Outputs, UInt32 LockTime)
        {
            using (var stream = new MemoryStream())
            using (var writer = new BinaryWriter(stream))
            {
                writer.WriteUInt32(Version);
                writer.WriteList(Inputs, input => EncodeTxInput(writer, input));
                writer.WriteList(Outputs, output => EncodeTxOutput(writer, output));
                writer.WriteUInt32(LockTime);

                var txBytes = stream.ToArray();
                var txHash = new UInt256(SHA256Static.ComputeDoubleHash(txBytes));
                var tx = new Transaction(Version, Inputs, Outputs, LockTime, txHash);

                return new DecodedTx(txBytes.ToImmutableArray(), tx);
            }
        }
Example #21
0
        public bool TryAddBlockUnmintedTxes(UInt256 blockHash, IImmutableList<UnmintedTx> unmintedTxes)
        {
            CheckWriteTransaction();

            try
            {
                using (SetSessionContext())
                using (var jetUpdate = this.jetSession.BeginUpdate(this.unmintedTxTableId, JET_prep.Insert))
                {
                    byte[] unmintedTxesBytes;
                    using (var stream = new MemoryStream())
                    using (var writer = new BinaryWriter(stream))
                    {
                        writer.WriteList(unmintedTxes, unmintedTx => DataEncoder.EncodeUnmintedTx(writer, unmintedTx));
                        unmintedTxesBytes = stream.ToArray();
                    }

                    Api.SetColumns(this.jetSession, this.unmintedTxTableId,
                        new BytesColumnValue { Columnid = this.unmintedBlockHashColumnId, Value = DbEncoder.EncodeUInt256(blockHash) },
                        new BytesColumnValue { Columnid = this.unmintedDataColumnId, Value = unmintedTxesBytes });

                    jetUpdate.Save();
                }

                return true;
            }
            catch (EsentKeyDuplicateException)
            {
                return false;
            }
        }
Example #22
0
 public void Write(BinaryWriter writer)
 {
     writer.Write(GameHost);
     writer.WriteList(GameMoves);
     writer.Write(Winner);
     writer.Write(GameDuration);
     writer.Write(GameStartTime);
     writer.WriteDictionary(PlayerDictionary);
 }