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.

NFTokenCreateOffer.js 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.validateNFTokenCreateOffer = exports.NFTokenCreateOfferFlags = void 0;
  4. const errors_1 = require("../../errors");
  5. const utils_1 = require("../utils");
  6. const common_1 = require("./common");
  7. var NFTokenCreateOfferFlags;
  8. (function (NFTokenCreateOfferFlags) {
  9. NFTokenCreateOfferFlags[NFTokenCreateOfferFlags["tfSellNFToken"] = 1] = "tfSellNFToken";
  10. })(NFTokenCreateOfferFlags = exports.NFTokenCreateOfferFlags || (exports.NFTokenCreateOfferFlags = {}));
  11. function validateNFTokenSellOfferCases(tx) {
  12. if (tx.Owner != null) {
  13. throw new errors_1.ValidationError('NFTokenCreateOffer: Owner must not be present for sell offers');
  14. }
  15. }
  16. function validateNFTokenBuyOfferCases(tx) {
  17. if (tx.Owner == null) {
  18. throw new errors_1.ValidationError('NFTokenCreateOffer: Owner must be present for buy offers');
  19. }
  20. if ((0, common_1.parseAmountValue)(tx.Amount) <= 0) {
  21. throw new errors_1.ValidationError('NFTokenCreateOffer: Amount must be greater than 0 for buy offers');
  22. }
  23. }
  24. function validateNFTokenCreateOffer(tx) {
  25. (0, common_1.validateBaseTransaction)(tx);
  26. if (tx.Account === tx.Owner) {
  27. throw new errors_1.ValidationError('NFTokenCreateOffer: Owner and Account must not be equal');
  28. }
  29. if (tx.Account === tx.Destination) {
  30. throw new errors_1.ValidationError('NFTokenCreateOffer: Destination and Account must not be equal');
  31. }
  32. if (tx.NFTokenID == null) {
  33. throw new errors_1.ValidationError('NFTokenCreateOffer: missing field NFTokenID');
  34. }
  35. if (!(0, common_1.isAmount)(tx.Amount)) {
  36. throw new errors_1.ValidationError('NFTokenCreateOffer: invalid Amount');
  37. }
  38. if (typeof tx.Flags === 'number' &&
  39. (0, utils_1.isFlagEnabled)(tx.Flags, NFTokenCreateOfferFlags.tfSellNFToken)) {
  40. validateNFTokenSellOfferCases(tx);
  41. }
  42. else {
  43. validateNFTokenBuyOfferCases(tx);
  44. }
  45. }
  46. exports.validateNFTokenCreateOffer = validateNFTokenCreateOffer;
  47. //# sourceMappingURL=NFTokenCreateOffer.js.map