diff --git a/.github/workflows/check_pre-merge_master.yml b/.github/workflows/check_pre-merge_master.yml
index 397d2e79..9dae4b05 100644
--- a/.github/workflows/check_pre-merge_master.yml
+++ b/.github/workflows/check_pre-merge_master.yml
@@ -40,7 +40,8 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
- os: [macos-10.15, macos-11.0]
+ os: [macos-10.15]
+# os: [macos-10.15, macos-11.0]
steps:
- uses: actions/checkout@v2
diff --git a/.github/workflows/check_pre-merge_sprint.yml b/.github/workflows/check_pre-merge_sprint.yml
index 7b537f4f..43ed6b79 100644
--- a/.github/workflows/check_pre-merge_sprint.yml
+++ b/.github/workflows/check_pre-merge_sprint.yml
@@ -40,7 +40,8 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
- os: [macos-10.15, macos-11.0]
+ os: [macos-10.15]
+ # os: [macos-10.15, macos-11.0]
steps:
- uses: actions/checkout@v2
@@ -104,6 +105,41 @@ jobs:
name: output-lcov-cfdcore-${{ matrix.os }}
path: ./build/lcov_cfdcore_output.zip
+ ubuntu-valgrind:
+ name: valgrind-ubuntu
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ os: [ubuntu-18.04]
+ shared: [on]
+
+ steps:
+ - uses: actions/checkout@v2
+ - name: dump version
+ run: |
+ cmake --version
+ gcc --version
+ - name: ubuntu-apt-install
+ run: |
+ cat /etc/os-release
+ sudo apt-get update
+ sudo apt-get install -y valgrind
+ - name: cmake-build
+ run: |
+ cmake --version
+ cmake -S . -B build -G "Unix Makefiles"
+ cmake -DENABLE_SHARED=${{ matrix.shared }} -DCMAKE_BUILD_TYPE=Debug -DTARGET_RPATH=./build/Debug --build build
+ cmake --build build --config Debug --parallel 4
+ - name: valgrind
+ run: |
+ # --valgrind-stacksize=1048576 --num-callers=12
+ valgrind -v --tool=memcheck --leak-check=full --valgrind-stacksize=10485760 --log-file=./valgrind.log --time-stamp=yes ./build/Debug/cfdcore_test
+ - name: upload coverage
+ uses: actions/upload-artifact@v1
+ with:
+ name: valgrind-log
+ path: ./valgrind.log
+
doxygen-ubuntu:
name: doxygen-check
runs-on: ubuntu-18.04
diff --git a/.github/workflows/code_scanner.yml b/.github/workflows/code_scanner.yml
index 97a986d0..43048bdb 100644
--- a/.github/workflows/code_scanner.yml
+++ b/.github/workflows/code_scanner.yml
@@ -14,11 +14,6 @@ on:
- '**.h'
- '**/code_scanner.yml'
- '**/external_project_local_setting.config'
- pull_request:
- branches:
- - master
- - develop
- - features/sprint*
jobs:
analyze-CodeQL:
diff --git a/README.md b/README.md
index 028afa3e..38501d2f 100644
--- a/README.md
+++ b/README.md
@@ -1,17 +1,53 @@
# Crypto Finance Development Kit Core (CFD-CORE)
-core moduels for cfd libraries
-
-
+This library is development kit for crypto finance application.
+Useful when developing applications for cryptocurrencies.
+
+### Target Network
+
+- Bitcoin
+- Liquid Network
+
+### Support function by cfd-core
+
+- Bitcoin
+ - Bitcoin Script (builder, viewer)
+ - Transaction
+ - PSBT (v0)
+ - ECDSA Pubkey/Privkey (TweakAdd/Mul, Negate, Sign, Verify)
+ - BIP32, BIP39
+ - Output Descriptor (contains miniscript parser)
+ - Schnorr/Taproot
+ - Bitcoin Address (Segwit-v0, Segwit-v1, P2PKH/P2SH)
+- Liquid Network
+ - Confidential Transaction
+ - Blind, Unblind
+ - Issuance, Reissuance
+ - PegIn, PegOut
+ - Confidential Address
+
+### Libraries for each language
+
+- C++ : cfd-core
+ - Core library. Definition base class.
+- C/C++ : cfd
+ - Extend the cfd-core library. Defines the C language API and extension classes.
+- Libraries to link cfd library:
+ - JavaScript : cfd-js
+ - WebAssembly : cfd-js-wasm
+ - Python : cfd-python
+ - C# : cfd-csharp
+ - Go : cfd-go
+ - Rust : cfd-rust
## Dependencies
- C/C++ Compiler
- - can compile c++11
+ - can compile c++11
- CMake (3.14.3 or higher)
- When using npm scripts and cmake-js
- node.js (stable version)
@@ -21,6 +57,7 @@ core moduels for cfd libraries
### Windows
download and install files.
+
- [CMake](https://cmake.org/) (3.14.3 or higher)
- Compiler or development environment (One of the following)
- MSVC
@@ -55,7 +92,7 @@ apt-get install -y build-essential cmake python nodejs
```
cmake version 3.14.2 or lower, download from website and install cmake.
-(https://cmake.org/download/)
+()
---
@@ -88,7 +125,7 @@ cmake -D ENABLE_SHARED=1 -DCMAKE_BUILD_TYPE=Release --build build
cmake --build build
```
-**CMake options**
+### CMake options
- `-DENABLE_ELEMENTS`: Enable functionalies for elements sidechain. [ON/OFF] (default:ON)
- `-DENABLE_SHARED`: Enable building a shared library. [ON/OFF] (default:OFF)
@@ -118,6 +155,7 @@ npm cmake_make_install
```
cmake version is 3.15 or higher:
+
```Shell
npm cmake_install
(Enter the password when prompted to use the sudo command.)
@@ -135,6 +173,7 @@ cd build && sudo ninja install
cmake version is 3.15 or higher: `cmake --install build`
### uninstall
+
```Shell
(uninstall by using makefile)
cd build && sudo make uninstall
@@ -167,6 +206,7 @@ npm run ctest
### using library
- [libwally-core](https://github.com/cryptogarageinc/libwally-core/tree/cfd-develop) (forked from [ElementsProject/libwally-core](https://github.com/ElementsProject/libwally-core))
+ - [secp256k1-zkp](https://github.com/cryptogarageinc/secp256k1-zkp/tree/cfd-develop) (forked from [ElementsProject/secp256k1-zkp](https://github.com/ElementsProject/secp256k1-zkp))
- [univalue](https://github.com/jgarzik/univalue) (for JSON encoding and decoding)
- [googletest](https://github.com/google/googletest) (for testing)
@@ -199,26 +239,29 @@ npm run ctest
## Note
-### Git connection:
+### Git connection
Git repository connections default to HTTPS.
However, depending on the connection settings of GitHub, you may only be able to connect via SSH.
As a countermeasure, forcibly establish SSH connection by setting `CFD_CMAKE_GIT_SSH=1` in the environment variable.
- Windows: (On the command line. Or set from the system setting screen.)
-```
+
+```Bat
set CFD_CMAKE_GIT_SSH=1
```
- MacOS & Linux(Ubuntu):
-```
+
+```Shell
export CFD_CMAKE_GIT_SSH=1
```
-### Ignore git update for CMake External Project:
+### Ignore git update for CMake External Project
Depending on your git environment, you may get the following error when checking out external:
-```
+
+```Shell
Performing update step for 'libwally-core-download'
Current branch cmake_build is up to date.
No stash entries found.
@@ -237,11 +280,13 @@ This phenomenon is due to the `git update` related command.
Please set an environment variable that skips update processing.
- Windows: (On the command line. Or set from the system setting screen.)
-```
+
+```Bat
set CFD_CMAKE_GIT_SKIP_UPDATE=1
```
- MacOS & Linux(Ubuntu):
-```
+
+```Shell
export CFD_CMAKE_GIT_SKIP_UPDATE=1
```
diff --git a/cmake/CfdCommonOption.cmake b/cmake/CfdCommonOption.cmake
index 73a61cef..848197f8 100644
--- a/cmake/CfdCommonOption.cmake
+++ b/cmake/CfdCommonOption.cmake
@@ -6,6 +6,7 @@ endif()
option(ENABLE_ELEMENTS "enable elements code (ON or OFF. default:ON)" ON)
option(ENABLE_TESTS "enable code tests (ON or OFF. default:ON)" ON)
option(ENABLE_EMSCRIPTEN "enable EMSCRIPTEN (ON or OFF. default:OFF)" OFF)
+option(STD_CPP_VERSION "c++ version (11/14/17. default:11)" "11")
# use "cmake -DCMAKE_BUILD_TYPE=Debug" or "cmake-js -D"
# option(ENABLE_DEBUG "enable debugging (ON or OFF. default:OFF)" OFF)
diff --git a/cmake/CfdWallyOption.cmake b/cmake/CfdWallyOption.cmake
index 63df95d0..8dc2cade 100644
--- a/cmake/CfdWallyOption.cmake
+++ b/cmake/CfdWallyOption.cmake
@@ -6,4 +6,5 @@ option(ENABLE_JS_WRAPPER "enable the Javascript interface wrappers (ON or OFF. d
else()
set(ENABLE_JS_WRAPPER OFF)
endif()
-set(GENERATE_WALLY ON)
+option(GENERATE_WALLY "generate the wally.xxx library (ON or OFF. default:ON)" ON)
+option(EXCLUDE_WALLYCORE_LIB "exclude wallycore lib (ON or OFF. default:OFF)" OFF)
diff --git a/cmake/Cpp11Setting.cmake b/cmake/Cpp11Setting.cmake
index c6beeab8..b92ed3e8 100644
--- a/cmake/Cpp11Setting.cmake
+++ b/cmake/Cpp11Setting.cmake
@@ -13,6 +13,11 @@ if(${USE_EMSCRIPTEN})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s DISABLE_EXCEPTION_CATCHING=0")
endif()
+if(${STD_CPP_VERSION})
+set(CMAKE_CXX_STANDARD ${STD_CPP_VERSION})
+message(STATUS "[STD_CPP_VERSION] ${STD_CPP_VERSION}")
+else()
set(CMAKE_CXX_STANDARD 11)
+endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt
index 45041394..3317a148 100644
--- a/external/CMakeLists.txt
+++ b/external/CMakeLists.txt
@@ -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.2.4)
+set(LIBWALLY_TARGET_TAG refs/tags/cfd-0.3.4)
endif()
if(${USE_GIT_SSH})
diff --git a/include/cfdcore/Makefile.srclist b/include/cfdcore/Makefile.srclist
index 0f78b3d7..0a262061 100644
--- a/include/cfdcore/Makefile.srclist
+++ b/include/cfdcore/Makefile.srclist
@@ -20,10 +20,12 @@ CFDCORE_PKGINCLUDE_FILES = \
cfdcore_key.h \
cfdcore_script.h \
cfdcore_descriptor.h \
+ cfdcore_psbt.h \
cfdcore_exception.h \
cfdcore_iterator.h \
cfdcore_logger_interface.h \
cfdcore_schnorrsig.h \
cfdcore_ecdsa_adaptor.h \
+ cfdcore_taproot.h \
$(CFDCORE_ELEMENTS_PKGINCLUDE_FILES)
diff --git a/include/cfdcore/cfdcore_address.h b/include/cfdcore/cfdcore_address.h
index 556b6c0a..c7d28813 100644
--- a/include/cfdcore/cfdcore_address.h
+++ b/include/cfdcore/cfdcore_address.h
@@ -2,7 +2,7 @@
/**
* @file cfdcore_address.h
*
- * @brief Addressクラス定義
+ * @brief Bitcoin address definition file.
*/
#ifndef CFD_CORE_INCLUDE_CFDCORE_CFDCORE_ADDRESS_H_
#define CFD_CORE_INCLUDE_CFDCORE_CFDCORE_ADDRESS_H_
@@ -13,7 +13,9 @@
#include "cfdcore/cfdcore_common.h"
#include "cfdcore/cfdcore_key.h"
+#include "cfdcore/cfdcore_schnorrsig.h"
#include "cfdcore/cfdcore_script.h"
+#include "cfdcore/cfdcore_taproot.h"
namespace cfd {
namespace core {
@@ -45,69 +47,68 @@ constexpr const char* const kPrefixBlindBech32Hrp = "blech32";
/**
* @class AddressFormatData
- * @brief \~japanese Address format dataクラス
- * \~english class for showing format data of address
+ * @brief class for showing format data of address
*/
class CFD_CORE_EXPORT AddressFormatData {
public:
/**
- * @brief コンストラクタ
+ * @brief constructor.
*/
AddressFormatData();
/**
- * @brief コンストラクタ
+ * @brief constructor.
* @param[in] default_format_name default format name
*/
explicit AddressFormatData(const std::string& default_format_name);
/**
- * @brief コンストラクタ
+ * @brief constructor.
* @param[in] map_data prefix setting map
*/
explicit AddressFormatData(
const std::map& map_data);
/**
- * @brief 文字列情報を取得する.
+ * @brief Get string value.
* @param[in] key mapping key
* @return value
*/
std::string GetString(const std::string& key) const;
/**
- * @brief 文字列情報を数値型に変換して取得する.
+ * @brief Get numeric value from string.
* @param[in] key mapping key
* @return uint32_t value
*/
uint32_t GetValue(const std::string& key) const;
/**
- * @brief P2pkhのprefix値を取得する.
+ * @brief Get P2pkh prefix.
* @return P2pkh prefix
*/
uint8_t GetP2pkhPrefix() const;
/**
- * @brief P2shのprefix値を取得する.
+ * @brief Get P2sh prefix.
* @return P2sh prefix
*/
uint8_t GetP2shPrefix() const;
/**
- * @brief bech32のhrpを取得する.
+ * @brief Get hrp on bech32.
* @return Bech32 hrp
*/
std::string GetBech32Hrp() const;
/**
- * @brief netTypeを取得する.
+ * @brief Get network type.
* @return network type
*/
NetType GetNetType() const;
/**
- * @brief json文字列情報からAddress format dataを取得する.
+ * @brief Get Address format data from json string.
* @param[in] json_data json string
* @return Address format data
*/
static AddressFormatData ConvertFromJson(const std::string& json_data);
/**
- * @brief json文字列情報からAddress format data一覧を取得する.
+ * @brief Get Address format data list from json string.
* @param[in] json_data json string
* @return Address format data list
*/
@@ -119,76 +120,64 @@ class CFD_CORE_EXPORT AddressFormatData {
};
/**
- * @brief Bitcoin のデフォルトのアドレスフォーマットリストを取得する.
- * @return Bitcoinデフォルトのアドレスフォーマットリスト
+ * @brief Get address format list by Bitcoin default.
+ * @return Address format list by Bitcoin default.
*/
CFD_CORE_API std::vector GetBitcoinAddressFormatList();
/**
* @typedef AddressType
- * @brief Address種別の定義
+ * @brief Address type.
*/
enum AddressType {
- kP2shAddress = 1, //!< Legacy address (Script Hash)
- kP2pkhAddress, //!< Legacy address (PublicKey Hash)
- kP2wshAddress, //!< Native segwit address (Script Hash)
- kP2wpkhAddress, //!< Native segwit address (PublicKey Hash)
- kP2shP2wshAddress, //!< P2sh wrapped address (Script Hash)
- kP2shP2wpkhAddress //!< P2sh wrapped address (Pubkey Hash)
-};
-
-/**
- * @typedef WitnessVersion
- * @brief Witnessバージョンの定義
- */
-enum WitnessVersion {
- kVersionNone = -1, //!< Missing WitnessVersion
- kVersion0 = 0, //!< version 0
- kVersion1, //!< version 1 (for future use)
- kVersion2, //!< version 2 (for future use)
- kVersion3, //!< version 3 (for future use)
- kVersion4, //!< version 4 (for future use)
- kVersion5, //!< version 5 (for future use)
- kVersion6, //!< version 6 (for future use)
- kVersion7, //!< version 7 (for future use)
- kVersion8, //!< version 8 (for future use)
- kVersion9, //!< version 9 (for future use)
- kVersion10, //!< version 10 (for future use)
- kVersion11, //!< version 11 (for future use)
- kVersion12, //!< version 12 (for future use)
- kVersion13, //!< version 13 (for future use)
- kVersion14, //!< version 14 (for future use)
- kVersion15, //!< version 15 (for future use)
- kVersion16 //!< version 16 (for future use)
+ kP2shAddress = 1, //!< Legacy address (Script Hash)
+ kP2pkhAddress, //!< Legacy address (PublicKey Hash)
+ kP2wshAddress, //!< Native segwit address (Script Hash)
+ kP2wpkhAddress, //!< Native segwit address (PublicKey Hash)
+ kP2shP2wshAddress, //!< P2sh wrapped address (Script Hash)
+ kP2shP2wpkhAddress, //!< P2sh wrapped address (Pubkey Hash)
+ kTaprootAddress, //!< Taproot (segwit v1) address
+ kWitnessUnknown //!< witness unknown address
};
/**
* @class Address
- * @brief アドレスの生成クラス
+ * @brief address class.
*/
class CFD_CORE_EXPORT Address {
public:
/**
- * @brief デフォルトコンストラクタ
+ * @brief default constructor.
*/
Address();
+ /**
+ * @brief copy constructor.
+ * @param[in] object object
+ */
+ Address(const Address& object);
+ /**
+ * @brief copy constructor.
+ * @param[in] object object
+ * @return object
+ */
+ Address& operator=(const Address& object);
/**
- * @brief コンストラクタ(hex文字列からの復元)
- * @param[in] address_string アドレス文字列
+ * @brief Constructor. (for string)
+ * @param[in] address_string address string
*/
explicit Address(const std::string& address_string);
/**
- * @brief コンストラクタ(hex文字列からの復元)
- * @param[in] address_string アドレス文字列
+ * @brief Constructor. (for string)
+ * @param[in] address_string address string
* @param[in] network_parameters network parameter list
*/
explicit Address(
const std::string& address_string,
const std::vector& network_parameters);
/**
- * @brief コンストラクタ(hex文字列からの復元)
- * @param[in] address_string アドレス文字列
+ * @brief Constructor. (for string)
+ * @param[in] address_string address string
* @param[in] network_parameter network parameter
*/
explicit Address(
@@ -196,20 +185,20 @@ class CFD_CORE_EXPORT Address {
const AddressFormatData& network_parameter);
/**
- * @brief コンストラクタ(P2PKH用)
+ * @brief Constructor. (for P2PKH)
* @param[in] type NetType
* @param[in] pubkey PublicKey
*/
Address(NetType type, const Pubkey& pubkey);
/**
- * @brief コンストラクタ(P2PKH用)
+ * @brief Constructor. (for P2PKH)
* @param[in] type NetType
* @param[in] pubkey PublicKey
* @param[in] prefix p2pkh prefix
*/
Address(NetType type, const Pubkey& pubkey, uint8_t prefix);
/**
- * @brief コンストラクタ(P2PKH用)
+ * @brief Constructor. (for P2PKH)
* @param[in] type NetType
* @param[in] pubkey PublicKey
* @param[in] network_parameter network parameter
@@ -218,7 +207,7 @@ class CFD_CORE_EXPORT Address {
NetType type, const Pubkey& pubkey,
const AddressFormatData& network_parameter);
/**
- * @brief コンストラクタ(P2PKH用)
+ * @brief Constructor. (for P2PKH)
* @param[in] type NetType
* @param[in] pubkey PublicKey
* @param[in] network_parameters network parameter list
@@ -228,16 +217,16 @@ class CFD_CORE_EXPORT Address {
const std::vector& network_parameters);
/**
- * @brief コンストラクタ(P2WPKH用)
+ * @brief Constructor. (for P2WPKH)
* @param[in] type NetType
- * @param[in] witness_ver Witnessバージョン
+ * @param[in] witness_ver Witness version
* @param[in] pubkey PublicKey
*/
Address(NetType type, WitnessVersion witness_ver, const Pubkey& pubkey);
/**
- * @brief コンストラクタ(P2WPKH用)
+ * @brief Constructor. (for P2WPKH)
* @param[in] type NetType
- * @param[in] witness_ver Witnessバージョン
+ * @param[in] witness_ver Witness version
* @param[in] pubkey PublicKey
* @param[in] bech32_hrp bech32 hrp
*/
@@ -245,9 +234,9 @@ class CFD_CORE_EXPORT Address {
NetType type, WitnessVersion witness_ver, const Pubkey& pubkey,
const std::string& bech32_hrp);
/**
- * @brief コンストラクタ(P2WPKH用)
+ * @brief Constructor. (for P2WPKH)
* @param[in] type NetType
- * @param[in] witness_ver Witnessバージョン
+ * @param[in] witness_ver Witness version
* @param[in] pubkey PublicKey
* @param[in] network_parameter network parameter
*/
@@ -255,9 +244,9 @@ class CFD_CORE_EXPORT Address {
NetType type, WitnessVersion witness_ver, const Pubkey& pubkey,
const AddressFormatData& network_parameter);
/**
- * @brief コンストラクタ(P2WPKH用)
+ * @brief Constructor. (for P2WPKH)
* @param[in] type NetType
- * @param[in] witness_ver Witnessバージョン
+ * @param[in] witness_ver Witness version
* @param[in] pubkey PublicKey
* @param[in] network_parameters network parameter list
*/
@@ -266,20 +255,20 @@ class CFD_CORE_EXPORT Address {
const std::vector& network_parameters);
/**
- * @brief コンストラクタ(P2SH用)
+ * @brief Constructor. (for P2SH)
* @param[in] type NetType
* @param[in] redeem_script Redeem Script
*/
Address(NetType type, const Script& redeem_script);
/**
- * @brief コンストラクタ(P2SH用)
+ * @brief Constructor. (for P2SH)
* @param[in] type NetType
* @param[in] redeem_script Redeem Script
* @param[in] prefix p2sh prefix
*/
Address(NetType type, const Script& redeem_script, uint8_t prefix);
/**
- * @brief コンストラクタ(P2SH用)
+ * @brief Constructor. (for P2SH)
* @param[in] type NetType
* @param[in] redeem_script Redeem Script
* @param[in] network_parameter network parameter
@@ -288,7 +277,7 @@ class CFD_CORE_EXPORT Address {
NetType type, const Script& redeem_script,
const AddressFormatData& network_parameter);
/**
- * @brief コンストラクタ(P2SH用)
+ * @brief Constructor. (for P2SH)
* @param[in] type NetType
* @param[in] redeem_script Redeem Script
* @param[in] network_parameters network parameter list
@@ -298,17 +287,17 @@ class CFD_CORE_EXPORT Address {
const std::vector& network_parameters);
/**
- * @brief コンストラクタ(P2WSH用)
+ * @brief Constructor. (for P2WSH)
* @param[in] type NetType
- * @param[in] witness_ver Witnessバージョン
+ * @param[in] witness_ver Witness version
* @param[in] redeem_script Redeem Script
*/
Address(
NetType type, WitnessVersion witness_ver, const Script& redeem_script);
/**
- * @brief コンストラクタ(P2WSH用)
+ * @brief Constructor. (for P2WSH)
* @param[in] type NetType
- * @param[in] witness_ver Witnessバージョン
+ * @param[in] witness_ver Witness version
* @param[in] redeem_script Redeem Script
* @param[in] bech32_hrp bech32 hrp
*/
@@ -316,9 +305,9 @@ class CFD_CORE_EXPORT Address {
NetType type, WitnessVersion witness_ver, const Script& redeem_script,
const std::string& bech32_hrp);
/**
- * @brief コンストラクタ(P2WSH用)
+ * @brief Constructor. (for P2WSH)
* @param[in] type NetType
- * @param[in] witness_ver Witnessバージョン
+ * @param[in] witness_ver Witness version
* @param[in] redeem_script Redeem Script
* @param[in] network_parameter network parameter
*/
@@ -326,9 +315,9 @@ class CFD_CORE_EXPORT Address {
NetType type, WitnessVersion witness_ver, const Script& redeem_script,
const AddressFormatData& network_parameter);
/**
- * @brief コンストラクタ(P2WSH用)
+ * @brief Constructor. (for P2WSH)
* @param[in] type NetType
- * @param[in] witness_ver Witnessバージョン
+ * @param[in] witness_ver Witness version
* @param[in] redeem_script Redeem Script
* @param[in] network_parameters network parameter list
*/
@@ -337,27 +326,112 @@ class CFD_CORE_EXPORT Address {
const std::vector& network_parameters);
/**
- * @brief コンストラクタ(P2PKH/P2SH用。AddressType明示)
+ * @brief Constructor. (for Taproot)
+ * @param[in] type NetType
+ * @param[in] witness_ver Witness version
+ * @param[in] pubkey PublicKey
+ */
+ Address(
+ NetType type, WitnessVersion witness_ver, const SchnorrPubkey& pubkey);
+ /**
+ * @brief Constructor. (for Taproot)
+ * @param[in] type NetType
+ * @param[in] witness_ver Witness version
+ * @param[in] pubkey PublicKey
+ * @param[in] bech32_hrp bech32 hrp
+ */
+ Address(
+ NetType type, WitnessVersion witness_ver, const SchnorrPubkey& pubkey,
+ const std::string& bech32_hrp);
+ /**
+ * @brief Constructor. (for Taproot)
+ * @param[in] type NetType
+ * @param[in] witness_ver Witness version
+ * @param[in] pubkey PublicKey
+ * @param[in] network_parameter network parameter
+ */
+ Address(
+ NetType type, WitnessVersion witness_ver, const SchnorrPubkey& pubkey,
+ const AddressFormatData& network_parameter);
+ /**
+ * @brief Constructor. (for Taproot)
+ * @param[in] type NetType
+ * @param[in] witness_ver Witness version
+ * @param[in] pubkey PublicKey
+ * @param[in] network_parameters network parameter list
+ */
+ Address(
+ NetType type, WitnessVersion witness_ver, const SchnorrPubkey& pubkey,
+ const std::vector& network_parameters);
+
+ /**
+ * @brief Constructor. (for Taproot)
+ * @param[in] type NetType
+ * @param[in] witness_ver Witness version
+ * @param[in] tree tapscript tree
+ * @param[in] internal_pubkey internal PublicKey
+ */
+ Address(
+ NetType type, WitnessVersion witness_ver, const TaprootScriptTree& tree,
+ const SchnorrPubkey& internal_pubkey);
+ /**
+ * @brief Constructor. (for Taproot)
+ * @param[in] type NetType
+ * @param[in] witness_ver Witness version
+ * @param[in] tree tapscript tree
+ * @param[in] internal_pubkey internal PublicKey
+ * @param[in] bech32_hrp bech32 hrp
+ */
+ Address(
+ NetType type, WitnessVersion witness_ver, const TaprootScriptTree& tree,
+ const SchnorrPubkey& internal_pubkey, const std::string& bech32_hrp);
+ /**
+ * @brief Constructor. (for Taproot)
+ * @param[in] type NetType
+ * @param[in] witness_ver Witness version
+ * @param[in] tree tapscript tree
+ * @param[in] internal_pubkey internal PublicKey
+ * @param[in] network_parameter network parameter
+ */
+ Address(
+ NetType type, WitnessVersion witness_ver, const TaprootScriptTree& tree,
+ const SchnorrPubkey& internal_pubkey,
+ const AddressFormatData& network_parameter);
+ /**
+ * @brief Constructor. (for Taproot)
+ * @param[in] type NetType
+ * @param[in] witness_ver Witness version
+ * @param[in] tree tapscript tree
+ * @param[in] internal_pubkey internal PublicKey
+ * @param[in] network_parameters network parameter list
+ */
+ Address(
+ NetType type, WitnessVersion witness_ver, const TaprootScriptTree& tree,
+ const SchnorrPubkey& internal_pubkey,
+ const std::vector& network_parameters);
+
+ /**
+ * @brief Constructor. (for P2PKH/P2SH)
* @param[in] type NetType
- * @param[in] addr_type 種別
- * @param[in] hash ハッシュ化済みの値
+ * @param[in] addr_type Address type
+ * @param[in] hash hashed data
*/
Address(NetType type, AddressType addr_type, const ByteData160& hash);
/**
- * @brief コンストラクタ(P2PKH/P2SH用。AddressType明示)
+ * @brief Constructor. (for P2PKH/P2SH)
* @param[in] type NetType
- * @param[in] addr_type 種別
- * @param[in] hash ハッシュ化済みの値
+ * @param[in] addr_type Address type
+ * @param[in] hash hashed data
* @param[in] network_parameter network parameter
*/
Address(
NetType type, AddressType addr_type, const ByteData160& hash,
const AddressFormatData& network_parameter);
/**
- * @brief コンストラクタ(P2PKH/P2SH用。AddressType明示)
+ * @brief Constructor. (for P2PKH/P2SH)
* @param[in] type NetType
- * @param[in] addr_type 種別
- * @param[in] hash ハッシュ化済みの値
+ * @param[in] addr_type Address type
+ * @param[in] hash hashed data
* @param[in] network_parameters network parameter list
*/
Address(
@@ -365,27 +439,27 @@ class CFD_CORE_EXPORT Address {
const std::vector& network_parameters);
/**
- * @brief コンストラクタ(ハッシュ化済みの値用)
+ * @brief Constructor. (for hashed data)
* @param[in] type NetType
- * @param[in] witness_ver Witnessバージョン
- * @param[in] hash ハッシュ化済みの値
+ * @param[in] witness_ver Witness version
+ * @param[in] hash hashed data
*/
Address(NetType type, WitnessVersion witness_ver, const ByteData& hash);
/**
- * @brief コンストラクタ(ハッシュ化済みの値用)
+ * @brief Constructor. (for hashed data)
* @param[in] type NetType
- * @param[in] witness_ver Witnessバージョン
- * @param[in] hash ハッシュ化済みの値
+ * @param[in] witness_ver Witness version
+ * @param[in] hash hashed data
* @param[in] network_parameter network parameter
*/
Address(
NetType type, WitnessVersion witness_ver, const ByteData& hash,
const AddressFormatData& network_parameter);
/**
- * @brief コンストラクタ(ハッシュ化済みの値用)
+ * @brief Constructor. (for hashed data)
* @param[in] type NetType
- * @param[in] witness_ver Witnessバージョン
- * @param[in] hash ハッシュ化済みの値
+ * @param[in] witness_ver Witness version
+ * @param[in] hash hashed data
* @param[in] network_parameters network parameter list
*/
Address(
@@ -393,92 +467,103 @@ class CFD_CORE_EXPORT Address {
const std::vector& network_parameters);
/**
- * @brief アドレスのhex文字列を取得する.
- * @return アドレス文字列
+ * @brief Get address string.
+ * @return address string
*/
std::string GetAddress() const;
/**
- * @brief AddressのNetTypeを取得する.
+ * @brief Get network type.
* @return NetType
*/
NetType GetNetType() const { return type_; }
/**
- * @brief Address種別を取得する.
- * @return Address種別
+ * @brief Get address type.
+ * @return Address type
*/
AddressType GetAddressType() const { return addr_type_; }
/**
- * @brief Witnessバージョンを取得する.
- * @return Witnessバージョン
+ * @brief Get witness version.
+ * @return Witness version
*/
WitnessVersion GetWitnessVersion() const { return witness_ver_; }
/**
- * @brief アドレスHashを取得する.
- * @return アドレスHashのByteDataインスタンス
+ * @brief Get address Hash.
+ * @return address hash
*/
ByteData GetHash() const { return hash_; }
/**
- * @brief PublicKeyを取得する.
- * @return Pubkeyオブジェクト
+ * @brief Get PublicKey.
+ * @return Pubkey
*/
Pubkey GetPubkey() const { return pubkey_; }
/**
- * @brief Redeem Scriptを取得する.
- * @return Scriptオブジェクト
+ * @brief Get Schnorr PublicKey.
+ * @return Schnorr Pubkey
+ */
+ SchnorrPubkey GetSchnorrPubkey() const { return schnorr_pubkey_; }
+ /**
+ * @brief Get taproot script tree.
+ * @return taproot script tree
+ */
+ TaprootScriptTree GetScriptTree() const { return script_tree_; }
+
+ /**
+ * @brief Get Redeem Script.
+ * @return Script
*/
Script GetScript() const { return redeem_script_; }
/**
- * @brief AddressFormatDataを取得する.
- * @return AddressFormatDataオブジェクト
+ * @brief Get AddressFormatData.
+ * @return AddressFormatData
*/
AddressFormatData GetAddressFormatData() const { return format_data_; }
/**
- * @brief LockingScriptを取得する
+ * @brief Get LockingScript
* @return locking script
*/
Script GetLockingScript() const;
private:
/**
- * @brief P2SH Addressの情報を算出する.
+ * @brief calculate P2SH Address
* @param[in] prefix p2sh prefix
*/
void CalculateP2SH(uint8_t prefix = 0);
/**
- * @brief P2SH Addressの情報を算出する.
- * @param[in] hash_data ハッシュ化済みRedeem script
+ * @brief calculate P2SH Address.
+ * @param[in] hash_data RedeemScript hash
* @param[in] prefix p2sh prefix
*/
void CalculateP2SH(const ByteData160& hash_data, uint8_t prefix = 0);
/**
- * @brief P2PKH Addressの情報を算出する.
+ * @brief calculate P2PKH Address
* @param[in] prefix p2pkh prefix
*/
void CalculateP2PKH(uint8_t prefix = 0);
/**
- * @brief P2PKH Addressの情報を算出する.
- * @param[in] hash_data ハッシュ化済みPubkey
+ * @brief calculate P2PKH Address
+ * @param[in] hash_data Pubkey hash
* @param[in] prefix p2pkh prefix
*/
void CalculateP2PKH(const ByteData160& hash_data, uint8_t prefix = 0);
/**
- * @brief P2WSH Addressの情報を算出する.
+ * @brief calculate P2WSH Address
* @param[in] bech32_hrp bech32 hrp
*/
void CalculateP2WSH(const std::string& bech32_hrp = "");
/**
- * @brief P2WSH Addressの情報を算出する.
- * @param[in] hash_data ハッシュ化済みRedeemScript
+ * @brief calculate P2WSH Address
+ * @param[in] hash_data RedeemScript hash
* @param[in] bech32_hrp bech32 hrp
*/
void CalculateP2WSH(
@@ -486,93 +571,88 @@ class CFD_CORE_EXPORT Address {
const std::string& bech32_hrp = "");
/**
- * @brief P2WPKH Address算出()
+ * @brief calculate P2WPKH Address
* @param[in] bech32_hrp bech32 hrp
*/
void CalculateP2WPKH(const std::string& bech32_hrp = "");
/**
- * @brief P2WPKH Addressの情報を算出する.
- * @param[in] hash_data ハッシュ化済みPubkey
+ * @brief calculate P2WPKH Address
+ * @param[in] hash_data pubkey hash
* @param[in] bech32_hrp bech32 hrp
*/
void CalculateP2WPKH(
const ByteData160& hash_data, // pubkey hash
const std::string& bech32_hrp = "");
- /* Segwit Address Format
- *
- * 例:bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4
- *
- * "bc"or"tb"
- * :Human-readable part(bc=mainnet/tb=testnet)
- * "1" :Separator 1固定
- * "v8f3t4"
- * :checksum
- *
- * "qw508d6qejxtdg4y5r3zarvary0c5xw7k"をbase32Decode
- * -> "0014751e76e8199196d454941c45d1b3a323f1433bd6"
- * "00" :witness version
- * "14" :data長(P2WPKHは20byte/P2WSHは32byte)
- * "751e76e8199196d454941c45d1b3a323f1433bd6"
- * :witness program(PubkeyHash or ScriptHash)
- */
- /**
- * @brief Hex文字列をdecodeする.
- * @param[in] bs58 デコードするアドレスのbase58文字列
+ /**
+ * @brief calculate Taproot Address
+ * @param[in] bech32_hrp bech32 hrp
+ */
+ void CalculateTaproot(const std::string& bech32_hrp = "");
+ /**
+ * @brief calculate Bech32m Address
+ * @param[in] hash_data hash data
+ * @param[in] bech32_hrp bech32 hrp
+ */
+ void CalculateBech32m(
+ const ByteData& hash_data, // hash data
+ const std::string& bech32_hrp = "");
+
+ /**
+ * @brief decode address from address string.
+ * @param[in] address_string address string
* @param[in] network_parameters network parameter list
*/
void DecodeAddress(
- std::string bs58, // LF
+ std::string address_string, // LF
const std::vector* network_parameters);
/**
- * @brief NetType設定用のWrapper関数.
+ * @brief set network type.
* @param[in] format_data Address format data
*/
void SetNetType(const AddressFormatData& format_data);
/**
- * @brief AddressType設定用のWrapper関数.
+ * @brief set address type.
* @param[in] addr_type Address type
*/
void SetAddressType(AddressType addr_type);
/**
- * \~english
* @brief Get AddressFormatData with NetType from format list.
* @param[in] network_parameters Address format data list
- * \~japanese
- * @brief Address format data一覧から指定NetTypeの情報を取得する.
- * @param[in] network_parameters AddressFormatData一覧
- * \~
* @param[in] type NetType
* @return Address format data
*/
static AddressFormatData GetTargetFormatData(
const std::vector& network_parameters, NetType type);
- //! アドレスのNetType
+ //! address's NetType
NetType type_;
- //! アドレス種別
+ //! address type
AddressType addr_type_;
- //! Witnessバージョン
+ //! Witness version
WitnessVersion witness_ver_;
- //! アドレス文字列
+ //! address string
std::string address_;
- //! アドレスHash
+ //! address Hash
ByteData hash_;
//! PublicKey
Pubkey pubkey_;
+ SchnorrPubkey schnorr_pubkey_; //!< Schnorr PublicKey
+ TaprootScriptTree script_tree_; //!< Taproot ScriptTree
+
//! Redeem Script
Script redeem_script_;
- //! チェックサム
+ //! checksum
uint8_t checksum_[4];
//! address prefix format data
diff --git a/include/cfdcore/cfdcore_amount.h b/include/cfdcore/cfdcore_amount.h
index feec9a12..ea171ab8 100644
--- a/include/cfdcore/cfdcore_amount.h
+++ b/include/cfdcore/cfdcore_amount.h
@@ -2,7 +2,7 @@
/**
* @file cfdcore_amount.h
*
- * @brief Amount関連クラス定義
+ * @brief The amount related class definition.
*
*/
#ifndef CFD_CORE_INCLUDE_CFDCORE_CFDCORE_AMOUNT_H_
@@ -14,35 +14,31 @@
#include "cfdcore/cfdcore_common.h"
/**
- * @brief cfd名前空間
+ * @brief cfd namespace
*/
namespace cfd {
/**
- * @brief cfd::core名前空間
+ * @brief cfd::core namespace
*/
namespace core {
-//! bitcoinとsatoshi単位の変換に用いる因数(10^8)
+//! Factors used to convert bitcoin and satoshi units(10^8)
static constexpr int64_t kCoinBase = 100000000;
/**
- * @brief satoshi単位の最大値
- * @details 厳密には流通通貨の最大値とは異なるが、bitcoin coreに合わせて限度額を設定
+ * @brief Maximum value in satoshi unit.
+ * @details Strictly speaking, it is different from the maximum \
+ * value of the currency in circulation, but the limit is \
+ * set according to the bitcoin core.
* @see https://github.com/bitcoin/bitcoin/blob/e756eca9e8bf39f0a891f1760df0a317ecb7fee8/src/amount.h#L25
*/
static constexpr int64_t kMaxAmount = 21000000 * kCoinBase;
/**
- * @brief BitcoinのAmountを表現するクラス
+ * @brief A class that represents Bitcoin's Amount.
*/
class CFD_CORE_EXPORT Amount {
public:
/**
- * \~japanese
- * @brief satoshi単位のAmountからAmountインスタンスを生成する.
- * @param[in] amount satoshi単位のAmount
- * @return Amountインスタンス
- * @exception CfdException 不正な値が渡された場合
- * \~english
* @brief Create Amount instance by amount satoshi units
* @param[in] amount amount in satoshi units
* @return instance of Amount class
@@ -51,12 +47,6 @@ class CFD_CORE_EXPORT Amount {
static Amount CreateBySatoshiAmount(int64_t amount);
/**
- * \~japanese
- * @brief bitcoin単位のAmountからAmountインスタンスを生成する
- * @param[in] coin_amount bitcoin単位のAmount
- * @return Amountインスタンス
- * @exception CfdException 不正な値が渡された場合
- * \~english
* @brief Create Amount instance by amount bitcoin units
* @param[in] coin_amount amount in bitcoin units
* @return instance of Amount class
@@ -97,108 +87,105 @@ class CFD_CORE_EXPORT Amount {
explicit Amount(int64_t amount, bool ignore_check);
/**
- * @brief 自身のインスタンスからsatoshi単位のAmount額を取得する.
- * @return satoshi単位のAmountの数値
+ * @brief Get the Amount amount in satoshi units from object.
+ * @return Amount value in satoshi units.
*/
int64_t GetSatoshiValue() const;
/**
- * @brief 自身のインスタンスからbitcoin単位のAmount額を取得する.
- * @details double精度の誤差が生じる可能性があるため注意.
- * @return bitcoin単位のAmountの数値
+ * @brief Get the Amount amount in bitcoin units from object.
+ * @details Note that double precision errors may occur.
+ * @return Amount value in bitcoin units.
*/
double GetCoinValue() const;
/**
- * @brief ByteDataをBigEndianで取得する.
- * @return satoshiのByteData
+ * @brief Get ByteData by BigEndian.
+ * @return satoshi's ByteData
*/
ByteData GetByteData() const;
// operator overloading
/**
- * @brief 等価比較オペレータ
- * @param[in] amount 被演算子 比較対象とするAmountインスタンス
- * @retval true 等価
- * @retval false 不等価
- * @return 等価であればtrue, それ以外はfalse
+ * @brief Equals operator.
+ * @param[in] amount Amount instance
+ * @retval true equals
+ * @retval false not equals
*/
bool operator==(const Amount &amount) const;
/**
- * @brief 等価比較オペレータ
- * @param[in] satoshi_amount 被演算子 比較対象とするsatoshi単位のAmount額
- * @retval true 等価
- * @retval false 不等価
+ * @brief Equals operator.
+ * @param[in] satoshi_amount amount in satoshi units
+ * @retval true equals
+ * @retval false not equals
*/
bool operator==(const int64_t satoshi_amount) const;
/**
- * @brief 不等価比較オペレータ
- * @param[in] amount 被演算子 比較対象とするAmountインスタンス
- * @retval true 不等価
- * @retval false 等価
+ * @brief not equals operator.
+ * @param[in] amount Amount instance
+ * @retval true not equals
+ * @retval false equals
*/
bool operator!=(const Amount &amount) const;
/**
- * @brief 不等価比較オペレータ
- * @param[in] satoshi_amount 被演算子 比較対象とするsatoshi単位のAmount額
- * @retval true 不等価
- * @retval false 等価
+ * @brief not equals operator.
+ * @param[in] satoshi_amount amount in satoshi units
+ * @retval true not equals
+ * @retval false equals
*/
bool operator!=(const int64_t satoshi_amount) const;
/**
- * @brief 加算代入オペレータ(Amount += Amount)
- * @param[in] amount 加数 Amountインスタンス
- * @return 計算結果 Amountインスタンス
+ * @brief Addition operator (Amount += Amount)
+ * @param[in] amount Amount instance
+ * @return Amount instance
*/
Amount operator+=(const Amount &amount);
/**
- * @brief 加算代入オペレータ(Amount += int64_t)
- * @param[in] satoshi_amount 加数 satoshi単位のAmount額
- * @return 計算結果 Amountインスタンス
+ * @brief Addition operator(Amount += int64_t)
+ * @param[in] satoshi_amount 加数 amount in satoshi units
+ * @return Amount instance
*/
Amount operator+=(const int64_t satoshi_amount);
/**
- * @brief 減算代入オペレータ(Amount -= Amount)
- * @param[in] amount 減数 Amountインスタンス
- * @return 計算結果 Amountインスタンス
+ * @brief Subtraction operator(Amount -= Amount)
+ * @param[in] amount Amount instance
+ * @return Amount instance
*/
Amount operator-=(const Amount &amount);
/**
- * @brief 減算代入オペレータ(Amount -= int64_t)
- * @param[in] satoshi_amount 減数 satoshi単位のAmount額
- * @return 計算結果 Amountインスタンス
+ * @brief Subtraction operator(Amount -= int64_t)
+ * @param[in] satoshi_amount amount in satoshi units
+ * @return Amount instance
*/
Amount operator-=(const int64_t satoshi_amount);
/**
- * @brief 乗算代入オペレータ(Amount *= int64_t)
- * @param[in] value 乗数
- * @return 計算結果 Amountインスタンス
+ * @brief Multiplication operator(Amount *= int64_t)
+ * @param[in] value multiplier
+ * @return Amount instance
*/
Amount operator*=(const int64_t value);
/**
- * @brief 除算代入オペレータ(Amount /= int64_t)
- * @param[in] value 除数
- * @return 計算結果 Amountインスタンス
+ * @brief Division operator(Amount /= int64_t)
+ * @param[in] value divisor
+ * @return Amount instance
*/
Amount operator/=(const int64_t value);
/**
- * @brief コンストラクタ.
- *
- * リスト要素指定時の初期化用.
+ * @brief default constructor.
*/
Amount();
private:
- //! satoshi単位のAmount
+ //! amount in satoshi units
int64_t amount_;
//! ignore valid check flag.
bool ignore_check_;
/**
- * @brief 引数で与えられたAmount額が不正なものでないかを検証する.
- * @param[in] amount satoshi単位のAmount
- * @retval true 正常Amount額
- * @retval false 不正Amount額
+ * @brief Verify that the amount is not invalid.
+ * @param[in] amount amount in satoshi units
+ * @retval true valid
+ * @retval false invalid
*/
static bool IsValidAmount(int64_t amount) {
return (amount >= 0 && amount <= kMaxAmount);
@@ -206,193 +193,193 @@ class CFD_CORE_EXPORT Amount {
/**
* @brief 引数で与えられたsatoshi単位のAmountが不正な値でないかを検証する.
- * @param[in] satoshi_amount satoshi単位のAmount
- * @exception CfdException 不正な値が渡された場合
+ * @param[in] satoshi_amount amount in satoshi units
+ * @exception CfdException If an invalid value is passed
*/
static void CheckValidAmount(int64_t satoshi_amount);
};
/**
- * @brief 等価比較オペレータ
- * @param[in] satoshi_amount satoshi単位のAmount額
- * @param[in] amount 比較対象Amountインスタンス
- * @retval true 等価
- * @retval false 不等価
+ * @brief Equals operator.
+ * @param[in] satoshi_amount amount in satoshi units
+ * @param[in] amount Amount instance
+ * @retval true equals
+ * @retval false not equals
*/
CFD_CORE_EXPORT bool operator==(
const int64_t satoshi_amount, const Amount &amount);
/**
- * @brief 不等価比較オペレータ
- * @param[in] satoshi_amount satoshi単位のAmount額
- * @param[in] amount 比較対象Amountインスタンス
- * @retval true 不等価
- * @retval false 等価
+ * @brief not equals operator.
+ * @param[in] satoshi_amount amount in satoshi units
+ * @param[in] amount Amount instance
+ * @retval true not equals
+ * @retval false equals
*/
CFD_CORE_EXPORT bool operator!=(
const int64_t satoshi_amount, const Amount &amount);
/**
- * @brief 二方比較オペレータ
- * @param[in] lhs 被比較数(Amount)
- * @param[in] rhs 比較数(Amount)
+ * @brief comparison operator
+ * @param[in] lhs Value to be compared(Amount)
+ * @param[in] rhs Value to compare(Amount)
* @retval true lhs is less than rhs
* @retval false lhs is greater than or equal rhs
*/
CFD_CORE_EXPORT bool operator<(const Amount &lhs, const Amount &rhs);
/**
- * @brief 二方比較オペレータ
- * @param[in] lhs 被比較数(int64_t)
- * @param[in] rhs 比較数(Amount)
+ * @brief comparison operator
+ * @param[in] lhs Value to be compared(int64_t)
+ * @param[in] rhs Value to compare(Amount)
* @retval true lhs is less than rhs
* @retval false lhs is greater than or equal rhs
*/
CFD_CORE_EXPORT bool operator<(const int64_t lhs, const Amount &rhs);
/**
- * @brief 二方比較オペレータ
- * @param[in] lhs 被比較数(Amount)
- * @param[in] rhs 比較数(int64_t)
+ * @brief comparison operator
+ * @param[in] lhs Value to be compared(Amount)
+ * @param[in] rhs Value to compare(int64_t)
* @retval true lhs is less than rhs
* @retval false lhs is greater than or equal rhs
*/
CFD_CORE_EXPORT bool operator<(const Amount &lhs, const int64_t rhs);
/**
- * @brief 二方比較オペレータ
- * @param[in] lhs 被比較数(Amount)
- * @param[in] rhs 比較数(Amount)
+ * @brief comparison operator
+ * @param[in] lhs Value to be compared(Amount)
+ * @param[in] rhs Value to compare(Amount)
* @retval true lhs is greater than rhs
* @retval false lhs is less than or equal rhs
*/
CFD_CORE_EXPORT bool operator>(const Amount &lhs, const Amount &rhs);
/**
- * @brief 二方比較オペレータ
- * @param[in] lhs 被比較数(int64_t)
- * @param[in] rhs 比較数(Amount)
+ * @brief comparison operator
+ * @param[in] lhs Value to be compared(int64_t)
+ * @param[in] rhs Value to compare(Amount)
* @retval true lhs is greater than rhs
* @retval false lhs is less than or equal rhs
*/
CFD_CORE_EXPORT bool operator>(const int64_t lhs, const Amount &rhs);
/**
- * @brief 二方比較オペレータ
- * @param[in] lhs 被比較数(Amount)
- * @param[in] rhs 比較数(int64_t)
+ * @brief comparison operator
+ * @param[in] lhs Value to be compared(Amount)
+ * @param[in] rhs Value to compare(int64_t)
* @retval true lhs is greater than rhs
* @retval false lhs is less than or equal rhs
*/
CFD_CORE_EXPORT bool operator>(const Amount &lhs, const int64_t rhs);
/**
- * @brief 二方比較オペレータ
- * @param[in] lhs 被比較数(Amount)
- * @param[in] rhs 比較数(Amount)
+ * @brief comparison operator
+ * @param[in] lhs Value to be compared(Amount)
+ * @param[in] rhs Value to compare(Amount)
* @retval true lhs is less than or equal rhs
* @retval false lhs is greater than rhs
*/
CFD_CORE_EXPORT bool operator<=(const Amount &lhs, const Amount &rhs);
/**
- * @brief 二方比較オペレータ
- * @param[in] lhs 被比較数(int64_t)
- * @param[in] rhs 比較数(Amount)
+ * @brief comparison operator
+ * @param[in] lhs Value to be compared(int64_t)
+ * @param[in] rhs Value to compare(Amount)
* @retval true lhs is less than or equal rhs
* @retval false lhs is greater than rhs
*/
CFD_CORE_EXPORT bool operator<=(const int64_t lhs, const Amount &rhs);
/**
- * @brief 二方比較オペレータ
- * @param[in] lhs 被比較数(Amount)
- * @param[in] rhs 比較数(int64_t)
+ * @brief comparison operator
+ * @param[in] lhs Value to be compared(Amount)
+ * @param[in] rhs Value to compare(int64_t)
* @retval true lhs is less than or equal rhs
* @retval false lhs is greater than rhs
*/
CFD_CORE_EXPORT bool operator<=(const Amount &lhs, const int64_t rhs);
/**
- * @brief 二方比較オペレータ
- * @param[in] lhs 被比較数(Amount)
- * @param[in] rhs 比較数(Amount)
+ * @brief comparison operator
+ * @param[in] lhs Value to be compared(Amount)
+ * @param[in] rhs Value to compare(Amount)
* @retval true lhs is greater than or equal rhs
* @retval false lhs is less than rhs
*/
CFD_CORE_EXPORT bool operator>=(const Amount &lhs, const Amount &rhs);
/**
- * @brief 二方比較オペレータ
- * @param[in] lhs 被比較数(int64_t)
- * @param[in] rhs 比較数(Amount)
+ * @brief comparison operator
+ * @param[in] lhs Value to be compared(int64_t)
+ * @param[in] rhs Value to compare(Amount)
* @retval true lhs is greater than or equal rhs
* @retval false lhs is less than rhs
*/
CFD_CORE_EXPORT bool operator>=(const int64_t lhs, const Amount &rhs);
/**
- * @brief 二方比較オペレータ
- * @param[in] lhs 被比較数(Amount)
- * @param[in] rhs 比較数(int64_t)
+ * @brief comparison operator
+ * @param[in] lhs Value to be compared(Amount)
+ * @param[in] rhs Value to compare(int64_t)
* @retval true lhs is greater than or equal rhs
* @retval false lhs is less than rhs
*/
CFD_CORE_EXPORT bool operator>=(const Amount &lhs, const int64_t rhs);
/**
- * @brief 加算オペレータ(Amount + Amount)
- * @param[in] left_amount 被加数 Amountインスタンス
- * @param[in] right_amount 加数 Amountインスタンス
- * @return 計算結果 Amountインスタンス
+ * @brief Addition operator(Amount + Amount)
+ * @param[in] left_amount Amount instance
+ * @param[in] right_amount Amount instance
+ * @return Amount instance
*/
CFD_CORE_EXPORT Amount
operator+(const Amount &left_amount, const Amount &right_amount);
/**
- * @brief 加算オペレータ(Amount + int64_t)
- * @param[in] amount 被加数 Amountインスタンス
- * @param[in] satoshi_amount 加数 satoshi単位のAmount額
- * @return 計算結果 Amountインスタンス
+ * @brief Addition operator(Amount + int64_t)
+ * @param[in] amount Amount instance
+ * @param[in] satoshi_amount amount in satoshi units
+ * @return Amount instance
*/
CFD_CORE_EXPORT Amount
operator+(const Amount &amount, const int64_t satoshi_amount);
/**
- * @brief 加算オペレータ(int64_t + Amount)
- * @param[in] satoshi_amount 被加数 satoshi単位のAmount額
- * @param[in] amount 加数 Amountインスタンス
- * @return 計算結果 Amountインスタンス
+ * @brief Addition operator(int64_t + Amount)
+ * @param[in] satoshi_amount amount in satoshi units
+ * @param[in] amount Amount instance
+ * @return Amount instance
*/
CFD_CORE_EXPORT Amount
operator+(const int64_t satoshi_amount, const Amount &amount);
/**
- * @brief 減算オペレータ(Amount - Amount)
- * @param[in] left_amount 被減数 Amountインスタンス
- * @param[in] right_amount 減数 Amountインスタンス
- * @return 計算結果 Amountインスタンス
+ * @brief Subtraction operator(Amount - Amount)
+ * @param[in] left_amount Amount instance
+ * @param[in] right_amount Amount instance
+ * @return Amount instance
*/
CFD_CORE_EXPORT Amount
operator-(const Amount &left_amount, const Amount &right_amount);
/**
- * @brief 減算オペレータ(int64_t - Amount)
- * @param[in] amount 被減数 Amountインスタンス
- * @param[in] satoshi_amount 減数 satoshi単位のAmount額
- * @return 計算結果 Amountインスタンス
+ * @brief Subtraction operator(int64_t - Amount)
+ * @param[in] amount Amount instance
+ * @param[in] satoshi_amount amount in satoshi units
+ * @return Amount instance
*/
CFD_CORE_EXPORT Amount
operator-(const Amount &amount, const int64_t satoshi_amount);
/**
- * @brief 減算オペレータ(Amount - int64_t)
- * @param[in] satoshi_amount 被減数 satoshi単位のAmount額
- * @param[in] amount 減数 Amountインスタンス
- * @return 計算結果 Amountインスタンス
+ * @brief Subtraction operator(Amount - int64_t)
+ * @param[in] satoshi_amount amount in satoshi units
+ * @param[in] amount Amount instance
+ * @return Amount instance
*/
CFD_CORE_EXPORT Amount
operator-(const int64_t satoshi_amount, const Amount &amount);
/**
- * @brief 乗算オペレータ(Amount * int64_t)
- * @param[in] amount 被乗数 Amountインスタンス
- * @param[in] value 乗数
- * @return 計算結果 Amountインスタンス
+ * @brief Multiplication operator(Amount * int64_t)
+ * @param[in] amount Amount instance
+ * @param[in] value multiplier
+ * @return Amount instance
*/
CFD_CORE_EXPORT Amount operator*(const Amount &amount, const int64_t value);
/**
- * @brief 乗算オペレータ(int64_t * Amount)
- * @param[in] value 乗数
- * @param[in] amount 被演算子 Amountインスタンス
- * @return 計算結果 Amountインスタンス
+ * @brief Multiplication operator(int64_t * Amount)
+ * @param[in] value multiplier
+ * @param[in] amount Amount instance
+ * @return Amount instance
*/
CFD_CORE_EXPORT Amount operator*(const int64_t value, const Amount &amount);
/**
- * @brief 除算オペレータ(Amount / int64_t)
- * @param[in] amount 被除数 Amountインスタンス
- * @param[in] value 除数
- * @return 計算結果 Amountインスタンス
+ * @brief Division operator(Amount / int64_t)
+ * @param[in] amount Amount instance
+ * @param[in] value divisor
+ * @return Amount instance
*/
CFD_CORE_EXPORT Amount operator/(const Amount &amount, const int64_t value);
diff --git a/include/cfdcore/cfdcore_bytedata.h b/include/cfdcore/cfdcore_bytedata.h
index 6500f6d2..35b30ae6 100644
--- a/include/cfdcore/cfdcore_bytedata.h
+++ b/include/cfdcore/cfdcore_bytedata.h
@@ -2,7 +2,7 @@
/**
* @file cfdcore_bytedata.h
*
- * @brief ByteData関連クラス定義
+ * @brief The ByteData related class definition.
*/
#ifndef CFD_CORE_INCLUDE_CFDCORE_CFDCORE_BYTEDATA_H_
@@ -22,24 +22,24 @@ class ByteData256;
/**
* @class ByteData
- * @brief 可変サイズのByte配列データクラス
+ * @brief The variable size byte array data class.
*/
class CFD_CORE_EXPORT ByteData {
public:
/**
- * @brief デフォルトコンストラクタ
+ * @brief default constructor.
*/
ByteData();
/**
- * @brief コンストラクタ
- * @param[in] vector 格納Byte配列
+ * @brief constructor
+ * @param[in] vector byte array.
*/
ByteData(const std::vector& vector); // NOLINT
/**
- * @brief コンストラクタ
- * @param[in] hex Byteデータ HEX文字列
+ * @brief constructor
+ * @param[in] hex hex string.
*/
explicit ByteData(const std::string& hex);
@@ -51,42 +51,48 @@ class CFD_CORE_EXPORT ByteData {
explicit ByteData(const uint8_t* buffer, uint32_t size);
/**
- * @brief HEX文字列を取得する.
- * @return HEX文字列
+ * @brief constructor
+ * @param[in] single_byte 1-Byte data
+ */
+ explicit ByteData(const uint8_t single_byte);
+
+ /**
+ * @brief Get a hex string.
+ * @return hex string.
*/
std::string GetHex() const;
/**
- * @brief Byte配列を取得する.
- * @return Byte配列
+ * @brief Get a byte array.
+ * @return byte array.
*/
std::vector GetBytes() const;
/**
- * @brief データサイズを取得する.
- * @return Byte配列サイズ
+ * @brief Get a byte data size.
+ * @return byte data size.
*/
size_t GetDataSize() const;
/**
- * @brief データが空か取得する.
- * @retval true データが空
- * @retval false データが存在
+ * @brief Check is data empty.
+ * @retval true empty.
+ * @retval false not empty.
* @deprecated replace to IsEmpty .
*/
bool Empty() const;
/**
- * @brief データが空か取得する.
- * @retval true データが空
- * @retval false データが存在
+ * @brief Check is data empty.
+ * @retval true empty.
+ * @retval false not empty.
*/
bool IsEmpty() const;
/**
- * @brief ByteData比較
- * @param bytedata 比較対象のオブジェクト
- * @retval true 一致した場合
- * @retval false 不一致の場合
+ * @brief Check equals.
+ * @param bytedata compare target object.
+ * @retval true equals.
+ * @retval false not equals.
*/
bool Equals(const ByteData& bytedata) const;
@@ -98,13 +104,13 @@ class CFD_CORE_EXPORT ByteData {
uint8_t GetHeadData() const;
/**
- * @brief byte data情報をserializeする.
+ * @brief Serialize byte data.
* @return serialize data
*/
ByteData Serialize() const;
/**
- * @brief serializeされたbyte dataのサイズを取得する。
+ * @brief Get the serialized size.
* @return serialize data size
*/
size_t GetSerializeSize() const;
@@ -178,65 +184,70 @@ class CFD_CORE_EXPORT ByteData {
/**
* @brief Push to back.
* @param[in] back_insert_data back insert data.
- * @return joined byte data.
*/
void Push(const ByteData& back_insert_data);
/**
* @brief Push to back.
* @param[in] back_insert_data back insert data.
- * @return joined byte data.
*/
void Push(const ByteData160& back_insert_data);
/**
* @brief Push to back.
* @param[in] back_insert_data back insert data.
- * @return joined byte data.
*/
void Push(const ByteData256& back_insert_data);
/**
- * @brief 可変長サイズ情報(バッファ)を取得する.
+ * @brief Equals operator.
+ * @param[in] object target object.
+ * @retval true equals
+ * @retval false not equals
+ */
+ bool operator==(const ByteData& object) const;
+
+ /**
+ * @brief Get the variable integer buffer.
* @param[in] value size value
* @return variable size buffer
*/
static ByteData GetVariableInt(uint64_t value);
/**
- * @brief 指定された2つのバッファのHEX値を比較する.
+ * @brief Compare the HEX values of the two specified buffers.
* @param[in] source source target
* @param[in] destination destination target
- * @retval true 大きい
- * @retval false 小さい
+ * @retval true Large
+ * @retval false Small or equals.
*/
static bool IsLarge(const ByteData& source, const ByteData& destination);
private:
/**
- * @brief データ格納Byte配列
+ * @brief データbyte array.
*/
std::vector data_;
};
/**
* @class ByteData160
- * @brief サイズ固定(20byte)のByte配列データクラス
+ * @brief Fixed size (20 bytes) Byte array data class
*/
class CFD_CORE_EXPORT ByteData160 {
public:
/**
- * @brief デフォルトコンストラクタ
+ * @brief default constructor
*/
ByteData160();
/**
- * @brief コンストラクタ
- * @param[in] vector 20byteデータ格納Byte配列
+ * @brief constructor
+ * @param[in] vector byte array(20byte).
*/
ByteData160(const std::vector& vector); // NOLINT
/**
- * @brief コンストラクタ
- * @param[in] hex ByteデータHEX文字列
+ * @brief constructor
+ * @param[in] hex hex string.
*/
explicit ByteData160(const std::string& hex);
@@ -247,41 +258,41 @@ class CFD_CORE_EXPORT ByteData160 {
explicit ByteData160(const ByteData& byte_data);
/**
- * @brief HEX文字列を取得する.
- * @return HEX文字列
+ * @brief Get a hex string.
+ * @return hex string.
*/
std::string GetHex() const;
/**
- * @brief Byte配列を取得する.
- * @return Byte配列
+ * @brief Get a byte array.
+ * @return byte array.
*/
std::vector GetBytes() const;
/**
- * @brief データが空か取得する.
- * @retval true データが空
- * @retval false データが存在
+ * @brief Check is data empty.
+ * @retval true empty.
+ * @retval false not empty.
* @deprecated replace to IsEmpty .
*/
bool Empty() const;
/**
- * @brief データが空か取得する.
- * @retval true データが空
- * @retval false データが存在
+ * @brief Check is data empty.
+ * @retval true empty.
+ * @retval false not empty.
*/
bool IsEmpty() const;
/**
- * @brief ByteData比較
- * @param bytedata 比較対象のオブジェクト
- * @retval true 一致した場合
- * @retval false 不一致の場合
+ * @brief Check equals.
+ * @param bytedata compare target object.
+ * @retval true equals.
+ * @retval false not equals.
*/
bool Equals(const ByteData160& bytedata) const;
/**
- * @brief byte data情報を取得する.
+ * @brief Get a byte data object.
* @return byte data
*/
ByteData GetData() const;
@@ -360,38 +371,46 @@ class CFD_CORE_EXPORT ByteData160 {
}
/**
- * @brief byte data情報をserializeする.
+ * @brief Serialize byte data.
* @return serialize data
*/
ByteData Serialize() const;
+ /**
+ * @brief Equals operator.
+ * @param[in] object target object.
+ * @retval true equals
+ * @retval false not equals
+ */
+ bool operator==(const ByteData160& object) const;
+
private:
/**
- * @brief 20byte固定データ格納Byte配列
+ * @brief 20byte fixed data.
*/
std::vector data_;
};
/**
* @class ByteData256
- * @brief サイズ固定(32byte)のByte配列データクラス
+ * @brief Fixed size (32 bytes) Byte array data class.
*/
class CFD_CORE_EXPORT ByteData256 {
public:
/**
- * @brief デフォルトコンストラクタ
+ * @brief default constructor
*/
ByteData256();
/**
- * @brief コンストラクタ
- * @param[in] vector 32byteデータ格納Byte配列
+ * @brief constructor
+ * @param[in] vector byte array(32byte).
*/
ByteData256(const std::vector& vector); // NOLINT
/**
- * @brief コンストラクタ
- * @param[in] hex ByteデータHEX文字列
+ * @brief constructor
+ * @param[in] hex hex string.
*/
explicit ByteData256(const std::string& hex);
@@ -402,41 +421,41 @@ class CFD_CORE_EXPORT ByteData256 {
explicit ByteData256(const ByteData& byte_data);
/**
- * @brief HEX文字列を取得する.
- * @return HEX文字列
+ * @brief Get a hex string.
+ * @return hex string.
*/
std::string GetHex() const;
/**
- * @brief Byte配列を取得する.
- * @return Byte配列
+ * @brief Get a byte array.
+ * @return byte array.
*/
std::vector GetBytes() const;
/**
- * @brief データが空か取得する.
- * @retval true データが空
- * @retval false データが存在
+ * @brief Check is data empty.
+ * @retval true empty.
+ * @retval false not empty.
* @deprecated replace to IsEmpty .
*/
bool Empty() const;
/**
- * @brief データが空か取得する.
- * @retval true データが空
- * @retval false データが存在
+ * @brief Check is data empty.
+ * @retval true empty.
+ * @retval false not empty.
*/
bool IsEmpty() const;
/**
- * @brief ByteData比較
- * @param bytedata 比較対象のオブジェクト
- * @retval true 一致した場合
- * @retval false 不一致の場合
+ * @brief Check equals.
+ * @param bytedata compare target object.
+ * @retval true equals.
+ * @retval false not equals.
*/
bool Equals(const ByteData256& bytedata) const;
/**
- * @brief byte data情報を取得する.
+ * @brief Get a byte data object.
* @return byte data
*/
ByteData GetData() const;
@@ -515,18 +534,291 @@ class CFD_CORE_EXPORT ByteData256 {
}
/**
- * @brief byte data情報をserializeする.
+ * @brief Serialize byte data.
* @return serialize data
*/
ByteData Serialize() const;
+ /**
+ * @brief Equals operator.
+ * @param[in] object target object.
+ * @retval true equals
+ * @retval false not equals
+ */
+ bool operator==(const ByteData256& object) const;
+
private:
/**
- * @brief 32byte固定データ格納Byte配列
+ * @brief 32byte fixed data.
*/
std::vector data_;
};
+/**
+ * @class Serializer
+ * @brief A class that serializes a byte array.
+ */
+class CFD_CORE_EXPORT Serializer {
+ public:
+ static constexpr uint8_t kViTag16 = 253; //!< VarInt16
+ static constexpr uint8_t kViTag32 = 254; //!< VarInt32
+ static constexpr uint8_t kViTag64 = 255; //!< VarInt64
+ static constexpr uint8_t kViMax8 = 252; //!< VarInt8
+
+ /**
+ * @brief get variable integer size.
+ * @param[in] value value
+ * @return variable integer size
+ */
+ static uint32_t GetVariableIntSize(uint64_t value);
+
+ /**
+ * @brief constructor.
+ */
+ Serializer();
+ /**
+ * @brief constructor.
+ * @param[in] initial_size initial buffer size.
+ */
+ explicit Serializer(uint32_t initial_size);
+ /**
+ * @brief destructor.
+ */
+ virtual ~Serializer() {}
+ /**
+ * @brief copy constructor.
+ * @param[in] object object
+ */
+ Serializer(const Serializer& object);
+ /**
+ * @brief copy constructor.
+ * @param[in] object object
+ * @return object
+ */
+ Serializer& operator=(const Serializer& object);
+
+ /**
+ * @brief add variable integer.
+ * @param[in] value value
+ */
+ void AddVariableInt(uint64_t value);
+
+ /**
+ * @brief add variable buffer.
+ * @param[in] buffer buffer
+ */
+ void AddVariableBuffer(const ByteData& buffer);
+ /**
+ * @brief add prefix buffer.
+ * @param[in] prefix prefix
+ * @param[in] buffer buffer
+ */
+ void AddPrefixBuffer(uint64_t prefix, const ByteData& buffer);
+ /**
+ * @brief add direct byte array.
+ * @param[in] buffer buffer
+ */
+ void AddDirectBytes(const ByteData& buffer);
+ /**
+ * @brief add direct byte array.
+ * @param[in] buffer buffer
+ */
+ void AddDirectBytes(const ByteData256& buffer);
+
+ /**
+ * @brief add variable buffer.
+ * @param[in] buffer buffer
+ * @param[in] buffer_size buffer size
+ */
+ void AddVariableBuffer(const uint8_t* buffer, uint32_t buffer_size);
+ /**
+ * @brief add prefix buffer.
+ * @param[in] prefix prefix
+ * @param[in] buffer buffer
+ * @param[in] buffer_size buffer size
+ */
+ void AddPrefixBuffer(
+ uint64_t prefix, const uint8_t* buffer, uint32_t buffer_size);
+ /**
+ * @brief add direct byte array.
+ * @param[in] buffer buffer
+ * @param[in] buffer_size buffer size
+ */
+ void AddDirectBytes(const uint8_t* buffer, uint32_t buffer_size);
+
+ /**
+ * @brief add direct byte data.
+ * @param[in] byte_data byte data
+ */
+ void AddDirectByte(uint8_t byte_data);
+ /**
+ * @brief add direct number.
+ * @param[in] number value
+ */
+ void AddDirectNumber(uint32_t number);
+ /**
+ * @brief add direct number.
+ * @param[in] number value
+ */
+ void AddDirectNumber(uint64_t number);
+ /**
+ * @brief add direct number.
+ * @param[in] number value
+ */
+ void AddDirectNumber(int64_t number);
+
+ /**
+ * @brief add direct byte array.
+ * @param[in] buffer buffer
+ * @return serializer object.
+ */
+ Serializer& operator<<(const ByteData& buffer);
+ /**
+ * @brief add direct byte array.
+ * @param[in] buffer buffer
+ * @return serializer object.
+ */
+ Serializer& operator<<(const ByteData256& buffer);
+ /**
+ * @brief add direct byte data.
+ * @param[in] byte_data byte data
+ * @return serializer object.
+ */
+ Serializer& operator<<(uint8_t byte_data);
+ /**
+ * @brief add direct number.
+ * @param[in] number value
+ * @return serializer object.
+ */
+ Serializer& operator<<(uint32_t number);
+ /**
+ * @brief add direct number.
+ * @param[in] number value
+ * @return serializer object.
+ */
+ Serializer& operator<<(uint64_t number);
+ /**
+ * @brief add direct number.
+ * @param[in] number value
+ * @return serializer object.
+ */
+ Serializer& operator<<(int64_t number);
+
+ /**
+ * @brief Output byte array.
+ * @return byte array.
+ */
+ ByteData Output();
+
+ protected:
+ std::vector buffer_; //!< buffer
+ uint32_t offset_; //!< offset
+
+ /**
+ * @brief check need buffer size.
+ * @param[in] need_size need buffer size
+ */
+ void CheckNeedSize(uint32_t need_size);
+};
+
+/**
+ * @class Deserializer
+ * @brief A class that analyze a serialized byte array.
+ */
+class CFD_CORE_EXPORT Deserializer {
+ public:
+ /**
+ * @brief constructor.
+ */
+ Deserializer() : offset_(0) {}
+ /**
+ * @brief constructor.
+ * @param[in] buffer buffer
+ */
+ explicit Deserializer(const std::vector& buffer);
+ /**
+ * @brief constructor.
+ * @param[in] buffer buffer
+ */
+ explicit Deserializer(const ByteData& buffer);
+ /**
+ * @brief destructor.
+ */
+ virtual ~Deserializer() {}
+ /**
+ * @brief copy constructor.
+ * @param[in] object object
+ */
+ Deserializer(const Deserializer& object);
+ /**
+ * @brief copy constructor.
+ * @param[in] object object
+ * @return object
+ */
+ Deserializer& operator=(const Deserializer& object);
+
+ /**
+ * @brief read uint64.
+ * @return uint64
+ */
+ uint64_t ReadUint64();
+ /**
+ * @brief read uint32.
+ * @return uint32
+ */
+ uint32_t ReadUint32();
+ /**
+ * @brief read uint8.
+ * @return uint8
+ */
+ uint8_t ReadUint8();
+
+ /**
+ * @brief read variable integer.
+ * @return uint64
+ */
+ uint64_t ReadVariableInt();
+ /**
+ * @brief read buffer.
+ * @param[in] size read size.
+ * @return buffer
+ */
+ std::vector ReadBuffer(uint32_t size);
+ /**
+ * @brief read array.
+ * @param[in,out] output write array.
+ * @param[in] size read size.
+ */
+ void ReadArray(uint8_t* output, size_t size);
+
+ /**
+ * @brief read variable buffer.
+ * @return buffer
+ */
+ std::vector ReadVariableBuffer();
+ /**
+ * @brief read variable buffer.
+ * @return buffer
+ */
+ ByteData ReadVariableData();
+
+ /**
+ * @brief get all read size.
+ * @return size (offset)
+ */
+ uint32_t GetReadSize();
+
+ protected:
+ std::vector buffer_; //!< buffer
+ uint32_t offset_; //!< offset
+
+ /**
+ * @brief check read offset size.
+ * @param[in] size need size
+ */
+ void CheckReadSize(uint64_t size);
+};
+
} // namespace core
} // namespace cfd
diff --git a/include/cfdcore/cfdcore_coin.h b/include/cfdcore/cfdcore_coin.h
index a202a315..ab4b855e 100644
--- a/include/cfdcore/cfdcore_coin.h
+++ b/include/cfdcore/cfdcore_coin.h
@@ -2,7 +2,7 @@
/**
* @file cfdcore_coin.h
*
- * @brief Coin(UTXO)関連クラス定義
+ * @brief Coin (UTXO) related class definition.
*/
#ifndef CFD_CORE_INCLUDE_CFDCORE_CFDCORE_COIN_H_
@@ -18,44 +18,56 @@ namespace cfd {
namespace core {
/**
- * @brief transaction idクラス
+ * @brief transaction id class.
*/
class CFD_CORE_EXPORT Txid {
public:
/**
- * @brief デフォルトコンストラクタ
+ * @brief default constructor
*/
Txid();
/**
- * @brief コンストラクタ
- * @param[in] hex Hex文字列
+ * @brief constructor
+ * @param[in] hex hex string
*/
explicit Txid(const std::string& hex);
/**
- * @brief コンストラクタ
- * @param[in] data ByteData256インスタンス
+ * @brief constructor
+ * @param[in] data ByteData256 instance
*/
explicit Txid(const ByteData256& data);
/**
- * @brief デストラクタ
+ * @brief destructor.
*/
virtual ~Txid() {
// do nothing
}
/**
- * @brief Hex文字列を取得する.
- * @return Hex文字列
+ * @brief copy constructor.
+ * @param[in] object object
+ */
+ Txid(const Txid& object);
+ /**
+ * @brief copy constructor.
+ * @param[in] object object
+ * @return object
+ */
+ Txid& operator=(const Txid& object);
+ /**
+ * @brief Get a hex string.
+ * @return hex string
*/
const std::string GetHex() const;
/**
- * @brief ByteDataを取得する.
- * @return ByteDataオブジェクト
+ * @brief Get a ByteData object.
+ * @return ByteData object.
*/
const ByteData GetData() const;
/**
- * @brief Txid比較
- * @param txid 比較対象のオブジェクト
- * @return true:一致/false:不一致
+ * @brief compare Txid.
+ * @param txid compare target.
+ * @retval true equals.
+ * @retval false not equals.
*/
bool Equals(const Txid& txid) const;
/**
@@ -70,40 +82,51 @@ class CFD_CORE_EXPORT Txid {
};
/**
- * @brief block hashクラス
+ * @brief block hash class.
*/
class CFD_CORE_EXPORT BlockHash {
public:
/**
- * @brief デフォルトコンストラクタ
+ * @brief default constructor
*/
BlockHash() {
// do nothing
}
/**
- * @brief コンストラクタ
- * @param[in] hex Hex文字列
+ * @brief constructor
+ * @param[in] hex hex string
*/
explicit BlockHash(const std::string& hex);
/**
- * @brief コンストラクタ
- * @param[in] data ByteData256インスタンス
+ * @brief constructor
+ * @param[in] data ByteData256 object.
*/
explicit BlockHash(const ByteData256& data);
/**
- * @brief デストラクタ
+ * @brief destructor.
*/
virtual ~BlockHash() {
// do nothing
}
/**
- * @brief Hex文字列を取得する.
- * @return Hex文字列
+ * @brief copy constructor.
+ * @param[in] object object
+ */
+ BlockHash(const BlockHash& object);
+ /**
+ * @brief copy constructor.
+ * @param[in] object object
+ * @return object
+ */
+ BlockHash& operator=(const BlockHash& object);
+ /**
+ * @brief Get a hex string.
+ * @return hex string
*/
const std::string GetHex() const;
/**
- * @brief ByteDataを取得する.
- * @return ByteDataオブジェクト
+ * @brief Get a ByteData object.
+ * @return ByteData object.
*/
const ByteData GetData() const;
/**
diff --git a/include/cfdcore/cfdcore_common.h b/include/cfdcore/cfdcore_common.h
index 40288f24..0fd0cafa 100644
--- a/include/cfdcore/cfdcore_common.h
+++ b/include/cfdcore/cfdcore_common.h
@@ -1,7 +1,7 @@
// Copyright 2019 CryptoGarage
/**
* @file cfdcore_common.h
- * @brief cfdcoreの共通定義ファイル。
+ * @brief Common definition file for cfdcore.
*/
#ifndef CFD_CORE_INCLUDE_CFDCORE_CFDCORE_COMMON_H_
#define CFD_CORE_INCLUDE_CFDCORE_CFDCORE_COMMON_H_
@@ -9,7 +9,7 @@
#include
/**
- * @brief APIのDLLエクスポート定義
+ * @brief API DLL export definition
*/
#ifndef CFD_CORE_API
#if defined(_WIN32)
@@ -28,7 +28,7 @@
#endif
/**
- * @brief クラスのDLLエクスポート定義
+ * @brief DLL export definition for class
*/
#ifndef CFD_CORE_EXPORT
#if defined(_WIN32)
@@ -47,19 +47,19 @@
#endif
/**
- * @brief cfd名前空間
+ * @brief cfd namespace
*/
namespace cfd {
/**
- * @brief cfd::core名前空間
+ * @brief cfd::core namespace
*/
namespace core {
-/// cfdcoreのハンドル値。
+/// Handle value of cfdcore.
using CfdCoreHandle = void*;
/**
- * @brief ライブラリがサポートしている機能の定義値
+ * @brief Definition value of the function supported by the library.
*/
enum LibraryFunction {
kEnableBitcoin = 0x0001, //!< enable bitcoin function
@@ -68,19 +68,19 @@ enum LibraryFunction {
// API
/**
- * @brief ライブラリがサポートしている機能の値を取得する。
- * @return LibraryFunctionのビットフラグ
+ * @brief Get the value of the function supported by the library.
+ * @return Library Function bit flag
*/
CFD_CORE_API uint64_t GetSupportedFunction();
/**
- * @brief cfdcoreの初期化を行う。
- * @param[out] handle ハンドル値。
+ * @brief Initialize cfdcore.
+ * @param[out] handle Handle value.
*/
CFD_CORE_API void Initialize(CfdCoreHandle* handle);
/**
- * @brief cfdcoreの終了処理を行う。
- * @param[in] handle ハンドル値。
- * @param[in] is_finish_process プロセス終了時かどうか
+ * @brief Performs cfdcore termination processing.
+ * @param[in] handle Handle value.
+ * @param[in] is_finish_process Whether at the end of the process.
*/
CFD_CORE_API void Finalize(
const CfdCoreHandle handle, bool is_finish_process = false);
diff --git a/include/cfdcore/cfdcore_descriptor.h b/include/cfdcore/cfdcore_descriptor.h
index 9d7a8238..c55f0a33 100644
--- a/include/cfdcore/cfdcore_descriptor.h
+++ b/include/cfdcore/cfdcore_descriptor.h
@@ -2,7 +2,7 @@
/**
* @file cfdcore_descriptor.h
*
- * @brief Output Descriptor関連クラス定義
+ * @brief The Output Descriptor related class definition.
*
*/
#ifndef CFD_CORE_INCLUDE_CFDCORE_CFDCORE_DESCRIPTOR_H_
@@ -28,7 +28,7 @@ namespace core {
constexpr const char* const kArgumentBaseExtkey = "base";
/**
- * @brief DescriptorNode の種別定義.
+ * @brief DescriptorNode type definition.
*/
enum DescriptorNodeType {
kDescriptorTypeNull, //!< null
@@ -38,7 +38,7 @@ enum DescriptorNodeType {
};
/**
- * @brief DescriptorNode のScript種別定義.
+ * @brief Script type definition of DescriptorNode.
*/
enum DescriptorScriptType {
kDescriptorScriptNull, //!< null
@@ -56,7 +56,7 @@ enum DescriptorScriptType {
};
/**
- * @brief DescriptorNode のKey種別定義.
+ * @brief Key type definition of DescriptorNode.
*/
enum DescriptorKeyType {
kDescriptorKeyNull, //!< null
@@ -66,7 +66,7 @@ enum DescriptorKeyType {
};
/**
- * @brief key型descriptorの情報クラスです.
+ * @brief Information class of key type descriptor.
*/
class CFD_CORE_EXPORT DescriptorKeyInfo {
public:
@@ -216,7 +216,7 @@ class CFD_CORE_EXPORT DescriptorKeyInfo {
};
/**
- * @brief key型descriptorの参照クラスです.
+ * @brief It is a reference class of key type descriptor.
*/
class CFD_CORE_EXPORT DescriptorKeyReference {
public:
@@ -243,6 +243,13 @@ class CFD_CORE_EXPORT DescriptorKeyReference {
*/
explicit DescriptorKeyReference(
const ExtPubkey& ext_pubkey, const std::string* arg = nullptr);
+ /**
+ * @brief constructor.
+ * @param[in] key key data
+ * @param[in] arg argument
+ */
+ explicit DescriptorKeyReference(
+ const KeyData& key, const std::string* arg = nullptr);
/**
* @brief copy constructor.
* @param[in] object DescriptorKeyReference object
@@ -289,6 +296,11 @@ class CFD_CORE_EXPORT DescriptorKeyReference {
* @return ext-pubkey
*/
ExtPubkey GetExtPubkey() const;
+ /**
+ * @brief getting key data.
+ * @return key data
+ */
+ KeyData GetKeyData() const;
/**
* @brief getting key type.
* @return key type
@@ -300,11 +312,12 @@ class CFD_CORE_EXPORT DescriptorKeyReference {
Pubkey pubkey_; //!< pubkey
ExtPrivkey extprivkey_; //!< ext privkey
ExtPubkey extpubkey_; //!< ext pubkey
+ KeyData key_data_; //!< key data
std::string argument_; //!< argument
};
/**
- * @brief Script型descriptorの参照クラスです.
+ * @brief Script type descriptor is a reference class.
*/
class CFD_CORE_EXPORT DescriptorScriptReference {
public:
@@ -474,7 +487,7 @@ class CFD_CORE_EXPORT DescriptorScriptReference {
};
/**
- * @brief Descriptor用Node定義クラス
+ * @brief Node definition class for Descriptor.
*/
class CFD_CORE_EXPORT DescriptorNode {
public:
@@ -520,21 +533,25 @@ class CFD_CORE_EXPORT DescriptorNode {
/**
* @brief get reference object.
* @param[in] array_argument argument
+ * @param[in] parent parent object
* @return reference object
*/
DescriptorScriptReference GetReference(
- std::vector* array_argument) const;
+ std::vector* array_argument,
+ const DescriptorNode* parent = nullptr) const;
/**
* @brief get reference object list.
* @param[in] array_argument argument
+ * @param[in] parent parent object
* @return reference object list
*/
std::vector GetReferences(
- std::vector* array_argument) const;
+ std::vector* array_argument,
+ const DescriptorNode* parent = nullptr) const;
/**
- * @brief argumentに必要な数を取得する。
+ * @brief Get the number required for argument.
* @return argument number.
*/
uint32_t GetNeedArgumentNum() const;
@@ -547,12 +564,12 @@ class CFD_CORE_EXPORT DescriptorNode {
std::string ToString(bool append_checksum = true) const;
/**
- * @brief DescriptorNodeの種別を取得する。
+ * @brief Get the type of DescriptorNode.
* @return DescriptorNodeType
*/
DescriptorNodeType GetNodeType() const { return node_type_; }
/**
- * @brief DescriptorNodeのScript種別を取得する。
+ * @brief Get the Script type of DescriptorNode.
* @return DescriptorScriptType
*/
DescriptorScriptType GetScriptType() const { return script_type_; }
@@ -741,6 +758,31 @@ class CFD_CORE_EXPORT Descriptor {
std::vector GetReferenceAll(
const std::vector* array_argument = nullptr) const;
+ /**
+ * @brief getting key data.
+ * @return key data
+ */
+ KeyData GetKeyData() const;
+ /**
+ * @brief getting key data.
+ * @param[in] argument argument
+ * @return key data
+ */
+ KeyData GetKeyData(const std::string& argument) const;
+ /**
+ * @brief getting key data.
+ * @param[in] array_argument argument
+ * @return key data
+ */
+ KeyData GetKeyData(const std::vector& array_argument) const;
+ /**
+ * @brief getting key data list.
+ * @param[in] array_argument argument
+ * @return key data
+ */
+ std::vector GetKeyDataAll(
+ const std::vector* array_argument = nullptr) const;
+
/**
* @brief getting output descriptor.
* @param[in] append_checksum append checksum
diff --git a/include/cfdcore/cfdcore_elements_address.h b/include/cfdcore/cfdcore_elements_address.h
index 087b9ab3..554fdbc5 100644
--- a/include/cfdcore/cfdcore_elements_address.h
+++ b/include/cfdcore/cfdcore_elements_address.h
@@ -2,7 +2,7 @@
/**
* @file cfdcore_elements_address.h
*
- * @brief Elements対応したAddressクラス定義
+ * @brief The address class definition file used in Elements (liquid network).
*/
#ifndef CFD_CORE_INCLUDE_CFDCORE_CFDCORE_ELEMENTS_ADDRESS_H_
#define CFD_CORE_INCLUDE_CFDCORE_CFDCORE_ELEMENTS_ADDRESS_H_
@@ -21,32 +21,32 @@ namespace cfd {
namespace core {
/**
- * @brief ConfidentialKey(= Pubkey)の型定義
+ * @brief Type definition of ConfidentialKey (= Pubkey)
* @see Pubkey
*/
using ConfidentialKey = Pubkey;
/**
* @typedef ElementsNetType
- * @brief Elements Networkの定義
+ * @brief Elements Network definition
*/
using ElementsNetType = NetType;
/**
* @typedef ElementsAddressType
- * @brief ElementsのAddress種別の定義
+ * @brief Definition of Address type of Elements
*/
using ElementsAddressType = AddressType;
/**
- * @brief Elements のデフォルトのアドレスフォーマットリストを取得する.
- * @return Elementsデフォルトのアドレスフォーマットリスト
+ * @brief Get the default address format list for Elements.
+ * @return default address format list for Elements.
*/
CFD_CORE_API std::vector GetElementsAddressFormatList();
/**
* @class ElementsConfidentialAddress
- * @brief ElementsのConfidentialアドレスを表現するクラス
+ * @brief A class that represents the Confidential address of Elements
*/
class CFD_CORE_EXPORT ElementsConfidentialAddress {
public:
@@ -60,91 +60,103 @@ class CFD_CORE_EXPORT ElementsConfidentialAddress {
const Privkey& master_blinding_key, const Script& locking_script);
/**
- * @brief デフォルトコンストラクタ
+ * @brief default constructor.
*/
ElementsConfidentialAddress();
/**
- * @brief コンストラクタ(UnblindedAddressからConfidentialAddress生成)
- * @param unblinded_address UnblindedAddress インスタンス
- * @param confidential_key ConfidentialKey インスタンス
+ * @brief constructor. (Generate Confidential Address from Unblinded Address)
+ * @param unblinded_address UnblindedAddress instance
+ * @param confidential_key ConfidentialKey instance
*/
- ElementsConfidentialAddress(
+ explicit ElementsConfidentialAddress(
const Address& unblinded_address,
const ConfidentialKey& confidential_key);
/**
- * @brief コンストラクタ(ConfidentialAddress文字列からのデコード)
- * @param[in] confidential_address confidential アドレス文字列
+ * @brief constructor. (Decoding from the ConfidentialAddress string)
+ * @param[in] confidential_address confidential address string.
*/
explicit ElementsConfidentialAddress(
const std::string& confidential_address);
/**
- * @brief コンストラクタ(ConfidentialAddress文字列からのデコード)
- * @param[in] confidential_address confidential アドレス文字列
+ * @brief constructor. (Decoding from the ConfidentialAddress string)
+ * @param[in] confidential_address confidential address string.
* @param[in] prefix_list address prefix list
*/
explicit ElementsConfidentialAddress(
const std::string& confidential_address,
const std::vector& prefix_list);
+ /**
+ * @brief copy constructor.
+ * @param[in] object object
+ */
+ ElementsConfidentialAddress(const ElementsConfidentialAddress& object);
+ /**
+ * @brief copy constructor.
+ * @param[in] object object
+ * @return object
+ */
+ ElementsConfidentialAddress& operator=(
+ const ElementsConfidentialAddress& object) &;
/**
- * @brief UnblindedAddressを取得
- * @return ConfidentialAddressに紐づくUnblindedAddressインスタンス
+ * @brief Get UnblindedAddress
+ * @return UnblindedAddress instance associated with ConfidentialAddress
*/
Address GetUnblindedAddress() const;
/**
- * @brief ConfidentialKeyを取得
- * @return ConfidentialAddressに紐づくConfidentialKeyインスタンス
+ * @brief Get Confidential Key
+ * @return Confidential Key instance associated with Confidential Address
*/
ConfidentialKey GetConfidentialKey() const;
/**
- * @brief アドレスのhex文字列を取得する.
- * @return アドレス文字列
+ * @brief Get the address string.
+ * @return address string.
*/
std::string GetAddress() const;
/**
- * @brief AddressのElementsNetTypeを取得する.
+ * @brief Get the ElementsNetType of Address.
* @return ElementsNetType
*/
ElementsNetType GetNetType() const;
/**
- * @brief Address種別を取得する.
- * @return Elements Address種別
+ * @brief Get the Address type.
+ * @return Address type.
*/
ElementsAddressType GetAddressType() const;
/**
- * @brief アドレスHashを取得する.
- * @return アドレスHashのByteDataインスタンス
+ * @brief Get the address Hash.
+ * @return address Hash.
*/
ByteData GetHash() const;
/**
- * @brief LockingScriptを取得する
+ * @brief Get LockingScript
* @return locking script
*/
Script GetLockingScript() const;
/**
- * @brief 引数で指定されたアドレスがBlindされているアドレスであるかを判定する
- * @param address アドレス(base58)文字列
- * @retval true Blindされているアドレスの場合
- * @retval false Blindされていないアドレスの場合
+ * @brief Determines if the specified address is a Blinded address
+ * @param address address string
+ * @retval true has blind address
+ * @retval false not blind address
*/
static bool IsConfidentialAddress(const std::string& address);
/**
- * @brief 引数で指定されたアドレスがBlindされているアドレスであるかを判定する
- * @param[in] address アドレス文字列
- * @param[in] prefix_list アドレス文字列
- * @retval true Blindされているアドレスの場合
- * @retval false Blindされていないアドレスの場合
+ * @brief Determines if the specified address is a Blinded address
+ * @param[in] address address string
+ * @param[in] prefix_list address prefix list
+ * @retval true has blind address
+ * @retval false not blind address
*/
static bool IsConfidentialAddress(
const std::string& address,
@@ -152,7 +164,7 @@ class CFD_CORE_EXPORT ElementsConfidentialAddress {
private:
/**
- * @brief confidentialアドレス文字列からモデルのデコードを行う
+ * @brief Decode the model from the confidential address string
* @param[in] confidential_address confidential address string
* @param[in] prefix_list address prefix list
*/
@@ -161,10 +173,11 @@ class CFD_CORE_EXPORT ElementsConfidentialAddress {
const std::vector& prefix_list);
/**
- * @brief unblinded_addressとconfidential_keyから、confidential_addressを計算する.
- * @details Elementsのネットワーク種別については、ublinded_addressと同種のネットワークで計算を行う.
- * @param unblinded_address UnblindedAddressインスタンス
- * @param confidential_key Blindに利用するConfidentialKeyインスタンス
+ * @brief Calculate the confidential_address from the unblinded_address and confidential_key.
+ * @details For the network type of Elements, the calculation is performed \
+ * on the same type of network as connected_address.
+ * @param unblinded_address UnblindedAddress
+ * @param confidential_key Confidential Key instance used for Blind
*/
void CalculateAddress(
const Address& unblinded_address,
@@ -176,7 +189,7 @@ class CFD_CORE_EXPORT ElementsConfidentialAddress {
/// Confidential Key
ConfidentialKey confidential_key_;
- /// アドレス文字列
+ /// address string
std::string address_;
};
diff --git a/include/cfdcore/cfdcore_elements_script.h b/include/cfdcore/cfdcore_elements_script.h
index 11f46944..82c3b21a 100644
--- a/include/cfdcore/cfdcore_elements_script.h
+++ b/include/cfdcore/cfdcore_elements_script.h
@@ -2,7 +2,7 @@
/**
* @file cfdcore_elements_script.h
*
- * @brief Elements対応したScriptクラス定義
+ * @brief The script class definition file used in Elements (liquid network).
*/
#ifndef CFD_CORE_INCLUDE_CFDCORE_CFDCORE_ELEMENTS_SCRIPT_H_
#define CFD_CORE_INCLUDE_CFDCORE_CFDCORE_ELEMENTS_SCRIPT_H_
@@ -18,34 +18,34 @@ namespace core {
/**
* @class ContractHashUtil
- * @brief ElementsのContractHash関連処理を行うクラス.
+ * @brief A class that performs ContractHash related processing of Elements.
*
* @details
- * 本クラスではcfd_coreの機能として必要な最小限の処理のみ実装する。
- * 本クラスの対象外である下記の要素については、別途作成すること。
- * - Privkey: Privkey::GenerageRandomKey()でランダム生成する。
- * - Pubkey: PrivkeyのGeneratePubkey(true)で生成する。
- * - claim script: p2wpkh or p2pkhのlockingScriptを生成する。
- * - Elementsのデフォルトはbech32(p2wpkh)形式。
+ * In this class, only the minimum processing required as a function of cfd_core is implemented.
+ * The following elements that are not covered by this class should be created separately.
+ * - Privkey: private key.
+ * - Pubkey: Generate using Privkey::GeneratePubkey(true).
+ * - claim script: Generate a lockingScript of p2wpkh or p2pkh.
+ * - Elements default to bech32 (p2wpkh) format.
* (script: OP_0 <20-byte-key-hash>)
- * - 生成方法: ScriptBuilder().AppendOperator(ScriptOperator::OP_0)
+ * - Generation: ScriptBuilder().AppendOperator(ScriptOperator::OP_0)
* .AppendData(AddHashUtil::hash160(pubkey)).Build()
- * - mainchain address: ContractScriptから生成する。
- * - Elementsのデフォルトはp2sh-segwit。
- * - 生成方法 \n
- * 1. ContractScriptから、p2wshのlockingScriptを作成。
+ * - mainchain address: Generated from ContractScript.
+ * - The default for Elements is p2sh-segwit.
+ * - Generation \n
+ * 1. Create a p2wsh locking Script from ContractScript.
* (script: OP_0 <32-byte-script-hash>) \n
* ScriptBuilder().AppendOperator(ScriptOperator::OP_0)
* .AppendData(AddHashUtil::sha256(ContractScript)).Build()
- * 2. 1を用いて、p2shのAddressを作成。
- * Address(NetType, 1のlockingScript)
+ * 2. Create a p2sh Address using 1's locking script.
+ * Address(NetType, 1's 'lockingScript)
*/
class CFD_CORE_EXPORT ContractHashUtil {
public:
/**
- * @brief Pay-to-Contractスクリプトを生成する。
+ * @brief Generate a Pay-to-Contract script.
* @param[in] claim_script claim script
- * @param[in] fedpeg_script elementsdのside chain設定スクリプト
+ * @param[in] fedpeg_script elementsd side chain configuration script
* @return Pay-to-Contract script.
*/
static Script GetContractScript(
@@ -53,7 +53,7 @@ class CFD_CORE_EXPORT ContractHashUtil {
private:
/**
- * @brief liquidV1 watchman script形式かどうかをチェックする。
+ * @brief Check if it is in liquidV1 watchman script format.
* @param[in] script script
* @retval true liquidV1 watchman script format
* @retval false other script
@@ -61,7 +61,7 @@ class CFD_CORE_EXPORT ContractHashUtil {
static bool CheckLiquidV1Watchman(const Script& script);
/**
- * @brief コンストラクタ
+ * @brief constructor.
*/
ContractHashUtil();
};
diff --git a/include/cfdcore/cfdcore_elements_transaction.h b/include/cfdcore/cfdcore_elements_transaction.h
index 0813e77b..d568fab1 100644
--- a/include/cfdcore/cfdcore_elements_transaction.h
+++ b/include/cfdcore/cfdcore_elements_transaction.h
@@ -2,7 +2,7 @@
/**
* @file cfdcore_elements_transaction.h
*
- * @brief Elements Transaction関連クラスを定義する。
+ * @brief Define Elements Transaction related classes.
*
*/
#ifndef CFD_CORE_INCLUDE_CFDCORE_CFDCORE_ELEMENTS_TRANSACTION_H_
@@ -26,56 +26,65 @@ class BlindFactor;
constexpr const int kDefaultBlindMinimumBits = 52;
/**
- * @brief nonce情報を保持するクラス
+ * @brief Class that holds nonce information
*/
class CFD_CORE_EXPORT ConfidentialNonce {
public:
/**
- * @brief コンストラクタ.
- *
- * リスト定義等における初期化のため、定義する。
+ * @brief constructor.
*/
ConfidentialNonce();
/**
- * @brief コンストラクタ.
+ * @brief constructor.
* @param[in] hex_string hex string.
*/
explicit ConfidentialNonce(const std::string& hex_string);
/**
- * @brief コンストラクタ.
+ * @brief constructor.
* @param[in] byte_data byte array data.
*/
explicit ConfidentialNonce(const ByteData& byte_data);
/**
- * @brief コンストラクタ.
+ * @brief constructor.
* @param[in] pubkey pubkey.
*/
explicit ConfidentialNonce(const Pubkey& pubkey);
/**
- * @brief デストラクタ.
+ * @brief destructor.
*/
virtual ~ConfidentialNonce() {
// do nothing
}
+ /**
+ * @brief copy constructor.
+ * @param[in] object object
+ */
+ ConfidentialNonce(const ConfidentialNonce& object);
+ /**
+ * @brief copy constructor.
+ * @param[in] object object
+ * @return object
+ */
+ ConfidentialNonce& operator=(const ConfidentialNonce& object);
/**
- * @brief バイトデータを取得する.
+ * @brief Get byte data.
* @return byte array data.
*/
ByteData GetData() const;
/**
- * @brief HEX文字列を取得する.
+ * @brief Get the HEX string.
* @return hex string
*/
std::string GetHex() const;
/**
- * @brief blind有無を取得する.
+ * @brief Get if it is blind.
* @retval true blind
* @retval false unblind
*/
bool HasBlinding() const;
/**
- * @brief 空かどうかを取得する.
+ * @brief Get if it's empty.
* @retval true empty
* @retval false exist value
*/
@@ -93,56 +102,65 @@ class CFD_CORE_EXPORT ConfidentialNonce {
};
/**
- * @brief AssetId情報を保持するクラス
+ * @brief Class that holds AssetId information
*/
class CFD_CORE_EXPORT ConfidentialAssetId {
public:
/**
- * @brief コンストラクタ.
- *
- * リスト定義等における初期化のため、定義する。
+ * @brief constructor.
*/
ConfidentialAssetId();
/**
- * @brief コンストラクタ.
+ * @brief constructor.
* @param[in] hex_string hex string.
*/
explicit ConfidentialAssetId(const std::string& hex_string);
/**
- * @brief コンストラクタ.
+ * @brief constructor.
* @param[in] byte_data byte array data.
*/
explicit ConfidentialAssetId(const ByteData& byte_data);
/**
- * @brief デストラクタ.
+ * @brief destructor.
*/
virtual ~ConfidentialAssetId() {
// do nothing
}
+ /**
+ * @brief copy constructor.
+ * @param[in] object object
+ */
+ ConfidentialAssetId(const ConfidentialAssetId& object);
+ /**
+ * @brief copy constructor.
+ * @param[in] object object
+ * @return object
+ */
+ ConfidentialAssetId& operator=(const ConfidentialAssetId& object);
/**
- * @brief バイトデータを取得する.
+ * @brief Get byte data.
* @return byte array data.
*/
ByteData GetData() const;
/**
- * @brief HEX文字列を取得する.
+ * @brief Get the HEX string.
* @return hex string (reverse data)
*/
std::string GetHex() const;
/**
- * @brief blind有無を取得する.
+ * @brief Get if it is blind.
* @retval true blind
* @retval false unblind
*/
bool HasBlinding() const;
/**
- * @brief unblind時、バイトデータを取得する.
+ * @brief Get unblinded byte data.
* @return byte array data.
*/
ByteData GetUnblindedData() const;
/**
- * @brief 空かどうかを取得する.
+ * @brief Get if it's empty.
* @retval true empty
* @retval false exist value
*/
@@ -170,76 +188,85 @@ class CFD_CORE_EXPORT ConfidentialAssetId {
};
/**
- * @brief value情報を保持するクラス
+ * @brief Class that holds value information
*/
class CFD_CORE_EXPORT ConfidentialValue {
public:
/**
- * @brief コンストラクタ.
- *
- * リスト定義等における初期化のため、定義する。
+ * @brief constructor.
*/
ConfidentialValue();
/**
- * @brief コンストラクタ.
+ * @brief constructor.
* @param[in] hex_string hex string.
*/
explicit ConfidentialValue(const std::string& hex_string);
/**
- * @brief コンストラクタ.
+ * @brief constructor.
* @param[in] byte_data byte array data.
*/
explicit ConfidentialValue(const ByteData& byte_data);
/**
- * @brief コンストラクタ.
+ * @brief constructor.
* @param[in] amount amount
*/
explicit ConfidentialValue(const Amount& amount);
/**
- * @brief デストラクタ.
+ * @brief destructor.
*/
virtual ~ConfidentialValue() {
// do nothing
}
+ /**
+ * @brief copy constructor.
+ * @param[in] object object
+ */
+ ConfidentialValue(const ConfidentialValue& object);
+ /**
+ * @brief copy constructor.
+ * @param[in] object object
+ * @return object
+ */
+ ConfidentialValue& operator=(const ConfidentialValue& object);
/**
- * @brief バイトデータを取得する.
+ * @brief Get byte data.
* @return byte array data.
*/
ByteData GetData() const;
/**
- * @brief HEX文字列を取得する.
+ * @brief Get the HEX string.
* @return hex string
*/
std::string GetHex() const;
/**
- * @brief Amountを取得する.
+ * @brief Get Amount.
*
- * なおblind状態では0を返却する。
+ * In the blind state, 0 is returned.
* @return Amount
*/
Amount GetAmount() const;
/**
- * @brief blind有無を取得する.
+ * @brief Get if it is blind.
* @retval true blind
* @retval false unblind
*/
bool HasBlinding() const;
/**
- * @brief 空かどうかを取得する.
+ * @brief Get if it's empty.
* @retval true empty
* @retval false exist value
*/
bool IsEmpty() const;
/**
- * @brief satoshiをConfidentialValueへと変換する.
+ * @brief Convert satoshi to Confidential Value.
* @param[in] value amount value.
* @return ConfidentialValue
*/
static ByteData ConvertToConfidentialValue(const Amount& value);
/**
- * @brief ConfidentialValueをsatoshiへと変換する.
+ * @brief Convert Confidential Value to satoshi.
* @param[in] value ConfidentialValue.
* @return amount value
*/
@@ -268,50 +295,59 @@ class CFD_CORE_EXPORT ConfidentialValue {
};
/**
- * @brief factor情報を保持するクラス
+ * @brief Class that holds blind factor information
*/
class CFD_CORE_EXPORT BlindFactor {
public:
/**
- * @brief コンストラクタ.
- *
- * リスト定義等における初期化のため、定義する。
+ * @brief constructor.
*/
BlindFactor();
/**
- * @brief コンストラクタ.
+ * @brief constructor.
* @param[in] hex_string hex string.
*/
explicit BlindFactor(const std::string& hex_string);
/**
- * @brief コンストラクタ.
+ * @brief constructor.
* @param[in] byte_data byte array data.
*/
explicit BlindFactor(const ByteData& byte_data);
/**
- * @brief コンストラクタ.
+ * @brief constructor.
* @param[in] byte_data byte array data.
*/
explicit BlindFactor(const ByteData256& byte_data);
/**
- * @brief デストラクタ.
+ * @brief destructor.
*/
virtual ~BlindFactor() {
// do nothing
}
+ /**
+ * @brief copy constructor.
+ * @param[in] object object
+ */
+ BlindFactor(const BlindFactor& object);
+ /**
+ * @brief copy constructor.
+ * @param[in] object object
+ * @return object
+ */
+ BlindFactor& operator=(const BlindFactor& object);
/**
- * @brief バイトデータを取得する.
+ * @brief Get byte data.
* @return byte array data.
*/
ByteData256 GetData() const;
/**
- * @brief HEX文字列を取得する.
+ * @brief Get the HEX string.
* @return hex string (reverse data)
*/
std::string GetHex() const;
/**
- * @brief 空かどうかを取得する.
+ * @brief Get if it's empty.
* @retval true empty
* @retval false exist value
*/
@@ -322,7 +358,7 @@ class CFD_CORE_EXPORT BlindFactor {
};
/**
- * @brief TxIn情報を保持するクラス
+ * @brief Class that holds TxIn information
*/
class CFD_CORE_EXPORT ConfidentialTxIn : public AbstractTxIn {
public:
@@ -383,37 +419,37 @@ class CFD_CORE_EXPORT ConfidentialTxIn : public AbstractTxIn {
uint32_t* rangeproof_size = nullptr);
/**
- * @brief コンストラクタ.
+ * @brief constructor.
*/
ConfidentialTxIn();
/**
- * @brief コンストラクタ.
+ * @brief constructor.
* @param[in] txid txid
- * @param[in] index txidのトランザクションのTxOutのIndex情報(vout)
+ * @param[in] index txout's index (vout)
*/
ConfidentialTxIn(const Txid& txid, uint32_t index);
/**
- * @brief コンストラクタ.
+ * @brief constructor.
* @param[in] txid txid
- * @param[in] index txidのトランザクションのTxOutのIndex情報(vout)
- * @param[in] sequence sequence情報
+ * @param[in] index txout's index (vout)
+ * @param[in] sequence sequence
*/
ConfidentialTxIn(const Txid& txid, uint32_t index, uint32_t sequence);
/**
- * @brief コンストラクタ.
+ * @brief constructor.
* @param[in] txid txid
- * @param[in] index txidのトランザクションのTxOutのIndex情報(vout)
- * @param[in] sequence sequence情報
+ * @param[in] index txout's index (vout)
+ * @param[in] sequence sequence
* @param[in] unlocking_script unlocking script
*/
ConfidentialTxIn(
const Txid& txid, uint32_t index, uint32_t sequence,
const Script& unlocking_script);
/**
- * @brief コンストラクタ.
+ * @brief constructor.
* @param[in] txid txid
- * @param[in] index txidのトランザクションのTxOutのIndex情報(vout)
- * @param[in] sequence sequence情報
+ * @param[in] index txout's index (vout)
+ * @param[in] sequence sequence
* @param[in] unlocking_script unlocking script
* @param[in] witness_stack witness stack
* @param[in] blinding_nonce blinding nonce
@@ -434,14 +470,14 @@ class CFD_CORE_EXPORT ConfidentialTxIn : public AbstractTxIn {
const ByteData& inflation_keys_rangeproof,
const ScriptWitness& pegin_witness);
/**
- * @brief デストラクタ
+ * @brief destructor
*/
virtual ~ConfidentialTxIn() {
// do nothing
}
/**
- * @brief 情報を更新する.
+ * @brief Update issuance information.
* @param[in] blinding_nonce blinding nonce
* @param[in] asset_entropy asset entropy
* @param[in] issuance_amount issuance amount
@@ -456,72 +492,72 @@ class CFD_CORE_EXPORT ConfidentialTxIn : public AbstractTxIn {
const ByteData& issuance_amount_rangeproof,
const ByteData& inflation_keys_rangeproof);
/**
- * @brief BlindingNonceを取得する
- * @return BlindingNonceのByteData256インスタンス
+ * @brief Get Blinding Nonce
+ * @return BlindingNonce
*/
ByteData256 GetBlindingNonce() const { return blinding_nonce_; }
/**
- * @brief AssetEntropyを取得する
- * @return AssetEntropyのByteData256インスタンス
+ * @brief Get Asset Entropy
+ * @return AssetEntropy
*/
ByteData256 GetAssetEntropy() const { return asset_entropy_; }
/**
- * @brief IssuanceAmountを取得する
- * @return IssuanceAmountのByteDataインスタンス
+ * @brief Get IssuanceAmount
+ * @return IssuanceAmount
*/
ConfidentialValue GetIssuanceAmount() const { return issuance_amount_; }
/**
- * @brief InflationKeysを取得する
- * @return InflationKeysのByteDataインスタンス
+ * @brief Get InflationKeys
+ * @return InflationKeys
*/
ConfidentialValue GetInflationKeys() const { return inflation_keys_; }
/**
- * @brief IssuanceAmountRangeproofを取得する
- * @return IssuanceAmountRangeproofのByteDataインスタンス
+ * @brief Get IssuanceAmountRangeproof
+ * @return IssuanceAmountRangeproof
*/
ByteData GetIssuanceAmountRangeproof() const {
return issuance_amount_rangeproof_;
}
/**
- * @brief InflationKeysRangeproofを取得する
- * @return InflationKeysRangeproofのByteDataインスタンス
+ * @brief Get InflationKeysRangeproof
+ * @return InflationKeysRangeproof
*/
ByteData GetInflationKeysRangeproof() const {
return inflation_keys_rangeproof_;
}
/**
- * @brief PeginWitnessを取得する
- * @return PeginWitnessのScriptWitnessインスタンス
+ * @brief Get PeginWitness
+ * @return PeginWitness's 'ScriptWitness
*/
ScriptWitness GetPeginWitness() const { return pegin_witness_; }
/**
- * @brief pegin witnessの現在のstack数を取得する.
- * @return pegin witnessのstack数
+ * @brief Get the current stack count of pegin witness.
+ * @return stack count of pegin witness.
*/
uint32_t GetPeginWitnessStackNum() const {
return pegin_witness_.GetWitnessNum();
}
/**
- * @brief pegin witnessにバイトデータを追加する.
- * @param[in] data witness stack情報
- * @return pegin witnessのScriptWitnessインスタンス
+ * @brief Add byte data to pegin witness.
+ * @param[in] data witness stack data
+ * @return Script Witness instance of pegin witness
*/
ScriptWitness AddPeginWitnessStack(const ByteData& data);
/**
- * @brief pegin witnessにバイトデータを設定する.
- * @param[in] index witness stackのindex値
- * @param[in] data witness stack情報
- * @return pegin witnessのScriptWitnessインスタンス
+ * @brief Set byte data to pegin witness.
+ * @param[in] index witness stack index
+ * @param[in] data witness stack data
+ * @return Script Witness instance of pegin witness
*/
ScriptWitness SetPeginWitnessStack(uint32_t index, const ByteData& data);
/**
- * @brief pegin witnessを全て削除する.
+ * @brief Remove all pegin witness.
*/
void RemovePeginWitnessStackAll();
/**
- * @brief witness hashを取得する.
+ * @brief Get the witness hash.
* @return witness hash
*/
ByteData256 GetWitnessHash() const;
@@ -537,72 +573,70 @@ class CFD_CORE_EXPORT ConfidentialTxIn : public AbstractTxIn {
};
/**
- * @brief TxIn情報を参照するためのクラス
+ * @brief Class for referencing TxIn information
*/
class CFD_CORE_EXPORT ConfidentialTxInReference
: public AbstractTxInReference {
public:
/**
- * @brief コンストラクタ.
- * @param[in] tx_in 参照するTxInインスタンス
+ * @brief constructor.
+ * @param[in] tx_in TxIn
*/
explicit ConfidentialTxInReference(const ConfidentialTxIn& tx_in);
/**
- * @brief デフォルトコンストラクタ.
- *
- * リスト作成用。
+ * @brief default constructor.
*/
ConfidentialTxInReference();
/**
- * @brief デストラクタ
+ * @brief destructor
*/
virtual ~ConfidentialTxInReference() {
// do nothing
}
/**
- * @brief BlindingNonceを取得する
- * @return BlindingNonceのByteData256インスタンス
+ * @brief Get Blinding Nonce
+ * @return BlindingNonce
*/
ByteData256 GetBlindingNonce() const { return blinding_nonce_; }
/**
- * @brief AssetEntropyを取得する
- * @return AssetEntropyのByteData256インスタンス
+ * @brief Get AssetEntropy
+ * @return AssetEntropy
*/
ByteData256 GetAssetEntropy() const { return asset_entropy_; }
/**
- * @brief IssuanceAmountを取得する
- * @return IssuanceAmountのByteDataインスタンス
+ * @brief Get IssuanceAmount
+ * @return IssuanceAmount
*/
ConfidentialValue GetIssuanceAmount() const { return issuance_amount_; }
/**
- * @brief InflationKeysを取得する
- * @return InflationKeysのByteDataインスタンス
+ * @brief Get InflationKeys
+ * @return InflationKeys
*/
ConfidentialValue GetInflationKeys() const { return inflation_keys_; }
/**
- * @brief IssuanceAmountRangeproofを取得する
- * @return IssuanceAmountRangeproofのByteDataインスタンス
+ * @brief Get IssuanceAmountRangeproof
+ * @return IssuanceAmountRangeproof
*/
ByteData GetIssuanceAmountRangeproof() const {
return issuance_amount_rangeproof_;
}
/**
- * @brief InflationKeysRangeproofを取得する
- * @return InflationKeysRangeproofのByteDataインスタンス
+ * @brief Get InflationKeysRangeproof
+ * @return InflationKeysRangeproof
*/
ByteData GetInflationKeysRangeproof() const {
return inflation_keys_rangeproof_;
}
/**
- * @brief PeginWitnessを取得する
- * @return PeginWitnessのScriptWitnessインスタンス
+ * @brief Get PeginWitness
+ * @return ScriptWitness instance of PeginWitness
*/
ScriptWitness GetPeginWitness() const { return pegin_witness_; }
/**
- * @brief pegin witnessの現在のstack数を取得する.
- * @return pegin witnessのstack数
+ * @brief Get the current stack count of pegin witness.
+ * @return stack count of pegin witness.
*/
uint32_t GetPeginWitnessStackNum() const {
return pegin_witness_.GetWitnessNum();
@@ -674,16 +708,16 @@ struct RangeProofInfo {
};
/**
- * @brief Confidential TransactionのTxOut情報を保持するクラス
+ * @brief Class that holds TxOut information of Confidential Transaction
*/
class CFD_CORE_EXPORT ConfidentialTxOut : public AbstractTxOut {
public:
/**
- * @brief コンストラクタ
+ * @brief constructor
*/
ConfidentialTxOut();
/**
- * @brief コンストラクタ.
+ * @brief constructor.
* @param[in] locking_script locking script.
* @param[in] asset asset.
* @param[in] confidential_value value by confidential transaction.
@@ -692,9 +726,9 @@ class CFD_CORE_EXPORT ConfidentialTxOut : public AbstractTxOut {
const Script& locking_script, const ConfidentialAssetId& asset,
const ConfidentialValue& confidential_value);
/**
- * @brief コンストラクタ.
+ * @brief constructor.
*
- * blind後の情報登録用.
+ * For information registration after blind.
* @param[in] locking_script locking script.
* @param[in] asset asset.
* @param[in] confidential_value value by confidential transaction.
@@ -708,9 +742,9 @@ class CFD_CORE_EXPORT ConfidentialTxOut : public AbstractTxOut {
const ConfidentialNonce& nonce, const ByteData& surjection_proof,
const ByteData& range_proof);
/**
- * @brief コンストラクタ.
+ * @brief constructor.
*
- * fee追加用.
+ * For additional fee.
* @param[in] asset asset.
* @param[in] confidential_value value by confidential transaction.
*/
@@ -718,15 +752,15 @@ class CFD_CORE_EXPORT ConfidentialTxOut : public AbstractTxOut {
const ConfidentialAssetId& asset,
const ConfidentialValue& confidential_value);
/**
- * @brief コンストラクタ.
+ * @brief constructor.
*
- * fee追加用.
+ * For additional fee.
* @param[in] asset asset.
* @param[in] amount amount.
*/
ConfidentialTxOut(const ConfidentialAssetId& asset, const Amount& amount);
/**
- * @brief コンストラクタ.
+ * @brief constructor.
* @param[in] address address.
* @param[in] asset asset.
* @param[in] amount amount.
@@ -735,7 +769,7 @@ class CFD_CORE_EXPORT ConfidentialTxOut : public AbstractTxOut {
const Address& address, const ConfidentialAssetId& asset,
const Amount& amount);
/**
- * @brief コンストラクタ.
+ * @brief constructor.
* @param[in] confidential_address confidential address.
* @param[in] asset asset.
* @param[in] amount amount.
@@ -744,7 +778,7 @@ class CFD_CORE_EXPORT ConfidentialTxOut : public AbstractTxOut {
const ElementsConfidentialAddress& confidential_address,
const ConfidentialAssetId& asset, const Amount& amount);
/**
- * @brief デストラクタ
+ * @brief destructor
*/
virtual ~ConfidentialTxOut() {
// do nothing
@@ -772,18 +806,18 @@ class CFD_CORE_EXPORT ConfidentialTxOut : public AbstractTxOut {
*/
void SetNonce(const ConfidentialNonce& nonce);
/**
- * @brief valueを設定する。
+ * @brief set amount value.
* @param[in] value amount value.
*/
virtual void SetValue(const Amount& value);
/**
- * @brief assetを取得する。
+ * @brief set asset.
* @return asset
*/
ConfidentialAssetId GetAsset() const { return asset_; }
/**
- * @brief confidential valueを取得する。
+ * @brief Get confidential value.
* @return confidential value
*/
ConfidentialValue GetConfidentialValue() const {
@@ -791,25 +825,25 @@ class CFD_CORE_EXPORT ConfidentialTxOut : public AbstractTxOut {
}
/**
- * @brief nonceを取得する。
+ * @brief Get nonce
* @return nonce
*/
ConfidentialNonce GetNonce() const { return nonce_; }
/**
- * @brief surjection proofを取得する。
+ * @brief Get surjection proof
* @return surjection proof
*/
ByteData GetSurjectionProof() const { return surjection_proof_; }
/**
- * @brief range proofを取得する。
+ * @brief Get range proof
* @return range proof
*/
ByteData GetRangeProof() const { return range_proof_; }
/**
- * @brief witness hashを取得する.
+ * @brief Get witness hash
* @return witness hash
*/
ByteData256 GetWitnessHash() const;
@@ -840,40 +874,38 @@ class CFD_CORE_EXPORT ConfidentialTxOut : public AbstractTxOut {
};
/**
- * @brief Confidential TransactionのTxOut情報を参照するためのクラス
+ * @brief Class for referencing TxOut information of Confidential Transaction
*/
class CFD_CORE_EXPORT ConfidentialTxOutReference
: public AbstractTxOutReference {
public:
/**
- * @brief コンストラクタ
+ * @brief constructor
* @param[in] tx_out Confidential Transaction's TxOut.
*/
explicit ConfidentialTxOutReference(const ConfidentialTxOut& tx_out);
/**
- * @brief デフォルトコンストラクタ.
- *
- * リスト作成用。
+ * @brief default constructor.
*/
ConfidentialTxOutReference()
: ConfidentialTxOutReference(ConfidentialTxOut()) {
// do nothing
}
/**
- * @brief デストラクタ
+ * @brief destructor
*/
virtual ~ConfidentialTxOutReference() {
// do nothing
}
/**
- * @brief assetを取得する。
+ * @brief Get asset
* @return asset
*/
ConfidentialAssetId GetAsset() const { return asset_; }
/**
- * @brief confidential valueを取得する。
+ * @brief Get confidential value
* @return confidential value
*/
ConfidentialValue GetConfidentialValue() const {
@@ -881,19 +913,19 @@ class CFD_CORE_EXPORT ConfidentialTxOutReference
}
/**
- * @brief nonceを取得する。
+ * @brief Get nonce
* @return nonce
*/
ConfidentialNonce GetNonce() const { return nonce_; }
/**
- * @brief surjection proofを取得する。
+ * @brief Get surjection proof
* @return surjection proof
*/
ByteData GetSurjectionProof() const { return surjection_proof_; }
/**
- * @brief range proofを取得する。
+ * @brief Get range proof
* @return range proof
*/
ByteData GetRangeProof() const { return range_proof_; }
@@ -945,7 +977,7 @@ class CFD_CORE_EXPORT ConfidentialTxOutReference
};
/**
- * @brief Issuance出力情報構造体
+ * @brief Issuance output information structure
*/
struct IssuanceParameter {
BlindFactor entropy; //!< entropy
@@ -954,7 +986,7 @@ struct IssuanceParameter {
};
/**
- * @brief Unblind出力情報構造体
+ * @brief Unblind output information structure
*/
struct UnblindParameter {
ConfidentialAssetId asset; //!< confidential asset
@@ -964,7 +996,7 @@ struct UnblindParameter {
};
/**
- * @brief Blind用情報構造体
+ * @brief Information structure for Blind
*/
using BlindParameter = UnblindParameter;
@@ -983,7 +1015,7 @@ struct BlindData {
};
/**
- * @brief Issuance confidentialKeyペア構造体
+ * @brief Issuance confidentialKey pair structure
*/
struct IssuanceBlindingKeyPair {
Privkey asset_key; //!< asset blinding key
@@ -991,7 +1023,7 @@ struct IssuanceBlindingKeyPair {
};
/**
- * @brief PegOut Key情報構造体
+ * @brief PegOut Key Information Structure
*/
struct PegoutKeyData {
Pubkey btc_pubkey_bytes; //!< bitcoin pubkey byte data
@@ -999,28 +1031,26 @@ struct PegoutKeyData {
};
/**
- * @brief Confidential Transaction情報クラス
+ * @brief Confidential Transaction information class
*/
class CFD_CORE_EXPORT ConfidentialTransaction : public AbstractTransaction {
public:
- /// ElementsTransactionの最小サイズ
+ /// Minimum size of Elements Transaction
static constexpr size_t kElementsTransactionMinimumSize = 11;
/**
- * @brief コンストラクタ.
- *
- * リスト作成用。
+ * @brief constructor.
*/
ConfidentialTransaction();
/**
- * @brief コンストラクタ
+ * @brief constructor
* @param[in] version version
* @param[in] lock_time lock time
*/
explicit ConfidentialTransaction(int32_t version, uint32_t lock_time);
/**
- * @brief コンストラクタ
- * @param[in] hex_string txバイトデータのHEX文字列
+ * @brief constructor
+ * @param[in] hex_string tx hex string
*/
explicit ConfidentialTransaction(const std::string& hex_string);
/**
@@ -1029,155 +1059,155 @@ class CFD_CORE_EXPORT ConfidentialTransaction : public AbstractTransaction {
*/
explicit ConfidentialTransaction(const ByteData& byte_data);
/**
- * @brief コンストラクタ
- * @param[in] transaction トランザクション情報
+ * @brief copy constructor
+ * @param[in] transaction transaction object
*/
explicit ConfidentialTransaction(const ConfidentialTransaction& transaction);
/**
- * @brief デストラクタ
+ * @brief destructor
*/
virtual ~ConfidentialTransaction() {
// do nothing
}
/**
- * @brief コピーコンストラクタ.
- * @param[in] transaction トランザクション情報
- * @return Confidential Transactionオブジェクト
+ * @brief copy constructor.
+ * @param[in] transaction transaction object
+ * @return Confidential Transaction
*/
ConfidentialTransaction& operator=(
const ConfidentialTransaction& transaction) &;
/**
- * @brief TxInを取得する.
- * @param[in] index 取得するindex位置
- * @return 指定indexのTxInインスタンス
+ * @brief Get TxIn.
+ * @param[in] index index
+ * @return ConfidentialTxInReference
*/
const ConfidentialTxInReference GetTxIn(uint32_t index) const;
/**
- * @brief TxInのindexを取得する.
- * @param[in] txid 取得するTxInのtxid
- * @param[in] vout 取得するTxInのvout
- * @return 条件に合致するTxInのindex番号
+ * @brief Get TxIn index.
+ * @param[in] txid txid
+ * @param[in] vout vout
+ * @return index
*/
virtual uint32_t GetTxInIndex(const Txid& txid, uint32_t vout) const;
/**
- * @brief TxOutのindexを取得する.
+ * @brief Get the index of TxOut.
* @param[in] locking_script locking script
- * @return 条件に合致するTxOutのindex番号
+ * @return TxOut index
*/
virtual uint32_t GetTxOutIndex(const Script& locking_script) const;
/**
- * @brief TxOutのindexを一括取得する.
+ * @brief Get the indexes of TxOut.
* @param[in] locking_script locking script
- * @return 条件に合致するTxOutのindex番号の一覧
+ * @return TxOut index list.
*/
virtual std::vector GetTxOutIndexList(
const Script& locking_script) const;
/**
- * @brief 保持しているTxInの数を取得する.
- * @return TxIn数
+ * @brief Get the count of TxIns.
+ * @return count of TxIns.
*/
uint32_t GetTxInCount() const;
/**
- * @brief TxIn一覧を取得する.
- * @return TxInReference一覧
+ * @brief Get TxIn list.
+ * @return TxInReference list
*/
const std::vector GetTxInList() const;
/**
- * @brief TxInを追加する.
+ * @brief Add TxIn.
* @param[in] txid txid
* @param[in] index vout
* @param[in] sequence sequence
- * @param[in] unlocking_script unlocking script (未指定時はEmptyを設定する. default Script::Empty)
- * @return 追加したTxInのindex位置
+ * @param[in] unlocking_script unlocking script
+ * @return Added TxIn index
*/
uint32_t AddTxIn(
const Txid& txid, uint32_t index, uint32_t sequence,
const Script& unlocking_script = Script::Empty);
/**
- * @brief TxIn情報を削除する.
- * @param[in] index 削除するindex位置
+ * @brief Delete TxIn
+ * @param[in] index txin index
*/
void RemoveTxIn(uint32_t index);
/**
- * @brief unlocking scriptを設定する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @param[in] unlocking_script TxInに設定するunlocking script (Push Op Only)
+ * @brief Set unlocking script.
+ * @param[in] tx_in_index TxIn index
+ * @param[in] unlocking_script unlocking script (Push Op Only)
*/
void SetUnlockingScript(
uint32_t tx_in_index, const Script& unlocking_script);
/**
- * @brief unlocking scriptを設定する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @param[in] unlocking_script TxInに設定するunlocking scriptの構成要素リスト
+ * @brief Set unlocking script.
+ * @param[in] tx_in_index TxIn index
+ * @param[in] unlocking_script Unlocking script component list
*/
void SetUnlockingScript(
uint32_t tx_in_index, const std::vector& unlocking_script);
/**
- * @brief witness stackの現在の個数を取得する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @return witness stackの個数
+ * @brief Get the count of witness stacks.
+ * @param[in] tx_in_index TxIn index
+ * @return count of witness stacks.
*/
uint32_t GetScriptWitnessStackNum(uint32_t tx_in_index) const;
/**
- * @brief witness stackに追加する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @param[in] data witness stackに追加する情報
+ * @brief Add to witness stack.
+ * @param[in] tx_in_index TxIn index
+ * @param[in] data Information to add to the witness stack
* @return witness stack
*/
const ScriptWitness AddScriptWitnessStack(
uint32_t tx_in_index, const ByteData& data);
/**
- * @brief witness stackに追加する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @param[in] data witness stackに追加する20byte情報
+ * @brief Add to witness stack.
+ * @param[in] tx_in_index TxIn index
+ * @param[in] data Information to add to the witness stack
* @return witness stack
*/
const ScriptWitness AddScriptWitnessStack(
uint32_t tx_in_index, const ByteData160& data);
/**
- * @brief witness stackに追加する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @param[in] data witness stackに追加する32byte情報
+ * @brief Add to witness stack.
+ * @param[in] tx_in_index TxIn index
+ * @param[in] data Information to add to the witness stack
* @return witness stack
*/
const ScriptWitness AddScriptWitnessStack(
uint32_t tx_in_index, const ByteData256& data);
/**
- * @brief witness stackの指定index位置を更新する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @param[in] witness_index witness stackのindex位置
- * @param[in] data witness stackに追加する情報
+ * @brief Update the specified index position of the witness stack.
+ * @param[in] tx_in_index TxIn index
+ * @param[in] witness_index witness stack index
+ * @param[in] data Information to add to the witness stack
* @return witness stack
*/
const ScriptWitness SetScriptWitnessStack(
uint32_t tx_in_index, uint32_t witness_index, const ByteData& data);
/**
- * @brief witness stackの指定index位置を更新する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @param[in] witness_index witness stackのindex位置
- * @param[in] data witness stackに追加する20byte情報
+ * @brief Update the specified index position of the witness stack.
+ * @param[in] tx_in_index TxIn index
+ * @param[in] witness_index witness stack index
+ * @param[in] data Information to add to the witness stack
* @return witness stack
*/
const ScriptWitness SetScriptWitnessStack(
uint32_t tx_in_index, uint32_t witness_index, const ByteData160& data);
/**
- * @brief witness stackの指定index位置を更新する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @param[in] witness_index witness stackのindex位置
- * @param[in] data witness stackに追加する32byte情報
+ * @brief Update the specified index position of the witness stack.
+ * @param[in] tx_in_index TxIn index
+ * @param[in] witness_index witness stack index
+ * @param[in] data Information to add to the witness stack
* @return witness stack
*/
const ScriptWitness SetScriptWitnessStack(
uint32_t tx_in_index, uint32_t witness_index, const ByteData256& data);
/**
- * @brief script witnessを全て削除する.
- * @param[in] tx_in_index 設定するTxInのindex位置
+ * @brief Remove all script witness.
+ * @param[in] tx_in_index TxIn index
*/
void RemoveScriptWitnessStackAll(uint32_t tx_in_index);
/**
* @brief 情報を更新する.
- * @param[in] tx_in_index 設定するTxInのindex位置
+ * @param[in] tx_in_index TxIn index
* @param[in] blinding_nonce blinding nonce
* @param[in] asset_entropy asset entropy
* @param[in] issuance_amount issuance amount
@@ -1193,69 +1223,69 @@ class CFD_CORE_EXPORT ConfidentialTransaction : public AbstractTransaction {
const ByteData inflation_keys_rangeproof);
/**
* @brief witness stackの現在の個数を取得する.
- * @param[in] tx_in_index 設定するTxInのindex位置
+ * @param[in] tx_in_index TxIn index
* @return witness stackの個数
*/
uint32_t GetPeginWitnessStackNum(uint32_t tx_in_index) const;
/**
- * @brief witness stackに追加する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @param[in] data witness stackに追加する情報
+ * @brief Add to witness stack.
+ * @param[in] tx_in_index TxIn index
+ * @param[in] data Information to add to the witness stack
* @return witness stack
*/
const ScriptWitness AddPeginWitnessStack(
uint32_t tx_in_index, const ByteData& data);
/**
- * @brief witness stackに追加する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @param[in] data witness stackに追加する20byte情報
+ * @brief Add to witness stack.
+ * @param[in] tx_in_index TxIn index
+ * @param[in] data Information to add to the witness stack
* @return witness stack
*/
const ScriptWitness AddPeginWitnessStack(
uint32_t tx_in_index, const ByteData160& data);
/**
- * @brief witness stackに追加する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @param[in] data witness stackに追加する32byte情報
+ * @brief Add to witness stack.
+ * @param[in] tx_in_index TxIn index
+ * @param[in] data Information to add to the witness stack
* @return witness stack
*/
const ScriptWitness AddPeginWitnessStack(
uint32_t tx_in_index, const ByteData256& data);
/**
- * @brief witness stackの指定index位置を更新する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @param[in] witness_index witness stackのindex位置
- * @param[in] data witness stackに追加する情報
+ * @brief Update the specified index position of the witness stack.
+ * @param[in] tx_in_index TxIn index
+ * @param[in] witness_index witness stack index
+ * @param[in] data Information to add to the witness stack
* @return witness stack
*/
const ScriptWitness SetPeginWitnessStack(
uint32_t tx_in_index, uint32_t witness_index, const ByteData& data);
/**
- * @brief witness stackの指定index位置を更新する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @param[in] witness_index witness stackのindex位置
- * @param[in] data witness stackに追加する20byte情報
+ * @brief Update the specified index position of the witness stack.
+ * @param[in] tx_in_index TxIn index
+ * @param[in] witness_index witness stack index
+ * @param[in] data Information to add to the witness stack
* @return witness stack
*/
const ScriptWitness SetPeginWitnessStack(
uint32_t tx_in_index, uint32_t witness_index, const ByteData160& data);
/**
- * @brief witness stackの指定index位置を更新する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @param[in] witness_index witness stackのindex位置
- * @param[in] data witness stackに追加する32byte情報
+ * @brief Update the specified index position of the witness stack.
+ * @param[in] tx_in_index TxIn index
+ * @param[in] witness_index witness stack index
+ * @param[in] data Information to add to the witness stack
* @return witness stack
*/
const ScriptWitness SetPeginWitnessStack(
uint32_t tx_in_index, uint32_t witness_index, const ByteData256& data);
/**
- * @brief script witnessを全て削除する.
- * @param[in] tx_in_index 設定するTxInのindex位置
+ * @brief Remove all script witness.
+ * @param[in] tx_in_index TxIn index
*/
void RemovePeginWitnessStackAll(uint32_t tx_in_index);
/**
- * @brief IssueAssetの情報を設定する.
+ * @brief Set the Issue Asset information.
* @param[in] tx_in_index Txin index
* @param[in] asset_amount issuance amount
* @param[in] asset_locking_script asset locking script
@@ -1274,7 +1304,7 @@ class CFD_CORE_EXPORT ConfidentialTransaction : public AbstractTransaction {
const ConfidentialNonce& token_nonce, bool is_blind,
const ByteData256& contract_hash);
/**
- * @brief IssueAssetの情報を設定する.
+ * @brief Set the Issue Asset information.
* @param[in] tx_in_index Txin index
* @param[in] asset_amount issuance amount
* @param[in] asset_output_amount_list asset output list
@@ -1300,7 +1330,7 @@ class CFD_CORE_EXPORT ConfidentialTransaction : public AbstractTransaction {
const ByteData256& contract_hash);
/**
- * @brief ReissueAssetの情報を設定する.
+ * @brief ReSet the Issue Asset information.
* @param[in] tx_in_index Txin index
* @param[in] asset_amount reissuance amount
* @param[in] asset_locking_script asset locking script
@@ -1315,7 +1345,7 @@ class CFD_CORE_EXPORT ConfidentialTransaction : public AbstractTransaction {
const ConfidentialNonce& asset_blind_nonce,
const BlindFactor& asset_blind_factor, const BlindFactor& entropy);
/**
- * @brief ReissueAssetの情報を設定する.
+ * @brief ReSet the Issue Asset information.
* @param[in] tx_in_index Txin index
* @param[in] asset_amount reissuance amount
* @param[in] asset_output_amount_list asset output list
@@ -1333,61 +1363,61 @@ class CFD_CORE_EXPORT ConfidentialTransaction : public AbstractTransaction {
const BlindFactor& asset_blind_factor, const BlindFactor& entropy);
/**
- * @brief TxOutを取得する.
- * @param[in] index 取得するindex位置
- * @return TxOutReference
+ * @brief Get TxOut.
+ * @param[in] index index
+ * @return ConfidentialTxOutReference
*/
const ConfidentialTxOutReference GetTxOut(uint32_t index) const;
/**
- * @brief 保持しているTxOutの数を取得する.
- * @return TxOut数
+ * @brief Get the count of TxOuts.
+ * @return count of TxOuts.
*/
uint32_t GetTxOutCount() const;
/**
- * @brief TxOut一覧を取得する.
- * @return TxOutReference一覧
+ * @brief Get TxOut list.
+ * @return ConfidentialTxOutReference list
*/
const std::vector GetTxOutList() const;
/**
- * @brief TxOut情報を追加する.
+ * @brief Add TxOut information.
* @param[in] value amount
* @param[in] asset asset
* @param[in] locking_script locking script
- * @return 追加したTxOutのindex位置
+ * @return Added TxOut index
*/
uint32_t AddTxOut(
const Amount& value, const ConfidentialAssetId& asset,
const Script& locking_script);
/**
- * @brief TxOut情報を追加する.
+ * @brief Add TxOut information.
* @param[in] value amount
* @param[in] asset asset
* @param[in] locking_script locking script
* @param[in] nonce nonce
- * @return 追加したTxOutのindex位置
+ * @return Added TxOut index
*/
uint32_t AddTxOut(
const Amount& value, const ConfidentialAssetId& asset,
const Script& locking_script, const ConfidentialNonce& nonce);
/**
- * @brief TxOut情報を追加する.
+ * @brief Add TxOut information.
* @param[in] value amount
* @param[in] asset asset
* @param[in] locking_script locking script
* @param[in] nonce nonce.
* @param[in] surjection_proof surjection proof.
* @param[in] range_proof range proof.
- * @return 追加したTxOutのindex位置
+ * @return Added TxOut index
*/
uint32_t AddTxOut(
const Amount& value, const ConfidentialAssetId& asset,
const Script& locking_script, const ConfidentialNonce& nonce,
const ByteData& surjection_proof, const ByteData& range_proof);
/**
- * @brief TxOut情報としてfeeを追加する.
+ * @brief Add fee as TxOut information.
* @param[in] value amount
* @param[in] asset asset
- * @return 追加したTxOutのindex位置
+ * @return Added TxOut index
*/
uint32_t AddTxOutFee(const Amount& value, const ConfidentialAssetId& asset);
/**
@@ -1397,8 +1427,8 @@ class CFD_CORE_EXPORT ConfidentialTransaction : public AbstractTransaction {
*/
void SetTxOutValue(uint32_t index, const Amount& value);
/**
- * @brief TxOut情報を更新する.
- * @param[in] index index位置
+ * @brief Update TxOut information.
+ * @param[in] index index
* @param[in] asset asset
* @param[in] value amount
* @param[in] nonce nonce.
@@ -1410,10 +1440,27 @@ class CFD_CORE_EXPORT ConfidentialTransaction : public AbstractTransaction {
const ConfidentialValue& value, const ConfidentialNonce& nonce,
const ByteData& surjection_proof, const ByteData& range_proof);
/**
- * @brief TxOut情報を削除する.
- * @param[in] index 取得するindex位置
+ * @brief Delete the TxOut information.
+ * @param[in] index index
*/
void RemoveTxOut(uint32_t index);
+
+ /**
+ * @brief Get the total byte size of Transaction.
+ * @return Total byte size
+ */
+ virtual uint32_t GetTotalSize() const;
+ /**
+ * @brief Get vsize information of Transaction.
+ * @return vsize
+ */
+ virtual uint32_t GetVsize() const;
+ /**
+ * @brief Get the Weight information of Transaction.
+ * @return weight
+ */
+ virtual uint32_t GetWeight() const;
+
/**
* @brief Blinding transaction.
* @param[in] txin_info_list txin blind info list.
@@ -1435,7 +1482,7 @@ class CFD_CORE_EXPORT ConfidentialTransaction : public AbstractTransaction {
int minimum_bits = kDefaultBlindMinimumBits,
std::vector* blinder_list = nullptr);
/**
- * @brief TransactionのTxOutのblindingを行う.
+ * @brief Blinding TxOut of Transaction.
* @param[in] txin_info_list txin blind info list.
* @param[in] txout_confidential_keys blinding pubkey list.
* @param[in] minimum_range_value rangeproof minimum value.
@@ -1453,39 +1500,39 @@ class CFD_CORE_EXPORT ConfidentialTransaction : public AbstractTransaction {
int minimum_bits = kDefaultBlindMinimumBits,
std::vector* blinder_list = nullptr);
/**
- * @brief indexで指定されたInputに対して、unblind処理を行う.
- * @param tx_in_index TxInのindex値
- * @param blinding_key blinding key(秘密鍵)
- * @param token_blinding_key token blinding key(秘密鍵).
- * @return unblindの出力データを格納したUnblindParameter構造体
+ * @brief Performs unblind processing for the specified Input.
+ * @param tx_in_index TxIn index
+ * @param blinding_key blinding key(private key)
+ * @param token_blinding_key token blinding key(private key).
+ * @return UnblindParameter structure containing unblind output data list
*/
std::vector UnblindTxIn(
uint32_t tx_in_index, const Privkey& blinding_key,
const Privkey token_blinding_key = Privkey());
/**
- * @brief indexで指定されたOutputに対して、unblind処理を行う.
- * @param tx_out_index TxOutのindex値
- * @param blinding_key blinding key(秘密鍵)
- * @return unblindの出力データを格納したUnblindParameter構造体
+ * @brief Performs unblind processing for the specified Output.
+ * @param tx_out_index TxOut index
+ * @param blinding_key blinding key(private key)
+ * @return UnblindParameter structure containing unblind output data
*/
UnblindParameter UnblindTxOut(
uint32_t tx_out_index, const Privkey& blinding_key);
/**
- * @brief Transactionの全てのOutputに対して、unblind処理を行う.
- * @param[in] blinding_keys blinding key(秘密鍵) list
- * @return unblindの出力データを格納したUnblindParameter構造体リスト
+ * @brief Unblind processing is performed for all Outputs of Transaction.
+ * @param[in] blinding_keys blinding key(private key) list
+ * @return UnblindParameter structure containing unblind output data list
*/
std::vector UnblindTxOut(
const std::vector& blinding_keys);
/**
- * @brief Elements用signatureハッシュを取得する.
- * @param[in] txin_index TxInのindex値
- * @param[in] script_data unlocking script もしくは witness_program.
+ * @brief Get the signature hash for Confidential Transaction.
+ * @param[in] txin_index TxIn index
+ * @param[in] script_data unlocking script or witness program.
* @param[in] sighash_type SigHashType(@see cfdcore_util.h)
- * @param[in] value TxInのAmount/amountcommitment値.
+ * @param[in] value TxIn Amount/amountcommitment.
* @param[in] version Witness version
- * @return signatureハッシュ
+ * @return signature hash
*/
ByteData256 GetElementsSignatureHash(
uint32_t txin_index, const ByteData& script_data,
@@ -1494,32 +1541,32 @@ class CFD_CORE_EXPORT ConfidentialTransaction : public AbstractTransaction {
WitnessVersion version = WitnessVersion::kVersionNone) const;
/**
- * @brief TxOutの順序をランダムソートする.
- * @details ブラインド前のみ実施可能.
+ * @brief Randomly sort the order of TxOut.
+ * @details Can only be done before the blinds.
*/
void RandomSortTxOut();
/**
- * @brief witness情報のみのHashを取得する.
+ * @brief Get a Hash of witness information only.
* @return witness only hash
*/
ByteData256 GetWitnessOnlyHash() const;
/**
- * @brief witness情報かどうかを取得する.
- * @retval true witness
- * @retval false witnessではない
+ * @brief Get if it have witness information.
+ * @retval true witness exist
+ * @retval false witness not found
*/
virtual bool HasWitness() const;
/**
- * @brief libwally処理用フラグを取得する。
- * @return libwally用フラグ
+ * @brief libwally Get the processing flag.
+ * @return libwally flag
*/
virtual uint32_t GetWallyFlag() const;
/**
- * @brief Bitcoin Transaction情報を取得する。
+ * @brief Get Bitcoin Transaction information.
* @param[in] bitcoin_tx_data bitcoin transaction data
* @param[in] is_remove_witness remove witness flag
* @return transaction data.
@@ -1527,7 +1574,7 @@ class CFD_CORE_EXPORT ConfidentialTransaction : public AbstractTransaction {
static ByteData GetBitcoinTransaction(
const ByteData& bitcoin_tx_data, bool is_remove_witness = false);
/**
- * @brief asset entropyの情報を算出する.
+ * @brief Calculate asset entropy information.
* @param[in] txid utxo txid
* @param[in] vout utxo vout
* @param[in] contract_hash asset entropy
@@ -1536,13 +1583,13 @@ class CFD_CORE_EXPORT ConfidentialTransaction : public AbstractTransaction {
static BlindFactor CalculateAssetEntropy(
const Txid& txid, const uint32_t vout, const ByteData256& contract_hash);
/**
- * @brief assetの情報を算出する.
+ * @brief Calculate asset information.
* @param[in] entropy asset entropy
* @return asset id (ConfidentialAssetId).
*/
static ConfidentialAssetId CalculateAsset(const BlindFactor& entropy);
/**
- * @brief reissuance tokenの情報を算出する.
+ * @brief Calculate the reissuance token information.
* @param[in] entropy asset entropy
* @param[in] is_blind asset is blinded or not
* @return reissuance token (ConfidentialAssetId).
@@ -1550,7 +1597,7 @@ class CFD_CORE_EXPORT ConfidentialTransaction : public AbstractTransaction {
static ConfidentialAssetId CalculateReissuanceToken(
const BlindFactor& entropy, bool is_blind);
/**
- * @brief IssueAssetの情報を設定する.
+ * @brief Set the Issue Asset information.
* @param[in] txid utxo txid
* @param[in] vout utxo vout
* @param[in] is_blind blinding issuance
@@ -1562,7 +1609,7 @@ class CFD_CORE_EXPORT ConfidentialTransaction : public AbstractTransaction {
const Txid& txid, uint32_t vout, bool is_blind,
const ByteData256& contract_hash, const ByteData256& asset_entropy);
/**
- * @brief issuance/reissuanceのblinding keyを取得する.
+ * @brief Get the blinding key of issuance / reissuance.
* @param[in] master_blinding_key master blindingKey
* @param[in] txid issuance utxo txid
* @param[in] vout issuance utxo vout
@@ -1571,7 +1618,7 @@ class CFD_CORE_EXPORT ConfidentialTransaction : public AbstractTransaction {
static Privkey GetIssuanceBlindingKey(
const Privkey& master_blinding_key, const Txid& txid, uint32_t vout);
/**
- * @brief pegoutで使用するpubkey情報を取得する.
+ * @brief Get the pubkey information used by pegout.
* @param[in] online_pubkey online pubkey
* @param[in] master_online_key online privkey
* @param[in] bitcoin_descriptor bip32 pubkey (m/0/\*)
@@ -1593,107 +1640,106 @@ class CFD_CORE_EXPORT ConfidentialTransaction : public AbstractTransaction {
Address* descriptor_derive_address = nullptr);
protected:
- std::vector vin_; ///< TxIn配列
- std::vector vout_; ///< TxOut配列
+ std::vector vin_; ///< TxIn array
+ std::vector vout_; ///< TxOut array
/**
- * @brief HEX文字列からTransaction情報を設定する.
- * @param[in] hex_string TransactionバイトデータのHEX文字列
+ * @brief Set Transaction information from HEX string.
+ * @param[in] hex_string HEX string.
*/
void SetFromHex(const std::string& hex_string);
private:
/**
- * @brief TxIn配列のIndex範囲をチェックする.
- * @param[in] index TxIn配列のIndex値
- * @param[in] line 行数
- * @param[in] caller コール元関数名
+ * @brief check TxIn array range.
+ * @param[in] index TxIn Index
+ * @param[in] line Number of lines
+ * @param[in] caller Calling function name
*/
virtual void CheckTxInIndex(
uint32_t index, int line, const char* caller) const;
/**
- * @brief TxOut配列のIndex範囲をチェックする.
* @brief check TxOut array range.
- * @param[in] index TxOut配列のIndex値
- * @param[in] line 行数
- * @param[in] caller コール元関数名
+ * @param[in] index TxOut Index
+ * @param[in] line Number of lines
+ * @param[in] caller Calling function name
*/
virtual void CheckTxOutIndex(
uint32_t index, int line, const char* caller) const;
/**
- * @brief witness stackに情報を追加する.
- * @param[in] tx_in_index TxIn配列のindex値
- * @param[in] data witness stackに追加するバイトデータ
+ * @brief Add information to the witness stack.
+ * @param[in] tx_in_index TxIn index
+ * @param[in] data data to add to the witness stack
* @return witness stack
*/
const ScriptWitness AddScriptWitnessStack(
uint32_t tx_in_index, const std::vector& data);
/**
- * @brief witness stackの指定index位置を更新する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @param[in] witness_index witness stackのindex位置
- * @param[in] data witness stackに追加する32byte情報
+ * @brief Update the specified index position of the witness stack.
+ * @param[in] tx_in_index TxIn index
+ * @param[in] witness_index witness stack index
+ * @param[in] data Information to add to the witness stack
* @return witness stack
*/
const ScriptWitness SetScriptWitnessStack(
uint32_t tx_in_index, uint32_t witness_index,
const std::vector& data);
/**
- * @brief witness stackに情報を追加する.
- * @param[in] tx_in_index TxIn配列のindex値
- * @param[in] data witness stackに追加するバイトデータ
+ * @brief Add information to the pegin witness stack.
+ * @param[in] tx_in_index TxIn index
+ * @param[in] data data to add to the witness stack
* @return witness stack
*/
const ScriptWitness AddPeginWitnessStack(
uint32_t tx_in_index, const std::vector& data);
/**
- * @brief witness stackの指定index位置を更新する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @param[in] witness_index witness stackのindex位置
- * @param[in] data witness stackに追加する32byte情報
+ * @brief Update the specified index position of the pegin witness stack.
+ * @param[in] tx_in_index TxIn index
+ * @param[in] witness_index witness stack index
+ * @param[in] data Information to add to the witness stack
* @return witness stack
*/
const ScriptWitness SetPeginWitnessStack(
uint32_t tx_in_index, uint32_t witness_index,
const std::vector& data);
/**
- * @brief Transactionのバイトデータを取得する.
- * @param[in] has_witness witnessを含めるかのフラグ
- * @return バイトデータ
+ * @brief Get the byte data of Transaction.
+ * @param[in] has_witness Flag to include witness
+ * @return ByteData
*/
ByteData GetByteData(bool has_witness) const;
/**
- * @brief ElementsのTx状態フラグ(libwally値)を設定する。
+ * @brief Set the Tx status flag (libwally value) of Elements.
*/
void SetElementsTxState();
/**
- * @brief 配列をByteDataへと変換する.
+ * @brief Convert the array to ByteData.
* @param[in] data buffer
* @param[in] size size
* @return ByteData
*/
static ByteData ConvertToByteData(const uint8_t* data, size_t size);
/**
- * @brief ConfidentialNonce情報をコピーする。
- * @param[in] buffer コピー元のバッファ
- * @param[in] buffer_size バッファサイズ
- * @param[in] explicit_size unblind時のサイズ
- * @param[in] address コピー先のアドレス
- * @return 移動後のアドレス
+ * @brief Copy the Confidential Nonce information.
+ * @param[in] buffer Copy source buffer
+ * @param[in] buffer_size Copy source buffer size
+ * @param[in] explicit_size Unblind size
+ * @param[in] address Copy destination address
+ * @return Address after moving
*/
static uint8_t* CopyConfidentialCommitment(
const void* buffer, size_t buffer_size, size_t explicit_size,
uint8_t* address);
/**
- * blindされたデータに対して、unblind処理をかける
- * @param[in] nonce nonce値
- * @param[in] blinding_key blindingした際の秘密鍵
- * @param[in] rangeproof asset amountの検証に用いる検証値
- * @param[in] value_commitment blindされたvalueのcommitement値
- * @param[in] extra unblindに必要な情報
+ * @brief Unblind processing is applied to blinded data
+ * @param[in] nonce nonce
+ * @param[in] blinding_key blinding private key
+ * @param[in] rangeproof asset amount rangeproof
+ * @param[in] value_commitment blind value commitement
+ * @param[in] extra unblind need data
* @param[in] asset confidential asset id
- * @return Unblindされた際に出力されたUnblindParameter構造体
+ * @return UnblindParameter structure output when unblinded
*/
static UnblindParameter CalculateUnblindData(
const ConfidentialNonce& nonce, const Privkey& blinding_key,
@@ -1701,13 +1747,13 @@ class CFD_CORE_EXPORT ConfidentialTransaction : public AbstractTransaction {
const Script& extra, const ConfidentialAssetId& asset);
/**
- * blindされたIssueデータに対して、unblind処理をかける
- * @param[in] blinding_key blindingした際の秘密鍵
- * @param[in] rangeproof asset amountの検証に用いる検証値
- * @param[in] value_commitment blindされたvalueのcommitement値
- * @param[in] extra unblindに必要な情報
+ * @brief Unblind processing is applied to the blinded Issue data
+ * @param[in] blinding_key blinding private key
+ * @param[in] rangeproof asset amount rangeproof
+ * @param[in] value_commitment blind value commitement
+ * @param[in] extra unblind need data
* @param[in] asset confidential asset id
- * @return Unblindされた際に出力されたUnblindParameter構造体
+ * @return UnblindParameter structure output when unblinded
*/
static UnblindParameter CalculateUnblindIssueData(
const Privkey& blinding_key, const ByteData& rangeproof,
@@ -1715,7 +1761,7 @@ class CFD_CORE_EXPORT ConfidentialTransaction : public AbstractTransaction {
const ConfidentialAssetId& asset);
/**
- * @brief rangeProofなどを生成する。
+ * @brief Generate rangeProof etc.
* @param[in] value amount
* @param[in] pubkey public key
* @param[in] privkey private key
@@ -1741,7 +1787,7 @@ class CFD_CORE_EXPORT ConfidentialTransaction : public AbstractTransaction {
std::vector* commitment, std::vector* range_proof);
/**
- * @brief Descriptor情報から拡張Keyを生成する.
+ * @brief Generate an extended Key from Descriptor information.
* @param[in] bitcoin_descriptor descriptor
* @param[in] bip32_counter bip32 counter
* @param[in] prefix extend pubkey prefix
diff --git a/include/cfdcore/cfdcore_exception.h b/include/cfdcore/cfdcore_exception.h
index c11a2bc5..760c9d76 100644
--- a/include/cfdcore/cfdcore_exception.h
+++ b/include/cfdcore/cfdcore_exception.h
@@ -1,7 +1,7 @@
// Copyright 2019 CryptoGarage
/**
* @file cfdcore_exception.h
- * @brief cfdの例外クラス定義ファイルです。
+ * @brief The cfd exception class definition file.
*/
#ifndef CFD_CORE_INCLUDE_CFDCORE_CFDCORE_EXCEPTION_H_
#define CFD_CORE_INCLUDE_CFDCORE_CFDCORE_EXCEPTION_H_
@@ -14,11 +14,11 @@
#include "cfdcore/cfdcore_common.h"
#ifndef _GLIBCXX_TXN_SAFE_DYN
-/// インクルードガード(_GLIBCXX_TXN_SAFE_DYN)
+/// Include guard (_GLIBCXX_TXN_SAFE_DYN)
#define _GLIBCXX_TXN_SAFE_DYN
#endif
#ifndef _GLIBCXX_USE_NOEXCEPT
-/// インクルードガード(_GLIBCXX_USE_NOEXCEPT)
+/// Include guard (_GLIBCXX_USE_NOEXCEPT)
#define _GLIBCXX_USE_NOEXCEPT noexcept
#endif
@@ -26,78 +26,78 @@ namespace cfd {
namespace core {
/**
- * @brief エラーコード定義
+ * @brief Error code definition.
*/
typedef enum {
- kCfdSuccess = 0, //!< 正常終了
- kCfdUnknownError = -1, //!< 不明なエラー
- kCfdInternalError = -2, //!< 内部エラー
- kCfdMemoryFullError = -3, //!< メモリ確保エラー
- kCfdIllegalArgumentError = 1, //!< 引数不正
- kCfdIllegalStateError = 2, //!< 状態不正
- kCfdOutOfRangeError = 3, //!< 範囲外の値
- kCfdInvalidSettingError = 4, //!< 設定不正
- kCfdConnectionError = 5, //!< 接続エラー
- kCfdDiskAccessError = 6 //!< ディスクアクセスエラー
+ kCfdSuccess = 0, //!< Successful completion
+ kCfdUnknownError = -1, //!< Unknown error
+ kCfdInternalError = -2, //!< Internal error
+ kCfdMemoryFullError = -3, //!< Memory allocation error
+ kCfdIllegalArgumentError = 1, //!< Invalid argument
+ kCfdIllegalStateError = 2, //!< Illegal state
+ kCfdOutOfRangeError = 3, //!< Out of range value
+ kCfdInvalidSettingError = 4, //!< Improper settings
+ kCfdConnectionError = 5, //!< Connection error
+ kCfdDiskAccessError = 6 //!< Disk access error
} CfdError;
-/// @brief エラーメッセージ:不明なエラー
+/// @brief Error message: Unknown error
const char kCfdUnknownErrorMessage[] = "Unknown error occurred.";
/**
- * @brief CFD例外クラス
+ * @brief CFD exception class.
*/
class CfdException : public std::exception {
public:
/**
- * @brief コンストラクタ
+ * @brief Constructor.
*/
CfdException()
: error_code_(kCfdUnknownError), message_(kCfdUnknownErrorMessage) {}
/**
- * @brief コンストラクタ
- * @param[in] message エラーメッセージ
+ * @brief Constructor.
+ * @param[in] message Error message.
*/
explicit CfdException(const std::string& message)
: error_code_(kCfdUnknownError), message_(message) {}
/**
- * @brief コンストラクタ
- * @param[in] error_code エラーコード
+ * @brief Constructor.
+ * @param[in] error_code Error code.
*/
explicit CfdException(CfdError error_code)
: error_code_(error_code), message_(kCfdUnknownErrorMessage) {}
/**
- * @brief コンストラクタ
- * @param[in] error_code エラーコード
- * @param[in] message エラーメッセージ
+ * @brief Constructor.
+ * @param[in] error_code Error code.
+ * @param[in] message Error message.
*/
CfdException(CfdError error_code, const std::string& message)
: error_code_(error_code), message_(message) {}
/**
- * @brief デストラクタ
+ * @brief Destructor.
*/
virtual ~CfdException(void) _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_USE_NOEXCEPT {
// do nothing
}
/**
- * @brief エラーメッセージを取得する.
- * @return エラーメッセージ
+ * @brief Get an error message.
+ * @return Error message.
*/
virtual const char* what() const _GLIBCXX_TXN_SAFE_DYN
_GLIBCXX_USE_NOEXCEPT {
return message_.c_str();
}
/**
- * @brief エラーコードを取得する.
- * @return エラーコード
+ * @brief Get an error code.
+ * @return Error code.
*/
virtual CfdError GetErrorCode() const _GLIBCXX_TXN_SAFE_DYN
_GLIBCXX_USE_NOEXCEPT {
return error_code_;
}
/**
- * @brief エラーコードに即したエラータイプを取得する.
- * @return エラータイプ文字列
+ * @brief Get the error type according to the error code.
+ * @return Error type string.
*/
virtual std::string GetErrorType() const _GLIBCXX_TXN_SAFE_DYN
_GLIBCXX_USE_NOEXCEPT {
@@ -116,38 +116,38 @@ class CfdException : public std::exception {
}
protected:
- CfdError error_code_; ///< エラーコード
- std::string message_; ///< エラーメッセージ
+ CfdError error_code_; ///< error code
+ std::string message_; ///< error message
};
// -----------------------------------------------------------------------------
// InvalidScriptException
// -----------------------------------------------------------------------------
-/// @brief スクリプト例外メッセージ
+/// @brief Script exception message
const char kCfdInvalidScriptMessage[] = "invalid script error.";
/**
- * @brief スクリプト例外クラス.
+ * @brief Script exception class.
*/
class InvalidScriptException : public CfdException {
public:
/**
- * @brief コンストラクタ.
+ * @brief Constructor.
*/
InvalidScriptException()
: CfdException(kCfdIllegalArgumentError, kCfdInvalidScriptMessage) {
// do nothing
}
/**
- * @brief コンストラクタ.
- * @param[in] message エラーメッセージ
+ * @brief Constructor.
+ * @param[in] message error message
*/
explicit InvalidScriptException(const std::string& message)
: CfdException(kCfdIllegalArgumentError, message) {
// do nothing
}
/**
- * @brief デストラクタ.
+ * @brief Destructor.
*/
virtual ~InvalidScriptException(void)
_GLIBCXX_TXN_SAFE_DYN _GLIBCXX_USE_NOEXCEPT {
diff --git a/include/cfdcore/cfdcore_hdwallet.h b/include/cfdcore/cfdcore_hdwallet.h
index 63a46588..19368935 100644
--- a/include/cfdcore/cfdcore_hdwallet.h
+++ b/include/cfdcore/cfdcore_hdwallet.h
@@ -1,8 +1,8 @@
-// Copyright 2019 CryptoGarage
+// Copyright 2020 CryptoGarage
/**
* @file cfdcore_hdwallet.h
*
- * @brief BIP32/BIP39/BIP44関連クラス
+ * @brief definition for BIP32/BIP39/BIP44 class.
*/
#ifndef CFD_CORE_INCLUDE_CFDCORE_CFDCORE_HDWALLET_H_
#define CFD_CORE_INCLUDE_CFDCORE_CFDCORE_HDWALLET_H_
@@ -19,9 +19,10 @@ namespace core {
class ExtPrivkey;
class ExtPubkey;
+class KeyData;
/**
- * @brief HDWalletを表現するデータクラス
+ * @brief A data class that represents an HD Wallet.
*/
class CFD_CORE_EXPORT HDWallet {
public:
@@ -39,41 +40,41 @@ class CFD_CORE_EXPORT HDWallet {
static constexpr uint32_t kSeed512Size = 64; // BIP32_ENTROPY_LEN_512
/**
- * @brief デフォルトコンストラクタ
+ * @brief constructor.
*/
HDWallet();
/**
- * @brief コンストラクタ
- * @param[in] seed シード値
+ * @brief constructor.
+ * @param[in] seed seed
*/
explicit HDWallet(const ByteData& seed);
/**
- * @brief コンストラクタ
- * @param[in] mnemonic ニーモニック文字列配列
- * @param[in] passphrase パスフレーズ
- * @param[in] use_ideographic_space 全角スペース利用フラグ(default: false)
+ * @brief constructor.
+ * @param[in] mnemonic mnemonic
+ * @param[in] passphrase passphrase
+ * @param[in] use_ideographic_space ideographic space use flag. (default: false)
*/
HDWallet(
std::vector mnemonic, std::string passphrase,
bool use_ideographic_space = false);
/**
- * @brief seedを取得する
- * @return seed値ByteData
+ * @brief Get seed value.
+ * @return seed
*/
ByteData GetSeed() const;
/**
- * @brief 拡張秘密鍵を生成する。
+ * @brief Generate an extended privkey.
* @param[in] network_type network type
* @return extended privkey
* @throws CfdException If invalid seed.
*/
ExtPrivkey GeneratePrivkey(NetType network_type) const;
/**
- * @brief 拡張秘密鍵を生成する。
+ * @brief Generate an extended privkey.
* @param[in] network_type network type
* @param[in] child_num child number
* @return extended privkey
@@ -81,7 +82,7 @@ class CFD_CORE_EXPORT HDWallet {
*/
ExtPrivkey GeneratePrivkey(NetType network_type, uint32_t child_num) const;
/**
- * @brief 拡張秘密鍵を生成する。
+ * @brief Generate an extended privkey.
* @param[in] network_type network type
* @param[in] path child number path
* @return extended privkey
@@ -90,7 +91,7 @@ class CFD_CORE_EXPORT HDWallet {
ExtPrivkey GeneratePrivkey(
NetType network_type, const std::vector& path) const;
/**
- * @brief 拡張秘密鍵を生成する。
+ * @brief Generate an extended privkey.
* @param[in] network_type network type
* @param[in] string_path child number string path
* @return extended privkey
@@ -100,14 +101,33 @@ class CFD_CORE_EXPORT HDWallet {
NetType network_type, const std::string& string_path) const;
/**
- * @brief 拡張公開鍵を生成する。
+ * @brief Generate an extended privkey data.
+ * @param[in] network_type network type
+ * @param[in] path child number path
+ * @return extended privkey
+ * @throws CfdException If invalid seed.
+ */
+ KeyData GeneratePrivkeyData(
+ NetType network_type, const std::vector& path) const;
+ /**
+ * @brief Generate an extended privkey data.
+ * @param[in] network_type network type
+ * @param[in] string_path child number string path
+ * @return extended privkey
+ * @throws CfdException If invalid seed.
+ */
+ KeyData GeneratePrivkeyData(
+ NetType network_type, const std::string& string_path) const;
+
+ /**
+ * @brief Generate an extended pubkey.
* @param[in] network_type network type
* @return extended pubkey
* @throws CfdException If invalid seed.
*/
ExtPubkey GeneratePubkey(NetType network_type) const;
/**
- * @brief 拡張公開鍵を生成する。
+ * @brief Generate an extended pubkey.
* @param[in] network_type network type
* @param[in] child_num child number
* @return extended pubkey
@@ -115,7 +135,7 @@ class CFD_CORE_EXPORT HDWallet {
*/
ExtPubkey GeneratePubkey(NetType network_type, uint32_t child_num) const;
/**
- * @brief 拡張公開鍵を生成する。
+ * @brief Generate an extended pubkey.
* @param[in] network_type network type
* @param[in] path child number path
* @return extended pubkey
@@ -124,7 +144,7 @@ class CFD_CORE_EXPORT HDWallet {
ExtPubkey GeneratePubkey(
NetType network_type, const std::vector& path) const;
/**
- * @brief 拡張公開鍵を生成する。
+ * @brief Generate an extended pubkey.
* @param[in] network_type network type
* @param[in] string_path child number string path
* @return extended pubkey
@@ -134,29 +154,48 @@ class CFD_CORE_EXPORT HDWallet {
NetType network_type, const std::string& string_path) const;
/**
- * @brief Mnemonic で利用できる Wordlist を取得する.
- * @param[in] language 取得するWordlistの言語
- * @return Wordlist配列
- * @throws CfdException 非対応の言語が渡された場合
+ * @brief Generate an extended pubkey data.
+ * @param[in] network_type network type
+ * @param[in] path child number path
+ * @return extended pubkey
+ * @throws CfdException If invalid seed.
+ */
+ KeyData GeneratePubkeyData(
+ NetType network_type, const std::vector& path) const;
+ /**
+ * @brief Generate an extended pubkey data.
+ * @param[in] network_type network type
+ * @param[in] string_path child number string path
+ * @return extended pubkey
+ * @throws CfdException If invalid seed.
+ */
+ KeyData GeneratePubkeyData(
+ NetType network_type, const std::string& string_path) const;
+
+ /**
+ * @brief Get the Wordlist available in Mnemonic.
+ * @param[in] language language to Wordlist
+ * @return Wordlist vector
+ * @throws CfdException If invalid language passed.
*/
static std::vector GetMnemonicWordlist(
const std::string& language);
/**
- * @brief Mnemonic で利用できる Wordlist を取得する.
- * @param[in] entropy Mnemonic生成のエントロピー値
- * @param[in] language Mnemonicの言語
- * @return ニーモニック配列
- * @throws CfdException 非対応の言語が渡された場合
+ * @brief Get the Wordlist available in Mnemonic.
+ * @param[in] entropy Entropy value for Mnemonic generation
+ * @param[in] language language to mnemonic
+ * @return mnemonic vector
+ * @throws CfdException If invalid language passed.
*/
static std::vector ConvertEntropyToMnemonic(
const ByteData& entropy, const std::string& language);
/**
- * @brief Mnemonic から Entropy へ変換する.
- * @param[in] mnemonic エントロピーを導出するニーモニック配列
- * @param[in] language ニーモニックの言語
- * @return エントロピー値バイトデータ
+ * @brief Convert from Mnemonic to Entropy.
+ * @param[in] mnemonic mnemonic vector
+ * @param[in] language language to mnemonic
+ * @return entropy data
* @throws CfdException If invalid language passed.
*/
static ByteData ConvertMnemonicToEntropy(
@@ -167,7 +206,7 @@ class CFD_CORE_EXPORT HDWallet {
* @param[in] mnemonic mnemonic vector to check valid
* @param[in] language language to verify
* @retval true mnemonic checksum is valid
- * @retval true mnemonic checksum is invalid
+ * @retval false mnemonic checksum is invalid
*/
static bool CheckValidMnemonic(
const std::vector& mnemonic, const std::string& language);
@@ -176,7 +215,7 @@ class CFD_CORE_EXPORT HDWallet {
ByteData seed_; //!< seed
/**
- * @brief Mnemonic でサポートしている言語であるかを判定する.
+ * @brief Determine if the language is supported by Mnemonic.
* @param[in] language language used by mnemonic.
* @retval true If language is supported.
* @retval false If language is not supported.
@@ -184,11 +223,11 @@ class CFD_CORE_EXPORT HDWallet {
static bool CheckSupportedLanguages(const std::string& language);
/**
- * @brief mnemonic と passphrase から seed を生成する.
- * @param[in] mnemonic ニーモニック配列
- * @param[in] passphrase パスフレーズ
- * @param[in] use_ideographic_space 全角スペースで区切るかのフラグ
- * @return シード値バイトデータ
+ * @brief Generate seed from mnemonic and passphrase.
+ * @param[in] mnemonic mnemonic vector
+ * @param[in] passphrase passphrase
+ * @param[in] use_ideographic_space Flag to separate with double-byte space
+ * @return seed
*/
static ByteData ConvertMnemonicToSeed(
const std::vector& mnemonic, const std::string& passphrase,
@@ -196,7 +235,7 @@ class CFD_CORE_EXPORT HDWallet {
};
/**
- * @brief 拡張秘密鍵を表現するデータクラス
+ * @brief A data class that represents an extended private key.
*/
class CFD_CORE_EXPORT ExtPrivkey {
public:
@@ -205,7 +244,7 @@ class CFD_CORE_EXPORT ExtPrivkey {
*/
static constexpr uint32_t kSerializeSize = 78; // BIP32_SERIALIZED_LEN
/**
- * @brief 強化鍵定義
+ * @brief hardened key definition
*/
static constexpr uint32_t kHardenedKey = 0x80000000;
/**
@@ -218,41 +257,41 @@ class CFD_CORE_EXPORT ExtPrivkey {
static constexpr uint32_t kVersionTestnetPrivkey = 0x04358394;
/**
- * @brief デフォルトコンストラクタ
+ * @brief constructor.
*/
ExtPrivkey();
/**
- * @brief コンストラクタ
+ * @brief constructor.
* @param[in] seed seed byte
* @param[in] network_type network type
*/
explicit ExtPrivkey(const ByteData& seed, NetType network_type);
/**
- * @brief コンストラクタ
+ * @brief constructor.
* @param[in] serialize_data serialize data
*/
explicit ExtPrivkey(const ByteData& serialize_data);
/**
- * @brief コンストラクタ
+ * @brief constructor.
* @param[in] serialize_data serialize data
* @param[in] tweak_sum tweak sum
*/
explicit ExtPrivkey(
const ByteData& serialize_data, const ByteData256& tweak_sum);
/**
- * @brief コンストラクタ
+ * @brief constructor.
* @param[in] base58_data base58 data
*/
explicit ExtPrivkey(const std::string& base58_data);
/**
- * @brief コンストラクタ
+ * @brief constructor.
* @param[in] base58_data base58 data
* @param[in] tweak_sum tweak sum
*/
explicit ExtPrivkey(
const std::string& base58_data, const ByteData256& tweak_sum);
/**
- * @brief コンストラクタ
+ * @brief constructor.
* @param[in] network_type network type
* @param[in] parent_key parent privkey
* @param[in] parent_chain_code parent chain code
@@ -264,7 +303,7 @@ class CFD_CORE_EXPORT ExtPrivkey {
const ByteData256& parent_chain_code, uint8_t parent_depth,
uint32_t child_num);
/**
- * @brief コンストラクタ
+ * @brief constructor.
* @param[in] network_type network type
* @param[in] parent_key parent privkey
* @param[in] privkey privkey
@@ -276,7 +315,7 @@ class CFD_CORE_EXPORT ExtPrivkey {
NetType network_type, const Privkey& parent_key, const Privkey& privkey,
const ByteData256& chain_code, uint8_t depth, uint32_t child_num);
/**
- * @brief コンストラクタ
+ * @brief constructor.
* @param[in] network_type network type
* @param[in] parent_fingerprint parent fingerprint(4byte)
* @param[in] privkey privkey
@@ -290,37 +329,37 @@ class CFD_CORE_EXPORT ExtPrivkey {
uint32_t child_num);
/**
- * @brief 拡張keyのSerialize情報を取得する.
+ * @brief Get Serialize information of extension key.
* @return serialize data
*/
ByteData GetData() const;
/**
- * @brief 拡張keyのBase58文字列を取得する.
+ * @brief Get the Base58 string of the extended key.
* @return base58 string
*/
std::string ToString() const;
/**
- * @brief Privkeyインスタンスを取得する.
- * @return Privkeyインスタンス
+ * @brief Get a privkey.
+ * @return Privkey
*/
Privkey GetPrivkey() const;
/**
- * @brief 指定階層の拡張秘密鍵を取得する。
+ * @brief Acquires the extended private key of the specified hierarchy.
* @param[in] child_num child number
* @return extended pubprivkeykey
* @throws CfdException If invalid seed.
*/
ExtPrivkey DerivePrivkey(uint32_t child_num) const;
/**
- * @brief 指定階層の拡張秘密鍵を取得する。
+ * @brief Acquires the extended private key of the specified hierarchy.
* @param[in] path child number path
* @return extended privkey
* @throws CfdException If invalid seed.
*/
ExtPrivkey DerivePrivkey(const std::vector& path) const;
/**
- * @brief 指定階層の拡張秘密鍵を取得する。
+ * @brief Acquires the extended private key of the specified hierarchy.
* @param[in] string_path child number string path
* @return extended pubkey
* @throws CfdException If invalid seed.
@@ -328,27 +367,42 @@ class CFD_CORE_EXPORT ExtPrivkey {
ExtPrivkey DerivePrivkey(const std::string& string_path) const;
/**
- * @brief 同一階層の拡張公開鍵を取得する。
+ * @brief Derive extended privkey.
+ * @param[in] path child number path
+ * @return extended privkey
+ * @throws CfdException If invalid seed.
+ */
+ KeyData DerivePrivkeyData(const std::vector& path) const;
+ /**
+ * @brief Derive ext-privkey.
+ * @param[in] string_path child number string path
+ * @return extended privkey
+ * @throws CfdException If invalid seed.
+ */
+ KeyData DerivePrivkeyData(const std::string& string_path) const;
+
+ /**
+ * @brief Obtain the extended public key of the same layer.
* @return extended pubkey
* @throws CfdException If invalid seed.
*/
ExtPubkey GetExtPubkey() const;
/**
- * @brief 指定階層の拡張公開鍵を取得する。
+ * @brief Obtain the extended public key of the specified hierarchy.
* @param[in] child_num child number
* @return extended pubkey
* @throws CfdException If invalid seed.
*/
ExtPubkey DerivePubkey(uint32_t child_num) const;
/**
- * @brief 指定階層の拡張公開鍵を取得する。
+ * @brief Obtain the extended public key of the specified hierarchy.
* @param[in] path child number path
* @return extended pubkey
* @throws CfdException If invalid seed.
*/
ExtPubkey DerivePubkey(const std::vector& path) const;
/**
- * @brief 指定階層の拡張公開鍵を取得する。
+ * @brief Obtain the extended public key of the specified hierarchy.
* @param[in] string_path child number string path
* @return extended pubkey
* @throws CfdException If invalid seed.
@@ -356,54 +410,69 @@ class CFD_CORE_EXPORT ExtPrivkey {
ExtPubkey DerivePubkey(const std::string& string_path) const;
/**
- * @brief 状態が正常であるかを返却する.
- * @retval true 正常
- * @retval false 不正
+ * @brief Derive ext-pubkey.
+ * @param[in] path child number path
+ * @return extended pubkey
+ * @throws CfdException If invalid seed.
+ */
+ KeyData DerivePubkeyData(const std::vector& path) const;
+ /**
+ * @brief Derive extended pubkey.
+ * @param[in] string_path child number string path
+ * @return extended pubkey
+ * @throws CfdException If invalid seed.
+ */
+ KeyData DerivePubkeyData(const std::string& string_path) const;
+
+ /**
+ * @brief Check if the data format is correct.
+ * @retval true valid
+ * @retval false invalid
*/
bool IsValid() const;
/**
- * @brief 拡張keyのDepthを取得する.
+ * @brief Get depth.
* @return depth value
*/
uint8_t GetDepth() const;
/**
- * @brief version部を取得する.
+ * @brief Get veresion.
* @return version data (4byte)
*/
uint32_t GetVersion() const;
/**
- * @brief child number部を取得する.
+ * @brief Get veresion.
+ * @return version data (4byte)
+ */
+ ByteData GetVersionData() const;
+ /**
+ * @brief Get child number.
* @return child number (4byte)
*/
uint32_t GetChildNum() const;
/**
- * @brief chain code部を取得する.
+ * @brief Get chain code.
* @return chain code (32byte)
*/
ByteData256 GetChainCode() const;
/**
- * @brief version部を取得する.
- * @return version data (4byte)
- */
- ByteData GetVersionData() const;
- /**
- * @brief fingerprint部を取得する.
+ * @brief Get fingerprint.
* @return fingerprint data (4byte)
*/
uint32_t GetFingerprint() const;
/**
- * @brief fingerprint部を取得する.
+ * @brief Get fingerprint.
* @return fingerprint data (4byte)
*/
ByteData GetFingerprintData() const;
/**
- * @brief 派生Pubkeyを生成する過程で生成されたtweak値の合成値を取得する。
+ * @brief Get the composite value of the tweak value generated in the process of generating the derived Pubkey.
* @return tweak sum
*/
ByteData256 GetPubTweakSum() const;
/**
- * @brief get network type.
+ * @brief Get network type.
* @return network type.
*/
NetType GetNetworkType() const;
@@ -420,7 +489,7 @@ class CFD_CORE_EXPORT ExtPrivkey {
};
/**
- * @brief 拡張公開鍵を表現するデータクラス
+ * @brief A data class that represents an extended public key.
*/
class CFD_CORE_EXPORT ExtPubkey {
public:
@@ -434,35 +503,35 @@ class CFD_CORE_EXPORT ExtPubkey {
static constexpr uint32_t kVersionTestnetPubkey = 0x043587cf;
/**
- * @brief デフォルトコンストラクタ
+ * @brief constructor.
*/
ExtPubkey();
/**
- * @brief コンストラクタ
+ * @brief constructor.
* @param[in] serialize_data serialize data
*/
explicit ExtPubkey(const ByteData& serialize_data);
/**
- * @brief コンストラクタ
+ * @brief constructor.
* @param[in] serialize_data serialize data
* @param[in] tweak_sum tweak sum
*/
explicit ExtPubkey(
const ByteData& serialize_data, const ByteData256& tweak_sum);
/**
- * @brief コンストラクタ
+ * @brief constructor.
* @param[in] base58_data base58 data
*/
explicit ExtPubkey(const std::string& base58_data);
/**
- * @brief コンストラクタ
+ * @brief constructor.
* @param[in] base58_data base58 data
* @param[in] tweak_sum tweak sum
*/
explicit ExtPubkey(
const std::string& base58_data, const ByteData256& tweak_sum);
/**
- * @brief コンストラクタ
+ * @brief constructor.
* @param[in] network_type network type
* @param[in] parent_key parent pubkey
* @param[in] parent_chain_code parent chain code
@@ -474,7 +543,7 @@ class CFD_CORE_EXPORT ExtPubkey {
const ByteData256& parent_chain_code, uint8_t parent_depth,
uint32_t child_num);
/**
- * @brief コンストラクタ
+ * @brief constructor.
* @param[in] network_type network type
* @param[in] parent_key parent pubkey
* @param[in] pubkey pubkey
@@ -486,7 +555,7 @@ class CFD_CORE_EXPORT ExtPubkey {
NetType network_type, const Pubkey& parent_key, const Pubkey& pubkey,
const ByteData256& chain_code, uint8_t depth, uint32_t child_num);
/**
- * @brief コンストラクタ
+ * @brief constructor.
* @param[in] network_type network type
* @param[in] parent_fingerprint parent fingerprint(4byte)
* @param[in] pubkey pubkey
@@ -500,37 +569,37 @@ class CFD_CORE_EXPORT ExtPubkey {
uint32_t child_num);
/**
- * @brief 拡張keyのSerialize情報を取得する.
+ * @brief Get Serialize information of extended key.
* @return serialize data
*/
ByteData GetData() const;
/**
- * @brief 拡張keyのBase58文字列を取得する.
+ * @brief Get the Base58 string of the extended key.
* @return base58 string
*/
std::string ToString() const;
/**
- * @brief Pubkeyインスタンスを取得する.
- * @return Pubkeyインスタンス
+ * @brief Get pubkey.
+ * @return Pubkey
*/
Pubkey GetPubkey() const;
/**
- * @brief 指定階層の拡張公開鍵を取得する。
+ * @brief Obtain the extended public key of the specified hierarchy.
* @param[in] child_num child number
* @return extended pubkey
* @throws CfdException If invalid seed.
*/
ExtPubkey DerivePubkey(uint32_t child_num) const;
/**
- * @brief 指定階層の拡張公開鍵を取得する。
+ * @brief Obtain the extended public key of the specified hierarchy.
* @param[in] path child number path
* @return extended pubkey
* @throws CfdException If invalid seed.
*/
ExtPubkey DerivePubkey(const std::vector& path) const;
/**
- * @brief 指定階層の拡張公開鍵を取得する。
+ * @brief Obtain the extended public key of the specified hierarchy.
* @param[in] string_path child number string path
* @return extended pubkey
* @throws CfdException If invalid seed.
@@ -538,61 +607,76 @@ class CFD_CORE_EXPORT ExtPubkey {
ExtPubkey DerivePubkey(const std::string& string_path) const;
/**
- * @brief 派生Pubkeyを生成する過程で生成されたtweak値の合成値を取得する。
+ * @brief Derive extended pubkey.
+ * @param[in] path child number path
+ * @return extended pubkey
+ * @throws CfdException If invalid seed.
+ */
+ KeyData DerivePubkeyData(const std::vector& path) const;
+ /**
+ * @brief Derive extended pubkey.
+ * @param[in] string_path child number string path
+ * @return extended pubkey
+ * @throws CfdException If invalid seed.
+ */
+ KeyData DerivePubkeyData(const std::string& string_path) const;
+
+ /**
+ * @brief Get the tweak value generated in the process of generating the derived Pubkey.
* @param[in] path child number path
* @return tweak sum
*/
ByteData256 DerivePubTweak(const std::vector& path) const;
/**
- * @brief 派生Pubkeyを生成する過程で生成されたtweak値の合成値を取得する。
+ * @brief Get the composite value of the tweak value generated in the process of generating the derived Pubkey.
* @return tweak sum
*/
ByteData256 GetPubTweakSum() const;
/**
- * @brief 状態が正常であるかを返却する.
- * @retval true 正常
- * @retval false 不正
+ * @brief Check if the data format is correct.
+ * @retval true valid
+ * @retval false invalid
*/
bool IsValid() const;
/**
- * @brief 拡張keyのDepthを取得する.
+ * @brief Get depth.
* @return depth value
*/
uint8_t GetDepth() const;
/**
- * @brief version部を取得する.
+ * @brief Get version.
* @return version data (4byte)
*/
uint32_t GetVersion() const;
/**
- * @brief child number部を取得する.
+ * @brief Get version.
+ * @return version data (4byte)
+ */
+ ByteData GetVersionData() const;
+ /**
+ * @brief Get child number.
* @return child number (4byte)
*/
uint32_t GetChildNum() const;
/**
- * @brief chain code部を取得する.
+ * @brief Get chain code.
* @return chain code (32byte)
*/
ByteData256 GetChainCode() const;
/**
- * @brief version部を取得する.
- * @return version data (4byte)
- */
- ByteData GetVersionData() const;
- /**
- * @brief fingerprint部を取得する.
+ * @brief Get fingerprint.
* @return fingerprint data (4byte)
*/
uint32_t GetFingerprint() const;
/**
- * @brief fingerprint部を取得する.
+ * @brief Get fingerprint.
* @return fingerprint data (4byte)
*/
ByteData GetFingerprintData() const;
/**
- * @brief get network type.
+ * @brief Get network type.
* @return network type.
*/
NetType GetNetworkType() const;
@@ -608,6 +692,222 @@ class CFD_CORE_EXPORT ExtPubkey {
ByteData256 tweak_sum_; //!< tweak sum
};
+/**
+ * @brief hardened string type.
+ */
+enum HardenedType {
+ kApostrophe = 0, //!< apostrophe
+ kLargeH = 1, //!< 'H'
+ kSmallH = 2, //!< 'h'
+ kNumber = 3, //!< number only (0x80000000)
+};
+
+/**
+ * @brief key and bip32 path information class.
+ */
+class CFD_CORE_EXPORT KeyData {
+ public:
+ /**
+ * @brief constructor.
+ */
+ KeyData();
+ /**
+ * @brief Get key text information from ext-privkey.
+ * @param[in] ext_privkey privkey
+ * @param[in] child_path bip32 path for child.
+ * @param[in] finterprint master-pubkey fingerprint
+ */
+ explicit KeyData(
+ const ExtPrivkey& ext_privkey, const std::string& child_path,
+ const ByteData& finterprint);
+ /**
+ * @brief Get key text information from ext-pubkey.
+ * @param[in] ext_pubkey pubkey
+ * @param[in] child_path bip32 path for child.
+ * @param[in] finterprint master-pubkey fingerprint
+ */
+ explicit KeyData(
+ const ExtPubkey& ext_pubkey, const std::string& child_path,
+ const ByteData& finterprint);
+ /**
+ * @brief Get key text information from privkey.
+ * @param[in] privkey privkey
+ * @param[in] child_path bip32 path for child.
+ * @param[in] finterprint master-pubkey fingerprint
+ */
+ explicit KeyData(
+ const Privkey& privkey, const std::string& child_path,
+ const ByteData& finterprint);
+ /**
+ * @brief Get key text information from pubkey.
+ * @param[in] pubkey pubkey
+ * @param[in] child_path bip32 path for child.
+ * @param[in] finterprint master-pubkey fingerprint
+ */
+ explicit KeyData(
+ const Pubkey& pubkey, const std::string& child_path,
+ const ByteData& finterprint);
+ /**
+ * @brief Get key text information from ext-privkey.
+ * @param[in] ext_privkey privkey
+ * @param[in] child_num_list bip32 path for child.
+ * @param[in] finterprint master-pubkey fingerprint
+ */
+ explicit KeyData(
+ const ExtPrivkey& ext_privkey,
+ const std::vector& child_num_list,
+ const ByteData& finterprint);
+ /**
+ * @brief Get key text information from ext-pubkey.
+ * @param[in] ext_pubkey pubkey
+ * @param[in] child_num_list bip32 path for child.
+ * @param[in] finterprint master-pubkey fingerprint
+ */
+ explicit KeyData(
+ const ExtPubkey& ext_pubkey, const std::vector& child_num_list,
+ const ByteData& finterprint);
+ /**
+ * @brief Get key text information from privkey.
+ * @param[in] privkey privkey
+ * @param[in] child_num_list bip32 path for child.
+ * @param[in] finterprint master-pubkey fingerprint
+ */
+ explicit KeyData(
+ const Privkey& privkey, const std::vector& child_num_list,
+ const ByteData& finterprint);
+ /**
+ * @brief Get key text information from pubkey.
+ * @param[in] pubkey pubkey
+ * @param[in] child_num_list bip32 path for child.
+ * @param[in] finterprint master-pubkey fingerprint
+ */
+ explicit KeyData(
+ const Pubkey& pubkey, const std::vector& child_num_list,
+ const ByteData& finterprint);
+ /**
+ * @brief Get key text information from string.
+ * @param[in] path_info key-path info.
+ * @param[in] child_num child number to use if an asterisk is used.
+ */
+ explicit KeyData(const std::string& path_info, int32_t child_num = -1);
+
+ /**
+ * @brief exist ext-privkey.
+ * @retval true exist
+ * @retval false not exist
+ */
+ bool HasExtPrivkey() const;
+ /**
+ * @brief exist ext-pubkey.
+ * @retval true exist
+ * @retval false not exist
+ */
+ bool HasExtPubkey() const;
+ /**
+ * @brief exist privkey.
+ * @retval true exist
+ * @retval false not exist
+ */
+ bool HasPrivkey() const;
+ /**
+ * @brief getting pubkey.
+ * @return pubkey
+ */
+ Pubkey GetPubkey() const;
+ /**
+ * @brief getting privkey.
+ * @return privkey
+ */
+ Privkey GetPrivkey() const;
+ /**
+ * @brief getting ext-privkey.
+ * @details need ext-privkey exists.
+ * @return ext-privkey
+ */
+ ExtPrivkey GetExtPrivkey() const;
+ /**
+ * @brief getting ext-pubkey.
+ * @details need ext-pubkey exists.
+ * @return ext-pubkey
+ */
+ ExtPubkey GetExtPubkey() const;
+
+ /**
+ * @brief Derive ext-privkey.
+ * @param[in] path path
+ * @param[in] has_rebase_path rebase path/fingerprint base
+ * @return path info with ext-privkey.
+ */
+ KeyData DerivePrivkey(
+ std::vector path, bool has_rebase_path) const;
+ /**
+ * @brief Derive ext-privkey.
+ * @param[in] path path
+ * @param[in] has_rebase_path rebase path/fingerprint base
+ * @return path info with ext-privkey.
+ */
+ KeyData DerivePrivkey(std::string path, bool has_rebase_path) const;
+ /**
+ * @brief Derive ext-pubkey.
+ * @param[in] path path
+ * @param[in] has_rebase_path rebase path/fingerprint base
+ * @return path info with ext-pubkey.
+ */
+ KeyData DerivePubkey(std::vector path, bool has_rebase_path) const;
+ /**
+ * @brief Derive ext-pubkey.
+ * @param[in] path path
+ * @param[in] has_rebase_path rebase path/fingerprint base
+ * @return path info with ext-pubkey.
+ */
+ KeyData DerivePubkey(std::string path, bool has_rebase_path) const;
+
+ /**
+ * @brief getting bip32 path.
+ * @param[in] hardened_type hardened string type
+ * @param[in] has_hex using hex string
+ * @return bip32 path
+ */
+ std::string GetBip32Path(
+ HardenedType hardened_type = HardenedType::kApostrophe,
+ bool has_hex = false) const;
+ /**
+ * @brief get message string.
+ * @param[in] has_pubkey displays the pubkey string.
+ * @param[in] hardened_type hardened string type
+ * @param[in] has_hex using hex string
+ * @return message string.
+ */
+ std::string ToString(
+ bool has_pubkey = true,
+ HardenedType hardened_type = HardenedType::kApostrophe,
+ bool has_hex = false) const;
+ /**
+ * @brief get fingerprint.
+ * @return fingerprint.
+ */
+ ByteData GetFingerprint() const;
+ /**
+ * @brief get child number array.
+ * @return child number array.
+ */
+ std::vector GetChildNumArray() const;
+ /**
+ * @brief check valid.
+ * @retval true valid
+ * @retval false invalid
+ */
+ bool IsValid() const;
+
+ private:
+ Pubkey pubkey_; //!< pubkey
+ Privkey privkey_; //!< privkey
+ ExtPrivkey extprivkey_; //!< ext privkey
+ ExtPubkey extpubkey_; //!< ext pubkey
+ std::vector path_; //!< bip32 path
+ ByteData fingerprint_; //!< fingerprint by key string
+};
+
} // namespace core
} // namespace cfd
diff --git a/include/cfdcore/cfdcore_iterator.h b/include/cfdcore/cfdcore_iterator.h
index 43acb3b7..7ffa48f4 100644
--- a/include/cfdcore/cfdcore_iterator.h
+++ b/include/cfdcore/cfdcore_iterator.h
@@ -2,7 +2,7 @@
/**
* @file cfdcore_iterator.h
*
- * @brief Iterator Wrapperクラス定義
+ * @brief The Iterator Wrapper class definition
*/
#ifndef CFD_CORE_INCLUDE_CFDCORE_CFDCORE_ITERATOR_H_
#define CFD_CORE_INCLUDE_CFDCORE_CFDCORE_ITERATOR_H_
@@ -19,14 +19,14 @@ namespace cfd {
namespace core {
/**
- * @brief IteratorのWrapperクラス
+ * @brief Iterator's Wrapper class.
*/
template
class IteratorWrapper {
public:
/**
* @brief constructor.
- * @details 引数で指定されたvectorのiterator wrapperインスタンスの作成をする.
+ * @details Create an iterator wrapper instance of the vector specified by the argument.
* @param vector
* @param error_message
* @param is_reverse
@@ -48,9 +48,10 @@ class IteratorWrapper {
// do nothing
}
/**
- * @brief 次の要素が取得可能であるかを返却する.
- * @retval true 次の要素が取得可能であるとき
- * @retval true 次の要素が取得できないとき(イテレータが末端を指しているとき)
+ * @brief Returns whether the next element is available.
+ * @retval true When the next element is available
+ * @retval false When the next element cannot be obtained \
+ * (when the iterator points to the end)
*/
bool hasNext() const {
if (reverse_) {
@@ -59,9 +60,10 @@ class IteratorWrapper {
return iterator_ != vector_.cend();
}
/**
- * @brief 前の要素が取得可能であるかを返却する.
- * @retval true 前の要素が取得可能であるとき
- * @retval true 前の要素が取得できないとき(イテレータが始端を指しているとき)
+ * @brief Returns whether the previous element is available.
+ * @retval true When the previous element is available
+ * @retval false When the previous element cannot be obtained \
+ * (when the iterator points to the beginning)
*/
bool hasBack() const {
if (reverse_) {
@@ -70,8 +72,8 @@ class IteratorWrapper {
return iterator_ != vector_.cbegin();
}
/**
- * @brief 次の要素を取得する.
- * @return 現在のイテレータの次の要素
+ * @brief Get the next element.
+ * @return The next element of the current iterator
*/
T next() {
if (!hasNext()) {
@@ -88,8 +90,8 @@ class IteratorWrapper {
return *(iterator_++);
}
/**
- * @brief 前の要素を取得する.
- * @return 現在のイテレータの次の要素
+ * @brief Get the previous element.
+ * @return The next element of the current iterator
*/
T back() {
if (!hasBack()) {
diff --git a/include/cfdcore/cfdcore_json_mapping_base.h b/include/cfdcore/cfdcore_json_mapping_base.h
index 55bd830a..bbb971a0 100644
--- a/include/cfdcore/cfdcore_json_mapping_base.h
+++ b/include/cfdcore/cfdcore_json_mapping_base.h
@@ -2,9 +2,9 @@
/**
* @file cfdcore_json_mapping_base.h
*
- * @brief JSON-クラスマッピング処理を定義するファイル。
+ * @brief JSON-A file that defines the class mapping process.
*
- * 継承クラスを作成して利用する。
+ * Create and use an inherited class.
*/
#ifndef CFD_CORE_INCLUDE_CFDCORE_CFDCORE_JSON_MAPPING_BASE_H_
#define CFD_CORE_INCLUDE_CFDCORE_CFDCORE_JSON_MAPPING_BASE_H_
@@ -30,10 +30,10 @@ namespace cfd {
namespace core {
// -----------------------------------------------------------------------------
-// クラス定義
+// Class definition
// -----------------------------------------------------------------------------
/**
- * @brief Get/Set/Type処理用のテンプレート構造体
+ * @brief Template structure for Get / Set / Type processing.
*/
template
struct CLASS_FUNCTION_TABLE {
@@ -43,15 +43,15 @@ struct CLASS_FUNCTION_TABLE {
};
/**
- * @brief Json型処理を行うためのマッピングテンプレート
+ * @brief Mapping template for Json type processing
*/
template
using JsonTableMap = std::map>;
/**
- * @brief 文字列変換を行います。
- * @param[in] value 変換元の値
- * @return 文字列変換後の値
+ * @brief Performs character string conversion.
+ * @param[in] value Source value
+ * @return Value after string conversion
*/
inline std::string ConvertToString(const uint32_t& value) { // NOLINT
UniValue json_value(static_cast(value));
@@ -60,18 +60,18 @@ inline std::string ConvertToString(const uint32_t& value) { // NOLINT
}
/**
- * @brief 文字列変換を行います。
- * @param[in] value 変換元の値
- * @return 文字列変換後の値
+ * @brief Performs character string conversion.
+ * @param[in] value Source value
+ * @return Value after string conversion
*/
inline std::string ConvertToString(const uint64_t& value) { // NOLINT
return std::to_string(value);
}
/**
- * @brief 文字列変換を行います。
- * @param[in] value 変換元の値
- * @return 文字列変換後の値
+ * @brief Performs character string conversion.
+ * @param[in] value Source value
+ * @return Value after string conversion
*/
template
inline std::string ConvertToString(const T& value) { // NOLINT
@@ -81,9 +81,9 @@ inline std::string ConvertToString(const T& value) { // NOLINT
}
/**
- * @brief UniValueオブジェクトからstring型に変換します。
- * @param[out] value 変換後の設定値
- * @param[in] json_value UniValueオブジェクト
+ * @brief Convert from UniValue object to string type.
+ * @param[out] value Set value after conversion
+ * @param[in] json_value UniValue object
*/
inline void ConvertFromUniValue(
std::string& value, // NOLINT
@@ -102,9 +102,9 @@ inline void ConvertFromUniValue(
}
/**
- * @brief UniValueオブジェクトからbool型に変換します。
- * @param[out] value 変換後の設定値
- * @param[in] json_value UniValueオブジェクト
+ * @brief Convert from UniValue object to bool type.
+ * @param[out] value Set value after conversion
+ * @param[in] json_value UniValue object
*/
inline void ConvertFromUniValue(
bool& value, const UniValue& json_value) { // NOLINT
@@ -122,9 +122,9 @@ inline void ConvertFromUniValue(
}
/**
- * @brief UniValueオブジェクトからdouble型に変換します。
- * @param[out] value 変換後の設定値
- * @param[in] json_value UniValueオブジェクト
+ * @brief Convert from UniValue object to double type.
+ * @param[out] value Set value after conversion
+ * @param[in] json_value UniValue object
*/
inline void ConvertFromUniValue(
double& value, const UniValue& json_value) { // NOLINT
@@ -142,9 +142,9 @@ inline void ConvertFromUniValue(
}
/**
- * @brief UniValueオブジェクトからfloat型に変換します。
- * @param[out] value 変換後の設定値
- * @param[in] json_value UniValueオブジェクト
+ * @brief Convert from UniValue object to float type.
+ * @param[out] value Set value after conversion
+ * @param[in] json_value UniValue object
*/
inline void ConvertFromUniValue(
float& value, const UniValue& json_value) { // NOLINT
@@ -162,9 +162,9 @@ inline void ConvertFromUniValue(
}
/**
- * @brief UniValueオブジェクトからfloat型に変換します。
- * @param[out] value 変換後の設定値
- * @param[in] json_value UniValueオブジェクト
+ * @brief Convert from UniValue object to unsigned 64bit type.
+ * @param[out] value Set value after conversion
+ * @param[in] json_value UniValue object
*/
inline void ConvertFromUniValue(
uint64_t& value, const UniValue& json_value) { // NOLINT
@@ -203,9 +203,9 @@ inline void ConvertFromUniValue(
}
/**
- * @brief UniValueオブジェクトから指定された型に変換します。
- * @param[out] value 変換後の設定値
- * @param[in] json_value UniValueオブジェクト
+ * @brief Convert from UniValue object to template type.
+ * @param[out] value Set value after conversion
+ * @param[in] json_value UniValue object
*/
template
inline void ConvertFromUniValue(
@@ -259,51 +259,51 @@ inline void ConvertFromUniValue(
}
}
-// テンプレートクラス(JSON処理のためテンプレートに)
+// Template class (in template for JSON processing)
/**
- * @brief Jsonマッピング変換クラスのベースクラス。
+ * @brief Base class for Json mapping transformation class.
*
- * 本ファイル下部のマクロを利用して継承クラスを定義する。
+ * Define the inherited class using the macro at the bottom of this file.
*/
template
class JsonClassBase {
public:
/**
- * @brief コンストラクタ
+ * @brief Constructor.
*/
JsonClassBase() {}
/**
- * @brief デストラクタ
+ * @brief Destructor.
*/
virtual ~JsonClassBase() {}
/**
- * @brief シリアライズ開始前にコールされる関数。
+ * @brief A function that is called before serialization begins.
*
- * 必要に応じて継承クラス側でオーバーライドする。
+ * Override on the inherited class side if necessary.
*/
virtual void PreSerialize() const {}
/**
- * @brief シリアライズ終了時にコールされる関数。
+ * @brief A function called at the end of serialization.
*
- * 必要に応じて継承クラス側でオーバーライドする。
+ * Override on the inherited class side if necessary.
*/
virtual void PostSerialize() const {}
/**
- * @brief デシリアライズ開始前にコールされる関数。
+ * @brief A function that is called before deserialization begins.
*
- * 必要に応じて継承クラス側でオーバーライドする。
+ * Override on the inherited class side if necessary.
*/
virtual void PreDeserialize() {}
/**
- * @brief デシリアライズ終了時にコールされる関数。
+ * @brief A function called at the end of deserialization.
*
- * 必要に応じて継承クラス側でオーバーライドする。
+ * Override on the inherited class side if necessary.
*/
virtual void PostDeserialize() {}
/**
- * @brief シリアライズ処理(JSON文字列化)を行う。
- * @return JSON文字列
+ * @brief Performs serialization processing (JSON character string conversion).
+ * @return JSON string
*/
virtual std::string Serialize() const {
PreSerialize();
@@ -339,8 +339,8 @@ class JsonClassBase {
}
/**
- * @brief デシリアライズ処理(JSONオブジェクト化)を行う。
- * @param[in] value JSON文字列
+ * @brief Perform deserialization processing (JSON objectization).
+ * @param[in] value JSON string.
*/
virtual void Deserialize(const std::string& value) {
UniValue object;
@@ -349,12 +349,12 @@ class JsonClassBase {
}
/**
- * @brief デシリアライズ処理(JSONオブジェクト化)を行う。
- * @param[in] value UniValueオブジェクト
+ * @brief Perform deserialization processing (JSON objectization).
+ * @param[in] value UniValue object.
*/
virtual void DeserializeUniValue(const UniValue& value) {
if (value.isArray()) {
- // rootがリスト1つの場合、子クラスに引継ぎ
+ // If root is one list, take over to child class
JsonTableMap mapper = GetJsonMapper();
if (mapper.size() == 1) {
PreDeserialize();
@@ -386,51 +386,54 @@ class JsonClassBase {
protected:
/**
- * @brief JSONマッピングオブジェクトを取得する。
+ * @brief Get the JSON mapping object.
*
- * テンプレートを用いる関係上、実態を有する継承クラス側で実装する。
- * @return JSONマッピングオブジェクト
+ * Since the template is used, it is implemented on the \
+ * inherited class side that has the actual situation.
+ * @return JSON mapping object.
*/
virtual const JsonTableMap& GetJsonMapper() const = 0;
/**
- * @brief JSONマッピングのアイテム一覧を取得する。
+ * @brief Get the JSON mapping item list.
*
- * 対象の変数名を、定義順序に従い一覧取得する。
- * テンプレートを用いる関係上、実態を有する継承クラス側で実装する。
- * @return JSONマッピングのアイテム一覧
+ * Get a list of target variable names according to the definition order.
+ * Since the template is used, it is implemented on the inherited class \
+ * side that has the actual situation.
+ * @return JSON mapping item list.
*/
virtual const std::vector& GetJsonItemList() const = 0;
/**
- * @brief JSONマッピング時に無視するアイテム一覧を取得する。
+ * @brief Get a list of items to ignore during JSON mapping.
*
- * Serialize時に対象の変数を無視する。
- * テンプレートを用いる関係上、実態を有する継承クラス側で実装する。
- * @return JSONマッピング時に無視するアイテム一覧
+ * Ignore the target variable when serializing.
+ * Since the template is used, it is implemented on the \
+ * inherited class side that has the actual situation.
+ * @return Item list to ignore when JSON mapping
*/
virtual const std::set& GetIgnoreItem() const = 0;
};
/**
- * @brief Jsonマッピング変換リストクラスのベースクラス。
+ * @brief Base class for Json mapping transformation list class.
*
- * 本ファイル下部のマクロを利用して継承クラスを定義する。
+ * Define the inherited class using the macro at the bottom of this file.
*/
template
class JsonVector : public std::vector {
public:
/**
- * @brief コンストラクタ
+ * @brief Constructor.
*/
JsonVector() {}
/**
- * @brief デストラクタ
+ * @brief Destructor.
*/
virtual ~JsonVector() {}
/**
- * @brief オペレーター(代入)
- * @param[in] obj 代入する側のインスタンス
- * @return 代入される側のインスタンス
+ * @brief Substitution operator.
+ * @param[in] obj instance.
+ * @return setting object.
*/
TYPE& operator=(const TYPE& obj) {
std::string serialize_string = obj.Serialize();
@@ -439,14 +442,14 @@ class JsonVector : public std::vector {
}
/**
- * @brief シリアライズ処理(JSON文字列化)を行う。
- * @return JSON文字列
+ * @brief Performs serialization processing (JSON character string conversion).
+ * @return JSON string
*/
virtual std::string Serialize() const = 0;
/**
- * @brief デシリアライズ処理(JSONオブジェクト化)を行う。
- * @param[in] value JSON文字列
+ * @brief Perform deserialization processing (JSON objectization).
+ * @param[in] value JSON string
*/
virtual void Deserialize(const std::string& value) {
UniValue object;
@@ -455,32 +458,32 @@ class JsonVector : public std::vector {
}
/**
- * @brief デシリアライズ処理(JSONオブジェクト化)を行う。
- * @param[in] value UniValueオブジェクト
+ * @brief Perform deserialization processing (JSON objectization).
+ * @param[in] value UniValue object
*/
virtual void DeserializeUniValue(const UniValue& value) = 0;
};
/**
- * @brief 設定値用のJsonマッピング変換リストクラスのベースクラス。
+ * @brief Base class of Json mapping transformation list class for settings.
*
- * 本ファイル下部のマクロを利用して継承クラスを定義する。
+ * Define the inherited class using the macro at the bottom of this file.
*/
template
class JsonValueVector : public JsonVector {
public:
/**
- * @brief コンストラクタ
+ * @brief Constructor.
*/
JsonValueVector() {}
/**
- * @brief デストラクタ
+ * @brief Destructor.
*/
virtual ~JsonValueVector() {}
/**
- * @brief シリアライズ処理(JSON文字列化)を行う。
- * @return JSON文字列
+ * @brief Performs serialization processing (JSON character string conversion).
+ * @return JSON string.
*/
virtual std::string Serialize() const {
std::string result;
@@ -505,8 +508,8 @@ class JsonValueVector : public JsonVector {
}
/**
- * @brief デシリアライズ処理(JSONオブジェクト化)を行う。
- * @param[in] value UniValueオブジェクト
+ * @brief Perform deserialization processing (JSON objectization).
+ * @param[in] value UniValue object.
*/
virtual void DeserializeUniValue(const UniValue& value) {
if (!value.isArray()) {
@@ -523,8 +526,8 @@ class JsonValueVector : public JsonVector {
}
/**
- * @brief Struct情報からの変換処理を行う。
- * @param[in] list リスト情報
+ * @brief Performs conversion processing from Struct information.
+ * @param[in] list List information
*/
void ConvertFromStruct(const std::vector& list) {
for (const auto& element : list) {
@@ -533,8 +536,8 @@ class JsonValueVector : public JsonVector {
}
/**
- * @brief Struct情報への変換処理を行う。
- * @return 変換済みリスト情報
+ * @brief Performs conversion processing to Struct information.
+ * @return Converted list information
*/
std::vector ConvertToStruct() const {
std::vector result;
@@ -547,25 +550,25 @@ class JsonValueVector : public JsonVector {
};
/**
- * @brief クラスオブジェクト用のJsonマッピング変換リストクラスのベースクラス。
+ * @brief Base class for Json mapping transformation list classes for class objects.
*
- * 本ファイル下部のマクロを利用して継承クラスを定義する。
+ * Define the inherited class using the macro at the bottom of this file.
*/
template
class JsonObjectVector : public JsonVector {
public:
/**
- * @brief コンストラクタ
+ * @brief Constructor.
*/
JsonObjectVector() {}
/**
- * @brief デストラクタ
+ * @brief Destructor.
*/
virtual ~JsonObjectVector() {}
/**
- * @brief シリアライズ処理(JSON文字列化)を行う。
- * @return JSON文字列
+ * @brief Performs serialization processing (JSON character string conversion).
+ * @return JSON string.
*/
virtual std::string Serialize() const {
std::string result;
@@ -590,8 +593,8 @@ class JsonObjectVector : public JsonVector {
}
/**
- * @brief デシリアライズ処理(JSONオブジェクト化)を行う。
- * @param[in] value UniValueオブジェクト
+ * @brief Perform deserialization processing (JSON objectization).
+ * @param[in] value UniValue object
*/
virtual void DeserializeUniValue(const UniValue& value) {
if (!value.isArray()) {
@@ -608,8 +611,8 @@ class JsonObjectVector : public JsonVector {
}
/**
- * @brief Struct情報からの変換処理を行う。
- * @param[in] list リスト情報
+ * @brief Performs conversion processing from Struct information.
+ * @param[in] list List information
*/
void ConvertFromStruct(const std::vector& list) {
for (const auto& element : list) {
@@ -620,8 +623,8 @@ class JsonObjectVector : public JsonVector {
}
/**
- * @brief Struct情報への変換処理を行う。
- * @return 変換済みリスト情報
+ * @brief Performs conversion processing to Struct information.
+ * @return Converted list information
*/
std::vector ConvertToStruct() const {
std::vector result;
diff --git a/include/cfdcore/cfdcore_json_writer.h b/include/cfdcore/cfdcore_json_writer.h
index c7f87ef1..a0366193 100644
--- a/include/cfdcore/cfdcore_json_writer.h
+++ b/include/cfdcore/cfdcore_json_writer.h
@@ -2,7 +2,7 @@
/**
* @file cfdcore_json_writer.h
*
- * @brief JSON文字列の生成時に使用にするクラスを定義する。
+ * @brief Define the class to be used when generating the JSON string.
*/
#ifndef CFD_CORE_INCLUDE_CFDCORE_CFDCORE_JSON_WRITER_H_
#define CFD_CORE_INCLUDE_CFDCORE_CFDCORE_JSON_WRITER_H_
@@ -16,75 +16,76 @@ namespace cfd {
namespace core {
/**
- * @brief Json生成時に利用するクラス。
+ * @brief Class used when generating Json.
*/
class JsonElement {
public:
/**
- * @brief コンストラクタ
- * @param[in] key キー値
+ * @brief Constructor.
+ * @param[in] key key
*/
explicit JsonElement(std::string key) : key_(key), value_() {}
/**
- * @brief コンストラクタ
- * @param[in] key キー値
- * @param[in] object エレメントオブジェクト
+ * @brief Constructor.
+ * @param[in] key key
+ * @param[in] object element object
*/
JsonElement(std::string key, const JsonElement& object)
: key_(key), value_(UniValue::VOBJ) {
value_.push_back(object.GetUnivalue());
}
/**
- * @brief コンストラクタ
- * @param[in] value UniValueオブジェクト
+ * @brief Constructor.
+ * @param[in] value UniValue object
*/
explicit JsonElement(const UniValue& value) : key_(), value_(value) {}
/**
- * @brief コンストラクタ
- * @param[in] key キー値
- * @param[in] value UniValueオブジェクト
+ * @brief Constructor.
+ * @param[in] key key
+ * @param[in] value UniValue object
*/
JsonElement(std::string key, const UniValue& value)
: key_(key), value_(value) {}
/**
- * @brief コンストラクタ
- * @param[in] key キー値
- * @param[in] value 設定値
+ * @brief Constructor.
+ * @param[in] key key
+ * @param[in] value value
*/
template
JsonElement(std::string key, TYPE value) : key_(key), value_(value) {}
/**
- * @brief デストラクタ
+ * @brief destructor.
*/
virtual ~JsonElement() {}
/**
- * @brief キー値を設定する。
- * @param[in] key キー値
+ * @brief Set the key.
+ * @param[in] key key
*/
void SetKey(const std::string& key) { key_ = key; }
/**
- * @brief キー値を取得する。
- * @return キー値
+ * @brief Get the key.
+ * @return key
*/
const std::string& GetKey() const { return key_; }
/**
- * @brief UniValue値を取得する。
- * @return UniValueオブジェクト
+ * @brief Get the UniValue object.
+ * @return UniValue object
*/
const UniValue& GetUnivalue() const { return value_; }
protected:
- std::string key_; ///< キー値
- UniValue value_; ///< UniValueオブジェクト
+ std::string key_; ///< key
+ UniValue value_; ///< UniValue object
};
/**
- * @brief Json生成用クラス。
+ * @brief Json generation class.
*
- * Json生成のみ対応。Json文字列からの変換には対応せず。
+ * Only Json generation is supported.
+ * Does not support conversion from Json strings.
*
- * イメージ(テスト実装)
+ * Image (test implementation):
* @code
* JsonBuilder jb;
* jb.Set(
@@ -110,24 +111,24 @@ class JsonElement {
*/
class JsonBuilder {
/**
- * @brief JsonElementの初期化子リスト
+ * @brief JsonElement initializer list
*/
using JsonElementInitialize = std::initializer_list;
public:
/**
- * @brief コンストラクタ
+ * @brief Constructor.
*/
JsonBuilder() : root_() {}
/**
- * @brief デストラクタ
+ * @brief Destructor.
*/
virtual ~JsonBuilder() {}
/**
- * @brief ルートに指定されたエレメントを設定する。
- * @param[in] value JsonElementオブジェクト
- * @param[in] args 可変引数(JsonElementオブジェクト)
+ * @brief Set the element specified in the root.
+ * @param[in] value JsonElement object
+ * @param[in] args Variadic argument (JsonElement object)
*/
template
void Set(const JsonElement& value, Args&&... args) {
@@ -148,49 +149,53 @@ class JsonBuilder {
}
/**
- * @brief JSON文字列を生成する。
- * @param[in] indent Indent値。0は整形なし(1行出力)。1以上は整形+指定値分Indentする。
- * @return JSON文字列
+ * @brief Generate a JSON string.
+ * @param[in] indent Indent value. \
+ * 0 is no formatting (1 line output). \
+ * 1 or more is shaped + indented by the specified value.
+ * @return JSON string
*/
std::string Build(int indent = 0) {
- // IndentLevel(writeの第二引数)はどうも((indent-1)*IndentLevel)分だけ2行目以降のIndentに加算するので、変えない方がいい。
- // 固定値加算ならともかく、なぜに乗算。
+ // IndentLevel (second argument of write function) is added to \
+ // Indent on the second and subsequent lines by \
+ // ((indent-1) * IndentLevel), so it is better not to change it.
+ // Why is it multiplying rather than adding at a fixed value.
return root_.write(indent);
}
/**
- * @brief 文字列型を生成する。
- * @param[in] key キー値
- * @param[in] value JsonElementオブジェクト
- * @return 文字列型を設定したJsonElement
+ * @brief Generate a string type.
+ * @param[in] key key
+ * @param[in] value JsonElement object
+ * @return JsonElement with string type set
*/
JsonElement Str(std::string key, const JsonElement& value) {
return JsonElement(key, value.GetUnivalue());
}
/**
- * @brief 文字列型を生成する。
- * @param[in] key キー値
- * @param[in] value stringオブジェクト
- * @return 文字列型を設定したJsonElement
+ * @brief Generate a string type.
+ * @param[in] key key
+ * @param[in] value string object
+ * @return JsonElement with string type set
*/
JsonElement Str(std::string key, const std::string& value) {
return JsonElement(key, value);
}
/**
- * @brief 数値型を生成する。
- * @param[in] key キー値
- * @param[in] value JsonElementオブジェクト
- * @return 数値型を設定したJsonElement
+ * @brief Generate a numeric type.
+ * @param[in] key key
+ * @param[in] value JsonElement object
+ * @return JsonElement with numeric type
*/
JsonElement Num(std::string key, const JsonElement& value) {
return JsonElement(key, value.GetUnivalue());
}
/**
- * @brief 数値列型を生成する。
- * @param[in] key キー値
- * @param[in] value 数値型の値
- * @return 数値型を設定したJsonElement
+ * @brief Generate a numeric type.
+ * @param[in] key key
+ * @param[in] value Numeric value
+ * @return JsonElement with numeric type
*/
template
JsonElement Num(std::string key, TYPE value) {
@@ -198,29 +203,29 @@ class JsonBuilder {
}
/**
- * @brief bool型を生成する。
- * @param[in] key キー値
- * @param[in] value JsonElementオブジェクト
- * @return bool型を設定したJsonElement
+ * @brief Generate a bool type.
+ * @param[in] key key
+ * @param[in] value JsonElement object
+ * @return JsonElement with bool type
*/
JsonElement Bool(std::string key, const JsonElement& value) {
return JsonElement(key, value.GetUnivalue());
}
/**
- * @brief bool型を生成する。
- * @param[in] key キー値
- * @param[in] is_true bool値
- * @return bool型を設定したJsonElement
+ * @brief Generate a bool type.
+ * @param[in] key key
+ * @param[in] is_true bool value
+ * @return JsonElement with bool type
*/
JsonElement Bool(std::string key, bool is_true) {
return JsonElement(key, is_true);
}
/**
- * @brief オブジェクト型を生成する。
- * @param[in] key キー値
- * @param[in] args オブジェクト型に設定するJsonElementオブジェクト
- * @return オブジェクト型を設定したJsonElement
+ * @brief Generate an object type.
+ * @param[in] key key
+ * @param[in] args JsonElement object to set to object type
+ * @return JsonElement with object type set
*/
template
JsonElement Object(std::string key, Args&&... args) {
@@ -231,10 +236,10 @@ class JsonBuilder {
}
/**
- * @brief Array型を生成する。
- * @param[in] key キー値
- * @param[in] args Array型に設定するJsonElementオブジェクト
- * @return Array型を設定したJsonElement
+ * @brief Generate Array type.
+ * @param[in] key key
+ * @param[in] args JsonElement object set to Array type
+ * @return JsonElement with Array type set
*/
template
JsonElement Array(std::string key, Args&&... args) {
@@ -245,28 +250,28 @@ class JsonBuilder {
}
/**
- * @brief 文字列型を生成する。
- * @param[in] value JsonElementオブジェクト
- * @return 文字列型を設定したJsonElement
+ * @brief Generate a string type.
+ * @param[in] value JsonElement object
+ * @return JsonElement with string type set
*/
JsonElement StrV(const JsonElement& value) { return Str("", value); }
/**
- * @brief 文字列型を生成する。
- * @param[in] value stringオブジェクト
- * @return 文字列型を設定したJsonElement
+ * @brief Generate a string type.
+ * @param[in] value string object
+ * @return JsonElement with string type set
*/
JsonElement StrV(const std::string& value) { return Str("", value); }
/**
- * @brief 数値型を生成する。
- * @param[in] value JsonElementオブジェクト
- * @return 数値型を設定したJsonElement
+ * @brief Generate a numeric type.
+ * @param[in] value JsonElement object
+ * @return JsonElement with numeric type
*/
JsonElement NumV(const JsonElement& value) { return Num("", value); }
/**
- * @brief 数値列型を生成する。
- * @param[in] value 数値型の値
- * @return 数値型を設定したJsonElement
+ * @brief Generate a numeric type.
+ * @param[in] value Numeric value
+ * @return JsonElement with numeric type
*/
template
JsonElement NumV(TYPE value) {
@@ -274,22 +279,22 @@ class JsonBuilder {
}
/**
- * @brief bool型を生成する。
- * @param[in] value JsonElementオブジェクト
- * @return bool型を設定したJsonElement
+ * @brief Generate a bool type.
+ * @param[in] value JsonElement object
+ * @return JsonElement with bool type
*/
JsonElement BoolV(const JsonElement& value) { return Bool("", value); }
/**
- * @brief bool型を生成する。
- * @param[in] is_true bool値
- * @return bool型を設定したJsonElement
+ * @brief Generate a bool type.
+ * @param[in] is_true bool value
+ * @return JsonElement with bool type
*/
JsonElement BoolV(bool is_true) { return Bool("", is_true); }
/**
- * @brief オブジェクト型を生成する。
- * @param[in] args オブジェクト型に設定するJsonElementオブジェクト
- * @return オブジェクト型を設定したJsonElement
+ * @brief Generate an object type.
+ * @param[in] args JsonElement object set to object type
+ * @return JsonElement with object type set
*/
template
JsonElement ObjectV(Args&&... args) {
@@ -300,9 +305,9 @@ class JsonBuilder {
}
/**
- * @brief Array型を生成する。
- * @param[in] args Array型に設定するJsonElementオブジェクト
- * @return Array型を設定したJsonElement
+ * @brief Generate Array type.
+ * @param[in] args JsonElement object set to Array type
+ * @return JsonElement with Array type set
*/
template
JsonElement ArrayV(Args&&... args) {
@@ -313,7 +318,7 @@ class JsonBuilder {
}
private:
- UniValue root_; ///< UniValueオブジェクト
+ UniValue root_; ///< UniValue object
};
} // namespace core
diff --git a/include/cfdcore/cfdcore_key.h b/include/cfdcore/cfdcore_key.h
index fcc2acde..d930e842 100644
--- a/include/cfdcore/cfdcore_key.h
+++ b/include/cfdcore/cfdcore_key.h
@@ -1,8 +1,8 @@
-// Copyright 2019 CryptoGarage
+// Copyright 2020 CryptoGarage
/**
* @file cfdcore_key.h
*
- * @brief Pubkey/Privkey関連クラス定義
+ * @brief definition for Pubkey/Privkey class
*/
#ifndef CFD_CORE_INCLUDE_CFDCORE_CFDCORE_KEY_H_
#define CFD_CORE_INCLUDE_CFDCORE_CFDCORE_KEY_H_
@@ -18,7 +18,7 @@ namespace core {
/**
* @typedef NetType
- * @brief Bitcoin networkの定義
+ * @brief definition for Bitcoin/Liquid network.
*/
typedef enum {
kMainnet = 0, //!< MAINNET
@@ -31,7 +31,7 @@ typedef enum {
} NetType;
/**
- * @brief PublicKeyを表現するデータクラス
+ * @brief Data class representing PublicKey
*/
class CFD_CORE_EXPORT Pubkey {
public:
@@ -45,37 +45,38 @@ class CFD_CORE_EXPORT Pubkey {
static constexpr uint32_t kCompressedPubkeySize = 33;
/**
- * @brief デフォルトコンストラクタ
+ * @brief constructor
*/
Pubkey();
/**
- * @brief コンストラクタ
- * @param[in] byte_data 公開鍵のByteDataインスタンス
+ * @brief constructor
+ * @param[in] byte_data Public key ByteData instance
*/
explicit Pubkey(ByteData byte_data);
/**
- * @brief HEX文字列からPublicKeyモデルを復元するコンストラクタ.
- * @param[in] hex_string PublicKeyのHEX文字列
+ * @brief constructor
+ * @param[in] hex_string Public Key HEX string
*/
explicit Pubkey(const std::string &hex_string);
/**
- * @brief 自身のByteDataからHEX文字列を取得する.
- * @return 公開鍵のHEX文字列
+ * @brief Get HEX string.
+ * @return HEX string.
*/
std::string GetHex() const;
/**
- * @brief 自身のByteDataを取得する.
- * @return 公開鍵のByteData
+ * @brief Get ByteData instance.
+ * @return ByteData
*/
ByteData GetData() const;
/**
- * @brief 公開鍵がCompress形式であるかを返却する.
- * @return Compressであればtrue, Uncompressであればfalse
+ * @brief Returns whether the public key is in Compress format.
+ * @retval true compressed key.
+ * @retval false uncompressed key.
*/
bool IsCompress() const;
@@ -87,32 +88,39 @@ class CFD_CORE_EXPORT Pubkey {
bool IsParity() const;
/**
- * @brief 公開鍵として正しい形式であるかを検証する.
- * @retval true 正常フォーマット
- * @retval false 不正フォーマット
+ * @brief Verify that the public key is in the correct format.
+ * @retval true valid format
+ * @retval false invalid format
*/
bool IsValid() const;
/**
- * @brief 公開鍵が一致するかチェックする.
- * @param[in] pubkey 比較対象Pubkey
- * @retval true 一致
- * @retval false 不一致
+ * @brief Check if the public keys match.
+ * @param[in] pubkey check target Pubkey
+ * @retval true equal
+ * @retval false not equal
*/
bool Equals(const Pubkey &pubkey) const;
/**
- * @brief 合成Pubkeyを生成する.
- * @param[in] pubkeys 合成元Pubkey list
- * @return 合成したPubkeyインスタンス
+ * @brief Get fingerprint.
+ * @param[in] get_size get fingerprint size.
+ * @return fingerprint
+ */
+ ByteData GetFingerprint(uint32_t get_size = 4) const;
+
+ /**
+ * @brief Combine pubkeys.
+ * @param[in] pubkeys Pubkey list
+ * @return Combined pubkey
*/
static Pubkey CombinePubkey(const std::vector &pubkeys);
/**
- * @brief 合成Pubkeyを生成する.
- * @param[in] pubkey 合成元Pubkey
- * @param[in] message_key 合成するmessage Pubkey
- * @return 合成したPubkeyインスタンス
+ * @brief Combine pubkey.
+ * @param[in] pubkey base pubkey
+ * @param[in] message_key combine pubkey
+ * @return Combined pubkey
*/
static Pubkey CombinePubkey(const Pubkey &pubkey, const Pubkey &message_key);
@@ -164,19 +172,19 @@ class CFD_CORE_EXPORT Pubkey {
const ByteData256 &signature_hash, const ByteData &signature) const;
/**
- * @brief 公開鍵として正しい形式であるかを検証する.
- * @param[in] byte_data 公開鍵のByteData
- * @retval true 正常フォーマット
- * @retval false 不正フォーマット
+ * @brief Verify that the public key is in the correct format.
+ * @param[in] byte_data pubkey bytedata
+ * @retval true valid format
+ * @retval false invalid format
*/
static bool IsValid(const ByteData &byte_data);
/**
- * @brief 指定された2つの公開鍵のHEX値を比較する.
+ * @brief Compare the HEX values of the two specified public keys.
* @param[in] source source target
* @param[in] destination destination target
- * @retval true 大きい
- * @retval false 小さい
+ * @retval true Large
+ * @retval false Small
*/
static bool IsLarge(const Pubkey &source, const Pubkey &destination);
@@ -213,7 +221,7 @@ class CFD_CORE_EXPORT Pubkey {
};
/**
- * @brief Private Keyを表現するデータクラス
+ * @brief Data class representing Private Key
*/
class CFD_CORE_EXPORT Privkey {
public:
@@ -222,52 +230,69 @@ class CFD_CORE_EXPORT Privkey {
*/
static constexpr uint32_t kPrivkeySize = 32; // EC_PRIVATE_KEY_LEN
/**
- * @brief デフォルトコンストラクタ
+ * @brief default constructor.
*/
Privkey();
/**
- * @brief コンストラクタ
- * @param[in] byte_data 秘密鍵のByteDataインスタンス
+ * @brief constructor.
+ * @param[in] byte_data ByteData object.
+ * @param[in] net_type Mainnet or Testnet
+ * @param[in] is_compressed pubkey compressed flag.
*/
- explicit Privkey(const ByteData &byte_data);
+ explicit Privkey(
+ const ByteData &byte_data, NetType net_type = NetType::kMainnet,
+ bool is_compressed = true);
/**
- * @brief コンストラクタ
- * @param[in] byte_data 秘密鍵のByteDataインスタンス
+ * @brief constructor.
+ * @param[in] byte_data ByteData object.
+ * @param[in] net_type Mainnet or Testnet
+ * @param[in] is_compressed pubkey compressed flag.
*/
- explicit Privkey(const ByteData256 &byte_data);
+ explicit Privkey(
+ const ByteData256 &byte_data, NetType net_type = NetType::kMainnet,
+ bool is_compressed = true);
/**
- * @brief 文字列からPrivateKeyモデルを復元するコンストラクタ.
- * @param[in] hex_str PrivateKeyのHEX文字列
+ * @brief constructor.
+ * @param[in] hex_str PrivateKey HEX string
+ * @param[in] net_type Mainnet or Testnet
+ * @param[in] is_compressed pubkey compressed flag.
*/
- explicit Privkey(const std::string &hex_str);
+ explicit Privkey(
+ const std::string &hex_str, NetType net_type = NetType::kMainnet,
+ bool is_compressed = true);
/**
- * @brief 自身のByteDataからHEX文字列を取得する.
- * @return 秘密鍵のHEX文字列
+ * @brief Get HEX string.
+ * @return HEX string
*/
std::string GetHex() const;
/**
- * @brief 自身のByteDataを取得する.
- * @return 秘密鍵のByteData
+ * @brief Get ByteData instance.
+ * @return ByteData
*/
ByteData GetData() const;
/**
- * @brief WIFに変換する.
+ * @brief Convert to WIF.
* @param[in] net_type Mainnet or Testnet
- * @param[in] is_compressed privatekeyから導出するpubkeyのcompress有無
- * @return WIF文字列
+ * @param[in] is_compressed pubkey compressed flag.
+ * @return WIF
*/
std::string ConvertWif(NetType net_type, bool is_compressed = true) const;
+ /**
+ * @brief Get Wallet Import Format from member value.
+ * @return WIF
+ */
+ std::string GetWif() const;
/**
- * @brief Private keyからPubkeyインスタンスを生成する.
- * @param[in] is_compressed privatekeyから導出するpubkeyのcompress有無
- * @return Pubkeyインスタンス
+ * @brief Generate pubkey to privkey.
+ * @param[in] is_compressed pubkey compressed flag.
+ * @return Pubkey
*/
Pubkey GeneratePubkey(bool is_compressed = true) const;
@@ -320,17 +345,17 @@ class CFD_CORE_EXPORT Privkey {
Privkey CreateNegate() const;
/**
- * @brief PrivateKeyの設定状態が不正であるかを返却する.
- * @retval true 状態が不正
- * @retval false 状態は正常
- * @deprecated API整理時に削除予定
+ * @brief Returns whether the private key setting status is invalid.
+ * @retval true invalid
+ * @retval false valid
+ * @deprecated Scheduled to be deleted when organizing API
*/
bool IsInvalid() const;
/**
- * @brief PrivateKeyの設定状態が正常であるかを返却する.
- * @retval true 状態は正常
- * @retval false 状態が不正
+ * @brief Returns whether the Private Key setting status is normal.
+ * @retval true valid
+ * @retval false invalid
*/
bool IsValid() const;
@@ -356,22 +381,28 @@ class CFD_CORE_EXPORT Privkey {
* @param[in] is_compressed pubkey compressed.
*/
void SetPubkeyCompressed(bool is_compressed);
+ /**
+ * @brief set network type.
+ * @param[in] net_type network type.
+ */
+ void SetNetType(NetType net_type);
/**
- * @brief WIFからPrivKeyインスタンスを生成する.
- * @param[in] wif WIF文字列
+ * @brief Generate privkey from WIF.
+ * @param[in] wif WIF
* @param[in] net_type Mainnet or Testnet
- * @param[in] is_compressed privatekeyから導出するpubkeyのcompress有無
- * @return Privkeyインスタンス
+ * @param[in] is_compressed pubkey compress flag.
+ * @return Privkey
*/
static Privkey FromWif(
- const std::string &wif, NetType net_type, bool is_compressed = true);
+ const std::string &wif, NetType net_type = NetType::kCustomChain,
+ bool is_compressed = true);
/**
- * @brief 乱数からPrivkeyインスタンスを生成する.
+ * @brief Generate Privkey from random numbers.
*
- * 生成できるまで繰り返すため、時間がかかる場合がある.
- * @return Privkeyインスタンス
+ * It may take some time because it repeats until it can be generated.
+ * @return Privkey
*/
static Privkey GenerageRandomKey();
@@ -433,12 +464,16 @@ class CFD_CORE_EXPORT Privkey {
* @brief pubkey compressed.
*/
bool is_compressed_ = true;
+ /**
+ * @brief network type.
+ */
+ NetType net_type_ = NetType::kMainnet;
/**
- * @brief 秘密鍵として正しい形式であるかを検証する.
- * @param[in] buffer 秘密鍵のByteData
- * @retval true 正常フォーマット
- * @retval false 不正フォーマット
+ * @brief Verify that it is in the correct format as a private key.
+ * @param[in] buffer ByteData of privkey.
+ * @retval true valid
+ * @retval false invalid
*/
static bool IsValid(const std::vector &buffer);
};
diff --git a/include/cfdcore/cfdcore_logger_interface.h b/include/cfdcore/cfdcore_logger_interface.h
index 4c97742e..70c957c9 100644
--- a/include/cfdcore/cfdcore_logger_interface.h
+++ b/include/cfdcore/cfdcore_logger_interface.h
@@ -2,7 +2,7 @@
/**
* @file cfdcore_logger_interface.h
*
- * @brief ログ処理のインタフェースを定義するファイル。
+ * @brief A file that defines the interface for log processing.
*/
#ifndef CFD_CORE_INCLUDE_CFDCORE_CFDCORE_LOGGER_INTERFACE_H_
#define CFD_CORE_INCLUDE_CFDCORE_CFDCORE_LOGGER_INTERFACE_H_
@@ -13,19 +13,19 @@ namespace cfd {
namespace core {
/**
- * @brief ログ出力用の関数ポインタを設定する。
- * @param[in] function_address 関数ポインタ
+ * @brief Set a function pointer for log output.
+ * @param[in] function_address Function pointer
*/
CFD_CORE_API void SetLogger(void* function_address);
/**
- * @brief ログ機能の初期化を行う。
+ * @brief Initialize the log function.
*/
CFD_CORE_API void InitializeLogger(void);
/**
- * @brief ログ機能の終了処理を行う。
- * @param[in] is_finish_process プロセス終了時かどうか
+ * @brief Performs termination processing of the log function.
+ * @param[in] is_finish_process Whether at the end of the process
*/
CFD_CORE_API void FinalizeLogger(bool is_finish_process = false);
diff --git a/include/cfdcore/cfdcore_psbt.h b/include/cfdcore/cfdcore_psbt.h
new file mode 100644
index 00000000..bb8a24dc
--- /dev/null
+++ b/include/cfdcore/cfdcore_psbt.h
@@ -0,0 +1,731 @@
+// Copyright 2020 CryptoGarage
+/**
+ * @file cfdcore_psbt.h
+ *
+ * @brief This file is defines Partially Signed Bitcoin Transaction.
+ *
+ */
+#ifndef CFD_CORE_INCLUDE_CFDCORE_CFDCORE_PSBT_H_
+#define CFD_CORE_INCLUDE_CFDCORE_CFDCORE_PSBT_H_
+
+#include
+#include
+#include
+
+#include "cfdcore/cfdcore_address.h"
+#include "cfdcore/cfdcore_hdwallet.h"
+#include "cfdcore/cfdcore_transaction.h"
+
+namespace cfd {
+namespace core {
+
+/**
+ * @brief The class of Partially Signed Bitcoin Transaction.
+ */
+class CFD_CORE_EXPORT Psbt {
+ public:
+ //! PSBT_GLOBAL_UNSIGNED_TX
+ static constexpr uint8_t kPsbtGlobalUnsignedTx = 0x00;
+ //! PSBT_GLOBAL_XPUB
+ static constexpr uint8_t kPsbtGlobalXpub = 0x01;
+ //! PSBT_GLOBAL_VERSION
+ static constexpr uint8_t kPsbtGlobalVersion = 0xfb;
+ //! PSBT_GLOBAL_PROPRIETARY
+ static constexpr uint8_t kPsbtGlobalProprietary = 0xfc;
+ //! PSBT_IN_NON_WITNESS_UTXO
+ static constexpr uint8_t kPsbtInputNonWitnessUtxo = 0x00;
+ //! PSBT_IN_WITNESS_UTXO
+ static constexpr uint8_t kPsbtInputWitnessUtxo = 0x01;
+ //! PSBT_IN_PARTIAL_SIG
+ static constexpr uint8_t kPsbtInputPartialSig = 0x02;
+ //! PSBT_IN_SIGHASH_TYPE
+ static constexpr uint8_t kPsbtInputSighashType = 0x03;
+ //! PSBT_IN_REDEEM_SCRIPT
+ static constexpr uint8_t kPsbtInputRedeemScript = 0x04;
+ //! PSBT_IN_WITNESS_SCRIPT
+ static constexpr uint8_t kPsbtInputWitnessScript = 0x05;
+ //! PSBT_IN_BIP32_DERIVATION
+ static constexpr uint8_t kPsbtInputBip32Derivation = 0x06;
+ //! PSBT_IN_FINAL_SCRIPTSIG
+ static constexpr uint8_t kPsbtInputFinalScriptsig = 0x07;
+ //! PSBT_IN_FINAL_SCRIPTWITNESS
+ static constexpr uint8_t kPsbtInputFinalScriptWitness = 0x08;
+ //! PSBT_IN_POR_COMMITMENT
+ static constexpr uint8_t kPsbtInputPorCommitment = 0x09;
+ //! PSBT_IN_RIPEMD160
+ static constexpr uint8_t kPsbtInputRipemd160 = 0x0a;
+ //! PSBT_IN_SHA256
+ static constexpr uint8_t kPsbtInputSha256 = 0x0b;
+ //! PSBT_IN_HASH160
+ static constexpr uint8_t kPsbtInputHash160 = 0x0c;
+ //! PSBT_IN_HASH256
+ static constexpr uint8_t kPsbtInputHash256 = 0x0d;
+ //! PSBT_IN_PROPRIETARY
+ static constexpr uint8_t kPsbtInputProprietary = 0xfc;
+ //! PSBT_OUT_REDEEM_SCRIPT
+ static constexpr uint8_t kPsbtOutputRedeemScript = 0x00;
+ //! PSBT_OUT_WITNESS_SCRIPT
+ static constexpr uint8_t kPsbtOutputWitnessScript = 0x01;
+ //! PSBT_OUT_BIP32_DERIVATION
+ static constexpr uint8_t kPsbtOutputBip32Derivation = 0x02;
+ //! PSBT_OUT_PROPRIETARY
+ static constexpr uint8_t kPsbtOutputProprietary = 0xfc;
+
+ /**
+ * @brief Get PSBT default version.
+ * @return PSBT version.
+ */
+ static uint32_t GetDefaultVersion();
+ /**
+ * @brief Create psbt record key.
+ * @param[in] type key type.
+ * @return key data.
+ */
+ static ByteData CreateRecordKey(uint8_t type);
+ /**
+ * @brief Create psbt fix size record key.
+ * @param[in] type key type.
+ * @param[in] fixed_size_key fixed size key value.
+ * @return key data.
+ */
+ static ByteData CreateFixRecordKey(
+ uint8_t type, const ByteData& fixed_size_key);
+ /**
+ * @brief Create psbt record key.
+ * @param[in] type key type.
+ * @param[in] key_bytes key value.
+ * @return key data.
+ */
+ static ByteData CreateRecordKey(uint8_t type, const ByteData& key_bytes);
+ /**
+ * @brief Create psbt record key.
+ * @param[in] type key type.
+ * @param[in] key key value.
+ * @return key data.
+ */
+ static ByteData CreateRecordKey(uint8_t type, const std::string& key);
+ /**
+ * @brief Create psbt record key.
+ * @param[in] type key type.
+ * @param[in] prefix key prefix.
+ * @param[in] sub_type sub field key type.
+ * @return key data.
+ */
+ static ByteData CreateRecordKey(
+ uint8_t type, const ByteData& prefix, uint8_t sub_type);
+ /**
+ * @brief Create psbt record key.
+ * @param[in] type key type.
+ * @param[in] prefix key prefix.
+ * @param[in] sub_type sub field key type.
+ * @return key data.
+ */
+ static ByteData CreateRecordKey(
+ uint8_t type, const std::string& prefix, uint8_t sub_type);
+ /**
+ * @brief Create psbt record key.
+ * @param[in] type key type.
+ * @param[in] prefix key prefix.
+ * @param[in] sub_type sub field key type.
+ * @param[in] sub_key_bytes sub field key value.
+ * @return key data.
+ */
+ static ByteData CreateRecordKey(
+ uint8_t type, const ByteData& prefix, uint8_t sub_type,
+ const ByteData& sub_key_bytes);
+ /**
+ * @brief Create psbt record key.
+ * @param[in] type key type.
+ * @param[in] prefix key prefix.
+ * @param[in] sub_type sub field key type.
+ * @param[in] sub_key sub field key value.
+ * @return key data.
+ */
+ static ByteData CreateRecordKey(
+ uint8_t type, const std::string& prefix, uint8_t sub_type,
+ const std::string& sub_key);
+ /**
+ * @brief Create psbt pubkey record key.
+ * @param[in] type key type.
+ * @param[in] pubkey pubkey value.
+ * @return key data.
+ */
+ static ByteData CreatePubkeyRecordKey(uint8_t type, const Pubkey& pubkey);
+
+ /**
+ * @brief constructor.
+ *
+ * for List.
+ */
+ Psbt();
+ /**
+ * @brief constructor
+ * @param[in] version tx version
+ * @param[in] lock_time lock time
+ */
+ explicit Psbt(uint32_t version, uint32_t lock_time);
+ /**
+ * @brief constructor
+ * @param[in] psbt_version psbt version
+ * @param[in] version tx version
+ * @param[in] lock_time lock time
+ */
+ explicit Psbt(uint32_t psbt_version, uint32_t version, uint32_t lock_time);
+ /**
+ * @brief constructor
+ * @param[in] base64 base64 string.
+ */
+ explicit Psbt(const std::string& base64);
+ /**
+ * @brief constructor
+ * @param[in] byte_data byte data
+ */
+ explicit Psbt(const ByteData& byte_data);
+ /**
+ * @brief constructor
+ * @param[in] transaction Transaction object.
+ */
+ explicit Psbt(const Transaction& transaction);
+ /**
+ * @brief constructor
+ * @param[in] psbt_version psbt version
+ * @param[in] transaction Transaction object.
+ */
+ explicit Psbt(uint32_t psbt_version, const Transaction& transaction);
+ /**
+ * @brief constructor
+ * @param[in] psbt Psbt object.
+ */
+ Psbt(const Psbt& psbt);
+ /**
+ * @brief destructor
+ */
+ virtual ~Psbt() { Psbt::FreeWallyPsbtAddress(wally_psbt_pointer_); }
+
+ /**
+ * @brief copy constructor.
+ * @param[in] psbt Psbt object.
+ * @return Psbt object.
+ */
+ Psbt& operator=(const Psbt& psbt) &;
+
+ /**
+ * @brief Get base64 string.
+ * @return base64 string.
+ */
+ std::string GetBase64() const;
+
+ /**
+ * @brief Get binary data.
+ * @return binary data.
+ */
+ ByteData GetData() const;
+
+ /**
+ * @brief Get binary size.
+ * @return binary size.
+ */
+ uint32_t GetDataSize() const;
+
+ /**
+ * @brief check finalized.
+ * @retval true already finalized.
+ * @retval false not finalized.
+ */
+ bool IsFinalized() const;
+
+ /**
+ * @brief check finalized input.
+ * @param[in] index txin index.
+ * @retval true already finalized input.
+ * @retval false not finalized input.
+ */
+ bool IsFinalizedInput(uint32_t index) const;
+
+ /**
+ * @brief finalize input all.
+ * @details support hashtype is p2pkh, p2wpkh, p2sh-p2wpkh, multisig(p2sh, p2wsh, p2sh-p2wsh)
+ */
+ void Finalize();
+
+ /**
+ * @brief extract transaction.
+ * @details need already finalized.
+ * @return binary transaction data.
+ */
+ ByteData Extract() const;
+
+ /**
+ * @brief extract transaction.
+ * @details need already finalized.
+ * @return transactiona.
+ */
+ Transaction ExtractTransaction() const;
+
+ /**
+ * @brief Get currently base transaction.
+ * @return base transaction.
+ */
+ Transaction GetTransaction() const;
+
+ /**
+ * @brief Join psbt transaction before sign.
+ * @param[in] transaction psbt transaction.
+ * @param[in] ignore_duplicate_error ignore duplicate parameter error.
+ */
+ void Join(const Psbt& transaction, bool ignore_duplicate_error = false);
+
+ /**
+ * @brief Sign psbt transaction.
+ * @param[in] privkey private key.
+ * @param[in] has_grind_r Grind-R option.
+ */
+ void Sign(const Privkey& privkey, bool has_grind_r = true);
+
+ /**
+ * @brief Combine signed psbt transaction.
+ * @param[in] transaction signed psbt transaction.
+ */
+ void Combine(const Psbt& transaction);
+
+ /**
+ * @brief Get txin count.
+ * @return txin count.
+ */
+ uint32_t GetTxInCount() const;
+
+ /**
+ * @brief Get txout count.
+ * @return txout count.
+ */
+ uint32_t GetTxOutCount() const;
+
+ /**
+ * @brief add base transaction input.
+ * @param[in] txin transaction input.
+ * @return added index.
+ */
+ uint32_t AddTxIn(const TxIn& txin);
+ /**
+ * @brief add base transaction input.
+ * @param[in] txin transaction input.
+ * @return added index.
+ */
+ uint32_t AddTxIn(const TxInReference& txin);
+ /**
+ * @brief add base transaction input.
+ * @param[in] txid utxo txid.
+ * @param[in] vout utxo vout.
+ * @param[in] sequence sequence.
+ * @return added index.
+ */
+ uint32_t AddTxIn(const Txid& txid, uint32_t vout, uint32_t sequence);
+
+ /**
+ * @brief set input utxo data.
+ * @param[in] index input index
+ * @param[in] tx utxo transaction
+ * @param[in] key utxo related pubkey
+ */
+ void SetTxInUtxo(uint32_t index, const Transaction& tx, const KeyData& key);
+ /**
+ * @brief set input utxo data.
+ * @param[in] index input index
+ * @param[in] tx utxo transaction
+ * @param[in] redeem_script utxo related script (only script hash)
+ * @param[in] key utxo related pubkey
+ */
+ void SetTxInUtxo(
+ uint32_t index, const Transaction& tx, const Script& redeem_script,
+ const KeyData& key);
+ /**
+ * @brief set input utxo data.
+ * @param[in] index input index
+ * @param[in] tx utxo transaction
+ * @param[in] redeem_script utxo related script (only script hash)
+ * @param[in] key_list utxo related pubkey list
+ */
+ void SetTxInUtxo(
+ uint32_t index, const Transaction& tx, const Script& redeem_script,
+ const std::vector& key_list);
+ /**
+ * @brief set input utxo data.
+ * @param[in] index input index
+ * @param[in] txout utxo witness transaction output
+ * @param[in] key utxo related pubkey
+ */
+ void SetTxInUtxo(
+ uint32_t index, const TxOutReference& txout, const KeyData& key);
+ /**
+ * @brief set input utxo data.
+ * @param[in] index input index
+ * @param[in] txout utxo witness transaction output
+ * @param[in] redeem_script utxo related script (only script hash)
+ * @param[in] key utxo related pubkey
+ */
+ void SetTxInUtxo(
+ uint32_t index, const TxOutReference& txout, const Script& redeem_script,
+ const KeyData& key);
+ /**
+ * @brief set input utxo data.
+ * @param[in] index input index
+ * @param[in] txout utxo witness transaction output
+ * @param[in] redeem_script utxo related script (only script hash)
+ * @param[in] key_list utxo related pubkey list
+ */
+ void SetTxInUtxo(
+ uint32_t index, const TxOutReference& txout, const Script& redeem_script,
+ const std::vector& key_list);
+ /**
+ * @brief set input utxo data on direct.
+ * @param[in] index input index
+ * @param[in] txout utxo witness transaction output
+ */
+ void SetTxInWitnessUtxoDirect(uint32_t index, const TxOutReference& txout);
+ /**
+ * @brief set input bip32 key on direct.
+ * @param[in] index input index
+ * @param[in] key_data key data
+ */
+ void SetTxInBip32KeyDirect(uint32_t index, const KeyData& key_data);
+
+ /**
+ * @brief set input signature.
+ * @param[in] index input index
+ * @param[in] key utxo related pubkey
+ * @param[in] signature signature data
+ */
+ void SetTxInSignature(
+ uint32_t index, const KeyData& key, const ByteData& signature);
+ /**
+ * @brief set input sighash type.
+ * @param[in] index input index
+ * @param[in] sighash_type sighash type
+ */
+ void SetTxInSighashType(uint32_t index, const SigHashType& sighash_type);
+ /**
+ * @brief set input final script.
+ * @param[in] index input index
+ * @param[in] unlocking_script unlocking script data list.
+ */
+ void SetTxInFinalScript(
+ uint32_t index, const std::vector& unlocking_script);
+ /**
+ * @brief set input record.
+ * @param[in] index input index
+ * @param[in] key key
+ * @param[in] value value
+ */
+ void SetTxInRecord(
+ uint32_t index, const ByteData& key, const ByteData& value);
+
+ /**
+ * @brief get input utxo full transaction.
+ * @param[in] index input index
+ * @param[in] ignore_error ignore error with empty data.
+ * @param[out] is_witness has witness.
+ * @return utxo transaction
+ */
+ Transaction GetTxInUtxoFull(
+ uint32_t index, bool ignore_error = false,
+ bool* is_witness = nullptr) const;
+ /**
+ * @brief get input utxo output data.
+ * @param[in] index input index
+ * @param[in] ignore_error ignore error with empty data.
+ * @param[out] is_witness has witness.
+ * @return utxo transaction output
+ */
+ TxOut GetTxInUtxo(
+ uint32_t index, bool ignore_error = false,
+ bool* is_witness = nullptr) const;
+ /**
+ * @brief get input redeem script.
+ * @param[in] index input index
+ * @param[in] ignore_error ignore error with empty data.
+ * @param[out] is_witness has witness.
+ * @return redeem script (or witness script)
+ */
+ Script GetTxInRedeemScript(
+ uint32_t index, bool ignore_error = false,
+ bool* is_witness = nullptr) const;
+ /**
+ * @brief get input redeem script.
+ * @param[in] index input index
+ * @param[in] ignore_error ignore error with empty data.
+ * @param[in] is_witness getting target witness.
+ * @return redeem script (or witness script)
+ */
+ Script GetTxInRedeemScriptDirect(
+ uint32_t index, bool ignore_error = false, bool is_witness = true) const;
+ /**
+ * @brief get input key data list.
+ * @param[in] index input index
+ * @return key data list
+ */
+ std::vector GetTxInKeyDataList(uint32_t index) const;
+ /**
+ * @brief get input key data (only list top data).
+ * @param[in] index input index
+ * @param[in] ignore_error ignore error with empty data.
+ * @return key data
+ */
+ KeyData GetTxInKeyData(uint32_t index, bool ignore_error = false) const;
+ /**
+ * @brief get input key data list related to signature.
+ * @param[in] index input index
+ * @return key data list
+ */
+ std::vector GetTxInSignaturePubkeyList(uint32_t index) const;
+ /**
+ * @brief get input signature related pubkey.
+ * @param[in] index input index
+ * @param[in] pubkey pubkey
+ * @return signature
+ */
+ ByteData GetTxInSignature(uint32_t index, const Pubkey& pubkey) const;
+ /**
+ * @brief exist input signature related pubkey.
+ * @param[in] index input index
+ * @param[in] pubkey pubkey
+ * @retval true exist signature
+ * @retval false signature not found
+ */
+ bool IsFindTxInSignature(uint32_t index, const Pubkey& pubkey) const;
+ /**
+ * @brief get input sighash type.
+ * @param[in] index input index
+ * @return sighash type
+ */
+ SigHashType GetTxInSighashType(uint32_t index) const;
+ /**
+ * @brief exist input sighash type.
+ * @param[in] index input index
+ * @retval true exist sighash type
+ * @retval false sighash type not found
+ */
+ bool IsFindTxInSighashType(uint32_t index) const;
+ /**
+ * @brief get input final script.
+ * @param[in] index input index
+ * @param[in] is_witness_stack target witness flag
+ * @return witness stack or scriptSig
+ */
+ std::vector GetTxInFinalScript(
+ uint32_t index, bool is_witness_stack = true) const;
+ /**
+ * @brief get input record value.
+ * @param[in] index input index
+ * @param[in] key record key
+ * @return record value
+ */
+ ByteData GetTxInRecord(uint32_t index, const ByteData& key) const;
+ /**
+ * @brief exist input record.
+ * @param[in] index input index
+ * @param[in] key record key
+ * @retval true exist record
+ * @retval false record not found
+ */
+ bool IsFindTxInRecord(uint32_t index, const ByteData& key) const;
+ /**
+ * @brief get record key list.
+ * @param[in] index input index
+ * @return record key list
+ */
+ std::vector GetTxInRecordKeyList(uint32_t index) const;
+ /**
+ * @brief clear input sign data.
+ * @details clear target is redeem script, signature, sighashtype.
+ * @param[in] index input index
+ */
+ void ClearTxInSignData(uint32_t index);
+
+ /**
+ * @brief add base transaction output.
+ * @param[in] txout transaction output.
+ * @return added index.
+ */
+ uint32_t AddTxOut(const TxOut& txout);
+ /**
+ * @brief add base transaction output.
+ * @param[in] txout transaction output.
+ * @return added index.
+ */
+ uint32_t AddTxOut(const TxOutReference& txout);
+ /**
+ * @brief add base transaction output.
+ * @param[in] locking_script locking script.
+ * @param[in] amount amount.
+ * @return added index.
+ */
+ uint32_t AddTxOut(const Script& locking_script, const Amount& amount);
+
+ /**
+ * @brief set output data.
+ * @param[in] index output index
+ * @param[in] key output related pubkey
+ */
+ void SetTxOutData(uint32_t index, const KeyData& key);
+ /**
+ * @brief set output data.
+ * @param[in] index output index
+ * @param[in] redeem_script output redeem script (only script hash)
+ * @param[in] key output related pubkey
+ */
+ void SetTxOutData(
+ uint32_t index, const Script& redeem_script, const KeyData& key);
+ /**
+ * @brief set output data.
+ * @param[in] index output index
+ * @param[in] redeem_script output redeem script (only script hash)
+ * @param[in] key_list output related pubkey list
+ */
+ void SetTxOutData(
+ uint32_t index, const Script& redeem_script,
+ const std::vector& key_list);
+ /**
+ * @brief set output record.
+ * @param[in] index output index
+ * @param[in] key record key
+ * @param[in] value record value
+ */
+ void SetTxOutRecord(
+ uint32_t index, const ByteData& key, const ByteData& value);
+
+ /**
+ * @brief get output redeem script.
+ * @param[in] index output index
+ * @param[in] ignore_error ignore error with empty data.
+ * @param[out] is_witness has witness.
+ * @return redeem script (or witness script)
+ */
+ Script GetTxOutScript(
+ uint32_t index, bool ignore_error = false,
+ bool* is_witness = nullptr) const;
+ /**
+ * @brief get output key data (only list top data).
+ * @param[in] index output index
+ * @param[in] ignore_error ignore error with empty data.
+ * @return key data
+ */
+ KeyData GetTxOutKeyData(uint32_t index, bool ignore_error = false) const;
+ /**
+ * @brief get output key data list related to redeem script.
+ * @param[in] index output index
+ * @return key data list
+ */
+ std::vector GetTxOutKeyDataList(uint32_t index) const;
+ /**
+ * @brief get output record value.
+ * @param[in] index output index
+ * @param[in] key record key
+ * @return record value
+ */
+ ByteData GetTxOutRecord(uint32_t index, const ByteData& key) const;
+ /**
+ * @brief exist output record.
+ * @param[in] index output index
+ * @param[in] key record key
+ * @retval true exist record
+ * @retval false record not found
+ */
+ bool IsFindTxOutRecord(uint32_t index, const ByteData& key) const;
+ /**
+ * @brief get record key list.
+ * @param[in] index output index
+ * @return record key list
+ */
+ std::vector GetTxOutRecordKeyList(uint32_t index) const;
+
+ /**
+ * @brief Get the psbt version.
+ * @return psbt version
+ */
+ uint32_t GetPsbtVersion() const;
+ /**
+ * @brief set global extpubkey.
+ * @param[in] key extkey data.
+ */
+ void SetGlobalXpubkey(const KeyData& key);
+ /**
+ * @brief get global extpubkey.
+ * @param[in] key extpubkey
+ * @return key data
+ */
+ KeyData GetGlobalXpubkeyBip32(const ExtPubkey& key) const;
+ /**
+ * @brief exist global extpubkey.
+ * @param[in] key extpubkey
+ * @retval true exist record
+ * @retval false record not found
+ */
+ bool IsFindGlobalXpubkey(const ExtPubkey& key) const;
+ /**
+ * @brief get global key data list.
+ * @return key data list
+ */
+ std::vector GetGlobalXpubkeyDataList() const;
+ /**
+ * @brief set global record.
+ * @param[in] key record key
+ * @param[in] value record value
+ */
+ void SetGlobalRecord(const ByteData& key, const ByteData& value);
+ /**
+ * @brief get global record value.
+ * @param[in] key record key
+ * @return record value
+ */
+ ByteData GetGlobalRecord(const ByteData& key) const;
+ /**
+ * @brief exist global record.
+ * @param[in] key record key
+ * @retval true exist record
+ * @retval false record not found
+ */
+ bool IsFindGlobalRecord(const ByteData& key) const;
+ /**
+ * @brief get record key list.
+ * @return record key list
+ */
+ std::vector GetGlobalRecordKeyList() const;
+
+ protected:
+ void* wally_psbt_pointer_; ///< libwally psbt pointer
+ Transaction base_tx_; ///< base transaction
+
+ /**
+ * @brief Free a heap address for libwally-core psbt object.
+ * @param[in] wally_psbt_pointer address
+ */
+ static void FreeWallyPsbtAddress(const void* wally_psbt_pointer);
+ /**
+ * @brief Rebuild base transaction.
+ * @param[in] wally_psbt_pointer address
+ * @return Transaction
+ */
+ static Transaction RebuildTransaction(const void* wally_psbt_pointer);
+
+ /**
+ * @brief Check the index range of the TxIn array.
+ * @param[in] index input index
+ * @param[in] line file line
+ * @param[in] caller caller function name
+ */
+ virtual void CheckTxInIndex(
+ uint32_t index, int line, const char* caller) const;
+ /**
+ * @brief Check the index range of the TxOut array.
+ * @param[in] index output index
+ * @param[in] line file line
+ * @param[in] caller caller function name
+ */
+ virtual void CheckTxOutIndex(
+ uint32_t index, int line, const char* caller) const;
+};
+
+} // namespace core
+} // namespace cfd
+
+#endif // CFD_CORE_INCLUDE_CFDCORE_CFDCORE_PSBT_H_
diff --git a/include/cfdcore/cfdcore_schnorrsig.h b/include/cfdcore/cfdcore_schnorrsig.h
index 3f780ddf..c41f9809 100644
--- a/include/cfdcore/cfdcore_schnorrsig.h
+++ b/include/cfdcore/cfdcore_schnorrsig.h
@@ -1,12 +1,14 @@
// Copyright 2020 CryptoGarage
+#ifndef CFD_CORE_INCLUDE_CFDCORE_CFDCORE_SCHNORRSIG_H_
+#define CFD_CORE_INCLUDE_CFDCORE_CFDCORE_SCHNORRSIG_H_
+
#include
+#include
#include "cfdcore/cfdcore_bytedata.h"
#include "cfdcore/cfdcore_common.h"
#include "cfdcore/cfdcore_key.h"
-
-#ifndef CFD_CORE_INCLUDE_CFDCORE_CFDCORE_SCHNORRSIG_H_
-#define CFD_CORE_INCLUDE_CFDCORE_CFDCORE_SCHNORRSIG_H_
+#include "cfdcore/cfdcore_util.h"
namespace cfd {
namespace core {
@@ -15,6 +17,7 @@ using cfd::core::ByteData;
using cfd::core::ByteData256;
using cfd::core::Privkey;
using cfd::core::Pubkey;
+using cfd::core::SigHashType;
class SchnorrSignature;
@@ -60,6 +63,12 @@ class CFD_CORE_EXPORT SchnorrPubkey {
* @return ByteData
*/
ByteData GetData() const;
+ /**
+ * @brief Get the underlying ByteData256 object
+ *
+ * @return ByteData256
+ */
+ ByteData256 GetByteData256() const;
/**
* @brief Get the hex string.
*
@@ -128,7 +137,7 @@ class CFD_CORE_EXPORT SchnorrPubkey {
* @param[in] parity the parity of the pubkey.
* @return pubkey
*/
- Pubkey CreatePubkey(bool parity) const;
+ Pubkey CreatePubkey(bool parity = false) const;
/**
* @brief get schnorr public key from private key.
@@ -211,19 +220,39 @@ class CFD_CORE_EXPORT SchnorrSignature {
* @param data the data representing the adaptor signature
*/
explicit SchnorrSignature(const std::string &data);
+ /**
+ * @brief Construct a new Schnorr Signature object from a Signature object.
+ *
+ * @param[in] object the data representing the adaptor signature
+ */
+ SchnorrSignature(const SchnorrSignature &object);
+ /**
+ * @brief copy constructor.
+ * @param[in] object the data representing the adaptor signature
+ * @return object
+ */
+ SchnorrSignature &operator=(const SchnorrSignature &object);
/**
* @brief Get the underlying ByteData object
- *
+ *
+ * @param[in] append_sighash_type add sighash type.
* @return ByteData
*/
- ByteData GetData() const;
+ ByteData GetData(bool append_sighash_type = false) const;
/**
* @brief Get the hex string.
*
+ * @param[in] append_sighash_type add sighash type.
* @return hex string.
*/
- std::string GetHex() const;
+ std::string GetHex(bool append_sighash_type = false) const;
+ /**
+ * @brief Get the sighash type.
+ *
+ * @return sighash type.
+ */
+ SigHashType GetSigHashType() const;
/**
* @brief Return the nonce part of the signature.
@@ -239,12 +268,31 @@ class CFD_CORE_EXPORT SchnorrSignature {
*/
Privkey GetPrivkey() const;
+ /**
+ * @brief Get the sighash type.
+ * @param[in] sighash_type sighash type
+ */
+ void SetSigHashType(const SigHashType &sighash_type);
+
+ /**
+ * @brief check valid sighash type.
+ * @param[in] sighash_type_value sighash type
+ * @retval true valid
+ * @retval false invalid
+ */
+ static bool IsValidSigHashType(uint8_t sighash_type_value);
+
private:
/**
* @brief The underlying data
*
*/
ByteData data_;
+ /**
+ * @brief The sighash type
+ *
+ */
+ SigHashType sighash_type_;
};
/**
@@ -252,6 +300,16 @@ class CFD_CORE_EXPORT SchnorrSignature {
*/
class CFD_CORE_EXPORT SchnorrUtil {
public:
+ /**
+ * @brief Create a schnorr signature over the given message using the given
+ * private key and auxiliary random data.
+ *
+ * @param msg the message to create the signature for.
+ * @param sk the secret key to create the signature with.
+ * @return SchnorrSignature
+ */
+ static SchnorrSignature Sign(const ByteData256 &msg, const Privkey &sk);
+
/**
* @brief Create a schnorr signature over the given message using the given
* private key and auxiliary random data.
@@ -288,6 +346,23 @@ class CFD_CORE_EXPORT SchnorrUtil {
const ByteData256 &msg, const SchnorrPubkey &nonce,
const SchnorrPubkey &pubkey);
+ /**
+ * @brief Compute the sum of signature points for a set of Schnorr signature.
+ * This enable reducing the number of EC multiplications done when computing the
+ * addition of multiple signature points. So instead of computing:
+ * S = (R_0 + X * H(X || R_0 || m_0)) + ... + (R_n + X * H(X || R_n || m_n))
+ * This function computes:
+ * S = (R_0 + ... + R_n) + X * (H(X || R_0 || m_0) + ... + H(X || R_n || m_n))
+ *
+ * @param msgs the set of messages that will be signed.
+ * @param nonces the public component of the nonces that will be used.
+ * @param pubkey the public key for which the signatures will be valid.
+ * @return Pubkey the signature point.
+ */
+ static Pubkey ComputeSigPointBatch(
+ const std::vector &msgs,
+ const std::vector &nonces, const SchnorrPubkey &pubkey);
+
/**
* @brief Verify a Schnorr signature.
*
diff --git a/include/cfdcore/cfdcore_script.h b/include/cfdcore/cfdcore_script.h
index c4d96fac..4827ace4 100644
--- a/include/cfdcore/cfdcore_script.h
+++ b/include/cfdcore/cfdcore_script.h
@@ -2,7 +2,7 @@
/**
* @file cfdcore_script.h
*
- * @brief Script関連クラス定義
+ * @brief The script related class definition.
*
*/
#ifndef CFD_CORE_INCLUDE_CFDCORE_CFDCORE_SCRIPT_H_
@@ -21,19 +21,46 @@
namespace cfd {
namespace core {
-/// P2PKHのScriptサイズ(WALLY_SCRIPTPUBKEY_P2PKH_LEN)
+/// Script size on P2PKH.
constexpr size_t kScriptHashP2pkhLength = 25;
-/// P2SHのScriptサイズ(WALLY_SCRIPTPUBKEY_P2SH_LEN)
+/// Script size on P2SH.
constexpr size_t kScriptHashP2shLength = 23;
-/// P2WPKHのScriptサイズ(WALLY_SCRIPTPUBKEY_P2WPKH_LEN)
+/// Script size on P2WPKH.
constexpr size_t kScriptHashP2wpkhLength = 22;
-/// P2WSHのScriptサイズ(WALLY_SCRIPTPUBKEY_P2WSH_LEN)
+/// Script size on P2WSH.
constexpr size_t kScriptHashP2wshLength = 34;
-/// WitnessProgramの最小サイズ
+/// Script size on Taproot.
+constexpr size_t kScriptHashTaprootLength = 34;
+/// WitnessProgram's minimum size.
constexpr size_t kMinWitnessProgramLength = 4;
-/// WitnessProgramの最大サイズ
+/// WitnessProgram's maximum size.
constexpr size_t kMaxWitnessProgramLength = 42;
+/**
+ * @typedef WitnessVersion
+ * @brief Witness version
+ */
+enum WitnessVersion {
+ kVersionNone = -1, //!< Missing WitnessVersion
+ kVersion0 = 0, //!< version 0
+ kVersion1, //!< version 1 (for future use)
+ kVersion2, //!< version 2 (for future use)
+ kVersion3, //!< version 3 (for future use)
+ kVersion4, //!< version 4 (for future use)
+ kVersion5, //!< version 5 (for future use)
+ kVersion6, //!< version 6 (for future use)
+ kVersion7, //!< version 7 (for future use)
+ kVersion8, //!< version 8 (for future use)
+ kVersion9, //!< version 9 (for future use)
+ kVersion10, //!< version 10 (for future use)
+ kVersion11, //!< version 11 (for future use)
+ kVersion12, //!< version 12 (for future use)
+ kVersion13, //!< version 13 (for future use)
+ kVersion14, //!< version 14 (for future use)
+ kVersion15, //!< version 15 (for future use)
+ kVersion16 //!< version 16 (for future use)
+};
+
/**
* @brief script element type
*/
@@ -56,6 +83,7 @@ enum ScriptType {
kOpPushData4 = 0x4e, //!< kOpPushData4
kOp1Negate = 0x4f, //!< kOp1Negate
kOpReserved = 0x50, //!< kOpReserved
+ kOpSuccess80 = 0x50, //!< kOpSuccess80 (BIP-342)
kOp_1 = 0x51, //!< kOp_1
kOpTrue = 0x51, //!< kOpTrue
kOp_2 = 0x52, //!< kOp_2
@@ -75,6 +103,7 @@ enum ScriptType {
kOp_16 = 0x60, //!< kOp_16
kOpNop = 0x61, //!< kOpNop
kOpVer = 0x62, //!< kOpVer
+ kOpSuccess98 = 0x62, //!< kOpSuccess98 (BIP-342)
kOpIf = 0x63, //!< kOpIf
kOpNotIf = 0x64, //!< kOpNotIf
kOpVerIf = 0x65, //!< kOpVerIf
@@ -106,19 +135,31 @@ enum ScriptType {
kOpSubstr = 0x7f, //!< kOpSubstr
kOpLeft = 0x80, //!< kOpLeft
kOpRight = 0x81, //!< kOpRight
+ kOpSuccess126 = 0x7e, //!< kOpSuccess126 (BIP-342)
+ kOpSuccess127 = 0x7f, //!< kOpSuccess127 (BIP-342)
+ kOpSuccess128 = 0x80, //!< kOpSuccess128 (BIP-342)
+ kOpSuccess129 = 0x81, //!< kOpSuccess129 (BIP-342)
kOpSize = 0x82, //!< kOpSize
kOpInvert = 0x83, //!< kOpInvert
kOpAnd = 0x84, //!< kOpAnd
kOpOr = 0x85, //!< kOpOr
kOpXor = 0x86, //!< kOpXor
+ kOpSuccess131 = 0x83, //!< kOpSuccess131 (BIP-342)
+ kOpSuccess132 = 0x84, //!< kOpSuccess132 (BIP-342)
+ kOpSuccess133 = 0x85, //!< kOpSuccess133 (BIP-342)
+ kOpSuccess134 = 0x86, //!< kOpSuccess134 (BIP-342)
kOpEqual = 0x87, //!< kOpEqual
kOpEqualVerify = 0x88, //!< kOpEqualVerify
kOpReserved1 = 0x89, //!< kOpReserved1
kOpReserved2 = 0x8a, //!< kOpReserved2
+ kOpSuccess137 = 0x89, //!< kOpSuccess137 (BIP-342)
+ kOpSuccess138 = 0x8a, //!< kOpSuccess138 (BIP-342)
kOp1Add = 0x8b, //!< kOp1Add
kOp1Sub = 0x8c, //!< kOp1Sub
kOp2Mul = 0x8d, //!< kOp2Mul
kOp2Div = 0x8e, //!< kOp2Div
+ kOpSuccess141 = 0x8d, //!< kOpSuccess141 (BIP-342)
+ kOpSuccess142 = 0x8e, //!< kOpSuccess142 (BIP-342)
kOpNegate = 0x8f, //!< kOpNegate
kOpAbs = 0x90, //!< kOpAbs
kOpNot = 0x91, //!< kOpNot
@@ -130,6 +171,11 @@ enum ScriptType {
kOpMod = 0x97, //!< kOpMod
kOpLShift = 0x98, //!< kOpLShift
kOpRShift = 0x99, //!< kOpRShift
+ kOpSuccess149 = 0x95, //!< kOpSuccess149 (BIP-342)
+ kOpSuccess150 = 0x96, //!< kOpSuccess150 (BIP-342)
+ kOpSuccess151 = 0x97, //!< kOpSuccess151 (BIP-342)
+ kOpSuccess152 = 0x98, //!< kOpSuccess152 (BIP-342)
+ kOpSuccess153 = 0x99, //!< kOpSuccess153 (BIP-342)
kOpBoolAnd = 0x9a, //!< kOpBoolAnd
kOpBoolOr = 0x9b, //!< kOpBoolOr
kOpNumEqual = 0x9c, //!< kOpNumEqual
@@ -164,6 +210,75 @@ enum ScriptType {
kOpNop8 = 0xb7, //!< kOpNop8
kOpNop9 = 0xb8, //!< kOpNop9
kOpNop10 = 0xb9, //!< kOpNop10
+ kOpCheckSigAdd = 0xba, //!< kOpCheckSigAdd (BIP-342)
+ kOpSuccess187 = 0xbb, //!< kOpSuccess187 (BIP-342)
+ kOpSuccess188 = 0xbc, //!< kOpSuccess188 (BIP-342)
+ kOpSuccess189 = 0xbd, //!< kOpSuccess189 (BIP-342)
+ kOpSuccess190 = 0xbe, //!< kOpSuccess190 (BIP-342)
+ kOpSuccess191 = 0xbf, //!< kOpSuccess191 (BIP-342)
+ kOpSuccess192 = 0xc0, //!< kOpSuccess192 (BIP-342)
+ kOpSuccess193 = 0xc1, //!< kOpSuccess193 (BIP-342)
+ kOpSuccess194 = 0xc2, //!< kOpSuccess194 (BIP-342)
+ kOpSuccess195 = 0xc3, //!< kOpSuccess195 (BIP-342)
+ kOpSuccess196 = 0xc4, //!< kOpSuccess196 (BIP-342)
+ kOpSuccess197 = 0xc5, //!< kOpSuccess197 (BIP-342)
+ kOpSuccess198 = 0xc6, //!< kOpSuccess198 (BIP-342)
+ kOpSuccess199 = 0xc7, //!< kOpSuccess199 (BIP-342)
+ kOpSuccess200 = 0xc8, //!< kOpSuccess200 (BIP-342)
+ kOpSuccess201 = 0xc9, //!< kOpSuccess201 (BIP-342)
+ kOpSuccess202 = 0xca, //!< kOpSuccess202 (BIP-342)
+ kOpSuccess203 = 0xcb, //!< kOpSuccess203 (BIP-342)
+ kOpSuccess204 = 0xcc, //!< kOpSuccess204 (BIP-342)
+ kOpSuccess205 = 0xcd, //!< kOpSuccess205 (BIP-342)
+ kOpSuccess206 = 0xce, //!< kOpSuccess206 (BIP-342)
+ kOpSuccess207 = 0xcf, //!< kOpSuccess207 (BIP-342)
+ kOpSuccess208 = 0xd0, //!< kOpSuccess208 (BIP-342)
+ kOpSuccess209 = 0xd1, //!< kOpSuccess209 (BIP-342)
+ kOpSuccess210 = 0xd2, //!< kOpSuccess210 (BIP-342)
+ kOpSuccess211 = 0xd3, //!< kOpSuccess211 (BIP-342)
+ kOpSuccess212 = 0xd4, //!< kOpSuccess212 (BIP-342)
+ kOpSuccess213 = 0xd5, //!< kOpSuccess213 (BIP-342)
+ kOpSuccess214 = 0xd6, //!< kOpSuccess214 (BIP-342)
+ kOpSuccess215 = 0xd7, //!< kOpSuccess215 (BIP-342)
+ kOpSuccess216 = 0xd8, //!< kOpSuccess216 (BIP-342)
+ kOpSuccess217 = 0xd9, //!< kOpSuccess217 (BIP-342)
+ kOpSuccess218 = 0xda, //!< kOpSuccess218 (BIP-342)
+ kOpSuccess219 = 0xdb, //!< kOpSuccess219 (BIP-342)
+ kOpSuccess220 = 0xdc, //!< kOpSuccess220 (BIP-342)
+ kOpSuccess221 = 0xdd, //!< kOpSuccess221 (BIP-342)
+ kOpSuccess222 = 0xde, //!< kOpSuccess222 (BIP-342)
+ kOpSuccess223 = 0xdf, //!< kOpSuccess223 (BIP-342)
+ kOpSuccess224 = 0xe0, //!< kOpSuccess224 (BIP-342)
+ kOpSuccess225 = 0xe1, //!< kOpSuccess225 (BIP-342)
+ kOpSuccess226 = 0xe2, //!< kOpSuccess226 (BIP-342)
+ kOpSuccess227 = 0xe3, //!< kOpSuccess227 (BIP-342)
+ kOpSuccess228 = 0xe4, //!< kOpSuccess228 (BIP-342)
+ kOpSuccess229 = 0xe5, //!< kOpSuccess229 (BIP-342)
+ kOpSuccess230 = 0xe6, //!< kOpSuccess230 (BIP-342)
+ kOpSuccess231 = 0xe7, //!< kOpSuccess231 (BIP-342)
+ kOpSuccess232 = 0xe8, //!< kOpSuccess232 (BIP-342)
+ kOpSuccess233 = 0xe9, //!< kOpSuccess233 (BIP-342)
+ kOpSuccess234 = 0xea, //!< kOpSuccess234 (BIP-342)
+ kOpSuccess235 = 0xeb, //!< kOpSuccess235 (BIP-342)
+ kOpSuccess236 = 0xec, //!< kOpSuccess236 (BIP-342)
+ kOpSuccess237 = 0xed, //!< kOpSuccess237 (BIP-342)
+ kOpSuccess238 = 0xee, //!< kOpSuccess238 (BIP-342)
+ kOpSuccess239 = 0xef, //!< kOpSuccess239 (BIP-342)
+ kOpSuccess240 = 0xf0, //!< kOpSuccess240 (BIP-342)
+ kOpSuccess241 = 0xf1, //!< kOpSuccess241 (BIP-342)
+ kOpSuccess242 = 0xf2, //!< kOpSuccess242 (BIP-342)
+ kOpSuccess243 = 0xf3, //!< kOpSuccess243 (BIP-342)
+ kOpSuccess244 = 0xf4, //!< kOpSuccess244 (BIP-342)
+ kOpSuccess245 = 0xf5, //!< kOpSuccess245 (BIP-342)
+ kOpSuccess246 = 0xf6, //!< kOpSuccess246 (BIP-342)
+ kOpSuccess247 = 0xf7, //!< kOpSuccess247 (BIP-342)
+ kOpSuccess248 = 0xf8, //!< kOpSuccess248 (BIP-342)
+ kOpSuccess249 = 0xf9, //!< kOpSuccess249 (BIP-342)
+ kOpSuccess250 = 0xfa, //!< kOpSuccess250 (BIP-342)
+ kOpSuccess251 = 0xfb, //!< kOpSuccess251 (BIP-342)
+ kOpSuccess252 = 0xfc, //!< kOpSuccess252 (BIP-342)
+ kOpSuccess253 = 0xfd, //!< kOpSuccess253 (BIP-342)
+ kOpSuccess254 = 0xfe, //!< kOpSuccess254 (BIP-342)
kOpInvalidOpCode = 0xff, //!< kOpInvalidOpCode
#ifndef CFD_DISABLE_ELEMENTS
kOpDeterministricRandom = 0xc0, //!< kOpDeterministricRandom
@@ -181,13 +296,13 @@ enum ScriptType {
class Script;
/**
- * @brief Script操作定義クラス。
+ * @brief Script Operation definition class.
* @details
- * OP_XXXXの定義値についてですが、使用時は以下に注意してください。
- * - static linkする場合は、グローバル変数の初期値に使用しないこと。
- * - 初期化順序の関係で、未初期化状態で設定されることがあります。
- * - グローバル変数の初期値に使う場合、
- * ScriptOperatorではなくScriptTypeを使用して下さい。
+ * Regarding the definition value of OP_XXXX, please note the following when using it.
+ * - When statically linking, do not use it as the initial value of global variables.
+ * - Due to the initialization order, it may be set in the uninitialized state.
+ * - When using it as the initial value of a global variable, \
+ * use ScriptType instead of ScriptOperator.
*/
class CFD_CORE_EXPORT ScriptOperator {
public:
@@ -282,8 +397,7 @@ class CFD_CORE_EXPORT ScriptOperator {
static const ScriptOperator OP_LESSTHAN; //!< OP_LESSTHAN
static const ScriptOperator OP_GREATERTHAN; //!< OP_GREATERTHAN
static const ScriptOperator OP_LESSTHANOREQUAL; //!< OP_LESSTHANOREQUAL
- static const ScriptOperator
- OP_GREATERTHANOREQUAL; //!< OP_GREATERTHANOREQUAL //NOLINT
+ static const ScriptOperator OP_GREATERTHANOREQUAL; //!< OP_GREATERTHANOREQUAL //NOLINT
static const ScriptOperator OP_MIN; //!< OP_MIN
static const ScriptOperator OP_MAX; //!< OP_MAX
static const ScriptOperator OP_WITHIN; //!< OP_WITHIN
@@ -296,14 +410,11 @@ class CFD_CORE_EXPORT ScriptOperator {
static const ScriptOperator OP_CHECKSIG; //!< OP_CHECKSIG
static const ScriptOperator OP_CHECKSIGVERIFY; //!< OP_CHECKSIGVERIFY
static const ScriptOperator OP_CHECKMULTISIG; //!< OP_CHECKMULTISIG
- static const ScriptOperator
- OP_CHECKMULTISIGVERIFY; //!< OP_CHECKMULTISIGVERIFY //NOLINT
+ static const ScriptOperator OP_CHECKMULTISIGVERIFY; //!< OP_CHECKMULTISIGVERIFY //NOLINT
static const ScriptOperator OP_NOP1; //!< OP_NOP1
- static const ScriptOperator
- OP_CHECKLOCKTIMEVERIFY; //!< OP_CHECKLOCKTIMEVERIFY //NOLINT
+ static const ScriptOperator OP_CHECKLOCKTIMEVERIFY; //!< OP_CHECKLOCKTIMEVERIFY //NOLINT
static const ScriptOperator OP_NOP2; //!< OP_NOP2
- static const ScriptOperator
- OP_CHECKSEQUENCEVERIFY; //!< OP_CHECKSEQUENCEVERIFY //NOLINT
+ static const ScriptOperator OP_CHECKSEQUENCEVERIFY; //!< OP_CHECKSEQUENCEVERIFY //NOLINT
static const ScriptOperator OP_NOP3; //!< OP_NOP3
static const ScriptOperator OP_NOP4; //!< OP_NOP4
static const ScriptOperator OP_NOP5; //!< OP_NOP5
@@ -312,6 +423,7 @@ class CFD_CORE_EXPORT ScriptOperator {
static const ScriptOperator OP_NOP8; //!< OP_NOP8
static const ScriptOperator OP_NOP9; //!< OP_NOP9
static const ScriptOperator OP_NOP10; //!< OP_NOP10
+ static const ScriptOperator OP_CHECKSIGADD; //!< OP_CHECKSIGADD
static const ScriptOperator OP_INVALIDOPCODE; //!< OP_INVALIDOPCODE
#ifndef CFD_DISABLE_ELEMENTS
static const ScriptOperator
@@ -325,6 +437,93 @@ class CFD_CORE_EXPORT ScriptOperator {
static const ScriptOperator OP_PUBKEYHASH; //!< OP_PUBKEYHASH
static const ScriptOperator OP_PUBKEY; //!< OP_PUBKEY
#endif // CFD_DISABLE_ELEMENTS
+ static const ScriptOperator OP_SUCCESS80; //!< OP_SUCCESS80 (BIP-342)
+ static const ScriptOperator OP_SUCCESS98; //!< OP_SUCCESS98 (BIP-342)
+ static const ScriptOperator OP_SUCCESS126; //!< OP_SUCCESS126 (BIP-342)
+ static const ScriptOperator OP_SUCCESS127; //!< OP_SUCCESS127 (BIP-342)
+ static const ScriptOperator OP_SUCCESS128; //!< OP_SUCCESS128 (BIP-342)
+ static const ScriptOperator OP_SUCCESS129; //!< OP_SUCCESS129 (BIP-342)
+ static const ScriptOperator OP_SUCCESS131; //!< OP_SUCCESS131 (BIP-342)
+ static const ScriptOperator OP_SUCCESS132; //!< OP_SUCCESS132 (BIP-342)
+ static const ScriptOperator OP_SUCCESS133; //!< OP_SUCCESS133 (BIP-342)
+ static const ScriptOperator OP_SUCCESS134; //!< OP_SUCCESS134 (BIP-342)
+ static const ScriptOperator OP_SUCCESS137; //!< OP_SUCCESS137 (BIP-342)
+ static const ScriptOperator OP_SUCCESS138; //!< OP_SUCCESS138 (BIP-342)
+ static const ScriptOperator OP_SUCCESS141; //!< OP_SUCCESS141 (BIP-342)
+ static const ScriptOperator OP_SUCCESS142; //!< OP_SUCCESS142 (BIP-342)
+ static const ScriptOperator OP_SUCCESS149; //!< OP_SUCCESS149 (BIP-342)
+ static const ScriptOperator OP_SUCCESS150; //!< OP_SUCCESS150 (BIP-342)
+ static const ScriptOperator OP_SUCCESS151; //!< OP_SUCCESS151 (BIP-342)
+ static const ScriptOperator OP_SUCCESS152; //!< OP_SUCCESS152 (BIP-342)
+ static const ScriptOperator OP_SUCCESS153; //!< OP_SUCCESS153 (BIP-342)
+ static const ScriptOperator OP_SUCCESS187; //!< OP_SUCCESS187 (BIP-342)
+ static const ScriptOperator OP_SUCCESS188; //!< OP_SUCCESS188 (BIP-342)
+ static const ScriptOperator OP_SUCCESS189; //!< OP_SUCCESS189 (BIP-342)
+ static const ScriptOperator OP_SUCCESS190; //!< OP_SUCCESS190 (BIP-342)
+ static const ScriptOperator OP_SUCCESS191; //!< OP_SUCCESS191 (BIP-342)
+ static const ScriptOperator OP_SUCCESS192; //!< OP_SUCCESS192 (BIP-342)
+ static const ScriptOperator OP_SUCCESS193; //!< OP_SUCCESS193 (BIP-342)
+ static const ScriptOperator OP_SUCCESS194; //!< OP_SUCCESS194 (BIP-342)
+ static const ScriptOperator OP_SUCCESS195; //!< OP_SUCCESS195 (BIP-342)
+ static const ScriptOperator OP_SUCCESS196; //!< OP_SUCCESS196 (BIP-342)
+ static const ScriptOperator OP_SUCCESS197; //!< OP_SUCCESS197 (BIP-342)
+ static const ScriptOperator OP_SUCCESS198; //!< OP_SUCCESS198 (BIP-342)
+ static const ScriptOperator OP_SUCCESS199; //!< OP_SUCCESS199 (BIP-342)
+ static const ScriptOperator OP_SUCCESS200; //!< OP_SUCCESS200 (BIP-342)
+ static const ScriptOperator OP_SUCCESS201; //!< OP_SUCCESS201 (BIP-342)
+ static const ScriptOperator OP_SUCCESS202; //!< OP_SUCCESS202 (BIP-342)
+ static const ScriptOperator OP_SUCCESS203; //!< OP_SUCCESS203 (BIP-342)
+ static const ScriptOperator OP_SUCCESS204; //!< OP_SUCCESS204 (BIP-342)
+ static const ScriptOperator OP_SUCCESS205; //!< OP_SUCCESS205 (BIP-342)
+ static const ScriptOperator OP_SUCCESS206; //!< OP_SUCCESS206 (BIP-342)
+ static const ScriptOperator OP_SUCCESS207; //!< OP_SUCCESS207 (BIP-342)
+ static const ScriptOperator OP_SUCCESS208; //!< OP_SUCCESS208 (BIP-342)
+ static const ScriptOperator OP_SUCCESS209; //!< OP_SUCCESS209 (BIP-342)
+ static const ScriptOperator OP_SUCCESS210; //!< OP_SUCCESS210 (BIP-342)
+ static const ScriptOperator OP_SUCCESS211; //!< OP_SUCCESS211 (BIP-342)
+ static const ScriptOperator OP_SUCCESS212; //!< OP_SUCCESS212 (BIP-342)
+ static const ScriptOperator OP_SUCCESS213; //!< OP_SUCCESS213 (BIP-342)
+ static const ScriptOperator OP_SUCCESS214; //!< OP_SUCCESS214 (BIP-342)
+ static const ScriptOperator OP_SUCCESS215; //!< OP_SUCCESS215 (BIP-342)
+ static const ScriptOperator OP_SUCCESS216; //!< OP_SUCCESS216 (BIP-342)
+ static const ScriptOperator OP_SUCCESS217; //!< OP_SUCCESS217 (BIP-342)
+ static const ScriptOperator OP_SUCCESS218; //!< OP_SUCCESS218 (BIP-342)
+ static const ScriptOperator OP_SUCCESS219; //!< OP_SUCCESS219 (BIP-342)
+ static const ScriptOperator OP_SUCCESS220; //!< OP_SUCCESS220 (BIP-342)
+ static const ScriptOperator OP_SUCCESS221; //!< OP_SUCCESS221 (BIP-342)
+ static const ScriptOperator OP_SUCCESS222; //!< OP_SUCCESS222 (BIP-342)
+ static const ScriptOperator OP_SUCCESS223; //!< OP_SUCCESS223 (BIP-342)
+ static const ScriptOperator OP_SUCCESS224; //!< OP_SUCCESS224 (BIP-342)
+ static const ScriptOperator OP_SUCCESS225; //!< OP_SUCCESS225 (BIP-342)
+ static const ScriptOperator OP_SUCCESS226; //!< OP_SUCCESS226 (BIP-342)
+ static const ScriptOperator OP_SUCCESS227; //!< OP_SUCCESS227 (BIP-342)
+ static const ScriptOperator OP_SUCCESS228; //!< OP_SUCCESS228 (BIP-342)
+ static const ScriptOperator OP_SUCCESS229; //!< OP_SUCCESS229 (BIP-342)
+ static const ScriptOperator OP_SUCCESS230; //!< OP_SUCCESS230 (BIP-342)
+ static const ScriptOperator OP_SUCCESS231; //!< OP_SUCCESS231 (BIP-342)
+ static const ScriptOperator OP_SUCCESS232; //!< OP_SUCCESS232 (BIP-342)
+ static const ScriptOperator OP_SUCCESS233; //!< OP_SUCCESS233 (BIP-342)
+ static const ScriptOperator OP_SUCCESS234; //!< OP_SUCCESS234 (BIP-342)
+ static const ScriptOperator OP_SUCCESS235; //!< OP_SUCCESS235 (BIP-342)
+ static const ScriptOperator OP_SUCCESS236; //!< OP_SUCCESS236 (BIP-342)
+ static const ScriptOperator OP_SUCCESS237; //!< OP_SUCCESS237 (BIP-342)
+ static const ScriptOperator OP_SUCCESS238; //!< OP_SUCCESS238 (BIP-342)
+ static const ScriptOperator OP_SUCCESS239; //!< OP_SUCCESS239 (BIP-342)
+ static const ScriptOperator OP_SUCCESS240; //!< OP_SUCCESS240 (BIP-342)
+ static const ScriptOperator OP_SUCCESS241; //!< OP_SUCCESS241 (BIP-342)
+ static const ScriptOperator OP_SUCCESS242; //!< OP_SUCCESS242 (BIP-342)
+ static const ScriptOperator OP_SUCCESS243; //!< OP_SUCCESS243 (BIP-342)
+ static const ScriptOperator OP_SUCCESS244; //!< OP_SUCCESS244 (BIP-342)
+ static const ScriptOperator OP_SUCCESS245; //!< OP_SUCCESS245 (BIP-342)
+ static const ScriptOperator OP_SUCCESS246; //!< OP_SUCCESS246 (BIP-342)
+ static const ScriptOperator OP_SUCCESS247; //!< OP_SUCCESS247 (BIP-342)
+ static const ScriptOperator OP_SUCCESS248; //!< OP_SUCCESS248 (BIP-342)
+ static const ScriptOperator OP_SUCCESS249; //!< OP_SUCCESS249 (BIP-342)
+ static const ScriptOperator OP_SUCCESS250; //!< OP_SUCCESS250 (BIP-342)
+ static const ScriptOperator OP_SUCCESS251; //!< OP_SUCCESS251 (BIP-342)
+ static const ScriptOperator OP_SUCCESS252; //!< OP_SUCCESS252 (BIP-342)
+ static const ScriptOperator OP_SUCCESS253; //!< OP_SUCCESS253 (BIP-342)
+ static const ScriptOperator OP_SUCCESS254; //!< OP_SUCCESS254 (BIP-342)
// @formatter:on
// clang-format on
@@ -343,6 +542,14 @@ class CFD_CORE_EXPORT ScriptOperator {
*/
static ScriptOperator Get(const std::string &message);
+ /**
+ * @brief Check if it is OP_SUCCESSxx.
+ * @param[in] op_code OP Code
+ * @retval true OP_SUCCESSxx
+ * @retval false other
+ */
+ static bool IsOpSuccess(ScriptType op_code);
+
/**
* @brief get data type.
* @return script data type
@@ -397,54 +604,50 @@ class CFD_CORE_EXPORT ScriptOperator {
ScriptOperator &operator=(const ScriptOperator &object);
/**
- * @brief 等価比較オペレータ
- * @param[in] object 比較対象
- * @retval true 等価
- * @retval false 不等価
- * @return 等価であればtrue, それ以外はfalse
+ * @brief Equals operator.
+ * @param[in] object object
+ * @retval true equals
+ * @retval false not equals
*/
bool operator==(const ScriptOperator &object) const;
/**
- * @brief 不等価比較オペレータ
- * @param[in] object 比較対象
- * @retval true 不等価
- * @retval false 等価
- * @return 不等価であればtrue, それ以外はfalse
+ * @brief Not Equals operator.
+ * @param[in] object object
+ * @retval true not equals
+ * @retval false equals
*/
bool operator!=(const ScriptOperator &object) const;
/**
- * @brief 比較オペレータ
- * @param[in] object 比較対象
- * @retval true 条件に合致
- * @retval false 条件に合致せず
+ * @brief Compare operator.
+ * @param[in] object object
+ * @retval true match
+ * @retval false unmatch
*/
bool operator<(const ScriptOperator &object) const;
/**
- * @brief 比較オペレータ
- * @param[in] object 比較対象
- * @retval true 条件に合致
- * @retval false 条件に合致せず
+ * @brief Compare operator.
+ * @param[in] object object
+ * @retval true match
+ * @retval false unmatch
*/
bool operator<=(const ScriptOperator &object) const;
/**
- * @brief 比較オペレータ
- * @param[in] object 比較対象
- * @retval true 条件に合致
- * @retval false 条件に合致せず
+ * @brief Compare operator.
+ * @param[in] object object
+ * @retval true match
+ * @retval false unmatch
*/
bool operator>(const ScriptOperator &object) const;
/**
- * @brief 比較オペレータ
- * @param[in] object 比較対象
- * @retval true 条件に合致
- * @retval false 条件に合致せず
+ * @brief Compare operator.
+ * @param[in] object object
+ * @retval true match
+ * @retval false unmatch
*/
bool operator>=(const ScriptOperator &object) const;
/**
* @brief default constructor.
- *
- * リスト型使用時のため.
*/
ScriptOperator()
: data_type_(kOpInvalidOpCode), text_data_("OP_INVALIDOPCODE") {
@@ -470,117 +673,122 @@ class CFD_CORE_EXPORT ScriptOperator {
};
/**
- * @brief Script要素保持クラス。
+ * @brief Script element class.
*/
class CFD_CORE_EXPORT ScriptElement {
public:
/**
- * @brief コンストラクタ.
- * @param[in] element オブジェクト
+ * @brief constructor.
+ * @param[in] element object
*/
ScriptElement(const ScriptElement &element);
/**
- * @brief コンストラクタ.
+ * @brief constructor.
* @param[in] type OP_CODE
*/
explicit ScriptElement(const ScriptType &type);
/**
- * @brief コンストラクタ.
+ * @brief constructor.
* @param[in] op_code OP_CODE
*/
explicit ScriptElement(const ScriptOperator &op_code);
/**
- * @brief コンストラクタ.
+ * @brief constructor.
* @param[in] binary_data binary data
*/
explicit ScriptElement(const ByteData &binary_data);
/**
- * @brief コンストラクタ.
+ * @brief constructor.
* @param[in] value script number.
*/
explicit ScriptElement(int64_t value);
/**
- * @brief デストラクタ.
+ * @brief constructor.
+ * @param[in] value script number.
+ * @param[in] is_binary binary mode.
+ */
+ explicit ScriptElement(int64_t value, bool is_binary);
+ /**
+ * @brief destructor.
*/
virtual ~ScriptElement() {
// do nothing
}
/**
- * @brief コピーコンストラクタ.
- * @param[in] element オブジェクト
- * @return オブジェクト
+ * @brief copy constructor.
+ * @param[in] element object
+ * @return object
*/
ScriptElement &operator=(const ScriptElement &element);
/**
- * @brief 要素種別を取得する.
- * @return 要素種別.
+ * @brief Get the element type.
+ * @return element type.
*/
ScriptElementType GetType() const;
/**
- * @brief OP_CODEを取得する.
+ * @brief Get the OP_CODE.
* @return OP_CODE
*/
const ScriptOperator &GetOpCode() const;
/**
- * @brief バイナリ値を取得する.
- * @return バイナリ値
+ * @brief Get a binary data.
+ * @return binary data.
*/
ByteData GetBinaryData() const;
/**
- * @brief 数値情報を取得する.
- * @return 数値情報
+ * @brief Get a numeric value.
+ * @return numeric value.
*/
int64_t GetNumber() const;
/**
- * @brief バイト配列を取得する.
- * @return バイト配列
+ * @brief Get a byte array.
+ * @return byte array.
*/
ByteData GetData() const;
/**
- * @brief 文字列情報を取得する.
- * @return 文字列情報
+ * @brief Get a stirng data.
+ * @return string data.
*/
std::string ToString() const;
/**
- * @brief OP_CODE型の情報かどうか判定する.
+ * @brief Determine if it is OP_CODE type information.
* @retval true OP_CODE
- * @retval false その他
+ * @retval false other
*/
bool IsOpCode() const { return type_ == kElementOpCode; }
/**
- * @brief 数値型の情報かどうか判定する.
- * @retval true 数値型
- * @retval false その他
+ * @brief Determine if it is numeric type information.
+ * @retval true Numeric type
+ * @retval false other type
*/
bool IsNumber() const {
- // 数値型明示 or 数値が入っている or OP_0 の何れかなら数値とみなす
+ // If either the numeric type is specified, the number is included,
+ // or OP_0 is specified, it is regarded as a number.
return (type_ == kElementNumber) || (value_ != 0) ||
(op_code_.GetDataType() == kOp_0);
}
/**
- * @brief バイナリ情報かどうか判定する.
- * @retval true バイナリ情報
- * @retval false その他
+ * @brief Determine if it is binary information.
+ * @retval true Binary information
+ * @retval false other
*/
bool IsBinary() const { return type_ == kElementBinary; }
/**
- * @brief バイナリ値から数値型に変換する.
- * @param[out] int64_value 数値
- * @retval true 数値型変換OK
- * @retval false 数値型変換NG
+ * @brief Convert from a binary value to a numeric type.
+ * @param[out] int64_value numeric
+ * @retval true conversion OK
+ * @retval false conversion fail.
*/
bool ConvertBinaryToNumber(int64_t *int64_value = nullptr) const;
/**
- * @brief デフォルトコンストラクタ.
- *
- * リスト作成のため.
+ * @brief default constructor.
*/
ScriptElement()
: type_(kElementOpCode), op_code_(), binary_data_(), value_(0) {
@@ -588,15 +796,15 @@ class CFD_CORE_EXPORT ScriptElement {
}
private:
- ScriptElementType type_; ///< 要素種別
+ ScriptElementType type_; ///< element type
ScriptOperator op_code_; ///< OP_CODE
- ByteData binary_data_; ///< バイナリ情報
- int64_t value_; ///< 数値
+ ByteData binary_data_; ///< binary data
+ int64_t value_; ///< numeric value
/**
- * @brief Scriptに追加する数値をbyteデータに変換する
- * @param[in] value scriptに追加する数値
- * @return numberをserializeしたbyteデータ
+ * @brief Convert the numerical value to be added to Script to byte data.
+ * @param[in] value Numerical value to add to script
+ * @return Byte data with serialized number
*/
static std::vector SerializeScriptNum(int64_t value);
};
@@ -649,6 +857,8 @@ class CFD_CORE_EXPORT Script {
static constexpr uint32_t kMaxScriptSize = 10000;
//! maximum size of RedeemScript
static constexpr uint32_t kMaxRedeemScriptSize = 520;
+ //! maximum size of multisig
+ static constexpr uint32_t kMaxMultisigPubkeyNum = 20;
/**
* @brief constructor.
@@ -670,6 +880,17 @@ class CFD_CORE_EXPORT Script {
virtual ~Script() {
// do nothing
}
+ /**
+ * @brief copy constructor.
+ * @param[in] object object
+ */
+ Script(const Script &object);
+ /**
+ * @brief copy constructor.
+ * @param[in] object object
+ * @return object
+ */
+ Script &operator=(const Script &object) &;
/**
* @brief get script.
* @return script
@@ -701,6 +922,13 @@ class CFD_CORE_EXPORT Script {
* @retval false data exist.
*/
bool IsEmpty() const;
+ /**
+ * @brief check equal object.
+ * @param[in] script check target,
+ * @retval true equal
+ * @retval false differ
+ */
+ bool Equals(const Script &script) const;
/**
* @brief get element list.
* @return element list
@@ -767,6 +995,13 @@ class CFD_CORE_EXPORT Script {
*/
bool IsP2wshScript() const;
+ /**
+ * @brief Check if the script is taproot script.
+ * @retval true script is taproot.
+ * @retval false not taproot.
+ */
+ bool IsTaprootScript() const;
+
/**
* @brief Check if the script is pegout script.
* @retval true script is pegout script.
@@ -774,6 +1009,12 @@ class CFD_CORE_EXPORT Script {
*/
bool IsPegoutScript() const;
+ /**
+ * @brief get witness version on locking script.
+ * @return witness version.
+ */
+ WitnessVersion GetWitnessVersion() const;
+
private:
/// script byte data
ByteData script_data_;
@@ -800,7 +1041,7 @@ class CFD_CORE_EXPORT Script {
};
/**
- * @brief script builderクラス.
+ * @brief script builder class.
*/
class CFD_CORE_EXPORT ScriptBuilder {
public:
@@ -886,6 +1127,67 @@ class CFD_CORE_EXPORT ScriptBuilder {
// ScriptBuilder& AppendData(const ByteData& data, bool is_template);
+ /**
+ * @brief append string data.
+ * @param[in] message string data.
+ * @return script builder object.
+ */
+ ScriptBuilder &operator<<(const std::string &message);
+ /**
+ * @brief append script operator.
+ * @param[in] type ScriptType.
+ * @return script builder object.
+ */
+ ScriptBuilder &operator<<(ScriptType type);
+ /**
+ * @brief append script operator.
+ * @param[in] operate_object operator object.
+ * @return script builder object.
+ */
+ ScriptBuilder &operator<<(const ScriptOperator &operate_object);
+ /**
+ * @brief append script data.
+ * @param[in] data script data.
+ * @return script builder object.
+ */
+ ScriptBuilder &operator<<(const ByteData &data);
+ /**
+ * @brief append script data.
+ * @param[in] data script data.
+ * @return script builder object.
+ */
+ ScriptBuilder &operator<<(const ByteData160 &data);
+ /**
+ * @brief append script data.
+ * @param[in] data script data.
+ * @return script builder object.
+ */
+ ScriptBuilder &operator<<(const ByteData256 &data);
+ /**
+ * @brief append script data.
+ * @param[in] pubkey public key.
+ * @return script builder object.
+ */
+ ScriptBuilder &operator<<(const Pubkey &pubkey);
+ /**
+ * @brief append script data.
+ * @param[in] script script data.
+ * @return script builder object.
+ */
+ ScriptBuilder &operator<<(const Script &script);
+ /**
+ * @brief append script data.
+ * @param[in] data script number.
+ * @return script builder object.
+ */
+ ScriptBuilder &operator<<(const int64_t &data);
+ /**
+ * @brief append script element data.
+ * @param[in] element element data.
+ * @return script builder object.
+ */
+ ScriptBuilder &operator<<(const ScriptElement &element);
+
/**
* @brief build script.
* @return script
@@ -897,127 +1199,144 @@ class CFD_CORE_EXPORT ScriptBuilder {
};
/**
- * @brief Scriptを作成する関数群クラス
+ * @brief Utility class that creates Script.
*/
class CFD_CORE_EXPORT ScriptUtil {
public:
/**
- * @brief P2PKのlocking scriptを作成する.
- * @param[in] pubkey Pubkeyインスタンス
- * @return Scriptインスタンス
- * @details 下記の内容のScriptを作成する.
+ * @brief Create a P2PK locking script.
+ * @param[in] pubkey Pubkey
+ * @return Script
+ * @details Create a Script with the following content.
* @code{.unparse}
* OP_CHECKSIG
* @endcode
*/
static Script CreateP2pkLockingScript(const Pubkey &pubkey);
/**
- * @brief P2PKHのlocking scriptを作成する.
- * @param[in] pubkey_hash pubkey hashが格納されたByteData160インスタンス
- * @return Scriptインスタンス
- * @details 下記の内容のScriptを作成する.
+ * @brief Create a P2PKH locking script.
+ * @param[in] pubkey_hash pubkey hash
+ * @return Script
+ * @details Create a Script with the following content.
* @code{.unparse}
* OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG
* @endcode
*/
static Script CreateP2pkhLockingScript(const ByteData160 &pubkey_hash);
/**
- * @brief P2PKHのlocking scriptを作成する.
- * @param[in] pubkey Pubkeyインスタンス
- * @return Scriptインスタンス
- * @details 下記の内容のScriptを作成する.
+ * @brief Create a P2PKH locking script.
+ * @param[in] pubkey Pubkey
+ * @return Script
+ * @details Create a Script with the following content.
* @code{.unparse}
* OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG
* @endcode
*/
static Script CreateP2pkhLockingScript(const Pubkey &pubkey);
/**
- * @brief P2SHのlocking scriptを作成する.
- * @param[in] script_hash script hashが格納されたByteData160インスタンス
- * @return Scriptインスタンス
- * @details 下記の内容のScriptを作成する.
+ * @brief Create a P2SH locking script.
+ * @param[in] script_hash script hash
+ * @return Script
+ * @details Create a Script with the following content.
* @code{.unparse}
* OP_HASH160 OP_EQUAL
* @endcode
*/
static Script CreateP2shLockingScript(const ByteData160 &script_hash);
/**
- * @brief P2SHのlocking scriptを作成する.
- * @param[in] redeem_script redeem scriptのScriptインスタンス
- * @return Scriptインスタンス
- * @details 下記の内容のScriptを作成する.
+ * @brief Create a P2SH locking script.
+ * @param[in] redeem_script redeem script
+ * @return Script
+ * @details Create a Script with the following content.
* @code{.unparse}
* OP_HASH160 OP_EQUAL
* @endcode
*/
static Script CreateP2shLockingScript(const Script &redeem_script);
/**
- * @brief P2WPKHのlocking scriptを作成する.
- * @param[in] pubkey_hash pubkey hashが格納されたByteData160インスタンス
- * @return Scriptインスタンス
- * @details 下記の内容のScriptを作成する.
+ * @brief Create a P2WPKH locking script.
+ * @param[in] pubkey_hash pubkey hash
+ * @return Script
+ * @details Create a Script with the following content.
* @code{.unparse}
* OP_0
* @endcode
*/
static Script CreateP2wpkhLockingScript(const ByteData160 &pubkey_hash);
/**
- * @brief P2WPKHのlocking scriptを作成する.
- * @param[in] pubkey Pubkeyインスタンス
- * @return Scriptインスタンス
- * @details 下記の内容のScriptを作成する.
+ * @brief Create a P2WPKH locking script.
+ * @param[in] pubkey Pubkey
+ * @return Script
+ * @details Create a Script with the following content.
* @code{.unparse}
* OP_0
* @endcode
*/
static Script CreateP2wpkhLockingScript(const Pubkey &pubkey);
/**
- * @brief P2WSHのlocking scriptを作成する.
- * @param[in] script_hash script hashのByteData256インスタンス
- * @return Scriptインスタンス
- * @details 下記の内容のScriptを作成する.
+ * @brief Create a P2WSH locking script.
+ * @param[in] script_hash script hash
+ * @return Script
+ * @details Create a Script with the following content.
* @code{.unparse}
* OP_0
* @endcode
*/
static Script CreateP2wshLockingScript(const ByteData256 &script_hash);
/**
- * @brief P2WSHのlocking scriptを作成する.
- * @param[in] redeem_script redeem scriptのScriptインスタンス
- * @return Scriptインスタンス
- * @details 下記の内容のScriptを作成する.
+ * @brief Create a P2WSH locking script.
+ * @param[in] redeem_script redeem script
+ * @return Script
+ * @details Create a Script with the following content.
* @code{.unparse}
* OP_0
* @endcode
*/
static Script CreateP2wshLockingScript(const Script &redeem_script);
/**
- * @brief RedeemScriptが有効なものであるかをチェックする.
+ * @brief Create locking script for taproot.
+ * @param[in] data witness program
+ * @return Script
+ * @details Create a Script with the following content.
+ * @code{.unparse}
+ * OP_1 <32-byte>
+ * @endcode
+ */
+ static Script CreateTaprootLockingScript(const ByteData256 &data);
+ /**
+ * @brief Check if Redeem Script is valid.
* @param[in] redeem_script redeem script
- * @retval true 有効なredeem script
- * @retval false 有効でないredeem script
+ * @retval true valid
+ * @retval false invalid
*/
static bool IsValidRedeemScript(const Script &redeem_script);
/**
- * @brief M-of-N Multisigのredeem scriptを作成する.
- * @param[in] require_sig_num unlockingに必要なSignature数(Mに相当)
- * @param[in] pubkeys 署名に対応するPubkey配列(Nに相当)
- * @return Scriptインスタンス
- * @details 下記の内容のScriptを作成する.
+ * @brief Create redeem script of the M-of-N Multisig.
+ * @param[in] require_sig_num \
+ * Number of Signatures required for unlocking (equivalent to M)
+ * @param[in] pubkeys Pubkey array corresponding to the signature. \
+ * (equivalent to N)
+ * @param[in] has_witness target is witness script.
+ * @return Script
+ * @details Create a Script with the following content.
* @code{.unparse}
* OP_ ... OP_n OP_CHECKMULTISIG
* @endcode
*/
static Script CreateMultisigRedeemScript(
- uint32_t require_sig_num, const std::vector &pubkeys);
+ uint32_t require_sig_num, const std::vector &pubkeys,
+ bool has_witness = true);
+
#ifndef CFD_DISABLE_ELEMENTS
/**
- * @brief Pegoutのlocking scriptを作成する.
- * @param[in] genesisblock_hash mainchainのgenesisblock hash
- * @param[in] parent_locking_script 送り先 bitcoin address の locking script
- * @param[in] btc_pubkey_bytes DerivePubTweak関数で作られたpubkey情報
- * @param[in] whitelist_proof whitelistの証明
- * @return Scriptインスタンス
+ * @brief Create a Pegout locking script.
+ * @param[in] genesisblock_hash mainchain genesis block hash
+ * @param[in] parent_locking_script \
+ * Destination bitcoin address locking script
+ * @param[in] btc_pubkey_bytes \
+ * Pubkey information created by the DerivePubTweak function
+ * @param[in] whitelist_proof Proof of whitelist
+ * @return Script
* @code{.unparse}
* OP_RETURN
* @endcode
diff --git a/include/cfdcore/cfdcore_taproot.h b/include/cfdcore/cfdcore_taproot.h
new file mode 100644
index 00000000..4aeceff6
--- /dev/null
+++ b/include/cfdcore/cfdcore_taproot.h
@@ -0,0 +1,346 @@
+// Copyright 2021 CryptoGarage
+/**
+ * @file cfdcore_taproot.h
+ *
+ * @brief This file defines the taproot utility class.
+ */
+#ifndef CFD_CORE_INCLUDE_CFDCORE_CFDCORE_TAPROOT_H_
+#define CFD_CORE_INCLUDE_CFDCORE_CFDCORE_TAPROOT_H_
+
+#include
+#include
+
+#include "cfdcore/cfdcore_bytedata.h"
+#include "cfdcore/cfdcore_common.h"
+#include "cfdcore/cfdcore_key.h"
+#include "cfdcore/cfdcore_schnorrsig.h"
+#include "cfdcore/cfdcore_util.h"
+
+namespace cfd {
+namespace core {
+
+/**
+ * @brief This class implements a taproot script tree branch.
+ */
+class CFD_CORE_EXPORT TapBranch {
+ public:
+ /**
+ * @brief default constructor.
+ */
+ TapBranch();
+ /**
+ * @brief constructor.
+ * @param[in] commitment commitment
+ */
+ explicit TapBranch(const ByteData256& commitment);
+ /**
+ * @brief copy constructor.
+ * @param[in] branch branch object
+ */
+ TapBranch(const TapBranch& branch);
+ /**
+ * @brief destructor.
+ */
+ virtual ~TapBranch() {}
+ /**
+ * @brief copy constructor.
+ * @param[in] object object
+ * @return object
+ */
+ TapBranch& operator=(const TapBranch& object);
+
+ /**
+ * @brief Add branch.
+ * @param[in] pubkey schnorr pubkey
+ */
+ virtual void AddBranch(const SchnorrPubkey& pubkey);
+ /**
+ * @brief Add branch.
+ * @param[in] commitment branch commitment.
+ */
+ virtual void AddBranch(const ByteData256& commitment);
+ /**
+ * @brief Add branch.
+ * @param[in] branch branch.
+ */
+ void AddBranch(const TapBranch& branch);
+ /**
+ * @brief Get a base hash.
+ * @return base hash.
+ */
+ ByteData256 GetBaseHash() const;
+ /**
+ * @brief Get a current branch hash.
+ * @return branch hash.
+ */
+ ByteData256 GetCurrentBranchHash() const;
+ /**
+ * @brief Get a branch hash.
+ * @param[in] depth depth
+ * @return branch hash.
+ */
+ ByteData256 GetBranchHash(uint8_t depth = 255) const;
+
+ /**
+ * @brief Exist a tapleaf.
+ * @retval true exist
+ * @retval false not exist
+ */
+ bool HasTapLeaf() const;
+ /**
+ * @brief Get a leaf version.
+ * @return leaf version.
+ */
+ uint8_t GetLeafVersion() const;
+
+ /**
+ * @brief Get a tapscript.
+ * @return tapscript.
+ */
+ Script GetScript() const;
+ /**
+ * @brief Get a node list.
+ * @return node list.
+ */
+ std::vector GetBranchList() const;
+ /**
+ * @brief Get a node list.
+ * @return node list.
+ */
+ virtual std::vector GetNodeList() const;
+
+ /**
+ * @brief find tapscript in this branch.
+ * @param[in] tapscript tapscript
+ * @retval true find this branch.
+ * @retval false not found.
+ */
+ bool IsFindTapScript(const Script& tapscript) const;
+
+ /**
+ * @brief Get a string format. (cfd original)
+ * @return text data.
+ */
+ std::string ToString() const;
+
+ /**
+ * @brief Change tapleaf.
+ * @param[in] tapscript leaf tapscript.
+ * @param[in] target_nodes target nodes.
+ * @return object
+ */
+ TapBranch ChangeTapLeaf(
+ const Script& tapscript, const std::vector& target_nodes =
+ std::vector()) const;
+
+ /**
+ * @brief Convert from string format. (cfd original)
+ * @param[in] text string format.
+ * @return object
+ * @see TapBranch::ToString()
+ */
+ static TapBranch FromString(const std::string& text);
+
+ protected:
+ bool has_leaf_; //!< exist leaf
+ uint8_t leaf_version_; //!< leaf version
+ Script script_; //!< tapscript
+ ByteData256 root_commitment_; //!< root commitment data
+ std::vector branch_list_; //!< branch list
+};
+
+/**
+ * @brief This class implements a taproot Merklized Alternative Script Trees.
+ * @see https://bitcoinops.org/en/newsletters/2019/05/14/
+ */
+class CFD_CORE_EXPORT TaprootScriptTree : public TapBranch {
+ public:
+ /**
+ * @brief The taproot control node maximum count.
+ */
+ static constexpr size_t kTaprootControlMaxNodeCount = 128;
+ /**
+ * @brief The tapleaf version on tapscript.
+ */
+ static constexpr uint8_t kTapScriptLeafVersion = 0xc0;
+
+ /**
+ * @brief constructor.
+ */
+ TaprootScriptTree();
+ /**
+ * @brief constructor.
+ * @param[in] script tapscript
+ */
+ explicit TaprootScriptTree(const Script& script);
+ /**
+ * @brief constructor.
+ * @param[in] leaf_version leaf version
+ * @param[in] script tapscript
+ */
+ explicit TaprootScriptTree(uint8_t leaf_version, const Script& script);
+ /**
+ * @brief constructor. convert from tapleaf branch.
+ * @param[in] leaf_branch leaf branch
+ */
+ explicit TaprootScriptTree(const TapBranch& leaf_branch);
+ /**
+ * @brief copy constructor.
+ * @param[in] tap_tree tree object
+ */
+ TaprootScriptTree(const TaprootScriptTree& tap_tree);
+ /**
+ * @brief destructor.
+ */
+ virtual ~TaprootScriptTree() {}
+ /**
+ * @brief copy constructor.
+ * @param[in] object tree object
+ * @return object
+ */
+ TaprootScriptTree& operator=(const TaprootScriptTree& object) &;
+
+ using TapBranch::AddBranch;
+ /**
+ * @brief Add branch.
+ * @param[in] commitment branch commitment.
+ */
+ virtual void AddBranch(const ByteData256& commitment);
+ /**
+ * @brief Add branch.
+ * @param[in] branch branch.
+ */
+ void AddBranch(const TapBranch& branch);
+ /**
+ * @brief Add branch.
+ * @param[in] tree script tree node.
+ */
+ void AddBranch(const TaprootScriptTree& tree);
+
+ /**
+ * @brief Get a tapleaf hash.
+ * @return tapleaf hash.
+ */
+ ByteData256 GetTapLeafHash() const;
+ /**
+ * @brief Get tweak.
+ * @param[in] internal_pubkey internal pubkey
+ * @return tweak.
+ */
+ ByteData256 GetTapTweak(const SchnorrPubkey& internal_pubkey) const;
+
+ /**
+ * @brief Get a tweaked pubkey.
+ * @param[in] internal_pubkey internal pubkey
+ * @param[out] parity parity flag.
+ * @return tweaked schnorr pubkey.
+ */
+ SchnorrPubkey GetTweakedPubkey(
+ const SchnorrPubkey& internal_pubkey, bool* parity = nullptr) const;
+ /**
+ * @brief Get a tweaked privkey.
+ * @param[in] internal_privkey internal privkey
+ * @param[out] parity parity flag.
+ * @return tweaked privkey.
+ */
+ Privkey GetTweakedPrivkey(
+ const Privkey& internal_privkey, bool* parity = nullptr) const;
+
+ /**
+ * @brief Get a node list.
+ * @return node list.
+ */
+ virtual std::vector GetNodeList() const;
+
+ /**
+ * @brief Convert from string format. (cfd original)
+ * @param[in] text string format.
+ * @param[in] tapscript leaf tapscript.
+ * @param[in] target_nodes target nodes.
+ * @return object
+ * @see TapBranch::FromString()
+ */
+ static TaprootScriptTree FromString(
+ const std::string& text, const Script& tapscript,
+ const std::vector& target_nodes =
+ std::vector());
+
+ private:
+ std::vector nodes_; //!< node list
+};
+
+/**
+ * @brief This class contain utility functions to work with taproot.
+ */
+class CFD_CORE_EXPORT TaprootUtil {
+ public:
+ /**
+ * @brief The annex tag.
+ */
+ static constexpr uint8_t kAnnexTag = 0x50;
+
+ /**
+ * @brief Check valid leaf version.
+ * @param[in] leaf_version leaf version
+ * @retval true valid
+ * @retval false invalid
+ */
+ static bool IsValidLeafVersion(uint8_t leaf_version);
+
+ /**
+ * @brief create tapscript control data.
+ * @param[in] internal_pubkey internal pubkey
+ * @param[in] merkle_tree merkle tree
+ * @param[out] witness_program witness program
+ * @param[out] locking_script taproot locking script
+ * @return tapscript control data.
+ */
+ static ByteData CreateTapScriptControl(
+ const SchnorrPubkey& internal_pubkey,
+ const TaprootScriptTree& merkle_tree,
+ SchnorrPubkey* witness_program = nullptr,
+ Script* locking_script = nullptr);
+
+ /**
+ * @brief Verify taproot commitment.
+ * @param[in] has_parity parity flag
+ * @param[in] tapleaf_bit tapleaf bit
+ * @param[in] target_taproot witness program
+ * @param[in] internal_pubkey internal pubkey
+ * @param[in] nodes taptree node list
+ * @param[in] tapscript tapscript
+ * @param[out] tapleaf_hash tapleaf hash
+ * @retval true valid
+ * @retval false invalid
+ */
+ static bool VerifyTaprootCommitment(
+ bool has_parity, uint8_t tapleaf_bit,
+ const SchnorrPubkey& target_taproot,
+ const SchnorrPubkey& internal_pubkey,
+ const std::vector& nodes, const Script& tapscript,
+ ByteData256* tapleaf_hash = nullptr);
+
+ /**
+ * @brief Parse taproot sign (witness stack) data
+ * @param[in] witness_stack witness stack
+ * @param[out] schnorr_signature schnorr signature
+ * @param[out] has_parity parity flag
+ * @param[out] tapleaf_bit tapleaf bit
+ * @param[out] internal_pubkey internal pubkey
+ * @param[out] nodes taproot node list
+ * @param[out] tapscript tapscript
+ * @param[out] stack script stack data
+ * @param[out] annex annex data
+ */
+ static void ParseTaprootSignData(
+ const std::vector& witness_stack,
+ SchnorrSignature* schnorr_signature, bool* has_parity,
+ uint8_t* tapleaf_bit, SchnorrPubkey* internal_pubkey,
+ std::vector* nodes, Script* tapscript,
+ std::vector* stack = nullptr, ByteData* annex = nullptr);
+};
+
+} // namespace core
+} // namespace cfd
+
+#endif // CFD_CORE_INCLUDE_CFDCORE_CFDCORE_TAPROOT_H_
diff --git a/include/cfdcore/cfdcore_transaction.h b/include/cfdcore/cfdcore_transaction.h
index 052cccaa..756773f4 100644
--- a/include/cfdcore/cfdcore_transaction.h
+++ b/include/cfdcore/cfdcore_transaction.h
@@ -2,7 +2,7 @@
/**
* @file cfdcore_transaction.h
*
- * @brief Transaction関連クラスを定義する。
+ * @brief This file that defines Transaction related classes.
*
*/
#ifndef CFD_CORE_INCLUDE_CFDCORE_CFDCORE_TRANSACTION_H_
@@ -24,6 +24,18 @@
namespace cfd {
namespace core {
+//! OP_CODESEPARATOR default position
+constexpr const uint32_t kDefaultCodeSeparatorPosition = 0xffffffff;
+
+/**
+ * @brief Tapscript data struct.
+ */
+struct TapScriptData {
+ ByteData256 tap_leaf_hash; //!< tapleaf hash
+ //! OP_CODESEPARATOR position
+ uint32_t code_separator_position = kDefaultCodeSeparatorPosition;
+};
+
//! transaction callback type: add txin
constexpr const uint32_t kStateChangeAddTxIn = 0x00000001;
//! transaction callback type: update txin
@@ -40,28 +52,28 @@ constexpr const uint32_t kStateChangeUpdateTxOut = 0x00000200;
constexpr const uint32_t kStateChangeRemoveTxOut = 0x00000400;
/**
- * @brief TxOut情報を保持するクラス
+ * @brief Class that holds TxOut information
*/
class CFD_CORE_EXPORT TxOut : public AbstractTxOut {
public:
/**
- * @brief コンストラクタ
+ * @brief constructor
*/
TxOut();
/**
- * @brief コンストラクタ
+ * @brief constructor
* @param[in] value amount value.
* @param[in] locking_script locking script.
*/
TxOut(const Amount& value, const Script& locking_script);
/**
- * @brief コンストラクタ
+ * @brief constructor
* @param[in] value amount value.
* @param[in] address out address.
*/
TxOut(const Amount& value, const Address& address);
/**
- * @brief デストラクタ
+ * @brief destructor
*/
virtual ~TxOut() {
// do nothing
@@ -69,25 +81,23 @@ class CFD_CORE_EXPORT TxOut : public AbstractTxOut {
};
/**
- * @brief TxOut情報を参照するためのクラス
+ * @brief Class for referencing TxOut information.
*/
class CFD_CORE_EXPORT TxOutReference : public AbstractTxOutReference {
public:
/**
- * @brief コンストラクタ
- * @param[in] tx_out 参照するTxOutインスタンス
+ * @brief constructor
+ * @param[in] tx_out TxOut instance
*/
explicit TxOutReference(const TxOut& tx_out);
/**
- * @brief デフォルトコンストラクタ.
- *
- * リスト作成用。
+ * @brief default constructor.
*/
TxOutReference() : TxOutReference(TxOut()) {
// do nothing
}
/**
- * @brief デストラクタ
+ * @brief destructor
*/
virtual ~TxOutReference() {
// do nothing
@@ -95,13 +105,13 @@ class CFD_CORE_EXPORT TxOutReference : public AbstractTxOutReference {
};
/**
- * @brief TxIn情報を保持するクラス
+ * @brief Class that holds TxIn information
*/
class CFD_CORE_EXPORT TxIn : public AbstractTxIn {
public:
/**
- * @brief 最小のTxInサイズ
- * @details 対象サイズ:txid(64), vout(4), sequence(4), scriptLength(1(仮))
+ * @brief Minimum TxIn size
+ * @details txid(32), vout(4), sequence(4), scriptLength(1)
*/
static constexpr const size_t kMinimumTxInSize = 41;
@@ -132,24 +142,24 @@ class CFD_CORE_EXPORT TxIn : public AbstractTxIn {
const Script* scriptsig_template = nullptr);
/**
- * @brief コンストラクタ.
+ * @brief constructor.
* @param[in] txid txid
- * @param[in] index txidのトランザクションのTxOutのIndex情報(vout)
- * @param[in] sequence sequence情報
+ * @param[in] index tx output index(vout)
+ * @param[in] sequence sequence
*/
TxIn(const Txid& txid, uint32_t index, uint32_t sequence);
/**
- * @brief コンストラクタ.
+ * @brief constructor.
* @param[in] txid txid
- * @param[in] index txidのトランザクションのTxOutのIndex情報(vout)
- * @param[in] sequence sequence情報
+ * @param[in] index tx output index(vout)
+ * @param[in] sequence sequence
* @param[in] unlocking_script unlocking script
*/
TxIn(
const Txid& txid, uint32_t index, uint32_t sequence,
const Script& unlocking_script);
/**
- * @brief デストラクタ
+ * @brief destructor
*/
virtual ~TxIn() {
// do nothing
@@ -157,26 +167,24 @@ class CFD_CORE_EXPORT TxIn : public AbstractTxIn {
};
/**
- * @brief TxIn情報を参照するためのクラス
+ * @brief Class for referencing TxIn information
*/
class CFD_CORE_EXPORT TxInReference : public AbstractTxInReference {
public:
/**
- * @brief コンストラクタ.
- * @param[in] tx_in 参照するTxInインスタンス
+ * @brief constructor.
+ * @param[in] tx_in TxIn instance to reference
*/
explicit TxInReference(const TxIn& tx_in);
/**
- * @brief デフォルトコンストラクタ.
- *
- * リスト作成用。
+ * @brief default constructor.
*/
TxInReference() : TxInReference(TxIn(Txid(), 0, 0)) {
// do nothing
}
/**
- * @brief デストラクタ
+ * @brief destructor
*/
virtual ~TxInReference() {
// do nothing
@@ -184,18 +192,16 @@ class CFD_CORE_EXPORT TxInReference : public AbstractTxInReference {
};
/**
- * @brief トランザクション情報クラス
+ * @brief Transaction class
*/
class CFD_CORE_EXPORT Transaction : public AbstractTransaction {
public:
/**
- * @brief コンストラクタ.
- *
- * リスト作成用。
+ * @brief constructor.
*/
Transaction();
/**
- * @brief コンストラクタ
+ * @brief constructor
* @param[in] version version
* @param[in] lock_time lock time
*/
@@ -206,194 +212,194 @@ class CFD_CORE_EXPORT Transaction : public AbstractTransaction {
*/
explicit Transaction(const ByteData& byte_data);
/**
- * @brief コンストラクタ
- * @param[in] hex_string txバイトデータのHEX文字列
+ * @brief constructor
+ * @param[in] hex_string HEX string
*/
explicit Transaction(const std::string& hex_string);
/**
- * @brief コンストラクタ
- * @param[in] transaction トランザクション情報
+ * @brief copy constructor.
+ * @param[in] transaction transaction object.
*/
- explicit Transaction(const Transaction& transaction);
+ Transaction(const Transaction& transaction);
/**
- * @brief デストラクタ
+ * @brief destructor.
*/
virtual ~Transaction() {
// do nothing
}
/**
- * @brief コピーコンストラクタ.
- * @param[in] transaction トランザクション情報
- * @return Transactionオブジェクト
+ * @brief copy constructor.
+ * @param[in] transaction transaction object.
+ * @return transaction object.
*/
Transaction& operator=(const Transaction& transaction) &;
/**
- * @brief Transactionの合計バイトサイズを取得する.
- * @return 合計バイトサイズ
+ * @brief Get the total byte size of Transaction.
+ * @return total byte size
*/
virtual uint32_t GetTotalSize() const;
/**
- * @brief Transactionのvsize情報を取得する.
+ * @brief Get vsize information of Transaction.
* @return vsize
*/
virtual uint32_t GetVsize() const;
/**
- * @brief TransactionのWeight情報を取得する.
+ * @brief Get the Weight information of Transaction.
* @return weight
*/
virtual uint32_t GetWeight() const;
/**
- * @brief TxInを取得する.
- * @param[in] index 取得するindex位置
- * @return 指定indexのTxInインスタンス
+ * @brief Get TxIn.
+ * @param[in] index txin index.
+ * @return TxIn object.
*/
const TxInReference GetTxIn(uint32_t index) const;
/**
- * @brief TxInのindexを取得する.
- * @param[in] txid 取得するTxInのtxid
- * @param[in] vout 取得するTxInのvout
- * @return 条件に合致するTxInのindex番号
+ * @brief Get the index of TxIn.
+ * @param[in] txid txid
+ * @param[in] vout vout
+ * @return TxIn index
*/
virtual uint32_t GetTxInIndex(const Txid& txid, uint32_t vout) const;
/**
- * @brief 保持しているTxInの数を取得する.
- * @return TxIn数
+ * @brief Get the count of TxIn.
+ * @return TxIn count.
*/
uint32_t GetTxInCount() const;
/**
- * @brief TxIn一覧を取得する.
- * @return TxInReference一覧
+ * @brief Get the TxIn list.
+ * @return TxInReference list
*/
const std::vector GetTxInList() const;
/**
- * @brief TxInを追加する.
+ * @brief Add TxIn.
* @param[in] txid txid
* @param[in] index vout
* @param[in] sequence sequence
- * @param[in] unlocking_script unlocking script (未指定時はEmptyを設定する. default Script::Empty)
- * @return 追加したTxInのindex位置
+ * @param[in] unlocking_script unlocking script
+ * @return Index position of added TxIn
*/
uint32_t AddTxIn(
const Txid& txid, uint32_t index, uint32_t sequence,
const Script& unlocking_script = Script::Empty);
/**
- * @brief TxIn情報を削除する.
- * @param[in] index 削除するindex位置
+ * @brief Delete the TxIn information.
+ * @param[in] index index
*/
void RemoveTxIn(uint32_t index);
/**
- * @brief unlocking scriptを設定する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @param[in] unlocking_script TxInに設定するunlocking script (Push Op Only)
+ * @brief Set the unlocking script.
+ * @param[in] tx_in_index TxIn index
+ * @param[in] unlocking_script unlocking script (Push Op Only)
*/
void SetUnlockingScript(
uint32_t tx_in_index, const Script& unlocking_script);
/**
- * @brief unlocking scriptを設定する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @param[in] unlocking_script TxInに設定するunlocking scriptの構成要素リスト
+ * @brief Set the unlocking script.
+ * @param[in] tx_in_index TxIn index
+ * @param[in] unlocking_script Unlocking script component list
*/
void SetUnlockingScript(
uint32_t tx_in_index, const std::vector& unlocking_script);
/**
- * @brief witness stackの現在の個数を取得する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @return witness stackの個数
+ * @brief Get the count of witness stacks.
+ * @param[in] tx_in_index TxIn index
+ * @return count of witness stacks.
*/
uint32_t GetScriptWitnessStackNum(uint32_t tx_in_index) const;
/**
- * @brief witness stackに追加する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @param[in] data witness stackに追加する情報
+ * @brief Add to witness stack.
+ * @param[in] tx_in_index TxIn index
+ * @param[in] data Data to add to the witness stack
* @return witness stack
*/
const ScriptWitness AddScriptWitnessStack(
uint32_t tx_in_index, const ByteData& data);
/**
- * @brief witness stackに追加する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @param[in] data witness stackに追加する20byte情報
+ * @brief Add to witness stack.
+ * @param[in] tx_in_index TxIn index
+ * @param[in] data Data to add to the witness stack
* @return witness stack
*/
const ScriptWitness AddScriptWitnessStack(
uint32_t tx_in_index, const ByteData160& data);
/**
- * @brief witness stackに追加する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @param[in] data witness stackに追加する32byte情報
+ * @brief Add to witness stack.
+ * @param[in] tx_in_index TxIn index
+ * @param[in] data Data to add to the witness stack
* @return witness stack
*/
const ScriptWitness AddScriptWitnessStack(
uint32_t tx_in_index, const ByteData256& data);
/**
- * @brief witness stackの指定index位置を更新する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @param[in] witness_index witness stackのindex位置
- * @param[in] data witness stackに追加する情報
+ * @brief Update the specified index position of the witness stack.
+ * @param[in] tx_in_index TxIn index
+ * @param[in] witness_index witness stack index
+ * @param[in] data Data to add to the witness stack
* @return witness stack
*/
const ScriptWitness SetScriptWitnessStack(
uint32_t tx_in_index, uint32_t witness_index, const ByteData& data);
/**
- * @brief witness stackの指定index位置を更新する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @param[in] witness_index witness stackのindex位置
- * @param[in] data witness stackに追加する20byte情報
+ * @brief Update the specified index position of the witness stack.
+ * @param[in] tx_in_index TxIn index
+ * @param[in] witness_index witness stack index
+ * @param[in] data Data to add to the witness stack
* @return witness stack
*/
const ScriptWitness SetScriptWitnessStack(
uint32_t tx_in_index, uint32_t witness_index, const ByteData160& data);
/**
- * @brief witness stackの指定index位置を更新する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @param[in] witness_index witness stackのindex位置
- * @param[in] data witness stackに追加する32byte情報
+ * @brief Update the specified index position of the witness stack.
+ * @param[in] tx_in_index TxIn index
+ * @param[in] witness_index witness stack index
+ * @param[in] data Data to add to the witness stack
* @return witness stack
*/
const ScriptWitness SetScriptWitnessStack(
uint32_t tx_in_index, uint32_t witness_index, const ByteData256& data);
/**
- * @brief script witnessを全て削除する.
- * @param[in] tx_in_index 設定するTxInのindex位置
+ * @brief Remove all script witness.
+ * @param[in] tx_in_index TxIn index
*/
void RemoveScriptWitnessStackAll(uint32_t tx_in_index);
/**
- * @brief TxOutを取得する.
- * @param[in] index 取得するindex位置
+ * @brief Get TxOut.
+ * @param[in] index txout index
* @return TxOutReference
*/
const TxOutReference GetTxOut(uint32_t index) const;
/**
- * @brief TxOutのindexを取得する.
+ * @brief Get the index of TxOut.
* @param[in] locking_script locking script
- * @return 条件に合致するTxOutのindex番号
+ * @return txout index
*/
virtual uint32_t GetTxOutIndex(const Script& locking_script) const;
/**
- * @brief TxOutのindexを一括取得する.
+ * @brief Get the TxOut index all at once.
* @param[in] locking_script locking script
- * @return 条件に合致するTxOutのindex番号の一覧
+ * @return txout index list.
*/
virtual std::vector GetTxOutIndexList(
const Script& locking_script) const;
/**
- * @brief 保持しているTxOutの数を取得する.
- * @return TxOut数
+ * @brief Get the count of TxOuts.
+ * @return count of TxOuts
*/
uint32_t GetTxOutCount() const;
/**
- * @brief TxOut一覧を取得する.
- * @return TxOutReference一覧
+ * @brief Get the TxOut list.
+ * @return TxOutReference list
*/
const std::vector GetTxOutList() const;
/**
- * @brief TxOut情報を追加する.
+ * @brief Add TxOut information.
* @param[in] value amount
* @param[in] locking_script locking script
- * @return 追加したTxOutのindex位置
+ * @return Index position of added TxOut
*/
uint32_t AddTxOut(const Amount& value, const Script& locking_script);
/**
@@ -403,105 +409,119 @@ class CFD_CORE_EXPORT Transaction : public AbstractTransaction {
*/
void SetTxOutValue(uint32_t index, const Amount& value);
/**
- * @brief TxOut情報を削除する.
- * @param[in] index 取得するindex位置
+ * @brief Delete the TxOut information.
+ * @param[in] index txout index
*/
void RemoveTxOut(uint32_t index);
/**
- * @brief signatureハッシュを取得する.
- * @param[in] txin_index TxInのindex値
- * @param[in] script_data unlocking script もしくは witness_program.
+ * @brief Get the signature hash.
+ * @param[in] txin_index TxIn index
+ * @param[in] script_data unlocking script or witness program.
* @param[in] sighash_type SigHashType(@see cfdcore_util.h)
- * @param[in] value TxInのAmount値.
+ * @param[in] value TxIn Amount.
* @param[in] version Witness version
- * @return signatureハッシュ
+ * @return signature hash
*/
ByteData256 GetSignatureHash(
uint32_t txin_index, const ByteData& script_data,
SigHashType sighash_type, const Amount& value = Amount(),
WitnessVersion version = WitnessVersion::kVersionNone) const;
/**
- * @brief witness情報かどうかを取得する.
- * @retval true witness
- * @retval false witnessではない
+ * @brief Get signature hash by schnorr.
+ * @param[in] txin_index TxIn's index
+ * @param[in] sighash_type SigHashType(@see cfdcore_util.h)
+ * @param[in] utxo_list utxo list (for amount & scriptPubkey)
+ * @param[in] script_data tap script data
+ * @param[in] annex annex data
+ * @return signature hash
+ */
+ ByteData256 GetSchnorrSignatureHash(
+ uint32_t txin_index, SigHashType sighash_type,
+ const std::vector& utxo_list,
+ const TapScriptData* script_data = nullptr,
+ const ByteData& annex = ByteData()) const;
+ /**
+ * @brief Whether it holds witness information.
+ * @retval true witness exist.
+ * @retval false witness not found.
*/
virtual bool HasWitness() const;
+ // internal
/**
- * @brief libwally処理用フラグを取得する。
- * @return libwally用フラグ
+ * @brief libwally Get the processing flag.
+ * @return Flag for libwally
*/
virtual uint32_t GetWallyFlag() const;
protected:
- std::vector vin_; ///< TxIn配列
- std::vector vout_; ///< TxOut配列
+ std::vector vin_; ///< TxIn array
+ std::vector vout_; ///< TxOut array
/**
- * @brief HEX文字列からTransaction情報を設定する.
- * @param[in] hex_string TransactionバイトデータのHEX文字列
+ * @brief Set Transaction information from HEX string.
+ * @param[in] hex_string HEX string of Transaction byte data
*/
void SetFromHex(const std::string& hex_string);
private:
/**
- * @brief TxIn配列のIndex範囲をチェックする.
- * @param[in] index TxIn配列のIndex値
- * @param[in] line 行数
- * @param[in] caller コール元関数名
+ * @brief check TxIn array range.
+ * @param[in] index TxIn Index
+ * @param[in] line Number of lines
+ * @param[in] caller Calling function name
*/
virtual void CheckTxInIndex(
uint32_t index, int line, const char* caller) const;
/**
- * @brief TxOut配列のIndex範囲をチェックする.
* @brief check TxOut array range.
- * @param[in] index TxOut配列のIndex値
- * @param[in] line 行数
- * @param[in] caller コール元関数名
+ * @param[in] index TxOut Index
+ * @param[in] line Number of lines
+ * @param[in] caller Calling function name
*/
virtual void CheckTxOutIndex(
uint32_t index, int line, const char* caller) const;
/**
- * @brief witness stackに情報を追加する.
- * @param[in] tx_in_index TxIn配列のindex値
- * @param[in] data witness stackに追加するバイトデータ
+ * @brief Add information to the witness stack.
+ * @param[in] tx_in_index TxIn index
+ * @param[in] data data to add to the witness stack
* @return witness stack
*/
const ScriptWitness AddScriptWitnessStack(
uint32_t tx_in_index, const std::vector& data);
/**
- * @brief witness stackの指定index位置を更新する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @param[in] witness_index witness stackのindex位置
- * @param[in] data witness stackに追加する32byte情報
+ * @brief Update the specified index position of the witness stack.
+ * @param[in] tx_in_index TxIn index
+ * @param[in] witness_index witness stack index
+ * @param[in] data data to add to the witness stack
* @return witness stack
*/
const ScriptWitness SetScriptWitnessStack(
uint32_t tx_in_index, uint32_t witness_index,
const std::vector& data);
/**
- * @brief Transactionのバイトデータを取得する.
- * @param[in] has_witness witnessを含めるかのフラグ
- * @return バイトデータ
+ * @brief Get the byte data of Transaction.
+ * @param[in] has_witness Flag to include witness
+ * @return ByteData
*/
ByteData GetByteData(bool has_witness) const;
/**
- * @brief TxOut領域のByteDataの整合性チェックと、TxOutへの設定を行う.
+ * @brief Check the consistency of ByteData in the TxOut area and set to TxOut.
*
- * tx_pointerがNULLではない場合のみ、TxOutへの設定を行う.
- * tx_pointerがNULLの場合は整合性チェックのみ行う.
- * @param[in] buffer TxOut領域のByteData
- * @param[in] buf_size TxOut領域のByteDataサイズ
- * @param[in] txout_num TxOut領域のTxOut情報数
- * @param[in] txout_num_size TxOut情報領域サイズ
- * @param[out] tx_pointer Transaction情報バッファ(NULL可)
- * @param[out] txout_list TxOut配列(nullptr可)
- * @retval true 整合性チェックOK、およびTxOut情報コピーOK
- * @retval false 整合性チェックNG、もしくはTxOut情報コピー失敗
+ * Set to TxOut only if tx_pointer is not NULL.
+ * If tx_pointer is NULL, only consistency check is performed.
+ * @param[in] buffer ByteData in the TxOut area
+ * @param[in] buf_size ByteData size in the TxOut area
+ * @param[in] txout_num Number of TxOut information in the TxOut area
+ * @param[in] txout_num_size TxOut information area size
+ * @param[out] tx_pointer Transaction information buffer (nullable)
+ * @param[out] txout_list TxOut array (nullable)
+ * @retval true Consistency check OK, TxOut information copy OK
+ * @retval false Consistency check NG or TxOut information copy failure
*/
static bool CheckTxOutBuffer(
const uint8_t* buffer, size_t buf_size, uint64_t txout_num,
- size_t txout_num_size, void* tx_pointer = NULL,
+ size_t txout_num_size, void* tx_pointer = nullptr,
std::vector* txout_list = nullptr);
};
diff --git a/include/cfdcore/cfdcore_transaction_common.h b/include/cfdcore/cfdcore_transaction_common.h
index aaa8ba56..5a51e8f6 100644
--- a/include/cfdcore/cfdcore_transaction_common.h
+++ b/include/cfdcore/cfdcore_transaction_common.h
@@ -2,7 +2,7 @@
/**
* @file cfdcore_transaction_common.h
*
- * @brief Transaction関連の共通クラスおよび基底クラスを定義する。
+ * @brief Define Transaction-related common class and base class.
*
*/
#ifndef CFD_CORE_INCLUDE_CFDCORE_CFDCORE_TRANSACTION_COMMON_H_
@@ -24,69 +24,70 @@ namespace cfd {
namespace core {
/**
- * @brief ハッシュ種別定義
+ * @brief Hash type definition
*/
enum HashType {
kP2pkh = 0, //!< P2pkh
kP2sh = 1, //!< P2sh
kP2wpkh = 2, //!< P2wpkh
- kP2wsh = 3 //!< P2wsh
+ kP2wsh = 3, //!< P2wsh
+ kTaproot = 6 //!< Taproot
};
/**
- * @brief witness情報の保持クラス
+ * @brief witness information retention class
*/
class CFD_CORE_EXPORT ScriptWitness {
public:
/**
- * @brief コンストラクタ
+ * @brief constructor.
*/
ScriptWitness() : witness_stack_() {
// do nothing
}
/**
- * @brief デストラクタ
+ * @brief destructor.
*/
virtual ~ScriptWitness() {
// do nothing
}
/**
- * @brief witness stackを取得する.
+ * @brief Get the witness stack.
* @return witness stack
*/
const std::vector GetWitness() const;
/**
- * @brief witness stack数を取得する.
- * @return witness stack数
+ * @brief Get the number of witness stacks.
+ * @return number of witness stacks.
*/
uint32_t GetWitnessNum() const;
/**
- * @brief witness stackに追加する.
- * @param[in] data バイトデータ
+ * @brief Add to witness stack.
+ * @param[in] data byte array.
*/
void AddWitnessStack(const ByteData& data);
/**
- * @brief witness stackの指定indexを更新する.
- * @param[in] index 設定先index値
- * @param[in] data バイトデータ
+ * @brief Update the specified index of the witness stack.
+ * @param[in] index index
+ * @param[in] data byte array.
*/
void SetWitnessStack(uint32_t index, const ByteData& data);
/**
- * @brief データが空か取得する.
- * @retval true データが空
- * @retval false データが存在
+ * @brief Check if the data is empty.
+ * @retval true empty.
+ * @retval false exist.
* @deprecated replace to IsEmpty .
*/
bool Empty() const;
/**
- * @brief データが空か取得する.
- * @retval true データが空
- * @retval false データが存在
+ * @brief Check if the data is empty.
+ * @retval true empty.
+ * @retval false exist.
*/
bool IsEmpty() const;
/**
- * @brief witness stack情報をserializeする.
+ * @brief Serialize witness stack information.
* @return serialize data
*/
ByteData Serialize() const;
@@ -130,17 +131,17 @@ class CFD_CORE_EXPORT OutPoint {
bool IsValid() const;
/**
- * @brief 等価比較オペレータ
- * @param[in] object 比較対象
- * @retval true 等価
- * @retval false 不等価
+ * @brief Equals operator.
+ * @param[in] object compare target.
+ * @retval true equals
+ * @retval false not equals
*/
bool operator==(const OutPoint& object) const;
/**
- * @brief 不等価比較オペレータ
- * @param[in] object 比較対象
- * @retval true 不等価
- * @retval false 等価
+ * @brief Not Equals operator.
+ * @param[in] object compare target.
+ * @retval true not equals
+ * @retval false equals
*/
bool operator!=(const OutPoint& object) const;
@@ -150,126 +151,126 @@ class CFD_CORE_EXPORT OutPoint {
};
/**
- * @brief 不等価比較オペレータ
- * @param[in] source 比較元
- * @param[in] dest 比較対象
- * @retval true 不等価
- * @retval false 等価
+ * @brief Compare operator.
+ * @param[in] source source
+ * @param[in] dest destination
+ * @retval true match
+ * @retval false unmatch
*/
CFD_CORE_EXPORT bool operator<(const OutPoint& source, const OutPoint& dest);
/**
- * @brief 不等価比較オペレータ
- * @param[in] source 比較元
- * @param[in] dest 比較対象
- * @retval true 不等価
- * @retval false 等価
+ * @brief Compare operator.
+ * @param[in] source source
+ * @param[in] dest destination
+ * @retval true match
+ * @retval false unmatch
*/
CFD_CORE_EXPORT bool operator<=(const OutPoint& source, const OutPoint& dest);
/**
- * @brief 不等価比較オペレータ
- * @param[in] source 比較元
- * @param[in] dest 比較対象
- * @retval true 不等価
- * @retval false 等価
+ * @brief Compare operator.
+ * @param[in] source source
+ * @param[in] dest destination
+ * @retval true match
+ * @retval false unmatch
*/
CFD_CORE_EXPORT bool operator>(const OutPoint& source, const OutPoint& dest);
/**
- * @brief 不等価比較オペレータ
- * @param[in] source 比較元
- * @param[in] dest 比較対象
- * @retval true 不等価
- * @retval false 等価
+ * @brief Compare operator.
+ * @param[in] source source
+ * @param[in] dest destination
+ * @retval true match
+ * @retval false unmatch
*/
CFD_CORE_EXPORT bool operator>=(const OutPoint& source, const OutPoint& dest);
/**
- * @brief TxInの基本情報を保持する基底クラス
+ * @brief Base class that holds basic information about TxIn.
*/
class CFD_CORE_EXPORT AbstractTxIn {
public:
/**
- * @brief コンストラクタ.
+ * @brief constructor.
* @param[in] txid txid
- * @param[in] index txidのトランザクションのTxOutのIndex情報(vout)
- * @param[in] sequence sequence情報
+ * @param[in] index TxOut Index information for txid transactions(vout)
+ * @param[in] sequence sequence
*/
AbstractTxIn(const Txid& txid, uint32_t index, uint32_t sequence);
/**
- * @brief コンストラクタ.
+ * @brief constructor.
* @param[in] txid txid
- * @param[in] index txidのトランザクションのTxOutのIndex情報(vout)
- * @param[in] sequence sequence情報
+ * @param[in] index TxOut Index information for txid transactions(vout)
+ * @param[in] sequence sequence
* @param[in] unlocking_script unlocking script
*/
AbstractTxIn(
const Txid& txid, uint32_t index, uint32_t sequence,
const Script& unlocking_script);
/**
- * @brief デストラクタ
+ * @brief destructor
*/
virtual ~AbstractTxIn() {
// do nothing
}
/**
- * @brief txidを取得する.
- * @return Txidインスタンス
+ * @brief Get a txid.
+ * @return Txid
*/
Txid GetTxid() const;
/**
- * @brief voutを取得する.
+ * @brief Get a vout.
* @return vout
*/
uint32_t GetVout() const;
/**
- * @brief outpointを取得する.
+ * @brief Get an outpoint.
* @return outpoint
*/
OutPoint GetOutPoint() const;
/**
- * @brief unlocking scriptを取得する.
+ * @brief Get an unlocking script.
* @return unlocking script
*/
Script GetUnlockingScript() const;
/**
- * @brief unlocking scriptを設定する.
+ * @brief Set an unlocking script.
* @param[in] unlocking_script unlocking script
*/
void SetUnlockingScript(const Script& unlocking_script);
/**
- * @brief sequenceを取得する.
+ * @brief Get a sequence.
* @return sequence番号
*/
uint32_t GetSequence() const;
/**
- * @brief script witness情報を取得する.
- * @return ScriptWitnessインスタンス
+ * @brief Get a script witness.
+ * @return ScriptWitness
*/
ScriptWitness GetScriptWitness() const;
/**
- * @brief script witnessの現在のstack数を取得する.
- * @return script witnessのstack数
+ * @brief Get the current stack number of script witness.
+ * @return number of script witness.
*/
uint32_t GetScriptWitnessStackNum() const;
/**
- * @brief script witnessにバイトデータを追加する.
- * @param[in] data witness stack情報
- * @return script witnessオブジェクト
+ * @brief Add byte data to script witness.
+ * @param[in] data witness stack
+ * @return ScriptWitness object
*/
ScriptWitness AddScriptWitnessStack(const ByteData& data);
/**
- * @brief script witnessにバイトデータを設定する.
- * @param[in] index witness stackのindex値
- * @param[in] data witness stack情報
- * @return ScriptWitnessインスタンス
+ * @brief Set byte data in script witness.
+ * @param[in] index witness stack index
+ * @param[in] data witness stack data
+ * @return ScriptWitness object
*/
ScriptWitness SetScriptWitnessStack(uint32_t index, const ByteData& data);
/**
- * @brief script witnessを全て削除する.
+ * @brief Remove all script witness.
*/
void RemoveScriptWitnessStackAll();
/**
- * @brief txid/voutによりcoinbaseを判定する.
+ * @brief Determine coinbase by txid / vout.
* @retval true coinbase
* @retval false other
*/
@@ -284,55 +285,55 @@ class CFD_CORE_EXPORT AbstractTxIn {
};
/**
- * @brief TxInの基本情報を参照するための基底クラス
+ * @brief Base class for referencing basic information on TxIn.
*/
class CFD_CORE_EXPORT AbstractTxInReference {
public:
/**
- * @brief コンストラクタ.
- * @param[in] tx_in 参照するTxInインスタンス
+ * @brief constructor.
+ * @param[in] tx_in TxIn instance to reference
*/
explicit AbstractTxInReference(const AbstractTxIn& tx_in);
/**
- * @brief デストラクタ
+ * @brief destructor.
*/
virtual ~AbstractTxInReference() {
// do nothing
}
/**
- * @brief txidを取得する.
- * @return Txidインスタンス
+ * @brief Get a txid.
+ * @return Txid object.
*/
Txid GetTxid() const { return txid_; }
/**
- * @brief voutを取得する.
+ * @brief Get a vout.
* @return vout
*/
uint32_t GetVout() const { return vout_; }
/**
- * @brief outpointを取得する.
+ * @brief Get an outpoint.
* @return outpoint
*/
OutPoint GetOutPoint() const { return OutPoint(txid_, vout_); }
/**
- * @brief unlocking scriptを取得する.
+ * @brief Get an unlocking script.
* @return unlocking script
*/
Script GetUnlockingScript() const { return unlocking_script_; }
/**
- * @brief sequenceを取得する.
- * @return sequence番号
+ * @brief Get a sequence.
+ * @return sequence
*/
uint32_t GetSequence() const { return sequence_; }
/**
- * @brief script witness情報を取得する.
- * @return ScriptWitnessインスタンス
+ * @brief Get a script witness.
+ * @return ScriptWitness
*/
ScriptWitness GetScriptWitness() const { return script_witness_; }
/**
- * @brief script witnessの現在のstack数を取得する.
- * @return script witnessのstack数
+ * @brief Get a stack number of script witness.
+ * @return stack number of script witness.
*/
uint32_t GetScriptWitnessStackNum() const {
return script_witness_.GetWitnessNum();
@@ -347,38 +348,38 @@ class CFD_CORE_EXPORT AbstractTxInReference {
};
/**
- * @brief TxOutの基本情報を保持する基底クラス
+ * @brief Base class that holds basic information about TxOut.
*/
class CFD_CORE_EXPORT AbstractTxOut {
public:
/**
- * @brief コンストラクタ
+ * @brief constructor
*/
AbstractTxOut();
/**
- * @brief コンストラクタ
+ * @brief constructor
* @param[in] value amount value.
* @param[in] locking_script locking script.
*/
AbstractTxOut(const Amount& value, const Script& locking_script);
/**
- * @brief コンストラクタ
+ * @brief constructor
* @param[in] locking_script locking script.
*/
explicit AbstractTxOut(const Script& locking_script);
/**
- * @brief デストラクタ
+ * @brief destructor
*/
virtual ~AbstractTxOut() {
// do nothing
}
/**
- * @brief Amountを取得する.
+ * @brief Get the amount.
* @return amount
*/
const Amount GetValue() const;
/**
- * @brief locking script を取得する
+ * @brief Get the locking script.
* @return locking script
*/
const Script GetLockingScript() const;
@@ -389,35 +390,35 @@ class CFD_CORE_EXPORT AbstractTxOut {
virtual void SetValue(const Amount& value);
protected:
- Amount value_; ///< 金額
+ Amount value_; ///< amount
Script locking_script_; ///< locking script
};
/**
- * @brief TxOutの基本情報を参照するための基底クラス
+ * @brief Base class for referencing basic information on TxOut.
*/
class CFD_CORE_EXPORT AbstractTxOutReference {
public:
/**
- * @brief コンストラクタ
- * @param[in] tx_out 参照するTxOutインスタンス
+ * @brief constructor.
+ * @param[in] tx_out TxOut instance to reference
*/
explicit AbstractTxOutReference(const AbstractTxOut& tx_out);
/**
- * @brief デストラクタ
+ * @brief destructor
*/
virtual ~AbstractTxOutReference() {
// do nothing
}
/**
- * @brief Amountを取得する.
+ * @brief Get an amount.
* @return amount
*/
const Amount GetValue() const { return value_; }
/**
- * @brief locking script を取得する
+ * @brief Get a locking script.
* @return locking script
*/
const Script GetLockingScript() const { return locking_script_; }
@@ -435,133 +436,133 @@ class CFD_CORE_EXPORT AbstractTxOutReference {
uint32_t GetSerializeVsize() const;
protected:
- Amount value_; ///< 金額
+ Amount value_; ///< amount
Script locking_script_; ///< locking script
};
/**
- * @brief トランザクション情報の基底クラス
+ * @brief Base class of transaction information.
*/
class CFD_CORE_EXPORT AbstractTransaction {
public:
- /// Transactionの最小サイズ
+ /// Minimum size of Transaction
static constexpr size_t kTransactionMinimumSize = 10;
/**
- * @brief コンストラクタ
+ * @brief constructor.
*/
AbstractTransaction();
/**
- * @brief デストラクタ
+ * @brief destructor.
*/
virtual ~AbstractTransaction() {
AbstractTransaction::FreeWallyAddress(wally_tx_pointer_);
}
/**
- * @brief バージョン情報を取得する.
- * @return version番号
+ * @brief Get a version information.
+ * @return version
*/
int32_t GetVersion() const;
/**
- * @brief lock timeを取得する.
+ * @brief Get a lock time.
* @return lock time
*/
uint32_t GetLockTime() const;
/**
- * @brief TxInのindexを取得する.
- * @param[in] txid 取得するTxInのtxid
- * @param[in] vout 取得するTxInのvout
- * @return 条件に合致するTxInのindex番号
+ * @brief Get a TxIn index.
+ * @param[in] txid txid
+ * @param[in] vout vout
+ * @return index
*/
virtual uint32_t GetTxInIndex(const Txid& txid, uint32_t vout) const = 0;
/**
- * @brief TxOutのindexを取得する.
+ * @brief Get a TxOut index.
* @param[in] locking_script locking script
- * @return 条件に合致するTxOutのindex番号
+ * @return index
*/
virtual uint32_t GetTxOutIndex(const Script& locking_script) const = 0;
/**
- * @brief Transactionの合計バイトサイズを取得する.
- * @return 合計バイトサイズ
+ * @brief Get the total byte size of Transaction.
+ * @return Total byte size
*/
virtual uint32_t GetTotalSize() const;
/**
- * @brief Transactionのvsize情報を取得する.
+ * @brief Get vsize information of Transaction.
* @return vsize
*/
virtual uint32_t GetVsize() const;
/**
- * @brief TransactionのWeight情報を取得する.
+ * @brief Get the Weight information of Transaction.
* @return weight
*/
virtual uint32_t GetWeight() const;
/**
- * @brief TransactionのTxOut合計額を取得する.
- * @return TxOut合計額
+ * @brief Get the total TxOut amount of Transaction.
+ * @return total TxOut amount
*/
Amount GetValueOut() const;
/**
- * @brief witness情報かどうかを取得する.
+ * @brief Get witness information.
* @retval true witness
- * @retval false witnessではない
+ * @retval false not witness
*/
virtual bool HasWitness() const;
/**
- * @brief Transactionのハッシュ値を取得する.
+ * @brief Get the hash value of Transaction.
*
- * Witness形式の場合、Witness情報はハッシュ計算に含めない.
- * @return ハッシュ値
+ * In the Witness format, the Witness information is not included in the hash calculation.
+ * @return Hash value
*/
ByteData256 GetHash() const;
/**
- * @brief Witness情報を含めたTransactionのハッシュ値を取得する.
- * @return ハッシュ値
+ * @brief Get the hash value of Transaction including Witness information.
+ * @return Hash value
*/
ByteData256 GetWitnessHash() const;
/**
- * @brief Transactionのバイトデータを取得する.
- * @return バイトデータ
+ * @brief Get the byte data of Transaction.
+ * @return byte data
*/
virtual ByteData GetData() const;
/**
- * @brief TransactionのバイトデータをHEX文字列変換して取得する.
- * @return HEX文字列
+ * @brief Get the byte data of Transaction by converting to HEX character string.
+ * @return hex string.
*/
std::string GetHex() const;
/**
- * @brief txidを取得する.
+ * @brief Get the txid.
*
- * GetHash()と同値となる.
+ * Equivalent to GetHash().
* @return txid
*/
Txid GetTxid() const;
/**
- * @brief coinbaseかどうか判定する.
- * @retval true coinbase transaction
- * @retval false 通常のtransaction
+ * @brief Determine if it is coinbase.
+ * @retval true coinbase transaction
+ * @retval false normaltransaction
*/
bool IsCoinBase() const;
/**
- * @brief libwally処理用フラグを取得する。
- * @return libwally用フラグ
+ * @brief libwally Get the processing flag.
+ * @return Flag for libwally
*/
virtual uint32_t GetWallyFlag() const = 0;
/**
- * @brief size情報からvsizeを取得する。
- * @param[in] no_witness_size 非witness領域サイズ
- * @param[in] witness_size witness領域サイズ
+ * @brief Get vsize from size information.
+ * @param[in] no_witness_size Non-witness area size
+ * @param[in] witness_size witness area size
* @return vsize
*/
static uint32_t GetVsizeFromSize(
uint32_t no_witness_size, uint32_t witness_size);
protected:
- void* wally_tx_pointer_; ///< libwally tx構造体アドレス
+ void* wally_tx_pointer_; ///< libwally tx structure address
/**
* @brief This function is called by the state change.
@@ -569,142 +570,141 @@ class CFD_CORE_EXPORT AbstractTransaction {
*/
virtual void CallbackStateChange(uint32_t type);
/**
- * @brief TxInを追加する.
+ * @brief Add TxIn.
* @param[in] txid txid
* @param[in] index vout
* @param[in] sequence sequence
- * @param[in] unlocking_script unlocking script (未指定時はEmptyを設定する. default Script::Empty)
+ * @param[in] unlocking_script unlocking script
*/
void AddTxIn(
const Txid& txid, uint32_t index, uint32_t sequence,
const Script& unlocking_script = Script::Empty);
/**
- * @brief TxIn情報を削除する.
- * @param[in] index 削除するindex位置
+ * @brief Delete the TxIn information.
+ * @param[in] index index
*/
void RemoveTxIn(uint32_t index);
/**
- * @brief unlocking scriptを設定する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @param[in] unlocking_script TxInに設定するunlocking script (Push Op Only)
+ * @brief Set the unlocking script.
+ * @param[in] tx_in_index index
+ * @param[in] unlocking_script Unlocking script to set to TxIn (Push Op Only)
*/
void SetUnlockingScript(
uint32_t tx_in_index, const Script& unlocking_script);
/**
- * @brief unlocking scriptを設定する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @param[in] unlocking_script TxInに設定するunlocking scriptの構成要素リスト
- * @return 生成したUnlockingScript
+ * @brief Set the unlocking script.
+ * @param[in] tx_in_index index
+ * @param[in] unlocking_script List of unlocking script components to set in TxIn
+ * @return Generated Unlocking Script
*/
Script SetUnlockingScript(
uint32_t tx_in_index, const std::vector& unlocking_script);
/**
- * @brief script witnessを全て削除する.
- * @param[in] tx_in_index 設定するTxInのindex位置
+ * @brief Remove all script witness.
+ * @param[in] tx_in_index index
*/
void RemoveScriptWitnessStackAll(uint32_t tx_in_index);
/**
- * @brief TxOut情報を追加する.
+ * @brief Add TxOut information.
* @param[in] value amount
* @param[in] locking_script locking script
*/
void AddTxOut(const Amount& value, const Script& locking_script);
/**
- * @brief TxOut情報を削除する.
- * @param[in] index 取得するindex位置
+ * @brief Delete the TxOut information.
+ * @param[in] index index
*/
void RemoveTxOut(uint32_t index);
/**
- * @brief TxIn配列のIndex範囲をチェックする.
- * @param[in] index TxIn配列のIndex値
- * @param[in] line 行数
- * @param[in] caller コール元関数名
+ * @brief Check the Index range of the TxIn array.
+ * @param[in] index index
+ * @param[in] line Number of lines
+ * @param[in] caller Calling function name
*/
virtual void CheckTxInIndex(
uint32_t index, int line, const char* caller) const = 0;
/**
- * @brief TxOut配列のIndex範囲をチェックする.
* @brief check TxOut array range.
- * @param[in] index TxOut配列のIndex値
- * @param[in] line 行数
- * @param[in] caller コール元関数名
+ * @param[in] index index
+ * @param[in] line Number of lines
+ * @param[in] caller Calling function name
*/
virtual void CheckTxOutIndex(
uint32_t index, int line, const char* caller) const = 0;
/**
- * @brief witness stackに情報を追加する.
- * @param[in] tx_in_index TxIn配列のindex値
- * @param[in] data witness stackに追加するバイトデータ
+ * @brief Add information to the witness stack.
+ * @param[in] tx_in_index index
+ * @param[in] data Byte data to add to the witness stack
*/
void AddScriptWitnessStack(
uint32_t tx_in_index, const std::vector& data);
/**
- * @brief witness stackの指定index位置を更新する.
- * @param[in] tx_in_index 設定するTxInのindex位置
- * @param[in] witness_index witness stackのindex位置
- * @param[in] data witness stackに追加する32byte情報
+ * @brief Update the specified index position of the witness stack.
+ * @param[in] tx_in_index index position of txin
+ * @param[in] witness_index index position of witness stack
+ * @param[in] data 32byte information to add to the witness stack
*/
void SetScriptWitnessStack(
uint32_t tx_in_index, uint32_t witness_index,
const std::vector& data);
/**
- * @brief transactionのハッシュ値を取得する.
- * @param[in] has_witness witnessを計算に含めるか(wtxid計算を行うかどうか)
- * @return ハッシュ値
+ * @brief Get the hash value of transaction.
+ * @param[in] has_witness Whether to include witness in the calculation (whether to perform wtxid calculation)
+ * @return Hash value
*/
ByteData256 GetHash(bool has_witness) const;
/**
- * @brief Transactionのバイトデータを取得する.
- * @param[in] has_witness witnessを含めるかのフラグ
- * @return バイトデータ
+ * @brief Get the byte data of Transaction.
+ * @param[in] has_witness Flag to include witness
+ * @return byte data
*/
virtual ByteData GetByteData(bool has_witness) const = 0;
/**
- * @brief VariableIntデータを取得する.
- * @param[in] p_byte_data Byte配列アドレス
- * @param[in] data_size Byte配列サイズ
- * @param[out] p_result VariableIntデータ
- * @param[out] p_size VariableIntデータサイズ
- * @retval true 成功
- * @retval false 失敗
+ * @brief Get VariableInt data.
+ * @param[in] p_byte_data Byte array address
+ * @param[in] data_size Byte array size
+ * @param[out] p_result VariableInt data
+ * @param[out] p_size VariableInt data size
+ * @retval true success
+ * @retval false fail
*/
static bool GetVariableInt(
const uint8_t* p_byte_data, size_t data_size, uint64_t* p_result,
size_t* p_size);
/**
- * @brief VariableIntデータをコピーする.
- * @param[in] v VariableIntデータ
- * @param[out] bytes_out コピー先アドレス
- * @return コピー先アドレス
+ * @brief Copy VariableInt data.
+ * @param[in] v VariableInt data
+ * @param[out] bytes_out Copy destination address
+ * @return Copy destination address
*/
static uint8_t* CopyVariableInt(uint64_t v, uint8_t* bytes_out);
/**
- * @brief VariableBufferデータをコピーする.
- * @param[in] bytes Byte配列アドレス
- * @param[in] bytes_len Byte配列サイズ
- * @param[out] bytes_out コピー先アドレス
- * @return コピー先アドレス
+ * @brief Copy VariableBuffer data.
+ * @param[in] bytes Byte array address
+ * @param[in] bytes_len Byte array size
+ * @param[out] bytes_out Copy destination address
+ * @return Copy destination address
*/
static uint8_t* CopyVariableBuffer(
const uint8_t* bytes, size_t bytes_len, uint8_t* bytes_out);
/**
- * @brief libwallyのヒープアドレスを解放する。
- * @param[in] wally_tx_pointer アドレス
+ * @brief Free the libwally heap address.
+ * @param[in] wally_tx_pointer address
*/
static void FreeWallyAddress(const void* wally_tx_pointer);
};
/**
- * @brief signature計算を行うクラス.
+ * @brief A class that performs signature calculations.
*/
class CFD_CORE_EXPORT SignatureUtil {
public:
/**
- * @brief 楕円曲線暗号を用いて、秘密鍵からsignatureを計算する.
- * @param[in] signature_hash signatureハッシュ
- * @param[in] private_key 秘密鍵
- * @param[in] has_grind_r EC_FLAG_GRIND_Rフラグ有無
+ * @brief Calculate the signature from the private key using elliptic curve cryptography.
+ * @param[in] signature_hash signature hash
+ * @param[in] private_key private key
+ * @param[in] has_grind_r EC_FLAG_GRIND_R flag
* @return signature
*/
static ByteData CalculateEcSignature(
diff --git a/include/cfdcore/cfdcore_util.h b/include/cfdcore/cfdcore_util.h
index e4e0f671..7e2e0c83 100644
--- a/include/cfdcore/cfdcore_util.h
+++ b/include/cfdcore/cfdcore_util.h
@@ -2,7 +2,7 @@
/**
* @file cfdcore_util.h
*
- * @brief Utility関連クラス定義
+ * @brief The utility related class definition
*/
#ifndef CFD_CORE_INCLUDE_CFDCORE_CFDCORE_UTIL_H_
#define CFD_CORE_INCLUDE_CFDCORE_CFDCORE_UTIL_H_
@@ -20,17 +20,17 @@ namespace cfd {
namespace core {
/**
- * @brief 20byte長
+ * @brief 20byte length
*/
const uint32_t kByteData160Length = 20;
/**
- * @brief 32byte長
+ * @brief 32byte length
*/
const uint32_t kByteData256Length = 32;
/**
- * @brief 64byte長
+ * @brief 64byte length
*/
const uint32_t kByteData512Length = 64;
@@ -38,55 +38,73 @@ const uint32_t kByteData512Length = 64;
* @brief Sighash flags for transaction signing.
*/
enum SigHashAlgorithm {
- kSigHashAll = 0x01, //!< SIGHASH_ALL
- kSigHashNone = 0x02, //!< SIGHASH_NONE
- kSigHashSingle = 0x03, //!< SIGHASH_SINGLE
+ kSigHashDefault = 0, //!< default (= SIGHASH_ALL)
+ kSigHashAll = 0x01, //!< SIGHASH_ALL
+ kSigHashNone = 0x02, //!< SIGHASH_NONE
+ kSigHashSingle = 0x03, //!< SIGHASH_SINGLE
+ kSigHashUnknown = 0xffff //!< invalid
};
/**
- * @brief SigHash算出時の種別
+ * @brief Type when calculating SigHash
*/
class CFD_CORE_EXPORT SigHashType {
public:
/**
- * @brief SIGHASH_FORKIDフラグ
+ * @brief SIGHASH_FORKID flag
*/
const uint8_t kSigHashForkId = 0x40;
+ /*
+ * @brief SIGHASH_RANGEPROOF flag
+ */
+ // const uint8_t kSigHashRangeproof = 0x40;
+ // for feature
/**
- * @brief SIGHASH_ANYONECANPAYフラグ
+ * @brief SIGHASH_ANYONECANPAY flag
*/
const uint8_t kSigHashAnyOneCanPay = 0x80;
/**
- * @brief デフォルトコンストラクタ
+ * @brief Create by SigHash flag.
+ * @param[in] flag SigHash flag
+ * @param[in] is_append_anyone_can_pay add SIGHASH_ANYONECANPAY if true.
+ * @param[in] is_append_fork_id add SIGHASH_FORKID if true.
+ * @return SigHashType
+ */
+ static SigHashType Create(
+ uint8_t flag, bool is_append_anyone_can_pay = false,
+ bool is_append_fork_id = false);
+
+ /**
+ * @brief default constructor.
*/
SigHashType();
/**
- * @brief コンストラクタ
- * @param algorithm Sighashアルゴリズム
- * @param is_anyone_can_pay SIGHASH_ANYONECANPAYフラグ有無
- * @param is_fork_id SIGHASH_FORKIDフラグ有無
+ * @brief constructor.
+ * @param algorithm Sighash algorithm
+ * @param is_anyone_can_pay SIGHASH_ANYONECANPAY flag
+ * @param is_fork_id SIGHASH_FORKID flag
*/
explicit SigHashType(
SigHashAlgorithm algorithm, bool is_anyone_can_pay = false,
bool is_fork_id = false);
/**
- * @brief コピーコンストラクタ.
- * @param[in] sighash_type SigHashType オブジェクト
+ * @brief copy constructor.
+ * @param[in] sighash_type SigHashType
*/
SigHashType(const SigHashType &sighash_type);
/**
- * @brief コピーコンストラクタ.
- * @param[in] sighash_type SigHashType オブジェクト
- * @return SigHashType オブジェクト
+ * @brief copy constructor.
+ * @param[in] sighash_type SigHashType
+ * @return SigHashType
*/
SigHashType &operator=(const SigHashType &sighash_type);
/**
- * @brief SigHashフラグ取得
- * @return SigHashフラグ
+ * @brief Get a SigHash flag.
+ * @return SigHash flag
*/
uint32_t GetSigHashFlag() const;
@@ -108,245 +126,420 @@ class CFD_CORE_EXPORT SigHashType {
*/
bool IsForkId() const;
+ /**
+ * @brief Valid sighash state.
+ * @retval true valid
+ * @retval false invalid
+ */
+ bool IsValid() const;
+
/**
* @brief Set parameter from SigHash flag.
* @param[in] flag SigHash flag
*/
void SetFromSigHashFlag(uint8_t flag);
+ /**
+ * @brief Set SIGHASH_ANYONECANPAY flag.
+ * @param[in] is_anyone_can_pay SIGHASH_ANYONECANPAY flag
+ */
+ void SetAnyoneCanPay(bool is_anyone_can_pay);
+
+ /**
+ * @brief Get string.
+ * @return SigHashType string.
+ */
+ std::string ToString() const;
private:
/**
- * @brief Sighashアルゴリズム
+ * @brief Sighash algorithm
*/
SigHashAlgorithm hash_algorithm_;
/**
- * @brief SIGHASH_ANYONECANPAYフラグ有無
+ * @brief SIGHASH_ANYONECANPAY flag
*/
bool is_anyone_can_pay_;
/**
- * @brief SIGHASH_FORKIDフラグ有無
+ * @brief SIGHASH_FORKID flag
*/
bool is_fork_id_;
};
/**
- * @brief Hash関数を定義したUtilクラス
+ * @brief Util class that defines the Hash function.
*/
class CFD_CORE_EXPORT HashUtil {
public:
+ // Ripemd160 --------------------------------------------------------------
+ /**
+ * @brief Hash the string with Ripemd160.
+ * @param[in] str message text
+ * @return hashed data
+ */
+ static ByteData160 Ripemd160(const std::string &str);
+ /**
+ * @brief Hash the byte array with Ripemd160.
+ * @param[in] bytes message data
+ * @return hashed data
+ */
+ static ByteData160 Ripemd160(const std::vector &bytes);
+ /**
+ * @brief Hash the byte array with Ripemd160.
+ * @param[in] data message data
+ * @return hashed data
+ */
+ static ByteData160 Ripemd160(const ByteData &data);
+ /**
+ * @brief Hash the byte array with Ripemd160.
+ * @param[in] data message data
+ * @return hashed data
+ */
+ static ByteData160 Ripemd160(const ByteData160 &data);
+ /**
+ * @brief Hash the byte array with Ripemd160.
+ * @param[in] data message data
+ * @return hashed data
+ */
+ static ByteData160 Ripemd160(const ByteData256 &data);
+ /**
+ * @brief Hash the pubkey bytes with Ripemd160.
+ * @param[in] pubkey Pubkey
+ * @return pubkey hash
+ */
+ static ByteData160 Ripemd160(const Pubkey &pubkey);
+ /**
+ * @brief Hash the script bytes with Ripemd160.
+ * @param[in] script Script
+ * @return script hash
+ */
+ static ByteData160 Ripemd160(const Script &script);
+
// Hash160 --------------------------------------------------------------
/**
- * @brief 文字列をHash160でハッシュする.
- * @param[in] str 文字列
- * @return hashed ByteData160データ
+ * @brief Hash the string.
+ * @param[in] str string
+ * @return hashed data
*/
static ByteData160 Hash160(const std::string &str);
/**
- * @brief byteデータ配列をHash160でハッシュする.
- * @param[in] bytes byteデータ配列
- * @return hashed ByteData160データ
+ * @brief Hash the byte data array.
+ * @param[in] bytes byte array
+ * @return hashed data
*/
static ByteData160 Hash160(const std::vector &bytes);
/**
- * @brief ByteDataをHash160でハッシュする.
- * @param[in] data ByteDataインスタンス
- * @return hashed ByteData160データ
+ * @brief Hash the byte data array.
+ * @param[in] data byte array
+ * @return hashed data
*/
static ByteData160 Hash160(const ByteData &data);
/**
- * @brief ByteData160をHash160でハッシュする.
- * @param[in] data byteデータ配列
- * @return hashed ByteData160データ
+ * @brief Hash the byte data array.
+ * @param[in] data byte array
+ * @return hashed data
*/
static ByteData160 Hash160(const ByteData160 &data);
/**
- * @brief ByteData256をHash160でハッシュする.
- * @param[in] data byteデータ配列
- * @return hashed ByteData160データ
+ * @brief Hash the byte data array.
+ * @param[in] data byte array
+ * @return hashed data
*/
static ByteData160 Hash160(const ByteData256 &data);
/**
- * @brief 公開鍵をHash160でハッシュする.
- * @param[in] pubkey Pubkeyインスタンス
+ * @brief Hash the pubkey.
+ * @param[in] pubkey Pubkey
* @return pubkey hash
*/
static ByteData160 Hash160(const Pubkey &pubkey);
/**
- * @brief ScriptをHash160でハッシュする.
- * @param[in] script Scriptインスタンス
+ * @brief Hash the script.
+ * @param[in] script Script
* @return script hash
*/
static ByteData160 Hash160(const Script &script);
// Sha256 --------------------------------------------------------------
/**
- * @brief 文字列をSha256でハッシュする.
- * @param[in] str 文字列
- * @return hashed ByteData256データ
+ * @brief Hash the string.
+ * @param[in] str string
+ * @return hashed data
*/
static ByteData256 Sha256(const std::string &str);
/**
- * @brief byteデータ配列をSha256でハッシュする.
- * @param[in] bytes byteデータ配列
- * @return hashed ByteData256データ
+ * @brief Hash the byte data array.
+ * @param[in] bytes byte array
+ * @return hashed data
*/
static ByteData256 Sha256(const std::vector &bytes);
/**
- * @brief ByteDataをSha256でハッシュする.
- * @param[in] data ByteDataインスタンス
- * @return hashed ByteData256データ
+ * @brief Hash the byte data array.
+ * @param[in] data byte array
+ * @return hashed data
*/
static ByteData256 Sha256(const ByteData &data);
/**
- * @brief ByteData160をSha256でハッシュする.
- * @param[in] data ByteData160インスタンス
- * @return hashed ByteData256データ
+ * @brief Hash the byte data array.
+ * @param[in] data byte array
+ * @return hashed data
*/
static ByteData256 Sha256(const ByteData160 &data);
/**
- * @brief ByteData256をSha256でハッシュする.
- * @param[in] data ByteData256インスタンス
- * @return hashed ByteData256データ
+ * @brief Hash the byte data array.
+ * @param[in] data byte array
+ * @return hashed data
*/
static ByteData256 Sha256(const ByteData256 &data);
/**
- * @brief 公開鍵をSha256でハッシュする.
- * @param[in] pubkey Pubkeyインスタンス
+ * @brief Hash the pubkey.
+ * @param[in] pubkey Pubkey
* @return pubkey hash
*/
static ByteData256 Sha256(const Pubkey &pubkey);
/**
- * @brief ScriptをSha256でハッシュする.
- * @param[in] script Scriptインスタンス
+ * @brief Hash the script bytes with Ripemd160.
+ * @param[in] script Script
* @return script hash
*/
static ByteData256 Sha256(const Script &script);
// Sha256D --------------------------------------------------------------
/**
- * @brief 文字列をSha256Dでハッシュ化する.
- * @param[in] str 文字列
- * @return hashed ByteData256データ
+ * @brief Hash the string.
+ * @param[in] str string
+ * @return hashed data
*/
static ByteData256 Sha256D(const std::string &str);
/**
- * @brief byteデータ配列をSha256Dでハッシュ化する.
- * @param[in] bytes byteデータ配列
- * @return hashed ByteData256データ
+ * @brief Hash the byte data array.
+ * @param[in] bytes byte array
+ * @return hashed data
*/
static ByteData256 Sha256D(const std::vector &bytes);
/**
- * @brief ByteDataをSha256Dでハッシュ化する.
- * @param[in] data ByteDataインスタンス
- * @return hashed ByteData256データ
+ * @brief Hash the byte data array.
+ * @param[in] data byte array
+ * @return hashed data
*/
static ByteData256 Sha256D(const ByteData &data);
/**
- * @brief ByteData160をSha256Dでハッシュ化する.
- * @param[in] data ByteData160インスタンス
- * @return hashed ByteData256データ
+ * @brief Hash the byte data array.
+ * @param[in] data byte array
+ * @return hashed data
*/
static ByteData256 Sha256D(const ByteData160 &data);
/**
- * @brief ByteData256をSha256Dでハッシュ化する.
- * @param[in] data ByteData256インスタンス
- * @return hashed ByteData256データ
+ * @brief Hash the byte data array.
+ * @param[in] data byte array
+ * @return hashed data
*/
static ByteData256 Sha256D(const ByteData256 &data);
/**
- * @brief 公開鍵をSha256Dでハッシュ化する.
- * @param[in] pubkey Pubkeyインスタンス
- * @return hashed ByteData256データ
+ * @brief Hash the pubkey.
+ * @param[in] pubkey Pubkey
+ * @return pubkey hash
*/
static ByteData256 Sha256D(const Pubkey &pubkey);
/**
- * @brief ScriptをSha256Dでハッシュ化する.
- * @param[in] script Scriptインスタンス
- * @return hashed ByteData256データ
+ * @brief Hash the script bytes with Ripemd160.
+ * @param[in] script Script
+ * @return script hash
*/
static ByteData256 Sha256D(const Script &script);
// Sha512 ---------------------------------------------------------------
/**
- * @brief 文字列をSha512でハッシュ化する.
- * @param[in] str 文字列
- * @return hashed ByteDataデータ
+ * @brief Hash the string.
+ * @param[in] str string
+ * @return hashed data
*/
static ByteData Sha512(const std::string &str);
/**
- * @brief byteデータ配列をSha512でハッシュ化する.
- * @param[in] bytes byteデータ配列
- * @return hashed ByteDataデータ
+ * @brief Hash the byte data array.
+ * @param[in] bytes byte array
+ * @return hashed data
*/
static ByteData Sha512(const std::vector &bytes);
/**
- * @brief ByteDataをSha512でハッシュ化する.
- * @param[in] data ByteDataインスタンス
- * @return hashed ByteDataデータ
+ * @brief Hash the byte data array.
+ * @param[in] data byte array
+ * @return hashed data
*/
static ByteData Sha512(const ByteData &data);
/**
- * @brief ByteData160をSha512でハッシュ化する.
- * @param[in] data ByteData160インスタンス
- * @return hashed ByteDataデータ
+ * @brief Hash the byte data array.
+ * @param[in] data byte array
+ * @return hashed data
*/
static ByteData Sha512(const ByteData160 &data);
/**
- * @brief ByteData256をSha512でハッシュ化する.
- * @param[in] data ByteData256インスタンス
- * @return hashed ByteDataデータ
+ * @brief Hash the byte data array.
+ * @param[in] data byte array
+ * @return hashed data
*/
static ByteData Sha512(const ByteData256 &data);
/**
- * @brief 公開鍵をSha512でハッシュ化する.
- * @param[in] pubkey Pubkeyインスタンス
- * @return hashed ByteDataデータ
+ * @brief Hash the pubkey.
+ * @param[in] pubkey Pubkey
+ * @return pubkey hash
*/
static ByteData Sha512(const Pubkey &pubkey);
/**
- * @brief ScriptをSha512でハッシュ化する.
- * @param[in] script Scriptインスタンス
- * @return hashed ByteDataデータ
+ * @brief Hash the script bytes with Ripemd160.
+ * @param[in] script Script
+ * @return script hash
*/
static ByteData Sha512(const Script &script);
+ // builder ---------------------------------------------------------------
+ //! HashType: Ripemd160
+ static constexpr uint8_t kRipemd160 = 1;
+ //! HashType: Hash160
+ static constexpr uint8_t kHash160 = 2;
+ //! HashType: Sha256
+ static constexpr uint8_t kSha256 = 3;
+ //! HashType: Sha256D
+ static constexpr uint8_t kSha256D = 4;
+ //! HashType: Sha512
+ static constexpr uint8_t kSha512 = 5;
+
+ /**
+ * @brief constructor.
+ * @param[in] hash_type hash type.
+ */
+ explicit HashUtil(uint8_t hash_type);
+ /**
+ * @brief constructor.
+ * @param[in] hash_type hash type.
+ */
+ explicit HashUtil(const std::string &hash_type);
+ /**
+ * @brief destructor.
+ */
+ virtual ~HashUtil() {}
+ /**
+ * @brief copy constructor.
+ * @param[in] object object
+ */
+ HashUtil(const HashUtil &object);
+ /**
+ * @brief copy constructor.
+ * @param[in] object object
+ * @return object
+ */
+ HashUtil &operator=(const HashUtil &object);
+
+ /**
+ * @brief Hash the string.
+ * @param[in] str string
+ * @return hash util object.
+ */
+ HashUtil &operator<<(const std::string &str);
+ /**
+ * @brief Hash the byte data array.
+ * @param[in] bytes byte array
+ * @return hash util object.
+ */
+ HashUtil &operator<<(const std::vector &bytes);
+ /**
+ * @brief Hash the byte data array.
+ * @param[in] data byte array
+ * @return hash util object.
+ */
+ HashUtil &operator<<(const ByteData &data);
+ /**
+ * @brief Hash the byte data array.
+ * @param[in] data byte array
+ * @return hash util object.
+ */
+ HashUtil &operator<<(const ByteData160 &data);
+ /**
+ * @brief Hash the byte data array.
+ * @param[in] data byte array
+ * @return hash util object.
+ */
+ HashUtil &operator<<(const ByteData256 &data);
+ /**
+ * @brief Hash the pubkey.
+ * @param[in] pubkey Pubkey
+ * @return hash util object.
+ */
+ HashUtil &operator<<(const Pubkey &pubkey);
+ /**
+ * @brief Hash the script bytes with Ripemd160.
+ * @param[in] script Script
+ * @return hash util object.
+ */
+ HashUtil &operator<<(const Script &script);
+ /**
+ * @brief Output data.
+ * @return hashed data
+ */
+ ByteData Output();
+ /**
+ * @brief Output data.
+ * @return hashed data
+ */
+ ByteData160 Output160();
+ /**
+ * @brief Output data.
+ * @return hashed data
+ */
+ ByteData256 Output256();
+
private:
HashUtil();
+
+ uint8_t hash_type_; //!< hash type
+ ByteData buffer_; //!< buffer
};
/**
* @class CryptoUtil
- * @brief 暗号化/復号化関数のUtilクラス
+ * @brief Utility class of encryption / decryption function
*/
class CFD_CORE_EXPORT CryptoUtil {
public:
- /// AES Blockサイズ
+ /// AES Block size
static const size_t kAesBlockLength = 16;
/**
- * @brief 文字列をAES256暗号化する.
- * @param[in] key keyとなる32Byteの配列データ
- * @param[in] data 暗号化する文字列
- * @return 暗号化したByteData
+ * @brief AES256 encryption of the string.
+ * @param[in] key 32-byte array data as a key
+ * @param[in] data String to encrypt
+ * @return Encrypted ByteData
*/
static ByteData EncryptAes256(
const std::vector &key, const std::string &data);
/**
- * @brief ByteDataをAES256復号化する.
- * @param[in] key keyとなる32Byteの配列データ
- * @param[in] data 暗号化されたByteData
- * @return 復号化した文字列
+ * @brief Encrypto ByteData with AES256.
+ * @param[in] key key array with 32Byte.
+ * @param[in] data target byte data.
+ * @return encrypted byte data.
+ */
+ static ByteData EncryptAes256(const ByteData &key, const ByteData &data);
+ /**
+ * @brief Decrypt ByteData to AES256.
+ * @param[in] key key array with 32Byte.
+ * @param[in] data encrypted byte data.
+ * @return decrypted byte data.
*/
static std::string DecryptAes256ToString(
const std::vector &key, const ByteData &data);
/**
- * @brief 文字列をAES256CBC暗号化する.
- * @param[in] key keyとなる32Byteの配列データ
- * @param[in] iv initial vectorとなる16Byteの配列データ
- * @param[in] data 暗号化するByteData
- * @return 暗号化したByteData
+ * @brief Decrypto ByteData with AES256.
+ * @param[in] key key array with 32Byte.
+ * @param[in] data target encrypted byte data.
+ * @return decrypted byte data.
+ */
+ static ByteData DecryptAes256(const ByteData &key, const ByteData &data);
+ /**
+ * @brief AES256CBC encryption of the string.
+ * @param[in] key 32-byte array data as a key
+ * @param[in] iv 16Byte array data that will be the initial vector
+ * @param[in] data target byte data.
+ * @return encrypted byte data.
*/
static ByteData EncryptAes256Cbc(
const std::vector &key, const std::vector &iv,
@@ -361,11 +554,11 @@ class CFD_CORE_EXPORT CryptoUtil {
static ByteData EncryptAes256Cbc(
const ByteData &key, const ByteData &iv, const ByteData &data);
/**
- * @brief ByteDataをAES256CBC復号化する.
- * @param[in] key keyとなる32Byteの配列データ
- * @param[in] iv initial vectorとなる16Byteの配列データ
- * @param[in] data 暗号化されたByteData
- * @return 復号化した文字列
+ * @brief Decrypt ByteData to AES256CBC.
+ * @param[in] key key array with 32Byte.
+ * @param[in] iv initial vector with 16Byte.
+ * @param[in] data target encrypted byte data.
+ * @return decrypted byte data.
*/
static std::string DecryptAes256CbcToString(
const std::vector &key, const std::vector &iv,
@@ -380,10 +573,10 @@ class CFD_CORE_EXPORT CryptoUtil {
static ByteData DecryptAes256Cbc(
const ByteData &key, const ByteData &iv, const ByteData &data);
/**
- * @brief ByteDataのHMAC-SHA256を計算する.
- * @param[in] key keyとなるByte配列データ
- * @param[in] data ByteDataインスタンス
- * @return ByteData256データ
+ * @brief Calculate HMAC-SHA256 for ByteData.
+ * @param[in] key Byte array data as a key
+ * @param[in] data ByteData object
+ * @return ByteData256 data
*/
static ByteData256 HmacSha256(
const std::vector &key, const ByteData &data);
@@ -395,10 +588,10 @@ class CFD_CORE_EXPORT CryptoUtil {
*/
static ByteData256 HmacSha256(const ByteData &key, const ByteData &data);
/**
- * @brief ByteDataのHMAC-SHA512を計算する.
- * @param[in] key keyとなるByte配列データ
- * @param[in] data ByteDataインスタンス
- * @return ByteDataデータ
+ * @brief Calculate HMAC-SHA512 for ByteData.
+ * @param[in] key key-byte-array
+ * @param[in] data input-data
+ * @return ByteData
*/
static ByteData HmacSha512(
const std::vector &key, const ByteData &data);
@@ -433,15 +626,15 @@ class CFD_CORE_EXPORT CryptoUtil {
static ByteData ConvertSignatureFromDer(
const ByteData &der_data, SigHashType *sighash_type);
/**
- * @brief ByteDataをBase64エンコードする.
- * @param[in] data エンコードするByteData
- * @return encodeした文字列
+ * @brief Base64 encode ByteData.
+ * @param[in] data ByteData to encode
+ * @return encoded string
*/
static std::string EncodeBase64(const ByteData &data);
/**
- * @brief 文字列をBase64デコードする.
- * @param[in] str Base64エンコードされた文字列
- * @return decodeしたByteData
+ * @brief Base64 decode the string.
+ * @param[in] str Base64 encoded string
+ * @return decoded ByteData
*/
static ByteData DecodeBase64(const std::string &str);
/**
@@ -451,9 +644,9 @@ class CFD_CORE_EXPORT CryptoUtil {
*/
static ByteData DecodeBase58(const std::string &str);
/**
- * @brief 文字列をBase58デコードおよびチェックサム確認する.
- * @param[in] str Base58エンコードされた文字列
- * @return decodeしたByteData
+ * @brief Base58 decode and checksum check the string.
+ * @param[in] str Base58 encoded string
+ * @return decoded ByteData
*/
static ByteData DecodeBase58Check(const std::string &str);
/**
@@ -470,7 +663,7 @@ class CFD_CORE_EXPORT CryptoUtil {
static std::string EncodeBase58Check(const ByteData &data);
/**
- * @brief merkle rootの簡易計算を行う。
+ * @brief Perform a simple calculation of merkle root.
* @param[in] hashes hash list
* @return merkle root
*/
@@ -478,7 +671,7 @@ class CFD_CORE_EXPORT CryptoUtil {
const std::vector &hashes);
/**
- * @brief merkle hash計算を行う。
+ * @brief Perform merkle hash calculation.
* @param[in] left left hash
* @param[in] right right hash
* @return merkle hash
@@ -492,25 +685,25 @@ class CFD_CORE_EXPORT CryptoUtil {
/**
* @class RandomNumberUtil
- * @brief 乱数関連関数のUtilクラス
+ * @brief Utility class of random number related functions
*/
class CFD_CORE_EXPORT RandomNumberUtil {
public:
/**
- * 乱数を生成する.
- * @param[in] len 乱数の長さ
- * @return 乱数配列
+ * @brief Generate random numbers.
+ * @param[in] len Random number length
+ * @return Random number array
*/
static std::vector GetRandomBytes(int len);
/**
- * 乱数で指定範囲のIndexListを生成する.
- * @param[in] length リストの長さ
+ * @brief Generate IndexList of specified range with random numbers.
+ * @param[in] length List length
* @return index list
*/
static std::vector GetRandomIndexes(uint32_t length);
/**
- * ランダムなbool値を生成する.
- * @param[in,out] random_cache 乱数キャッシュ値
+ * @brief Generate a random bool value.
+ * @param[in,out] random_cache Random number cache value
* @return true/false
*/
static bool GetRandomBool(std::vector *random_cache);
@@ -521,35 +714,42 @@ class CFD_CORE_EXPORT RandomNumberUtil {
/**
* @class StringUtil
- * @brief 文字列操作Utilクラス
+ * @brief String manipulation Util class.
*/
class CFD_CORE_EXPORT StringUtil {
public:
/**
- * @brief hex文字列からbyteデータ配列への変換をする.
- * @param[in] hex_str HEX文字列
- * @return byteデータ配列
+ * @brief Check hex string.
+ * @param[in] hex_str HEX string
+ * @retval true valid hex string.
+ * @retval false invalid string.
+ */
+ static bool IsValidHexString(const std::string &hex_str);
+ /**
+ * @brief Convert from hex character string to byte data array.
+ * @param[in] hex_str HEX string
+ * @return byte data array.
*/
static std::vector StringToByte(const std::string &hex_str);
/**
- * @brief byteデータ配列からHEX文字列への変換をする.
- * @param[in] bytes byteデータ配列
- * @return HEX文字列
+ * @brief Convert from byte data array to HEX character string.
+ * @param[in] bytes byte data array
+ * @return HEX string
*/
static std::string ByteToString(const std::vector &bytes);
/**
- * @brief 文字列を区切り文字で分割する.
- * @param[in] str 分割対象文字列
- * @param[in] delim 区切り文字列
- * @return 区切り文字で区切られた文字列vector
+ * @brief Divide the string by the delimiter.
+ * @param[in] str Character string to be divided
+ * @param[in] delim Delimiter string
+ * @return String vector separated by delimiter
*/
static std::vector Split(
const std::string &str, const std::string &delim);
/**
- * @brief 文字列配列を連結する.
- * @param[in] str_list 文字列配列
- * @param[in] separate_word 連結文字列
- * @return 連結された文字列
+ * @brief Concatenate string arrays.
+ * @param[in] str_list String array
+ * @param[in] separate_word Concatenated string
+ * @return Concatenated string
*/
static std::string Join(
const std::vector &str_list,
diff --git a/package.json b/package.json
index be7dfb9a..0e73c6f2 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "cfd-core",
- "version": "0.2.0",
+ "version": "0.3.0",
"description": "cfd-core",
"scripts": {
"code_format": "clang-format -i --style=file src/*.cpp src/*.h src/include/cfdcore/*.h include/cfdcore/*.h",
diff --git a/src/Makefile.srclist b/src/Makefile.srclist
index c77d5dd2..21b0f897 100644
--- a/src/Makefile.srclist
+++ b/src/Makefile.srclist
@@ -18,8 +18,10 @@ CFDCORE_SOURCES = \
cfdcore_amount.cpp \
cfdcore_coin.cpp \
cfdcore_address.cpp \
+ cfdcore_psbt.cpp \
cfdcore_secp256k1.cpp \
cfdcore_schnorrsig.cpp \
+ cfdcore_taproot.cpp \
secp256k1_util.cpp \
cfdcore_ecdsa_adaptor.cpp \
${CFDCORE_ELEMENTS_SOURCES}
diff --git a/src/cfdcore_address.cpp b/src/cfdcore_address.cpp
index b4a8355c..701d4279 100644
--- a/src/cfdcore_address.cpp
+++ b/src/cfdcore_address.cpp
@@ -2,8 +2,7 @@
/**
* @file cfdcore_address.cpp
*
- * @brief \~japanese Addressを表現するクラス
- * \~english Class to show address.
+ * @brief Class to show address.
*/
#include "cfdcore/cfdcore_address.h"
@@ -14,6 +13,7 @@
#include "cfdcore/cfdcore_logger.h"
#include "cfdcore/cfdcore_script.h"
+#include "cfdcore/cfdcore_taproot.h"
#include "cfdcore/cfdcore_util.h"
#include "cfdcore_wally_util.h" // NOLINT
#include "univalue.h" // NOLINT
@@ -197,11 +197,43 @@ Address::Address()
address_(""),
hash_(),
pubkey_(),
+ schnorr_pubkey_(),
redeem_script_() {
memset(checksum_, 0, sizeof(checksum_));
info(CFD_LOG_SOURCE, "call Address()");
}
+Address::Address(const Address& object)
+ : type_(object.type_),
+ addr_type_(object.addr_type_),
+ witness_ver_(object.witness_ver_),
+ address_(object.address_),
+ hash_(object.hash_),
+ pubkey_(object.pubkey_),
+ schnorr_pubkey_(object.schnorr_pubkey_),
+ script_tree_(object.script_tree_),
+ redeem_script_(object.redeem_script_) {
+ memcpy(checksum_, object.checksum_, sizeof(checksum_));
+ format_data_ = object.format_data_;
+}
+
+Address& Address::operator=(const Address& object) {
+ if (this != &object) {
+ type_ = object.type_;
+ addr_type_ = object.addr_type_;
+ witness_ver_ = object.witness_ver_;
+ address_ = object.address_;
+ hash_ = object.hash_;
+ pubkey_ = object.pubkey_;
+ schnorr_pubkey_ = object.schnorr_pubkey_;
+ script_tree_ = object.script_tree_;
+ redeem_script_ = object.redeem_script_;
+ memcpy(checksum_, object.checksum_, sizeof(checksum_));
+ format_data_ = object.format_data_;
+ }
+ return *this;
+}
+
Address::Address(const std::string& address_string)
: type_(kMainnet),
addr_type_(kP2shAddress),
@@ -209,6 +241,7 @@ Address::Address(const std::string& address_string)
address_(address_string),
hash_(),
pubkey_(),
+ schnorr_pubkey_(),
redeem_script_() {
memset(checksum_, 0, sizeof(checksum_));
DecodeAddress(address_string, nullptr);
@@ -223,6 +256,7 @@ Address::Address(
address_(address_string),
hash_(),
pubkey_(),
+ schnorr_pubkey_(),
redeem_script_() {
memset(checksum_, 0, sizeof(checksum_));
const std::vector* params = nullptr;
@@ -241,6 +275,7 @@ Address::Address(
address_(address_string),
hash_(),
pubkey_(),
+ schnorr_pubkey_(),
redeem_script_() {
memset(checksum_, 0, sizeof(checksum_));
const std::vector params = {network_parameter};
@@ -259,6 +294,7 @@ Address::Address(NetType type, const Pubkey& pubkey, uint8_t prefix)
address_(""),
hash_(),
pubkey_(pubkey),
+ schnorr_pubkey_(),
redeem_script_() {
memset(checksum_, 0, sizeof(checksum_));
CalculateP2PKH(prefix);
@@ -276,6 +312,7 @@ Address::Address(
address_(""),
hash_(),
pubkey_(pubkey),
+ schnorr_pubkey_(),
redeem_script_(),
format_data_(network_parameter) {
memset(checksum_, 0, sizeof(checksum_));
@@ -295,6 +332,7 @@ Address::Address(
address_(""),
hash_(),
pubkey_(pubkey),
+ schnorr_pubkey_(),
redeem_script_(),
format_data_(GetTargetFormatData(network_parameters, type)) {
memset(checksum_, 0, sizeof(checksum_));
@@ -317,6 +355,7 @@ Address::Address(NetType type, const Script& script, uint8_t prefix)
address_(""),
hash_(),
pubkey_(),
+ schnorr_pubkey_(),
redeem_script_(script) {
memset(checksum_, 0, sizeof(checksum_));
CalculateP2SH(prefix);
@@ -334,6 +373,7 @@ Address::Address(
address_(""),
hash_(),
pubkey_(),
+ schnorr_pubkey_(),
redeem_script_(script),
format_data_(network_parameter) {
memset(checksum_, 0, sizeof(checksum_));
@@ -353,6 +393,7 @@ Address::Address(
address_(""),
hash_(),
pubkey_(),
+ schnorr_pubkey_(),
redeem_script_(script),
format_data_(GetTargetFormatData(network_parameters, type)) {
memset(checksum_, 0, sizeof(checksum_));
@@ -378,6 +419,7 @@ Address::Address(
address_(""),
hash_(),
pubkey_(pubkey),
+ schnorr_pubkey_(),
redeem_script_() {
memset(checksum_, 0, sizeof(checksum_));
CalculateP2WPKH(bech32_hrp);
@@ -395,6 +437,7 @@ Address::Address(
address_(""),
hash_(),
pubkey_(pubkey),
+ schnorr_pubkey_(),
redeem_script_(),
format_data_(network_parameter) {
memset(checksum_, 0, sizeof(checksum_));
@@ -414,6 +457,7 @@ Address::Address(
address_(""),
hash_(),
pubkey_(pubkey),
+ schnorr_pubkey_(),
redeem_script_(),
format_data_(GetTargetFormatData(network_parameters, type)) {
memset(checksum_, 0, sizeof(checksum_));
@@ -439,6 +483,7 @@ Address::Address(
address_(""),
hash_(),
pubkey_(),
+ schnorr_pubkey_(),
redeem_script_(script) {
memset(checksum_, 0, sizeof(checksum_));
CalculateP2WSH(bech32_hrp);
@@ -456,6 +501,7 @@ Address::Address(
address_(""),
hash_(),
pubkey_(),
+ schnorr_pubkey_(),
redeem_script_(script),
format_data_(network_parameter) {
memset(checksum_, 0, sizeof(checksum_));
@@ -475,6 +521,7 @@ Address::Address(
address_(""),
hash_(),
pubkey_(),
+ schnorr_pubkey_(),
redeem_script_(script),
format_data_(GetTargetFormatData(network_parameters, type)) {
memset(checksum_, 0, sizeof(checksum_));
@@ -485,6 +532,141 @@ Address::Address(
AddressType::kP2wshAddress, format_data_.GetBech32Hrp());
}
+Address::Address(
+ NetType type, WitnessVersion witness_ver, const SchnorrPubkey& pubkey)
+ : Address(type, witness_ver, pubkey, "") {
+ // do nothing
+}
+
+Address::Address(
+ NetType type, WitnessVersion witness_ver, const SchnorrPubkey& pubkey,
+ const std::string& bech32_hrp)
+ : type_((!bech32_hrp.empty()) ? kCustomChain : type),
+ addr_type_(AddressType::kTaprootAddress),
+ witness_ver_(witness_ver),
+ address_(""),
+ hash_(),
+ pubkey_(),
+ schnorr_pubkey_(pubkey),
+ redeem_script_() {
+ memset(checksum_, 0, sizeof(checksum_));
+ CalculateTaproot(bech32_hrp);
+ info(
+ CFD_LOG_SOURCE, "call Address({},{},{})", type_, addr_type_, bech32_hrp);
+}
+
+Address::Address(
+ NetType type, WitnessVersion witness_ver, const SchnorrPubkey& pubkey,
+ const AddressFormatData& network_parameter)
+ : type_(type),
+ addr_type_(AddressType::kTaprootAddress),
+ witness_ver_(witness_ver),
+ address_(""),
+ hash_(),
+ pubkey_(),
+ schnorr_pubkey_(pubkey),
+ redeem_script_(),
+ format_data_(network_parameter) {
+ memset(checksum_, 0, sizeof(checksum_));
+ SetNetType(format_data_);
+ CalculateTaproot(network_parameter.GetBech32Hrp());
+ info(
+ CFD_LOG_SOURCE, "call Address({},{},{})", type_, addr_type_,
+ network_parameter.GetBech32Hrp());
+}
+
+Address::Address(
+ NetType type, WitnessVersion witness_ver, const SchnorrPubkey& pubkey,
+ const std::vector& network_parameters)
+ : type_(type),
+ addr_type_(AddressType::kTaprootAddress),
+ witness_ver_(witness_ver),
+ address_(""),
+ hash_(),
+ pubkey_(),
+ schnorr_pubkey_(pubkey),
+ redeem_script_(),
+ format_data_(GetTargetFormatData(network_parameters, type)) {
+ memset(checksum_, 0, sizeof(checksum_));
+ SetNetType(format_data_);
+ CalculateTaproot(format_data_.GetBech32Hrp());
+ info(
+ CFD_LOG_SOURCE, "call Address({},{},{})", type_, addr_type_,
+ format_data_.GetBech32Hrp());
+}
+
+Address::Address(
+ NetType type, WitnessVersion witness_ver, const TaprootScriptTree& tree,
+ const SchnorrPubkey& internal_pubkey)
+ : Address(type, witness_ver, tree, internal_pubkey, "") {
+ // do nothing
+}
+
+Address::Address(
+ NetType type, WitnessVersion witness_ver, const TaprootScriptTree& tree,
+ const SchnorrPubkey& internal_pubkey, const std::string& bech32_hrp)
+ : type_((!bech32_hrp.empty()) ? kCustomChain : type),
+ addr_type_(AddressType::kTaprootAddress),
+ witness_ver_(witness_ver),
+ address_(""),
+ hash_(),
+ pubkey_(),
+ schnorr_pubkey_(),
+ script_tree_(tree),
+ redeem_script_() {
+ memset(checksum_, 0, sizeof(checksum_));
+ schnorr_pubkey_ = tree.GetTweakedPubkey(internal_pubkey);
+ CalculateTaproot(bech32_hrp);
+ info(
+ CFD_LOG_SOURCE, "call Address({},{},{})", type_, addr_type_, bech32_hrp);
+}
+
+Address::Address(
+ NetType type, WitnessVersion witness_ver, const TaprootScriptTree& tree,
+ const SchnorrPubkey& internal_pubkey,
+ const AddressFormatData& network_parameter)
+ : type_(type),
+ addr_type_(AddressType::kTaprootAddress),
+ witness_ver_(witness_ver),
+ address_(""),
+ hash_(),
+ pubkey_(),
+ schnorr_pubkey_(),
+ script_tree_(tree),
+ redeem_script_(),
+ format_data_(network_parameter) {
+ memset(checksum_, 0, sizeof(checksum_));
+ SetNetType(format_data_);
+ schnorr_pubkey_ = tree.GetTweakedPubkey(internal_pubkey);
+ CalculateTaproot(network_parameter.GetBech32Hrp());
+ info(
+ CFD_LOG_SOURCE, "call Address({},{},{})", type_, addr_type_,
+ network_parameter.GetBech32Hrp());
+}
+
+Address::Address(
+ NetType type, WitnessVersion witness_ver, const TaprootScriptTree& tree,
+ const SchnorrPubkey& internal_pubkey,
+ const std::vector& network_parameters)
+ : type_(type),
+ addr_type_(AddressType::kTaprootAddress),
+ witness_ver_(witness_ver),
+ address_(""),
+ hash_(),
+ pubkey_(),
+ schnorr_pubkey_(),
+ script_tree_(tree),
+ redeem_script_(),
+ format_data_(GetTargetFormatData(network_parameters, type)) {
+ memset(checksum_, 0, sizeof(checksum_));
+ SetNetType(format_data_);
+ schnorr_pubkey_ = tree.GetTweakedPubkey(internal_pubkey);
+ CalculateTaproot(format_data_.GetBech32Hrp());
+ info(
+ CFD_LOG_SOURCE, "call Address({},{},{})", type_, addr_type_,
+ format_data_.GetBech32Hrp());
+}
+
Address::Address(NetType type, AddressType addr_type, const ByteData160& hash)
: type_(type),
addr_type_(addr_type),
@@ -492,6 +674,7 @@ Address::Address(NetType type, AddressType addr_type, const ByteData160& hash)
address_(""),
hash_(hash.GetBytes()),
pubkey_(),
+ schnorr_pubkey_(),
redeem_script_() {
memset(checksum_, 0, sizeof(checksum_));
if (addr_type == kP2pkhAddress) {
@@ -515,6 +698,7 @@ Address::Address(
address_(""),
hash_(hash.GetBytes()),
pubkey_(),
+ schnorr_pubkey_(),
redeem_script_(),
format_data_(network_parameter) {
memset(checksum_, 0, sizeof(checksum_));
@@ -547,10 +731,11 @@ Address::Address(
address_(""),
hash_(hash),
pubkey_(),
+ schnorr_pubkey_(),
redeem_script_() {
memset(checksum_, 0, sizeof(checksum_));
- if (witness_ver_ != WitnessVersion::kVersionNone) {
+ if (witness_ver_ == WitnessVersion::kVersion0) {
if (hash.GetDataSize() == kByteData160Length) {
SetAddressType(kP2wpkhAddress);
CalculateP2WPKH(ByteData160(hash.GetBytes()));
@@ -562,6 +747,15 @@ Address::Address(
info(CFD_LOG_SOURCE, "illegal hash data. hash={}", hash.GetHex());
throw CfdException(kCfdIllegalArgumentError, "hash value error.");
}
+ } else if (witness_ver_ != WitnessVersion::kVersionNone) {
+ if ((witness_ver_ == WitnessVersion::kVersion1) &&
+ (hash.GetDataSize() == SchnorrPubkey::kSchnorrPubkeySize)) {
+ SetAddressType(kTaprootAddress);
+ schnorr_pubkey_ = SchnorrPubkey(hash);
+ } else {
+ SetAddressType(kWitnessUnknown);
+ }
+ CalculateBech32m(hash);
}
}
@@ -574,11 +768,12 @@ Address::Address(
address_(""),
hash_(hash),
pubkey_(),
+ schnorr_pubkey_(),
redeem_script_(),
format_data_(network_parameter) {
memset(checksum_, 0, sizeof(checksum_));
- if (witness_ver_ != WitnessVersion::kVersionNone) {
+ if (witness_ver_ == WitnessVersion::kVersion0) {
if (hash.GetDataSize() == kByteData160Length) {
SetAddressType(kP2wpkhAddress);
SetNetType(format_data_);
@@ -594,6 +789,16 @@ Address::Address(
info(CFD_LOG_SOURCE, "illegal hash data. hash={}", hash.GetHex());
throw CfdException(kCfdIllegalArgumentError, "hash value error.");
}
+ } else if (witness_ver_ != WitnessVersion::kVersionNone) {
+ if ((witness_ver_ == WitnessVersion::kVersion1) &&
+ (hash.GetDataSize() == SchnorrPubkey::kSchnorrPubkeySize)) {
+ SetAddressType(kTaprootAddress);
+ schnorr_pubkey_ = SchnorrPubkey(hash);
+ } else {
+ SetAddressType(kWitnessUnknown);
+ }
+ SetNetType(format_data_);
+ CalculateBech32m(hash, network_parameter.GetBech32Hrp());
}
}
@@ -770,8 +975,45 @@ void Address::CalculateP2WPKH(
address_ = WallyUtil::ConvertStringAndFree(output);
}
+void Address::CalculateTaproot(const std::string& bech32_hrp) {
+ hash_ = schnorr_pubkey_.GetData();
+ CalculateBech32m(hash_, bech32_hrp);
+}
+
+void Address::CalculateBech32m(
+ const ByteData& hash_data, const std::string& bech32_hrp) {
+ std::vector pubkey_hash = hash_data.GetBytes();
+ pubkey_hash.insert(
+ pubkey_hash.begin(), static_cast(kByteData256Length));
+ pubkey_hash.insert(pubkey_hash.begin(), witness_ver_ + kOp_1 - 1);
+
+ std::string human_code = bech32_hrp;
+ if (human_code.empty() && (kMainnet <= type_) && (type_ <= kRegtest)) {
+ human_code = kBitcoinAddressFormatList[type_].GetBech32Hrp();
+ format_data_ = kBitcoinAddressFormatList[type_];
+ SetNetType(format_data_);
+ }
+ char* output = NULL;
+ int ret = wally_addr_segwit_from_bytes(
+ pubkey_hash.data(), pubkey_hash.size(), human_code.data(), 0, &output);
+ if (ret != WALLY_OK) {
+ warn(CFD_LOG_SOURCE, "wally_addr_segwit_from_bytes error. ret={}.", ret);
+ info(
+ CFD_LOG_SOURCE, "input hash={}",
+ StringUtil::ByteToString(pubkey_hash));
+ if (ret == WALLY_EINVAL) {
+ throw CfdException(
+ kCfdIllegalArgumentError, "Segwit-address create error.");
+ } else {
+ throw CfdException(kCfdInternalError, "Segwit-address create error.");
+ }
+ }
+
+ address_ = WallyUtil::ConvertStringAndFree(output);
+}
+
void Address::DecodeAddress(
- std::string bs58,
+ std::string address_string,
const std::vector* network_parameters) {
static const std::string kBech32Separator = "1";
static const auto StartsWith = [](const std::string& message,
@@ -779,6 +1021,7 @@ void Address::DecodeAddress(
return (message.find(bech32_hrp + kBech32Separator) == 0);
};
+ std::string bs58 = address_string;
std::string segwit_prefix = "";
int ret = -1;
@@ -823,12 +1066,24 @@ void Address::DecodeAddress(
}
data_part.resize(written);
- witness_ver_ = kVersion0;
+ Script script(ByteData(data_part.data(), static_cast(written)));
+ if (!script.IsWitnessProgram()) {
+ throw CfdException(kCfdInternalError, "address decode check error.");
+ }
+ witness_ver_ = script.GetWitnessVersion();
- if (written == kScriptHashP2wpkhLength) {
- SetAddressType(kP2wpkhAddress);
- } else if (written == kScriptHashP2wshLength) {
- SetAddressType(kP2wshAddress);
+ if (witness_ver_ == kVersion1) {
+ if (written != (SchnorrPubkey::kSchnorrPubkeySize + 2)) {
+ throw CfdException(
+ kCfdInternalError, "segwit v1 address decode check error.");
+ }
+ SetAddressType(kTaprootAddress);
+ } else if (witness_ver_ == kVersion0) {
+ if (written == kScriptHashP2wpkhLength) {
+ SetAddressType(kP2wpkhAddress);
+ } else if (written == kScriptHashP2wshLength) {
+ SetAddressType(kP2wshAddress);
+ }
}
// Delete 0byte:WitnessVersion and 1byte:data_part
@@ -891,6 +1146,7 @@ void Address::DecodeAddress(
// Setting for Hash.
hash_ = ByteData(data_part);
+ if (witness_ver_ == kVersion1) schnorr_pubkey_ = SchnorrPubkey(hash_);
SetNetType(format_data_);
info(
CFD_LOG_SOURCE, "DecodeAddress nettype={},{}", format_data_.GetNetType(),
@@ -931,6 +1187,10 @@ AddressFormatData Address::GetTargetFormatData(
Script Address::GetLockingScript() const {
Script locking_script;
switch (addr_type_) {
+ case AddressType::kTaprootAddress:
+ locking_script =
+ ScriptUtil::CreateTaprootLockingScript(ByteData256(hash_));
+ break;
case AddressType::kP2pkhAddress: {
ByteData160 pubkey_hash(hash_.GetBytes());
locking_script = ScriptUtil::CreateP2pkhLockingScript(pubkey_hash);
diff --git a/src/cfdcore_amount.cpp b/src/cfdcore_amount.cpp
index 002bcb68..25e07dfc 100644
--- a/src/cfdcore_amount.cpp
+++ b/src/cfdcore_amount.cpp
@@ -2,8 +2,7 @@
/**
* @file cfdcore_amount.cpp
*
- * @brief \~japanese Amountを表現するクラス
- * \~english Class to show amount.
+ * @brief Class to show amount.
*/
#include "cfdcore/cfdcore_amount.h"
diff --git a/src/cfdcore_bytedata.cpp b/src/cfdcore_bytedata.cpp
index dd3476cd..8bac8c46 100644
--- a/src/cfdcore_bytedata.cpp
+++ b/src/cfdcore_bytedata.cpp
@@ -2,8 +2,7 @@
/**
* @file cfdcore_bytedata.cpp
*
- * @brief \~japanese ByteData関連クラス実装
- * \~english implimentation of ByteData class
+ * @brief implimentation of ByteData class
*/
#include "cfdcore/cfdcore_bytedata.h"
@@ -20,31 +19,6 @@ namespace core {
using logger::warn;
-// -----------------------------------------------------------------------------
-// inner file
-// -----------------------------------------------------------------------------
-static constexpr uint8_t kViTag16 = 253; //!< VarInt16
-static constexpr uint8_t kViTag32 = 254; //!< VarInt32
-static constexpr uint8_t kViTag64 = 255; //!< VarInt64
-static constexpr uint8_t kViMax8 = 252; //!< VarInt8
-
-/**
- * @brief serialize from buffer.
- * @param[in] data buffer
- * @result serialize buffer
- */
-static std::vector SerializeFromBuffer(
- const std::vector& data) {
- std::vector result;
- std::vector count_buffer =
- ByteData::GetVariableInt(data.size()).GetBytes();
- result.insert(result.end(), count_buffer.begin(), count_buffer.end());
- if (data.size() != 0) {
- result.insert(result.end(), data.begin(), data.end());
- }
- return result;
-}
-
//////////////////////////////////
/// ByteData
//////////////////////////////////
@@ -52,12 +26,17 @@ ByteData::ByteData() : data_(0) {
// do nothing
}
-ByteData::ByteData(const std::vector& vector) : data_(vector) {}
+ByteData::ByteData(const std::vector& vector) : data_(vector) {
+ if (data_.size() > std::numeric_limits::max()) {
+ warn(CFD_LOG_SOURCE, "It exceeds the handling size.");
+ throw CfdException(kCfdIllegalStateError, "It exceeds the handling size.");
+ }
+}
ByteData::ByteData(const std::string& hex)
: data_(StringUtil::StringToByte(hex)) {}
-ByteData::ByteData(const uint8_t* buffer, uint32_t size) : data_(0) {
+ByteData::ByteData(const uint8_t* buffer, uint32_t size) : data_(size) {
if (buffer == nullptr) {
if (size == 0) {
// create empty buffer
@@ -71,6 +50,10 @@ ByteData::ByteData(const uint8_t* buffer, uint32_t size) : data_(0) {
}
}
+ByteData::ByteData(const uint8_t single_byte) : data_(1) {
+ data_[0] = single_byte;
+}
+
std::string ByteData::GetHex() const {
return StringUtil::ByteToString(data_);
}
@@ -95,36 +78,19 @@ uint8_t ByteData::GetHeadData() const {
}
ByteData ByteData::Serialize() const {
- return ByteData(SerializeFromBuffer(data_));
+ Serializer obj(static_cast(data_.size()));
+ obj.AddVariableBuffer(data_.data(), static_cast(data_.size()));
+ return obj.Output();
}
size_t ByteData::GetSerializeSize() const {
- ByteData size_buffer = GetVariableInt(data_.size());
- return size_buffer.GetDataSize() + data_.size();
+ return Serializer::GetVariableIntSize(data_.size()) + data_.size();
}
ByteData ByteData::GetVariableInt(uint64_t v) {
- std::vector size_byte;
- if (v <= kViMax8) {
- uint8_t v8 = static_cast(v);
- size_byte.push_back(v8);
- } else if (v <= std::numeric_limits::max()) {
- uint16_t v16 = static_cast(v);
- size_byte.resize(sizeof(v16) + 1);
- size_byte[0] = kViTag16;
- memcpy(size_byte.data() + 1, &v16, sizeof(v16));
- } else if (v <= std::numeric_limits::max()) {
- uint32_t v32 = static_cast(v);
- size_byte.resize(sizeof(v32) + 1);
- size_byte[0] = kViTag32;
- memcpy(size_byte.data() + 1, &v32, sizeof(v32));
- } else {
- size_byte.resize(sizeof(v) + 1);
- size_byte[0] = kViTag64;
- memcpy(size_byte.data() + 1, &v, sizeof(v));
- }
-
- return ByteData(size_byte);
+ Serializer obj(sizeof(v) + 1);
+ obj.AddVariableInt(v);
+ return obj.Output();
}
bool ByteData::IsLarge(const ByteData& source, const ByteData& destination) {
@@ -132,18 +98,29 @@ bool ByteData::IsLarge(const ByteData& source, const ByteData& destination) {
}
void ByteData::Push(const ByteData& back_insert_data) {
- std::vector insert_bytes = back_insert_data.GetBytes();
- data_.insert(data_.end(), insert_bytes.begin(), insert_bytes.end());
+ if (back_insert_data.IsEmpty()) return;
+ const std::vector& insert_bytes = back_insert_data.data_;
+ data_.reserve(data_.size() + insert_bytes.size() + 8);
+ std::copy(
+ insert_bytes.begin(), insert_bytes.end(), std::back_inserter(data_));
}
void ByteData::Push(const ByteData160& back_insert_data) {
std::vector insert_bytes = back_insert_data.GetBytes();
- data_.insert(data_.end(), insert_bytes.begin(), insert_bytes.end());
+ data_.reserve(data_.size() + insert_bytes.size() + 8);
+ std::copy(
+ insert_bytes.begin(), insert_bytes.end(), std::back_inserter(data_));
}
void ByteData::Push(const ByteData256& back_insert_data) {
std::vector insert_bytes = back_insert_data.GetBytes();
- data_.insert(data_.end(), insert_bytes.begin(), insert_bytes.end());
+ data_.reserve(data_.size() + insert_bytes.size() + 8);
+ std::copy(
+ insert_bytes.begin(), insert_bytes.end(), std::back_inserter(data_));
+}
+
+bool ByteData::operator==(const ByteData& object) const {
+ return (data_ == object.data_);
}
//////////////////////////////////
@@ -203,7 +180,13 @@ ByteData ByteData160::GetData() const { return ByteData(data_); }
uint8_t ByteData160::GetHeadData() const { return data_[0]; }
ByteData ByteData160::Serialize() const {
- return ByteData(SerializeFromBuffer(data_));
+ Serializer obj(static_cast(data_.size()));
+ obj.AddVariableBuffer(data_.data(), static_cast(data_.size()));
+ return obj.Output();
+}
+
+bool ByteData160::operator==(const ByteData160& object) const {
+ return (data_ == object.data_);
}
//////////////////////////////////
@@ -263,7 +246,333 @@ ByteData ByteData256::GetData() const { return ByteData(data_); }
uint8_t ByteData256::GetHeadData() const { return data_[0]; }
ByteData ByteData256::Serialize() const {
- return ByteData(SerializeFromBuffer(data_));
+ Serializer obj(static_cast(data_.size()));
+ obj.AddVariableBuffer(data_.data(), static_cast(data_.size()));
+ return obj.Output();
+}
+
+bool ByteData256::operator==(const ByteData256& object) const {
+ return (data_ == object.data_);
+}
+
+//////////////////////////////////
+/// Serializer
+//////////////////////////////////
+Serializer::Serializer() : buffer_(8), offset_(0) {
+ // do nothing
+}
+
+Serializer::Serializer(uint32_t initial_size)
+ : buffer_(initial_size + 9), offset_(0) {
+ // do nothing
+}
+
+Serializer::Serializer(const Serializer& object)
+ : buffer_(object.buffer_), offset_(object.offset_) {
+ // do nothing
+}
+
+Serializer& Serializer::operator=(const Serializer& object) {
+ if (this != &object) {
+ buffer_ = object.buffer_;
+ offset_ = object.offset_;
+ }
+ return *this;
+}
+
+void Serializer::CheckNeedSize(uint32_t need_size) {
+ size_t size = buffer_.size() - static_cast(offset_);
+ if (size < need_size) {
+ size_t cap = buffer_.capacity() - static_cast(offset_);
+ if (cap < (need_size * 2)) {
+ buffer_.reserve(buffer_.capacity() + (need_size * 10));
+ }
+ buffer_.resize(buffer_.size() + (need_size * 2));
+ }
+}
+
+uint32_t Serializer::GetVariableIntSize(uint64_t value) {
+ if (value <= kViMax8)
+ return 1;
+ else if (value <= std::numeric_limits::max())
+ return 3;
+ else if (value <= std::numeric_limits::max())
+ return 5;
+ else
+ return 9;
+}
+
+void Serializer::AddVariableInt(uint64_t value) {
+ // TODO(k-matsuzawa) need endian support.
+ CheckNeedSize(9);
+ uint8_t* buf = &buffer_.data()[offset_];
+ if (value <= kViMax8) {
+ *buf = static_cast(value);
+ ++offset_;
+ } else if (value <= std::numeric_limits