diff --git a/README.md b/README.md
index 559988b180..a0c83057b2 100644
--- a/README.md
+++ b/README.md
@@ -5,6 +5,8 @@ This Ripple Developer Portal is focused solely on documentation for the [`ripple
The documentation is stored in the "API.md" file in the root of the `ripple-dev-portal` repository. Versioning for the documentation will match the tagged release version for `ripple-rest`.
-### The ripple-dev-portal is currently hosted at https://dev.ripple.com ###
+### The ripple-dev-portal is currently hosted at https://dev.ripple.com ###
+
+
diff --git a/css/custom.css b/css/custom.css
index 8be32bbc78..389cf92d69 100644
--- a/css/custom.css
+++ b/css/custom.css
@@ -44,6 +44,10 @@ body .content-root {
padding-top: 10px;
}
+.content img {
+ width: 100%;
+}
+
.menubar {
padding-top: 10px;
}
@@ -57,6 +61,11 @@ body .content-root {
.header-subnav li a:active {
color: #f09 !important;
}
+
+.content a[title="Source"] {
+ float:right;
+}
+
/* Brand Guidelines */
.brand_guidelines .content-root {
@@ -239,4 +248,4 @@ consensus whitepaper
font-size: 24px;
text-align: center;
padding: 5px;
-}
\ No newline at end of file
+}
diff --git a/gatewayd.html b/gatewayd.html
new file mode 100644
index 0000000000..fd815d4af2
--- /dev/null
+++ b/gatewayd.html
@@ -0,0 +1,176 @@
+
+
+
+
+
+
diff --git a/gatewayd.md b/gatewayd.md
index 269a24c98b..8767a8f48e 100644
--- a/gatewayd.md
+++ b/gatewayd.md
@@ -1,17 +1,17 @@
-# gatewayd #
+# About Gatewayd #
Gatewayd (pronounced "gateway-dee"), provides a framework you can extend to build a gateway on the Ripple Network. The system includes a core database that manages accounting for deposits and withdrawals of assets, linking the network with your holdings in the outside world. Gatewayd provides a standard interface for issuing any currency on the Ripple network and exchange, with the goal of completely abstracting interaction with Ripple.
-Interact with the gatewayd by building custom integrations with banking and payment systems around the world, and by using the built-in APIs for designing beautiful gateway mobile apps and user interfaces. A HTTP/JSON server, Javascript library, and commandline interface are provided as interfaces to the gatewayd software.
+Interact with the gatewayd by building custom integrations with banking and payment systems around the world, and by using the built-in APIs for designing beautiful gateway mobile apps and user interfaces. Gatewayd includes a REST API, Javascript library, and commandline interface; developers can also interact with Gatewayd by directly modifying the database records it monitors.
Gatewayd's features include:
- - user registration
- deposits and withdrawals
- issuing currency
- - robust Ripple payment sending
+ - robust Ripple payment sending
- incoming Ripple payment monitoring
- gateway administration
+ - support for custom plugins
## Dependencies
@@ -25,7 +25,7 @@ Gatewayd's features include:
- For local development on Mac the simplest installation is via the [Postgres App](http://postgresapp.com/) by Heroku.
- On Linux, you can generally install Postgres from your distro's package manager. See instructions for:
- [Ubuntu](https://help.ubuntu.com/community/PostgreSQL)
- - [Debian](http://www.postgresql.org/download/linux/debian/)
+ - [Debian](https://wiki.debian.org/PostgreSql)
- [Red Hat, Fedora, CentOS](http://www.postgresql.org/download/linux/redhat/)
- [SuSE](http://www.postgresql.org/download/linux/suse/)
- [Arch Linux](https://wiki.archlinux.org/index.php/Postgres)
@@ -34,35 +34,174 @@ Gatewayd's features include:
- The Ripple REST API provides a simplified HTTP/JSON interface to all the Ripple protocol network operations, such as payments and other transactions.
4. [git](http://git-scm.com/) is required for installation and updating. It is not used during general operation.
+## Gatewayd Architecture ##
+
+A gateway acts as a link between Ripple's shared global Ledger and value outside of the network, such as traditional banking balances, other virtual currencies, or more. Thus, gatewayd sits between the `rippled` server (which participates in the network that defines the Ripple global ledger) and some source of information about external activities. Gatewayd's main job is to monitor each side for transactions and translate them into the appropriate actions on the other side.
+
+Gatewayd has effectively 4 queues: an inbox and outbox for transactions going from the outside world into the Ripple Network; and a corresponding inbox and outbox for transactions going the opposite direction. It has 2 software services for sending and receiving Ripple transactions, and 2 more services for converting between Ripple transactions and external transactions. In order to have a fully functional gateway, you must add custom code for sending and receiving transactions in the outside world. Naturally, these vary depending on how your gateway accepts outside payment.
+
+You can visualize Gatewayd's architecture according to the following diagram:
+
+
+
+### External Connector ###
+
+The external connector is a piece of custom code that ties Gatewayd to the outside system that is specific to you, the gateway operator. It might connect to your unique in-house banking system, or it might just be a script that monitors your PayPal account. As far as Gatewayd is concerned, it does not matter.
+
+The external connector has three tasks: submitting external deposits to gatewayd, monitoring gatewayd for outgoing withdrawals, and clearing outgoing withdrawals when finished. You can build a connector that handles those functions in a few different ways. Feel free to choose whichever suits your needs best:
+
+* You can build a process plugin in Javascript that runs as part of gatewayd. The [gatewayd Github organization](https://github.com/gatewayd/) maintains a list of existing plugins, including ones for existing payment networks.
+* You can build your own service that consumes [Gatewayd's REST API](#gatewayd-api). In that case, you'll use the [Record Deposit](#record-deposit), [List Pending Withdrawals](#list-pending-withdrawals), and [Clear Pending Withdrawal](#clear-pending-withdrawal) API methods.
+* You can access Gatewayd's database directly. This may be convenient if your existing software already manages SQL databases. You should have a good understanding of Gatewayd's [Data Models](#data-models) if you do this.
+
+### Gatewayd Services ###
+
+Gatewayd is implemented as a [Node.js](http://nodejs.org/) web application that keeps track of transactions that are entering and leaving the Ripple Network, and exposes a RESTful API for configuring and controlling its behavior. It persists transactions to a [Postgres database](http://www.postgresql.org/). This application has 6 main processes that comprise its operation:
+
+| Process | Purpose |
+|---------|---------|
+| server | Provides the RESTful API for controlling gatewayd and querying about its status; also serves a ripple.txt file to identify the gateway. |
+| ripple-rest | The [Ripple-REST](ripple-rest.html) service that communicates with a `rippled` server. |
+| incoming | Monitors the Ripple Network for incoming Ripple payments |
+| withdrawals | Converts records of incoming Ripple payments into pending withdrawal records |
+| outgoing | Sends pending Ripple payments out to the network to issue balances |
+| deposits | Converts records of external deposits into pending Ripple payments |
+
+You can get a list of services and their status by running the following command:
+
+ pm2 list
+
+[Plugins](https://github.com/gatewayd/) may provide additional services that also appear in this list.
+
+### Data Models ###
+
+[[Source] ](https://github.com/ripple/gatewayd/tree/master/lib/data/models "Source")
+
+One of the key aspects of Gatewayd is that it keeps records of all the transactions that go in and out of the gateway, which get persisted to the database. Gatewayd is intentionally designed so that you can manually view and modify the database records if you want to. The important data models are defined as in the following diagram:
+
+
+
+In short, the key data models are: External Account, Ripple Address, User, External Transaction, and Ripple Transaction. It's important to note that incoming and outgoing transactions of the same type (Ripple or External) are persisted to a single, shared database table.
+
+All tables have the following common fields:
+
+| Field | Type | Description |
+| ----- | -----| ----------- |
+| `id` | Integer (auto-increment) | A unique identifier for each row |
+| `uid`| String (unique) | A unique string identifier, which can be arbitrarily set. |
+| `data` | String | Any arbitrary data. If the contents of this field can be parsed as JSON, then it is represented as JSON in Gatewayd; otherwise, it is treated as a string. |
+
+#### User, Ripple Address, and External Account Models ####
+
+A user is a fundamental unit of identity for your gateway's customers; these persist to the *User* table. Each user is linked to any number of External Accounts as well as any number of Ripple Addresses, which are persisted to their own tables.
+
+*Note:* The User model is expected to change dramatically in future versions of of Gatewayd. The current model should be considered DEPRECATED.
+
+In addition to the common fields, the User model has the following:
+
+| Field | Type | Description |
+| ----- | -----| ----------- |
+| `active` | Boolean | Whether or not this user is marked as activated. (This status is not currently enforced in any way.) |
+| `admin` | Boolean | Unused. |
+| `external_id` | String | Arbitrary value used to identify this user in an external system |
+| `federation_name` | String | Federation name for the user. |
+| `federation_tag` | String | Federation tag for the user. |
+| `kyc_id` | Integer | Reference to entry in KYC table with info about this customer |
+| `password_hash` | String | Hashed version of this user's password (Optional) |
+| `salt` | String | Cryptographic salt used when hashing this user's password. |
+
+The [Register User](#register-user) API method creates new users, along with their corresponding external account and Ripple account records.
+
+#### External Transaction Model ####
+
+The External Transactions table holds both incoming deposits and outgoing withdrawals. In addition to the common fields, it has the following:
+
+| Field | Type | Description |
+| ----- | -----| ----------- |
+| `deposit` | boolean | Defines which type of transaction this is (*true* means deposit, *false* means withdrawal).
+| `amount` | Decimal | The size of the external payment |
+| `currency` | String | The currency of the external payment
+| `status` | String (Enum) | What state the transaction is in, such as pending or completed.
+| `ripple_transaction_id` | Integer | Reference to a corresponding Ripple transaction. |
+
+The [Record Deposit API method](#record-deposit) creates new deposit records; the [withdrawals process](#gatewayd-services) automatically creates new withdrawal records when it finds unprocessed incoming Ripple payments.
+
+#### Ripple Transaction Model ####
+
+The Ripple Transactions table holds incoming and outgoing Ripple payments. The direction of the payment is determined by which of the `to_address_id` and `from_address_id` fields references a Gateway wallet (hot or cold). In addition to the common fields, it has the following:
+
+| Field | Type | Description |
+| ----- | -----| ----------- |
+| `to_address_id` | Integer | Reference to the Ripple address receiving the payment |
+| `from_address_id` | Ineger | Reference to the Ripple address sending the payment |
+| `to_amount` | Decimal | Amount of money the recipient got |
+| `to_currency` | String | What currency the recipient got |
+| `to_issuer` | String | The Ripple Account that issued the currency received on the Ripple Network. (In the case of outgoing payments, this would be the cold wallet |
+| `from_amount` | Decimal | Amount of money the sender spent |
+| `from_currency`| String | What currency the sender used |
+| `from_issuer` | String | The Ripple Account that issued the currency sent on the Ripple Network. (This may be different than the currency received if there were other parties in the middle of the transaction.) |
+| `transaction_state` | String (Enum) | What state a transaction is in, such as pending or completed.
+| `transaction_hash` | String | The unique identifier of the transaction in the Ripple Network. |
+| `external_transaction_id` | Integer | Reference to a corresponding external transaction. |
+
+The [incoming process](#gatewayd-services) automatically creates records for new Ripple transactions by polling the Ripple-REST server; the [deposits process](#gatewayd-services) automatically creates new outgoing Ripple payments when it finds unprocessed external deposits.
+
+#### Future Models ####
+
+*Note:* As development on Gatewayd continues, the data model is expected to change. In particular, we expect to create a "Gateway Transaction" object to link External and Ripple transactions, and a "Policy" object that links a Gateway Transaction to the business logic of executing it (for example, setting custom fees for different types of actions or different customers).
+
+## Authentication ##
+
+Gatewayd has a powerful API, so it's important to keep it secure from unauthorized access: customers should not access Gatewayd directly. We expect that you will access Gatewayd's REST API through an application server that also provides a customer-facing interface. This could be an existing mobile app or website, or it could be entirely new. If you're building a new one, you could even build it as a process plugin that uses the same Node.js server as Gatewayd. You might also access the API from a simple HTTP client for testing and development purposes. You might not even use the API at all.
+
+Depending on your situation, there are some configuration variables you can set:
+
+* The `HTTP_SERVER` option (on by default) defines whether or not Gatewayd runs a REST API. If you don't use the REST API at all, you can turn it off entirely to reduce your risk profile.
+* The `HOST` option defines the interface where Gatewayd's REST API should listen for connections. This can be the hostname or IP address of the server if you are connecting externally, or "localhost" or "127.0.0.1" to listen only to connections on the same machine (either by a local proxy or directly for development).
+* The `SSL` option (on by default) defines whether or not the REST API communicates over an encrypted transport, e.g. HTTPS instead of simple HTTP. We recommend *always* using SSL, unless you are only listening on localhost.
+ * Gatewayd comes with a self-signed certificate for SSL pre-configured. This is adequate for development use.
+ * For production use, you should set the `SSL_KEY_PATH` and `SSL_CERTIFICATE_PATH` settings to point at a certificate purchased from a trusted [CA](http://en.wikipedia.org/wiki/Certificate_authority).
+* The `BASIC_AUTH` option (on by default) defines whether or not the REST API requires a password to connect. We recommend *always* using this.
+ * The `KEY` option (not defined by default) sets the API key used for Basic Auth. You can authenticate by sending this API key as either the username or the password. (Previously, the username was required to be "admin@yourdomain.com", based Gatewayd's `DOMAIN` setting, and the API key was only accepted as the password.)
+ * You can generate a new `KEY` value with the [Set API Key](#set-api-key) method. (Use the commandline version if it's your first time.)
+
+*Exception:* Gatewayd's HTTP server also serves a `ripple.txt` response that imitates a text file, but is actually dynamically generated based on its current configuration. This route is intended to be public, and is not protected even when BASIC_AUTH is enabled. However, it is disabled if the `HTTP_SERVER` option is disabled.
+
+Gatewayd implements authentication using the [Passport Node.js Module](http://passportjs.org/), so if you are familiar with Passport, you can easily customize the authentication scheme for Gatewayd to fit your needs.
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/passport_auth.js "Source")
+
+### Production ###
+
+In a production environment, you will probably send requests to Gatewayd through a proxy server like [Nginx](http://nginx.com/), which could run on the same machine as Gatewayd. If the proxy is not on the same machine, you might need to configure Nginx and Gatewayd to share the same SSL cert. Alternatively, you could terminate SSL at Nginx or a load balancer and use HTTP over your internal network for the remaining hops, but we recommend [encrypting everything as a "defense-in-depth" strategy](http://arstechnica.com/information-technology/2013/11/googlers-say-f-you-to-nsa-company-encrypts-internal-network/).
+
+### Deprecated User-Auth Routes ###
+
+The User-Auth routes are deprecated and may be removed without further notice. These routes are available only if the `USER_AUTH` config option is enabled. In this case, the name and password associated with a user account are used for Basic-Auth on the User-Auth Routes instead of using the API key.
+
+## Hot Wallet, Cold Wallet, Trust ##
+
+When a gateway issues balances of non-XRP currencies on the Ripple Network, those balances become liabilities in the real world that must be covered when people redeem those balances as external withdrawals. Additionally, actual XRP balances are digital assets that can be stolen or lost. Gatewayd uses the concept of a "hot wallet" and a "cold wallet" to minimize the risk of losses for both categories. (In practice, there is no difference between the term "wallet" and "account" on Ripple.)
+
+The cold wallet is like your vault. It issues all your funds, and holds the bulk of your XRP assets. The secret key that is used for this wallet is kept offline, accessible to a few trusted operators. Every now and then, the cold wallet is used to refill the stores in the hot wallet.
+
+The hot wallet is like your cash register. It holds a small amount of funds at a time, and customers deal with it directly. The secret key for this wallet is, by necessity, stored on a server that is connected to the outside internet. (Specifically, it is stored in Gatewayd's config file.) The hot wallet can be replaced without affecting the balances already issued by the cold wallet and held by users.
+
+All issuances of non-XRP currency and assets come from the cold wallet; it effectively 'creates' the currency on the Ripple Network to mirror the deposits received via external transactions. Consequently, Ripple accounts (customers as well as the hot wallet) must trust the cold wallet account in order to hold currency issued by that gateway. (Trusting a gateway means that you believe its issuances are worth something.) Customers do not need to trust the hot wallet, and should not.
+
+Although you could send the issuances directly to customers from the account issuing them, that exposes you to risk: if the account issuing the currency is compromised, potentially unlimited issuances could be made on your behalf. Using a hot/cold wallet distinction decreases the chances that your issuing account will be compromised, because you can keep it safely offline while day-to-day business is happening. The hot wallet, which is exposed to the most risk, can only lose as much money as it holds.
+
+# Gatewayd Usage #
## Installation
- Comprehensive [installation script](https://github.com/ripple/gatewayd/blob/master/doc/install.md) for Ubuntu
-## Configuration ##
+- The Gateway Appliance virtual machine comes with Gatewayd already installed. (Update when the VM is public: How do you get the appliance and where is Gatewayd installed?)
-Before you can run gatewayd, you need to set up the appropriate accounts that will be used to store and send funds in the Ripple network. You also need to define which currencies your gateway issues. Beyond that, there are some options you can set if they set your needs.
-
-The defaults for all of gatewayd's settings are found in the file `config/config.js`. You can override any of those settings with your own values by editing them in the file `config/config.json`. Don't mix up these two files!
-
-### Hot Wallet, Cold Wallet, Trust ###
-
-When a gateway issues balances of non-XRP currencies on the Ripple Network, those balances become liabilities in the real world that must be covered when people redeem those balances as external withdrawals. Additionally, actual XRP balances are digital assets that can be stolen or lost, so it is important to take proper precautions to minimize the risk of losses. To accomplish this, gatewayd uses the concept of a "hot wallet" and a "cold wallet".
-
-The cold wallet is like your vault. It issues all your funds, and holds the bulk of your XRP assets. The secret key that is used for this wallet is kept offline, accessible to a few trusted operators.
-
-The hot wallet is like your cash register. It holds a small amount of funds at a time, and customers deal with it directly. The secret key for this wallet is, by necessity, stored on a server that is connected to the outside internet.
-
-All Issuances of non-XRP currency and assets come from the cold wallet; it effectively 'creates' the currency on the Ripple Network to mirror the deposits received from external transfers. Consequently, all Ripple accounts must trust the cold wallet account in order to hold currency issued by that gateway. (Trusting a gateway means that you believe its issuances are worth something.)
-
-Although you could send the Issuances directly from the cold wallet to customers, that exposes you to risk.
-
-## Updating
+## Updating ##
The update process for gatewayd may change in the future, but for now, updating to a new version follows this process:
-(Not totally sure about the commandline syntax for all of these
-
1. Use git to pull the `master` branch [from Github](https://github.com/ripple/gatewayd.git). (This assumes you created it by using `git clone` on the repository first.)
`git pull`
2. Install any new npm modules needed by the new version
@@ -73,227 +212,508 @@ The update process for gatewayd may change in the future, but for now, updating
`grunt migrate`
5. Restart the gatewayd processes. (This ends downtime)
`bin/gateway start`
+
+If you are using the Gateway Appliance virtual machine from Ripple Labs, there is a script to automatically update Gatewayd. (Where?)
-# Gatewayd Usage #
+## Configuration ##
-## Running gatewayd
+Before you can run gatewayd, you need to set up the appropriate accounts that will be used to store and send funds in the Ripple network. You also need to define which currencies your gateway issues. Beyond that, there are some options you can set if they fit your needs.
+
+The defaults for all of gatewayd's settings are found in the file `config/config.js`. You can override any of those settings with your own values by editing them in the file `config/config.json`, or by using the API methods for setting the configuration. (The API methods result in editing the `config/config.json` file anyway.) Don't edit the `config/config.js` file, since that only contains the defaults, and gets overridden in a software update.
+
+### Setting Up Wallets for gatewayd ###
+
+The actual process of configuring gatewayd with the appropriate accounts is easy. First, generate an account key pair for a cold wallet. You can use the official Ripple client to do so:
+
+[Ripple Client](https://ripple.com/client/#/register)
+
+*Note:* The key generation process in the Ripple Client happens on your local machine, and is never sent to Ripple or anyone else. You can even go offline while you generate the key (as long as you've fully loaded the page first).
+
+Save the secret key somewhere that it will be completely safe. Never send it unencrypted to an untrusted entity such as your web host.
+
+Now, set the address of the cold wallet in gatewayd using the commandline:
+
+ bin/gateway set_cold_wallet rsnCCioK33L19UwywUPoHK3ucTcQR2fpfm
+
+Next, generate a new key pair for the hot wallet account.
+
+ bin/gateway generate_wallet
+
+Set the address _and_ the secret key for the hot wallet in gatewayd using the commandline:
+
+ bin/gateway set_hot_wallet rhfyVnzjPvvtdnZNSiNufRCZhHpc9yh1rA ssmgxde6ozSViVkuWvsC6HJxpLvH4
+
+(*Tip:* Ripple addresses always start with `r`; Ripple secrets always start with `s`.)
+
+Define which currencies your gateway will support. (This does not include XRP, which is necessary for every Ripple account and gateway.) You can do this with the commandline as well. Run the `add_currency` command with the 3-letter ISO 4217 currency codes for whichever currencies you want to support:
+
+ bin/gateway add_currency USD
+ bin/gateway add_currency XAU
+
+Fund both accounts. This requires some outside source of XRP to send a payment to the address of each one. For now, we recommend at least 50 XRP. (Because it requires outside intervention, you cannot do this step with gatewayd.)
+
+At this point, you need to create trustlines between the hot and cold wallet accounts. You can also do this with the gatewayd commandline. Run the `set_trust` command, with reasonable maximum quantities that you want your hot wallet to hold at a time, for each currency you support.
+
+ bin/gateway set_trust USD 1000
+ bin/gateway set_trust XAU 2
+
+*Aside:* Keep in mind the very different values for currencies. In this example, the two troy ounces of gold (XAU 2) are, at the time of writing, worth approximately $2600 USD.) Fortunately, gatewayd supports very large and small numbers.
+
+The last step before you can start your gateway is to set the last payment hash. This indicates a cutoff point in time, where the gateway should monitor Ripple for payments that are newer and try to process them, but ignore payments that are older. To get a good starting value, look up the transaction history for the cold wallet and choose the most recent transaction.
+
+## Running gatewayd ##
After installation, start the gateway processes by running the command:
bin/gateway start
-## Gatewayd Architecture
-
-A gateway acts as a link between the Ripple Network and activities outside of the network, such as traditional banking activities. Thus, gatewayd sits between the `rippled` server (which participates in the network) and some source of information about external activities. (This could be custom banking software that is aware of deposits and withdrawals, or it could even be manually monitored.)
-
-Gatewayd is implemented as a [Node.js](http://nodejs.org/) web application that keeps track of transactions that are entering and leaving the Ripple Network, and exposes a RESTful API for configuring and controlling its behavior. It persists transactions to a [Postgres database](http://www.postgresql.org/). This application has 6 main processes that comprise its operation:
-
-| Process | Purpose |
-|---------|---------|
-| server | Provides the RESTful API for controlling gatewayd and querying about its status; also serves a ripple.txt file to identify the gateway. |
-| ripple-rest | Provides a [Ripple-REST](?p=ripple-rest-api) service that communicates with a `rippled` server. |
-| incoming | Monitors the Ripple Network for incoming Ripple payments |
-| withdrawals | Converts records of incoming Ripple payments into pending withdrawal records |
-| outgoing | Sends pending Ripple payments out to the network to issue balances |
-| deposits | Converts records of external deposits into pending Ripple payments |
-
-In essence, the `server` and `ripple-rest` processes are infrastructure, while the other four processes form two thirds of a complete two-way link between an outside network and the Ripple Network. The missing piece: integrations with the outside network. Naturally, these vary depending on the gateway and how it accepts outside payment. In other words: that part, you must build for yourself.
-
-Fortunately, all the pieces are here already. When you receive information about an external transaction, you can use gatewayd's API to record it as a deposit in your system. You can use gatewayd's API to look for new withdrawals, so that you can process them; and when you're done, just call gatewayd's API again to clear them. You can perform these calls manually (not recommended), you can write software that depends on gatewayd's API to do them, or you can skip the API and write to the Postgres database directly (also not recommended). If you like, you can even write the processes as additional Node.js services and incorporate them into gatewayd, to be run alongside the build-in processes.
-
-Conceptually, gatewayd processes two flows in opposite directions:
-
-* Outside world -> External Transaction Inbox -> Ripple Transaction Outbox -> Ripple
-* Ripple -> Ripple Transaction Inbox -> External Transaction Outbox -> Outside world
-
-However, the implementation combines the inboxes and outboxes for like objects into a single database table each, so one database table contains external transactions that are ingoing alongside ones that are outgoing; and another database table contains Ripple transactions in both states.
-
-That means that the overall process looks like this:
-
-
-
-(Probably need to revise this diagram somewhat.)
-
-## Process Flow of a Gateway Deposit
-
-### Process 1: Recording Deposits ###
-
-A banking API integration or manual human gateway operator receives the deposit of an asset and records the deposit in the ripple gateway data store. This process is designed to be implemented externally, and example implementations are provided by the command line interface and the http/json express.js server.
-
-API calls: [Create Deposit](#create-deposit)
-
-### Process 2: Deposit Business Logic ###
-
-A newly recorded deposit is handed to the business logic, which performs some function, ultimately en-queuing a corresponding ripple payment. This process is designed to be modified and customized.
-
- node processes/deposits.js
-
-API calls: [List Deposits](#list-deposits), [Enqueue Payment](#enqueue-payment) (missing??)
-
-### Process 3: Send Outgoing Ripple Payments ###
-
-A payment record resulting from the deposit business logic process is sent to the Ripple REST server, ultimately propagating to the network. This process is standard and should not be modified.
-
- node processes/outgoing.js
-
-API calls: [Send Payment](#send-payment) (also missing??)
-
-## Process Flow of a Gateway Withdrawal
-
-### Process 1: Record inbound Ripple payments ###
-
-Poll the Ripple REST server for new payment notifications to the gateway, and record the incoming payments in the ripple gateway data store. This process is standard and should not be modified.
-
- node processes/incoming.js
-
-API calls: [List Incoming Payments](#list-incoming-payments) (aka get_payment_notification??), record_payment(??)
-
-### Process 2: Withdrawal Business Logic ###
-
-A newly recorded incoming ripple payment is handed to the business logic, which performs some function, ultimately en-queuing a corresponding asset withdrawal record. This process is designed to be modified and customized.
-
- node processes/withdrawals.js
-
-API calls: enqueue_withdrawal
-
-### Process 3: Clear Withdrawals ###
-
-A banking API integration or manual human gateway operator reads the queue of pending withdrawals from the gateway data store, redeems the corresponding asset, and finally clears the withdrawal from the queue by updating the gateway data store. This process is designed to be implemented externally, and example implementations are provided by the command line interface and the http/json express.js server.
-
-API calls: list_withdrawals, clear_withdrawal
-
-Alternatively one can provide a WITHDRAWALS_CALLBACK_URL in the configuration, and then start the withdrawal_callbacks process to receive POST notifications whenever a new withdrawal comes in the gateway from the Ripple network. This process is currently not starte by default.
-
-
## Command Line Interface ##
-```
-bin/gateway [options] [command]
-```
+In addition to the REST interface, many pieces of Gatewayd can be controlled directly through the commandline. This is done by running the `gateway` script (`bin/gateway` from the project's top level directory) with the relevant commands.
-The available *options* are as follows:
+You can get usage information for the commandline as follows:
```
--h, --help output usage information
+bin/gateway -h
```
-
-The available commands are as follows:
-
-| Command Syntax | Description |
-|----------------|-------------|
-| `register_user ` | create a user with a ripple address |
-| `list_users` | list registered users |
-| `record_deposit ` | record a deposit in the deposit processing queue |
-| `list_deposits` | list deposits in the deposit processing queue |
-| `list_outgoing_payments` | list the outgoing ripple payments. |
-| `list_incoming_payments` | list unprocesses incoming ripple payments |
-| `list_withdrawals` | get pending withdrawals to external accounts |
-| `clear_withdrawal ` | clear pending withdrawal to external account |
-| `generate_wallet` | generate a random ripple wallet |
-| `set_hot_wallet ` | set the gateway hot wallet |
-| `get_hot_wallet` | get the address of the gateway hot wallet |
-| `get_hot_wallet_secret` | get the secret of the gateway hot wallet |
-| `fund_hot_wallet ` | issue funds from cold wallet to hot wallet |
-| `set_cold_wallet ` | set the gateway hot wallet |
-| `get_cold_wallet` | get the gateway cold wallet |
-| `refund_cold_wallet ` | send back funds from the hot wallet to cold wallet |
-| `set_trust ` | set level of trust from hot to cold wallet |
-| `get_trust_lines` | get the trust lines from hot wallet to cold wallet |
-| `list_currencies` | List all currencies supported by the gateway |
-| `add_currency ` | add support for a currency |
-| `remove_currency ` | remove support for a currency |
-| `set_domain ` | set the domain name of the gateway |
-| `get_domain` | get the domain name of the gateway |
-| `set_postgres_url ` | set the url of the postgres database |
-| `get_postgres_url` | get the url of the postgres database |
-| `set_ripple_rest_url ` | set the url of the Ripple-REST api |
-| `get_ripple_rest_url` | get the url of the Ripple-REST api |
-| `set_key` | set the admin api key |
-| `get_key` | get the admin api key |
-| `set_last_payment_hash ` | set the last encountered payment hash for incoming processing. |
-| `get_last_payment_hash` | get the last encountered payment hash for incoming processing. |
-
-# Gatewayd API #
+# Gatewayd API Reference #
+(Update this version number with the right one!)
`gatewayd : v3.20.0`
-## Available API Routes ##
+The API serves several purposes: it provides an easy way to customize settings without having to edit the config files directly; it provides access to status and historical information about all transactions made in the gateway; and it provides one avenue for building an [external connector](#external-connector).
-* [`POST /v1/registrations`](#registering-a-user)
-* [`POST /v1/users/{:id}/activate`](#activating-a-user)
-* [`POST /v1/users/{:id}`](#deactivating-a-user)
-* [`POST /v1/deposits/`](#creating-a-deposit)
-* [`GET /v1/deposits`](#listing-deposits)
-* [`GET /v1/payments/outgoing`](#listing-outgoing-payments)
-* [`GET /v1/payments/failed`](#listing-failed-payments)
-* [`POST /v1/payments/failed/{:id}/retry`](#retrying-a-failed-payment)
-* [`GET /v1/payments/incoming`](#listing-incoming-payments)
-* [`GET /v1/withdrawals`](#listing-withdrawals)
-* [`POST /v1/withdrawals/{:id}/clear`](#clearing-a-withdrawal)
-* [`GET /v1/cleared`](#listing-cleared-external-transactions)
-* [`GET /v1/balances`](#listing-hot-wallet-balances)
-* [`GET /v1/liabilities`](#listing-cold-wallet-liabilities)
+#### External Transactions ####
-## User-Auth API Routes
+* [Record Deposit - `POST /v1/deposits/`](#record-deposit)
+* [List Queued Deposits - `GET /v1/deposits`](#list-queued-deposits)
+* [List Pending Withdrawals - `GET /v1/withdrawals`](#list-pending-withdrawals)
+* [Clear Pending Withdrawal - `POST /v1/withdrawals/{:id}/clear`](#clear-pending-withdrawal)
+* [List Cleared External Transactions - `GET /v1/cleared`](#list-cleared-external-transactions)
-* [`POST /v1/register`](#registering-a-user)
-* [`POST /v1/users/login`](#logging-in-a-user)
-* [`GET /v1/users/{:id}`](#showing-a-user)
-* [`GET /v1/users/{:id}/external_accounts`](#listing-user-external-accounts)
-* [`GET /v1/users/{:id}/external_transactions`](#listing-user-external-transactions)
-* [`GET /v1/users/{:id}/ripple_addresses`](#listing-user-ripple-addresses)
-* [`GET /v1/users/{:id}/ripple_transactions`](#listing-user-ripple-transactions)
+#### User Management ####
-## Admin Configuration API Routes
+* [Register User - `POST /v1/registrations`](#register-user)
+* [Activate User - `POST /v1/users/{:id}/activate`](#activate-user)
+* [Deactivate User - `POST /v1/users/{:id}`](#deactivate-user)
-* [`POST /v1/wallets/hot/fund`](#funding-the-hot-wallet)
-* [`POST /v1/config/database`](#setting-the-database-url)
-* [`GET /v1/config/database`](#showing-the-database-url)
-* [`POST /v1/config/ripple/rest`](#setting-the-ripple-rest-url)
-* [`GET /v1/config/ripple/rest`](#showing-the-ripple-rest-url)
-* [`POST /v1/config/wallets/cold`](#setting-the-cold-wallet)
-* [`GET /v1/config/wallets/cold`](#showing-the-cold-wallet)
-* [`POST /v1/config/wallets/generate`](#generating-a-ripple-wallet)
-* [`POST /v1/config/wallets/hot`](#setting-the-hot-wallet)
-* [`GET /v1/config/wallets/hot`](#showing-the-hot-wallet)
-* [`POST /v1/trust`](#setting-trust-from-hot-wallet-to-cold-wallet)
-* [`GET /v1/trust`](#listing-trust-from-hot-wallet-to-cold-wallet)
-* [`POST /v1/wallets/hot/fund`](#funding-the-hot-wallet)
-* [`POST /v1/config/last_payment_hash`](#setting-the-last-payment-hash)
-* [`GET /v1/config/last_payment_hash`](#showing-the-last-payment-hash)
-* [`POST /v1/config/domin`](#setting-the-domain)
-* [`GET /v1/config/domain`](#showing-the-domain)
-* [`POST /v1/config/key`](#setting-the-api-key)
-* [`GET /v1/config/key`](#showing-the-api-key)
-* [`POST /v1/currencies`](#setting-currencies)
-* [`GET /v1/currencies`](#listing-currencies)
-* [`POST /v1/wallets/cold/refund`](#sending-funds-from-hot-wallet-to-cold-wallet)
-* [`POST /v1/start`](#starting-worker-processes)
-* [`POST /v1/processes`](#listing-current-processes)
+#### Ripple Transactions ####
-# API Method Reference #
+* [List Outgoing Payments - `GET /v1/payments/outgoing`](#list-outgoing-payments)
+* [List Failed Payments - `GET /v1/payments/failed`](#list-failed-payments)
+* [Retry Failed Payments - `POST /v1/payments/failed/{:id}/retry`](#retry-failed-payment)
+* [List Incoming Payments - `GET /v1/payments/incoming`](#list-incoming-payments)
-## Managing Users ##
+#### Ripple Management ####
-### Register User ###
-__`POST /v1/registrations`__
+* [Generate Ripple Wallet - `POST /v1/config/wallets/generate`](#generate-ripple-wallet)
+* [List Hot Wallet Balances - `GET /v1/balances`](#list-hot-wallet-balances)
+* [List Cold Wallet Liabilities - `GET /v1/liabilities`](#list-cold-wallet-liabilities)
+* [Fund Hot Wallet - `POST /v1/wallets/hot/fund`](#fund-hot-wallet)
+* [Return Funds from Hot Wallet to Cold Wallet - `POST /v1/wallets/cold/refund`](#return-funds-from-hot-wallet-to-cold-wallet)
+* [Set Trust from Hot Wallet to Cold Wallet - `POST /v1/trust`](#set-trust-from-hot-wallet-to-cold-wallet)
+* [Show Trust from Hot Wallet to Cold Wallet - `GET /v1/trust`](#show-trust-from-hot-wallet-to-cold-wallet)
-Register a user with the gatewayd. A username, password, and ripple address are required. Upon
-registration several records are created in the gatewayd database, including a user record,
-a "independent" ripple address record with the address provided, a "hosted" ripple address
-record for making withdrawals, and a "default" external account for recording deposits and
-withdrawals.
+#### Gatewayd Configuration ####
+
+* [Set Database URL - `POST /v1/config/database`](#set-database-url)
+* [Retrieve Database URL - `GET /v1/config/database`](#retrieve-database-url)
+* [Set Ripple-REST URL - `POST /v1/config/ripple/rest`](#set-ripple-rest-url)
+* [Retrieve Ripple-REST URL - `GET /v1/config/ripple/rest`](#retrieve-ripple-rest-url)
+* [Set Cold Wallet - `POST /v1/config/wallets/cold`](#set-cold-wallet)
+* [Retrieve Cold Wallet - `GET /v1/config/wallets/cold`](#retrieve-cold-wallet)
+* [Set Hot Wallet - `POST /v1/config/wallets/hot`](#set-hot-wallet)
+* [Retrieve Hot Wallet - `GET /v1/config/wallets/hot`](#retrieve-hot-wallet)
+* [Set Last Payment Hash - `POST /v1/config/last_payment_hash`](#set-last-payment-hash)
+* [Retrieve Last Payment Hash - `GET /v1/config/last_payment_hash`](#retrieve-last-payment-hash)
+* [Set Gateway Domain - `POST /v1/config/domin`](#set-gateway-domain)
+* [Retrieve Domain - `GET /v1/config/domain`](#retrieve-domain)
+* [Set API Key - `POST /v1/config/key`](#set-api-key)
+* [Retrieve API Key - `GET /v1/config/key`](#retrieve-api-key)
+* [Add Supported Currency - `POST /v1/currencies`](#add-supported-currency)
+* [List Supported Currencies - `GET /v1/currencies`](#list-supported-currencies)
+* [Remove Supported Currency - `DELETE /v1/currencies/{:currency}`](#remove-supported-currency)
+
+#### Gatewayd Processes ####
+
+* [Start Worker Processes - `POST /v1/start`](#start-worker-processes)
+* [List Current Processes - `POST /v1/processes`](#list-current-processes)
+
+#### User-Auth API Routes #####
+
+All these routes are **DEPRECATED**. Authentication for these routes works differently. See [Deprecated User-Auth Routes](#deprecated-user-auth-routes) for details.
+
+* [`POST /v1/users/login`](#log-in-user)
+* [`GET /v1/users/{:id}`](#retrieve-user)
+* [`GET /v1/users/{:id}/external_accounts`](#list-user-external-accounts)
+* [`GET /v1/users/{:id}/external_transactions`](#list-user-external-transactions)
+* [`GET /v1/users/{:id}/ripple_addresses`](#list-user-ripple-addresses)
+* [`GET /v1/users/{:id}/ripple_transactions`](#list-user-ripple-transactions)
+
+## External Transactions ##
+
+### Record Deposit ###
+
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/record_deposit.js "Source")
+
+
+*REST*
+
+```
+POST /v1/deposits
+{
+ "external_account_id": 307,
+ "currency": "BTC"
+ "amount": "10.7"
+ "data": "(This field is optional.)"
+}
+```
+
+*Commandline*
+
+```
+# Syntax: record_deposit
+$ bin/gateway record_deposit 95.29 USD 13
+```
+
+*Javascript*
+
+```
+//options: object with the following fields:
+// - external_account_id: unique ID of the depositor's external account record
+// - amount: numeric deposit amount
+// - currency: currency string (e.g. "USD")
+// - data: Arbitrary data in JSON/string format
+//callback: function(err, deposit) to run on callback
+gateway.api.recordDeposit(options, callback);
+```
+
+
+This method is the entry point to creating Ripple balances. When you receive
+an asset outside the Ripple Network from a user, you can call this method to
+create a "deposit" record in gatewayd's database tracking it. By default, the
+deposit record is marked as "queued", which means that gatewayd's deposit
+process will automatically apply fees and then enqueue an outgoing Ripple
+payment to the user's Ripple address.
+
+The most important field is the `external_account_id`, which references the
+external account record for the user making this deposit. This value is returned
+by the [Register User](#register-user) method when a user is created.
+
+Response Body:
+
+```
+{
+ "deposit": {
+ "data": null,
+ "external_account_id": 307,
+ "currency": "BTC",
+ "amount": "10.7",
+ "deposit": true,
+ "status": "queued",
+ "updatedAt": "2014-06-12T00:46:02.080Z",
+ "createdAt": "2014-06-12T00:46:02.080Z",
+ "id": 1,
+ "ripple_transaction_id": null,
+ "uid": null
+ }
+}
+```
+
+### List Queued Deposits ###
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/list_queued_deposits.js "Source")
+
+
+
+To retrieve assets from the gateway, a user sends funds back to the gateway's
+Ripple account. After the incoming payment has been received and processed
+(fees subtracted), it is placed in the pending withdrawals queue, which is a
+list of external transaction withdrawal records with a state of "pending". If
+the gateway administrator has registered a withdrawal callback url, the
+withdrawal callbacks process will read withdrawals from this list and
+POST their data to the callback url provided.
+
+This method retrieves the list of pending withdrawals.
+
+Response Body:
-Request Body:
```
{
- "name": "steven@ripple.com",
- "password": "s0m3supe&$3cretp@s$w0r*",
- "ripple_address": "r4EwBWxrx5HxYRyisfGzMto3AT8FZiYdWk"
+ "withdrawals": [
+ {
+ "data": null,
+ "id": 79,
+ "amount": "1001",
+ "currency": "SWD",
+ "deposit": false,
+ "external_account_id": 6,
+ "status": "queued",
+ "ripple_transaction_id": 80,
+ "createdAt": "2014-05-30T19:23:48.390Z",
+ "updatedAt": "2014-05-30T19:23:48.390Z",
+ "uid": null
+ },
+ {
+ "data": null,
+ "id": 84,
+ "amount": "8.5",
+ "currency": "SWD",
+ "deposit": false,
+ "external_account_id": 6,
+ "status": "queued",
+ "ripple_transaction_id": 85,
+ "createdAt": "2014-06-11T00:23:56.992Z",
+ "updatedAt": "2014-06-11T00:23:56.992Z",
+ "uid": null
+ }
+ ]
}
```
+### Clear Pending Withdrawal ###
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/clear_withdrawal.js "Source")
+
+
+*REST*
+
+```
+POST /v1/withdrawals/{:id}/clear
+{}
+```
+
+*Commandline*
+
+```
+# Syntax: clear_withdrawal
+$ bin/gateway clear_withdrawal 9
+```
+
+*Javascript*
+
+```
+//id: Unique integer ID of withdrawal to clear
+//callback: function(err, withdrawal) to run on callback
+gateway.api.clearWithdrawal(id, callback);
+```
+
+
+A pending withdrawal record indicates to the gateway operator that a
+user wishes to withdraw a given asset. Once the operator processes the
+withdrawal by sending the asset to the user, mark the withdrawal as "cleared"
+by calling this method.
+
+Response Body:
+
+```
+ {
+ "withdrawal": {
+ "data": null,
+ "id": 84,
+ "amount": "8.5",
+ "currency": "SWD",
+ "deposit": false,
+ "external_account_id": 6,
+ "status": "cleared",
+ "ripple_transaction_id": 85,
+ "createdAt": "2014-06-11T00:23:56.992Z",
+ "updatedAt": "2014-06-12T20:01:29.663Z",
+ "uid": null
+ }
+ }
+```
+
+### List Cleared External Transactions ###
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/list_cleared.js "Source")
+
+
+
+This method retrieves the list of all external transactions that are no longer
+considered pending. This includes all deposits that have been issued as a
+balance with a Ripple payment, and all withdrawals that have been cleared.
+
+*Note:* There is an apparent bug with this method, where both deposits and withdrawals are returned in the "deposits" field. (See [Issue #240](https://github.com/ripple/gatewayd/issues/240) for details and status.)
+
+Response Body:
+
+```
+{
+ "deposits": [
+ {
+ "data": null,
+ "id": 3,
+ "amount": "4.95",
+ "currency": "SWD",
+ "deposit": false,
+ "external_account_id": 1,
+ "status": "cleared",
+ "ripple_transaction_id": 3,
+ "createdAt": "2014-05-13T23:10:20.803Z",
+ "updatedAt": "2014-05-13T23:11:26.323Z",
+ "uid": null
+ },
+ {
+ "data": null,
+ "id": 5,
+ "amount": "2.9699999999999998",
+ "currency": "SWD",
+ "deposit": false,
+ "external_account_id": 1,
+ "status": "cleared",
+ "ripple_transaction_id": 5,
+ "createdAt": "2014-05-14T19:45:05.244Z",
+ "updatedAt": "2014-05-14T21:19:54.231Z",
+ "uid": null
+ }
+ ]
+}
+```
+
+## User Management ##
+
+### Register User ###
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/register_user.js "Source")
+
+
+
+Register a user with the gatewayd. A username, password, and ripple address
+are required. Upon registration several records are created in the gatewayd
+database, including a user record, a "independent" ripple address record with
+the address provided, a "hosted" ripple address record for making withdrawals,
+and a "default" external account for recording deposits and withdrawals.
+
+Use the `user.external_account.id` field of the response to link a future
+deposit to this user.
+
Response Body:
```
{
@@ -355,18 +775,37 @@ Response Body:
```
### Activate User ###
-__`POST /v1/users/{:id}/activate`__
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/activate_user.js "Source")
+
+
+*REST*
+
+```
+POST /v1/users/{:id}/activate
+{}
+```
+
+*Commandline*
+
+```
+# Syntax: activate_user
+$ bin/gateway activate_user 508
+```
+
+*Javascript*
+
+```
+//id: integer account ID
+//callback: function(err, user) to run on callback
+gateway.api.activateUser(id, callback)
+```
+
+
By default a user is marked as "inactive", although no action is taken to
enforce this status. To mark a user as active, run this command with the user's
ID.
-Request Body:
-
-```
-{}
-```
-
Response Body:
```
@@ -392,17 +831,36 @@ Response Body:
```
### Deactivate User ###
-__`POST /v1/users/{:id}/deactivate`__
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/deactivate_user.js "Source")
+
+
+*REST*
+
+```
+POST /v1/users/{:id}/deactivate
+{}
+```
+
+*Commandline*
+
+```
+# Syntax: deactivate user
+$ bin/gateway deactivate_user 508
+```
+
+*Javascript*
+
+```
+//id: integer account ID
+//callback: function(err, user) to run on callback
+gateway.api.deactivateUser(id, callback);
+```
+
+
To mark a user an "inactive", run this command with the user's ID. This flag is
purely for informational purposes and is not enforced in any way.
-Request Body:
-
-```
-{}
-```
-
Response Body:
```
@@ -427,226 +885,33 @@ Response Body:
}
```
-### Log In User ###
-__`POST /v1/users/login`__
-
-Verifies that a user has the correct username and password combination. Used
-for the web application and requires user credentials in place of an API key.
-
-Naturally, since this includes sensitive credentials, do not run this command
-over an unsecure connection.
-
-Request Body:
-
-```
-{
- "name": "steven@ripple.com",
- "password": "s0m3supe&$3cretp@s$w0r*"
-}
-```
-
-Response Body:
-Not sure if res.send({ user: user }); indicates
-that only the username is returned?
-
-### Retrieve User ###
-__`GET /v1/users/{:id}`__
-
-To retrieve a user's base account information, pass the user's ID to this
-method.
-
-Response Body:
-
-```
-{
- "success": true,
- "users": {
- "id": 8,
- "name": "steven@ripple.com",
- "salt": "1366f14307850818afddd1509f329fdc1a73fb93919d92d5b44c91f07560c999",
- "federation_tag": null,
- "admin": null,
- "federation_name": null,
- "password_hash": "dd1d5a0ba63c63a117ff811f14040fa87dcbfedd7e37b5df506bfc4e8014c8e5",
- "bank_account_id": null,
- "kyc_id": null,
- "createdAt": "2014-06-10T22:37:19.647Z",
- "updatedAt": "2014-06-10T22:37:19.647Z",
- "external_id": null,
- "data": null,
- "uid": null,
- "active": false
- }
-}
-```
-
-### List User External Accounts ###
-__`GET /v1/users/{:id}/external_accounts`__
-
-To list all external (non-Ripple) account records for a user, pass the user's
-ID to this method.
-
-Response Body:
-
-```
-{
- "external_accounts": [
- {
- "data": null,
- "id": 8,
- "name": "default",
- "user_id": 8,
- "createdAt": "2014-06-10T22:37:19.835Z",
- "updatedAt": "2014-06-10T22:37:19.835Z",
- "uid": null
- }
- ]
-}
-```
-
-### List User External Transactions ###
-__`GET /v1/users/{:id}/external_transactions`__
-
-List all external (non-Ripple) transaction records for a given user. These
-records are the user's deposits into the gateway and withdrawals from it.
-
-Response Body:
-
-```
-{
- "externalTransactions": [
- {
- "id": 80,
- "currency": "SWD",
- "amount": "1",
- "deposit": true,
- "ripple_transaction_id": 81,
- "external_account_id": 8,
- "status": "processed"
- },
- {
- "id": 81,
- "currency": "SWD",
- "amount": "1.5999",
- "deposit": true,
- "ripple_transaction_id": 82,
- "external_account_id": 8,
- "status": "processed"
- }
- ]
-}
-```
-
-### List User Ripple Addresses ###
-__`GET /v1/users/{:id}/ripple_addresses`__
-
-To list all ripple addresses for a given user, pass the user's ID to this
-method. Most users will have at least one independent address and one hosted
-address.
-
-Response Body:
-
-```
-{
- "rippleAddresses": [
- {
- "data": null,
- "id": 16,
- "managed": false,
- "address": "r4EwBWxrx5HxYRyisfGzMto3AT8FZiYdWk",
- "type": "independent",
- "user_id": 8,
- "tag": null,
- "secret": null,
- "previous_transaction_hash": null,
- "createdAt": "2014-06-10T22:37:19.825Z",
- "updatedAt": "2014-06-10T22:37:19.825Z",
- "uid": null
- },
- {
- "data": null,
- "id": 17,
- "managed": true,
- "address": "rDNP5C7Vjt2mLushCmUPwm6dvwNzNiuND6",
- "type": "hosted",
- "user_id": 8,
- "tag": 8,
- "secret": null,
- "previous_transaction_hash": null,
- "createdAt": "2014-06-10T22:37:19.844Z",
- "updatedAt": "2014-06-10T22:37:19.844Z",
- "uid": null
- }
- ]
-}
-```
-
-### List User Ripple Transactions ###
-__`GET /v1/users/{:id}/ripple_transactions`__
-
-To list all Ripple transactions for a given user, pass the user's ID to this
-method. The response includes an array of transactions made to or from any of
-the users's Ripple addresses.
-
-Response Body:
-
-```
-{
- "rippleTransactions": [
- {
- "address": "r4EwBWxrx5HxYRyisfGzMto3AT8FZiYdWk",
- "tag": null,
- "ripple_address_id": 16,
- "id": 81,
- "to_address_id": 16,
- "from_address_id": 1,
- "transaction_state": "tesSUCCESS",
- "transaction_hash": "F0737576A4E7D064BF00145FAD6E6BAD19115C7739A3C8CDB6D1FD38888C8364",
- "to_amount": "1",
- "to_currency": "SWD",
- "to_issuer": "rDNP5C7Vjt2mLushCmUPwm6dvwNzNiuND6",
- "from_amount": "1",
- "from_currency": "SWD",
- "from_issuer": "rDNP5C7Vjt2mLushCmUPwm6dvwNzNiuND6",
- "createdAt": "2014-06-10T22:41:14.258Z",
- "updatedAt": "2014-06-10T22:41:16.717Z",
- "uid": "505a336f-4ff9-473d-862b-164b3ad63b73",
- "data": null,
- "client_resource_id": "false",
- "state": "succeeded",
- "external_transaction_id": 80
- },
- {
- "address": "r4EwBWxrx5HxYRyisfGzMto3AT8FZiYdWk",
- "tag": null,
- "ripple_address_id": 16,
- "id": 82,
- "to_address_id": 16,
- "from_address_id": 1,
- "transaction_state": "tesSUCCESS",
- "transaction_hash": "7DEEF3BBAEEA3FEECF7819D3FAA53C580ED4A790A98DD2E761E8D747EAFB1969",
- "to_amount": "1.5999",
- "to_currency": "SWD",
- "to_issuer": "rDNP5C7Vjt2mLushCmUPwm6dvwNzNiuND6",
- "from_amount": "1.5999",
- "from_currency": "SWD",
- "from_issuer": "rDNP5C7Vjt2mLushCmUPwm6dvwNzNiuND6",
- "createdAt": "2014-06-10T22:43:57.090Z",
- "updatedAt": "2014-06-10T22:43:59.364Z",
- "uid": "5205d9b4-f1c2-4273-b656-78e908e94210",
- "data": null,
- "client_resource_id": "false",
- "state": "succeeded",
- "external_transaction_id": 81
- }
- ]
-}
-```
-
-## Managing Transactions ##
+## Ripple Transactions ##
### List Outgoing Payments ###
-__`GET /v1/payments/outgoing`__
+
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/list_outgoing_payments.js "Source")
+
+
+*REST*
+
+```
+GET /v1/payments/outgoing
+```
+
+*Commandline*
+
+```
+# Syntax:
+$ bin/gateway list_outgoing_payments
+```
+
+*Javascript*
+
+```
+//callback: function(err, payments) to run on callback
+gateway.api.listOutgoingPayments(callback);
+```
+
Ripple transaction records that are marked as "outgoing" are picked up
and sent to the Ripple network. This method returns a list of the
@@ -703,7 +968,30 @@ Response Body:
```
### List Failed Payments ###
-__`GET /v1/payments/failed`__
+
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/list_failed_payments.js "Source")
+
+
Outgoing payments are often rejected from Ripple, such as when there is
insufficient trust from the recipient account to the gateway account, or
@@ -712,11 +1000,11 @@ payment. In the case that a payment will never make it into the Ripple
ledger the outgoing payment is marked as "failed". This method lists the
history of such payments.
-Does this array just grow indefinitely? Is there a
-way to limit the amount of data in the response, to expire old failures, or
-anything to that effect? If not, it seems it'll be necessary eventually.
+*Note:* Currently, a payment is removed from this list if you [retry](#retry-failed-payment) it. In the future, this behavior may change so that old failures remain until manually deleted, and retrying creates a separate transaction, in order to preserve historical data on transaction failure for analysis. (See [Issue #239](https://github.com/ripple/gatewayd/issues/239) for status.)
-Request Body:
+If you want to remove a failed payment without retrying it, you can delete the corresponding record from the database.
+
+Response Body:
```
{
@@ -766,7 +1054,31 @@ Request Body:
```
### Retry Failed Payment ###
-__`POST /v1/payments/failed/{:id}/retry`__
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/retry_failed_payment.js "Source")
+
+
+*REST*
+
+```
+POST /v1/payments/failed/{:id}/retry
+{}
+```
+
+*Commandline*
+
+```
+# Syntax: retry_failed_payment
+$ bin/gateway retry_failed_payment 6
+```
+
+*Javascript*
+
+```
+//ripple_transaction_id: Integer ID of transaction to retry
+//callback: function(err, payment) to run on callback
+gateway.api.retryFailedPayment(ripple_transaction_id, callback);
+```
+
A payment that failed due to insufficient funds or lack of trust lines
may be successfully retried once funds are increased or an appropriate
@@ -775,8 +1087,7 @@ use this method to retrying a payment. This method simply changes the
payment's state from "failed" to "outgoing", effectively enqueueing the
transaction to be re-submitted to Ripple.
-Request Body:
-(Apparently ignored?)
+*Note:* In the future, this behavior may change to preserve the old, failed transaction for historical purposes and create a new, separate transaction to be submitted to Ripple. See [Issue #239](https://github.com/ripple/gatewayd/issues/239) for details.
Response Body:
@@ -806,7 +1117,30 @@ Response Body:
```
### List Incoming Payments ###
-__`GET /v1/payments/incoming`__
+
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/list_incoming_payments.js "Source")
+
+
Gatewayd monitors the gateway's Ripple account for inbound payments made to the
gateway, and records the payments in the Ripple Transactions database table. Newly recorded incoming Ripple transactions are always marked as "incoming" until the gatewayd "withdrawals" process picks them up and, after applying fees, enqueues a withdrawal record in the external transactions table.
@@ -842,465 +1176,436 @@ Response Body:
]
}
```
-
-### Set Last Payment Hash ###
-__`POST /v1/config/last_payment_hash`__
-Gatewayd polls the Ripple Network for notifications of inbound and outbound
-payments beginning with the last known transaction hash.
+## Ripple Management ##
-This method manually sets that hash. Gatewayd will skip any payments older
-than the transaction identified by the given hash.
+### Generate Ripple Wallet ###
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/generate_wallet.js "Source")
-Request Body:
+
+*REST*
```
-{
- "payment_hash": "4394DB1CDB591CFE697C50EAB974E7BDD6826F18B8660DACC50A88EEC98E0CD8"
-}
+POST /v1/config/wallets/generate
+{}
```
+*Commandline*
+
+```
+# Syntax: generate_wallet
+$ bin/gateway generate_wallet
+```
+
+*Javascript*
+
+```
+//options: object with
+//callback: function(err, ) to run on callback
+gateway.api.generateWallet(callback);
+```
+
+
+Generate a random Ripple address and secret key. Together, these represent an
+unfunded Ripple account. After it receives enough XRP to meet the account
+reserve, the account is included in the Ripple Ledger.
+
Response Body:
```
{
- "LAST_PAYMENT_HASH": "4394DB1CDB591CFE697C50EAB974E7BDD6826F18B8660DACC50A88EEC98E0CD8"
+ "wallet": {
+ "address": "rscJF4TWS2jBe43MvUomTtCcyrbtTRMSNr",
+ "secret": "ssuBBapjuJ2hE5wto254aNWERa8VV"
+ }
}
```
-### Retrieve Last Payment Hash ###
-__`GET /v1/config/last_payment_hash`__
-
-Gatewayd polls the ripple network for notifications of inbound and outbound
-payments beginning with the last known transaction hash.
-
-This method returns the transaction hash currently being used.
-
-Response Body:
-
-```
- {
- "LAST_PAYMENT_HASH": "12AE1B1843D886D7D6783DA02AB5F43C32579212853CF3CEFD6DBDF29F03BC80"
- }
-```
-
-### Create Deposit ###
-__`POST /v1/deposits`__
-
-This method is the entry point to creating Ripple balances. When you receive
-an asset outside the Ripple Network from a user, you can call this method to
-create a "deposit" record in gatewayd's database tracking it. By default, the
-deposit record is marked as "queued", which means that gatewayd's deposit
-process will automatically apply fees and then enqueue an outgoing Ripple
-payment to the user's Ripple address.
-
-Request Body:
-
-```
- {
- "external_account_id": 307,
- "currency": "BTC"
- "amount": "10.7"
- }
-```
-
-Response Body:
-
-```
- {
- "deposit": {
- "data": null,
- "external_account_id": 307,
- "currency": "BTC",
- "amount": "10.7",
- "deposit": true,
- "status": "queued",
- "updatedAt": "2014-06-12T00:46:02.080Z",
- "createdAt": "2014-06-12T00:46:02.080Z",
- "id": 1,
- "ripple_transaction_id": null,
- "uid": null
- }
- }
-```
-
-### List Queued Deposits ###
-__`GET /v1/deposits`__
-
-This method retrieves a list of all deposits that are currently queued. These
-deposits represent incoming assets that have not yet been processed and sent
-out as balances on the Ripple network.
-
-Response Body:
-
-```
- {
- "deposits": [
- {
- "data": null,
- "id": 1,
- "amount": "10.7",
- "currency": "BTC",
- "deposit": true,
- "external_account_id": 307,
- "status": "queued",
- "ripple_transaction_id": null,
- "createdAt": "2014-06-12T00:46:02.080Z",
- "updatedAt": "2014-06-12T00:46:02.080Z",
- "uid": null
- },
- {
- "data": null,
- "id": 2,
- "amount": "281.2",
- "currency": "XAG",
- "deposit": true,
- "external_account_id": 307,
- "status": "queued",
- "ripple_transaction_id": null,
- "createdAt": "2014-06-12T00:47:24.754Z",
- "updatedAt": "2014-06-12T00:47:24.754Z",
- "uid": null
- }
- ]
- }
-```
-
-### List Pending Withdrawals ###
-__`GET /v1/withdrawals`__
-
-To retrieve assets from the gateway, a user sends funds back to the gateway's
-Ripple account. After the incoming payment has been received and processed
-(fees subtracted), it is placed in the pending withdrawals queue, which is a
-list of external transaction withdrawal records with a state of "pending". If
-the gateway administrator has registered a withdrawal callback url, the
-withdrawal callbacks process will read withdrawals from this list and
-POST their data to the callback url provided.
-
-This method retrieves the list of pending withdrawals.
-
-Response Body:
-
-```
- {
- "withdrawals": [
- {
- "data": null,
- "id": 79,
- "amount": "1001",
- "currency": "SWD",
- "deposit": false,
- "external_account_id": 6,
- "status": "queued",
- "ripple_transaction_id": 80,
- "createdAt": "2014-05-30T19:23:48.390Z",
- "updatedAt": "2014-05-30T19:23:48.390Z",
- "uid": null
- },
- {
- "data": null,
- "id": 84,
- "amount": "8.5",
- "currency": "SWD",
- "deposit": false,
- "external_account_id": 6,
- "status": "queued",
- "ripple_transaction_id": 85,
- "createdAt": "2014-06-11T00:23:56.992Z",
- "updatedAt": "2014-06-11T00:23:56.992Z",
- "uid": null
- }
- ]
- }
-```
-
-### Clear Pending Withdrawal ###
-__`POST /v1/withdrawals/{:id}/clear`__
-
-A pending withdrawal record indicates to the gateway operator that a
-user wishes to withdraw a given asset. Once the operator processes the withdrawal
-by sending the asset to the user, mark the withdrawal as "cleared" by calling
-this method.
-
-Response Body:
-
-```
- {
- "withdrawal": {
- "data": null,
- "id": 84,
- "amount": "8.5",
- "currency": "SWD",
- "deposit": false,
- "external_account_id": 6,
- "status": "cleared",
- "ripple_transaction_id": 85,
- "createdAt": "2014-06-11T00:23:56.992Z",
- "updatedAt": "2014-06-12T20:01:29.663Z",
- "uid": null
- }
- }
-```
-
-### List Cleared External Transactions ###
-__`GET /v1/cleared`__
-
-This method retrieves the list of all external transactions that are no longer
-considered pending. This includes all deposits that have been issued as a
-balance with a Ripple payment, and all withdrawals that have been cleared.
-
-Response Body:
-
-```
- {
- "deposits": [
- {
- "data": null,
- "id": 3,
- "amount": "4.95",
- "currency": "SWD",
- "deposit": false,
- "external_account_id": 1,
- "status": "cleared",
- "ripple_transaction_id": 3,
- "createdAt": "2014-05-13T23:10:20.803Z",
- "updatedAt": "2014-05-13T23:11:26.323Z",
- "uid": null
- },
- {
- "data": null,
- "id": 5,
- "amount": "2.9699999999999998",
- "currency": "SWD",
- "deposit": false,
- "external_account_id": 1,
- "status": "cleared",
- "ripple_transaction_id": 5,
- "createdAt": "2014-05-14T19:45:05.244Z",
- "updatedAt": "2014-05-14T21:19:54.231Z",
- "uid": null
- }
- ]
- }
-```
-
-## Managing Wallets ##
-
### List Hot Wallet Balances ###
-__`GET /v1/balances`__
-The hot wallet holds limited funds issued by the cold wallet, and the current
-balance thereof is represented as hot wallet balances.
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/get_balance.js "Source")
+
+
+*REST*
+
+```
+GET /v1/balances
+```
+
+*Javascript*
+
+```
+//callback: function(err, balances) to run on callback
+balance.getAccountBalance(null, callback);
+```
+
+
+*Note:* There is no commandline version for this method yet.
+
+This method lists the funds that are held by the hot wallet, ready to be
+distributed to clients.
Response Body:
```
+{
+ "success": true,
+ "balances": [
{
- "success": true,
- "balances": [
- {
- "value": "29.999358",
- "currency": "XRP",
- "counterparty": ""
- },
- {
- "value": "8776.3012",
- "currency": "SWD",
- "counterparty": "rDNP5C7Vjt2mLushCmUPwm6dvwNzNiuND6"
- },
- {
- "value": "0",
- "currency": "USD",
- "counterparty": "rNoc7mZg54TkSd1mENAtEi65c9afYMBuTu"
- }
- ]
+ "value": "29.999358",
+ "currency": "XRP",
+ "counterparty": ""
+ },
+ {
+ "value": "8776.3012",
+ "currency": "SWD",
+ "counterparty": "rDNP5C7Vjt2mLushCmUPwm6dvwNzNiuND6"
+ },
+ {
+ "value": "0",
+ "currency": "USD",
+ "counterparty": "rNoc7mZg54TkSd1mENAtEi65c9afYMBuTu"
}
+ ]
+}
```
### List Cold Wallet Liabilities ###
-__`GET /v1/liabilities`__
+
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/get_liabilities.js "Source")
+
+
+*REST*
+
+```
+GET /v1/liabilities
+```
+
+*Javascript*
+
+```
+//callback: function(err, balance) to run on callback
+balance.getLiabilities(callback);
+```
+
+
+*Note:* There is no commandline version for this method yet.
Every asset that the gateway holds and for which it issues currency is
-a liability of the gateway. This method lists total liabilities for each type of
-currency and the other Ripple account holding that currency on the network.
+a liability of the gateway. This method lists total liabilities for each type
+of currency and the other Ripple account holding that currency on the network.
- RESPONSE:
- {
- "success": true,
- "balances": [
- {
- "value": "29.999985",
- "currency": "XRP",
- "counterparty": ""
- },
- {
- "value": "-8776.3012",
- "currency": "SWD",
- "counterparty": "rEmFrbcZvNR9i2fkBkLxDzB4X85aB4qwyZ"
- },
- {
- "value": "-63.1843",
- "currency": "SWD",
- "counterparty": "r4EwBWxrx5HxYRyisfGzMto3AT8FZiYdWk"
- },
- {
- "value": "0",
- "currency": "SWD",
- "counterparty": "rNoc7mZg54TkSd1mENAtEi65c9afYMBuTu"
- },
- {
- "value": "0",
- "currency": "SWD",
- "counterparty": "rwNJY1jnzXHCyfKRyCyVyt8UcSZfAo7z68"
- },
- {
- "value": "0",
- "currency": "SWD",
- "counterparty": "raj7HbHuG4da8bm5eNA8dAD19t8Kj8G4NR"
- }
- ]
- }
-
-
-### Fund the Hot Wallet ###
-__`POST /v1/wallets/hot/fund`__
-
-Issue funds from the cold wallet to the hot wallet, specifying the amount, currency, and
-the cold wallet secret key.
-
-### Set Cold Wallet ###
-__`POST /v1/config/wallets/cold`__
-
-Set the gateway cold wallet, from which funds are issued.
-
-### Retrieve Cold Wallet ###
-__`GET /v1/config/wallets/cold`__
-
-Show the gatewayd cold wallet, from which funds are issued.
-
-### Generate Ripple Wallet ###
-__`POST /v1/config/wallets/generate`__
-
-Generate a random ripple address and secret key pair, which
-represents an unfunded ripple account.
-
-### Set Hot Wallet ###
-__`POST /v1/config/wallets/cold`__
-
-The hot wallet holds and sends funds to customers automatically. This method
-sets the Ripple account to use as the hot wallet.
-
-Request Body:
+Response Body:
```
{
- "address": "rscJF4TWS2jBe43MvUomTtCcyrbtTRMSNr",
- "secret": "ssuBBapjuJ2hE5wto254aNWERa8VV"
+ "success": true,
+ "balances": [
+ {
+ "value": "29.999985",
+ "currency": "XRP",
+ "counterparty": ""
+ },
+ {
+ "value": "-8776.3012",
+ "currency": "SWD",
+ "counterparty": "rEmFrbcZvNR9i2fkBkLxDzB4X85aB4qwyZ"
+ },
+ {
+ "value": "-63.1843",
+ "currency": "SWD",
+ "counterparty": "r4EwBWxrx5HxYRyisfGzMto3AT8FZiYdWk"
+ },
+ {
+ "value": "0",
+ "currency": "SWD",
+ "counterparty": "rNoc7mZg54TkSd1mENAtEi65c9afYMBuTu"
+ },
+ {
+ "value": "0",
+ "currency": "SWD",
+ "counterparty": "rwNJY1jnzXHCyfKRyCyVyt8UcSZfAo7z68"
+ },
+ {
+ "value": "0",
+ "currency": "SWD",
+ "counterparty": "raj7HbHuG4da8bm5eNA8dAD19t8Kj8G4NR"
+ }
+ ]
}
```
-*Caution:* This method request contains account secrets! Be especially careful not to transmit this data over insecure channels.
+### Fund Hot Wallet ###
-Response Body:
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/fund_hot_wallet.js "Source")
-(Example needed)
+
+*REST*
-### Retrieve Hot Wallet ###
-__`GET /v1/config/wallets/hot`__
+```
+POST /v1/wallets/hot/fund
+{
+ "amount": 500.35,
+ "currency": "USD",
+ "secret": "snYYdj7vo4ouWZboLfNhTd4YaUJ4r"
+}
+```
-Show the gatewayd hot wallet, which is used to automatically send
-funds, and which maintains trust to and balances of the cold wallet.
+*Commandline*
+
+```
+# Syntax: fund_hot_wallet
+$ bin/gateway 500.35 USD snYYdj7vo4ouWZboLfNhTd4YaUJ4r
+```
+
+*Javascript*
+
+```
+//options: object with the following fields:
+// - amount: numeric amount to send
+// - currency: string currency
+// - secret: string cold wallet secret
+//callback: function(err, hot_wallet) to run on callback
+gateway.api.fundHotWallet(options, callback);
+```
+
+
+Issue funds from the cold wallet to the hot wallet, specifying the amount,
+currency, and the *cold wallet* secret key.
+
+
+
+### Return Funds from Hot Wallet to Cold Wallet ###
+
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/refund_cold_wallet.js "Source")
+
+
+*REST*
+
+```
+POST /v1/wallets/cold/refund
+{
+ "currency": "USD",
+ "amount": 324.765
+}
+```
+
+*Commandline*
+
+```
+# Syntax:
+$ bin/gateway
+```
+
+*Javascript*
+
+```
+//currency: String definition of currency to return, e.g. "USD"
+//amount: Numeric amount to send back to the cold wallet
+//callback: function(err, transaction) to run on callback
+gateway.api.refundColdWallet(currency, amount, callback);
+```
+
+
+This method returns funds from the hot wallet back to the cold wallet. This is
+an important step in phasing out a hot wallet, especially if its security may
+be compromised.
-Response Body:
-(Example needed)
### Set Trust from Hot Wallet to Cold Wallet ###
-__`POST /v1/trust`__
+
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/set_trust_line.js "Source")
+
+
+*REST*
+
+```
+POST /v1/trust
+{
+ "currency": "USD",
+ "amount": 1000
+}
+```
+
+*Commandline*
+
+```
+# Syntax: set_trust
+$ bin/gateway USD 1000
+```
+
+*Javascript*
+
+```
+//currency: string currency definition, e.g. "USD"
+//amount: numeric amount of trust to extent, e.g. 1000
+//callback: function(err, lines) to run on callback
+gateway.api.setTrustLine(currency, amount, callback);
+```
+
This method sets a line of trust from the gateway hot wallet to the gateway
cold wallet. The line of trust represents the total amount of one type of
currency that gatewayd's hot wallet can hold and automatically send out without
the gateway operator manually adding more funds to the hot wallet.
-Request Body:
-
-```
-{
- "currency": "USD",
- "amount": 1000
-}
-```
Response Body:
-(Example needed)
+```
+{
+ "lines": [
+ {
+ "account": "rAR8rR8sUkBoCZFawhkWzY4Y5YoyuznwD",
+ "balance": "324.765",
+ "currency": "USD",
+ "limit": "1000",
+ "limit_peer": "0",
+ "quality_in": 0,
+ "quality_out": 0
+ },
+ {
+ "account": "rAR8rR8sUkBoCZFawhkWzY4Y5YoyuznwD",
+ "balance": "0.0139",
+ "currency": "XAU",
+ "limit": "2",
+ "limit_peer": "0",
+ "quality_in": 0,
+ "quality_out": 0
+ }
+ ]
+}
+```
### Show Trust from Hot Wallet to Cold Wallet ###
-__`GET /v1/trust`__
+
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/get_trust_lines.js "Source")
+
+
List lines of trust from the gateway hot wallet to the gateway cold
wallet. The line of trust represents the total amount of each asset
that gatewayd can hold and automatically send out without a manual
refunding by a gateway operator.
+
Response Body:
```
- {
- "lines": [
+{
+ "lines": [
{
- "account": "rDNP5C7Vjt2mLushCmUPwm6dvwNzNiuND6",
- "balance": "8776.3012",
- "currency": "SWD",
- "limit": "10000",
+ "account": "rAR8rR8sUkBoCZFawhkWzY4Y5YoyuznwD",
+ "balance": "324.765",
+ "currency": "USD",
+ "limit": "1000",
+ "limit_peer": "0",
+ "quality_in": 0,
+ "quality_out": 0
+ },
+ {
+ "account": "rAR8rR8sUkBoCZFawhkWzY4Y5YoyuznwD",
+ "balance": "0.0139",
+ "currency": "XAU",
+ "limit": "2",
"limit_peer": "0",
"quality_in": 0,
"quality_out": 0
}
]
- }
-```
-
-### Sending Funds From Hot Wallet To Cold Wallet ###
-__`POST /v1/wallets/cold/refund`__
-
-This method returns funds from the hot wallet back to the cold wallet. This is
-an important step in phasing out a hot wallet, especially if its security may
-be compromised.
-
-Request Body:
-
-```
-{
- "currency": "USD",
- "amount": 1000
}
```
-Response Body:
-
-(Example needed)
-
-## Configuring gatewayd ##
+## Gatewayd Configuration ##
### Set Database URL ###
-__`POST /v1/config/database`__
-This method tells gatewayd which Postgres database to use.
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/set_database_url.js "Source")
-Request Body:
+
This method shows the URL that gatewayd uses to access the Postgres database.
@@ -1315,85 +1620,436 @@ Response Body:
*Caution:* This method contains sensitive database credentials. Do not use it on unsafe channels!
### Set Ripple-REST URL ###
-__`POST /v1/config/ripple/rest`__
+
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/set_ripple_rest_url.js "Source")
+
+
+*REST*
+
+```
+POST /v1/config/ripple/rest
+{
+ "url": "http://localhost:5990/"
+}
+```
+
+*Commandline*
+
+```
+# Syntax: set_ripple_rest_url
+$ bin/gateway http://localhost:5990/
+```
+
+*Javascript*
+
+```
+//ripple_rest_url: string URL of Ripple-REST instance to use
+//callback: function(err, url) to call on completion
+gateway.api.setRippleRestUrl(ripple_rest_url, callback);
+```
+
This method tells gatewayd what Ripple-REST server to use in order to access
the Ripple Network.
-Request Body: (Mock example, need confirmation)
+Response Body:
```
{
- "url": "https://localhost:5990"
+ "RIPPLE_REST_API": "https://localhost:5990"
}
```
-Response Body:
-
-(Example needed)
-
### Retrieve Ripple-REST URL ###
-__`GET /v1/config/ripple/rest`__
+
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/get_ripple_rest_url.js "Source")
+
+
This method shows the URL that gatewayd is configured to use for accessing Ripple-REST.
Response Body:
+```
+{
+ "RIPPLE_REST_API": "http://localhost:5990/"
+}
+```
+
+### Set Cold Wallet ###
+
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/set_cold_wallet.js "Source")
+
+
+
+Set the gateway cold wallet, from which funds are issued.
+
+*Note:* If the cold wallet is already set, the REST version returns 304 Not Modified.
+
+Response Body:
+
+```
+{
+ "COLD_WALLET": "rAR8rR8sUkBoCZFawhkWzY4Y5YoyuznwD"
+}
+```
+
+### Retrieve Cold Wallet ###
+
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/get_cold_wallet.js "Source")
+
+
+*REST*
+
+```
+GET /v1/config/wallets/cold
+```
+
+*Commandline*
+
+```
+# Syntax: get_cold_wallet
+$ bin/gateway get_cold_wallet
+```
+
+*Javascript*
+
+```
+// May return null if cold wallet has not been set
+gateway.config.get('COLD_WALLET');
+```
+
+
+Show the gatewayd cold wallet, from which funds are issued.
+
+Response Body:
+
+```
+{
+ "COLD_WALLET": {
+ "address": "rAR8rR8sUkBoCZFawhkWzY4Y5YoyuznwD"
+ }
+}
+```
+
+### Set Hot Wallet ###
+
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/set_hot_wallet.js "Source")
+
+
+*REST*
+
+```
+POST /v1/config/wallets/cold
+{
+ "address": "rscJF4TWS2jBe43MvUomTtCcyrbtTRMSNr",
+ "secret": "ssuBBapjuJ2hE5wto254aNWERa8VV"
+}
+```
+
+*Commandline*
+
+```
+# Syntax: set_hot_wallet
+$ bin/gateway set_hot_wallet rscJF4TWS2jBe43MvUomTtCcyrbtTRMSNr ssuBBapjuJ2hE5wto254aNWERa8VV
+```
+
+*Javascript*
+
+```
+//address: String address of account to use
+//secret: String secret of account to use
+//callback: function(err, wallet) to run on callback
+gateway.api.setHotWallet(address, secret, callback);
+```
+
+
+The hot wallet holds and sends funds to customers automatically. This method
+sets the Ripple account to use as the hot wallet. If the *address* and *secret* fields are omitted from the REST or commandline versions, then a new wallet address and secret are generated on the fly. (You still need to fund the hot wallet with at least the account reserve in XRP before you can use it.)
+
+*Caution:* This method request contains account secrets! Be especially careful not to transmit this data over insecure channels.
+
+Response Body:
+
+```
+{
+ "address": "rscJF4TWS2jBe43MvUomTtCcyrbtTRMSNr",
+ "secret": "ssuBBapjuJ2hE5wto254aNWERa8VV"
+}
+```
+
+### Retrieve Hot Wallet ###
+
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/get_hot_wallet.js "Source")
+
+
+
+Show the gatewayd hot wallet, which is used to automatically send
+funds, and which maintains trust to and balances of the cold wallet.
+
+Response Body:
+
+```
+{
+ "address": "rscJF4TWS2jBe43MvUomTtCcyrbtTRMSNr"
+}
+```
+
+### Set Last Payment Hash ###
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/set_last_payment_hash.js "Source")
+
+
+*REST*
+
+```
+POST /v1/config/last_payment_hash
+{
+ "payment_hash": "4394DB1CDB591CFE697C50EAB974E7BDD6826F18B8660DACC50A88EEC98E0CD8"
+}
+```
+
+*Commandline*
+
+```
+# Syntax: set_last_payment_hash
+$ bin/gateway set_last_payment_hash 4394DB1CDB591CFE697C50EAB974E7BDD6826F18B8660DACC50A88EEC98E0CD8
+```
+
+*Javascript*
+
+```
+//options: object with field hash: string of last payment hash to use
+//callback: function(err) to run on callback
+gateway.api.setLastPaymentHash(options, callback);
+```
+
+
+Gatewayd polls the Ripple Network for notifications of inbound payments to the
+cold wallet beginning with the last known transaction hash.
+
+This method manually sets that hash. Gatewayd will skip any payments older
+than the transaction identified by the given hash. Generally you do this one time, during setup, choosing the latest transaction in the cold wallet's history at that time, and never set it manually again.
+
+Response Body:
+
+```
+{
+ "LAST_PAYMENT_HASH": "4394DB1CDB591CFE697C50EAB974E7BDD6826F18B8660DACC50A88EEC98E0CD8"
+}
+```
+
+### Retrieve Last Payment Hash ###
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/get_last_payment_hash.js "Source")
+
+
+
+Gatewayd polls the Ripple Network for notifications of inbound payments to the
+cold wallet beginning with the last known transaction hash.
+
+This method returns the transaction hash currently being used.
+
+Response Body:
+
```
{
- "RIPPLE_REST_API": "http://localhost:5990/"
+ "LAST_PAYMENT_HASH": "12AE1B1843D886D7D6783DA02AB5F43C32579212853CF3CEFD6DBDF29F03BC80"
}
```
### Set Gateway Domain ###
-__`POST /v1/config/domain`__
+
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/set_domain.js "Source")
+
+
This method sets the domain that gatewayd uses to identify itself. This domain
is included in the gateway's ripple.txt.
-Request Body:
-
-```
- {
- "domain": "stevenzeiler.com"
- }
-```
-
Response Body:
```
- {
- "DOMAIN": "stevenzeiler.com"
- }
+{
+ "DOMAIN": "stevenzeiler.com"
+}
```
### Retrieve Domain ###
-__`GET /v1/config/domain`__
-Show the domain of the gateway, which is shown in the gateway's ripple.txt.
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/get_domain.js "Source")
+
+
+
+Show the domain of the gateway, which is shown in the gateway's `ripple.txt`.
Response Body:
```
- {
- "DOMAIN": "stroopgate.com"
- }
+{
+ "DOMAIN": "stevenzeiler.com"
+}
```
### Set API Key ###
-__`POST /v1/config/key`__
-This method reset's the gateway's API key; it generates, saves, and returns a
-new key.
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/set_key.js "Source")
-Request Body:
+
+*REST*
```
+POST /v1/config/key
{
"key": "1234578dddd"
}
```
+*Commandline*
+
+```
+# Syntax: set_key
+$ bin/gateway set_key
+```
+
+*Javascript*
+
+```
+//key: string API key to set. Optionally, generate a key randomly:
+// key = crypto.randomBytes(32).toString('hex')
+gateway.config.set('KEY', key);
+//callback: function() to call on completion
+gateway.config.save(callback);
+```
+
+
+This method reset's the gateway's API key, which is used for authenticating to the REST API. (See [Authentication](#authentication) for more details.)
+
+The REST version accepts a key parameter, which it sets as the API key. The commandline version generates and returns a new key randomly. (*Note:* This behavior may be changed to be more uniform. See [Issue #245](https://github.com/ripple/gatewayd/issues/245) for more details.)
+
+
Response Body:
```
@@ -1403,7 +2059,29 @@ Response Body:
```
### Retrieve API Key ###
-__`GET /v1/config/key`__
+
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/get_key.js "Source")
+
+
This method shows the gateway API key currently in use.
@@ -1415,58 +2093,196 @@ Response Body:
}
```
-### List Supported Currencies ###
-__`GET /v1/currencies`__
+### Add Supported Currency ###
-List currencies supported by the gateway, which are shown in the gateway's ripple.txt
-manifest file.
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/add_currency.js "Source")
+
+
+*REST*
+
+```
+POST /v1/currencies
+{
+ "currency": "XAG"
+}
+```
+
+*Commandline*
+
+```
+# Syntax: add_currency
+$ bin/gateway add_currency XAG
+```
+
+*Javascript*
+
+```
+//currency: string currency to add, for example "USD"
+//callback: function(err, currencies) to run on callback
+gateway.api.addCurrency(currency, callback);
+```
+
+
+This method adds a currency to the gateway's list of supported currencies,
+which is shown in the gateway's `ripple.txt` manifest file.
+
+Response Body:
+
+```
+{
+ "currencies": {
+ "USD": 0,
+ "XAU": 0
+ }
+}
+```
+
+### List Supported Currencies ###
+
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/list_currencies.js "Source")
+
+
+
+This method lists currencies officially supported by the gateway. These
+currencies are also listed in the gateway's `ripple.txt` manifest file.
Response Body:
```
{
"CURRENCIES": {
- "SWD": 10000
+ "USD": 0,
+ "XAU": 0
}
}
```
-### Set Supported Currencies ###
-__`POST /v1/currencies`__
+*Note:* The amounts for each currency do not currently mean anything. If you [add supported currencies](#add-supported-currency) using the REST API, they will always be set to 0. You can manually set the values by editing the `config/config.json` file, but there is no meaningful effect.
-Add a currency to be supported by the gateway. This currency is shown in the gateway's
-ripple.txt manifest file.
+### Remove Supported Currency ###
-Request Body:
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/remove_currency.js "Source")
+
+
+*REST*
+
+```
+DELETE /v1/currencies/{:currency}
+```
+
+*Commandline*
+
+```
+# Syntax: remove_currency
+$ bin/gateway remove_currency XAG
+```
+
+*Javascript*
+
+```
+//currency: string currency to remove, for example "USD"
+//callback: function(err, currencies) to run on callback
+gateway.api.removeCurrency(currency, callback);
+```
+
+
+This method removes a currency (usually defined by its 3-letter code) from the list of supported currencies.
+
+Response Body:
```
{
- currency: "XAG"
+ "currencies": {
+ "USD": 0,
+ "XAU": 0
+ }
}
```
-Response Body
-
-```
-{
- "CURRENCIES": {
- "SWD": 10000,
- "XAG": 0
- }
-}
-```
-## Managing Gateway Processes ##
+## Gatewayd Processes ##
### Start Worker Processes ###
-__`POST /v1/start`__
-Start one or more gateway processes, including but not limited to "deposits", "outgoing",
-"incoming", "withdrawals", "callbacks", etc.
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/start_gateway.js "Source")
+
+
+
+Start one or more gateway processes, including but not limited to "deposits",
+"outgoing", "incoming", "withdrawals", "callbacks", etc. (See [Gatewayd Services](#gatewayd-services) for more details.)
+
+
### List Current Processes ###
-__`GET /v1/processes`__
-List information about the currently-running gateway daemon processes.
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/api/list_processes.js "Source")
+
+
+*REST*
+
+```
+GET /v1/processes
+```
+
+*Commandline*
+
+```
+# Syntax: list_processes
+$ bin/gateway list_processes
+```
+
+*Javascript*
+
+```
+//options: object with the following field:
+// - json: boolean, if true return in JSON format
+//callback: function(err, ) to run on callback
+gateway.api.listProcesses(options, callback);
+```
+
+
+List information about the currently-running gateway daemon processes. (See [Gatewayd Processes](#gatewayd-processes) for more details.)
Response Body:
@@ -1718,3 +2534,322 @@ Response Body:
monit: { memory: 0, cpu: 0 } } ]
```
+## User-Auth Methods ##
+
+### Log In User ###
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/public/login_user.js "Source")
+
+
+
+*Note:* This method intentionally lacks commandline and Javascript versions.
+
+Verifies that a user has the correct username and password combination. Used
+for the web application and requires user credentials in place of an API key.
+
+Naturally, since this includes sensitive credentials, do not run this command
+over an unsecure connection.
+
+
+
+### Retrieve User ###
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/resources/users_controller.js#L38 "Source")
+
+
+*REST*
+
+```
+GET /v1/users/{:id}
+```
+
+*Commandline*
+
+```
+// no commandline equivalent?
+```
+
+*Javascript*
+```
+//requires User data model
+//user_id: Integer user ID
+//callback: function(err, user) to run on callback
+User.find({ where: { id: user_id }}).complete(callback);
+```
+
+*REST*
+
+```
+GET /v1/users/{:id}/external_accounts
+```
+
+*Commandline*
+
+```
+# Syntax: list_user_external_accounts
+bin/gateway list_user_external_accounts 508
+```
+
+*Javascript*
+```
+//id: integer ID of account to get external accounts from
+//callback: function(err, accounts) to run on callback
+gateway.api.listUserExternalAccounts(id, callback);
+```
+
+
+To list all external (non-Ripple) account records for a user, pass the user's
+ID to this method.
+
+Response Body:
+
+```
+{
+ "external_accounts": [
+ {
+ "data": null,
+ "id": 8,
+ "name": "default",
+ "user_id": 8,
+ "createdAt": "2014-06-10T22:37:19.835Z",
+ "updatedAt": "2014-06-10T22:37:19.835Z",
+ "uid": null
+ }
+ ]
+}
+```
+
+### List User External Transactions ###
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/users/index.js#L24 "Source")
+
+
+*REST*
+
+```
+GET /v1/users/{:id}/external_transactions
+```
+
+*Javascript*
+
+```
+//id: Integer user ID of user to find transactions of
+//callback: function(err, transactions) to run on callback
+gateway.data.externalTransactions.forUser(id, callback);
+```
+
+
+*Note:* This method intentionally lacks a commandline version.
+
+List all external (non-Ripple) transaction records for a given user. These
+records are the user's deposits into the gateway and withdrawals from it.
+
+Response Body:
+
+```
+{
+ "externalTransactions": [
+ {
+ "id": 80,
+ "currency": "SWD",
+ "amount": "1",
+ "deposit": true,
+ "ripple_transaction_id": 81,
+ "external_account_id": 8,
+ "status": "processed"
+ },
+ {
+ "id": 81,
+ "currency": "SWD",
+ "amount": "1.5999",
+ "deposit": true,
+ "ripple_transaction_id": 82,
+ "external_account_id": 8,
+ "status": "processed"
+ }
+ ]
+}
+```
+
+### List User Ripple Addresses ###
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/users/index.js#L36 "Source")
+
+
+*REST*
+
+```
+/v1/users/{:id}/ripple_addresses
+```
+
+*Javascript*
+
+```
+//id = Integer ID of user to retrieve Ripple addresses of
+//callback: function(err, addresses) to run on callback
+gateway.data.rippleAddresses.readAll({ user_id: id }, callback);
+```
+
+
+*Note:* This method intentionally lacks a commandline version.
+
+To list all ripple addresses for a given user, pass the user's ID to this
+method. Most users will have at least one independent address and one hosted
+address.
+
+Response Body:
+
+```
+{
+ "rippleAddresses": [
+ {
+ "data": null,
+ "id": 16,
+ "managed": false,
+ "address": "r4EwBWxrx5HxYRyisfGzMto3AT8FZiYdWk",
+ "type": "independent",
+ "user_id": 8,
+ "tag": null,
+ "secret": null,
+ "previous_transaction_hash": null,
+ "createdAt": "2014-06-10T22:37:19.825Z",
+ "updatedAt": "2014-06-10T22:37:19.825Z",
+ "uid": null
+ },
+ {
+ "data": null,
+ "id": 17,
+ "managed": true,
+ "address": "rDNP5C7Vjt2mLushCmUPwm6dvwNzNiuND6",
+ "type": "hosted",
+ "user_id": 8,
+ "tag": 8,
+ "secret": null,
+ "previous_transaction_hash": null,
+ "createdAt": "2014-06-10T22:37:19.844Z",
+ "updatedAt": "2014-06-10T22:37:19.844Z",
+ "uid": null
+ }
+ ]
+}
+```
+
+### List User Ripple Transactions ###
+[[Source] ](https://github.com/ripple/gatewayd/blob/master/lib/http/controllers/users/index.js#L46 "Source")
+
+
+*REST*
+
+```
+GET /v1/users/{:id}/ripple_transactions
+```
+
+*Javascript*
+
+```
+//id: Integer user ID of the user to retrieve transactions of
+//callback: function(err, transactions) to run on callback
+gateway.data.rippleTransactions.forUser(id, callback);
+```
+
+
+*Note:* This method intentionally lacks a commandline version.
+
+To list all Ripple transactions for a given user, pass the user's ID to this
+method. The response includes an array of transactions made to or from any of
+the users's Ripple addresses.
+
+Response Body:
+
+```
+{
+ "rippleTransactions": [
+ {
+ "address": "r4EwBWxrx5HxYRyisfGzMto3AT8FZiYdWk",
+ "tag": null,
+ "ripple_address_id": 16,
+ "id": 81,
+ "to_address_id": 16,
+ "from_address_id": 1,
+ "transaction_state": "tesSUCCESS",
+ "transaction_hash": "F0737576A4E7D064BF00145FAD6E6BAD19115C7739A3C8CDB6D1FD38888C8364",
+ "to_amount": "1",
+ "to_currency": "SWD",
+ "to_issuer": "rDNP5C7Vjt2mLushCmUPwm6dvwNzNiuND6",
+ "from_amount": "1",
+ "from_currency": "SWD",
+ "from_issuer": "rDNP5C7Vjt2mLushCmUPwm6dvwNzNiuND6",
+ "createdAt": "2014-06-10T22:41:14.258Z",
+ "updatedAt": "2014-06-10T22:41:16.717Z",
+ "uid": "505a336f-4ff9-473d-862b-164b3ad63b73",
+ "data": null,
+ "client_resource_id": "false",
+ "state": "succeeded",
+ "external_transaction_id": 80
+ },
+ {
+ "address": "r4EwBWxrx5HxYRyisfGzMto3AT8FZiYdWk",
+ "tag": null,
+ "ripple_address_id": 16,
+ "id": 82,
+ "to_address_id": 16,
+ "from_address_id": 1,
+ "transaction_state": "tesSUCCESS",
+ "transaction_hash": "7DEEF3BBAEEA3FEECF7819D3FAA53C580ED4A790A98DD2E761E8D747EAFB1969",
+ "to_amount": "1.5999",
+ "to_currency": "SWD",
+ "to_issuer": "rDNP5C7Vjt2mLushCmUPwm6dvwNzNiuND6",
+ "from_amount": "1.5999",
+ "from_currency": "SWD",
+ "from_issuer": "rDNP5C7Vjt2mLushCmUPwm6dvwNzNiuND6",
+ "createdAt": "2014-06-10T22:43:57.090Z",
+ "updatedAt": "2014-06-10T22:43:59.364Z",
+ "uid": "5205d9b4-f1c2-4273-b656-78e908e94210",
+ "data": null,
+ "client_resource_id": "false",
+ "state": "succeeded",
+ "external_transaction_id": 81
+ }
+ ]
+}
+```
+
diff --git a/guidelines.html b/guidelines.html
index fdf816e91e..3a3bc63513 100644
--- a/guidelines.html
+++ b/guidelines.html
@@ -408,7 +408,7 @@ mixpanel.init("132d42885e094171f34467fc54da6fab");