diff --git a/packages/api-contract/src/base/Contract.ts b/packages/api-contract/src/base/Contract.ts index 5b230af658..0233bc19ec 100644 --- a/packages/api-contract/src/base/Contract.ts +++ b/packages/api-contract/src/base/Contract.ts @@ -69,8 +69,11 @@ export default class Contract extends BaseWithTxAndRpc private createOutcome (result: ContractExecResult, origin: AccountId, message: ContractABIMessage, params: any[]): ContractCallOutcome { let output: string; + if (result.isSuccess) { const { data } = result.asSuccess; + + // TODO We actually want to return the full Codec type here, not a string value output = message.returnType ? formatData(data, message.returnType).toString() : data.toHex(); diff --git a/packages/api-contract/src/util.ts b/packages/api-contract/src/util.ts index 037a2f75a4..5fe9529845 100644 --- a/packages/api-contract/src/util.ts +++ b/packages/api-contract/src/util.ts @@ -4,20 +4,18 @@ 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'; +import { Data, Option, createClass } from '@polkadot/types'; +import { createTypeUnsafe } from '@polkadot/types/codec'; -export function formatData (value: Bytes, { info, type }: TypeDef): Codec { - const input = compactStripLength(value.toU8a(true))[1]; - const data = createType('Data', input); +export function formatData (data: Data, { info, type }: TypeDef): Codec { + const u8a = data.toU8a(); if (info === TypeDefInfo.Option) { return new Option( createClass(type), - createTypeUnsafe(type, [data], true) + createTypeUnsafe(type, [u8a], true) ); } - return createTypeUnsafe(type, [data], true); + return createTypeUnsafe(type, [u8a], true); } diff --git a/packages/types/src/interfaces/contracts/definitions.ts b/packages/types/src/interfaces/contracts/definitions.ts index bea1ae9e46..3d04416440 100644 --- a/packages/types/src/interfaces/contracts/definitions.ts +++ b/packages/types/src/interfaces/contracts/definitions.ts @@ -22,7 +22,7 @@ export default { }, ContractExecResultSuccess: { status: 'u8', - data: 'Bytes' + data: 'Data' }, ContractExecResult: { _enum: { diff --git a/packages/types/src/interfaces/contracts/types.ts b/packages/types/src/interfaces/contracts/types.ts index db9299f1f1..374831600f 100644 --- a/packages/types/src/interfaces/contracts/types.ts +++ b/packages/types/src/interfaces/contracts/types.ts @@ -3,7 +3,7 @@ import { Codec } from '@polkadot/types/types'; import { Compact, Enum, Option, Struct } from '@polkadot/types/codec'; -import { Bytes, Null, bool, u32, u64, u8 } from '@polkadot/types/primitive'; +import { Bytes, Data, Null, bool, u32, u64, u8 } from '@polkadot/types/primitive'; import { AccountId, Balance, BlockNumber, Hash } from '@polkadot/types/interfaces/runtime'; /** Struct */ @@ -53,8 +53,8 @@ export interface ContractExecResult extends Enum { export interface ContractExecResultSuccess extends Struct { /** u8 */ readonly status: u8; - /** Bytes */ - readonly data: Bytes; + /** Data */ + readonly data: Data; } /** Enum */