def generate_pos(self, node_id, btime=None):
    ' stakes a block using generate on nodes[node_id]'
    assert_greater_than(len(self.nodes), node_id)
    rpc_conn = self.nodes[node_id]
    ss = rpc_conn.getstakingstatus()
    assert ss['walletunlocked']
    assert (ss['stakeablecoins'] > 0)
    assert (ss['stakingbalance'] > 0.0)
    if (btime is not None):
        next_btime = (btime + 60)
    fStaked = False
    failures = 0
    while (not fStaked):
        try:
            rpc_conn.generate(1)
            fStaked = True
        except JSONRPCException as e:
            if ("Couldn't create new block" in str(e)):
                failures += 1
                if (failures > 60):
                    ss = rpc_conn.getstakingstatus()
                    if (not (ss['walletunlocked'] and (ss['stakeablecoins'] > 0) and (ss['stakingbalance'] > 0.0))):
                        raise AssertionError(('Node %d unable to stake!' % node_id))
                if (btime is not None):
                    btime += 1
                    set_node_times(self.nodes, btime)
                else:
                    time.sleep(1)
            else:
                raise e
    if (btime is not None):
        btime = max((btime + 1), next_btime)
        set_node_times(self.nodes, btime)
        return btime
    else:
        return None
stakes a block using generate on nodes[node_id]
def generate_pos(self, node_id, btime=None):
    ' '
    assert_greater_than(len(self.nodes), node_id)
    rpc_conn = self.nodes[node_id]
    ss = rpc_conn.getstakingstatus()
    assert ss['walletunlocked']
    assert (ss['stakeablecoins'] > 0)
    assert (ss['stakingbalance'] > 0.0)
    if (btime is not None):
        next_btime = (btime + 60)
    fStaked = False
    failures = 0
    while (not fStaked):
        try:
            rpc_conn.generate(1)
            fStaked = True
        except JSONRPCException as e:
            if ("Couldn't create new block" in str(e)):
                failures += 1
                if (failures > 60):
                    ss = rpc_conn.getstakingstatus()
                    if (not (ss['walletunlocked'] and (ss['stakeablecoins'] > 0) and (ss['stakingbalance'] > 0.0))):
                        raise AssertionError(('Node %d unable to stake!' % node_id))
                if (btime is not None):
                    btime += 1
                    set_node_times(self.nodes, btime)
                else:
                    time.sleep(1)
            else:
                raise e
    if (btime is not None):
        btime = max((btime + 1), next_btime)
        set_node_times(self.nodes, btime)
        return btime
    else:
        return None