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

Derive Copy for types based on fixed-len arrays #268

Merged
merged 3 commits into from
Oct 23, 2023
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
2 changes: 1 addition & 1 deletion chain/rust/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@ mod tests {
let script_hash =
ScriptHash::from_raw_bytes(oneof_native_script.hash().to_raw_bytes()).unwrap();

let spend_cred = StakeCredential::new_script(script_hash.clone());
let spend_cred = StakeCredential::new_script(script_hash);
let stake_cred = StakeCredential::new_script(script_hash);
let addr_net_0 = BaseAddress::new(
NetworkInfo::testnet().network_id(),
Expand Down
16 changes: 8 additions & 8 deletions chain/rust/src/assets/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ where
// asset name is missing from left hand side
if !T::min_value().is_zero() {
bundle.set(
policy.clone(),
*policy,
asset_name.clone(),
T::zero().clamped_sub(rhs_amount),
);
Expand All @@ -169,7 +169,7 @@ where
// policy id missing from left hand side
if !T::min_value().is_zero() {
bundle.set(
policy.clone(),
*policy,
asset_name.clone(),
T::zero().clamped_sub(rhs_amount),
);
Expand Down Expand Up @@ -210,7 +210,7 @@ where
let mut bundle = self.0.clone();
for (policy, assets) in rhs.0.iter() {
for (asset_name, amount) in assets.iter() {
match bundle.entry(policy.clone()) {
match bundle.entry(*policy) {
Entry::Occupied(mut assets) => {
match assets.get_mut().entry(asset_name.clone()) {
Entry::Occupied(mut assets2) => {
Expand Down Expand Up @@ -268,7 +268,7 @@ where
},
None => {
// policy id missing from left hand side
return Err(AssetArithmeticError::PolicyIdDoesntExist(policy.clone()));
return Err(AssetArithmeticError::PolicyIdDoesntExist(*policy));
}
}
}
Expand Down Expand Up @@ -296,7 +296,7 @@ impl Mint {
acc
});
if !assets.is_empty() {
acc.insert(policy.clone(), new_assets);
acc.insert(*policy, new_assets);
}
acc
})
Expand Down Expand Up @@ -693,7 +693,7 @@ impl Deserialize for Value {
multiasset_value_value_encodings,
);
if multiasset_table
.insert(multiasset_key.clone(), multiasset_value)
.insert(multiasset_key, multiasset_value)
.is_some()
{
return Err(DeserializeFailure::DuplicateKey(Key::Str(
Expand All @@ -702,9 +702,9 @@ impl Deserialize for Value {
.into());
}
multiasset_key_encodings
.insert(multiasset_key.clone(), multiasset_key_encoding);
.insert(multiasset_key, multiasset_key_encoding);
multiasset_value_encodings.insert(
multiasset_key.clone(),
multiasset_key,
(multiasset_value_encoding, multiasset_value_value_encodings),
);
}
Expand Down
30 changes: 15 additions & 15 deletions chain/rust/src/builders/certificate_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,28 @@ pub fn cert_required_wits(cert: &Certificate, required_witnesses: &mut RequiredW
Certificate::StakeRegistration(_cert) => (),
Certificate::StakeDeregistration(cert) => match &cert.stake_credential {
StakeCredential::Script { hash, .. } => {
required_witnesses.add_script_hash(hash.clone());
required_witnesses.add_script_hash(*hash);
}
StakeCredential::PubKey { hash, .. } => {
required_witnesses.add_vkey_key_hash(hash.clone());
required_witnesses.add_vkey_key_hash(*hash);
}
},
Certificate::StakeDelegation(cert) => match &cert.stake_credential {
StakeCredential::Script { hash, .. } => {
required_witnesses.add_script_hash(hash.clone());
required_witnesses.add_script_hash(*hash);
}
StakeCredential::PubKey { hash, .. } => {
required_witnesses.add_vkey_key_hash(hash.clone());
required_witnesses.add_vkey_key_hash(*hash);
}
},
Certificate::PoolRegistration(cert) => {
for owner in &cert.pool_params.pool_owners {
required_witnesses.add_vkey_key_hash(owner.clone());
required_witnesses.add_vkey_key_hash(*owner);
}
required_witnesses.add_vkey_key_hash(cert.pool_params.operator.clone());
required_witnesses.add_vkey_key_hash(cert.pool_params.operator);
}
Certificate::PoolRetirement(cert) => {
required_witnesses.add_vkey_key_hash(cert.ed25519_key_hash.clone());
required_witnesses.add_vkey_key_hash(cert.ed25519_key_hash);
}
Certificate::RegCert(_cert) => todo!(),
Certificate::UnregCert(_cert) => todo!(),
Expand Down Expand Up @@ -78,28 +78,28 @@ pub fn add_cert_vkeys(
Certificate::StakeRegistration(_cert) => {}
Certificate::StakeDeregistration(cert) => match &cert.stake_credential {
StakeCredential::Script { hash, .. } => {
return Err(CertBuilderError::ExpectedKeyHash(hash.clone()))
return Err(CertBuilderError::ExpectedKeyHash(*hash))
}
StakeCredential::PubKey { hash, .. } => {
vkeys.insert(hash.clone());
vkeys.insert(*hash);
}
},
Certificate::StakeDelegation(cert) => match &cert.stake_credential {
StakeCredential::Script { hash, .. } => {
return Err(CertBuilderError::ExpectedKeyHash(hash.clone()))
return Err(CertBuilderError::ExpectedKeyHash(*hash))
}
StakeCredential::PubKey { hash, .. } => {
vkeys.insert(hash.clone());
vkeys.insert(*hash);
}
},
Certificate::PoolRegistration(cert) => {
for owner in &cert.pool_params.pool_owners {
vkeys.insert(owner.clone());
vkeys.insert(*owner);
}
vkeys.insert(cert.pool_params.operator.clone());
vkeys.insert(cert.pool_params.operator);
}
Certificate::PoolRetirement(cert) => {
vkeys.insert(cert.ed25519_key_hash.clone());
vkeys.insert(cert.ed25519_key_hash);
}
Certificate::RegCert(_cert) => todo!(),
Certificate::UnregCert(_cert) => todo!(),
Expand Down Expand Up @@ -209,7 +209,7 @@ impl SingleCertificateBuilder {
let mut required_wits = RequiredWitnessSet::default();
required_signers
.iter()
.for_each(|required_signer| required_wits.add_vkey_key_hash(required_signer.clone()));
.for_each(|required_signer| required_wits.add_vkey_key_hash(*required_signer));
cert_required_wits(&self.cert, &mut required_wits);
let mut required_wits_left = required_wits.clone();

Expand Down
8 changes: 4 additions & 4 deletions chain/rust/src/builders/input_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ pub fn input_required_wits(
if let Some(cred) = utxo_info.address().payment_cred() {
match cred {
StakeCredential::PubKey { hash, .. } => {
required_witnesses.add_vkey_key_hash(hash.clone());
required_witnesses.add_vkey_key_hash(*hash);
}
StakeCredential::Script { hash, .. } => {
required_witnesses.add_script_hash(hash.clone());
required_witnesses.add_script_hash(*hash);
if let Some(data_hash) = utxo_info.datum_hash() {
required_witnesses.add_plutus_datum_hash(data_hash.clone());
required_witnesses.add_plutus_datum_hash(*data_hash);
// note: redeemer is required as well
// but we can't know the index, so we rely on the tx builder to satisfy this requirement
}
Expand Down Expand Up @@ -138,7 +138,7 @@ impl SingleInputBuilder {
let mut required_wits = RequiredWitnessSet::default();
required_signers
.iter()
.for_each(|required_signer| required_wits.add_vkey_key_hash(required_signer.clone()));
.for_each(|required_signer| required_wits.add_vkey_key_hash(*required_signer));
input_required_wits(&self.utxo_info, &mut required_wits);
let mut required_wits_left = required_wits.clone();

Expand Down
6 changes: 3 additions & 3 deletions chain/rust/src/builders/mint_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl SingleMintBuilder {
) -> MintBuilderResult {
let mut required_wits = RequiredWitnessSet::default();
let script_hash = native_script.hash();
required_wits.add_script_hash(script_hash.clone());
required_wits.add_script_hash(script_hash);

MintBuilderResult {
assets: self.assets,
Expand All @@ -60,8 +60,8 @@ impl SingleMintBuilder {
let script_hash = partial_witness.script.hash();
required_signers
.iter()
.for_each(|required_signer| required_wits.add_vkey_key_hash(required_signer.clone()));
required_wits.add_script_hash(script_hash.clone());
.for_each(|required_signer| required_wits.add_vkey_key_hash(*required_signer));
required_wits.add_script_hash(script_hash);

MintBuilderResult {
assets: self.assets,
Expand Down
4 changes: 2 additions & 2 deletions chain/rust/src/builders/redeemer_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ impl RedeemerSetBuilder {
};
if let Some(data) = plutus_data {
self.mint.insert(
result.policy_id.clone(),
result.policy_id,
Some(UntaggedRedeemerPlaceholder::JustData(data.clone())),
);
} else {
self.mint.insert(result.policy_id.clone(), None);
self.mint.insert(result.policy_id, None);
}
}

Expand Down
Loading
Loading