The procurement and sale of illegal weapons worldwide is complex and includes multiple venues whereby individuals, criminal and terrorist organizations can buy these arms. We know today, that many terrorist organizations are perpetuating terrorist atta…
Between Two Tokens: Episode 1 — Ahmed Abdullah on Conducting IEOsPhoto by Austin Distel on UnsplashThis is a brand new series where we ask Blockchain thought leaders, entrepreneurs, and specialists about their experiences of working in the Blockchain s…
What to Talk About if You’re a Person in Tech this Week: All the ~free~ opinions you need to sound like a smartypants at lunchhuman-robot relations making headlines this weekHello Hackers,Welcome to this week’s edition of must-read-tech-reads from Hack…
Source: Libra.orgFacebook has finally disclosed the details of its cryptocurrency Libra with the long-awaited Libra whitepaper. Libra will allow its users to buy things or transfer money to others with zero fees.Libra cryptocurrency holders will also b…
Smart-contracts have become synonymous with Solidity scripts on Ethereum and they can be used to create many things: multi-signature wallets, fungible and non-fungible tokens, payments with the escrow and so on. In most cases, you don’t need to decentr…
Transforming into a DAO — What Does That Involve?For those of you who follow the Digitex Futures project, you’ll have heard the news by now. In Adam’s video update yesterday, you saw he threw another curveball at the community by announcing that Digite…
Facebook leads the creation of a new currency called Libra powered by blockchain.
Silicon Valley giant Facebook has finally unveiled its new project! The company started by Mark Zuckerberg is coming together with 27 organizations around the world to start the non-profit Libra Association and create a new currency called Libra.
“Libra’s mission is to create a simple global financial infrastructure that empowers billions of people around the world,” wrote Zuckerberg in a post on Facebook. “It’s powered by blockchain technology and the plan is to launch it in 2020.”
Libra, according to the Libra Association website, wants to “reinvent money, transform the global economy, so people everywhere can live better lives.”
“Being able to use mobile money can have an important positive impact on people’s lives because you don’t have to always carry cash, which can be insecure, or pay extra fees for transfers,” explained Zuckerberg. “This is especially important for people who don’t have access to traditional banks or financial services. Right now, there are around a billion people who don’t have a bank account but do have a mobile phone.”
According to Techcrunch, each founding member paid a minimum of $10 million to join. In joining, they gain one vote — or 1% of the total vote (whichever is larger) — in the Libra Association council, and be entitled to a share (proportionate to their investment) of the dividends from interest earned on the Libra reserve users pay fiat currency into to receive Libra.
Facebook says it hopes to reach 100 founding members before the official Libra launch and it’s open to anyone that meets the requirements including direct competitors like Google or Twitter, writes Techcrunch, explaining that the Libra Association, based in Geneva, Switzerland, will meet biannually. “The country was chosen for its neutral status and strong support for financial innovation including blockchain technology,” according to Techcrunch.
The idea behind Libra rests on a few elements and characteristics:
- Mobile: Libra will be accessible to anyone with an entry-level smartphone and data connectivity.
- Stable: Libra is backed by a reserve made to keep its value stable.
- Fast: Libra transactions are quick and easy, no matter where you are sending, or spending, your money.
- For the world: Libra is a global cryptocurrency that will be available around the world.
- Scalable: Libra will foster an ecosystem of products and services made to help people use Libra in their everyday lives.
- Secure: Libra is a cryptocurrency, built on a blockchain designed with security in mind.
According to The New York Times Times, Facebook has sky-high hopes that Libra could become the foundation for a new financial system not controlled by today’s power brokers on Wall Street or central banks.
“It feels like it is time for a better system,” David Marcus, head of Facebook’s blockchain technology research, said in an interview. “This is something that could be a profound change for the entire world.”
1/ Hello, ≋
In a Twitter thread, Marcus explained: “The journey begins today, and we’re grateful to have such an outstanding group of cofounding members of the Libra Association — the independent non-for-profit entity that will govern this new network and currency, which we hope will become a public good for the world.”
In addition to the Libra Association, Facebook has created a subsidiary named Calibra. It will be led by Marcus and will will build services on top of the Libra network and currency, starting with a wallet — one of many that will launch on Libra.
“One of the reasons for creating Calibra was to have a dedicated, regulated entity that will make strong privacy commitments to its customers as we’ve heard loud and clear that you don’t want social and financial data commingled,” wrote Marcus on Twitter.
We understand we will have to earn your trust.
He continued: “While Facebook/Calibra will continue to contribute and work on this project, we will not have any special rights or privilege with the Libra Association and the network by the time it launches. In other words, we will have the same governance rights as any other member.”
Libra has three distinct components, according to Marcus:
- a BFT-based (LibraBFT) permissioned (to start) scalable blockchain;
- a reserve-backed cryptocurrency designed to be a medium of exchange;
- a new programming language (Move).
The Libra White Paper, in addition to explaining structure and goals, highlights the need for the involvement of the crypto and blockchain community.
- If you are a researcher or protocol developer, an early preview of the Libra testnet is available under the Apache 2.0 Open Source License, with accompanying documentation. This is just the start of the process, and the testnet is still an early prototype under development, but you can read, build, and provide feedback right away. Since the current focus is on stabilizing the prototype, the project may initially be slower to take community contributions. However, we are committed to building a community-oriented development process and opening the platform to developers — starting with pull requests — as soon as possible.
- If you want to learn about the Libra Association, read more here.
- If your organization is interested in becoming a Founding Member or applying for social impact grants from the Libra Association, read more here.
Cryptocurrencies have long been dogged by a reputation when it comes to security. Could artificial intelligence be about to change that?Image source: PixabayThere are several significant concerns regarding cryptocurrency that make some investors hesita…
Everything You Need to Know About BlockchainA Financial War is coming.The blockchain revolution is coming. And it’s going to fundamentally change how businesses operate.Make no mistake… this revolution is at least as significant as the one brought abou…
Gaming was one of the main hopes for the mass adoption of Blockchain technology at some point. People foresaw the emergence of amazing games and decentralized applications (DAPPs), which would push the internet to the edge of web 3.0.Right now we are a…
Critical Security Update: Coinbase Security Team Discovers Zero-Day Exploit in FirefoxZero-Day Exploit Found Targeting Crypto-UsersCoinbase Security and Samuel Groß, a security researcher with Google, discovered a zero-day exploit on the Mozilla Firefo…
When working with MapR Database, there are limitless ways to interact with it as we have explored in previous posts, such as Interacting with MapR Database, MapR Database Spark Connector with Secondary Indexes Support, and MapR-DB Atomic Document Updat…
Are you a developer trying to understand how serverless architecture works? Find out how in this guide.If you’ve heard of “serverless architecture,” but you’re still confused about what it means, don’t worry. This concept has been growing in popularity…
Have you ever managed to have that long-distance relationship with your employees being a project manager? Well, we all are aware of long distance relationships being a little difficult to maintain. With the hike of digital entrepreneurs there comes a …
Identity and access Management (IAM) is one of the key tools to ensure enterprise network security. There are many security providers on the market, but how do I find the right identity and access management solution for you?When choosing an IAM soluti…
The Stablecoin you Decide to Spend will Determine how Future Banking UnfoldsWe may soon live in a world where the currency you choose to use each day matter (source)Stablecoin is a type of a cryptocurrency that is designed to be ‘stable’ by minimizing …
MimbleWimble and GRIN Coin: A Return to the Original Vision of Bitcoin?MimbleWimble is a scalable, privacy-based blockchain protocol that verifies transactions without needing to store the entire history of the chain.Image by mseeryWhat is MimbleWimble…
Simply Explained: Blockchain Scalability Solutions — Past, Present, and FutureAnd how Polkadot & Substrate fits into this ecosystemI recently gave a talk at Cogx about how blockchains scale. Where, we also discoursed how Polkadot fits into a future…
What comes after Proof of Work?Since the creation of Bitcoin by Satoshi Nakamoto in 2009, Bitcoin has transformed how the world thinks about money, privacy, contracts, and more.Launched as an experimental, decentralized form of money, Bitcoin has been …
It is no secret that the crypto community is still trying to find use cases that bring blockchain and cryptocurrency into the mainstream. The technology has seen waves of adoption through the Initial Coin Offering (ICO) craze, the CryptoKitties era, an…
San Francisco, CALIFORNIA — Last Thursday, Facebook, Inc. and Princeton University were hit with a major lawsuit from home design company, Planner 5D, claiming the two Defendants were scraping over five gigabytes of data from more than 2,500 three-dime…
Machines may not have taken over the world yet, but they are seeping into our lives and making it better. AI is changing every aspect of our lives. From self-driving cars to talking bots, there are so many examples of AI in use today. The technology is…
An explanation of TandaPay’s social agenda productYou say you want a revolution, well, you knowWe all want to change the world. How are we supposed to change the world when protests don’t produce the change we want to see? When unarmed members of local…
Binance is the largest and most well-established exchange in the cryptomarket. Learn how to use the platform in this article.Screenshot from the front-page of Binance.com mid-2019Bitcoin (BTC), Ethereum (ETH), Litecoin (LTC), Ripple (XRP), Monero (XMR)…
Android Unidirectional Data Flow with LiveData
Improving Coinverse’s Performance and Structure
The Unidirectional Data Flow (UDF) pattern has improved the usability and performance of Coinverse since the first beta launched in February. Coinverse is the first app creating audiocasts covering technology and news in cryptocurrency. Upgrades using UDF include more efficient newsfeed creation, removal of adjacent native ads, and faster audiocast loading.
The UDF pattern organizes the app into three main areas, view state, events, and effects ensuring the app is modularized and reliable. I learned of the UDF pattern from episode 148 of the Fragmented podcast, Evolving Android architectures (Part 1) with Kaushik Gopal at Instacart and Donn Felker. On first listen it was interesting, but a large overhaul. UDF became compelling as I worked on fixing bugs and realized how complex various flows had become.
The examples of UDF I’ve seen thus far have been with Rx. Rx a powerful and customizable tool for creating streams of data that can be observed in real-time. However, LiveData provides the same benefit of observing state changes and on top of that is simple, directly integrates with Android’s architecture components, and handles Android’s lifecycle events by default. If unfamiliar, check out Google’s Jose Alcérreca’s talk on LiveData. To try out UDF I refactored the newsfeed flows in Coinverse as we’ll walkthrough below.
UDF pattern, a.k.a. Unidirectional Data or State Flow was originally popularized in web development with Facebook’s React and Readux state management, and Flux UI libraries. Early Android experimentation can be found from Brian Egan and Guillaume Lung at SoundCloud in 2015. Jake Wharton’s talks on Rx educated developers on reactive programming which are fundamental to UDF.
Growing Number of Android Apps Adopting
To name a few…
- Kaushik Gopal and Laimonas Turauskas @ Instacart
- Dan Hill @ Robinhood
- Donald Chen @ Instagram Engineering / Lyft
- Cesar Valiente @ Microsoft
Model View View Model — MVVM
For the first iteration of Coinverse I used the Model View View Model (MVVM) approach. MVVM separates the UI from the business logic, improving readability and organization. However, as an app grows with MVVM it becomes a lake of data. Information flows in, out, and around at many points via Activities and Fragments with Data Binding, ViewModels, and Repositories. This adds complexity for keeping track of logic, debugging, and testing, which requires mocking many components.
UDF is a waterfall, information flows in one direction through a single source providing many benefits.
- One point of entry for streams — The UI and business logic interact through single points of entry.
- Control UI involving async events — Know exactly when and where things begin and finish
- Debug issues — Easy to follow sequence of events and identify errors
- Streamlined tests — The majority of logic is contained in the ViewModel requiring less mocking.
LiveData provides a straightforward approach to implementing UDF.
- Lifecycle aware
- Can emit multiple or single events
- Concise code
- Quick to implement
View State, Events, and Effects
View state is responsible for holding the final view’s persisted data. This entails all of the content shown to a user on a screen, including information about the content such as enabled statuses.
Looking at Coinverse’s main newsfeed above, examples of view state include the contents of the toolbar, what timeframe and the feedtype of feed to display, as well as the contentList to populate the feed with.
View events consist of both user interface and system initiated actions. UI actions include button presses and text input, whereas system actions might be Android lifecycle events and screen rotation.
In the case of The Coinbase Blog’s content selected above a view event is created, ContentSelected. The event will share information with the business layer to initiate the retrieval of the audiocast selected.
View effects are one time UI occurrences that don’t persist. Effects include navigation, dialogs, and toasts. Effects are created by the business layer to initiate changes in the UI.
When the CCN item above is swiped right, the business layer adds a saved label to the content. The business layer sends an effect, ContentSwiped, informing the UI of the change in the content’s label. The UI can then remove the content from the main newsfeed.
Let’s understand how the one-way flow of data is structured. The View handles all UI and system level actions stored in a single stream. The stream is sent to the ViewModel that receives the actions and handles them accordingly in the business logic.
The ViewModel is the source of truth for the view state and creates any necessary effects. The ViewModel also handles requests to the data Repository layer, managing the results loading, success (content), and error states returned from the Repository with an Lce object (more on Lce’s below).
Both the state and effects are observed by the View, updating any changes from the ViewModel in real-time.
We’ll use Coinverse’s main newsfeed loading as our example for how to implement UDF.
Step 1 of 6 — Define Models
- View state — Stored as a LiveData object in the ViewModel, storing the contentList of LiveData type
- View event and effect — Use Kotlin’s Sealed class to pass one time events
The view state uses LiveData because it’s important the data is immutable vs. MutableLiveData. Otherwise, the flow of data would not be unidirectional, and the state could be changed in many places.
View events and effects are not persisted in the ViewModel. A Sealed class, like an Enum, but on a class level, is used to pass information. Sealed classes define a parent and child class with or without data. TheScreenLoad event is a data class with data about what the ViewModel should load. Whereas the UpdateAds effect is a class without data telling the view to update the ads in the newsfeed.
Step 2 of 6 — Pass events to ViewModel
In this example, when the system action of onCreate occurs, a ScreenLoad event is added to the stream of view events and sent from the Fragment to the ViewModel to start creating the main feed.
All of the events created in the View / Fragment are added to a LiveData object _viewEvent, a MutableLiveData object which updates the immutable LiveData object. I’m using the pattern of passing all of the events in onResume based on Kaushik’s sample.
The LiveData stores data wrapped in an Event. As explained by Jose in his LiveData post about events, events ensure a single unique object is added to a stream. This avoids the accidental creation of multiple objects for a single action.
Step 3 of 6 — Process events
The ViewModel receives incoming events, handling each event in a when statement based on the type of Sealed ViewEvent class. For ScreenLoad, the entireViewState is updated with the required data. To populate the newsfeed a request to the Repository with getMainFeed is made.
Update State Value
In cases where an attribute of the ViewState needs to be updated rather than the entire ViewState, Kotlin’s shallow copy function is useful.
Step 4 of 6 — Manage Network Requests with LCE Pattern
To manage network requests, Kaushik introduces the Lce Sealed class object with three states, loading, content, and error. The content state represents a successful request.
A Sealed class is also useful for returning different types of results.
getMainFeed’s network request shares send the Lce states to the ViewModel via the LiveData stream. The PagedListResult class can be passed into the Lce for both the content and error states. The ViewModel will then manage each state appropriately.
Step 5 of 6 — Handle LCE States
The gif shows something has gone awry. We’ll see how the error is handled in the ViewModel.
UDF has streamlined both methods of requesting new content from the network and retrieving the updated content from the Room database. Prior to using UDF, Coinverse called two repository methods separately to populate the main newsfeed.
When the feed is loading the existing Room database content is returned so that the user is not staring at an empty screen. For the successful Content case, the updated content from Room is returned. For errors requesting new content, the existing Room content is also displayed similar to theLoading case. In the error above, a SnackBar view effect is passed to the Fragment to display the error message.
The ViewModel observes each Lce state with a LiveData SwitchMap. The SwitchMap passes in one LiveData object and returns a new and different LiveData object that is saved to the view state.
Like all LiveData, a SwitchMap must be observed in the view in order for the value to be emitted within the map inside the ViewModel.
Step 6 of 6 — Observe State Change!
Now the view state may be observed when an update occurs. The view effects are observed in the same way.
Bonus — Removing Adjacent Ads
In addition to a streamlined newsfeed above, UDF has improved how Twitter’s native MoPub ads are shown in the newsfeed. MoPub’s MoPubRecyclerAdapter does not have a built-in approach to avoid adjacent ads from showing. Content can be swiped to be saved or dismissed, eventually causing two ads to appear next to each other. Prior to UDF, this was handled with a manual swipe-to-refresh by the user.
With UDF there is a contentLabeled view state. When the status of the view state changes, meaning an item is labeled to be removed from the main feed, a check for adjacent ads is made. If removing the content creates adjacent ads, the ads are automatically refreshed.
Using LiveData for the Unidirectional Data Flow has been great, but it’s not perfect.
LiveData is only applicable for logic impacting the UI. For non-UI logic LiveData will not be observed since it requires lifecycle to be passed in. For these instances, Kotlin coroutines or Rx may be used. If no UI is involved then an even better solution might be to offload the logic completely to the backend with Firebase Cloud Functions.
There’s not as much customization with LiveData for things like threading. With this year’s latest Google I/O updates coroutines appear to easily integrate with LiveData offering more customization.
Coinverse Next Steps
- Unidirectional Data Flow — Expanding to the rest of Coinverse’s app
- JUnit testing — Now that the majority of the newsfeed logic is modularized in the ViewModel, JUnit testing will be easier with less mocking of components.
- Kotlin coroutines — Exploring integration with LiveData
- Slides — Unidirectional Data Flow por Adam Hurwitz @ Medellín Android MeetUp
- Notes — Unidirectional Data Flow guide
I’d love your feedback on the Coinverse beta!
Follow me to be updated on a Unidirectional Data Flow sample app and more.
Whether you are new or experienced in the world of Bitcoin and cryptocurrencies, it is essential to constantly train yourself. This training work involves reading books on the subject. Faced with the abundance of books around Bitcoin and cryptocurrenci…