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

Add support for Checks #853

Merged
merged 11 commits into from
Mar 2, 2018
Merged

Add support for Checks #853

merged 11 commits into from
Mar 2, 2018

Conversation

intelliot
Copy link
Collaborator

Copy link
Collaborator

@scottschurr scottschurr left a comment

Choose a reason for hiding this comment

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

Thanks for getting to this so quickly, @intelliot. I'm, of course, reading this as a TypeScript illiterate. But it all looks reasonable to me.

I'm wondering if ripple-lib has support for finding account objects, like Offers. If it does, you might consider adding support for finding the checks that are associated with an account. There are two kinds of checks that can be associated with an account: those written by the account, and checks that are the destination of the account. Folks may want to know about either.

What I've seen here looks good to me. 👍

},
"deliverMin": {
"$ref": "laxAmount",
"description": "Redeem the Check for at least this amount as for as much as possible. The currency must match that of the sendMax of the corresponding CheckCreate transaction. You must provide either this field or amount."
Copy link
Collaborator

Choose a reason for hiding this comment

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

"...amount or for as much..."?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

and

:)

},
"sendMax": {
"$ref": "laxAmount",
"description": "Amount of source currency the check is allowed to debit the sender, including transfer fees on non-XRP currencies."
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice description.

"destinationTag": {
"$ref": "tag",
"description": "Destination tag that identifies the reason for the check, or a hosted recipient to pay."
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'll mention is passing that a "sourceTag" is also an allowed field. But that's allowed in any transaction, so you may be handling that elsewhere.

// for as much as possible
deliverMin: parseAmount(tx.DeliverMin).value

// *must* include either Amount or DeliverMin, but not both
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@wilsonianb
Copy link
Collaborator

I'm wondering if ripple-lib has support for finding account object

There's getPaymentChannel, but that's by id as opposed to something like rippled's account_objects

@intelliot intelliot changed the base branch from add-deposit-auth to develop February 22, 2018 01:15
@FredKSchott
Copy link
Contributor

I'm wondering if ripple-lib has support for finding account object

There's getPaymentChannel, but that's by id as opposed to something like rippled's account_objects

Today you can call api.connection.request({}) to make rippled requests like {command: 'account_objects', ...} directly, although it's kind of hidden. Work is being done to expose this more clearly via a new api.request() method.

Copy link
Collaborator

@scottschurr scottschurr left a comment

Choose a reason for hiding this comment

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

Tests are good. I don't read javascript well enough to have a useful opinion here. But I do like having tests. 😄 👍

Copy link
Contributor

@FredKSchott FredKSchott left a comment

Choose a reason for hiding this comment

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

Looks good! Added a few comments

import {removeUndefined} from '../../common'
import parseAmount from './amount'

function parseCheckCreate(tx: any): Object {
Copy link
Contributor

Choose a reason for hiding this comment

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

We're moving towards typing the output of these parsing functions so that they're easier to consume (also a great place to document the formatted type).

So instead of returning a type Object you would return a type FormattedCheckCreate, something like this:

export type FormattedCheckCreate = {
  // account that can cash the check.
  destination: string,
  // amount the check is allowed to debit the sender, including transfer fees on non-XRP currencies.
  sendMax: Amount,
  // (Optional) identifies the reason for the check, or a hosted recipient.
  destinationTag?: string,
  // (Optional) time in seconds since the Ripple Epoch.
  expiration?: string, 
  // (Optional) 256-bit hash representing a specific reason or identifier.
  invoiceID?: string
}

function parseCheckCreate(tx: any): FormattedCheckCreate {
  // ...
}

Can you do this for the other two new parsers?


function createCheckCancelTransaction(account: string,
cancel: CheckCancel
): Object {
Copy link
Contributor

Choose a reason for hiding this comment

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

Object actually doesn't mean an arbitrary object like it did in Glow, it's closer to an empty object than an arbitrary one. Change to any or object (lower-case) to represent any arbitrary object, and then you should be able to remove the : any you had to add to the txJSON below.

}

if (checkCash.amount && checkCash.deliverMin) {
throw new ValidationError('"amount" and "deliverMin" properties on '
Copy link
Contributor

Choose a reason for hiding this comment

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

We tend to do data validation as the first thing in the function. It's a good general rule so that you don't have to worry about what logic is safe to do pre-validation vs. post-validation (ex: if someone later had to add something to the txJSON definition above).

@intelliot
Copy link
Collaborator Author

@FredKSchott Thank you! Have a second look?

@intelliot
Copy link
Collaborator Author

@shekenahglory @wilsonianb Would love if you guys could review as well.

Copy link
Contributor

@FredKSchott FredKSchott left a comment

Choose a reason for hiding this comment

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

lgtm!

@intelliot intelliot merged commit facc513 into develop Mar 2, 2018
@intelliot intelliot deleted the add-checks branch March 2, 2018 05:42
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.

4 participants