machinomy / machinomy

Node.js library for micropayments in Ether and ERC20 tokens over HTTP

Home Page:http://machinomy.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Broken payment validation

kincaidoneil opened this issue · comments

Since all of the methods within https://github.com/machinomy/machinomy/blob/master/packages/machinomy/src/PaymentValidation.ts are async and return promises, the conditions can't be applied to && directly. In effect, the isValid method just returns the last boolean promise (isAboveMinSettlementPeriod), and never checks any of the other conditions.

This is the cause for #231, as when passing Machinomy a payment with a negative price, it would log the error that the payment was invalid/price was negative, but isValid here

const valid = await this.paymentManager.isValid(payment, channel)
would still always return true, saving the payment to the DB. Then when attempting to claim it, it cleared the entire channel, since the value is parsed as an unsigned integer.

🤦‍♂️

Thank you @kincaidoneil!!

Fixed in #233