UNPKG

@ethersphere/bee-js

Version:
61 lines (60 loc) 2.81 kB
import { EnvelopeWithBatchId, NumberString } from '../types'; import { Bytes } from './bytes'; import { Duration } from './duration'; import { Size } from './size'; import { BZZ } from './tokens'; /** * Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth. * * For smaller depths (up to 20), this may provide less accurate results. * * @returns {number} A number between 0 and 1 representing the usage of the postage batch. */ export declare function getStampUsage(utilization: number, depth: number, bucketDepth: number): number; /** * Utility function that calculates the theoritical maximum size of a postage batch based on its depth. * * For smaller depths (up to 22), this may provide less accurate results. * * @returns {number} The maximum theoretical size of the postage batch in bytes. */ export declare function getStampTheoreticalBytes(depth: number): number; /** * Utility function that calculates the effective size of a postage batch based on its depth. * * Below 22 depth the effective size is 0 * Above 34 it's always > 99% * * @returns {number} The effective size of the postage batch in bytes. */ export declare function getStampEffectiveBytes(depth: number): number; export declare function getStampEffectiveBytesBreakpoints(): Map<number, number>; /** * Utility function that calculates the cost of a postage batch based on its depth and amount. */ export declare function getStampCost(depth: number, amount: NumberString | string | bigint): BZZ; /** * Utility function that calculates the TTL of a postage batch based on its amount, price per block and block time. * * For more accurate results, get the price per block and block time from the Bee node or the blockchain. * * @returns {number} The TTL of the postage batch. */ export declare function getStampDuration(amount: NumberString | string | bigint, pricePerBlock: number, blockTime: number): Duration; /** * Get the postage batch `amount` required for a given `duration`. * * @param duration A duration object representing the duration of the storage. * @param pricePerBlock The price per block in PLUR. * @param blockTime The block time in seconds. */ export declare function getAmountForDuration(duration: Duration, pricePerBlock: number, blockTime: number): bigint; /** * Utility function that calculates the depth required for a postage batch to achieve the specified effective size * * @param size The effective size of the postage batch * @returns */ export declare function getDepthForSize(size: Size): number; export declare function convertEnvelopeToMarshaledStamp(envelope: EnvelopeWithBatchId): Bytes; export declare function marshalStamp(signature: Uint8Array, batchId: Uint8Array, timestamp: Uint8Array, index: Uint8Array): Bytes;