Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
chore: patch ContractExecResult
Browse files Browse the repository at this point in the history
  • Loading branch information
kingsleydon committed Nov 9, 2022
1 parent fbc69f7 commit 17d72ae
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@phala/sdk",
"version": "0.3.5-beta.0",
"version": "0.3.5-beta.1",
"description": "Phala JS SDK",
"homepage": "https://github.com/Phala-Network/js-sdk/tree/main/packages/sdk#readme",
"repository": {
Expand Down
35 changes: 24 additions & 11 deletions packages/sdk/src/create.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type {ApiPromise} from '@polkadot/api'
import type {SubmittableExtrinsic} from '@polkadot/api/types'
import type {Bytes} from '@polkadot/types-codec'
import type {AccountId} from '@polkadot/types/interfaces'
import type {ISubmittableResult} from '@polkadot/types/types'
import type {Bytes, Compact, u64} from '@polkadot/types-codec'
import type {AccountId, WeightV2} from '@polkadot/types/interfaces'
import type {Codec, ISubmittableResult} from '@polkadot/types/types'
import {
hexAddPrefix,
hexStripPrefix,
Expand Down Expand Up @@ -258,14 +258,27 @@ export const create: CreateFn = async ({api, baseURL, contractId}) => {
.toHex(),
origin
).then((data) => {
return api.createType(
'ContractExecResult',
(
api.createType('InkResponse', hexAddPrefix(data)).toJSON() as {
result: {ok: {inkMessageReturn: string}}
}
).result.ok.inkMessageReturn
)
const inkMessageReturn = (
api.createType('InkResponse', hexAddPrefix(data)).toJSON() as {
result: {ok: {inkMessageReturn: string}}
}
).result.ok.inkMessageReturn

let result

try {
result = api.createType('ContractExecResult', inkMessageReturn)
} catch (err) {
result = api.createType(
'ContractExecResultV2',
inkMessageReturn
) as any

result.gasConsumed = result.gasConsumed.proofSize
result.gasRequired = result.gasRequired.proofSize
}

return result
})
)
},
Expand Down
7 changes: 7 additions & 0 deletions packages/sdk/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,11 @@ export const types: RegistryTypes = {
message: 'Vec<u8>',
},
InkCommand: {_enum: {InkMessage: 'InkMessage'}},
ContractExecResultV2: {
gasConsumed: 'WeightV2',
gasRequired: 'WeightV2',
storageDeposit: 'StorageDeposit',
debugMessage: 'Text',
result: 'ContractExecResultResult',
},
}

0 comments on commit 17d72ae

Please sign in to comment.