diff --git a/packages/types/src/CodeHash.ts b/packages/types/src/CodeHash.ts new file mode 100644 index 0000000000..27b1fc8f74 --- /dev/null +++ b/packages/types/src/CodeHash.ts @@ -0,0 +1,14 @@ +// Copyright 2017-2019 @polkadot/types 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 Hash from './Hash'; + +/** + * @name CodeHash + * @description + * The default contract code hash that is used accross the system. It is a + * wrapper around [[Hash]], representing a 32-byte blake2b (Substrate) value + */ +export default class CodeHash extends Hash { +} diff --git a/packages/types/src/Schedule.ts b/packages/types/src/Schedule.ts new file mode 100644 index 0000000000..b048b930d3 --- /dev/null +++ b/packages/types/src/Schedule.ts @@ -0,0 +1,91 @@ +// Copyright 2017-2019 @polkadot/types 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 Struct from './codec/Struct'; +import Gas from './Gas'; +import U32 from './U32'; + +/** + * @name Schedule + * @description + * Definition of the cost schedule and other parameterizations for wasm vm + */ +export default class Schedule extends Struct { + constructor (value?: any) { + super({ + version: U32, + putCodePerByteCost: Gas, + growMemCost: Gas, + regularOpCost: Gas, + returnDataPerByteCost: Gas, + sandboxDataReadCost: Gas, + sandboxDataWriteCost: Gas, + maxStackHeight: U32, + maxMemoryPages: U32 + }, value); + } + + /** + * @description Gas cost of a growing memory by single page. + */ + get growMemCost (): Gas { + return this.get('growMemCost') as Gas; + } + + /** + * @description What is the maximal memory pages amount is allowed to have for a contract. + */ + get maxMemoryPages (): U32 { + return this.get('maxMemoryPages') as U32; + } + + /** + * @description How tall the stack is allowed to grow? + */ + get maxStackHeight (): U32 { + return this.get('maxStackHeight') as U32; + } + + /** + * @description Cost of putting a byte of code into the storage. + */ + get putCodePerByteCost (): Gas { + return this.get('putCodePerByteCost') as Gas; + } + + /** + * @description Gas cost of a regular operation. + */ + get regularOpCost (): Gas { + return this.get('regularOpCost') as Gas; + } + + /** + * @description Gas cost per one byte returned. + */ + get returnDataPerByteCost (): Gas { + return this.get('returnDataPerByteCost') as Gas; + } + + /** + * @description Gas cost per one byte read from the sandbox memory. + */ + get sandboxDataReadCost (): Gas { + return this.get('sandboxDataReadCost') as Gas; + } + + /** + * @description Gas cost per one byte written to the sandbox memory. + */ + get sandboxDataWriteCost (): Gas { + return this.get('sandboxDataWriteCost') as Gas; + } + + /** + * @description Version of the schedule. + */ + get version (): U32 { + return this.get('version') as U32; + } +} diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 4272141e11..ee859aa656 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -27,6 +27,7 @@ export { default as BlockNumber } from './BlockNumber'; export { default as bool } from './Bool'; export { default as Bytes } from './Bytes'; export { default as ChainProperties } from './ChainProperties'; +export { default as CodeHash } from './CodeHash'; export { default as Data } from './Data'; export { default as Digest } from './Digest'; export { default as Event } from './Event'; @@ -74,6 +75,7 @@ export { default as ProposalIndex } from './ProposalIndex'; export { default as ReferendumIndex } from './ReferendumIndex'; export { default as ReferendumInfo } from './ReferendumInfo'; export { default as RuntimeVersion } from './RuntimeVersion'; +export { default as Schedule } from './Schedule'; export { default as SessionKey } from './SessionKey'; export { default as Signature } from './Signature'; export { default as SignedBlock } from './SignedBlock';