Skip to content

Commit

Permalink
upgrade: update from cryptogarageinc v0.3.18 (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
ko-matsu authored Sep 26, 2021
1 parent 822c872 commit 4e90823
Show file tree
Hide file tree
Showing 47 changed files with 1,929 additions and 267 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/check_pre-merge_develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,12 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, ubuntu-18.04, ubuntu-16.04]
os: [ubuntu-20.04, ubuntu-18.04]
shared: [on, off]
elements: [on, off]
exclude:
- os: ubuntu-18.04
elements: off
- os: ubuntu-16.04
elements: off

steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/check_pre-merge_master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,12 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, ubuntu-18.04, ubuntu-16.04]
os: [ubuntu-20.04, ubuntu-18.04]
shared: [on, off]
elements: [on, off]
exclude:
- os: ubuntu-18.04
elements: off
- os: ubuntu-16.04
elements: off

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ if(LIBWALLY_TARGET_VERSION)
set(LIBWALLY_TARGET_TAG ${LIBWALLY_TARGET_VERSION})
message(STATUS "[external project local] libwally-core target=${LIBWALLY_TARGET_VERSION}")
else()
set(LIBWALLY_TARGET_TAG refs/tags/cfd-0.3.7)
set(LIBWALLY_TARGET_TAG refs/tags/cfd-0.3.8)
endif()
if(LIBWALLY_TARGET_URL)
set(LIBWALLY_TARGET_REP ${LIBWALLY_TARGET_URL})
Expand Down
28 changes: 28 additions & 0 deletions include/cfdcore/cfdcore_address.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,34 @@ class CFD_CORE_EXPORT Address {
*/
Script GetLockingScript() const;

/**
* @brief Get the pegout address.
* @param[in] type network type
* @param[in] locking_script pegout locking script
* @return address
*/
static Address GetPegoutAddress(NetType type, const Script& locking_script);
/**
* @brief Get the pegout address.
* @param[in] type network type
* @param[in] locking_script pegout locking script
* @param[in] network_parameter network prefix parameter
* @return address
*/
static Address GetPegoutAddress(
NetType type, const Script& locking_script,
const AddressFormatData& network_parameter);
/**
* @brief Get the pegout address.
* @param[in] type network type
* @param[in] locking_script pegout locking script
* @param[in] network_parameters network prefix list
* @return address
*/
static Address GetPegoutAddress(
NetType type, const Script& locking_script,
const std::vector<AddressFormatData>& network_parameters);

private:
/**
* @brief calculate P2SH Address
Expand Down
154 changes: 154 additions & 0 deletions include/cfdcore/cfdcore_block.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
// Copyright 2021 CryptoGarage
/**
* @file cfdcore_block.h
*
* @brief The block related class definition.
*/
#ifndef CFD_CORE_INCLUDE_CFDCORE_CFDCORE_BLOCK_H_
#define CFD_CORE_INCLUDE_CFDCORE_CFDCORE_BLOCK_H_

#include <string>
#include <vector>

#include "cfdcore/cfdcore_bytedata.h"
#include "cfdcore/cfdcore_coin.h"
#include "cfdcore/cfdcore_common.h"
#include "cfdcore/cfdcore_transaction.h"

namespace cfd {
namespace core {

/**
* @brief block header.
*/
struct BlockHeader {
uint32_t version = 0; //!< version
BlockHash prev_block_hash; //!< previous block hash
BlockHash merkle_root_hash; //!< merkle root hash
uint32_t time = 0; //!< time
uint32_t bits = 0; //!< bits
uint32_t nonce = 0; //!< nonce
};

/**
* @brief block data class.
*/
class CFD_CORE_EXPORT Block {
public:
/**
* @brief default constructor
*/
Block();
/**
* @brief constructor
* @param[in] hex hex string
*/
explicit Block(const std::string& hex);
/**
* @brief constructor
* @param[in] data byte data
*/
explicit Block(const ByteData& data);
/**
* @brief destructor.
*/
virtual ~Block() {
// do nothing
}
/**
* @brief copy constructor.
* @param[in] object object
*/
Block(const Block& object);
/**
* @brief copy constructor.
* @param[in] object object
* @return object
*/
Block& operator=(const Block& object);
/**
* @brief Get a hex string.
* @return hex string
*/
std::string GetHex() const;
/**
* @brief Get a ByteData object.
* @return ByteData object.
*/
ByteData GetData() const;
/**
* @brief check valid data.
* @retval true valid.
* @retval false invalid.
*/
bool IsValid() const;
/**
* @brief Get a BlockHash.
* @return block hash.
*/
BlockHash GetBlockHash() const;

/**
* @brief get txoutproof.
* @param[in] txid target txid
* @return txoutproof.
*/
ByteData GetTxOutProof(const Txid& txid) const;
/**
* @brief get txoutproof.
* @param[in] txids target txid list
* @return txoutproof.
*/
ByteData GetTxOutProof(const std::vector<Txid>& txids) const;

/**
* @brief get txid.
* @param[in] index tx index
* @return txid.
*/
Txid GetTxid(uint32_t index) const;
/**
* @brief get txid list.
* @return txid list.
*/
std::vector<Txid> GetTxids() const;
/**
* @brief exist txid.
* @param[in] txid txid
* @retval true exist
* @retval false not exist
*/
bool ExistTxid(const Txid& txid) const;
/**
* @brief Get the transaction.
* @param[in] txid txid
* @return transaction
*/
Transaction GetTransaction(const Txid& txid) const;
/**
* @brief Get the transaction count.
* @return transaction count
*/
uint32_t GetTransactionCount() const;
/**
* @brief get block header.
* @return block header.
*/
BlockHeader GetBlockHeader() const;
/**
* @brief Serialize block header.
* @return Serialized block header.
*/
ByteData SerializeBlockHeader() const;

private:
ByteData data_; ///< byte data
BlockHeader header_; ///< block header
std::vector<ByteData> txs_; ///< transaction data list
std::vector<Txid> txids_; ///< transaction id list
};

} // namespace core
} // namespace cfd

#endif // CFD_CORE_INCLUDE_CFDCORE_CFDCORE_BLOCK_H_
40 changes: 40 additions & 0 deletions include/cfdcore/cfdcore_bytedata.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,21 @@ class CFD_CORE_EXPORT ByteData {
return result.Concat(args...);
}

/**
* @brief Split a byte data.
* @param[in] split_size_list split size list.
* @return split byte data list.
*/
std::vector<ByteData> SplitData(
const std::vector<uint32_t>& split_size_list) const;

/**
* @brief Split a byte data.
* @param[in] size_from_top size from top.
* @return split byte data list.
*/
ByteData SplitData(uint32_t size_from_top) const;

/**
* @brief Push to back.
* @param[in] back_insert_data back insert data.
Expand Down Expand Up @@ -565,6 +580,13 @@ class CFD_CORE_EXPORT Serializer {
static constexpr uint8_t kViTag64 = 255; //!< VarInt64
static constexpr uint8_t kViMax8 = 252; //!< VarInt8

/**
* @brief check big endian.
* @retval true big endian.
* @retval false little endian.
*/
static bool IsBigEndian();

/**
* @brief get variable integer size.
* @param[in] value value
Expand Down Expand Up @@ -667,6 +689,12 @@ class CFD_CORE_EXPORT Serializer {
*/
void AddDirectNumber(int64_t number);

/**
* @brief add direct number.
* @param[in] number value
*/
void AddDirectBigEndianNumber(uint32_t number);

/**
* @brief add direct byte array.
* @param[in] buffer buffer
Expand Down Expand Up @@ -772,6 +800,11 @@ class CFD_CORE_EXPORT Deserializer {
* @return uint8
*/
uint8_t ReadUint8();
/**
* @brief read uint32 from big endian.
* @return uint32
*/
uint32_t ReadUint32FromBigEndian();

/**
* @brief read variable integer.
Expand Down Expand Up @@ -808,6 +841,13 @@ class CFD_CORE_EXPORT Deserializer {
*/
uint32_t GetReadSize();

/**
* @brief Check EOF.
* @retval true already eof.
* @retval false not eof.
*/
bool HasEof();

protected:
std::vector<uint8_t> buffer_; //!< buffer
uint32_t offset_; //!< offset
Expand Down
36 changes: 27 additions & 9 deletions include/cfdcore/cfdcore_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,19 @@ class CFD_CORE_EXPORT DescriptorScriptReference {
explicit DescriptorScriptReference(
const Address& address_script,
const std::vector<AddressFormatData>& address_prefixes);
/**
* @brief constructor.
* @param[in] locking_script locking script
* @param[in] script_type script type
* @param[in] key_list key(pubkey, extprivkey, extpubkey) list
* @param[in] tapbranch taproot tapbranch
* @param[in] address_prefixes address prefix list
*/
explicit DescriptorScriptReference(
const Script& locking_script, DescriptorScriptType script_type,
const std::vector<DescriptorKeyReference>& key_list,
const TapBranch& tapbranch,
const std::vector<AddressFormatData>& address_prefixes);
/**
* @brief constructor.
* @param[in] locking_script locking script
Expand Down Expand Up @@ -525,6 +538,17 @@ class CFD_CORE_EXPORT DescriptorScriptReference {
std::vector<DescriptorKeyReference> GetKeyList() const;

// taproot api
/**
* @brief exist taproot tapbranch.
* @retval true exist
* @retval false not exist
*/
bool HasTapBranch() const;
/**
* @brief getting taproot tapbranch.
* @return tapbranch
*/
TapBranch GetTapBranch() const;
/**
* @brief exist taproot script tree.
* @retval true exist
Expand All @@ -550,6 +574,8 @@ class CFD_CORE_EXPORT DescriptorScriptReference {
Script redeem_script_; //!< redeem script
Address address_script_; //!< address script data
uint32_t req_num_; //!< multisig require signature number
TapBranch tapbranch_; //!< taproot branch
bool is_tapbranch_; //!< exist tapbranch
TaprootScriptTree script_tree_; //!< taproot script tree
//! child script
std::shared_ptr<DescriptorScriptReference> child_script_ = nullptr;
Expand Down Expand Up @@ -658,20 +684,12 @@ class CFD_CORE_EXPORT DescriptorNode {
* @return pubkey
*/
Pubkey GetPubkey(std::vector<std::string>* array_argument) const;
/**
* @brief get schnorr pubkey.
* @param[in] array_argument argument array.
* @return schnorr pubkey
*/
SchnorrPubkey GetSchnorrPubkey(
std::vector<std::string>* array_argument) const;
/**
* @brief get script tree.
* @param[in] array_argument argument array.
* @return TapBranch
*/
TaprootScriptTree GetScriptTree(
std::vector<std::string>* array_argument) const;
TapBranch GetTapBranch(std::vector<std::string>* array_argument) const;
/**
* @brief get key reference object.
* @param[in] array_argument argument
Expand Down
Loading

0 comments on commit 4e90823

Please sign in to comment.