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

clients/horizonclient: Add support for Accounts endpoint. #2229

Merged

Conversation

abuiles
Copy link
Contributor

@abuiles abuiles commented Feb 5, 2020

PR Checklist

PR Structure

  • This PR has reasonably narrow scope (if not, break it down into smaller PRs).
  • This PR avoids mixing refactoring changes with feature changes (split into two PRs
    otherwise).
  • This PR's title starts with name of package that is most changed in the PR, ex.
    services/friendbot, or all or doc if the changes are broad or impact many
    packages.

Thoroughness

  • This PR adds tests for the most critical parts of the new functionality or fixes.
  • I've updated any docs (developer docs, .md
    files, etc... affected by this change). Take a look in the docs folder for a given service,
    like this one.

Release planning

  • I've updated the relevant CHANGELOG (here for Horizon) if
    needed with deprecations, added features, breaking changes, and DB schema changes.
  • I've decided if this PR requires a new major/minor version according to
    semver, or if it's mainly a patch change. The PR is targeted at the next
    release branch if it's not a patch change.

What

Extend the horizonclient to support accounts filtering. It allows account retrieval by signer or with a trustline to an asset.

	client := horizonclient.DefaultPublicNetClient
        accountID := "GCLWGQPMKXQSPF776IU33AH4PZNOOWNAWGGKVTBQMIC5IMKUNP3E6NVU"
	accountsRequest := horizonclient.AccountsRequest{Signer: accountID}

	account, err := client.Accounts(accountsRequest)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Print(account)

Why

This is part of the work in #2014, which is required to have full compatibility with Horizon 1.0.

Known limitations

[TODO or N/A]

Extend the horizonclient to support accounts filter. It allows you to
retrive all the accounts with a given signer or with a trustline to an
asset.

```go
	client := horizonclient.DefaultPublicNetClient
	accountsRequest := horizonclient.AccountsRequest{Signer: "GCLWGQPMKXQSPF776IU33AH4PZNOOWNAWGGKVTBQMIC5IMKUNP3E6NVU"}

	account, err := client.Accounts(accountsRequest)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Print(account)
```
Copy link
Member

@ire-and-curses ire-and-curses left a comment

Choose a reason for hiding this comment

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

Looks like it does the right thing, just a couple of comments

clients/horizonclient/client.go Outdated Show resolved Hide resolved
clients/horizonclient/main.go Outdated Show resolved Hide resolved
Limit uint
}

// AccountRequest struct contains data for making requests to the show account endpoint of a horizon server.
Copy link
Member

Choose a reason for hiding this comment

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

It doesn't seem great that we have two structs with very similar names AccountsRequest vs AccountRequest. Is there something we can do to name them more clearly?

Copy link
Member

Choose a reason for hiding this comment

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

(I don't really like the plural name AccountsRequest`)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ire-and-curses I agree with you, initially I thought about following a similar approach for EffectRequest, but it seems to me that we are trying to do too much with those structs.

That said though, we could be consistent and try to follow a similar approach. Basically extend the AccountRequest struct to also take ForSigner and ForAsset. When called through client.Accounts they will be the only fields we look at + Page params, ignoring the rest.

I personally don't like that interface, but it is consistent with how the other *Request like structs behave.

Copy link
Member

Choose a reason for hiding this comment

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

I think this is okay given that we can't make it more consistent with other functions without it being backwards compatible, and the alternatives of smooshing the two types together into a single shared types would be worse and could result in bad human errors. The compiler will make sure the caller uses the right type so whilst there might be some confusion with similar named types any errors arising from that should be prevented.

abuiles and others added 3 commits February 5, 2020 15:09
Co-Authored-By: Eric Saunders <ire-and-curses@users.noreply.github.com>
@abuiles abuiles merged commit f7d9abc into stellar:release-horizonclient-v2.1.0 Feb 5, 2020
@abuiles abuiles deleted the accounts-support branch February 5, 2020 21:38
abuiles added a commit that referenced this pull request Feb 19, 2020
* clients/horizonclient: Add support for Accounts endpoint.

Extend the horizonclient to support accounts filter. It allows you to
retrive all the accounts with a given signer or with a trustline to an
asset.

```go
	client := horizonclient.DefaultPublicNetClient
	accountsRequest := horizonclient.AccountsRequest{Signer: "GCLWGQPMKXQSPF776IU33AH4PZNOOWNAWGGKVTBQMIC5IMKUNP3E6NVU"}

	account, err := client.Accounts(accountsRequest)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Print(account)
```

* Apply suggestions from code review

Co-Authored-By: Eric Saunders <ire-and-curses@users.noreply.github.com>

* Remove if.

* Typos.

Co-authored-by: Eric Saunders <ire-and-curses@users.noreply.github.com>
abuiles added a commit that referenced this pull request Feb 25, 2020
* clients/horizonclient: Add support for Accounts endpoint.

Extend the horizonclient to support accounts filter. It allows you to
retrive all the accounts with a given signer or with a trustline to an
asset.

```go
	client := horizonclient.DefaultPublicNetClient
	accountsRequest := horizonclient.AccountsRequest{Signer: "GCLWGQPMKXQSPF776IU33AH4PZNOOWNAWGGKVTBQMIC5IMKUNP3E6NVU"}

	account, err := client.Accounts(accountsRequest)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Print(account)
```

* Apply suggestions from code review

Co-Authored-By: Eric Saunders <ire-and-curses@users.noreply.github.com>

* Remove if.

* Typos.

Co-authored-by: Eric Saunders <ire-and-curses@users.noreply.github.com>
abuiles added a commit that referenced this pull request Feb 29, 2020
* clients/horizonclient: Add support for Accounts endpoint.

Extend the horizonclient to support accounts filter. It allows you to
retrive all the accounts with a given signer or with a trustline to an
asset.

```go
	client := horizonclient.DefaultPublicNetClient
	accountsRequest := horizonclient.AccountsRequest{Signer: "GCLWGQPMKXQSPF776IU33AH4PZNOOWNAWGGKVTBQMIC5IMKUNP3E6NVU"}

	account, err := client.Accounts(accountsRequest)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Print(account)
```

* Apply suggestions from code review

Co-Authored-By: Eric Saunders <ire-and-curses@users.noreply.github.com>

* Remove if.

* Typos.

Co-authored-by: Eric Saunders <ire-and-curses@users.noreply.github.com>
abuiles added a commit that referenced this pull request Apr 7, 2020
* clients/horizonclient: Add support for Accounts endpoint.

Extend the horizonclient to support accounts filter. It allows you to
retrive all the accounts with a given signer or with a trustline to an
asset.

```go
	client := horizonclient.DefaultPublicNetClient
	accountsRequest := horizonclient.AccountsRequest{Signer: "GCLWGQPMKXQSPF776IU33AH4PZNOOWNAWGGKVTBQMIC5IMKUNP3E6NVU"}

	account, err := client.Accounts(accountsRequest)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Print(account)
```

* Apply suggestions from code review

Co-Authored-By: Eric Saunders <ire-and-curses@users.noreply.github.com>

* Remove if.

* Typos.

Co-authored-by: Eric Saunders <ire-and-curses@users.noreply.github.com>
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