<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sergei Sevriugin on Medium]]></title>
        <description><![CDATA[Stories by Sergei Sevriugin on Medium]]></description>
        <link>https://medium.com/@colnagorider?source=rss-e770a8802d0e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*3oyw8oWruhDQtyVJhqKZNg.jpeg</url>
            <title>Stories by Sergei Sevriugin on Medium</title>
            <link>https://medium.com/@colnagorider?source=rss-e770a8802d0e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 04:38:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@colnagorider/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Firebase Trigger Email Extension]]></title>
            <link>https://colnagorider.medium.com/firebase-trigger-email-extension-4f1a8b30f97e?source=rss-e770a8802d0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f1a8b30f97e</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[firestore]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Sergei Sevriugin]]></dc:creator>
            <pubDate>Fri, 08 Jan 2021 07:44:24 GMT</pubDate>
            <atom:updated>2021-01-08T07:44:24.181Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I0qjnbnDVbCjRWTYNGNJig.png" /></figure><p>What we need is love and good email email service :) that we can use to send email to our users. Firebase is providing Trigger Email Extension that could be a good start if you are using Firebase for mobile app development. The problem here that description of the extension is very short and does not really explain how to use it. So, I have managed to understand and would like to share with you to save you time reading through the source code provided by Google.</p><p>First of all we need to create collection that will store information needed to create each email. As a default this collection is called ‘email’. From documentation example we know that we could add new document to this collection to trigger email sending process and the document could be very short like this one:</p><pre>{<br> to: ‘someone@example.com’,<br> message: {<br>       subject: ‘Hello from Firebase!’,<br>       html: ‘This is an &lt;code&gt;HTML&lt;/code&gt; email body.’,<br>   },<br>}</pre><p>but what other parameters we can add here? The answer give us the following snippet of the function source code:</p><pre>to: string[]; <br>toUids?: string[]; <br>cc: string[]; <br>ccUids?: string[]; <br>bcc: string[]; <br>bccUids?: string[]; <br>from?: string; <br>replyTo?: string; <br>headers?: any;</pre><p>So, you could see that we can use arrays of string to add <em>to</em>, <em>cc</em> and <em>bcc</em> email parameters and we also can use <em>uids</em> as the values in this case you need to provide user collection and each user document should have email field.</p><p>Most interesting part is about templates. We can use template field in mail document to ask extension to create email based on template name. In this case our email document should look like this one:</p><pre>{<br> to: ‘someone@example.com’,<br> template: {<br>       name: ‘client001’,<br>       data: {<br>           fullName: &#39;Sergei Sevriugin<br>       },<br>}</pre><p>to make Firebase extension to create email based on this document we shout also provide the extension during configuration stage the name of templates collection where the documents should looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sKXTuNX13BzDSlBjaNsO_w.png" /><figcaption>Firebase Template Collection for Trigger Email Extension</figcaption></figure><p>Please note that the documents <em>IDs</em> must match the <em>name</em> value in the <em>template</em> parameter of <em>email</em> collection document.</p><p>The whole list of the fields that we could use in the template document is here:</p><pre>subject?: string; <br>html?: string; <br>text?: string; <br>amp?: string; <br>partial?: boolean;</pre><p>There is the link to GitHub with the extension source code provided by Google Firebase <a href="https://github.com/firebase/extensions/tree/master/firestore-send-email/functions/src">https://github.com/firebase/extensions/tree/master/firestore-send-email/functions/src</a></p><p>Enjoy !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f1a8b30f97e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[iOS Swift UITableView with overlapping cells]]></title>
            <link>https://colnagorider.medium.com/ios-swift-uitableview-with-overlapping-cells-fa2735b59854?source=rss-e770a8802d0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa2735b59854</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[uitableview]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[uitableviewcell]]></category>
            <dc:creator><![CDATA[Sergei Sevriugin]]></dc:creator>
            <pubDate>Tue, 28 Apr 2020 07:55:18 GMT</pubDate>
            <atom:updated>2020-04-28T07:55:18.486Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*woZPSnOdzsgSZZzaEx7Uyw.gif" /><figcaption>UITableView with overlapping cells</figcaption></figure><p>Everyone knows that for iOS application the design is very important matter but sometimes an implementing designer ideas is really challenging task. In my case it was irregular table view where each cell overlaps the previous one.</p><p>The first version of the implementation works perfectly without scrolling but brakes as soon as a user has scrolled the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/1*c9vxOyJlAzutv1Q77R8IpA.png" /><figcaption>The first implementation after the scrolling</figcaption></figure><p>The second one works great with scrolling but without overlapping effect and the final solution was a combination of these two.</p><p>Let me show you how it works.</p><p>First of all we need to create the shape of the cell and path for the stroke:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7LS_WD1Jcy3Uz0VaIUn2ig.png" /><figcaption>Create cell shape and stroke path</figcaption></figure><p>Then we need the mask with the same path:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5onBTngLeI5Xn1bi2kn3JA.png" /><figcaption>Creating mask</figcaption></figure><p>And the last but not least we need to create triangle layer of the cell. I don’t know why but without it the overlapping effect will be not present.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1serC4-wKkzXXKg-CyqjVw.png" /><figcaption>Create cell triangle that overlaps the previous cell</figcaption></figure><p>And now we can use our shapes in the cell <em>draw</em> function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6GDuMaDlqyRtdmO34SOJBA.png" /><figcaption>UITableViewCell draw function</figcaption></figure><p>But again it will not show overlapping. To make it visible we need to call <em>configure</em> function every time when <em>UITableView</em> calls <em>cellForRowAt indexPath</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mLqz-UmQAzQBV1zs3QtuPA.png" /><figcaption>UITable view cellForRowAt indexPath</figcaption></figure><p>And here it is our cell configure function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*svCivLEvYNpyNBrWKtsh9w.png" /><figcaption>Cell configure function that creating triangle layer</figcaption></figure><p>So, now it works!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa2735b59854" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Show Must Go On!]]></title>
            <link>https://colnagorider.medium.com/the-show-must-go-on-22fc6fc0d5a7?source=rss-e770a8802d0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/22fc6fc0d5a7</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[erc721]]></category>
            <category><![CDATA[crowdsurance]]></category>
            <category><![CDATA[erc20]]></category>
            <category><![CDATA[erc721smarttoken]]></category>
            <dc:creator><![CDATA[Sergei Sevriugin]]></dc:creator>
            <pubDate>Sun, 16 Sep 2018 20:45:40 GMT</pubDate>
            <atom:updated>2018-09-17T21:47:06.306Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*KQSunDao5-JJodNVWEXyVA.jpeg" /></figure><h4>Testing new features of REGA Luggage Crowdsurance smart contracts.</h4><p>As soon as we’ve issued the new interface for the<a href="https://savemyluggage.io/"> Luggage Crowdsurance DApp</a> we are back to the development process and this week made some cool adjustments to the old good <a href="https://tokencrowdsurance.io/">tokencrowdsurance.io</a> that is our playground for new features. First of all we add an option to join crowdsurance pool with Ether. From now anyone can buy RST token from our <a href="https://simpleexchange.io/">simpleexchange.io</a> or got to <a href="https://tokencrowdsurance.io/">tokencrowdsurance.io</a> and join luggage crowdsurance right there sending Ether to crowdsurance pool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q02LamcHgt1jcht1tn0S1Q.png" /><figcaption>Join REGA Crowdsurance optionns : RST/ETH</figcaption></figure><p>The next very cool feature is token transfer. Thanks to our ERC721 Smart Token standard a token owner could transfer the LCST token to other address before token activation. We are waiting Metamask support this feature in the wallet but now you can do it in our DApp.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5dPGKgxToE5UNkVvKQprtQ.png" /><figcaption>REGA Crowdsurance Transfer / Activate</figcaption></figure><p>If you have number of LCST token then you can see all your token IDs in Token Tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*KWBUBeVaQinqm4CIBz1IWw.png" /><figcaption>REGA Crowdsurance Token Tab</figcaption></figure><p>An the last but not least a Crowdsurance Tab, the place where you can see all information about you token including join and activation time, coverage period and token status.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*fOXzftBdsJLAZfi-BQHqWw.png" /><figcaption>REGA Crowdsurance Info</figcaption></figure><p>All updates is up and running in Main Ethereum network and Rinkeby test network. Check our <a href="https://github.com/REGA-RS/LuggageCrowdsurance/tree/mainnet">GitHub</a> for latest updates!</p><ul><li><a href="https://tokencrowdsurance.io/">REGA</a></li><li><a href="https://simpleexchange.io/">REGA</a></li></ul><p><a href="https://savemyluggage.io/">https://savemyluggage.io</a></p><p>Update: Claim Tab is added and now you can see the claim information including claim submission date, voting time and other important data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PJ3fxYdXG3W-alRMC2Ov5w.png" /><figcaption>REGA Crowdsurance Claim Tab</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22fc6fc0d5a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Join REGA Luggage Crowdsurance with Ether]]></title>
            <link>https://colnagorider.medium.com/join-rega-luggage-crowdsurance-with-ether-c6a6b2feaa94?source=rss-e770a8802d0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6a6b2feaa94</guid>
            <category><![CDATA[erc721]]></category>
            <category><![CDATA[erc20]]></category>
            <category><![CDATA[erc721smarttoken]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[crowdsurance]]></category>
            <dc:creator><![CDATA[Sergei Sevriugin]]></dc:creator>
            <pubDate>Sat, 15 Sep 2018 20:51:03 GMT</pubDate>
            <atom:updated>2018-09-15T21:05:46.013Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*sK0e9941A1Mw-jsYPO4_OA.png" /><figcaption>REGA Simple Exchange</figcaption></figure><p>If you don’t have 0.76 RST to join Luggage Crowdsurance from now you could use <a href="https://simpleexchange.io/">simpleexchange.io</a> to buy them.</p><p><strong>Simple Exchange DApp</strong> allows you to buy <strong>RST</strong> tokens from other community members without any centralized exchange. The Order Amount, the number of <strong>RST</strong> tokens that you can buy or sell is fixed. If you need more token than the Order Amount you need to execute more Orders.</p><p>Each Order is ERC721 Smart Token. If you place an Order you will receive a new issued <strong>XRST</strong>Token. If you buy <strong>RST</strong> tokens then you should select <strong>XRST</strong> Token ID of the Order that you wish to execute. Simple Exchange Smart Contract will find you the best Order to execute with minimum value.</p><p>To place the Order you need to have <strong>RST</strong> tokens on your personal account and as the first step should provide an allowance for Simple Exchange Smart contract to transfer your <strong>RST</strong> tokens to buyer when you Order will be executed. For each order you need to enter <strong>RST</strong> token exchange Rate. The Minimum Rate is fixed and you need to select the rate that is more or equal to the Minimum Rate.</p><p>Check our smart contracts here: <a href="https://github.com/REGA-RS/SimpleExchange/tree/mainnet">https://github.com/REGA-RS/SimpleExchange/tree/mainnet</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FkiMwo6Sxn_c%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DkiMwo6Sxn_c&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FkiMwo6Sxn_c%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d4823c1337625a72accb938b1efdfa5/href">https://medium.com/media/3d4823c1337625a72accb938b1efdfa5/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6a6b2feaa94" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Luggage Crowdsurance application process]]></title>
            <link>https://colnagorider.medium.com/luggage-crowdsurance-application-process-c65b7e57e8fa?source=rss-e770a8802d0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/c65b7e57e8fa</guid>
            <category><![CDATA[crowdsurance]]></category>
            <category><![CDATA[erc20]]></category>
            <category><![CDATA[erc721]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[insurance]]></category>
            <dc:creator><![CDATA[Sergei Sevriugin]]></dc:creator>
            <pubDate>Fri, 14 Sep 2018 19:00:58 GMT</pubDate>
            <atom:updated>2018-09-14T19:50:05.057Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/188/1*7iMmfT9QeiR-F9o1X1Iceg@2x.jpeg" /></figure><p>To start the REGA Luggage Crowdsurance application process you need <a href="http://metamask.io/">Metamask.io</a> wallet with a personal account that has some amount in Ether and at least 0.76 RST. Make sure that the Main Ethereum Network is selected and load <a href="https://savemyluggage.io/">savemyluggage.io</a> DApp to start.</p><ol><li>The first step is making an application and then wait when your application will be approved by scoring system.</li></ol><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FRWFsZPkSaZQ%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DRWFsZPkSaZQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FRWFsZPkSaZQ%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/411f6d3ab34f0db77e6ea03f285ea8bb/href">https://medium.com/media/411f6d3ab34f0db77e6ea03f285ea8bb/href</a></iframe><p>2. The second step is make an allowance. You will approve RST token transfer from your account to the Luggage Crowdsurance smart contract account. Please note that the actual RST token transfer will be done during the 3rd step.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FL5_YTvzgu4s%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DL5_YTvzgu4s&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FL5_YTvzgu4s%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/802ff28ffe343a1df9dade1669a40b8d/href">https://medium.com/media/802ff28ffe343a1df9dade1669a40b8d/href</a></iframe><p>3. Now you are ready to join crowdsurance pool with RST tokens. After the end of this step you will receive ERC721 LCST Token and 0.76 RST tokens will be transferred from your account to the Luggage Crowdsurance smart contract account.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F_l3Qk4jynmk&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D_l3Qk4jynmk&amp;image=http%3A%2F%2Fi.ytimg.com%2Fvi%2F_l3Qk4jynmk%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c51f02cf1b977766e83d57e80db5f15/href">https://medium.com/media/5c51f02cf1b977766e83d57e80db5f15/href</a></iframe><p>Wow, thanks to join us! For only 0,76 RST you can use our breathtaking product and get the payment up to 4 ETH. Also you can get refund in 180 days after activation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c65b7e57e8fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Meteor Ethereum Transaction Server]]></title>
            <link>https://medium.com/coinmonks/meteor-ethereum-transaction-server-784b26a247e?source=rss-e770a8802d0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/784b26a247e</guid>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[crowdsurance]]></category>
            <category><![CDATA[truffle]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[meteor]]></category>
            <dc:creator><![CDATA[Sergei Sevriugin]]></dc:creator>
            <pubDate>Sun, 19 Aug 2018 15:17:50 GMT</pubDate>
            <atom:updated>2020-09-01T17:37:59.245Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*td-bY79ZZEMzjBkPtJIB6A.png" /></figure><p>It probably kills the idea of decentralisation but for some application we need a server to make transactions in the blockchain. If we will use <a href="https://www.meteor.com/">Meteor</a> as a server then thanks to <a href="https://blog.meteor.com/introducing-ddp-6b40c6aff27d">DDP technology</a> clients receive updates just in time when a new transaction is included in the block and became confirmed.</p><p>To make a Meteor Ethereum Transaction Server we include in the project smart contract <a href="https://github.com/sevriugin/LoyaltyCrowdsurance/tree/mainnet/build/contracts">artifacts</a> that in our case were produced by <a href="https://truffleframework.com/">Truffle</a>. We also need <em>Web3</em> library and a keystore to keep server accounts. In our case we use <a href="https://github.com/trufflesuite/truffle-hdwallet-provider"><em>truffle-hdwallet-provider</em></a> as the keystore where we would like to have two addresses that the server can use to sign Ethereum transactions:</p><pre>import { Meteor }           from &#39;meteor/meteor&#39;;<br>import Web3                 from &#39;web3&#39;;<br>import contract             from &#39;truffle-contract&#39;;<br>import HDWalletProvider     from &#39;truffle-hdwallet-provider&#39;;<br>import TokenLoyaltyArtifact from &#39;./build/contracts/TokenLoyalty.json&#39;;</pre><pre>export default class TokenLoyalty {<br>  constructor() {<br>    this.instance = undefined;<br>    this.data = undefined;<br>    this.web3Provider = new HDWalletProvider(Meteor.settings.mnemonic, Meteor.settings.networks.rinkeby, 0, 2);</pre><pre>this.address = this.web3Provider.addresses[0];    // contract owner<br>this.tokenAddr = this.web3Provider.addresses[1];  // token owner</pre><pre>// ...</pre><pre>}</pre><p>The last parameter in <em>HDWalletProvider</em> constructor asks <em>truffle-hdwallet-provider</em> to generate two accounts and after that the provider can sign transactions from both of them. Please note that if you don’t like to receive an error like this</p><pre>TypeError: private key should be a Buffer</pre><p>during the transaction signing then you better be sure that all letters in a <em>from</em> parameter value are small ones.</p><pre>instance.payment(data.tokenId, {<strong>from: this.tokenAddr</strong>, gas:700000, gasPrice:&quot;20000000000&quot;})<br>  .then(result =&gt; cb(result))<br>  .catch(error =&gt; console.error(error));</pre><p>For example, in our case the <strong>‘private key should be a Buffer’ </strong>error was produced when we try to use the following constant instead of <em>this.tokenAddr</em></p><pre>const ownerAddress = &quot;0x2952920b5813447f86D6c30Ad1e5C0975Fe563dd&quot;;</pre><p>There are some capital letters here but not all of them and that is why it’s difficult to notice this. This constant is just copy and past from <a href="https://truffleframework.com/ganache">Ganache</a> account section:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c3PXo3tDg3jxCGqJbk1myw.png" /><figcaption>Ganache 1.1.0 ACCOUNTS</figcaption></figure><p>Now when our keystore is ready and we can use the <em>HDWalletProvider </em>to<em> </em>sing transactions we can write methods to call smart contract functions like in the previous example when we call <em>payment</em> and start listening to events to update MongoDb collections on our server. For example, when <em>Paid</em> event is arrived we use <em>_setData</em> method to call callback function that updates the database state:</p><pre>instance.Paid().watch((err, responce) =&gt; {<br>  if(err) {<br>    console.error(err)<br>  }<br>  else {<br>    that._setData({ event:responce.event,<br>      tx:responce.transactionHash,<br>      tokenId:responce.args.tokenId.toString(),<br>      supPoolId:responce.args.subPoolId.toString(),<br>    });<br>  }<br>});</pre><pre>_setData(data) {<br>  if(this.data !== data) {<br>    this.data = data;<br>    if(this.watch !== undefined) {<br>      this.watch(data);<br>    }<br>  }<br>}</pre><pre>setWatch(cb) {<br>  this.watch = cb;<br>}</pre><pre>// ...</pre><pre>let tokenLoyalty;</pre><pre>if (Meteor.isServer) {<br>  tokenLoyalty = new TokenLoyalty();<br>  tokenLoyalty.setWatch(Meteor.bindEnvironment((data) =&gt; {<br>    // ...<br>    if(data.event === &quot;Paid&quot; &amp;&amp; <br>      Tokens.collection.findOne({ nft_id: data.tokenId })) {<br>        Tokens.collection.update({ nft_id: data.tokenId }, <br>          { $set: { paid:true, inprogress:false } });<br>        //...<br>    }<br>    // ...<br>  }));<br>}</pre><p>In our case our smart contract has the following event that we process:</p><pre>/// payment event</pre><pre>event Paid(uint subPoolId, uint tokenId, uint value, uint debit, uint payment, uint timeStamp, uint closure);</pre><p>So, we use <em>responce.args.tokenId </em>for collection update. In the event the type of event subject is <em>uint </em>and<em> </em>in this case the value of <em>responce.args.tokenId </em>will be a big number looking like this</p><pre>BigNumber { s: 1, e: 0, c: [ 3 ] }</pre><p>and that is why we use <em>toString() </em>function to have more convenient object type to store and seach. We also need to wrap callback function on server side in <em>Meteor.bindEnvironment() </em>method call otherwise you can get the following error message:</p><pre>Error: Meteor code must always run within a Fiber.</pre><p>Another very important discovery that we have found during smart contract test using our server was the gas amount for function call must be set to the maximum what function can consume in all cases. For example, the following code woks without problem for most cases but will give an error when we need to add sub pool to our structure during the <em>create</em> call.</p><pre>instance.create(data.member, data.clientId, {from: that.address,<br>  gas:500000, gasPrice:&quot;20000000000&quot;})<br>    .then(result =&gt; cb(result))<br>    .catch(error =&gt; console.error(error));</pre><p>Unfortunately the error message that we can receive in this case</p><pre>Transaction: 0x4dbcf824185eb06d68e94f01b2542c134409b6793cadf9b3a1eb325a731769e2 exited with an error (status 0). Please check that the transaction:<br>  - satisfies all conditions set by Solidity `require` statements.<br>  - does not trigger a Solidity `revert` statement.</pre><p>says nothing about the gas issue and we have spent some time in <a href="https://rinkeby.etherscan.io/vmtrace?txhash=0x4dbcf824185eb06d68e94f01b2542c134409b6793cadf9b3a1eb325a731769e2">etherscan.io</a> to undestand that SSTORE instruction has spent most of remaining gas.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6Spfz2lweDk2yJ18O8xF6g.png" /><figcaption>etherscan.io <strong>GETH</strong> Trace for TxHash</figcaption></figure><p>So, after we have changed the gas amount from 500000 to 900000 the <em>create</em> transaction passes without any problem. Need to say that in DAPP environment thanks to <a href="http://metamask.io/">Metamask.io</a> gas prediction function we will not have such problem and gas amount will be adjusted accordingly.</p><p>You can find the code for Meteor Ethereum Transaction Server in our<a href="https://github.com/REGA-RS/meteor-token/tree/ethereum"> REGA Risk Sharing repository </a>and all smart contracts are in <a href="https://github.com/sevriugin/LoyaltyCrowdsurance">here</a>.</p><blockquote><a href="https://coincodecap.com/?utm_source=coinmonks">Get Best Software Deals Directly In Your Inbox</a></blockquote><figure><a href="https://coincodecap.com/?utm_source=coinmonks"><img alt="" src="https://cdn-images-1.medium.com/max/584/0*OJ-qb5G6i863msBB.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=784b26a247e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/meteor-ethereum-transaction-server-784b26a247e">Meteor Ethereum Transaction Server</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Decentralised insurance model]]></title>
            <link>https://medium.com/coinmonks/decentralised-insurance-model-c69886320a1a?source=rss-e770a8802d0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/c69886320a1a</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[decentralized]]></category>
            <category><![CDATA[insurance]]></category>
            <category><![CDATA[crowdsurance]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Sergei Sevriugin]]></dc:creator>
            <pubDate>Fri, 17 Aug 2018 08:09:16 GMT</pubDate>
            <atom:updated>2020-09-01T17:52:35.352Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*PUCMFA0Nma5OAfDbRv6FNA.jpeg" /></figure><h4>Abstract</h4><p>With the development of sharing economy and decentralised platforms like Bit- coin and Ethereum the financial products decentralisation has been the focal point for some projects and studies in the blockchain world. In this paper, we build a decen- tralised insurance model based on our researches and experience in REGA Risk Sharing and evaluate the model parameters to prove that the decentralised insurance can be an alternative solution to the traditional insurance approach.</p><h4>Keywords</h4><p>Decentralised insurance, blockchain, smart contract, crowdsurance, valuation, marketing.</p><h4>1. Introduction</h4><p>The decentralised insurance or crowdsurance meaning people unite in communi- ties to provide a guarantee of compensation for unexpected loss. Compared to tradi- tional insurance, in crowdsurance there are no insurers, intermediaries and brokers, all the processes being controlled and managed by programs stored in blockchain and executed by a distributed virtual computer. The main question in this case is how to motivate people inside the community to use crowdsurance programs in the right way to provide the risk coverage and fight the fraud. Some people intensions and actions can be in opposition of these objectives but in the decentralised economy if most ac- tors are motivated properly to bring value to the community then the outcome of the whole process will be inline with common goal.</p><p>There are two groups of people using crowdsurance program: A — people who join crowdsurance pool to get risk coverage and B — people who help the first group manage risks inside the crowdsurance pools. We will call the first group a crowd- surance community or community and the second one — experts. To join the crowd- surance community someone should buy a crowdsurance token (CST) and transfer a crowdsurance join amount to the crowdsurance token smart contract. To became an expert a person should buy a license, Risk Sharing Token (RST) and transfer an expert join amount to the RST smart contract. Funds collected in RST smart contract are using for crowdsurance product development and for the initial crowdsurance pools capitali- sation. Inside the crowdsurance token smart contract there is three level pool structure: super pool, pools and sub pools. Each CST belongs to one sub pool that belongs to one pool and all pools included in super pool. The crowdsurance join amount is divided between different levels in there following way: 50% goes to sub pool, 20% to pool and 10% is transferred to super pool. The rest 20% is crowdsurance smart contract com- mission. A CST holder can activate the token to initiate the risk coverage period during which he/her can submit a claim to receive crowdsurance payment in case of unex- pected event. The submitted claim will be processed by the crowdsurance program and will be submitted to an expert jury for final approval. For each outstanding claim the randomly selected jury will be created and experts will vote for the case using crowdsurance token smart contract. During the claim voting period (up to 48 hours) any jury member can review claim supported documents and vote in favour of payment or against it. The claim payment will be processed by the crowdsurance smart contract based on voting result and the CST holder could receive the claim payment if payment was approved by the jury. A part of the smart contract commission (3%) will go to the experts to compensate transaction fee and working time. If an expert was selected to vote but did not cast the vote during the voting period then he/her will not receive the compensation. Otherwise all other experts will receive expert commission even if they did not selected to vote. The crowdsurance smart token linked to the Risk Sharing To- ken through the super pool. The RST value will rise if the super pool balance will be more then a certain threshold at the end of risk coverage period as result of the experts performance. In the next section we will describe the crowdsurance model that explains an expert motivation to process claims and vote for the legitimate cases and decline the fraudulent ones. The model takes into account a community member satisfaction level for different voting outcomes.</p><h4>2. The model</h4><p>The model consists of crowdsurance token smart contract working through two risk coverage periods. Similar to [1] community member decision making to join crowd- surance pool is modelled using the the surplus the member obtain from the decen- tralised product experience. The surplus is the difference between a member’s valua- tion for the product and the amount he/she must transfer to join it. It’s assumed that a member joins the crowdsurance pool, if the offer yields a nonnegative surplus. Let’s as- sume that μ is the average risk coverage period for the community member that did not submit any claim. For a member who has submitted the claim in the first risk cover- age period and has received the payment the product valuation for the next period should be more that the average one. From the other hand if claim was rejected then the valuation must be less. So, we can assume that for the member that has received the claim payment the crowdsurance contract lasts μ + <em>x </em>and the rejected claim results in μ − <em>y </em>periods. If <em>A </em>‘ ⊂ <em>A </em>is group of members who has submitted the claim then the super pool financial result after the two risk coverage period can be calculated by the following expression:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w8AiKXZ6OzA0x7H3WXT6ng.png" /></figure><p>where <em>J </em>is crowdsurance join amount and ω is the average super pool balance update due to the claim processing. To calculate ω we need to consider the following cases:</p><ul><li>the submitted claim <em>c </em>∈ <em>L </em>is legitimate one;</li><li>the submitted claim <em>f </em>∈<em>F </em>is fraudulent one.</li></ul><p>In both cases we will have the following outcomes for the expert voting proce- dure:</p><p>- <em>D </em>the claim is approved by the jury and member will receive claim payment amount <em>D</em>;</p><p>- <em>J </em>the voting procedure has been finished by timeout and the number of col- lected votes is less than specified limit or the number of positive votes is equal of number of negative votes. In this case the member will receive join amount <em>J </em>;</p><p>- <em>Z </em>the claim has beed declined by the jury and the member not receive any payment from the crowdsurance pool.</p><p>Based on assumption that the member product valuation will change he/her average risk coverage period we can say that for (<em>L</em>, <em>D</em>) voting outcome will credit the super pool balance to 0.1 <em>J x </em>and the (<em>L</em>,<em>Z</em>) will debit it −0.1 <em>J y </em>. We also can assume that (<em>L</em>,<em>J</em>) will bring the member product valuation surplus to 0 but it should not change the average crowdsurance period. Please note, that we are considering the crowdsurance model where all legitimate claims can be paid out using sub pool and pool funds and (<em>L</em>, <em>D</em>) , (<em>L</em>, <em>J </em>) voting outcomes are not using the super pool balance to pay claim in full <em>D </em>or to return crowdsurance join amount <em>J </em>. On another hand fraudulent claims can have negative impact on super pool balance due to the shortage of funds in corresponding sub pool and pool. Thereby (<em>F</em>, <em>D</em>) outcome will change the super pool balance to 0.1 <em>J x </em>− <em>D p </em>and ( <em>F </em>, <em>J </em>) to − <em>J p </em>where <em>p </em>is prob — ability of the fund shortage in sub pool and pool. The following table summarise described above outcomes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7ShZQqYKRGk5Txu0ELyrXA.png" /></figure><p>We suppose that for member submitted fraudulent claim voting results (<em>F</em>, <em>J </em>) and(<em>F</em>,<em>Z</em>) does not change the average crowdsurance period μon another hand if fraudulent case has been paid then the member will more probably join the next period to try cheat again.</p><p>Now we can calculate ω using the following expression:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4uu2m3he2vww9R-0QhOQUw.png" /></figure><p>Applying conditional probability theory, the above equation can be rewritten as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P_7GbSL5YieKz7J9tHyPPQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KjZeCPs0kLFEgfnoQHUMaA.png" /></figure><p>We should assume that number of fraudulent claims is much less then the num- ber of legitimate one, so we are adding the following condition: Pr(<em>F</em>) ≤ Pr(<em>L</em>)<em>l </em>to the expression 2 where 0 &lt; <em>l </em>&lt; 0.2 . With this assumption we can try to calculate the probability of the funds shortage <em>p </em>. If <em>N </em>is total number of claims, <em>NL </em>is number of legitimate <em>NF </em>+ <em>NL </em>≤ <em>NL </em>(1 + <em>l </em>) ≤ <em>NL </em>(1 + 0.2 ) ≤ 1.2 <em>NL </em>claims and <em>NF </em>is fraudulent ones then<em>NF </em>≤ <em>NLl </em>and <em>NF </em>≤ <em>NLl </em>. In this case we can estimate <em>NF </em>+ <em>NL </em>with the following expression:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S2Wss3mKvcPUkiWb1bAm-A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SPmzU4Xc-SIOcqyJ80A7UA.png" /></figure><h4>3. Model parameters valuation</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2yds188C5P_TIw-OU0Ny_g.png" /></figure><p>Consider the following outcome probabilities example</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Imn01LR1ZBAEYeR6NtSUBA.png" /></figure><p>If μ = 1.1 then we can assume that <em>y </em>= 0.1 and all member who has submitted le-</p><p>gitimate claim and did not received the payment left the crowdsurance pool after the first period. On another hand we can assume that all members that have received the approval have two periods and <em>x </em>= 0.9 . Based on our example outcome probabilities we can see that for <em>x </em>= 0.9 and <em>y </em>= 0.1 ω &gt; 0 . Please note then the minimum value for <em>x</em></p><p>in our example that gives 0 ≤ <em>y </em>≤1 is <em>x </em>= 0.00094765 and for <em>y </em>= 0.1 we need 16.2 <em>x </em>&gt; 0.115352 or <em>x </em>&gt; 0.00712049 .</p><h4>4. Summary and conclusion</h4><p>In the previous sections we have build crowdsurance model with expert perfor- mance function (2) that explain expert motivation to consider claims properly voting to legitimate ones and reject fraudulent attempts. Based on expression (2) we can see that if experts have decided to vote again all cases including legitimate ones then the value of expert performance function ω will become negative that brings decrease to RST token value. On another hand if experts have decided to approve all cases including fraudulent ones then this decision will change the risk balance in next crowdsurance period due to the fact that more fraud attempts will appear and the probability <em>p </em>of</p><p>pool / sub pool funds shortage will increase. Thus with increase of <em>p</em>and Pr(<em>D</em>,*)the value of −Pr(<em>D</em>|<em>F</em>)Pr(<em>F</em>)<em>Dp </em>in (2) can became more substantial and again the expert performance will became negative. We also have evaluated the model parameters 0 ≤ <em>x</em>, <em>y</em>, <em>p </em>≤ 1 using example for voting outcome distribution and have proved that there is not empty set of outcome distributions that gives realistic value to the model parameters 0 ≤ <em>x</em>, <em>y</em>, <em>p </em>≤ 1 . It’s save to assume that the average crowdsurance period will be around 1.1 and in our example distribution we check that for <em>y </em>= 0.1the value for expert performance function ω will be positive for all <em>x </em>from (0.00712049, 0.9] .</p><p>Based on the above summary we can conclude that the decentralised insurance product with two group of people with different motivations connected thought blockchain program can be created and function to bring value to both groups. We hope that it will help crowdsurance to became an alternative solution for risk coverage and will change insurance landscape in the nearest future.</p><h4>References</h4><p>[1] Amir Gandomi and Saeed Zolfaghari, 2011 “Profitability of Loyalty Programs in th Presence of Uncertainty in Customers’ Valuations” Proceedings of the 2011 Indus- trial Engineering Research Conference</p><blockquote><a href="https://coincodecap.com/?utm_source=coinmonks">Get Best Software Deals Directly In Your Inbox</a></blockquote><figure><a href="https://coincodecap.com/?utm_source=coinmonks"><img alt="" src="https://cdn-images-1.medium.com/max/584/0*OJ-qb5G6i863msBB.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c69886320a1a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/decentralised-insurance-model-c69886320a1a">Decentralised insurance model</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Drizzle DAPP with Meteor backend]]></title>
            <link>https://medium.com/coinmonks/drizzle-dapp-with-meteor-backend-b16ff0a8dd11?source=rss-e770a8802d0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/b16ff0a8dd11</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[truffle]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[dapps]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Sergei Sevriugin]]></dc:creator>
            <pubDate>Fri, 22 Jun 2018 21:37:57 GMT</pubDate>
            <atom:updated>2018-06-23T04:00:03.538Z</atom:updated>
            <content:encoded><![CDATA[<p>For some blockchain projects we need to store information in old fashion way using application server. It can be a private client information or a BLOB that we can’t afford to store in Ethereum due to the gas cost. In this case we can use Distributed Data Protocol (DDP) that is solving a lot of problems that all developers are facing: querying a server-side database, sending the results down to the client, and then pushing changes to the client whenever anything changes in the database.</p><p>In this article we would like to show how to use Meteor backend that supports DDP in Truffle/Drizzle distributed application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MCoVM6sNl5M4d0ulVGzbnA.png" /><figcaption>Truffle/Drizzle/Meteor Application Map</figcaption></figure><p>Let’s start from the DAPP side. Just unpack <a href="https://truffleframework.com/boxes/drizzle">Drizzle box</a> and we have running DAPP in few steps. Now we need to add a library that supports DDP protocol to our Drizzle/Truffle application. In our case we use <a href="https://github.com/mondora/asteroid">Asteroid</a> that is an isomorphic/universal javascript library which allows to connect to a Meteor backend from almost any JS environment. To listen our server we need to provide to an endpoint and create new Asteroid object.</p><pre>const Asteroid = createClass();</pre><pre>// Connect to a Meteor backend<br>const asteroid = new Asteroid({<br>  endpoint: &#39;ws://localhost:9000/websocket&#39;,<br>});</pre><p>Then we can subscribe to our collections using <em>asteroid.subscribe</em> function.</p><p>As our DAPP is already using a <a href="https://redux.js.org/">Redux</a> store we can use it to record sate changes and update user interface if needed. For example, if a new record is added to our server collection we dispatch a new action to save the changes.</p><pre>asteroid.ddp.on(&#39;added&#39;, (doc) =&gt; {<br>  if (doc.collection === &#39;tasks&#39;) {<br>    const docObj = Object.assign({}, doc.fields, { _id: doc.id });<br>    store.dispatch(addTodo(docObj));<br>  }<br>  if (doc.collection === &#39;users&#39;) {<br>    store.dispatch(setLoggedUser(doc.fields));<br>  }<br>});</pre><p>To follow Redux store rules we also need create a <a href="https://redux.js.org/basics/reducers">Reducer</a> for our distributed collection.</p><pre>const todos = (state = [], action) =&gt; {<br>  switch (action.type) {<br>    case ADD_TODO:<br>      return add(state, action);<br>    case REMOVE_TODO:<br>      return remove(state, action);<br>    case EDIT_TODO:<br>      return edit(state, action);<br>    case GET_ALL_TODO:<br>      return action.data;<br>    default:<br>      return state;<br>  }<br>};</pre><p>and then add it to the combined reducer defined in our Drizzle box.</p><pre>const reducer = combineReducers({<br>  routing: routerReducer,<br>  todos,<br>  user,<br>  ...drizzleReducers<br>})<br>export default reducer</pre><p>In our exampe we have <em>HomeContainer</em> that is wrapping our <em>Home</em> components and provides translation for the state to the component <em>props. </em>Now we need to add our distributed collection to the mapping to have access to our server data in React.</p><pre>const mapStateToProps = state =&gt; {<br>  return {<br>    accounts: state.accounts,<br>    SimpleStorage: state.contracts.SimpleStorage,<br>    TutorialToken: state.contracts.TutorialToken,<br>    drizzleStatus: state.drizzleStatus,<br>    todos: state.todos,<br>    user: state.user,<br>  }<br>}</pre><pre>const mapDispatchToProps = dispatch =&gt; ({<br>  dispatchCallAddTodo: data =&gt; dispatch(callAddTodo(data)),<br>});</pre><pre>Home.contextTypes = {<br>  drizzle: PropTypes.object<br>}</pre><pre>const HomeContainer = drizzleConnect(Home, mapStateToProps, mapDispatchToProps);</pre><p>Plase note then we also adding <em>mapDispatchToProps </em>to provide <em>Home</em> component with ability to add a data to the collection. Then two mappings are connected to React component using <em>drizzleConnect.</em></p><p>So, now we are ready to update <em>Home</em> component and add a logic for show our server data.</p><pre>&lt;h3&gt;Todos&lt;/h3&gt;<br>&lt;div&gt;<br>  &lt;input<br>    type=&quot;text&quot;<br>    placeholder=&quot;Add todo item ...&quot;<br>    onKeyPress={this.handleAddTodo}<br>  /&gt;<br>&lt;/div&gt;<br>&lt;ul&gt;<br>  {this.props.todos.map((t, i) =&gt;<br>    &lt;li key={i}&gt;<br>      &lt;span className=&quot;text&quot;&gt;<br>        &lt;strong&gt;{t.data !== undefined ? t.data :&#39;n/a&#39;}&lt;/strong&gt;:      <br>        {t.text}<br>      &lt;/span&gt;<br>    &lt;/li&gt;<br>  )}<br>&lt;/ul&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*85ubC_u9Vx3ydjiA95sHaw.png" /></figure><p>Plase note that due to DDP we have access to server collection in our React component as <em>props </em>parameter<em> </em>and if server collection is updated then our React component will be re-rended to provide user with refreshed data.</p><p>We have connected Drizzle/Truffle DAPP with Meteor backend using Asteroid javascript libraly but it’s only one task that we need to solve. Our next goal to update DAPP subscription based on smart-contract state. For this purpose we are going to use Drizzle ‘out of the box’ <em>SimpleStorage</em> smart-contact.</p><pre>pragma solidity ^0.4.18;</pre><pre>contract SimpleStorage {</pre><pre>  event StorageSet( string _message );</pre><pre>  uint public storedData;</pre><pre>  function set(uint x) public { <br>    storedData = x;<br>    StorageSet(&quot;Data stored successfully!&quot;);<br>  }<br>}</pre><p>Let’s have a look now at our backend side and integrate smart-contract logic there. Thanks to Truffle framework we can use the same artefacts that we’ve used alredy in our DAPP. Need to say that the backend also have client part running under Meteor/React control. We are not going to make transactions on server part and will use <em>web3</em> library here without any key storage. Backend client part can use Truffle library with Metamask. To update React component we use <em>withTracker </em>function<em> </em>together<em> </em>with<em> Tracker.Dependency </em>object<em>. </em>In smart contract wrapper class we have simple getters and setters with <em>depend</em> and <em>changed </em>functions.</p><pre>const contractDep = new Tracker.Dependency;</pre><pre>class SimpleStorage {<br>  //...<br>  getData() {<br>    contractDep.depend();<br>    return this.data;<br>  }</pre><pre>  _setData(data) {<br>    if(this.data !== data) {<br>      this.data = data;<br>      contractDep.changed();<br>    }<br>  }<br>  // ...<br>}</pre><p>Now inside <em>withTracker </em>loop if contract data is changed then component <em>props</em> will be updated and then React component will be re-rendered.</p><pre>class App extends Component {<br>  // ...<br>  export default withTracker(() =&gt; {<br>    const update = simpleStorage.getData();<br>    Meteor.subscribe(&#39;tasks&#39;);</pre><pre>    return {<br>      tasks: Tasks.find({}, { sort: { createdAt: -1 } }).fetch(),<br>      incompleteCount: Tasks.find({ <br>          checked: { $ne: true } }).count(),<br>      currentUser: Meteor.user(),<br>      currentData: simpleStorage.getData(),<br>    };<br>})(App);</pre><p>Now we are going to update backend server part and make publication depends on the smart contract current state. On server we use <em>web3</em> library to listen <em>SimpleStorage</em> event.</p><pre>let listener = null;</pre><pre>function setListener(cb) {<br>  listener = cb;<br>}</pre><pre>if (Meteor.isServer) {<br>  if (typeof web3 !== &#39;undefined&#39;) {<br>    web3 = new Web3(web3.currentProvider);<br>  } else {<br>    web3 = new Web3(new<br>    Web3.providers.WebsocketProvider(&quot;ws://localhost:8545&quot;));<br>  }<br>  const sc = new web3.eth.Contract(SimpleStorageArtifact.abi);<br>  sc.options.address = SimpleStorageArtifact.networks[5777].address;</pre><pre>  sc.events.StorageSet({fromBlock:0}, <br>    (error, event) =&gt; { if(error)console.error(event) })<br>     .on(&#39;data&#39;, function(event) {<br>       sc.methods.storedData().call().then(result =&gt; {<br>         if(listener) {<br>           listener(result)<br>         });<br>   })<br>}<br>export default setListener</pre><p>Now we can adjust publication for the collection</p><pre>let collectionFilter</pre><pre>function setFilter(filter) {<br>  if(filter === undefined) return;<br>  collectionFilter = filter;<br>}<br>setListener(setFilter)</pre><pre>if (Meteor.isServer) {<br>  Meteor.publish(&#39;tasks&#39;, function tasksPublication(data) {<br>    return Tasks.find({<br>      $or: [<br>        { private: { $ne: true } },<br>        { data: collectionFilter },<br>      ],<br>    });<br>  });<br>}</pre><p>So we are publishing only items with <em>data </em>equal<em> </em>to<em> collectionFilter</em> that is <em>SimpleStorage</em> data. The problem here that <em>Meteor.publish</em> is not re-publish collection if <em>collectionFilter</em> is changed. Only client can push server publish and makes<em> Task.find</em> re-run to provide fresh data. Thanks to Tracker Meteor re-run subscribe and push re-publish if subscribe parameter is changed. So, we can update backend client subscription to get re-publish works in the following way:</p><pre>export default withTracker(() =&gt; {</pre><pre>  const update = simpleStorage.getData();<br>  Meteor.subscribe(&#39;tasks&#39;, <br>    update !== undefined ? update.toString(10) : &#39;loading&#39;);<br>  // ..</pre><pre>}</pre><p>Now we need to go back to our DAPP to make subscription works also here. First of all we are going to get update if store state is changed due to the smart-contract transaction and then if we have new state unsubscribe to the collection and subscribe again using updated <em>SimpleStorage</em> data value.</p><pre>function _select(state) {<br>  return state.contracts.SimpleStorage.storedData[&#39;0x0&#39;] !==   undefined ? state.contracts.SimpleStorage.storedData[&#39;0x0&#39;].value : undefined;<br>}<br>let currentValue = 0;<br>let subscription = asteroid.subscribe(&#39;tasks&#39;, currentValue);</pre><pre>function _refresh() {<br>  let previousValue = currentValue<br>  currentValue = _select(store.getState())<br>  if (previousValue !== currentValue) {<br>    asteroid.unsubscribe(subscription.id);<br>    subscription = asteroid.subscribe(&#39;tasks&#39;, currentValue);<br>  }<br>}<br>store.subscribe(_refresh);</pre><p>Now our DAPP use <em>SimpleStorage</em> as a key to ‘open’ off-chain data for the client. Our backend part is listening blockchain events and as soon as a new transaction arrived open access for the client to the new content. When the client update subscription using Asteroid <em>unsubscribe/subscribe </em>the new content will be available in React interface.</p><p>The full code in our <a href="https://github.com/REGA-RS/meteor-drizzle">GitHub repository</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b16ff0a8dd11" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/drizzle-dapp-with-meteor-backend-b16ff0a8dd11">Drizzle DAPP with Meteor backend</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Luggage Crowdsurance Test]]></title>
            <link>https://colnagorider.medium.com/luggage-crowdsurance-test-284fd79f5c7b?source=rss-e770a8802d0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/284fd79f5c7b</guid>
            <category><![CDATA[luggagecrowdsurance]]></category>
            <category><![CDATA[erc721]]></category>
            <category><![CDATA[crowdsurance]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Sergei Sevriugin]]></dc:creator>
            <pubDate>Tue, 29 May 2018 19:42:11 GMT</pubDate>
            <atom:updated>2018-05-31T19:29:53.080Z</atom:updated>
            <content:encoded><![CDATA[<ol><li>Open Google Chrome</li><li>Install <a href="http://metamask.io/">metamask.io</a> if you don’t have it</li><li>Open metamask and select Ropsten Test Net</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*SUOztlzYYUq3B0sEK_prBA.png" /></figure><p>4. Open <a href="https://faucet.metamask.io/">faucet.metamask.io</a> and request 1 ether for you account</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*miwQx8HrZEle5m2gar2kdg.png" /></figure><p>5. Open <a href="https://tokencrowdsurance.io/">LuggageCrowdsurance DAPP</a> and follow test check list. Please make sure to enter the same name and surname in Activate and Claim steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SOqp1FLSET5oLB9WU2KgaA.png" /></figure><p>6. Share comments in the <a href="https://t.me/joinchat/EDnan0YtQJuAGCUuo8gBVA">product chat</a></p><p>See how it works here</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FhSgpmUp0-7o%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DhSgpmUp0-7o&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FhSgpmUp0-7o%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/517edf49ec819b315a1f62922b15d665/href">https://medium.com/media/517edf49ec819b315a1f62922b15d665/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=284fd79f5c7b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Luggage crowdsurance]]></title>
            <link>https://medium.com/coinmonks/luggage-crowdsurance-d685d3d73121?source=rss-e770a8802d0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d685d3d73121</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[erc721]]></category>
            <category><![CDATA[crowdsurance]]></category>
            <category><![CDATA[dapps]]></category>
            <dc:creator><![CDATA[Sergei Sevriugin]]></dc:creator>
            <pubDate>Fri, 20 Apr 2018 15:40:01 GMT</pubDate>
            <atom:updated>2018-04-22T22:24:20.168Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*9IHuBPcuz9FEYPivjLTfig.png" /></figure><p>The luggage crowdsurance product is TokenCrowdsurance <a href="https://github.com/REGA-RS/ERC721SmartToken">NFT721SmartToken</a>. To build a decentralised financial product we need to use the non fungible token standard ERC721 but as each token it has its own value, so we are connecting this standard with ERC20 token. The following picture shows how it works:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lUOKLYqZ00X0Yvj9iM3hRw.png" /></figure><p>To access ERC20 functions that also has ERC721 token we’ve created ERC20 Adapter, the smart contract connected to the ERC721SmartToken that implements ERC20Controller. So, to get ERC20 balance for a specific account address we should call BalanceOf of the ERC20Adapter and the result (in our example) will be 200. If we want to get a number of tokens belonging to the same address, we will call BalanceOf function of the ERC721 and get 3 as the result. This is just one example how to use the ERC721SmartToken. The full smart contract description is <a href="https://github.com/REGA-RS/ERC721SmartToken/blob/master/help.md">here</a>.</p><p>The next level for building crowdsurance product is adding the TokenContainer concept. One ERC721 token can hold other tokens in the same smart contract.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1XTombHwmFZCjUCuwTKbsw.png" /></figure><p>In this example the Person NFT ID 10 owns to the pets tokens: CAT — NFT ID 1 and DOG — NFT ID 2. <a href="https://github.com/REGA-RS/ERC721SmartToken#tokencontainer">Token Container</a> provides a number of functions to work with the containers including token adding and removing.</p><p>For the specific tasks, including crowdsurance, we need to create the next level that we call the <a href="https://github.com/REGA-RS/ERC721SmartToken#tokenpool">TokenPool</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0g7ohths1fQHYMfvb5SMaQ.png" /></figure><p>Now we have the 4 level pool hierarchy : Super Pool, Pool, SubPool and NFT token. The last level can be also the container as shows our example where the NFT token Person owns two pets tokens and belongs to SubPool NFT ID 3.</p><p>Based on <a href="https://github.com/REGA-RS/ERC721SmartToken#tokenpool">TokenPool</a> we have developed the <a href="https://github.com/REGA-RS/ERC721SmartToken#tokencrowdsurance">TokenCrowdsurance</a> smart contract that provides the functionality of Crowdsurance product. The term “Crowdsurance” means people unite in communities to provide a guarantee of compensation for unexpected loss. Thanks to ERC721SmartToken crowdsurance product can be &#39;tokenized&#39; and can be availible as ERC20 token.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FYKnaK3GUgDbdY6nY-tlXw.png" /></figure><p>In this example we can see how the “join” crowdsurance function works. The join amount has been distributed between pools and commission of the token provider. The description of the issuing process:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xr8480OUi-9WbnhL0fcR4g.png" /></figure><p>The next picture demonstrates how the claim payment process works when the claim for payment appears:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZJwP0b_EIAFTlTeuvev8cw.png" /></figure><p>Finally we introduce the <a href="https://github.com/REGA-RS/ERC721SmartToken#luggagecrowdsurance">LuggageCrowdsurance</a> token with the following parameters:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/1*yrbC9dKFFX42l_v6DKB0Uw.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F41d817%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F41d817&amp;image=https%3A%2F%2Fe.enpose.co%2F%3Fkey%3DdRXnS9Gplk%26w%3D700%26h%3D425%26url%3Dhttps%253A%252F%252Fupscri.be%252F41d817%252F%253Fenpose&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/ebbe4d33ac6b8f6af3724807b028c5eb/href">https://medium.com/media/ebbe4d33ac6b8f6af3724807b028c5eb/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d685d3d73121" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/luggage-crowdsurance-d685d3d73121">Luggage crowdsurance</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>