Craig Raw
3 years ago
12 changed files with 94 additions and 37 deletions
@ -1 +1 @@ |
|||
Subproject commit b4f4cc8726de3e7b5f875816affe1e0f78f2fa25 |
|||
Subproject commit 94d22b875868760a95222e0254ec10b59c71e04f |
@ -0,0 +1,9 @@ |
|||
package com.sparrowwallet.sparrow.event; |
|||
|
|||
import com.sparrowwallet.drongo.wallet.Wallet; |
|||
|
|||
public class WalletMasterMixConfigChangedEvent extends WalletMixConfigChangedEvent { |
|||
public WalletMasterMixConfigChangedEvent(Wallet wallet) { |
|||
super(wallet.isMasterWallet() ? wallet : wallet.getMasterWallet()); |
|||
} |
|||
} |
@ -1,33 +1,70 @@ |
|||
package com.sparrowwallet.sparrow.whirlpool.dataSource; |
|||
|
|||
import com.samourai.wallet.client.indexHandler.AbstractIndexHandler; |
|||
import com.sparrowwallet.drongo.KeyPurpose; |
|||
import com.sparrowwallet.drongo.wallet.Wallet; |
|||
import com.sparrowwallet.drongo.wallet.WalletNode; |
|||
import com.sparrowwallet.sparrow.EventManager; |
|||
import com.sparrowwallet.sparrow.event.WalletMixConfigChangedEvent; |
|||
|
|||
public class SparrowIndexHandler extends AbstractIndexHandler { |
|||
private final Wallet wallet; |
|||
private final WalletNode walletNode; |
|||
private final int defaultValue; |
|||
|
|||
public SparrowIndexHandler(WalletNode walletNode) { |
|||
this(walletNode, 0); |
|||
public SparrowIndexHandler(Wallet wallet, WalletNode walletNode) { |
|||
this(wallet, walletNode, 0); |
|||
} |
|||
|
|||
public SparrowIndexHandler(WalletNode walletNode, int defaultValue) { |
|||
public SparrowIndexHandler(Wallet wallet, WalletNode walletNode, int defaultValue) { |
|||
this.wallet = wallet; |
|||
this.walletNode = walletNode; |
|||
this.defaultValue = defaultValue; |
|||
} |
|||
|
|||
@Override |
|||
public synchronized int get() { |
|||
Integer currentIndex = walletNode.getHighestUsedIndex(); |
|||
return currentIndex == null ? defaultValue : currentIndex + 1; |
|||
return Math.max(getCurrentIndex(), getStoredIndex()); |
|||
} |
|||
|
|||
@Override |
|||
public synchronized int getAndIncrement() { |
|||
return get(); |
|||
int index = get(); |
|||
set(index + 1); |
|||
return index; |
|||
} |
|||
|
|||
@Override |
|||
public synchronized void set(int value) { |
|||
setStoredIndex(value); |
|||
} |
|||
|
|||
private int getCurrentIndex() { |
|||
Integer currentIndex = walletNode.getHighestUsedIndex(); |
|||
return currentIndex == null ? defaultValue : currentIndex + 1; |
|||
} |
|||
|
|||
private int getStoredIndex() { |
|||
if(wallet.getMixConfig() != null) { |
|||
if(walletNode.getKeyPurpose() == KeyPurpose.RECEIVE) { |
|||
return wallet.getMixConfig().getReceiveIndex(); |
|||
} else if(walletNode.getKeyPurpose() == KeyPurpose.CHANGE) { |
|||
return wallet.getMixConfig().getChangeIndex(); |
|||
} |
|||
} |
|||
|
|||
return defaultValue; |
|||
} |
|||
|
|||
private void setStoredIndex(int index) { |
|||
if(wallet.getMixConfig() != null) { |
|||
if(walletNode.getKeyPurpose() == KeyPurpose.RECEIVE) { |
|||
wallet.getMixConfig().setReceiveIndex(index); |
|||
} else if(walletNode.getKeyPurpose() == KeyPurpose.CHANGE) { |
|||
wallet.getMixConfig().setChangeIndex(index); |
|||
} |
|||
} |
|||
|
|||
EventManager.get().post(new WalletMixConfigChangedEvent(wallet)); |
|||
} |
|||
} |
|||
|
@ -1,2 +1,2 @@ |
|||
create table mixConfig (id identity not null, scode varchar(255), mixOnStartup boolean, mixToWalletFile varchar(1024), mixToWalletName varchar(255), minMixes integer, wallet bigint not null); |
|||
create table mixConfig (id identity not null, scode varchar(255), mixOnStartup boolean, mixToWalletFile varchar(1024), mixToWalletName varchar(255), minMixes integer, receiveIndex integer not null, changeIndex integer not null, wallet bigint not null); |
|||
create table utxoMixData (id identity not null, hash binary(32) not null, mixesDone integer not null default 0, expired bigint, wallet bigint not null); |
Loading…
Reference in new issue