@polkadot/types#u128 TypeScript Examples

The following examples show how to use @polkadot/types#u128. 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: helpers.ts    From atlas with GNU General Public License v3.0 6 votes vote down vote up
prepareAssetsForExtrinsic = async (api: PolkadotApi, dataObjectsMetadata: DataObjectMetadata[]) => {
  if (!dataObjectsMetadata.length) {
    return null
  }

  const feePerMB = await api.query.storage.dataObjectPerMegabyteFee()
  const feePerMBUint = new u128(api.registry, feePerMB)

  const mappedDataObjectMetadata = dataObjectsMetadata.map((metadata) => ({
    size: metadata.size,
    ipfsContentId: new Bytes(api.registry, metadata.ipfsHash),
  }))
  const dataObjectsVec = new Vec(api.registry, DataObjectCreationParameters, mappedDataObjectMetadata)

  return new StorageAssets(api.registry, {
    expected_data_size_fee: feePerMBUint,
    object_creation_list: dataObjectsVec,
  })
}
Example #2
Source File: test-staking.ts    From moonbeam with GNU General Public License v3.0 6 votes vote down vote up
async function getRewardedEventsAt(
  context: DevTestContext,
  blockHash: string
): Promise<Array<{ account: string; amount: u128 }>> {
  const signedBlock = await context.polkadotApi.rpc.chain.getBlock(blockHash);
  const apiAt = await context.polkadotApi.at(signedBlock.block.header.hash);

  let rewardedEvents: Array<{ account: string; amount: u128 }> = [];
  for await (const event of await apiAt.query.system.events()) {
    if (context.polkadotApi.events.parachainStaking.Rewarded.is(event.event)) {
      rewardedEvents.push({
        account: event.event.data[0].toString(),
        amount: event.event.data[1],
      });
    }
  }

  return rewardedEvents;
}
Example #3
Source File: types.ts    From commonwealth with GNU General Public License v3.0 6 votes vote down vote up
constructor(
    denom: string,
    n: number | u128 | BN | SubstrateCoin | Compact<u128>,
    dollar: BN,
    inDollars: boolean = false,
  ) {
    if (n instanceof SubstrateCoin) {
      super(denom, n.asBN, inDollars, dollar);
    } else if (n instanceof Compact || n instanceof u128) {
      super(denom, n.toBn(), inDollars, dollar);
    } else {
      super(denom, n, inDollars, dollar);
    }
  }
Example #4
Source File: embeds.ts    From community-repo with GNU General Public License v3.0 5 votes vote down vote up
getMintCapacityChangedEmbed = (minted: number, mint: u128, blockNumber: number, event: EventRecord): Discord.MessageEmbed => {

    return addCommonProperties(new Discord.MessageEmbed()
        .setTitle(`? ? ? ? ? ${formatBalance(minted, { withUnit: 'JOY' })} minted to the Treasury ? ? ? ? ? `)
        .addFields(
            { name: 'Balance', value: formatBalance(mint, { withUnit: 'JOY' }), inline: true },
        ), blockNumber, event );
}
Example #5
Source File: shared.ts    From commonwealth with GNU General Public License v3.0 5 votes vote down vote up
public coins(n: number | BN | SubstrateCoin | Compact<u128>, inDollars?: boolean) {
    if (typeof n !== 'undefined') {
      return new SubstrateCoin(this._tokenSymbol, n, new BN(10).pow(new BN(this._tokenDecimals)), inDollars);
    }
  }