Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
parity
Mirrored projects
polkadot
Commits
6aa73f26
Unverified
Commit
6aa73f26
authored
Mar 07, 2021
by
Amar Singh
Committed by
GitHub
Mar 07, 2021
Browse files
add accountkey20 conversion impls (#2576)
parent
500d90c4
Pipeline
#127181
passed with stages
in 29 minutes and 26 seconds
Changes
3
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
xcm/xcm-builder/src/lib.rs
View file @
6aa73f26
...
...
@@ -18,13 +18,13 @@
mod
location_conversion
;
pub
use
location_conversion
::{
Account32Hash
,
ParentIsDefault
,
ChildParachainConvertsVia
,
SiblingParachainConvertsVia
,
AccountId32Aliases
Account32Hash
,
ParentIsDefault
,
ChildParachainConvertsVia
,
SiblingParachainConvertsVia
,
AccountId32Aliases
,
AccountKey20Aliases
,
};
mod
origin_conversion
;
pub
use
origin_conversion
::{
SovereignSignedViaLocation
,
ParentAsSuperuser
,
ChildSystemParachainAsSuperuser
,
SiblingSystemParachainAsSuperuser
,
ChildParachainAsNative
,
SiblingParachainAsNative
,
RelayChainAsNative
,
SignedAccountId32AsNative
ChildParachainAsNative
,
SiblingParachainAsNative
,
RelayChainAsNative
,
SignedAccountId32AsNative
,
SignedAccountKey20AsNative
,
};
mod
currency_adapter
;
...
...
xcm/xcm-builder/src/location_conversion.rs
View file @
6aa73f26
...
...
@@ -124,3 +124,27 @@ impl<
Ok
(
Junction
::
AccountId32
{
id
:
who
.into
(),
network
:
Network
::
get
()
}
.into
())
}
}
pub
struct
AccountKey20Aliases
<
Network
,
AccountId
>
(
PhantomData
<
(
Network
,
AccountId
)
>
);
impl
<
Network
:
Get
<
NetworkId
>
,
AccountId
:
From
<
[
u8
;
20
]
>
+
Into
<
[
u8
;
20
]
>
>
LocationConversion
<
AccountId
>
for
AccountKey20Aliases
<
Network
,
AccountId
>
{
fn
from_location
(
location
:
&
MultiLocation
)
->
Option
<
AccountId
>
{
if
let
MultiLocation
::
X1
(
Junction
::
AccountKey20
{
key
,
network
})
=
location
{
if
matches!
(
network
,
NetworkId
::
Any
)
||
network
==
&
Network
::
get
()
{
return
Some
((
*
key
)
.into
());
}
}
None
}
fn
try_into_location
(
who
:
AccountId
)
->
Result
<
MultiLocation
,
AccountId
>
{
Ok
(
Junction
::
AccountKey20
{
key
:
who
.into
(),
network
:
Network
::
get
(),
}
.into
())
}
}
xcm/xcm-builder/src/origin_conversion.rs
View file @
6aa73f26
...
...
@@ -148,3 +148,24 @@ impl<
}
}
}
pub
struct
SignedAccountKey20AsNative
<
Network
,
Origin
>
(
PhantomData
<
(
Network
,
Origin
)
>
);
impl
<
Network
:
Get
<
NetworkId
>
,
Origin
:
OriginTrait
>
ConvertOrigin
<
Origin
>
for
SignedAccountKey20AsNative
<
Network
,
Origin
>
where
Origin
::
AccountId
:
From
<
[
u8
;
20
]
>
,
{
fn
convert_origin
(
origin
:
MultiLocation
,
kind
:
OriginKind
)
->
Result
<
Origin
,
MultiLocation
>
{
match
(
kind
,
origin
)
{
(
OriginKind
::
Native
,
MultiLocation
::
X1
(
Junction
::
AccountKey20
{
key
,
network
}))
if
matches!
(
network
,
NetworkId
::
Any
)
||
network
==
Network
::
get
()
=>
{
Ok
(
Origin
::
signed
(
key
.into
()))
}
(
_
,
origin
)
=>
Err
(
origin
),
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment