mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-22 22:45:21 +01:00
Merge branch 'handle-genesis-change' of https://github.com/sqrrm/exchange into sqrrm-handle-genesis-change
# Conflicts: # core/src/main/java/io/bisq/core/dao/node/consensus/GenesisTxController.java
This commit is contained in:
commit
a8962c833a
1 changed files with 18 additions and 5 deletions
|
@ -19,7 +19,9 @@ package io.bisq.core.dao.node.consensus;
|
|||
|
||||
import io.bisq.core.dao.DaoOptionKeys;
|
||||
import io.bisq.core.dao.blockchain.WritableBsqBlockChain;
|
||||
import io.bisq.core.dao.blockchain.ReadableBsqBlockChain;
|
||||
import io.bisq.core.dao.blockchain.vo.Tx;
|
||||
import io.bisq.core.dao.blockchain.vo.TxOutput;
|
||||
import io.bisq.core.dao.blockchain.vo.TxType;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
@ -31,14 +33,17 @@ import javax.inject.Named;
|
|||
public class GenesisTxController {
|
||||
|
||||
private final WritableBsqBlockChain writableBsqBlockChain;
|
||||
private final ReadableBsqBlockChain readableBsqBlockChain;
|
||||
private final String genesisTxId;
|
||||
private final int genesisBlockHeight;
|
||||
|
||||
@Inject
|
||||
public GenesisTxController(WritableBsqBlockChain writableBsqBlockChain,
|
||||
ReadableBsqBlockChain readableBsqBlockChain,
|
||||
@Named(DaoOptionKeys.GENESIS_TX_ID) String genesisTxId,
|
||||
@Named(DaoOptionKeys.GENESIS_BLOCK_HEIGHT) int genesisBlockHeight) {
|
||||
this.writableBsqBlockChain = writableBsqBlockChain;
|
||||
this.readableBsqBlockChain = readableBsqBlockChain;
|
||||
this.genesisTxId = genesisTxId;
|
||||
this.genesisBlockHeight = genesisBlockHeight;
|
||||
}
|
||||
|
@ -47,12 +52,20 @@ public class GenesisTxController {
|
|||
return tx.getId().equals(genesisTxId) && blockHeight == genesisBlockHeight;
|
||||
}
|
||||
|
||||
// TODO Refactor to new GenesisTxOutputsController class to separate verification logic
|
||||
// from state change
|
||||
public void applyStateChange(Tx tx) {
|
||||
tx.getOutputs().forEach(txOutput -> {
|
||||
txOutput.setUnspent(true);
|
||||
txOutput.setVerified(true);
|
||||
writableBsqBlockChain.addUnspentTxOutput(txOutput);
|
||||
});
|
||||
long totalOutput = 0;
|
||||
for (int i = 0; i < tx.getOutputs().size(); ++i) {
|
||||
TxOutput txOutput = tx.getOutputs().get(i);
|
||||
totalOutput += txOutput.getValue();
|
||||
// Handle change from genesis transaction, only count outputs below the issuance amount as BSQ outputs
|
||||
if (totalOutput <= readableBsqBlockChain.getIssuedAmount().getValue()) {
|
||||
txOutput.setUnspent(true);
|
||||
txOutput.setVerified(true);
|
||||
writableBsqBlockChain.addUnspentTxOutput(txOutput);
|
||||
}
|
||||
}
|
||||
tx.setTxType(TxType.GENESIS);
|
||||
|
||||
writableBsqBlockChain.setGenesisTx(tx);
|
||||
|
|
Loading…
Add table
Reference in a new issue