Skip to content

Commit

Permalink
Merge pull request #1914 from dusk-network/mocello/deposit
Browse files Browse the repository at this point in the history
Remove `deposit` boolean from the `Payload` struct
  • Loading branch information
moCello authored Jul 3, 2024
2 parents 4d1f725 + d819930 commit 1322166
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 43 deletions.
4 changes: 0 additions & 4 deletions contracts/stake/tests/common/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,6 @@ pub fn create_transaction<const I: usize>(
let tx_payload = Payload {
tx_skeleton,
fee,
deposit: match deposit {
0 => false,
_ => true,
},
contract_call,
};

Expand Down
4 changes: 2 additions & 2 deletions contracts/transfer/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ impl TransferState {
self.tree
.extend_notes(block_height, tx_skeleton.outputs.clone());

// place the contract deposit on the state
if tx.payload().deposit {
// if present, place the contract deposit on the state
if tx.payload().tx_skeleton().deposit > 0 {
let contract = match tx.payload().contract_call() {
Some(call) => ContractId::from_bytes(call.contract),
None => {
Expand Down
4 changes: 0 additions & 4 deletions contracts/transfer/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,6 @@ pub fn create_transaction<const I: usize>(
let tx_payload = Payload {
tx_skeleton,
fee,
deposit: match deposit {
0 => false,
_ => true,
},
contract_call,
};

Expand Down
25 changes: 0 additions & 25 deletions execution-core/src/transfer/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ pub struct Payload {
pub tx_skeleton: TxSkeleton,
/// Data used to calculate the transaction fee.
pub fee: Fee,
/// `true` if the transaction is a contract deposit.
pub deposit: bool,
/// Data to do a contract call.
pub contract_call: Option<ContractCall>,
}
Expand All @@ -47,13 +45,11 @@ impl Payload {
pub fn new(
tx_skeleton: TxSkeleton,
fee: Fee,
deposit: bool,
contract_call: Option<ContractCall>,
) -> Self {
Self {
tx_skeleton,
fee,
deposit,
contract_call,
}
}
Expand All @@ -70,12 +66,6 @@ impl Payload {
&self.fee
}

/// Return true if the transaction is a deposit of funds into a contract.
#[must_use]
pub fn deposit(&self) -> bool {
self.deposit
}

/// Return the contract-call data.
#[must_use]
pub fn contract_call(&self) -> &Option<ContractCall> {
Expand All @@ -95,9 +85,6 @@ impl Payload {
// serialize the fee
bytes.extend(self.fee.to_bytes());

// serialize the deposit
bytes.push(u8::from(self.deposit));

// serialize the contract-call
match self.contract_call {
Some(ref call) => {
Expand Down Expand Up @@ -129,15 +116,6 @@ impl Payload {
// deserialize fee
let fee = Fee::from_reader(&mut buf)?;

// deserialize deposit data
let deposit = match u8::from_reader(&mut buf)? {
0 => false,
1 => true,
_ => {
return Err(BytesError::InvalidData);
}
};

// deserialize contract-call data
let contract_call = match u8::from_reader(&mut buf)? {
0 => None,
Expand All @@ -150,7 +128,6 @@ impl Payload {
Ok(Self {
tx_skeleton,
fee,
deposit,
contract_call,
})
}
Expand All @@ -163,8 +140,6 @@ impl Payload {
pub fn to_hash_input_bytes(&self) -> Vec<u8> {
let mut bytes = self.tx_skeleton.to_hash_input_bytes();

bytes.push(u8::from(self.deposit));

if let Some(call) = &self.contract_call {
bytes.extend(call.contract);
bytes.extend(call.fn_name.as_bytes());
Expand Down
2 changes: 1 addition & 1 deletion execution-core/tests/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn transaction_from_to_bytes() -> Result<(), Error> {
};

// build the payload
let payload = Payload::new(tx_skeleton, fee, true, Some(call));
let payload = Payload::new(tx_skeleton, fee, Some(call));

// set a random proof
let proof = [42; 42].to_vec();
Expand Down
3 changes: 1 addition & 2 deletions node-data/src/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,7 @@ pub mod faker {
let contract_call =
ContractCall::new([21; 32], "some_method", &()).unwrap();

let payload =
Payload::new(tx_skeleton, fee, false, Some(contract_call));
let payload = Payload::new(tx_skeleton, fee, Some(contract_call));
let proof = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];

PhoenixTransaction::new(payload, proof).into()
Expand Down
2 changes: 0 additions & 2 deletions rusk-prover/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@ mod tests {
};

let fee = Fee::new(&mut rng, &sender_pk, 4242, 42);
let has_deposit = true;
let call = ContractCall::new(
[10; 32],
"some method",
Expand All @@ -397,7 +396,6 @@ mod tests {
let payload = Payload {
tx_skeleton,
fee,
deposit: has_deposit,
contract_call: Some(call),
};

Expand Down
2 changes: 1 addition & 1 deletion rusk-prover/tests/utx.hex

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions test-wallet/src/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,9 +762,8 @@ fn new_unproven_tx<Rng: RngCore + CryptoRng, SC: StateClient>(
max_fee: fee.max_fee(),
deposit,
};
let has_deposit = deposit > 0;

let payload = Payload::new(tx_skeleton, fee, has_deposit, call);
let payload = Payload::new(tx_skeleton, fee, call);
let payload_hash = payload.hash();

let inputs: Vec<UnprovenTransactionInput> = inputs
Expand Down

0 comments on commit 1322166

Please sign in to comment.