Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private createObservable (name: string, section: RpcInterface$Section): RpcRxInterface$Method {
if (isFunction(section[name].unsubscribe)) {
const memoized: Memoized = memoize(
(...params: Array) => this.createReplay(name, params, section, memoized),
{
length: false,
// Normalize args so that different args that should be cached
// together are cached together.
// E.g.: `query.my.method('abc') === query.my.method(new AccountId('abc'));`
normalizer: (args) => {
// `args` is arguments object as accessible in memoized function
return JSON.stringify(args);
}
}
);
return memoized as unknown as RpcRxInterface$Method;
}
private createObservable (subName: string, name: string, section: RpcInterface$Section): RpcRxObervable {
const isSubscription = isFunction(section[name].unsubscribe);
const fn = isSubscription
? this.createCachedObservable(subName, name, section)
: (...params: Array): Observable =>
from(
section[name]
.apply(null, params)
.catch((error: Error) => {
console.error(error);
})
);
const result = fn as RpcRxObervable;
result.isSubscription = isSubscription;
return result;
const unsubscribe = await extrinsicCall.apply(extrinsic, [...params, async (result: SubmittableResult): Promise => {
if (!result || !result.status) {
return;
}
const status = result.status.type.toLowerCase() as QueueTxStatus;
console.log('makeExtrinsicCall: updated status ::', JSON.stringify(result));
queueSetTxStatus(id, status, result);
if (isFunction(txUpdateCb)) {
txUpdateCb(result);
}
if (result.status.isFinalized) {
unsubscribe();
result.events
.filter(({ event: { section } }): boolean => section === 'system')
.forEach(({ event: { method } }): void => {
if (isFunction(txFailedCb) && method === 'ExtrinsicFailed') {
txFailedCb(result);
} else if (isFunction(txSuccessCb) && method === 'ExtrinsicSuccess') {
txSuccessCb(result);
}
});
} else if (result.isError && isFunction(txFailedCb)) {
private async makeExtrinsicSignature (extrinsic: SubmittableExtrinsic, { id, signerCb, signerOptions }: QueueTx, pair: KeyringPair): Promise {
console.log('makeExtrinsicSignature: extrinsic ::', extrinsic.toHex());
extrinsic.sign(pair, signerOptions || {});
if (isFunction(signerCb)) {
signerCb(id, true);
}
}
}
function getExtrinsic (api: ApiPromise, txDef: T): SubmittableExtrinsic | null {
if (!txDef) {
return null;
}
if (Array.isArray(txDef)) {
const [section, method] = txDef[0].split('.');
assert(api.tx[section] && api.tx[section][method], `Unable to find api.tx.${section}.${method}`);
try {
return api.tx[section][method](...(
isFunction(txDef[1])
? txDef[1]()
: txDef[1]
)) as any as SubmittableExtrinsic;
} catch (e) {
return null;
}
} else {
if ((txDef as Call).callIndex) {
const fn = api.findCall(txDef.callIndex);
return api.tx[fn.section][fn.method](...txDef.args);
}
return txDef as any as SubmittableExtrinsic;
}
}
function hasEndpoint (api: ApiPromise, endpoint: string): boolean {
const [area, section, method] = endpoint.split('.');
try {
return isFunction((api as any)[area][section][method]);
} catch (error) {
return false;
}
}
value: function (account: IKeyringPair | string | AccountId | Address, optionsOrStatus?: Partial | Callback, statusCb?: Callback): SumbitableResultResult | SumbitableResultSubscription {
let options: Partial = {};
if (isFunction(optionsOrStatus)) {
statusCb = optionsOrStatus;
} else {
options = { ...optionsOrStatus };
}
const isSubscription = _noStatusCb || !!statusCb;
const address = isKeyringPair(account) ? account.address : account.toString();
let updateId: number | undefined;
return decorateMethod(
(): Observable => (
getPrelimState(address, options).pipe(
first(),
mergeMap(async ([nonce, header]): Promise => {
const eraOptions = expandEraOptions(options, { header, nonce });
export async function getNpmVersion (): Promise {
return isFunction(npmQuery)
? npmQuery(pkgJson.name)
.then((npmJson): string => (npmJson as unknown as PackageJson).version)
.catch((): string => 'unknown')
: 'unknown';
}