All files / src/contracts ContractParamsProvider.ts

35.71% Statements 5/14
0% Branches 0/4
0% Functions 0/7
38.46% Lines 5/13

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 383x 3x 3x 3x   3x                                                                
import { hexlify } from "@ethersproject/bytes";
import { toUtf8Bytes } from "@ethersproject/strings/lib/utf8";
import { arrayify } from "ethers/lib/utils";
import { DataPackagesRequestParams, requestRedstonePayload } from "../index";
 
export class ContractParamsProvider {
  constructor(public readonly requestParams: DataPackagesRequestParams) {}
 
  async getPayloadHex(withPrefix = true): Promise<string> {
    return (
      (withPrefix ? "0x" : "") + (await this.requestPayload(this.requestParams))
    );
  }
 
  async getPayloadData(): Promise<number[]> {
    return Array.from(arrayify(await this.getPayloadHex(true)));
  }
 
  getHexlifiedFeedIds(): string[] {
    return this.getDataFeedIds().map((feed) => hexlify(toUtf8Bytes(feed)));
  }
 
  getDataFeedIds(): string[] {
    Iif (!this.requestParams.dataFeeds) {
      throw new Error("That invocation requires non-empty dataFeeds");
    }
 
    return this.requestParams.dataFeeds;
  }
 
  // eslint-disable-next-line @typescript-eslint/class-methods-use-this
  protected async requestPayload(
    requestParams: DataPackagesRequestParams
  ): Promise<string> {
    return await requestRedstonePayload(requestParams);
  }
}