Blockchain Management Service (BMS)
The blockchain management service is a centralization of all known nodes and blockchains. It provides the means to interact with a network of registered systems.
Creating a blockchain management instance
To create a blockchain management instance do the following:
#include "ULC.hpp"
using namespace ULC;
using namespace ULC::BMS;
UL_BlockchainManagement bms{};
Setting the URL of the BMS service
To set the URL of the blockchain management service do the following:
// You could also pass this paramater into the constructor of the bms.
bms.SetBmsUrl(UL_BMS_URL); // This is the default url.
Giving authority to the blockchain management instance
To give the instance authentication credentials do the following:
// Add the using declaration for brevity
using namespace ULC::AUTH;
// Create the auth instance
UL_Auth auth{};
auth.SetCertFilePath("cacert.pem"); // This is your certificate file included with ULC.
auth.SetBearer("My JWT Token"); // For use with private blockchains.
auth.SetApiKey("My api key"); // Interchangeable with the bearer, but this allows explicitly setting a key for an api.
bms.SetAuthorizor(auth);
Setting options for a blockchain management instance
To set options for the blockchain management instance to use during http calls do the following:
// Add the using declaration for brevity
using namespace ULC::HTTP;
UL_Options options{};
options.VerboseLogs(true); // For verbose curl logs.
options.UnsafeRequest(false); // For debugging those pesky calls, do not leave true for a production network as this leaves you vulnerable to man in the middle attacks.
options.Timeout = UL_DEFAULT_HTTP_REQUEST_TIMEOUT; // How many seconds before timeout on http calls.
bms.SetOptions(options);
Getting the version of a BMS
Getting the version for a bms is a great way to ping the service and check that the bms is accessible.
To get the version of a bms do the following:
// Include string
#include <string>
// Get the version of the bms
std::string versionJson;
bool success = bms.GetVersion(versionJson);
if (!success) {
// Handle error
}
else {
std::cout << "Version: " << versionJson.c_str() << std::endl;
}
Getting the BMS information
To get metrics about the bms do the following:
UL_ServicesResponse bmsInfo;
bool success = bms.GetServices(bmsInfo);
if (!success) {
// Handle error
}
else {
std::cout << "BMS Info: " << bmsInfo.ToJson(true).c_str() << std::endl;
}
Getting a blockchains transaction history
To get the history of the transactions on the blockchain do the following:
std::string blockchainId = "my_blockchain_id";
constexpr int count = 10; // How many transaction to look for.
constexpr int start = 0; // Which entry to start from, this can be out of the range of actual transactions.
const bool sort = true; // Sort the transactions by time.
const bool trim = false; // Do not trim the payload data from the transaction.
UL_Pagination pagination{count, start, sort, trim};
UL_TransactionList transactions;
bool success = bms.GetTransactions(blockchainId, pagination, transactions);
if (!success) {
// Handle error.
}
else {
std::cout << "Transactions: " << transactions.ToJson(true).c_str() << std::endl;
}
Getting the transactions from a block
To get the transactions from a specific block do the following:
std::string blockId = "my_block_id";
constexpr int count = 10; // How many transaction to look for.
constexpr int start = 0; // Which entry to start from, this can be out of the range of actual transactions.
const bool sort = true; // Sort the transactions by time.
const bool trim = false; // Do not trim the payload data from the transaction.
UL_Pagination pagination{count, start, sort, trim};
UL_TransactionsList transactions;
bool success = bms.GetTransactionsFromBlock(blockId, pagination, transactions);
if (!success) {
// Handle error.
}
else {
std::cout << "Transactions: " << transactions.ToJson(true).c_str() << std::endl;
}
Getting the blocks on a blockchain
To get the blocks on a blockchain do the following:
std::string blockchainId = "my_blockchain_id";
constexpr int count = 10; // How many transaction to look for.
constexpr int start = 0; // Which entry to start from, this can be out of the range of actual transactions.
const bool sort = true; // Sort the transactions by time.
const bool trim = false; // Do not trim the payload data from the transaction.
UL_Pagination pagination{count, start, sort, trim};
UL_BlocksList blocks;
bool success = bms.GetBlocks(blockchainId, pagination, blocks);
if (!success) {
// Handle error.
}
else {
std::cout << "Blocks:" << blocks.ToJson(true).c_str() << std::endl;
}
Getting a users history
To get a users(wallet address) history do the following:
std::string blockchainId = "my_blockchain_id";
constexpr int count = 10; // How many transaction to look for.
constexpr int start = 0; // Which entry to start from, this can be out of the range of actual transactions.
const bool sort = true; // Sort the transactions by time.
const bool trim = false; // Do not trim the payload data from the transaction.
UL_Pagination pagination{count, start, sort, trim};
UL_UserHistory userHistory;
bool success = bms.GetUserHistory(blockchainId, pagination, userHistory);
if (!success) {
// Handle error.
}
else {
std::cout << "User History: " << userHistory.ToJson(true).c_str() << std::endl;
}
Searching a block by its Id
To search for a block by its Id do the following:
std::string blockId = "my_block_id";
constexpr int count = 10; // How many transaction to look for.
constexpr int start = 0; // Which entry to start from, this can be out of the range of actual transactions.
const bool sort = true; // Sort the transactions by time.
const bool trim = false; // Do not trim the payload data from the transaction.
UL_Pagination pagination{count, start, sort, trim};
UL_Block block;
bool success = bms.SearchBlockById(blockId, pagination, block);
if (!success) {
// Handle error.
}
else {
std::cout << "Block: " << block.ToJson(true).c_str() << std::endl;
}
Searching for a transaction by its Id
To search for a transaction by its Id do the following:
std::string transactionId = "my_transaction_id";
constexpr int count = 10; // How many transaction to look for.
constexpr int start = 0; // Which entry to start from, this can be out of the range of actual transactions.
const bool sort = true; // Sort the transactions by time.
const bool trim = false; // Do not trim the payload data from the transaction.
UL_Pagination pagination{count, start, sort, trim};
UL_TransactionResponse foundTransaction;
bool success = bms.SearchTransactionById(transactionId, pagination, foundTransaction);
if (!success) {
// Handle error.
}
else {
std::cout << "Transaction: " << foundTransaction.ToJson(true).c_str() << std::endl;
}
Search blocks and transaction by partial key
To search for blocks and transactions by a partial key do the following:
std::string blockchainId = "my_blockchain_id";
std::string partialKey = "partial_key";
constexpr int count = 10; // How many transaction to look for.
constexpr int start = 0; // Which entry to start from, this can be out of the range of actual transactions.
const bool sort = true; // Sort the transactions by time.
const bool trim = false; // Do not trim the payload data from the transaction.
UL_Pagination pagination{count, start, sort, trim};
UL_SearchQuery query{};
bool success = bms.SearchBlocksAndTransactions(blockchainId, partialKey, pagination, query);
if (!success) {
// Handle error.
}
else {
std::cout << "Search Query: " << query.ToJson(true).c_str() << std::endl;
}