Author

Topic: Android Wallet bug fix - Reward 0.3BTC (Dev is 98% done) (Read 948 times)

sr. member
Activity: 350
Merit: 250
Independent Cryptoveloper
After looking at the github, it appears that you have commented out the lines for PeerDBDiscovery.  It should be working now.

Ideally that should be working as the Litecoin team has it working in their app.  I wanted to add it to my apps as well.

do you know what's the major different betwee the current megacoin and litecoin resp?
I am also trying to make the android wallet. but seems litecoin wallet has no KGW impl.

The current litecoin app is forked from the bitcoin wallet.  The megacoin app is a fork of the digitalcoin app which is a fork of the bitcoin wallet.

The code base is very similar.  You could take the KGW code from the Megacoinj library and place it into the Litecoin bitcoinj module.  I even wrote a native implementation of KGW.

you can PM me if you have further questions as I wrote the java code for KGW.

hero member
Activity: 1428
Merit: 538
After looking at the github, it appears that you have commented out the lines for PeerDBDiscovery.  It should be working now.

Ideally that should be working as the Litecoin team has it working in their app.  I wanted to add it to my apps as well.

do you know what's the major different betwee the current megacoin and litecoin resp?
I am also trying to make the android wallet. but seems litecoin wallet has no KGW impl.



sr. member
Activity: 350
Merit: 250
Independent Cryptoveloper
After looking at the github, it appears that you have commented out the lines for PeerDBDiscovery.  It should be working now.

Ideally that should be working as the Litecoin team has it working in their app.  I wanted to add it to my apps as well.
full member
Activity: 138
Merit: 100
Gaelcoin - Ireland's first Crypto Currency
Hey I got it working with a bit of hacking and slashing but it's start !

Thank you for your help guys, the latest version is up on Git
full member
Activity: 138
Merit: 100
Gaelcoin - Ireland's first Crypto Currency
Thanks for that ! I changed the parameters and it works now but crashes after due to the Peer lookup.. Trying to find a way to void it
sr. member
Activity: 350
Merit: 250
Independent Cryptoveloper
Here are the changes to the LitecoinParams that will resolve the error in the OP:

Code:
diff --git a/core/src/main/java/org/litecoin/LitecoinParams.java b/core/src/main/java/org/litecoin/LitecoinParams.java
index c33b770..1bf631a 100644
--- a/core/src/main/java/org/litecoin/LitecoinParams.java
+++ b/core/src/main/java/org/litecoin/LitecoinParams.java
@@ -38,7 +38,7 @@ public class LitecoinParams extends NetworkParameters {
         id = "org.litecoin.production";
         proofOfWorkLimit = Utils.decodeCompactBits(0x1e0fffffL);
         addressHeader = 15;
-        acceptableAddressCodes = new int[] { 48 };
+        acceptableAddressCodes = new int[] { 15 };
         port = 12622;
         packetMagic = 0xfbc0b6dbL;
         dumpedPrivateKeyHeader = 128 + addressHeader;
@@ -54,15 +54,15 @@ public class LitecoinParams extends NetworkParameters {
         try {
             // A script containing the difficulty bits and the following message:
             //
-            //   "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks"
+            //   "Irish universities fail to make list of top 100 institutions"
             byte[] bytes = Hex.decode
-                    ("0497269736820756e69766572736974696573206661696c20746f206d616b65206c697374206f6620746f702031303020696e737469747574696f6e73");
+                    ("04ffff001d01043c497269736820756e69766572736974696573206661696c20746f206d616b65206c697374206f6620746f702031303020696e737469747574696f6e73");
             t.addInput(new TransactionInput(this, t, bytes));
             ByteArrayOutputStream scriptPubKeyBytes = new ByteArrayOutputStream();
             Script.writeBytes(scriptPubKeyBytes, Hex.decode
                     ("040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9"));
             scriptPubKeyBytes.write(ScriptOpCodes.OP_CHECKSIG);
-            t.addOutput(new TransactionOutput(this, t, Utils.toNanoCoins(50, 0), scriptPubKeyBytes.toByteArray()));
+            t.addOutput(new TransactionOutput(this, t, Utils.toNanoCoins(25, 0), scriptPubKeyBytes.toByteArray()));
         } catch (Exception e) {
             // Cannot happen.
             throw new RuntimeException(e);

However, there is still another exception:

Code:
04-26 21:17:53.514    2633-2692/de.schildbach.wallet_ltc E/AndroidRuntime﹕ FATAL EXCEPTION: PeerGroup
    java.lang.RuntimeException: java.io.IOException: pipe failed: EMFILE (Too many open files)
            at com.google.bitcoin.net.NioClientManager.(NioClientManager.java:85)
            at com.google.bitcoin.core.PeerGroup.(PeerGroup.java:207)
            at com.google.bitcoin.core.PeerGroup.(PeerGroup.java:199)
            at org.litecoin.LitcoinPeerDBDiscovery$PeerGroupWrapper.(LitcoinPeerDBDiscovery.java:75)
            at org.litecoin.LitcoinPeerDBDiscovery$PeerGroupWrapper.(LitcoinPeerDBDiscovery.java:71)
            at org.litecoin.LitcoinPeerDBDiscovery.(LitcoinPeerDBDiscovery.java:86)
            at de.schildbach.wallet.service.BlockchainServiceImpl$3$1.getPeers(BlockchainServiceImpl.java:425)
            at com.google.bitcoin.core.PeerGroup.discoverPeers(PeerGroup.java:502)
            at com.google.bitcoin.core.PeerGroup.connectToAnyPeer(PeerGroup.java:556)
            at com.google.bitcoin.core.PeerGroup.run(PeerGroup.java:534)
            at com.google.common.util.concurrent.AbstractExecutionThreadService$1$1.run(AbstractExecutionThreadService.java:52)
            at java.lang.Thread.run(Thread.java:856)
     Caused by: java.io.IOException: pipe failed: EMFILE (Too many open files)
            at java.nio.SelectorImpl.(SelectorImpl.java:99)
            at java.nio.SelectorProviderImpl.openSelector(SelectorProviderImpl.java:41)
            at com.google.bitcoin.net.NioClientManager.(NioClientManager.java:83)
            at com.google.bitcoin.core.PeerGroup.(PeerGroup.java:207)
            at com.google.bitcoin.core.PeerGroup.(PeerGroup.java:199)
            at org.litecoin.LitcoinPeerDBDiscovery$PeerGroupWrapper.(LitcoinPeerDBDiscovery.java:75)
            at org.litecoin.LitcoinPeerDBDiscovery$PeerGroupWrapper.(LitcoinPeerDBDiscovery.java:71)
            at org.litecoin.LitcoinPeerDBDiscovery.(LitcoinPeerDBDiscovery.java:86)
            at de.schildbach.wallet.service.BlockchainServiceImpl$3$1.getPeers(BlockchainServiceImpl.java:425)
            at com.google.bitcoin.core.PeerGroup.discoverPeers(PeerGroup.java:502)
            at com.google.bitcoin.core.PeerGroup.connectToAnyPeer(PeerGroup.java:556)
            at com.google.bitcoin.core.PeerGroup.run(PeerGroup.java:534)
            at com.google.common.util.concurrent.AbstractExecutionThreadService$1$1.run(AbstractExecutionThreadService.java:52)
            at java.lang.Thread.run(Thread.java:856)
     Caused by: libcore.io.ErrnoException: pipe failed: EMFILE (Too many open files)
            at libcore.io.Posix.pipe(Native Method)
            at libcore.io.ForwardingOs.pipe(ForwardingOs.java:94)
            at java.nio.SelectorImpl.(SelectorImpl.java:92)
            at java.nio.SelectorProviderImpl.openSelector(SelectorProviderImpl.java:41)
            at com.google.bitcoin.net.NioClientManager.(NioClientManager.java:83)
            at com.google.bitcoin.core.PeerGroup.(PeerGroup.java:207)
            at com.google.bitcoin.core.PeerGroup.(PeerGroup.java:199)
            at org.litecoin.LitcoinPeerDBDiscovery$PeerGroupWrapper.(LitcoinPeerDBDiscovery.java:75)
            at org.litecoin.LitcoinPeerDBDiscovery$PeerGroupWrapper.(LitcoinPeerDBDiscovery.java:71)
            at org.litecoin.LitcoinPeerDBDiscovery.(LitcoinPeerDBDiscovery.java:86)
            at de.schildbach.wallet.service.BlockchainServiceImpl$3$1.getPeers(BlockchainServiceImpl.java:425)
            at com.google.bitcoin.core.PeerGroup.discoverPeers(PeerGroup.java:502)
            at com.google.bitcoin.core.PeerGroup.connectToAnyPeer(PeerGroup.java:556)
            at com.google.bitcoin.core.PeerGroup.run(PeerGroup.java:534)
            at com.google.common.util.concurrent.AbstractExecutionThreadService$1$1.run(AbstractExecutionThreadService.java:52)
            at java.lang.Thread.run(Thread.java:856)

This error is a result of some changes the Litecoin Dev Team made to the bitcoin code.  I also had this problem when I imported their PeerDBDiscovery class into one of my android apps.  Catching this RuntimeException does not solve the problem, but locks up the app.  This error does not happen immediately, but after a period of time.  Perhaps the pipes are not being closed?

At this time, I don't have a solution for it, except to remove it and use DnsDiscovery instead.
sr. member
Activity: 350
Merit: 250
Independent Cryptoveloper
I will take a look at this soon, as I have been able to fix many bugs in these apps.

The exception generated appears to be from the initialization of a static Property of the Constants class, which is probably because the genesis block is not configured correctly to match the hash.

full member
Activity: 138
Merit: 100
Gaelcoin - Ireland's first Crypto Currency
Hi Guys,

I'm developing an android Gaelcoin wallet but stuck at the moment, must be something obvious

I've uploaded the code onto github

https://github.com/GaelCoin/bitcoin-wallet

https://github.com/GaelCoin/bitcoinj


I've got 0.3BTC reward for the person who can get it to run & connect to the Gaelcoin network (Generate addresses , send & receive etc) i'll take care of the rest in terms of layout images,text etc

Most of the work is already done in terms of the various parameters


The params
Code:

package org.litecoin;

import com.google.bitcoin.core.*;
import com.google.bitcoin.script.Script;
import com.google.bitcoin.script.ScriptOpCodes;
import com.lambdaworks.crypto.SCrypt;
import org.spongycastle.util.encoders.Hex;

import java.io.ByteArrayOutputStream;
import java.math.BigInteger;
import java.security.GeneralSecurityException;

import static com.google.common.base.Preconditions.checkState;

/**
 * Parameters for the testnet, a separate public instance of Bitcoin that has relaxed rules suitable for development
 * and testing of applications and new Bitcoin versions.
 */
public class LitecoinParams extends NetworkParameters {
    public LitecoinParams() {
        super();
        id = "org.litecoin.production";
        proofOfWorkLimit = Utils.decodeCompactBits(0x1e0fffffL);
        addressHeader = 15;
        acceptableAddressCodes = new int[] { 48 };
        port = 12622;
        packetMagic = 0xfbc0b6dbL;
        dumpedPrivateKeyHeader = 128 + addressHeader;

        targetTimespan = (int)(6 * 8 * 60);
        interval = targetTimespan/((int)(2 * 60));

        genesisBlock.setDifficultyTarget(0x1e0ffff0L);
        genesisBlock.setTime(1394208197L);
        genesisBlock.setNonce(2085670015);
        genesisBlock.removeTransaction(0);
        Transaction t = new Transaction(this);
        try {
            // A script containing the difficulty bits and the following message:
            //
            //   "Irish universities fail to make list of top 100 institutions"
            byte[] bytes = Hex.decode
                    ("04ffff001d010440497269736820756e69766572736974696573206661696c20746f206d616b65206c697374206f6620746f702031303020696e737469747574696f6e73");
            t.addInput(new TransactionInput(this, t, bytes));
            ByteArrayOutputStream scriptPubKeyBytes = new ByteArrayOutputStream();
            Script.writeBytes(scriptPubKeyBytes, Hex.decode
                    ("040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9"));
            scriptPubKeyBytes.write(ScriptOpCodes.OP_CHECKSIG);
            t.addOutput(new TransactionOutput(this, t, Utils.toNanoCoins(50, 0), scriptPubKeyBytes.toByteArray()));
        } catch (Exception e) {
            // Cannot happen.
            throw new RuntimeException(e);
        }
        genesisBlock.addTransaction(t);
        String genesisHash = genesisBlock.getHashAsString();
        checkState(genesisHash.equals("3831a2c571523657ea6886293559c8751a9e8bc195a9f437febbb3df56bc55a1"),
                genesisBlock);

        subsidyDecreaseBlockCount = 450000;

        dnsSeeds = new String[] {
                "seed.gaelcoin.org",
                "pool.gaelcoin.org",

        };
    }

    private static BigInteger MAX_MONEY = Utils.COIN.multiply(BigInteger.valueOf(640000000));
    @Override
    public BigInteger getMaxMoney() { return MAX_MONEY; }

    private static LitecoinParams instance;
    public static synchronized LitecoinParams get() {
        if (instance == null) {
            instance = new LitecoinParams();
        }
        return instance;
    }

    /** The number of previous blocks to look at when calculating the next Block's difficulty */
    @Override
    public int getRetargetBlockCount(StoredBlock cursor) {
        if (cursor.getHeight() + 1 != getInterval()) {
            //Logger.getLogger("wallet_ltc").info("Normal LTC retarget");
            return getInterval();
        } else {
            //Logger.getLogger("wallet_ltc").info("Genesis LTC retarget");
            return getInterval() - 1;
        }
    }

    @Override public String getURIScheme() { return "litecoin:"; }

    /** Gets the hash of the given block for the purpose of checking its PoW */
    public Sha256Hash calculateBlockPoWHash(Block b) {
        byte[] blockHeader = b.cloneAsHeader().bitcoinSerialize();
        try {
            return new Sha256Hash(Utils.reverseBytes(SCrypt.scrypt(blockHeader, blockHeader, 1024, 1, 1, 32)));
        } catch (GeneralSecurityException e) {
            throw new RuntimeException(e);
        }
    }

    static {
        NetworkParameters.registerParams(get());
        NetworkParameters.PROTOCOL_VERSION = 70002;
    }
}


The error:

Code:
04-26 23:12:07.120  32461-32461/de.schildbach.wallet_ltc W/dalvikvm﹕ Exception Ljava/lang/IllegalStateException; thrown while initializing Lorg/litecoin/LitecoinParams;
04-26 23:12:07.120  32461-32461/de.schildbach.wallet_ltc W/dalvikvm﹕ Exception Ljava/lang/ExceptionInInitializerError; thrown while initializing Lde/schildbach/wallet/Constants;
04-26 23:12:07.120  32461-32461/de.schildbach.wallet_ltc W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41642e18)
04-26 23:12:07.130  32461-32461/de.schildbach.wallet_ltc E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: de.schildbach.wallet_ltc, PID: 32461
    java.lang.ExceptionInInitializerError
            at de.schildbach.wallet.Constants.(Constants.java:42)
            at de.schildbach.wallet.WalletApplication.initLogging(WalletApplication.java:174)
            at de.schildbach.wallet.WalletApplication.onCreate(WalletApplication.java:109)
            at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java)
            at android.app.ActivityThread.handleBindApplication(ActivityThread.java)
            at android.app.ActivityThread.access$1500(ActivityThread.java)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java)
            at android.os.Handler.dispatchMessage(Handler.java)
            at android.os.Looper.loop(Looper.java)
            at android.app.ActivityThread.main(ActivityThread.java)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.IllegalStateException: v1 block:
    previous block: 0000000000000000000000000000000000000000000000000000000000000000
    merkle root: 2a9d0d840f9485dd422b7d58a5d92ede9590676e635d43a333f02fcdf1face6f
    time: [1394208197] Fri Mar 07 16:03:17 GMT+00:00 2014
    difficulty target (nBits): 504365040
    nonce: 2085670015
    with 1 transaction(s):
    2a9d0d840f9485dd422b7d58a5d92ede9590676e635d43a333f02fcdf1face6f: Unknown confidence level.
    == COINBASE TXN (scriptSig ???)  (scriptPubKey ???)
            at com.google.common.base.Preconditions.checkState(Preconditions.java:149)
            at org.litecoin.LitecoinParams.(LitecoinParams.java:72)
            at org.litecoin.LitecoinParams.get(LitecoinParams.java:91)
            at org.litecoin.LitecoinParams.(LitecoinParams.java:121)
            ... 15 more
04-26 23:12:18.151  32461-32461/de.schildbach.wallet_ltc D/Process﹕ killProcess, pid=32461
04-26 23:12:18.151  32461-32461/de.schildbach.wallet_ltc D/Process﹕ com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException:-1 java.lang.ThreadGroup.uncaughtException:-1 java.lang.ThreadGroup.uncaughtException:-1
Jump to: