Skip to content

Commit

Permalink
update to v0.1.4 (#14)
Browse files Browse the repository at this point in the history
* feat: linux rpath origin support.
* feat: custom error support.
* refactor: example

Co-authored-by: k-matsuzawa <[email protected]>
  • Loading branch information
ko-matsu and k-matsuzawa authored Jul 30, 2020
1 parent 012477a commit 7d4713c
Show file tree
Hide file tree
Showing 56 changed files with 4,005 additions and 3,199 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/check_pre-merge_develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ jobs:
node: 8
- os: macos-latest
node: 13
- os: macos-latest
node: 14

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -92,7 +90,7 @@ jobs:
npm --version
echo "::set-output name=npm_cachedir::$(npm config get cache)"
- name: use npm cache
if: steps.node_cache.outputs.cache-hit != 'true'
if: matrix.os != 'windows-latest' && steps.node_cache.outputs.cache-hit != 'true'
uses: actions/cache@v1
id: npm_cache
with:
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/check_pre-merge_master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ jobs:
node: 8
- os: macos-latest
node: 13
- os: macos-latest
node: 14

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -90,7 +88,7 @@ jobs:
npm --version
echo "::set-output name=npm_cachedir::$(npm config get cache)"
- name: use npm cache
if: steps.node_cache.outputs.cache-hit != 'true'
if: matrix.os != 'windows-latest' && steps.node_cache.outputs.cache-hit != 'true'
uses: actions/cache@v1
id: npm_cache
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check_pre-merge_sprint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
npm --version
echo "::set-output name=npm_cachedir::$(npm config get cache)"
- name: use npm cache
if: steps.node_cache.outputs.cache-hit != 'true'
if: matrix.os != 'windows-latest' && steps.node_cache.outputs.cache-hit != 'true'
uses: actions/cache@v1
id: npm_cache
with:
Expand Down
29 changes: 26 additions & 3 deletions cmake/CfdCommonOption.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ if(NOT WIN32)
#option(TARGET_RPATH "target rpath list (separator is ';') (default:)" "")
set(TARGET_RPATH "" CACHE STRING "target rpath list (separator is ';') (default:)")
option(ENABLE_COVERAGE "enable code coverage (ON or OFF. default:OFF)" OFF)
option(ENABLE_RPATH "enable rpath (ON or OFF. default:ON)" ON)
else()
set(TARGET_RPATH "")
set(ENABLE_COVERAGE FALSE)
set(ENABLE_RPATH off)
endif()

if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
Expand All @@ -33,17 +35,38 @@ set(STACK_PROTECTOR_OPT "")
endif() # CMAKE_BUILD_TYPE

if(NOT WIN32)
if(ENABLE_RPATH)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
if(APPLE)
set(CMAKE_MACOSX_RPATH 1)
else()
set(CMAKE_BUILD_RPATH_USE_ORIGIN TRUE)
endif()
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

if(TARGET_RPATH)
set(CMAKE_INSTALL_RPATH "${TARGET_RPATH};./;@rpath")
if(APPLE)
string(REPLACE "\$\$ORIGIN" "." TEMP_RPATH1 "${TARGET_RPATH}")
string(REPLACE "\$ORIGIN" "." TEMP_RPATH2 "${TEMP_RPATH1}")
string(REPLACE "\$\${ORIGIN}" "." TEMP_RPATH3 "${TEMP_RPATH2}")
string(REPLACE "\${ORIGIN}" "." MODIFIED_RPATH "${TEMP_RPATH3}")
set(CMAKE_INSTALL_RPATH "${MODIFIED_RPATH};./;./build/${RPATH_TARGET};@rpath")
else()
string(REPLACE "\$\${ORIGIN}" "$$ORIGIN" TEMP_RPATH1 "${TARGET_RPATH}")
string(REPLACE "\${ORIGIN}" "$ORIGIN" MODIFIED_RPATH "${TEMP_RPATH1}")
set(CMAKE_INSTALL_RPATH "${MODIFIED_RPATH};$ORIGIN/;./;./build/${RPATH_TARGET};@rpath")
endif()
else(TARGET_RPATH)
if(APPLE)
set(CMAKE_INSTALL_RPATH "./;./build/${RPATH_TARGET};@rpath")
else()
set(CMAKE_INSTALL_RPATH "$ORIGIN/;./;./build/${RPATH_TARGET};@rpath")
endif()
endif(TARGET_RPATH)
# message(STATUS "CMAKE_INSTALL_RPATH is => ${CMAKE_INSTALL_RPATH}")
else()
set(CMAKE_INSTALL_RPATH "./;@rpath")
set(CMAKE_SKIP_BUILD_RPATH TRUE)
endif()
endif()

Expand Down
4 changes: 2 additions & 2 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ if(CFD_TARGET_VERSION)
set(CFD_TARGET_TAG ${CFD_TARGET_VERSION})
message(STATUS "[external project local] cfd target=${CFD_TARGET_VERSION}")
else()
set(CFD_TARGET_TAG v0.1.3)
set(CFD_TARGET_TAG v0.1.4)
endif()
if(CFD_TARGET_URL)
set(CFD_TARGET_REP ${CFD_TARGET_URL})
Expand Down Expand Up @@ -135,7 +135,7 @@ if(LIBWALLY_TARGET_VERSION)
set(LIBWALLY_TARGET_TAG ${LIBWALLY_TARGET_VERSION})
message(STATUS "[external project cfd-js local] libwally-core target=${LIBWALLY_TARGET_VERSION}")
else()
set(LIBWALLY_TARGET_TAG refs/tags/cfd-0.0.2)
set(LIBWALLY_TARGET_TAG refs/tags/cfd-0.0.3)
endif()

if(${USE_GIT_SSH})
Expand Down
9 changes: 9 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable max-len */
/* eslint-disable require-jsdoc */
export interface MultisigSignData {
hex: string;
type?: string;
Expand Down Expand Up @@ -1611,3 +1613,10 @@ export function UpdateWitnessStack(jsonObject: UpdateWitnessStackRequest): Updat
export function VerifySign(jsonObject: VerifySignRequest): VerifySignResponse;

export function VerifySignature(jsonObject: VerifySignatureRequest): VerifySignatureResponse;

export class CfdError extends Error {
constructor(message: string, errorInformation: InnerErrorResponse, cause: Error);
toString(): string;
getErrorInformation(): InnerErrorResponse;
getCause(): Error;
}
54 changes: 49 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,55 @@ if (typeof cfdjs !== 'object' || cfdjs === null) {
throw new ReferenceError('Not support typeof cfdjs.');
}

/**
* cfd error class.
*/
class CfdError extends Error {
/**
* constructor.
* @param {string} message error message.
* @param {*} errorInformation error information object.
* @param {Error} cause cause error.
*/
constructor(message, errorInformation = undefined, cause = undefined) {
super((!errorInformation) ?
message : message + JSON.stringify(errorInformation));
this.name = 'CfdError';
this.errorInformation = errorInformation;
this.cause = cause;
}
// eslint-disable-next-line valid-jsdoc
/**
* error object string.
* @return message string.
*/
toString() {
return `${this.name}: ${this.message}`;
}
// eslint-disable-next-line valid-jsdoc
/**
* get error information.
* @return InnerErrorResponse object.
*/
getErrorInformation() {
return this.errorInformation;
}
// eslint-disable-next-line valid-jsdoc
/**
* get error cause.
* @return Error or undefined.
*/
getCause() {
return this.cause;
}
}

const wrappedModule = {};
Object.keys(cfdjs).forEach((key) => {
const hook = function(...args) {
if (args.length > 1) {
throw Error('ERROR: Invalid argument passed:' +
`func=[${funcName}], args=[${args}]`);
throw new CfdError('ERROR: Invalid argument passed:' +
` func=[${funcName}], args=[${args}]`);
}

let retObj;
Expand All @@ -23,12 +66,12 @@ Object.keys(cfdjs).forEach((key) => {
} catch (err) {
// JSON convert error
// console.log(err);
throw new Error('ERROR: Invalid function call:' +
` func=[${key}], args=[${args}]`);
throw new CfdError('ERROR: Invalid function call:' +
` func=[${key}], args=[${args}]`, undefined, err);
}

if (retObj.hasOwnProperty('error')) {
throw new Error(JSON.stringify(retObj.error));
throw new CfdError('', retObj.error);
}
return retObj;
};
Expand All @@ -39,3 +82,4 @@ Object.keys(cfdjs).forEach((key) => {
});

module.exports = wrappedModule;
module.exports.CfdError = CfdError;
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cfd-js",
"version": "0.1.3",
"version": "0.1.4",
"domain": "p2pderivatives",
"repository": {
"type": "git",
Expand Down Expand Up @@ -34,18 +34,18 @@
"install": "prebuild-install --verbose || run-s install_cmake",
"install_cmake": "run-s download_object cmake_install_configure cmake_compile",
"prebuild_all": "run-s prebuild_nodejs prebuild_electron",
"prebuild_nodejs": "prebuild --backend cmake-js -t 8.17.0 -t 10.20.1 -t 12.16.3 -t 13.14.0 -t 14.3.0 -r node --verbose --include-regex \".*(node|a|so|dll|dylib)$\" -- -O build --CDENABLE_SHARED=off --CDENABLE_CAPI=off --CDENABLE_TESTS=off --CDTARGET_RPATH=\"@executable_path;/usr/local/lib;/usr/local/lib64;./node_modules/cfd-js/build/Release;../node_modules/cfd-js/build/Release;../../node_modules/cfd-js/build/Release;../../../node_modules/cfd-js/build/Release;../../../../node_modules/cfd-js/build/Release;../../../../../node_modules/cfd-js/build/Release;../../../../../../node_modules/cfd-js/build/Release;./build/Release;./build/Release;./wrap_js/dl_lib/lib\" -C --CDnapi_build_version=3",
"prebuild_electron": "prebuild --backend cmake-js -t 3.0.0 -t 4.0.4 -t 5.0.0 -t 6.0.0 -t 7.0.0 -t 8.0.0 -t 9.0.0 -r electron --verbose --include-regex \".*(node|a|so|dll|dylib)$\" -- -O build --CDENABLE_SHARED=off --CDENABLE_CAPI=off --CDENABLE_TESTS=off --CDTARGET_RPATH=\"@executable_path;/usr/local/lib;/usr/local/lib64;./node_modules/cfd-js/build/Release;../node_modules/cfd-js/build/Release;../../node_modules/cfd-js/build/Release;../../../node_modules/cfd-js/build/Release;../../../../node_modules/cfd-js/build/Release;../../../../../node_modules/cfd-js/build/Release;../../../../../../node_modules/cfd-js/build/Release;./build/Release;./build/Release;./wrap_js/dl_lib/lib\" -C --CDnapi_build_version=3",
"prebuild_nodejs": "prebuild --backend cmake-js -t 8.17.0 -t 10.20.1 -t 12.16.3 -t 13.14.0 -t 14.3.0 -r node --verbose --include-regex \".*(node|a|so|dll|dylib)$\" -- -O build --CDENABLE_SHARED=off --CDENABLE_CAPI=off --CDENABLE_TESTS=off --CDTARGET_RPATH=\"@executable_path;/usr/local/lib;/usr/local/lib64;\\$\\$ORIGIN/node_modules/cfd-js/build/Release;\\$ORIGIN/node_modules/cfd-js/build/Release;\\$ORIGIN/../node_modules/cfd-js/build/Release;\\$ORIGIN/../../node_modules/cfd-js/build/Release;\\$ORIGIN/../../../node_modules/cfd-js/build/Release;\\$ORIGIN/../../../../node_modules/cfd-js/build/Release;\\$ORIGIN/../../../../../node_modules/cfd-js/build/Release;\\$ORIGIN/../../../../../../node_modules/cfd-js/build/Release;\\$ORIGIN/build/Release;\\$ORIGIN/wrap_js/dl_lib/lib\" -C --CDnapi_build_version=3",
"prebuild_electron": "prebuild --backend cmake-js -t 3.0.0 -t 4.0.4 -t 5.0.0 -t 6.0.0 -t 7.0.0 -t 8.0.0 -t 9.0.0 -r electron --verbose --include-regex \".*(node|a|so|dll|dylib)$\" -- -O build --CDENABLE_SHARED=off --CDENABLE_CAPI=off --CDENABLE_TESTS=off --CDTARGET_RPATH=\"@executable_path;/usr/local/lib;/usr/local/lib64;\\$\\$ORIGIN/node_modules/cfd-js/build/Release;\\$ORIGIN/node_modules/cfd-js/build/Release;\\$ORIGIN/../node_modules/cfd-js/build/Release;\\$ORIGIN/../../node_modules/cfd-js/build/Release;\\$ORIGIN/../../../node_modules/cfd-js/build/Release;\\$ORIGIN/../../../../node_modules/cfd-js/build/Release;\\$ORIGIN/../../../../../node_modules/cfd-js/build/Release;\\$ORIGIN/../../../../../../node_modules/cfd-js/build/Release;\\$ORIGIN/build/Release;\\$ORIGIN/wrap_js/dl_lib/lib\" -C --CDnapi_build_version=3",
"prebuild_upload_all": "prebuild --upload-all",
"check_version": "node ./tools/checker.js version",
"download_object": "node ./pkg_getter.js",
"deploy_object": "node ./pkg_getter.js deployment",
"cmake_compile": "cmake-js compile -O build",
"cmake_install_configure": "cmake-js configure -O build --CDENABLE_SHARED=off --CDENABLE_CAPI=off --CDENABLE_TESTS=off --CDTARGET_RPATH=\"@executable_path;/usr/local/lib;/usr/local/lib64;./node_modules/cfd-js/build/Release;../node_modules/cfd-js/build/Release;../../node_modules/cfd-js/build/Release;../../../node_modules/cfd-js/build/Release;../../../../node_modules/cfd-js/build/Release;../../../../../node_modules/cfd-js/build/Release;../../../../../../node_modules/cfd-js/build/Release;./build/Release;./build/Release;./wrap_js/dl_lib/lib\" -C",
"cmake_install_configure": "cmake-js configure -O build --CDENABLE_SHARED=off --CDENABLE_CAPI=off --CDENABLE_TESTS=off --CDTARGET_RPATH=\"@executable_path;/usr/local/lib;/usr/local/lib64;\\$\\$ORIGIN/node_modules/cfd-js/build/Release;\\$ORIGIN/node_modules/cfd-js/build/Release;\\$ORIGIN/../node_modules/cfd-js/build/Release;\\$ORIGIN/../../node_modules/cfd-js/build/Release;\\$ORIGIN/../../../node_modules/cfd-js/build/Release;\\$ORIGIN/../../../../node_modules/cfd-js/build/Release;\\$ORIGIN/../../../../../node_modules/cfd-js/build/Release;\\$ORIGIN/../../../../../../node_modules/cfd-js/build/Release;\\$ORIGIN/build/Release;\\$ORIGIN/wrap_js/dl_lib/lib\" -C",
"cmake_release_parallel": "run-s cmake_clean cmake_install_configure cmake_build_parallel",
"example": "node wrap_js/example.js",
"elements_example": "node wrap_js/elements_example.js",
"elements_pegin_example": "node wrap_js/elements_pegin_example.js",
"example": "node wrap_js/example.js example",
"elements_example": "node wrap_js/example.js elements_example",
"util_example": "node wrap_js/cfdjs_util_example.js",
"ts_example": "ts-node wrap_js/ts_example.ts",
"test": "jest --no-cache",
"test_watch": "jest --no-cache --watch",
Expand Down Expand Up @@ -154,8 +154,8 @@
"eslint_check": "eslint --ext .js,.ts *.ts *.js wrap_js/",
"git_subm_update": "git submodule -q foreach git fetch -q && git submodule -q update -i",
"check_local": "run-p doxygen_dev format_cpp_all format_js_all",
"check": "run-s doxygen_check lint_all ctest_quiet test_quiet example elements_example ts_example",
"check_all": "run-s cmake_clean git_subm_update cmake_quiet doxygen_check ctest_quiet test_quiet example elements_example ts_example lint_all",
"check": "run-s doxygen_check lint_all ctest_quiet test_quiet example elements_example ts_example util_example",
"check_all": "run-s cmake_clean git_subm_update cmake_quiet doxygen_check ctest_quiet test_quiet example elements_example ts_example util_example lint_all",
"convert_json": "ts-node ./tools/generate_json_map_class.ts",
"convert_json_debug": "ts-node ./tools/generate_json_map_class.ts mode=debug"
},
Expand Down
2 changes: 1 addition & 1 deletion src/input_json_format/cfdapi_add_multisig_sign.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"redeemScript:require": "optional",
"redeemScript:comment": "(required for P2SH or P2SH-P2WSH) redeem script for unlocking script",
"witnessScript": "",
"redeemScript:require": "optional",
"witnessScript:require": "optional",
"witnessScript:comment": "(required for P2WSH or P2SH-P2WSH) witness script for witness stack",
"hashType": "",
"hashType:require": "require",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"mainchainTxoutproof:require": "require"
},
"isRemoveMainchainTxWitness": false,
"isRemoveNonce:require": "optional",
"isRemoveMainchainTxWitness:require": "optional",
"isRemoveMainchainTxWitness:hint": "It is necessary to set true for Elements v0.18 or higher."
}
],
Expand Down
7 changes: 5 additions & 2 deletions src/input_json_format/cfdapi_fund_raw_transaction.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@
"targetAmount:type": "int64_t",
"targetAmount:require": "optional",
"targetAmount:hint": "This field is available only bitcoin.",
"targetAmount:comment": "Amount more than the specified amount is set in txout. default is 0 (disable).",
"reserveAddress": "",
"reserveAddress:require": "optional",
"reserveAddress:comment": "This address use when append TxOut.",
"reserveAddress:comment": "This address use when append TxOut. Also serves as a change address.",
"reserveAddress:hint": "This field is available only bitcoin.",
"targets:require": "optional",
"targets": [{
Expand All @@ -93,9 +94,10 @@
"amount": 0,
"amount:type": "int64_t",
"amount:require": "require",
"amount:comment": "Amount more than the specified amount is set in txout. default is 0 (disable).",
"reserveAddress": "",
"reserveAddress:require": "require",
"reserveAddress:comment": "This address use when append TxOut.",
"reserveAddress:comment": "This address use when append TxOut. Also serves as a change address.",
"reserveAddress:hint": "This field is available only bitcoin."
}],
"targets:hint": "This field is available only elements.",
Expand All @@ -113,6 +115,7 @@
"knapsackMinChange": -1,
"knapsackMinChange:require": "optional",
"knapsackMinChange:hint": "knapsack minimum change amount.",
"knapsackMinChange:comment": "knapsack logic's threshold. Recommended value is 1.",
"dustFeeRate": 3.0,
"dustFeeRate:type": "double",
"dustFeeRate:require": "optional",
Expand Down
5 changes: 4 additions & 1 deletion src/input_json_format/cfdapi_select_utxos.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"targetAmount:type": "int64_t",
"targetAmount:require": "optional",
"targetAmount:hint": "This field is available only bitcoin.",
"targetAmount:comment": "Amount more than the specified amount is set in txout. default is 0 (disable).",
"isElements": false,
"isElements:require": "optional",
"targets:require": "optional",
Expand All @@ -35,7 +36,8 @@
"asset": "",
"amount": 0,
"amount:type": "int64_t",
"amount:require": "optional"
"amount:require": "optional",
"amount:comment": "Amount more than the specified amount is set in txout. default is 0 (disable)."
}],
"targets:hint": "This field is available only elements.",
"feeInfo:require": "optional",
Expand All @@ -56,6 +58,7 @@
"knapsackMinChange:require": "optional",
"knapsackMinChange:type": "int32_t",
"knapsackMinChange:hint": "knapsack minimum change amount.",
"knapsackMinChange:comment": "knapsack logic's threshold. Recommended value is 1.",
"feeAsset": "",
"feeAsset:require": "optional",
"feeAsset:hint": "This field is available only elements.",
Expand Down
Loading

0 comments on commit 7d4713c

Please sign in to comment.