-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added util function getSovereignAccountAddresses (#226)
- Loading branch information
Showing
6 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@moonbeam-network/xcm-utils': patch | ||
--- | ||
|
||
Added util function getSovereignAccountAddresses |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './polkadot.api'; | ||
export * from './polkadot.address'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { getSovereignAccountAddresses } from './polkadot.address'; | ||
|
||
describe('utils - polkadot address', () => { | ||
describe('getSovereignAccountAddresses', () => { | ||
it('should get correct addresses for paraId 1000', async () => { | ||
expect(getSovereignAccountAddresses(1000)).toStrictEqual({ | ||
generic: | ||
'0x7369626ce8030000000000000000000000000000000000000000000000000000', | ||
moonbeam: '0x7369626ce8030000000000000000000000000000', | ||
relay: | ||
'0x70617261e8030000000000000000000000000000000000000000000000000000', | ||
}); | ||
}); | ||
|
||
it('should get correct addresses for paraId 3019', async () => { | ||
expect(getSovereignAccountAddresses(3019)).toStrictEqual({ | ||
generic: | ||
'0x7369626ccb0b0000000000000000000000000000000000000000000000000000', | ||
moonbeam: '0x7369626ccb0b0000000000000000000000000000', | ||
relay: | ||
'0x70617261cb0b0000000000000000000000000000000000000000000000000000', | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { bnToU8a, u8aToHex, stringToU8a } from '@polkadot/util'; | ||
|
||
export function getSovereignAccountAddresses(paraId: number) { | ||
const paraIdU8a = bnToU8a(paraId, { bitLength: 32 }); | ||
const relay = u8aToHex( | ||
new Uint8Array([...stringToU8a('para'), ...paraIdU8a]), | ||
).padEnd(66, '0'); | ||
const generic = u8aToHex( | ||
new Uint8Array([...stringToU8a('sibl'), ...paraIdU8a]), | ||
).padEnd(66, '0'); | ||
const moonbeam = generic.slice(0, 42); | ||
|
||
return { | ||
generic, | ||
moonbeam, | ||
relay, | ||
}; | ||
} |