Skip to content

Commit 3f2065f

Browse files
authored
Merge pull request #35 from functionland/added-exchang-
added exchange
2 parents 1befcf6 + 2209469 commit 3f2065f

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { fula } from 'react-native-fula'; // Until the library becomes stable, w
1515
```
1616

1717
```js
18-
//Initialize the fula client, which creates the libp2p connection. Note that input is not an object e.g. init('','','')
18+
//Initialize the fula client, which creates the libp2p connection. Note that input is not an object e.g. init('','','','noop')
1919
[
2020
peerId, //returns peerId of the created libp2p instance in form of a string of bytes
2121
cid, //return the root cid of the WNFS merkle DAG in form of a string
@@ -26,6 +26,7 @@ await fula.init(
2626
identity: string, //bytes of the privateKey of did identity in string format
2727
storePath: string, // leave empty to use the default temp one
2828
bloxAddr: string, //leave empty for testing without a backend node
29+
exchange: 'noop'|'' //add noop for testing without a backend
2930
);
3031
```
3132

android/src/main/java/land/fx/fula/FulaModule.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,14 @@ private static byte[] convertStringToByte(@NonNull String data) {
129129
}
130130

131131
@ReactMethod
132-
public void init(String identityString, String storePath, String bloxAddr, Promise promise) {
132+
public void init(String identityString, String storePath, String bloxAddr, String exchange, Promise promise) {
133133
Log.d("ReactNative", "init started");
134134
ThreadUtils.runOnExecutor(() -> {
135135
try {
136136
Log.d("ReactNative", "init storePath= " + storePath);
137137
byte[] identity = toByte(identityString);
138138
Log.d("ReactNative", "init identity= " + identityString);
139-
String[] obj = initInternal(identity, storePath, bloxAddr);
139+
String[] obj = initInternal(identity, storePath, bloxAddr, exchange);
140140
Log.d("ReactNative", "init object created: [ " + obj[0] + ", " + obj[1] + ", " + obj[2] + " ]");
141141
promise.resolve(obj);
142142
} catch (Exception e) {
@@ -171,7 +171,7 @@ private byte[] createPeerIdentity(byte[] privateKey) throws Exception {
171171
}
172172

173173
@NonNull
174-
private String[] initInternal(byte[] identity, String storePath, String bloxAddr) throws Exception {
174+
private String[] initInternal(byte[] identity, String storePath, String bloxAddr, String exchange) throws Exception {
175175
try {
176176
Config config_ext = new Config();
177177
if (storePath == null || storePath.trim().isEmpty()) {
@@ -186,6 +186,7 @@ private String[] initInternal(byte[] identity, String storePath, String bloxAddr
186186
Log.d("ReactNative", "peerIdentity is set: " + toString(config_ext.getIdentity()));
187187
config_ext.setBloxAddr(bloxAddr);
188188
Log.d("ReactNative", "bloxAddr is set: " + config_ext.getBloxAddr());
189+
config_ext.setExchange(exchange);
189190
this.fula = Fulamobile.newClient(config_ext);
190191
this.client = new Client(this.fula);
191192
Log.d("ReactNative", "fula initialized: " + this.fula.id());

example/src/App.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ const App = () => {
2323
let f = await fula.init(
2424
privateKey.toString(),
2525
'',
26-
'/ip4/59.23.13.76/tcp/46640/p2p/QmRS9H18XHFrbmGKxi2TEBFz5ZzurkU9cbAwMsRzXcjr5X'
26+
'/ip4/59.23.13.76/tcp/46640/p2p/QmRS9H18XHFrbmGKxi2TEBFz5ZzurkU9cbAwMsRzXcjr5X',
27+
'noop'
2728
);
2829
console.log('initialization result', f);
2930
return f;

src/interfaces/fulaNativeModule.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ interface FulaNativeModule {
44
init: (
55
identity: string | null, //Private key of did identity
66
storePath: string | null, //You can leave empty
7-
bloxAddr: string //Blox multiadddr needs to be manually entered now
7+
bloxAddr: string, //Blox multiadddr needs to be manually entered now
8+
exchange: string //set to 'noope' for testing
89
) => Promise<[string, string, string]>;
910
get: (key: string) => Promise<string>;
1011
has: (key: Uint8Array) => Promise<boolean>;

src/protocols/fula.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import Fula from '../interfaces/fulaNativeModule';
66
* @param config
77
* @returns boolean
88
*/
9+
910
export const init = (
10-
identity: string | null, //privateKey of did identity
11-
storePath: string | null,
11+
identity: string, //privateKey of did identity
12+
storePath: string,
1213
bloxAddr: string,
14+
exchange: string
1315
): Promise<[string, string, string]> => {
14-
console.log('init in react-native started',identity, storePath, bloxAddr);
15-
return Fula.init(identity, storePath, bloxAddr);
16+
console.log('init in react-native started',identity, storePath, bloxAddr, exchange);
17+
return Fula.init(identity, storePath, bloxAddr, exchange);
1618
};
1719

1820
/**

0 commit comments

Comments
 (0)