pub fn import_raw_key<T>(params: Params, client: ValidatorClient<T>) -> Result<Value, Error>
where
    T: MessageSender,
{
    info!("personal_importRawKey");

    let usage = "Takes [key: DATA]";

    let (key, password): (String, Option<String>) =
        params.parse().map_err(|_| Error::invalid_params(usage))?;

    let priv_key = Secp256k1PrivateKey::from_hex(&key)
        .map_err(|err| fail!("Private key must be hex-encoded", err))?;
    let pem_str = match password {
        Some(ref pw) => priv_key.to_pem_with_password(&pw),
        None => priv_key.to_pem(),
    }
    .map_err(|err| fail!("Couldn't load key", err))?;

    let account = Account::load_from_str(&pem_str, &password)
        .map_err(|err| fail!("Error loading account from key", err))?;

    let mut filename = get_key_dir().ok_or_else(Error::internal_error)?;
    filename.push(account.address());

    fs::write(filename.with_extension("pem"), pem_str)
        .map_err(|err| fail!("Error generating key", err))?;

    // Create and send the transaction in for processing
    let mut txn = SethTransactionPb::new();
    txn.set_transaction_type(SethTransaction_TransactionType::CREATE_EXTERNAL_ACCOUNT);
    txn.set_create_external_account({
        let mut inner = CreateExternalAccountTxn::new();
        inner.set_nonce(0);

        inner
    });

    client
        .send_transaction(
            &account.address(),
            &SethTransaction::try_from(txn).ok_or_else(Error::internal_error)?,
        )
        .map_err(|err| fail!("Error sending transaction", err))?;

    client
        .unlock_account(&account, Some(0))
        .map_err(|err| fail!("Couldn't unlock account", err))?;

    Ok(transform::hex_prefix(&account.address()))
}
/// Imports a raw, hex-encoded secp256k1 key
Imports a raw, hex-encoded secp256k1 key
Imports a raw hex - encoded secp256k1 key
pub fn import_raw_key<T>(params: Params, client: ValidatorClient<T>) -> Result<Value, Error>
where
    T: MessageSender,
{
    info!("personal_importRawKey");
    let usage = "Takes [key: DATA]";
    let (key, password): (String, Option<String>) =
        params.parse().map_err(|_| Error::invalid_params(usage))?;
    let priv_key = Secp256k1PrivateKey::from_hex(&key)
        .map_err(|err| fail!("Private key must be hex-encoded", err))?;
    let pem_str = match password {
        Some(ref pw) => priv_key.to_pem_with_password(&pw),
        None => priv_key.to_pem(),
    }
    .map_err(|err| fail!("Couldn't load key", err))?;
    let account = Account::load_from_str(&pem_str, &password)
        .map_err(|err| fail!("Error loading account from key", err))?;
    let mut filename = get_key_dir().ok_or_else(Error::internal_error)?;
    filename.push(account.address());
    fs::write(filename.with_extension("pem"), pem_str)
        .map_err(|err| fail!("Error generating key", err))?;
    // Create and send the transaction in for processing
    let mut txn = SethTransactionPb::new();
    txn.set_transaction_type(SethTransaction_TransactionType::CREATE_EXTERNAL_ACCOUNT);
    txn.set_create_external_account({
        let mut inner = CreateExternalAccountTxn::new();
        inner.set_nonce(0);
        inner
    });
    client
        .send_transaction(
            &account.address(),
            &SethTransaction::try_from(txn).ok_or_else(Error::internal_error)?,
        )
        .map_err(|err| fail!("Error sending transaction", err))?;
    client
        .unlock_account(&account, Some(0))
        .map_err(|err| fail!("Couldn't unlock account", err))?;
    Ok(transform::hex_prefix(&account.address()))
}
pub fn import_raw_key < T > ( params : Params , client : ValidatorClient < T > ) -> Result < Value , Error > where T : MessageSender , { info ! ( " " ) ; let usage = " " ; let ( key , password ) : ( String , Option < String > ) = params . parse ( ) . map_err ( | _ | Error :: invalid_params ( usage ) ) ? ; let priv_key = Secp256k1PrivateKey :: from_hex ( & key ) . map_err ( | err | fail ! ( " " err ) ) ? ; let pem_str = match password { Some ( ref pw ) => priv_key . to_pem_with_password ( & pw ) , None => priv_key . to_pem ( ) , } . map_err ( | err | fail ! ( " " err ) ) ? ; let account = Account :: load_from_str ( & pem_str , & password ) . map_err ( | err | fail ! ( " " err ) ) ? ; let mut filename = get_key_dir ( ) . ok_or_else ( Error :: internal_error ) ? ; filename . push ( account . address ( ) ) ; fs :: write ( filename . with_extension ( " " ) , pem_str ) . map_err ( | err | fail ! ( " " err ) ) ? ; // Create and send the transaction in for processing let mut txn = SethTransactionPb :: new ( ) ; txn . set_transaction_type ( SethTransaction_TransactionType :: CREATE_EXTERNAL_ACCOUNT ) ; txn . set_create_external_account ( { let mut inner = CreateExternalAccountTxn :: new ( ) ; inner . set_nonce ( 0 ) ; inner } ) ; client . send_transaction ( & account . address ( ) , & SethTransaction :: try_from ( txn ) . ok_or_else ( Error :: internal_error ) ? , ) . map_err ( | err | fail ! ( " " err ) ) ? ; client . unlock_account ( & account , Some ( 0 ) ) . map_err ( | err | fail ! ( " " err ) ) ? ; Ok ( transform :: hex_prefix ( & account . address ( ) ) ) }
Imports a raw, hex-encoded secp256k1 key
Imports a raw hex - encoded secp256k1 key
params
Params
client
ValidatorClient<T>
params
Params
client
ValidatorClient<T>