Skip to content

Updated Implementation Proposal #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: v0.6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
446 changes: 446 additions & 0 deletions docs/2018-11-12 - Implementation Proposal.md

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion include/blocksci/address/address.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,22 @@ namespace blocksci {

ranges::any_view<OutputPointer> getOutputPointers() const;
int64_t calculateBalance(BlockHeight height) const;
// get balances for each related chain
std::vector<std::pair<uint8_t, int64_t>> calculateBalances(BlockHeight height) const;

ranges::any_view<Output> getOutputs() const;
ranges::any_view<Input> getInputs() const;

std::vector<std::pair<uint8_t, ranges::any_view<Output>>> getOutputs(std::vector<uint8_t> chainIds) const;
std::vector<Output> getOutputs(uint8_t chainId) const;

std::vector<std::pair<uint8_t, ranges::any_view<Input>>> getInputs(std::vector<uint8_t> chainIds) const;
std::vector<Input> getInputs(uint8_t chainId) const;

std::vector<Transaction> getTransactions() const;
ranges::any_view<Transaction> getOutputTransactions() const;
std::vector<Transaction> getInputTransactions() const;

std::string fullType() const;
};

Expand Down
2 changes: 2 additions & 0 deletions include/blocksci/chain/block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ namespace blocksci {
Transaction coinbaseTx() const {
return (*this)[0];
}

uint8_t getChainId() const;
};

inline bool BLOCKSCI_EXPORT isSegwit(const Block &block) {
Expand Down
2 changes: 2 additions & 0 deletions include/blocksci/chain/blockchain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ namespace blocksci {
void reload();

uint32_t addressCount(AddressType::Enum type) const;

uint8_t getChainId() const;
};

uint32_t BLOCKSCI_EXPORT txCount(Blockchain &chain);
Expand Down
12 changes: 12 additions & 0 deletions include/blocksci/chain/input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,25 @@ namespace blocksci {

// Get the Transaction that contains the output that is spent by this input
Transaction getSpentTx() const;
Transaction getSpentTx(uint8_t chainId) const;

std::vector<std::pair<uint8_t, Transaction>> getSpentTxes() const;
std::vector<std::pair<uint8_t, Transaction>> getSpentTxes(std::vector<uint8_t> chainIds) const;

// Get OutputPointer of the output that this input spends
OutputPointer getSpentOutputPointer() const {
return {inout->getLinkedTxNum(), *spentOutputNum};
}

// Get OutputPointer of the outputs that this input spends
OutputPointer getSpentOutputPointers() const;
OutputPointer getSpentOutputPointers(uint8_t chainId) const;
OutputPointer getSpentOutputPointers(std::vector<uint8_t> chainIds) const;

Output getSpentOutput() const;


uint8_t getChainId() const;
};

inline bool BLOCKSCI_EXPORT operator==(const Input& a, const Input& b) {
Expand Down
32 changes: 28 additions & 4 deletions include/blocksci/chain/output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,21 @@ namespace blocksci {

Output(const OutputPointer &pointer_, BlockHeight blockHeight_, const Inout &inout_, uint32_t maxTxLoaded, DataAccess &access_) :
access(&access_), inout(&inout_), blockHeight(blockHeight_), pointer(pointer_) {
if (inout->getLinkedTxNum() < maxTxLoaded) {
spendingTxIndex = inout->getLinkedTxNum();
} else {
spendingTxIndex = 0;
/* TODO: getSpendingTx issue
*
*/
if (blockHeight < access->getChain().forkBlockHeight) {
//
// for pre-fork data, get spendingTxIndex from separate file, as the Inout only cointains data from the parent (= main) chain
// eg. a FixedSizeFileMapper<uint32_t>, accessed by tx index
}
else {
// get spendingTxIndex from tx_data.dat file of the fork itself
if (inout->getLinkedTxNum() < maxTxLoaded) {
spendingTxIndex = inout->getLinkedTxNum();
} else {
spendingTxIndex = 0;
}
}
}

Expand All @@ -61,6 +72,9 @@ namespace blocksci {
ranges::optional<uint32_t> getSpendingTxIndex() const {
return spendingTxIndex > 0 ? ranges::optional<uint32_t>{spendingTxIndex} : ranges::nullopt;
}

// Get the tx numbers of the txes that spend this output (in one of its inputs)
std::vector<std::pair<uint8_t, uint32_t>> getSpendingTxIndexes() const;

uint32_t txIndex() const {
return pointer.txNum;
Expand Down Expand Up @@ -100,6 +114,16 @@ namespace blocksci {
ranges::optional<Input> getSpendingInput() const;

ranges::optional<InputPointer> getSpendingInputPointer() const;

uint8_t getChainId() const;

// get all transactions that spend this output
std::vector<std::pair<uint8_t, Transaction>> getSpendingTxes() const;

// Get the Inputs that spend this Output (possibly on several chains)
std::vector<std::pair<uint8_t, Input>> getSpendingInputs() const;

std::vector<std::pair<uint8_t, InputPointer>> getSpendingInputPointers() const;
};

inline bool BLOCKSCI_EXPORT operator==(const Output& a, const Output& b) {
Expand Down
19 changes: 19 additions & 0 deletions include/blocksci/chain/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,25 @@ namespace blocksci {
}

Block block() const;

// get transactions with the same tx hash (forks without replay protection)
// can be implemented as a range query on HashIndex
// for all chains
std::vector<Transaction> getDuplicates() const;
// for the given chain
Transaction getDuplicates(uint8_t chainId) const;
// for the given chains
Transaction getDuplicates(std::vector<uint8_t> chainIds) const;

// check whether other transactions with the same tx hash exists
// can be implemented as a range query on HashIndex as well
bool hasDuplicates() const;
bool hasDuplicate(uint8_t chainId) const;
bool hasDuplicate(std::vector<uint8_t> chainIds) const;

uint8_t getChainId() const {
return getAccess()->config.chainConfig.coinName;
}
};

inline bool BLOCKSCI_EXPORT operator==(const Transaction& a, const Transaction& b) {
Expand Down
45 changes: 45 additions & 0 deletions include/blocksci/core/chain_ids.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// chain_ids.hpp
// blocksci_devel
//

#ifndef blocksci_chain_ids_hpp
#define blocksci_chain_ids_hpp

#include <blocksci/blocksci_export.h>

#include <cstddef>
#include <functional>
#include <tuple>


namespace blocksci {
class BLOCKSCI_EXPORT ChainId {
public:
static const uint8_t RESERVED = 0;

static const uint8_t BITCOIN = 1;
static const uint8_t BITCOIN_TESTNET = 2;
static const uint8_t BITCOIN_REGTEST = 3;

static const uint8_t BITCOIN_CASH = 4;
static const uint8_t BITCOIN_CASH_TESTNET = 5;
static const uint8_t BITCOIN_CASH_REGTEST = 6;

static const uint8_t LITECOIN = 7;
static const uint8_t LITECOIN_TESTNET = 8;
static const uint8_t LITECOIN_REGTEST = 9;

static const uint8_t DASH = 10;
static const uint8_t DASH_TESTNET = 11;

static const uint8_t ZCASH = 12;
static const uint8_t ZCASH_TESTNET = 13;

static const uint8_t NAMECOIN = 14;
static const uint8_t NAMECOIN_TESTNET = 15;

};
}

#endif /* blocksci_chain_ids_hpp */
Loading