Right, I see. There's still the difference of having official permission according to the legal system, such as the search warrant being a mechanism codified in law, or the mechanism to get a license as an apothecary to operate a pharmacy
If there is no such license you can apply for, I'm not sure there exists a system by which you can be indemnified from criminal prosecution for doing such sales (or possession or whatever the case may be)
The question reminded me of a 2019 case where two parties went to the judge to get a ruling on something, without there being damages or claims. (Here, a potential buyer and seller could ask to decide whether a certain substance would be legal to sell before the sale happens, steering clear of prosecution until there is a ruling.) Reading that case back, the legal provision that made this possible only applies to situations where the parties are free to do whatever (such as with a contract dispute); it does not work for creating jurisprudence on criminal law. Asking ChatGPT as a quick last attempt, it proposes to ask a lawyer (you've shared how well that worked) or to sue the government over the law that makes the sale illegal which would be void if the judge goes "this substance doesn't fall under that law anyway" and then you've got jurisprudence to work with. The latter sounds a bit strange, not sure if that's actually possible, but it'd be worth exploring for such edge cases where it may or may not be criminal to do a certain thing
Of course, I totally see how this is a double standard: you've done your homework and to the best of everyone's knowledge it's legal, and then when it turns out you're wrong, whether you get sent to prison depends on whether it was the government who sanctioned it. Everyone can make an honest mistake, government or no
I don't know the intentions of the drugs dealers you have experience with. If there are legit purposes for the specific analog they were selling (that is, purposes falling outside of the spirit of the law that makes fentanyl (analogs) illegal) then it seems strange that a judge would send them to prison for years. Was a long prison sentence perhaps compulsory due to some minimum sentence requirement as part of this war on drugs thing? Wondering this since our government is implementing more and more minimum punishments despite research showing this does not deter the behavior and also increases recidivism due to the longer time you spend outside society, losing any position that you had in it. It's great