mirror of
https://github.com/alexgo-io/stacks.js.git
synced 2026-04-28 17:25:51 +08:00
deprecating opendig and replacing with blockstore client/cli
This commit is contained in:
58
.gitignore
vendored
58
.gitignore
vendored
@@ -1,37 +1,57 @@
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Packages
|
||||
*.egg
|
||||
*.egg-info
|
||||
dist
|
||||
build
|
||||
eggs
|
||||
parts
|
||||
var
|
||||
sdist
|
||||
develop-eggs
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
env/
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
lib
|
||||
lib64
|
||||
__pycache__
|
||||
*.egg
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.coverage
|
||||
.tox
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*,cover
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Mr Developer
|
||||
.mr.developer.cfg
|
||||
.project
|
||||
.pydevproject
|
||||
# Django stuff:
|
||||
*.log
|
||||
|
||||
ignore
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
target/
|
||||
|
||||
57
blockstore_client/.gitignore
vendored
57
blockstore_client/.gitignore
vendored
@@ -1,57 +0,0 @@
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
env/
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*,cover
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
target/
|
||||
@@ -1,10 +0,0 @@
|
||||
Coinkit is maintained by few developers from Halfmoon Labs and various contributors to OpenNameSystem.org
|
||||
|
||||
Development Leads
|
||||
````````````````
|
||||
- Muneeb Ali| @muneeb
|
||||
- Ryan Shea | @ryaneshea
|
||||
|
||||
Patches and Suggestions
|
||||
````````````````
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 OpenNameSystem.org
|
||||
|
||||
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.
|
||||
@@ -1,82 +0,0 @@
|
||||
opendig
|
||||
=======
|
||||
|
||||
[](https://pypi.python.org/pypi/opendig/)
|
||||
[](https://pypi.python.org/pypi/opendig/)
|
||||
[](https://pypi.python.org/pypi/opendig>/)
|
||||
|
||||
### Table of Contents
|
||||
[Overview](#overview)
|
||||
[Installation](#installation)
|
||||
[Command Line Usage](#cli)
|
||||
[Python Package Usage](#pythonpackage)
|
||||
[Configuration](#configuration)
|
||||
|
||||
<a name="overview"/>
|
||||
## Overview
|
||||
|
||||
`opendig` is a command-line tool that extends the functionality of `dig` to be compatible with the Openname System. Specifically, it adds support for the resolution of blockchain user handles.
|
||||
|
||||
ONS extends DNS in a backwards-compatible way by supporting the registration and resolution of:
|
||||
|
||||
+ user handles on the blockchain (currently supported by opendig)
|
||||
+ domains on the blockchain (in the design phase)
|
||||
|
||||
#### ONS = ICANN DNS + blockchain handles + blockchain domains
|
||||
|
||||
User calls to opendig will return user data in a standard schema.
|
||||
|
||||
[Read about the schema](https://github.com/opennamesystem/openspecs)
|
||||
|
||||
<a name="installation"/>
|
||||
## Installation
|
||||
|
||||
```
|
||||
$ sudo pip install opendig
|
||||
```
|
||||
|
||||
<a name="cli"/>
|
||||
## Command-line Usage
|
||||
|
||||
```
|
||||
$ opendig +naval
|
||||
$ opendig startupboy.com
|
||||
```
|
||||
|
||||
<a name="pythonpackage"/>
|
||||
## Python Package Usage
|
||||
|
||||
```
|
||||
from opendig import ons_resolver
|
||||
print ons_resolver('naval')
|
||||
|
||||
from opendig import dns_resolver
|
||||
print dns_resolver('startupboy.com')
|
||||
```
|
||||
|
||||
<a name="configuration"/>
|
||||
## Configuration
|
||||
|
||||
OpenDig comes with pre-configured default servers 8.8.8.8 (public DNS server by Google) and 162.243.253.65, 107.170.167.141 (public ONS server by OneName). We *strongly* recommend using a local config file, and using your own servers. Instructions for setting up your own server can be found [here](https://github.com/opennamesystem/ons-server/blob/master/doc/build-debian.md).
|
||||
|
||||
```
|
||||
$ touch ~/.opendig
|
||||
$ vi ~/.opendig
|
||||
```
|
||||
A sample config looks like this:
|
||||
|
||||
```
|
||||
[dns]
|
||||
servers = 8.8.8.8, 8.8.4.4
|
||||
|
||||
[ons]
|
||||
#all these servers are queried and a check is performed that they return the same data
|
||||
#to reduce trust on any single party, use your own servers or multiple public servers
|
||||
servers = 162.243.253.65, 107.170.167.141
|
||||
|
||||
[namecoind]
|
||||
port = 8332
|
||||
user = opennamesystem
|
||||
passwd = opennamesystem
|
||||
use_https = True
|
||||
```
|
||||
@@ -1,52 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
OpenDig
|
||||
~~~~~
|
||||
|
||||
:copyright: (c) 2014 by OpenNameSystem.org
|
||||
:license: MIT, see LICENSE for more details.
|
||||
"""
|
||||
|
||||
import os
|
||||
import ConfigParser
|
||||
|
||||
__version__ = '0.1.0'
|
||||
|
||||
home_dir = os.path.expanduser('~')
|
||||
current_dir = os.path.abspath(os.path.dirname(__file__))
|
||||
|
||||
config_local = home_dir + '/.opendig'
|
||||
config_default = current_dir + '/config.py'
|
||||
|
||||
config = ConfigParser.ConfigParser()
|
||||
|
||||
|
||||
# ------------------------------
|
||||
def get_list(data):
|
||||
|
||||
output = []
|
||||
data = data.rsplit(',')
|
||||
|
||||
for item in data:
|
||||
item = item.lstrip(' ')
|
||||
item = item.rstrip(' ')
|
||||
output.append(item)
|
||||
|
||||
return output
|
||||
|
||||
# ------------------------------
|
||||
# if no local configuration then use the default servers
|
||||
try:
|
||||
config.read(config_local)
|
||||
DNS_SERVERS = get_list(config.get('dns', 'servers'))
|
||||
ONS_SERVERS = get_list(config.get('ons', 'servers'))
|
||||
NAMECOIND_PORT = config.get('namecoind', 'port')
|
||||
NAMECOIND_USER = config.get('namecoind', 'user')
|
||||
NAMECOIND_PASSWD = config.get('namecoind', 'passwd')
|
||||
USE_HTTPS = config.get('namecoind', 'use_https')
|
||||
except Exception as e:
|
||||
from opendig.config import *
|
||||
|
||||
from .dns_resolver import dns_resolver
|
||||
from .ons_resolver import ons_resolver
|
||||
from .opendig_cli import run_cli
|
||||
@@ -1,24 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
OpenDig
|
||||
~~~~~
|
||||
|
||||
:copyright: (c) 2014 by Openname.org
|
||||
:license: MIT, see LICENSE for more details.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Hack around absolute paths
|
||||
current_dir = os.path.abspath(os.path.dirname(__file__))
|
||||
parent_dir = os.path.abspath(current_dir + "/../")
|
||||
|
||||
sys.path.insert(0, parent_dir)
|
||||
|
||||
from opendig import run_cli
|
||||
|
||||
# ----------------------------------------
|
||||
if __name__ == '__main__':
|
||||
run_cli()
|
||||
@@ -1,20 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
OpenDig
|
||||
~~~~~
|
||||
|
||||
:copyright: (c) 2014 by Openname.org
|
||||
:license: MIT, see LICENSE for more details.
|
||||
"""
|
||||
|
||||
# these default options are provided only for the convenience of users
|
||||
# users should really specify their own servers in ~/.opendig (in ini format)
|
||||
|
||||
VERSION = 'v0.1-beta'
|
||||
|
||||
DNS_SERVERS = ['8.8.8.8', '8.8.4.4'] # use a Google DNS servers as default
|
||||
ONS_SERVERS = ['162.243.253.65', '107.170.167.141'] # default ONS servers
|
||||
NAMECOIND_PORT = 8332
|
||||
NAMECOIND_USER = 'opennamesystem'
|
||||
NAMECOIND_PASSWD = 'opennamesystem'
|
||||
USE_HTTPS = True
|
||||
@@ -1,54 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
OpenDig
|
||||
~~~~~
|
||||
|
||||
:copyright: (c) 2014 by OpenNameSystem.org
|
||||
:license: MIT, see LICENSE for more details.
|
||||
"""
|
||||
|
||||
import socket
|
||||
import dns.resolver
|
||||
|
||||
from opendig import DNS_SERVERS
|
||||
|
||||
ADDITIONAL_RDCLASS = 65535
|
||||
|
||||
# ----------------------------------------
|
||||
|
||||
|
||||
def dns_resolver(domain):
|
||||
|
||||
import dns.name
|
||||
import dns.message
|
||||
import dns.query
|
||||
import dns.flags
|
||||
|
||||
domain = dns.name.from_text(domain)
|
||||
if not domain.is_absolute():
|
||||
domain = domain.concatenate(dns.name.root)
|
||||
|
||||
request = dns.message.make_query(domain, dns.rdatatype.ANY)
|
||||
request.flags |= dns.flags.AD
|
||||
request.find_rrset(request.additional, dns.name.root, ADDITIONAL_RDCLASS,
|
||||
dns.rdatatype.OPT, create=True, force_unique=True)
|
||||
|
||||
data = dns.query.udp(request, DNS_SERVERS[0])
|
||||
return data
|
||||
|
||||
# ----------------------------------------
|
||||
|
||||
|
||||
def json_data(data):
|
||||
|
||||
# there is no real JSON standard for DNS data
|
||||
# it'd be nice to return json data
|
||||
|
||||
# for reply in data.answer:
|
||||
# reply = reply.to_text()
|
||||
# answers = reply.rsplit('\n')
|
||||
# for answer in answers:
|
||||
# print answer
|
||||
|
||||
return data
|
||||
@@ -1,69 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
OpenDig
|
||||
~~~~~
|
||||
|
||||
:copyright: (c) 2014 by OpenNameSystem.org
|
||||
:license: MIT, see LICENSE for more details.
|
||||
"""
|
||||
|
||||
from opendig import ONS_SERVERS, NAMECOIND_PORT, NAMECOIND_USER, \
|
||||
NAMECOIND_PASSWD, USE_HTTPS
|
||||
|
||||
import json
|
||||
import hashlib
|
||||
from coinrpc.namecoind_server import NamecoindServer
|
||||
from multiprocessing.pool import ThreadPool
|
||||
from collections import Counter
|
||||
|
||||
SERVER_CONFIRMATION_PERCENTAGE = 60
|
||||
|
||||
# currently using namecoind for storing data (but ONS can use any blockchain)
|
||||
# ---------------------------------------
|
||||
|
||||
|
||||
def error_reply(msg, code=-1):
|
||||
reply = {}
|
||||
reply['status'] = code
|
||||
reply['message'] = "ERROR: " + msg
|
||||
return reply
|
||||
|
||||
# -----------------------------------
|
||||
|
||||
|
||||
def ons_resolver(key):
|
||||
|
||||
def check_server(server):
|
||||
|
||||
try:
|
||||
namecoind = NamecoindServer(server, NAMECOIND_PORT, NAMECOIND_USER,
|
||||
NAMECOIND_PASSWD)
|
||||
return_data = namecoind.get_full_profile('u/' + key)
|
||||
return return_data
|
||||
except:
|
||||
return error_reply("Couldn't connect to namecoind")
|
||||
|
||||
pool = ThreadPool(len(ONS_SERVERS))
|
||||
|
||||
replies = pool.map(check_server, ONS_SERVERS)
|
||||
pool.close()
|
||||
pool.join()
|
||||
|
||||
data_hashes = []
|
||||
for reply in replies:
|
||||
data_hashes.append(hashlib.md5(json.dumps(reply)).hexdigest())
|
||||
|
||||
count = Counter(data_hashes)
|
||||
max_repeated_times = count.most_common()[0][1]
|
||||
|
||||
if max_repeated_times >= (SERVER_CONFIRMATION_PERCENTAGE/100.0) * len(ONS_SERVERS):
|
||||
return replies[0]
|
||||
else:
|
||||
return error_reply("Data from different ONS servers doens't match")
|
||||
|
||||
# ------------------------------------
|
||||
|
||||
if __name__ == "__main__":
|
||||
key = "ibrahim"
|
||||
print ons_resolver(key)
|
||||
@@ -1,138 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
OpenDig
|
||||
~~~~~
|
||||
|
||||
:copyright: (c) 2014 by OpenNameSystem.org
|
||||
:license: MIT, see LICENSE for more details.
|
||||
"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
import time
|
||||
import datetime
|
||||
import argparse
|
||||
|
||||
from opendig import dns_resolver, ons_resolver
|
||||
from .config import VERSION, DNS_SERVERS, ONS_SERVERS
|
||||
|
||||
|
||||
# -------------------------
|
||||
def run_cli():
|
||||
""" run cli
|
||||
"""
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description='OpenDig: Command-line client for Openname \
|
||||
(http://Openname.org)')
|
||||
|
||||
parser.add_argument("options", help="+USERNAME will get the user info, \
|
||||
DOMAIN will get domain info", type=str)
|
||||
|
||||
# Print default help message, if no argument is given
|
||||
if len(sys.argv) == 1:
|
||||
parser.print_help()
|
||||
exit(1)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
"""
|
||||
Check if its onename username or a domain name
|
||||
"""
|
||||
if str(args.options[0]) == '+': # username
|
||||
|
||||
username = args.options[1:]
|
||||
print_header(username)
|
||||
|
||||
try:
|
||||
data, elapsed_time = get_ons_data(username)
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
s = "\n;; Got answer:\n\n;; QUESTION SECTION:\n;+%s\n\n;; \
|
||||
ANSWER SECTION:\n" % (username)
|
||||
sys.stdout.write(s)
|
||||
|
||||
sys.stdout.write(pretty_dump(data))
|
||||
print_ons_footer(elapsed_time)
|
||||
|
||||
else: # domain
|
||||
|
||||
domain = args.options
|
||||
print_header(domain)
|
||||
start_time = time.time()
|
||||
|
||||
try:
|
||||
data = dns_resolver(domain)
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
s = "\n;; Got answer:\n\n;; QUESTION SECTION:\n;%s\n\n;; \
|
||||
ANSWER SECTION:\n" % (domain + ".")
|
||||
sys.stdout.write(s)
|
||||
|
||||
elapsed_time = round(time.time() - start_time, 3)
|
||||
elapsed_time = int(1000 * elapsed_time) # msecs
|
||||
for reply in data.answer:
|
||||
sys.stdout.write(reply.to_text() + '\n')
|
||||
|
||||
print_dns_footer(elapsed_time)
|
||||
|
||||
# -------------------------
|
||||
|
||||
|
||||
def pretty_dump(input):
|
||||
|
||||
return json.dumps(input, sort_keys=False, indent=4, separators=(',', ': '))
|
||||
|
||||
# -------------------------
|
||||
|
||||
|
||||
def print_header(query):
|
||||
|
||||
sys.stdout.write("\n;; <<>> OpenDig %s <<>> %s" % (VERSION, query))
|
||||
|
||||
# -------------------------
|
||||
|
||||
|
||||
def print_dns_footer(elapsed_time):
|
||||
|
||||
sys.stdout.write("\n;; Query time: %s msec\n" % elapsed_time)
|
||||
sys.stdout.write(";; SERVER: %s \n" % DNS_SERVERS[0])
|
||||
sys.stdout.write(";; WHEN: %s\n\n" % datetime.datetime.now().strftime(
|
||||
"%a %b %d %H:%M:%S %Y"))
|
||||
|
||||
# -------------------------
|
||||
|
||||
|
||||
def print_ons_footer(elapsed_time):
|
||||
|
||||
sys.stdout.write("\n\n;; Query time: %s msec\n" % elapsed_time)
|
||||
sys.stdout.write(";; SERVERS: ")
|
||||
for server in ONS_SERVERS:
|
||||
sys.stdout.write("%s " % server)
|
||||
sys.stdout.write("\n;; WHEN: %s\n\n" % datetime.datetime.now().strftime(
|
||||
"%a %b %d %H:%M:%S %Y"))
|
||||
|
||||
# -------------------------
|
||||
|
||||
|
||||
def get_ons_data(username):
|
||||
start_time = time.time()
|
||||
|
||||
try:
|
||||
data = ons_resolver(username)
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
elapsed_time = round(time.time() - start_time, 3)
|
||||
elapsed_time = int(1000 * elapsed_time) # msecs
|
||||
|
||||
return data, elapsed_time
|
||||
|
||||
# ----------------------------------------
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run_cli()
|
||||
@@ -1,2 +0,0 @@
|
||||
cement==2.2.2
|
||||
dnspython==1.11.1
|
||||
@@ -1,2 +0,0 @@
|
||||
[metadata]
|
||||
description-file = README.md
|
||||
@@ -1,32 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
OpenDig
|
||||
~~~~~
|
||||
|
||||
:copyright: (c) 2014 by OpenNameSystem.org
|
||||
:license: MIT, see LICENSE for more details.
|
||||
"""
|
||||
|
||||
from setuptools import setup
|
||||
|
||||
setup(
|
||||
name='opendig',
|
||||
version='0.1.0',
|
||||
url='https://github.com/opennamesystem/opendig',
|
||||
license='MIT',
|
||||
author='Muneeb Ali (@muneeb), Ryan Shea (@ryaneshea)',
|
||||
author_email='hello@halfmoonlabs.com',
|
||||
description="A command-line tool for the Open Name System (the equivalent of dig for DNS).",
|
||||
packages=['opendig'],
|
||||
scripts=['bin/opendig'],
|
||||
zip_safe=False,
|
||||
download_url='https://github.com/opennamesystem/opendig/archive/master.zip',
|
||||
install_requires=['cement==2.2.2','dnspython==1.11.1','coinrpc==0.1.0'],
|
||||
keywords=['domain', 'name', 'resolution', 'bitcoin', 'address'],
|
||||
classifiers=[
|
||||
'Intended Audience :: Developers',
|
||||
'License :: OSI Approved :: MIT License',
|
||||
'Operating System :: OS Independent',
|
||||
'Programming Language :: Python',
|
||||
],
|
||||
)
|
||||
Reference in New Issue
Block a user