Instant payments, confirmations threshold, webworks and Bitcoin Cash support. Version 0.8.0#30
Instant payments, confirmations threshold, webworks and Bitcoin Cash support. Version 0.8.0#30maesitos wants to merge 22 commits intoSailias:masterfrom
Conversation
6e28b9b to
666a134
Compare
666a134 to
670877b
Compare
|
@maesitos thanks for the pull request. There is a lot to comment on, as this pull request takes WebhooksMy understanding is that you don't want to run the processor on an interval, but leverage Blocktrail's subscription API to receive only the events that we are monitoring. I looked through their documentation and didn't see any limits on the number of subscriptions you are allowed to create. While this seems like an instant win, it makes me think they will impose limitations and this solution won't scale. Perhaps we should reach out to Blocktrail to get more clarity on this before we make this the default implementation. I have been thinking about limiting API requests for a while and just never got around to it, so I think this would work quite nicely. Bitcoin CashAs you are aware there is another version of the gem https://github.com/Sailias/cryptocoin_payable that supports other cryptos. I am not opposed to only integrating BCH into this gem as it can leverage the same blockchain APIs, but I would draw the line close to that. Support of any other cryptocurrencies should be part of that other gem. Accept multiple fiats at runtimeI like this functionality. Charging of taxes isn't built into this repo and should be charged prior to issuing a payment. I will have to look through this to make sure all the conversions are being pulled properly. Instant paymentsConfirmations were added fairly recently and instant payments were the default. I will say that I am unsure about your implementation regarding this feature. Accepting a payment, marking it as If the number of confirmations is set to 0, it will immediately be "confirmed". The possible states are:
I think we just need to implement a better notification system between the gem and the parent app. If someone sees "paid_in_full" and wants to take an action on it, they can. If they want to ship the order only when it's "confirmed" they can. In https://github.com/Sailias/cryptocoin_payable, @mhluska has a pull request that implements better notifications. Sailias/cryptocoin_payable#6 Here is an excerpt: I will have more feedback soon. |
… will receive different types of notifications. One when a payment is received and a different one when the payment is secure.
…he address for future notifications
|
Hello @Sailias Web-hooksYes if it's going to be the default and only alternative for now it has to be a very reliable and 'unlimited' API. From their docs:
And that's previous from the acquisition by Bitmain. They made in 2017 a whopping revenue of 4 billion USD so the API is backed by a solvent business. I did request a pull to the blocktrail dependency so we could get an exception in case the limit is reached aside from the email they say the'd send you yunixon/blocktrail#4 Bitcoin CashI'm aware of the other library and since my new proposal creates a more coupled code—at least with the API—I preferred to work on top of this this gem. More features in exchange for a more coupled code code I guess. I think that more than about to crossing the border line, adding Bitcoin Cash is the only chance for this gem to have a use case in the mid term as Bitcoin have shifted towards transacting off chain witch is a complete new thing. Instant paymentsAt least there isn't anything related to confirmations in the master branch. I did improve the concept following your suggestion. Quoting from the new version of the Readme:
More generic notificationsGym time. I'll comment a bit more on my changes a bit later |
|
Looks like there's a lot of great work here. Would it make sense to split it up into several PRs? E.g. one for web hooks, one for Bitcoin Cash etc. I'm unsure of the decision to add Bitcoin Cash to this gem instead of |
|
I agree with @mhluska on both points. One thing about the webhook implementation is that all other adapters have been removed in your code. I find that as people contribute they have a preference as to which adapter they feel should be default. This is the reason I created adapters in the first place, so people could roll their own. I don't think that adapters should be deleted though as they will break other people's projects. I think it would be best of this pull request was split into at least 3 pull requests.
I also agree as previously stated that I'm not against adding BCH here and in cryptocoin_payable if we treat them as separate projects (which we are). @maesitos how do you feel about splitting this large PR into smaller ones that can be tested easier? Edit: Also let me know if you would prefer a different division of the PR content. |
|
I've been all evening dividing it into three PR, it's going to take me a while as this request has many house keeping and a lot of the logic is very interlinked. I'll post 3 PR chronologically so the next PR will include the changes of the previous, it's not going to be possible to do all the 3 PR from the master. Is that OK? You guys are lucky that I'm a Bitcoin millionaire with nothing to do... just kidding I sold my 450BTC extremely early :( 2013 even previous to the MtGox pump. |
I've been working in several features for this gem. I'm going to explain it a bit here but I've updated the README so everybody can understand how to use it.
Support for multi currencies
A simple way to create Bitcoin payments based on different currencies. If no currency is specified, the default will be used. You can do:
payable.bitcoin_payments.create!(reason: 'sale', price: amount_in_cents, currency: :usd)or
payable.bitcoin_payments.create!(reason: 'sale', price: amount_in_cents, currency: :cad)This method will now create the conversion before creating the payment if the conversion doesn't exist in the database.
New rake task
rake bitcoin_payable:update_rates_for_all_pairsWill update the rates of all pairs available in the payments and in the previous rates history.Confirmations
A payment won't be considered paid if a confirmation doesn't reach the desired confirmations in
BitcoinPayable.config.confirmations.rake bitcoin_payable:process_paymentswill be monitoring the confirmations for a given transaction and set the payment as paid when reached. Otherwise if the confirmations doesn't increase with the chain, the transaction will be 'set aside' (actually the confirmation value will be set to -1).Zero confirmations transactions
In order to improve the user experience the gem will allow you to accept transactions with zero confirmations. So if a transaction enters the mempool it'll set your 'payable' as paid. Simply done by setting
BitcoinPayable.config.zero_tx = true.rake bitcoin_payable:process_paymentswill monitor the confirmations and if a transaction doesn't reachBitcoinPayable.config.confirmationstheBitcoinPaymentwill be set as:pendingand the payable will be notified so he can do his stuff to roll back the payment.In order to implement the roll back notification (all covered in the README)
Webhooks
Enable them by setting
BitcoinPayable.config.allowwebhooks = true. The gem will set to routes:bitcoin/lastblock
Will be called every block and will trigger
rake bitcoin_payable:process_paymentsto see if the pending payments have been paid or to monitor the transaction that are still not secure.bitcoin/notifytransaction
This route will receive and store transactions that have zero confirmations, that is, that are still in the mempool. This route only will be enabled if
BitcoinPayable.config.zero_txis set to true. This will give the user the experience of sending an instant payment.Bitcoin Cash
It's possible now to use the Bitcoin Cash network by setting
BitcoinPayableconfig.crypto = :bch, setBitcoinPayableconfig.crypto = :btcfor Bitcoin.Miscellaneous.
There are some small changes I did to clean the code. Since this version has changed a lot and it's based in a new API I commented the rest of the adapters, I didn't see the point in implementing them.
Updating from the vesting 0.7 should be easy as the interface hasn't changed. You'd only need to set the environment variables for the API and set the new configuration in your Rails API.
I hope you like it! I'm looking forward for the merge so that I can implement it in my store.
PS: I'll also push a port for rails 3.2 (my store still uses 3.2)