Skip to content

Commit 604668d

Browse files
committed
accounts, build, mobile: revert remove Andriod and iOS support (ethereum#26599) / commit d9699c8
1 parent 4e3c849 commit 604668d

37 files changed

+4432
-2
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ eth/tracers/ @s1na
1313
graphql/ @gballet @s1na
1414
les/ @zsfelfoldi @rjl493456442
1515
light/ @zsfelfoldi @rjl493456442
16+
# ADDED by Jakub Pajek (revert mobile nuke)
17+
mobile/ @karalabe @ligi
1618
node/ @fjl
1719
p2p/ @fjl @zsfelfoldi
1820
rpc/ @fjl @holiman

.travis.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,77 @@ jobs:
120120
- go run build/ci.go install -dlgo -arch arm64 -cc aarch64-linux-gnu-gcc
121121
- go run build/ci.go archive -arch arm64 -type tar -signer LINUX_SIGNING_KEY -signify SIGNIFY_KEY -upload gethstore/builds
122122

123+
# ADDED by Jakub Pajek BEG (revert mobile nuke)
124+
# This builder does the Android Maven and Azure uploads
125+
- stage: build
126+
if: type = push
127+
os: linux
128+
dist: bionic
129+
addons:
130+
apt:
131+
packages:
132+
- openjdk-8-jdk
133+
env:
134+
- azure-android
135+
- maven-android
136+
- GO111MODULE=on
137+
git:
138+
submodules: false # avoid cloning ethereum/tests
139+
before_install:
140+
# Install Android and it's dependencies manually, Travis is stale
141+
- export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
142+
- curl https://dl.google.com/android/repository/commandlinetools-linux-6858069_latest.zip -o android.zip
143+
- unzip -q android.zip -d $HOME/sdk && rm android.zip
144+
- mv $HOME/sdk/cmdline-tools $HOME/sdk/latest && mkdir $HOME/sdk/cmdline-tools && mv $HOME/sdk/latest $HOME/sdk/cmdline-tools
145+
- export PATH=$PATH:$HOME/sdk/cmdline-tools/latest/bin
146+
- export ANDROID_HOME=$HOME/sdk
147+
148+
- yes | sdkmanager --licenses >/dev/null
149+
- sdkmanager "platform-tools" "platforms;android-15" "platforms;android-19" "platforms;android-24" "ndk-bundle"
150+
151+
# Install Go to allow building with
152+
- curl https://dl.google.com/go/go1.19.5.linux-amd64.tar.gz | tar -xz
153+
- export PATH=`pwd`/go/bin:$PATH
154+
- export GOROOT=`pwd`/go
155+
- export GOPATH=$HOME/go
156+
script:
157+
# Build the Android archive and upload it to Maven Central and Azure
158+
- mkdir -p $GOPATH/src/github.com/ethereum
159+
- ln -s `pwd` $GOPATH/src/github.com/ethereum/go-ethereum
160+
- go run build/ci.go aar -signer ANDROID_SIGNING_KEY -signify SIGNIFY_KEY -deploy https://oss.sonatype.org -upload gethstore/builds
161+
162+
# This builder does the OSX Azure, iOS CocoaPods and iOS Azure uploads
163+
- stage: build
164+
if: type = push
165+
os: osx
166+
go: 1.19.x
167+
env:
168+
- azure-osx
169+
- azure-ios
170+
- cocoapods-ios
171+
- GO111MODULE=on
172+
git:
173+
submodules: false # avoid cloning ethereum/tests
174+
script:
175+
- go run build/ci.go install -dlgo
176+
- go run build/ci.go archive -type tar -signer OSX_SIGNING_KEY -signify SIGNIFY_KEY -upload gethstore/builds
177+
178+
# Build the iOS framework and upload it to CocoaPods and Azure
179+
- gem uninstall cocoapods -a -x
180+
- gem install cocoapods
181+
182+
- mv ~/.cocoapods/repos/master ~/.cocoapods/repos/master.bak
183+
- sed -i '.bak' 's/repo.join/!repo.join/g' $(dirname `gem which cocoapods`)/cocoapods/sources_manager.rb
184+
- if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then git clone --depth=1 https://github.com/CocoaPods/Specs.git ~/.cocoapods/repos/master && pod setup --verbose; fi
185+
186+
- xctool -version
187+
- xcrun simctl list
188+
189+
# Workaround for https://github.com/golang/go/issues/23749
190+
- export CGO_CFLAGS_ALLOW='-fmodules|-fblocks|-fobjc-arc'
191+
- go run build/ci.go xcode -signer IOS_SIGNING_KEY -signify SIGNIFY_KEY -deploy trunk -upload gethstore/builds
192+
# ADDED by Jakub Pajek END (revert mobile nuke)
193+
123194
# These builders run the tests
124195
- stage: build
125196
os: linux

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ geth:
1616
all:
1717
$(GORUN) build/ci.go install
1818

19+
# ADDED by Jakub Pajek BEG (revert mobile nuke)
20+
android:
21+
$(GORUN) build/ci.go aar --local
22+
@echo "Done building."
23+
@echo "Import \"$(GOBIN)/geth.aar\" to use the library."
24+
@echo "Import \"$(GOBIN)/geth-sources.jar\" to add javadocs"
25+
@echo "For more info see https://stackoverflow.com/questions/20994336/android-studio-how-to-attach-javadoc"
26+
27+
ios:
28+
$(GORUN) build/ci.go xcode --local
29+
@echo "Done building."
30+
@echo "Import \"$(GOBIN)/Geth.framework\" to use the library."
31+
# ADDED by Jakub Pajek END (revert mobile nuke)
32+
1933
test: all
2034
$(GORUN) build/ci.go test
2135

accounts/abi/bind/bind.go

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package bind
2222

2323
import (
2424
"bytes"
25+
"errors"
2526
"fmt"
2627
"go/format"
2728
"regexp"
@@ -38,6 +39,10 @@ type Lang int
3839

3940
const (
4041
LangGo Lang = iota
42+
// ADDED by Jakub Pajek BEG (revert mobile nuke)
43+
LangJava
44+
LangObjC
45+
// ADDED by Jakub Pajek END (revert mobile nuke)
4146
)
4247

4348
func isKeyWord(arg string) bool {
@@ -218,6 +223,13 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
218223
if evmABI.HasReceive() {
219224
receive = &tmplMethod{Original: evmABI.Receive}
220225
}
226+
// ADDED by Jakub Pajek BEG (revert mobile nuke)
227+
// There is no easy way to pass arbitrary java objects to the Go side.
228+
if len(structs) > 0 && lang == LangJava {
229+
return "", errors.New("java binding for tuple arguments is not supported yet")
230+
}
231+
// ADDED by Jakub Pajek END (revert mobile nuke)
232+
221233
contracts[types[i]] = &tmplContract{
222234
Type: capitalise(types[i]),
223235
InputABI: strings.ReplaceAll(strippedABI, "\"", "\\\""),
@@ -291,6 +303,8 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
291303
// programming language types.
292304
var bindType = map[Lang]func(kind abi.Type, structs map[string]*tmplStruct) string{
293305
LangGo: bindTypeGo,
306+
// ADDED by Jakub Pajek (revert mobile nuke)
307+
LangJava: bindTypeJava,
294308
}
295309

296310
// bindBasicTypeGo converts basic solidity types(except array, slice and tuple) to Go ones.
@@ -333,10 +347,90 @@ func bindTypeGo(kind abi.Type, structs map[string]*tmplStruct) string {
333347
}
334348
}
335349

350+
// ADDED by Jakub Pajek (revert mobile nuke)
351+
// bindBasicTypeJava converts basic solidity types(except array, slice and tuple) to Java ones.
352+
func bindBasicTypeJava(kind abi.Type) string {
353+
switch kind.T {
354+
case abi.AddressTy:
355+
return "Address"
356+
case abi.IntTy, abi.UintTy:
357+
// Note that uint and int (without digits) are also matched,
358+
// these are size 256, and will translate to BigInt (the default).
359+
parts := regexp.MustCompile(`(u)?int([0-9]*)`).FindStringSubmatch(kind.String())
360+
if len(parts) != 3 {
361+
return kind.String()
362+
}
363+
// All unsigned integers should be translated to BigInt since gomobile doesn't
364+
// support them.
365+
if parts[1] == "u" {
366+
return "BigInt"
367+
}
368+
369+
namedSize := map[string]string{
370+
"8": "byte",
371+
"16": "short",
372+
"32": "int",
373+
"64": "long",
374+
}[parts[2]]
375+
376+
// default to BigInt
377+
if namedSize == "" {
378+
namedSize = "BigInt"
379+
}
380+
return namedSize
381+
case abi.FixedBytesTy, abi.BytesTy:
382+
return "byte[]"
383+
case abi.BoolTy:
384+
return "boolean"
385+
case abi.StringTy:
386+
return "String"
387+
case abi.FunctionTy:
388+
return "byte[24]"
389+
default:
390+
return kind.String()
391+
}
392+
}
393+
394+
// ADDED by Jakub Pajek (revert mobile nuke)
395+
// pluralizeJavaType explicitly converts multidimensional types to predefined
396+
// types in go side.
397+
func pluralizeJavaType(typ string) string {
398+
switch typ {
399+
case "boolean":
400+
return "Bools"
401+
case "String":
402+
return "Strings"
403+
case "Address":
404+
return "Addresses"
405+
case "byte[]":
406+
return "Binaries"
407+
case "BigInt":
408+
return "BigInts"
409+
}
410+
return typ + "[]"
411+
}
412+
413+
// ADDED by Jakub Pajek (revert mobile nuke)
414+
// bindTypeJava converts a Solidity type to a Java one. Since there is no clear mapping
415+
// from all Solidity types to Java ones (e.g. uint17), those that cannot be exactly
416+
// mapped will use an upscaled type (e.g. BigDecimal).
417+
func bindTypeJava(kind abi.Type, structs map[string]*tmplStruct) string {
418+
switch kind.T {
419+
case abi.TupleTy:
420+
return structs[kind.TupleRawName+kind.String()].Name
421+
case abi.ArrayTy, abi.SliceTy:
422+
return pluralizeJavaType(bindTypeJava(*kind.Elem, structs))
423+
default:
424+
return bindBasicTypeJava(kind)
425+
}
426+
}
427+
336428
// bindTopicType is a set of type binders that convert Solidity types to some
337429
// supported programming language topic types.
338430
var bindTopicType = map[Lang]func(kind abi.Type, structs map[string]*tmplStruct) string{
339431
LangGo: bindTopicTypeGo,
432+
// ADDED by Jakub Pajek (revert mobile nuke)
433+
LangJava: bindTopicTypeJava,
340434
}
341435

342436
// bindTopicTypeGo converts a Solidity topic type to a Go one. It is almost the same
@@ -356,10 +450,30 @@ func bindTopicTypeGo(kind abi.Type, structs map[string]*tmplStruct) string {
356450
return bound
357451
}
358452

453+
// ADDED by Jakub Pajek (revert mobile nuke)
454+
// bindTopicTypeJava converts a Solidity topic type to a Java one. It is almost the same
455+
// functionality as for simple types, but dynamic types get converted to hashes.
456+
func bindTopicTypeJava(kind abi.Type, structs map[string]*tmplStruct) string {
457+
bound := bindTypeJava(kind, structs)
458+
459+
// todo(rjl493456442) according solidity documentation, indexed event
460+
// parameters that are not value types i.e. arrays and structs are not
461+
// stored directly but instead a keccak256-hash of an encoding is stored.
462+
//
463+
// We only convert strings and bytes to hash, still need to deal with
464+
// array(both fixed-size and dynamic-size) and struct.
465+
if bound == "String" || bound == "byte[]" {
466+
bound = "Hash"
467+
}
468+
return bound
469+
}
470+
359471
// bindStructType is a set of type binders that convert Solidity tuple types to some supported
360472
// programming language struct definition.
361473
var bindStructType = map[Lang]func(kind abi.Type, structs map[string]*tmplStruct) string{
362474
LangGo: bindStructTypeGo,
475+
// ADDED by Jakub Pajek (revert mobile nuke)
476+
LangJava: bindStructTypeJava,
363477
}
364478

365479
// bindStructTypeGo converts a Solidity tuple type to a Go one and records the mapping
@@ -408,10 +522,77 @@ func bindStructTypeGo(kind abi.Type, structs map[string]*tmplStruct) string {
408522
}
409523
}
410524

525+
// ADDED by Jakub Pajek (revert mobile nuke)
526+
// bindStructTypeJava converts a Solidity tuple type to a Java one and records the mapping
527+
// in the given map.
528+
// Notably, this function will resolve and record nested struct recursively.
529+
func bindStructTypeJava(kind abi.Type, structs map[string]*tmplStruct) string {
530+
switch kind.T {
531+
case abi.TupleTy:
532+
// We compose a raw struct name and a canonical parameter expression
533+
// together here. The reason is before solidity v0.5.11, kind.TupleRawName
534+
// is empty, so we use canonical parameter expression to distinguish
535+
// different struct definition. From the consideration of backward
536+
// compatibility, we concat these two together so that if kind.TupleRawName
537+
// is not empty, it can have unique id.
538+
id := kind.TupleRawName + kind.String()
539+
if s, exist := structs[id]; exist {
540+
return s.Name
541+
}
542+
var fields []*tmplField
543+
for i, elem := range kind.TupleElems {
544+
field := bindStructTypeJava(*elem, structs)
545+
fields = append(fields, &tmplField{Type: field, Name: decapitalise(kind.TupleRawNames[i]), SolKind: *elem})
546+
}
547+
name := kind.TupleRawName
548+
if name == "" {
549+
name = fmt.Sprintf("Class%d", len(structs))
550+
}
551+
structs[id] = &tmplStruct{
552+
Name: name,
553+
Fields: fields,
554+
}
555+
return name
556+
case abi.ArrayTy, abi.SliceTy:
557+
return pluralizeJavaType(bindStructTypeJava(*kind.Elem, structs))
558+
default:
559+
return bindBasicTypeJava(kind)
560+
}
561+
}
562+
411563
// namedType is a set of functions that transform language specific types to
412564
// named versions that may be used inside method names.
413565
var namedType = map[Lang]func(string, abi.Type) string{
414566
LangGo: func(string, abi.Type) string { panic("this shouldn't be needed") },
567+
// ADDED by Jakub Pajek (revert mobile nuke)
568+
LangJava: namedTypeJava,
569+
}
570+
571+
// ADDED by Jakub Pajek (revert mobile nuke)
572+
// namedTypeJava converts some primitive data types to named variants that can
573+
// be used as parts of method names.
574+
func namedTypeJava(javaKind string, solKind abi.Type) string {
575+
switch javaKind {
576+
case "byte[]":
577+
return "Binary"
578+
case "boolean":
579+
return "Bool"
580+
default:
581+
parts := regexp.MustCompile(`(u)?int([0-9]*)(\[[0-9]*\])?`).FindStringSubmatch(solKind.String())
582+
if len(parts) != 4 {
583+
return javaKind
584+
}
585+
switch parts[2] {
586+
case "8", "16", "32", "64":
587+
if parts[3] == "" {
588+
return capitalise(fmt.Sprintf("%sint%s", parts[1], parts[2]))
589+
}
590+
return capitalise(fmt.Sprintf("%sint%ss", parts[1], parts[2]))
591+
592+
default:
593+
return javaKind
594+
}
595+
}
415596
}
416597

417598
// alias returns an alias of the given string based on the aliasing rules
@@ -427,6 +608,8 @@ func alias(aliases map[string]string, n string) string {
427608
// conform to target language naming conventions.
428609
var methodNormalizer = map[Lang]func(string) string{
429610
LangGo: abi.ToCamelCase,
611+
// ADDED by Jakub Pajek (revert mobile nuke)
612+
LangJava: decapitalise,
430613
}
431614

432615
// capitalise makes a camel-case string which starts with an upper case character.

0 commit comments

Comments
 (0)