diff --git a/app/src/main/cpp/monerujo.cpp b/app/src/main/cpp/monerujo.cpp index bf393c0..13cb0e7 100644 --- a/app/src/main/cpp/monerujo.cpp +++ b/app/src/main/cpp/monerujo.cpp @@ -40,6 +40,7 @@ static jclass class_TransactionInfo; static jclass class_Transfer; static jclass class_Ledger; static jclass class_WalletStatus; +static jclass class_CoinsInfo; std::mutex _listenerMutex; @@ -62,6 +63,8 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) { jenv->FindClass("net/mynero/wallet/model/WalletListener"))); class_WalletStatus = static_cast(jenv->NewGlobalRef( jenv->FindClass("net/mynero/wallet/model/Wallet$Status"))); + class_CoinsInfo = static_cast(jenv->NewGlobalRef( + jenv->FindClass("net/mynero/wallet/model/CoinsInfo"))); return JNI_VERSION_1_6; } #ifdef __cplusplus @@ -1024,6 +1027,48 @@ Java_net_mynero_wallet_model_Wallet_disposeTransaction(JNIEnv *env, jobject inst //virtual bool exportKeyImages(const std::string &filename) = 0; //virtual bool importKeyImages(const std::string &filename) = 0; +JNIEXPORT jlong JNICALL +Java_net_mynero_wallet_model_Wallet_getCoinsJ(JNIEnv *env, jobject instance) { + Monero::Wallet *wallet = getHandle(env, instance); + return reinterpret_cast(wallet->coins()); +} + +jobject newCoinsInfo(JNIEnv *env, Monero::CoinsInfo *info) { + jmethodID c = env->GetMethodID(class_CoinsInfo, "", + "(J)V"); + jobject result = env->NewObject(class_CoinsInfo, c, + static_cast (info->globalOutputIndex())); + return result; +} + +jobject coins_cpp2java(JNIEnv *env, const std::vector &vector) { + + jmethodID java_util_ArrayList_ = env->GetMethodID(class_ArrayList, "", "(I)V"); + jmethodID java_util_ArrayList_add = env->GetMethodID(class_ArrayList, "add", + "(Ljava/lang/Object;)Z"); + + jobject arrayList = env->NewObject(class_ArrayList, java_util_ArrayList_, + static_cast (vector.size())); + for (Monero::CoinsInfo *s: vector) { + jobject info = newCoinsInfo(env, s); + env->CallBooleanMethod(arrayList, java_util_ArrayList_add, info); + env->DeleteLocalRef(info); + } + return arrayList; +} + +JNIEXPORT jint JNICALL +Java_net_mynero_wallet_model_Coins_getCount(JNIEnv *env, jobject instance) { + Monero::Coins *coins = getHandle(env, instance); + return coins->count(); +} + +JNIEXPORT jobject JNICALL +Java_net_mynero_wallet_model_Coins_refreshJ(JNIEnv *env, jobject instance) { + Monero::Coins *coins = getHandle(env, instance); + coins->refresh(); + return coins_cpp2java(env, coins->getAll()); +} //virtual TransactionHistory * history() const = 0; JNIEXPORT jlong JNICALL @@ -1530,4 +1575,4 @@ int LedgerFind(char *buffer, size_t len) { #ifdef __cplusplus } -#endif +#endif \ No newline at end of file diff --git a/app/src/main/java/net/mynero/wallet/fragment/dialog/ReceiveBottomSheetDialog.java b/app/src/main/java/net/mynero/wallet/fragment/dialog/ReceiveBottomSheetDialog.java index 766950c..f3b484d 100644 --- a/app/src/main/java/net/mynero/wallet/fragment/dialog/ReceiveBottomSheetDialog.java +++ b/app/src/main/java/net/mynero/wallet/fragment/dialog/ReceiveBottomSheetDialog.java @@ -21,12 +21,15 @@ import com.google.zxing.qrcode.QRCodeWriter; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; import net.mynero.wallet.R; import net.mynero.wallet.data.Subaddress; +import net.mynero.wallet.model.CoinsInfo; +import net.mynero.wallet.model.WalletManager; import net.mynero.wallet.service.AddressService; import net.mynero.wallet.util.DayNightMode; import net.mynero.wallet.util.Helper; import net.mynero.wallet.util.NightmodeHelper; import java.util.HashMap; +import java.util.List; import java.util.Map; import timber.log.Timber; @@ -49,6 +52,12 @@ public class ReceiveBottomSheetDialog extends BottomSheetDialogFragment { addressTextView.setText(addr.getAddress()); addressImageView.setImageBitmap(generate(addr.getAddress(), 256, 256)); copyAddressImageButton.setOnClickListener(view1 -> Helper.clipBoardCopy(getContext(), "address", addr.getAddress())); + + List coins = WalletManager.getInstance().getWallet().getCoins().getAll(); + System.out.println("COINS::"); + for(CoinsInfo coinsInfo : coins) { + System.out.println(coinsInfo.getGlobalOutputIndex()); + } } public Bitmap generate(String text, int width, int height) { diff --git a/app/src/main/java/net/mynero/wallet/model/Coins.java b/app/src/main/java/net/mynero/wallet/model/Coins.java new file mode 100644 index 0000000..9483fb5 --- /dev/null +++ b/app/src/main/java/net/mynero/wallet/model/Coins.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2017 m2049r + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.mynero.wallet.model; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import timber.log.Timber; + +public class Coins { + static { + System.loadLibrary("monerujo"); + } + + private final long handle; + + private List coins = new ArrayList<>(); + + public Coins(long handle) { + this.handle = handle; + } + + public native int getCount(); // over all accounts/subaddresses + + public List getAll() { + return coins; + } + + public void refresh() { + List transactionInfos = refreshJ(); + Timber.d("refresh size=%d", transactionInfos.size()); + coins = transactionInfos; + } + + private native List refreshJ(); +} diff --git a/app/src/main/java/net/mynero/wallet/model/CoinsInfo.java b/app/src/main/java/net/mynero/wallet/model/CoinsInfo.java new file mode 100644 index 0000000..32e3de5 --- /dev/null +++ b/app/src/main/java/net/mynero/wallet/model/CoinsInfo.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2017 m2049r + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.mynero.wallet.model; + +import android.os.Parcel; +import android.os.Parcelable; + +import androidx.annotation.NonNull; + +import java.util.ArrayList; +import java.util.List; + +public class CoinsInfo implements Parcelable { + static { + System.loadLibrary("monerujo"); + } + + long globalOutputIndex; + + public CoinsInfo(long globalOutputIndex) { + this.globalOutputIndex = globalOutputIndex; + } + + protected CoinsInfo(Parcel in) { + globalOutputIndex = in.readLong(); + } + + public static final Creator CREATOR = new Creator() { + @Override + public CoinsInfo createFromParcel(Parcel in) { + return new CoinsInfo(in); + } + + @Override + public CoinsInfo[] newArray(int size) { + return new CoinsInfo[size]; + } + }; + + public long getGlobalOutputIndex() { + return globalOutputIndex; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(@NonNull Parcel parcel, int i) { + parcel.writeLong(globalOutputIndex); + } +} diff --git a/app/src/main/java/net/mynero/wallet/model/Wallet.java b/app/src/main/java/net/mynero/wallet/model/Wallet.java index 74d841d..5774e48 100644 --- a/app/src/main/java/net/mynero/wallet/model/Wallet.java +++ b/app/src/main/java/net/mynero/wallet/model/Wallet.java @@ -45,6 +45,7 @@ public class Wallet { private long listenerHandle = 0; private PendingTransaction pendingTransaction = null; private TransactionHistory history = null; + private Coins coins = null; Wallet(long handle) { this.handle = handle; @@ -324,6 +325,14 @@ public class Wallet { private native long getHistoryJ(); + public Coins getCoins() { + if (coins == null) { + coins = new Coins(getCoinsJ()); + } + return coins; + } + private native long getCoinsJ(); + //virtual bool exportKeyImages(const std::string &filename) = 0; //virtual bool importKeyImages(const std::string &filename) = 0; @@ -334,6 +343,10 @@ public class Wallet { getHistory().refreshWithNotes(this); } + public void refreshCoins() { + getCoins().refresh(); + } + private native long setListenerJ(WalletListener listener); public void setListener(WalletListener listener) { diff --git a/app/src/main/java/net/mynero/wallet/service/MoneroHandlerThread.java b/app/src/main/java/net/mynero/wallet/service/MoneroHandlerThread.java index ce53bb6..1780e55 100644 --- a/app/src/main/java/net/mynero/wallet/service/MoneroHandlerThread.java +++ b/app/src/main/java/net/mynero/wallet/service/MoneroHandlerThread.java @@ -115,6 +115,7 @@ public class MoneroHandlerThread extends Thread implements WalletListener { private void refresh() { wallet.refreshHistory(); + wallet.refreshCoins(); listener.onRefresh(); } diff --git a/external-libs/VERSION b/external-libs/VERSION index 442ed87..654ebac 100644 --- a/external-libs/VERSION +++ b/external-libs/VERSION @@ -1 +1 @@ -MONERUJO_monero master with monero release-v0.18.1.0-monerujo +MONERUJO_monero main with monero release-v0.18.1.0-mynero diff --git a/external-libs/include/wallet2_api.h b/external-libs/include/wallet2_api.h index b67bce6..7a4fce6 100644 --- a/external-libs/include/wallet2_api.h +++ b/external-libs/include/wallet2_api.h @@ -260,6 +260,51 @@ struct AddressBook virtual int lookupPaymentID(const std::string &payment_id) const = 0; }; +/** + * @brief The CoinsInfo - interface for displaying coins information + */ +struct CoinsInfo +{ + virtual ~CoinsInfo() = 0; + + virtual uint64_t blockHeight() const = 0; + virtual std::string hash() const = 0; + virtual size_t internalOutputIndex() const = 0; + virtual uint64_t globalOutputIndex() const = 0; + virtual bool spent() const = 0; + virtual bool frozen() const = 0; + virtual uint64_t spentHeight() const = 0; + virtual uint64_t amount() const = 0; + virtual bool rct() const = 0; + virtual bool keyImageKnown() const = 0; + virtual size_t pkIndex() const = 0; + virtual uint32_t subaddrIndex() const = 0; + virtual uint32_t subaddrAccount() const = 0; + virtual std::string address() const = 0; + virtual std::string addressLabel() const = 0; + virtual std::string keyImage() const = 0; + virtual uint64_t unlockTime() const = 0; + virtual bool unlocked() const = 0; + virtual std::string pubKey() const = 0; + virtual bool coinbase() const = 0; + virtual std::string description() const = 0; +}; + +struct Coins +{ + virtual ~Coins() = 0; + virtual int count() const = 0; + virtual CoinsInfo * coin(int index) const = 0; + virtual std::vector getAll() const = 0; + virtual void refresh() = 0; + virtual void setFrozen(std::string public_key) = 0; + virtual void setFrozen(int index) = 0; + virtual void thaw(std::string public_key) = 0; + virtual void thaw(int index) = 0; + virtual bool isTransferUnlocked(uint64_t unlockTime, uint64_t blockHeight) = 0; + virtual void setDescription(const std::string &public_key, const std::string &description) = 0; +}; + struct SubaddressRow { public: SubaddressRow(std::size_t _rowId, const std::string &_address, const std::string &_label): @@ -936,6 +981,7 @@ struct Wallet virtual TransactionHistory * history() = 0; virtual AddressBook * addressBook() = 0; + virtual Coins * coins() = 0; virtual Subaddress * subaddress() = 0; virtual SubaddressAccount * subaddressAccount() = 0; virtual void setListener(WalletListener *) = 0;