Skip to content

Commit 526f736

Browse files
authored
State tree and init actor (#52)
Signed-off-by: turuslan <[email protected]>
1 parent 5af73b9 commit 526f736

34 files changed

+556
-117
lines changed

.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ PointerAlignment: Right
77
BinPackArguments: false
88
BinPackParameters: false
99
AllowShortFunctionsOnASingleLine: Empty
10+
IncludeBlocks: Preserve

cmake/Hunter/config.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ hunter_config(
3030
)
3131

3232
hunter_config(libp2p
33-
URL https://github.com/soramitsu/libp2p/archive/2c23ef1b8d65cc32f8f6eb147aeea97d00e67eb1.zip
34-
SHA1 60ef5a8ad5cb3da582890762d1b963647c02ecd0
33+
URL https://github.com/soramitsu/libp2p/archive/40b257824d3c88c30e474267222955db0a5fccfc.zip
34+
SHA1 40e2713d976858d31637f123a54896d25a78661d
3535
CMAKE_ARGS TESTING=OFF
3636
)

core/codec/cbor/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ add_library(cbor
1010
cbor_resolve.cpp
1111
)
1212
target_link_libraries(cbor
13+
cid
1314
outcome
14-
p2p::p2p_cid
1515
tinycbor
1616
)

core/common/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,11 @@ add_library(logger
4141
target_link_libraries(logger
4242
spdlog::spdlog
4343
)
44+
45+
add_library(cid
46+
cid.cpp
47+
)
48+
target_link_libraries(cid
49+
blake2
50+
p2p::p2p_cid
51+
)

core/common/cid.cpp

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+
#include "common/cid.hpp"
7+
8+
#include "crypto/blake2/blake2b160.hpp"
9+
10+
namespace fc::common {
11+
outcome::result<CID> getCidOf(gsl::span<const uint8_t> bytes) {
12+
OUTCOME_TRY(hash_raw, crypto::blake2b::blake2b_256(bytes));
13+
OUTCOME_TRY(hash,
14+
libp2p::multi::Multihash::create(
15+
libp2p::multi::HashType::blake2b_256, hash_raw));
16+
return CID(CID::Version::V1, libp2p::multi::MulticodecType::DAG_CBOR, hash);
17+
}
18+
} // namespace fc::common

core/common/cid.hpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#ifndef CPP_FILECOIN_CORE_COMMON_CID_HPP
7+
#define CPP_FILECOIN_CORE_COMMON_CID_HPP
8+
9+
#include <libp2p/multi/content_identifier.hpp>
10+
11+
#include "common/outcome.hpp"
12+
13+
namespace fc {
14+
using CID = libp2p::multi::ContentIdentifier;
15+
} // namespace fc
16+
17+
namespace fc::common {
18+
/**
19+
* CID is not default-constructible, but in some cases we need default value.
20+
* This value can be used to initialize class member or local variable. Trying
21+
* to CBOR encode this value will yield error, to ensure proper
22+
* initialization.
23+
*/
24+
const static inline CID kEmptyCid(
25+
{}, {}, libp2p::multi::Multihash::create({}, {}).value());
26+
27+
/// Compute CID from bytes
28+
outcome::result<CID> getCidOf(gsl::span<const uint8_t> bytes);
29+
} // namespace fc::common
30+
31+
#endif // CPP_FILECOIN_CORE_COMMON_CID_HPP

core/crypto/blake2/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ add_library(blake2
1010
blake2b160.cpp
1111
)
1212
target_link_libraries(blake2
13+
blob
1314
outcome
1415
)

core/primitives/address/address.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ namespace fc::primitives::address {
4343
[](const BLSPublicKeyHash &v) { return Protocol::BLS; });
4444
}
4545

46+
Address Address::makeFromId(uint64_t id) {
47+
// TODO(turuslan): FIL-118 remove hardcoded TESTNET
48+
return {TESTNET, id};
49+
}
50+
4651
bool operator==(const Address &lhs, const Address &rhs) {
4752
return lhs.network == rhs.network && lhs.getProtocol() == rhs.getProtocol()
4853
&& lhs.data == rhs.data;

core/primitives/address/address.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ namespace fc::primitives::address {
6565
*/
6666
bool isKeyType() const;
6767

68+
/// id - number assigned to actors in a Filecoin Chain
69+
static Address makeFromId(uint64_t id);
70+
6871
Network network;
6972
Payload data;
7073
};

core/primitives/big_int.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ namespace fc::primitives {
2121
using cpp_int::cpp_int;
2222
};
2323

24+
static inline bool operator==(const BigInt &lhs, const BigInt &rhs) {
25+
return static_cast<cpp_int>(lhs) == static_cast<cpp_int>(rhs);
26+
}
27+
28+
static inline bool operator==(const BigInt &lhs, int rhs) {
29+
return static_cast<cpp_int>(lhs) == rhs;
30+
}
31+
2432
template <class Stream,
2533
class T,
2634
typename = std::enable_if_t<

0 commit comments

Comments
 (0)