Changeset View
Changeset View
Standalone View
Standalone View
contrib/seeds/generate-seeds.py
Show First 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | def main(): | ||||
if len(sys.argv) < 2: | if len(sys.argv) < 2: | ||||
print( | print( | ||||
'Usage: {} <path_to_nodes_txt>'.format( | 'Usage: {} <path_to_nodes_txt>'.format( | ||||
sys.argv[0]), | sys.argv[0]), | ||||
file=sys.stderr) | file=sys.stderr) | ||||
sys.exit(1) | sys.exit(1) | ||||
g = sys.stdout | g = sys.stdout | ||||
indir = sys.argv[1] | indir = sys.argv[1] | ||||
g.write('#ifndef BITCOIN_CHAINPARAMSSEEDS_H\n') | g.write('#include <chainparams.h>\n') | ||||
g.write('#define BITCOIN_CHAINPARAMSSEEDS_H\n') | g.write('#include <util/strencodings.h>\n') | ||||
g.write('#include <tinyformat.h>\n') | |||||
g.write('/**\n') | g.write('/**\n') | ||||
g.write(' * List of fixed seed nodes for the bitcoin network\n') | g.write(' * List of fixed seed nodes for the bitcoin network\n') | ||||
g.write(' * @{} by contrib/seeds/generate-seeds.py\n'.format('generated')) | g.write(' * @{} by contrib/seeds/generate-seeds.py\n'.format('generated')) | ||||
g.write(' *\n') | g.write(' *\n') | ||||
g.write(' * Each line contains a 16-byte IPv6 address and a port.\n') | g.write(' * Each line contains a 16-byte IPv6 address and a port.\n') | ||||
g.write( | g.write( | ||||
' * IPv4 as well as onion addresses are wrapped inside an IPv6 address accordingly.\n') | ' * IPv4 as well as onion addresses are wrapped inside an IPv6 address accordingly.\n') | ||||
g.write(' */\n') | g.write(' */\n') | ||||
with open(os.path.join(indir, 'nodes_main.txt'), 'r', encoding="utf8") as f: | with open(os.path.join(indir, 'nodes_main.txt'), 'r', encoding="utf8") as f: | ||||
process_nodes(g, f, 'pnSeed6_main', 8333) | process_nodes(g, f, 'pnSeed6_main', 8333) | ||||
g.write('\n') | g.write('\n') | ||||
with open(os.path.join(indir, 'nodes_test.txt'), 'r', encoding="utf8") as f: | with open(os.path.join(indir, 'nodes_test.txt'), 'r', encoding="utf8") as f: | ||||
process_nodes(g, f, 'pnSeed6_test', 18333) | process_nodes(g, f, 'pnSeed6_test', 18333) | ||||
g.write('#endif // BITCOIN_CHAINPARAMSSEEDS_H\n') | g.write( | ||||
'std::vector<SeedSpec6> FixedSeedsList(const std::string &chain) {\n') | |||||
g.write(' if (chain == CBaseChainParams::MAIN) {\n') | |||||
g.write(' return std::vector<SeedSpec6>(\n') | |||||
g.write(' pnSeed6_main, pnSeed6_main + ARRAYLEN(pnSeed6_main));\n') | |||||
g.write(' }\n') | |||||
g.write(' if (chain == CBaseChainParams::TESTNET) {\n') | |||||
g.write(' return std::vector<SeedSpec6>(\n') | |||||
g.write(' pnSeed6_test, pnSeed6_test + ARRAYLEN(pnSeed6_test));\n') | |||||
g.write(' }\n') | |||||
g.write(' throw std::runtime_error(\n') | |||||
g.write( | |||||
' strprintf("%s: Unknown or unsupported chain %s.", __func__, chain));\n') | |||||
g.write('}\n') | |||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
main() | main() |