-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathplotnft.py
246 lines (206 loc) · 7.64 KB
/
plotnft.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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
from __future__ import annotations
from decimal import Decimal
from typing import Optional
import click
from chia.cmds import options
MAX_CMDLINE_FEE = Decimal(0.5)
def validate_fee(ctx: click.Context, param: click.Parameter, value: str) -> str:
try:
fee = Decimal(value)
except ValueError:
raise click.BadParameter("Fee must be decimal dotted value in XCH (e.g. 0.00005)")
if fee < 0 or fee > MAX_CMDLINE_FEE:
raise click.BadParameter(f"Fee must be in the range 0 to {MAX_CMDLINE_FEE}")
return value
@click.group("plotnft", help="Manage your plot NFTs")
def plotnft_cmd() -> None:
pass
@plotnft_cmd.command("show", help="Show plotnft information")
@click.option(
"-wp",
"--wallet-rpc-port",
help="Set the port where the Wallet is hosting the RPC interface. See the rpc_port under wallet in config.yaml",
type=int,
default=None,
)
@click.option("-i", "--id", help="ID of the wallet to use", type=int, default=None, show_default=True, required=False)
@options.create_fingerprint()
def show_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: int) -> None:
import asyncio
from .plotnft_funcs import show
asyncio.run(show(wallet_rpc_port, fingerprint, id))
@plotnft_cmd.command("get_login_link", help="Create a login link for a pool. To get the launcher id, use plotnft show.")
@click.option("-l", "--launcher_id", help="Launcher ID of the plotnft", type=str, required=True)
def get_login_link_cmd(launcher_id: str) -> None:
import asyncio
from .plotnft_funcs import get_login_link
asyncio.run(get_login_link(launcher_id))
@plotnft_cmd.command("create", help="Create a plot NFT")
@click.option("-y", "--yes", "dont_prompt", help="No prompts", is_flag=True)
@options.create_fingerprint()
@click.option("-u", "--pool_url", help="HTTPS host:port of the pool to join", type=str, required=False)
@click.option("-s", "--state", help="Initial state of Plot NFT: local or pool", type=str, required=True)
@click.option(
"-m",
"--fee",
help="Set the fees per transaction, in XCH. Fee is used TWICE: once to create the singleton, once for init.",
type=str,
default="0",
show_default=True,
required=True,
callback=validate_fee,
)
@click.option(
"-wp",
"--wallet-rpc-port",
help="Set the port where the Wallet is hosting the RPC interface. See the rpc_port under wallet in config.yaml",
type=int,
default=None,
)
def create_cmd(
wallet_rpc_port: Optional[int],
fingerprint: int,
pool_url: str,
state: str,
fee: str,
dont_prompt: bool,
) -> None:
import asyncio
from .plotnft_funcs import create
if pool_url is not None and state.lower() == "local":
print(f" pool_url argument [{pool_url}] is not allowed when creating in 'local' state")
return
if pool_url in [None, ""] and state.lower() == "pool":
print(" pool_url argument (-u) is required for pool starting state")
return
valid_initial_states = {"pool": "FARMING_TO_POOL", "local": "SELF_POOLING"}
asyncio.run(
create(
wallet_rpc_port, fingerprint, pool_url, valid_initial_states[state], Decimal(fee), prompt=not dont_prompt
)
)
@plotnft_cmd.command("join", help="Join a plot NFT to a Pool")
@click.option("-y", "--yes", "dont_prompt", help="No prompts", is_flag=True)
@click.option("-i", "--id", help="ID of the wallet to use", type=int, default=None, show_default=True, required=True)
@options.create_fingerprint()
@click.option("-u", "--pool_url", help="HTTPS host:port of the pool to join", type=str, required=True)
@click.option(
"-m",
"--fee",
help="Set the fees per transaction, in XCH. Fee is used TWICE: once to leave pool, once to join.",
type=str,
default="0",
show_default=True,
required=True,
callback=validate_fee,
)
@click.option(
"-wp",
"--wallet-rpc-port",
help="Set the port where the Wallet is hosting the RPC interface. See the rpc_port under wallet in config.yaml",
type=int,
default=None,
)
def join_cmd(
wallet_rpc_port: Optional[int], fingerprint: int, id: int, fee: int, pool_url: str, dont_prompt: bool
) -> None:
import asyncio
from .plotnft_funcs import join_pool
asyncio.run(
join_pool(
wallet_rpc_port=wallet_rpc_port,
fingerprint=fingerprint,
pool_url=pool_url,
fee=Decimal(fee),
wallet_id=id,
prompt=not dont_prompt,
)
)
@plotnft_cmd.command("leave", help="Leave a pool and return to self-farming")
@click.option("-y", "--yes", "dont_prompt", help="No prompts", is_flag=True)
@click.option("-i", "--id", help="ID of the wallet to use", type=int, default=None, show_default=True, required=True)
@options.create_fingerprint()
@click.option(
"-m",
"--fee",
help="Set the fees per transaction, in XCH. Fee is charged TWICE.",
type=str,
default="0",
show_default=True,
required=True,
callback=validate_fee,
)
@click.option(
"-wp",
"--wallet-rpc-port",
help="Set the port where the Wallet is hosting the RPC interface. See the rpc_port under wallet in config.yaml",
type=int,
default=None,
)
def self_pool_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: int, fee: int, dont_prompt: bool) -> None:
import asyncio
from .plotnft_funcs import self_pool
asyncio.run(
self_pool(
wallet_rpc_port=wallet_rpc_port,
fingerprint=fingerprint,
fee=Decimal(fee),
wallet_id=id,
prompt=not dont_prompt,
)
)
@plotnft_cmd.command("inspect", help="Get Detailed plotnft information as JSON")
@click.option("-i", "--id", help="ID of the wallet to use", type=int, default=None, show_default=True, required=True)
@options.create_fingerprint()
@click.option(
"-wp",
"--wallet-rpc-port",
help="Set the port where the Wallet is hosting the RPC interface. See the rpc_port under wallet in config.yaml",
type=int,
default=None,
)
def inspect(wallet_rpc_port: Optional[int], fingerprint: int, id: int) -> None:
import asyncio
from .plotnft_funcs import inspect_cmd
asyncio.run(inspect_cmd(wallet_rpc_port, fingerprint, id))
@plotnft_cmd.command("claim", help="Claim rewards from a plot NFT")
@click.option("-i", "--id", help="ID of the wallet to use", type=int, default=None, show_default=True, required=True)
@options.create_fingerprint()
@click.option(
"-m",
"--fee",
help="Set the fees per transaction, in XCH.",
type=str,
default="0",
show_default=True,
required=True,
callback=validate_fee,
)
@click.option(
"-wp",
"--wallet-rpc-port",
help="Set the port where the Wallet is hosting the RPC interface. See the rpc_port under wallet in config.yaml",
type=int,
default=None,
)
def claim(wallet_rpc_port: Optional[int], fingerprint: int, id: int, fee: int) -> None:
import asyncio
from .plotnft_funcs import claim_cmd
asyncio.run(
claim_cmd(
wallet_rpc_port=wallet_rpc_port,
fingerprint=fingerprint,
fee=Decimal(fee),
wallet_id=id,
)
)
@plotnft_cmd.command(
"change_payout_instructions",
help="Change the payout instructions for a pool. To get the launcher id, use plotnft show.",
)
@click.option("-l", "--launcher_id", help="Launcher ID of the plotnft", type=str, required=True)
@click.option("-a", "--address", help="New address for payout instructions", type=str, required=True)
def change_payout_instructions_cmd(launcher_id: str, address: str) -> None:
import asyncio
from .plotnft_funcs import change_payout_instructions
asyncio.run(change_payout_instructions(launcher_id, address))