initial commit

This commit is contained in:
Joshua Seigler 2020-01-30 18:01:41 -05:00
commit 8cc1ca4c36
8 changed files with 7813 additions and 0 deletions

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
node_modules
.vscode
.cache
dist

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 Joshua Seigler
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

19
README.md Normal file
View file

@ -0,0 +1,19 @@
## Summary
This is a web widget which will connect to the Dash Insight server and
monitor for transactions to addresses specified in an HTML page.
## Usage
In an HTML page, add this to the `<head>`:
```html
<script src="https://seigler.github.io/monitor-dash-address/index.js"></script>
<link rel="stylesheet" href="https://seigler.github.io/monitor-dash-address/styles.css">
```
...and add this in the page where you want an address to be monitored:
```html
<div data-dash-address-watch="XmGw5qrhtJcmp3qebCDg9aLZH4ugraeakx"></div>
```
## [Demo](https://seigler.github.io/monitor-dash-address/)

7645
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

22
package.json Normal file
View file

@ -0,0 +1,22 @@
{
"name": "monitor-dash-address",
"version": "1.0.0",
"description": "script to monitor a Dash address for activity and display it onscreen",
"main": "src/index.js",
"scripts": {
"dev": "parcel src/index.js src/styles.css src/index.html",
"build": "npm run clean && parcel build src/index.js src/styles.css src/index.html --public-url replacethiswithadot && sed -i \"s/replacethiswithadot/./g\" dist/index.html",
"clean": "rimraf ./dist/",
"deploy": "npm run clean && npm run build && git-directory-deploy --directory dist/"
},
"author": "Joshua Seigler",
"license": "MIT",
"dependencies": {
"socket.io-client": "^2.3.0"
},
"devDependencies": {
"parcel-bundler": "^1.12.4",
"git-directory-deploy": "^1.5.1",
"rimraf": "^3.0.1"
}
}

14
src/index.html Normal file
View file

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Demo: monitor a Dash address</title>
<script src="index.js"></script>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div data-dash-address-watch="XmGw5qrhtJcmp3qebCDg9aLZH4ugraeakx"></div>
</body>
</html>

67
src/index.js Normal file
View file

@ -0,0 +1,67 @@
window.addEventListener('load', function () {
const containers = document.querySelectorAll('div[data-dash-address-watch]');
const addresses = [], watchers = {};
var insight;
if (containers.length === 0) {
console.log('No addresses to monitor.')
return;
}
insight = require('socket.io-client').connect(
'https://insight.dash.org:443/'
);
containers.forEach(function (container) {
const address = container.getAttribute('data-dash-address-watch');
const status = document.createElement('div');
status.className = 'dash-address-watch-status';
status.textContent = 'Loading...';
const label = document.createElement('div');
label.className = 'dash-address-watch-label';
label.textContent = address;
const log = document.createElement('div');
log.className = 'dash-address-watch-log';
container.appendChild(label);
container.appendChild(status);
container.appendChild(log);
addresses.push(address);
watchers[address] = {
container,
label,
status,
log
};
});
insight.on('connect', function () {
Object.values(watchers).forEach(function (c) {
c.status.textContent = 'Watching...'
});
insight.emit('subscribe', 'inv');
});
insight.on('disconnect', function () {
Object.values(watchers).forEach(function (c) {
c.status.textContent = 'Reconnecting...'
});
});
insight.on('tx', function(data) {
addresses.forEach(function (address) {
const amount = data.vout.reduce(
function (accum, item) {
return accum + (
Object.keys(item)[0] === address
? Object.values(item)[0]
: 0
);
},
0
);
if (amount > 0) {
const a = document.createElement('a');
a.setAttribute('href', 'https://insight.dash.org/insight/tx/' +
data.txid);
a.textContent = 'Received ' + amount / 100000000 + ' DASH';
watchers[address].log.insertBefore(a, watchers[address].log.firstChild);
}
});
});
});

21
src/styles.css Normal file
View file

@ -0,0 +1,21 @@
[data-dash-address-watch] {
display: inline-block;
border: 1px solid gray;
padding: 1em;
width: 30ch;
border-radius: 0.25em;
box-shadow: 0.5em 0.5em 1.5em -0.5em black;
}
.dash-address-watch-label {
position: absolute;
font-size: 0.75em;
margin-top: -1.75em;
background-color: white;
}
.dash-address-watch-status {
text-transform: uppercase;
font-size: 0.75em;
}
.dash-address-watch-log > a {
display: block;
}