<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Sep 10, 2014 at 10:36 PM, Rusty Russell <span dir="ltr"><<a href="mailto:rusty@rustcorp.com.au" target="_blank">rusty@rustcorp.com.au</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">Nelson Castillo <<a href="mailto:nelsoneci@gmail.com">nelsoneci@gmail.com</a>> writes:<br>
> Hello there.<br>
><br>
> I wrote some code to call Pettycoin from Python 3.<br>
><br>
>   <a href="https://github.com/arhuaco/pypettycoin/" target="_blank">https://github.com/arhuaco/pypettycoin/</a><br>
><br>
> First, fun with JSON.<br>
><br>
> When Pettycoin sends JSON replies the size of the reply is not known in<br>
> advance, so you have to use non-blocking UNIX sockets and parse on the fly.<br>
<br>
</span>Hi Nelson,<br>
<br>
        Great work!  Did you want some option which would put the length<br>
at the front to make this easier?  We could use a second socket, or just<br>
have a "prependlength" command which you would issue first.<br></blockquote><div><br></div><div><div>Hi there Rusty.</div><div><br></div><div>Do you know the length of the reply in advance?<br></div><div><br></div><div>Another way of stating the question: Does adding "prependlength" mean you have to use a buffer (more memory)?<br></div><div><br></div><div>Now that the code to wait for Pettycoin replies is written I do not really care. It just works :-)</div><div>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).</div><div> <br></div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<span class=""><br>
> I don't know if there is an easy way to do this, I could not find it. I<br>
> wrote a Python class to read Pettycoin replies:<br>
><br>
> <a href="https://github.com/arhuaco/pypettycoin/blob/master/pettycoin/json_socket_reader.py" target="_blank">https://github.com/arhuaco/pypettycoin/blob/master/pettycoin/json_socket_reader.py</a><br>
> It makes use of a simple socket wrapper:<br>
><br>
> <a href="https://github.com/arhuaco/pypettycoin/blob/master/pettycoin/socket_wrapper.py" target="_blank">https://github.com/arhuaco/pypettycoin/blob/master/pettycoin/socket_wrapper.py</a><br>
><br>
> The  code does not parse JSON on the fly, or better, it has trivial parsing<br>
> and only counts '{' and '}'. Thus it will fail if a JSON reply contains a<br>
> string with those characters. It has not happened with the calls I have<br>
> done so far. I can improve this later if needed.<br>
<br>
</span>I think you're safe so far.<br>
<span class=""><br>
> Second, Bad Proxy.<br>
><br>
> A casual user might find it difficult to call the Pettycoin JSON interface<br>
> so I wrote a proxy. It is less efficient but easier to call. It is also<br>
> insecure because another user could make Pettycoin calls (by default from<br>
> localhost). I called it Bad Proxy to keep this in mind, in case someone<br>
> wants to use it for something serious.<br>
>   <a href="https://github.com/arhuaco/pypettycoin/blob/master/pettycoin/bad_proxy.py" target="_blank">https://github.com/arhuaco/pypettycoin/blob/master/pettycoin/bad_proxy.py</a><br>
> Sample usage:<br>
><br>
> <a href="https://github.com/arhuaco/pypettycoin/blob/master/pettycoin/bad_proxy_usage_example.py" target="_blank">https://github.com/arhuaco/pypettycoin/blob/master/pettycoin/bad_proxy_usage_example.py</a><br>
<br>
</span>Nice!<br>
<span class=""><br>
> And last, say 'hello' to the web. Just the output from the 'getinfo' call:<br>
>   <a href="http://104.131.198.157:10002" target="_blank">http://104.131.198.157:10002</a><br>
> code:<br>
><br>
> <a href="https://github.com/arhuaco/pypettycoin/blob/master/pettycoin/simple_explorer.py" target="_blank">https://github.com/arhuaco/pypettycoin/blob/master/pettycoin/simple_explorer.py</a><br>
><br>
> As time permits I would like to write a simple explorer. It will help me<br>
> learn about the Pettycoin data structures. I make no promises but I will<br>
> try to make time for it.<br>
<br>
</span>I would love an explorer!  In particular, I think pettycoin lends itself<br>
to a graphical explorer: with 10 second block times I anticipate we will<br>
have forks as the common case whereas bitcoin explorers tend to assume a<br>
main fork and ignore others.  There's also a horizon, which is currently<br>
1 month (or 3 days on the test network).  Finally, there are also four<br>
different kinds of transactions: from gateway, to gateway, normal and<br>
claim transactions.<br>
<br>
My next development blog post (I'll CC those posts here from now on,<br>
too) will detail the plans for alpha02; in particular I am aiming for<br>
multiple gateways, so it'd be great to have an explorer which showed<br>
their activity (from the bitcoin side, too).<br>
<br>
Cheers!<br>
<span class=""><font color="#888888">Rusty.<br>
</font></span>PS.  For extra awesome, an explorer which a user could run locally :)<br>
<br>
</blockquote></div><br></div></div>