forked from tpruvot/yiimp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblocknotify.cpp
85 lines (65 loc) · 1.59 KB
/
blocknotify.cpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <errno.h>
#include <math.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
// program yaamp.com:port coinid blockhash
int main(int argc, char **argv)
{
if(argc < 4)
{
printf("usage: blocknotify server:port coinid blockhash\n");
return 1;
}
char *p = strchr(argv[1], ':');
if(!p)
{
printf("usage: blocknotify server:port coinid blockhash\n");
return 1;
}
int port = atoi(p+1);
*p = 0;
int coinid = atoi(argv[2]);
char blockhash[1024];
strncpy(blockhash, argv[3], 1024);
int sock = socket(AF_INET, SOCK_STREAM, 0);
if(sock <= 0)
{
printf("error socket %s id %s\n", argv[1], argv[2]);
return 1;
}
struct hostent *ent = gethostbyname(argv[1]);
if(!ent)
{
printf("error gethostbyname %s id %s\n", argv[1], argv[2]);
return 1;
}
struct sockaddr_in serv;
serv.sin_family = AF_INET;
serv.sin_port = htons(port);
bcopy((char *)ent->h_addr, (char *)&serv.sin_addr.s_addr, ent->h_length);
int res = connect(sock, (struct sockaddr*)&serv, sizeof(serv));
if(res < 0)
{
printf("error connect %s id %s\n", argv[1], argv[2]);
return 1;
}
char buffer[1024];
sprintf(buffer, "{\"id\":1,\"method\":\"mining.update_block\",\"params\":[\"tu8tu5\",%d,\"%s\"]}\n", coinid, blockhash);
send(sock, buffer, strlen(buffer), 0);
close(sock);
//fprintf(stdout, "notify %s\n", buffer);
return 0;
}