/
unapprovedtransactions.go
54 lines (43 loc) · 1.56 KB
/
unapprovedtransactions.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
package database
const unapprovedTransactionsTable = "unapprovedtransactions"
type UnapprovedTransactions struct {
DB *MySQLDB
tableName string
}
func (uts *UnapprovedTransactions) getTableName() string {
if uts.tableName == "" {
uts.tableName = uts.DB.tablesPrefix + unapprovedTransactionsTable
}
return uts.tableName
}
// Init DB. create table
func (uts *UnapprovedTransactions) InitDB() error {
return uts.DB.CreateTable(uts.getTableName(), "VARBINARY(100)", "LONGBLOB")
}
// Get all records as single request
func (uts *UnapprovedTransactions) GetAll() ([][][]byte, error) {
return uts.DB.GetAll(uts.getTableName())
}
// execute functon for each key/value in the bucket
func (uts *UnapprovedTransactions) ForEach(callback ForEachKeyIteratorInterface) error {
return uts.DB.forEachInTable(uts.getTableName(), callback)
}
// get count of records in the table
func (uts *UnapprovedTransactions) GetCount() (int, error) {
return uts.DB.getCountInTable(uts.getTableName())
}
func (uts *UnapprovedTransactions) TruncateDB() error {
return uts.DB.Truncate(uts.getTableName())
}
// returns transaction by ID if it exists
func (uts *UnapprovedTransactions) GetTransaction(txID []byte) ([]byte, error) {
return uts.DB.Get(uts.getTableName(), txID)
}
// Add transaction record
func (uts *UnapprovedTransactions) PutTransaction(txID []byte, txdata []byte) error {
return uts.DB.Put(uts.getTableName(), txID, txdata)
}
// delete transation from DB
func (uts *UnapprovedTransactions) DeleteTransaction(txID []byte) error {
return uts.DB.Delete(uts.getTableName(), txID)
}