Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ability to set expiry when creating a new invoice #632

Merged
merged 5 commits into from
Jun 19, 2018

Conversation

n1bor
Copy link
Contributor

@n1bor n1bor commented Jun 17, 2018

Add option to have 3rd parameter to receive API call so you can set the expiry.

@pm47 pm47 changed the title adding in ability to set expiry when creating a new invoice Adding ability to set expiry when creating a new invoice Jun 18, 2018
Copy link
Member

@pm47 pm47 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, with the simplification below I think this can be merged

README.md Outdated
@@ -138,6 +138,7 @@ java -Declair.datadir=/tmp/node1 -jar eclair-node-gui-<version>-<commit_id>.jar
allupdates | nodeId | list all channels updates for this nodeId
receive | description | generate a payment request without a required amount (can be useful for donations)
receive | amountMsat, description | generate a payment request for a given amount
receive | amountMsat, description, expiryDuration | generate a payment request for a given amount that expires after given duration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: expiryDuration -> expirySeconds

It's less fancy but simpler

@@ -225,7 +225,10 @@ trait Service extends Logging {
// the amount is now given with the description
case JInt(amountMsat) :: JString(description) :: Nil =>
completeRpcFuture(req.id, (paymentHandler ? ReceivePayment(Some(MilliSatoshi(amountMsat.toLong)), description)).mapTo[PaymentRequest].map(PaymentRequest.write))
case _ => reject(UnknownParamsRejection(req.id, "[description] or [amount, description]"))
case JInt(amountMsat) :: JString(description) :: JString(expiry) :: Nil =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if expiry is in seconds, this can be simplified

@@ -346,6 +349,7 @@ trait Service extends Logging {
"allupdates: list all channels updates",
"allupdates (nodeId): list all channels updates for this nodeId",
"receive (amountMsat, description): generate a payment request for a given amount",
"receive (amountMsat, description, duration): generate a payment request for a given amount - duration is a string like \"2 hours\" that is expiry of invoice",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: this should be the same description as in the README

@@ -182,7 +183,7 @@ object PaymentLifecycle {
def props(sourceNodeId: PublicKey, router: ActorRef, register: ActorRef) = Props(classOf[PaymentLifecycle], sourceNodeId, router, register)

// @formatter:off
case class ReceivePayment(amountMsat_opt: Option[MilliSatoshi], description: String)
case class ReceivePayment(amountMsat_opt: Option[MilliSatoshi], description: String, expiry: Option[FiniteDuration]=None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't forget to use proper formatting

@n1bor
Copy link
Contributor Author

n1bor commented Jun 18, 2018

Think I have fixed all the above. Was planning to just have seconds then saw the fancy code for the config and did that. Oh well...
PS - is it better when I rebase like this? Or do you prefer the 2 commits so you can see the changes? Guess for small change like this not much of an issue.

@@ -80,6 +79,8 @@ case ${METHOD}_${#} in

"receive_2") call ${METHOD} "'$(printf '[%s,"%s"]' "${1}" "${2}")'" ;; # ${1} is numeric (amount to receive)

"receive_3") call ${METHOD} "'$(printf '[%s,"%s","%s"]' "${1}" "${2}" ${3})'" ;; # ${1} is numeric (amount to receive) as is ${2} for expiry in seconds
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there shouldn't be quotes around %s for the expiry, as it is numeric

case _ => reject(UnknownParamsRejection(req.id, "[description] or [amount, description]"))
case JInt(amountMsat) :: JString(description) :: JInt(expirySeconds) :: Nil =>
completeRpcFuture(req.id, (paymentHandler ? ReceivePayment(Some(MilliSatoshi(amountMsat.toLong)), description, Some(expirySeconds.toLong))).mapTo[PaymentRequest].map(PaymentRequest.write))
case r => reject(UnknownParamsRejection(req.id, "[description] or [amount, description] or [amount, description, expiryDuration] : "+r.toString()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the more complete rejection handler is not necessarily a bad idea, but that is the kind of thing that needs to be addressed everywhere properly and not in a case-by-case basis, otherwise we end up with inconsistent code.

@pm47
Copy link
Member

pm47 commented Jun 19, 2018

PS - is it better when I rebase like this? Or do you prefer the 2 commits so you can see the changes? Guess for small change like this not much of an issue.

Leaving separate commits is better, it allows to see the progress and I can always group them when reviewing.

@pm47 pm47 merged commit b3731ad into ACINQ:master Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants