MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / GetTransactionList

Method GetTransactionList

api/models/transactions.go:93–151  ·  view source on GitHub ↗

GetTransactionList get a transaction list by hash marker.

(since string, page, size int)

Source from the content-addressed store, hash-verified

91
92// GetTransactionList get a transaction list by hash marker.
93func (m *TransactionsModel) GetTransactionList(since string, page, size int) (
94 txs []*Transaction, pagination *Pagination, err error,
95) {
96 var (
97 sinceBlockHeight = 0
98 sinceTxIndex = 0
99 )
100
101 if since != "" {
102 tx, err := m.GetTransactionByHash(since)
103 if tx == nil {
104 return txs, pagination, err
105 }
106 sinceBlockHeight = tx.BlockHeight
107 sinceTxIndex = tx.TxIndex
108 }
109
110 var (
111 querySQL = `
112 SELECT
113 block_height,
114 tx_index,
115 hash,
116 block_hash,
117 timestamp,
118 tx_type,
119 address,
120 raw
121 FROM
122 indexed_transactions
123 `
124 countSQL = buildCountSQL(querySQL)
125 conds []string
126 args []interface{}
127 )
128
129 pagination = NewPagination(page, size)
130 if sinceBlockHeight > 0 {
131 conds = append(conds, "(block_height < ? or (block_height = ? and tx_index < ?))")
132 args = append(args, sinceBlockHeight, sinceBlockHeight, sinceTxIndex)
133 }
134
135 querySQL, countSQL = buildSQLWithConds(querySQL, countSQL, conds)
136 count, err := chaindb.SelectInt(countSQL, args...)
137 if err != nil {
138 return nil, pagination, err
139 }
140 pagination.SetTotal(int(count))
141 if pagination.Offset() > pagination.Total {
142 return txs, pagination, nil
143 }
144
145 querySQL += " ORDER BY block_height DESC, tx_index DESC"
146 querySQL += " LIMIT ? OFFSET ?"
147 args = append(args, pagination.Limit(), pagination.Offset())
148
149 _, err = chaindb.Select(&txs, querySQL, args...)
150 return txs, pagination, err

Callers 1

bpGetTransactionListFunction · 0.95

Calls 7

GetTransactionByHashMethod · 0.95
buildCountSQLFunction · 0.85
NewPaginationFunction · 0.85
buildSQLWithCondsFunction · 0.85
SetTotalMethod · 0.80
OffsetMethod · 0.80
LimitMethod · 0.80

Tested by

no test coverage detected