You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.8 KiB

  1. // Copyright (c) 2019-2020, Zpalmtree
  2. //
  3. // Please see the included LICENSE file for more information.
  4. import { IConfig, Config, MergeConfig } from './Config';
  5. export class FeeType {
  6. /**
  7. * Uses the lowest fee possible. Currently is a fee per byte of 1.953125.
  8. */
  9. public static MinimumFee(config: IConfig = new Config()): FeeType {
  10. const tempConfig: Config = MergeConfig(config);
  11. return FeeType.FeePerByte(tempConfig.minimumFeePerByte);
  12. }
  13. /**
  14. * Specify a custom fee per byte to use. Can be a fractional amount.
  15. * Should be in atomic units.
  16. * Can not be lower than the minimum fee per byte allowed (currently 1.953125)
  17. *
  18. * Note that the fee per byte of the resulting transaction may be higher
  19. * than the specified fee per byte, but it will not be lower. It will also
  20. * not be any more than 2x higher than the specified fee per byte.
  21. * The fee per byte being potentially higher is due to how the transaction
  22. * size estimate process works.
  23. *
  24. * @param feePerByte The custom fee per byte value to use.
  25. */
  26. public static FeePerByte(feePerByte: number): FeeType {
  27. const fee = new FeeType();
  28. fee.isFeePerByte = true;
  29. fee.feePerByte = feePerByte;
  30. return fee;
  31. }
  32. /**
  33. * Specify a fixed fee to use. The transaction will fail if the calculated
  34. * minimum fee per byte for the transaction is lower than the specified
  35. * fixed fee.
  36. *
  37. * @param fixedFee The fixed fee to use
  38. */
  39. public static FixedFee(fixedFee: number): FeeType {
  40. const fee = new FeeType();
  41. fee.isFixedFee = true;
  42. fee.fixedFee = fixedFee;
  43. return fee;
  44. }
  45. public isFixedFee: boolean = false;
  46. public isFeePerByte: boolean = false;
  47. public fixedFee: number = 0;
  48. public feePerByte: number = 0;
  49. }