public void Deserialize(byte[] Data) { List<ProtocolDataType> PDTs = ProtocolPackager.UnPackRaw(Data); int cnt = 0; while (cnt < (int)PDTs.Count) { ProtocolDataType PDT = PDTs[cnt++]; switch (PDT.NameType) { case 0: { ProtocolPackager.UnpackInt64(PDT, 0, ref SequenceNumber); } break; case 1: { byte[] tempSource = new byte[0]; ProtocolPackager.UnpackByteVector(PDT, 1, ref tempSource); if (tempSource.Length > 0) { TransactionContent tsk = new TransactionContent(); tsk.Deserialize(tempSource); TxContent.Add(tsk); } } break; } } }
public void Deserialize(byte[] data) { List<ProtocolDataType> PDTs = ProtocolPackager.UnPackRaw(data); foreach (ProtocolDataType pdt in PDTs) { TransactionContent tc = new TransactionContent(); byte[] tcdata = new byte[0]; ProtocolPackager.UnpackByteVector(pdt, 0, ref tcdata); tc.Deserialize(tcdata); transactions.Add(tc.TransactionID, tc); } }
public DBResponse FetchTransaction(out TransactionContent transactionContent, out long sequenceNumber, Hash transactionID) { DBResponse response = DBResponse.FetchFailed; sequenceNumber = -1; using (SQLiteCommand cmd = new SQLiteCommand("SELECT * FROM Transactions WHERE TransactionID = @transactionID;", sqliteConnection)) { cmd.Parameters.Add(new SQLiteParameter("@transactionID", transactionID.Hex)); using (SQLiteDataReader reader = cmd.ExecuteReader()) { transactionContent = default(TransactionContent); if (reader.HasRows) { if (reader.Read()) { Hash _transactionID = new Hash((byte[])reader[0]); if (_transactionID == transactionID) // Proper row returned. { sequenceNumber = (long)reader[1]; transactionContent = new TransactionContent(); transactionContent.Deserialize((byte[])reader[2]); if (transactionContent.TransactionID == transactionID) // De-Serialization Suceeded. { response = DBResponse.FetchSuccess; } else { response = DBResponse.NonDBError; } } } } } } return response; }
public DBResponse FetchBySequenceNumber(out List<TransactionContentSet> transactions, long sequenceNumber, long Count) { DBResponse response = DBResponse.NonDBError; long sequenceMax = sequenceNumber + Count; string LIMIT_CLAUSE = "LIMIT " + Constants.DB_HISTORY_TX_LIMIT; using (SQLiteCommand cmd = new SQLiteCommand("SELECT * FROM Transactions WHERE (SequenceNumber >= @sequenceNumber AND SequenceNumber < @sequenceMax ) ORDER BY TimeStamp DESC " + LIMIT_CLAUSE + ";", sqliteConnection)) { cmd.Parameters.Add(new SQLiteParameter("@sequenceNumber", sequenceNumber)); cmd.Parameters.Add(new SQLiteParameter("@sequenceMax", sequenceMax)); using (SQLiteDataReader reader = cmd.ExecuteReader()) { transactions = new List<TransactionContentSet>(); if (reader.HasRows) { Dictionary<long, TransactionContentSet> transactionContentSet = new Dictionary<long, TransactionContentSet>(); while (reader.Read()) { Hash _transactionID = new Hash((byte[])reader[0]); sequenceNumber = (long)reader[1]; TransactionContent transactionContent = new TransactionContent(); transactionContent.Deserialize((byte[])reader[2]); if (_transactionID == transactionContent.TransactionID) { if (transactionContentSet.ContainsKey(sequenceNumber)) { transactionContentSet[sequenceNumber].Add(transactionContent); } else { transactionContentSet.Add(sequenceNumber, new TransactionContentSet(sequenceNumber, transactionContent)); } response = DBResponse.FetchSuccess; } else // BAD TRANSACTION DECODE. Real Bad. Should not happen !!! { return DBResponse.Exception; } } transactions.AddRange(transactionContentSet.Values); } } } return response; }