MCPcopy Create free account
hub / github.com/CovenantSQL/CovenantSQL / UpsertTx

Function UpsertTx

cmd/cql-eth-exchange/tx_record.go:150–188  ·  view source on GitHub ↗

UpsertTx add or update tx record to database.

(db *gorp.DbMap, r *TxRecord)

Source from the content-addressed store, hash-verified

148
149// UpsertTx add or update tx record to database.
150func UpsertTx(db *gorp.DbMap, r *TxRecord) (d *TxRecord, err error) {
151 defer func() {
152 var auditErr = err
153
154 if d != nil && d.State != ExchangeStateDetected {
155 auditErr = errors.New("transaction already processing")
156 }
157
158 _ = AddAuditRecord(db, &AuditRecord{
159 Hash: r.Hash,
160 Op: "upsert_tx",
161 Data: r,
162 Error: auditErr.Error(),
163 })
164 }()
165
166 err = db.SelectOne(&d, `SELECT * FROM "record" WHERE "hash" = ? LIMIT 1`, r.Hash)
167 if err != nil {
168 // not exists
169 err = db.Insert(r)
170 d = r
171 return
172 }
173
174 if d.State != ExchangeStateDetected {
175 return
176 }
177
178 d.Tx = r.Tx
179 d.ETHBlockNumber = r.ETHBlockNumber
180 d.ETHFromAddr = r.ETHFromAddr
181 d.ETHToAddr = r.ETHToAddr
182 d.ETHAmount = r.ETHAmount
183 d.CQLAccount = r.CQLAccount
184 d.CQLAmount = r.CQLAmount
185 d.IsReverted = r.IsReverted
186
187 return
188}
189
190// InvalidateTx invalidates eth transactions based on block number.
191func InvalidateTx(db *gorp.DbMap, blkNumber uint64) (err error) {

Callers 1

saveTxMethod · 0.85

Calls 4

AddAuditRecordFunction · 0.85
ErrorMethod · 0.80
InsertMethod · 0.80
NewMethod · 0.65

Tested by

no test coverage detected