Skip to content

Commit

Permalink
mobile: Update bundle miner methods to allocate/deallocate ctxs (#18)
Browse files Browse the repository at this point in the history
* mobile: Update bundle miner methods to allocate/deallocate ctxs

* mobile: Update demo apps

* mobile: Deallocate ctxs before if statement
  • Loading branch information
thibault-martinez committed Mar 5, 2020
1 parent 143c7d3 commit 16e8cd9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
12 changes: 10 additions & 2 deletions mobile/android/Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,20 @@ JNIEXPORT jlong JNICALL Java_org_iota_mobile_Interface_bundle_1miner_1mine(
byte_t const* bundleNormalizedMax = (byte_t*)env->GetByteArrayElements(jbundleNormalizedMax, 0);
trit_t* essence = (trit_t*)env->GetByteArrayElements(jessence, 0);

ret = bundle_miner_mine(bundleNormalizedMax, jsecurity, essence, jessenceLength, jcount, jnprocs, jminingThreshold,
jfullySecure, &index);
bundle_miner_ctx_t* ctxs = NULL;
size_t num_ctxs = 0;
bool found_optimal_index = false;

bundle_miner_allocate_ctxs(jnprocs, &ctxs, &num_ctxs);

ret = bundle_miner_mine(bundleNormalizedMax, jsecurity, essence, jessenceLength, jcount, jminingThreshold,
jfullySecure, &index, ctxs, num_ctxs, &found_optimal_index);

env->ReleaseByteArrayElements(jbundleNormalizedMax, (jbyte*)bundleNormalizedMax, 0);
env->ReleaseByteArrayElements(jessence, (jbyte*)essence, 0);

bundle_miner_deallocate_ctxs(&ctxs);

if (ret != RC_OK) {
return -1;
}
Expand Down
18 changes: 18 additions & 0 deletions mobile/android/demo/DummyActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
import android.os.*;
import android.app.*;
import android.util.Log;
import java.util.Arrays;


public class DummyActivity extends Activity{
public final String TX_TRYTES = "XYIUIABLAEBBFCTMDCGPVNCQELHIEBVNRPWBSCABWRAVGVOVMFEHWJCUILYIXOPJNASEOHXPJBXFNHHSWEKEGEEFSAZDENWMOAXGJCQZQDGSTTMN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EEXK9CO9DCMNDY9VZUGMLVFKLUBNSQOABRDMIWVYGMENSBHUOMGIJ9MNKLST999999999999999999999999999999999999999999999999UMJOPYD99A99999999C99999999WUIHHDPDFBHIQLKEFLUOKIOVFOCPFPWBKUCCGA9YUUEPTLUXRLZHVKEOLJQWHBOLSCWKVXCOBSVJHY9YXDMTFSSWIPNAYXJPQNQCZAIT9ADYOLDXZVBTEUWMVYOOODSCPKAWWHOFQTLZKRPURYBMCU9YHSIYQZ9999W9VELHQPPERYSG9ZLLAHQKDLJQBKYYZOSRQOESEELED9CZHBLAMALTJJZAFWNMWGAAUFJMNQDGKVA9999999999999999999999999999999HDU9RGVJE999999999MMMMMMMMMDC99999999OKGA9999999999999";

public final byte[] BUNDLE_NORMALIZED_MAX = new byte[] {13, 13, 13, 13, 13, 11, -7, -3, 6, 4, 9, 11, 13, -7, 5, 5, 9, -9, 1, 5, -4,
9, 0, -8, -9, 6, 10, 13, 11, 8, 2, 7, 13, 1, 6, -1, 6, 7, 6, 7, 11, 4,
-1, 4, -3, 11, -8, 6, -1, 1, 0, 1, 10, 8, 13, 13, 1, 2, 7, 7, 11, 9, 10,
1, -5, 1, 12, 11, 13, -10, 12, 5, 12, 0, -5, 2, -8, 6, 11, 6, 5};

public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Expand All @@ -27,5 +34,16 @@ public void onCreate(Bundle savedInstanceState)
String signature = Interface.iota_sign_signature_gen_trytes(SEED, 2, 2, SEED);
Log.e("IOTA", "Seed: " + SEED);
Log.e("IOTA", "Calculated signature: " + signature);

Log.e("IOTA", "Starting Bundle Miner");
byte[] essence = new byte[486 * 4];
Arrays.fill(essence, (byte) 0);
int essenceLength = 486 * 4;
// Basically UINT32_MAX
int miningThreshold = (int) 4294967295L;
long index = Interface.bundle_miner_mine(BUNDLE_NORMALIZED_MAX, 2, essence, essenceLength, 1000000, 0, miningThreshold, false);
Log.e("IOTA", "Calculated index: " + index);


}
}
4 changes: 3 additions & 1 deletion mobile/ios/Demo/Demo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ - (void)viewDidLoad {
essence:essence
essenceLength:essenceLength
count:@1000000
nprocs:@0];
nprocs:@0
miningThreshold:@(UINT32_MAX)
fullySecure:NO];
NSLog(@"Calculated bundle index: %@ ", bundleIndex);
NSDate* endBundleMiner = [NSDate date];
NSTimeInterval durationBundleMiner = [endBundleMiner timeIntervalSinceDate:startBundleMiner] * 1000;
Expand Down
12 changes: 10 additions & 2 deletions mobile/ios/Interface.mm
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,18 @@ + (NSNumber*)bundle_miner_mine:(int8_t*)bundleNormalizedMax

byte_t const* cbundleNormalizedMax = (byte_t*)bundleNormalizedMax;

bundle_miner_ctx_t* ctxs = NULL;
size_t num_ctxs = 0;
bool found_optimal_index = false;

bundle_miner_allocate_ctxs((uint8_t)[nprocs unsignedCharValue], &ctxs, &num_ctxs);

retcode_t rc = bundle_miner_mine(cbundleNormalizedMax, (uint8_t)[security unsignedCharValue], (trit_t*)essence,
(size_t)[essenceLength unsignedLongValue], (uint32_t)[count unsignedIntValue],
(uint8_t)[nprocs unsignedCharValue], (uint32_t)[miningThreshold unsignedIntValue],
fullySecure, &cindex);
(uint32_t)[miningThreshold unsignedIntValue], fullySecure, &cindex, ctxs, num_ctxs,
&found_optimal_index);

bundle_miner_deallocate_ctxs(&ctxs);

if (rc != RC_OK) {
return @(-1);
Expand Down

0 comments on commit 16e8cd9

Please sign in to comment.