Refactor remote-wallet path parsing (backport #16798) (#16894)

* SDK: More conversions for `Pubkey`

(cherry picked from commit 9b7120bf73)

* SDK: More conversion for `DerivationPath`

(cherry picked from commit 722de942ca)

* remote-wallet: Add helpers for locating remote wallets

(cherry picked from commit 64fcb792c2)

* remote-wallet: Plumb `Locator` into `RemoteWalletInfo`

(cherry picked from commit 3d12be29ec)

* remote-wallet: `derivation-path` crate doesn't like empty trailing child indexes

(cherry picked from commit 4ce4f04c58)

* remote-wallet: Move `Locator` to its own module

(cherry picked from commit cac666d035)

Co-authored-by: Trent Nelson <trent@solana.com>
This commit is contained in:
mergify[bot]
2021-04-28 01:20:41 +00:00
committed by GitHub
parent dbc58455df
commit 9797178ad1
10 changed files with 757 additions and 103 deletions

View File

@@ -1,7 +1,11 @@
use crate::{decode_error::DecodeError, hash::hashv};
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use num_derive::{FromPrimitive, ToPrimitive};
use std::{convert::TryFrom, fmt, mem, str::FromStr};
use std::{
convert::{Infallible, TryFrom},
fmt, mem,
str::FromStr,
};
use thiserror::Error;
/// Number of bytes in a pubkey
@@ -63,7 +67,16 @@ pub enum ParsePubkeyError {
WrongSize,
#[error("Invalid Base58 string")]
Invalid,
#[error("Infallible")]
Infallible,
}
impl From<Infallible> for ParsePubkeyError {
fn from(_: Infallible) -> Self {
Self::Infallible
}
}
impl<T> DecodeError<T> for ParsePubkeyError {
fn type_of() -> &'static str {
"ParsePubkeyError"
@@ -88,6 +101,13 @@ impl FromStr for Pubkey {
}
}
impl TryFrom<&str> for Pubkey {
type Error = ParsePubkeyError;
fn try_from(s: &str) -> Result<Self, Self::Error> {
Pubkey::from_str(s)
}
}
impl Pubkey {
pub fn new(pubkey_vec: &[u8]) -> Self {
Self(