Bytecoin API overview

From Bytecoin Wiki
Jump to: navigation, search
Api-scheme.png

The scheme on the right side of the screen is a visualization of the current Bytecoin API. All Bytecoin APIs are designed as a combination of various interfaces. Let's have a quick overview starting from INode and INodeObserver interfaces. INode is an interface that contains methods for the interaction with the Bytecoin P2P network, which allows user to request information about the actual state of blockchain and transaction pool. It also provides methods for attaching observers (objects that implement INodeObserver interface), the main purpose of which is to observe P2P network changes, such as blockchain height or new pool transactions. So they receive notifications about these changes from INode.

Next layer of the API (the `synchronization` layer) is represented by IBlockchainSynchronizer and IBlockchainSynchronizerObserver interfaces. It synchronizes the data between P2P (represented by INode) and so-called consumers. IBlockchainSynchronizer is an interface that enables a user to control the synchronization process and manage the `consumers`.

Consumers implement the IBlockhainConsumer interface being attached to IBlockchainSynchronizer and wait for notifications from Synchronizer about new blocks, pool changes and switching network into alternative blockchain. BlockchainSynchronizer records synchronization statuses of all consumers and gives them appropriate blocks and pool transactions. It also notifies its own observers (IBlockchainSynchronizerObserver) about the progress and completion of a synchronization process.

TransferConsumer is an object that implements IBlockhainConsumer. TransferConsumer contains public view key (part of Bytecoin wallet address), which may correspond to multiple addresses and provides an option to process transaction for these addresses. It also contains an object that implements ITransferSubscription interface which represents a subscription for a specific spent key for given TransferSubscription. TransferSubscription also manages observers that are attached to it and implements the ITransfersObserver interface, and notifies them about transactions' information related to address which given subscription represents. TransferSubscription provides an access to object that implements ITransfersContainer interface, which main purpose is to contain data about transactions for given address such as inputs, outputs, their confirmation statuses, spent key images and so on. It also allows user to calculate balance set from different types of outputs (locked, softlocked, unlocked), and pick spendable outputs for creating a new transaction. And finally, there is ITransferSynchronizer interface that provides user with an option to subscribe for transactions for a given address. TransferSynchronizer creates such subscription and passes the ITransferSubscription object back to user.

Contents

Detailed Info

Node

INode.png

INodeObserver

Interface of the node observer. It allows node’s clients to receive notifications about the changes in blockchain height or transaction pool.

Callbacks

lastKnownBlockHeightUpdated() - notifies about last known block height changing.

poolChanged() - notifies about changes in transaction pool.

INode

Node’s interface which provides user with connection to Bytecoin P2P network and allows user to request actual state of the transaction pool, block info and create/remove observer.

Methods

queryBlocks() - returns blocks to a caller depending on known block hashes.

getPoolSymmetricDifference() - returns the difference between network's transactions pool and user's.

add/removeObserver() - adds or removes an INodeObserver.



Blocks and Pool

IBlockchainSynchronizer.png

IBlockchainSynchronizer

Interface which is responsible for a synchronization between the Node and the “Wallet”. It requests transaction pool, blockchain history and creates/removes consumers. Consumer contains a view key and provides user with an option to process transactions with the same view key. 1 consumer = 1 view key.

Methods

addConsumer() - adds IBlockchainConsumer.

removeConsumer() - removes IBlockchainConsumer.

start/stop() - start/stop synchronization.

IBlockchainSynchronizerObserver

Interface of the IBlockchainSynchronizer observers. It is used for a purpose of subscriber notification on the end of the synchronization or it’s status. It also returns blockchain height and the status of the synchronization completion.

Callbacks

synchronizationProgressUpdated() - notifies about the synchronization progress updates.

synchronizationCompleted() - notifies about synchronization completion.



Transactions

IBlockchainConsumer.png

IBlockchainConsumer

Block and transaction consumer interface. It's an object that implements this interface and receives messages about new blocks, block detach and pool state changes.

Callbacks

onNewBlocks() - notifies user about arriving of new blocks and passes them.

onPoolUpdated() - notifies about changes in transaction pool, passes hashes of deleted transactions and new transactions to a user.

onBlockchainDetach() - notifies about switching to an alternative blockchain and passes the splitting height.



Transfers (inputs and outputs)

ITransfer.png

ITransferSubscription

Interface that provides an access to the ITransferContainer (transaction container) interface for a particular spend and view keys pair. It is also a source of the events for these transactions. It notifies ITransferObserver interface subscribers about these transactions.

Methods

add/removeObserver() - adds and removes ITransfersObserver.

getAddress() - returns subscription address

getContainer() - returns an object that implements ITransfersContainer interface

ITransferObserver

Interface of the ITransferSubscription observer. It receives notifications about the events connected to the current subscriber, such as: transaction deleting, transaction adding, transaction status update (for example, transaction was in the transaction pool and got into blockchain) and transaction processing errors.

Callbacks

onError() - notifies about transactions proceeding errors.

onTransactionUpdated() - notifies about transaction adding or changes in transaction properties.

onTransactionDeleted() - notifies about transaction deleting.

ITransferContainer

Interface that provides information about transactions, outputs and status of the outputs for these transactions. It also allows user to calculate a balance from all the types of outputs (locked, softlocked and unlocked)

Methods

balance() - returns sum of amounts that corresponds to user's outputs.

getTransactionInformation() - returns an information about transaction.

getUnconfirmedTransactions() - returns a list of unconfirmed transactions

getTransactionOutputs() - returns a list of outputs for a particular transaction.

getSpentOutputs() - returns a list of spent outputs.



Synchronization Management

ITransferSynchronizer.png

ITransferSynchronizer

Interface that provides the user with objects of the ITransferSubscription type based on the received spend and view keys pair.

Methods

addSubscription() - creates subscription for a passed account address and returns it to the caller.

getSubscription() - returns an ITransfersSubscription object that corresponds to a passed account address or nullptr if such subscription does not exist.

getSubscriptions() - returns a list of subscribed accounts' addresses.

removeSubscription() - removes subscription for a given account address.

Wallet Implementation

IWallet-v2.png

IWallet

Interface that provides control to user's wallet. By means of it user can send transactions, save/load wallet and keys data, acquire his balance, information about transfers etc.

Methods

API methods for IWallet interface can be found here: IWallet Interface Methods

IWalletObserver

Interface that IWallet observers must inherit. Through it user's object may receive data about Wallet state, such as status of saving, loading, synchronization. It also provides information about balance changes and incoming transaction.

API methods for IWalletObserver interface can be found here: IWalletObserver Methods

Personal tools
Namespaces

Variants
Actions
Navigation
Tools