-
Notifications
You must be signed in to change notification settings - Fork 2
/
vanity.py
93 lines (76 loc) · 3.22 KB
/
vanity.py
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
#!/usr/bin/env python
import json
import requests
# LBRY JSON RPC URL
HOST = "http://localhost:5279"
# Do a claim list
response = requests.post(HOST, json={"method": "claim_list",
"params": {}}).json()
f = open("vanity_names_output.txt", "w")
# Get the number of claims
num_claims = response["result"]["total_items"]
def write(s, end="\n", flush=False):
"""
Write a string to stdout and the file
"""
print(s, end=end, flush=flush)
f.write(s)
f.write(end)
if flush:
f.flush()
# Get the claim info
write(f"You have {num_claims} claims.")
write("Getting claim information. This might take a while...",
flush=True, end="")
response = requests.post(HOST,
json={"method": "claim_list",
"params": {"page_size": num_claims,
"resolve": True}}).json()
claims = response["result"]["items"]
write("done.", end="\n\n", flush=True)
for claim in claims:
claim_id = claim["claim_id"]
# Vanity name and whether you're controlling it
vanity_name = claim["name"]
controlling = claim["meta"]["is_controlling"]
staked_amount = float(claim["amount"]) + float(claim["meta"]["support_amount"])
# Get multiplicity of the vanity name, and max LBC
max_lbc = None
response = requests.post(HOST,
json={"method": "claim_search",
"params": {"name": vanity_name}}).json()
multiplicity = response["result"]["total_items"]
response = requests.post(HOST,
json={"method": "claim_search",
"params": {"name": vanity_name,
"page_size": multiplicity}}).json()
competitors = 0
for item in response["result"]["items"]:
# Look at staked LBC
item_lbc = float(item["amount"]) + float(item["meta"]["support_amount"])
if item["claim_id"] != claim_id and \
(max_lbc is None or item_lbc > max_lbc):
max_lbc = item_lbc
# Count competitors
if (item["value_type"] != "repost" and item["claim_id"] != claim_id)\
or ("reposted_claim_id" in item and \
item["reposted_claim_id"] == claim_id):
competitors += 1
# Print some information
write("-------------------------------------------------------------------")
write(f"Name: {vanity_name}")
write("-------------------------------------------------------------------")
write(f"Do you control it?: {'YES' if controlling else 'NO'}")
write(f"Number of competing claims, excluding reposts of your claim: {competitors}")
write(f"LBC on your claim: {staked_amount}")
write(f"Maximum LBC on competing claims: {max_lbc}")
if claim["value_type"] == "repost":
write("This is a repost made by you, so you might not care anyway.")
if max_lbc is not None:
if controlling and max_lbc > staked_amount:
write("TAKEOVER WARNING!")
if not controlling and staked_amount > max_lbc:
write("YOUR CLAIM HAS ENOUGH LBC BUT IS WAITING FOR TAKEOVER.")
write("", end="\n\n", flush=True)
f.close()
print("Output saved to vanity_names_output.txt")