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:
Francisco Aguirre
2023-11-08 06:39:40 +01:00
committed by GitHub
parent 8ebb5c3319
commit 0524aa51d3
10 changed files with 247 additions and 1 deletions
@@ -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 },
])
);
}
}