Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

RPC: Return the data length for get account requests #28421

Merged
merged 1 commit into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions account-decoder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub struct UiAccount {
pub owner: String,
pub executable: bool,
pub rent_epoch: Epoch,
pub space: Option<u64>,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
Expand Down Expand Up @@ -83,6 +84,7 @@ impl UiAccount {
additional_data: Option<AccountAdditionalData>,
data_slice_config: Option<UiDataSliceConfig>,
) -> Self {
let space = account.data().len();
let data = match encoding {
UiAccountEncoding::Binary => {
let data = Self::encode_bs58(account, data_slice_config);
Expand Down Expand Up @@ -125,6 +127,7 @@ impl UiAccount {
owner: account.owner().to_string(),
executable: account.executable(),
rent_epoch: account.rent_epoch(),
space: Some(space as u64),
}
}

Expand Down
1 change: 1 addition & 0 deletions client-test/tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ fn test_account_subscription() {
"data": "",
"executable": false,
"rentEpoch": 0,
"space": 0,
},
});

Expand Down
59 changes: 35 additions & 24 deletions docs/src/developing/clients/jsonrpc-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ Response:
"executable": false,
"lamports": 1000000000,
"owner": "11111111111111111111111111111111",
"rentEpoch": 2
"rentEpoch": 2,
"space": 80
}
},
"id": 1
Expand Down Expand Up @@ -360,7 +361,8 @@ Response:
"executable": false,
"lamports": 1000000000,
"owner": "11111111111111111111111111111111",
"rentEpoch": 2
"rentEpoch": 2,
"space": 80
}
},
"id": 1
Expand Down Expand Up @@ -1849,18 +1851,20 @@ Result:
},
"value": [
{
"data": ["AAAAAAEAAAACtzNsyJrW0g==", "base64"],
"data": ["", "base64"],
"executable": false,
"lamports": 1000000000,
"owner": "11111111111111111111111111111111",
"rentEpoch": 2
"rentEpoch": 2,
"space": 16
},
{
"data": ["", "base64"],
"executable": false,
"lamports": 5000000000,
"owner": "11111111111111111111111111111111",
"rentEpoch": 2
"rentEpoch": 2,
"space": 0
}
]
},
Expand Down Expand Up @@ -1909,14 +1913,16 @@ Result:
"executable": false,
"lamports": 1000000000,
"owner": "11111111111111111111111111111111",
"rentEpoch": 2
"rentEpoch": 2,
"space": 80
},
{
"data": ["", "base58"],
"executable": false,
"lamports": 5000000000,
"owner": "11111111111111111111111111111111",
"rentEpoch": 2
"rentEpoch": 2,
"space": 0
}
]
},
Expand Down Expand Up @@ -1990,7 +1996,8 @@ Result:
"executable": false,
"lamports": 15298080,
"owner": "4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T",
"rentEpoch": 28
"rentEpoch": 28,
"space": 16
},
"pubkey": "CxELquR1gPP8wHe33gZ4QxqGB3sZ9RSwsJ2KshVewkFY"
}
Expand Down Expand Up @@ -2041,7 +2048,8 @@ Result:
"executable": false,
"lamports": 15298080,
"owner": "4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T",
"rentEpoch": 28
"rentEpoch": 28,
"space": 42
},
"pubkey": "CxELquR1gPP8wHe33gZ4QxqGB3sZ9RSwsJ2KshVewkFY"
}
Expand Down Expand Up @@ -2151,23 +2159,23 @@ Result:
"result": [
{
"slot": 348125,
"prioritizationFee": 0,
"prioritizationFee": 0
},
{
"slot": 348126,
"prioritizationFee": 1000,
"prioritizationFee": 1000
},
{
"slot": 348127,
"prioritizationFee": 500,
"prioritizationFee": 500
},
{
"slot": 348128,
"prioritizationFee": 0,
"prioritizationFee": 0
},
{
"slot": 348129,
"prioritizationFee": 1234,
"prioritizationFee": 1234
}
],
"id": 1
Expand Down Expand Up @@ -2795,7 +2803,8 @@ Result:
"executable": false,
"lamports": 1726080,
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"rentEpoch": 4
"rentEpoch": 4,
"space": 165
},
"pubkey": "28YTZEwqtMHWrhWcvv34se7pjS7wctgqzCPB3gReCFKp"
}
Expand Down Expand Up @@ -2902,7 +2911,8 @@ Result:
"executable": false,
"lamports": 1726080,
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"rentEpoch": 4
"rentEpoch": 4,
"space": 165
},
"pubkey": "C2gJg6tKpQs41PRS1nC8aw3ZKNZK3HQQZGVrDFDup5nx"
}
Expand Down Expand Up @@ -3620,10 +3630,7 @@ Result:
"Program 83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri success"
],
"returnData": {
"data": [
"Kg==",
"base64"
],
"data": ["Kg==", "base64"],
"programId": "83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri"
},
"unitsConsumed": 2366
Expand Down Expand Up @@ -3716,7 +3723,8 @@ Base58 encoding:
"executable": false,
"lamports": 33594,
"owner": "11111111111111111111111111111111",
"rentEpoch": 635
"rentEpoch": 635,
"space": 80
}
},
"subscription": 23784
Expand Down Expand Up @@ -3752,7 +3760,8 @@ Parsed-JSON encoding:
"executable": false,
"lamports": 33594,
"owner": "11111111111111111111111111111111",
"rentEpoch": 635
"rentEpoch": 635,
"space": 80
}
},
"subscription": 23784
Expand Down Expand Up @@ -4280,7 +4289,8 @@ Base58 encoding:
"executable": false,
"lamports": 33594,
"owner": "11111111111111111111111111111111",
"rentEpoch": 636
"rentEpoch": 636,
"space": 80
}
}
},
Expand Down Expand Up @@ -4319,7 +4329,8 @@ Parsed-JSON encoding:
"executable": false,
"lamports": 33594,
"owner": "11111111111111111111111111111111",
"rentEpoch": 636
"rentEpoch": 636,
"space": 80
}
}
},
Expand Down
21 changes: 15 additions & 6 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5484,7 +5484,8 @@ pub mod tests {
"lamports": TEST_MINT_LAMPORTS,
"data": "",
"executable": false,
"rentEpoch": 0
"rentEpoch": 0,
"space": 0,
},
});
assert_eq!(result, expected);
Expand All @@ -5502,6 +5503,7 @@ pub mod tests {
let result: Value = parse_success_result(rpc.handle_request_sync(request));
let expected = json!([base64::encode(&data), "base64"]);
assert_eq!(result["value"]["data"], expected);
assert_eq!(result["value"]["space"], 5);

let request = create_test_request(
"getAccountInfo",
Expand All @@ -5510,6 +5512,7 @@ pub mod tests {
let result: Value = parse_success_result(rpc.handle_request_sync(request));
let expected = json!([base64::encode(&data[1..3]), "base64"]);
assert_eq!(result["value"]["data"], expected);
assert_eq!(result["value"]["space"], 5);

let request = create_test_request(
"getAccountInfo",
Expand All @@ -5518,6 +5521,7 @@ pub mod tests {
let result: Value = parse_success_result(rpc.handle_request_sync(request));
let expected = bs58::encode(&data[1..3]).into_string();
assert_eq!(result["value"]["data"], expected);
assert_eq!(result["value"]["space"], 5);

let request = create_test_request(
"getAccountInfo",
Expand Down Expand Up @@ -5561,15 +5565,17 @@ pub mod tests {
"lamports": TEST_MINT_LAMPORTS,
"data": ["", "base64"],
"executable": false,
"rentEpoch": 0
"rentEpoch": 0,
"space": 0,
},
null,
{
"owner": "11111111111111111111111111111111",
"lamports": 42,
"data": [base64::encode(&data), "base64"],
"executable": false,
"rentEpoch": 0
"rentEpoch": 0,
"space": 5,
}
]);
assert_eq!(result.value, expected);
Expand All @@ -5593,15 +5599,17 @@ pub mod tests {
"lamports": TEST_MINT_LAMPORTS,
"data": ["", "base58"],
"executable": false,
"rentEpoch": 0
"rentEpoch": 0,
"space": 0,
},
null,
{
"owner": "11111111111111111111111111111111",
"lamports": 42,
"data": [bs58::encode(&data).into_string(), "base58"],
"executable": false,
"rentEpoch": 0
"rentEpoch": 0,
"space": 5,
}
]);
assert_eq!(result.value, expected);
Expand Down Expand Up @@ -5838,7 +5846,8 @@ pub mod tests {
"executable": false,
"owner": "11111111111111111111111111111111",
"lamports": rent_exempt_amount,
"rentEpoch": 0
"rentEpoch": 0,
"space": 0,
}
],
"err":null,
Expand Down
3 changes: 3 additions & 0 deletions rpc/src/rpc_pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,7 @@ mod tests {
"data": [base64::encode(expected_data), encoding],
"executable": false,
"rentEpoch": 0,
"space": expected_data.len(),
},
},
"subscription": 0,
Expand Down Expand Up @@ -1059,6 +1060,7 @@ mod tests {
"data": expected_data,
"executable": false,
"rentEpoch": 0,
"space": account.data().len(),
},
},
"subscription": 0,
Expand Down Expand Up @@ -1239,6 +1241,7 @@ mod tests {
"data": "",
"executable": false,
"rentEpoch": 0,
"space": 0,
},
},
"subscription": 0,
Expand Down
Loading