Merge pull request #974 from Roasbeef/invoice-expiry-fix

zpay32+rpc: ensure we can encode an expiry of math.MaxUint64, limit to 1 year in seconds
This commit is contained in:
Olaoluwa Osuntokun
2018-03-30 13:12:53 -07:00
committed by GitHub
3 changed files with 58 additions and 11 deletions

View File

@@ -2129,8 +2129,21 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
// will be explicitly added to this payment request, which will imply
// the default 3600 seconds.
if invoice.Expiry > 0 {
exp := time.Duration(invoice.Expiry) * time.Second
options = append(options, zpay32.Expiry(exp))
// We'll ensure that the specified expiry is restricted to sane
// number of seconds. As a result, we'll reject an invoice with
// an expiry greater than 1 year.
maxExpiry := time.Hour * 24 * 365
expSeconds := invoice.Expiry
if float64(expSeconds) > maxExpiry.Seconds() {
return nil, fmt.Errorf("expiry of %v seconds "+
"greater than max expiry of %v seconds",
float64(expSeconds), maxExpiry.Seconds())
}
expiry := time.Duration(invoice.Expiry) * time.Second
options = append(options, zpay32.Expiry(expiry))
}
// If the description hash is set, then we add it do the list of options.