def approve_root(badger: BadgerSystem):
    badgerTree = badger.badgerTree
    if not badgerTree.hasPendingRoot():
        console.print("No pending root")
        return False

    if rpc.is_active():
        badger.guardian = accounts.at(
            "0x626F69162Ea1556A75Dd4443D87D2fe38dd25901", force=True)

    current = fetchCurrentMerkleData(badger)
    pending = fetchPendingMerkleData(badger)

    (publishedRewards, sb, eb) = get_last_published_cycle(badger)
    (proposedRewards, startBlock, endBlock) = get_last_proposed_cycle(badger)

    console.print(proposedRewards["merkleRoot"])

    rootHash = hash(proposedRewards["merkleRoot"])
    contentFileName = content_hash_to_filename(rootHash)
    print("Uploading to file " + contentFileName)

    with open(contentFileName, "w") as outfile:
        json.dump(proposedRewards, outfile, indent=4)

    with open(contentFileName) as f:
        after_file = json.load(f)

    console.print(contentFileName)

    print(
        proposedRewards["merkleRoot"],
        startBlock,
        endBlock,
        badgerTree.lastProposeStartBlock(),
        badgerTree.lastProposeEndBlock(),
    )

    verify_rewards(badger, startBlock, endBlock, publishedRewards,
                   proposedRewards)

    badgerTree.approveRoot(
        proposedRewards["merkleRoot"],
        pending["contentHash"],
        proposedRewards["cycle"],
        startBlock,
        endBlock,
        {
            "from": badger.guardian,
            "gas_limit": 3000000,
            "allow_revert": True
        },
    )

    upload(contentFileName)
def approve_root(badger):
    (currentRewards, startBlock, endBlock) = get_last_proposed_cycle(badger)

    # If there is a pending root, approve after independently verifying it
    rootApproved = run_action(
        badger,
        {
            "action": "guardian",
            "startBlock": startBlock,
            "endBlock": endBlock,
            "pastRewards": currentRewards,
        },
        test=False,
    )
def main():
    badger = connect_badger(badger_config.prod_json, load_guardian=False)
    (currentRewards, startBlock, endBlock) = get_last_proposed_cycle(badger)

    # If there is a pending root, approve after independently verifying it
    rootApproved = run_action(
        badger,
        {
            "action": "guardian",
            "startBlock": startBlock,
            "endBlock": endBlock,
            "pastRewards": currentRewards,
        },
        test=True,
    )