import { GearCoreIdsMessageId, GearCoreIdsProgramId } from '@gear-js/api'; import { Bytes, Enum, GenericCall, GenericExtrinsic, Struct, Tuple, Vec, bool, u128, u64 } from '@polkadot/types'; import { Hash } from '@polkadot/types/interfaces'; import { AnyTuple, ITuple } from '@polkadot/types/types'; export const getExtrinsics = (extrinsics: Vec>, methods: string[]) => extrinsics.filter(({ method: { method } }) => methods.includes(method)); const BATCH_CALL_METHODS = ['sendMessage', 'sendReply', 'uploadProgram', 'createProgram', 'uploadCode']; export const getBatchExtrinsics = (extrinsics: Vec>>>) => extrinsics.filter(({ method: { method }, args }) => { if (!method.toLowerCase().startsWith('batch') && method.toLowerCase() !== 'forcebatch') { return false; } const calls = args.filter((arg: Vec) => { return arg.filter((call) => BATCH_CALL_METHODS.includes(call.method)).length > 0; }); if (calls.length === 0) { return false; } return true; }); interface VoucherCall extends Enum { isSendMessage: boolean; asSendMessage: { destination: GearCoreIdsProgramId; payload: Bytes; gasLimit: u64; value: u128; keepAlive: bool; }; isSendReply: boolean; asSendReply: { replyToId: GearCoreIdsMessageId; payload: Bytes; gasLimit: u64; value: u128; keepAlive: bool; }; isUploadCode: boolean; asUploadCode: { code: Bytes; }; } export const getVoucherExtrinsics = (extrinsics: Vec>) => extrinsics.filter( ({ method: { method, section } }) => section === 'gearVoucher' && method === 'call', ) as GenericExtrinsic>[]; export const getGearRunExtrinsic = (extrinsics: Vec>) => extrinsics.find(({ method: { section, method } }) => section === 'gear' && method === 'run');