Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial gomobile support #1164

Merged
merged 71 commits into from
Feb 1, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
7a05ce6
Add drop-in lib package for usage with gomobile
divan Aug 22, 2018
94b9880
Update Makefile to use gomobile
divan Aug 22, 2018
041990b
Add README to mobile
divan Aug 22, 2018
f2610b5
Merge branch 'develop' into gomobile
divan Oct 27, 2018
6fa22db
Fix library API
divan Oct 31, 2018
b178f25
clean up Makefile
adambabik Nov 26, 2018
0718c78
Merge branch 'develop' into gomobile
adambabik Nov 26, 2018
606ddfd
update missing exports
adambabik Nov 26, 2018
a628bd2
clean up
adambabik Nov 26, 2018
6e217ef
prepare Jenkinsfile
adambabik Nov 26, 2018
43d965e
fix Jenkinsfile
adambabik Nov 26, 2018
6c68d39
add steps
adambabik Nov 26, 2018
c4063f0
try now
adambabik Nov 26, 2018
55a28cb
fix parentheses
adambabik Nov 26, 2018
9d76ebe
fix location of envrionment section
jakubgs Nov 26, 2018
275d35d
split setup
adambabik Nov 26, 2018
1c6a332
skip TestGetFilterLogs
adambabik Nov 26, 2018
7dc20ae
disable USB detection
adambabik Nov 26, 2018
4cb9885
run gomobile-install in setup-build
adambabik Nov 26, 2018
719711e
add NoUSB in all places
adambabik Nov 26, 2018
0f55f56
set ANDROID_* envs
adambabik Nov 26, 2018
4105b09
Merge branch 'develop' into gomobile
adambabik Nov 26, 2018
af58279
Merge branch 'develop' into gomobile
adambabik Nov 28, 2018
0b92aa6
use ios/arm64 target for ios
adambabik Nov 28, 2018
8177afa
rename package from `status` to `statusgo` to generate the iOS framew…
mandrigin Dec 4, 2018
145192d
fixup for iOS signals compiling
mandrigin Dec 4, 2018
103eb85
fix ios target
adambabik Dec 4, 2018
648ba84
use Go code to propagate signals on mobile
mandrigin Dec 4, 2018
2f65110
clean up most of the C magic of signals package (only leftovers for D…
mandrigin Dec 4, 2018
5866167
fix target for android
adambabik Dec 5, 2018
71669fe
Merge remote-tracking branch 'origin/develop' into gomobile
adambabik Dec 5, 2018
ff42934
move comment
adambabik Dec 5, 2018
3bccb96
make NofifyUsers work again (after rebase)
mandrigin Dec 5, 2018
441bd5a
Notify user when the device is missing (#1298)
cammellos Dec 5, 2018
bf2c932
Mail peer store and connection manager (#1295)
dshulyak Dec 5, 2018
523d38b
delete Jenkinsfile-manual
adambabik Dec 6, 2018
a433f7a
Merge branch 'develop' into gomobile
adambabik Jan 3, 2019
a56a3a1
add fixes after rebase
adambabik Jan 3, 2019
1524e29
fix Desktop stage in Jenkinsfile
adambabik Jan 3, 2019
57493f4
fix Desktop archive in Jenkinsfile
adambabik Jan 3, 2019
6c8ac96
fix status.go
adambabik Jan 3, 2019
2b52042
Merge branch 'develop' into gomobile
adambabik Jan 10, 2019
7577690
Merge branch 'develop' into gomobile
adambabik Jan 24, 2019
e6452b4
fix mobile bindings
adambabik Jan 24, 2019
f4e64c0
Use custom NDK for building gomobile.
mandrigin Jan 30, 2019
7614f89
(to be reverted) disable canary test
mandrigin Jan 30, 2019
cd5f884
(to be reverted) only build mobile release on MacOS
mandrigin Jan 30, 2019
0468ac3
Revert "(to be reverted) only build mobile release on MacOS"
mandrigin Jan 30, 2019
ed70137
fix packages folder conflict in Jenkinsfile
mandrigin Jan 31, 2019
8f142b9
one more attempted fixup for Jenkinsfile
mandrigin Jan 31, 2019
e7580e5
update version (`g` means `gomobile`, update major because backward c…
mandrigin Jan 31, 2019
12f459b
use stash/unstash to release at the end
jakubgs Jan 31, 2019
63ad571
Fix how we stash Statusgo.framework
mandrigin Feb 1, 2019
44e373a
Tweak "Release" phase.
mandrigin Feb 1, 2019
09c9025
fix syntax error in Jenkinsfile (eeh)
mandrigin Feb 1, 2019
3553a48
one more syntax fixup
mandrigin Feb 1, 2019
0e0f7f4
:(
mandrigin Feb 1, 2019
bd32400
add debug output
mandrigin Feb 1, 2019
0e2aeba
add cleanup code
mandrigin Feb 1, 2019
820e398
fix dir path
mandrigin Feb 1, 2019
c787063
make Android stash look more like iOS
mandrigin Feb 1, 2019
bd8285d
Clean-up after yourself.
mandrigin Feb 1, 2019
ae68018
more debug output
mandrigin Feb 1, 2019
a0141f6
even more debug info
mandrigin Feb 1, 2019
e1fb48e
add more debug info
mandrigin Feb 1, 2019
a88795b
try not to clean-up files after stashing
mandrigin Feb 1, 2019
3395494
Merge branch 'develop' into gomobile
mandrigin Feb 1, 2019
4a5ef3a
Add `UpdateMailservers` to gomobile exports.
mandrigin Feb 1, 2019
1fa9103
split builds into separate Jenkinsfiles
jakubgs Feb 1, 2019
5634b92
Merge remote-tracking branch 'origin/gomobile-split' into gomobile
mandrigin Feb 1, 2019
47557cd
bump version to .1
mandrigin Feb 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: statusgo statusd-prune all test xgo clean help
.PHONY: statusgo statusd-prune all test xgo gomobile clean help
.PHONY: statusgo-android statusgo-ios

help: ##@other Show this help
Expand Down Expand Up @@ -101,24 +101,17 @@ statusgo-linux: xgo ##@cross-compile Build status-go for Linux
./_assets/patches/patcher -b . -p geth-xgo -r
@echo "Android cross compilation done."

statusgo-android: xgo ##@cross-compile Build status-go for Android
./_assets/patches/patcher -b . -p geth-xgo
$(GOPATH)/bin/xgo --image $(XGOIMAGE) --go=$(GO) -out statusgo --dest=$(GOBIN) --targets=android-16/aar -v -tags '$(BUILD_TAGS)' $(BUILD_FLAGS) ./lib
./_assets/patches/patcher -b . -p geth-xgo -r
@echo "Android cross compilation done."
## TODO(divan): rename statusgo-android-16.aar to Statusgo.aar
statusgo-android: gomobile ##@cross-compile Build status-go for Android
@echo "Building status-go for Android..."
@gomobile bind -target=android/arm -ldflags="-s -w" -o build/bin/statusgo-android-16.aar github.com/status-im/status-go/mobile
@echo "Android cross compilation done in build/bin/statusgo-android-16.aar"

statusgo-ios: xgo ##@cross-compile Build status-go for iOS
./_assets/patches/patcher -b . -p geth-xgo
$(GOPATH)/bin/xgo --image $(XGOIMAGE) --go=$(GO) -out statusgo --dest=$(GOBIN) --targets=ios-9.3/framework -v -tags '$(BUILD_TAGS)' $(BUILD_FLAGS) ./lib
./_assets/patches/patcher -b . -p geth-xgo -r
@echo "iOS framework cross compilation done."

statusgo-ios-simulator: xgo ##@cross-compile Build status-go for iOS Simulator
@docker pull $(XGOIMAGEIOSSIM)
./_assets/patches/patcher -b . -p geth-xgo
$(GOPATH)/bin/xgo --image $(XGOIMAGEIOSSIM) --go=$(GO) -out statusgo --dest=$(GOBIN) --targets=ios-9.3/framework -v -tags '$(BUILD_TAGS)' $(BUILD_FLAGS) ./lib
./_assets/patches/patcher -b . -p geth-xgo -r
@echo "iOS framework cross compilation done."
## TODO(divan): rename statusgo-ios-9.3-framework to Statusgo.framework/
statusgo-ios: gomobile ##@cross-compile Build status-go for iOS
@echo "Building status-go for iOS..."
@gomobile bind -target=ios -ldflags="-s -w" -o build/bin/statusgo-ios-9.3-framework github.com/status-im/status-go/mobile
@echo "iOS framework cross compilation done in build/bin/statusgo-ios-9.3-framework"

statusgo-library: ##@cross-compile Build status-go as static library for current platform
@echo "Building static library..."
Expand Down Expand Up @@ -171,7 +164,11 @@ xgo:
docker pull $(XGOIMAGE)
go get github.com/karalabe/xgo

setup: dep-install lint-install mock-install ##@other Prepare project for first build
gomobile:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gomobile-install?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense, thanks!

@echo "Installing gomobile..."
@go get -u golang.org/x/mobile/cmd/gomobile

setup: dep-install lint-install mock-install gomobile ##@other Prepare project for first build

mock-install: ##@other Install mocking tools
go get -u github.com/golang/mock/mockgen
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ There are two main modes status-go can be built:
Use following Makefile commands:

- `make statusgo` (builds binary into `build/bin/statusd`)
- `make statusgo-android` (builds .aar file `build/android-16/aar`)
- `make statusgo-ios` and `make statusgo-ios-simulator` (builds iOS related artifacts in `build/os-9.3/framework`)
- `make statusgo-android` (builds .aar file `build/bin/statusgo-android-16.aar`)
- `make statusgo-ios` (builds iOS framework in `build/bin/statusgo-ios-9.3-framework`)

In order to build and use `status-go` directly from `status-react`, follow the instructions in https://wiki.status.im/Building_Status, under the '**Building Status with the checked-out version of status-go**' section.

Expand Down
27 changes: 27 additions & 0 deletions mobile/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Mobile

Package mobile implements [gomobile](https://github.com/golang/mobile) bindings for status-go. Current implementation servers as a drop-in replacement for `lib` package.

# Usage

For properly using this package, please refer to Makefile in the root of `status-go` directory.

To manually build library, run following commands:

### iOS

```
gomobile bind -v -target=ios -ldflags="-s -w" github.com/status-im/status-go/mobile
```
This will produce `Status.framework` file in the current directory, which can be used in iOS project.

### Android

```
gomobile bind -v -target=android -ldflags="-s -w" github.com/status-im/status-go/mobile
```
This will generate `Status.aar` file in the current dir.

# Notes

See [https://github.com/golang/go/wiki/Mobile](https://github.com/golang/go/wiki/Mobile) for more information on `gomobile` usage.
64 changes: 64 additions & 0 deletions mobile/response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package status
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can either move it to types.go or change it to jsonrpc_response.go.

It's an issue that we have so many response types but this one was introduced for bindings that are meant to replace JSON-RPC calls. In status-react, commands like eth_sendTransaction are intercepted and a binding is called instead. Thanks to this type of response, the response can be easily returned without further processing.


import (
"encoding/json"

"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/status-im/status-go/account"
"github.com/status-im/status-go/transactions"
)

const (
codeUnknown int = iota
// special codes
codeFailedParseResponse
codeFailedParseParams
// account related codes
codeErrNoAccountSelected
codeErrInvalidTxSender
codeErrDecrypt
)

var errToCodeMap = map[error]int{
account.ErrNoAccountSelected: codeErrNoAccountSelected,
transactions.ErrInvalidTxSender: codeErrInvalidTxSender,
keystore.ErrDecrypt: codeErrDecrypt,
}

type jsonrpcSuccessfulResponse struct {
Result interface{} `json:"result"`
}

type jsonrpcErrorResponse struct {
Error jsonError `json:"error"`
}

type jsonError struct {
Code int `json:"code,omitempty"`
Message string `json:"message"`
}

func prepareJSONResponse(result interface{}, err error) string {
code := codeUnknown
if c, ok := errToCodeMap[err]; ok {
code = c
}

return prepareJSONResponseWithCode(result, err, code)
}

func prepareJSONResponseWithCode(result interface{}, err error, code int) string {
if err != nil {
errResponse := jsonrpcErrorResponse{
Error: jsonError{Code: code, Message: err.Error()},
}
response, _ := json.Marshal(&errResponse)
return string(response)
}

data, err := json.Marshal(jsonrpcSuccessfulResponse{result})
if err != nil {
return prepareJSONResponseWithCode(nil, err, codeFailedParseResponse)
}
return string(data)
}
27 changes: 27 additions & 0 deletions mobile/response_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package status

import (
"errors"
"testing"

"github.com/stretchr/testify/require"
)

type nonJSON struct{}

func (*nonJSON) MarshalJSON() ([]byte, error) {
return nil, errors.New("invalid JSON")
}

func TestPrepareJSONResponseErrorWithResult(t *testing.T) {
data := prepareJSONResponse("0x123", nil)
require.Equal(t, `{"result":"0x123"}`, data)

data = prepareJSONResponse(&nonJSON{}, nil)
require.Contains(t, data, `{"error":{"code":1,"message":`)
}

func TestPrepareJSONResponseErrorWithError(t *testing.T) {
data := prepareJSONResponse("0x123", errors.New("some error"))
require.Contains(t, data, `{"error":{"message":"some error"}}`)
}
Loading