UNPKG

@hashgraph/sdk

Version:
56 lines (48 loc) 1.5 kB
// SPDX-License-Identifier: Apache-2.0 /** * @namespace proto * @typedef {import("@hiero-ledger/proto").proto.PendingAirdropRecord} HieroProto.proto.PendingAirdropRecord */ import Long from "long"; import PendingAirdropId from "./PendingAirdropId.js"; import { convertAmountToLong } from "../util.js"; /** * @typedef {import("bignumber.js").default} BigNumber */ export default class PendingAirdropRecord { /** * @param {object} props * @param {PendingAirdropId} props.airdropId * @param {Long | number | BigNumber | bigint} props.amount */ constructor(props) { this.airdropId = props.airdropId; this.amount = convertAmountToLong(props.amount); } /** * @returns {HieroProto.proto.PendingAirdropRecord} */ toBytes() { return { pendingAirdropId: this.airdropId.toBytes(), pendingAirdropValue: { amount: this.amount, }, }; } /** * @param {HieroProto.proto.PendingAirdropRecord} pb * @returns {PendingAirdropRecord} */ static fromBytes(pb) { if (pb.pendingAirdropId == null) { throw new Error("pendingAirdropId is required"); } const airdropId = PendingAirdropId.fromBytes(pb.pendingAirdropId); const amount = pb.pendingAirdropValue?.amount; return new PendingAirdropRecord({ airdropId: airdropId, amount: amount ? amount : Long.ZERO, }); } }