Skip to content

Commit

Permalink
Bip32 test corrected + old protoc file included for compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
furszy committed Oct 18, 2018
1 parent db2191e commit 9e5ef7c
Show file tree
Hide file tree
Showing 128 changed files with 21,438 additions and 160 deletions.
Binary file modified .DS_Store
Binary file not shown.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ checkpoints.txt
core/2.0.32_pivx-wallet-backup_org.pivx.production-2017-11-20
*build/
*.DS_Store
*out/
*out/
*3.0.0_pivx-wallet-backup*
core/out/*
Binary file modified core/.DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ dependencies {
compileOnly 'org.fusesource.leveldbjni:leveldbjni-all:1.8'
testImplementation 'junit:junit:4.12'
testImplementation 'org.easymock:easymock:3.2'
testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.5.2'
testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.8.11.1'
testImplementation 'org.slf4j:slf4j-jdk14:1.7.25'
testImplementation 'com.h2database:h2:1.3.167'
testImplementation 'org.fusesource.leveldbjni:leveldbjni-all:1.8'
testCompile group: 'org.json', name: 'json', version: '20170516'
}

sourceCompatibility = 1.7
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/core/BitcoinSerializer.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/core/CoinDefinition.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/core/Context$1.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/core/Context.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/core/PeerGroup$1.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/core/PeerGroup$10.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/core/PeerGroup$11.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/core/PeerGroup$12.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/core/PeerGroup$13.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/core/PeerGroup$14.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/core/PeerGroup$15.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/core/PeerGroup$16.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/core/PeerGroup$17.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/core/PeerGroup$2.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/core/PeerGroup$3.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/core/PeerGroup$4.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/core/PeerGroup$5.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/core/PeerGroup$6.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/core/PeerGroup$7.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/core/PeerGroup$8.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/core/PeerGroup$9.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/core/PeerGroup.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/core/PeerSocketHandler.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/core/Transaction.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/core/Utils$Pair.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/core/Utils.class
Binary file not shown.
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/crypto/HDUtils.class
Binary file not shown.
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/crypto/X509Utils.class
Binary file not shown.
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/utils/Pair.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/utils/Threading$2.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/wallet/KeyChainGroup.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/wallet/SendRequest.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/wallet/Wallet$10.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/wallet/Wallet$11.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/wallet/Wallet$2.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/wallet/Wallet$3.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/wallet/Wallet$4.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/wallet/Wallet$5.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/wallet/Wallet$6.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/wallet/Wallet$7.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/wallet/Wallet$8.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/wallet/Wallet$9.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/wallet/Wallet.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/wallet/WalletFiles$1.class
Binary file not shown.
Binary file modified core/out/production/classes/org/pivxj/wallet/WalletFiles.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified core/out/test/classes/org/pivxj/crypto/BIP32Test.class
Binary file not shown.
Binary file not shown.
Binary file modified core/out/test/classes/org/pivxj/testing/TestWithWallet.class
Binary file not shown.
Binary file modified core/out/test/classes/org/pivxj/wallet/MultiWalletTest.class
Binary file not shown.
Binary file modified core/src/.DS_Store
Binary file not shown.
Binary file modified core/src/main/.DS_Store
Binary file not shown.
Binary file modified core/src/main/java/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public void saveNow() throws IOException {
log.info("Saving wallet; last seen block is height {}, date {}, hash {}", wallet.getLastBlockSeenHeight(),
lastBlockSeenTime != null ? Utils.dateTimeFormat(lastBlockSeenTime) : "unknown",
wallet.getLastBlockSeenHash());
saveNowInternal();
// Do it 2 seconds later to prevent a deadlock.
executor.schedule(saver, 1, TimeUnit.SECONDS);
}

private void saveNowInternal() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,13 @@ public byte[] bitcoinSerialize() {
}
}


@Override
public String toString() {
return "GenWitMessage{" +
"startHeight=" + startHeight +
", den=" + den +
", requestNum=" + requestNum +
'}';
}
}
58 changes: 58 additions & 0 deletions core/src/main/java/host/furszy/zerocoinj/wallet/AmountPerDen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package host.furszy.zerocoinj.wallet;

import com.zerocoinj.core.CoinDenomination;

import org.pivxj.core.Coin;

import java.util.Objects;

public class AmountPerDen {

private CoinDenomination den;
private Coin amount = Coin.ZERO;
private int coinsCont;

public AmountPerDen(CoinDenomination den) {
this.den = den;
}

public AmountPerDen(CoinDenomination den, int coinsCont) {
this.den = den;
this.coinsCont = coinsCont;
this.amount = Coin.valueOf(den.getDenomination() * coinsCont, 0 );
}

public CoinDenomination getDen() {
return den;
}

public Coin getAmount() {
if (amount == Coin.ZERO){
this.amount = Coin.valueOf(den.getDenomination() * coinsCont, 0 );
}
return amount;
}

public int getCoinsCont() {
return coinsCont;
}

public void increment(Coin value) {
amount = amount.add(value);
coinsCont++;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AmountPerDen that = (AmountPerDen) o;
return den == that.den;
}

@Override
public int hashCode() {

return Objects.hash(den);
}
}
72 changes: 42 additions & 30 deletions core/src/main/java/host/furszy/zerocoinj/wallet/MultiWallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ public class MultiWallet{
private DeterministicSeed seed;
private Wallet pivWallet;
private ZWallet zWallet;
private final NetworkParameters params;

protected volatile MultiWalletFiles vFileManager;

protected final ReentrantLock lock;

public enum WalletType{
PIV, ZPIV, ALL
}
Expand All @@ -55,23 +54,24 @@ public MultiWallet(NetworkParameters params, ZerocoinContext zContext, Determini
}

public MultiWallet(NetworkParameters params, ZerocoinContext zContext, DeterministicSeed seed, int lookaheadSize){
this.lock = Threading.lock("MultiWallet_1");
this.params = params;
this.seed = seed;
KeyChainGroup keyChainGroup = new KeyChainGroup(params, seed, BIP44_PIV);
if (lookaheadSize > 0)
keyChainGroup.setLookaheadSize(lookaheadSize);
this.pivWallet = new Wallet(params,keyChainGroup);
this.zWallet = new ZWallet(params, zContext, seed, lookaheadSize);
this.zWallet = new ZWallet(params, zContext, this, seed, lookaheadSize);
}

public MultiWallet(DeterministicSeed seed, List<Wallet> wallets) {
this.lock = Threading.lock("MultiWallet_1");
if(wallets.isEmpty()) throw new IllegalArgumentException("Empty wallets list");
ZerocoinContext zContext = Context.get().zerocoinContext;
this.params = wallets.get(0).getParams();
this.seed = seed;
for (Wallet wallet : wallets) {
if (wallet.getActiveKeyChain().isZerocoinPath()){
if (zWallet != null) throw new IllegalStateException("zWallet not null");
zWallet = new ZWallet(zContext,wallet);
zWallet = new ZWallet(zContext,this, wallet);
}else {
if (pivWallet != null) throw new IllegalStateException("pivWallet not null");
pivWallet = wallet;
Expand All @@ -80,8 +80,11 @@ public MultiWallet(DeterministicSeed seed, List<Wallet> wallets) {
}

public MultiWallet(Wallet pivWallet) {
this.lock = Threading.lock("MultiWallet_1");
this.params = pivWallet.getParams();
this.pivWallet = pivWallet;
this.seed = pivWallet.getKeyChainSeed();
ZerocoinContext zContext = Context.get().zerocoinContext;
this.zWallet = new ZWallet(params, zContext, this, seed, -1);
}

////////////////////////// Basic /////////////////////////////////
Expand All @@ -96,17 +99,17 @@ public NetworkParameters getParams(){

public void addPeergroup(PeerGroup peerGroup){
peerGroup.addWallet(pivWallet);
zWallet.addPeergroup(peerGroup);
if (zWallet != null) zWallet.addPeergroup(peerGroup);
}

public void removePeergroup(PeerGroup peerGroup){
peerGroup.removeWallet(pivWallet);
zWallet.removePeergroup(peerGroup);
if (zWallet != null) zWallet.removePeergroup(peerGroup);
}

public void addWalletFrom(BlockChain blockChain) {
blockChain.addWallet(pivWallet);
zWallet.addWalletFrom(blockChain);
if (zWallet != null) zWallet.addWalletFrom(blockChain);
}

public boolean isEveryOutputSpent(Transaction tx, WalletType walletType){
Expand All @@ -122,6 +125,7 @@ public boolean isEveryOutputSpent(Transaction tx, WalletType walletType){
}

public void commitTx(Transaction tx) {
// No commit
boolean isZcMint = false;
for (TransactionOutput output : tx.getOutputs()) {
if(output.isZcMint()){
Expand Down Expand Up @@ -350,25 +354,36 @@ public boolean addTx(Transaction tx, WalletType walletType){
return false;
}

public List<AmountPerDen> listAmountPerDen(){
return zWallet.listAmountPerDen();
}

/**
* TODO: Add fee here...
* @param amount
* @return
* @throws InsufficientMoneyException
*/
public SendRequest createMintRequest(Coin amount) throws InsufficientMoneyException {
Transaction tx = zWallet.createMint(amount);
Transaction tx = new Transaction(params);
tx = zWallet.createMint(tx, amount);
SendRequest request = SendRequest.forTx(tx);
pivWallet.completeTx(request);
return request;
}

public SendRequest createSpendRequest(Address to, Coin amount) throws InsufficientMoneyException {
Transaction tx = zWallet.createSpend(amount);
return createSpendRequest(to, amount, false);
}

public SendRequest createSpendRequest(Address to, Coin amount, boolean mintChange) throws InsufficientMoneyException {
Transaction tx = new Transaction(params);
tx.addOutput(amount, to);
tx = zWallet.createSpend(tx, amount, mintChange);
SendRequest sendRequest = SendRequest.forTx(tx);
// TODO: check if change this for a new zpiv mint is a good idea..
sendRequest.changeAddress = pivWallet.freshReceiveAddress();
tx.verify();
return sendRequest;
}

Expand Down Expand Up @@ -402,11 +417,6 @@ public Sha256Hash getLastBlockSeenHash() {
/** Saves the wallet first to the given temp file, then renames to the dest file. */
public void saveToFile(File temp, File destFile) throws IOException {
FileOutputStream stream = null;
if (!lock.isHeldByCurrentThread() && lock.isLocked()) {
log.info("MultiWallet, lock is held? " + lock.toString());
}
lock.lock();
log.info("MultiWallet saveToFile lock");
try {
stream = new FileOutputStream(temp);
saveToFileStream(stream);
Expand Down Expand Up @@ -434,8 +444,6 @@ public void saveToFile(File temp, File destFile) throws IOException {
log.error("Failed whilst saving wallet", e);
throw e;
}finally {
lock.unlock();
log.info("MultiWallet saveToFile unlock");
if (stream != null) {
stream.close();
}
Expand All @@ -461,16 +469,10 @@ public void saveToFile(File f) throws IOException {
* {@link WalletProtobufSerializer}.
*/
public void saveToFileStream(OutputStream f) throws IOException {
if (!lock.isHeldByCurrentThread()) {
log.info("MultiWallet, saveToFileStream lock is held? " + lock.toString());
}
lock.lock();
log.info("MultiWallet saveToFileStream lock");
try {
new WalletProtobufSerializer().writeMultiWallet(this, f);
} finally {
lock.unlock();
log.info("MultiWallet saveToFileStream unlock");
//log.info("MultiWallet saveToFileStream unlock");
}
}

Expand Down Expand Up @@ -498,7 +500,6 @@ public void saveToFileStream(OutputStream f) throws IOException {
*/
public MultiWalletFiles autosaveToFile(File f, long delayTime, TimeUnit timeUnit,
@Nullable Listener eventListener) {
lock.lock();
try {
checkState(vFileManager == null, "Already auto saving this wallet.");
MultiWalletFiles manager = new MultiWalletFiles(this, f, delayTime, timeUnit);
Expand All @@ -511,7 +512,7 @@ public MultiWalletFiles autosaveToFile(File f, long delayTime, TimeUnit timeUnit
zWallet.autosaveToFile(vFileManager, eventListener);
return manager;
} finally {
lock.unlock();
//lock.unlock();
}
}

Expand All @@ -523,17 +524,20 @@ public MultiWalletFiles autosaveToFile(File f, long delayTime, TimeUnit timeUnit
* </p>
*/
public void shutdownAutosaveAndWait() {
lock.lock();
//lock.lock();
try {
WalletFilesInterface files = vFileManager;
vFileManager = null;
checkState(files != null, "Auto saving not enabled.");
files.shutdownAndWait();
} finally {
lock.unlock();
//lock.unlock();
}
}

public boolean isAutosaveEnabled(){
return vFileManager != null;
}
public DeterministicSeed getSeed() {
return seed;
}
Expand Down Expand Up @@ -566,4 +570,12 @@ public void decrypt(KeyParameter keyParameter) {
public boolean isEncrypted(){
return pivWallet.isEncrypted() && zWallet.getWallet().isEncrypted();
}

@Override
public String toString() {
return "MultiWallet{" +
"pivWallet=" + pivWallet +
", zWallet=" + zWallet +
'}';
}
}
Loading

0 comments on commit 9e5ef7c

Please sign in to comment.