-func (t *Tracker) Retrive_transaction(subID uint16, act Action) (*Transaction, error){
- key := Transaction_key{subID, act}
- if xact, ok := t.transaction_table[key]; ok {
+func (t *Tracker) UpdateTransaction(SubID uint16, transType Action, xact Transaction) error {
+ key := TransactionKey{SubID, transType}
+ t.mutex.Lock()
+ defer t.mutex.Unlock()
+ if _, ok := t.transactionTable[key]; ok {
+ // TODO: Implement merge related check here. If the key is same but the value is different.
+ err := fmt.Errorf("transaction tracker: Similar transaction with sub id %d and type %v is ongoing", key.SubID, key.transType)
+ return err
+ }
+ t.transactionTable[key] = xact
+ return nil
+}
+
+/*
+Retreives the transaction table entry for the given request.
+Returns error in case the transaction cannot be found.
+*/
+func (t *Tracker) RetriveTransaction(subID uint16, act Action) (Transaction, error) {
+ key := TransactionKey{subID, act}
+ t.mutex.Lock()
+ defer t.mutex.Unlock()
+ var xact Transaction
+ if xact, ok := t.transactionTable[key]; ok {