-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtransfer.cpp
50 lines (39 loc) · 1.46 KB
/
transfer.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
#include "../src/polkadot.h"
int main(int argc, char *argv[]) {
// This is a manual test due to lack of test DOTs
if (argc < 4) {
cout << "This is intended to be a manual test" << endl;
cout << "Usage: ";
cout << argv[0] << " <sender address> <recipient address> <amount in fDOTs> <sender private key (hex)>" << endl;
cout << "success" << endl;
return 0;
}
// Extract parameters
string senderAddr(argv[1]);
string recipientAddr(argv[2]);
string amountStr(argv[3]);
string senderPrivateKeyStr(argv[4]);
JsonRpcParams params;
params.jsonrpcVersion = "2.0";
EasyLogger logger;
CJsonRpc jsonRpc(CWebSocketClient::getInstance(&logger), &logger, params);
CPolkaApi app(&logger, &jsonRpc);
app.connect();
// Transfer and wait for updates
bool done = false;
app.signAndSendTransfer(senderAddr, senderPrivateKeyStr, recipientAddr, 1000000000000, [&](string result) {
if (result == "ready")
cout << endl << endl << " ---=== Transaction was registered in network ===--- " << endl << endl << endl;
if (result == "finalized") {
cout << endl << endl << " ---=== Transaction was mined! ===--- " << endl << endl << endl;
done = true;
}
});
// Wait until transaction is mined
while (!done)
usleep(10000);
// Unsubscribe and close connection
app.disconnect();
cout << "success" << endl;
return 0;
}