David acknowledges that he deserves punishment when he has sinned against his neighbour. That is a beautiful humble position to take. He expresses this in some kind of oath, a possibility of self-destruction. When he misbehaves, his enemy can justly make his life miserable. Then he can go down ingloriously. He can be destroyed.
But from what follows, it shows that the person who is praying or the poet sees himself as righteous, thus innocent. It may concern false accusations of people (Psalm 7:14 gives birth to lies
) and not about the relationship with the Lord God.
The One who is truly righteous and is being persecuted without reason (Psalm 35:19 and Psalm 69:4) is Christ; thinking of that, the poet is a kind of shadow of the Lord.
3 O LORD my God, if I have done this, if there is wrong in my hands,