Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nyxpay committed Feb 11, 2018
0 parents commit 13d764d
Show file tree
Hide file tree
Showing 24 changed files with 2,508 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 The Dash Developers
Copyright (c) 2018 The Nyx Developers

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.
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Nyx Sentinel

An all-powerful toolset for Nyx.

Sentinel is an autonomous agent for persisting, processing and automating Nyx V12.1 governance objects and tasks, and for expanded functions in the upcoming Nyx V13 release (Evolution).

Sentinel is implemented as a Python application that binds to a local version 12.1 nyxd instance on each Nyx V12.1 Masternode.

This guide covers installing Sentinel onto an existing 12.1 Masternode in Ubuntu 14.04 / 16.04.

## Installation

### 1. Install Prerequisites

Make sure Python version 2.7.x or above is installed:

python --version

Update system packages and ensure virtualenv is installed:

$ sudo apt-get update
$ sudo apt-get -y install python-virtualenv

Make sure the local Nyx daemon running is at least version 12.1 (120100)

$ nyx-cli getinfo | grep version

### 2. Install Sentinel

Clone the Sentinel repo and install Python dependencies.

$ git clone https://github.com/nyxpay/sentinel.git && cd sentinel
$ virtualenv ./venv
$ ./venv/bin/pip install -r requirements.txt

### 3. Set up Cron

Set up a crontab entry to call Sentinel every minute:

$ crontab -e

In the crontab editor, add the lines below, replacing '/home/YOURUSERNAME/sentinel' to the path where you cloned sentinel to:

* * * * * cd /home/YOURUSERNAME/sentinel && ./venv/bin/python bin/sentinel.py >/dev/null 2>&1

## Configuration

An alternative (non-default) path to the `nyx.conf` file can be specified in `sentinel.conf`:

nyx_conf=/path/to/nyx.conf

## Troubleshooting

To view debug output, set the `SENTINEL_DEBUG` environment variable to anything non-zero, then run the script manually:

$ SENTINEL_DEBUG=1 ./venv/bin/python bin/sentinel.py

### License

Released under the MIT license, under the same terms as Nyx itself. See [LICENSE](LICENSE) for more info.
62 changes: 62 additions & 0 deletions bin/dbtest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*-
import pdb
from pprint import pprint
import re
import sys
import os
sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__), '../lib')))
import config
from models import Superblock, Proposal, GovernanceObject, Setting, Signal, Vote, Outcome, Watchdog
from models import VoteSignals, VoteOutcomes
from peewee import PeeweeException # , OperationalError, IntegrityError
from nyxd import NyxDaemon
import nyxlib
from decimal import Decimal
nyxd = NyxDaemon.from_nyx_conf(config.nyx_conf)
import misc
# ==============================================================================
# do stuff here

pr = Proposal(
name='proposal7',
url='https://nyxcentral.com/proposal7',
payment_address='yTC62huR4YQEPn9AJHjnQxxreHSbgAoatV',
payment_amount=39.23,
start_epoch=1483250400,
end_epoch=1491022800,
)

# sb = Superblock(
# event_block_height = 62500,
# payment_addresses = "yYe8KwyaUu5YswSYmB3q3ryx8XTUu9y7Ui|yTC62huR4YQEPn9AJHjnQxxreHSbgAoatV",
# payment_amounts = "5|3"
# )


# TODO: make this a test, mock 'nyxd' and tie a test block height to a
# timestamp, ensure only unit testing a within_window method
#
# also, create the `within_window` or similar method & use that.
#
bh = 131112
bh_epoch = nyxd.block_height_to_epoch(bh)

fudge = 72000
window_start = 1483689082 - fudge
window_end = 1483753726 + fudge

print("Window start: %s" % misc.epoch2str(window_start))
print("Window end: %s" % misc.epoch2str(window_end))
print("\nbh_epoch: %s" % misc.epoch2str(bh_epoch))


if (bh_epoch < window_start or bh_epoch > window_end):
print("outside of window!")
else:
print("Within window, we're good!")

# pdb.set_trace()
# nyxd.get_object_list()
# ==============================================================================
# pdb.set_trace()
1
10 changes: 10 additions & 0 deletions bin/dehex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import binascii
import sys

usage = "%s <hex>" % sys.argv[0]

if len(sys.argv) < 2:
print(usage)
else:
json = binascii.unhexlify(sys.argv[1])
print(json)
21 changes: 21 additions & 0 deletions bin/rehex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import simplejson
import binascii
import sys
import pdb
from pprint import pprint
import sys
import os
sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__), '../lib')))
import nyxlib
# ============================================================================
usage = "%s <hex>" % sys.argv[0]

obj = None
if len(sys.argv) < 2:
print(usage)
sys.exit(1)
else:
obj = nyxlib.deserialise(sys.argv[1])

pdb.set_trace()
1
Loading

0 comments on commit 13d764d

Please sign in to comment.