From 549993246ebe5f9c754e8e2075f0c2dfbff213e0 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 27 Jul 2017 14:14:43 -0400 Subject: [PATCH 1/2] First draft of API from our discussion --- docs/rest/API_draft.md | 207 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 207 insertions(+) create mode 100644 docs/rest/API_draft.md diff --git a/docs/rest/API_draft.md b/docs/rest/API_draft.md new file mode 100644 index 0000000000..5309b0d0fd --- /dev/null +++ b/docs/rest/API_draft.md @@ -0,0 +1,207 @@ +# API + +Serve on `http://localhost:2024` + +Don't allow cors + +## Create Tx + +`POST /tx` + +Input: signed tx as json, just like --prepare... +Goes to the node, and returns result: + +``` +{ + "check_tx": { + "code": 0, + "data": "", + "log": "" + }, + "deliver_tx": { + "code": 0, + "data": "", + "log": "" + }, + "hash": "4D0EB7853E71AB6E3021990CF733F70F4CC2E001", + "height": 1494 +} +``` + +`POST /sign` + +Input: + +{ + "name": "matt", + "password": "1234567890", + "tx": { + // just like prepare, tx (with sigs/multi but no sigs) + } +} + +Example tx: + +wrappers = combine(feeWrap, nonceWrap, chainWrap, sigWrap) + +UI will have to know about feeWrap to pass info in + +``` +{ + "type": "sigs/multi", + "data": { + "tx": { + "type": "chain/tx", + "data": { + "chain_id": "lakeshore", + "expires_at": 0, + "tx": { + "type": "nonce", + "data": { + "sequence": 3, + "signers": [ + { + "chain": "", + "app": "sigs", + "addr": "91C959ADE03D8973E8F2FBA9FD2EED327DCE2B0A" + } + ], + "tx": { + "type": "coin/send", + "data": { + "inputs": [ + { + "address": { + "chain": "", + "app": "role", + "addr": "62616E6B32" + }, + "coins": [ + { + "denom": "mycoin", + "amount": 900000 + } + ] + } + ], + "outputs": [ + { + "address": { + "chain": "", + "app": "sigs", + "addr": "BDADF167E6CF2CDF2D621E590FF1FED2787A40E0" + }, + "coins": [ + { + "denom": "mycoin", + "amount": 900000 + } + ] + } + ] + } + } + } + } + } + }, + "signatures": [] + } +} +``` + +Matt's proposal: + +`POST /build/send` + +Input: +``` +{ + "fees": {"denom": "atom", "amount": 23}, + "to": {"app": "role", "addr": "62616E6B32" }, + "from": {"app": "sigs", "addr": "BDADF167E6CF2CDF2D621E590FF1FED2787A40E0" }, + "amount": { "denom": "mycoin", "amount": 900000 }, + "multi": true, +} +``` + +Output: the input for /sign + +`POST /build/create-role` + +Input: +``` +{ + "name": "trduvtqicrtqvrqy", + "min_sigs": 2, + "members": [ + {"app": "sigs", "addr": "BDADF167E6CF2CDF2D621E590FF1FED2787A40E0" }, + {"app": "sigs", "addr": "91C959ADE03D8973E8F2FBA9FD2EED327DCE2B0A" } + ] +} +``` + + +## Query: + +`GET /query/account/sigs:BDADF167E6CF2CDF2D621E590FF1FED2787A40E0` + +``` +{ + "height": 1170, + "data": { + "coins": [ + { + "denom": "mycoin", + "amount": 12345 + } + ] + } +} +``` + + +## Other stuff + +`init` / `serve` on cli + +keys management under `/keys`: + +List, get, create (delete + update)? + +proxy mounted as well under `/tendermint` + +`/tendermint/status` +`/tendermint/block` + +info about self... + +`/` + +``` +{ + "app": "basecli", + "version": "0.7.1", // of client, server???? + "modules": { + "chain": "0.1.0", + "fees": "0.2.1", + "coin": "0.3.2", + "stake": "0.1.2" + }, + "nodes": [ + "localhost:46657", + "mercury.interchain.io:443" + ] +} +``` + +`/seeds` + +``` +{ + "last_height": 4555, + "update_problems": "too much change" +} +``` + +info on last seed From 9037b3508a7ba72baf45bf86396964851479efd4 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 27 Jul 2017 20:08:46 -0400 Subject: [PATCH 2/2] Clean up spec to focus on mvp with moving coins --- docs/rest/API_draft.md | 154 ++++++++++++++++++++++++++--------------- 1 file changed, 98 insertions(+), 56 deletions(-) diff --git a/docs/rest/API_draft.md b/docs/rest/API_draft.md index 5309b0d0fd..0721c1a99d 100644 --- a/docs/rest/API_draft.md +++ b/docs/rest/API_draft.md @@ -1,50 +1,38 @@ # API -Serve on `http://localhost:2024` +In order to allow for quick client development, with the security +of the light-client and ease of use the cli (embedding go-wire and +go-crypto), we will provide a REST API, which can run on localhost +as part of `basecli`, securely managing your keys, signing transactions, +and validating queries. It will be exposed for a locally deployed +application to make use of (eg. electron app, web server...) -Don't allow cors +By default we will serve on `http://localhost:2024`. CORS will be disabled by default. Potentially we can add a flag to enable it for one domain. -## Create Tx +## MVP -`POST /tx` +The MVP will allow us to move around money. This involves the +following functions: -Input: signed tx as json, just like --prepare... -Goes to the node, and returns result: +## Construct an unsigned tx -``` -{ - "check_tx": { - "code": 0, - "data": "", - "log": "" - }, - "deliver_tx": { - "code": 0, - "data": "", - "log": "" - }, - "hash": "4D0EB7853E71AB6E3021990CF733F70F4CC2E001", - "height": 1494 -} -``` - -`POST /sign` +`POST /build/send` Input: - +``` { - "name": "matt", - "password": "1234567890", - "tx": { - // just like prepare, tx (with sigs/multi but no sigs) - } + "to": {"app": "role", "addr": "62616E6B32" }, + "from": {"app": "sigs", "addr": "BDADF167E6CF2CDF2D621E590FF1FED2787A40E0" }, + "amount": { "denom": "mycoin", "amount": 900000 }, + "sequence": 1, + "multi": true, } +``` -Example tx: +Output (a json encoding of basecoin.Tx): -wrappers = combine(feeWrap, nonceWrap, chainWrap, sigWrap) +`basecli tx send --to=role:62616E6B32 --from=sigs:91C959ADE03D8973E8F2FBA9FD2EED327DCE2B0A --amount=900000mycoin --sequence=1 --multi --prepare=- --no-sign` -UI will have to know about feeWrap to pass info in ``` { @@ -58,7 +46,7 @@ UI will have to know about feeWrap to pass info in "tx": { "type": "nonce", "data": { - "sequence": 3, + "sequence": 1, "signers": [ { "chain": "", @@ -105,44 +93,97 @@ UI will have to know about feeWrap to pass info in } } }, - "signatures": [] + "signatures": null } } ``` -Matt's proposal: +## Sign a Tx -`POST /build/send` +Once you construct a proper json-encoded `basecoin.Tx`, you can sign it once, or (if you constructed it with `multi=true`), multiple times. + + +`POST /sign` Input: + ``` { - "fees": {"denom": "atom", "amount": 23}, - "to": {"app": "role", "addr": "62616E6B32" }, - "from": {"app": "sigs", "addr": "BDADF167E6CF2CDF2D621E590FF1FED2787A40E0" }, - "amount": { "denom": "mycoin", "amount": 900000 }, - "multi": true, + "name": "matt", + "password": "1234567890", + "tx": { + "type": "sigs/multi", + "data": { + "tx": // see output of /build/send, + "signatures": nil, + } + } } ``` -Output: the input for /sign +Output: -`POST /build/create-role` +`basecli tx send --to=role:62616E6B32 --from=sigs:91C959ADE03D8973E8F2FBA9FD2EED327DCE2B0A --amount=900000mycoin --sequence=1 --multi --no-sign --prepare=unsigned.json` + +`echo 1234567890 | basecli tx --in=unsigned.json --prepare=- --name=matt` -Input: ``` { - "name": "trduvtqicrtqvrqy", - "min_sigs": 2, - "members": [ - {"app": "sigs", "addr": "BDADF167E6CF2CDF2D621E590FF1FED2787A40E0" }, - {"app": "sigs", "addr": "91C959ADE03D8973E8F2FBA9FD2EED327DCE2B0A" } - ] + "type": "sigs/multi", + "data": { + "tx": // see output of /build/send, + "signatures": [ + { + "Sig": { + "type": "ed25519", + "data": "436188FAC4668DDF6729022454AFBA5DA0B44E516C4EC7013C6B00BD877F255CDE0355F3FBFE9CCF88C9F519C192D498BF087AFE0D531351813432A100857803" + }, + "Pubkey": { + "type": "ed25519", + "data": "B01508EB073C0823E2CE6ABF4538BA02EAEC39B02113290BBFCEC7E1B07F575A" + } + } + ] + } } ``` +## Send Tx to the Blockchain -## Query: +This will encode the transaction as binary and post it to the tendermint node, waiting until it is committed to the blockchain. +(TODO: make this async? return when recevied, notify when committed?) + +`POST /tx` + +Input: + +Signed tx as json, directly copy output of `/sign` + +Output: + + +`echo 1234567890 | basecli tx send --to=role:62616E6B32 --from=sigs:91C959ADE03D8973E8F2FBA9FD2EED327DCE2B0A --amount=900000mycoin --sequence=1 --multi --name=matt --prepare=signed.json` + +`basecli tx --in=signed.json --no-sign` + +``` +{ + "check_tx": { + "code": 0, + "data": "", + "log": "" + }, + "deliver_tx": { + "code": 0, + "data": "", + "log": "" + }, + "hash": "4D0EB7853E71AB6E3021990CF733F70F4CC2E001", + "height": 1494 +} +``` + +## Query account balance `GET /query/account/sigs:BDADF167E6CF2CDF2D621E590FF1FED2787A40E0` @@ -160,14 +201,15 @@ Input: } ``` +## Other stuff for MVP -## Other stuff +You must run `basecli init` int he cli to set things up. -`init` / `serve` on cli +When you run `basecli serve`, it will start the local rest api server, with the above endpoints. -keys management under `/keys`: +Also, support keys endpoints from go-crypto as they currently are and mount them under `/keys`. -List, get, create (delete + update)? +## Future Stuff proxy mounted as well under `/tendermint`