transaction-status: Add return data to meta (#23688)
* transaction-status: Add return data to meta * Add return data to simulation results * Use pretty-hex for printing return data * Update arg name, make TransactionRecord struct * Rename TransactionRecord -> ExecutionRecord
This commit is contained in:
@@ -57,6 +57,8 @@ message TransactionStatusMeta {
|
||||
repeated Reward rewards = 9;
|
||||
repeated bytes loaded_writable_addresses = 12;
|
||||
repeated bytes loaded_readonly_addresses = 13;
|
||||
ReturnData return_data = 14;
|
||||
bool return_data_none = 15;
|
||||
}
|
||||
|
||||
message TransactionError {
|
||||
@@ -88,6 +90,11 @@ message UiTokenAmount {
|
||||
string ui_amount_string = 4;
|
||||
}
|
||||
|
||||
message ReturnData {
|
||||
bytes program_id = 1;
|
||||
bytes data = 2;
|
||||
}
|
||||
|
||||
enum RewardType {
|
||||
Unspecified = 0;
|
||||
Fee = 1;
|
||||
|
@@ -12,6 +12,7 @@ use {
|
||||
pubkey::Pubkey,
|
||||
signature::Signature,
|
||||
transaction::{Transaction, TransactionError, VersionedTransaction},
|
||||
transaction_context::TransactionReturnData,
|
||||
},
|
||||
solana_transaction_status::{
|
||||
ConfirmedBlock, InnerInstructions, Reward, RewardType, TransactionByAddrInfo,
|
||||
@@ -363,6 +364,7 @@ impl From<TransactionStatusMeta> for generated::TransactionStatusMeta {
|
||||
post_token_balances,
|
||||
rewards,
|
||||
loaded_addresses,
|
||||
return_data,
|
||||
} = value;
|
||||
let err = match status {
|
||||
Ok(()) => None,
|
||||
@@ -403,6 +405,8 @@ impl From<TransactionStatusMeta> for generated::TransactionStatusMeta {
|
||||
.into_iter()
|
||||
.map(|key| <Pubkey as AsRef<[u8]>>::as_ref(&key).into())
|
||||
.collect();
|
||||
let return_data_none = return_data.is_none();
|
||||
let return_data = return_data.map(|return_data| return_data.into());
|
||||
|
||||
Self {
|
||||
err,
|
||||
@@ -418,6 +422,8 @@ impl From<TransactionStatusMeta> for generated::TransactionStatusMeta {
|
||||
rewards,
|
||||
loaded_writable_addresses,
|
||||
loaded_readonly_addresses,
|
||||
return_data,
|
||||
return_data_none,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -447,6 +453,8 @@ impl TryFrom<generated::TransactionStatusMeta> for TransactionStatusMeta {
|
||||
rewards,
|
||||
loaded_writable_addresses,
|
||||
loaded_readonly_addresses,
|
||||
return_data,
|
||||
return_data_none,
|
||||
} = value;
|
||||
let status = match &err {
|
||||
None => Ok(()),
|
||||
@@ -490,6 +498,11 @@ impl TryFrom<generated::TransactionStatusMeta> for TransactionStatusMeta {
|
||||
.map(|key| Pubkey::new(&key))
|
||||
.collect(),
|
||||
};
|
||||
let return_data = if return_data_none {
|
||||
None
|
||||
} else {
|
||||
return_data.map(|return_data| return_data.into())
|
||||
};
|
||||
Ok(Self {
|
||||
status,
|
||||
fee,
|
||||
@@ -501,6 +514,7 @@ impl TryFrom<generated::TransactionStatusMeta> for TransactionStatusMeta {
|
||||
post_token_balances,
|
||||
rewards,
|
||||
loaded_addresses,
|
||||
return_data,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -587,6 +601,24 @@ impl From<generated::MessageAddressTableLookup> for MessageAddressTableLookup {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TransactionReturnData> for generated::ReturnData {
|
||||
fn from(value: TransactionReturnData) -> Self {
|
||||
Self {
|
||||
program_id: <Pubkey as AsRef<[u8]>>::as_ref(&value.program_id).into(),
|
||||
data: value.data,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<generated::ReturnData> for TransactionReturnData {
|
||||
fn from(value: generated::ReturnData) -> Self {
|
||||
Self {
|
||||
program_id: Pubkey::new(&value.program_id),
|
||||
data: value.data,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CompiledInstruction> for generated::CompiledInstruction {
|
||||
fn from(value: CompiledInstruction) -> Self {
|
||||
Self {
|
||||
|
@@ -6,6 +6,7 @@ use {
|
||||
},
|
||||
solana_sdk::{
|
||||
deserialize_utils::default_on_eof, message::v0::LoadedAddresses, transaction::Result,
|
||||
transaction_context::TransactionReturnData,
|
||||
},
|
||||
solana_transaction_status::{
|
||||
InnerInstructions, Reward, RewardType, TransactionStatusMeta, TransactionTokenBalance,
|
||||
@@ -167,6 +168,8 @@ pub struct StoredTransactionStatusMeta {
|
||||
pub post_token_balances: Option<Vec<StoredTransactionTokenBalance>>,
|
||||
#[serde(deserialize_with = "default_on_eof")]
|
||||
pub rewards: Option<Vec<StoredExtendedReward>>,
|
||||
#[serde(deserialize_with = "default_on_eof")]
|
||||
pub return_data: Option<TransactionReturnData>,
|
||||
}
|
||||
|
||||
impl From<StoredTransactionStatusMeta> for TransactionStatusMeta {
|
||||
@@ -181,6 +184,7 @@ impl From<StoredTransactionStatusMeta> for TransactionStatusMeta {
|
||||
pre_token_balances,
|
||||
post_token_balances,
|
||||
rewards,
|
||||
return_data,
|
||||
} = value;
|
||||
Self {
|
||||
status,
|
||||
@@ -196,6 +200,7 @@ impl From<StoredTransactionStatusMeta> for TransactionStatusMeta {
|
||||
rewards: rewards
|
||||
.map(|rewards| rewards.into_iter().map(|reward| reward.into()).collect()),
|
||||
loaded_addresses: LoadedAddresses::default(),
|
||||
return_data,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -214,6 +219,7 @@ impl TryFrom<TransactionStatusMeta> for StoredTransactionStatusMeta {
|
||||
post_token_balances,
|
||||
rewards,
|
||||
loaded_addresses,
|
||||
return_data,
|
||||
} = value;
|
||||
|
||||
if !loaded_addresses.is_empty() {
|
||||
@@ -237,6 +243,7 @@ impl TryFrom<TransactionStatusMeta> for StoredTransactionStatusMeta {
|
||||
.map(|balances| balances.into_iter().map(|balance| balance.into()).collect()),
|
||||
rewards: rewards
|
||||
.map(|rewards| rewards.into_iter().map(|reward| reward.into()).collect()),
|
||||
return_data,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user