move to its own command
@@ -56,12 +56,12 @@ class Executor:
self.wallet = wallet
# Only load subtensor if we need it.
- if self.config.command in ["transfer", "unstake", "stake", "overview"]:
+ if self.config.command in ["transfer", "unstake", "stake", "overview", "save_state"]:
if subtensor == None:
subtensor = bittensor.subtensor.Subtensor( self.config, self.wallet )
self.subtensor = subtensor
- if self.config.command in ["overview"]:
+ if self.config.command in ["overview", "save_state"]:
self.metagraph = bittensor.metagraph.Metagraph( self.config, self.wallet, self.subtensor )
@@ -81,6 +81,8 @@ class Executor:
overview_parser = cmd_parsers.add_parser('overview',
help='''Show account overview.''')
+ save_state_parser = cmd_parsers.add_parser('save_state',
+ help='''Saves the metagraph state to a json file.''')
transfer_parser = cmd_parsers.add_parser('transfer',
help='''Transfer Tao between accounts.''')
@@ -126,11 +128,13 @@ class Executor:
bittensor.wallet.Wallet.add_args( new_hotkey_parser )
# Fill arguments for the overview command
- overview_parser.add_argument('--to_file', required=False, dest='to_file', action='store_false', help='''Write the overview to a file.''')
- overview_parser.set_defaults(to_file=True)
bittensor.subtensor.Subtensor.add_args( overview_parser )
bittensor.metagraph.Metagraph.add_args( overview_parser )
+ # Fill argument for the save_state command
+ bittensor.subtensor.Subtensor.add_args( save_state_parser )
+ bittensor.metagraph.Metagraph.add_args( save_state_parser )
+
# Fill arguments for unstake command.
unstake_parser.add_argument('--all', dest="unstake_all", action='store_true')
unstake_parser.add_argument('--uid', dest="uid", type=int, required=False)
@@ -192,6 +196,8 @@ class Executor:
self.stake()
elif self.config.command == "overview":
self.overview()
+ elif self.config.command == "save_state":
+ self.save_state()
elif self.config.command == "new_coldkey":
self.create_new_coldkey()
elif self.config.command == "new_hotkey":
@@ -261,8 +267,10 @@ class Executor:
print(t.get_string())
print("Total stake: ", total_stake)
- if self.config.to_file:
- filepath = os.path.expanduser(self.config.wallet.path + "/" + self.config.wallet.name + "/overview-block{}.txt".format(self.metagraph.block))
+ def save_state( self ):
+ self.subtensor.connect()
+ self.metagraph.sync()
+ filepath = os.path.expanduser('~/.bittensor/metagraph-at-block{}.txt'.format(self.metagraph.block))
print ('Saving metagraph.state to file: {}'.format( filepath ))
self.metagraph.state.write_to_file( filepath )
