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

Make AccountResponse conform to the StellarBase.Account interface. #655

Merged
merged 3 commits into from Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,9 @@ A breaking change will get clearly marked in this log.

## Unreleased

### Fix
- Fixes a breaking bug introduced in v8.2.0 in which `AccountResponse` no longer conformed to the `StellarBase.Account` interface, which was updated in [stellar-base@v5.2.0](https://github.com/stellar/js-stellar-base/releases/tag/v5.2.0) [(#655)](https://github.com/stellar/js-stellar-sdk/pull/655).


## [v8.2.1](https://github.com/stellar/js-stellar-sdk/compare/v8.2.0...v8.2.1)

Expand Down
6 changes: 5 additions & 1 deletion src/account_response.ts
@@ -1,7 +1,7 @@
/* tslint:disable:variable-name */

import forIn from "lodash/forIn";
import { Account as BaseAccount } from "stellar-base";
import { Account as BaseAccount, MuxedAccount } from "stellar-base";
import { Horizon } from "./horizon_api";
import { ServerApi } from "./server_api";

Expand Down Expand Up @@ -83,4 +83,8 @@ export class AccountResponse {
this._baseAccount.incrementSequenceNumber();
this.sequence = this._baseAccount.sequenceNumber();
}

public createSubaccount(id: string): MuxedAccount {
return this._baseAccount.createSubaccount(id);
}
Comment on lines +87 to +89
Copy link
Contributor

Choose a reason for hiding this comment

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

The Account.createSubaccount() method doesn't have a type annotation:

https://stellar.github.io/js-stellar-sdk/js-stellar-base_src_account.js.html

My guess is that TypeScript will assume id is of type Any, in which case Account would still be incompatible with AccountResponse because createSubaccount()'s function signature doesn't match.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

stellar-base is written in pure JavaScript, so its source will never have true type annotations (aside from in the jsdoc). They're provided after-the-fact in index.d.ts, where id is in fact specified to be a string. I've also made sure of this in a test script (based on #653).

Aside: The true long-term fix here is to make Account an interface just like in the Go SDK, with AccountResponse (at the SDK level) and another Account plus MuxedAccount (at the base level) being three implementations of it, but that's a bigger investment (and a major version bump) for Later:tm:.

}
8 changes: 6 additions & 2 deletions src/server.ts
Expand Up @@ -655,9 +655,13 @@ export class Server {
}

/**
* Fetches an account's most current state in the ledger and then creates and returns an {@link Account} object.
* Fetches an account's most current state in the ledger, then creates and
* returns an {@link AccountResponse} object.
*
* @param {string} accountId - The account to load.
* @returns {Promise} Returns a promise to the {@link AccountResponse} object with populated sequence number.
*
* @returns {Promise} Returns a promise to the {@link AccountResponse} object
* with populated sequence number.
*/
public async loadAccount(accountId: string): Promise<AccountResponse> {
const res = await this.accounts()
Expand Down