Giter VIP home page Giter VIP logo

perun-eth-mobile's Introduction

Perun mobile bindings

This project provides Android bindings for go-perun called prnm.
Right now, it supports two-party single-asset ledger payment channels.

Security Disclaimer

The authors take no responsibility for any loss of digital assets or other damage caused by the use of this software.
Do not use this software with real funds.

Getting Started

# Install gomobile, see https://godoc.org/golang.org/x/mobile/cmd/gomobile
go get golang.org/x/mobile/cmd/gomobile
gomobile init
# Get perun-eth-mobile
git clone https://github.com/perun-network/perun-eth-mobile
# Generate the bindings
cd perun-eth-mobile
gomobile bind -o android/app/prnm.aar -target=android

👉 More in-depth instructions can be found in DEVELOPING.md.

Structure

The android/ folder is an Android Studio Project, the only two important files are:

  • android/app/src/main/java/network/perun/app/MainActivity.java contains the Apps logic, exemplifying the use of go-perun.
    The MainActivity uses a Node to propose and accept payment channels. The Node is started with a prnm.Config which contains all needed configuration for the underlying prnm.Client. Its contructor creates a ProposalHandler that accepts all incomming channel proposals and forwards the new channels to Node.accept. Node.accept then starts two threads; one with an UpdateHandler that accepts all updates and one as on-chain watcher that reacts to disputes and settling. To propose a channel, Node.propose can be used.
  • android/app/src/main/AndroidManifest.xml lists the needed App permissions; INTERNET,ACCESS_NETWORK_STATE,WRITE_EXTERNAL_STORAGE,READ_EXTERNAL_STORAGE

After importing the android/ folder in Android Studio, run it in the Emulator or on a real phone.
The opposite party can be either also an App, or a perun-eth-demo-node.

Copyright

Copyright © 2020 Chair of Applied Cryptography, Technische Universität Darmstadt, Germany. All rights reserved. Use of the source code is governed by the Apache 2.0 license that can be found in the LICENSE file.

Contact us at [email protected].

perun-eth-mobile's People

Contributors

cryptphil avatar ggwpez avatar niiigoo avatar sebastianst avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

anquuni cryptphil

perun-eth-mobile's Issues

HappyAliceBob Java CI test

Build a CI test analogous to our HappyAliceBob test in go-perun.
Steps:

  • Write a HappyAliceBob test in Java
  • Start Ganache chain
  • Create prnm.aar bindings
  • Start two Android Emulators and run the test

We could also use one demo-node and one Android Emulator instead…

Validate ETH contracts

Validate the Adjudicator and Assetholder addresses in the client.setupContracts function when they are given.
Return the error from ValidateAssetHolderETH or ValidateAdjudicator otherwise.

Add Java sample code

Add Java example code on how to use prnm. In the best case it would be a complete Android Studio project that can be imported and tested easily.

Scope:

  • Wallet import+create Account
  • Contract set+deploy
  • Context cancelling
  • Channel open+settle+send+close
  • ProposalHandler
  • UpdateHandler
  • Watcher
  • App permissions
  • Project file

Update to go-perun 0.6.0 (Fenrir)

Use the go-perun CHANGELOG and the demo as help to find all necessary changes.
The java example should also be updated. We currently have a draft for CI tests in #23 but it is not final yet. I would then manually check this MR with the test.

Add means to deploy contracts

The user of prnm needs means to deploy the ETHAssetHolder and Adjudicator contracts. It is probably easiest to directly add methods for deploying them to the Client type (together with Address setters).

What do you think @ggwpez?

OnChainBalance

Create a function OnChainBalance(*Context, *Address) (*BigInt, error) that returns the on-chain ethereum balance for the given address in wei. See perun-eth-demo#7 for hints.

Charon update

We should update the mobile wrapper's go-perun to Charon.

This implies several changes/additions

  • Expose OnNewChannel callback registration. Document that starting of watcher should happen here, if wanted.
  • Change to and expose new common handler routine Client.Handle.
  • Add an optional dbpath section to the configuration. If set, use it to enable leveldb persistence.
  • Expose Client.Reconnect(*Context) method. Note that the OnNewChannel callback has to be set before restoring of channels from persistence happens, or persisted channels go unnoticed and are only pollable through Client.Channel.
  • Apply all changes to the Java example.

Add Go test CI

We should write a Go test (TestClient) for the prnm package:

First we need to setup a CI config

  • with a container where golang and nodejs are available,
  • caching of go and node packages
  • installation of ganache-cli at the beginning

Then the test itself

  1. Create two fixed configurations for two test roles Alice and Bob (either as (alice|bob).json in directory testdata using Go's native JSON unmarshaling, or as fixed vars of type *Config).
  2. Start a ganache-cli with os.Exec and a fixed mnemonic (-m).
  • Set alice's and bob's account in 1. to two accounts from the ones being created with this mnemonic. (only needs to be done once while doing this)
  • parse the output of this os.Exec until the test blockchain is setup
  1. Start two go routines for alice and bob (see also go-perun's client/happy_test.go)
  • both create client from config
  • one of them deploys the contracts
  • alice adds bob as a remote peer (AddPeer)
  • alice proposes a channel to bob
  • bob accepts
  • both send TXs back and forth
  • one sends a finalization request
  • both settle the channel
  • channel and client are Close()d.
  1. Perform balance assertions, similar to happy_test.go.

Upgrade to Despina

We did a big refactor in go-perun and moved connection handling out of the client.Client into a wire/net.Bus. The tcp/unix dialer and listener implementations were moved into wire/net/simple. This repo should be updated:

  • Inside prnm.NewClient, before creating the client, create a net.Bus with a tcp dialer and listener.
  • Start Listening with the net.Bus, not with the client.
  • Pass this bus to the client's constructor instead of a tcp dialer and listener, which were given to the bus before.
  • Client.Reconnect was renamed to Restore and the meaning of this method changed. Please also rename the method of the prnm client wrapper.
  • Remove prnm.Channel.Close

Maybe I forgot something, but this should become apparent while testing.

Function for creating accounts in wallets

We discussed to create a new function

prnm.CreateAccount(walletPath, passphrase string) (account string, err error)

that opens or creates a wallet path and then generates a new account in it and returns its address.

Originally posted by @sebastianst in #1

Work-around for go >= 1.16

Problem

The installation instructions for go-mobile do not work anymore with the specified minimum version of 1.16:

go install golang.org/x/mobile/cmd/gomobile@latest
gomobile init

This line seems to be responsible for the error:

go: downloading golang.org/x/mobile v0.0.0-20211103151657-e68c98865fb2
go: downloading golang.org/x/mod v0.4.2
go: downloading golang.org/x/tools v0.1.8-0.20211022200916-316ba0b74098
go: downloading golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
go: downloading golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e
gomobile: go install golang.org/x/mobile/cmd/gobind failed: exit status 1
go install: version is required when current directory is not in a module
	Try 'go install golang.org/x/mobile/cmd/gobind@latest' to install the latest version

My current work-around is to run:

go mod init example.com/m
go mod tidy
GO111MODULE=on  go get golang.org/x/mobile/cmd/...
GO111MODULE=on  go mod download golang.org/x/exp
GO111MODULE=off go get -d golang.org/x/mobile/cmd/gobind
gomobile init 

And then go mod download golang.org/x/mobile in the docker image before building the bindings.
However, this does not work anymore in go 1.17 🤡.

We can hopefully remove this when golang/go#46943 is fixed.
I will not open a MR on x/mobile because of the tedious dev process for external contributors.

Test MainActivity functionality

The MainActivity.java contains a working example on how to use the mobile API.
The code is currently untested. CI testing would be nice to have.

🐛 Cancelled context after funding success

PS: I just realized the demo and prnm dont use the same go-perun version, so that could be it.
  Lets keep it open until i verify that.

I sometimes get the following error when using the code from the README.
Quite weird since both funding events are registered and afterwards there is an error reported.
Not sure what it means so Im just recording it here:

trace msg=Registry.Get id=0x05e71027e7d3bd6261de7634cf50F0e2142067C4 peer=0xA298Fc05bccff341f340a11FffA30567a00e651f
trace msg="Registry.Get: peer not found, dialing..." id=0x05e71027e7d3bd6261de7634cf50F0e2142067C4 peer=0xA298Fc05bccff341f340a11FffA30567a00e651f
trace msg=Registry.addPeer id=0x05e71027e7d3bd6261de7634cf50F0e2142067C4 peer=0xA298Fc05bccff341f340a11FffA30567a00e651f
debug msg="setting up default subscriptions" id=0x05e71027e7d3bd6261de7634cf50F0e2142067C4 peer=0xA298Fc05bccff341f340a11FffA30567a00e651f
trace msg=Registry.Get id=0x05e71027e7d3bd6261de7634cf50F0e2142067C4 peer=0xA298Fc05bccff341f340a11FffA30567a00e651f
trace msg="Registry.Get: peer found, waiting for conn..." id=0x05e71027e7d3bd6261de7634cf50F0e2142067C4 peer=0xA298Fc05bccff341f340a11FffA30567a00e651f
trace msg="Registry.Get: peer connection established" id=0x05e71027e7d3bd6261de7634cf50F0e2142067C4 peer=0xA298Fc05bccff341f340a11FffA30567a00e651f
trace msg="phase transition: InitActing->InitSigning" ID=241abcaf1def9b25dd02149acc9b8ad94857553cd785796d92be2a5135568d40
trace msg="phase transition: InitSigning->Funding" ID=241abcaf1def9b25dd02149acc9b8ad94857553cd785796d92be2a5135568d40
debug msg="Funding Channel." account=0x05e71027e7d3bd6261de7634cf50F0e2142067C4 channel=241abcaf1def9b25dd02149acc9b8ad94857553cd785796d92be2a5135568d40
debug msg="peer[0] Received event with amount 1000" account=0x05e71027e7d3bd6261de7634cf50F0e2142067C4 fundingID=f876f6d843d603bce6e6e8c4bbfeb3fa534c12b3b4f3e078d0d729c61bacee98
debug msg="Deposited event received for asset 0 and participant 1" account=0x05e71027e7d3bd6261de7634cf50F0e2142067C4 fundingID=f876f6d843d603bce6e6e8c4bbfeb3fa534c12b3b4f3e078d0d729c61bacee98
debug msg="peer[0] Created funding transaction with txHash: 0xe7771f5e75b6095a71a34eafc719365cdae633ae6cdb36a7fb3d3aead61c282e, amount 2000" account=0x05e71027e7d3bd6261de7634cf50F0e2142067C4
debug msg="peer[0] Received event with amount 2000" account=0x05e71027e7d3bd6261de7634cf50F0e2142067C4 fundingID=7ac77048187db19ed7d5f0045261aad3af08555032e8a7981f4b1e00f3f74a91
debug msg="Deposited event received for asset 0 and participant 0" account=0x05e71027e7d3bd6261de7634cf50F0e2142067C4 fundingID=7ac77048187db19ed7d5f0045261aad3af08555032e8a7981f4b1e00f3f74a91
E/err----: go.Universe$proxyerror: error while funding channel: fund asset: sending funding tx: mining transaction: sending transaction: context canceled
warning msg="error while funding channel: fund asset: sending funding tx: mining transaction: sending transaction: context canceled" channel=241abcaf1def9b25dd02149acc9b8ad94857553cd785796d92be2a5135568d40 id=0x05e71027e7d3bd6261de7634cf50F0e2142067C4

The other party (demo node) looks fine:

DEBU[0004] Registry.Listen: setting up incoming connection  id=0xA298Fc05bccff341f340a11FffA30567a00e651f
TRAC[0004] Registry.addPeer                              id=0xA298Fc05bccff341f340a11FffA30567a00e651f peer=0x05e71027e7d3bd6261de7634cf50F0e2142067C4
DEBU[0004] setting up default subscriptions              id=0xA298Fc05bccff341f340a11FffA30567a00e651f peer=0x05e71027e7d3bd6261de7634cf50F0e2142067C4
TRAC[0004] calling proposal handler                      id=0xA298Fc05bccff341f340a11FffA30567a00e651f peer=0x05e71027e7d3bd6261de7634cf50F0e2142067C4
DEBU[0004] Received channel propsal                     
DEBU[0004] New peer                                      alias=bob id=0x05e71027e7d3bd6261de7634cf50F0e2142067C4
DEBU[0004] Channel propsal                               from=0x05e71027e7d3bd6261de7634cf50F0e2142067C4
TRAC[0004] Registry.Get                                  id=0xA298Fc05bccff341f340a11FffA30567a00e651f peer=0x05e71027e7d3bd6261de7634cf50F0e2142067C4
TRAC[0004] Registry.Get: peer found, waiting for conn...  id=0xA298Fc05bccff341f340a11FffA30567a00e651f peer=0x05e71027e7d3bd6261de7634cf50F0e2142067C4
TRAC[0004] Registry.Get: peer connection established     id=0xA298Fc05bccff341f340a11FffA30567a00e651f peer=0x05e71027e7d3bd6261de7634cf50F0e2142067C4
TRAC[0004] phase transition: InitActing->InitSigning     ID=241abcaf1def9b25dd02149acc9b8ad94857553cd785796d92be2a5135568d40
TRAC[0004] phase transition: InitSigning->Funding        ID=241abcaf1def9b25dd02149acc9b8ad94857553cd785796d92be2a5135568d40
DEBU[0004] Funding Channel.                              account=0xA298Fc05bccff341f340a11FffA30567a00e651f channel=241abcaf1def9b25dd02149acc9b8ad94857553cd785796d92be2a5135568d40
DEBU[0005] peer[1] Created funding transaction with txHash: 0x654347f761aea0be633eec8f9fc4b2129b08a113c8e1efb1271061944bb864af, amount 1000  account=0xA298Fc05bccff341f340a11FffA30567a00e651f
DEBU[0005] peer[1] Received event with amount 1000       account=0xA298Fc05bccff341f340a11FffA30567a00e651f fundingID=f876f6d843d603bce6e6e8c4bbfeb3fa534c12b3b4f3e078d0d729c61bacee98
DEBU[0005] Deposited event received for asset 0 and participant 1  account=0xA298Fc05bccff341f340a11FffA30567a00e651f fundingID=f876f6d843d603bce6e6e8c4bbfeb3fa534c12b3b4f3e078d0d729c61bacee98
DEBU[0005] peer[1] Received event with amount 2000       account=0xA298Fc05bccff341f340a11FffA30567a00e651f fundingID=7ac77048187db19ed7d5f0045261aad3af08555032e8a7981f4b1e00f3f74a91
DEBU[0005] Deposited event received for asset 0 and participant 0  account=0xA298Fc05bccff341f340a11FffA30567a00e651f fundingID=7ac77048187db19ed7d5f0045261aad3af08555032e8a7981f4b1e00f3f74a91
DEBU[0005] peer[1] Transaction with txHash: [0x654347f761aea0be633eec8f9fc4b2129b08a113c8e1efb1271061944bb864af] executed successful  account=0xA298Fc05bccff341f340a11FffA30567a00e651f
TRAC[0005] phase transition: Funding->Acting             ID=241abcaf1def9b25dd02149acc9b8ad94857553cd785796d92be2a5135568d40
🆕 Channel opened with bob  initial balance: [2000 1000]
DEBU[0005] Listening for channel updates                 channel=241abcaf1def9b25dd02149acc9b8ad94857553cd785796d92be2a5135568d40

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.