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

Respect rewards parameter in getBlock transaction-level rewards #27655

Merged
merged 2 commits into from
Sep 8, 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
14 changes: 12 additions & 2 deletions docs/src/developing/clients/jsonrpc-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,12 @@ The result field will be an object with the following fields:
- `preTokenBalances: <array|undefined>` - List of [token balances](#token-balances-structure) from before the transaction was processed or omitted if token balance recording was not yet enabled during this transaction
- `postTokenBalances: <array|undefined>` - List of [token balances](#token-balances-structure) from after the transaction was processed or omitted if token balance recording was not yet enabled during this transaction
- `logMessages: <array|null>` - array of string log messages or `null` if log message recording was not enabled during this transaction
- `rewards: <array|null>` - transaction-level rewards, populated if rewards are requested; an array of JSON objects containing:
- `pubkey: <string>` - The public key, as base-58 encoded string, of the account that received the reward
- `lamports: <i64>`- number of reward lamports credited or debited by the account, as a i64
- `postBalance: <u64>` - account balance in lamports after the reward was applied
- `rewardType: <string|undefined>` - type of reward: "fee", "rent", "voting", "staking"
- `commission: <u8|undefined>` - vote account commission when the reward was credited, only present for voting and staking rewards
- DEPRECATED: `status: <object>` - Transaction status
- `"Ok": <null>` - Transaction was successful
- `"Err": <ERR>` - Transaction failed with TransactionError
Expand All @@ -445,7 +451,7 @@ The result field will be an object with the following fields:
- `readonly: <array[string]>` - Ordered list of base-58 encoded addresses for readonly loaded accounts
- `version: <"legacy"|number|undefined>` - Transaction version. Undefined if `maxSupportedTransactionVersion` is not set in request params.
- `signatures: <array>` - present if "signatures" are requested for transaction details; an array of signatures strings, corresponding to the transaction order in the block
- `rewards: <array>` - present if rewards are requested; an array of JSON objects containing:
- `rewards: <array|undefined>` - block-level rewards, present if rewards are requested; an array of JSON objects containing:
- `pubkey: <string>` - The public key, as base-58 encoded string, of the account that received the reward
- `lamports: <i64>`- number of reward lamports credited or debited by the account, as a i64
- `postBalance: <u64>` - account balance in lamports after the reward was applied
Expand Down Expand Up @@ -486,6 +492,7 @@ Result:
"postTokenBalances": [],
"preBalances": [499998937500, 26858640, 1, 1, 1],
"preTokenBalances": [],
"rewards": null,
"status": {
"Ok": null
}
Expand Down Expand Up @@ -557,6 +564,7 @@ Result:
"postTokenBalances": [],
"preBalances": [499998937500, 26858640, 1, 1, 1],
"preTokenBalances": [],
"rewards": [],
"status": {
"Ok": null
}
Expand Down Expand Up @@ -3036,7 +3044,7 @@ Returns transaction details for a confirmed transaction
- DEPRECATED: `status: <object>` - Transaction status
- `"Ok": <null>` - Transaction was successful
- `"Err": <ERR>` - Transaction failed with TransactionError
- `rewards: <array>` - present if rewards are requested; an array of JSON objects containing:
- `rewards: <array|null>` - transaction-level rewards, populated if rewards are requested; an array of JSON objects containing:
- `pubkey: <string>` - The public key, as base-58 encoded string, of the account that received the reward
- `lamports: <i64>`- number of reward lamports credited or debited by the account, as a i64
- `postBalance: <u64>` - account balance in lamports after the reward was applied
Expand Down Expand Up @@ -3079,6 +3087,7 @@ Result:
"postTokenBalances": [],
"preBalances": [499998937500, 26858640, 1, 1, 1],
"preTokenBalances": [],
"rewards": [],
"status": {
"Ok": null
}
Expand Down Expand Up @@ -3149,6 +3158,7 @@ Result:
"postTokenBalances": [],
"preBalances": [499998937500, 26858640, 1, 1, 1],
"preTokenBalances": [],
"rewards": null,
"status": {
"Ok": null
}
Expand Down
2 changes: 1 addition & 1 deletion ledger-tool/src/bigtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ async fn confirm(
let decoded_tx = confirmed_tx.get_transaction();
let encoded_tx_with_meta = confirmed_tx
.tx_with_meta
.encode(UiTransactionEncoding::Json, Some(0))
.encode(UiTransactionEncoding::Json, Some(0), true)
.map_err(|_| "Failed to encode transaction in block".to_string())?;
transaction = Some(CliTransaction {
transaction: encoded_tx_with_meta.transaction,
Expand Down
31 changes: 23 additions & 8 deletions transaction-status/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ impl From<&LoadedAddresses> for UiLoadedAddresses {
}

impl UiTransactionStatusMeta {
fn parse(meta: TransactionStatusMeta, static_keys: &[Pubkey]) -> Self {
fn parse(meta: TransactionStatusMeta, static_keys: &[Pubkey], show_rewards: bool) -> Self {
let account_keys = AccountKeys::new(static_keys, Some(&meta.loaded_addresses));
Self {
err: meta.status.clone().err(),
Expand All @@ -378,7 +378,7 @@ impl UiTransactionStatusMeta {
post_token_balances: meta
.post_token_balances
.map(|balance| balance.into_iter().map(Into::into).collect()),
rewards: meta.rewards,
rewards: if show_rewards { meta.rewards } else { None },
loaded_addresses: None,
return_data: meta.return_data,
compute_units_consumed: meta.compute_units_consumed,
Expand Down Expand Up @@ -540,7 +540,11 @@ impl ConfirmedBlock {
self.transactions
.into_iter()
.map(|tx_with_meta| {
tx_with_meta.encode(encoding, options.max_supported_transaction_version)
tx_with_meta.encode(
encoding,
options.max_supported_transaction_version,
options.show_rewards,
)
})
.collect::<Result<Vec<_>, _>>()?,
),
Expand Down Expand Up @@ -659,6 +663,7 @@ impl TransactionWithStatusMeta {
self,
encoding: UiTransactionEncoding,
max_supported_transaction_version: Option<u8>,
show_rewards: bool,
) -> Result<EncodedTransactionWithStatusMeta, EncodeError> {
match self {
Self::MissingMetadata(ref transaction) => Ok(EncodedTransactionWithStatusMeta {
Expand All @@ -667,7 +672,7 @@ impl TransactionWithStatusMeta {
meta: None,
}),
Self::Complete(tx_with_meta) => {
tx_with_meta.encode(encoding, max_supported_transaction_version)
tx_with_meta.encode(encoding, max_supported_transaction_version, show_rewards)
}
}
}
Expand All @@ -685,6 +690,7 @@ impl VersionedTransactionWithStatusMeta {
self,
encoding: UiTransactionEncoding,
max_supported_transaction_version: Option<u8>,
show_rewards: bool,
) -> Result<EncodedTransactionWithStatusMeta, EncodeError> {
let version = match (
max_supported_transaction_version,
Expand All @@ -711,8 +717,15 @@ impl VersionedTransactionWithStatusMeta {
UiTransactionEncoding::JsonParsed => UiTransactionStatusMeta::parse(
self.meta,
self.transaction.message.static_account_keys(),
show_rewards,
),
_ => UiTransactionStatusMeta::from(self.meta),
_ => {
let mut meta = UiTransactionStatusMeta::from(self.meta);
if !show_rewards {
meta.rewards = None;
}
meta
}
}),
version,
})
Expand Down Expand Up @@ -757,9 +770,11 @@ impl ConfirmedTransactionWithStatusMeta {
) -> Result<EncodedConfirmedTransactionWithStatusMeta, EncodeError> {
Ok(EncodedConfirmedTransactionWithStatusMeta {
slot: self.slot,
transaction: self
.tx_with_meta
.encode(encoding, max_supported_transaction_version)?,
transaction: self.tx_with_meta.encode(
encoding,
max_supported_transaction_version,
true,
)?,
block_time: self.block_time,
})
}
Expand Down