def attempt_superblock_creation(kzcashd):
    import kzcashlib
    if (not kzcashd.is_masternode()):
        print("We are not a Masternode... can't submit superblocks!")
        return
    event_block_height = kzcashd.next_superblock_height()
    if Superblock.is_voted_funding(event_block_height):
        for sb in Superblock.at_height(event_block_height):
            if (not sb.voted_on(signal=VoteSignals.funding)):
                sb.vote(kzcashd, VoteSignals.funding, VoteOutcomes.no)
        return
    if (not kzcashd.is_govobj_maturity_phase()):
        printdbg('Not in maturity phase yet -- will not attempt Superblock')
        return
    proposals = Proposal.approved_and_ranked(proposal_quorum=kzcashd.governance_quorum(), next_superblock_max_budget=kzcashd.next_superblock_max_budget())
    budget_max = kzcashd.get_superblock_budget_allocation(event_block_height)
    sb_epoch_time = kzcashd.block_height_to_epoch(event_block_height)
    sb = kzcashlib.create_superblock(proposals, event_block_height, budget_max, sb_epoch_time)
    if (not sb):
        printdbg('No superblock created, sorry. Returning.')
        return
    dbrec = Superblock.find_highest_deterministic(sb.hex_hash())
    if dbrec:
        dbrec.vote(kzcashd, VoteSignals.funding, VoteOutcomes.yes)
        for sb in Superblock.select().where((Superblock.sb_hash == sb.hex_hash())):
            if (not sb.voted_on(signal=VoteSignals.funding)):
                sb.vote(kzcashd, VoteSignals.delete, VoteOutcomes.yes)
        printdbg("VOTED FUNDING FOR SB! We're done here 'til next superblock cycle.")
        return
    else:
        printdbg("The correct superblock wasn't found on the network...")
    if kzcashd.we_are_the_winner():
        printdbg('we are the winner! Submit SB to network')
        sb.submit(kzcashd)
def attempt_superblock_creation(kzcashd):
    import kzcashlib
    if (not kzcashd.is_masternode()):
        print("We are not a Masternode... can't submit superblocks!")
        return
    event_block_height = kzcashd.next_superblock_height()
    if Superblock.is_voted_funding(event_block_height):
        for sb in Superblock.at_height(event_block_height):
            if (not sb.voted_on(signal=VoteSignals.funding)):
                sb.vote(kzcashd, VoteSignals.funding, VoteOutcomes.no)
        return
    if (not kzcashd.is_govobj_maturity_phase()):
        printdbg('Not in maturity phase yet -- will not attempt Superblock')
        return
    proposals = Proposal.approved_and_ranked(proposal_quorum=kzcashd.governance_quorum(), next_superblock_max_budget=kzcashd.next_superblock_max_budget())
    budget_max = kzcashd.get_superblock_budget_allocation(event_block_height)
    sb_epoch_time = kzcashd.block_height_to_epoch(event_block_height)
    sb = kzcashlib.create_superblock(proposals, event_block_height, budget_max, sb_epoch_time)
    if (not sb):
        printdbg('No superblock created, sorry. Returning.')
        return
    dbrec = Superblock.find_highest_deterministic(sb.hex_hash())
    if dbrec:
        dbrec.vote(kzcashd, VoteSignals.funding, VoteOutcomes.yes)
        for sb in Superblock.select().where((Superblock.sb_hash == sb.hex_hash())):
            if (not sb.voted_on(signal=VoteSignals.funding)):
                sb.vote(kzcashd, VoteSignals.delete, VoteOutcomes.yes)
        printdbg("VOTED FUNDING FOR SB! We're done here 'til next superblock cycle.")
        return
    else:
        printdbg("The correct superblock wasn't found on the network...")
    if kzcashd.we_are_the_winner():
        printdbg('we are the winner! Submit SB to network')
        sb.submit(kzcashd)