Contract API for Rx/promises (#1520)
* wip with rxjs/promise * add outcome process * contract call decoding solved * restore messages as dict, cleanup * linting * linting * type fixes
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
// Copyright 2017-2019 @polkadot/rpc-core authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Codec, TypeDefInfo, TypeDef } from '@polkadot/types/types';
|
||||
|
||||
import { Bytes, Option, createClass } from '@polkadot/types';
|
||||
import { createType, createTypeUnsafe } from '@polkadot/types/codec';
|
||||
import { compactStripLength } from '@polkadot/util';
|
||||
|
||||
export function formatData (value: Bytes, { info, type }: TypeDef): Codec {
|
||||
const input = compactStripLength(value.toU8a(true))[1];
|
||||
const data = createType('Data', input);
|
||||
|
||||
if (info === TypeDefInfo.Option) {
|
||||
return new Option(
|
||||
createClass(type),
|
||||
createTypeUnsafe(type, [data], true)
|
||||
);
|
||||
}
|
||||
|
||||
return createTypeUnsafe(type, [data], true);
|
||||
}
|
||||
Reference in New Issue
Block a user