Allow salt in contract deploy (#2849)

* Allow salt in contract deploy

* Mark deprecated

* Shorten

* Cleanups

* Additional cleanups

* Cleanups

* Explicit Bytes to decodeEvent

* Adjust method creation

* Allow null salt
This commit is contained in:
Jaco Greeff
2020-11-16 07:35:02 +01:00
committed by GitHub
parent 0fc5e1d387
commit d3b13bceb0
12 changed files with 248 additions and 195 deletions
+16 -1
View File
@@ -3,13 +3,18 @@
import { SubmittableResult } from '@polkadot/api';
import { EventRecord } from '@polkadot/types/interfaces';
import { Codec, Registry, TypeDef } from '@polkadot/types/types';
import { Codec, CodecArg, Registry, TypeDef } from '@polkadot/types/types';
import { BlueprintOptions, ContractOptions } from './types';
import BN from 'bn.js';
import { Raw } from '@polkadot/types';
import { createTypeUnsafe } from '@polkadot/types/create';
import { isBn, isBigInt, isNumber, isString } from '@polkadot/util';
type ContractEvents = 'CodeStored' | 'ContractExecution' | 'Instantiated';
type TOptions = BlueprintOptions | ContractOptions;
export function formatData (registry: Registry, data: Raw, { type }: TypeDef): Codec {
return createTypeUnsafe(registry, type, [data], true);
}
@@ -25,3 +30,13 @@ export function applyOnEvent <T> (result: SubmittableResult, type: ContractEvent
return undefined;
}
export function isOptions <T> (options: BigInt | string | number | BN | T): options is T {
return !(isBn(options) || isBigInt(options) || isNumber(options) || isString(options));
}
export function extractOptions <T extends TOptions> (value: BigInt | string | number | BN, params: CodecArg[]): [T, CodecArg[]] {
const gasLimit = params.shift() as BN;
return [{ gasLimit, value } as T, params];
}