Skip to content

Commit 3f38d2e

Browse files
author
Adrian Nagy
committed
fix(graphql): Use explicit match instead of unwrap_or
1 parent 8fa0831 commit 3f38d2e

File tree

1 file changed

+37
-14
lines changed

1 file changed

+37
-14
lines changed

node/native/src/graphql/zkapp.rs

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ pub struct GraphQLAuthorizationKind {
296296
pub verification_key_hash: Option<String>,
297297
}
298298

299-
#[derive(GraphQLInputObject)]
299+
#[derive(GraphQLInputObject, Debug)]
300300
pub struct InputGraphQLAuthorizationKind {
301301
pub is_signed: bool,
302302
pub is_proved: bool,
@@ -330,20 +330,27 @@ impl From<MinaBaseAccountUpdateAuthorizationKindStableV1> for GraphQLAuthorizati
330330
impl TryFrom<InputGraphQLAuthorizationKind> for MinaBaseAccountUpdateAuthorizationKindStableV1 {
331331
type Error = ConversionError;
332332
fn try_from(value: InputGraphQLAuthorizationKind) -> Result<Self, Self::Error> {
333-
let res = if value.is_signed {
334-
MinaBaseAccountUpdateAuthorizationKindStableV1::Signature
335-
} else if value.is_proved {
336-
MinaBaseAccountUpdateAuthorizationKindStableV1::Proof(BigInt::from_decimal(
337-
&value
338-
.verification_key_hash
339-
.unwrap_or(Err(ConversionError::MissingField(
333+
if value.is_signed {
334+
return Ok(MinaBaseAccountUpdateAuthorizationKindStableV1::Signature);
335+
}
336+
337+
if value.is_proved {
338+
match &value.verification_key_hash {
339+
Some(vk_hash) => {
340+
let big_int = BigInt::from_decimal(vk_hash)?;
341+
return Ok(MinaBaseAccountUpdateAuthorizationKindStableV1::Proof(
342+
big_int,
343+
));
344+
}
345+
None => {
346+
return Err(ConversionError::MissingField(
340347
"verification_key_hash".to_string(),
341-
))?),
342-
)?)
343-
} else {
344-
MinaBaseAccountUpdateAuthorizationKindStableV1::NoneGiven
345-
};
346-
Ok(res)
348+
));
349+
}
350+
}
351+
}
352+
353+
Ok(MinaBaseAccountUpdateAuthorizationKindStableV1::NoneGiven)
347354
}
348355
}
349356

@@ -1502,6 +1509,22 @@ mod test {
15021509
}
15031510
}
15041511

1512+
#[test]
1513+
fn test_authorization_kind() {
1514+
let kind = InputGraphQLAuthorizationKind {
1515+
is_signed: false,
1516+
is_proved: true,
1517+
verification_key_hash: Some(
1518+
"19951435866906059835892103359374709356309230417850637795098911039647240505427"
1519+
.to_string(),
1520+
),
1521+
};
1522+
let converted: Result<MinaBaseAccountUpdateAuthorizationKindStableV1, ConversionError> =
1523+
kind.try_into();
1524+
1525+
assert!(converted.is_ok());
1526+
}
1527+
15051528
fn create_input_graphql_zkapp() -> InputGraphQLZkapp {
15061529
InputGraphQLZkapp {
15071530
zkapp_command: InputGraphQLZkappCommand {

0 commit comments

Comments
 (0)