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 LedgerHistory to Connection #1119

Merged
merged 3 commits into from
Jan 11, 2020
Merged

Conversation

FKSRipple
Copy link
Collaborator

Implements a change suggested in #1110.

  • Moved ledger logic off of the Connection class and into it's own Ledger class.
  • Updated _whenReady(promise) -> _waitForReady(). The old method appeared to not be working as expected: it was meant to run a promise after the connection was ready, but a promise would always start immediately at creation time. Instead we just remove the promise argument, and resolve once the connection is ready. Then, the caller can wait for this to resolve before moving on to start the thing that needed to wait.
  • There's a little bit of implicit behavior that I didn't get rid of: we assume that waitForReady will set some ledger data, so that methods like getBaseFee() will always return a number and never return null. It would be considered a bug if this promise was ever broken, but we could go one step further to throw an error OR add "null" as a possible return value so that the user had to handle this error case just in case. LMK your thoughts if you have any.

src/common/connection.ts Outdated Show resolved Hide resolved
src/common/connection.ts Outdated Show resolved Hide resolved
src/common/connection.ts Outdated Show resolved Hide resolved
src/common/connection.ts Show resolved Hide resolved
}
})
}

getLedgerVersion(): Promise<number> {
return this._whenReady(Promise.resolve(this._ledgerVersion!))
async getLedgerVersion(): Promise<number> {
Copy link
Contributor

Choose a reason for hiding this comment

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

possible nit: missing an access modifier here. Is this on purpose?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Which access modifier were you expecting? Since it's already a public method, we don't want to mark it private now and force a breaking change unnecessarily.

Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like my eslint config always yells at me to make access modifies explicit. I prefer to make things explicit, though if this library doesn't then I defer to the existing style.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh like adding "public"? I've actually never used that before. Not against it, but yea lets hold off to a future PR if you're interested in making that change. This library has only used them in 1-2 places and I see our eslint passing clean.

src/common/connection.ts Show resolved Hide resolved
src/common/connection.ts Show resolved Hide resolved
Copy link
Collaborator

@intelliot intelliot left a comment

Choose a reason for hiding this comment

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

good questions from Keefer

@FKSRipple FKSRipple changed the title Add ledger to Connection Add LedgerHistory to Connection Jan 8, 2020
Copy link
Collaborator

@intelliot intelliot left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@keefertaylor keefertaylor left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for changes and documentation!

@FKSRipple FKSRipple merged commit c564400 into develop Jan 11, 2020
@intelliot intelliot deleted the connection-cleanup-ledger branch May 6, 2020 22:53
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.

3 participants