Skip to content

Commit

Permalink
Respect rewards parameter in getBlock transaction-level rewards (#27655)
Browse files Browse the repository at this point in the history
* Respect options.show_rewards in UiTransactionStatusMeta

* Fixup docs

(cherry picked from commit 5428495)
  • Loading branch information
Tyera Eulberg authored and mergify[bot] committed Sep 8, 2022
1 parent b44fe59 commit 63b8dfa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
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 @@ -436,6 +436,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 @@ -444,7 +450,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 @@ -485,6 +491,7 @@ Result:
"postTokenBalances": [],
"preBalances": [499998937500, 26858640, 1, 1, 1],
"preTokenBalances": [],
"rewards": null,
"status": {
"Ok": null
}
Expand Down Expand Up @@ -556,6 +563,7 @@ Result:
"postTokenBalances": [],
"preBalances": [499998937500, 26858640, 1, 1, 1],
"preTokenBalances": [],
"rewards": [],
"status": {
"Ok": null
}
Expand Down Expand Up @@ -2976,7 +2984,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 @@ -3019,6 +3027,7 @@ Result:
"postTokenBalances": [],
"preBalances": [499998937500, 26858640, 1, 1, 1],
"preTokenBalances": [],
"rewards": [],
"status": {
"Ok": null
}
Expand Down Expand Up @@ -3089,6 +3098,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 @@ -357,7 +357,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 @@ -377,7 +377,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 @@ -539,7 +539,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 @@ -658,6 +662,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 @@ -666,7 +671,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 @@ -684,6 +689,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 @@ -710,8 +716,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 @@ -756,9 +769,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

0 comments on commit 63b8dfa

Please sign in to comment.