[Pettycoin-dev] Pettycoin from Python 3

Nelson Castillo nelsoneci at gmail.com
Thu Sep 11 14:21:53 EST 2014


On Wed, Sep 10, 2014 at 10:36 PM, Rusty Russell <rusty at rustcorp.com.au>
wrote:

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

Hi there Rusty.

Do you know the length of the reply in advance?

Another way of stating the question: Does adding "prependlength" mean you
have to use a buffer (more memory)?

Now that the code to wait for Pettycoin replies is written I do not really
care. It just works :-)
And I think it is easy to port it to other languages, specially if the
Pettycoin replies allow trivial parsing (never contain '{' or  '}' in
strings).


>
> > 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 :)
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ozlabs.org/pipermail/pettycoin-dev/attachments/20140910/e48d44f2/attachment.html>


More information about the Pettycoin-dev mailing list