use my own monero repo fork to fetch utxos

This commit is contained in:
pokkst 2022-09-22 04:31:50 -05:00
parent 5184ca1a4c
commit 223f8a5edf
No known key found for this signature in database
GPG Key ID: 90C2ED85E67A50FF
8 changed files with 234 additions and 2 deletions

View File

@ -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<jclass>(jenv->NewGlobalRef(
jenv->FindClass("net/mynero/wallet/model/Wallet$Status")));
class_CoinsInfo = static_cast<jclass>(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<Monero::Wallet>(env, instance);
return reinterpret_cast<jlong>(wallet->coins());
}
jobject newCoinsInfo(JNIEnv *env, Monero::CoinsInfo *info) {
jmethodID c = env->GetMethodID(class_CoinsInfo, "<init>",
"(J)V");
jobject result = env->NewObject(class_CoinsInfo, c,
static_cast<jlong> (info->globalOutputIndex()));
return result;
}
jobject coins_cpp2java(JNIEnv *env, const std::vector<Monero::CoinsInfo *> &vector) {
jmethodID java_util_ArrayList_ = env->GetMethodID(class_ArrayList, "<init>", "(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<jint> (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<Monero::Coins>(env, instance);
return coins->count();
}
JNIEXPORT jobject JNICALL
Java_net_mynero_wallet_model_Coins_refreshJ(JNIEnv *env, jobject instance) {
Monero::Coins *coins = getHandle<Monero::Coins>(env, instance);
coins->refresh();
return coins_cpp2java(env, coins->getAll());
}
//virtual TransactionHistory * history() const = 0;
JNIEXPORT jlong JNICALL

View File

@ -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<CoinsInfo> 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) {

View File

@ -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<CoinsInfo> coins = new ArrayList<>();
public Coins(long handle) {
this.handle = handle;
}
public native int getCount(); // over all accounts/subaddresses
public List<CoinsInfo> getAll() {
return coins;
}
public void refresh() {
List<CoinsInfo> transactionInfos = refreshJ();
Timber.d("refresh size=%d", transactionInfos.size());
coins = transactionInfos;
}
private native List<CoinsInfo> refreshJ();
}

View File

@ -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<CoinsInfo> CREATOR = new Creator<CoinsInfo>() {
@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);
}
}

View File

@ -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) {

View File

@ -115,6 +115,7 @@ public class MoneroHandlerThread extends Thread implements WalletListener {
private void refresh() {
wallet.refreshHistory();
wallet.refreshCoins();
listener.onRefresh();
}

View File

@ -1 +1 @@
MONERUJO_monero master with monero release-v0.18.1.0-monerujo
MONERUJO_monero main with monero release-v0.18.1.0-mynero

View File

@ -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<CoinsInfo*> 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;