Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
philipliu committed Nov 16, 2023
1 parent c624675 commit 4a77a64
Show file tree
Hide file tree
Showing 10 changed files with 202 additions and 345 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Using the Payment Observer allows you to delegate this step to the Anchor Platform. To enable the Payment Observer, use the `--stellar-observer` flag in the command section of the [compose file](#configuration).

The Payment Observer will track all transactions sent to the distribution account. When the transaction with the expected memo is detected in the network, the status will automatically change to `pending_anchor` and event will be the emitted (if Kafka is used).

In order to update the transaction's statuses, the observer makes corresponding JSON-RPC requests to the platform. It should use the following URL.

<CodeExample>

```bash
# dev.env
PLATFORM_API_BASE_URL=http://platform-server:8085
```

</CodeExample>

:::caution

The Payment Observer won't validate the amounts. It's your responsibility to verify that the amount sent by the user is correct.

:::

:::info

If you already have a system that monitors payments, make sure that the logic of the system matches the description below:

First, wait for the transaction to be included in the ledger (using an SDK). This transaction must have the expected memo and destination address (distribution account). Once this transaction has been detected and verified, notify the user that the funds have been received using the [notify_onchain_funds_received](#onchain-funds-received) JSON-RPC request.

:::

:::tip

The Fireblocks custody service will automatically track transactions and notify the user that the funds have been received. See the [Fireblocks custody service documentation][fireblocks] for more details.

:::

[fireblocks]: /docs/category/fireblocks
16 changes: 16 additions & 0 deletions docs/anchoring-assets/anchor-platform/component/rpc/error.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div>

| Error code | Meaning |
| :--------- | :------------------------------------------- |
| -32600 | The JSON sent is not a valid Request object |
| -32601 | The method does not exist / is not available |
| -32602 | Invalid method parameter(s) |
| -32603 | Internal JSON-RPC error |

</div>

:::tip

We will also reference a `$transaction_id` variable. This is an identification of transaction that is being returned from the Anchor Platform on an withdrawal or deposit start request. You can obtain the transaction ID by connecting the test wallet to your local Anchor Platform instance.

:::
29 changes: 29 additions & 0 deletions docs/anchoring-assets/anchor-platform/component/rpc/request.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
The Request object must contain the following attributes:

<AttributeTable>

- ATTRIBUTE
- DATA TYPE
- DESCRIPTION
- jsonrpc
- string
- A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0"
- method
- string
- A String containing the name of the method to be invoked. List of available methods you can see in [JSON-RPC Methods][json-rpc-methods]
- params
- object
- A Structured value that holds the parameter values, corresponding to method call, to be used during the invocation of the method
- id
- string
- An identifier established by the client. The Server will reply with the same value in the Response object

</AttributeTable>

:::tip

It's possible to provide multiple updates in a single JSON-RPC request (by placing multiple JSON-RPC request objects). When an update is done in this way, all updates will be done sequentially.

Most importantly, each JSON-RPC request is not atomic. If one update fails, all previous updates WILL be applied and all subsequent updates WILL be processed and applied as well.

:::
33 changes: 33 additions & 0 deletions docs/anchoring-assets/anchor-platform/component/rpc/response.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
The Response is expressed as a single JSON Object, with the following attributes:

<AttributeTable>

- ATTRIBUTE
- DATA TYPE
- DESCRIPTION
- jsonrpc
- string
- A String specifying the version of the JSON-RPC protocol. It's set to "2.0"
- result
- object
- A Structured value that holds the updated transaction details
- id
- string
- An identifier sent by the client
- error
- object
- A Structured value that holds the error details
- id
- string
- Unique id of the transaction for which an error occurred
- code
- number
- A number that indicates the error type that occurred. Please see a list of [error codes](#error-codes) below
- message
- string
- A String providing a short description of the error
- data
- string
- A primitive or structured value that contains additional information about the error

</AttributeTable>
17 changes: 17 additions & 0 deletions docs/anchoring-assets/anchor-platform/component/rpc/rpc.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Before making JSON-RPC requests, let's first create a template for making a request to the Anchor Platform.

<CodeExample>

```bash
# call-json-rpc.sh
#!/usr/bin/env bash

curl localhost:8085 \
-X POST \
-H 'Content-Type: application/json' \
--data "@$1"
```

</CodeExample>

This small script will make a JSON-RPC request to the Anchor Platform hosted on the default port (8085). JSON transaction data stored in the provided file will be used as body (requests must be an array).
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
To enable API key authentication, modify your `dev.env` file:

<CodeExample>

```bash
# dev.env
PLATFORM_SERVER_AUTH_TYPE=api_key
# Will be used as API key
SECRET_PLATFORM_API_AUTH_SECRET="your API key that business server will use"
```

</CodeExample>

After it's enabled, all requests must contain a valid `X-Api-Key` header, set to the configured API key.
14 changes: 14 additions & 0 deletions docs/anchoring-assets/anchor-platform/component/security/jwt.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
To enable API key authentication, modify your `dev.env` file:

<CodeExample>

```bash
# dev.env
PLATFORM_SERVER_AUTH_TYPE=api_key
# Will be used as API key
SECRET_PLATFORM_API_AUTH_SECRET="your API key that business server will use"
```

</CodeExample>

After it's enabled, all requests must contain a valid `X-Api-Key` header, set to the configured API key.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
:::caution

By default, the Platform API's endpoints such as `GET /transactions` and `GET /transactions/:id` are not protected, and are accessible by anyone who has access to the server, including wallet applications.

:::

:::info

It's recommended to keep Platform server accessible only from the private network. However, you may want to add additional layer of protection via securing the API.

:::
Loading

0 comments on commit 4a77a64

Please sign in to comment.