Skip to content

Commit 980419a

Browse files
authored
Merge pull request #17 from drift-labs/master
decode pubkey bug fix
2 parents a5f2b75 + 0c8ea94 commit 980419a

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

src/ws_server.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::{
33
collections::HashMap,
44
env,
55
net::SocketAddr,
6+
str::FromStr,
67
sync::{atomic::AtomicBool, Arc},
78
time::Duration,
89
};
@@ -32,7 +33,6 @@ use rdkafka::{
3233
consumer::{Consumer, StreamConsumer},
3334
Message as KafkaMessage,
3435
};
35-
use solana_sdk::bs58::{self};
3636
use tokio::{
3737
io::AsyncWriteExt,
3838
sync::{
@@ -999,22 +999,16 @@ pub async fn start_server() {
999999
}
10001000

10011001
// extract pubkey string from HTTP request
1002-
fn decode_pubkey(request: &str) -> Result<Pubkey, ()> {
1002+
fn decode_pubkey(request: &str) -> Result<Pubkey, &'static str> {
10031003
if let Some(idx) = request.find('=') {
1004-
let idx = idx + 1;
1005-
let mut pubkey = [0_u8; 32];
1006-
if bs58::decode(&request[idx..idx + 44])
1007-
.with_alphabet(bs58::Alphabet::DEFAULT)
1008-
.onto(&mut pubkey)
1009-
.is_err()
1010-
{
1011-
return Err(());
1012-
}
1013-
1014-
return Ok(Pubkey::new_from_array(pubkey));
1004+
let pubkey_str = &request[idx + 1..];
1005+
let pubkey_token = pubkey_str
1006+
.split_whitespace()
1007+
.next()
1008+
.ok_or("No pubkey found")?;
1009+
return Pubkey::from_str(pubkey_token).map_err(|_| "Invalid pubkey format");
10151010
}
1016-
1017-
Err(())
1011+
Err("No '=' found in request")
10181012
}
10191013

10201014
#[cfg(test)]

0 commit comments

Comments
 (0)