We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Finalize default amount for CLI when adding a mirror (chia data add_mirror)


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `chia/cmds/data.py`
Content:
```
1 import json
2 import logging
3 from pathlib import Path
4 from typing import Any, Coroutine, Dict, List, Optional, TypeVar
5 
6 import click
7 from typing_extensions import Protocol
8 
9 _T = TypeVar("_T")
10 
11 
12 class IdentityFunction(Protocol):
13     def __call__(self, __x: _T) -> _T:
14         ...
15 
16 
17 logger = logging.getLogger(__name__)
18 
19 
20 # TODO: this is more general and should be part of refactoring the overall CLI code duplication
21 def run(coro: Coroutine[Any, Any, Optional[Dict[str, Any]]]) -> None:
22     import asyncio
23 
24     response = asyncio.run(coro)
25 
26     success = response is not None and response.get("success", False)
27     logger.info(f"data layer cli call response:{success}")
28     # todo make sure all cli methods follow this pattern, uncomment
29     # if not success:
30     # raise click.ClickException(message=f"query unsuccessful, response: {response}")
31 
32 
33 @click.group("data", short_help="Manage your data")
34 def data_cmd() -> None:
35     pass
36 
37 
38 # TODO: maybe use more helpful `type=`s to get click to handle error reporting of
39 #       malformed inputs.
40 
41 
42 def create_changelist_option() -> IdentityFunction:
43     return click.option(
44         "-d",
45         "--changelist",
46         "changelist_string",
47         help="str representing the changelist",
48         type=str,
49         required=True,
50     )
51 
52 
53 def create_key_option() -> IdentityFunction:
54     return click.option(
55         "-h",
56         "--key",
57         "key_string",
58         help="str representing the key",
59         type=str,
60         required=True,
61     )
62 
63 
64 def create_data_store_id_option() -> "IdentityFunction":
65     return click.option(
66         "-store",
67         "--id",
68         help="The hexadecimal store id.",
69         type=str,
70         required=True,
71     )
72 
73 
74 def create_data_store_name_option() -> "IdentityFunction":
75     return click.option(
76         "-n",
77         "--table_name",
78         "table_name",
79         help="The name of the table.",
80         type=str,
81         required=True,
82     )
83 
84 
85 def create_rpc_port_option() -> "IdentityFunction":
86     return click.option(
87         "-dp",
88         "--data-rpc-port",
89         help="Set the port where the data layer is hosting the RPC interface. See rpc_port under wallet in config.yaml",
90         type=int,
91         default=None,
92         show_default=True,
93     )
94 
95 
96 def create_fee_option() -> "IdentityFunction":
97     return click.option(
98         "-m",
99         "--fee",
100         help="Set the fees for the transaction, in XCH",
101         type=str,
102         default=None,
103         show_default=True,
104         required=False,
105     )
106 
107 
108 @data_cmd.command("create_data_store", short_help="Create a new data store")
109 @create_rpc_port_option()
110 @create_fee_option()
111 def create_data_store(
112     data_rpc_port: int,
113     fee: Optional[str],
114 ) -> None:
115     from chia.cmds.data_funcs import create_data_store_cmd
116 
117     run(create_data_store_cmd(data_rpc_port, fee))
118 
119 
120 @data_cmd.command("get_value", short_help="Get the value for a given key and store")
121 @create_data_store_id_option()
122 @create_key_option()
123 @create_rpc_port_option()
124 def get_value(
125     id: str,
126     key_string: str,
127     data_rpc_port: int,
128 ) -> None:
129     from chia.cmds.data_funcs import get_value_cmd
130 
131     run(get_value_cmd(data_rpc_port, id, key_string))
132 
133 
134 @data_cmd.command("update_data_store", short_help="Update a store by providing the changelist operations")
135 @create_data_store_id_option()
136 @create_changelist_option()
137 @create_rpc_port_option()
138 @create_fee_option()
139 def update_data_store(
140     id: str,
141     changelist_string: str,
142     data_rpc_port: int,
143     fee: str,
144 ) -> None:
145     from chia.cmds.data_funcs import update_data_store_cmd
146 
147     run(update_data_store_cmd(rpc_port=data_rpc_port, store_id=id, changelist=json.loads(changelist_string), fee=fee))
148 
149 
150 @data_cmd.command("get_keys", short_help="Get all keys for a given store")
151 @create_data_store_id_option()
152 @create_rpc_port_option()
153 def get_keys(
154     id: str,
155     data_rpc_port: int,
156 ) -> None:
157     from chia.cmds.data_funcs import get_keys_cmd
158 
159     run(get_keys_cmd(data_rpc_port, id))
160 
161 
162 @data_cmd.command("get_keys_values", short_help="Get all keys and values for a given store")
163 @create_data_store_id_option()
164 @create_rpc_port_option()
165 def get_keys_values(
166     id: str,
167     data_rpc_port: int,
168 ) -> None:
169     from chia.cmds.data_funcs import get_keys_values_cmd
170 
171     run(get_keys_values_cmd(data_rpc_port, id))
172 
173 
174 @data_cmd.command("get_root", short_help="Get the published root hash value for a given store")
175 @create_data_store_id_option()
176 @create_rpc_port_option()
177 def get_root(
178     id: str,
179     data_rpc_port: int,
180 ) -> None:
181     from chia.cmds.data_funcs import get_root_cmd
182 
183     run(get_root_cmd(rpc_port=data_rpc_port, store_id=id))
184 
185 
186 @data_cmd.command("subscribe", short_help="Subscribe to a store")
187 @create_data_store_id_option()
188 @click.option(
189     "-u",
190     "--url",
191     "urls",
192     help="Manually provide a list of servers urls for downloading the data",
193     type=str,
194     multiple=True,
195 )
196 @create_rpc_port_option()
197 def subscribe(
198     id: str,
199     urls: List[str],
200     data_rpc_port: int,
201 ) -> None:
202     from chia.cmds.data_funcs import subscribe_cmd
203 
204     run(subscribe_cmd(rpc_port=data_rpc_port, store_id=id, urls=urls))
205 
206 
207 @data_cmd.command("remove_subscription", short_help="Remove server urls that are added via subscribing to urls")
208 @create_data_store_id_option()
209 @click.option("-u", "--url", "urls", help="Server urls to remove", type=str, multiple=True)
210 @create_rpc_port_option()
211 def remove_subscription(
212     id: str,
213     urls: List[str],
214     data_rpc_port: int,
215 ) -> None:
216     from chia.cmds.data_funcs import remove_subscriptions_cmd
217 
218     run(remove_subscriptions_cmd(rpc_port=data_rpc_port, store_id=id, urls=urls))
219 
220 
221 @data_cmd.command("unsubscribe", short_help="Completely untrack a store")
222 @create_data_store_id_option()
223 @create_rpc_port_option()
224 def unsubscribe(
225     id: str,
226     data_rpc_port: int,
227 ) -> None:
228     from chia.cmds.data_funcs import unsubscribe_cmd
229 
230     run(unsubscribe_cmd(rpc_port=data_rpc_port, store_id=id))
231 
232 
233 @data_cmd.command(
234     "get_kv_diff", short_help="Get the inserted and deleted keys and values between an initial and a final hash"
235 )
236 @create_data_store_id_option()
237 @click.option("-hash_1", "--hash_1", help="Initial hash", type=str)
238 @click.option("-hash_2", "--hash_2", help="Final hash", type=str)
239 @create_rpc_port_option()
240 def get_kv_diff(
241     id: str,
242     hash_1: str,
243     hash_2: str,
244     data_rpc_port: int,
245 ) -> None:
246     from chia.cmds.data_funcs import get_kv_diff_cmd
247 
248     run(get_kv_diff_cmd(rpc_port=data_rpc_port, store_id=id, hash_1=hash_1, hash_2=hash_2))
249 
250 
251 @data_cmd.command("get_root_history", short_help="Get all changes of a singleton")
252 @create_data_store_id_option()
253 @create_rpc_port_option()
254 def get_root_history(
255     id: str,
256     data_rpc_port: int,
257 ) -> None:
258     from chia.cmds.data_funcs import get_root_history_cmd
259 
260     run(get_root_history_cmd(rpc_port=data_rpc_port, store_id=id))
261 
262 
263 @data_cmd.command("add_missing_files", short_help="Manually reconstruct server files from the data layer database")
264 @click.option(
265     "-i",
266     "--ids",
267     help="List of stores to reconstruct. If not specified, all stores will be reconstructed",
268     type=str,
269     required=False,
270 )
271 @click.option(
272     "-o/-n",
273     "--overwrite/--no-overwrite",
274     help="Specify if already existing files need to be overwritten by this command",
275 )
276 @click.option(
277     "-f", "--foldername", type=str, help="If specified, use a non-default folder to write the files", required=False
278 )
279 @create_rpc_port_option()
280 def add_missing_files(ids: Optional[str], overwrite: bool, foldername: Optional[str], data_rpc_port: int) -> None:
281     from chia.cmds.data_funcs import add_missing_files_cmd
282 
283     run(
284         add_missing_files_cmd(
285             rpc_port=data_rpc_port,
286             ids=None if ids is None else json.loads(ids),
287             overwrite=overwrite,
288             foldername=None if foldername is None else Path(foldername),
289         )
290     )
291 
292 
293 @data_cmd.command("add_mirror", short_help="Publish mirror urls on chain")
294 @click.option("-i", "--id", help="Store id", type=str, required=True)
295 @click.option("-a", "--amount", help="Amount to spend for this mirror, in mojos", type=int, required=True)
296 @click.option(
297     "-u",
298     "--url",
299     "urls",
300     help="URL to publish on the new coin, multiple accepted and will be published to a single coin.",
301     type=str,
302     multiple=True,
303 )
304 @create_fee_option()
305 @create_rpc_port_option()
306 def add_mirror(id: str, amount: int, urls: List[str], fee: Optional[str], data_rpc_port: int) -> None:
307     from chia.cmds.data_funcs import add_mirror_cmd
308 
309     run(
310         add_mirror_cmd(
311             rpc_port=data_rpc_port,
312             store_id=id,
313             urls=urls,
314             amount=amount,
315             fee=fee,
316         )
317     )
318 
319 
320 @data_cmd.command("delete_mirror", short_help="Delete an owned mirror by its coin id")
321 @click.option("-c", "--coin_id", help="Coin id", type=str, required=True)
322 @create_fee_option()
323 @create_rpc_port_option()
324 def delete_mirror(coin_id: str, fee: Optional[str], data_rpc_port: int) -> None:
325     from chia.cmds.data_funcs import delete_mirror_cmd
326 
327     run(
328         delete_mirror_cmd(
329             rpc_port=data_rpc_port,
330             coin_id=coin_id,
331             fee=fee,
332         )
333     )
334 
335 
336 @data_cmd.command("get_mirrors", short_help="Get a list of all mirrors for a given store")
337 @click.option("-i", "--id", help="Store id", type=str, required=True)
338 @create_rpc_port_option()
339 def get_mirrors(id: str, data_rpc_port: int) -> None:
340     from chia.cmds.data_funcs import get_mirrors_cmd
341 
342     run(
343         get_mirrors_cmd(
344             rpc_port=data_rpc_port,
345             store_id=id,
346         )
347     )
348 
349 
350 @data_cmd.command("get_subscriptions", short_help="Get subscribed stores, including the owned stores")
351 @create_rpc_port_option()
352 def get_subscriptions(data_rpc_port: int) -> None:
353     from chia.cmds.data_funcs import get_subscriptions_cmd
354 
355     run(
356         get_subscriptions_cmd(
357             rpc_port=data_rpc_port,
358         )
359     )
360 
361 
362 @data_cmd.command("get_owned_stores", short_help="Get owned stores")
363 @create_rpc_port_option()
364 def get_owned_stores(data_rpc_port: int) -> None:
365     from chia.cmds.data_funcs import get_owned_stores_cmd
366 
367     run(
368         get_owned_stores_cmd(
369             rpc_port=data_rpc_port,
370         )
371     )
372
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/chia/cmds/data.py b/chia/cmds/data.py
--- a/chia/cmds/data.py
+++ b/chia/cmds/data.py
@@ -292,7 +292,9 @@
 
 @data_cmd.command("add_mirror", short_help="Publish mirror urls on chain")
 @click.option("-i", "--id", help="Store id", type=str, required=True)
-@click.option("-a", "--amount", help="Amount to spend for this mirror, in mojos", type=int, required=True)
+@click.option(
+    "-a", "--amount", help="Amount to spend for this mirror, in mojos", type=int, default=0, show_default=True
+)
 @click.option(
     "-u",
     "--url",

{"golden_diff": "diff --git a/chia/cmds/data.py b/chia/cmds/data.py\n--- a/chia/cmds/data.py\n+++ b/chia/cmds/data.py\n@@ -292,7 +292,9 @@\n \n @data_cmd.command(\"add_mirror\", short_help=\"Publish mirror urls on chain\")\n @click.option(\"-i\", \"--id\", help=\"Store id\", type=str, required=True)\n-@click.option(\"-a\", \"--amount\", help=\"Amount to spend for this mirror, in mojos\", type=int, required=True)\n+@click.option(\n+    \"-a\", \"--amount\", help=\"Amount to spend for this mirror, in mojos\", type=int, default=0, show_default=True\n+)\n @click.option(\n     \"-u\",\n     \"--url\",\n", "issue": "Finalize default amount for CLI when adding a mirror (chia data add_mirror)\n\n", "before_files": [{"content": "import json\nimport logging\nfrom pathlib import Path\nfrom typing import Any, Coroutine, Dict, List, Optional, TypeVar\n\nimport click\nfrom typing_extensions import Protocol\n\n_T = TypeVar(\"_T\")\n\n\nclass IdentityFunction(Protocol):\n    def __call__(self, __x: _T) -> _T:\n        ...\n\n\nlogger = logging.getLogger(__name__)\n\n\n# TODO: this is more general and should be part of refactoring the overall CLI code duplication\ndef run(coro: Coroutine[Any, Any, Optional[Dict[str, Any]]]) -> None:\n    import asyncio\n\n    response = asyncio.run(coro)\n\n    success = response is not None and response.get(\"success\", False)\n    logger.info(f\"data layer cli call response:{success}\")\n    # todo make sure all cli methods follow this pattern, uncomment\n    # if not success:\n    # raise click.ClickException(message=f\"query unsuccessful, response: {response}\")\n\n\n@click.group(\"data\", short_help=\"Manage your data\")\ndef data_cmd() -> None:\n    pass\n\n\n# TODO: maybe use more helpful `type=`s to get click to handle error reporting of\n#       malformed inputs.\n\n\ndef create_changelist_option() -> IdentityFunction:\n    return click.option(\n        \"-d\",\n        \"--changelist\",\n        \"changelist_string\",\n        help=\"str representing the changelist\",\n        type=str,\n        required=True,\n    )\n\n\ndef create_key_option() -> IdentityFunction:\n    return click.option(\n        \"-h\",\n        \"--key\",\n        \"key_string\",\n        help=\"str representing the key\",\n        type=str,\n        required=True,\n    )\n\n\ndef create_data_store_id_option() -> \"IdentityFunction\":\n    return click.option(\n        \"-store\",\n        \"--id\",\n        help=\"The hexadecimal store id.\",\n        type=str,\n        required=True,\n    )\n\n\ndef create_data_store_name_option() -> \"IdentityFunction\":\n    return click.option(\n        \"-n\",\n        \"--table_name\",\n        \"table_name\",\n        help=\"The name of the table.\",\n        type=str,\n        required=True,\n    )\n\n\ndef create_rpc_port_option() -> \"IdentityFunction\":\n    return click.option(\n        \"-dp\",\n        \"--data-rpc-port\",\n        help=\"Set the port where the data layer is hosting the RPC interface. See rpc_port under wallet in config.yaml\",\n        type=int,\n        default=None,\n        show_default=True,\n    )\n\n\ndef create_fee_option() -> \"IdentityFunction\":\n    return click.option(\n        \"-m\",\n        \"--fee\",\n        help=\"Set the fees for the transaction, in XCH\",\n        type=str,\n        default=None,\n        show_default=True,\n        required=False,\n    )\n\n\n@data_cmd.command(\"create_data_store\", short_help=\"Create a new data store\")\n@create_rpc_port_option()\n@create_fee_option()\ndef create_data_store(\n    data_rpc_port: int,\n    fee: Optional[str],\n) -> None:\n    from chia.cmds.data_funcs import create_data_store_cmd\n\n    run(create_data_store_cmd(data_rpc_port, fee))\n\n\n@data_cmd.command(\"get_value\", short_help=\"Get the value for a given key and store\")\n@create_data_store_id_option()\n@create_key_option()\n@create_rpc_port_option()\ndef get_value(\n    id: str,\n    key_string: str,\n    data_rpc_port: int,\n) -> None:\n    from chia.cmds.data_funcs import get_value_cmd\n\n    run(get_value_cmd(data_rpc_port, id, key_string))\n\n\n@data_cmd.command(\"update_data_store\", short_help=\"Update a store by providing the changelist operations\")\n@create_data_store_id_option()\n@create_changelist_option()\n@create_rpc_port_option()\n@create_fee_option()\ndef update_data_store(\n    id: str,\n    changelist_string: str,\n    data_rpc_port: int,\n    fee: str,\n) -> None:\n    from chia.cmds.data_funcs import update_data_store_cmd\n\n    run(update_data_store_cmd(rpc_port=data_rpc_port, store_id=id, changelist=json.loads(changelist_string), fee=fee))\n\n\n@data_cmd.command(\"get_keys\", short_help=\"Get all keys for a given store\")\n@create_data_store_id_option()\n@create_rpc_port_option()\ndef get_keys(\n    id: str,\n    data_rpc_port: int,\n) -> None:\n    from chia.cmds.data_funcs import get_keys_cmd\n\n    run(get_keys_cmd(data_rpc_port, id))\n\n\n@data_cmd.command(\"get_keys_values\", short_help=\"Get all keys and values for a given store\")\n@create_data_store_id_option()\n@create_rpc_port_option()\ndef get_keys_values(\n    id: str,\n    data_rpc_port: int,\n) -> None:\n    from chia.cmds.data_funcs import get_keys_values_cmd\n\n    run(get_keys_values_cmd(data_rpc_port, id))\n\n\n@data_cmd.command(\"get_root\", short_help=\"Get the published root hash value for a given store\")\n@create_data_store_id_option()\n@create_rpc_port_option()\ndef get_root(\n    id: str,\n    data_rpc_port: int,\n) -> None:\n    from chia.cmds.data_funcs import get_root_cmd\n\n    run(get_root_cmd(rpc_port=data_rpc_port, store_id=id))\n\n\n@data_cmd.command(\"subscribe\", short_help=\"Subscribe to a store\")\n@create_data_store_id_option()\n@click.option(\n    \"-u\",\n    \"--url\",\n    \"urls\",\n    help=\"Manually provide a list of servers urls for downloading the data\",\n    type=str,\n    multiple=True,\n)\n@create_rpc_port_option()\ndef subscribe(\n    id: str,\n    urls: List[str],\n    data_rpc_port: int,\n) -> None:\n    from chia.cmds.data_funcs import subscribe_cmd\n\n    run(subscribe_cmd(rpc_port=data_rpc_port, store_id=id, urls=urls))\n\n\n@data_cmd.command(\"remove_subscription\", short_help=\"Remove server urls that are added via subscribing to urls\")\n@create_data_store_id_option()\n@click.option(\"-u\", \"--url\", \"urls\", help=\"Server urls to remove\", type=str, multiple=True)\n@create_rpc_port_option()\ndef remove_subscription(\n    id: str,\n    urls: List[str],\n    data_rpc_port: int,\n) -> None:\n    from chia.cmds.data_funcs import remove_subscriptions_cmd\n\n    run(remove_subscriptions_cmd(rpc_port=data_rpc_port, store_id=id, urls=urls))\n\n\n@data_cmd.command(\"unsubscribe\", short_help=\"Completely untrack a store\")\n@create_data_store_id_option()\n@create_rpc_port_option()\ndef unsubscribe(\n    id: str,\n    data_rpc_port: int,\n) -> None:\n    from chia.cmds.data_funcs import unsubscribe_cmd\n\n    run(unsubscribe_cmd(rpc_port=data_rpc_port, store_id=id))\n\n\n@data_cmd.command(\n    \"get_kv_diff\", short_help=\"Get the inserted and deleted keys and values between an initial and a final hash\"\n)\n@create_data_store_id_option()\n@click.option(\"-hash_1\", \"--hash_1\", help=\"Initial hash\", type=str)\n@click.option(\"-hash_2\", \"--hash_2\", help=\"Final hash\", type=str)\n@create_rpc_port_option()\ndef get_kv_diff(\n    id: str,\n    hash_1: str,\n    hash_2: str,\n    data_rpc_port: int,\n) -> None:\n    from chia.cmds.data_funcs import get_kv_diff_cmd\n\n    run(get_kv_diff_cmd(rpc_port=data_rpc_port, store_id=id, hash_1=hash_1, hash_2=hash_2))\n\n\n@data_cmd.command(\"get_root_history\", short_help=\"Get all changes of a singleton\")\n@create_data_store_id_option()\n@create_rpc_port_option()\ndef get_root_history(\n    id: str,\n    data_rpc_port: int,\n) -> None:\n    from chia.cmds.data_funcs import get_root_history_cmd\n\n    run(get_root_history_cmd(rpc_port=data_rpc_port, store_id=id))\n\n\n@data_cmd.command(\"add_missing_files\", short_help=\"Manually reconstruct server files from the data layer database\")\n@click.option(\n    \"-i\",\n    \"--ids\",\n    help=\"List of stores to reconstruct. If not specified, all stores will be reconstructed\",\n    type=str,\n    required=False,\n)\n@click.option(\n    \"-o/-n\",\n    \"--overwrite/--no-overwrite\",\n    help=\"Specify if already existing files need to be overwritten by this command\",\n)\n@click.option(\n    \"-f\", \"--foldername\", type=str, help=\"If specified, use a non-default folder to write the files\", required=False\n)\n@create_rpc_port_option()\ndef add_missing_files(ids: Optional[str], overwrite: bool, foldername: Optional[str], data_rpc_port: int) -> None:\n    from chia.cmds.data_funcs import add_missing_files_cmd\n\n    run(\n        add_missing_files_cmd(\n            rpc_port=data_rpc_port,\n            ids=None if ids is None else json.loads(ids),\n            overwrite=overwrite,\n            foldername=None if foldername is None else Path(foldername),\n        )\n    )\n\n\n@data_cmd.command(\"add_mirror\", short_help=\"Publish mirror urls on chain\")\n@click.option(\"-i\", \"--id\", help=\"Store id\", type=str, required=True)\n@click.option(\"-a\", \"--amount\", help=\"Amount to spend for this mirror, in mojos\", type=int, required=True)\n@click.option(\n    \"-u\",\n    \"--url\",\n    \"urls\",\n    help=\"URL to publish on the new coin, multiple accepted and will be published to a single coin.\",\n    type=str,\n    multiple=True,\n)\n@create_fee_option()\n@create_rpc_port_option()\ndef add_mirror(id: str, amount: int, urls: List[str], fee: Optional[str], data_rpc_port: int) -> None:\n    from chia.cmds.data_funcs import add_mirror_cmd\n\n    run(\n        add_mirror_cmd(\n            rpc_port=data_rpc_port,\n            store_id=id,\n            urls=urls,\n            amount=amount,\n            fee=fee,\n        )\n    )\n\n\n@data_cmd.command(\"delete_mirror\", short_help=\"Delete an owned mirror by its coin id\")\n@click.option(\"-c\", \"--coin_id\", help=\"Coin id\", type=str, required=True)\n@create_fee_option()\n@create_rpc_port_option()\ndef delete_mirror(coin_id: str, fee: Optional[str], data_rpc_port: int) -> None:\n    from chia.cmds.data_funcs import delete_mirror_cmd\n\n    run(\n        delete_mirror_cmd(\n            rpc_port=data_rpc_port,\n            coin_id=coin_id,\n            fee=fee,\n        )\n    )\n\n\n@data_cmd.command(\"get_mirrors\", short_help=\"Get a list of all mirrors for a given store\")\n@click.option(\"-i\", \"--id\", help=\"Store id\", type=str, required=True)\n@create_rpc_port_option()\ndef get_mirrors(id: str, data_rpc_port: int) -> None:\n    from chia.cmds.data_funcs import get_mirrors_cmd\n\n    run(\n        get_mirrors_cmd(\n            rpc_port=data_rpc_port,\n            store_id=id,\n        )\n    )\n\n\n@data_cmd.command(\"get_subscriptions\", short_help=\"Get subscribed stores, including the owned stores\")\n@create_rpc_port_option()\ndef get_subscriptions(data_rpc_port: int) -> None:\n    from chia.cmds.data_funcs import get_subscriptions_cmd\n\n    run(\n        get_subscriptions_cmd(\n            rpc_port=data_rpc_port,\n        )\n    )\n\n\n@data_cmd.command(\"get_owned_stores\", short_help=\"Get owned stores\")\n@create_rpc_port_option()\ndef get_owned_stores(data_rpc_port: int) -> None:\n    from chia.cmds.data_funcs import get_owned_stores_cmd\n\n    run(\n        get_owned_stores_cmd(\n            rpc_port=data_rpc_port,\n        )\n    )\n", "path": "chia/cmds/data.py"}], "after_files": [{"content": "import json\nimport logging\nfrom pathlib import Path\nfrom typing import Any, Coroutine, Dict, List, Optional, TypeVar\n\nimport click\nfrom typing_extensions import Protocol\n\n_T = TypeVar(\"_T\")\n\n\nclass IdentityFunction(Protocol):\n    def __call__(self, __x: _T) -> _T:\n        ...\n\n\nlogger = logging.getLogger(__name__)\n\n\n# TODO: this is more general and should be part of refactoring the overall CLI code duplication\ndef run(coro: Coroutine[Any, Any, Optional[Dict[str, Any]]]) -> None:\n    import asyncio\n\n    response = asyncio.run(coro)\n\n    success = response is not None and response.get(\"success\", False)\n    logger.info(f\"data layer cli call response:{success}\")\n    # todo make sure all cli methods follow this pattern, uncomment\n    # if not success:\n    # raise click.ClickException(message=f\"query unsuccessful, response: {response}\")\n\n\n@click.group(\"data\", short_help=\"Manage your data\")\ndef data_cmd() -> None:\n    pass\n\n\n# TODO: maybe use more helpful `type=`s to get click to handle error reporting of\n#       malformed inputs.\n\n\ndef create_changelist_option() -> IdentityFunction:\n    return click.option(\n        \"-d\",\n        \"--changelist\",\n        \"changelist_string\",\n        help=\"str representing the changelist\",\n        type=str,\n        required=True,\n    )\n\n\ndef create_key_option() -> IdentityFunction:\n    return click.option(\n        \"-h\",\n        \"--key\",\n        \"key_string\",\n        help=\"str representing the key\",\n        type=str,\n        required=True,\n    )\n\n\ndef create_data_store_id_option() -> \"IdentityFunction\":\n    return click.option(\n        \"-store\",\n        \"--id\",\n        help=\"The hexadecimal store id.\",\n        type=str,\n        required=True,\n    )\n\n\ndef create_data_store_name_option() -> \"IdentityFunction\":\n    return click.option(\n        \"-n\",\n        \"--table_name\",\n        \"table_name\",\n        help=\"The name of the table.\",\n        type=str,\n        required=True,\n    )\n\n\ndef create_rpc_port_option() -> \"IdentityFunction\":\n    return click.option(\n        \"-dp\",\n        \"--data-rpc-port\",\n        help=\"Set the port where the data layer is hosting the RPC interface. See rpc_port under wallet in config.yaml\",\n        type=int,\n        default=None,\n        show_default=True,\n    )\n\n\ndef create_fee_option() -> \"IdentityFunction\":\n    return click.option(\n        \"-m\",\n        \"--fee\",\n        help=\"Set the fees for the transaction, in XCH\",\n        type=str,\n        default=None,\n        show_default=True,\n        required=False,\n    )\n\n\n@data_cmd.command(\"create_data_store\", short_help=\"Create a new data store\")\n@create_rpc_port_option()\n@create_fee_option()\ndef create_data_store(\n    data_rpc_port: int,\n    fee: Optional[str],\n) -> None:\n    from chia.cmds.data_funcs import create_data_store_cmd\n\n    run(create_data_store_cmd(data_rpc_port, fee))\n\n\n@data_cmd.command(\"get_value\", short_help=\"Get the value for a given key and store\")\n@create_data_store_id_option()\n@create_key_option()\n@create_rpc_port_option()\ndef get_value(\n    id: str,\n    key_string: str,\n    data_rpc_port: int,\n) -> None:\n    from chia.cmds.data_funcs import get_value_cmd\n\n    run(get_value_cmd(data_rpc_port, id, key_string))\n\n\n@data_cmd.command(\"update_data_store\", short_help=\"Update a store by providing the changelist operations\")\n@create_data_store_id_option()\n@create_changelist_option()\n@create_rpc_port_option()\n@create_fee_option()\ndef update_data_store(\n    id: str,\n    changelist_string: str,\n    data_rpc_port: int,\n    fee: str,\n) -> None:\n    from chia.cmds.data_funcs import update_data_store_cmd\n\n    run(update_data_store_cmd(rpc_port=data_rpc_port, store_id=id, changelist=json.loads(changelist_string), fee=fee))\n\n\n@data_cmd.command(\"get_keys\", short_help=\"Get all keys for a given store\")\n@create_data_store_id_option()\n@create_rpc_port_option()\ndef get_keys(\n    id: str,\n    data_rpc_port: int,\n) -> None:\n    from chia.cmds.data_funcs import get_keys_cmd\n\n    run(get_keys_cmd(data_rpc_port, id))\n\n\n@data_cmd.command(\"get_keys_values\", short_help=\"Get all keys and values for a given store\")\n@create_data_store_id_option()\n@create_rpc_port_option()\ndef get_keys_values(\n    id: str,\n    data_rpc_port: int,\n) -> None:\n    from chia.cmds.data_funcs import get_keys_values_cmd\n\n    run(get_keys_values_cmd(data_rpc_port, id))\n\n\n@data_cmd.command(\"get_root\", short_help=\"Get the published root hash value for a given store\")\n@create_data_store_id_option()\n@create_rpc_port_option()\ndef get_root(\n    id: str,\n    data_rpc_port: int,\n) -> None:\n    from chia.cmds.data_funcs import get_root_cmd\n\n    run(get_root_cmd(rpc_port=data_rpc_port, store_id=id))\n\n\n@data_cmd.command(\"subscribe\", short_help=\"Subscribe to a store\")\n@create_data_store_id_option()\n@click.option(\n    \"-u\",\n    \"--url\",\n    \"urls\",\n    help=\"Manually provide a list of servers urls for downloading the data\",\n    type=str,\n    multiple=True,\n)\n@create_rpc_port_option()\ndef subscribe(\n    id: str,\n    urls: List[str],\n    data_rpc_port: int,\n) -> None:\n    from chia.cmds.data_funcs import subscribe_cmd\n\n    run(subscribe_cmd(rpc_port=data_rpc_port, store_id=id, urls=urls))\n\n\n@data_cmd.command(\"remove_subscription\", short_help=\"Remove server urls that are added via subscribing to urls\")\n@create_data_store_id_option()\n@click.option(\"-u\", \"--url\", \"urls\", help=\"Server urls to remove\", type=str, multiple=True)\n@create_rpc_port_option()\ndef remove_subscription(\n    id: str,\n    urls: List[str],\n    data_rpc_port: int,\n) -> None:\n    from chia.cmds.data_funcs import remove_subscriptions_cmd\n\n    run(remove_subscriptions_cmd(rpc_port=data_rpc_port, store_id=id, urls=urls))\n\n\n@data_cmd.command(\"unsubscribe\", short_help=\"Completely untrack a store\")\n@create_data_store_id_option()\n@create_rpc_port_option()\ndef unsubscribe(\n    id: str,\n    data_rpc_port: int,\n) -> None:\n    from chia.cmds.data_funcs import unsubscribe_cmd\n\n    run(unsubscribe_cmd(rpc_port=data_rpc_port, store_id=id))\n\n\n@data_cmd.command(\n    \"get_kv_diff\", short_help=\"Get the inserted and deleted keys and values between an initial and a final hash\"\n)\n@create_data_store_id_option()\n@click.option(\"-hash_1\", \"--hash_1\", help=\"Initial hash\", type=str)\n@click.option(\"-hash_2\", \"--hash_2\", help=\"Final hash\", type=str)\n@create_rpc_port_option()\ndef get_kv_diff(\n    id: str,\n    hash_1: str,\n    hash_2: str,\n    data_rpc_port: int,\n) -> None:\n    from chia.cmds.data_funcs import get_kv_diff_cmd\n\n    run(get_kv_diff_cmd(rpc_port=data_rpc_port, store_id=id, hash_1=hash_1, hash_2=hash_2))\n\n\n@data_cmd.command(\"get_root_history\", short_help=\"Get all changes of a singleton\")\n@create_data_store_id_option()\n@create_rpc_port_option()\ndef get_root_history(\n    id: str,\n    data_rpc_port: int,\n) -> None:\n    from chia.cmds.data_funcs import get_root_history_cmd\n\n    run(get_root_history_cmd(rpc_port=data_rpc_port, store_id=id))\n\n\n@data_cmd.command(\"add_missing_files\", short_help=\"Manually reconstruct server files from the data layer database\")\n@click.option(\n    \"-i\",\n    \"--ids\",\n    help=\"List of stores to reconstruct. If not specified, all stores will be reconstructed\",\n    type=str,\n    required=False,\n)\n@click.option(\n    \"-o/-n\",\n    \"--overwrite/--no-overwrite\",\n    help=\"Specify if already existing files need to be overwritten by this command\",\n)\n@click.option(\n    \"-f\", \"--foldername\", type=str, help=\"If specified, use a non-default folder to write the files\", required=False\n)\n@create_rpc_port_option()\ndef add_missing_files(ids: Optional[str], overwrite: bool, foldername: Optional[str], data_rpc_port: int) -> None:\n    from chia.cmds.data_funcs import add_missing_files_cmd\n\n    run(\n        add_missing_files_cmd(\n            rpc_port=data_rpc_port,\n            ids=None if ids is None else json.loads(ids),\n            overwrite=overwrite,\n            foldername=None if foldername is None else Path(foldername),\n        )\n    )\n\n\n@data_cmd.command(\"add_mirror\", short_help=\"Publish mirror urls on chain\")\n@click.option(\"-i\", \"--id\", help=\"Store id\", type=str, required=True)\n@click.option(\n    \"-a\", \"--amount\", help=\"Amount to spend for this mirror, in mojos\", type=int, default=0, show_default=True\n)\n@click.option(\n    \"-u\",\n    \"--url\",\n    \"urls\",\n    help=\"URL to publish on the new coin, multiple accepted and will be published to a single coin.\",\n    type=str,\n    multiple=True,\n)\n@create_fee_option()\n@create_rpc_port_option()\ndef add_mirror(id: str, amount: int, urls: List[str], fee: Optional[str], data_rpc_port: int) -> None:\n    from chia.cmds.data_funcs import add_mirror_cmd\n\n    run(\n        add_mirror_cmd(\n            rpc_port=data_rpc_port,\n            store_id=id,\n            urls=urls,\n            amount=amount,\n            fee=fee,\n        )\n    )\n\n\n@data_cmd.command(\"delete_mirror\", short_help=\"Delete an owned mirror by its coin id\")\n@click.option(\"-c\", \"--coin_id\", help=\"Coin id\", type=str, required=True)\n@create_fee_option()\n@create_rpc_port_option()\ndef delete_mirror(coin_id: str, fee: Optional[str], data_rpc_port: int) -> None:\n    from chia.cmds.data_funcs import delete_mirror_cmd\n\n    run(\n        delete_mirror_cmd(\n            rpc_port=data_rpc_port,\n            coin_id=coin_id,\n            fee=fee,\n        )\n    )\n\n\n@data_cmd.command(\"get_mirrors\", short_help=\"Get a list of all mirrors for a given store\")\n@click.option(\"-i\", \"--id\", help=\"Store id\", type=str, required=True)\n@create_rpc_port_option()\ndef get_mirrors(id: str, data_rpc_port: int) -> None:\n    from chia.cmds.data_funcs import get_mirrors_cmd\n\n    run(\n        get_mirrors_cmd(\n            rpc_port=data_rpc_port,\n            store_id=id,\n        )\n    )\n\n\n@data_cmd.command(\"get_subscriptions\", short_help=\"Get subscribed stores, including the owned stores\")\n@create_rpc_port_option()\ndef get_subscriptions(data_rpc_port: int) -> None:\n    from chia.cmds.data_funcs import get_subscriptions_cmd\n\n    run(\n        get_subscriptions_cmd(\n            rpc_port=data_rpc_port,\n        )\n    )\n\n\n@data_cmd.command(\"get_owned_stores\", short_help=\"Get owned stores\")\n@create_rpc_port_option()\ndef get_owned_stores(data_rpc_port: int) -> None:\n    from chia.cmds.data_funcs import get_owned_stores_cmd\n\n    run(\n        get_owned_stores_cmd(\n            rpc_port=data_rpc_port,\n        )\n    )\n", "path": "chia/cmds/data.py"}]}