here is my automatic failover script powered by xerocs python-graphenelib. I am a noob at teh programming, and if I did anything wrong I would love the feedback.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import json
from grapheneapi import GrapheneWebsocket, GrapheneWebsocketProtocol
import time
import config
rpc = GrapheneWebsocket("localhost", 8092, "", "")
publickeys = config.publickeys
witnessname = config.witnessname
def getmissed(witnessname):
witness = rpc.get_witness(witnessname)
missed = witness["total_missed"]
return missed
missed = getmissed(config.witnessname)
def switch(witnessname, publickeys, missed):
keynumber = missed % len(publickeys)
key = publickeys[keynumber]
rpc.update_witness(witnessname, "", key, "true")
print("witness down switching to " + key)
print ("Nothing in this window will change unless a block is missed")
while True:
if missed < getmissed(config.witnessname):
missed = getmissed(config.witnessname)
switch(witnessname, publickeys, missed)
else:
time.sleep(3)
You need to add two lines to your config.py file. witnessname as a string and publickeys as strings in a tuple of the public keys you want to switch between. those lines look like this in my case.
witnessname = "dele-puppy"
publickeys = ("GPH75xxKG4ZeztPpnhmFch99smunUWMvDy9mB6Le497vpAA3XUXaD", "GPH8Sj81ncf8PK5QwJZvhWsvwp6m4bXzTFvp4bKycNNFvHaJpZSnH")
The wallet this script is running through needs to be unlocked, and must contain the owner key (I think its the owner key, rather than the active key) of the witness.