All files / src/api/read-only utils.ts

66.66% Statements 6/9
25% Branches 1/4
50% Functions 1/2
66.66% Lines 6/9

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 259x   9x           9x     1x 1x           9x            
import { ClarityValue, createAddress, hexToCV } from 'micro-stacks/clarity';
import { ReadOnlyFunctionResponse } from './types';
import { StacksNetworkVersion } from 'micro-stacks/crypto';
 
/**
 * Converts the response of a read-only function call into its Clarity Value
 * @param response - {@link ReadOnlyFunctionResponse}
 */
export function parseReadOnlyResponse<T extends ClarityValue>(
  response: ReadOnlyFunctionResponse
): T {
  if (response.okay) {
    return hexToCV(response.result);
  } else E{
    throw new Error(response.cause);
  }
}
 
export function isMainnetAddress(contractAddress: string) {
  const { version } = createAddress(contractAddress);
  return (
    version === StacksNetworkVersion.mainnetP2SH || version === StacksNetworkVersion.mainnetP2PKH
  );
}