Skip to content

Latest commit

 

History

History

backend

Diem Reference Wallet

Diem Reference Wallet is an open-source project aimed at helping developers kickstart wallet building in the Diem ecosystem. We tried to incorporate both technical and design aspects to show not only how the different technical pieces fit together but also demonstrate thoughtful design, content, and best experience practices.

Note to Developers

  • Diem Reference Wallet is a reference implementation, and not meant to be fully production grade.
  • The project will continue to develop to include the different aspects of the evolving Diem ecosystem.

Getting Started

The quickest way to get started testing the Diem Reference Wallet is by using Docker Compose.

Next, setup the local system and generate necesssary keys using the script below. This information will be shared into the local environment for Docker Compose to consume.

$ ./scripts/lrw.sh setup_environment  # generate and register keys

Then run the following to build the images from source and stand up a local deployment:

$ ./scripts/lrw.sh develop

The default gateway port is 8080, so you can visit http://localhost:8080. Develop mode also exposes the other ports from the backend services onto the host. The main backend webserver is on 5000. Swagger API docs can be found at http://localhost:5000/apidocs.

Getting started in the code, we've provided detailed logs through each of the workflows, which can be found at http://localhost:5000/execution_logs.

Docker Compose

More docs can be found in scripts/README. Many commands, such as lrw.sh develop, start, and build will build images and stand up containers as specified within the docker-compose files. Of the images built, ones of particular note are: lrw_gateway, lrw_backend, and lrw_liquidity.

  • lrw_gateway contains nginx configuration and serves our frontend
  • lrw_backend contains our backend code and various entrypoints for the web server, its workers, and a pubsub worker
  • lrw_liquidity contains our liquidity service

Minikube

We’ve included some helm chart boilerplate in helm/reference-wallet, outlining a barebones deployment. This spins up the services and deployments for each of our backend services, as well as for our frontend gateway to serve static content, and an nginx ingress controller.

For testing locally, you can use minikube. Our script includes a deploy_minikube option for local testing. You may also need to tweak the variables in helm/reference-wallet/values.yaml to specify keys. You can grab those from the .env files generated by the lrw.sh script during setup.

$ minikube start  # start minikube locally
$ minikube addons enable ingress  # enable the ingress addon for minikube
$ ./scripts/lrw.sh deploy_minikube  # build images and deploy using helm

After deploying, you should be able to see the live address by running kubectl get ingress.

If you want to go the extra mile, you can also use helm to install the Diem Reference Wallet onto an existing kubernetes cluster, for example using eksctl. You can then install LRW onto the cluster as we did with minikube. You may need to specify an ingress class in the helm values under ingress >> annotations in the provided helm values file, depending on where you deploy.

Manually

The Python backend relies on pipenv. To set up, run pipenv install --dev in /backend directory.

The workflows use dramatiq with the Redis broker. Install Redis and run it as a daemon:

$ redis-server --daemonize yes

After ensuring you have Redis running:

$ ./run_web.sh  # runs main webserver
$ ./run_worker.sh  # runs dramatiq workers

To test:

$ ./format.sh  # runs black
$ ./test.sh  # runs unit tests and type-checker

Running the Diem Mini Wallet (DMW) TestSuite

  1. Ensure that you have DRW running ../scripts/lrw.sh develop 8080
  2. Run the mw_drw proxy: DRW_URL_PREFIX=http://localhost:8080 MW_DRW_PROXY_PORT=3130 pipenv run python3 ./tests/mw_drw_proxy/proxy.py . There is additional documentation on this command in the tests/mw_drw_proxy folder.
  3. Run the test suite: pipenv run dmw -- test --verbose --target http://127.0.0.1:3130. To run a specific test, you can add --pytest-args '-ktest_payment_under_threshold_succeed[sender-999999]' to the test command

Git setup

It is recommended to install our git pre-commit hook. This hook runs all needed validations before committing:

$ ./scripts/install-git-hooks.sh

Feature Set

  • External transfer transaction without travel rule
  • Internal transfer transaction
  • Multi-currency accounts
  • User registration and login, including KYC flow
  • User account view with balances
  • List of user transaction
  • Cash in cash out flow (deposit and withdrawal)
  • Receiving address generation