Skip to content

Commit

Permalink
Try with prefix in account
Browse files Browse the repository at this point in the history
  • Loading branch information
mustermeiszer committed Feb 5, 2023
1 parent 8c923a9 commit 4617597
Showing 1 changed file with 71 additions and 21 deletions.
92 changes: 71 additions & 21 deletions xcm/xcm-builder/src/location_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,65 @@ impl<AccountId: From<[u8; 32]> + Clone> Convert<MultiLocation, AccountId>

impl<AccountId> ForeignChainAliasAccount<AccountId> {
fn from_para_32(para_id: &u32, id: &[u8; 32]) -> [u8; 32] {
(FOREIGN_CHAIN_PREFIX, para_id, id).using_encoded(blake2_256)
const PREFIX: [u8; 8] = *b"ForeignP";
let mut out = (FOREIGN_CHAIN_PREFIX, para_id, id).using_encoded(blake2_256);

out[0] = PREFIX[0];
out[1] = PREFIX[1];
out[2] = PREFIX[2];
out[3] = PREFIX[3];
out[4] = PREFIX[4];
out[5] = PREFIX[5];
out[6] = PREFIX[6];
out[7] = PREFIX[7];

let id: [u8; 4] = para_id.to_le_bytes();

out[8] = id[0];
out[9] = id[1];
out[10] = id[2];
out[11] = id[3];

out
}

fn from_para_20(para_id: &u32, id: &[u8; 20]) -> [u8; 32] {
(FOREIGN_CHAIN_PREFIX, para_id, id).using_encoded(blake2_256)
const PREFIX: [u8; 8] = *b"ForeignP";
let mut out = (FOREIGN_CHAIN_PREFIX, para_id, id).using_encoded(blake2_256);

out[0] = PREFIX[0];
out[1] = PREFIX[1];
out[2] = PREFIX[2];
out[3] = PREFIX[3];
out[4] = PREFIX[4];
out[5] = PREFIX[5];
out[6] = PREFIX[6];
out[7] = PREFIX[7];

let id: [u8; 4] = para_id.to_le_bytes();

out[8] = id[0];
out[9] = id[1];
out[10] = id[2];
out[11] = id[3];

out
}

fn from_relay_32(id: &[u8; 32]) -> [u8; 32] {
(FOREIGN_CHAIN_PREFIX, id).using_encoded(blake2_256)
const PREFIX: [u8; 8] = *b"ForeignR";
let mut out = (FOREIGN_CHAIN_PREFIX, id).using_encoded(blake2_256);

out[0] = PREFIX[0];
out[1] = PREFIX[1];
out[2] = PREFIX[2];
out[3] = PREFIX[3];
out[4] = PREFIX[4];
out[5] = PREFIX[5];
out[6] = PREFIX[6];
out[7] = PREFIX[7];

out
}
}

Expand Down Expand Up @@ -306,8 +356,8 @@ mod tests {

assert_eq!(
[
99, 200, 141, 87, 123, 89, 117, 64, 130, 31, 1, 205, 203, 222, 3, 213, 96, 214,
109, 250, 209, 25, 219, 76, 147, 227, 249, 57, 153, 100, 151, 161
70, 111, 114, 101, 105, 103, 110, 80, 1, 0, 0, 0, 203, 222, 3, 213, 96, 214, 109,
250, 209, 25, 219, 76, 147, 227, 249, 57, 153, 100, 151, 161
],
rem_1
);
Expand All @@ -330,8 +380,8 @@ mod tests {

assert_eq!(
[
134, 167, 40, 2, 211, 236, 255, 60, 95, 118, 137, 13, 55, 219, 60, 190, 109, 255,
233, 208, 180, 150, 245, 242, 86, 9, 223, 26, 207, 103, 117, 3
70, 111, 114, 101, 105, 103, 110, 80, 2, 0, 0, 0, 55, 219, 60, 190, 109, 255, 233,
208, 180, 150, 245, 242, 86, 9, 223, 26, 207, 103, 117, 3
],
rem_2
);
Expand All @@ -349,8 +399,8 @@ mod tests {

assert_eq!(
[
138, 178, 174, 32, 50, 130, 59, 252, 53, 61, 149, 173, 157, 117, 42, 161, 77, 123,
199, 182, 244, 201, 112, 60, 34, 233, 140, 160, 182, 150, 132, 98
70, 111, 114, 101, 105, 103, 110, 80, 1, 0, 0, 0, 157, 117, 42, 161, 77, 123, 199,
182, 244, 201, 112, 60, 34, 233, 140, 160, 182, 150, 132, 98
],
rem_1
);
Expand All @@ -373,8 +423,8 @@ mod tests {

assert_eq!(
[
71, 235, 74, 190, 35, 18, 98, 222, 79, 110, 131, 222, 110, 187, 70, 157, 157, 61,
12, 38, 183, 87, 243, 73, 132, 12, 89, 169, 57, 160, 43, 241
70, 111, 114, 101, 105, 103, 110, 80, 2, 0, 0, 0, 110, 187, 70, 157, 157, 61, 12,
38, 183, 87, 243, 73, 132, 12, 89, 169, 57, 160, 43, 241
],
rem_2
);
Expand All @@ -392,7 +442,7 @@ mod tests {

assert_eq!(
[
126, 169, 155, 79, 160, 47, 12, 149, 120, 177, 75, 189, 219, 70, 212, 232, 67, 8,
70, 111, 114, 101, 105, 103, 110, 82, 120, 177, 75, 189, 219, 70, 212, 232, 67, 8,
3, 204, 96, 162, 6, 249, 195, 169, 46, 151, 100, 221, 9, 249
],
rem_1
Expand All @@ -413,7 +463,7 @@ mod tests {

assert_eq!(
[
180, 59, 39, 58, 99, 137, 223, 252, 92, 171, 106, 182, 150, 228, 6, 66, 154, 209,
70, 111, 114, 101, 105, 103, 110, 82, 92, 171, 106, 182, 150, 228, 6, 66, 154, 209,
41, 100, 2, 187, 51, 247, 231, 43, 84, 150, 13, 159, 236, 153
],
rem_2
Expand All @@ -432,8 +482,8 @@ mod tests {

assert_eq!(
[
138, 178, 174, 32, 50, 130, 59, 252, 53, 61, 149, 173, 157, 117, 42, 161, 77, 123,
199, 182, 244, 201, 112, 60, 34, 233, 140, 160, 182, 150, 132, 98
70, 111, 114, 101, 105, 103, 110, 80, 1, 0, 0, 0, 157, 117, 42, 161, 77, 123, 199,
182, 244, 201, 112, 60, 34, 233, 140, 160, 182, 150, 132, 98
],
rem_1
);
Expand All @@ -456,8 +506,8 @@ mod tests {

assert_eq!(
[
71, 235, 74, 190, 35, 18, 98, 222, 79, 110, 131, 222, 110, 187, 70, 157, 157, 61,
12, 38, 183, 87, 243, 73, 132, 12, 89, 169, 57, 160, 43, 241
70, 111, 114, 101, 105, 103, 110, 80, 2, 0, 0, 0, 110, 187, 70, 157, 157, 61, 12,
38, 183, 87, 243, 73, 132, 12, 89, 169, 57, 160, 43, 241
],
rem_2
);
Expand All @@ -475,8 +525,8 @@ mod tests {

assert_eq!(
[
99, 200, 141, 87, 123, 89, 117, 64, 130, 31, 1, 205, 203, 222, 3, 213, 96, 214,
109, 250, 209, 25, 219, 76, 147, 227, 249, 57, 153, 100, 151, 161
70, 111, 114, 101, 105, 103, 110, 80, 1, 0, 0, 0, 203, 222, 3, 213, 96, 214, 109,
250, 209, 25, 219, 76, 147, 227, 249, 57, 153, 100, 151, 161
],
rem_1
);
Expand All @@ -499,8 +549,8 @@ mod tests {

assert_eq!(
[
134, 167, 40, 2, 211, 236, 255, 60, 95, 118, 137, 13, 55, 219, 60, 190, 109, 255,
233, 208, 180, 150, 245, 242, 86, 9, 223, 26, 207, 103, 117, 3
70, 111, 114, 101, 105, 103, 110, 80, 2, 0, 0, 0, 55, 219, 60, 190, 109, 255, 233,
208, 180, 150, 245, 242, 86, 9, 223, 26, 207, 103, 117, 3
],
rem_2
);
Expand Down

0 comments on commit 4617597

Please sign in to comment.