-
Notifications
You must be signed in to change notification settings - Fork 0
/
processor.go
58 lines (51 loc) · 1.97 KB
/
processor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package relayer_srv
import (
"fmt"
"sync"
"github.com/volmexfinance/relayers/relayer-srv/db"
"github.com/volmexfinance/relayers/relayer-srv/worker"
)
var lock sync.Mutex
// TODO: relayer sign check should be included here
func (r *RelayerSrv) SendToContract(orderLeft, orderRight []*db.Order, orderIDs []string, relayerSigns [][]byte, wrkr *worker.Worker) (*db.TransactionSent, error) {
lock.Lock()
defer lock.Unlock()
txSent := db.TransactionSent{
TransactionStatus: db.TransactionStatusTypeInit,
OrderID: orderIDs,
}
orderCombined := append(orderLeft, orderRight...)
// TODO: double spending
txHash, er := wrkr.ExecuteGnosisTx(orderLeft, orderRight, relayerSigns)
if er != nil {
txSent.TransactionStatus = db.TransactionStatusTypeSentFailed
txSent.Error = er.Error()
r.logger.Warnf("Error sending to contract: %s", er.Error())
if err := r.postgresDB.UpdateFillAndStatusByTxnLog(orderCombined, db.MatchedStatusSentFailed); err != nil {
return &txSent, fmt.Errorf("SendToContract: Unable to update %w", er)
}
if err := r.sqlitedb.UpdateFillAndStatusByTxnLog(orderCombined, db.MatchedStatusSentFailed); err != nil {
return &txSent, fmt.Errorf("SendToContract: Unable to update %w", er)
}
if err := r.postgresDB.CreateTxSent(&txSent, wrkr.ChainName); err != nil {
return nil, err
}
if err := r.sqlitedb.CreateTxSent(&txSent, wrkr.ChainName); err != nil {
return nil, err
}
return &txSent, fmt.Errorf("SendToContract: %w", er)
}
r.logger.Infof("tx sent success for orderIDs: %s, txhash: %s", orderIDs, txHash)
// updating tx_sents table
txSent.TransactionHash = txHash
if err := r.postgresDB.UpdateBatchOrderStatus(orderCombined, db.MatchedStatusSentToContract); err != nil {
return &txSent, fmt.Errorf("SendToContract: %w", err)
}
if err := r.postgresDB.CreateTxSent(&txSent, wrkr.ChainName); err != nil {
return nil, err
}
if err := r.sqlitedb.CreateTxSent(&txSent, wrkr.ChainName); err != nil {
return nil, err
}
return &txSent, nil
}