Skip to main content

A JSON RPC client for the Witnet Protocol.

Project description

witpy

Build Status

witpy is a library for interfacing with the Witnet protocol. ( See Witnet.io for more information )

Built on top of websockets and jsonrpcclient, it provides an easy way to automate wallet operations by node operators and any one else who might find it useful.

Quick Install:

> pip install witpy

Consider using virtualenv:

> sudo apt-get install virtualenv
> virtualenv env
> source env/bin/activate
(env) > pip install witpy

Usage:

Must have a Witnet node and wallet server running. See the Github for more information.

The WalletClient is a singleton and can be retrieved by:

from witpy.wallet import WalletClient

client = WalletClient.socket(url='127.0.0.1', port=11212)

All the functions in witpy/wallet/client.py act as a direct passthrough of the json-rpc API provided by the Witnet wallet server. The json-rpc "method": is called as a client function with the "params": being keyword arguments **kwargs. It returns the raw json-rpc response from the wallet server.

An example of requests:

from witpy.wallet import WalletClient
from witpy.radon.types import FILTERS, REDUCERS, TYPES
from witpy.radon.script import Script, Source, Aggregator, Tally

from witpy.transactions.data_request import DataRequest as Request
from witpy.transactions.rad_request import RadRequest

wallet_id = 'my-wallet-id'
session_id = client.unlock_wallet(wallet_id=wallet_id, password='secret')['session_id']


#
client = WalletClient.socket('127.0.0.1', port=11212)
bitstamp = Source('https://www.bitstamp.net/api/ticker/')
bitstamp.parse_map_json().get_float('last').multiply(1000).round()

blockchain = Source('https://blockchain.info/ticker')
blockchain.parse_map_json().get_map('USD').get_float('last').multiply(1000).round()

coindesk = Source('https://api.coindesk.com/v1/bpi/currentprice.json')
coindesk.parse_map_json().get_map('bpi').get_map('USD').get_float('rate_float').multiply(1000).round()
print()
# Set aggregator and Tally
aggregator = Aggregator(filters=[[witnet.FILTERS.deviation_standard, 1.5]], reducer=REDUCERS.average_mean)
tally = Tally(filters=[[FILTERS.deviation_standard, 1]], reducer=REDUCERS.average_mean)

# Test Radon
rad_request = RadRequest().add_source(bitstamp).add_source(blockchain).add_source(coindesk)
rad_request.set_aggregate(aggregator).set_tally(tally)
rad = client.run_rad_request(rad_request=rad_request.to_json())
print(rad)

# Test Data Request
data_request = Request().add_source(bitstamp).add_source(blockchain).add_source(coindesk)
data_request.set_aggregate(aggregator).set_tally(tally).set_quorum(20, 5, 2, 2, 51).set_fees(1, 1, 1, 1).schedule(0)
print(data_request.to_json())

# Create and Send Transaction
# trx = client.create_data_request(wallet_id=wallet_id, session_id=session_id, request=data_request.to_json(), fee=1)
# print(trx)
# print(trx['transaction'])

# resp = client.send_transaction(wallet_id=wallet_id, session_id=session_id, transaction=trx['transaction'])
# print(resp)

Disclaimer:*

witpy is provided on an "as is" basis without any warranties of any kind regarding any content, data, materials and/or services provided by this library. In no event shall the owners of, or contributors to, witpy be liable for any damages of any kind, including, but not limited to, loss of use, loss of profits, or loss of data arising out of or in any way connected with the use of the witpy library.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

witpy-0.8.1.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

witpy-0.8.1-py2.py3-none-any.whl (13.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file witpy-0.8.1.tar.gz.

File metadata

  • Download URL: witpy-0.8.1.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.0

File hashes

Hashes for witpy-0.8.1.tar.gz
Algorithm Hash digest
SHA256 41a0975d02f8adeee2e7b42ee469d2b598f36556b3802f565e01ff85a8d13028
MD5 b1cad7b20f65a6745dc8bc495f66820c
BLAKE2b-256 77611f528b23dd83206db1763a1285b2aea2685a9f03a68e6f2e09e29cdc2e18

See more details on using hashes here.

File details

Details for the file witpy-0.8.1-py2.py3-none-any.whl.

File metadata

  • Download URL: witpy-0.8.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.0

File hashes

Hashes for witpy-0.8.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3f50415ff387b3ac8d51f674295b40903bcad8b861e99d8afd77661749cea9c6
MD5 9e520fcba6d06efa76fae37e7f2f1946
BLAKE2b-256 97bcdf936b15af40687e3a76f816f2db5e1dbbfcf3622609f7e76e9f034e17b9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page