Skip to content

Commit b1f6955

Browse files
sleepdefic1tfaustbrian
authored andcommitted
feat(api): add blockchain endpoint (#104)
1 parent f39aebe commit b1f6955

32 files changed

+336
-267
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## Unreleased
99

10+
### Added
11+
12+
- added Blockchain API endpoint ([#104])
13+
1014
### Changed
1115

1216
- improved class members and test coverage ([#93])

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
## Documentation
1515

16-
You can find installation instructions and detailed instructions on how to use this package at the [dedicated documentation site](https://docs.ark.io/sdk/clients/cpp.html).
16+
You can find installation instructions and detailed instructions on how to use this package at the [dedicated documentation site](https://docs.ark.io/sdk/clients/usage.html).
1717

1818
## Security
1919

docs/INSTALL_ARDUINO.md

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ void setup() {
4848

4949
Ark::Client::Connection<Ark::Client::Api> connection(CustomNetwork);
5050

51+
Serial.println(arkClient.blockchain.get().c_str());
52+
5153
Serial.println(arkClient.blocks.all().c_str());
5254
Serial.println();
5355

docs/cpp.md

+57-43
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,22 @@ This package is still under development. This page will get more content as it e
1111
[[toc]]
1212

1313
## Platforms
14-
* [Arduino](#Arduino)
15-
* [Linux >= 16.04](#OS)
16-
* [macOS >= 10.10](#OS)
17-
* [Windows >= 7](#OS)
14+
15+
- [Arduino](#Arduino)
16+
- [Linux >= 16.04](#OS)
17+
- [macOS >= 10.10](#OS)
18+
- [Windows >= 7](#OS)
1819

1920
## Usage
2021

21-
The Cpp Client is meant to be used for creating request to an API endpoint.
22-
For cryptography related functionality, such as generating addresses or creating transactions,
22+
The Cpp Client is meant to be used for creating request to an API endpoint.
23+
For cryptography related functionality, such as generating addresses or creating transactions,
2324
please see the [Cpp Crypto](https://github.com/ArkEcosystem/cpp-crypto) repository.
2425

2526
### Connection
2627

27-
Before making a request, you should create a `Connection`.
28-
A `Connection` expects a `host`, which is an url on which the API can be reached.
28+
Before making a request, you should create a `Connection`.
29+
A `Connection` expects a `host`, which is an url on which the API can be reached.
2930
An example `Connection`, that interfaces with the API of an Ark Node, would be created as follows:
3031

3132
```cpp
@@ -38,10 +39,9 @@ Ark::Client::Connection<Ark::Client::Api> connection("167.114.29.54", 4003);
3839
The below example shows how you can perform a request.
3940
4041
```cpp
41-
// Check the API Version
42-
auto apiVersion = connection.api.version();
43-
4442
// Perform an API call using the connection to access endpoint
43+
const auto blockchainResponse = connection.api.blockchain.get();
44+
4545
const auto blockResponse = connection.api.blocks.get("13114381566690093367")
4646
4747
const auto delegateResponse = connection.api.delegates.get("boldninja");
@@ -56,19 +56,23 @@ const auto vote = connection.api.votes.get("d202acbfa947acac53ada2ac8a0eb662c9f7
5656
5757
const auto walletsSearch = connection.api.wallets.search({"username", "baldninja"});
5858
```
59-
> *note: All API response are of the type `std::string`
6059

61-
#
60+
> \*note: All API response are of the type `std::string`
61+
62+
#
6263

6364
### Getting an API Path
6465

65-
There are instances when a client may use a gateway or bridge to do http get/post;
66-
for this we have provided an interface for obtaining a properly formatted API Path for a given API Endpoint.
66+
There are instances when a client may use a gateway or bridge to do http get/post;
67+
for this we have provided an interface for obtaining a properly formatted API Path for a given API Endpoint.
6768
Below are examples of how to access the Path interface:
6869

6970
```cpp
7071
Ark::Client::Host dummyHost("0.0.0.0:4003");
7172

73+
std::string blockchainGetPath = Ark::Client::API::Paths::Blockschain::get(dummyHost);
74+
// blockchainGetPath will be the string "0.0.0.0:4003/api/blockchain"
75+
7276
std::string blocksAllPath = Ark::Client::API::Paths::Blocks::all(dummyHost, 5 /* limit */, 1 /* page */);
7377
// blocksAllPath will be the string "0.0.0.0:4003/api/v2/blocks?limit=5&page=1"
7478

@@ -100,14 +104,15 @@ std::pair<std::string, std::string> walletsSearchPath = Ark::Client::API::Paths:
100104
```
101105
102106
# Arduino
103-
**Arduino IDE:**
104-
Download and install the Arduino IDE (>=1.8.5) from the following link:
105-
```https://www.arduino.cc/en/Main/Software```
106107
107-
Using the Arduino IDE's built in Library Manager,
108-
install the following Libraries:
109-
```ArduinoJson v6.10.1```
110-
```AUnit```
108+
**Arduino IDE:**
109+
Download and install the Arduino IDE (>=1.8.5) from the following link:
110+
`https://www.arduino.cc/en/Main/Software`
111+
112+
Using the Arduino IDE's built in Library Manager,
113+
install the following Libraries:
114+
`ArduinoJson v6.10.1`
115+
`AUnit`
111116
112117
#### Arduino Example using the Adafruit Feather ESP8266
113118
@@ -129,15 +134,17 @@ void setup() {
129134
130135
Ark::Client::Connection<Ark::Client::Api> connection("167.114.29.54", 4003);
131136
137+
Serial.println(arkClient.blockchain.get().c_str());
138+
132139
auto allBlocks = arkClient.blocks.all();
133140
Serial.println(allBlocks.c_str());
134141
135142
auto allDelegates = arkClient.delegates.all();
136143
Serial.println(allDelegates.c_str());
137-
144+
138145
auto delegatesCount = arkClient.delegates.count();
139146
Serial.println(delegatesCount.c_str());
140-
147+
141148
auto allPeers = arkClient.peers.all();
142149
Serial.println(allPeers.c_str());
143150
@@ -148,15 +155,17 @@ void setup() {
148155
void loop() {}
149156
```
150157

151-
**PlatformIO IDE:**
158+
**PlatformIO IDE:**
159+
160+
#### Python:
152161

153-
#### Python:
154-
Use an installer package from the following link or use your preferred method to install Python:
155-
```https://www.python.org/downloads/```
162+
Use an installer package from the following link or use your preferred method to install Python:
163+
`https://www.python.org/downloads/`
156164

157165
Install PlatformIO:
158166

159167
pip install -U platformio
168+
160169
or
161170

162171
python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/develop/scripts/get-platformio.py)"
@@ -165,49 +174,54 @@ Install ArduinoJson@6.10.1 AUnit (2778)
165174

166175
platformio lib -g install 64@6.10.1 2778
167176

168-
#### Provide your WiFi info for your board to access the internet
177+
#### Provide your WiFi info for your board to access the internet
178+
179+
Open the following file in your preferred code editor:
169180

170-
Open the following file in your preferred code editor:
171-
> "*.../cpp-client/test/IoT/test_main.cpp*"
181+
> "_.../cpp-client/test/IoT/test_main.cpp_"
182+
183+
lines 19 & 20:
172184

173-
lines 19 & 20:
174185
```
175186
char ssid[] = "your_ssid"; // your network SSID (name)
176187
const char password[] = "your_password"; // your network password
177188
```
178189

179190
#### running the tests on an Arduino board
180191

181-
cd Cpp-Client
192+
cd Cpp-Client
182193
cd test
183194

184-
#### execute the following command to upload test to your board
195+
#### execute the following command to upload test to your board
185196

186-
>| board | command |
187-
>|:-- |:-- |
188-
>| ESP8266 | ```pio run -e esp8266 -t upload``` |
189-
>| ESP32 | ```pio run -e esp32 -t upload``` |
197+
> | board | command |
198+
> | :------ | :----------------------------- |
199+
> | ESP8266 | `pio run -e esp8266 -t upload` |
200+
> | ESP32 | `pio run -e esp32 -t upload` |
190201
191202
#
192203

193204
# OS
205+
194206
## Linux, macOS and Windows
195207

196-
**CMake:**
208+
**CMake:**
197209

198-
Use an installer package from the following link, Homebrew, or use your preferred method:
199-
```https://www.cmake.org/download/```
210+
Use an installer package from the following link, Homebrew, or use your preferred method:
211+
`https://www.cmake.org/download/`
200212

201213
using
202-
**Homebrew:**
214+
**Homebrew:**
203215

204216
brew install cmake
205217

206218
> note: all other dependencies will be automatically installed via git submodule and CMake.
207219
208220
### make and build
209-
cd cpp-client/
221+
222+
cd cpp-client/
210223
cmake . && cmake --build .
211224

212225
### run tests
226+
213227
./bin/Ark-Cpp-Client-tests

0 commit comments

Comments
 (0)