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; } } }
/// <summary> /// Use the signature data, with the transaction data, to create the TransactionContent /// </summary> /// <param name="signature"></param> /// <param name="transactionContent"></param> /// <returns></returns> public TransactionProcessingResult Create(Hash signature, out TransactionContent transactionContent) { TC.SetSignatures(new List<Hash> { signature }); transactionContent = TC; return TC.VerifySignature(); }
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 SingleTransactionFactory(AccountIdentifier source, AccountIdentifier destination, long transactionFee, long destValue) { this.source = source; this.destination = destination; this.destValue = destValue; this.transactionFee = transactionFee; TransactionEntity teSrc = new TransactionEntity(this.source, destValue + transactionFee); TransactionEntity teDst = new TransactionEntity(this.destination, destValue); long Time = DateTime.UtcNow.ToFileTimeUtc(); TC = new TransactionContent(new TransactionEntity[] { teSrc }, new TransactionEntity[] { teDst }, transactionFee, Time); tranxData = TC.GetTransactionData(); }
/// <summary> /// Insert a new transaction to the incoming transaction processing queue. /// This queue is processed from time to time. /// </summary> /// <param name="transactionContent"></param> /// <param name="senderPublicKey"></param> public void InsertNewTransaction(TransactionContent transactionContent, Hash senderPublicKey) { TransactionProcessingResult rslt = transactionContent.VerifySignature(); if (rslt == TransactionProcessingResult.Accepted) { // Insert if the transaction does not already exist. if (!IncomingTransactions.ContainsKey(transactionContent.TransactionID)) { IncomingTransactions.TryAdd(transactionContent.TransactionID, transactionContent); } } else { // Add the user to the blacklist if signature is invalid or integrity checks fails. nodeState.GlobalBlacklistedUsers.Add(senderPublicKey); } }
/// <summary> /// Handles Propagation request /// </summary> /// <param name="transactionContent"></param> /// <returns></returns> public TransactionProcessingResult HandlePropagationRequest(TransactionContent transactionContent) { Interlocked.Increment(ref nodeState.NodeInfo.NodeDetails.TransactionsProcessed); TransactionProcessingResult rslt = transactionContent.VerifySignature(); transactionStateManager.Set(transactionContent.TransactionID, rslt); transactionStateManager.Set(transactionContent.TransactionID, TransactionStatusType.Proposed); if (!IncomingPropagations_ALL.ContainsKey(transactionContent.TransactionID)) { IncomingPropagations_ALL.TryAdd(transactionContent.TransactionID, transactionContent); } if (rslt == TransactionProcessingResult.Accepted) { lock (transactionLock) { // Insert if the transaction does not already exist. if (!IncomingPropagations.ContainsKey(transactionContent.TransactionID)) { if (IncomingPropagations.TryAdd(transactionContent.TransactionID, transactionContent)) { transactionStateManager.Set(transactionContent.TransactionID, TransactionStatusType.InPreProcessing); } else { DisplayUtils.Display("IncomingTransactionMap : HandlePropagationRequest : IncomingPropagations.TryAdd Failed", DisplayType.Warning); } } } } return rslt; }
public TransactionContentData() { TransactionContent = new TransactionContent(); ForwardersPK = new HashSet<Hash>(); }
public TransactionContentPack(Hash Source, TransactionContent Transacation) { this.Source = Source; this.Transacation = Transacation; }
/// <summary> /// Add a transaction to the transaction store. /// Currently no method to revoke transactions. /// Do nor call directly in a loop, use BeginTransaction / Commit. /// </summary> /// <param name="transactionContent"></param> /// <returns></returns> DBResponse AddUpdate(TransactionContent transactionContent, SQLiteTransaction transaction, long sequenceNumber) { bool doUpdate = false; using (SQLiteCommand cmd = new SQLiteCommand("SELECT TransactionID FROM Transactions WHERE TransactionID = @transactionID;", sqliteConnection, transaction)) { cmd.Parameters.Add(new SQLiteParameter("@transactionID", transactionContent.TransactionID.Hex)); SQLiteDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { doUpdate = true; // Perform update as the entry already exists. } } DBResponse response = DBResponse.Exception; if (doUpdate) { // ///////////// Perform the UPDATE /////////////// // WELL ITS IMPLEMENTED BUT NOT NEEDED. // Not emplemet because of the unnecessary added complexity of handling the history table. throw new NotImplementedException("Unsupported right now. Technically not needed. Transactions need to be only added and fetched."); /* using (SQLiteCommand cmd = new SQLiteCommand("UPDATE Transactions SET SerializedContent = @serializedContent WHERE TransactionID = @transactionID;", sqliteConnection)) { cmd.Parameters.Add(new SQLiteParameter("@transactionID", transactionContent.TransactionID.Hex)); cmd.Parameters.Add(new SQLiteParameter("@serializedContent", transactionContent.Serialize())); if (cmd.ExecuteNonQuery() != 1) { response = DBResponse.UpdateFailed; } else { response = DBResponse.UpdateSuccess; } }*/ } else { /////////////// Perform the INSERT /////////////// using (SQLiteCommand cmd = new SQLiteCommand("INSERT INTO Transactions VALUES(@transactionID, @sequenceNumber, @serializedContent);", sqliteConnection)) { cmd.Parameters.Add(new SQLiteParameter("@transactionID", transactionContent.TransactionID.Hex)); cmd.Parameters.Add(new SQLiteParameter("@sequenceNumber", sequenceNumber)); cmd.Parameters.Add(new SQLiteParameter("@serializedContent", transactionContent.Serialize())); if (cmd.ExecuteNonQuery() != 1) { response = DBResponse.InsertFailed; } else { response = DBResponse.InsertSuccess; } } if (response == DBResponse.InsertSuccess) { // Add to the History Table foreach (TransactionEntity entity in transactionContent.Sources) { InsertToHistoryTable(transactionContent.TransactionID, transactionContent.Timestamp, entity, transaction); } foreach (TransactionEntity entity in transactionContent.Destinations) { InsertToHistoryTable(transactionContent.TransactionID, transactionContent.Timestamp, entity, transaction); } } } return response; }
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; }
public JS_TransactionReply(TransactionContent content) { VersionData = content.VersionData; ExecutionData = content.ExecutionData; Sources = (from src in content.Sources select new JS_TransactionEntity(src)).ToArray(); Destinations = (from dst in content.Destinations select new JS_TransactionEntity(dst)).ToArray(); Signatures = (from sig in content.Signatures select sig.Hex).ToList(); Timestamp = content.Timestamp; TransactionID = content.TransactionID.Hex; TransactionFee = content.TransactionFee; Value = content.Value; }
public void Add(TransactionContent transactionContent) { TxContent.Add(transactionContent); }
public TransactionContentSet(long sequenceNumber, TransactionContent transactionContent) { TxContent.Add(transactionContent); SequenceNumber = sequenceNumber; }