Skip to content

Commit 63a91f9

Browse files
authored
Merge pull request #64 from SparqNet/development
Contract JSON RPC hotfix
2 parents 14dd027 + f2470fd commit 63a91f9

File tree

16 files changed

+415
-343
lines changed

16 files changed

+415
-343
lines changed

.github/workflows/c-cpp.yml

+6
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ jobs:
109109
name: build
110110
path: build
111111

112+
- name : Update apt-get
113+
run: apt-get update
114+
115+
- name : Install Doxygen
116+
run: apt-get install -y doxygen
117+
112118
- name: Generate Doxygen Documentation
113119
run: |
114120
mkdir docs

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
1717
endif()
1818

1919
# Project data
20-
project(orbitersdk VERSION 0.1.0 DESCRIPTION "Sparq subnet")
20+
project(orbitersdk VERSION 0.1.1 DESCRIPTION "Sparq subnet")
2121
set(CMAKE_CXX_STANDARD 23)
2222
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
2323
set(CMAKE_CXX_EXTENSIONS OFF)

Doxyfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ RECURSIVE = YES
995995
# Note that relative paths are relative to the directory from which doxygen is
996996
# run.
997997

998-
EXCLUDE = "src/libs" "src/utils/json.hpp" "src/utils/meta_all.hpp"
998+
EXCLUDE = "src/libs" "src/utils/json.hpp" "src/utils/meta_all.hpp" "src/utils/options.cpp"
999999

10001000
# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
10011001
# directories that are symbolic links (a Unix file system feature) are excluded

scripts/AIO-setup.sh

+14-14
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ if [ "$DEPLOY" = true ]; then
130130
# Create the JSON files for the Discovery Node, Validators and Normal Nodes
131131
echo '{
132132
"rootPath": "discoveryNode",
133-
"web3clientVersion": "OrbiterSDK/cpp/linux_x86-64/0.1.0",
133+
"web3clientVersion": "OrbiterSDK/cpp/linux_x86-64/0.1.1",
134134
"version": 1,
135135
"chainID": 808080,
136136
"wsPort": 8080,
@@ -141,7 +141,7 @@ if [ "$DEPLOY" = true ]; then
141141
# Create the JSON file for the Validators
142142
echo '{
143143
"rootPath": "blockchain",
144-
"web3clientVersion": "OrbiterSDK/cpp/linux_x86-64/0.1.0",
144+
"web3clientVersion": "OrbiterSDK/cpp/linux_x86-64/0.1.1",
145145
"version": 1,
146146
"chainID": 808080,
147147
"wsPort": 8081,
@@ -157,7 +157,7 @@ if [ "$DEPLOY" = true ]; then
157157

158158
echo '{
159159
"rootPath": "blockchain",
160-
"web3clientVersion": "OrbiterSDK/cpp/linux_x86-64/0.1.0",
160+
"web3clientVersion": "OrbiterSDK/cpp/linux_x86-64/0.1.1",
161161
"version": 1,
162162
"chainID": 808080,
163163
"wsPort": 8082,
@@ -173,7 +173,7 @@ if [ "$DEPLOY" = true ]; then
173173

174174
echo '{
175175
"rootPath": "blockchain",
176-
"web3clientVersion": "OrbiterSDK/cpp/linux_x86-64/0.1.0",
176+
"web3clientVersion": "OrbiterSDK/cpp/linux_x86-64/0.1.1",
177177
"version": 1,
178178
"chainID": 808080,
179179
"wsPort": 8083,
@@ -189,7 +189,7 @@ if [ "$DEPLOY" = true ]; then
189189

190190
echo '{
191191
"rootPath": "blockchain",
192-
"web3clientVersion": "OrbiterSDK/cpp/linux_x86-64/0.1.0",
192+
"web3clientVersion": "OrbiterSDK/cpp/linux_x86-64/0.1.1",
193193
"version": 1,
194194
"chainID": 808080,
195195
"wsPort": 8084,
@@ -205,7 +205,7 @@ if [ "$DEPLOY" = true ]; then
205205

206206
echo '{
207207
"rootPath": "blockchain",
208-
"web3clientVersion": "OrbiterSDK/cpp/linux_x86-64/0.1.0",
208+
"web3clientVersion": "OrbiterSDK/cpp/linux_x86-64/0.1.1",
209209
"version": 1,
210210
"chainID": 808080,
211211
"wsPort": 8085,
@@ -222,7 +222,7 @@ if [ "$DEPLOY" = true ]; then
222222
# Create the json file for the Normal Nodes
223223
echo '{
224224
"rootPath": "blockchain",
225-
"web3clientVersion": "OrbiterSDK/cpp/linux_x86-64/0.1.0",
225+
"web3clientVersion": "OrbiterSDK/cpp/linux_x86-64/0.1.1",
226226
"version": 1,
227227
"chainID": 808080,
228228
"wsPort": 8086,
@@ -237,7 +237,7 @@ if [ "$DEPLOY" = true ]; then
237237

238238
echo '{
239239
"rootPath": "blockchain",
240-
"web3clientVersion": "OrbiterSDK/cpp/linux_x86-64/0.1.0",
240+
"web3clientVersion": "OrbiterSDK/cpp/linux_x86-64/0.1.1",
241241
"version": 1,
242242
"chainID": 808080,
243243
"wsPort": 8087,
@@ -252,7 +252,7 @@ if [ "$DEPLOY" = true ]; then
252252

253253
echo '{
254254
"rootPath": "blockchain",
255-
"web3clientVersion": "OrbiterSDK/cpp/linux_x86-64/0.1.0",
255+
"web3clientVersion": "OrbiterSDK/cpp/linux_x86-64/0.1.1",
256256
"version": 1,
257257
"chainID": 808080,
258258
"wsPort": 8088,
@@ -267,7 +267,7 @@ if [ "$DEPLOY" = true ]; then
267267

268268
echo '{
269269
"rootPath": "blockchain",
270-
"web3clientVersion": "OrbiterSDK/cpp/linux_x86-64/0.1.0",
270+
"web3clientVersion": "OrbiterSDK/cpp/linux_x86-64/0.1.1",
271271
"version": 1,
272272
"chainID": 808080,
273273
"wsPort": 8089,
@@ -282,7 +282,7 @@ if [ "$DEPLOY" = true ]; then
282282

283283
echo '{
284284
"rootPath": "blockchain",
285-
"web3clientVersion": "OrbiterSDK/cpp/linux_x86-64/0.1.0",
285+
"web3clientVersion": "OrbiterSDK/cpp/linux_x86-64/0.1.1",
286286
"version": 1,
287287
"chainID": 808080,
288288
"wsPort": 8110,
@@ -297,7 +297,7 @@ if [ "$DEPLOY" = true ]; then
297297

298298
echo '{
299299
"rootPath": "blockchain",
300-
"web3clientVersion": "OrbiterSDK/cpp/linux_x86-64/0.1.0",
300+
"web3clientVersion": "OrbiterSDK/cpp/linux_x86-64/0.1.1",
301301
"version": 1,
302302
"chainID": 808080,
303303
"wsPort": 8111,
@@ -312,7 +312,7 @@ if [ "$DEPLOY" = true ]; then
312312

313313
echo '{
314314
"rootPath": "blockchain",
315-
"web3clientVersion": "OrbiterSDK/cpp/linux_x86-64/0.1.0",
315+
"web3clientVersion": "OrbiterSDK/cpp/linux_x86-64/0.1.1",
316316
"version": 1,
317317
"chainID": 808080,
318318
"wsPort": 8110,
@@ -327,7 +327,7 @@ if [ "$DEPLOY" = true ]; then
327327

328328
echo '{
329329
"rootPath": "blockchain",
330-
"web3clientVersion": "OrbiterSDK/cpp/linux_x86-64/0.1.0",
330+
"web3clientVersion": "OrbiterSDK/cpp/linux_x86-64/0.1.1",
331331
"version": 1,
332332
"chainID": 808080,
333333
"wsPort": 8111,

src/contract/contractmanager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void ContractManager::ethCall(const ethCallInfo& callInfo) {
7474
createIt->second(callInfo);
7575
return;
7676
}
77-
throw std::runtime_error("Invalid function call with functor: " + Utils::bytesToString(functor.asBytes()));
77+
throw std::runtime_error("Invalid function call with functor: " + functor.hex().get());
7878
}
7979

8080
Bytes ContractManager::getDeployedContracts() const {

src/contract/variables/safearray.h

+89-79
Original file line numberDiff line numberDiff line change
@@ -6,142 +6,152 @@
66
#include "safebase.h"
77

88
/**
9-
* Safe wrapper for std::array
10-
* Same as std::vector
11-
* but with more contrains as a std::array is a fixed size container
12-
* SafeArray is ALWAYS initialized with default values, differently from std::array
9+
* Safe wrapper for `std::array`.
10+
* Works the same as SafeVector, but with more constraints as a std::array is a fixed size container.
11+
* SafeArray is ALWAYS initialized with default values, differently from std::array.
12+
* @see SafeVector
13+
* @see SafeBase
1314
*/
14-
15-
template <typename T, unsigned N>
16-
class SafeArray : public SafeBase {
15+
template <typename T, unsigned N> class SafeArray : public SafeBase {
1716
private:
18-
std::array<T, N> array_; ///< The original array
19-
mutable std::unique_ptr<std::map<uint64_t, T>> tmp_; ///< The temporary array
17+
std::array<T, N> array_; ///< Original array.
18+
mutable std::unique_ptr<std::map<uint64_t, T>> tmp_; ///< Temporary array.
2019

21-
/// Check the tmp_ variables!
20+
/// Check if the temporary array is initialized (and initialize it if not).
2221
inline void check() const {
23-
if (tmp_ == nullptr) {
24-
tmp_ = std::make_unique<std::map<uint64_t, T>>();
25-
}
22+
if (this->tmp_ == nullptr) this->tmp_ = std::make_unique<std::map<uint64_t, T>>();
2623
}
2724

2825
/// Check a index and copy if necessary.
26+
/**
27+
* Check if a specific index exists in the temporary array, copying it from the original if not.
28+
* @param index The index to check.
29+
* @throw std::out_of_range if index is bigger than the maximum index of the array.
30+
*/
2931
inline void checkIndexAndCopy(const uint64_t& index) {
3032
this->check();
31-
if (index >= N) {
32-
throw std::out_of_range("Index out of range");
33-
}
34-
if (tmp_->contains(index)) {
35-
return;
36-
}
37-
tmp_->emplace(index, array_[index]);
33+
if (index >= N) throw std::out_of_range("Index out of range");
34+
if (this->tmp_->contains(index)) return;
35+
this->tmp_->emplace(index, this->array_[index]);
3836
}
3937

4038
public:
41-
42-
/// Default Constructor
39+
/**
40+
* Default constructor.
41+
* @param a (optional) An array of T with fixed size of N to use during construction.
42+
* Defaults to an empty array.
43+
*/
4344
SafeArray(const std::array<T, N>& a = {}) : SafeBase(nullptr) {
4445
check();
4546
uint64_t index = 0;
4647
for (const auto& value : a) {
47-
tmp_->emplace(index, value);
48-
++index;
48+
this->tmp_->emplace(index, value);
49+
index++;
4950
}
5051
};
5152

52-
/// Constructor for contracts
53+
/**
54+
* Constructor with owner, for contracts.
55+
* @param owner The owner of the variable.
56+
* @param a (optional) An array of T with fixed size of N to use during construction.
57+
* Defaults to an empty array.
58+
*/
5359
SafeArray(DynamicContract* owner, const std::array<T, N>& a = {}) : SafeBase(owner) {
5460
check();
5561
uint64_t index = 0;
5662
for (const auto& value : a) {
57-
tmp_->emplace(index, value);
58-
++index;
63+
this->tmp_->emplace(index, value);
64+
index++;
5965
}
6066
};
6167

62-
/// Access specified element with bounds checking
68+
/**
69+
* Access a specified element of the temporary array with bounds checking.
70+
* @param pos The position of the index to access.
71+
* @return The element at the given index.
72+
*/
6373
inline T& at(std::size_t pos) {
6474
checkIndexAndCopy(pos);
6575
markAsUsed();
66-
return tmp_->at(pos);
76+
return this->tmp_->at(pos);
6777
}
6878

69-
/// Access specified element with bounds checking (const version)
79+
/**
80+
* Const overload of at().
81+
* @param pos The position of the index to access.
82+
* @return The element at the given index.
83+
*/
7084
const T& at(std::size_t pos) const {
7185
checkIndexAndCopy(pos);
72-
return tmp_->at(pos);
86+
return this->tmp_->at(pos);
7387
}
7488

75-
/// Access specified element
89+
/**
90+
* Access a specified element of the temporary array without bounds checking.
91+
* @param pos The position of the index to access.
92+
* @return The element at the given index.
93+
*/
7694
inline T& operator[](std::size_t pos) {
7795
checkIndexAndCopy(pos);
7896
markAsUsed();
79-
return (*tmp_)[pos];
97+
return (*this->tmp_)[pos];
8098
}
8199

82-
/// Access specified element (const version)
100+
/**
101+
* Const overload of operator[].
102+
* @param pos The position of the index to access.
103+
* @return The element at the given index.
104+
*/
83105
inline const T& operator[](std::size_t pos) const {
84106
checkIndexAndCopy(pos);
85-
return (*tmp_)[pos];
107+
return (*this->tmp_)[pos];
86108
}
87109

88-
/// Return the ORIGINAL array const begin()
89-
inline std::array<T, N>::const_iterator cbegin() const {
90-
return array_.cbegin();
91-
}
110+
/// Get an iterator to the beginning of the original array.
111+
inline std::array<T, N>::const_iterator cbegin() const { return this->array_.cbegin(); }
92112

93-
/// Return the ORIGINAL array const end()
94-
inline std::array<T, N>::const_iterator cend() const {
95-
return array_.cend();
96-
}
113+
/// Get an iterator to the end of the original array.
114+
inline std::array<T, N>::const_iterator cend() const { return this->array_.cend(); }
97115

98-
/// Return the ORIGINAL array const crbegin()
99-
inline std::array<T, N>::const_reverse_iterator crbegin() const {
100-
return array_.crbegin();
101-
}
116+
/// Get a reverse iterator to the beginning of the original array.
117+
inline std::array<T, N>::const_reverse_iterator crbegin() const { return this->array_.crbegin(); }
102118

103-
/// Return the ORIGINAL array const crend()
104-
inline std::array<T, N>::const_reverse_iterator crend() const {
105-
return array_.crend();
106-
}
119+
/// Get a reverse iterator to the end of the original array.
120+
inline std::array<T, N>::const_reverse_iterator crend() const { return this->array_.crend(); }
107121

108-
/// Empty
109-
inline bool empty() const {
110-
return (N == 0);
111-
}
122+
/**
123+
* Check if the original array is empty (has no elements).
124+
* @return `true` if array is empty, `false` otherwise.
125+
*/
126+
inline bool empty() const { return (N == 0); }
112127

113-
/// Size
114-
inline std::size_t size() const {
115-
return N;
116-
}
128+
/**
129+
* Get the current size of the original array.
130+
* @return The size of the array.
131+
*/
132+
inline std::size_t size() const { return N; }
117133

118-
/// Max size
119-
inline std::size_t max_size() const {
120-
return N;
121-
}
134+
/**
135+
* Get the maximum possible size of the original array.
136+
* @return The maximum size.
137+
*/
138+
inline std::size_t max_size() const { return N; }
122139

123140
/**
124-
* Fill the array with a value
125-
* @param value The value to fill the array with
126-
*/
141+
* Fill the temporary array with a given value.
142+
* @param value The value to fill the array with.
143+
*/
127144
inline void fill(const T& value) {
128-
for (uint64_t i = 0; i < N; ++i) {
129-
tmp_->insert_or_assign(i, value);
130-
}
145+
for (uint64_t i = 0; i < N; i++) this->tmp_->insert_or_assign(i, value);
131146
}
132147

133-
/// Commit function.
148+
/// Commit the value. Updates the original array from the temporary one and clears it.
134149
void commit() override {
135-
for (const auto& [index, value] : *tmp_) {
136-
array_[index] = value;
137-
}
150+
for (const auto& [index, value] : *this->tmp_) this->array_[index] = value;
138151
}
139152

140-
/// Rollback function.
141-
void revert() const override {
142-
tmp_ = nullptr;
143-
}
153+
/// Revert the value. Nullifies the temporary array.
154+
void revert() const override { this->tmp_ = nullptr; }
144155
};
145156

146-
147-
#endif // SAFEARRAY_H
157+
#endif // SAFEARRAY_H

0 commit comments

Comments
 (0)