I'm sorry you deal with chronic pain.
Yes, unfortunately, you did screw up. Hopefully this is a good lesson about not self medicating or taking things you aren't prescribed to you. If you need the medications, you simply cannot do anything to jeopardize that. Plus, that adds to the challenges that chronic pain pts face every day. I'm sure you're already aware of that.
Most likely, the doctor won't cancel the script, but you won't know for sure until you try to get it filled. My advice would be to use the smallest amount possible while you look for another doctor. You COULD try to ask if your doc would see you and just get real with him, be 100% honest and tell him you messed up and would like another chance. Tell him you would be glad to meet any requirements he places on you. It's worth giving it a try, you never know, maybe he will give you a second chance.
If he doesn't take you back, be prepared to have a rough time finding a doc, as they're going to want copies of your medical record, and the dismissal from your last doc will be documented. People don't think of just how far reaching the consequences can be, rather than deal with the pain the RIGHT way by calling the doc, they self medicate, and then it follows them. Chronic pain patients are forever under the microscope because of the serious abuse of prescription pain meds. Taking meds that aren't Rx'ed to you from a friend actually contributes to that problem, that's called diversion.
It's just SO important that you're always honest about what you're doing and what you're taking and PLEASE be cautious with these meds. People end up with an addiction problem all the time, starting with an innocent prescribed medication. You accepting opiates from a friend kind of throws up a red flag too that you might have some addictive tendencies. Just be very careful and if you DO feel you may have an addiction problem (not just being dependent), then you would want to address that right away as addiction is only progressive.
Start calling around for a new doctor and my advice is to be honest with everyone about what you did. Honesty is the best policy. If you try to make excuses, or make up stories, it's going to put up even more red flags.
Very best to you, I hope you are able to find some solutions for your pain! Please understand that none of my reply is meant to be judgemental, I'm just being straight with you. It's refreshing that you were honest here about messing up and admitting that you didn't make the best decision.
If you need it, we have a great addiction forum with awesome people there who would help you on top of the pain folks here.
http://www.medhelp.org/forums/Addiction-Substance-Abuse/show/77
Take care!