Skip to content

Commit

Permalink
fix(dpp): identity factory doesn't handle versions
Browse files Browse the repository at this point in the history
  • Loading branch information
shumkov committed Oct 3, 2024
1 parent 7a92d1d commit 56d7a89
Showing 1 changed file with 51 additions and 11 deletions.
62 changes: 51 additions & 11 deletions packages/rs-dpp/src/identity/identity_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use crate::state_transition::identity_credit_transfer_transition::v0::IdentityCr
use crate::state_transition::identity_credit_transfer_transition::IdentityCreditTransferTransition;
#[cfg(all(feature = "state-transitions", feature = "client"))]
use crate::state_transition::identity_credit_withdrawal_transition::v0::IdentityCreditWithdrawalTransitionV0;
#[cfg(all(feature = "state-transitions", feature = "client"))]
use crate::state_transition::identity_credit_withdrawal_transition::v1::IdentityCreditWithdrawalTransitionV1;
#[cfg(all(feature = "state-transitions", feature = "client"))]
use crate::state_transition::identity_credit_withdrawal_transition::IdentityCreditWithdrawalTransition;
Expand Down Expand Up @@ -237,19 +238,58 @@ impl IdentityFactory {
output_script: Option<CoreScript>,
identity_nonce: IdentityNonce,
) -> Result<IdentityCreditWithdrawalTransition, ProtocolError> {
let identity_credit_withdrawal_transition = IdentityCreditWithdrawalTransitionV1 {
identity_id,
amount,
core_fee_per_byte,
pooling,
output_script,
nonce: identity_nonce,
..Default::default()
let platform_version = PlatformVersion::get(self.protocol_version)?;

let identity_credit_withdrawal_transition = match platform_version
.dpp
.state_transitions
.identities
.credit_withdrawal
.default_constructor
{
0 => {
let output_script = output_script.ok_or_else(|| {
ProtocolError::Generic(
"Output script is required for IdentityCreditWithdrawalTransitionV0"
.to_string(),
)
})?;

let transition = IdentityCreditWithdrawalTransitionV0 {
identity_id,
amount,
core_fee_per_byte,
pooling,
output_script,
nonce: identity_nonce,
..Default::default()
};

IdentityCreditWithdrawalTransition::from(transition)
}
1 => {
let transition = IdentityCreditWithdrawalTransitionV1 {
identity_id,
amount,
core_fee_per_byte,
pooling,
output_script,
nonce: identity_nonce,
..Default::default()
};

IdentityCreditWithdrawalTransition::from(transition)
}
version => {
return Err(ProtocolError::UnknownVersionMismatch {
method: "create_identity_credit_withdrawal_transition".to_string(),
known_versions: vec![0, 1],
received: version,
});
}
};

Ok(IdentityCreditWithdrawalTransition::from(
identity_credit_withdrawal_transition,
))
Ok(identity_credit_withdrawal_transition)
}

#[cfg(all(feature = "state-transitions", feature = "client"))]
Expand Down

0 comments on commit 56d7a89

Please sign in to comment.