Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

Commit

Permalink
Define VersionName in settings, removed from jsons
Browse files Browse the repository at this point in the history
  • Loading branch information
metachris committed Jan 23, 2018
1 parent a02a61d commit 4a5dace
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 17 deletions.
7 changes: 4 additions & 3 deletions examples/json-rpc-api-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def main():
parser.add_argument("-p", "--privnet", action="store_true", default=False,
help="Use PrivNet instead of the default TestNet")
parser.add_argument("-c", "--config", action="store", help="Use a specific config file")
parser.add_argument("--port", action="store", help="Port to use", default=8000)
parser.add_argument("-t", "--set-default-theme", dest="theme",
choices=["dark", "light"],
help="Set the default theme to be loaded from the config file. Default: 'dark'")
Expand Down Expand Up @@ -73,13 +72,15 @@ def main():
ndb = NotificationDB.instance()
ndb.start()

api_server = JsonRpcApi(args.port)
api_server = JsonRpcApi(settings.NODE_PORT)

# Run
reactor.suggestThreadPoolSize(15)
NodeLeader.Instance().Start()

api_server.app.run('0.0.0.0', args.port)
host = "0.0.0.0"
print("Starting server on %s:%s" % (host, settings.NODE_PORT))
api_server.app.run(host, settings.NODE_PORT)


if __name__ == "__main__":
Expand Down
7 changes: 6 additions & 1 deletion neo/Settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import os
import logging
from json.decoder import JSONDecodeError

from neo import __version__
from neocore.Cryptography import Helper

import logzero
Expand Down Expand Up @@ -81,6 +83,9 @@ def net_name(self):
return 'TestNet'
return 'PrivateNet'

def __init__(self):
self.VERSION_NAME = "/NEO-PYTHON:%s/" % __version__

# Setup methods
def setup(self, config_file):
""" Load settings from a JSON config file """
Expand All @@ -106,7 +111,7 @@ def setup(self, config_file):
self.NODE_PORT = int(config['NodePort'])
self.WS_PORT = config['WsPort']
self.URI_PREFIX = config['UriPrefix']
self.VERSION_NAME = config['VersionName']

self.BOOTSTRAP_FILE = config['BootstrapFile']

Helper.ADDRESS_VERSION = self.ADDRESS_VERSION
Expand Down
12 changes: 10 additions & 2 deletions neo/api/JSONRPC/JsonRpcApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
* http://www.jsonrpc.org/specification
"""
import json
import random
from json.decoder import JSONDecodeError

from klein import Klein
from logzero import logger

from neo import __version__
from neo.Settings import settings
from neo.Core.Blockchain import Blockchain
from neo.api.utils import json_response
from neo.Core.State.AccountState import AccountState
Expand Down Expand Up @@ -65,10 +67,16 @@ def internalError(message=None):
class JsonRpcApi(object):
app = Klein()
port = None
nonce = None

def __init__(self, port):
self.port = port

# `nonce` in neo-cli this comes from https://github.com/neo-project/neo/blob/46c635adda6cf61090a67a3bef0f3bb1bc85dd81/neo/Network/LocalNode.cs#L68
# In neo-python the closest thing to it is https://github.com/CityOfZion/neo-python/blob/master/neo/Network/NeoNode.py#L34
# since we don't get direct access to this NeoNode, we generate a new nonce here
self.nonce = random.randint(1294967200, 4294967200)

#
# JSON-RPC API Route
#
Expand Down Expand Up @@ -203,8 +211,8 @@ def json_rpc_method_handler(self, method, params):
elif method == "getversion":
return {
"port": self.port,
"nonce": 771199013, # TODO: make this the real nonce, currently taken straight from testnet neo-cli
"useragent": "/neo-python:%s/" % __version__ # This ok, or should we mimic `/NEO:2.6.0/`?
"nonce": self.nonce,
"useragent": settings.VERSION_NAME
}

elif method == "getrawtransaction":
Expand Down
2 changes: 2 additions & 0 deletions neo/api/JSONRPC/neo-cli-json-rpc-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Documentation for the JSON-RPC implementation
curl -X POST http://seed2.neo.org:20332 -H 'Content-Type: application/json' -d '{ "jsonrpc": "2.0", "id": 5, "method": "getrawmempool", "params": [] }'
{ "jsonrpc": "2.0", "id": 5, "result": [] }

On MainNet there are actually entries, each of which has this format: `0xde3bc1dead8a89b06787db663b59c4f33efe0afe6b97b1c9c997f2695d7ae0da`

## `getversion`

curl -X POST http://seed2.neo.org:20332 -H 'Content-Type: application/json' -d '{ "jsonrpc": "2.0", "id": 5, "method": "getversion", "params": [] }'
Expand Down
2 changes: 1 addition & 1 deletion neo/api/JSONRPC/test_json_rpc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,4 @@ def test_get_version(self):
mock_req = mock_request(json.dumps(req).encode("utf-8"))
res = json.loads(self.app.home(mock_req))
self.assertEqual(res["result"]["port"], 20333)
self.assertEqual(res["result"]["useragent"], "/neo-python:%s/" % __version__)
self.assertEqual(res["result"]["useragent"], "/NEO-PYTHON:%s/" % __version__)
2 changes: 0 additions & 2 deletions neo/api/REST/NotificationRestApi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
The REST API is using the Python package 'klein', which makes it possible to
create HTTP routes and handlers with Twisted in a similar style to Flask:
https://github.com/twisted/klein
Expand Down
3 changes: 1 addition & 2 deletions protocol.coz.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
"UriPrefix": [ "http://*:20332"],
"SslCert": "",
"SslCertPassword": "",
"VersionName":"/NEO-PYTHON:2.3.4/",
"BootstrapFile":"",
"DebugStorage":1
}
}
}
3 changes: 1 addition & 2 deletions protocol.mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@
"UriPrefix": [ "http://*:10332" ],
"SslCert": "",
"SslCertPassword": "",
"VersionName":"/NEO-PYTHON:2.3.4/",
"BootstrapFile":"https://s3.us-east-2.amazonaws.com/cityofzion/bootstrap_main/Chain1550000.tar.gz",
"DebugStorage":1
}
}
}
3 changes: 1 addition & 2 deletions protocol.privnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
"UriPrefix": [ "http://*:20332" ],
"SslCert": "",
"SslCertPassword": "",
"VersionName":"/NEO-PYTHON:2.3.4/",
"BootstrapFile":"",
"DebugStorage":1
}
}
}
3 changes: 1 addition & 2 deletions protocol.testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"UriPrefix": [
"http://*:20332"
],
"VersionName": "/NEO-PYTHON:2.3.4/",
"WsPort": 20334,
"BootstrapFile":"https://s3.us-east-2.amazonaws.com/cityofzion/bootstrap_testnet/Chain780000.tar.gz",
"DebugStorage":1
Expand Down Expand Up @@ -51,4 +50,4 @@
"RegisterTransaction": 100
}
}
}
}

0 comments on commit 4a5dace

Please sign in to comment.