@polkadot/types/types#RegistryTypes TypeScript Examples

The following examples show how to use @polkadot/types/types#RegistryTypes. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: generateJSON.ts    From moonbeam with GNU General Public License v3.0 6 votes vote down vote up
async function generateJSON() {
  const version = process.argv[2] || "latest";
  let types: RegistryTypes;
  if (!moonbeamDefinitions.types) {
    throw new Error("missing types definitions");
  } else if (version === "latest") {
    types = moonbeamDefinitions.types[moonbeamDefinitions.types.length - 1].types;
  } else if (Number(version)) {
    let i = 0;
    while (
      i < moonbeamDefinitions.types.length &&
      moonbeamDefinitions.types[i].minmax[1] &&
      Number(moonbeamDefinitions.types[i].minmax[1]) < Number(version)
    ) {
      i += 1;
    }
    types = moonbeamDefinitions.types[i].types;
  } else {
    throw new Error("parameter must be number or `latest`");
  }
  console.log(JSON.stringify(types));
  fs.appendFile("moonbeam-types-" + version + ".json", JSON.stringify(types), function (err) {
    if (err) throw err;
    console.log("Saved for version : " + version);
  });
}
Example #2
Source File: index.ts    From moonbeam with GNU General Public License v3.0 6 votes vote down vote up
TYPES_0_4: RegistryTypes = {
  AccountId: "EthereumAccountId",
  Address: "AccountId",
  Balance: "u128",
  RefCount: "u8",
  LookupSource: "AccountId",
  Account: {
    nonce: "U256",
    balance: "u128",
  },
}
Example #3
Source File: index.ts    From moonbeam with GNU General Public License v3.0 6 votes vote down vote up
TYPES_37_42: RegistryTypes = {
  ...TYPES_36_36,
  AccountId32: "H256",
  AuthorId: "AccountId32",
  ProxyType: {
    _enum: [
      "Any",
      "NonTransfer",
      "Governance",
      "Staking",
      "CancelProxy",
      "Balances",
      "AuthorMapping",
    ],
  },
  RelayChainAccountId: "AccountId32",
  RewardInfo: {
    totalReward: "Balance",
    claimedReward: "Balance",
  },
}
Example #4
Source File: index.ts    From moonbeam with GNU General Public License v3.0 6 votes vote down vote up
TYPES_43_154: RegistryTypes = {
  ...TYPES_37_42,
  Collator2: {
    id: "AccountId",
    bond: "Balance",
    nominators: "Vec<AccountId>",
    topNominators: "Vec<Bond>",
    bottomNominators: "Vec<Bond>",
    totalCounted: "Balance",
    totalBacking: "Balance",
    state: "CollatorStatus",
  },
  NominatorAdded: {
    _enum: { AddedToBottom: "Null", AddedToTop: "Balance" },
  },
  RegistrationInfo: {
    account: "AccountId",
    deposit: "Balance",
  },
  ParachainBondConfig: {
    account: "AccountId",
    percent: "Percent",
  },
}
Example #5
Source File: index.ts    From moonbeam with GNU General Public License v3.0 6 votes vote down vote up
TYPES_155_199: RegistryTypes = {
  ...TYPES_43_154,
  EthereumSignature: {
    r: "H256",
    s: "H256",
    v: "U8",
  },
  NominatorAdded: {
    _enum: { AddedToTop: "Balance", AddedToBottom: "Null" },
  },
}
Example #6
Source File: index.ts    From moonbeam with GNU General Public License v3.0 6 votes vote down vote up
TYPES_200_399: RegistryTypes = {
  ...TYPES_155_199,
  NominatorStatus: {
    _enum: { Active: "Null", Leaving: "RoundIndex" },
  },
  Nominator2: {
    nominations: "Vec<Bond>",
    revocations: "Vec<AccountId>",
    total: "Balance",
    scheduledRevocationsCount: "u32",
    scheduledRevocationsTotal: "Balance",
    status: "NominatorStatus",
  },
  ExitQ: {
    candidates: "Vec<AccountId>",
    nominatorsLeaving: "Vec<AccountId>",
    candidateSchedule: "Vec<(AccountId, RoundIndex)>",
    nominatorSchedule: "Vec<(AccountId, Option<AccountId>, RoundIndex)>",
  },
}
Example #7
Source File: index.ts    From moonbeam with GNU General Public License v3.0 6 votes vote down vote up
TYPES_800_899: RegistryTypes = {
  ...TYPES_600_799,
  JunctionV1: {
    _enum: {
      Parachain: "Compact<u32>",
      AccountId32: "ENUM_AccountId32",
      AccountIndex64: "ENUM_AccountIndex64",
      AccountKey20: "ENUM_AccountKey20",
      PalletInstance: "u8",
      GeneralIndex: "Compact<u128>",
      GeneralKey: "Vec<u8>",
      OnlyChild: "Null",
      Plurality: "ENUM_Plurality",
    },
  },
  MultiLocation: "MultiLocationV1",
}
Example #8
Source File: index.ts    From moonbeam with GNU General Public License v3.0 6 votes vote down vote up
TYPES_900_undefined_deprecated: RegistryTypes = {
  ...TYPES_800_899,
  MoonbaseRuntimeAssetRegistrarMetadata: {
    name: "Vec<u8>",
    symbol: "Vec<u8>",
    decimals: "u8",
    is_frozen: "bool",
  },
  PalletCrowdloanRewardsRewardInfo: {
    total_reward: "Balance",
    claimed_reward: "Balance",
    contributed_relay_addresses: "Vec<RelayChainAccountId>",
  },
  ParachainStakingNominator2: {
    nominations: "Vec<Bond>",
    revocations: "Vec<AccountId>",
    total: "Balance",
    scheduled_revocations_count: "u32",
    scheduled_revocations_total: "Balance",
    status: "NominatorStatus",
  },
  ParachainStakingExitQ: {
    candidates: "Vec<AccountId>",
    nominators_leaving: "Vec<AccountId>",
    candidate_schedule: "Vec<(AccountId, RoundIndex)>",
    nominator_schedule: "Vec<(AccountId, Option<AccountId>, RoundIndex)>",
  },
  ParachainStakingCollator2: {
    id: "AccountId",
    bond: "Balance",
    nominators: "Vec<AccountId>",
    top_nominators: "Vec<Bond>",
    bottom_nominators: "Vec<Bond>",
    total_counted: "Balance",
    total_backing: "Balance",
    state: "CollatorStatus",
  },
}
Example #9
Source File: index.ts    From moonbeam with GNU General Public License v3.0 6 votes vote down vote up
TYPES_POST_900: RegistryTypes = {
  ProxyType: {
    _enum: [
      "Any",
      "NonTransfer",
      "Governance",
      "Staking",
      "CancelProxy",
      "Balances",
      "AuthorMapping",
    ],
  },
}
Example #10
Source File: index.ts    From moonbeam with GNU General Public License v3.0 5 votes vote down vote up
TYPES_6_19: RegistryTypes = {
  ...TYPES_5_5,
  ExtrinsicSignature: "EthereumSignature",
  RoundIndex: "u32",
  Candidate: {
    id: "AccountId",
    fee: "Perbill",
    bond: "Balance",
    nominators: "Vec<Bond>",
    total: "Balance",
    state: "ValidatorStatus",
  },
  Nominator: {
    nominations: "Vec<Bond>",
    total: "Balance",
  },
  Bond: {
    owner: "AccountId",
    amount: "Balance",
  },
  ValidatorStatus: {
    _enum: { Active: "Null", Idle: "Null", Leaving: "RoundIndex" },
  },
  TxPoolResultContent: {
    pending: "HashMap<H160, HashMap<U256, PoolTransaction>>",
    queued: "HashMap<H160, HashMap<U256, PoolTransaction>>",
  },
  TxPoolResultInspect: {
    pending: "HashMap<H160, HashMap<U256, Summary>>",
    queued: "HashMap<H160, HashMap<U256, Summary>>",
  },
  TxPoolResultStatus: {
    pending: "U256",
    queued: "U256",
  },
  Summary: "Bytes",
  PoolTransaction: {
    hash: "H256",
    nonce: "U256",
    blockHash: "Option<H256>",
    blockNumber: "Option<U256>",
    from: "H160",
    to: "Option<H160>",
    value: "U256",
    gasPrice: "U256",
    gas: "U256",
    input: "Bytes",
  },
}
Example #11
Source File: index.ts    From moonbeam with GNU General Public License v3.0 5 votes vote down vote up
TYPES_19_35: RegistryTypes = {
  ...omitFields,
  AccountInfo: "AccountInfoWithTripleRefCount",
  Candidate: {
    id: "AccountId",
    fee: "Perbill",
    bond: "Balance",
    nominators: "Vec<Bond>",
    total: "Balance",
    state: "CollatorStatus",
  },
  CollatorStatus: {
    _enum: { Active: "Null", Idle: "Null", Leaving: "RoundIndex" },
  },
  // Staking inflation
  Range: "RangeBalance",
  RangeBalance: {
    min: "Balance",
    ideal: "Balance",
    max: "Balance",
  },
  RangePerbill: {
    min: "Perbill",
    ideal: "Perbill",
    max: "Perbill",
  },
  InflationInfo: {
    expect: "RangeBalance",
    annual: "RangePerbill",
    round: "RangePerbill",
  },
  OrderedSet: "Vec<Bond>",
  Collator: {
    id: "AccountId",
    bond: "Balance",
    nominators: "Vec<Bond>",
    total: "Balance",
    state: "CollatorStatus",
  },
  CollatorSnapshot: {
    bond: "Balance",
    nominators: "Vec<Bond>",
    total: "Balance",
  },
  SystemInherentData: {
    validationData: "PersistedValidationData",
    relayChain_state: "StorageProof",
    downwardMessages: "Vec<InboundDownwardMessage>",
    horizontalMessages: "BTreeMap<ParaId, Vec<InboundHrmpMessage>>",
  },
  RoundInfo: {
    current: "RoundIndex",
    first: "BlockNumber",
    length: "u32",
  },
}
Example #12
Source File: index.ts    From moonbeam with GNU General Public License v3.0 5 votes vote down vote up
TYPES_36_36: RegistryTypes = {
  ...TYPES_19_35,
  AuthorId: "AccountId",
}
Example #13
Source File: index.ts    From moonbeam with GNU General Public License v3.0 5 votes vote down vote up
TYPES_400_599: RegistryTypes = {
  ...TYPES_200_399,
  RewardInfo: {
    totalReward: "Balance",
    claimedReward: "Balance",
    contributedRelayAddresses: "Vec<RelayChainAccountId>",
  },
}
Example #14
Source File: index.ts    From moonbeam with GNU General Public License v3.0 5 votes vote down vote up
TYPES_600_799: RegistryTypes = {
  ...TYPES_400_599,
  AssetType: {
    _enum: {
      Xcm: "MultiLocation",
    },
  },
  AssetId: "u128",
  TAssetBalance: "u128",
  ENUM_AccountId32: {
    network: "NetworkId",
    id: "[u8; 32]",
  },
  ENUM_AccountKey20: {
    network: "NetworkId",
    key: "[u8; 20]",
  },
  ENUM_AccountIndex64: {
    network: "NetworkId",
    index: "Compact<u64>",
  },
  ENUM_Plurality: {
    id: "BodyId",
    part: "BodyPart",
  },
  JunctionV0: {
    _enum: {
      Parent: "Null",
      Parachain: "Compact<u32>",
      AccountId32: "ENUM_AccountId32",
      AccountIndex64: "ENUM_AccountIndex64",
      AccountKey20: "ENUM_AccountKey20",
      PalletInstance: "u8",
      GeneralIndex: "Compact<u128>",
      GeneralKey: "Vec<u8>",
      OnlyChild: "Null",
      Plurality: "ENUM_Plurality",
    },
  },
  CurrencyId: {
    _enum: {
      SelfReserve: "Null",
      OtherReserve: "u128",
    },
  },
  AssetRegistrarMetadata: {
    name: "Vec<u8>",
    symbol: "Vec<u8>",
    decimals: "u8",
    isFrozen: "bool",
  },
  VestingBlockNumber: "u32",
  MultiLocation: "MultiLocationV0",
}
Example #15
Source File: factory.ts    From interbtc-api with Apache License 2.0 5 votes vote down vote up
export function getAPITypes(): RegistryTypes {
    return Object.values(definitions).reduce((res, { types }) => ({ ...res, ...types }), {});
}
Example #16
Source File: index.ts    From squid with GNU General Public License v3.0 5 votes vote down vote up
export async function getApiPromise(): Promise<ApiPromise> {
  if (apiPromise) {
    return apiPromise
  }

  debug(`Creating new Api Promise`)

  const conf = getConfig()
  const provider = new WsProvider(conf.WS_PROVIDER_ENDPOINT_URI)

  const names = Object.keys(conf.TYPES_JSON)

  names.length && debug(`Injected types: ${names.join(', ')}`)

  apiPromise = await pRetry(
    async () =>
      new ApiPromise({
        provider,
        types: conf.TYPES_JSON as RegistryTypes,
        typesAlias: conf.TYPES_ALIAS as Record<string, OverrideModuleType>,
        typesBundle: conf.BUNDLE_TYPES as OverrideBundleType,
        typesSpec: conf.SPEC_TYPES as Record<string, RegistryTypes>,
        typesChain: conf.CHAIN_TYPES as Record<string, RegistryTypes>,
      }).isReadyOrError,
    {
      retries: 99, // large enough
      onFailedAttempt: (error) =>
        debug(`API failed to connect: ${JSON.stringify(error)}`),
    }
  )

  apiPromise.on('error', async (e) => {
    debug(`Api error: ${JSON.stringify(e)}, reconnecting....`)
    apiPromise = await getApiPromise()
  })

  apiPromise.on('connected', () => {
    debug(`Api connected`)
    eventEmitter.emit(IndexerEvents.API_CONNECTED)
  })

  return apiPromise
}