@@ -10,14 +10,15 @@ import Vapor
10
10
import Alamofire
11
11
import model
12
12
import common
13
+ import Redis
13
14
14
15
typealias Request = Vapor . Request
15
16
16
17
extension TransactionController {
17
18
/**
18
19
Get user data by user
19
20
*/
20
- func getUser( id: HexString , page: Int ? , per: Int ? , db: Database ) async -> User ? {
21
+ func getUser( id: HexString , page: Int ? , per: Int ? , db: DatabaseClient ) async -> User ? {
21
22
let task = AF . request ( Environment . get ( ENVIRONMENT_RPC_URL_KEY) !,
22
23
method: . post,
23
24
parameters: BalanceRequest ( params: [ id. stringValue ?? " " , " latest " ] ) ,
@@ -29,7 +30,7 @@ extension TransactionController {
29
30
}
30
31
31
32
32
- let result = try ? await Transaction . query ( on: db)
33
+ let result = try ? await Transaction . query ( on: db. databaseClient )
33
34
. group ( . or) {
34
35
group in
35
36
group. filter ( \. $from == id) . filter ( \. $to == id)
@@ -46,8 +47,8 @@ extension TransactionController {
46
47
/**
47
48
Get Block by block id
48
49
*/
49
- func getBlock( id: HexString , with db: Database ) async -> Block ? {
50
- let result = try ? await Block . query ( on: db)
50
+ func getBlock( id: HexString , with db: DatabaseClient ) async -> Block ? {
51
+ let result = try ? await Block . query ( on: db. databaseClient )
51
52
. filter ( \. $hash == id)
52
53
. first ( )
53
54
return result
@@ -56,7 +57,7 @@ extension TransactionController {
56
57
/**
57
58
Find transaction by transaction id
58
59
*/
59
- func getTransaction( id: HexString ) async -> Transaction ? {
60
+ func getTransaction( id: HexString , with database : DatabaseClient ) async -> Transaction ? {
60
61
let task = AF . request ( Environment . get ( " RPC_URL " ) !,
61
62
method: . post,
62
63
parameters: TransactionRequest ( params: [ id] ) ,
@@ -74,8 +75,9 @@ extension TransactionController {
74
75
75
76
76
77
let hexStringID = try HexString ( id)
78
+ let dbClient = DatabaseClient ( logger: req. logger, cacheClient: req. redis, databaseClient: req. db)
77
79
78
- let result = try await findById ( id: hexStringID, with: req . db , page: query. page, perPage: query. per) as? QueryResponse
80
+ let result = try await findById ( id: hexStringID, with: dbClient , page: query. page, perPage: query. per) as? QueryResponse
79
81
if let result = result {
80
82
return result
81
83
}
0 commit comments