forked from cronos-labs/play-cpp-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Problem: Missing examples of using the cpp sdk (fix cronos-labs#103)
Solution: - Add examples.
- Loading branch information
Showing
5 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "include/extra-cpp-bindings/src/lib.rs.h" | ||
#include "include/rust/cxx.h" | ||
#include <iostream> | ||
using namespace com::crypto::game_sdk; | ||
using namespace rust; | ||
using namespace std; | ||
|
||
// Read CronoScan api key in env | ||
const String CRONOSCAN_API_KEY = getenv("CRONOSCAN_API_KEY"); | ||
|
||
int main(int argc, char *argv[]) { | ||
// Get a list of "CRC20 - Token Transfer Events" by Address | ||
// Returns up to a maximum of the last 10000 transactions only | ||
// https://cronoscan.com/tokentxns?a=0xa9b34a4b568e640d5e5d1e6e13101025e1262864 | ||
Vec<RawTxDetail> erc20_txs = get_erc20_transfer_history_blocking( | ||
"0xa9b34a4b568e640d5e5d1e6e13101025e1262864", "", QueryOption::ByAddress, | ||
CRONOSCAN_API_KEY); | ||
|
||
for (Vec<RawTxDetail>::iterator ptr = erc20_txs.begin(); | ||
ptr < erc20_txs.end(); ptr++) { | ||
cout << "hash: " << ptr->hash << " "; | ||
cout << "to: " << ptr->to_address << " "; | ||
cout << "from: " << ptr->from_address << " "; | ||
cout << "value:" << ptr->value << " "; | ||
cout << "block_no: " << ptr->block_no << " "; | ||
cout << "timestamp: " << ptr->timestamp << " "; | ||
cout << "contract: " << ptr->contract_address << " " << endl; | ||
} | ||
|
||
cout << "A total of " << erc20_txs.size() << " transactions" << endl; | ||
|
||
// Get a list of "CRC20 - Token Transfer Events" by ByAddressAndContract | ||
// Returns up to a maximum of the last 10000 transactions only | ||
// https://cronoscan.com/token/0x2d03bece6747adc00e1a131bba1469c15fd11e03?a=0xa9b34a4b568e640d5e5d1e6e13101025e1262864 | ||
erc20_txs = get_erc20_transfer_history_blocking( | ||
"0xa9b34a4b568e640d5e5d1e6e13101025e1262864", | ||
"0x2D03bECE6747ADC00E1a131BBA1469C15fD11e03", | ||
QueryOption::ByAddressAndContract, CRONOSCAN_API_KEY); | ||
|
||
for (Vec<RawTxDetail>::iterator ptr = erc20_txs.begin(); | ||
ptr < erc20_txs.end(); ptr++) { | ||
cout << "hash: " << ptr->hash << " "; | ||
cout << "to: " << ptr->to_address << " "; | ||
cout << "from: " << ptr->from_address << " "; | ||
cout << "value:" << ptr->value << " "; | ||
cout << "block_no: " << ptr->block_no << " "; | ||
cout << "timestamp: " << ptr->timestamp << " "; | ||
cout << "contract: " << ptr->contract_address << " " << endl; | ||
} | ||
cout << "A total of " << erc20_txs.size() << " transactions" << endl; | ||
|
||
// Get a list of "CRC20 - Token Transfer Events" by ByContract | ||
// Returns up to a maximum of the last 10000 transactions only | ||
erc20_txs = get_erc20_transfer_history_blocking( | ||
"", "0x66e428c3f67a68878562e79A0234c1F83c208770", QueryOption::ByContract, | ||
CRONOSCAN_API_KEY); | ||
|
||
cout << "A total of " << erc20_txs.size() << " transactions" << endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include "include/extra-cpp-bindings/src/lib.rs.h" | ||
#include "include/rust/cxx.h" | ||
#include <iostream> | ||
using namespace com::crypto::game_sdk; | ||
using namespace rust; | ||
using namespace std; | ||
|
||
// Read CronoScan api key in env | ||
const String CRONOSCAN_API_KEY = getenv("CRONOSCAN_API_KEY"); | ||
|
||
int main(int argc, char *argv[]) { | ||
// Get a list of "ERC721 - Token Transfer Events" by Address | ||
// Returns up to a maximum of the last 10000 transactions only | ||
// https://cronoscan.com/tokentxns-nft?a=0x668f126b87936df4f9a98f18c44eb73868fffea0 | ||
Vec<RawTxDetail> erc721_txs = get_erc721_transfer_history_blocking( | ||
"0x668f126b87936df4f9a98f18c44eb73868fffea0", "", QueryOption::ByAddress, | ||
CRONOSCAN_API_KEY); | ||
|
||
for (Vec<RawTxDetail>::iterator ptr = erc721_txs.begin(); | ||
ptr < erc721_txs.end(); ptr++) { | ||
cout << "hash: " << ptr->hash << " "; | ||
cout << "to: " << ptr->to_address << " "; | ||
cout << "from: " << ptr->from_address << " "; | ||
cout << "TokenID:" << ptr->value << " "; | ||
cout << "block_no: " << ptr->block_no << " "; | ||
cout << "timestamp: " << ptr->timestamp << " "; | ||
cout << "contract: " << ptr->contract_address << " " << endl; | ||
} | ||
|
||
cout << "A total of " << erc721_txs.size() << " transactions" << endl; | ||
|
||
// Get a list of "ERC721 - Token Transfer Events" ByAddressAndContract | ||
// Returns up to a maximum of the last 10000 transactions only | ||
// https://cronoscan.com/token/0x562f021423d75a1636db5be1c4d99bc005ccebfe?a=0x668f126b87936df4f9a98f18c44eb73868fffea0 | ||
erc721_txs = get_erc721_transfer_history_blocking( | ||
"0x668f126b87936df4f9a98f18c44eb73868fffea0", | ||
"0x562F021423D75A1636DB5bE1C4D99Bc005ccebFe", | ||
QueryOption::ByAddressAndContract, CRONOSCAN_API_KEY); | ||
|
||
for (Vec<RawTxDetail>::iterator ptr = erc721_txs.begin(); | ||
ptr < erc721_txs.end(); ptr++) { | ||
cout << "hash: " << ptr->hash << " "; | ||
cout << "to: " << ptr->to_address << " "; | ||
cout << "from: " << ptr->from_address << " "; | ||
cout << "TokenID:" << ptr->value << " "; | ||
cout << "block_no: " << ptr->block_no << " "; | ||
cout << "timestamp: " << ptr->timestamp << " "; | ||
cout << "contract: " << ptr->contract_address << " " << endl; | ||
} | ||
cout << "A total of " << erc721_txs.size() << " transactions" << endl; | ||
|
||
// Get a list of "ERC721 - Token Transfer Events" ByContract | ||
// Returns up to a maximum of the last 10000 transactions only | ||
// https://cronoscan.com/token/0x18b73d1f9e2d97057dec3f8d6ea9e30fcadb54d7 | ||
erc721_txs = get_erc721_transfer_history_blocking( | ||
"", "0x18b73D1f9e2d97057deC3f8D6ea9e30FCADB54D7", QueryOption::ByContract, | ||
CRONOSCAN_API_KEY); | ||
for (Vec<RawTxDetail>::iterator ptr = erc721_txs.begin(); | ||
ptr < erc721_txs.end(); ptr++) { | ||
cout << "hash: " << ptr->hash << " "; | ||
cout << "to: " << ptr->to_address << " "; | ||
cout << "from: " << ptr->from_address << " "; | ||
cout << "TokenID:" << ptr->value << " "; | ||
cout << "block_no: " << ptr->block_no << " "; | ||
cout << "timestamp: " << ptr->timestamp << " "; | ||
cout << "contract: " << ptr->contract_address << " " << endl; | ||
} | ||
|
||
cout << "A total of " << erc721_txs.size() << " transactions" << endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "include/defi-wallet-core-cpp/src/lib.rs.h" | ||
#include "include/rust/cxx.h" | ||
#include <iostream> | ||
using namespace org::defi_wallet_core; | ||
using namespace std; | ||
|
||
int main(int argc, char *argv[]) { | ||
auto wallet = new_wallet("", MnemonicWordCount::TwentyFour); | ||
cout << wallet->get_default_address(CoinType::CronosMainnet) << endl; | ||
cout << wallet->get_address(CoinType::CronosMainnet, 0) << endl; | ||
cout << wallet->get_eth_address(0) << endl; | ||
auto private_key = wallet->get_key("m/44'/60/0'/0/0"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "include/defi-wallet-core-cpp/src/lib.rs.h" | ||
#include "include/rust/cxx.h" | ||
#include <iostream> | ||
using namespace org::defi_wallet_core; | ||
using namespace std; | ||
|
||
int main(int argc, char *argv[]) { | ||
auto wallet = restore_wallet("shed crumble dismiss loyal latin million oblige gesture shrug still oxygen custom remove ribbon disorder palace addict again blanket sad flock consider obey popular", ""); | ||
cout << wallet->get_default_address(CoinType::CronosMainnet) << endl; | ||
cout << wallet->get_address(CoinType::CronosMainnet, 0) << endl; | ||
cout << wallet->get_eth_address(0) << endl; | ||
auto private_key = wallet->get_key("m/44'/60/0'/0/0"); | ||
return 0; | ||
} |