package org.bitcoinj.evolution;

import com.google.common.collect.ImmutableList;
import org.bitcoinj.core.Base58;
import org.bitcoinj.core.Sha256Hash;
import org.bitcoinj.crypto.ChildNumber;
import org.bitcoinj.crypto.ExtendedChildNumber;
import org.bitcoinj.wallet.FriendKeyChain;

public class EvolutionContact {
    Sha256Hash evolutionUserId;
    Sha256Hash friendUserId;
    int userAccount;

    public EvolutionContact(String userId, String friendUserId) {
        this(Sha256Hash.wrap(Base58.decode(userId)), Sha256Hash.wrap(Base58.decode(friendUserId)));
    }

    public EvolutionContact(String userId, int account, String friendUserId) {
        this(Sha256Hash.wrap(Base58.decode(userId)), account, Sha256Hash.wrap(Base58.decode(friendUserId)));
    }

    public EvolutionContact(Sha256Hash evolutionUserId, Sha256Hash friendUserId) {
        this(evolutionUserId, 0, friendUserId);
    }

    public EvolutionContact(Sha256Hash evolutionUserId, int userAccount, Sha256Hash friendUserId) {
        this.evolutionUserId = evolutionUserId;
        this.userAccount = userAccount;
        this.friendUserId = friendUserId;
    }

    public EvolutionContact(ImmutableList<ChildNumber> accountPath, boolean owner) {
        this.evolutionUserId = Sha256Hash.wrap(((ExtendedChildNumber)accountPath.get(owner ?
                FriendKeyChain.PATH_INDEX_TO_ID : FriendKeyChain.PATH_INDEX_FROM_ID)).bi());
        this.friendUserId = Sha256Hash.wrap(((ExtendedChildNumber)accountPath.get(!owner ?
                FriendKeyChain.PATH_INDEX_TO_ID : FriendKeyChain.PATH_INDEX_FROM_ID)).bi());
        this.userAccount = accountPath.get(FriendKeyChain.PATH_INDEX_ACCOUNT).num();
    }

    public Sha256Hash getEvolutionUserId() {
        return evolutionUserId;
    }

    public Sha256Hash getFriendUserId() {
        return friendUserId;
    }

    public int getUserAccount() {
        return userAccount;
    }
}

@@ -389,16 +389,48 @@
 Account;
+%0A    int friendAccountReference;
 %0A%0A    pu
@@ -663,32 +663,60 @@
 ing friendUserId
+, int friendAccountReference
 ) %7B%0A        this
@@ -801,32 +801,56 @@
 e(friendUserId))
+, friendAccountReference
 );%0A    %7D%0A%0A    pu
@@ -971,16 +971,19 @@
 ndUserId
+, 0
 );%0A    %7D
@@ -1072,32 +1072,60 @@
 ash friendUserId
+, int friendAccountReference
 ) %7B%0A        this
@@ -1234,32 +1234,94 @@
 = friendUserId;%0A
+        this.friendAccountReference = friendAccountReference;%0A
     %7D%0A%0A    publi
@@ -1792,16 +1792,24 @@
 ccount =
+ owner ?
  account
@@ -1857,16 +1857,130 @@
 T).num()
+ : 0;%0A        this.friendAccountReference = !owner ? accountPath.get(FriendKeyChain.PATH_INDEX_ACCOUNT).num() : -1
 ;%0A    %7D%0A
@@ -2209,11 +2209,102 @@
 t;%0A    %7D
+%0A%0A    public int getFriendAccountReference() %7B%0A        return friendAccountReference;%0A    %7D
 %0A%7D%0A

Add friendAccountReference