[Pettycoin-dev] Pettycoin from Python 3

Rusty Russell rusty at rustcorp.com.au
Thu Sep 11 13:36:58 EST 2014


Nelson Castillo <nelsoneci at gmail.com> writes:
> 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.

Hi Nelson,

        Great work!  Did you want some option which would put the length
at the front to make this easier?  We could use a second socket, or just
have a "prependlength" command which you would issue first.

> 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.

I think you're safe so far.

> 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

Nice!

> 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.

I would love an explorer!  In particular, I think pettycoin lends itself
to a graphical explorer: with 10 second block times I anticipate we will
have forks as the common case whereas bitcoin explorers tend to assume a
main fork and ignore others.  There's also a horizon, which is currently
1 month (or 3 days on the test network).  Finally, there are also four
different kinds of transactions: from gateway, to gateway, normal and
claim transactions.

My next development blog post (I'll CC those posts here from now on,
too) will detail the plans for alpha02; in particular I am aiming for
multiple gateways, so it'd be great to have an explorer which showed
their activity (from the bitcoin side, too).

Cheers!
Rusty.
PS.  For extra awesome, an explorer which a user could run locally :)



More information about the Pettycoin-dev mailing list