Skip to content

Commit

Permalink
Fix up federation server config examples, describe dropping `reverse-…
Browse files Browse the repository at this point in the history
…federation` field
  • Loading branch information
Mr0grog committed Aug 24, 2016
1 parent eb51291 commit 5d66cb8
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions services/federation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ By default this server uses a config file named `federation.cfg` in the current
* `port` - server listening port
* `database`
* `type` - database type (sqlite3, mysql, postgres)
* `dsn` - The DSN (data source name) used to connect to the database connection. This value should be appropriate for the databse type chosen.
* `dsn` - The DSN (data source name) used to connect to the database connection. This value should be appropriate for the database type chosen.
* `queries`
* `federation` - Implementation dependent query to fetch federation results, should return either 1 or 3 columns. These columns should be labeled `id`,`memo`,`memo_type`. Memo and memo_type are optional - see [Federation](https://www.stellar.org/developers/learn/concepts/federation.html) docs for more detail). When executed, this query will be provided with two input parameters, the first will be the name portion of a stellar address and the second will be the domain portion of a stellar address. For example, a request for `scott*stellar.org` would trigger a query with two input parameters, `scott` and `stellar.org` respectively.
* `reverse-federation` - A SQL query to fetch reverse federation results that should return two columns, labeled `name` and `domain`. When executed, this query will be provided with one input parameter, a [stellar account ID](https://www.stellar.org/developers/guides/concepts/accounts.html#account-id) used to lookup the name and domain mapping.

If reverse-lookup isn't supported (e.g. you have a single Stellar account for all users), leave this entry out.

* `tls` (only when running HTTPS server)
* `certificate-file` - a file containing a certificate
* `private-key-file` - a file containing a matching private key
Expand All @@ -42,16 +45,16 @@ type = "mysql"
url = "root:@/dbname"

[queries]
federation = "SELECT account_id as id FROM Users WHERE username = ?"
reverse-federation = "SELECT username as name FROM Users WHERE account_id = $1"
federation = "SELECT account_id as id FROM Users WHERE username = ? AND domain = ?"
reverse-federation = "SELECT username as name, domain FROM Users WHERE account_id = ?"
```


### #2: Single Stellar account for all incoming transactions

If you have a single Stellar account for all incoming transactions you need to use `memo` to check which internal account should receive the payment.

Let's say that your Stellar account ID is: `GAHG6B6QWTC3YNJIKJYUFGRMQNQNEGBALDYNZUEAPVCN2SGIKHTQIKPV` and every user has an `id` and `username` in your database. Then your `queries` section could look like this:
Let's say that your Stellar account ID is: `GD6WU64OEP5C4LRBH6NK3MHYIA2ADN6K6II6EXPNVUR3ERBXT4AN4ACD` and every user has an `id` and `username` in your database. Then your `queries` section could look like this:

```toml
port = 8000
Expand All @@ -62,16 +65,16 @@ url = "root:@/dbname"

[queries]
federation = "SELECT username as memo, 'text' as memo_type, 'GD6WU64OEP5C4LRBH6NK3MHYIA2ADN6K6II6EXPNVUR3ERBXT4AN4ACD' as id FROM Users WHERE username = ? AND domain = ?"
reverse-federation = "SELECT username as name, domain FROM Users WHERE account_id = ?"
# No entry for `reverse-federation` since a reverse-lookup isn't possible
```

## Providing federation for a single domain

In the event that your organization only wants to offer federation for a single domain, a little bit of trickery can be used to configure your queries to satisfy this use case. For example, let's say you own `acme.org` and want to provide only results for that domain. The following example config illustrates:

```toml
federation = "SELECT username as memo, 'text' as memo_type, 'GD6WU64OEP5C4LRBH6NK3MHYIA2ADN6K6II6EXPNVUR3ERBXT4AN4ACD' as id FROM Users WHERE username = ? AND ? = 'acme.org"
reverse-federation = "SELECT username as name, 'acme.org' FROM Users WHERE account_id = ?"
federation = "SELECT username as memo, 'text' as memo_type, 'GD6WU64OEP5C4LRBH6NK3MHYIA2ADN6K6II6EXPNVUR3ERBXT4AN4ACD' as id FROM Users WHERE username = ? AND ? = 'acme.org'"
reverse-federation = "SELECT username as name, 'acme.org' as domain FROM Users WHERE account_id = ?"
```

Notice that SQL fragment `? = 'acme.org"` on the `federation` query: It ensures the incoming query is for the correct domain. Additionally, the `reverse-federation` query always returns `acme.org` for the domain.
Expand Down

0 comments on commit 5d66cb8

Please sign in to comment.