From efc8d346755a32f60e3678fb0582a47bbe91ffd8 Mon Sep 17 00:00:00 2001 From: Steven Crader Date: Sun, 4 Dec 2022 22:23:00 -0800 Subject: [PATCH] Add ignore and formatting --- .editorconfig | 11 +++++++ .gitignore | 1 + README.md | 15 +++++++++ hive-watcher.js | 82 +++++++++++++++++++++++++------------------------ index.html | 24 +++++++-------- 5 files changed, 81 insertions(+), 52 deletions(-) create mode 100644 .editorconfig create mode 100644 .gitignore diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..fdacf33 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +max_line_length = 120 +tab_width = 4 +ij_continuation_indent_size = 8 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/README.md b/README.md index 57fa513..dd8f413 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,17 @@ # podping-hivewatcher-js + A watcher script for the hive backed podping network. (Javascript) + +Uses [@hiveio/dhive](https://yarnpkg.com/package/@hiveio/dhive) to communicate with the Hive blockchain. + +# Use + +1. Add `hive-watcher.js` and `index.html` to a web server + 1. Ex using node: + 1. Run `npm install http-server -g` + 2. Run `http-server` + 1. Will start a server at `http://localhost:8080/` by default + 2. Ex using Python: + 1. Run `python -m http.server` + 2. Will start a server at `http://localhost:8000` by default +2. Open `index.html` in a web browser. Podpings will be added to list as they are received. diff --git a/hive-watcher.js b/hive-watcher.js index 9891b64..2b94568 100644 --- a/hive-watcher.js +++ b/hive-watcher.js @@ -56,11 +56,11 @@ const addressList = [ shuffleArray(addressList) console.log(`Using API address "${addressList[0]}"`) const client = new dhive.Client( - addressList, { - // reducing timeout and threshold makes fall over to other API address happen faster - timeout: 6000, // in ms - failoverThreshold: 1, - } + addressList, { + // reducing timeout and threshold makes fall over to other API address happen faster + timeout: 6000, // in ms + failoverThreshold: 1, + } ); let validAccounts = ['podping'] @@ -155,15 +155,17 @@ function handlePodpingPost(post, timestamp, blockNumber, transactionId) { let updateReason = postJson.reason || postJson.r || postJson.type let medium = postJson.medium - if (version === "1.0") { - if (!(PodpingReason.includes(updateReason) && PodpingMedium.includes(medium))) { - return - } - } else { + let versionValue = parseFloat(version) + if (isNaN(versionValue)) { // fallback to any possible // old posts didn't include an update type so still accept them if (updateReason !== undefined && updateReason !== "feed_update" && updateReason !== 1) return + } else { + // handle version 1.0 and newer + if (!(PodpingReason.includes(updateReason) && PodpingMedium.includes(medium))) { + return + } } let iris = postJson.iris || [] @@ -222,21 +224,21 @@ function isAccountAllowed(required_posting_auths) { } client.database.call('get_following', [validAccounts[0], null, 'blog', 100]) - .then( - /** - * Get all accounts that are accepted as a valid PodPing poster - * - * @param followers list of follower objects - */ - function (followers) { - for (let follower of followers) { - validAccounts = validAccounts.concat(follower.following) - } - } - ) - .then( - startStream - ) + .then( + /** + * Get all accounts that are accepted as a valid PodPing poster + * + * @param followers list of follower objects + */ + function (followers) { + for (let follower of followers) { + validAccounts = validAccounts.concat(follower.following) + } + } + ) + .then( + startStream + ) ; function startStream(blockNumber = undefined) { @@ -247,20 +249,20 @@ function startStream(blockNumber = undefined) { from: blockNumber, mode: dhive.BlockchainMode.Latest }) - .on('data', handleBlock) - .on('error', - function (error) { - console.error('Error occurred parsing stream') - console.error(error) - // Note: when an error occurs, the `end` event is emitted (see below) - } - ) - .on('end', - function () { - console.log('Reached end of stream') - // Note: this restart the stream - startStream(lastBlockNumber); - } - ); + .on('data', handleBlock) + .on('error', + function (error) { + console.error('Error occurred parsing stream') + console.error(error) + // Note: when an error occurs, the `end` event is emitted (see below) + } + ) + .on('end', + function () { + console.log('Reached end of stream') + // Note: this restart the stream + startStream(lastBlockNumber); + } + ); } diff --git a/index.html b/index.html index 8adb01d..8274f02 100644 --- a/index.html +++ b/index.html @@ -1,17 +1,17 @@ - - + + - Hive Watcher + Hive Watcher - - - - - -

Hive Posts

-

Parsing block #0

-
    - + + + + + +

    Hive Posts

    +

    Parsing block #0

    +
      +