From 8ed05b4586c58039216b0d39796eef5ef536c49d Mon Sep 17 00:00:00 2001 From: Jeremy Kauffman Date: Sun, 29 Jan 2017 18:12:13 -0500 Subject: [PATCH 1/4] first steps --- controller/Controller.class.php | 1 + .../action/AcquisitionActions.class.php | 8 +- .../acquisition/credits-for-developers.php | 25 ++++ view/template/layout/basic.php | 4 +- view/template/page/quickstart.php | 120 ++++++++++++++++++ web/scss/_content.scss | 7 +- web/scss/_form.scss | 14 ++ 7 files changed, 174 insertions(+), 5 deletions(-) create mode 100644 view/template/acquisition/credits-for-developers.php create mode 100644 view/template/page/quickstart.php diff --git a/controller/Controller.class.php b/controller/Controller.class.php index b721fff2..ec62b745 100644 --- a/controller/Controller.class.php +++ b/controller/Controller.class.php @@ -88,6 +88,7 @@ class Controller $router->get(['/android', 'get-android'], 'DownloadActions::executeGet'); $router->get(['/ios', 'get-ios'], 'DownloadActions::executeGet'); $router->get('/roadmap', 'ContentActions::executeRoadmap'); + $router->get('/credits-for-developers', 'AcquisitionActions::executeCreditsForDevelopers'); $router->get(['/press-kit.zip', 'press-kit'], 'ContentActions::executePressKit'); diff --git a/controller/action/AcquisitionActions.class.php b/controller/action/AcquisitionActions.class.php index 148f5cc7..42c2e804 100644 --- a/controller/action/AcquisitionActions.class.php +++ b/controller/action/AcquisitionActions.class.php @@ -2,12 +2,13 @@ class AcquisitionActions extends Actions { + const DEVELOPER_REWARD = 250; + public static function executeThanks() { return ['acquisition/thanks']; } - public static function executeYouTubeSub() { if (!Request::isPost()) @@ -40,4 +41,9 @@ class AcquisitionActions extends Actions } return [$template]; } + + public static function executeCreditsForDevelopers() + { + return ['acquisition/credits-for-developers']; + } } \ No newline at end of file diff --git a/view/template/acquisition/credits-for-developers.php b/view/template/acquisition/credits-for-developers.php new file mode 100644 index 00000000..6df1b9e6 --- /dev/null +++ b/view/template/acquisition/credits-for-developers.php @@ -0,0 +1,25 @@ + + + + false, 'isAbsolute' => false]) ?> +
+
+

Credits For Developers

+

All developers with a GitHub account prior to 2017 are eligible for free credits.

+

To claim your credits, enter a wallet address in the form below and authenticate with GitHub.

+

+ We will store your GitHub username and email address, but nothing else. +

+
+

Receive Credits

+
+ +
+ +
+
+ +
+
+
+ \ No newline at end of file diff --git a/view/template/layout/basic.php b/view/template/layout/basic.php index 849d24b3..6a6f254d 100644 --- a/view/template/layout/basic.php +++ b/view/template/layout/basic.php @@ -47,11 +47,9 @@ - - - +
diff --git a/view/template/page/quickstart.php b/view/template/page/quickstart.php new file mode 100644 index 00000000..94cbc46b --- /dev/null +++ b/view/template/page/quickstart.php @@ -0,0 +1,120 @@ + + + + false, 'isAbsolute' => false]) ?> +
+

Quickstart

+

This step-by-step guide will have running LBRY and interacting with the API in just a few minutes.

+

This guide is for programmers and other technical users. For consumer usage of LBRY, please go here.

+

What's Covered

+
    +
  1. Installation
  2. +
  3. Running LBRY
  4. +
  5. API Basics
  6. +
  7. Credits
  8. +
  9. Start Building
  10. +
  11. Community & Issues
  12. +
+
+

1. Installation

+

The easiest way to install LBRY is to use a pre-packaged binary. We provide binaries for Windows, macOS, and Debian-based Linux.

+ + + + + + + + + + + + + + + +
macOS Linux Windows
Download DMGDownload DEBDownload MSI
+

+ If you prefer to compile from source or are not on one of the above operating systems, follow + this guide. +

+
+
+

2. Running LBRY

+

+ Launch the deamon to run as a background process: +

+

+ + lbrynet-daemon --no-launch + +

+

The first time you run the daemon, it must catch-up with most recent blockheaders. This can take several minutes.

+
+
+

3. API Basics

+

+ When running, the LBRY daemon provides a JSON-RPC server running at https://localhost:5279/lbryapi. +

+

+ It can be accessed via cURL or any other utility capable of making HTTPS GET and POST requests. +

+

+ To verify the LBRY daemon is running correctly and responding to requests, run: +

+

+ + curl --data "{ method: 'status' }" http://localhost:5279/lbryapi + +

+

+ You should receive a response like: +

+

+ + (will copy/paste once it works) + +

+

This makes it easy to interact with the LBRY API in the programming language of your choice.

+
+
+

4. Getting Credits

+

Many actions, such as publishing or purchasing paid content, require credits.

+

To receive credits, first generate a wallet address:

+

+ + curl --data "{ method: 'wallet_new_address' }" http://localhost:5279/lbryapi
+ I am a response +
+

+

Use this address to get credits in one of two ways:

+
+
+

4a) Get Credits For Free

+

+ All developers are eligible to receive free credits. + Go here to claim them. +

+
+
+

4b) Purchase Credits

+

+ Credits can be bought on a variety of exchanges. + Go here to see a full list. + After purchasing them, send them to the address generated above. +

+
+
+
+
+

6. Community & Issues

+

+ Join our Slack Channel to interact with LBRY developers and other community members. Please visit the #dev room (this is not a default channel). +

+

+ Visit our GitHub to view the source code or report issues. +

+
+
+ + \ No newline at end of file diff --git a/web/scss/_content.scss b/web/scss/_content.scss index 34016aab..2bf7c601 100644 --- a/web/scss/_content.scss +++ b/web/scss/_content.scss @@ -128,6 +128,11 @@ &:last-child { margin-bottom: $spacing-vertical / 2; } padding-left: 2em; counter-reset: li-counter; + &.table-of-contents > li + { + line-height: 2em; + &:before { top: -0.1em; } + } > li { position: relative; @@ -138,7 +143,7 @@ &:before { position: absolute; - top: -0.25em; + top: -0.35em; left: -1em; width: 0.8em; diff --git a/web/scss/_form.scss b/web/scss/_form.scss index cf455026..4754d778 100644 --- a/web/scss/_form.scss +++ b/web/scss/_form.scss @@ -21,6 +21,15 @@ form { margin-bottom: $line-height; } +form.form-inset +{ + margin-left: auto; + margin-right: auto; + background: #eee; + padding: $spacing-vertical; + max-width: 600px; +} + label[for], .label-radio { cursor: pointer; @@ -72,6 +81,11 @@ input[type="date"] { vertical-align: middle; } +input.input-wallet +{ + width: 400px; +} + textarea { height: auto; min-height: 60px; From 8d0c394d59ea9b1d3cd34b5d2b29fde1713e92ee Mon Sep 17 00:00:00 2001 From: Jeremy Kauffman Date: Sun, 29 Jan 2017 23:52:11 -0500 Subject: [PATCH 2/4] quickstart almost gtg --- controller/Controller.class.php | 5 +- .../action/AcquisitionActions.class.php | 101 +++++++++++++++++- ...r-developers.php => developer-program.php} | 14 ++- view/template/page/quickstart.php | 53 ++++----- view/template/report/dmca.php | 2 +- 5 files changed, 132 insertions(+), 43 deletions(-) rename view/template/acquisition/{credits-for-developers.php => developer-program.php} (55%) diff --git a/controller/Controller.class.php b/controller/Controller.class.php index ec62b745..d344c8a9 100644 --- a/controller/Controller.class.php +++ b/controller/Controller.class.php @@ -88,7 +88,10 @@ class Controller $router->get(['/android', 'get-android'], 'DownloadActions::executeGet'); $router->get(['/ios', 'get-ios'], 'DownloadActions::executeGet'); $router->get('/roadmap', 'ContentActions::executeRoadmap'); - $router->get('/credits-for-developers', 'AcquisitionActions::executeCreditsForDevelopers'); + + $router->get('/developer-program', 'AcquisitionActions::executeDeveloperProgram'); + $router->post('/developer-program', 'AcquisitionActions::executeDeveloperProgramRedirect'); + $router->get('/developer-program/callback', 'AcquisitionActions::executeDeveloperProgramGithubCallback'); $router->get(['/press-kit.zip', 'press-kit'], 'ContentActions::executePressKit'); diff --git a/controller/action/AcquisitionActions.class.php b/controller/action/AcquisitionActions.class.php index 42c2e804..82cd1249 100644 --- a/controller/action/AcquisitionActions.class.php +++ b/controller/action/AcquisitionActions.class.php @@ -2,8 +2,11 @@ class AcquisitionActions extends Actions { - const DEVELOPER_REWARD = 250; - + const DEVELOPER_REWARD = 250, + SESSION_KEY_DEVELOPER_CREDITS_ERROR = 'acquisition.developer-credits-error', + SESSION_KEY_DEVELOPER_CREDITS_SUCCESS = 'acquisition.developer-credits-success', + SESSION_KEY_DEVELOPER_CREDITS_WALLET_ADDRESS = 'acquisition.developer-credits-wallet-address'; + public static function executeThanks() { return ['acquisition/thanks']; @@ -42,8 +45,98 @@ class AcquisitionActions extends Actions return [$template]; } - public static function executeCreditsForDevelopers() + public static function executeDeveloperProgram() { - return ['acquisition/credits-for-developers']; + $vars = [ + 'defaultWalletAddress' => Session::get(static::SESSION_KEY_DEVELOPER_CREDITS_WALLET_ADDRESS), + 'error' => Session::get(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR), + 'success' => Session::get(static::SESSION_KEY_DEVELOPER_CREDITS_SUCCESS) + ]; + Session::unsetKey(static::SESSION_KEY_DEVELOPER_CREDITS_SUCCESS); + Session::unsetKey(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR); + return ['acquisition/developer-program', $vars]; + } + + public static function executeDeveloperProgramRedirect() + { + $walletAddress = trim(Request::getPostParam('wallet')); + Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_WALLET_ADDRESS, $walletAddress); + if (!$walletAddress) + { + Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR, 'Please provide a wallet address.'); + } + elseif (!preg_match('/^b[1-9A-HJ-NP-Za-km-z]{33}$/', $walletAddress)) + { + Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR, 'This does not appear to be a valid wallet address.'); + } + else + { + $githubParams = [ + 'client_id' => Config::get('github_developer_credits_client_id'), + 'redirect_uri' => 'http://localhost:8000/developer-program/callback', + 'scope' => 'user:email', + 'allow_signup' => false + ]; + return Controller::redirect('https://github.com/login/oauth/authorize?' . http_build_query($githubParams)); + } + return Controller::redirect('/developer-program'); + } + + public static function executeDeveloperProgramGithubCallback() + { + $code = Request::getParam('code'); + $walletAddress = Session::get(static::SESSION_KEY_DEVELOPER_CREDITS_WALLET_ADDRESS); + if (!$walletAddress || !$code) + { + Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR, 'Your wallet address disappeared while authenticated with GitHub.'); + } + elseif (!$code) + { + Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR, 'This does not appear to be a valid response from GitHub.'); + } + else + { + $authResponseData = Curl::post('https://github.com/login/oauth/access_token', [ + 'code' => $code, + 'client_id' => Config::get('github_developer_credits_client_id'), + 'client_secret' => Config::get('github_developer_credits_client_secret') + ], [ + 'headers' => ['Accept: application/json'], + 'json_response' => true + ]); + if (!$authResponseData || !isset($authResponseData['access_token'])) + { + Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR, 'Request to GitHub failed.'); + } + elseif (isset($authResponseData['error_description'])) + { + Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR, 'GitHub replied: ' . $authResponseData['error_description']); + } + else + { + $accessToken = $authResponseData['access_token']; + $userResponseData = Curl::get('https://api.github.com/user', [], [ + 'headers' => ['Authorization: token ' . $accessToken, 'Accept: application/json', 'User-Agent: lbryio'], + 'json_response' => true + ]); + + if (date('Y-m', strtotime($userResponseData['created_at'])) > '2017-01') + { + Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR, 'This GitHub account is too recent.'); + } + else + { + // print_r($userResponseData); + /* + * TODO: send credits here, see success message below for relevant values + * (keep wallet address in success message) + */ + + Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_SUCCESS, + 'Send credits to GitHub user ' . $userResponseData['login'] . ' (' . $userResponseData['email'] . ') at wallet address ' . $walletAddress); + } + } + } + return Controller::redirect('/developer-program'); } } \ No newline at end of file diff --git a/view/template/acquisition/credits-for-developers.php b/view/template/acquisition/developer-program.php similarity index 55% rename from view/template/acquisition/credits-for-developers.php rename to view/template/acquisition/developer-program.php index 6df1b9e6..c6c66347 100644 --- a/view/template/acquisition/credits-for-developers.php +++ b/view/template/acquisition/developer-program.php @@ -4,18 +4,24 @@ false, 'isAbsolute' => false]) ?>
-

Credits For Developers

-

All developers with a GitHub account prior to 2017 are eligible for free credits.

+

Developer Program

+

All developers with a GitHub account prior to January 31st, 2017 are eligible for free credits.

To claim your credits, enter a wallet address in the form below and authenticate with GitHub.

We will store your GitHub username and email address, but nothing else.

-
+

Receive Credits

+ +
+ +
+
- +
diff --git a/view/template/page/quickstart.php b/view/template/page/quickstart.php index 94cbc46b..845d0d8e 100644 --- a/view/template/page/quickstart.php +++ b/view/template/page/quickstart.php @@ -10,9 +10,8 @@
  1. Installation
  2. Running LBRY
  3. -
  4. API Basics
  5. +
  6. The API
  7. Credits
  8. -
  9. Start Building
  10. Community & Issues
@@ -52,7 +51,7 @@

The first time you run the daemon, it must catch-up with most recent blockheaders. This can take several minutes.

-

3. API Basics

+

3. The API

When running, the LBRY daemon provides a JSON-RPC server running at https://localhost:5279/lbryapi.

@@ -62,57 +61,45 @@

To verify the LBRY daemon is running correctly and responding to requests, run:

-

- - curl --data "{ method: 'status' }" http://localhost:5279/lbryapi - -

-

- You should receive a response like: -

-

- - (will copy/paste once it works) - -

-

This makes it easy to interact with the LBRY API in the programming language of your choice.

+
curl --data "{ method: 'status' }" http://localhost:5279/lbryapi
+(add response when this works)
+

This makes it easy to interact with the LBRY API in the programming language of your choice. Here's another example:

+
curl --data "{ method: 'resolve_name', params: [{ name: "what"}] }" http://localhost:5279/lbryapi
+(add response when this works)
+

LBRY can be used to build everything from a censorship-proof image host, to a store for 3D printing files, to distribute large files or datasets, or use cases even we can't imagine!

+

View Full API Documentation

4. Getting Credits

-

Many actions, such as publishing or purchasing paid content, require credits.

+

Many actions, such as reserving a name or purchasing paid content, require credits.

To receive credits, first generate a wallet address:

-

- - curl --data "{ method: 'wallet_new_address' }" http://localhost:5279/lbryapi
- I am a response -
-

+
curl --data "{ method: 'wallet_new_address' }" http://localhost:5279/lbryapi
+I am a response

Use this address to get credits in one of two ways:

-

4a) Get Credits For Free

+

4a) Receive Free Credits

- All developers are eligible to receive free credits. - Go here to claim them. + All developers with a valid GitHub account are eligible to receive free credits.

+ Claim Your Free Credits

4b) Purchase Credits

- Credits can be bought on a variety of exchanges. - Go here to see a full list. - After purchasing them, send them to the address generated above. + Credits can be bought on a variety of exchanges. + After purchasing, send them to the address generated above.

-

6. Community & Issues

+

5. Community & Issues

- Join our Slack Channel to interact with LBRY developers and other community members. Please visit the #dev room (this is not a default channel). + Join our Slack Channel to interact with LBRY developers and other community members. Please visit the #dev room (note: this is not a default channel).

- Visit our GitHub to view the source code or report issues. + Visit our GitHub page to view the source code or report issues.

diff --git a/view/template/report/dmca.php b/view/template/report/dmca.php index f406e38c..6011fc01 100644 --- a/view/template/report/dmca.php +++ b/view/template/report/dmca.php @@ -10,7 +10,7 @@
- + 'name', From 4849c5b37066212441a7f83de84869c436063626 Mon Sep 17 00:00:00 2001 From: Alex Grintsvayg Date: Mon, 30 Jan 2017 15:19:31 -0500 Subject: [PATCH 3/4] fixes --- controller/Controller.class.php | 2 +- .../action/AcquisitionActions.class.php | 41 ++++++++++-------- .../acquisition/developer-program.php | 2 +- view/template/page/quickstart.php | 42 ++++++++++++++++--- 4 files changed, 62 insertions(+), 25 deletions(-) diff --git a/controller/Controller.class.php b/controller/Controller.class.php index d344c8a9..7f42aead 100644 --- a/controller/Controller.class.php +++ b/controller/Controller.class.php @@ -90,7 +90,7 @@ class Controller $router->get('/roadmap', 'ContentActions::executeRoadmap'); $router->get('/developer-program', 'AcquisitionActions::executeDeveloperProgram'); - $router->post('/developer-program', 'AcquisitionActions::executeDeveloperProgramRedirect'); + $router->post('/developer-program/post', 'AcquisitionActions::executeDeveloperProgramPost'); $router->get('/developer-program/callback', 'AcquisitionActions::executeDeveloperProgramGithubCallback'); $router->get(['/press-kit.zip', 'press-kit'], 'ContentActions::executePressKit'); diff --git a/controller/action/AcquisitionActions.class.php b/controller/action/AcquisitionActions.class.php index 82cd1249..17bda1e1 100644 --- a/controller/action/AcquisitionActions.class.php +++ b/controller/action/AcquisitionActions.class.php @@ -3,9 +3,9 @@ class AcquisitionActions extends Actions { const DEVELOPER_REWARD = 250, - SESSION_KEY_DEVELOPER_CREDITS_ERROR = 'acquisition.developer-credits-error', - SESSION_KEY_DEVELOPER_CREDITS_SUCCESS = 'acquisition.developer-credits-success', - SESSION_KEY_DEVELOPER_CREDITS_WALLET_ADDRESS = 'acquisition.developer-credits-wallet-address'; + SESSION_KEY_DEVELOPER_CREDITS_ERROR = 'acquisition.developer-credits-error', + SESSION_KEY_DEVELOPER_CREDITS_SUCCESS = 'acquisition.developer-credits-success', + SESSION_KEY_DEVELOPER_CREDITS_WALLET_ADDRESS = 'acquisition.developer-credits-wallet-address'; public static function executeThanks() { @@ -49,15 +49,15 @@ class AcquisitionActions extends Actions { $vars = [ 'defaultWalletAddress' => Session::get(static::SESSION_KEY_DEVELOPER_CREDITS_WALLET_ADDRESS), - 'error' => Session::get(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR), - 'success' => Session::get(static::SESSION_KEY_DEVELOPER_CREDITS_SUCCESS) + 'error' => Session::get(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR), + 'success' => Session::get(static::SESSION_KEY_DEVELOPER_CREDITS_SUCCESS) ]; Session::unsetKey(static::SESSION_KEY_DEVELOPER_CREDITS_SUCCESS); Session::unsetKey(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR); return ['acquisition/developer-program', $vars]; } - public static function executeDeveloperProgramRedirect() + public static function executeDeveloperProgramPost() { $walletAddress = trim(Request::getPostParam('wallet')); Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_WALLET_ADDRESS, $walletAddress); @@ -71,10 +71,15 @@ class AcquisitionActions extends Actions } else { + if (!Config::get('github_developer_credits_client_id')) + { + throw new Exception('no github client id'); + } + $githubParams = [ - 'client_id' => Config::get('github_developer_credits_client_id'), - 'redirect_uri' => 'http://localhost:8000/developer-program/callback', - 'scope' => 'user:email', + 'client_id' => Config::get('github_developer_credits_client_id'), + 'redirect_uri' => Request::getHostAndProto() . '/developer-program/callback', + 'scope' => 'user:email', 'allow_signup' => false ]; return Controller::redirect('https://github.com/login/oauth/authorize?' . http_build_query($githubParams)); @@ -84,9 +89,10 @@ class AcquisitionActions extends Actions public static function executeDeveloperProgramGithubCallback() { - $code = Request::getParam('code'); + $code = Request::getParam('code'); $walletAddress = Session::get(static::SESSION_KEY_DEVELOPER_CREDITS_WALLET_ADDRESS); - if (!$walletAddress || !$code) + + if (!$walletAddress) { Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR, 'Your wallet address disappeared while authenticated with GitHub.'); } @@ -97,11 +103,11 @@ class AcquisitionActions extends Actions else { $authResponseData = Curl::post('https://github.com/login/oauth/access_token', [ - 'code' => $code, - 'client_id' => Config::get('github_developer_credits_client_id'), + 'code' => $code, + 'client_id' => Config::get('github_developer_credits_client_id'), 'client_secret' => Config::get('github_developer_credits_client_secret') ], [ - 'headers' => ['Accept: application/json'], + 'headers' => ['Accept: application/json'], 'json_response' => true ]); if (!$authResponseData || !isset($authResponseData['access_token'])) @@ -114,9 +120,9 @@ class AcquisitionActions extends Actions } else { - $accessToken = $authResponseData['access_token']; + $accessToken = $authResponseData['access_token']; $userResponseData = Curl::get('https://api.github.com/user', [], [ - 'headers' => ['Authorization: token ' . $accessToken, 'Accept: application/json', 'User-Agent: lbryio'], + 'headers' => ['Authorization: token ' . $accessToken, 'Accept: application/json', 'User-Agent: lbryio'], 'json_response' => true ]); @@ -133,7 +139,8 @@ class AcquisitionActions extends Actions */ Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_SUCCESS, - 'Send credits to GitHub user ' . $userResponseData['login'] . ' (' . $userResponseData['email'] . ') at wallet address ' . $walletAddress); + 'Send credits to GitHub user ' . $userResponseData['login'] . ' (' . $userResponseData['email'] . ') at wallet address ' . + $walletAddress); } } } diff --git a/view/template/acquisition/developer-program.php b/view/template/acquisition/developer-program.php index c6c66347..621396a6 100644 --- a/view/template/acquisition/developer-program.php +++ b/view/template/acquisition/developer-program.php @@ -10,7 +10,7 @@

We will store your GitHub username and email address, but nothing else.

- +

Receive Credits

diff --git a/view/template/page/quickstart.php b/view/template/page/quickstart.php index 845d0d8e..dde43f94 100644 --- a/view/template/page/quickstart.php +++ b/view/template/page/quickstart.php @@ -61,11 +61,41 @@

To verify the LBRY daemon is running correctly and responding to requests, run:

-
curl --data "{ method: 'status' }" http://localhost:5279/lbryapi
-(add response when this works)
+
curl 'http://localhost:5279/lbryapi' --data '{"method":"status","params":[]}'
+[
+  {
+    "connection_status": {
+      "message": "No connection problems detected",
+      "code": "connected"
+    },
+    "is_first_run": false,
+    "is_running": true,
+    "blocks_behind": 0,
+    "startup_status": {
+      "message": "Started lbrynet",
+      "code": "started"
+    },
+    "lbry_id": "7J75jSuxU9eizREuxk1r"
+  }
+]

This makes it easy to interact with the LBRY API in the programming language of your choice. Here's another example:

-
curl --data "{ method: 'resolve_name', params: [{ name: "what"}] }" http://localhost:5279/lbryapi
-(add response when this works)
+
curl 'http://localhost:5279/lbryapi' --data '{"method":"resolve_name","params":[{"name":"what"}]}'
+[
+  {
+    "ver": "0.0.3",
+    "description": "What is LBRY? An introduction with Alex Tabarrok",
+    "license": "LBRY inc",
+    "title": "What is LBRY?",
+    "author": "Samuel Bryan",
+    "language": "en",
+    "sources": {
+      "lbry_sd_hash": "d5169241150022f996fa7cd6a9a1c421937276a3275eb912790bd07ba7aec1fac5fd45431d226b8fb402691e79aeb24b"
+    },
+    "content_type": "video\/mp4",
+    "nsfw": false,
+    "thumbnail": "https:\/\/s3.amazonaws.com\/files.lbry.io\/logo.png"
+  }
+]

LBRY can be used to build everything from a censorship-proof image host, to a store for 3D printing files, to distribute large files or datasets, or use cases even we can't imagine!

View Full API Documentation

@@ -73,8 +103,8 @@

4. Getting Credits

Many actions, such as reserving a name or purchasing paid content, require credits.

To receive credits, first generate a wallet address:

-
curl --data "{ method: 'wallet_new_address' }" http://localhost:5279/lbryapi
-I am a response
+
curl 'http://localhost:5279/lbryapi' --data '{"method":"wallet_new_address","params":[]}'
+["bbFxRyWCFRkA9YcuuZD8nE7XTLUxYnddTs"]

Use this address to get credits in one of two ways:

From 02bd91272d8e0b6b2f1909e5a3c07309de3ec921 Mon Sep 17 00:00:00 2001 From: Alex Grintsvayg Date: Mon, 30 Jan 2017 16:16:31 -0500 Subject: [PATCH 4/4] send credits --- controller/Session.class.php | 3 + .../action/AcquisitionActions.class.php | 89 ++++++++++++------- lib/tools/Lock.class.php | 70 +++++++++++++++ 3 files changed, 132 insertions(+), 30 deletions(-) create mode 100644 lib/tools/Lock.class.php diff --git a/controller/Session.class.php b/controller/Session.class.php index 8d14fd2d..4291690f 100644 --- a/controller/Session.class.php +++ b/controller/Session.class.php @@ -6,6 +6,9 @@ class Session KEY_DOWNLOAD_ALLOWED = 'beta_download_allowed2', KEY_PREFINERY_USER_ID = 'prefinery_user_id', KEY_PREFINER_USED_CUSTOM_CODE = 'prefinery_used_custom_code', + KEY_DEVELOPER_CREDITS_ERROR = 'developer_credits_error', + KEY_DEVELOPER_CREDITS_SUCCESS = 'developer_credits_success', + KEY_DEVELOPER_CREDITS_WALLET_ADDRESS = 'developer_credits_wallet_address', KEY_LIST_SUB_ERROR = 'list_error', KEY_USER_CULTURE = 'user_culture'; diff --git a/controller/action/AcquisitionActions.class.php b/controller/action/AcquisitionActions.class.php index 17bda1e1..847d4d92 100644 --- a/controller/action/AcquisitionActions.class.php +++ b/controller/action/AcquisitionActions.class.php @@ -2,10 +2,7 @@ class AcquisitionActions extends Actions { - const DEVELOPER_REWARD = 250, - SESSION_KEY_DEVELOPER_CREDITS_ERROR = 'acquisition.developer-credits-error', - SESSION_KEY_DEVELOPER_CREDITS_SUCCESS = 'acquisition.developer-credits-success', - SESSION_KEY_DEVELOPER_CREDITS_WALLET_ADDRESS = 'acquisition.developer-credits-wallet-address'; + const DEVELOPER_REWARD = 250; public static function executeThanks() { @@ -47,27 +44,25 @@ class AcquisitionActions extends Actions public static function executeDeveloperProgram() { - $vars = [ - 'defaultWalletAddress' => Session::get(static::SESSION_KEY_DEVELOPER_CREDITS_WALLET_ADDRESS), - 'error' => Session::get(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR), - 'success' => Session::get(static::SESSION_KEY_DEVELOPER_CREDITS_SUCCESS) - ]; - Session::unsetKey(static::SESSION_KEY_DEVELOPER_CREDITS_SUCCESS); - Session::unsetKey(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR); - return ['acquisition/developer-program', $vars]; + return ['acquisition/developer-program', [ + 'defaultWalletAddress' => Session::get(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS), + 'error' => Session::getFlash(Session::KEY_DEVELOPER_CREDITS_ERROR), + 'success' => Session::getFlash(Session::KEY_DEVELOPER_CREDITS_SUCCESS) + ]]; } public static function executeDeveloperProgramPost() { $walletAddress = trim(Request::getPostParam('wallet')); - Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_WALLET_ADDRESS, $walletAddress); + Session::set(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS, $walletAddress); + if (!$walletAddress) { - Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR, 'Please provide a wallet address.'); + Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'Please provide a wallet address.'); } elseif (!preg_match('/^b[1-9A-HJ-NP-Za-km-z]{33}$/', $walletAddress)) { - Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR, 'This does not appear to be a valid wallet address.'); + Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'This does not appear to be a valid wallet address.'); } else { @@ -90,15 +85,15 @@ class AcquisitionActions extends Actions public static function executeDeveloperProgramGithubCallback() { $code = Request::getParam('code'); - $walletAddress = Session::get(static::SESSION_KEY_DEVELOPER_CREDITS_WALLET_ADDRESS); + $walletAddress = Session::get(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS); if (!$walletAddress) { - Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR, 'Your wallet address disappeared while authenticated with GitHub.'); + Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'Your wallet address disappeared while authenticated with GitHub.'); } elseif (!$code) { - Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR, 'This does not appear to be a valid response from GitHub.'); + Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'This does not appear to be a valid response from GitHub.'); } else { @@ -112,11 +107,11 @@ class AcquisitionActions extends Actions ]); if (!$authResponseData || !isset($authResponseData['access_token'])) { - Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR, 'Request to GitHub failed.'); + Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'Request to GitHub failed.'); } elseif (isset($authResponseData['error_description'])) { - Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR, 'GitHub replied: ' . $authResponseData['error_description']); + Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'GitHub replied: ' . $authResponseData['error_description']); } else { @@ -126,21 +121,55 @@ class AcquisitionActions extends Actions 'json_response' => true ]); - if (date('Y-m', strtotime($userResponseData['created_at'])) > '2017-01') + if (date('Y-m-d', strtotime($userResponseData['created_at'])) > '2017-01-30') { - Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR, 'This GitHub account is too recent.'); + Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'This GitHub account is too recent.'); } else { - // print_r($userResponseData); - /* - * TODO: send credits here, see success message below for relevant values - * (keep wallet address in success message) - */ + $lockName = 'github_dev_credits_write'; + $dataFile = ROOT_DIR . '/data/writeable/github_developer_credits'; - Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_SUCCESS, - 'Send credits to GitHub user ' . $userResponseData['login'] . ' (' . $userResponseData['email'] . ') at wallet address ' . - $walletAddress); + $lock = Lock::getLock($lockName, true); // EXCLUSIVE LOCK. IF SENDING CREDITS IS SLOW, THIS COULD BLOCK USERS + + $existing = is_file($dataFile) ? json_decode(file_get_contents($dataFile), true) : []; + + if (isset($existing[$userResponseData['login']])) + { + Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'You account already received credits.'); + } + else + { + list($code, $out, $err) = + Shell::exec('/usr/bin/lbrynet-cli send_amount_to_address amount=250 ' . escapeshellarg('address=' . $walletAddress)); + + if ($code != 0) + { + if (stripos($out, 'InsufficientFundsError') !== false) + { + Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, + 'Our wallet is running low on funds. Please ping jeremy@lbry.io so he can refill it, then try again.'); + } + else + { + Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, + 'Failed to send credits. This is an error on our side. Please email jeremy@lbry.io if it persists.'); + } + } + else + { + $existing[$userResponseData['login']] = [$userResponseData['email'], $walletAddress, date('Y-m-d H:i:s')]; + file_put_contents($dataFile, json_encode($existing)); + + Session::setFlash(Session::KEY_DEVELOPER_CREDITS_SUCCESS, + 'Send credits to GitHub user ' . $userResponseData['login'] . ' (' . $userResponseData['email'] . ') at wallet address ' . + $walletAddress); + + } + } + + Lock::freeLock($lock); + $lock = null; } } } diff --git a/lib/tools/Lock.class.php b/lib/tools/Lock.class.php new file mode 100644 index 00000000..4c5affbe --- /dev/null +++ b/lib/tools/Lock.class.php @@ -0,0 +1,70 @@ +