February Progress Update

in #bcshop6 years ago

progress.jpg
February 2019

Affiliates on live server

This month Affiliate feature was deployed to the live server.

When you open bcshop.io now you’ll notice the new Affiliate section in the upper menu with your personal link inside.

In previous posts we already explained how Affiliate system functions. Here it is once again in a nutshell. t

  1. You share your personal link with other people.

  2. A person visits website using this link and unlocks the wallet using an Ethereum address with no created offers yet.

  3. Then a person creates the very first offer.

  4. Starting from this moment this person becomes your referral. You receive 30% of platform fees generated by their sales.

Please keep in mind that numbers might be changed by the release date.

The story of one bug

Software development rarely goes without bugs or unpredicted behaviour and subsequent fixes of those.

As you may have heard we are going to introduce revoke purchase feature. This means merchants will be able to ‘cancel’ a purchase themselves if something went wrong and return all the payment back to the customer without raising a dispute. Of course it is possible if only no dispute was raised so far.

Before that all purchases in our system had one of these states:

  1. Finished - for completed purchases

  2. Paid - protected by escrow and dispute can be raised

  3. DIspute - dispute is raised

  4. Canceled - purchase was canceled as a result of dispute

  5. Pending - merchant can withdraw the payment for this purchase.

The most obvious way to implement revoked purchase was to introduce new state to this list - Revoked. And here is where the problem lied.

States were declared as enum type inside the ProductStorage.sol - contract implementing permanent non-updatable primary storage of products and purchases information. So initially there were only first 5 states.

enum PurchaseState {Finished, Paid, Dispute, Canceled, Pending}

All the contracts that user interacts with refer to this enum to update a purchase, for example payment contract uses Dispute state to mark a raised dispute.

So what one could expect when adding new state to the enum and deployed the new payment contract? Probably, something like this. New enum member State.Revoke is used to update the revoked purchase.

In fact all the tests passed successfully and acted exactly like the picture above. But when update hit the ropsten testnet things gone wrong. Our contracts architecture is built on the fact that we never redeploy the Storage contract, only extend it with other secondary storage contracts if needed and only functional contract that contain business logic are redeployed. Thus we redeployed ProductPayment contract and that lead us to the following situation.

ProductPayment contract knew about Revoked state as it received it from the ProductStorage.sol file. But that file wasn’t redeployed and old ProductStorage contract knew nothing about new enum member. Unfortunately EVM couldn’t cast new enum member to for example next integer number and write it to the old ProductStorage contract, so all the revoke transactions were reverted. The official Solidity docs confirm this behaviour as well

“The explicit conversion from integer checks at runtime that the value lies inside the range of the enum and causes a failing assert otherwise.”

The sad thing here is all truffle tests ran on the updated version of ProductStorage.sol with new Revoked state, so that’s why they passed.

How to fix it?

Since adding new enum member is not an option we followed our standard update path - introduced a new storage contract. It is responsible for storing the mapping of purchase to the flag showing is it was revoked. And all the process looks like this.

RevokePurchase function writes already existing State.Finished to the old Storage contract, and to indicate the revocation fact it writes a flag to the new storage contract.

About BCShop.io

BCShop.io project aims to reinvent the way digital commerce and payments work today. Focusing on digital goods and services area project’s goal is to enhance it with fast-growing opportunities blockchain technologies and cryptocurrencies have to offer. In January 2018 BCShop.io hit hard cap of 2000 ETH at its token sale.
Website: https://bcshop.io/
Twitter https://twitter.com/BCShop_io
Telegram https://t.me/bcshopio
Facebook https://www.facebook.com/BCShop.io/
Business Inquiries [email protected]

Coin Marketplace

STEEM 0.20
TRX 0.25
JST 0.038
BTC 96656.73
ETH 3341.70
USDT 1.00
SBD 3.20