Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bundle_transactions_t *bundleFromJavaBundle(JNIEnv *env, jobject javaBundle){
- bundle_transactions_t *bundle = NULL;
- bundle_transactions_new(&bundle);
- jclass bundleClass = (*env)->FindClass(env, "org/iota/jota/model/Bundle" );
- jclass transactionClass = (*env)->FindClass(env, "org/iota/jota/model/Transaction" );
- jmethodID getTransactions = (*env)->GetMethodID(env, bundleClass , "getTransactions", "()Ljava/util/List;" );
- jmethodID toTrytes = (*env)->GetMethodID(env, transactionClass , "toTrytes", "()java/lang/String;" );
- jobject txList = (*env)->CallObjectMethod(env, javaBundle, getTransactions );
- jclass listClass = (*env)->FindClass(env, "java/util/List" );
- jmethodID getMethodID = (*env)->GetMethodID(env, listClass, "get", "(I)Ljava/lang/Object;" );
- jmethodID sizeMethodID = (*env)->GetMethodID(env, listClass, "size", "()I" );
- int listItemsCount = (int)(*env)->CallIntMethod(env, txList, sizeMethodID );
- for( int i=0; i<listItemsCount; ++i ){
- jobject javaTx = (*env)->CallObjectMethod(env, txList, getMethodID, i - 1 );
- jstring txTrytes = (*env)->CallObjectMethod(env, javaTx, toTrytes);
- jboolean tx_isCopy;
- tryte_t *c_tx_trytes = (tryte_t *) (*env)->GetStringUTFChars(env, txTrytes, &tx_isCopy);
- size_t trytes_len = strlen(c_tx_trytes);
- flex_trit_t *flex_trits = malloc(numOfFlexTritsForTxTrits * sizeof(flex_trit_t));
- flex_trits_from_trytes(flex_trits, numOfFlexTritsForTxTrits, c_tx_trytes, trytes_len, trytes_len);
- iota_transaction_t *c_transaction = transaction_deserialize(flex_trits, false);
- bundle_transactions_add(bundle, c_transaction);
- if (tx_isCopy == JNI_TRUE) {
- (*env)->ReleaseStringUTFChars(env, c_tx_trytes, txTrytes);
- }
- }
- return bundle;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement