My question involves police conduct in the State of: Texas

So, i had just left the bank and I was walking home with a friend.. We get halfway down and a officer pulls over and asks for our names he proceeds to pat down my friend, then walks to me and sticks his hands in my pocket.. Pulls out my wallet and then starts to count my money? Then he ask's how I got that much money am I working etc? I was wondering if he's allowed to do such a thing and If i could sue?