mirror of
https://github.com/LBRYFoundation/lbry-database-java.git
synced 2025-08-23 09:27:22 +00:00
Add classes
This commit is contained in:
parent
07a5b0131b
commit
770b6c8cf0
123 changed files with 4098 additions and 0 deletions
65
src/main/java/com/lbry/database/Prefix.java
Normal file
65
src/main/java/com/lbry/database/Prefix.java
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
package com.lbry.database;
|
||||||
|
|
||||||
|
public enum Prefix{
|
||||||
|
CLAIM_TO_SUPPORT('K'),
|
||||||
|
SUPPORT_TO_CLAIM('L'),
|
||||||
|
|
||||||
|
CLAIM_TO_TXO('E'),
|
||||||
|
TXO_TO_CLAIM('G'),
|
||||||
|
|
||||||
|
CLAIM_TO_CHANNEL('I'),
|
||||||
|
CHANNEL_TO_CLAIM('J'),
|
||||||
|
|
||||||
|
CLAIM_SHORT_ID_PREFIX('F'),
|
||||||
|
BID_ORDER('D'),
|
||||||
|
CLAIM_EXPIRATION('O'),
|
||||||
|
|
||||||
|
CLAIM_TAKEOVER('P'),
|
||||||
|
PENDING_ACTIVATION('Q'),
|
||||||
|
ACTIVATED_CLAIM_AND_SUPPORT('R'),
|
||||||
|
ACTIVE_AMOUNT('S'),
|
||||||
|
|
||||||
|
REPOST('V'),
|
||||||
|
REPOSTED_CLAIM('W'),
|
||||||
|
|
||||||
|
UNDO('M'),
|
||||||
|
TOUCHED_OR_DELETED('Y'),
|
||||||
|
|
||||||
|
TX('B'),
|
||||||
|
BLOCK_HASH('C'),
|
||||||
|
HEADER('H'),
|
||||||
|
TX_NUM('N'),
|
||||||
|
TX_COUNT('T'),
|
||||||
|
TX_HASH('X'),
|
||||||
|
UTXO('u'),
|
||||||
|
HASHX_UTXO('h'),
|
||||||
|
HASHX_HISTORY('x'),
|
||||||
|
DB_STATE('s'),
|
||||||
|
CHANNEL_COUNT('Z'),
|
||||||
|
SUPPORT_AMOUNT('a'),
|
||||||
|
BLOCK_TX('b'),
|
||||||
|
TRENDING_NOTIFICATION('c'),
|
||||||
|
MEMPOOL_TX('d'),
|
||||||
|
TOUCHED_HASHX('e'),
|
||||||
|
HASHX_STATUS('f'),
|
||||||
|
HASHX_MEMPOOL_STATUS('g'),
|
||||||
|
REPOSTED_COUNT('j'),
|
||||||
|
EFFECTIVE_AMOUNT('i'),
|
||||||
|
FUTURE_EFFECTIVE_AMOUNT('k'),
|
||||||
|
HASHX_HISTORY_HASH('l');
|
||||||
|
|
||||||
|
private final byte value;
|
||||||
|
|
||||||
|
Prefix(char value){
|
||||||
|
this((byte) value);
|
||||||
|
}
|
||||||
|
|
||||||
|
Prefix(byte value){
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte getValue(){
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
345
src/main/java/com/lbry/database/PrefixDB.java
Normal file
345
src/main/java/com/lbry/database/PrefixDB.java
Normal file
|
@ -0,0 +1,345 @@
|
||||||
|
package com.lbry.database;
|
||||||
|
|
||||||
|
import com.lbry.database.revert.RevertibleDelete;
|
||||||
|
import com.lbry.database.revert.RevertibleOperation;
|
||||||
|
import com.lbry.database.revert.RevertibleOperationStack;
|
||||||
|
import com.lbry.database.revert.RevertiblePut;
|
||||||
|
import com.lbry.database.rows.*;
|
||||||
|
import org.rocksdb.*;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class for a revertible RocksDB database: A RocksDB database where each set of applied changes can be undone.
|
||||||
|
*/
|
||||||
|
public class PrefixDB{
|
||||||
|
|
||||||
|
private final List<ColumnFamilyHandle> columnFamilyHandles;
|
||||||
|
private final RocksDB database;
|
||||||
|
private final RevertibleOperationStack operationStack;
|
||||||
|
private final int maxUndoDepth;
|
||||||
|
|
||||||
|
public final ClaimToSupportPrefixRow claim_to_support;
|
||||||
|
public final SupportToClaimPrefixRow support_to_claim;
|
||||||
|
public final ClaimToTXOPrefixRow claim_to_txo;
|
||||||
|
public final TXOToClaimPrefixRow txo_to_claim;
|
||||||
|
public final ClaimToChannelPrefixRow claim_to_channel;
|
||||||
|
public final ChannelToClaimPrefixRow channel_to_claim;
|
||||||
|
public final ClaimShortIDPrefixRow claim_short_id;
|
||||||
|
public final ClaimExpirationPrefixRow claim_expiration;
|
||||||
|
public final ClaimTakeoverPrefixRow claim_takeover;
|
||||||
|
public final PendingActivationPrefixRow pending_activation;
|
||||||
|
public final ActivatedPrefixRow activated;
|
||||||
|
public final ActiveAmountPrefixRow active_amount;
|
||||||
|
public final BidOrderPrefixRow bid_order;
|
||||||
|
public final RepostPrefixRow repost;
|
||||||
|
public final RepostedPrefixRow reposted_claim;
|
||||||
|
public final RepostedCountPrefixRow reposted_count;
|
||||||
|
public final UndoPrefixRow undo;
|
||||||
|
public final UTXOPrefixRow utxo;
|
||||||
|
public final HashXUTXOPrefixRow hashX_utxo;
|
||||||
|
public final HashXHistoryPrefixRow hashX_history;
|
||||||
|
public final BlockHashPrefixRow block_hash;
|
||||||
|
public final TxCountPrefixRow tx_count;
|
||||||
|
public final TXHashPrefixRow tx_hash;
|
||||||
|
public final TXNumPrefixRow tx_num;
|
||||||
|
public final TXPrefixRow tx;
|
||||||
|
public final BlockHeaderPrefixRow header;
|
||||||
|
public final TouchedOrDeletedPrefixRow touched_or_deleted;
|
||||||
|
public final ChannelCountPrefixRow channel_count;
|
||||||
|
public final DBStatePrefixRow db_state;
|
||||||
|
public final SupportAmountPrefixRow support_amount;
|
||||||
|
public final BlockTxsPrefixRow block_txs;
|
||||||
|
public final MempoolTXPrefixRow mempool_tx;
|
||||||
|
public final TrendingNotificationPrefixRow trending_notification;
|
||||||
|
public final TouchedHashXPrefixRow touched_hashX;
|
||||||
|
public final HashXStatusPrefixRow hashX_status;
|
||||||
|
public final HashXMempoolStatusPrefixRow hashX_mempool_status;
|
||||||
|
public final EffectiveAmountPrefixRow effective_amount;
|
||||||
|
public final FutureEffectiveAmountPrefixRow future_effective_amount;
|
||||||
|
public final HashXHistoryHasherPrefixRow hashX_history_hasher;
|
||||||
|
|
||||||
|
public PrefixDB(String path) throws RocksDBException {
|
||||||
|
this(path,64);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PrefixDB(String path,int maxOpenFiles) throws RocksDBException{
|
||||||
|
this(path,maxOpenFiles,null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PrefixDB(String path,int maxOpenFiles,String secondaryPath) throws RocksDBException{
|
||||||
|
this(path,maxOpenFiles,secondaryPath,200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PrefixDB(String path,int maxOpenFiles,String secondaryPath,int maxUndoDepth) throws RocksDBException{
|
||||||
|
List<ColumnFamilyDescriptor> columnFamilyDescriptors = new ArrayList<>();
|
||||||
|
columnFamilyDescriptors.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
||||||
|
for(Prefix prefix : Prefix.values()){
|
||||||
|
byte[] name = new byte[]{prefix.getValue()};
|
||||||
|
ColumnFamilyDescriptor descriptor = new ColumnFamilyDescriptor(name);
|
||||||
|
columnFamilyDescriptors.add(descriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.columnFamilyHandles = new ArrayList<>();
|
||||||
|
|
||||||
|
Options options = new Options()
|
||||||
|
.setCreateIfMissing(true)
|
||||||
|
.setUseFsync(false)
|
||||||
|
.setTargetFileSizeBase(33554432)
|
||||||
|
.setMaxOpenFiles(secondaryPath==null?maxOpenFiles:-1)
|
||||||
|
.setCreateMissingColumnFamilies(true);
|
||||||
|
|
||||||
|
this.database = RocksDB.open(new DBOptions(options),path,columnFamilyDescriptors,this.columnFamilyHandles);
|
||||||
|
|
||||||
|
this.operationStack = new RevertibleOperationStack();
|
||||||
|
|
||||||
|
this.maxUndoDepth = maxUndoDepth;
|
||||||
|
|
||||||
|
this.claim_to_support = new ClaimToSupportPrefixRow(this);
|
||||||
|
this.support_to_claim = new SupportToClaimPrefixRow(this);
|
||||||
|
this.claim_to_txo = new ClaimToTXOPrefixRow(this);
|
||||||
|
this.txo_to_claim = new TXOToClaimPrefixRow(this);
|
||||||
|
this.claim_to_channel = new ClaimToChannelPrefixRow(this);
|
||||||
|
this.channel_to_claim = new ChannelToClaimPrefixRow(this);
|
||||||
|
this.claim_short_id = new ClaimShortIDPrefixRow(this);
|
||||||
|
this.claim_expiration = new ClaimExpirationPrefixRow(this);
|
||||||
|
this.claim_takeover = new ClaimTakeoverPrefixRow(this);
|
||||||
|
this.pending_activation = new PendingActivationPrefixRow(this);
|
||||||
|
this.activated = new ActivatedPrefixRow(this);
|
||||||
|
this.active_amount = new ActiveAmountPrefixRow(this);
|
||||||
|
this.bid_order = new BidOrderPrefixRow(this);
|
||||||
|
this.repost = new RepostPrefixRow(this);
|
||||||
|
this.reposted_claim = new RepostedPrefixRow(this);
|
||||||
|
this.reposted_count = new RepostedCountPrefixRow(this);
|
||||||
|
this.undo = new UndoPrefixRow(this);
|
||||||
|
this.utxo = new UTXOPrefixRow(this);
|
||||||
|
this.hashX_utxo = new HashXUTXOPrefixRow(this);
|
||||||
|
this.hashX_history = new HashXHistoryPrefixRow(this);
|
||||||
|
this.block_hash = new BlockHashPrefixRow(this);
|
||||||
|
this.tx_count = new TxCountPrefixRow(this);
|
||||||
|
this.tx_hash = new TXHashPrefixRow(this);
|
||||||
|
this.tx_num = new TXNumPrefixRow(this);
|
||||||
|
this.tx = new TXPrefixRow(this);
|
||||||
|
this.header = new BlockHeaderPrefixRow(this);
|
||||||
|
this.touched_or_deleted = new TouchedOrDeletedPrefixRow(this);
|
||||||
|
this.channel_count = new ChannelCountPrefixRow(this);
|
||||||
|
this.db_state = new DBStatePrefixRow(this);
|
||||||
|
this.support_amount = new SupportAmountPrefixRow(this);
|
||||||
|
this.block_txs = new BlockTxsPrefixRow(this);
|
||||||
|
this.mempool_tx = new MempoolTXPrefixRow(this);
|
||||||
|
this.trending_notification = new TrendingNotificationPrefixRow(this);
|
||||||
|
this.touched_hashX = new TouchedHashXPrefixRow(this);
|
||||||
|
this.hashX_status = new HashXStatusPrefixRow(this);
|
||||||
|
this.hashX_mempool_status = new HashXMempoolStatusPrefixRow(this);
|
||||||
|
this.effective_amount = new EffectiveAmountPrefixRow(this);
|
||||||
|
this.future_effective_amount = new FutureEffectiveAmountPrefixRow(this);
|
||||||
|
this.hashX_history_hasher = new HashXHistoryHasherPrefixRow(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write staged changes to the database without keeping undo information. Changes written cannot be undone.
|
||||||
|
*/
|
||||||
|
public void unsafeCommit(){
|
||||||
|
this.applyStash();
|
||||||
|
try{
|
||||||
|
//TODO
|
||||||
|
}finally{
|
||||||
|
this.operationStack.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void commit(){
|
||||||
|
this.applyStash();
|
||||||
|
try{
|
||||||
|
//TODO
|
||||||
|
}finally{
|
||||||
|
this.operationStack.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rollback(int height,byte[] blockHash){
|
||||||
|
try{
|
||||||
|
//TODO
|
||||||
|
}finally{
|
||||||
|
this.operationStack.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void applyStash(){
|
||||||
|
this.operationStack.validateAndApplyStashedOperations();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get value by prefixed key.
|
||||||
|
* @param key The prefixed key.
|
||||||
|
* @return The value or null.
|
||||||
|
* @throws RocksDBException The exception.
|
||||||
|
*/
|
||||||
|
public byte[] get(byte[] key) throws RocksDBException{
|
||||||
|
return this.get(key,true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get value by prefixed key.
|
||||||
|
* @param key The prefixed key.
|
||||||
|
* @param fillCache Fill cache option.
|
||||||
|
* @return The value or null.
|
||||||
|
* @throws RocksDBException The exception.
|
||||||
|
*/
|
||||||
|
public byte[] get(byte[] key,boolean fillCache) throws RocksDBException{
|
||||||
|
ColumnFamilyHandle columnFamily = null;
|
||||||
|
for(ColumnFamilyHandle handle : this.columnFamilyHandles){
|
||||||
|
if(key.length>0 && Arrays.equals(handle.getName(),new byte[]{key[0]})){
|
||||||
|
columnFamily = handle;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ReadOptions options = new ReadOptions().setFillCache(fillCache);
|
||||||
|
byte[] value = this.database.get(columnFamily,options,key);
|
||||||
|
options.close();
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get multiple values by prefixed keys.
|
||||||
|
* @param keys The prefixed keys.
|
||||||
|
* @return The values.
|
||||||
|
* @throws RocksDBException The exception.
|
||||||
|
*/
|
||||||
|
public List<byte[]> multiGet(List<byte[]> keys) throws RocksDBException{
|
||||||
|
return this.multiGet(keys,true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get multiple values by prefixed keys.
|
||||||
|
* @param keys The prefixed keys.
|
||||||
|
* @param fillCache Fill cache option.
|
||||||
|
* @return The values.
|
||||||
|
* @throws RocksDBException The exception.
|
||||||
|
*/
|
||||||
|
public List<byte[]> multiGet(List<byte[]> keys,boolean fillCache) throws RocksDBException{
|
||||||
|
List<ColumnFamilyHandle> columnFamilies = new ArrayList<>();
|
||||||
|
for(byte[] key : keys){
|
||||||
|
for(ColumnFamilyHandle handle : this.columnFamilyHandles){
|
||||||
|
if(Arrays.equals(handle.getName(),new byte[]{key[0]})){
|
||||||
|
columnFamilies.add(handle);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ReadOptions options = new ReadOptions().setFillCache(fillCache);
|
||||||
|
List<byte[]> values = this.database.multiGetAsList(options,columnFamilies,keys);
|
||||||
|
options.close();
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stash multiple items for deletion.
|
||||||
|
* @param items The items.
|
||||||
|
*/
|
||||||
|
public void multiDelete(Map<byte[],byte[]> items){
|
||||||
|
this.operationStack.stashOperations(items.entrySet().stream().map((entry) -> new RevertibleDelete(entry.getKey(),entry.getValue())).toArray(RevertibleOperation[]::new));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stash multiple items for putting.
|
||||||
|
* @param items The items.
|
||||||
|
*/
|
||||||
|
public void multiPut(Map<byte[],byte[]> items){
|
||||||
|
this.operationStack.stashOperations(items.entrySet().stream().map((entry) -> new RevertiblePut(entry.getKey(),entry.getValue())).toArray(RevertibleOperation[]::new));
|
||||||
|
}
|
||||||
|
|
||||||
|
public RocksIterator iterator(){
|
||||||
|
return this.iterator(null,null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RocksIterator iterator(ReadOptions readOptions){
|
||||||
|
return this.iterator(null,readOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RocksIterator iterator(ColumnFamilyHandle columnFamily){
|
||||||
|
return this.iterator(columnFamily,null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RocksIterator iterator(ColumnFamilyHandle columnFamily,ReadOptions readOptions){
|
||||||
|
if(columnFamily==null && readOptions==null){
|
||||||
|
return this.database.newIterator();
|
||||||
|
}
|
||||||
|
if(columnFamily==null){
|
||||||
|
return this.database.newIterator(readOptions);
|
||||||
|
}
|
||||||
|
if(readOptions==null){
|
||||||
|
return this.database.newIterator(columnFamily);
|
||||||
|
}
|
||||||
|
return this.database.newIterator(columnFamily,readOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close database.
|
||||||
|
*/
|
||||||
|
public void close(){
|
||||||
|
this.database.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tryCatchUpWithPrimary() throws RocksDBException{
|
||||||
|
this.database.tryCatchUpWithPrimary();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stash item for deletion.
|
||||||
|
* @param key The item prefixed key.
|
||||||
|
* @param value The value.
|
||||||
|
*/
|
||||||
|
public void stashRawDelete(byte[] key,byte[] value){
|
||||||
|
this.operationStack.stashOperations(new RevertibleOperation[]{
|
||||||
|
new RevertibleDelete(key,value),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stash item for putting.
|
||||||
|
* @param key The item prefixed key.
|
||||||
|
* @param value The value.
|
||||||
|
*/
|
||||||
|
public void stashRawPut(byte[] key,byte[] value){
|
||||||
|
this.operationStack.stashOperations(new RevertibleOperation[]{
|
||||||
|
new RevertiblePut(key,value),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public int estimateNumKeys() throws RocksDBException{
|
||||||
|
return this.estimateNumKeys(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int estimateNumKeys(ColumnFamilyHandle columnFamily) throws RocksDBException{
|
||||||
|
return Integer.parseInt(this.database.getProperty(columnFamily,"rocksdb.estimate-num-keys"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean keyMayExist(byte[] key) throws RocksDBException{
|
||||||
|
ColumnFamilyHandle columnFamily = null;
|
||||||
|
for(ColumnFamilyHandle handle : this.columnFamilyHandles){
|
||||||
|
if(key.length>0 && Arrays.equals(handle.getName(),new byte[]{key[0]})){
|
||||||
|
columnFamily = handle;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.database.keyMayExist(columnFamily,ByteBuffer.wrap(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ColumnFamilyHandle getColumnFamilyByPrefix(Prefix prefix) throws RocksDBException{
|
||||||
|
if(prefix==null){
|
||||||
|
return this.database.getDefaultColumnFamily();
|
||||||
|
}
|
||||||
|
for(ColumnFamilyHandle columnFamily : this.columnFamilyHandles){
|
||||||
|
if(Arrays.equals(columnFamily.getName(),new byte[]{prefix.getValue()})){
|
||||||
|
return columnFamily;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
18
src/main/java/com/lbry/database/keys/ActivationKey.java
Normal file
18
src/main/java/com/lbry/database/keys/ActivationKey.java
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
public class ActivationKey implements KeyInterface {
|
||||||
|
|
||||||
|
public byte txo_type;
|
||||||
|
public int tx_num;
|
||||||
|
public short position;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ActivationKey{" +
|
||||||
|
"txo_type=" + txo_type +
|
||||||
|
", tx_num=" + tx_num +
|
||||||
|
", position=" + position +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
24
src/main/java/com/lbry/database/keys/ActiveAmountKey.java
Normal file
24
src/main/java/com/lbry/database/keys/ActiveAmountKey.java
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class ActiveAmountKey implements KeyInterface {
|
||||||
|
|
||||||
|
public byte[] claim_hash;
|
||||||
|
public byte txo_type;
|
||||||
|
public int activation_height;
|
||||||
|
public int tx_num;
|
||||||
|
public short position;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ActiveAmountKey{" +
|
||||||
|
"claim_hash=" + Arrays.toString(claim_hash) +
|
||||||
|
", txo_type=" + txo_type +
|
||||||
|
", activation_height=" + activation_height +
|
||||||
|
", tx_num=" + tx_num +
|
||||||
|
", position=" + position +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
20
src/main/java/com/lbry/database/keys/BidOrderKey.java
Normal file
20
src/main/java/com/lbry/database/keys/BidOrderKey.java
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
public class BidOrderKey implements KeyInterface {
|
||||||
|
|
||||||
|
public String normalized_name;
|
||||||
|
public long effective_amount;
|
||||||
|
public int tx_num;
|
||||||
|
public short position;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "BidOrderKey{" +
|
||||||
|
"normalized_name='" + normalized_name + '\'' +
|
||||||
|
", effective_amount=" + effective_amount +
|
||||||
|
", tx_num=" + tx_num +
|
||||||
|
", position=" + position +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
14
src/main/java/com/lbry/database/keys/BlockHashKey.java
Normal file
14
src/main/java/com/lbry/database/keys/BlockHashKey.java
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
public class BlockHashKey implements KeyInterface {
|
||||||
|
|
||||||
|
public int height;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "BlockHashKey{" +
|
||||||
|
"height=" + height +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
14
src/main/java/com/lbry/database/keys/BlockHeaderKey.java
Normal file
14
src/main/java/com/lbry/database/keys/BlockHeaderKey.java
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
public class BlockHeaderKey implements KeyInterface {
|
||||||
|
|
||||||
|
public int height;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "BlockHeaderKey{" +
|
||||||
|
"height=" + height +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
14
src/main/java/com/lbry/database/keys/BlockTxsKey.java
Normal file
14
src/main/java/com/lbry/database/keys/BlockTxsKey.java
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
public class BlockTxsKey implements KeyInterface {
|
||||||
|
|
||||||
|
public int height;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "BlockTxsKey{" +
|
||||||
|
"height=" + height +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
src/main/java/com/lbry/database/keys/ChannelCountKey.java
Normal file
16
src/main/java/com/lbry/database/keys/ChannelCountKey.java
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class ChannelCountKey implements KeyInterface {
|
||||||
|
|
||||||
|
public byte[] channel_hash;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ChannelCountKey{" +
|
||||||
|
"channel_hash=" + Arrays.toString(channel_hash) +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
22
src/main/java/com/lbry/database/keys/ChannelToClaimKey.java
Normal file
22
src/main/java/com/lbry/database/keys/ChannelToClaimKey.java
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class ChannelToClaimKey implements KeyInterface {
|
||||||
|
|
||||||
|
public byte[] signing_hash;
|
||||||
|
public String name;
|
||||||
|
public int tx_num;
|
||||||
|
public short position;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ChannelToClaimKey{" +
|
||||||
|
"signing_hash=" + Arrays.toString(signing_hash) +
|
||||||
|
", name='" + name + '\'' +
|
||||||
|
", tx_num=" + tx_num +
|
||||||
|
", position=" + position +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
18
src/main/java/com/lbry/database/keys/ClaimExpirationKey.java
Normal file
18
src/main/java/com/lbry/database/keys/ClaimExpirationKey.java
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
public class ClaimExpirationKey implements KeyInterface {
|
||||||
|
|
||||||
|
public int expiration;
|
||||||
|
public int tx_num;
|
||||||
|
public short position;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ClaimExpirationKey{" +
|
||||||
|
"expiration=" + expiration +
|
||||||
|
", tx_num=" + tx_num +
|
||||||
|
", position=" + position +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
20
src/main/java/com/lbry/database/keys/ClaimShortIDKey.java
Normal file
20
src/main/java/com/lbry/database/keys/ClaimShortIDKey.java
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
public class ClaimShortIDKey implements KeyInterface {
|
||||||
|
|
||||||
|
public String normalized_name;
|
||||||
|
public String partial_claim_id;
|
||||||
|
public int root_tx_num;
|
||||||
|
public short root_position;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ClaimShortIDKey{" +
|
||||||
|
"normalized_name='" + normalized_name + '\'' +
|
||||||
|
", partial_claim_id='" + partial_claim_id + '\'' +
|
||||||
|
", root_tx_num=" + root_tx_num +
|
||||||
|
", root_position=" + root_position +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
14
src/main/java/com/lbry/database/keys/ClaimTakeoverKey.java
Normal file
14
src/main/java/com/lbry/database/keys/ClaimTakeoverKey.java
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
public class ClaimTakeoverKey implements KeyInterface {
|
||||||
|
|
||||||
|
public String normalized_name;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ClaimTakeoverKey{" +
|
||||||
|
"normalized_name='" + normalized_name + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
20
src/main/java/com/lbry/database/keys/ClaimToChannelKey.java
Normal file
20
src/main/java/com/lbry/database/keys/ClaimToChannelKey.java
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class ClaimToChannelKey implements KeyInterface {
|
||||||
|
|
||||||
|
public byte[] claim_hash;
|
||||||
|
public int tx_num;
|
||||||
|
public short position;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ClaimToChannelKey{" +
|
||||||
|
"claim_hash=" + Arrays.toString(claim_hash) +
|
||||||
|
", tx_num=" + tx_num +
|
||||||
|
", position=" + position +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
20
src/main/java/com/lbry/database/keys/ClaimToSupportKey.java
Normal file
20
src/main/java/com/lbry/database/keys/ClaimToSupportKey.java
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class ClaimToSupportKey implements KeyInterface {
|
||||||
|
|
||||||
|
public byte[] claim_hash;
|
||||||
|
public int tx_hash;
|
||||||
|
public short position;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ClaimToSupportKey{" +
|
||||||
|
"claim_hash=" + Arrays.toString(claim_hash) +
|
||||||
|
", tx_hash=" + tx_hash +
|
||||||
|
", position=" + position +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
src/main/java/com/lbry/database/keys/ClaimToTXOKey.java
Normal file
16
src/main/java/com/lbry/database/keys/ClaimToTXOKey.java
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class ClaimToTXOKey implements KeyInterface {
|
||||||
|
|
||||||
|
public byte[] claim_hash;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ClaimToTXOKey{" +
|
||||||
|
"claim_hash=" + Arrays.toString(claim_hash) +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
src/main/java/com/lbry/database/keys/EffectiveAmountKey.java
Normal file
16
src/main/java/com/lbry/database/keys/EffectiveAmountKey.java
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class EffectiveAmountKey implements KeyInterface {
|
||||||
|
|
||||||
|
public byte[] claim_hash;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "EffectiveAmountKey{" +
|
||||||
|
"claim_hash=" + Arrays.toString(claim_hash) +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
public class FutureEffectiveAmountKey implements KeyInterface {
|
||||||
|
|
||||||
|
public byte[] claim_hash;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
public class HashXHistoryHasherKey implements KeyInterface {
|
||||||
|
|
||||||
|
public byte[] hashX;
|
||||||
|
|
||||||
|
}
|
18
src/main/java/com/lbry/database/keys/HashXHistoryKey.java
Normal file
18
src/main/java/com/lbry/database/keys/HashXHistoryKey.java
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class HashXHistoryKey implements KeyInterface {
|
||||||
|
|
||||||
|
public byte[] hashX;
|
||||||
|
public int height;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "HashXHistoryKey{" +
|
||||||
|
"hashX=" + Arrays.toString(hashX) +
|
||||||
|
", height=" + height +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
7
src/main/java/com/lbry/database/keys/HashXStatusKey.java
Normal file
7
src/main/java/com/lbry/database/keys/HashXStatusKey.java
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
public class HashXStatusKey implements KeyInterface {
|
||||||
|
|
||||||
|
public byte[] hashX;
|
||||||
|
|
||||||
|
}
|
20
src/main/java/com/lbry/database/keys/HashXUTXOKey.java
Normal file
20
src/main/java/com/lbry/database/keys/HashXUTXOKey.java
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class HashXUTXOKey implements KeyInterface {
|
||||||
|
|
||||||
|
public byte[] short_tx_hash;
|
||||||
|
public int tx_num;
|
||||||
|
public short nout;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "HashXUTXOKey{" +
|
||||||
|
"short_tx_hash=" + Arrays.toString(short_tx_hash) +
|
||||||
|
", tx_num=" + tx_num +
|
||||||
|
", nout=" + nout +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
7
src/main/java/com/lbry/database/keys/KeyInterface.java
Normal file
7
src/main/java/com/lbry/database/keys/KeyInterface.java
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
public interface KeyInterface{
|
||||||
|
|
||||||
|
KeyInterface NULL = null;
|
||||||
|
|
||||||
|
}
|
16
src/main/java/com/lbry/database/keys/MempoolTxKey.java
Normal file
16
src/main/java/com/lbry/database/keys/MempoolTxKey.java
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class MempoolTxKey implements KeyInterface {
|
||||||
|
|
||||||
|
public byte[] tx_hash;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "MempoolTxKey{" +
|
||||||
|
"tx_hash=" + Arrays.toString(tx_hash) +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
public class PendingActivationKey implements KeyInterface {
|
||||||
|
|
||||||
|
public int height;
|
||||||
|
public byte txo_type;
|
||||||
|
public int tx_num;
|
||||||
|
public short position;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "PendingActivationKey{" +
|
||||||
|
"height=" + height +
|
||||||
|
", txo_type=" + txo_type +
|
||||||
|
", tx_num=" + tx_num +
|
||||||
|
", position=" + position +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
src/main/java/com/lbry/database/keys/RepostKey.java
Normal file
16
src/main/java/com/lbry/database/keys/RepostKey.java
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class RepostKey implements KeyInterface {
|
||||||
|
|
||||||
|
public byte[] claim_hash;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "RepostKey{" +
|
||||||
|
"claim_hash=" + Arrays.toString(claim_hash) +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
src/main/java/com/lbry/database/keys/RepostedCountKey.java
Normal file
16
src/main/java/com/lbry/database/keys/RepostedCountKey.java
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class RepostedCountKey implements KeyInterface {
|
||||||
|
|
||||||
|
public byte[] claim_hash;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "RepostedCountKey{" +
|
||||||
|
"claim_hash=" + Arrays.toString(claim_hash) +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
20
src/main/java/com/lbry/database/keys/RepostedKey.java
Normal file
20
src/main/java/com/lbry/database/keys/RepostedKey.java
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class RepostedKey implements KeyInterface {
|
||||||
|
|
||||||
|
public byte[] reposted_claim_hash;
|
||||||
|
public int tx_num;
|
||||||
|
public short position;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "RepostedKey{" +
|
||||||
|
"reposted_claim_hash=" + Arrays.toString(reposted_claim_hash) +
|
||||||
|
", tx_num=" + tx_num +
|
||||||
|
", position=" + position +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
src/main/java/com/lbry/database/keys/SupportAmountKey.java
Normal file
16
src/main/java/com/lbry/database/keys/SupportAmountKey.java
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class SupportAmountKey implements KeyInterface {
|
||||||
|
|
||||||
|
public byte[] claim_hash;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "SupportAmountKey{" +
|
||||||
|
"claim_hash=" + Arrays.toString(claim_hash) +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
src/main/java/com/lbry/database/keys/SupportToClaimKey.java
Normal file
16
src/main/java/com/lbry/database/keys/SupportToClaimKey.java
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
public class SupportToClaimKey implements KeyInterface {
|
||||||
|
|
||||||
|
public int tx_num;
|
||||||
|
public short position;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "SupportToClaimKey{" +
|
||||||
|
"tx_num=" + tx_num +
|
||||||
|
", position=" + position +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
src/main/java/com/lbry/database/keys/TXOToClaimKey.java
Normal file
16
src/main/java/com/lbry/database/keys/TXOToClaimKey.java
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
public class TXOToClaimKey implements KeyInterface {
|
||||||
|
|
||||||
|
public int tx_num;
|
||||||
|
public short position;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "TXOToClaimKey{" +
|
||||||
|
"tx_num=" + tx_num +
|
||||||
|
", position=" + position +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
14
src/main/java/com/lbry/database/keys/TouchedHashXKey.java
Normal file
14
src/main/java/com/lbry/database/keys/TouchedHashXKey.java
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
public class TouchedHashXKey implements KeyInterface {
|
||||||
|
|
||||||
|
public int height;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "TouchedHashXKey{" +
|
||||||
|
"height=" + height +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
public class TouchedOrDeletedClaimKey implements KeyInterface {
|
||||||
|
|
||||||
|
public int height;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "TouchedOrDeletedClaimKey{" +
|
||||||
|
"height=" + height +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class TrendingNotificationKey implements KeyInterface {
|
||||||
|
|
||||||
|
public int height;
|
||||||
|
public byte[] claim_hash;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "TrendingNotificationKey{" +
|
||||||
|
"height=" + height +
|
||||||
|
", claim_hash=" + Arrays.toString(claim_hash) +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
14
src/main/java/com/lbry/database/keys/TxCountKey.java
Normal file
14
src/main/java/com/lbry/database/keys/TxCountKey.java
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
public class TxCountKey implements KeyInterface {
|
||||||
|
|
||||||
|
public int height;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "TxCountKey{" +
|
||||||
|
"height=" + height +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
14
src/main/java/com/lbry/database/keys/TxHashKey.java
Normal file
14
src/main/java/com/lbry/database/keys/TxHashKey.java
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
public class TxHashKey implements KeyInterface {
|
||||||
|
|
||||||
|
public int tx_num;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "TxHashKey{" +
|
||||||
|
"tx_num=" + tx_num +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
src/main/java/com/lbry/database/keys/TxKey.java
Normal file
16
src/main/java/com/lbry/database/keys/TxKey.java
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class TxKey implements KeyInterface {
|
||||||
|
|
||||||
|
public byte[] tx_hash;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "TxKey{" +
|
||||||
|
"tx_hash=" + Arrays.toString(tx_hash) +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
src/main/java/com/lbry/database/keys/TxNumKey.java
Normal file
16
src/main/java/com/lbry/database/keys/TxNumKey.java
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class TxNumKey implements KeyInterface {
|
||||||
|
|
||||||
|
public byte[] tx_hash;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "TxNumKey{" +
|
||||||
|
"tx_hash=" + Arrays.toString(tx_hash) +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
20
src/main/java/com/lbry/database/keys/UTXOKey.java
Normal file
20
src/main/java/com/lbry/database/keys/UTXOKey.java
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class UTXOKey implements KeyInterface {
|
||||||
|
|
||||||
|
public byte[] hashX;
|
||||||
|
public int tx_num;
|
||||||
|
public short nout;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "UTXOKey{" +
|
||||||
|
"hashX=" + Arrays.toString(hashX) +
|
||||||
|
", tx_num=" + tx_num +
|
||||||
|
", nout=" + nout +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
18
src/main/java/com/lbry/database/keys/UndoKey.java
Normal file
18
src/main/java/com/lbry/database/keys/UndoKey.java
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package com.lbry.database.keys;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class UndoKey implements KeyInterface {
|
||||||
|
|
||||||
|
public long height;
|
||||||
|
public byte[] block_hash;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "UndoKey{" +
|
||||||
|
"height=" + height +
|
||||||
|
", block_hash=" + Arrays.toString(block_hash) +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
14
src/main/java/com/lbry/database/revert/RevertibleDelete.java
Normal file
14
src/main/java/com/lbry/database/revert/RevertibleDelete.java
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
package com.lbry.database.revert;
|
||||||
|
|
||||||
|
public class RevertibleDelete extends RevertibleOperation{
|
||||||
|
|
||||||
|
public RevertibleDelete(byte[] key,byte[] value){
|
||||||
|
super(key,value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RevertibleOperation invert(){
|
||||||
|
return new RevertiblePut(this.key,this.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.lbry.database.revert;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public abstract class RevertibleOperation{
|
||||||
|
|
||||||
|
protected byte[] key;
|
||||||
|
protected byte[] value;
|
||||||
|
|
||||||
|
protected boolean isPut;
|
||||||
|
|
||||||
|
public RevertibleOperation(byte[] key,byte[] value){
|
||||||
|
this.key = key;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getKey(){
|
||||||
|
return this.key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getValue(){
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDelete(){
|
||||||
|
return !this.isPut;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RevertibleOperation invert(){
|
||||||
|
throw new RuntimeException("Not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO PACK
|
||||||
|
//TODO UNPACK
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj){
|
||||||
|
if(obj instanceof RevertibleOperation){
|
||||||
|
RevertibleOperation op = (RevertibleOperation) obj;
|
||||||
|
return this.isPut==op.isPut && Arrays.equals(this.key,op.key) && Arrays.equals(this.value,op.value);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO REPR
|
||||||
|
//TODO STR
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.lbry.database.revert;
|
||||||
|
|
||||||
|
public class RevertibleOperationStack{
|
||||||
|
|
||||||
|
public void stashOperations(RevertibleOperation[] operations){
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
public void validateAndApplyStashedOperations(){
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
src/main/java/com/lbry/database/revert/RevertiblePut.java
Normal file
16
src/main/java/com/lbry/database/revert/RevertiblePut.java
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package com.lbry.database.revert;
|
||||||
|
|
||||||
|
public class RevertiblePut extends RevertibleOperation{
|
||||||
|
|
||||||
|
protected boolean isPut = true;
|
||||||
|
|
||||||
|
public RevertiblePut(byte[] key,byte[] value){
|
||||||
|
super(key,value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RevertibleOperation invert(){
|
||||||
|
return new RevertibleDelete(this.key,this.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
59
src/main/java/com/lbry/database/rows/ActivatedPrefixRow.java
Normal file
59
src/main/java/com/lbry/database/rows/ActivatedPrefixRow.java
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.ActivationKey;
|
||||||
|
import com.lbry.database.values.ActivationValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class ActivatedPrefixRow extends PrefixRow<ActivationKey,ActivationValue>{
|
||||||
|
|
||||||
|
public ActivatedPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.ACTIVATED_CLAIM_AND_SUPPORT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(ActivationKey key) {
|
||||||
|
return ByteBuffer.allocate(1+1+4+2).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).put(key.txo_type).putInt(key.tx_num).putShort(key.position).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActivationKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ActivationKey keyObj = new ActivationKey();
|
||||||
|
keyObj.txo_type = bb.get();
|
||||||
|
keyObj.tx_num = bb.getInt();
|
||||||
|
keyObj.position = bb.getShort();
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(ActivationValue value) {
|
||||||
|
byte[] strBytes = value.normalized_name.getBytes();
|
||||||
|
return ByteBuffer.allocate(4+20+2+strBytes.length).order(ByteOrder.BIG_ENDIAN).putInt(value.height).put(value.claim_hash).putShort((short) strBytes.length).put(strBytes).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActivationValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
ActivationValue valueObj = new ActivationValue();
|
||||||
|
valueObj.height = bb.getInt();
|
||||||
|
valueObj.claim_hash = new byte[20];
|
||||||
|
bb.get(valueObj.claim_hash);
|
||||||
|
byte[] strBytes = new byte[bb.getShort()];
|
||||||
|
bb.get(strBytes);
|
||||||
|
valueObj.normalized_name = new String(strBytes);
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.ActiveAmountKey;
|
||||||
|
import com.lbry.database.values.ActiveAmountValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class ActiveAmountPrefixRow extends PrefixRow<ActiveAmountKey,ActiveAmountValue>{
|
||||||
|
|
||||||
|
public ActiveAmountPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.ACTIVE_AMOUNT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(ActiveAmountKey key) {
|
||||||
|
return ByteBuffer.allocate(1+20+1+4+4+2).order(ByteOrder.BIG_ENDIAN)
|
||||||
|
.put(this.prefix().getValue())
|
||||||
|
.put(key.claim_hash)
|
||||||
|
.put(key.txo_type)
|
||||||
|
.putInt(key.activation_height)
|
||||||
|
.putInt(key.tx_num)
|
||||||
|
.putShort(key.position)
|
||||||
|
.array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActiveAmountKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ActiveAmountKey keyObj = new ActiveAmountKey();
|
||||||
|
keyObj.claim_hash = new byte[20];
|
||||||
|
bb.get(keyObj.claim_hash);
|
||||||
|
keyObj.txo_type = bb.get();
|
||||||
|
keyObj.activation_height = bb.getInt();
|
||||||
|
keyObj.tx_num = bb.getInt();
|
||||||
|
keyObj.position = bb.getShort();
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(ActiveAmountValue value) {
|
||||||
|
return ByteBuffer.allocate(8).order(ByteOrder.BIG_ENDIAN).putLong(value.amount).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActiveAmountValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
ActiveAmountValue valueObj = new ActiveAmountValue();
|
||||||
|
valueObj.amount = bb.getLong();
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
65
src/main/java/com/lbry/database/rows/BidOrderPrefixRow.java
Normal file
65
src/main/java/com/lbry/database/rows/BidOrderPrefixRow.java
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.BidOrderKey;
|
||||||
|
import com.lbry.database.values.BidOrderValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class BidOrderPrefixRow extends PrefixRow<BidOrderKey,BidOrderValue>{
|
||||||
|
|
||||||
|
public BidOrderPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.BID_ORDER;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(BidOrderKey key) {
|
||||||
|
byte[] strBytes = key.normalized_name.getBytes();
|
||||||
|
return ByteBuffer.allocate(1+2+strBytes.length+8+4+2).order(ByteOrder.BIG_ENDIAN)
|
||||||
|
.put(this.prefix().getValue())
|
||||||
|
.putShort((short) strBytes.length)
|
||||||
|
.put(strBytes)
|
||||||
|
.putLong(0xFFFFFFFFFFFFFFFFL - key.effective_amount)
|
||||||
|
.putInt(key.tx_num)
|
||||||
|
.putShort(key.position)
|
||||||
|
.array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BidOrderKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
BidOrderKey keyObj = new BidOrderKey();
|
||||||
|
byte[] strBytes = new byte[bb.getShort()];
|
||||||
|
bb.get(strBytes);
|
||||||
|
keyObj.normalized_name = new String(strBytes);
|
||||||
|
keyObj.effective_amount = 0xFFFFFFFFFFFFFFFFL - bb.getLong();
|
||||||
|
keyObj.tx_num = bb.getInt();
|
||||||
|
keyObj.position = bb.getShort();
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(BidOrderValue value) {
|
||||||
|
return ByteBuffer.allocate(20).order(ByteOrder.BIG_ENDIAN).put(value.claim_hash).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BidOrderValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
BidOrderValue valueObj = new BidOrderValue();
|
||||||
|
valueObj.claim_hash = new byte[20];
|
||||||
|
bb.get(valueObj.claim_hash);
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
52
src/main/java/com/lbry/database/rows/BlockHashPrefixRow.java
Normal file
52
src/main/java/com/lbry/database/rows/BlockHashPrefixRow.java
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.BlockHashKey;
|
||||||
|
import com.lbry.database.values.BlockHashValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class BlockHashPrefixRow extends PrefixRow<BlockHashKey,BlockHashValue>{
|
||||||
|
|
||||||
|
public BlockHashPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.BLOCK_HASH;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(BlockHashKey key) {
|
||||||
|
return ByteBuffer.allocate(1+4).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).putInt(key.height).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockHashKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
BlockHashKey keyObj = new BlockHashKey();
|
||||||
|
keyObj.height = bb.getInt();
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(BlockHashValue value) {
|
||||||
|
return ByteBuffer.allocate(32).order(ByteOrder.BIG_ENDIAN).put(value.block_hash).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockHashValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
BlockHashValue valueObj = new BlockHashValue();
|
||||||
|
valueObj.block_hash = new byte[32];
|
||||||
|
bb.get(valueObj.block_hash);
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.BlockHeaderKey;
|
||||||
|
import com.lbry.database.values.BlockHeaderValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class BlockHeaderPrefixRow extends PrefixRow<BlockHeaderKey,BlockHeaderValue>{
|
||||||
|
|
||||||
|
public BlockHeaderPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.HEADER;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(BlockHeaderKey key) {
|
||||||
|
return ByteBuffer.allocate(1+4).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).putInt(key.height).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockHeaderKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
BlockHeaderKey keyObj = new BlockHeaderKey();
|
||||||
|
keyObj.height = bb.getInt();
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(BlockHeaderValue value) {
|
||||||
|
return ByteBuffer.allocate(112).order(ByteOrder.BIG_ENDIAN).put(value.header).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockHeaderValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value);
|
||||||
|
BlockHeaderValue valueObj = new BlockHeaderValue();
|
||||||
|
valueObj.header = new byte[112];
|
||||||
|
bb.get(valueObj.header);
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
60
src/main/java/com/lbry/database/rows/BlockTxsPrefixRow.java
Normal file
60
src/main/java/com/lbry/database/rows/BlockTxsPrefixRow.java
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.BlockTxsKey;
|
||||||
|
import com.lbry.database.values.BlockTxsValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class BlockTxsPrefixRow extends PrefixRow<BlockTxsKey,BlockTxsValue>{
|
||||||
|
|
||||||
|
public BlockTxsPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.BLOCK_TX;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(BlockTxsKey key) {
|
||||||
|
return ByteBuffer.allocate(1+4).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).putInt(key.height).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockTxsKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
BlockTxsKey keyObj = new BlockTxsKey();
|
||||||
|
keyObj.height = bb.getInt();
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(BlockTxsValue value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.allocate(value.tx_hashes.size()*32).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
for(byte[] txHash : value.tx_hashes){
|
||||||
|
bb.put(txHash);
|
||||||
|
}
|
||||||
|
return bb.array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockTxsValue unpackValue(byte[] value){
|
||||||
|
BlockTxsValue valueObj = new BlockTxsValue();
|
||||||
|
valueObj.tx_hashes = new ArrayList<>();
|
||||||
|
for(int i=0;i<value.length/32;i++){
|
||||||
|
byte[] txHash = new byte[32];
|
||||||
|
System.arraycopy(value,i*32,txHash,0,txHash.length);
|
||||||
|
valueObj.tx_hashes.add(txHash);
|
||||||
|
}
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.ChannelCountKey;
|
||||||
|
import com.lbry.database.values.ChannelCountValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class ChannelCountPrefixRow extends PrefixRow<ChannelCountKey,ChannelCountValue>{
|
||||||
|
|
||||||
|
public ChannelCountPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.CHANNEL_COUNT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(ChannelCountKey key) {
|
||||||
|
return ByteBuffer.allocate(1+20).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).put(key.channel_hash).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChannelCountKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ChannelCountKey keyObj = new ChannelCountKey();
|
||||||
|
keyObj.channel_hash = new byte[20];
|
||||||
|
bb.get(keyObj.channel_hash);
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(ChannelCountValue value) {
|
||||||
|
return ByteBuffer.allocate(4).order(ByteOrder.BIG_ENDIAN).putInt(value.count).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChannelCountValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
ChannelCountValue valueObj = new ChannelCountValue();
|
||||||
|
valueObj.count = bb.getInt();
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.ChannelToClaimKey;
|
||||||
|
import com.lbry.database.values.ChannelToClaimValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class ChannelToClaimPrefixRow extends PrefixRow<ChannelToClaimKey,ChannelToClaimValue>{
|
||||||
|
|
||||||
|
public ChannelToClaimPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.CHANNEL_TO_CLAIM;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(ChannelToClaimKey key) {
|
||||||
|
byte[] strBytes = key.name.getBytes();
|
||||||
|
return ByteBuffer.allocate(1+20+2+strBytes.length+4+2).order(ByteOrder.BIG_ENDIAN)
|
||||||
|
.put(this.prefix().getValue())
|
||||||
|
.put(key.signing_hash)
|
||||||
|
.putShort((short) strBytes.length)
|
||||||
|
.put(strBytes)
|
||||||
|
.putInt(key.tx_num)
|
||||||
|
.putShort(key.position)
|
||||||
|
.array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChannelToClaimKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ChannelToClaimKey keyObj = new ChannelToClaimKey();
|
||||||
|
keyObj.signing_hash = new byte[20];
|
||||||
|
bb.get(keyObj.signing_hash);
|
||||||
|
byte[] strBytes = new byte[bb.getShort()];
|
||||||
|
bb.get(strBytes);
|
||||||
|
keyObj.name = new String(strBytes);
|
||||||
|
keyObj.tx_num = bb.getInt();
|
||||||
|
keyObj.position = bb.getShort();
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(ChannelToClaimValue value) {
|
||||||
|
return ByteBuffer.allocate(20).order(ByteOrder.BIG_ENDIAN).put(value.claim_hash).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChannelToClaimValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
ChannelToClaimValue valueObj = new ChannelToClaimValue();
|
||||||
|
valueObj.claim_hash = new byte[20];
|
||||||
|
bb.get(valueObj.claim_hash);
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.ClaimExpirationKey;
|
||||||
|
import com.lbry.database.values.ClaimExpirationValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class ClaimExpirationPrefixRow extends PrefixRow<ClaimExpirationKey,ClaimExpirationValue>{
|
||||||
|
|
||||||
|
public ClaimExpirationPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.CLAIM_EXPIRATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(ClaimExpirationKey key) {
|
||||||
|
return ByteBuffer.allocate(1+4+4+2).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).putInt(key.expiration).putInt(key.tx_num).putShort(key.position).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClaimExpirationKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ClaimExpirationKey keyObj = new ClaimExpirationKey();
|
||||||
|
keyObj.expiration = bb.getInt();
|
||||||
|
keyObj.tx_num = bb.getInt();
|
||||||
|
keyObj.position = bb.getShort();
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(ClaimExpirationValue value) {
|
||||||
|
byte[] strBytes = value.normalized_name.getBytes();
|
||||||
|
return ByteBuffer.allocate(20+2+strBytes.length).order(ByteOrder.BIG_ENDIAN).put(value.claim_hash).putShort((short) strBytes.length).put(strBytes).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClaimExpirationValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
ClaimExpirationValue valueObj = new ClaimExpirationValue();
|
||||||
|
valueObj.claim_hash = new byte[20];
|
||||||
|
bb.get(valueObj.claim_hash);
|
||||||
|
byte[] strBytes = new byte[bb.getShort()];
|
||||||
|
bb.get(strBytes);
|
||||||
|
valueObj.normalized_name = new String(strBytes);
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.ClaimShortIDKey;
|
||||||
|
import com.lbry.database.values.ClaimShortIDValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class ClaimShortIDPrefixRow extends PrefixRow<ClaimShortIDKey,ClaimShortIDValue>{
|
||||||
|
|
||||||
|
public ClaimShortIDPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.CLAIM_SHORT_ID_PREFIX;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(ClaimShortIDKey key) {
|
||||||
|
byte[] strBytesName = key.normalized_name.getBytes();
|
||||||
|
byte[] strBytesClaimID = key.partial_claim_id.getBytes();
|
||||||
|
return ByteBuffer.allocate(1+2+strBytesName.length+2+strBytesClaimID.length+4+2).order(ByteOrder.BIG_ENDIAN)
|
||||||
|
.put(this.prefix().getValue())
|
||||||
|
.putShort((short) strBytesName.length)
|
||||||
|
.put(strBytesName)
|
||||||
|
.putShort((short) strBytesClaimID.length)
|
||||||
|
.put(strBytesClaimID)
|
||||||
|
.putInt(key.root_tx_num)
|
||||||
|
.putShort(key.root_position)
|
||||||
|
.array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClaimShortIDKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ClaimShortIDKey keyObj = new ClaimShortIDKey();
|
||||||
|
byte[] strBytesName = new byte[bb.getShort()];
|
||||||
|
bb.get(strBytesName);
|
||||||
|
keyObj.normalized_name = new String(strBytesName);
|
||||||
|
byte[] strBytesClaimID = new byte[bb.getShort()];
|
||||||
|
bb.get(strBytesClaimID);
|
||||||
|
keyObj.partial_claim_id = new String(strBytesClaimID);
|
||||||
|
keyObj.root_tx_num = bb.getInt();
|
||||||
|
keyObj.root_position = bb.getShort();
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(ClaimShortIDValue value) {
|
||||||
|
return ByteBuffer.allocate(4+2).order(ByteOrder.BIG_ENDIAN).putInt(value.tx_num).putShort(value.position).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClaimShortIDValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
ClaimShortIDValue valueObj = new ClaimShortIDValue();
|
||||||
|
valueObj.tx_num = bb.getInt();
|
||||||
|
valueObj.position = bb.getShort();
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.ClaimTakeoverKey;
|
||||||
|
import com.lbry.database.values.ClaimTakeoverValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class ClaimTakeoverPrefixRow extends PrefixRow<ClaimTakeoverKey,ClaimTakeoverValue>{
|
||||||
|
|
||||||
|
public ClaimTakeoverPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.CLAIM_TAKEOVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(ClaimTakeoverKey key) {
|
||||||
|
byte[] strBytes = key.normalized_name.getBytes();
|
||||||
|
return ByteBuffer.allocate(1+2+strBytes.length).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).putShort((short) strBytes.length).put(strBytes).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClaimTakeoverKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ClaimTakeoverKey keyObj = new ClaimTakeoverKey();
|
||||||
|
byte[] strBytes = new byte[bb.getShort()];
|
||||||
|
bb.get(strBytes);
|
||||||
|
keyObj.normalized_name = new String(strBytes);
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(ClaimTakeoverValue value) {
|
||||||
|
return ByteBuffer.allocate(20+4).order(ByteOrder.BIG_ENDIAN).put(value.claim_hash).putInt(value.height).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClaimTakeoverValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
ClaimTakeoverValue valueObj = new ClaimTakeoverValue();
|
||||||
|
valueObj.claim_hash = new byte[20];
|
||||||
|
bb.get(valueObj.claim_hash);
|
||||||
|
valueObj.height = bb.getInt();
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.ClaimToChannelKey;
|
||||||
|
import com.lbry.database.values.ClaimToChannelValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class ClaimToChannelPrefixRow extends PrefixRow<ClaimToChannelKey,ClaimToChannelValue>{
|
||||||
|
|
||||||
|
public ClaimToChannelPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.CLAIM_TO_CHANNEL;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(ClaimToChannelKey key) {
|
||||||
|
return ByteBuffer.allocate(1+20+4+2).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).put(key.claim_hash).putInt(key.tx_num).putShort(key.position).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClaimToChannelKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ClaimToChannelKey keyObj = new ClaimToChannelKey();
|
||||||
|
keyObj.claim_hash = new byte[20];
|
||||||
|
bb.get(keyObj.claim_hash);
|
||||||
|
keyObj.tx_num = bb.getInt();
|
||||||
|
keyObj.position = bb.getShort();
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(ClaimToChannelValue value) {
|
||||||
|
return ByteBuffer.allocate(20).order(ByteOrder.BIG_ENDIAN).put(value.signing_hash).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClaimToChannelValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
ClaimToChannelValue valueObj = new ClaimToChannelValue();
|
||||||
|
valueObj.signing_hash = new byte[20];
|
||||||
|
bb.get(valueObj.signing_hash);
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.ClaimToSupportKey;
|
||||||
|
import com.lbry.database.values.ClaimToSupportValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class ClaimToSupportPrefixRow extends PrefixRow<ClaimToSupportKey,ClaimToSupportValue>{
|
||||||
|
|
||||||
|
public ClaimToSupportPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.CLAIM_TO_SUPPORT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(ClaimToSupportKey key) {
|
||||||
|
return ByteBuffer.allocate(1+20+4+2).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).put(key.claim_hash).putInt(key.tx_hash).putShort(key.position).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClaimToSupportKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ClaimToSupportKey keyObj = new ClaimToSupportKey();
|
||||||
|
keyObj.claim_hash = new byte[20];
|
||||||
|
bb.get(keyObj.claim_hash);
|
||||||
|
keyObj.tx_hash = bb.getInt();
|
||||||
|
keyObj.position = bb.getShort();
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(ClaimToSupportValue value) {
|
||||||
|
return ByteBuffer.allocate(8).order(ByteOrder.BIG_ENDIAN).putLong(value.amount).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClaimToSupportValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
ClaimToSupportValue valueObj = new ClaimToSupportValue();
|
||||||
|
valueObj.amount = bb.getLong();
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,72 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.ClaimToTXOKey;
|
||||||
|
import com.lbry.database.values.ClaimToTXOValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class ClaimToTXOPrefixRow extends PrefixRow<ClaimToTXOKey,ClaimToTXOValue>{
|
||||||
|
|
||||||
|
public ClaimToTXOPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.CLAIM_TO_TXO;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(ClaimToTXOKey key) {
|
||||||
|
return ByteBuffer.allocate(1+20).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).put(key.claim_hash).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClaimToTXOKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ClaimToTXOKey keyObj = new ClaimToTXOKey();
|
||||||
|
keyObj.claim_hash = new byte[20];
|
||||||
|
bb.get(keyObj.claim_hash);
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(ClaimToTXOValue value) {
|
||||||
|
byte[] strBytes = value.name.getBytes();
|
||||||
|
|
||||||
|
return ByteBuffer.allocate(4+2+4+2+8+1)
|
||||||
|
.order(ByteOrder.BIG_ENDIAN)
|
||||||
|
.putInt(value.tx_num)
|
||||||
|
.putShort(value.position)
|
||||||
|
.putInt(value.root_tx_num)
|
||||||
|
.putShort(value.root_position)
|
||||||
|
.putLong(value.amount)
|
||||||
|
.put((byte) (value.channel_signature_is_valid?0x01:0x00))
|
||||||
|
.putShort((short) strBytes.length)
|
||||||
|
.put(strBytes)
|
||||||
|
.array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClaimToTXOValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
ClaimToTXOValue valueObj = new ClaimToTXOValue();
|
||||||
|
valueObj.tx_num = bb.getInt();
|
||||||
|
valueObj.position = bb.getShort();
|
||||||
|
valueObj.root_tx_num = bb.getInt();
|
||||||
|
valueObj.root_position = bb.getShort();
|
||||||
|
valueObj.amount = bb.getLong();
|
||||||
|
valueObj.channel_signature_is_valid = bb.get()!=0x00;
|
||||||
|
byte[] strBytes = new byte[bb.getShort()];
|
||||||
|
bb.get(strBytes);
|
||||||
|
valueObj.name = new String(strBytes);
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
84
src/main/java/com/lbry/database/rows/DBStatePrefixRow.java
Normal file
84
src/main/java/com/lbry/database/rows/DBStatePrefixRow.java
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.KeyInterface;
|
||||||
|
import com.lbry.database.values.DBState;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class DBStatePrefixRow extends PrefixRow<KeyInterface,DBState>{
|
||||||
|
|
||||||
|
public DBStatePrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.DB_STATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(KeyInterface key) {
|
||||||
|
return new byte[]{Prefix.DB_STATE.getValue()};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeyInterface unpackKey(byte[] key) {
|
||||||
|
return KeyInterface.NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(DBState value) {
|
||||||
|
return ByteBuffer.allocate(1+32+4+4+32+4+4+1+1+4+4+4+4+4).order(ByteOrder.BIG_ENDIAN)
|
||||||
|
.put(this.prefix().getValue())
|
||||||
|
.put(value.genesis)
|
||||||
|
.putInt(value.height)
|
||||||
|
.putInt(value.tx_count)
|
||||||
|
.put(value.tip)
|
||||||
|
.putInt(value.utxo_flush_count)
|
||||||
|
.putInt(value.wall_time)
|
||||||
|
.put(value.bit_fields)
|
||||||
|
.put(value.db_version)
|
||||||
|
.putInt(value.hist_flush_count)
|
||||||
|
.putInt(value.comp_flush_count)
|
||||||
|
.putInt(value.comp_cursor)
|
||||||
|
.putInt(value.es_sync_height)
|
||||||
|
.putInt(value.hashX_status_last_indexed_height)
|
||||||
|
.array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DBState unpackValue(byte[] value){
|
||||||
|
int height = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN).position(32).getInt();
|
||||||
|
if(value.length==94){
|
||||||
|
value = ByteBuffer.allocate(value.length+4).order(ByteOrder.BIG_ENDIAN).put(value).putInt(height).array();
|
||||||
|
}
|
||||||
|
if(value.length==98){
|
||||||
|
value = ByteBuffer.allocate(value.length+4).order(ByteOrder.BIG_ENDIAN).put(value).putInt(height).array();
|
||||||
|
}
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
DBState valueObj = new DBState();
|
||||||
|
valueObj.genesis = new byte[32];
|
||||||
|
bb.get(valueObj.genesis);
|
||||||
|
valueObj.height = bb.getInt();
|
||||||
|
valueObj.tx_count = bb.getInt();
|
||||||
|
valueObj.tip = new byte[32];
|
||||||
|
bb.get(valueObj.tip);
|
||||||
|
valueObj.utxo_flush_count = bb.getInt();
|
||||||
|
valueObj.wall_time = bb.getInt();
|
||||||
|
valueObj.bit_fields = bb.get();
|
||||||
|
valueObj.db_version = bb.get();
|
||||||
|
valueObj.hist_flush_count = bb.getInt();
|
||||||
|
valueObj.comp_flush_count = bb.getInt();
|
||||||
|
valueObj.comp_cursor = bb.getInt();
|
||||||
|
valueObj.es_sync_height = bb.getInt();
|
||||||
|
valueObj.hashX_status_last_indexed_height = bb.getInt();
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.EffectiveAmountKey;
|
||||||
|
import com.lbry.database.values.EffectiveAmountValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class EffectiveAmountPrefixRow extends PrefixRow<EffectiveAmountKey,EffectiveAmountValue>{
|
||||||
|
|
||||||
|
public EffectiveAmountPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.EFFECTIVE_AMOUNT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(EffectiveAmountKey key) {
|
||||||
|
return ByteBuffer.allocate(1+20).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).put(key.claim_hash).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EffectiveAmountKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
EffectiveAmountKey keyObj = new EffectiveAmountKey();
|
||||||
|
keyObj.claim_hash = new byte[20];
|
||||||
|
bb.get(keyObj.claim_hash);
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(EffectiveAmountValue value) {
|
||||||
|
assert value.activated_sum >= value.activated_support_sum : "Effective amount should be larger than support sum.";
|
||||||
|
return ByteBuffer.allocate(16).order(ByteOrder.BIG_ENDIAN).putLong(value.activated_sum).putLong(value.activated_support_sum).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EffectiveAmountValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
EffectiveAmountValue valueObj = new EffectiveAmountValue();
|
||||||
|
valueObj.activated_sum = bb.getLong();
|
||||||
|
valueObj.activated_support_sum = bb.getLong();
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.FutureEffectiveAmountKey;
|
||||||
|
import com.lbry.database.values.FutureEffectiveAmountValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class FutureEffectiveAmountPrefixRow extends PrefixRow<FutureEffectiveAmountKey,FutureEffectiveAmountValue>{
|
||||||
|
|
||||||
|
public FutureEffectiveAmountPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.FUTURE_EFFECTIVE_AMOUNT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(FutureEffectiveAmountKey key) {
|
||||||
|
return ByteBuffer.allocate(1+20).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).put(key.claim_hash).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FutureEffectiveAmountKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
FutureEffectiveAmountKey keyObj = new FutureEffectiveAmountKey();
|
||||||
|
keyObj.claim_hash = new byte[20];
|
||||||
|
bb.get(keyObj.claim_hash);
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(FutureEffectiveAmountValue value) {
|
||||||
|
return ByteBuffer.allocate(8).order(ByteOrder.BIG_ENDIAN).putLong(value.future_effective_amount).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FutureEffectiveAmountValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
FutureEffectiveAmountValue valueObj = new FutureEffectiveAmountValue();
|
||||||
|
valueObj.future_effective_amount = bb.getLong();
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.HashXHistoryHasherKey;
|
||||||
|
import com.lbry.database.values.HashXHistoryHasherValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class HashXHistoryHasherPrefixRow extends PrefixRow<HashXHistoryHasherKey,HashXHistoryHasherValue>{
|
||||||
|
|
||||||
|
public HashXHistoryHasherPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.HASHX_HISTORY_HASH;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(HashXHistoryHasherKey key) {
|
||||||
|
return ByteBuffer.allocate(1+11).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).put(key.hashX).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HashXHistoryHasherKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
HashXHistoryHasherKey keyObj = new HashXHistoryHasherKey();
|
||||||
|
keyObj.hashX = new byte[11];
|
||||||
|
bb.get(keyObj.hashX);
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(HashXHistoryHasherValue value) {
|
||||||
|
//MessageDigest md;md.getProvider().
|
||||||
|
//TODO SHA-256
|
||||||
|
return new byte[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HashXHistoryHasherValue unpackValue(byte[] value) {
|
||||||
|
//TODO SHA-256
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.HashXHistoryKey;
|
||||||
|
import com.lbry.database.values.HashXHistoryValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class HashXHistoryPrefixRow extends PrefixRow<HashXHistoryKey,HashXHistoryValue>{
|
||||||
|
|
||||||
|
public HashXHistoryPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.HASHX_HISTORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(HashXHistoryKey key) {
|
||||||
|
return ByteBuffer.allocate(1+11+4).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).put(key.hashX).putInt(key.height).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HashXHistoryKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
HashXHistoryKey keyObj = new HashXHistoryKey();
|
||||||
|
keyObj.hashX = new byte[11];
|
||||||
|
bb.get(keyObj.hashX);
|
||||||
|
keyObj.height = bb.getInt();
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(HashXHistoryValue value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.allocate(value.tx_nums.size()*4).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
for(int txNum : value.tx_nums){
|
||||||
|
bb.putInt(txNum);
|
||||||
|
}
|
||||||
|
return bb.array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HashXHistoryValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
HashXHistoryValue valueObj = new HashXHistoryValue();
|
||||||
|
valueObj.tx_nums = new ArrayList<>();
|
||||||
|
for(int i=0;i<value.length/4;i++){
|
||||||
|
valueObj.tx_nums.add(bb.getInt());
|
||||||
|
}
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.HashXStatusKey;
|
||||||
|
import com.lbry.database.values.HashXStatusValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class HashXMempoolStatusPrefixRow extends PrefixRow<HashXStatusKey,HashXStatusValue>{
|
||||||
|
|
||||||
|
public HashXMempoolStatusPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.HASHX_MEMPOOL_STATUS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(HashXStatusKey key) {
|
||||||
|
return ByteBuffer.allocate(1+20).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).put(key.hashX).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HashXStatusKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
HashXStatusKey keyObj = new HashXStatusKey();
|
||||||
|
keyObj.hashX = new byte[20];
|
||||||
|
bb.get(keyObj.hashX);
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(HashXStatusValue value) {
|
||||||
|
return ByteBuffer.allocate(32).order(ByteOrder.BIG_ENDIAN).put(value.status).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HashXStatusValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
HashXStatusValue keyObj = new HashXStatusValue();
|
||||||
|
keyObj.status = new byte[32];
|
||||||
|
bb.get(keyObj.status);
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.HashXStatusKey;
|
||||||
|
import com.lbry.database.values.HashXStatusValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class HashXStatusPrefixRow extends PrefixRow<HashXStatusKey,HashXStatusValue>{
|
||||||
|
|
||||||
|
public HashXStatusPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.HASHX_STATUS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(HashXStatusKey key) {
|
||||||
|
return ByteBuffer.allocate(1+11).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).put(key.hashX).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HashXStatusKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
HashXStatusKey keyObj = new HashXStatusKey();
|
||||||
|
keyObj.hashX = new byte[11];
|
||||||
|
bb.get(keyObj.hashX);
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(HashXStatusValue value) {
|
||||||
|
return ByteBuffer.allocate(32).order(ByteOrder.BIG_ENDIAN).put(value.status).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HashXStatusValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
HashXStatusValue valueObj = new HashXStatusValue();
|
||||||
|
valueObj.status = new byte[32];
|
||||||
|
bb.get(valueObj.status);
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
55
src/main/java/com/lbry/database/rows/HashXUTXOPrefixRow.java
Normal file
55
src/main/java/com/lbry/database/rows/HashXUTXOPrefixRow.java
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.HashXUTXOKey;
|
||||||
|
import com.lbry.database.values.HashXUTXOValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class HashXUTXOPrefixRow extends PrefixRow<HashXUTXOKey,HashXUTXOValue>{
|
||||||
|
|
||||||
|
public HashXUTXOPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.HASHX_UTXO;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(HashXUTXOKey key) {
|
||||||
|
return ByteBuffer.allocate(1+4+4+2).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).put(key.short_tx_hash).putInt(key.tx_num).putShort(key.nout).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HashXUTXOKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
HashXUTXOKey keyObj = new HashXUTXOKey();
|
||||||
|
keyObj.short_tx_hash = new byte[4];
|
||||||
|
bb.get(keyObj.short_tx_hash);
|
||||||
|
keyObj.tx_num = bb.getInt();
|
||||||
|
keyObj.nout = bb.getShort();
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(HashXUTXOValue value) {
|
||||||
|
return ByteBuffer.allocate(11).order(ByteOrder.BIG_ENDIAN).put(value.hashX).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HashXUTXOValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
HashXUTXOValue valueObj = new HashXUTXOValue();
|
||||||
|
valueObj.hashX = new byte[11];
|
||||||
|
bb.get(valueObj.hashX);
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
51
src/main/java/com/lbry/database/rows/MempoolTXPrefixRow.java
Normal file
51
src/main/java/com/lbry/database/rows/MempoolTXPrefixRow.java
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.MempoolTxKey;
|
||||||
|
import com.lbry.database.values.MempoolTxValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class MempoolTXPrefixRow extends PrefixRow<MempoolTxKey,MempoolTxValue>{
|
||||||
|
|
||||||
|
public MempoolTXPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.MEMPOOL_TX;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(MempoolTxKey key) {
|
||||||
|
return ByteBuffer.allocate(1+32).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).put(key.tx_hash).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MempoolTxKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
MempoolTxKey keyObj = new MempoolTxKey();
|
||||||
|
keyObj.tx_hash = new byte[32];
|
||||||
|
bb.get(keyObj.tx_hash);
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(MempoolTxValue value) {
|
||||||
|
return value.raw_tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MempoolTxValue unpackValue(byte[] value) {
|
||||||
|
MempoolTxValue valueObj = new MempoolTxValue();
|
||||||
|
valueObj.raw_tx = value;
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,59 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.PendingActivationKey;
|
||||||
|
import com.lbry.database.values.PendingActivationValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class PendingActivationPrefixRow extends PrefixRow<PendingActivationKey,PendingActivationValue>{
|
||||||
|
|
||||||
|
public PendingActivationPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.PENDING_ACTIVATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(PendingActivationKey key) {
|
||||||
|
return ByteBuffer.allocate(1+11).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).putInt(key.height).put(key.txo_type).putInt(key.tx_num).putShort(key.position).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PendingActivationKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
PendingActivationKey keyObj = new PendingActivationKey();
|
||||||
|
keyObj.height = bb.getInt();
|
||||||
|
keyObj.txo_type = bb.get();
|
||||||
|
keyObj.tx_num = bb.getInt();
|
||||||
|
keyObj.position = bb.getShort();
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(PendingActivationValue value) {
|
||||||
|
byte[] strBytes = value.normalized_name.getBytes();
|
||||||
|
return ByteBuffer.allocate(20+2+strBytes.length).order(ByteOrder.BIG_ENDIAN).put(value.claim_hash).putShort((short) strBytes.length).put(strBytes).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PendingActivationValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
PendingActivationValue valueObj = new PendingActivationValue();
|
||||||
|
valueObj.claim_hash = new byte[20];
|
||||||
|
bb.get(valueObj.claim_hash);
|
||||||
|
byte[] strBytes = new byte[bb.getShort()];
|
||||||
|
bb.get(strBytes);
|
||||||
|
valueObj.normalized_name = new String(strBytes);
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
112
src/main/java/com/lbry/database/rows/PrefixRow.java
Normal file
112
src/main/java/com/lbry/database/rows/PrefixRow.java
Normal file
|
@ -0,0 +1,112 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.KeyInterface;
|
||||||
|
import com.lbry.database.values.ValueInterface;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.rocksdb.ColumnFamilyHandle;
|
||||||
|
import org.rocksdb.ReadOptions;
|
||||||
|
import org.rocksdb.RocksDBException;
|
||||||
|
import org.rocksdb.RocksIterator;
|
||||||
|
|
||||||
|
public abstract class PrefixRow<K extends KeyInterface,V extends ValueInterface>{
|
||||||
|
|
||||||
|
private final PrefixDB database;
|
||||||
|
|
||||||
|
public PrefixRow(PrefixDB database){
|
||||||
|
this.database = database;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RocksIterator iterate() throws RocksDBException{
|
||||||
|
return this.iterate(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RocksIterator iterate(ReadOptions readOptions) throws RocksDBException{
|
||||||
|
return this.database.iterator(this.getColumnFamily(),readOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object get(K key) throws RocksDBException{
|
||||||
|
return this.get(key,true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object get(K key,boolean fillCache) throws RocksDBException{
|
||||||
|
return this.get(key,fillCache,true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object get(K key,boolean fillCache,boolean deserializeValue) throws RocksDBException {
|
||||||
|
byte[] v = this.database.get(this.packKey(key),fillCache);
|
||||||
|
if(v!=null){
|
||||||
|
if(deserializeValue){
|
||||||
|
return this.unpackValue(v);
|
||||||
|
}
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean keyExists(K key) throws RocksDBException{
|
||||||
|
boolean keyMayExist = this.database.keyMayExist(this.packKey(key));
|
||||||
|
if(!keyMayExist){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return this.database.get(this.packKey(key),true)!=null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Object> multiGet(List<K> keys,boolean fillCache,boolean deserializeValue) throws RocksDBException{
|
||||||
|
List<byte[]> result = this.database.multiGet(keys.stream().map(this::packKey).collect(Collectors.toList()),fillCache);
|
||||||
|
return result.stream().map(v -> {
|
||||||
|
if(v!=null){
|
||||||
|
if(deserializeValue){
|
||||||
|
return this.unpackValue(v);
|
||||||
|
}
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stashMultiDelete(Map<K,V> items){
|
||||||
|
Map<byte[],byte[]> map = new LinkedHashMap<>();
|
||||||
|
for(Map.Entry<K,V> entry : items.entrySet()){
|
||||||
|
map.put(this.packKey(entry.getKey()),this.packValue(entry.getValue()));
|
||||||
|
}
|
||||||
|
this.database.multiDelete(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stashMultiPut(Map<K,V> items){
|
||||||
|
Map<byte[],byte[]> map = new LinkedHashMap<>();
|
||||||
|
for(Map.Entry<K,V> entry : items.entrySet()){
|
||||||
|
map.put(this.packKey(entry.getKey()),this.packValue(entry.getValue()));
|
||||||
|
}
|
||||||
|
this.database.multiPut(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stashDelete(K key,V value){
|
||||||
|
this.database.stashRawDelete(this.packKey(key),this.packValue(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stashPut(K key,V value){
|
||||||
|
this.database.stashRawPut(this.packKey(key),this.packValue(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ColumnFamilyHandle getColumnFamily() throws RocksDBException{
|
||||||
|
return this.database.getColumnFamilyByPrefix(this.prefix());
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Prefix prefix();
|
||||||
|
|
||||||
|
public abstract byte[] packKey(K key);
|
||||||
|
|
||||||
|
public abstract byte[] packValue(V value);
|
||||||
|
|
||||||
|
public abstract K unpackKey(byte[] key);
|
||||||
|
|
||||||
|
public abstract V unpackValue(byte[] value);
|
||||||
|
|
||||||
|
}
|
51
src/main/java/com/lbry/database/rows/RepostPrefixRow.java
Normal file
51
src/main/java/com/lbry/database/rows/RepostPrefixRow.java
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.RepostKey;
|
||||||
|
import com.lbry.database.values.RepostValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class RepostPrefixRow extends PrefixRow<RepostKey,RepostValue>{
|
||||||
|
|
||||||
|
public RepostPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.REPOST;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(RepostKey key) {
|
||||||
|
return ByteBuffer.allocate(1+20).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).put(key.claim_hash).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RepostKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
RepostKey keyObj = new RepostKey();
|
||||||
|
keyObj.claim_hash = new byte[20];
|
||||||
|
bb.get(keyObj.claim_hash);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(RepostValue value) {
|
||||||
|
return value.reposted_claim_hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RepostValue unpackValue(byte[] value) {
|
||||||
|
RepostValue valueObj = new RepostValue();
|
||||||
|
valueObj.reposted_claim_hash = value;
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.RepostedCountKey;
|
||||||
|
import com.lbry.database.values.RepostedCountValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class RepostedCountPrefixRow extends PrefixRow<RepostedCountKey,RepostedCountValue>{
|
||||||
|
|
||||||
|
public RepostedCountPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.REPOSTED_COUNT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(RepostedCountKey key) {
|
||||||
|
return ByteBuffer.allocate(1+20).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).put(key.claim_hash).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RepostedCountKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
RepostedCountKey keyObj = new RepostedCountKey();
|
||||||
|
keyObj.claim_hash = new byte[20];
|
||||||
|
bb.get(keyObj.claim_hash);
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(RepostedCountValue value) {
|
||||||
|
return ByteBuffer.allocate(4).order(ByteOrder.BIG_ENDIAN).putInt(value.reposted_count).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RepostedCountValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
RepostedCountValue valueObj = new RepostedCountValue();
|
||||||
|
valueObj.reposted_count = bb.getInt();
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
55
src/main/java/com/lbry/database/rows/RepostedPrefixRow.java
Normal file
55
src/main/java/com/lbry/database/rows/RepostedPrefixRow.java
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.RepostedKey;
|
||||||
|
import com.lbry.database.values.RepostedValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class RepostedPrefixRow extends PrefixRow<RepostedKey,RepostedValue>{
|
||||||
|
|
||||||
|
public RepostedPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.REPOSTED_CLAIM;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(RepostedKey key) {
|
||||||
|
return ByteBuffer.allocate(1+20+4+2).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).put(key.reposted_claim_hash).putInt(key.tx_num).putShort(key.position).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RepostedKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
RepostedKey keyObj = new RepostedKey();
|
||||||
|
keyObj.reposted_claim_hash = new byte[20];
|
||||||
|
bb.get(keyObj.reposted_claim_hash);
|
||||||
|
keyObj.tx_num = bb.getInt();
|
||||||
|
keyObj.position = bb.getShort();
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(RepostedValue value) {
|
||||||
|
return ByteBuffer.allocate(20).order(ByteOrder.BIG_ENDIAN).put(value.claim_hash).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RepostedValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
RepostedValue valueObj = new RepostedValue();
|
||||||
|
valueObj.claim_hash = new byte[20];
|
||||||
|
bb.get(valueObj.claim_hash);
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.SupportAmountKey;
|
||||||
|
import com.lbry.database.values.SupportAmountValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class SupportAmountPrefixRow extends PrefixRow<SupportAmountKey,SupportAmountValue>{
|
||||||
|
|
||||||
|
public SupportAmountPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.SUPPORT_AMOUNT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(SupportAmountKey key) {
|
||||||
|
return ByteBuffer.allocate(1+20).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).put(key.claim_hash).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SupportAmountKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
SupportAmountKey keyObj = new SupportAmountKey();
|
||||||
|
keyObj.claim_hash = new byte[20];
|
||||||
|
bb.get(keyObj.claim_hash);
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(SupportAmountValue value) {
|
||||||
|
return ByteBuffer.allocate(8).order(ByteOrder.BIG_ENDIAN).putLong(value.amount).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SupportAmountValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
SupportAmountValue valueObj = new SupportAmountValue();
|
||||||
|
valueObj.amount = bb.getLong();
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.SupportToClaimKey;
|
||||||
|
import com.lbry.database.values.SupportToClaimValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class SupportToClaimPrefixRow extends PrefixRow<SupportToClaimKey,SupportToClaimValue>{
|
||||||
|
|
||||||
|
public SupportToClaimPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.SUPPORT_TO_CLAIM;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(SupportToClaimKey key) {
|
||||||
|
return ByteBuffer.allocate(7).order(ByteOrder.BIG_ENDIAN).put(Prefix.SUPPORT_TO_CLAIM.getValue()).putInt(key.tx_num).putShort(key.position).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(SupportToClaimValue value) {
|
||||||
|
return ByteBuffer.allocate(1+20).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).put(value.claim_hash).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SupportToClaimKey unpackKey(byte[] key){
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
SupportToClaimKey keyObj = new SupportToClaimKey();
|
||||||
|
keyObj.tx_num = bb.getInt();
|
||||||
|
keyObj.position = bb.getShort();
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SupportToClaimValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
SupportToClaimValue valueObj = new SupportToClaimValue();
|
||||||
|
valueObj.claim_hash = new byte[20];
|
||||||
|
bb.get(valueObj.claim_hash);
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
52
src/main/java/com/lbry/database/rows/TXHashPrefixRow.java
Normal file
52
src/main/java/com/lbry/database/rows/TXHashPrefixRow.java
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.TxHashKey;
|
||||||
|
import com.lbry.database.values.TxHashValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class TXHashPrefixRow extends PrefixRow<TxHashKey, TxHashValue>{
|
||||||
|
|
||||||
|
public TXHashPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.TX_HASH;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(TxHashKey key) {
|
||||||
|
return ByteBuffer.allocate(1+4).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).putInt(key.tx_num).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TxHashKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
TxHashKey keyObj = new TxHashKey();
|
||||||
|
keyObj.tx_num = bb.getInt();
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(TxHashValue value) {
|
||||||
|
return ByteBuffer.allocate(32).order(ByteOrder.BIG_ENDIAN).put(value.tx_hash).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TxHashValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
TxHashValue valueObj = new TxHashValue();
|
||||||
|
valueObj.tx_hash = new byte[32];
|
||||||
|
bb.get(valueObj.tx_hash);
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
52
src/main/java/com/lbry/database/rows/TXNumPrefixRow.java
Normal file
52
src/main/java/com/lbry/database/rows/TXNumPrefixRow.java
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.TxNumKey;
|
||||||
|
import com.lbry.database.values.TxNumValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class TXNumPrefixRow extends PrefixRow<TxNumKey,TxNumValue>{
|
||||||
|
|
||||||
|
public TXNumPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.TX_NUM;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(TxNumKey key) {
|
||||||
|
return ByteBuffer.allocate(1+32).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).put(key.tx_hash).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TxNumKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
TxNumKey keyObj = new TxNumKey();
|
||||||
|
keyObj.tx_hash = new byte[32];
|
||||||
|
bb.get(keyObj.tx_hash);
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(TxNumValue value) {
|
||||||
|
return ByteBuffer.allocate(4).order(ByteOrder.BIG_ENDIAN).putInt(value.tx_num).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TxNumValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
TxNumValue valueObj = new TxNumValue();
|
||||||
|
valueObj.tx_num = bb.getInt();
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.TXOToClaimKey;
|
||||||
|
import com.lbry.database.values.TXOToClaimValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class TXOToClaimPrefixRow extends PrefixRow<TXOToClaimKey, TXOToClaimValue>{
|
||||||
|
|
||||||
|
public TXOToClaimPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.TXO_TO_CLAIM;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(TXOToClaimKey key) {
|
||||||
|
return ByteBuffer.allocate(1+6).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).putInt(key.tx_num).putShort(key.position).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TXOToClaimKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
TXOToClaimKey keyObj = new TXOToClaimKey();
|
||||||
|
keyObj.tx_num = bb.getInt();
|
||||||
|
keyObj.position = bb.getShort();
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(TXOToClaimValue value) {
|
||||||
|
byte[] strBytes = value.name.getBytes();
|
||||||
|
return ByteBuffer.allocate(20+2+strBytes.length).order(ByteOrder.BIG_ENDIAN).put(value.claim_hash).putShort((short) strBytes.length).put(strBytes).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TXOToClaimValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
TXOToClaimValue valueObj = new TXOToClaimValue();
|
||||||
|
valueObj.claim_hash = new byte[20];
|
||||||
|
bb.get(valueObj.claim_hash);
|
||||||
|
byte[] strBytes = new byte[bb.getShort()];
|
||||||
|
bb.get(strBytes);
|
||||||
|
valueObj.name = new String(strBytes);
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
51
src/main/java/com/lbry/database/rows/TXPrefixRow.java
Normal file
51
src/main/java/com/lbry/database/rows/TXPrefixRow.java
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.TxKey;
|
||||||
|
import com.lbry.database.values.TxValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class TXPrefixRow extends PrefixRow<TxKey,TxValue>{
|
||||||
|
|
||||||
|
public TXPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.TX;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(TxKey key) {
|
||||||
|
return ByteBuffer.allocate(1+32).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).put(key.tx_hash).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TxKey unpackKey(byte[] key){
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
TxKey keyObj = new TxKey();
|
||||||
|
keyObj.tx_hash = new byte[32];
|
||||||
|
bb.get(keyObj.tx_hash);
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(TxValue value) {
|
||||||
|
return value.raw_tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TxValue unpackValue(byte[] value) {
|
||||||
|
TxValue valueObj = new TxValue();
|
||||||
|
valueObj.raw_tx = value;
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.TouchedHashXKey;
|
||||||
|
import com.lbry.database.values.TouchedHashXValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class TouchedHashXPrefixRow extends PrefixRow<TouchedHashXKey,TouchedHashXValue>{
|
||||||
|
|
||||||
|
public TouchedHashXPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.TOUCHED_HASHX;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(TouchedHashXKey key) {
|
||||||
|
return ByteBuffer.allocate(1+4).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).putInt(key.height).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TouchedHashXKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
TouchedHashXKey keyObj = new TouchedHashXKey();
|
||||||
|
keyObj.height = bb.getInt();
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(TouchedHashXValue value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.allocate(value.touched_hashXs.size()*11).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
for(byte[] hashX : value.touched_hashXs){
|
||||||
|
bb.put(hashX);
|
||||||
|
}
|
||||||
|
return bb.array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TouchedHashXValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
TouchedHashXValue valueObj = new TouchedHashXValue();
|
||||||
|
valueObj.touched_hashXs = new ArrayList<>();
|
||||||
|
for(int i=0;i<value.length/11;i++){
|
||||||
|
byte[] hashX = new byte[11];
|
||||||
|
bb.get(hashX);
|
||||||
|
valueObj.touched_hashXs.add(hashX);
|
||||||
|
}
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,77 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.TouchedOrDeletedClaimKey;
|
||||||
|
import com.lbry.database.values.TouchedOrDeletedClaimValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
|
||||||
|
public class TouchedOrDeletedPrefixRow extends PrefixRow<TouchedOrDeletedClaimKey,TouchedOrDeletedClaimValue>{
|
||||||
|
|
||||||
|
public TouchedOrDeletedPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.TOUCHED_OR_DELETED;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(TouchedOrDeletedClaimKey key) {
|
||||||
|
return ByteBuffer.allocate(1+4).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).putInt(key.height).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TouchedOrDeletedClaimKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
TouchedOrDeletedClaimKey keyValue = new TouchedOrDeletedClaimKey();
|
||||||
|
keyValue.height = bb.getInt();
|
||||||
|
return keyValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(TouchedOrDeletedClaimValue value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.allocate(8+value.touched_claims.size()*20+value.deleted_claims.size()*20).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
bb.putInt(value.touched_claims.size());
|
||||||
|
bb.putInt(value.deleted_claims.size());
|
||||||
|
for(byte[] touched : value.touched_claims){
|
||||||
|
assert touched.length==20 : "Every touched item should have a length of 20 bytes.";
|
||||||
|
bb.put(touched);
|
||||||
|
}
|
||||||
|
for(byte[] deleted : value.deleted_claims){
|
||||||
|
assert deleted.length==20 : "Every deleted item should have a length of 20 bytes.";
|
||||||
|
bb.put(deleted);
|
||||||
|
}
|
||||||
|
return bb.array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TouchedOrDeletedClaimValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
int touchedAmount = bb.getInt();
|
||||||
|
int deletedAmount = bb.getInt();
|
||||||
|
assert value.length==8+touchedAmount+deletedAmount : "Data has too less or too much bytes.";
|
||||||
|
TouchedOrDeletedClaimValue valueObj = new TouchedOrDeletedClaimValue();
|
||||||
|
valueObj.touched_claims = new LinkedHashSet<>();
|
||||||
|
for(int i=0;i<touchedAmount;i++){
|
||||||
|
byte[] touchedClaim = new byte[20];
|
||||||
|
bb.get(touchedClaim);
|
||||||
|
valueObj.touched_claims.add(touchedClaim);
|
||||||
|
}
|
||||||
|
valueObj.deleted_claims = new LinkedHashSet<>();
|
||||||
|
for(int i=0;i<deletedAmount;i++){
|
||||||
|
byte[] deletedClaim = new byte[20];
|
||||||
|
bb.get(deletedClaim);
|
||||||
|
valueObj.deleted_claims.add(deletedClaim);
|
||||||
|
}
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.TrendingNotificationKey;
|
||||||
|
import com.lbry.database.values.TrendingNotificationValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class TrendingNotificationPrefixRow extends PrefixRow<TrendingNotificationKey,TrendingNotificationValue>{
|
||||||
|
|
||||||
|
public TrendingNotificationPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.TRENDING_NOTIFICATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(TrendingNotificationKey key) {
|
||||||
|
return ByteBuffer.allocate(1+4+20).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).putInt(key.height).put(key.claim_hash).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TrendingNotificationKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
TrendingNotificationKey keyObj = new TrendingNotificationKey();
|
||||||
|
keyObj.height = bb.getInt();
|
||||||
|
keyObj.claim_hash = new byte[20];
|
||||||
|
bb.get(keyObj.claim_hash);
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(TrendingNotificationValue value) {
|
||||||
|
return ByteBuffer.allocate(16).order(ByteOrder.BIG_ENDIAN).putLong(value.previous_amount).putLong(value.new_amount).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TrendingNotificationValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
TrendingNotificationValue valueObj = new TrendingNotificationValue();
|
||||||
|
valueObj.previous_amount = bb.getLong();
|
||||||
|
valueObj.new_amount = bb.getLong();
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
51
src/main/java/com/lbry/database/rows/TxCountPrefixRow.java
Normal file
51
src/main/java/com/lbry/database/rows/TxCountPrefixRow.java
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.TxCountKey;
|
||||||
|
import com.lbry.database.values.TxCountValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class TxCountPrefixRow extends PrefixRow<TxCountKey, TxCountValue>{
|
||||||
|
|
||||||
|
public TxCountPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.TX_COUNT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(TxCountKey key) {
|
||||||
|
return ByteBuffer.allocate(1+4).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).putInt(key.height).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TxCountKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
TxCountKey keyObj = new TxCountKey();
|
||||||
|
keyObj.height = bb.getInt();
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(TxCountValue value) {
|
||||||
|
return ByteBuffer.allocate(4).order(ByteOrder.BIG_ENDIAN).putInt(value.tx_count).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TxCountValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
TxCountValue valueObj = new TxCountValue();
|
||||||
|
valueObj.tx_count = bb.getInt();
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
54
src/main/java/com/lbry/database/rows/UTXOPrefixRow.java
Normal file
54
src/main/java/com/lbry/database/rows/UTXOPrefixRow.java
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.UTXOKey;
|
||||||
|
import com.lbry.database.values.UTXOValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class UTXOPrefixRow extends PrefixRow<UTXOKey,UTXOValue>{
|
||||||
|
|
||||||
|
public UTXOPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.UTXO;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(UTXOKey key) {
|
||||||
|
return ByteBuffer.allocate(1+11+4+2).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).put(key.hashX).putInt(key.tx_num).putShort(key.nout).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UTXOKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
UTXOKey keyObj = new UTXOKey();
|
||||||
|
keyObj.hashX = new byte[11];
|
||||||
|
bb.get(keyObj.hashX);
|
||||||
|
keyObj.tx_num = bb.getInt();
|
||||||
|
keyObj.nout = bb.getShort();
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(UTXOValue value) {
|
||||||
|
return ByteBuffer.allocate(8).order(ByteOrder.BIG_ENDIAN).putLong(value.amount).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UTXOValue unpackValue(byte[] value) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
UTXOValue valueObj = new UTXOValue();
|
||||||
|
valueObj.amount = bb.getLong();
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
52
src/main/java/com/lbry/database/rows/UndoPrefixRow.java
Normal file
52
src/main/java/com/lbry/database/rows/UndoPrefixRow.java
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
package com.lbry.database.rows;
|
||||||
|
|
||||||
|
import com.lbry.database.Prefix;
|
||||||
|
import com.lbry.database.PrefixDB;
|
||||||
|
import com.lbry.database.keys.UndoKey;
|
||||||
|
import com.lbry.database.values.UndoValue;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
public class UndoPrefixRow extends PrefixRow<UndoKey,UndoValue>{
|
||||||
|
|
||||||
|
public UndoPrefixRow(PrefixDB database){
|
||||||
|
super(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prefix prefix(){
|
||||||
|
return Prefix.UNDO;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packKey(UndoKey key) {
|
||||||
|
return ByteBuffer.allocate(1+8+32).order(ByteOrder.BIG_ENDIAN).put(this.prefix().getValue()).putLong(key.height).put(key.block_hash).array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UndoKey unpackKey(byte[] key) {
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
if(bb.get()!=this.prefix().getValue()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
UndoKey keyObj = new UndoKey();
|
||||||
|
keyObj.height = bb.getLong();
|
||||||
|
keyObj.block_hash = new byte[32];
|
||||||
|
bb.get(keyObj.block_hash);
|
||||||
|
return keyObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] packValue(UndoValue value) {
|
||||||
|
return value.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UndoValue unpackValue(byte[] value) {
|
||||||
|
UndoValue valueObj = new UndoValue();
|
||||||
|
valueObj.data = value;
|
||||||
|
return valueObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
20
src/main/java/com/lbry/database/values/ActivationValue.java
Normal file
20
src/main/java/com/lbry/database/values/ActivationValue.java
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package com.lbry.database.values;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class ActivationValue implements ValueInterface {
|
||||||
|
|
||||||
|
public int height;
|
||||||
|
public byte[] claim_hash;
|
||||||
|
public String normalized_name;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ActivationValue{" +
|
||||||
|
"height=" + height +
|
||||||
|
", claim_hash=" + Arrays.toString(claim_hash) +
|
||||||
|
", normalized_name='" + normalized_name + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.lbry.database.values;
|
||||||
|
|
||||||
|
public class ActiveAmountValue implements ValueInterface {
|
||||||
|
|
||||||
|
public long amount;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ActiveAmountValue{" +
|
||||||
|
"amount=" + amount +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
src/main/java/com/lbry/database/values/BidOrderValue.java
Normal file
16
src/main/java/com/lbry/database/values/BidOrderValue.java
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package com.lbry.database.values;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class BidOrderValue implements ValueInterface {
|
||||||
|
|
||||||
|
public byte[] claim_hash;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "BidOrderValue{" +
|
||||||
|
"claim_hash=" + Arrays.toString(claim_hash) +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
src/main/java/com/lbry/database/values/BlockHashValue.java
Normal file
16
src/main/java/com/lbry/database/values/BlockHashValue.java
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package com.lbry.database.values;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class BlockHashValue implements ValueInterface {
|
||||||
|
|
||||||
|
public byte[] block_hash;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "BlockHashValue{" +
|
||||||
|
"block_hash=" + Arrays.toString(block_hash) +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
src/main/java/com/lbry/database/values/BlockHeaderValue.java
Normal file
16
src/main/java/com/lbry/database/values/BlockHeaderValue.java
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package com.lbry.database.values;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class BlockHeaderValue implements ValueInterface {
|
||||||
|
|
||||||
|
public byte[] header;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "BlockHeaderValue{" +
|
||||||
|
"header=" + Arrays.toString(header) +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
src/main/java/com/lbry/database/values/BlockTxsValue.java
Normal file
16
src/main/java/com/lbry/database/values/BlockTxsValue.java
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package com.lbry.database.values;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class BlockTxsValue implements ValueInterface {
|
||||||
|
|
||||||
|
public List<byte[]> tx_hashes;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "BlockTxsValue{" +
|
||||||
|
"tx_hashes=" + tx_hashes +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.lbry.database.values;
|
||||||
|
|
||||||
|
public class ChannelCountValue implements ValueInterface {
|
||||||
|
|
||||||
|
public int count;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ChannelCountValue{" +
|
||||||
|
"count=" + count +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.lbry.database.values;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class ChannelToClaimValue implements ValueInterface {
|
||||||
|
|
||||||
|
public byte[] claim_hash;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ChannelToClaimValue{" +
|
||||||
|
"claim_hash=" + Arrays.toString(claim_hash) +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.lbry.database.values;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class ClaimExpirationValue implements ValueInterface {
|
||||||
|
|
||||||
|
public byte[] claim_hash;
|
||||||
|
public String normalized_name;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ClaimExpirationValue{" +
|
||||||
|
"claim_hash=" + Arrays.toString(claim_hash) +
|
||||||
|
", normalized_name='" + normalized_name + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.lbry.database.values;
|
||||||
|
|
||||||
|
public class ClaimShortIDValue implements ValueInterface {
|
||||||
|
|
||||||
|
public int tx_num;
|
||||||
|
public short position;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ClaimShortIDValue{" +
|
||||||
|
"tx_num=" + tx_num +
|
||||||
|
", position=" + position +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.lbry.database.values;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class ClaimTakeoverValue implements ValueInterface {
|
||||||
|
|
||||||
|
public byte[] claim_hash;
|
||||||
|
public int height;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ClaimTakeoverValue{" +
|
||||||
|
"claim_hash=" + Arrays.toString(claim_hash) +
|
||||||
|
", height=" + height +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.lbry.database.values;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class ClaimToChannelValue implements ValueInterface {
|
||||||
|
|
||||||
|
public byte[] signing_hash;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ClaimToChannelValue{" +
|
||||||
|
"signing_hash=" + Arrays.toString(signing_hash) +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.lbry.database.values;
|
||||||
|
|
||||||
|
public class ClaimToSupportValue implements ValueInterface {
|
||||||
|
|
||||||
|
public long amount;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ClaimToSupportValue{" +
|
||||||
|
"amount=" + amount +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
27
src/main/java/com/lbry/database/values/ClaimToTXOValue.java
Normal file
27
src/main/java/com/lbry/database/values/ClaimToTXOValue.java
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
package com.lbry.database.values;
|
||||||
|
|
||||||
|
public class ClaimToTXOValue implements ValueInterface {
|
||||||
|
|
||||||
|
public int tx_num;
|
||||||
|
public short position;
|
||||||
|
public int root_tx_num;
|
||||||
|
public short root_position;
|
||||||
|
public long amount;
|
||||||
|
// public int activation;
|
||||||
|
public boolean channel_signature_is_valid;
|
||||||
|
public String name;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ClaimToTXOValue{" +
|
||||||
|
"tx_num=" + tx_num +
|
||||||
|
", position=" + position +
|
||||||
|
", root_tx_num=" + root_tx_num +
|
||||||
|
", root_position=" + root_position +
|
||||||
|
", amount=" + amount +
|
||||||
|
", channel_signature_is_valid=" + channel_signature_is_valid +
|
||||||
|
", name='" + name + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
40
src/main/java/com/lbry/database/values/DBState.java
Normal file
40
src/main/java/com/lbry/database/values/DBState.java
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
package com.lbry.database.values;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class DBState implements ValueInterface {
|
||||||
|
|
||||||
|
public byte[] genesis;
|
||||||
|
public int height;
|
||||||
|
public int tx_count;
|
||||||
|
public byte[] tip;
|
||||||
|
public int utxo_flush_count;
|
||||||
|
public int wall_time;
|
||||||
|
public byte bit_fields;
|
||||||
|
public byte db_version;
|
||||||
|
public int hist_flush_count;
|
||||||
|
public int comp_flush_count;
|
||||||
|
public int comp_cursor;
|
||||||
|
public int es_sync_height;
|
||||||
|
public int hashX_status_last_indexed_height;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "DBState{" +
|
||||||
|
"genesis=" + Arrays.toString(genesis) +
|
||||||
|
", height=" + height +
|
||||||
|
", tx_count=" + tx_count +
|
||||||
|
", tip=" + Arrays.toString(tip) +
|
||||||
|
", utxo_flush_count=" + utxo_flush_count +
|
||||||
|
", wall_time=" + wall_time +
|
||||||
|
", bit_fields=" + bit_fields +
|
||||||
|
", db_version=" + db_version +
|
||||||
|
", hist_flush_count=" + hist_flush_count +
|
||||||
|
", comp_flush_count=" + comp_flush_count +
|
||||||
|
", comp_cursor=" + comp_cursor +
|
||||||
|
", es_sync_height=" + es_sync_height +
|
||||||
|
", hashX_status_last_indexed_height=" + hashX_status_last_indexed_height +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.lbry.database.values;
|
||||||
|
|
||||||
|
public class EffectiveAmountValue implements ValueInterface {
|
||||||
|
|
||||||
|
public long activated_sum;
|
||||||
|
public long activated_support_sum;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "EffectiveAmountValue{" +
|
||||||
|
"activated_sum=" + activated_sum +
|
||||||
|
", activated_support_sum=" + activated_support_sum +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue