Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
v-almonacid committed Jul 28, 2020
1 parent 4f734d2 commit f357d91
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,11 @@
`$ react-native link react-native-haskell-shelley`

## Usage
```javascript
import HaskellShelley from 'react-native-haskell-shelley';

// TODO: What to do with the module?
HaskellShelley;
```
See examples in [`App.js`](example/App.js).

## How to add new classes and functions

(WIP)

Note: the terms function and method may be used interchangeably.

The process is basically as follows: we start by writting a rust wrapper of some struct method from our target rust library. Both iOS and Android require specific rust wrappers, so there are separate folder (`rust/ios` and `rust/android`). When this project is compiled by the host react native app, all the wrappers are transformed into a native library. In Android, java can directly interact with the rust binaries (the instructions for compiling our rust library are in `build.gradle`), while in iOS there is an additional step in which the rust library is transformed into C, with which can we easily interact with through Objective-C. This intermediate step is contained in `ios/build.sh`, where we basically use `cbindgen` to automatically generate C binaries as well as C headers (which are written in `rust/include/react_native_haskell_shelley.h`).
After writing the corresponding iOS and Android wrappers, we finally just write a simple JS library in `index.js` and define its types in `index.d.ts`.

Expand Down Expand Up @@ -55,12 +47,12 @@ As you may have noticed, the two steps above are equivalent to those with Androi

For every new function in the module:
- Add a rust wrapper of the form: `pub unsafe extern "C" fn function_name_in_snake_case`
- Write a iOS-native wrapper in Objective-C in `ios/HaskellShelley.m`. In contrast to Android (java), the iOS native wrappers can't directly interact with rust so we actually use a C library.
- Write a iOS-native wrapper in Objective-C in `ios/HaskellShelley.m`. In contrast to Android (java), the iOS native wrappers can't directly interact with rust so we actually use a C library. This C library is automatically generated by `cargo` when the project is built.


### Additional steps in Rust

- Add new classes in `rust/src/ptr_impl.rs`
- Any new struct from `cardano_serialization_lib` that is required either as an input or output in our rust wrappers must implement the `RPtrRepresentable` trait. Add them in [`ptr_impl.rs`](rust/src/ptr_impl.rs).

### Javascript

Expand Down

0 comments on commit f357d91

Please sign in to comment.