dapp

Source dapp

The DApp library is a collection of several functions to handle DApp loading, starting and depdency resolve.


getSplittedVersion

dapp.getSplittedVersion(versionString);

Splits an version, removes non number characters, reduce length to 3 and adds missing numbers.

Parameters

  1. versionString - string (optional): Version that should be splitted (eg. “0.1.0”)

Returns

Array<number|string> : The splitted version.

Example

getSplittedVersion("0.1.0")
// [0, 1, 0]

getVersionDBCPHashFromDAppVersion

dapp.getVersionDBCPHashFromDAppVersion(requiredVersion, childENS, childDefinition);

Returns the ipfs hash to the dbcp of the child with the correct version.

Parameters

  1. requiredVersion - string: version that should be loaded from the child
  2. childENS - string: ens address of the child (the current deployed version is not listed in the versions object, the function sets the ens address within the versions object with the current version)
  3. childDefinition - any: The version dbcp hash from the specific DApp version.

Returns

string : The version dbcp hash from the specific DApp version.

Example

getVersionDBCPHashFromDAppVersion(
  dependencies[dependency],
  dependency,
  subDefinition
)
// returns : Qmb...

getDAppDependencies

dapp.getDAppDependencies(originName, ensDefinition, depTree, deep);

Loads all (sub) dependencies dbcp’s of the provided dapp and set systemjs maps to the correct dbcp hashes. Explanation:

  • load the latest dbcp.json from the dapp ens address
  • after this, the correct lib ipfs hash gets extracted from the version history of the latest dbcp.json
  • the new definition will loaded from the extracted ipfs hash and this versions will be overwritten by the latest one, to be sure, that all versions, including the latest one, are included
  • the used definition will now not the latest one, only the correct dbcp description of the desired version
  • dev version only used for DApps, that also requires the latest current version of the library

Parameters

  1. originName - string: name of the module that should be traversed;
  2. ensDefinition - any: ens definition of the module that should be traversed (iterate through dependencies);
  3. depTree - Array<Array<n>> (default = [ ]): dependency tree of a DApp;
  4. deep - number (default = 0): recursion count to prevent recursive dependency;

Returns

Promise returns Array<Array<n>>: dependency tree of a DApp

Example

await getDAppDependencies(dappEns, ensDefinition);
// returns: [
//   [],
//   [
//     {
//       "name": "angular-libs",
//       "definition": {
//         ...
//       },
//       "location": "angularlibs.evan!dapp-content"
//     }
//   ],
//   [
//     {
//       "name": "angular-core",
//       "definition": {
//         ...
//       },
//       "location": "angularcore.evan!dapp-content"
//     }
//   ]
// ]

loadDAppDependencies

bcc.loadDAppDependencies(dappEns, useDefaultDomain);

Load all dependencies of the dapp using SystemJS and register its ens names, so each DApp can load the dependency using it within import statements.

import {
  ...
} from 'angular-core';

Parameters

  1. dappEns - object: ens of the dapp
  2. useDefaultDomain - boolean (optional): decide if the default domain should be used

Returns

Promise returns any: ens definition from the DApp

Example

dapp.loadDAppDependencies(dappEns, useDefaultDomain);

// returns ens definition
// {
//   "name": "angular-libs",
//   "definition": {
//     ...
//   },
//   "location": "angularlibs.evan!dapp-content"
// }

loadDApp

dapp.loadDApp(dappEns, useDefaultDomain);

loads a DApp description and register it’s dependencies. Returns the js exported module and the loaded ens definition.

Parameters

  1. dappEns - object: ens of the dapp
  2. useDefaultDomain - boolean (optional): decide if the default domain should be used

Returns

Promise returns any: returns { module: { … }, ensDefinition: {…}}

Example

loadDApp('dashboard', true);

// returns:
//  {
//    module: loadedModule,
//    ensDefinition: ensDefinition
//  }

startDApp

dapp.startDApp(dappEns, container, useDefaultDomain);

Loads an DApp from ENS, resolves it’s dependencies and runs the startDApp function or, in case of an html entrypoint, adds an iframe and loads the url.

Parameters

  1. dappEns - object: ens address to load the dapp from
  2. container - Element (default = document.body): element where DApp was started
  3. useDefaultDomain - boolean (optional): decide if the default domain should be used

Returns

Promise returns void: resolved when DApp started

Example

await dapp.startDApp('dashboard.evan');

getDomainName

dapp.getDomainName(...subLabels);

builds a full domain name for the current bcc config

Parameters

  1. Array<string> - subLabels: used to enhance nameResolver config

Returns

The domain name : The domain name.

Example

ensDomain = `bcc.${ getDomainName() }!dapp-content`
// returns: bcc.evan!dapp-content