All files / src/api/burnchain fetchers.ts

100% Statements 16/16
100% Branches 0/0
100% Functions 5/5
100% Lines 16/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88            10x               10x 1x       1x                 10x           1x       1x                 10x 1x       1x                 10x           1x       1x                 10x       1x 1x    
import {
  BurnchainRewardSlotHolderListResponse,
  BurnchainRewardListResponse,
  BurnchainRewardsTotal,
} from '@stacks/stacks-blockchain-api-types';
import { BaseListParams } from '../types';
import { fetchJson, generateUrl, burnchainEndpoint } from '../utils';
 
/**
 * Get recent reward slot holders
 *
 * @see https://docs.micro-stacks.dev/modules/core/api/burnchain#fetchburnchainrewardslotholders
 */
 
export async function fetchBurnchainRewardSlotHolders({ url, limit, offset }: BaseListParams) {
  const path = generateUrl(`${burnchainEndpoint(url)}/reward_slot_holders`, {
    limit,
    offset,
  });
  return fetchJson<BurnchainRewardSlotHolderListResponse>(path);
}
 
/**
 * Get recent reward slot holder entries for the given address
 *
 * @see https://docs.micro-stacks.dev/modules/core/api/burnchain#fetchburnchainrewardslotholdersbyaddress
 */
 
export async function fetchBurnchainRewardSlotHoldersByAddress({
  url,
  limit,
  offset,
  address,
}: BaseListParams & { address: string }) {
  const path = generateUrl(`${burnchainEndpoint(url)}/reward_slot_holders/${address}`, {
    limit,
    offset,
  });
  return fetchJson<BurnchainRewardSlotHolderListResponse>(path);
}
 
/**
 * Get recent burnchain reward recipients
 *
 * @see https://docs.micro-stacks.dev/modules/core/api/burnchain#fetchburnchainrewards
 */
 
export async function fetchBurnchainRewards({ url, limit, offset }: BaseListParams) {
  const path = generateUrl(`${burnchainEndpoint(url)}/rewards`, {
    limit,
    offset,
  });
  return fetchJson<BurnchainRewardListResponse>(path);
}
 
/**
 * Get recent burnchain reward for the given recipient
 *
 * @see https://docs.micro-stacks.dev/modules/core/api/burnchain#fetchburnchainrewardsbyaddress
 */
 
export async function fetchBurnchainRewardsByAddress({
  url,
  limit,
  offset,
  address,
}: BaseListParams & { address: string }) {
  const path = generateUrl(`${burnchainEndpoint(url)}/rewards/${address}`, {
    limit,
    offset,
  });
  return fetchJson<BurnchainRewardListResponse>(path);
}
 
/**
 * Get total burnchain rewards for the given recipient
 *
 * @see https://docs.micro-stacks.dev/modules/core/api/burnchain#fetchtotalburnchainrewardsbyaddress
 */
 
export async function fetchTotalBurnchainRewardsByAddress({
  url,
  address,
}: BaseListParams & { address: string }) {
  const path = generateUrl(`${burnchainEndpoint(url)}/rewards/${address}/total`, {});
  return fetchJson<BurnchainRewardsTotal>(path);
}