Created
March 16, 2021 17:00
-
-
Save kdembler/9cebb676782c3d73c96414a36fd5a28d to your computer and use it in GitHub Desktop.
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
import { Bytes, Raw } from "@polkadot/types"; | |
import { ChannelMetadata } from "@joystream/content-metadata-protobuf"; | |
import { ChannelCreationParameters } from "@joystream/types/content"; | |
// getApi, getAssets, getRewardAccount and getMetaFromEvent are stubs here | |
const api = await getApi(); | |
// ===== encode channel params ===== | |
const metadata = new ChannelMetadata(); | |
metadata.setTitle("my new channel"); | |
const serialized = metadata.serializeBinary(); | |
// api.createType('Raw', serialized) can be used as well | |
const metaRaw = new Raw(api.registry, serialized); | |
const meta = new Bytes(api.registry, serializedRaw); | |
const params = new ChannelCreationParameters(api.registry, { | |
meta, | |
assets: getAssets(), | |
reward_account: getRewardAccount(), | |
}); | |
// ===== decode channel params ===== | |
const metaBytes = getMetaFromEvent(); // meta will be of type Bytes | |
// true option here is crucial, it indicates that we want just the underlying bytes (by default it will also include bytes encoding the length) | |
const metaU8a = metaBytes.toU8a(true); | |
const decoded = ChannelMetadata.deserializeBinary(metaU8a); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment