<div dir="ltr">Hey there,<div><br></div><div>So the essence of this protocol is as follows:</div><div><br></div><div><pre style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;margin-top:0px;margin-bottom:0px;color:rgb(51,51,51);line-height:18px">
<div class="" id="LC72" style="padding-left:10px"><span class="" style="font-weight:bold">enum</span> <span class="" style>PaymentFrequencyType</span> <span class="" style>{</span></div><div class="" id="LC73" style="padding-left:10px">
        <span class="" style="color:teal">WEEKLY</span> <span class="" style="font-weight:bold">=</span> <span class="" style="color:rgb(0,153,153)">1</span><span class="" style>;</span></div><div class="" id="LC74" style="padding-left:10px">
        <span class="" style="color:teal">MONTHLY</span> <span class="" style="font-weight:bold">=</span> <span class="" style="color:rgb(0,153,153)">2</span><span class="" style>;</span></div><div class="" id="LC75" style="padding-left:10px">
        <span class="" style="color:teal">QUARTERLY</span> <span class="" style="font-weight:bold">=</span> <span class="" style="color:rgb(0,153,153)">3</span><span class="" style>;</span></div><div class="" id="LC76" style="padding-left:10px">
        <span class="" style="color:teal">ANNUAL</span> <span class="" style="font-weight:bold">=</span> <span class="" style="color:rgb(0,153,153)">4</span><span class="" style>;</span></div><div class="" id="LC77" style="padding-left:10px">
<span class="" style>}</span></div><div class="" id="LC78" style="padding-left:10px"><span class="" style="font-weight:bold">message</span> <span class="" style="color:rgb(68,85,136);font-weight:bold">RecurringPaymentDetails</span> <span class="" style>{</span></div>
<div class="" id="LC78" style="padding-left:10px"><span class="" style>        </span><span style="color:rgb(153,153,136);font-style:italic">// Namespace for the merchant such as org.foo.bar</span></div><div class="" id="LC79" style="padding-left:10px">
        <span class="" style="font-weight:bold">required</span> <span class="" style="color:rgb(68,85,136);font-weight:bold">string</span> <span class="" style="color:teal">merchant_id</span> <span class="" style="font-weight:bold">=</span> <span class="" style="color:rgb(0,153,153)">1</span><span class="" style>;</span>                 </div>
<div class="" id="LC79" style="padding-left:10px">        <span style="color:rgb(153,153,136);font-style:italic">// Id for the recurring subscription</span></div><div class="" id="LC80" style="padding-left:10px">        <span class="" style="font-weight:bold">required</span> <span class="" style="color:rgb(68,85,136);font-weight:bold">bytes</span> <span class="" style="color:teal">subscription_id</span> <span class="" style="font-weight:bold">=</span> <span class="" style="color:rgb(0,153,153)">2</span><span class="" style>;</span>              </div>
<div class="" id="LC80" style="padding-left:10px">        <span style="color:rgb(153,153,136);font-style:italic">// Contracts associated with a given subscription</span></div><div class="" id="LC81" style="padding-left:10px">
        <span class="" style="font-weight:bold">repeated</span> <span class="" style>RecurringPaymentContract</span> <span class="" style="color:teal">contracts</span> <span class="" style="font-weight:bold">=</span> <span class="" style="color:rgb(0,153,153)">3</span><span class="" style>;</span> </div>
<div class="" id="LC82" style="padding-left:10px"><span class="" style>}</span></div><div class="" id="LC83" style="padding-left:10px"><span class="" style="font-weight:bold">message</span> <span class="" style="color:rgb(68,85,136);font-weight:bold">RecurringPaymentContract</span> <span class="" style>{</span></div>
<div class="" id="LC83" style="padding-left:10px"><span class="" style>        </span><span style="color:rgb(153,153,136);font-style:italic">// Unique id for a given contract</span></div><div class="" id="LC84" style="padding-left:10px">
        <span class="" style="font-weight:bold">required</span> <span class="" style="color:rgb(68,85,136);font-weight:bold">bytes</span> <span class="" style="color:teal">contract_id</span> <span class="" style="font-weight:bold">=</span> <span class="" style="color:rgb(0,153,153)">1</span><span class="" style>;</span>                           </div>
<div class="" id="LC84" style="padding-left:10px">        <span style="color:rgb(153,153,136);font-style:italic">// URL to poll to get the next PaymentRequest</span></div><div class="" id="LC85" style="padding-left:10px">
        <span class="" style="font-weight:bold">required</span> <span class="" style="color:rgb(68,85,136);font-weight:bold">string</span> <span class="" style="color:teal">polling_url</span> <span class="" style="font-weight:bold">=</span> <span class="" style="color:rgb(0,153,153)">2</span><span class="" style>;</span>                          </div>
<div class="" id="LC85" style="padding-left:10px">        <span style="color:rgb(153,153,136);font-style:italic">// Timestamp; when this contract starts</span></div><div class="" id="LC86" style="padding-left:10px">        <span class="" style="font-weight:bold">required</span> <span class="" style="color:rgb(68,85,136);font-weight:bold">uint64</span> <span class="" style="color:teal">starts</span> <span class="" style="font-weight:bold">=</span> <span class="" style="color:rgb(0,153,153)">3</span><span class="" style>;</span>                               </div>
<div class="" id="LC86" style="padding-left:10px">        <span style="color:rgb(153,153,136);font-style:italic">// Timestamp; when this contract should be considered invalid </span></div><div class="" id="LC87" style="padding-left:10px">
        <span class="" style="font-weight:bold">optional</span> <span class="" style="color:rgb(68,85,136);font-weight:bold">uint64</span> <span class="" style="color:teal">ends</span> <span class="" style="font-weight:bold">=</span> <span class="" style="color:rgb(0,153,153)">4</span><span class="" style>;</span>                                 </div>
<div class="" id="LC87" style="padding-left:10px">        <span style="color:rgb(153,153,136);font-style:italic">// Expected payment frequency</span></div><div class="" id="LC88" style="padding-left:10px">        <span class="" style="font-weight:bold">optional</span> <span class="" style>PaymentFrequencyType</span> <span class="" style="color:teal">payment_frequency_type</span> <span class="" style="font-weight:bold">=</span> <span class="" style="color:rgb(0,153,153)">5</span><span class="" style>;</span> </div>
<div class="" id="LC88" style="padding-left:10px">        <span style="color:rgb(153,153,136);font-style:italic">// Max payment amount within that frequency (e.g. no more than 5 BTC per month)</span></div><div class="" id="LC89" style="padding-left:10px">
        <span class="" style="font-weight:bold">optional</span> <span class="" style="color:rgb(68,85,136);font-weight:bold">uint64</span> <span class="" style="color:teal">max_payment_per_period</span>  <span class="" style="font-weight:bold">=</span> <span class="" style="color:rgb(0,153,153)">6</span><span class="" style>;</span>              </div>
<div class="" id="LC89" style="padding-left:10px">        <span style="color:rgb(153,153,136);font-style:italic">// Max payment amount (e.g. no more than 3 BTC per payment)</span></div><div class="" id="LC90" style="padding-left:10px">
        <span class="" style="font-weight:bold">optional</span> <span class="" style="color:rgb(68,85,136);font-weight:bold">uint64</span> <span class="" style="color:teal">max_payment_amount</span> <span class="" style="font-weight:bold">=</span> <span class="" style="color:rgb(0,153,153)">7</span><span class="" style>;</span>                   </div>
<div><span class="" style="color:rgb(153,153,136);font-style:italic">}</span></div><div><span class="" style="color:rgb(153,153,136);font-style:italic"><br></span></div></pre></div><div>I have the following comments:</div>
<div><ol><li>There&#39;s no need to serialize RecurringPaymentDetails as bytes here. It&#39;s done that way outside of PaymentDetails in order to support digital signatures over protobufs that may have extensions the wallet app isn&#39;t aware of, but it&#39;s a pain and inside PaymentDetails (and therefore for most extensions) it shouldn&#39;t be necessary. So you can just use &quot;optional RecurringPamentDetails recurring_payments = 8;&quot;<br>
<br></li><li>There&#39;s only 4 possibilities here for recurrences. That seems rather restrictive. Is the cost of being more expressive really so high? Why not allow more flexible specification of periods?<br><br></li><li>
If there&#39;s no payment_frequency_type field then what happens? A quirk of protobufs to be aware of is that making an enum field &quot;required&quot; can hurt backwards compatibility. Because it will be expressed using a languages underlying enum type, if there&#39;s a new enum member added later old software that attempts to deserialize this will throw exceptions because the new &quot;unknown&quot; member would be unrepresentable in the old model. Making the field optional avoids this problem (it will be treated as missing instead) but means software needs to be written to know what to do when it can&#39;t read the enum value / sees enum values from the future.<br>
<br></li><li>I assume the amounts are specified in terms of satoshi, and timestamps are UNIX time, but better to make that explicit.<br><br></li><li>Seems there&#39;s an implicit value constraint that max_payment_amount &lt;= max_payment_per_period. What happens if that constraint is violated? Best to document that.<br>
<br></li><li>What&#39;s the &quot;merchant ID&quot; namespace thing about? What&#39;s it for? What happens if I set my competitors merchant ID there?<br><br></li><li>What&#39;s the &quot;subscription ID&quot;? Is this stuff not duplicative/redundant with the existing merchant_data field?<br>
<br></li><li>In what situations would you have &gt;1 contract per payment request? I&#39;m not sure I understand why it&#39;s repeated. Presumably if there are zero contracts included the data should be ignored, or an error thrown and the entire payment request rejected? Which should it be?<br>
<br></li><li>It&#39;s unclear to me given such a contract when the payment should actually occur. For instance if it&#39;s &quot;monthly&quot; then what day in the month would the payment occur?<br><br></li><li>You&#39;ll notice I moved the comments to be above the field definitions. I know the current proto isn&#39;t done that way, but let&#39;s change it - long comments are good and putting them above the field definitions encourages people to write enough detail without being put off by line length constraints</li>
</ol></div><div><br></div><div>I think the next step would be to talk to BitPay/get Jeff+Stephen involved because I know they have customers that really want recurring payments, and those guys will have a clearer idea of customer requirements than we do. I feel uncomfortable with designing or reviewing in a vacuum without some actual people who would use it chiming in, as I don&#39;t really know much about the underlying business processes.</div>
<div><br></div><div>I have some other comments about the bitcoinj implementation specifically - for instance, we don&#39;t have a &quot;wallet directory&quot; concept: everything goes into the wallet file. So we&#39;ll need to think about how to structure the code to allow that. Also, just using a background polling thread is likely not flexible enough, as on some platforms you can&#39;t stay running all the time (e.g. Android) without upsetting people, but the underlying OS can wake you up at the right times, so wallet apps should have an ability to control wakeup tasks. But we can discuss that over on the bitcoinj list specifically. Let&#39;s keep this thread for the general protocol design.</div>
<div><br></div><div class="gmail_extra">BIP 70 is indeed implemented in Bitcoin Core on the C++ side, so that isn&#39;t a concern. It could be done there too.<br><br></div></div>