Skip to content

Commit

Permalink
Support https protocol (#4)
Browse files Browse the repository at this point in the history
* Support https protocol

* Update github repo url

* Line length fix
  • Loading branch information
hayorov authored Feb 27, 2019
1 parent aca9fb4 commit e62ecb6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 36 deletions.
47 changes: 24 additions & 23 deletions multichaincli/client.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
import requests
import json
from base64 import b64encode
import logging
import requests
from base64 import b64encode

log = logging.getLogger(__name__)

Expand All @@ -11,13 +11,13 @@ class Multichain():
__id_count = 0

def __init__(self,
rpcuser,
rpcpasswd,
rpchost,
rpcport,
chainname,
rpc_call=None
):
rpcuser,
rpcpasswd,
rpchost,
rpcport,
chainname,
rpc_call=None
):
self.__rpcuser = rpcuser
self.__rpcpasswd = rpcpasswd
self.__rpchost = rpchost
Expand All @@ -27,10 +27,10 @@ def __init__(self,
['Basic', b64encode(':'.join([rpcuser, rpcpasswd]).encode()).decode()]
)
self.__headers = {'Host': self.__rpchost,
'User-Agent': 'Multichain python binding',
'Authorization': self.__auth_header,
'Content-type': 'application/json'
}
'User-Agent': 'Multichain python binding',
'Authorization': self.__auth_header,
'Content-type': 'application/json'
}
self.__rpc_call = rpc_call

def __getattr__(self, name):
Expand All @@ -40,20 +40,21 @@ def __getattr__(self, name):
if self.__rpc_call is not None:
name = "%s.%s" % (self.__rpc_call, name)
return Multichain(self.__rpcuser,
self.__rpcpasswd,
self.__rpchost,
self.__rpcport,
self.__chainname,
name)
self.__rpcpasswd,
self.__rpchost,
self.__rpcport,
self.__chainname,
name)

def __call__(self, *args):
Multichain.__id_count += 1
postdata = {'chain_name': self.__chainname,
'version': '1.1',
'params': args,
'method': self.__rpc_call,
'id': Multichain.__id_count}
url = ''.join(['http://', self.__rpchost, ':', self.__rpcport])
'version': '2.0',
'params': args,
'method': self.__rpc_call,
'id': Multichain.__id_count}
protocol = 'https' if int(self.__rpcport) == 443 else 'http'
url = '{0}://{1}:{2}'.format(protocol, self.__rpchost, self.__rpcport)
encoded = json.dumps(postdata)
log.info("Request: %s" % encoded)
r = requests.post(url, data=encoded, headers=self.__headers)
Expand Down
28 changes: 15 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
from setuptools import setup, find_packages


# Utility function to read the README file.
# Used for the long_description. It's nice, because now 1) we have a top level
# README file and 2) it's easier to type in the README file than to put a raw
Expand All @@ -11,16 +12,17 @@ def read(fname):


setup(name='multichaincli',
version='1.0.7',
description='A python binding for Multichain Json-RPC API',
long_description=read('README.md'),
license="BSD",
author='Alex Khaerov, Federico Cardoso',
author_email='[email protected], [email protected]',
url='https://github.com/chainstack/multichain-python-sdk',
keywords='multichain python blockchain jsonrpc',
packages=find_packages(),
install_requires=[
'requests>=2.20.0',
],
)
version='1.1.0',
description='A python binding for Multichain Json-RPC API',
long_description=read('README.md'),
license="BSD",
author='Alex Khaerov, Federico Cardoso',
author_email='[email protected],'
'[email protected]',
url='https://github.com/chainstack/multichaincli',
keywords='multichain python blockchain jsonrpc',
packages=find_packages(),
install_requires=[
'requests>=2.20.0',
],
)

0 comments on commit e62ecb6

Please sign in to comment.