Skip to main content

Function Library

Common functionality has been included with ULC to ensure an easier experience. While the examples used have all been very manual, you can utilize these functions to condense lots of common functionality.

Auth

CreateAuthorization

To create an authorization instance do the following:

ULC::AUTH::UL_Auth authorization = CreateAuthorization("My JWT", "My API Key", "My Cacert File Location");
info

You can leave any of these inputs as empty strings without worry. If you don't need them, don't use them.

Options

CreateSessionOptions

To create options for a session do the following:

// bool UseVerboseNetworkLogs, long NetworkTimeoutSeconds, UL_Debug_Flags SessionFlags, bool UseUnsageDebugging
ULC::UL_Options CreateSessionOptions(false, 30L, {}, false);
info

These are the default options, and are not needed when performing any subsequent functions. You can modify any of these values. The flags act as a bitmask for options to be included in the future.

Wallets

To save a wallet, you can still call the underlying Save method on the returned wallet object from these methods.

CreateWallet

To create a wallet from scratch without saving do the following:

const std::string wordsFilePath = "english.txt";
bool walletCreationSuccess;
ULC::Wallets::UL_FileWallet wallet = CreateWallet(walletCreationSuccess, "MyNewWallet.ukey", wordsFilePath);
info

This function is noexcept but will output errors if there are issues with generating a seed phrase or with creating the wallet from the seed phrase. This may indicate a problem with the file path.

LoadWallet

To load a wallet without saving do the following:

bool walletLoadSuccess;
bool isEncrypted = false;
const std::string encryptedPassword = "";
ULC::Wallets::UL_FileWallet wallet = LoadWallet(walletLoadSuccess, "MyNewWallet.ukey", isEncrypted, encryptedPassword);

CreateAndSaveWallet

To create a wallet from scratch and save do the following:

const std::string wordsFilePath = "english.txt";
bool createAndSaveSuccess;
bool isEncrypted = false;
const std::string encryptedPassword = "";
ULC::Wallets::UL_FileWallet(createAndSaveSuccess, "MyNewWallet.ukey", wordsFilePath, isEncrypted, encryptedPassword);

Node

ConnectToNode

To connect to a node on the network do the following:

bool connectSuccess;
ULC::NODE::UL_Node node = ConnectToNode(connectSuccess, "Node URL", "", auth);

To specify a custom node Id or a custom atomic clock url do the following:

bool connectSuccess;
ULC::NODE::UL_Node node = ConnectToNode(connectSuccess, "Node URL", "Node ID", "Atomic Clock URL", auth, sessionOptions);

GetAtomicTimestamp

To get an atomic timestamp do the following:

bool timestampSuccess;
ULC::UL_Timestamp timestamp = GetAtomicTimestamp(timestampSuccess, node);

RegisterWalletWithBlockchain

To register a wallet with a blockchain do the following:

bool registerSuccess = RegisterWalletWithBlockchain("Blockchain ID", wallet, node);

CreateTransaction

To create a new transaction for posting do the following:

bool createTransactionSuccess;
ULC::UL_NodeTransaction transaction = CreateTransaction(createTransactionSuccess, wallet, node, "To Address");

To specify a custom payload for the transaction do the following:

bool createTransactionSuccess;
ULC::UL_NodeTransaction transaction = CreateTransaction(createTransactionSuccess, wallet, node, "To Address", "{\"My_Payload\":\"Some_JSON_Payload\"}");

PostTransaction

To post a transaction do the following:

bool postSuccess;
ULC::UL_TransactionResponse response = PostTransaction(postSuccess, "Blockchain ID", transaction, node);

CreateAndPostTransaction

To create and then send the transaction immediately do the following:

bool success;
ULC::UL_TransactionResponse response = CreateAndPostTransaction(success, wallet, node, "Blockchain ID", "To Address");

To specify a custom payload for the transaction do the following:

bool success;
ULC::UL_TransactionResponse response = CreateAndPostTransaction(success, wallet, node, "Blockchain ID", "To Address", "{\"My_Payload\":\"Some_JSON_Payload\"}");

BMS

ConnectToBms

To connect to a BMS do the following:

info

This requires valid authentication, and will connect to the global BMS system run by ULedger. You can leave out session options, as this is used to modify a session (typically for debugging connections).

bool connectSuccess;
ULC::BMS::UL_BlockchainManagement bms = ConnectToBms(connectSuccess, auth, sessionOptions);

To Specify a custom BMS address do the following:

bool connectSuccess;
ULC::BMS::UL_BlockchainManagement bms = ConnectToBms(connectSuccess, "My BMS URL", auth, sessionOptions);

GetBmsVersion

To retrieve the version of the BMS after establishing a connection, proceed with the following steps:

info

Obtaining the version is the way the ConnectTo methods verify that they have a valid BMS to connect to, as there is no persistent active connection.

bool versionSuccess;
const std::string version = GetBmsVersion(versionSuccess, bms);

GetBmsServicesCount

To get analytics on the services offered by the BMS do the following:

bool servicesSuccess;
ULC::UL_ServicesResponse services = GetBmsServicesCount(servicesSuccess, bms);

GetTransactions

To get the transactions on a blockchain do the following:

bool transactionsSuccess;
ULC::UL_TransactionsList transactions = GetTransactions(transactionsSuccess, "Blockchain ID", bms);

To specify custom pagination to hone in on your intended results do the following:

bool transactionsSuccess;
constexpr int maxPages = 10;
constexpr int startPage = 0;
const bool sort = true;
const bool removePayload = false;
ULC::UL_TransactionsList transactions = GetTransactions(transactionsSuccess, "Blockchain ID", bms, ULC::UL_Pagination(maxPages, startPage, sort, removePayload));

GetTransactionsFromBlock

To get the transactions from a block do the following:

bool transactionsSuccess;
ULC::UL_Pagination pagination = ULC::UL_Pagination(10, 0, true, false);
ULC::UL_TransactionsList transactions = GetTransactionsFromBlock(transactionsSuccess, bms, "Block ID", pagination);

GetBlocksOnABlockchain

To get the blocks on a blockchain do the following:

bool blocksSuccess;
ULC::UL_BlocksList blocks = GetBlocksOnABlockchain(blocksSuccess, bms, "Blockchain ID", pagination);

GetUserHistory

To get a user's history, do the following:

bool historySuccess;
ULC::UL_UserHistory history = GetUserHistory(historySuccess, bms, "Blockchain ID", "Address", pagination);

SearchForBlockById

To search for a block by its ID, do the following:

bool searchSuccess;
ULC::UL_Block block = SearchForBlockById(searchSuccess, bms, "Block ID", pagination);

SearchForTransactionById

To search for a transaction by its ID, do the following:

bool searchSuccess;
bool isPolling = false; // Used for polling a transaction, typically in a loop to wait after a post transaction is made.
ULC::UL_TransactionResponse response = SearchForTransactionById(searchSuccess, bms, "Transaction ID", false, pagination);

SearchByPartialKey

To search for a transaction or block by a partial key, do the following:

info

This is a fuzzy find option for when you only know a portion of an ID or if you want to make a fuzzy search engine.

bool searchSuccess;
ULC::UL_SearchQuery result = SearchByPartialKey(searchSuccess, bms, "Blockchain ID", "Partial Key", pagination);
© 2023 ULedger Inc. All rights reserved