-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rpc: rework binary encoding. BREAKING CHANGE #11646
Changes from all commits
0bfa237
fb79087
4130cd8
430e326
0f196c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,12 +15,7 @@ use bincode::serialize; | |
use indicatif::{ProgressBar, ProgressStyle}; | ||
use log::*; | ||
use serde_json::{json, Value}; | ||
use solana_account_decoder::{ | ||
parse_token::UiTokenAmount, | ||
UiAccount, | ||
UiAccountData::{Binary, Binary64}, | ||
UiAccountEncoding, | ||
}; | ||
use solana_account_decoder::{parse_token::UiTokenAmount, UiAccount, UiAccountEncoding}; | ||
use solana_sdk::{ | ||
account::Account, | ||
clock::{ | ||
|
@@ -469,7 +464,7 @@ impl RpcClient { | |
commitment_config: CommitmentConfig, | ||
) -> RpcResult<Option<Account>> { | ||
let config = RpcAccountInfoConfig { | ||
encoding: Some(UiAccountEncoding::Binary64), | ||
encoding: Some(UiAccountEncoding::Base64), | ||
commitment: Some(commitment_config), | ||
data_slice: None, | ||
}; | ||
|
@@ -487,17 +482,8 @@ impl RpcClient { | |
} | ||
let Response { | ||
context, | ||
value: mut rpc_account, | ||
value: rpc_account, | ||
} = serde_json::from_value::<Response<Option<UiAccount>>>(result_json)?; | ||
if let Some(ref mut account) = rpc_account { | ||
if let Binary(_) = &account.data { | ||
let tmp = Binary64(String::new()); | ||
match std::mem::replace(&mut account.data, tmp) { | ||
Binary(new_data) => account.data = Binary64(new_data), | ||
_ => panic!("should have gotten binary here."), | ||
} | ||
} | ||
} | ||
Comment on lines
-492
to
-500
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem with |
||
trace!("Response account {:?} {:?}", pubkey, rpc_account); | ||
let account = rpc_account.and_then(|rpc_account| rpc_account.decode()); | ||
Ok(Response { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -244,8 +244,11 @@ impl JsonRpcRequestProcessor { | |
if let Some(account) = bank.get_account(pubkey) { | ||
if account.owner == spl_token_id_v1_0() && encoding == UiAccountEncoding::JsonParsed { | ||
response = Some(get_parsed_token_account(bank.clone(), pubkey, account)); | ||
} else if encoding == UiAccountEncoding::Binary && account.data.len() > 128 { | ||
let message = "Encoded binary (base 58) data should be less than 128 bytes, please use Binary64 encoding.".to_string(); | ||
} else if (encoding == UiAccountEncoding::Binary | ||
|| encoding == UiAccountEncoding::Base58) | ||
&& account.data.len() > 128 | ||
{ | ||
let message = "Encoded binary (base 58) data should be less than 128 bytes, please use Base64 encoding.".to_string(); | ||
return Err(error::Error { | ||
code: error::ErrorCode::InvalidRequest, | ||
message, | ||
|
@@ -1266,7 +1269,7 @@ fn check_slice_and_encoding(encoding: &UiAccountEncoding, data_slice_is_some: bo | |
UiAccountEncoding::JsonParsed => { | ||
if data_slice_is_some { | ||
let message = | ||
"Sliced account data can only be encoded using binary (base 58) or binary64 encoding." | ||
"Sliced account data can only be encoded using binary (base 58) or base64 encoding." | ||
.to_string(); | ||
Err(error::Error { | ||
code: error::ErrorCode::InvalidRequest, | ||
|
@@ -1277,7 +1280,7 @@ fn check_slice_and_encoding(encoding: &UiAccountEncoding, data_slice_is_some: bo | |
Ok(()) | ||
} | ||
} | ||
UiAccountEncoding::Binary | UiAccountEncoding::Binary64 => Ok(()), | ||
UiAccountEncoding::Binary | UiAccountEncoding::Base58 | UiAccountEncoding::Base64 => Ok(()), | ||
} | ||
} | ||
|
||
|
@@ -3097,13 +3100,13 @@ pub mod tests { | |
"result": { | ||
"context":{"slot":0}, | ||
"value":{ | ||
"owner": "11111111111111111111111111111111", | ||
"lamports": 20, | ||
"data": "", | ||
"executable": false, | ||
"rentEpoch": 0 | ||
}, | ||
"owner": "11111111111111111111111111111111", | ||
"lamports": 20, | ||
"data": "", | ||
"executable": false, | ||
"rentEpoch": 0 | ||
}, | ||
}, | ||
"id": 1, | ||
}); | ||
let expected: Response = | ||
|
@@ -3119,24 +3122,27 @@ pub mod tests { | |
bank.store_account(&address, &account); | ||
|
||
let req = format!( | ||
r#"{{"jsonrpc":"2.0","id":1,"method":"getAccountInfo","params":["{}", {{"encoding":"binary64"}}]}}"#, | ||
r#"{{"jsonrpc":"2.0","id":1,"method":"getAccountInfo","params":["{}", {{"encoding":"base64"}}]}}"#, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, this feels so much nicer. "binary64"? What's that! "base64"? Oh, that's base64. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes yes yes!! 🙌 |
||
address | ||
); | ||
let res = io.handle_request_sync(&req, meta.clone()); | ||
let result: Value = serde_json::from_str(&res.expect("actual response")) | ||
.expect("actual response deserialization"); | ||
assert_eq!(result["result"]["value"]["data"], base64::encode(&data)); | ||
assert_eq!( | ||
result["result"]["value"]["data"], | ||
json!([base64::encode(&data), "base64"]), | ||
); | ||
|
||
let req = format!( | ||
r#"{{"jsonrpc":"2.0","id":1,"method":"getAccountInfo","params":["{}", {{"encoding":"binary64", "dataSlice": {{"length": 2, "offset": 1}}}}]}}"#, | ||
r#"{{"jsonrpc":"2.0","id":1,"method":"getAccountInfo","params":["{}", {{"encoding":"base64", "dataSlice": {{"length": 2, "offset": 1}}}}]}}"#, | ||
address | ||
); | ||
let res = io.handle_request_sync(&req, meta.clone()); | ||
let result: Value = serde_json::from_str(&res.expect("actual response")) | ||
.expect("actual response deserialization"); | ||
assert_eq!( | ||
result["result"]["value"]["data"], | ||
base64::encode(&data[1..3]), | ||
json!([base64::encode(&data[1..3]), "base64"]), | ||
); | ||
|
||
let req = format!( | ||
|
@@ -4315,7 +4321,7 @@ pub mod tests { | |
for TransactionWithStatusMeta { transaction, meta } in | ||
confirmed_block.transactions.into_iter() | ||
{ | ||
if let EncodedTransaction::Binary(transaction) = transaction { | ||
if let EncodedTransaction::LegacyBinary(transaction) = transaction { | ||
let decoded_transaction: Transaction = | ||
deserialize(&bs58::decode(&transaction).into_vec().unwrap()).unwrap(); | ||
if decoded_transaction.signatures[0] == confirmed_block_signatures[0] { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One day we can remove "binary" when it starts getting in the way. It's no longer documented