bitcoinj.github.io - How the different components of your app fit together









Search Preview

How the different components of your app fit together

bitcoinj.github.io
Introduction Getting started Documentation Community How the different components of your app fit together Introduction
.io > bitcoinj.github.io

SEO audit: Content analysis

Language Error! No language localisation is found.
Title How the different components of your app fit together
Text / HTML ratio 72 %
Frame Excellent! The website does not use iFrame solutions.
Flash Excellent! The website does not have any flash contents.
Keywords cloud block chain transaction data object blocks transactions message connection interface store MemoryPool class wallet network app provided full reorganize messages
Keywords consistency
Keyword Content Title Description Headings
block 24
chain 23
transaction 22
data 19
object 14
blocks 13
Headings
H1 H2 H3 H4 H5 H6
1 7 1 0 0 0
Images We found 1 images on this web page.

SEO Keywords (Single)

Keyword Occurrence Density
block 24 1.20 %
chain 23 1.15 %
transaction 22 1.10 %
data 19 0.95 %
object 14 0.70 %
blocks 13 0.65 %
transactions 11 0.55 %
message 10 0.50 %
connection 10 0.50 %
interface 9 0.45 %
store 9 0.45 %
MemoryPool 8 0.40 %
class 8 0.40 %
wallet 8 0.40 %
network 7 0.35 %
app 7 0.35 %
provided 7 0.35 %
full 6 0.30 %
reorganize 6 0.30 %
messages 6 0.30 %

SEO Keywords (Two Word)

Keyword Occurrence Density
of the 14 0.70 %
block chain 8 0.40 %
the block 7 0.35 %
is a 7 0.35 %
a block 7 0.35 %
the same 6 0.30 %
can be 6 0.30 %
the MemoryPool 6 0.30 %
for the 5 0.25 %
best chain 5 0.25 %
the chain 5 0.25 %
to a 5 0.25 %
when a 5 0.25 %
it is 5 0.25 %
from the 5 0.25 %
your app 5 0.25 %
transaction data 5 0.25 %
may be 5 0.25 %
the best 4 0.20 %
This is 4 0.20 %

SEO Keywords (Three Word)

Keyword Occurrence Density Possible Spam
an implementation of 4 0.20 % No
the block chain 4 0.20 % No
thread per connection 3 0.15 % No
the best chain 3 0.15 % No
interface provides methods 3 0.15 % No
provides methods for 3 0.15 % No
implementation of the 3 0.15 % No
from the network 3 0.15 % No
for each transaction 3 0.15 % No
a thread per 3 0.15 % No
a side chain 3 0.15 % No
it can be 3 0.15 % No
when a block 3 0.15 % No
on the best 3 0.15 % No
sent to us 3 0.15 % No
new best chain 2 0.10 % No
This interface provides 2 0.10 % No
object that implements 2 0.10 % No
the same sequence 2 0.10 % No
a block chain 2 0.10 % No

SEO Keywords (Four Word)

Keyword Occurrence Density Possible Spam
on the best chain 3 0.15 % No
a thread per connection 3 0.15 % No
an implementation of the 3 0.15 % No
interface provides methods for 3 0.15 % No
the block chain to 2 0.10 % No
an object that implements 2 0.10 % No
is interested in it 2 0.10 % No
when a block is 2 0.10 % No
a block is received 2 0.10 % No
block is received that 2 0.10 % No
a side chain and 2 0.10 % No
have the same sequence 2 0.10 % No
useful when you want 2 0.10 % No
the new best chain 2 0.10 % No
that extend a side 2 0.10 % No
blocks that extend a 2 0.10 % No
a block chain listener 2 0.10 % No
sent to us by 2 0.10 % No
is sent to us 2 0.10 % No
best chain triggers isTransactionRelevant 2 0.10 % No

Internal links in - bitcoinj.github.io

Watch or read a tutorial
Building a simple GUI wallet tutorial
Bitcoin standards
Which BIPs are supported by bitcoinj
use Maven
How to depend on bitcoinj with Maven using projects
use Gradle
How to depend on bitcoinj with Gradle using projects
Getting started
An introduction to using the library
0.14.7 API documentation
bitcoinj 0.14.7 API
Limitations and missing features
Limitations and missing features.
Understanding the bitcoinj security model
Understanding the bitcoinj security model
Working with bitcoinj
Working with bitcoinj
How the different components of your app fit together
How the different components of your app fit together
How to test your software
How to test applications
Working with transactions
Working with transactions
Working with the wallet
Working with the wallet
Working with monetary amounts
Working with monetary amounts
How to use the network API and info about Tor support
How to handle networking/peer APIs
API contexts
API Contexts
How to use the experimental fully verifying mode
Using the experimental full verification mode
Working with contracts
Working with contracts
Working with the BIP70 payment protocol
Working with the BIP70 payment protocol API
Working with micropayment channels
Working with micropayment channels
Using bitcoinj from other languages like C++, JavaScript, Ruby, Python, etc
How to access bitcoinj from other languages
Coding conventions in the library itself
Coding conventions in bitcoinj
release notes
Release notes

Bitcoinj.github.io Spined HTML


How the variegated components of your app fit together Introduction Getting started Documentation Community How the variegated components of your app fit together Introduction The network De/serialization Peer logic The memory pool Chains and stores Data pruning The wallet How the variegated components of your app fit together Introduction This vendible shows you how the variegated objects and interfaces in a typical bitcoinj based using interact. We will see how data arrives from the network, is converted into Java objects, and then how those objects travel virtually until they are sooner used to perform various deportment or saved to disk. For the purposes of this vendible we will seem the using is a wallet. The network The life of a piece of Bitcoin data starts in two ways - when it is sent to us by flipside node in the peer-to-peer network, or when a transaction is created by ourselves. The lowest level of the Networking API is an object that implements ClientConnectionManager. This interface provides methods for opening new connections, and requesting that some (randomly chosen) connections be closed. To unshut a new connection, an object that implements the StreamParser interface must be provided withal with the network write to connect to. The vendee connection manager will then set up a socket and manage reads/writes to it. There are no guarantees well-nigh threading here - the manager may run methods of the provided StreamParser on any number of threads or just one. There are two implementations provided: BlockingClientManager and NioClientManager. If you create a upper level PeerGroup object then by default a NioClientManager will be created, though you can moreover provide your own via the constructors. The difference between them is that NioClientManager uses a single thread and async epoll/select based IO, and BlockingClientManager uses a thread per connection with standard Java blocking sockets. Why does bitcoinj support both approaches? Blocking IO is useful when you want features. Java can transparently support SSL, SOCKS proxying and via the Orchid library, Tor, but only when blocking sockets are used. Async IO is useful when you want to handle thousands of connections simultaneously without the spare memory pressure of a thread per connection. Note that for many types of apps, notably wallets or merchant apps, you don’t need lots of simultaneous connections and thus the performance difference between the two is largely irrelevant. Also, whilst the scalability difference between thread-per-connection and async IO was once very large in recent times the outstart of much largest kernel schedulers and multi-core systems ways the differences are often no longer so well-spoken cut. With shielding sustentation paid to thread stack sizes it can be the specimen that a thread per connection is not as expensive as it once was. In theory, NioClientManager could hands support both async IO and multiple threads together, however the current implementation does not. De/serialization As noted above, the vendee manager classes require an implementation of the StreamParser interface. This interface provides methods for notification that a connection is opened or closed, receiving raw byte buffers and stuff given an implementation of the MessageWriteTarget interface. StreamParsers are given data packets read from the network without any kind of framing or parsing done. For instance it’s valid for half a message to show up on a StreamParser’s front door. The parser buffers data, handles framing and consumes the data in some way. When a vendee manager is given a new parser, it sets an internal object as the MessageWriteTarget. This interface just exposes a method for writing bytes, and latter the connection. Thus the parser object usually manages the lifecycle of a connection once started. The utopian PeerSocketHandler matriculation implements StreamParser for the Bitcoin P2P networking protocol, by providing buffering, checksumming and parsing of the byte streams into Message objects. This is washed-up using the BitcoinSerializer class, which knows how to read the type of the message and its checksum from the wire, then build the towardly object to represent that kind of message. It has a static map of names to object types. Each object it can construct is a descendent of the Message class. Each message matriculation is responsible for its own deserialization from raw byte form. Once a Message is fully synthetic and finished deserializing itself, it’s passed to an utopian method on PeerSocketHandler. Thus if you want to just get wangle to a stream of parsed messages, you should subclass at this point. The serialization of messages is a custom binary format designed by Satoshi. It has minimal overhead and consequently minimal flexibility. Peer logic However, most likely your app does not want to handle a stream of raw Bitcoin protocol messages, but rather operate at a higher level. For this purpose, the Peer matriculation subclasses PeerSocketHandler, tracks state related to the connection and processes incoming messages. It provides upper level operations like downloading blocks, the unshortened chain, transactions, performing pings and so on. It moreover dispatches messages to various other objects to which it is connected, specifically: Any PeerEventListeners that are registered with it. A MemoryPool, if one is provided (see below). Any Wallets that are unfluctuating to it. The provided woodcut uniting object, if any. On receiving a message, each PeerEventListener has a endangerment to read and intercept the message, possibly modifying it, replacing it with a variegated message or suppressing remoter processing entirely. If processing is not suppressed, the pursuit will happen: A received “inv” message that advertises new blocks or transactions will result in a “getdata” stuff sent, if the Peer has been instructed to download data. The MemoryPool will be notified well-nigh the “inv”. A received “tx” message that contains transaction data is first passed through the MemoryPool. Then each Wallet is asked via isPendingTransactionRelevant whether it cares well-nigh that particular transaction, and if it does all the transactions pending dependencies are moreover downloaded recursively. Once recursive download is done, the transaction and all pending dependencies are passed to Wallet.receivePending(). Finally PeerEventListener.onTransaction is invoked. Received blocks, filtered blocks or woodcut headers are sent to the AbstractBlockChain object for remoter processing. If a remote peer asks for our transaction data using “getdata”, wallets and listeners are polled to see if any can provide that data, and if one does it is sent in response. Misc messages like pings or alerts are handled as appropriate. The memory pool It can be user-friendly to know how many peers (and which ones) have spoken a particular transaction. See the vendible on the bitcoinj SecurityModel for information on why this may be interesting. To implement this, the MemoryPool matriculation keeps track of transactions and transaction hashes that have been seen. For example, if a peer sends us an “inv” stating it has the transaction with hash 87c79f8d77fe2078333c612e2bdf1735127c6c02 then the Peer will inform the MemoryPool of that, and it will record that this peer has seen that transaction. We may sooner download the given transaction to find out if it belongs to us, and at that point it’s moreover given to the MemoryPool which keeps it virtually in specimen some part of the app is interested in it. As remoter invs come in, the transactions conviction object is updated. It may be that the same “tx” message is sent to us multiple times. Normally this shouldn’t happen. But if it does the MemoryPool deduplicates them to ensure only one Java object is floating around, plane if it was deserialized multiple times. Chains and stores A subclass of AbstractBlockChain is responsible for receiving blocks, fitting them together, and doing validation on them. The BlockChain matriculation does SPV level validation, the FullPrunedBlockChain does full validation as the name implies. You pass the woodcut uniting to a Peer or PeerGroup and the woodcut data flows via that connection from the network, through the woodcut uniting object and towards an implementation of the BlockStore interface. There are multiple kinds of woodcut store, but all of them take woodcut data and save at least the headers, and possibly (for a full store) the transaction data as well. For SPV clients a SPVBlockStore is the usual nomination and for full mode clients an implementation of FullPrunedBlockStore is needed, for example, H2FullPrunedBlockStore. The stores talk directly to a database or disk file. There are no other objects underneath them. Chains invoke callbacks on their BlockChainListeners. A Wallet is an example of a woodcut uniting listener, although it’s recommended to use the increasingly specific BlockChain.addWallet() method (it does the same thing as addListener() but this may transpiration in future). Listeners are invoked for the pursuit events: notifyNewBestBlock: tabbed when a new woodcut is found that extends the weightier known chain. This is a normal continuation of the system. The woodcut parameter is a woodcut header only - no transaction data is available. reorganize: tabbed when a woodcut is received that extends a side uniting and makes it the new weightier chain. A reorganize results in one timeline stuff replaced by a variegated one in which transactions may have been re-ordered, replaced or dropped entirely. For this reason, on hearing well-nigh a reorg, a listener must update its internal book-keeping to worth for the new reality. The reorganize method is given the woodcut uniting segments that have reverted so they can icon out what to do. It may be tempting to skip this if you are implementing your own listeners, and your app will towards to work, but ignoring reorgs opens your app to security attacks and data corruption. isTransactionRelevant: tabbed for each transaction in a woodcut to find out if a listener is interested in it. This is an optimization step that may be removed in future - it allows the woodcut uniting to stave validating the merkle tree in SPV mode when it has full (unfiltered) blocks, unless there’s an very transaction in the woodcut that may be relevant to our wallet (sending money to/from our keys). This makes a big difference on mobile phones but with the rollout of Bloom filtering, it will wilt less and less useful. receiveFromBlock: tabbed for each transaction considered relevant by the previous method when a woodcut is received that contains it. The woodcut may or may not be on the weightier chain, a parameter tells you which one it is. Note that when Bloom filtering is active, not every transaction may show up here - if transactions were previously sent to us by peers then they won’t scarecrow sending it then when a woodcut containing it is solved, we’ll only be sent the hash. This is to save bandwidth. Therefore there is moreover a … notifyTransactionIsInBlock: this is the same as receiveFromBlock but you are provided with a hash instead of the full transaction. A listener is expected to once have a reprinting of the transaction data at this point. In order, a new full woodcut on the weightier uniting triggers isTransactionRelevant for each transaction, receiveFromBlock, then notifyNewBestBlock. A new filtered woodcut on the weightier uniting triggers isTransactionRelevant, a mix of receiveFromBlock or notifyTransactionIsInBlock, then notifyNewBestBlock. New blocks that proffer a side uniting have the same sequence but not notifyNewBestBlock and new blocks that proffer a side uniting and rationalization a reorganize have the same sequence but undeniability reorganize instead of notifyNewBestBlock at the end. For an SPV mode app, the woodcut store is given all non-orphan blocks regardless of where they connect, and is informed when the new weightier uniting throne changes so it can be written to disk. It is only expected to store headers. Data pruning For a fully validating node, the store is expected to do a lot increasingly and must implement the FullPrunedBlockStore interface. Together the uniting and store implement the ultraprune algorithm, the same as Bitcoin 0.8+ does. However unlike Bitcoin 0.8 the store will unquestionably permanently delete unneeded data without a while, so it cannot serve the uniting to other nodes, but the utilized disk space is a lot lower. A pruning node does not struggle to store the unshortened woodcut chain. Instead it stores only the set of unspent transaction outputs (UTXO set). Once a transaction output is spent, its data is no longer needed and it can be deleted. Reorganize events complicate the picture somewhat considering they can rewrite history, therefore pruning stores are expected to moreover alimony virtually a number of “undo blocks” which indulge a reversal of the changes to the UTXO set. The number of undo blocks stored is a tradeoff between disk space used and the largest reorganize that can be processed. If undo blocks are thrown yonder too aggressively, a large reorg might permanently kick the node off the uniting forcing re-initialization from scratch, so it’s weightier to be conservative. The FullPrunedBlockStore interface provides methods for adding, removing and testing the UTXO set. It moreover has methods for inserting blocks and undo blocks and beginning/ending database transactions (note: as unshared from Bitcoin transactions). The wallet The Wallet matriculation acts as a woodcut uniting listener and receives data and events from the uniting object. It saves the data it receives within itself and keeps track of all transactions that might be interesting for the wallet user, such as ones that send money to its keys. The wallet can be saved to a protocol buffer using WalletProtobufSerializer, and functionality is provided to automatically do so from time to time when the wallet has changed. Currently, the Wallet doesn’t have any way to store itself to a database. It would be a nice wing for the future. The Wallet moreover takes responsibility for updating the conviction levels of transactions placed within it. A transaction outside of the wallet might be updated by the MemoryPool as new peers signify it, but ultimately will not learn well-nigh its position in the chain.