|
@@ -489,13 +489,31 @@ impl<'ty> ConstraintGroupBuilder<'ty> {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+ let is_init = init.is_some();
|
|
|
let seeds = seeds.map(|c| ConstraintSeedsGroup {
|
|
|
- is_init: init.is_some(),
|
|
|
+ is_init,
|
|
|
seeds: c.seeds.clone(),
|
|
|
bump: into_inner!(bump)
|
|
|
.map(|b| b.bump)
|
|
|
.expect("bump must be provided with seeds"),
|
|
|
});
|
|
|
+ let associated_token = match (associated_token_mint, associated_token_authority) {
|
|
|
+ (Some(mint), Some(auth)) => Some(ConstraintAssociatedToken {
|
|
|
+ wallet: auth.into_inner().auth,
|
|
|
+ mint: mint.into_inner().mint,
|
|
|
+ }),
|
|
|
+ (Some(mint), None) => return Err(ParseError::new(
|
|
|
+ mint.span(),
|
|
|
+ "authority must be provided to specify an associated token program derived address",
|
|
|
+ )),
|
|
|
+ (None, Some(auth)) => {
|
|
|
+ return Err(ParseError::new(
|
|
|
+ auth.span(),
|
|
|
+ "mint must be provided to specify an associated token program derived address",
|
|
|
+ ))
|
|
|
+ }
|
|
|
+ _ => None,
|
|
|
+ };
|
|
|
Ok(ConstraintGroup {
|
|
|
init: init.as_ref().map(|_| Ok(ConstraintInitGroup {
|
|
|
seeds: seeds.clone(),
|
|
@@ -512,16 +530,10 @@ impl<'ty> ConstraintGroupBuilder<'ty> {
|
|
|
)),
|
|
|
},
|
|
|
}
|
|
|
- } else if let Some(tm) = &associated_token_mint {
|
|
|
+ } else if let Some(at) = &associated_token {
|
|
|
InitKind::AssociatedToken {
|
|
|
- mint: tm.clone().into_inner().mint,
|
|
|
- owner: match &associated_token_authority {
|
|
|
- Some(a) => a.clone().into_inner().auth,
|
|
|
- None => return Err(ParseError::new(
|
|
|
- tm.span(),
|
|
|
- "authority must be provided to initialize a token program derived address"
|
|
|
- )),
|
|
|
- },
|
|
|
+ mint: at.mint.clone(),
|
|
|
+ owner: at.wallet.clone()
|
|
|
}
|
|
|
} else if let Some(d) = &mint_decimals {
|
|
|
InitKind::Mint {
|
|
@@ -553,6 +565,7 @@ impl<'ty> ConstraintGroupBuilder<'ty> {
|
|
|
state: into_inner!(state),
|
|
|
close: into_inner!(close),
|
|
|
address: into_inner!(address),
|
|
|
+ associated_token: if !is_init { associated_token } else { None },
|
|
|
seeds,
|
|
|
})
|
|
|
}
|
|
@@ -669,12 +682,6 @@ impl<'ty> ConstraintGroupBuilder<'ty> {
|
|
|
if self.token_mint.is_some() {
|
|
|
return Err(ParseError::new(c.span(), "token mint already provided"));
|
|
|
}
|
|
|
- if self.init.is_none() {
|
|
|
- return Err(ParseError::new(
|
|
|
- c.span(),
|
|
|
- "init must be provided before token",
|
|
|
- ));
|
|
|
- }
|
|
|
self.associated_token_mint.replace(c);
|
|
|
Ok(())
|
|
|
}
|
|
@@ -726,12 +733,6 @@ impl<'ty> ConstraintGroupBuilder<'ty> {
|
|
|
"token authority already provided",
|
|
|
));
|
|
|
}
|
|
|
- if self.init.is_none() {
|
|
|
- return Err(ParseError::new(
|
|
|
- c.span(),
|
|
|
- "init must be provided before token authority",
|
|
|
- ));
|
|
|
- }
|
|
|
self.associated_token_authority.replace(c);
|
|
|
Ok(())
|
|
|
}
|