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

[mobile] Mobile RPCs #3282

Merged
merged 9 commits into from Sep 9, 2019
Merged

[mobile] Mobile RPCs #3282

merged 9 commits into from Sep 9, 2019

Conversation

@halseth
Copy link
Collaborator

@halseth halseth commented Jul 9, 2019

This PR adds the necessary APIs and build scripts in order to compile lnd for mobile platforms.

Building mobile libraries

Prerequisites

gomobile

Follow gomobile in order to intall gomobile and dependencies.

Remember to run gomobile init! (otherwise the lnd build might just hang).

falafel

Install falafel:

go get -u -v github.com/halseth/falafel

Building lnd for iOS

make ios

Building lnd for Android

make android

make mobile will build both iOS and Android libs.

Libraries

After the build has succeeded, the libraries will be found in mobile/build/ios/Lndmobile.framework and mobile/build/android/Lndmobile.aar. Reference your platforms' SDK documentation for how to add the library to your project.

API docs

TODO

@cfromknecht cfromknecht self-requested a review Jul 9, 2019
func Start(extraArgs string, callback Callback) {
// Add the extra arguments to os.Args, as that will be parsed during
// startup.
os.Args = append(os.Args, strings.Fields(extraArgs)...)
Copy link
Contributor

@ottosuess ottosuess Jul 10, 2019

Choose a reason for hiding this comment

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

splitting the extraArgs string breaks if I want to pass a path that contains a space.
e.g. /Library/Application\ Support

Loading

Copy link
Collaborator Author

@halseth halseth Jul 19, 2019

Choose a reason for hiding this comment

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

Can you check if this helps: 22f7b0c

Loading

Copy link
Contributor

@ottosuess ottosuess Jul 19, 2019

Choose a reason for hiding this comment

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

seems like it's working 🙌
haven't done a lot of testing though.

Loading

@cfromknecht
Copy link
Collaborator

@cfromknecht cfromknecht commented Jul 11, 2019

@halseth didn't get a chance to review the autogenerated code :(

Loading

@halseth
Copy link
Collaborator Author

@halseth halseth commented Jul 11, 2019

@cfromknecht added a temp commit with the generated API!

Loading

// NOTE: This method produces a stream of responses, and the receive stream can
// be called zero or more times. After EOF error is returned, no more responses
// will be produced.
func SendPayment(msg []byte, rStream RecvStream) {
Copy link
Contributor

@ottosuess ottosuess Jul 11, 2019

Choose a reason for hiding this comment

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

same name & package as the SendPayment method in lightning_api_generated.go.
maybe add a prefix to the methods generated by sub-services?

Loading

Copy link

@sergioabril sergioabril Jul 11, 2019

Choose a reason for hiding this comment

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

@ottosuess agree. But as @halseth suggested somewhere else, you can try setting usePrefex=1 on gen_bindings.sh

(Haven't tried though, I manually changed names)

Loading

Copy link
Collaborator Author

@halseth halseth Jul 19, 2019

Choose a reason for hiding this comment

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

Made it possible to add directly to make (73cb325):

make ios tags="routerrpc" prefix=1

Loading

@ottosuess
Copy link
Contributor

@ottosuess ottosuess commented Jul 11, 2019

Would be cool to have a way to inject custom protoc plugins like protoc-gen-swift.

At zap we have a custom "falafel" plugin to generate swift apis that i'd like to inject somehow.

Loading


# Generate APIs by passing the parsed protos to the falafel plugin.
opts="package_name=$pkg,target_package=$target_pkg,listeners=lightning=lightningLis walletunlocker=walletUnlockerLis,mem_rpc=1"
protoc -I/usr/local/include -I. \

Choose a reason for hiding this comment

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

Just thought I'd mention that I didn't have this command, had to run brew install protobuf to get it. Might be worth adding it as a prerequisite to the docs.

Loading

Copy link
Collaborator Author

@halseth halseth Jul 19, 2019

Choose a reason for hiding this comment

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

Thanks, fixed: 7d01dc5

Loading

@halseth
Copy link
Collaborator Author

@halseth halseth commented Jul 19, 2019

Would be cool to have a way to inject custom protoc plugins like protoc-gen-swift.

At zap we have a custom "falafel" plugin to generate swift apis that i'd like to inject somehow.

I think this is a pro-level feature for now, so can be done by modifying gen_bindings directly 😄

Loading

@halseth halseth force-pushed the mobile-rpcs branch 3 times, most recently from 5aded27 to 3760f29 Jul 24, 2019
@wpaulino wpaulino added this to the 0.8.0 milestone Jul 25, 2019
@halseth halseth force-pushed the mobile-rpcs branch 2 times, most recently from 3093a15 to 0fb59d1 Aug 26, 2019
@halseth
Copy link
Collaborator Author

@halseth halseth commented Aug 27, 2019

This commit currently breaks the build script: golang/mobile@597adff

So need to stay on an older revision for now to successfully build.

Latest gomobile@HEAD fixes this issue.

Loading

@halseth halseth force-pushed the mobile-rpcs branch 2 times, most recently from 8d06494 to 742c2b5 Aug 27, 2019
@halseth
Copy link
Collaborator Author

@halseth halseth commented Aug 27, 2019

Loading

Copy link
Member

@Roasbeef Roasbeef left a comment

LGTM 🐸

The auto generated code should be removed from this diff before we merge this PR.

Loading

lnd.go Outdated
@@ -93,6 +93,10 @@ var (
}
)

// rpcListeners us a function type used for closures that fetches a set of RPC
// listeners for the current configuration.
Copy link
Member

@Roasbeef Roasbeef Aug 28, 2019

Choose a reason for hiding this comment

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

Could use a comment explaining what the empty function closure return value is.

Loading

Copy link
Collaborator Author

@halseth halseth Sep 2, 2019

Choose a reason for hiding this comment

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

Not totally sure what you mean, but expanded the comment to note what the default return values should be: 78bc0b1

Loading

@halseth halseth force-pushed the mobile-rpcs branch 2 times, most recently from 78bc0b1 to 85244f7 Sep 2, 2019
@halseth
Copy link
Collaborator Author

@halseth halseth commented Sep 2, 2019

Rebased and removed generated code. Generated code can still be inspected here: https://github.com/lightningnetwork/lnd/tree/78bc0b1128edc56f5f7d095a66e3a025d6a2d89e/mobile

Loading

@wpaulino wpaulino requested a review from valentinewallace Sep 3, 2019
Copy link
Contributor

@valentinewallace valentinewallace left a comment

nits aside, LGTM 🍾 yay!

Loading

mobile/README.md Outdated
#### Generating proto definitions for your language.
In order to call the methods in the generated library, the serialized proto for the given RPC call must be provided. Similarly, the response will be a serialized proto.

I order to generate protobuf definitions for your language of choice, add the proto plugin to the `protoc` invocations found in [`gen_protos.sh`](../lnrpc/gen_protos.sh). For instance to generate protos for Swift, add `--swift_out=.` and run `make rpc`.
Copy link
Contributor

@valentinewallace valentinewallace Sep 4, 2019

Choose a reason for hiding this comment

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

Nit: s/I order/In order

Loading

Copy link
Collaborator Author

@halseth halseth Sep 4, 2019

Choose a reason for hiding this comment

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

Fixed: 210eeb8

Loading

mobile/gen_bindings.sh Outdated Show resolved Hide resolved
Loading
lnd.go Outdated Show resolved Hide resolved
Loading
@halseth
Copy link
Collaborator Author

@halseth halseth commented Sep 4, 2019

Should now be ready to merge

Loading

halseth added 9 commits Sep 5, 2019
ListenerCfg allows passing custom listeners to the main method, to be
used for the wallet unlocker and rpc server. If these are set these will
be used instead of the regular RPC listeners.
gen_bindings uses falafel to generate Go bindings from the lnrpc
protos.
@Roasbeef Roasbeef merged commit 918fd9e into lightningnetwork:master Sep 9, 2019
0 of 2 checks passed
Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

8 participants