Author Topic: [Python-API] python-bitsharesrpc  (Read 1977 times)

0 Members and 1 Guest are viewing this topic.

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
you can write a bitshares command line interface with just a few lines of python:
Minimalistic CLI:
Code: [Select]
#!/usr/bin/python
import bitsharesrpc, json
rpc = bitsharesrpc.client("http://localhost:1998/rpc", "username", "password")
while 1:
     cmd = raw_input(">>").split()
     print(json.dumps(rpc.rpcexec({"method":cmd[0],"params":list(cmd[1:]),
                                   "jsonrpc":"2.0","id":0}),indent=4))

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
So is this a potential vulnerability you fixed?
Hu? .. what vulnerability are you talking about?

The issues I recently fixed concerned the "genbtskey.py" script that replicated the generation of BTS pubkeys and addresses ..
The module in the OP is just a rewrite of the btsrpcapi.py class to make it alot easier to use and a standalone module ..

the only security issue I can see with this module is if people run this over the plain internet and not via tunnel .. I am unaware that the RPC can be run via SSL .. @toast ?
If it can run via SSL .. it's the responsibility of the coder to also ACCESS the RPC via SSL .. but if there is SSL available I could modify the script to ENFORCE the use of SSL if you wish


//edit: I reread you post and figured out yo meant it differently. The OP announces a python module that makes it alot easier to use inferface python with BitShares ..

Offline mike623317

  • Hero Member
  • *****
  • Posts: 637
    • View Profile
So is this a potential vulnerability you fixed?

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
python-bitsharesrpc
Python module for the BitShares client

Download
https://github.com/xeroc/python-bitsharesrpc

Installation
Code: [Select]
git clone https://github.com/xeroc/python-bitsharesrpc
cd python-bitsharesrpc
python setup install    # (optionally with parameter --user fo non-root installations)

Requirements
  • python-requests

Usage
All RPC commands of the BitShares client are exposed as methods in the class bitsharesrpc. Once an instance of bitsharesrpc is created, i.e.,

Code: [Select]
import bitsharesrpc
import config
rpc = bitsharesrpc.client(config.url, config.user, config.passwd)
any rpc command can be issued using the instance via the syntax rpc.command(parameters). Example:

Code: [Select]
rpc.get_info()
rpc.open_wallet("default")
rpc.ask(account, amount, quote, price, base)
...

Example to unlock the wallet
Code: [Select]
#!/usr/bin/python
import bitsharesrpc
import config

if __name__ == "__main__":
 rpc = bitsharesrpc.client(config.url, config.user, config.passwd)
 print(rpc.wallet_open(config.wallet))
 print(rpc.unlock(999999, config.unlock))

Example to lock the wallet
Code: [Select]
#!/usr/bin/python
import bitsharesrpc
import config

if __name__ == "__main__":
 rpc = bitsharesrpc.client(config.url, config.user, config.passwd)
 print rpc.wallet_open("delegate")
 print rpc.lock()

Minimalistic CLI:
Code: [Select]
#!/usr/bin/python
import bitsharesrpc, json
rpc = bitsharesrpc.client("http://localhost:1998/rpc", "username", "password")
while 1:
     cmd = raw_input(">>").split()
     print(json.dumps(rpc.rpcexec({"method":cmd[0],"params":list(cmd[1:]),
                                   "jsonrpc":"2.0","id":0}),indent=4))
« Last Edit: January 28, 2015, 02:10:14 pm by xeroc ¯\_(ツ)_/¯ »