mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 03:27:58 +00:00
XCM builder pattern improvement - Accept impl Into<T> instead of just T (#3708)
The XCM builder pattern lets you build xcms like so:
```rust
let xcm = Xcm::builder()
.withdraw_asset((Parent, 100u128).into())
.buy_execution((Parent, 1u128).into())
.deposit_asset(All.into(), AccountId32 { id: [0u8; 32], network: None }.into())
.build();
```
All the `.into()` become quite annoying to have to write.
I accepted `impl Into<T>` instead of `T` in the generated methods from
the macro.
Now the previous example can be simplified as follows:
```rust
let xcm = Xcm::builder()
.withdraw_asset((Parent, 100u128))
.buy_execution((Parent, 1u128))
.deposit_asset(All, [0u8; 32])
.build();
```
---------
Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: command-bot <>
Co-authored-by: Adrian Catangiu <adrian@parity.io>
This commit is contained in:
committed by
GitHub
parent
bcb4d137c9
commit
c130ea9939
@@ -22,11 +22,11 @@ use xcm::latest::prelude::*;
|
||||
#[test]
|
||||
fn builder_pattern_works() {
|
||||
let asset: Asset = (Here, 100u128).into();
|
||||
let beneficiary: Location = AccountId32 { id: [0u8; 32], network: None }.into();
|
||||
let beneficiary: Location = [0u8; 32].into();
|
||||
let message: Xcm<()> = Xcm::builder()
|
||||
.receive_teleported_asset(asset.clone().into())
|
||||
.receive_teleported_asset(asset.clone())
|
||||
.buy_execution(asset.clone(), Unlimited)
|
||||
.deposit_asset(asset.clone().into(), beneficiary.clone())
|
||||
.deposit_asset(asset.clone(), beneficiary.clone())
|
||||
.build();
|
||||
assert_eq!(
|
||||
message,
|
||||
@@ -53,8 +53,8 @@ fn default_builder_requires_buy_execution() {
|
||||
// To be able to do that, we need to use the explicitly unpaid variant
|
||||
let message: Xcm<()> = Xcm::builder_unpaid()
|
||||
.unpaid_execution(Unlimited, None)
|
||||
.withdraw_asset(asset.clone().into())
|
||||
.deposit_asset(asset.clone().into(), beneficiary.clone())
|
||||
.withdraw_asset(asset.clone())
|
||||
.deposit_asset(asset.clone(), beneficiary.clone())
|
||||
.build(); // This works
|
||||
assert_eq!(
|
||||
message,
|
||||
@@ -68,8 +68,8 @@ fn default_builder_requires_buy_execution() {
|
||||
// The other option doesn't have any limits whatsoever, so it should
|
||||
// only be used when you really know what you're doing.
|
||||
let message: Xcm<()> = Xcm::builder_unsafe()
|
||||
.withdraw_asset(asset.clone().into())
|
||||
.deposit_asset(asset.clone().into(), beneficiary.clone())
|
||||
.withdraw_asset(asset.clone())
|
||||
.deposit_asset(asset.clone(), beneficiary.clone())
|
||||
.build();
|
||||
assert_eq!(
|
||||
message,
|
||||
|
||||
Reference in New Issue
Block a user