@polkadot/util-crypto#xxhashAsU8a TypeScript Examples
The following examples show how to use
@polkadot/util-crypto#xxhashAsU8a.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: test-assets-sufficients.ts From moonbeam with GNU General Public License v3.0 | 5 votes |
async function mockAssetBalance(
context,
assetBalance,
assetDetails,
sudoAccount,
assetId,
account,
is_sufficient
) {
// Register the asset
await context.polkadotApi.tx.sudo
.sudo(
context.polkadotApi.tx.assetManager.registerForeignAsset(
sourceLocationRelayAssetType,
relayAssetMetadata,
new BN(1),
is_sufficient
)
)
.signAndSend(sudoAccount);
await context.createBlock();
let assets = (
(await context.polkadotApi.query.assetManager.assetIdType(assetId)) as any
).toJSON();
// make sure we created it
expect(assets["xcm"]["parents"]).to.equal(1);
// Get keys to modify balance
let module = xxhashAsU8a(new TextEncoder().encode("Assets"), 128);
let account_key = xxhashAsU8a(new TextEncoder().encode("Account"), 128);
let blake2concatAssetId = new Uint8Array([
...blake2AsU8a(assetId.toU8a(), 128),
...assetId.toU8a(),
]);
let blake2concatAccount = new Uint8Array([
...blake2AsU8a(hexToU8a(account), 128),
...hexToU8a(account),
]);
let overallAccountKey = new Uint8Array([
...module,
...account_key,
...blake2concatAssetId,
...blake2concatAccount,
]);
// Get keys to modify total supply
let assetKey = xxhashAsU8a(new TextEncoder().encode("Asset"), 128);
let overallAssetKey = new Uint8Array([...module, ...assetKey, ...blake2concatAssetId]);
await context.polkadotApi.tx.sudo
.sudo(
context.polkadotApi.tx.system.setStorage([
[u8aToHex(overallAccountKey), u8aToHex(assetBalance.toU8a())],
[u8aToHex(overallAssetKey), u8aToHex(assetDetails.toU8a())],
])
)
.signAndSend(sudoAccount);
await context.createBlock();
return;
}
Example #2
Source File: test-precompile-assets-erc20.ts From moonbeam with GNU General Public License v3.0 | 5 votes |
export async function mockAssetBalance(
context,
assetBalance,
assetDetails,
sudoAccount,
assetId,
account
) {
// Register the asset
await context.polkadotApi.tx.sudo
.sudo(
context.polkadotApi.tx.assetManager.registerForeignAsset(
sourceLocationRelayAssetType,
relayAssetMetadata,
new BN(1),
true
)
)
.signAndSend(sudoAccount);
await context.createBlock();
let assets = (
(await context.polkadotApi.query.assetManager.assetIdType(assetId)) as any
).toJSON();
// make sure we created it
expect(assets["xcm"]["parents"]).to.equal(1);
// Get keys to modify balance
let module = xxhashAsU8a(new TextEncoder().encode("Assets"), 128);
let account_key = xxhashAsU8a(new TextEncoder().encode("Account"), 128);
let blake2concatAssetId = new Uint8Array([
...blake2AsU8a(assetId.toU8a(), 128),
...assetId.toU8a(),
]);
let blake2concatAccount = new Uint8Array([
...blake2AsU8a(hexToU8a(account), 128),
...hexToU8a(account),
]);
let overallAccountKey = new Uint8Array([
...module,
...account_key,
...blake2concatAssetId,
...blake2concatAccount,
]);
// Get keys to modify total supply
let assetKey = xxhashAsU8a(new TextEncoder().encode("Asset"), 128);
let overallAssetKey = new Uint8Array([...module, ...assetKey, ...blake2concatAssetId]);
await context.polkadotApi.tx.sudo
.sudo(
context.polkadotApi.tx.system.setStorage([
[u8aToHex(overallAccountKey), u8aToHex(assetBalance.toU8a())],
[u8aToHex(overallAssetKey), u8aToHex(assetDetails.toU8a())],
])
)
.signAndSend(sudoAccount);
await context.createBlock();
return;
}
Example #3
Source File: test-precompile-xcm-transactor.ts From moonbeam with GNU General Public License v3.0 | 5 votes |
async function mockAssetBalance(context, assetBalance, assetDetails, sudoAccount, assetId) {
// Register the asset
await context.polkadotApi.tx.sudo
.sudo(
context.polkadotApi.tx.assetManager.registerForeignAsset(
sourceLocationRelayAssetType,
relayAssetMetadata,
new BN(1),
true
)
)
.signAndSend(sudoAccount);
await context.createBlock();
let assets = (
(await context.polkadotApi.query.assetManager.assetIdType(assetId)) as any
).toJSON();
// make sure we created it
expect(assets["xcm"]["parents"]).to.equal(1);
// Get keys to modify balance
let module = xxhashAsU8a(new TextEncoder().encode("Assets"), 128);
let account_key = xxhashAsU8a(new TextEncoder().encode("Account"), 128);
let blake2concatAssetId = new Uint8Array([
...blake2AsU8a(assetId.toU8a(), 128),
...assetId.toU8a(),
]);
let blake2concatAccount = new Uint8Array([
...blake2AsU8a(hexToU8a(ALITH), 128),
...hexToU8a(ALITH),
]);
let overallAccountKey = new Uint8Array([
...module,
...account_key,
...blake2concatAssetId,
...blake2concatAccount,
]);
// Get keys to modify total supply
let assetKey = xxhashAsU8a(new TextEncoder().encode("Asset"), 128);
let overallAssetKey = new Uint8Array([...module, ...assetKey, ...blake2concatAssetId]);
await context.polkadotApi.tx.sudo
.sudo(
context.polkadotApi.tx.system.setStorage([
[u8aToHex(overallAccountKey), u8aToHex(assetBalance.toU8a())],
[u8aToHex(overallAssetKey), u8aToHex(assetDetails.toU8a())],
])
)
.signAndSend(sudoAccount);
await context.createBlock();
return;
}