I just added this to my Multihashes utility:
public static boolean isValid(String multihash) {
try {
Multihash.decode(multihash);
return true;
} catch (IllegalArgumentException e) {
return false;
}
}
Because Base.lookup() throws an IllegalArgumentException, and decode() throws a UnsupportedOperationException, you currently as-is cannot really do it any better way.
But this is of course not ideal for performance. How about having a method like this in class Multibase here?
Would a PR for this be welcome here and get reviewed and merged?
@ianopolous @mk868
I just added this to my
Multihashesutility:Because
Base.lookup()throws an IllegalArgumentException, anddecode()throws a UnsupportedOperationException, you currently as-is cannot really do it any better way.But this is of course not ideal for performance. How about having a method like this in
class Multibasehere?Would a PR for this be welcome here and get reviewed and merged?
@ianopolous @mk868