mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-21 13:15:41 +00:00
XCM builder pattern (#2107)
Added a proc macro to be able to write XCMs using the builder pattern.
This means we go from having to do this:
```rust
let message: Xcm<()> = Xcm(vec![
WithdrawAsset(assets),
BuyExecution { fees: asset, weight_limit: Unlimited },
DepositAsset { assets, beneficiary },
]);
```
to this:
```rust
let message: Xcm<()> = Xcm::builder()
.withdraw_asset(assets)
.buy_execution(asset, Unlimited),
.deposit_asset(assets, beneficiary)
.build();
```
---------
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
Co-authored-by: command-bot <>
This commit is contained in:
committed by
GitHub
parent
8ebb5c3319
commit
0524aa51d3
@@ -649,4 +649,23 @@ mod tests {
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn builder_pattern_works() {
|
||||
let asset: MultiAsset = (Here, 100u128).into();
|
||||
let beneficiary: MultiLocation = AccountId32 { id: [0u8; 32], network: None }.into();
|
||||
let message: Xcm<()> = Xcm::builder()
|
||||
.withdraw_asset(asset.clone().into())
|
||||
.buy_execution(asset.clone(), Unlimited)
|
||||
.deposit_asset(asset.clone().into(), beneficiary)
|
||||
.build();
|
||||
assert_eq!(
|
||||
message,
|
||||
Xcm(vec![
|
||||
WithdrawAsset(asset.clone().into()),
|
||||
BuyExecution { fees: asset.clone(), weight_limit: Unlimited },
|
||||
DepositAsset { assets: asset.into(), beneficiary },
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user