[Pettycoin-dev] Pettycoin from Python 3

Nelson Castillo nelsoneci at gmail.com
Mon Sep 8 20:54:37 EST 2014


Hello there.

I wrote some code to call Pettycoin from Python 3.

  https://github.com/arhuaco/pypettycoin/

First, fun with JSON.

When Pettycoin sends JSON replies the size of the reply is not known in
advance, so you have to use non-blocking UNIX sockets and parse on the fly.

I don't know if there is an easy way to do this, I could not find it. I
wrote a Python class to read Pettycoin replies:

https://github.com/arhuaco/pypettycoin/blob/master/pettycoin/json_socket_reader.py
It makes use of a simple socket wrapper:

https://github.com/arhuaco/pypettycoin/blob/master/pettycoin/socket_wrapper.py

The  code does not parse JSON on the fly, or better, it has trivial parsing
and only counts '{' and '}'. Thus it will fail if a JSON reply contains a
string with those characters. It has not happened with the calls I have
done so far. I can improve this later if needed.

Second, Bad Proxy.

A casual user might find it difficult to call the Pettycoin JSON interface
so I wrote a proxy. It is less efficient but easier to call. It is also
insecure because another user could make Pettycoin calls (by default from
localhost). I called it Bad Proxy to keep this in mind, in case someone
wants to use it for something serious.
  https://github.com/arhuaco/pypettycoin/blob/master/pettycoin/bad_proxy.py
Sample usage:

https://github.com/arhuaco/pypettycoin/blob/master/pettycoin/bad_proxy_usage_example.py

And last, say 'hello' to the web. Just the output from the 'getinfo' call:
  http://104.131.198.157:10002
code:

https://github.com/arhuaco/pypettycoin/blob/master/pettycoin/simple_explorer.py

As time permits I would like to write a simple explorer. It will help me
learn about the Pettycoin data structures. I make no promises but I will
try to make time for it.

Cheers,
Nel.-
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ozlabs.org/pipermail/pettycoin-dev/attachments/20140908/776ad39d/attachment.html>


More information about the Pettycoin-dev mailing list