Skip to content
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

Hide the versioned struct fields from the public API #4248

Closed
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
20 changes: 10 additions & 10 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ impl Client {
transaction: &SignedTransaction,
) -> Result<HashOf<TransactionPayload>> {
let (init_sender, init_receiver) = tokio::sync::oneshot::channel();
let hash = transaction.payload().hash();
let hash = transaction.transaction().payload.hash();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let hash = transaction.transaction().payload.hash();
let hash = transaction.hash();

should be like this


thread::scope(|spawner| {
let submitter_handle = spawner.spawn(move || -> Result<()> {
Expand Down Expand Up @@ -693,7 +693,7 @@ impl Client {
)
.headers(self.headers.clone())
.body(transaction_bytes),
transaction.payload().hash(),
transaction.transaction().payload.hash(),
)
}

Expand Down Expand Up @@ -1642,8 +1642,8 @@ mod tests {
add_transaction_nonce: Some(true),
..ConfigurationProxy::default()
}
.build()
.expect("Client config should build as all required fields were provided");
.build()
.expect("Client config should build as all required fields were provided");
let client = Client::new(&cfg).expect("Invalid client configuration");

let build_transaction = || {
Expand All @@ -1653,16 +1653,16 @@ mod tests {
};
let tx1 = build_transaction();
let tx2 = build_transaction();
assert_ne!(tx1.payload().hash(), tx2.payload().hash());
assert_ne!(tx1.transaction().payload.hash(), tx2.transaction().payload.hash());

let tx2 = {
let mut tx =
TransactionBuilder::new(client.chain_id.clone(), client.account_id.clone())
.with_executable(tx1.payload().instructions.clone())
.with_metadata(tx1.payload().metadata.clone());
.with_executable(tx1.transaction().payload.instructions.clone())
.with_metadata(tx1.transaction().payload.metadata.clone());

tx.set_creation_time(tx1.payload().creation_time_ms);
if let Some(nonce) = tx1.payload().nonce {
tx.set_creation_time(tx1.transaction().payload.creation_time_ms);
if let Some(nonce) = tx1.transaction().payload.nonce {
tx.set_nonce(nonce);
}
if let Some(transaction_ttl) = client.transaction_ttl {
Expand All @@ -1671,7 +1671,7 @@ mod tests {

client.sign_transaction(tx).unwrap()
};
assert_eq!(tx1.payload().hash(), tx2.payload().hash());
assert_eq!(tx1.transaction().payload.hash(), tx2.transaction().payload.hash());
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion client/tests/integration/events/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn test_with_instruction_and_status_and_port(
// Given
let submitter = client;
let transaction = submitter.build_transaction(instruction, UnlimitedMetadata::new())?;
let hash = transaction.payload().hash();
let hash = transaction.transaction().payload.hash();
let mut handles = Vec::new();
for listener in clients {
let checker = Checker { listener, hash };
Expand Down
5 changes: 3 additions & 2 deletions core/src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,9 +900,10 @@ mod tests {
chain_id.clone(),
AccountId::from_str(alice_id).expect("Valid"),
)
.with_executable(tx.0.payload().instructions.clone());
.with_executable(tx.0.transaction().payload.instructions.clone());

new_tx.set_creation_time(tx.0.payload().creation_time_ms + 2 * future_threshold_ms);
new_tx
.set_creation_time(tx.0.transaction().payload.creation_time_ms + 2 * future_threshold_ms);

let new_tx = new_tx.sign(alice_key).expect("Failed to sign.");
let limits = TransactionLimits {
Expand Down
14 changes: 7 additions & 7 deletions core/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl AcceptedTransaction {
tx: GenesisTransaction,
expected_chain_id: &ChainId,
) -> Result<Self, AcceptTransactionFail> {
let actual_chain_id = &tx.0.payload().chain_id;
let actual_chain_id = &tx.0.transaction().payload.chain_id;

if expected_chain_id != actual_chain_id {
return Err(AcceptTransactionFail::ChainIdMismatch(Mismatch {
Expand All @@ -71,7 +71,7 @@ impl AcceptedTransaction {
expected_chain_id: &ChainId,
limits: &TransactionLimits,
) -> Result<Self, AcceptTransactionFail> {
let actual_chain_id = &tx.payload().chain_id;
let actual_chain_id = &tx.transaction().payload.chain_id;

if expected_chain_id != actual_chain_id {
return Err(AcceptTransactionFail::ChainIdMismatch(Mismatch {
Expand All @@ -80,11 +80,11 @@ impl AcceptedTransaction {
}));
}

if *iroha_genesis::GENESIS_ACCOUNT_ID == tx.payload().authority {
if *iroha_genesis::GENESIS_ACCOUNT_ID == tx.transaction().payload.authority {
return Err(AcceptTransactionFail::UnexpectedGenesisAccountSignature);
}

match &tx.payload().instructions {
match &tx.transaction().payload.instructions {
Executable::Instructions(instructions) => {
let instruction_count = instructions.len();
if Self::len_u64(instruction_count) > limits.max_instruction_number {
Expand Down Expand Up @@ -126,7 +126,7 @@ impl AcceptedTransaction {

/// Payload of the transaction
pub fn payload(&self) -> &TransactionPayload {
self.0.payload()
&self.0.transaction().payload
}

pub(crate) fn signatures(&self) -> &SignaturesOf<TransactionPayload> {
Expand Down Expand Up @@ -193,7 +193,7 @@ impl TransactionExecutor {
tx: AcceptedTransaction,
wsv: &mut WorldStateView,
) -> Result<(), TransactionRejectionReason> {
let authority = &tx.payload().authority;
let authority = &tx.0.transaction().payload.authority;

if !wsv
.domain(&authority.domain_id)
Expand Down Expand Up @@ -259,7 +259,7 @@ impl TransactionExecutor {
wsv: &mut WorldStateView,
) -> Result<(), TransactionRejectionReason> {
let tx: SignedTransaction = tx.into();
let authority = tx.payload().authority.clone();
let authority = tx.transaction().payload.authority.clone();

wsv.executor()
.clone() // Cloning executor is a cheap operation
Expand Down
21 changes: 10 additions & 11 deletions data_model/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ pub mod model {
#[ffi_type]
pub struct SignedTransactionV1 {
/// [`iroha_crypto::SignatureOf`]<[`TransactionPayload`]>.
pub(super) signatures: SignaturesOf<TransactionPayload>,
pub signatures: SignaturesOf<TransactionPayload>,
/// [`Transaction`] payload.
pub(super) payload: TransactionPayload,
pub payload: TransactionPayload,
}

/// Transaction Value used in Instructions and Queries
Expand Down Expand Up @@ -259,17 +259,16 @@ declare_versioned!(SignedTransaction 1..2, Debug, Display, Clone, PartialEq, Eq,
declare_versioned!(SignedTransaction 1..2, Debug, Display, Clone, PartialEq, Eq, PartialOrd, Ord, FromVariant, IntoSchema);

impl SignedTransaction {
/// Return transaction payload
// FIXME: Leaking concrete type TransactionPayload from Versioned container. Payload should be versioned
pub fn payload(&self) -> &TransactionPayload {
/// Define the version of SignedTransaction
/// Created to provide access to the transaction payload only to internal libs
// TODO: Make a correct implementation
pub fn transaction(&self) -> &SignedTransactionV1 {
let SignedTransaction::V1(tx) = self;
&tx.payload
tx
}
Comment on lines +262 to 268
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this function or make it private or guard it with transparent_api macro. Client must not get a handle to SignedTransactionV1


/// Return transaction signatures
pub fn signatures(&self) -> &SignaturesOf<TransactionPayload> {
let SignedTransaction::V1(tx) = self;
&tx.signatures
&self.transaction().signatures
}

/// Calculate transaction [`Hash`](`iroha_crypto::HashOf`).
Expand Down Expand Up @@ -303,7 +302,7 @@ impl SignedTransaction {
#[cfg(feature = "std")]
#[cfg(feature = "transparent_api")]
pub fn merge_signatures(&mut self, other: Self) -> bool {
if self.payload().hash() != other.payload().hash() {
if self.transaction().payload.hash() != other.transaction().payload.hash() {
return false;
}

Expand Down Expand Up @@ -340,7 +339,7 @@ impl TransactionValue {
/// [`Transaction`] payload.
#[inline]
pub fn payload(&self) -> &TransactionPayload {
self.value.payload()
&self.value.transaction().payload
}

/// [`iroha_crypto::SignatureOf`]<[`TransactionPayload`]>.
Expand Down
2 changes: 1 addition & 1 deletion data_model/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pub fn visit_transaction<V: Visit + ?Sized>(
authority: &AccountId,
transaction: &SignedTransaction,
) {
match transaction.payload().instructions() {
match transaction.transaction().payload.instructions() {
Executable::Wasm(wasm) => visitor.visit_wasm(authority, wasm),
Executable::Instructions(instructions) => {
for isi in instructions {
Expand Down
2 changes: 1 addition & 1 deletion smart_contract/executor/src/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn visit_transaction<V: Validate + ?Sized>(
authority: &AccountId,
transaction: &SignedTransaction,
) {
match transaction.payload().instructions() {
match transaction.transaction().payload.instructions() {
Executable::Wasm(wasm) => executor.visit_wasm(authority, wasm),
Executable::Instructions(instructions) => {
for isi in instructions {
Expand Down
4 changes: 2 additions & 2 deletions torii/src/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ pub async fn handle_pending_transactions(
.map(Into::into)
.filter(|current_transaction: &SignedTransaction| {
transaction_payload_eq_excluding_creation_time(
current_transaction.payload(),
transaction.payload(),
&current_transaction.transaction().payload,
&transaction.transaction().payload,
)
})
.collect()
Expand Down
Loading