From 770b6c8cf0cf656fbfdc130d401f53dda9f2d0d9 Mon Sep 17 00:00:00 2001 From: Ben van Hartingsveldt Date: Wed, 11 Sep 2024 21:15:18 +0200 Subject: [PATCH] Add classes --- src/main/java/com/lbry/database/Prefix.java | 65 ++++ src/main/java/com/lbry/database/PrefixDB.java | 345 ++++++++++++++++++ .../com/lbry/database/keys/ActivationKey.java | 18 + .../lbry/database/keys/ActiveAmountKey.java | 24 ++ .../com/lbry/database/keys/BidOrderKey.java | 20 + .../com/lbry/database/keys/BlockHashKey.java | 14 + .../lbry/database/keys/BlockHeaderKey.java | 14 + .../com/lbry/database/keys/BlockTxsKey.java | 14 + .../lbry/database/keys/ChannelCountKey.java | 16 + .../lbry/database/keys/ChannelToClaimKey.java | 22 ++ .../database/keys/ClaimExpirationKey.java | 18 + .../lbry/database/keys/ClaimShortIDKey.java | 20 + .../lbry/database/keys/ClaimTakeoverKey.java | 14 + .../lbry/database/keys/ClaimToChannelKey.java | 20 + .../lbry/database/keys/ClaimToSupportKey.java | 20 + .../com/lbry/database/keys/ClaimToTXOKey.java | 16 + .../database/keys/EffectiveAmountKey.java | 16 + .../keys/FutureEffectiveAmountKey.java | 7 + .../database/keys/HashXHistoryHasherKey.java | 7 + .../lbry/database/keys/HashXHistoryKey.java | 18 + .../lbry/database/keys/HashXStatusKey.java | 7 + .../com/lbry/database/keys/HashXUTXOKey.java | 20 + .../com/lbry/database/keys/KeyInterface.java | 7 + .../com/lbry/database/keys/MempoolTxKey.java | 16 + .../database/keys/PendingActivationKey.java | 20 + .../com/lbry/database/keys/RepostKey.java | 16 + .../lbry/database/keys/RepostedCountKey.java | 16 + .../com/lbry/database/keys/RepostedKey.java | 20 + .../lbry/database/keys/SupportAmountKey.java | 16 + .../lbry/database/keys/SupportToClaimKey.java | 16 + .../com/lbry/database/keys/TXOToClaimKey.java | 16 + .../lbry/database/keys/TouchedHashXKey.java | 14 + .../keys/TouchedOrDeletedClaimKey.java | 14 + .../keys/TrendingNotificationKey.java | 18 + .../com/lbry/database/keys/TxCountKey.java | 14 + .../com/lbry/database/keys/TxHashKey.java | 14 + .../java/com/lbry/database/keys/TxKey.java | 16 + .../java/com/lbry/database/keys/TxNumKey.java | 16 + .../java/com/lbry/database/keys/UTXOKey.java | 20 + .../java/com/lbry/database/keys/UndoKey.java | 18 + .../database/revert/RevertibleDelete.java | 14 + .../database/revert/RevertibleOperation.java | 49 +++ .../revert/RevertibleOperationStack.java | 17 + .../lbry/database/revert/RevertiblePut.java | 16 + .../database/rows/ActivatedPrefixRow.java | 59 +++ .../database/rows/ActiveAmountPrefixRow.java | 63 ++++ .../lbry/database/rows/BidOrderPrefixRow.java | 65 ++++ .../database/rows/BlockHashPrefixRow.java | 52 +++ .../database/rows/BlockHeaderPrefixRow.java | 52 +++ .../lbry/database/rows/BlockTxsPrefixRow.java | 60 +++ .../database/rows/ChannelCountPrefixRow.java | 52 +++ .../rows/ChannelToClaimPrefixRow.java | 66 ++++ .../rows/ClaimExpirationPrefixRow.java | 58 +++ .../database/rows/ClaimShortIDPrefixRow.java | 69 ++++ .../database/rows/ClaimTakeoverPrefixRow.java | 56 +++ .../rows/ClaimToChannelPrefixRow.java | 55 +++ .../rows/ClaimToSupportPrefixRow.java | 54 +++ .../database/rows/ClaimToTXOPrefixRow.java | 72 ++++ .../lbry/database/rows/DBStatePrefixRow.java | 84 +++++ .../rows/EffectiveAmountPrefixRow.java | 54 +++ .../rows/FutureEffectiveAmountPrefixRow.java | 52 +++ .../rows/HashXHistoryHasherPrefixRow.java | 52 +++ .../database/rows/HashXHistoryPrefixRow.java | 61 ++++ .../rows/HashXMempoolStatusPrefixRow.java | 53 +++ .../database/rows/HashXStatusPrefixRow.java | 53 +++ .../database/rows/HashXUTXOPrefixRow.java | 55 +++ .../database/rows/MempoolTXPrefixRow.java | 51 +++ .../rows/PendingActivationPrefixRow.java | 59 +++ .../com/lbry/database/rows/PrefixRow.java | 112 ++++++ .../lbry/database/rows/RepostPrefixRow.java | 51 +++ .../database/rows/RepostedCountPrefixRow.java | 52 +++ .../lbry/database/rows/RepostedPrefixRow.java | 55 +++ .../database/rows/SupportAmountPrefixRow.java | 52 +++ .../rows/SupportToClaimPrefixRow.java | 53 +++ .../lbry/database/rows/TXHashPrefixRow.java | 52 +++ .../lbry/database/rows/TXNumPrefixRow.java | 52 +++ .../database/rows/TXOToClaimPrefixRow.java | 57 +++ .../com/lbry/database/rows/TXPrefixRow.java | 51 +++ .../database/rows/TouchedHashXPrefixRow.java | 61 ++++ .../rows/TouchedOrDeletedPrefixRow.java | 77 ++++ .../rows/TrendingNotificationPrefixRow.java | 54 +++ .../lbry/database/rows/TxCountPrefixRow.java | 51 +++ .../com/lbry/database/rows/UTXOPrefixRow.java | 54 +++ .../com/lbry/database/rows/UndoPrefixRow.java | 52 +++ .../lbry/database/values/ActivationValue.java | 20 + .../database/values/ActiveAmountValue.java | 14 + .../lbry/database/values/BidOrderValue.java | 16 + .../lbry/database/values/BlockHashValue.java | 16 + .../database/values/BlockHeaderValue.java | 16 + .../lbry/database/values/BlockTxsValue.java | 16 + .../database/values/ChannelCountValue.java | 14 + .../database/values/ChannelToClaimValue.java | 16 + .../database/values/ClaimExpirationValue.java | 18 + .../database/values/ClaimShortIDValue.java | 16 + .../database/values/ClaimTakeoverValue.java | 18 + .../database/values/ClaimToChannelValue.java | 16 + .../database/values/ClaimToSupportValue.java | 14 + .../lbry/database/values/ClaimToTXOValue.java | 27 ++ .../com/lbry/database/values/DBState.java | 40 ++ .../database/values/EffectiveAmountValue.java | 16 + .../values/FutureEffectiveAmountValue.java | 14 + .../values/HashXHistoryHasherValue.java | 7 + .../database/values/HashXHistoryValue.java | 16 + .../database/values/HashXStatusValue.java | 16 + .../lbry/database/values/HashXUTXOValue.java | 16 + .../lbry/database/values/MempoolTxValue.java | 16 + .../values/PendingActivationValue.java | 18 + .../com/lbry/database/values/RepostValue.java | 16 + .../database/values/RepostedCountValue.java | 14 + .../lbry/database/values/RepostedValue.java | 16 + .../database/values/SupportAmountValue.java | 14 + .../database/values/SupportToClaimValue.java | 16 + .../lbry/database/values/TXOToClaimValue.java | 18 + .../database/values/TouchedHashXValue.java | 16 + .../values/TouchedOrDeletedClaimValue.java | 18 + .../values/TrendingNotificationValue.java | 16 + .../lbry/database/values/TxCountValue.java | 14 + .../com/lbry/database/values/TxHashValue.java | 16 + .../com/lbry/database/values/TxNumValue.java | 14 + .../com/lbry/database/values/TxValue.java | 16 + .../com/lbry/database/values/UTXOValue.java | 14 + .../com/lbry/database/values/UndoValue.java | 16 + .../lbry/database/values/ValueInterface.java | 7 + 123 files changed, 4098 insertions(+) create mode 100644 src/main/java/com/lbry/database/Prefix.java create mode 100644 src/main/java/com/lbry/database/PrefixDB.java create mode 100644 src/main/java/com/lbry/database/keys/ActivationKey.java create mode 100644 src/main/java/com/lbry/database/keys/ActiveAmountKey.java create mode 100644 src/main/java/com/lbry/database/keys/BidOrderKey.java create mode 100644 src/main/java/com/lbry/database/keys/BlockHashKey.java create mode 100644 src/main/java/com/lbry/database/keys/BlockHeaderKey.java create mode 100644 src/main/java/com/lbry/database/keys/BlockTxsKey.java create mode 100644 src/main/java/com/lbry/database/keys/ChannelCountKey.java create mode 100644 src/main/java/com/lbry/database/keys/ChannelToClaimKey.java create mode 100644 src/main/java/com/lbry/database/keys/ClaimExpirationKey.java create mode 100644 src/main/java/com/lbry/database/keys/ClaimShortIDKey.java create mode 100644 src/main/java/com/lbry/database/keys/ClaimTakeoverKey.java create mode 100644 src/main/java/com/lbry/database/keys/ClaimToChannelKey.java create mode 100644 src/main/java/com/lbry/database/keys/ClaimToSupportKey.java create mode 100644 src/main/java/com/lbry/database/keys/ClaimToTXOKey.java create mode 100644 src/main/java/com/lbry/database/keys/EffectiveAmountKey.java create mode 100644 src/main/java/com/lbry/database/keys/FutureEffectiveAmountKey.java create mode 100644 src/main/java/com/lbry/database/keys/HashXHistoryHasherKey.java create mode 100644 src/main/java/com/lbry/database/keys/HashXHistoryKey.java create mode 100644 src/main/java/com/lbry/database/keys/HashXStatusKey.java create mode 100644 src/main/java/com/lbry/database/keys/HashXUTXOKey.java create mode 100644 src/main/java/com/lbry/database/keys/KeyInterface.java create mode 100644 src/main/java/com/lbry/database/keys/MempoolTxKey.java create mode 100644 src/main/java/com/lbry/database/keys/PendingActivationKey.java create mode 100644 src/main/java/com/lbry/database/keys/RepostKey.java create mode 100644 src/main/java/com/lbry/database/keys/RepostedCountKey.java create mode 100644 src/main/java/com/lbry/database/keys/RepostedKey.java create mode 100644 src/main/java/com/lbry/database/keys/SupportAmountKey.java create mode 100644 src/main/java/com/lbry/database/keys/SupportToClaimKey.java create mode 100644 src/main/java/com/lbry/database/keys/TXOToClaimKey.java create mode 100644 src/main/java/com/lbry/database/keys/TouchedHashXKey.java create mode 100644 src/main/java/com/lbry/database/keys/TouchedOrDeletedClaimKey.java create mode 100644 src/main/java/com/lbry/database/keys/TrendingNotificationKey.java create mode 100644 src/main/java/com/lbry/database/keys/TxCountKey.java create mode 100644 src/main/java/com/lbry/database/keys/TxHashKey.java create mode 100644 src/main/java/com/lbry/database/keys/TxKey.java create mode 100644 src/main/java/com/lbry/database/keys/TxNumKey.java create mode 100644 src/main/java/com/lbry/database/keys/UTXOKey.java create mode 100644 src/main/java/com/lbry/database/keys/UndoKey.java create mode 100644 src/main/java/com/lbry/database/revert/RevertibleDelete.java create mode 100644 src/main/java/com/lbry/database/revert/RevertibleOperation.java create mode 100644 src/main/java/com/lbry/database/revert/RevertibleOperationStack.java create mode 100644 src/main/java/com/lbry/database/revert/RevertiblePut.java create mode 100644 src/main/java/com/lbry/database/rows/ActivatedPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/ActiveAmountPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/BidOrderPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/BlockHashPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/BlockHeaderPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/BlockTxsPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/ChannelCountPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/ChannelToClaimPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/ClaimExpirationPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/ClaimShortIDPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/ClaimTakeoverPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/ClaimToChannelPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/ClaimToSupportPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/ClaimToTXOPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/DBStatePrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/EffectiveAmountPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/FutureEffectiveAmountPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/HashXHistoryHasherPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/HashXHistoryPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/HashXMempoolStatusPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/HashXStatusPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/HashXUTXOPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/MempoolTXPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/PendingActivationPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/PrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/RepostPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/RepostedCountPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/RepostedPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/SupportAmountPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/SupportToClaimPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/TXHashPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/TXNumPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/TXOToClaimPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/TXPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/TouchedHashXPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/TouchedOrDeletedPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/TrendingNotificationPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/TxCountPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/UTXOPrefixRow.java create mode 100644 src/main/java/com/lbry/database/rows/UndoPrefixRow.java create mode 100644 src/main/java/com/lbry/database/values/ActivationValue.java create mode 100644 src/main/java/com/lbry/database/values/ActiveAmountValue.java create mode 100644 src/main/java/com/lbry/database/values/BidOrderValue.java create mode 100644 src/main/java/com/lbry/database/values/BlockHashValue.java create mode 100644 src/main/java/com/lbry/database/values/BlockHeaderValue.java create mode 100644 src/main/java/com/lbry/database/values/BlockTxsValue.java create mode 100644 src/main/java/com/lbry/database/values/ChannelCountValue.java create mode 100644 src/main/java/com/lbry/database/values/ChannelToClaimValue.java create mode 100644 src/main/java/com/lbry/database/values/ClaimExpirationValue.java create mode 100644 src/main/java/com/lbry/database/values/ClaimShortIDValue.java create mode 100644 src/main/java/com/lbry/database/values/ClaimTakeoverValue.java create mode 100644 src/main/java/com/lbry/database/values/ClaimToChannelValue.java create mode 100644 src/main/java/com/lbry/database/values/ClaimToSupportValue.java create mode 100644 src/main/java/com/lbry/database/values/ClaimToTXOValue.java create mode 100644 src/main/java/com/lbry/database/values/DBState.java create mode 100644 src/main/java/com/lbry/database/values/EffectiveAmountValue.java create mode 100644 src/main/java/com/lbry/database/values/FutureEffectiveAmountValue.java create mode 100644 src/main/java/com/lbry/database/values/HashXHistoryHasherValue.java create mode 100644 src/main/java/com/lbry/database/values/HashXHistoryValue.java create mode 100644 src/main/java/com/lbry/database/values/HashXStatusValue.java create mode 100644 src/main/java/com/lbry/database/values/HashXUTXOValue.java create mode 100644 src/main/java/com/lbry/database/values/MempoolTxValue.java create mode 100644 src/main/java/com/lbry/database/values/PendingActivationValue.java create mode 100644 src/main/java/com/lbry/database/values/RepostValue.java create mode 100644 src/main/java/com/lbry/database/values/RepostedCountValue.java create mode 100644 src/main/java/com/lbry/database/values/RepostedValue.java create mode 100644 src/main/java/com/lbry/database/values/SupportAmountValue.java create mode 100644 src/main/java/com/lbry/database/values/SupportToClaimValue.java create mode 100644 src/main/java/com/lbry/database/values/TXOToClaimValue.java create mode 100644 src/main/java/com/lbry/database/values/TouchedHashXValue.java create mode 100644 src/main/java/com/lbry/database/values/TouchedOrDeletedClaimValue.java create mode 100644 src/main/java/com/lbry/database/values/TrendingNotificationValue.java create mode 100644 src/main/java/com/lbry/database/values/TxCountValue.java create mode 100644 src/main/java/com/lbry/database/values/TxHashValue.java create mode 100644 src/main/java/com/lbry/database/values/TxNumValue.java create mode 100644 src/main/java/com/lbry/database/values/TxValue.java create mode 100644 src/main/java/com/lbry/database/values/UTXOValue.java create mode 100644 src/main/java/com/lbry/database/values/UndoValue.java create mode 100644 src/main/java/com/lbry/database/values/ValueInterface.java diff --git a/src/main/java/com/lbry/database/Prefix.java b/src/main/java/com/lbry/database/Prefix.java new file mode 100644 index 0000000..d380bab --- /dev/null +++ b/src/main/java/com/lbry/database/Prefix.java @@ -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; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/PrefixDB.java b/src/main/java/com/lbry/database/PrefixDB.java new file mode 100644 index 0000000..760d9f0 --- /dev/null +++ b/src/main/java/com/lbry/database/PrefixDB.java @@ -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 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 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 multiGet(List 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 multiGet(List keys,boolean fillCache) throws RocksDBException{ + List 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 values = this.database.multiGetAsList(options,columnFamilies,keys); + options.close(); + return values; + } + + /** + * Stash multiple items for deletion. + * @param items The items. + */ + public void multiDelete(Map 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 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; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/ActivationKey.java b/src/main/java/com/lbry/database/keys/ActivationKey.java new file mode 100644 index 0000000..4a08eca --- /dev/null +++ b/src/main/java/com/lbry/database/keys/ActivationKey.java @@ -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 + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/keys/ActiveAmountKey.java b/src/main/java/com/lbry/database/keys/ActiveAmountKey.java new file mode 100644 index 0000000..12a8fda --- /dev/null +++ b/src/main/java/com/lbry/database/keys/ActiveAmountKey.java @@ -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 + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/BidOrderKey.java b/src/main/java/com/lbry/database/keys/BidOrderKey.java new file mode 100644 index 0000000..1bb0ea2 --- /dev/null +++ b/src/main/java/com/lbry/database/keys/BidOrderKey.java @@ -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 + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/BlockHashKey.java b/src/main/java/com/lbry/database/keys/BlockHashKey.java new file mode 100644 index 0000000..758bf92 --- /dev/null +++ b/src/main/java/com/lbry/database/keys/BlockHashKey.java @@ -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 + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/BlockHeaderKey.java b/src/main/java/com/lbry/database/keys/BlockHeaderKey.java new file mode 100644 index 0000000..0c8a900 --- /dev/null +++ b/src/main/java/com/lbry/database/keys/BlockHeaderKey.java @@ -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 + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/BlockTxsKey.java b/src/main/java/com/lbry/database/keys/BlockTxsKey.java new file mode 100644 index 0000000..fbecf36 --- /dev/null +++ b/src/main/java/com/lbry/database/keys/BlockTxsKey.java @@ -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 + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/ChannelCountKey.java b/src/main/java/com/lbry/database/keys/ChannelCountKey.java new file mode 100644 index 0000000..25d4796 --- /dev/null +++ b/src/main/java/com/lbry/database/keys/ChannelCountKey.java @@ -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) + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/ChannelToClaimKey.java b/src/main/java/com/lbry/database/keys/ChannelToClaimKey.java new file mode 100644 index 0000000..045eff7 --- /dev/null +++ b/src/main/java/com/lbry/database/keys/ChannelToClaimKey.java @@ -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 + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/keys/ClaimExpirationKey.java b/src/main/java/com/lbry/database/keys/ClaimExpirationKey.java new file mode 100644 index 0000000..9ce4d01 --- /dev/null +++ b/src/main/java/com/lbry/database/keys/ClaimExpirationKey.java @@ -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 + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/ClaimShortIDKey.java b/src/main/java/com/lbry/database/keys/ClaimShortIDKey.java new file mode 100644 index 0000000..a731527 --- /dev/null +++ b/src/main/java/com/lbry/database/keys/ClaimShortIDKey.java @@ -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 + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/ClaimTakeoverKey.java b/src/main/java/com/lbry/database/keys/ClaimTakeoverKey.java new file mode 100644 index 0000000..3a77c99 --- /dev/null +++ b/src/main/java/com/lbry/database/keys/ClaimTakeoverKey.java @@ -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 + '\'' + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/ClaimToChannelKey.java b/src/main/java/com/lbry/database/keys/ClaimToChannelKey.java new file mode 100644 index 0000000..dd3beec --- /dev/null +++ b/src/main/java/com/lbry/database/keys/ClaimToChannelKey.java @@ -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 + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/keys/ClaimToSupportKey.java b/src/main/java/com/lbry/database/keys/ClaimToSupportKey.java new file mode 100644 index 0000000..2234254 --- /dev/null +++ b/src/main/java/com/lbry/database/keys/ClaimToSupportKey.java @@ -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 + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/keys/ClaimToTXOKey.java b/src/main/java/com/lbry/database/keys/ClaimToTXOKey.java new file mode 100644 index 0000000..6630909 --- /dev/null +++ b/src/main/java/com/lbry/database/keys/ClaimToTXOKey.java @@ -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) + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/EffectiveAmountKey.java b/src/main/java/com/lbry/database/keys/EffectiveAmountKey.java new file mode 100644 index 0000000..1293fef --- /dev/null +++ b/src/main/java/com/lbry/database/keys/EffectiveAmountKey.java @@ -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) + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/FutureEffectiveAmountKey.java b/src/main/java/com/lbry/database/keys/FutureEffectiveAmountKey.java new file mode 100644 index 0000000..9dcaa29 --- /dev/null +++ b/src/main/java/com/lbry/database/keys/FutureEffectiveAmountKey.java @@ -0,0 +1,7 @@ +package com.lbry.database.keys; + +public class FutureEffectiveAmountKey implements KeyInterface { + + public byte[] claim_hash; + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/HashXHistoryHasherKey.java b/src/main/java/com/lbry/database/keys/HashXHistoryHasherKey.java new file mode 100644 index 0000000..964bcc8 --- /dev/null +++ b/src/main/java/com/lbry/database/keys/HashXHistoryHasherKey.java @@ -0,0 +1,7 @@ +package com.lbry.database.keys; + +public class HashXHistoryHasherKey implements KeyInterface { + + public byte[] hashX; + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/HashXHistoryKey.java b/src/main/java/com/lbry/database/keys/HashXHistoryKey.java new file mode 100644 index 0000000..39315e7 --- /dev/null +++ b/src/main/java/com/lbry/database/keys/HashXHistoryKey.java @@ -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 + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/keys/HashXStatusKey.java b/src/main/java/com/lbry/database/keys/HashXStatusKey.java new file mode 100644 index 0000000..43e351a --- /dev/null +++ b/src/main/java/com/lbry/database/keys/HashXStatusKey.java @@ -0,0 +1,7 @@ +package com.lbry.database.keys; + +public class HashXStatusKey implements KeyInterface { + + public byte[] hashX; + +} diff --git a/src/main/java/com/lbry/database/keys/HashXUTXOKey.java b/src/main/java/com/lbry/database/keys/HashXUTXOKey.java new file mode 100644 index 0000000..5ff9a20 --- /dev/null +++ b/src/main/java/com/lbry/database/keys/HashXUTXOKey.java @@ -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 + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/KeyInterface.java b/src/main/java/com/lbry/database/keys/KeyInterface.java new file mode 100644 index 0000000..49b55b1 --- /dev/null +++ b/src/main/java/com/lbry/database/keys/KeyInterface.java @@ -0,0 +1,7 @@ +package com.lbry.database.keys; + +public interface KeyInterface{ + + KeyInterface NULL = null; + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/MempoolTxKey.java b/src/main/java/com/lbry/database/keys/MempoolTxKey.java new file mode 100644 index 0000000..2862606 --- /dev/null +++ b/src/main/java/com/lbry/database/keys/MempoolTxKey.java @@ -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) + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/keys/PendingActivationKey.java b/src/main/java/com/lbry/database/keys/PendingActivationKey.java new file mode 100644 index 0000000..d5c191f --- /dev/null +++ b/src/main/java/com/lbry/database/keys/PendingActivationKey.java @@ -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 + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/RepostKey.java b/src/main/java/com/lbry/database/keys/RepostKey.java new file mode 100644 index 0000000..048bfd1 --- /dev/null +++ b/src/main/java/com/lbry/database/keys/RepostKey.java @@ -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) + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/RepostedCountKey.java b/src/main/java/com/lbry/database/keys/RepostedCountKey.java new file mode 100644 index 0000000..9fe8d06 --- /dev/null +++ b/src/main/java/com/lbry/database/keys/RepostedCountKey.java @@ -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) + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/RepostedKey.java b/src/main/java/com/lbry/database/keys/RepostedKey.java new file mode 100644 index 0000000..78313f2 --- /dev/null +++ b/src/main/java/com/lbry/database/keys/RepostedKey.java @@ -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 + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/SupportAmountKey.java b/src/main/java/com/lbry/database/keys/SupportAmountKey.java new file mode 100644 index 0000000..af98a30 --- /dev/null +++ b/src/main/java/com/lbry/database/keys/SupportAmountKey.java @@ -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) + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/SupportToClaimKey.java b/src/main/java/com/lbry/database/keys/SupportToClaimKey.java new file mode 100644 index 0000000..4b1f2ac --- /dev/null +++ b/src/main/java/com/lbry/database/keys/SupportToClaimKey.java @@ -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 + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/keys/TXOToClaimKey.java b/src/main/java/com/lbry/database/keys/TXOToClaimKey.java new file mode 100644 index 0000000..7b139c2 --- /dev/null +++ b/src/main/java/com/lbry/database/keys/TXOToClaimKey.java @@ -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 + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/TouchedHashXKey.java b/src/main/java/com/lbry/database/keys/TouchedHashXKey.java new file mode 100644 index 0000000..ede0e9f --- /dev/null +++ b/src/main/java/com/lbry/database/keys/TouchedHashXKey.java @@ -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 + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/TouchedOrDeletedClaimKey.java b/src/main/java/com/lbry/database/keys/TouchedOrDeletedClaimKey.java new file mode 100644 index 0000000..a1ad025 --- /dev/null +++ b/src/main/java/com/lbry/database/keys/TouchedOrDeletedClaimKey.java @@ -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 + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/TrendingNotificationKey.java b/src/main/java/com/lbry/database/keys/TrendingNotificationKey.java new file mode 100644 index 0000000..d5f3ab2 --- /dev/null +++ b/src/main/java/com/lbry/database/keys/TrendingNotificationKey.java @@ -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) + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/TxCountKey.java b/src/main/java/com/lbry/database/keys/TxCountKey.java new file mode 100644 index 0000000..9633dd8 --- /dev/null +++ b/src/main/java/com/lbry/database/keys/TxCountKey.java @@ -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 + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/TxHashKey.java b/src/main/java/com/lbry/database/keys/TxHashKey.java new file mode 100644 index 0000000..cda4810 --- /dev/null +++ b/src/main/java/com/lbry/database/keys/TxHashKey.java @@ -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 + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/TxKey.java b/src/main/java/com/lbry/database/keys/TxKey.java new file mode 100644 index 0000000..337e57e --- /dev/null +++ b/src/main/java/com/lbry/database/keys/TxKey.java @@ -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) + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/TxNumKey.java b/src/main/java/com/lbry/database/keys/TxNumKey.java new file mode 100644 index 0000000..0efbc68 --- /dev/null +++ b/src/main/java/com/lbry/database/keys/TxNumKey.java @@ -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) + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/UTXOKey.java b/src/main/java/com/lbry/database/keys/UTXOKey.java new file mode 100644 index 0000000..3047b0e --- /dev/null +++ b/src/main/java/com/lbry/database/keys/UTXOKey.java @@ -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 + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/keys/UndoKey.java b/src/main/java/com/lbry/database/keys/UndoKey.java new file mode 100644 index 0000000..f805132 --- /dev/null +++ b/src/main/java/com/lbry/database/keys/UndoKey.java @@ -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) + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/revert/RevertibleDelete.java b/src/main/java/com/lbry/database/revert/RevertibleDelete.java new file mode 100644 index 0000000..2267fb2 --- /dev/null +++ b/src/main/java/com/lbry/database/revert/RevertibleDelete.java @@ -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); + } + +} diff --git a/src/main/java/com/lbry/database/revert/RevertibleOperation.java b/src/main/java/com/lbry/database/revert/RevertibleOperation.java new file mode 100644 index 0000000..2a05259 --- /dev/null +++ b/src/main/java/com/lbry/database/revert/RevertibleOperation.java @@ -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 + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/revert/RevertibleOperationStack.java b/src/main/java/com/lbry/database/revert/RevertibleOperationStack.java new file mode 100644 index 0000000..48f6006 --- /dev/null +++ b/src/main/java/com/lbry/database/revert/RevertibleOperationStack.java @@ -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(){ + + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/revert/RevertiblePut.java b/src/main/java/com/lbry/database/revert/RevertiblePut.java new file mode 100644 index 0000000..db34c96 --- /dev/null +++ b/src/main/java/com/lbry/database/revert/RevertiblePut.java @@ -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); + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/rows/ActivatedPrefixRow.java b/src/main/java/com/lbry/database/rows/ActivatedPrefixRow.java new file mode 100644 index 0000000..bc118e0 --- /dev/null +++ b/src/main/java/com/lbry/database/rows/ActivatedPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/ActiveAmountPrefixRow.java b/src/main/java/com/lbry/database/rows/ActiveAmountPrefixRow.java new file mode 100644 index 0000000..a116188 --- /dev/null +++ b/src/main/java/com/lbry/database/rows/ActiveAmountPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/BidOrderPrefixRow.java b/src/main/java/com/lbry/database/rows/BidOrderPrefixRow.java new file mode 100644 index 0000000..af251eb --- /dev/null +++ b/src/main/java/com/lbry/database/rows/BidOrderPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/BlockHashPrefixRow.java b/src/main/java/com/lbry/database/rows/BlockHashPrefixRow.java new file mode 100644 index 0000000..48aae28 --- /dev/null +++ b/src/main/java/com/lbry/database/rows/BlockHashPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/BlockHeaderPrefixRow.java b/src/main/java/com/lbry/database/rows/BlockHeaderPrefixRow.java new file mode 100644 index 0000000..c12798b --- /dev/null +++ b/src/main/java/com/lbry/database/rows/BlockHeaderPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/BlockTxsPrefixRow.java b/src/main/java/com/lbry/database/rows/BlockTxsPrefixRow.java new file mode 100644 index 0000000..3c43ed9 --- /dev/null +++ b/src/main/java/com/lbry/database/rows/BlockTxsPrefixRow.java @@ -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{ + + 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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/ChannelToClaimPrefixRow.java b/src/main/java/com/lbry/database/rows/ChannelToClaimPrefixRow.java new file mode 100644 index 0000000..96cf595 --- /dev/null +++ b/src/main/java/com/lbry/database/rows/ChannelToClaimPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/ClaimExpirationPrefixRow.java b/src/main/java/com/lbry/database/rows/ClaimExpirationPrefixRow.java new file mode 100644 index 0000000..0dc6389 --- /dev/null +++ b/src/main/java/com/lbry/database/rows/ClaimExpirationPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/ClaimShortIDPrefixRow.java b/src/main/java/com/lbry/database/rows/ClaimShortIDPrefixRow.java new file mode 100644 index 0000000..8aa4a44 --- /dev/null +++ b/src/main/java/com/lbry/database/rows/ClaimShortIDPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/ClaimTakeoverPrefixRow.java b/src/main/java/com/lbry/database/rows/ClaimTakeoverPrefixRow.java new file mode 100644 index 0000000..35a3b17 --- /dev/null +++ b/src/main/java/com/lbry/database/rows/ClaimTakeoverPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/ClaimToChannelPrefixRow.java b/src/main/java/com/lbry/database/rows/ClaimToChannelPrefixRow.java new file mode 100644 index 0000000..791b643 --- /dev/null +++ b/src/main/java/com/lbry/database/rows/ClaimToChannelPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/ClaimToSupportPrefixRow.java b/src/main/java/com/lbry/database/rows/ClaimToSupportPrefixRow.java new file mode 100644 index 0000000..b78cdc2 --- /dev/null +++ b/src/main/java/com/lbry/database/rows/ClaimToSupportPrefixRow.java @@ -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{ + + 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; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/rows/ClaimToTXOPrefixRow.java b/src/main/java/com/lbry/database/rows/ClaimToTXOPrefixRow.java new file mode 100644 index 0000000..cf2f452 --- /dev/null +++ b/src/main/java/com/lbry/database/rows/ClaimToTXOPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/DBStatePrefixRow.java b/src/main/java/com/lbry/database/rows/DBStatePrefixRow.java new file mode 100644 index 0000000..1b10b9a --- /dev/null +++ b/src/main/java/com/lbry/database/rows/DBStatePrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/EffectiveAmountPrefixRow.java b/src/main/java/com/lbry/database/rows/EffectiveAmountPrefixRow.java new file mode 100644 index 0000000..d42728a --- /dev/null +++ b/src/main/java/com/lbry/database/rows/EffectiveAmountPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/FutureEffectiveAmountPrefixRow.java b/src/main/java/com/lbry/database/rows/FutureEffectiveAmountPrefixRow.java new file mode 100644 index 0000000..12fe5b7 --- /dev/null +++ b/src/main/java/com/lbry/database/rows/FutureEffectiveAmountPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/HashXHistoryHasherPrefixRow.java b/src/main/java/com/lbry/database/rows/HashXHistoryHasherPrefixRow.java new file mode 100644 index 0000000..42ddca7 --- /dev/null +++ b/src/main/java/com/lbry/database/rows/HashXHistoryHasherPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/HashXHistoryPrefixRow.java b/src/main/java/com/lbry/database/rows/HashXHistoryPrefixRow.java new file mode 100644 index 0000000..8b3494e --- /dev/null +++ b/src/main/java/com/lbry/database/rows/HashXHistoryPrefixRow.java @@ -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{ + + 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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/HashXStatusPrefixRow.java b/src/main/java/com/lbry/database/rows/HashXStatusPrefixRow.java new file mode 100644 index 0000000..2f65de9 --- /dev/null +++ b/src/main/java/com/lbry/database/rows/HashXStatusPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/HashXUTXOPrefixRow.java b/src/main/java/com/lbry/database/rows/HashXUTXOPrefixRow.java new file mode 100644 index 0000000..da9d6f9 --- /dev/null +++ b/src/main/java/com/lbry/database/rows/HashXUTXOPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/MempoolTXPrefixRow.java b/src/main/java/com/lbry/database/rows/MempoolTXPrefixRow.java new file mode 100644 index 0000000..5d8039e --- /dev/null +++ b/src/main/java/com/lbry/database/rows/MempoolTXPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/PendingActivationPrefixRow.java b/src/main/java/com/lbry/database/rows/PendingActivationPrefixRow.java new file mode 100644 index 0000000..1e67318 --- /dev/null +++ b/src/main/java/com/lbry/database/rows/PendingActivationPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/PrefixRow.java b/src/main/java/com/lbry/database/rows/PrefixRow.java new file mode 100644 index 0000000..a320108 --- /dev/null +++ b/src/main/java/com/lbry/database/rows/PrefixRow.java @@ -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{ + + 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 multiGet(List keys,boolean fillCache,boolean deserializeValue) throws RocksDBException{ + List 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 items){ + Map map = new LinkedHashMap<>(); + for(Map.Entry entry : items.entrySet()){ + map.put(this.packKey(entry.getKey()),this.packValue(entry.getValue())); + } + this.database.multiDelete(map); + } + + public void stashMultiPut(Map items){ + Map map = new LinkedHashMap<>(); + for(Map.Entry 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); + +} diff --git a/src/main/java/com/lbry/database/rows/RepostPrefixRow.java b/src/main/java/com/lbry/database/rows/RepostPrefixRow.java new file mode 100644 index 0000000..983e22d --- /dev/null +++ b/src/main/java/com/lbry/database/rows/RepostPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/RepostedCountPrefixRow.java b/src/main/java/com/lbry/database/rows/RepostedCountPrefixRow.java new file mode 100644 index 0000000..4450088 --- /dev/null +++ b/src/main/java/com/lbry/database/rows/RepostedCountPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/RepostedPrefixRow.java b/src/main/java/com/lbry/database/rows/RepostedPrefixRow.java new file mode 100644 index 0000000..e17d388 --- /dev/null +++ b/src/main/java/com/lbry/database/rows/RepostedPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/SupportAmountPrefixRow.java b/src/main/java/com/lbry/database/rows/SupportAmountPrefixRow.java new file mode 100644 index 0000000..1b0a417 --- /dev/null +++ b/src/main/java/com/lbry/database/rows/SupportAmountPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/SupportToClaimPrefixRow.java b/src/main/java/com/lbry/database/rows/SupportToClaimPrefixRow.java new file mode 100644 index 0000000..671dcf3 --- /dev/null +++ b/src/main/java/com/lbry/database/rows/SupportToClaimPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/TXHashPrefixRow.java b/src/main/java/com/lbry/database/rows/TXHashPrefixRow.java new file mode 100644 index 0000000..5c648b9 --- /dev/null +++ b/src/main/java/com/lbry/database/rows/TXHashPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/TXNumPrefixRow.java b/src/main/java/com/lbry/database/rows/TXNumPrefixRow.java new file mode 100644 index 0000000..6b1465c --- /dev/null +++ b/src/main/java/com/lbry/database/rows/TXNumPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/TXOToClaimPrefixRow.java b/src/main/java/com/lbry/database/rows/TXOToClaimPrefixRow.java new file mode 100644 index 0000000..1e3d74d --- /dev/null +++ b/src/main/java/com/lbry/database/rows/TXOToClaimPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/TXPrefixRow.java b/src/main/java/com/lbry/database/rows/TXPrefixRow.java new file mode 100644 index 0000000..a174483 --- /dev/null +++ b/src/main/java/com/lbry/database/rows/TXPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/TouchedHashXPrefixRow.java b/src/main/java/com/lbry/database/rows/TouchedHashXPrefixRow.java new file mode 100644 index 0000000..03b8efe --- /dev/null +++ b/src/main/java/com/lbry/database/rows/TouchedHashXPrefixRow.java @@ -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{ + + 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{ + + 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(); + for(int i=0;i{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/TxCountPrefixRow.java b/src/main/java/com/lbry/database/rows/TxCountPrefixRow.java new file mode 100644 index 0000000..d7633e6 --- /dev/null +++ b/src/main/java/com/lbry/database/rows/TxCountPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/UTXOPrefixRow.java b/src/main/java/com/lbry/database/rows/UTXOPrefixRow.java new file mode 100644 index 0000000..67cae9d --- /dev/null +++ b/src/main/java/com/lbry/database/rows/UTXOPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/rows/UndoPrefixRow.java b/src/main/java/com/lbry/database/rows/UndoPrefixRow.java new file mode 100644 index 0000000..fdbd5cd --- /dev/null +++ b/src/main/java/com/lbry/database/rows/UndoPrefixRow.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/lbry/database/values/ActivationValue.java b/src/main/java/com/lbry/database/values/ActivationValue.java new file mode 100644 index 0000000..9987612 --- /dev/null +++ b/src/main/java/com/lbry/database/values/ActivationValue.java @@ -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 + '\'' + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/values/ActiveAmountValue.java b/src/main/java/com/lbry/database/values/ActiveAmountValue.java new file mode 100644 index 0000000..4f07c64 --- /dev/null +++ b/src/main/java/com/lbry/database/values/ActiveAmountValue.java @@ -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 + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/values/BidOrderValue.java b/src/main/java/com/lbry/database/values/BidOrderValue.java new file mode 100644 index 0000000..3e46419 --- /dev/null +++ b/src/main/java/com/lbry/database/values/BidOrderValue.java @@ -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) + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/values/BlockHashValue.java b/src/main/java/com/lbry/database/values/BlockHashValue.java new file mode 100644 index 0000000..f3cb4d3 --- /dev/null +++ b/src/main/java/com/lbry/database/values/BlockHashValue.java @@ -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) + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/values/BlockHeaderValue.java b/src/main/java/com/lbry/database/values/BlockHeaderValue.java new file mode 100644 index 0000000..18d345b --- /dev/null +++ b/src/main/java/com/lbry/database/values/BlockHeaderValue.java @@ -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) + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/values/BlockTxsValue.java b/src/main/java/com/lbry/database/values/BlockTxsValue.java new file mode 100644 index 0000000..1836c97 --- /dev/null +++ b/src/main/java/com/lbry/database/values/BlockTxsValue.java @@ -0,0 +1,16 @@ +package com.lbry.database.values; + +import java.util.List; + +public class BlockTxsValue implements ValueInterface { + + public List tx_hashes; + + @Override + public String toString() { + return "BlockTxsValue{" + + "tx_hashes=" + tx_hashes + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/values/ChannelCountValue.java b/src/main/java/com/lbry/database/values/ChannelCountValue.java new file mode 100644 index 0000000..a4f2de6 --- /dev/null +++ b/src/main/java/com/lbry/database/values/ChannelCountValue.java @@ -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 + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/values/ChannelToClaimValue.java b/src/main/java/com/lbry/database/values/ChannelToClaimValue.java new file mode 100644 index 0000000..aee9f19 --- /dev/null +++ b/src/main/java/com/lbry/database/values/ChannelToClaimValue.java @@ -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) + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/values/ClaimExpirationValue.java b/src/main/java/com/lbry/database/values/ClaimExpirationValue.java new file mode 100644 index 0000000..a0979d5 --- /dev/null +++ b/src/main/java/com/lbry/database/values/ClaimExpirationValue.java @@ -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 + '\'' + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/values/ClaimShortIDValue.java b/src/main/java/com/lbry/database/values/ClaimShortIDValue.java new file mode 100644 index 0000000..605ec39 --- /dev/null +++ b/src/main/java/com/lbry/database/values/ClaimShortIDValue.java @@ -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 + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/values/ClaimTakeoverValue.java b/src/main/java/com/lbry/database/values/ClaimTakeoverValue.java new file mode 100644 index 0000000..bbe35cd --- /dev/null +++ b/src/main/java/com/lbry/database/values/ClaimTakeoverValue.java @@ -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 + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/values/ClaimToChannelValue.java b/src/main/java/com/lbry/database/values/ClaimToChannelValue.java new file mode 100644 index 0000000..dfd53d3 --- /dev/null +++ b/src/main/java/com/lbry/database/values/ClaimToChannelValue.java @@ -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) + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/values/ClaimToSupportValue.java b/src/main/java/com/lbry/database/values/ClaimToSupportValue.java new file mode 100644 index 0000000..a749365 --- /dev/null +++ b/src/main/java/com/lbry/database/values/ClaimToSupportValue.java @@ -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 + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/values/ClaimToTXOValue.java b/src/main/java/com/lbry/database/values/ClaimToTXOValue.java new file mode 100644 index 0000000..8cd2dc3 --- /dev/null +++ b/src/main/java/com/lbry/database/values/ClaimToTXOValue.java @@ -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 + '\'' + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/values/DBState.java b/src/main/java/com/lbry/database/values/DBState.java new file mode 100644 index 0000000..f6da97a --- /dev/null +++ b/src/main/java/com/lbry/database/values/DBState.java @@ -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 + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/values/EffectiveAmountValue.java b/src/main/java/com/lbry/database/values/EffectiveAmountValue.java new file mode 100644 index 0000000..d30fbe6 --- /dev/null +++ b/src/main/java/com/lbry/database/values/EffectiveAmountValue.java @@ -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 + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/values/FutureEffectiveAmountValue.java b/src/main/java/com/lbry/database/values/FutureEffectiveAmountValue.java new file mode 100644 index 0000000..22933ab --- /dev/null +++ b/src/main/java/com/lbry/database/values/FutureEffectiveAmountValue.java @@ -0,0 +1,14 @@ +package com.lbry.database.values; + +public class FutureEffectiveAmountValue implements ValueInterface { + + public long future_effective_amount; + + @Override + public String toString() { + return "FutureEffectiveAmountValue{" + + "future_effective_amount=" + future_effective_amount + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/values/HashXHistoryHasherValue.java b/src/main/java/com/lbry/database/values/HashXHistoryHasherValue.java new file mode 100644 index 0000000..7cc5eaf --- /dev/null +++ b/src/main/java/com/lbry/database/values/HashXHistoryHasherValue.java @@ -0,0 +1,7 @@ +package com.lbry.database.values; + +public class HashXHistoryHasherValue implements ValueInterface { + + //TODO hasher: ResumableSHA256 + +} diff --git a/src/main/java/com/lbry/database/values/HashXHistoryValue.java b/src/main/java/com/lbry/database/values/HashXHistoryValue.java new file mode 100644 index 0000000..c6beb43 --- /dev/null +++ b/src/main/java/com/lbry/database/values/HashXHistoryValue.java @@ -0,0 +1,16 @@ +package com.lbry.database.values; + +import java.util.List; + +public class HashXHistoryValue implements ValueInterface { + + public List tx_nums; + + @Override + public String toString() { + return "HashXHistoryValue{" + + "tx_nums=" + tx_nums + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/values/HashXStatusValue.java b/src/main/java/com/lbry/database/values/HashXStatusValue.java new file mode 100644 index 0000000..1c28563 --- /dev/null +++ b/src/main/java/com/lbry/database/values/HashXStatusValue.java @@ -0,0 +1,16 @@ +package com.lbry.database.values; + +import java.util.Arrays; + +public class HashXStatusValue implements ValueInterface { + + public byte[] status; + + @Override + public String toString() { + return "HashXStatusValue{" + + "status=" + Arrays.toString(status) + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/lbry/database/values/HashXUTXOValue.java b/src/main/java/com/lbry/database/values/HashXUTXOValue.java new file mode 100644 index 0000000..996014d --- /dev/null +++ b/src/main/java/com/lbry/database/values/HashXUTXOValue.java @@ -0,0 +1,16 @@ +package com.lbry.database.values; + +import java.util.Arrays; + +public class HashXUTXOValue implements ValueInterface { + + public byte[] hashX; + + @Override + public String toString() { + return "HashXUTXOValue{" + + "hashX=" + Arrays.toString(hashX) + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/values/MempoolTxValue.java b/src/main/java/com/lbry/database/values/MempoolTxValue.java new file mode 100644 index 0000000..304fd81 --- /dev/null +++ b/src/main/java/com/lbry/database/values/MempoolTxValue.java @@ -0,0 +1,16 @@ +package com.lbry.database.values; + +import java.util.Arrays; + +public class MempoolTxValue implements ValueInterface { + + public byte[] raw_tx; + + @Override + public String toString() { + return "MempoolTxValue{" + + "raw_tx=" + Arrays.toString(raw_tx) + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/values/PendingActivationValue.java b/src/main/java/com/lbry/database/values/PendingActivationValue.java new file mode 100644 index 0000000..aaab23e --- /dev/null +++ b/src/main/java/com/lbry/database/values/PendingActivationValue.java @@ -0,0 +1,18 @@ +package com.lbry.database.values; + +import java.util.Arrays; + +public class PendingActivationValue implements ValueInterface { + + public byte[] claim_hash; + public String normalized_name; + + @Override + public String toString() { + return "PendingActivationValue{" + + "claim_hash=" + Arrays.toString(claim_hash) + + ", normalized_name='" + normalized_name + '\'' + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/values/RepostValue.java b/src/main/java/com/lbry/database/values/RepostValue.java new file mode 100644 index 0000000..31650f3 --- /dev/null +++ b/src/main/java/com/lbry/database/values/RepostValue.java @@ -0,0 +1,16 @@ +package com.lbry.database.values; + +import java.util.Arrays; + +public class RepostValue implements ValueInterface { + + public byte[] reposted_claim_hash; + + @Override + public String toString() { + return "RepostValue{" + + "reposted_claim_hash=" + Arrays.toString(reposted_claim_hash) + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/values/RepostedCountValue.java b/src/main/java/com/lbry/database/values/RepostedCountValue.java new file mode 100644 index 0000000..74db145 --- /dev/null +++ b/src/main/java/com/lbry/database/values/RepostedCountValue.java @@ -0,0 +1,14 @@ +package com.lbry.database.values; + +public class RepostedCountValue implements ValueInterface { + + public int reposted_count; + + @Override + public String toString() { + return "RepostedCountValue{" + + "reposted_count=" + reposted_count + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/values/RepostedValue.java b/src/main/java/com/lbry/database/values/RepostedValue.java new file mode 100644 index 0000000..c39fd16 --- /dev/null +++ b/src/main/java/com/lbry/database/values/RepostedValue.java @@ -0,0 +1,16 @@ +package com.lbry.database.values; + +import java.util.Arrays; + +public class RepostedValue implements ValueInterface { + + public byte[] claim_hash; + + @Override + public String toString() { + return "RepostedValue{" + + "claim_hash=" + Arrays.toString(claim_hash) + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/values/SupportAmountValue.java b/src/main/java/com/lbry/database/values/SupportAmountValue.java new file mode 100644 index 0000000..440a4d3 --- /dev/null +++ b/src/main/java/com/lbry/database/values/SupportAmountValue.java @@ -0,0 +1,14 @@ +package com.lbry.database.values; + +public class SupportAmountValue implements ValueInterface { + + public long amount; + + @Override + public String toString() { + return "SupportAmountValue{" + + "amount=" + amount + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/values/SupportToClaimValue.java b/src/main/java/com/lbry/database/values/SupportToClaimValue.java new file mode 100644 index 0000000..64ca5f4 --- /dev/null +++ b/src/main/java/com/lbry/database/values/SupportToClaimValue.java @@ -0,0 +1,16 @@ +package com.lbry.database.values; + +import java.util.Arrays; + +public class SupportToClaimValue implements ValueInterface { + + public byte[] claim_hash; + + @Override + public String toString() { + return "SupportToClaimValue{" + + "claim_hash=" + Arrays.toString(claim_hash) + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/values/TXOToClaimValue.java b/src/main/java/com/lbry/database/values/TXOToClaimValue.java new file mode 100644 index 0000000..57fd1d9 --- /dev/null +++ b/src/main/java/com/lbry/database/values/TXOToClaimValue.java @@ -0,0 +1,18 @@ +package com.lbry.database.values; + +import java.util.Arrays; + +public class TXOToClaimValue implements ValueInterface { + + public byte[] claim_hash; + public String name; + + @Override + public String toString() { + return "TXOToClaimValue{" + + "claim_hash=" + Arrays.toString(claim_hash) + + ", name='" + name + '\'' + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/values/TouchedHashXValue.java b/src/main/java/com/lbry/database/values/TouchedHashXValue.java new file mode 100644 index 0000000..a9e56e8 --- /dev/null +++ b/src/main/java/com/lbry/database/values/TouchedHashXValue.java @@ -0,0 +1,16 @@ +package com.lbry.database.values; + +import java.util.List; + +public class TouchedHashXValue implements ValueInterface { + + public List touched_hashXs; + + @Override + public String toString() { + return "TouchedHashXValue{" + + "touched_hashXs=" + touched_hashXs + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/values/TouchedOrDeletedClaimValue.java b/src/main/java/com/lbry/database/values/TouchedOrDeletedClaimValue.java new file mode 100644 index 0000000..ae7264d --- /dev/null +++ b/src/main/java/com/lbry/database/values/TouchedOrDeletedClaimValue.java @@ -0,0 +1,18 @@ +package com.lbry.database.values; + +import java.util.Set; + +public class TouchedOrDeletedClaimValue implements ValueInterface { + + public Set touched_claims; + public Set deleted_claims; + + @Override + public String toString() { + return "TouchedOrDeletedClaimValue{" + + "touched_claims=" + touched_claims + + ", deleted_claims=" + deleted_claims + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/values/TrendingNotificationValue.java b/src/main/java/com/lbry/database/values/TrendingNotificationValue.java new file mode 100644 index 0000000..0b99e27 --- /dev/null +++ b/src/main/java/com/lbry/database/values/TrendingNotificationValue.java @@ -0,0 +1,16 @@ +package com.lbry.database.values; + +public class TrendingNotificationValue implements ValueInterface { + + public long previous_amount; + public long new_amount; + + @Override + public String toString() { + return "TrendingNotificationValue{" + + "previous_amount=" + previous_amount + + ", new_amount=" + new_amount + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/values/TxCountValue.java b/src/main/java/com/lbry/database/values/TxCountValue.java new file mode 100644 index 0000000..fea8465 --- /dev/null +++ b/src/main/java/com/lbry/database/values/TxCountValue.java @@ -0,0 +1,14 @@ +package com.lbry.database.values; + +public class TxCountValue implements ValueInterface { + + public int tx_count; + + @Override + public String toString() { + return "TxCountValue{" + + "tx_count=" + tx_count + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/values/TxHashValue.java b/src/main/java/com/lbry/database/values/TxHashValue.java new file mode 100644 index 0000000..d415efb --- /dev/null +++ b/src/main/java/com/lbry/database/values/TxHashValue.java @@ -0,0 +1,16 @@ +package com.lbry.database.values; + +import java.util.Arrays; + +public class TxHashValue implements ValueInterface { + + public byte[] tx_hash; + + @Override + public String toString() { + return "TxHashValue{" + + "tx_hash=" + Arrays.toString(tx_hash) + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/values/TxNumValue.java b/src/main/java/com/lbry/database/values/TxNumValue.java new file mode 100644 index 0000000..a123bd4 --- /dev/null +++ b/src/main/java/com/lbry/database/values/TxNumValue.java @@ -0,0 +1,14 @@ +package com.lbry.database.values; + +public class TxNumValue implements ValueInterface { + + public int tx_num; + + @Override + public String toString() { + return "TxNumValue{" + + "tx_num=" + tx_num + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/values/TxValue.java b/src/main/java/com/lbry/database/values/TxValue.java new file mode 100644 index 0000000..28bcc56 --- /dev/null +++ b/src/main/java/com/lbry/database/values/TxValue.java @@ -0,0 +1,16 @@ +package com.lbry.database.values; + +import java.util.Arrays; + +public class TxValue implements ValueInterface { + + public byte[] raw_tx; + + @Override + public String toString() { + return "TxValue{" + + "raw_tx=" + Arrays.toString(raw_tx) + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/values/UTXOValue.java b/src/main/java/com/lbry/database/values/UTXOValue.java new file mode 100644 index 0000000..fdfc8a4 --- /dev/null +++ b/src/main/java/com/lbry/database/values/UTXOValue.java @@ -0,0 +1,14 @@ +package com.lbry.database.values; + +public class UTXOValue implements ValueInterface { + + public long amount; + + @Override + public String toString() { + return "UTXOValue{" + + "amount=" + amount + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/values/UndoValue.java b/src/main/java/com/lbry/database/values/UndoValue.java new file mode 100644 index 0000000..37aec18 --- /dev/null +++ b/src/main/java/com/lbry/database/values/UndoValue.java @@ -0,0 +1,16 @@ +package com.lbry.database.values; + +import java.util.Arrays; + +public class UndoValue implements ValueInterface { + + public byte[] data; + + @Override + public String toString() { + return "UndoValue{" + + "data=" + Arrays.toString(data) + + '}'; + } + +} diff --git a/src/main/java/com/lbry/database/values/ValueInterface.java b/src/main/java/com/lbry/database/values/ValueInterface.java new file mode 100644 index 0000000..dbe737c --- /dev/null +++ b/src/main/java/com/lbry/database/values/ValueInterface.java @@ -0,0 +1,7 @@ +package com.lbry.database.values; + +public interface ValueInterface { + + ValueInterface NULL = null; + +} \ No newline at end of file