How to use the @polkadot/types.Text function in @polkadot/types

To help you get started, we’ve selected a few @polkadot/types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github polkadot-js / api / packages / metadata / src / Decorated / storage / fromMetadata / createFunction.spec.ts View on Github external
it('allows creates double map function with a Null type key', (): void => {
    const storageFn = createFunction(registry, {
      prefix: 'System',
      section: 'system',
      method: 'EventTopics',
      meta: {
        type: {
          isDoubleMap: true,
          asDoubleMap: {
            hasher: new StorageHasher(registry, 'Blake2_256'),
            key1: new Text(registry, 'Null'),
            key2: new Text(registry, 'Hash'),
            value: new Text(registry, 'Vec<(BlockNumber,EventIndex)>'),
            key2Hasher: new StorageHasher(registry, 'Blake2_256')
          }
        }
      } as any
    }, { metaVersion: 8 });

    // the value of the Null type key does not effect the result
    expect(u8aToHex(storageFn(['any', [1, 2, 3]]))).toEqual(u8aToHex(storageFn([[1, 2, 3], [1, 2, 3]])));
    // the value of the not Null type key does effect the result
    expect(u8aToHex(storageFn(['any', [1, 2, 3]]))).not.toEqual(u8aToHex(storageFn(['any', [1, 2, 3, 4]])));
  });
github polkadot-js / api / packages / metadata / src / Decorated / storage / fromMetadata / createFunction.spec.ts View on Github external
it('allows creating of known DoubleMap keys (with Bytes)', (): void => {
    const storageFn = createFunction(registry, {
      prefix: 'Session',
      section: 'session',
      method: 'NextKeys',
      meta: {
        type: {
          isDoubleMap: true,
          asDoubleMap: {
            hasher: new StorageHasher(registry, 'Twox64Concat'),
            key1: new Text(registry, 'Bytes'),
            key2: new Text(registry, 'AccountId'),
            value: new Text(registry, 'SessionKeys5'),
            key2Hasher: new StorageHasher(registry, 'Blake2_256')
          }
        }
      } as any
    }, { metaVersion: 9 });

    expect(
      u8aToHex(
        storageFn([
          // hex, without length prefix
          '0x3a73657373696f6e3a6b657973',
          // address
          'DB2mp5nNhbFN86J9hxoAog8JALMhDXgwvWMxrRMLNUFMEY4'
        ])
github polkadot-js / api / packages / metadata / src / Decorated / storage / fromMetadata / createFunction.spec.ts View on Github external
it('allows creating of known DoubleMap keys (with Bytes)', (): void => {
    const storageFn = createFunction(registry, {
      prefix: 'Session',
      section: 'session',
      method: 'NextKeys',
      meta: {
        type: {
          isDoubleMap: true,
          asDoubleMap: {
            hasher: new StorageHasher(registry, 'Twox64Concat'),
            key1: new Text(registry, 'Bytes'),
            key2: new Text(registry, 'AccountId'),
            value: new Text(registry, 'SessionKeys5'),
            key2Hasher: new StorageHasher(registry, 'Blake2_256')
          }
        }
      } as any
    }, { metaVersion: 9 });

    expect(
      u8aToHex(
        storageFn([
          // hex, without length prefix
          '0x3a73657373696f6e3a6b657973',
          // address
          'DB2mp5nNhbFN86J9hxoAog8JALMhDXgwvWMxrRMLNUFMEY4'
        ])
      )
github polkadot-js / api / packages / metadata / src / Decorated / storage / fromMetadata / createFunction.spec.ts View on Github external
it('allows creates double map function with a Null type key', (): void => {
    const storageFn = createFunction(registry, {
      prefix: 'System',
      section: 'system',
      method: 'EventTopics',
      meta: {
        type: {
          isDoubleMap: true,
          asDoubleMap: {
            hasher: new StorageHasher(registry, 'Blake2_256'),
            key1: new Text(registry, 'Null'),
            key2: new Text(registry, 'Hash'),
            value: new Text(registry, 'Vec<(BlockNumber,EventIndex)>'),
            key2Hasher: new StorageHasher(registry, 'Blake2_256')
          }
        }
      } as any
    }, { metaVersion: 8 });

    // the value of the Null type key does not effect the result
    expect(u8aToHex(storageFn(['any', [1, 2, 3]]))).toEqual(u8aToHex(storageFn([[1, 2, 3], [1, 2, 3]])));
    // the value of the not Null type key does effect the result
    expect(u8aToHex(storageFn(['any', [1, 2, 3]]))).not.toEqual(u8aToHex(storageFn(['any', [1, 2, 3, 4]])));
  });
github polkadot-js / api / packages / type-storage / src / fromMetadata / v0 / substrate.ts View on Github external
const createRuntimeFunction = (method: string, key: string, { documentation, type }: SubstrateMetadata): StorageFunction =>
  createFunction(
    new Text('Substrate'),
    new Text(method),
    {
      documentation: new Vector(Text, [documentation]),
      modifier: new StorageFunctionModifier(1), // default
      type: new StorageFunctionType(type, 0),
      toJSON: (): any => key
    } as StorageFunctionMetadata,
    {
      isUnhashed: true,
      key
    }
  );
github dappforce / dappforce-subsocial-ui / src / components / posts / EditComment.tsx View on Github external
const buildTxParams = () => {
    if (!isValid) return [];

    if (!struct) {
      const parentCommentId = new Option(CommentId, parentId);
      return [ postId, parentCommentId, ipfsCid ];
    } else if (dirty) {
      const update = new CommentUpdate({
        ipfs_hash: new Text(ipfsCid)
      });
      return [ struct.id, update ];
    } else {
      console.log('Nothing to update in a comment');
      return [];
    }
  };
github polkadot-js / api / packages / metadata / src / Decorated / storage / fromMetadata / createFunction.spec.ts View on Github external
beforeAll((): void => {
      storageFn = createFunction(registry, {
        prefix: 'GenericAsset',
        section: 'genericAsset',
        method: 'FreeBalance',
        meta: {
          name: 'metaName',
          type: {
            isDoubleMap: true,
            asDoubleMap: {
              hasher: new StorageHasher(registry, 'Blake2_256'),
              key1: new Text(registry, 'AccountId'),
              key2: new Text(registry, 'AccountId'),
              value: new Text(registry, 'Balance'),
              key2Hasher: new StorageHasher(registry, 'Twox128')
            }
          }
        } as any
      }, { metaVersion: 8 });
    });