forked from matja/bitcoin-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprefix.c
149 lines (136 loc) · 3.73 KB
/
prefix.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include "prefix.h"
#include <string.h>
static const struct BitcoinNetworkType network_types[] = {
/*
Bitcoin:
https://en.bitcoin.it/wiki/List_of_address_prefixes
Peercoin, Primecoin and Zetacoin use the same constants.
*/
{
.name = "bitcoin",
.public_key_prefix = 0,
.script_prefix = 5,
.private_key_prefix = 128
},
{
.name = "bitcoin-testnet",
.public_key_prefix = 111,
.script_prefix = 196,
.private_key_prefix = 239
},
/*
Litecoin:
public keys / script:
https://github.com/litecoin-project/litecoin/blob/88e2a2e8988b89f905145bdc9af8c34028d0af90/src/base58.h#L275
private keys:
https://github.com/litecoin-project/litecoin/blob/88e2a2e8988b89f905145bdc9af8c34028d0af90/src/base58.h#L403
*/
{
.name = "litecoin",
.public_key_prefix = 48,
.script_prefix = 5,
.private_key_prefix = 48+128
},
{
.name = "litecoin-testnet",
.public_key_prefix = 111,
.script_prefix = 196,
.private_key_prefix = 111+128
},
/*
Feathercoin:
public keys / script:
https://github.com/FeatherCoin/Feathercoin-0.8.5/blob/master-0.8/src/base58.h#L275
private keys:
https://github.com/FeatherCoin/Feathercoin-0.8.5/blob/master-0.8/src/base58.h#L403
*/
{
.name = "feathercoin",
.public_key_prefix = 14,
.script_prefix = 5,
.private_key_prefix = 14+128
},
{
.name = "feathercoin-testnet",
.public_key_prefix = 111,
.script_prefix = 196,
.private_key_prefix = 111+128
},
/*
Dogecoin:
public keys / script:
https://github.com/dogecoin/dogecoin/blob/v1.5.0/src/base58.h#L276
private keys:
https://github.com/dogecoin/dogecoin/blob/v1.5.0/src/base58.h#L404
*/
{
.name = "dogecoin",
.public_key_prefix = 30,
.script_prefix = 22,
.private_key_prefix = 30+128
},
{
.name = "dogecoin-testnet",
.public_key_prefix = 113,
.script_prefix = 196,
.private_key_prefix = 113+128
},
/*
Quarkcoin:
public keys / script:
https://github.com/MaxGuevara/quark/blob/v0.8.3.20/src/base58.h#L275
private keys:
https://github.com/MaxGuevara/quark/blob/v0.8.3.20/src/base58.h#L403
*/
{
.name = "quarkcoin",
.public_key_prefix = 58,
.script_prefix = 9,
.private_key_prefix = 58+128
},
{
.name = "quarkcoin-testnet",
.public_key_prefix = 119,
.script_prefix = 199,
.private_key_prefix = 119+128
}
};
BitcoinKeyPrefix BitcoinNetworkType_GetPublicKeyPrefix(const struct BitcoinNetworkType *n)
{
return n->public_key_prefix;
}
BitcoinKeyPrefix BitcoinNetworkType_GetPrivateKeyPrefix(const struct BitcoinNetworkType *n)
{
return n->private_key_prefix;
}
const struct BitcoinNetworkType *Bitcoin_GetNetworkTypeByName(const char *name)
{
const struct BitcoinNetworkType *pn = network_types;
while (pn != network_types + (sizeof(network_types)/sizeof(network_types[0]))) {
if (strcmp(name, pn->name) == 0) {
return pn;
}
pn++;
}
return NULL;
}
const struct BitcoinNetworkType *Bitcoin_GetNetworkTypeByPrivateKeyPrefix(const BitcoinKeyPrefix prefix)
{
const struct BitcoinNetworkType *pn = network_types;
while (pn != network_types + (sizeof(network_types)/sizeof(network_types[0]))) {
if (prefix == pn->private_key_prefix) {
return pn;
}
pn++;
}
return NULL;
}
void Bitcoin_ListNetworks(FILE *output)
{
const struct BitcoinNetworkType *pn = network_types;
static const char indent[] = " ";
while (pn != network_types + (sizeof(network_types)/sizeof(network_types[0]))) {
fprintf(output, "%s%s\n", indent, pn->name);
pn++;
}
}