6
6
"fmt"
7
7
"log"
8
8
9
+ "github.com/go-redis/redis/v8"
9
10
"github.com/jayanthdeejay/mining/address"
10
11
_ "github.com/lib/pq"
11
12
"github.com/go-redis/redis/v8"
@@ -16,11 +17,11 @@ var ctx context.Context
16
17
var rdb * redis.Client
17
18
18
19
const (
19
- host = "localhost "
20
- port = 5432
21
- user = "postgres"
22
- password = "5te!nertRee "
23
- dbname = "nidhi"
20
+ host = "172.18.0.2 "
21
+ port = 5432
22
+ user = "postgres"
23
+ password = "VeryLongPassword "
24
+ dbname = "nidhi"
24
25
)
25
26
26
27
func init () {
@@ -44,7 +45,6 @@ func init() {
44
45
})
45
46
}
46
47
47
-
48
48
func main () {
49
49
// Read messages from the mining channel
50
50
count := 0
@@ -64,8 +64,6 @@ func main() {
64
64
}
65
65
}
66
66
67
-
68
-
69
67
func ProcessKey (key string ) {
70
68
add := address .GetEthAddress (key )
71
69
Checkaddress (key , add )
@@ -80,6 +78,7 @@ func ProcessKey(key string) {
80
78
Checkaddress (key , p2sh_add )
81
79
}
82
80
81
+
83
82
//func Checkaddress(key, add string) {
84
83
// var exists bool
85
84
// row := db.QueryRow(`
@@ -100,6 +99,18 @@ func ProcessKey(key string) {
100
99
// }
101
100
//}
102
101
102
+ func Checkaddress (key , add string ) {
103
+ var exists bool
104
+ row := db .QueryRow (`
105
+ SELECT EXISTS(SELECT 1 FROM ethereum WHERE address = $1)
106
+ OR EXISTS(SELECT 1 FROM bitcoin WHERE address = $1)` , add )
107
+ err := row .Scan (& exists )
108
+
109
+ if err != nil {
110
+ log .Fatalf ("Failed to check if address exists: %v" , err )
111
+ }
112
+
113
+
103
114
104
115
func Checkaddress (key , add string ) {
105
116
exists , err := rdb .SIsMember (ctx , "addresses" , add ).Result ()
0 commit comments