mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-26 01:56:44 +00:00
introduce general purpose hash index record
This commit is contained in:
parent
083288061f
commit
3a557e3af8
3 changed files with 7 additions and 28 deletions
|
@ -26,8 +26,8 @@ if(os.macOsX) {
|
||||||
osName = "osx"
|
osName = "osx"
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceCompatibility = 11
|
sourceCompatibility = 16
|
||||||
targetCompatibility = 11
|
targetCompatibility = 16
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
package com.sparrowwallet.drongo.protocol;
|
||||||
|
|
||||||
|
public record HashIndex(Sha256Hash hash, long index) {}
|
|
@ -1,12 +1,12 @@
|
||||||
package com.sparrowwallet.drongo.wallet;
|
package com.sparrowwallet.drongo.wallet;
|
||||||
|
|
||||||
|
import com.sparrowwallet.drongo.protocol.HashIndex;
|
||||||
import com.sparrowwallet.drongo.protocol.Sha256Hash;
|
import com.sparrowwallet.drongo.protocol.Sha256Hash;
|
||||||
import com.sparrowwallet.drongo.protocol.Transaction;
|
import com.sparrowwallet.drongo.protocol.Transaction;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class BlockTransaction extends BlockTransactionHash implements Comparable<BlockTransaction> {
|
public class BlockTransaction extends BlockTransactionHash implements Comparable<BlockTransaction> {
|
||||||
|
@ -67,7 +67,7 @@ public class BlockTransaction extends BlockTransactionHash implements Comparable
|
||||||
}
|
}
|
||||||
|
|
||||||
return blockchainTransaction.getTransaction().getInputs().stream()
|
return blockchainTransaction.getTransaction().getInputs().stream()
|
||||||
.map(txInput -> new HashIndex(txInput.getOutpoint().getHash(), (int)txInput.getOutpoint().getIndex()))
|
.map(txInput -> new HashIndex(txInput.getOutpoint().getHash(), txInput.getOutpoint().getIndex()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,28 +80,4 @@ public class BlockTransaction extends BlockTransactionHash implements Comparable
|
||||||
.map(txOutput -> new HashIndex(blockchainTransaction.getHash(), txOutput.getIndex()))
|
.map(txOutput -> new HashIndex(blockchainTransaction.getHash(), txOutput.getIndex()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class HashIndex {
|
|
||||||
public Sha256Hash hash;
|
|
||||||
public int index;
|
|
||||||
|
|
||||||
public HashIndex(Sha256Hash hash, int index) {
|
|
||||||
this.hash = hash;
|
|
||||||
this.index = index;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
HashIndex hashIndex = (HashIndex) o;
|
|
||||||
return index == hashIndex.index &&
|
|
||||||
hash.equals(hashIndex.hash);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(hash, index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue