-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathget_miners_collateral.py
More file actions
executable file
·62 lines (50 loc) · 1.61 KB
/
get_miners_collateral.py
File metadata and controls
executable file
·62 lines (50 loc) · 1.61 KB
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
#!/usr/bin/env python3
"""
Miner Collateral Query Tool
This script allows users to query the collateral amount for a specific miner
in a given smart contract. It connects to a blockchain network, validates
the provided addresses, and retrieves the collateral information.
The script will output the collateral amount in TAO (the native token).
"""
import argparse
import sys
import bittensor.utils
from common import (
get_web3_connection,
get_miner_collateral,
validate_address_format,
)
def main():
"""Main function to handle command line arguments and display collateral."""
parser = argparse.ArgumentParser(
description="Query the collateral amount for a specific miner in a smart contract"
)
parser.add_argument(
"--contract-address",
required=True,
help="The address of the smart contract"
)
parser.add_argument(
"--miner-address",
required=True,
help="The address of the miner to query"
)
parser.add_argument(
"--network",
default="finney",
help="The Subtensor Network to connect to.",
)
args = parser.parse_args()
validate_address_format(args.contract_address)
validate_address_format(args.miner_address)
w3 = get_web3_connection(args.network)
collateral = get_miner_collateral(w3, args.contract_address, args.miner_address)
print(
f"Collateral for miner {args.miner_address}: {w3.from_wei(collateral, 'ether')} TAO"
)
if __name__ == "__main__":
try:
main()
except Exception as e:
print(f"Error: {str(e)}", file=sys.stderr)
sys.exit(1)