-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.c
90 lines (60 loc) · 2.84 KB
/
main.c
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
83
84
85
86
87
88
89
90
// Copyright (c) 2016-2024 Knuth Project developers.
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
// Copyright (c) 2016-2024 Knuth Project developers.
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <stdio.h>
#include <kth/capi/node.h>
void WaitUntilBlock(kth_node_t node, uint64_t desiredHeight) {
ErrorCode error = 0;
uint64_t height = 0;
while (error == 0 && height < desiredHeight) {
Console.WriteLine($"---> height: {height} desiredHeight: {desiredHeight}");
var errorAndHeight = await node.Chain.GetLastHeightAsync();
error = errorAndHeight.ErrorCode;
height = errorAndHeight.Result;
if (height < desiredHeight) {
await Task.Delay(10000);
}
}
Console.WriteLine($"---> height: {height} desiredHeight: {desiredHeight}");
}
void DoSomething(kth_node_t node) {
int FIRST_NON_COINBASE_BLOCK_HEIGHT = 170;
int res = kth_node_init_and_run_wait(node);
if (res != kth_ec_success) {
printf("kth_node_init_and_run_wait failed: error code: %d", res);
return;
}
WaitUntilBlock(node, FIRST_NON_COINBASE_BLOCK_HEIGHT);
string txHashHexStr = "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16";
byte[] hash = Binary.HexStringToByteArray(txHashHexStr);
var ret = await node.Chain.GetTransactionAsync(hash, true);
var x1 = ret.Result;
var x2 = ret.Result.Tx;
var x3 = ret.Result.Tx.SignatureOperations;
Console.WriteLine($"ret.Result.Tx.SignatureOperations: {ret.Result.Tx.SignatureOperations}");
}
int main(int argc, char* argv[]) {
// string configFile = "/home/fernando/dev/kth/cs-api/tests/bch/config/invalid.cfg";
kth_node_t node = kth_node_construct("/home/fernando/dev/kth/cs-api/console/node.cfg", stdout, stderr);
printf("Is config file valid: %d\n", kth_node_load_config_valid(node));
DoSomething(node);
printf("Shutting down node...");
kth_node_destruct(node);
return 0;
}
// -----------------------------------------------------------
// #include <stdio.h>
// #include <kth/capi/node.h>
// int main(int argc, char* argv[]) {
// // kth_node_t node = kth_node_construct("/home/fernando/exec/btc-mainnet.cfg", stdout, stderr);
// // kth_node_t node = kth_node_construct("/home/fernando/dev/kth/cs-api/tests/bch/config/invalid.cfg", stdout, stderr);
// kth_node_t node = kth_node_construct("/home/fernando/dev/kth/cs-api/tests/bch/config/invalid.cfg", NULL, NULL);
// printf("Is config file valid: %d\n", kth_node_load_config_valid(node));
// int res1 = kth_node_initchain(node);
// // int res2 = kth_node_run_wait(node);
// kth_node_destruct(node);
// return 0;
// }