☁️
Züs
  • About Züs
  • Concepts
    • Architecture
      • Mining on the Züs Blockchain
        • Onboarding a New Miner or Sharder
        • Block Production Protocol
        • Block Finalization
        • Merkle Patricia Trees(MPT) and Recovery
        • View Change and Distributed Key Generation(DKG)
      • Payment
      • Storage
      • Token Bridge Protocol
      • Resources
    • Tokenomics
      • Staking Process
      • Block Rewards
      • Delegation
    • Store
    • Earn
    • Build
    • NFT
  • Resources
    • Whitepapers
      • Tokenomics Paper
      • Architecture Paper
      • Storage Paper
    • Patents
      • NON-FUNGIBLE TOKEN BLOCKCHAIN PROCESSING
      • FREE STORAGE PROTOCOL FOR BLOCKCHAIN PLATFORM
      • TRANSFERRING CONTENT VIA PROXY RE-ENCRYPTION
      • STREAMING CONTENT VIA BLOCKCHAIN TECHNOLOGY
      • SPLIT-KEY WALLET ACCESS BETWEEN BLOCKCHAINS
      • ENFORCING SECURITY PARAMETERS SPECIFIED BY AN OWNER ON A BLOCKCHAIN PLATFORM
      • CLIENT AUTHENTICATION USING SPLIT KEY SIGNING ON A BLOCKCHAIN PLATFORM
      • BLOCKCHAIN CONTENT PURCHASING PROTOCOL
      • BLOCKCHAIN BASED PRIVACY COMPLIANCE PLATFORM
      • SYSTEMS AND METHODS OF SELF-ADMINISTERED PROTOCOLS ON A BLOCKCHAIN PLATFORM
      • SYSTEMS AND METHODS OF AGGREGATE SIGNING OF DIGITAL SIGNATURES ON MULTIPLE MESSAGES SIMULTANEOUSLY U
      • SYSTEMS AND METHODS OF BLOCKCHAIN PLATFORM FOR AUTOMATED ASSET BASED PROVISIONING OF RESOURCES
      • SYSTEMS AND METHODS OF SELF-FORKING BLOCKCHAIN PROTOCOL
      • SYSTEMS AND METHODS OF SUSTAINABILITY PROTOCOL USING DISTRIBUTED BLOCKCHAIN APPLICATION WITH IoT SEN
      • SYSTEMS AND METHODS OF BLOCKCHAIN PLATFORM FOR DISTRIBUTED APPLICATIONS
  • API Reference
    • Endpoints
      • Block
      • Client
      • Connection
      • DNS
      • File
      • Smart Contracts
      • Blobber Stats
      • Transactions
      • Miners and Sharders
        • Stats
        • State
        • Diagnostics
        • Configuration
        • Smart Contract State
        • Smart Contract Stats
        • Chain Stats
  • Hackathon
    • Register to Hackathon
      • How to Add Members to Hackathon Team
    • Repos
    • Documentation
  • Products
    • Bolt
      • Get Started
      • Stake
      • Activity
      • Buy ZCN
      • Sell ZCN
      • Send Tokens
      • Receive Tokens
      • Settings
        • Manage Profile
        • Wallet
        • Read Pool
      • Troubleshooting
    • Vult
      • Sign Up
      • Upload File
      • Upload an Encrypted File
      • Upload a File to a Folder
      • Share a Uploaded File
      • Move a Uploaded File
      • Delete a File
      • Make File Available Offline
      • Troubleshooting
    • Atlus
      • Dashboard Overview
      • Service Providers
      • Charts
        • Market Charts
        • Network Charts
        • Storage Charts
        • Züs Explainer
      • Blockchain
      • Server Map
    • Blimp
      • Sign Up
        • Buy ZCN for Storage
      • Use Blimp as Direct Storage
      • Use Blimp as S3 Server
        • S3 Operations
      • Use Blimp for Cloud Migration
      • Manage Allocations
        • Extend Size
        • Extend Duration
        • Add Blobber
        • Replace Blobber
        • Make allocation Immutable
        • Freeze Allocation
        • Cancel Allocation
    • Chimney
      • Get Started
      • Deploy Blobber on Own Server
      • Deploy Blobber on Rented Server
      • Stake Blobber
      • Add Blobber
      • Monitor Blobbers
      • Visualize Blobber Logs
      • View Blobber Rank
    • Chalk
      • Sign Up
      • Create NFT Collection
        • Buy ZCN for NFT via ERC token
        • Buy ZCN for NFT via Credit card
      • Explore NFT Collections
      • My NFTs
      • Profile
        • Withdraw Earnings
        • Manage Collections
  • Guides
    • Zus GO SDK
    • Zus JS SDK
    • Zbox CLI
      • Repo
      • Get Started
      • Creating and Managing Allocations
      • Uploading and Managing Files
      • Lock and Unlock Tokens
      • Tips and Troubleshooting
    • Zwallet CLI
      • Repo
      • Get Started
      • Zwallet Operations
      • Staking on miners and sharders
      • Burn and Mint Tokens using Zwallet
      • Troubleshooting
    • Add a Blobber
      • Repo
      • Getting Started
    • Add a Miner/Sharder
      • Repo
      • Getting Started
    • Setup a Blockchain
      • Repo
      • Quickstart
        • Understand the Script
      • Step 1: Set up the project
      • Step 2: Setup the network for Züs components
      • Step 3: Initialize and Build the Züs components
      • Step 4: Start Sharder and Miner Containers
      • Step 5 : Create a wallet using zwalletcli
      • Step 6: Starting the blobber containers
      • Step 7: Validate Züs deployment
      • Step 8: Creating an Allocation on Blobber
      • Restarting Sharder and Miner Containers with CleanDB.
      • Additional Tips and Troubleshooting
    • Glossary
  • Support
    • Help Center
      • Community
      • Issues on Github
      • Contact Us
Powered by GitBook
On this page
  1. Guides
  2. Züs GoSDK
  3. GoSDK for mobile builds (iOS and Android)
  4. Android GoSDK Sample App

Integrating Storage and Wallet Functionalities

The page provides instructions on how to integrate storage and wallet functionalities to home page of your App.

Main Activity Directory

The following directories lie inside the android studio project:

│   ├── mainactivity
│   │   ├── MainActivity.kt (Launched at startup and sets up action bar and saved wallet.)
│   │   └── MainViewModel.kt (Core wallet saving classes using files in android)
└── ZusExampleApplication.kt (Application class for initializing static libraries. )
UI/mainactivity/MainActivity.kt
package org.zus.bolt.helloworld.ui.mainactivity

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.navigateUp
import androidx.navigation.ui.setupActionBarWithNavController
import kotlinx.coroutines.runBlocking
import org.zus.bolt.helloworld.R
import org.zus.bolt.helloworld.databinding.MainActivityBinding
import org.zus.bolt.helloworld.utils.Utils

class MainActivity : AppCompatActivity() {
    private val READ_AND_WRITE_STORAGE_PERMISSION: Int = 1
    private lateinit var binding: MainActivityBinding
    private lateinit var appBarConfiguration: AppBarConfiguration
    private lateinit var viewModel: MainViewModel
    private lateinit var utils: Utils
    override fun onCreate(savedInstanceState: Bundle?) {
        installSplashScreen()
        super.onCreate(savedInstanceState)
        binding = MainActivityBinding.inflate(layoutInflater)
        /* ViewModel to store the created wallet and allocation until the app is running. */
        viewModel = ViewModelProvider(this)[MainViewModel::class.java]
        utils = Utils(this)

        setContentView(binding.root)
        setSupportActionBar(binding.toolbar)

        /* Setting app bar for the back button navigation. */
        val navController = findNavController(R.id.nav_host_fragment_content_main)
        appBarConfiguration = AppBarConfiguration(navController.graph)
        setupActionBarWithNavController(navController, appBarConfiguration)
        /* Setting wallet json. */
        runBlocking {
            viewModel.wallet = utils.getWalletModel()
            viewModel.setWalletJson(utils.readWalletFromFileJSON())
            Log.i("WalletDetails", "json: ${viewModel.wallet?.walletJson}")
        }

        val permissions = arrayOf(
            android.Manifest.permission.READ_EXTERNAL_STORAGE,
            android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
        )
        ActivityCompat.requestPermissions(
            this,
            permissions,
            READ_AND_WRITE_STORAGE_PERMISSION
        )
    }

    override fun onSupportNavigateUp(): Boolean {
        val navController = findNavController(R.id.nav_host_fragment_content_main)
        return navController.navigateUp(appBarConfiguration)
                || super.onSupportNavigateUp()
    }
}

Describing Code:

  • MainActivity Classspecifies what the app does and how it should respond to the user. Its created in Android Studio by default with blank implementation. Developers implement it according to the desired activity lifecycle of an app.

  • Line 19 to 23 defines the following variables in the class: A viewModel variable to hold the MainView of the App A utils variable to access util functions A binding variable to bind app data to the view of the app. A appBarConfiguration to hold main AppView bar.

  • On Line 24 to 26 onCreate() method is overriden and is called with the super keyword is to call the constructor of its parent class to access the saved App Activity states

  • Line 27 creates an instance of binding class and binds the main activity state to interacts with views.

  • Line 29 viewModel temporarliy holds the created wallet until the app is viewable

  • Line 32 passes the rootview and make it the active view on the screen

  • Line 33 passes the appbar view and make it the active view on screen .

  • Line 35 to 55 sets up App bar with the app title and overflow menu for app navigation .Also wallet is set to be use.

  • Line 57 to 62 overrides the onSupportNavigateUp() method which comes from AppCompatActivity class. Overriding it helps NavigationUI correctly support the up navigation or even the drawer layout menu.

UI/mainactivity/MainViewModel.kt
package org.zus.bolt.helloworld.ui.mainactivity

import androidx.lifecycle.ViewModel
import org.zus.bolt.helloworld.models.bolt.WalletModel
import sdk.StorageSDK

class MainViewModel : ViewModel() {

    var wallet: WalletModel? = null
    var storageSDK: StorageSDK? = null

    fun setWalletJson(walletJson: String) {
        wallet?.walletJson = walletJson
    }
}

Describing Code :

  • Line 7 Class MainViewModel defines the following properties and fields for creating the MainActivity fragment to use.

  • Line 9 A writable wallet variable that can hold WalletModel Instance and access its methods.

  • Line 10 A writable storageSDK variable that can hold StorageSDK Instance and access its methods.

  • Line 12 to 14 defines function setWalletjson which sets Wallet.

UI/ZusExampleApplication.kt
package org.zus.bolt.helloworld.ui

import android.app.Application
import android.util.Log
import androidx.appcompat.app.AppCompatDelegate
import org.zus.bolt.helloworld.utils.Utils
import sdk.Sdk
import zcncore.Zcncore

private const val TAG_APP = "HelloWorldApplication"

class ZusExampleApplication : Application() {
    private val utils: Utils by lazy {
        Utils(applicationContext)
    }

    init {
        /* Loading .so files/native libraries in the jNi libs for proper functioning of the app with gosdk. */
        try {
            System.loadLibrary("c++_shared")
            System.loadLibrary("bls384")
            Log.i(TAG_APP, "successfully initialized native libraries")
        } catch (e: UnsatisfiedLinkError) {
            Log.e(TAG_APP, "failed to initialize native libraries UnstatisfiedLinkError", e)
        } catch (e: Exception) {
            Log.e(TAG_APP, "failed to initialize native libraries Exception", e)
        }
    }

    override fun onCreate() {
        super.onCreate()

        try {
            // Initialize Zcncore and Sdk with chain config  at the start of the Application.
            Zcncore.init(utils.config)
            Sdk.init(utils.config)
            if (utils.isWalletExist())
                Zcncore.setWalletInfo(utils.readWalletFromFileJSON(), false)
            Log.i(TAG_APP, "onCreate: sdk initialized successfully")
        } catch (e: Exception) {
            Log.e(TAG_APP, "onCreate: sdk initialization failed Exception", e)
        }
    }
}

Describing Code :

  • Line 3 to 8 loads certain libraries for properly intializing the zcncore.

  • Line 12 ZusExampleApplication class primarly initializes the zcncore required to interface with dStorage wallet and storage functions here .

  • Line 14 initalize zcncore , storage network configuration which is fetched from Utils.kt getConfigFromAssets function.

  • Line 30 onCreate() method initializes the zcncore libraries at line 31 for Ui to use.

  • Line 37 to 42 execute thrown errors if storage network and wallet config is not found If not found wallet is set via GoSDK setWalletInfo function.

Last updated 1 year ago