Skip to content

Commit e0b4ca0

Browse files
author
Mikhail Tagirov
authored
cpp-ledger (#595)
Signed-off-by: Mikhail Tagirov <[email protected]>
1 parent e7765eb commit e0b4ca0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2720
-16
lines changed

.github/workflows/asan.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: install
2828
run: |
2929
sudo apt-get update
30-
sudo apt-get install -y ninja-build python-setuptools pkg-config ocl-icd-* opencl-headers libhwloc-dev
30+
sudo apt-get install -y ninja-build python-setuptools pkg-config ocl-icd-* opencl-headers libhwloc-dev libhidapi-dev
3131
sudo python3 -m pip install --upgrade pip
3232
sudo python3 -m pip install scikit-build cmake requests gitpython gcovr pyyaml
3333
- name: cmake

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ jobs:
5454
set -e
5555
if [ "$RUNNER_OS" = "macOS" ]; then
5656
echo "LIBRARY_PATH=$LIBRARY_PATH:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib" >> $GITHUB_ENV
57-
brew install ninja pkg-config libb2 hwloc
57+
brew install ninja pkg-config libb2 hwloc hidapi
5858
else
5959
sudo apt-get update
60-
sudo apt-get install -y ninja-build python-setuptools pkg-config ocl-icd-* opencl-headers libhwloc-dev
60+
sudo apt-get install -y ninja-build python-setuptools pkg-config ocl-icd-* opencl-headers libhwloc-dev libhidapi-dev
6161
fi
6262
6363
pip3 -V || sudo python3 -m pip install --upgrade pip

.github/workflows/lsan.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: install
2828
run: |
2929
sudo apt-get update
30-
sudo apt-get install -y ninja-build python-setuptools pkg-config ocl-icd-* opencl-headers libhwloc-dev
30+
sudo apt-get install -y ninja-build python-setuptools pkg-config ocl-icd-* opencl-headers libhwloc-dev libhidapi-dev
3131
sudo python3 -m pip install --upgrade pip
3232
sudo python3 -m pip install scikit-build cmake requests gitpython gcovr pyyaml
3333
- name: cmake

.github/workflows/tsan.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: install
2828
run: |
2929
echo "LIBRARY_PATH=$LIBRARY_PATH:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib" >> $GITHUB_ENV
30-
brew install ninja llvm pkg-config libb2 hwloc
30+
brew install ninja llvm pkg-config libb2 hwloc hidapi
3131
sudo python3 -m pip install --upgrade pip
3232
sudo python3 -m pip install scikit-build cmake requests gitpython gcovr pyyaml
3333
- name: cmake

.github/workflows/ubsan.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: install
2828
run: |
2929
sudo apt-get update
30-
sudo apt-get install -y ninja-build python-setuptools pkg-config ocl-icd-* opencl-headers libhwloc-dev
30+
sudo apt-get install -y ninja-build python-setuptools pkg-config ocl-icd-* opencl-headers libhwloc-dev libhidapi-dev
3131
sudo python3 -m pip install --upgrade pip
3232
sudo python3 -m pip install scikit-build cmake requests gitpython gcovr pyyaml
3333
- name: cmake

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ add_subdirectory(deps)
109109
include_directories(
110110
# project includes
111111
${PROJECT_SOURCE_DIR}/core
112+
${PROJECT_SOURCE_DIR}/libs
112113
)
113114

114115
include_directories(
@@ -118,7 +119,13 @@ include_directories(
118119
deps/libsecp256k1/include
119120
)
120121

122+
if (APPLE)
123+
include_directories(/usr/local/include)
124+
link_directories(/usr/local/lib)
125+
endif ()
126+
121127
add_subdirectory(core)
128+
add_subdirectory(libs)
122129

123130

124131
if (TESTING)

core/api/rpc/json.hpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "api/rpc/rpc.hpp"
1414
#include "api/storage_miner/storage_api.hpp"
1515
#include "api/types/key_info.hpp"
16+
#include "api/types/ledger_key_info.hpp"
1617
#include "api/worker_api.hpp"
1718
#include "common/enum.hpp"
1819
#include "common/libp2p/peer/cbor_peer_info.hpp"
@@ -324,6 +325,20 @@ namespace fc::api {
324325
}
325326
}
326327

328+
ENCODE(uint32_t) {
329+
return Value{v};
330+
}
331+
332+
DECODE(uint32_t) {
333+
if (j.IsUint()) {
334+
v = j.GetUint();
335+
} else if (j.IsString()) {
336+
v = strtoull(j.GetString(), nullptr, 10);
337+
} else {
338+
outcome::raise(JsonError::kWrongType);
339+
}
340+
}
341+
327342
ENCODE(double) {
328343
return Value{v};
329344
}
@@ -523,6 +538,18 @@ namespace fc::api {
523538
}
524539
}
525540

541+
ENCODE(LedgerKeyInfo) {
542+
Value j{rapidjson::kObjectType};
543+
Set(j, "Address", v.address);
544+
Set(j, "Path", v.path);
545+
return j;
546+
}
547+
548+
DECODE(LedgerKeyInfo) {
549+
Get(j, "Address", v.address);
550+
Get(j, "Path", v.path);
551+
}
552+
526553
ENCODE(PoStProof) {
527554
Value j{rapidjson::kObjectType};
528555
Set(j, "PoStProof", v.registered_proof);
@@ -546,7 +573,7 @@ namespace fc::api {
546573
ENCODE(CallError) {
547574
Value j{rapidjson::kObjectType};
548575
Set(j, "Code", v.code);
549-
Set(j, "ProofBytes", v.message);
576+
Set(j, "Message", v.message);
550577
return j;
551578
}
552579

core/api/types/key_info.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#pragma once
77

88
#include "common/blob.hpp"
9+
#include "common/bytes.hpp"
10+
#include "common/outcome.hpp"
911
#include "crypto/signature/signature.hpp"
1012

1113
namespace fc::api {
@@ -14,7 +16,11 @@ namespace fc::api {
1416

1517
struct KeyInfo {
1618
SignatureType type = SignatureType::kUndefined;
17-
common::Blob<32> private_key;
19+
Bytes private_key;
20+
21+
inline outcome::result<Blob<32>> getPrivateKey() const {
22+
return Blob<32>::fromSpan(private_key);
23+
}
1824
};
1925

2026
} // namespace fc::api

core/api/types/ledger_key_info.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#pragma once
7+
8+
#include "primitives/address/address.hpp"
9+
10+
namespace fc::api {
11+
using primitives::address::Address;
12+
13+
struct LedgerKeyInfo {
14+
Address address;
15+
std::vector<uint32_t> path;
16+
};
17+
18+
} // namespace fc::api

core/api/wallet/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55

66
add_library(wallet
77
local_wallet.cpp
8+
ledger_wallet.cpp
9+
ledger.cpp
810
)
911
target_link_libraries(wallet
1012
address
13+
rpc
14+
ledger_filecoin
1115
)

0 commit comments

Comments
 (0)