At first sight, it appears in these verses that David is saying God has blessed him as outlined in the Psalm so far because David is a good man and had done many good things. We see, however, that this is far from his thinking at this point. He is saying, rather, that the righteousness that he sees in his life is a sure evidence that God has saved him. Saving faith will always result in the fruit of righteousness and good deeds will flow from it. So David rejoices that God has saved him, that the evidence is present through his changed heart and life and that because he is a child of God, God has blessed him, heard him and delivered him.
We see also that there is blessing in this life for obedience to the Lord. It does matter how we live as believers - we cannot be Christians and practice a life of ungodliness and disobedience. To the extent that we do obey and seek after the Lord, there are blessings and rewards for us in Christ. To the extent we quench and grieve the Spirit, those works will not be present, and we will lose our assurance of salvation and the blessing of obedience. The works we perform do not save us but they show we are saved and we are blessed accordingly.