From 3cac408ee45c09b7338b2b466e920a7689523c48 Mon Sep 17 00:00:00 2001 From: ehsan shariati Date: Mon, 4 Dec 2023 17:58:20 -0500 Subject: [PATCH] get account id and asset balance --- android/build.gradle | 2 +- .../main/java/land/fx/fula/FulaModule.java | 120 ++---------------- example/src/App.tsx | 44 ++++++- package.json | 2 +- src/interfaces/fulaNativeModule.ts | 6 + src/protocols/blockchain.ts | 50 ++++++++ src/types/blockchain.ts | 8 ++ 7 files changed, 117 insertions(+), 115 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index d7345b1..f1bfc00 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -94,7 +94,7 @@ dependencies { // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin //noinspection GradleDynamicVersion implementation "com.facebook.react:react-native:+" - implementation 'com.github.functionland:fula-build-aar:v1.15.1' // From jitpack.io + implementation 'com.github.functionland:fula-build-aar:v1.19.0' // From jitpack.io implementation 'com.github.functionland:wnfs-android:v1.8.1' // From jitpack.io implementation 'commons-io:commons-io:20030203.000550' implementation 'commons-codec:commons-codec:1.15' diff --git a/android/src/main/java/land/fx/fula/FulaModule.java b/android/src/main/java/land/fx/fula/FulaModule.java index b0fcf10..fbce891 100755 --- a/android/src/main/java/land/fx/fula/FulaModule.java +++ b/android/src/main/java/land/fx/fula/FulaModule.java @@ -1151,21 +1151,13 @@ public void shutdown(Promise promise) { //////////////////////ANYTHING BELOW IS FOR BLOCKCHAIN///// /////////////////////////////////////////////////////////// @ReactMethod - public void createAccount(String seedString, Promise promise) { + public void GetAccount(Promise promise) { ThreadUtils.runOnExecutor(() -> { - Log.d("ReactNative", "createAccount: seedString = " + seedString); + Log.d("ReactNative", "getAccount called "); try { - if (this.fula == null || this.fula.id() == null || this.fula.id().isEmpty()) { - promise.reject(new Error("Fula client is not initialized")); - } else { - - if (!seedString.startsWith("/")) { - promise.reject(new Error("seed should start with /")); - } - byte[] result = this.fula.seeded(seedString); - String resultString = toString(result); - promise.resolve(resultString); - } + byte[] result = this.fula.getAccount(); + String resultString = toString(result); + promise.resolve(resultString); } catch (Exception e) { Log.d("get", e.getMessage()); promise.reject(e); @@ -1174,11 +1166,11 @@ public void createAccount(String seedString, Promise promise) { } @ReactMethod - public void checkAccountExists(String accountString, Promise promise) { + public void AssetsBalance(String account, String assetId, String classId, Promise promise) { ThreadUtils.runOnExecutor(() -> { - Log.d("ReactNative", "checkAccountExists: accountString = " + accountString); + Log.d("ReactNative", "getAccount called "); try { - byte[] result = this.fula.accountExists(accountString); + byte[] result = this.fula.assetsBalance(account, assetId, classId); String resultString = toString(result); promise.resolve(resultString); } catch (Exception e) { @@ -1189,11 +1181,11 @@ public void checkAccountExists(String accountString, Promise promise) { } @ReactMethod - public void createPool(String seedString, String poolName, Promise promise) { + public void checkAccountExists(String accountString, Promise promise) { ThreadUtils.runOnExecutor(() -> { - Log.d("ReactNative", "createPool: seedString = " + seedString + "; poolName = " + poolName); + Log.d("ReactNative", "checkAccountExists: accountString = " + accountString); try { - byte[] result = this.fula.poolCreate(seedString, poolName); + byte[] result = this.fula.accountExists(accountString); String resultString = toString(result); promise.resolve(resultString); } catch (Exception e) { @@ -1264,21 +1256,6 @@ public void listPoolJoinRequests(long poolID, Promise promise) { }); } - @ReactMethod - public void votePoolJoinRequest(String seedString, long poolID, String accountString, boolean accept, Promise promise) { - ThreadUtils.runOnExecutor(() -> { - Log.d("ReactNative", "votePoolJoinRequest: seedString = " + seedString + "; poolID = " + poolID + "; accountString = " + accountString + "; accept = " + accept); - try { - byte[] result = this.fula.poolVote(seedString, poolID, accountString, accept); - String resultString = toString(result); - promise.resolve(resultString); - } catch (Exception e) { - Log.d("get", e.getMessage()); - promise.reject(e); - } - }); - } - @ReactMethod public void leavePool(long poolID, Promise promise) { ThreadUtils.runOnExecutor(() -> { @@ -1294,36 +1271,6 @@ public void leavePool(long poolID, Promise promise) { }); } - @ReactMethod - public void newReplicationRequest(String seedString, long poolID, long replicationFactor, String cid, Promise promise) { - ThreadUtils.runOnExecutor(() -> { - Log.d("ReactNative", "newReplicationRequest: seedString = " + seedString + "; poolID = " + poolID + "; replicationFactor = " + replicationFactor + "; cid = " + cid); - try { - byte[] result = this.fula.manifestUpload(seedString, poolID, replicationFactor, cid); - String resultString = toString(result); - promise.resolve(resultString); - } catch (Exception e) { - Log.d("get", e.getMessage()); - promise.reject(e); - } - }); - } - - @ReactMethod - public void newStoreRequest(String seedString, long poolID, String uploader, String cid, Promise promise) { - ThreadUtils.runOnExecutor(() -> { - Log.d("ReactNative", "newStoreRequest: seedString = " + seedString + "; poolID = " + poolID + "; uploader = " + uploader + "; cid = " + cid); - try { - byte[] result = this.fula.manifestStore(seedString, poolID, uploader, cid); - String resultString = toString(result); - promise.resolve(resultString); - } catch (Exception e) { - Log.d("get", e.getMessage()); - promise.reject(e); - } - }); - } - @ReactMethod public void listAvailableReplicationRequests(long poolID, Promise promise) { ThreadUtils.runOnExecutor(() -> { @@ -1339,51 +1286,6 @@ public void listAvailableReplicationRequests(long poolID, Promise promise) { }); } - @ReactMethod - public void removeReplicationRequest(String seedString, long poolID, String cid, Promise promise) { - ThreadUtils.runOnExecutor(() -> { - Log.d("ReactNative", "newReplicationRequest: seedString = " + seedString + "; poolID = " + poolID + "; cid = " + cid); - try { - byte[] result = this.fula.manifestRemove(seedString, poolID, cid); - String resultString = toString(result); - promise.resolve(resultString); - } catch (Exception e) { - Log.d("get", e.getMessage()); - promise.reject(e); - } - }); - } - - @ReactMethod - public void removeStorer(String seedString, String storage, long poolID, String cid, Promise promise) { - ThreadUtils.runOnExecutor(() -> { - Log.d("ReactNative", "removeStorer: seedString = " + seedString + "; storage = " + storage + "; poolID = " + poolID + "; cid = " + cid); - try { - byte[] result = this.fula.manifestRemoveStorer(seedString, storage, poolID, cid); - String resultString = toString(result); - promise.resolve(resultString); - } catch (Exception e) { - Log.d("get", e.getMessage()); - promise.reject(e); - } - }); - } - - @ReactMethod - public void removeStoredReplication(String seedString, String uploader, long poolID, String cid, Promise promise) { - ThreadUtils.runOnExecutor(() -> { - Log.d("ReactNative", "removeStoredReplication: seedString = " + seedString + "; uploader = " + uploader + "; poolID = " + poolID + "; cid = " + cid); - try { - byte[] result = this.fula.manifestRemoveStored(seedString, uploader, poolID, cid); - String resultString = toString(result); - promise.resolve(resultString); - } catch (Exception e) { - Log.d("get", e.getMessage()); - promise.reject(e); - } - }); - } - @ReactMethod private void listRecentCidsAsString(Promise promise) throws Exception { ThreadUtils.runOnExecutor(() -> { diff --git a/example/src/App.tsx b/example/src/App.tsx index 0e5f094..65c0692 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -58,10 +58,8 @@ const App = () => { const bloxPeerId_laptop = '12D3KooWLGatFxDzMrKd4S6UC4GAtuM4zcFJW8RPuMR9SH7j46A8'; - const bloxAddr = - '/dns/relay.dev.fx.land/tcp/4001/p2p/12D3KooWDRrBaAfPwsGJivBoUw5fE7ZpDiyfUjqgiURq2DEcL835/p2p-circuit/p2p/' + - bloxPeerId_tower; - //const bloxAddr = '/ip4/192.168.2.87/tcp/40001/p2p/' + bloxPeerId_tower; + //const bloxAddr = '/dns/relay.dev.fx.land/tcp/4001/p2p/12D3KooWDRrBaAfPwsGJivBoUw5fE7ZpDiyfUjqgiURq2DEcL835/p2p-circuit/p2p/' + bloxPeerId_laptop; + const bloxAddr = '/ip4/192.168.2.14/tcp/40001/p2p/' + bloxPeerId_laptop; const initFula = async () => { try { @@ -670,6 +668,44 @@ const App = () => { }} color={inprogress ? 'green' : 'blue'} /> + +