[Project] Android Mobile Wallet

nice site by the way

I could transfer coins too but that CheckStakeKernelHash was missing and is cruicall… I have to figure it out
and it depends on txPrev.offset which is txindex.pos.nTxPos - txindex.pos.nBlockPos

Have you checked the other branches: https://github.com/kac-/peercoinj/branches

Some seem to be more active than the trunk.

You should also try to get in touch with the main developper. He is also active on this forum.

yeah his comments were the most helpful ones :slight_smile:

// The offset is how many bytes into the provided byte array this message starts at.
protected transient int offset;

// The cursor keeps track of where we are in the byte array as we parse it.
// Note that it’s relative to the start of the array NOT the start of the message.
protected transient int cursor;

peercoin is kind of lagging behind in this area. Is there great difficulty in creating a wallet that mints on an android phone?

It appears difficult. Only YAC has made progress in cracking the nut.

Theer should be a working wallet that sends/receives peercoins first. After that comes the minting feature.

fuck the stake is wrong

this is what I have made in java, all selected blocks are fine just the last one is wrong :frowning:
This almoooust get me the block I need

[code]private StoredBlock selectBlockFromCandidates(
Map<Sha256Hash, Long> sortedByTimestamp,Map<Sha256Hash, StoredBlock> mapSelectedBlocks,
long selectionIntervalStop, long stakeModifier, StoredBlock pindex) throws BlockStoreException {
boolean fSelected = false;
Sha256Hash hashBest = Sha256Hash.ZERO_HASH;
Sha256Hash hashSelection = Sha256Hash.ZERO_HASH;
StoredBlock pindexSelected = null;
for (Map.Entry<Sha256Hash, Long> timestampBlocks : sortedByTimestamp.entrySet()) {
pindex = blockStore.get(timestampBlocks.getKey());
if(pindex == null)
throw new RuntimeException("block not found ");
if(fSelected && pindex.getHeader().getTimeSeconds() > selectionIntervalStop)
break;
if (mapSelectedBlocks.get(timestampBlocks.getKey())!=null){
continue;
}
//256 = 32, 64 = 8
byte[] arrayHHrf = pindex.getHeader().getHash().toBigInteger().toByteArray();
byte[] arraySTmd = new byte[8];
Utils.uint64ToByteArrayLE(stakeModifier, arraySTmd, 0);
// CDataStream ss(SER_GETHASH, 0);
ByteArrayOutputStream ssStakeStream = new UnsafeByteArrayOutputStream(32 + 8);
//ss << pindex->hashProof << nStakeModifierPrev;
try {
ssStakeStream.write(arrayHHrf);
ssStakeStream.write(arraySTmd);
//don’t use Sha256Hash.toBigInteger if you’re using unsigned (cause you make unsigned of unsigned maaan)
Sha256Hash sha256HashSelection = new Sha256Hash(Utils.reverseBytes(doubleDigest(ssStakeStream.toByteArray())));
hashSelection = sha256HashSelection;
} catch (IOException e) {
e.printStackTrace();
} finally{
try {
ssStakeStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

		if (pindex.isStake()){
			//hashSelection >>= 32;
			//hashSelection = hashSelection >> 32
			BigInteger uHashSelection = hashSelection.toBigInteger().shiftRight(32);
			hashSelection = new Sha256Hash(uHashSelection.toByteArray());
			log.info(" shifting 32");
		}

		if (fSelected && hashSelection.compareTo(hashBest) == -1){
			hashBest = hashSelection;
			pindexSelected = pindex;
		}
		
		else if (!fSelected)
        {
            fSelected = true;
            hashBest = hashSelection;
            pindexSelected = pindex;
        }
		
	}
	
	return pindexSelected;
}[/code]

What an unbelievable amount of work you have made, wow.
Are you sure it isn’t sortedByTimestamp or selectionIntervalStop?
Put some extensive logging on c++ and java sides, I see no other way, it may be something trivial.

You also have to reconsider making some kind of agreement with FuzzyBear, it’s way too much work for you alone, maybe you can list things you’ve already made and quote your price [till the commit 2b123b4 I want xxxx PPCs], then Fuzzy could create private git repo to work on it. When code is done you’ll publish it and take agreed amount + work made in priv repo. Imagine that your computer explode or you simply stuck at some point and abandon it, it would be awful. Just 2 PPC-cents.

This part is where I am not really sure what to do, so I suspect it’s wrong
I logged it and the log shows it selects last wrong block.

uint64 nStakeModifierPrev first one is 0x0000000000000000
uint256 hashProof = pindex->IsProofOfStake()? pindex->hashProofOfStake : pindex->GetBlockHash();

ss << hashProof << nStakeModifierPrev; uint256 hashSelection = Hash(ss.begin(), ss.end());

https://github.com/ppcoin/ppcoin/blob/master/src/kernel.cpp#L104

                    [code]//256 = 32, 64 = 8
		BigInteger arrayHHrf = pindex.getHeader().getHash().toBigInteger();
		byte[] arraySTmd = new byte[8];
		Utils.uint64ToByteArrayLE(stakeModifier, arraySTmd, 0);
		// CDataStream ss(SER_GETHASH, 0);
		ByteArrayOutputStream ssStakeStream = new UnsafeByteArrayOutputStream(32 + 8);
		//ss << pindex->hashProof << nStakeModifierPrev;
		try {
			ssStakeStream.write(arrayHHrf.toByteArray());
			ssStakeStream.write(arraySTmd);
			Sha256Hash sha256HashSelection = new Sha256Hash(Utils.reverseBytes(doubleDigest(ssStakeStream.toByteArray())));
			hashSelection = new BigInteger(sha256HashSelection.getBytes());
		} catch (IOException e) {				
			e.printStackTrace();
		} finally{
			try {
				ssStakeStream.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}[/code]

from this I can see what selection hash looks like it’s definitely wrong

But last hash only? It’s very strange.

So I debugged it and the hashSelection is wrong :frowning:

https://github.com/ppcoin/ppcoin/blob/master/src/kernel.cpp#L104

CDataStream ss(SER_GETHASH, 0); ss << hashProof << nStakeModifierPrev; uint256 hashSelection = Hash(ss.begin(), ss.end());

[code]
//256 = 32, 64 = 8
byte[] arrayHashProof = pindex.getHeader().getHash().toBigInteger().toByteArray();
// CDataStream ss(SER_GETHASH, 0);
ByteArrayOutputStream ssStakeStream = new UnsafeByteArrayOutputStream(32 + 8);
//ss << pindex->hashProof << nStakeModifierPrev;
try {
ssStakeStream.write(arrayHashProof);
Utils.uint64ToByteStreamLE(stakeModifier, ssStakeStream);
sha256HashSelection = new Sha256Hash(Utils.reverseBytes(doubleDigest(ssStakeStream.toByteArray())));
hashSelection = sha256HashSelection.toBigInteger();
} catch (IOException e) {
e.printStackTrace();
} finally{
try {
ssStakeStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

		[/code]

for example for hashProof
1faef25dec4fbcf906e6242621df2c183bf232f263d0ba5b101911e4563
and stakeModifier
0x0000000000000000
I get hashSelection.toString(16)
f1d854c7a268dcebc4b40a9ef954300f681a56796621469c63d643e29f7e7a81
but I should get
bb245d8baac1fd953cc6a0a6ec6ea6339d2ab755ebbb3801cd2c4c7268f5bd5e

corrected ;DD

you know where the error is?

here
ssStakeStream.write(Utils.reverseBytes(arrayHashProof));

Neglecting to reverse the bytes before hashing. This is some low-level stuff, indeed! Good catch.

Just want to put a note in and thank you, janko33, for your hard work on this Android wallet. I’m sure I speak for the entire community when I say that your work is very much appreciated. Thank you!

I totally agree!

Would be happy to help as a Java and Android developer.

Would anyone be opposed to a “strait port” to android using the existing code base?

That is, using the NDK to port all the existing backend (peercoind) to a shiny new Android interface? That would mean you would need to download the entire blockchain to your phone, and it would have to update completely before being able to make transaction (unlike the existing bitcoin android wallets, which only need the headers).

[quote=“janko33, post:54, topic:2104”]corrected ;DD

you know where the error is?

here
ssStakeStream.write(Utils.reverseBytes(arrayHashProof));[/quote]

It great to see your progress. How’s status now?

[quote=“SigmundAlpha, post:57, topic:2104”]Would anyone be opposed to a “strait port” to android using the existing code base?

That is, using the NDK to port all the existing backend (peercoind) to a shiny new Android interface? That would mean you would need to download the entire blockchain to your phone, and it would have to update completely before being able to make transaction (unlike the existing bitcoin android wallets, which only need the headers).[/quote]
Well, I wouldn’t be opposed. Choice is always good. However once Janko333 has finished his port, I would say that the priority for another Android wallet would be relatively low. The only feature would be a local blockchain which I would like for minting or even as a node (on a old phone with wifi), but I guess Janko333’s port would be more useful for quick mobile payments and mobile merchants or merchants with mobiles :slight_smile:

My opinion is it would may be more useful to work on stuff like OT when there is a choice, but others might disagree.

+1 and it seems always interesting to me to have a high level language wallet implementation.