This commit is contained in:
hatim boufnichel 2021-01-04 18:56:49 +01:00
parent bd89766265
commit 1cb7b137d6

View file

@ -5,15 +5,18 @@ const SEA = require('../gunDB/Mediator').mySEA
const Key = require('../gunDB/contact-api/key') const Key = require('../gunDB/contact-api/key')
/** /**
* @typedef {import('../gunDB/contact-api/SimpleGUN').ISEA} ISEA * @typedef {import('../gunDB/contact-api/SimpleGUN').ISEA} ISEA
* @typedef { 'spontaneousPayment' | 'tip' | 'service' | 'product' | 'other' } OrderType * @typedef { 'spontaneousPayment' | 'tip' | 'service' | 'product' | 'other'|'invoice'|'payment'|'chainTx' } OrderType
* *
* This represents a settled order only, unsettled orders have no coordinate * This represents a settled order only, unsettled orders have no coordinate
* @typedef {object} CoordinateOrder * @typedef {object} CoordinateOrder //everything is optional for different types
* @prop {string=} fromLndPub can be unknown when inbound * @prop {string=} fromLndPub can be unknown when inbound
* @prop {string} toLndPub always known * @prop {string=} toLndPub always known
* @prop {string=} fromGunPub can be optional, if the payment/invoice is not related to an order * @prop {string=} fromGunPub can be optional, if the payment/invoice is not related to an order
* @prop {string=} toGunPub can be optional, if the payment/invoice is not related to an order * @prop {string=} toGunPub can be optional, if the payment/invoice is not related to an order
* @prop {string=} fromBtcPub
* @prop {string=} toBtcPub
* @prop {boolean} inbound * @prop {boolean} inbound
* NOTE: type specific checks are not made before creating the order node, filters must be done before rendering or processing
* *
* @prop {string=} ownerGunPub Reserved for buddy system: * @prop {string=} ownerGunPub Reserved for buddy system:
* can be undefined, '', 'me', or node owner pub key to represent node owner, * can be undefined, '', 'me', or node owner pub key to represent node owner,
@ -41,6 +44,8 @@ const checkOrderInfo = order => {
toLndPub, toLndPub,
fromGunPub, fromGunPub,
toGunPub, toGunPub,
fromBtcPub,
toBtcPub,
inbound, inbound,
type, type,
amount, amount,
@ -54,7 +59,7 @@ const checkOrderInfo = order => {
if (fromLndPub && (typeof fromLndPub !== 'string' || fromLndPub === '')) { if (fromLndPub && (typeof fromLndPub !== 'string' || fromLndPub === '')) {
return 'invalid "fromLndPub" field provided to order coordinate' return 'invalid "fromLndPub" field provided to order coordinate'
} }
if (typeof toLndPub !== 'string' || toLndPub === '') { if (toLndPub && (typeof toLndPub !== 'string' || toLndPub === '')) {
return 'invalid or no "toLndPub" field provided to order coordinate' return 'invalid or no "toLndPub" field provided to order coordinate'
} }
if (fromGunPub && (typeof fromGunPub !== 'string' || fromGunPub === '')) { if (fromGunPub && (typeof fromGunPub !== 'string' || fromGunPub === '')) {
@ -63,6 +68,12 @@ const checkOrderInfo = order => {
if (toGunPub && (typeof toGunPub !== 'string' || toGunPub === '')) { if (toGunPub && (typeof toGunPub !== 'string' || toGunPub === '')) {
return 'invalid "toGunPub" field provided to order coordinate' return 'invalid "toGunPub" field provided to order coordinate'
} }
if (fromBtcPub && (typeof fromBtcPub !== 'string' || fromBtcPub === '')) {
return 'invalid "fromBtcPub" field provided to order coordinate'
}
if (toBtcPub && (typeof toBtcPub !== 'string' || toBtcPub === '')) {
return 'invalid "toBtcPub" field provided to order coordinate'
}
if (typeof inbound !== 'boolean') { if (typeof inbound !== 'boolean') {
return 'invalid or no "inbound" field provided to order coordinate' return 'invalid or no "inbound" field provided to order coordinate'
} }