Skip to content

Commit

Permalink
More base58 encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyera Eulberg committed Jan 10, 2020
1 parent fea1b70 commit 265803d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 28 deletions.
22 changes: 8 additions & 14 deletions client/src/rpc_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use jsonrpc_core::Result as JsonResult;
use serde_json::{json, Value};
use solana_sdk::{
clock::{Epoch, Slot},
hash::Hash,
message::MessageHeader,
transaction::{Result, Transaction},
};
Expand All @@ -26,8 +25,8 @@ pub struct Response<T> {
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RpcConfirmedBlock {
pub previous_blockhash: RpcEncodedHash,
pub blockhash: RpcEncodedHash,
pub previous_blockhash: String,
pub blockhash: String,
pub parent_slot: Slot,
pub transactions: Vec<(RpcEncodedTransaction, Option<RpcTransactionStatus>)>,
}
Expand All @@ -39,17 +38,10 @@ pub enum RpcTransactionEncoding {
Json,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(rename_all = "camelCase", untagged)]
pub enum RpcEncodedHash {
Binary(Hash),
Json(String),
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", untagged)]
pub enum RpcEncodedTransaction {
Binary(Vec<u8>),
Binary(String),
Json(RpcTransaction),
}

Expand Down Expand Up @@ -78,13 +70,15 @@ impl RpcEncodedTransaction {
.map(|instruction| RpcCompiledInstruction {
program_id_index: instruction.program_id_index,
accounts: instruction.accounts.clone(),
data: instruction.data.clone(),
data: bs58::encode(instruction.data.clone()).into_string(),
})
.collect(),
},
})
} else {
RpcEncodedTransaction::Binary(serialize(&transaction).unwrap())
RpcEncodedTransaction::Binary(
bs58::encode(serialize(&transaction).unwrap()).into_string(),
)
}
}
}
Expand Down Expand Up @@ -113,7 +107,7 @@ pub struct RpcMessage {
pub struct RpcCompiledInstruction {
pub program_id_index: u8,
pub accounts: Vec<u8>,
pub data: Vec<u8>,
pub data: String,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
Expand Down
17 changes: 3 additions & 14 deletions ledger/src/blocktree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ use rayon::{
};
use rocksdb::DBRawIterator;
use solana_client::rpc_request::{
RpcConfirmedBlock, RpcEncodedHash, RpcEncodedTransaction, RpcTransactionEncoding,
RpcTransactionStatus,
RpcConfirmedBlock, RpcEncodedTransaction, RpcTransactionEncoding, RpcTransactionStatus,
};
use solana_measure::measure::Measure;
use solana_metrics::{datapoint_debug, datapoint_error};
Expand Down Expand Up @@ -1351,23 +1350,13 @@ impl Blocktree {
} else {
Hash::default()
};
let previous_blockhash = if encoding == RpcTransactionEncoding::Json {
RpcEncodedHash::Json(previous_blockhash.to_string())
} else {
RpcEncodedHash::Binary(previous_blockhash)
};

let blockhash = get_last_hash(slot_entries.iter())
.unwrap_or_else(|| panic!("Rooted slot {:?} must have blockhash", slot));
let blockhash = if encoding == RpcTransactionEncoding::Json {
RpcEncodedHash::Json(blockhash.to_string())
} else {
RpcEncodedHash::Binary(blockhash)
};

let block = RpcConfirmedBlock {
previous_blockhash,
blockhash,
previous_blockhash: previous_blockhash.to_string(),
blockhash: blockhash.to_string(),
parent_slot: slot_meta.parent_slot,
transactions: self.map_transactions_to_statuses(
slot,
Expand Down

0 comments on commit 265803d

Please sign in to comment.