-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
90 lines (71 loc) · 2 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "./lib/epine-sdk-cpp/src/epine.h"
#include <functional>
#include <iostream>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <string>
#ifdef WIN32
#define HIGHLIGHT(__O__) std::cout << __O__ << std::endl
#define EM(__O__) std::cout << __O__ << std::endl
#include <stdio.h>
#include <tchar.h>
#define MAIN_FUNC int _tmain(int argc, _TCHAR *argv[])
#else
#define HIGHLIGHT(__O__) std::cout << "\e[1;31m" << __O__ << "\e[0m" << std::endl
#define EM(__O__) std::cout << "\e[1;30;1m" << __O__ << "\e[0m" << std::endl
#define MAIN_FUNC int main(int argc, const char *args[])
#endif
using namespace std;
using namespace sio;
std::mutex _lock;
std::condition_variable_any _cond;
bool isReady = false;
void wait() {
isReady = false;
// Lock thread till done
_lock.lock();
if (!isReady)
{
_cond.wait(_lock);
}
_lock.unlock();
}
void stopWaiting() {
_lock.lock();
_cond.notify_all();
isReady = true;
_lock.unlock();
}
MAIN_FUNC {
// Define Epine Client
Epine::Client epineClient;
// Set init callback
auto on_init_callback = [](){
HIGHLIGHT("Client is ready");
stopWaiting();
};
epineClient.set_on_init_callback(on_init_callback);
// Call init
epineClient.init();
wait();
// Get wallet balance
std::vector<Epine::Tokens::Token> tokens = epineClient.tokens->getAddressBalance(
"vitalik.eth",
Epine::Constants::Chains::Type::EVM,
Epine::Constants::Chains::ID::EVM_ETHEREUM
);
HIGHLIGHT("Wallet balance: " + std::to_string(tokens[0].balance) + " " + tokens[0].symbol);
// Set wallet connection callback
epineClient.auth->wallet->on(Epine::Auth::Wallet::Event::CONNECTED, [&](std::vector<std::string> addresses){
HIGHLIGHT("CONNECTED CALLBACK");
HIGHLIGHT("Connected address #0: " + addresses[0]);
stopWaiting();
});
// Request wallet connection
std::string uri = epineClient.auth->wallet->connect(Epine::Constants::Chains::Type::EVM);
HIGHLIGHT("Received URI: " + uri);
wait();
EM("Finished");
return 0;
}