8 changed files with 160 additions and 24 deletions
@ -0,0 +1,13 @@ |
|||
package com.sparrowwallet.sparrow.event; |
|||
|
|||
import com.sparrowwallet.drongo.wallet.Wallet; |
|||
|
|||
/** |
|||
* Indicates that the internal data (non-settings) of the wallet has changed, either from a blockchain update or entry label change etc. |
|||
* Used to trigger a background save of the wallet |
|||
*/ |
|||
public class WalletDataChangedEvent extends WalletChangedEvent { |
|||
public WalletDataChangedEvent(Wallet wallet) { |
|||
super(wallet); |
|||
} |
|||
} |
@ -0,0 +1,43 @@ |
|||
package com.sparrowwallet.sparrow.event; |
|||
|
|||
import com.sparrowwallet.drongo.KeyPurpose; |
|||
import com.sparrowwallet.drongo.wallet.Wallet; |
|||
import com.sparrowwallet.drongo.wallet.WalletNode; |
|||
import com.sparrowwallet.sparrow.io.ElectrumServer; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* Used to notify that a wallet node (identified by it's script hash) has been updated on the blockchain. |
|||
* Does not extend WalletChangedEvent as the wallet is not known when this is fired. |
|||
*/ |
|||
public class WalletNodeHistoryChangedEvent { |
|||
private final String scriptHash; |
|||
|
|||
public WalletNodeHistoryChangedEvent(String scriptHash) { |
|||
this.scriptHash = scriptHash; |
|||
} |
|||
|
|||
public WalletNode getWalletNode(Wallet wallet) { |
|||
List<KeyPurpose> keyPurposes = List.of(KeyPurpose.RECEIVE, KeyPurpose.CHANGE); |
|||
for(KeyPurpose keyPurpose : keyPurposes) { |
|||
WalletNode changedNode = getWalletNode(wallet, keyPurpose); |
|||
if(changedNode != null) { |
|||
return changedNode; |
|||
} |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
private WalletNode getWalletNode(Wallet wallet, KeyPurpose keyPurpose) { |
|||
WalletNode purposeNode = wallet.getNode(keyPurpose); |
|||
for(WalletNode addressNode : purposeNode.getChildren()) { |
|||
if(ElectrumServer.getScriptHash(wallet, addressNode).equals(scriptHash)) { |
|||
return addressNode; |
|||
} |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
} |
Loading…
Reference in new issue