In the last article implementing a simple blockchain in Java, we mainly talked about what a blockchain is (hint: blockchain is love) and how it is decentralized and immutable. And then by parsing an article about Java block chain abroad, using Java implements a simple block chain, of course, we finally make that thing that is really a bit too humble, reason is the lack of a very important process – trading, to describe how to use the code to achieve the specific business logic before, The first thing we need to know about the chain block is how the transaction, the specific transaction logic? And so on these problems, this article, we mainly from UTXO trading model, the light to go learn about exactly how UTXO trading system work, compared with the traditional balance model and the advantage of some kind?
Cut the crap and just get on with it
What is the UTXO transaction model?
Unspent Transaction Outputs UTXO (Unspent Transaction Outputs), proposed by Satoshi Nakamoto. It is a core concept of bitcoin transaction generation and verification. Transactions form a chain structure in which all legitimate Bitcoin transactions can be traced back to the output of one or more transactions, starting with mining rewards and ending with the output of transactions that are currently unspent.
Every transaction has a number of inputs, which are sources of money, and every transaction has a number of outputs, which are destinations of money. Generally speaking, each transaction costs an input and generates an output. The output generated is the “unspent transaction output”, that is, UTXO.
????? I don’t get it. Move the next one.
Indeed, this concept is a little bit complicated, I put aside the along while also didn’t want to imagine what wonderful metaphor (jo-jo infarction), if an article we compare block chain to be fall in love, get married so UTXO is to send the bride, the front is about how we dig mines, UTXO is speaking we dig into how the money will be spent.
In the story of the last article, we said that due to the immutable nature of blockchain, Green will surely find out that Ming is a cheating man who cheated on her. Considering that this article is about the UTXO transaction model, green has to choose to forgive Ming and accept Ming’s proposal. To help you understand what’s going on, I’m going to start with our next revolutionary product.
Xiao Ming: ah, small green his mother unexpectedly to me to five individual forced currency of the bride gift (not scold), I from which lane so much don’t force currency, also tell me what if love our home small green don’t force force, hand in currency, hand in green, this is not clearly robbing yao is not.
When the day was getting late, the depressed Xiaoming remembered the mining machine in his home that accompanied him to grow up, although it did not dig a mine, every time the electricity meter was turned back, but Xiaoming still loved it, who let it connect to the neighbor’s wires. Xiao Ming sat in front of the mining machine in the evening, and pressed the boot button that had been attached to countless dust by the years. With the rumbling of the machine, a line of small characters was slowly displayed on the screen:
Good luck, chicken you too beautiful, dig qualified hash, a dollar four, cheap sale, hey hey, Ollie to, who tm buy millet son
As we mentioned in the last article, the essence of ** mining is the process of producing a hash that meets the criteria. ** But the question is, how does the hash string I calculated relate to bitcoin? They both obviously is not a thing, the key is on UTXO trading model, the mine is buy a mill, and pay the electricity bills, flower is the size of the force well is not easy to dig out a new block, if can’t converted into the currency that is not the kui dead, mining, after all, is not mine that why whenever the miners to calculate a qualified block, The miner was given the privilege of being allowed to create an initial transaction (” coinbase “) in which the recipient could write his or her address openly and place a new sum of money.
On the current account balance trading system inside and it means if you calculate a new block, then you’ve got a privilege, allows you to directly in your bank account balance on the basis of legally plus specified amount, of course, is not infinite, or to add words who will dig up a life what mine, COINS, We now get 12.5 bitcoins for each new block unlocked, and the hash we calculated has actually morphed into our bitcoins.
Might be due to the power of love, xiao Ming has successfully dug to a block, and got to create a force of 10 individual currency initial deal privileges, so xiao Ming on the deal payment fill in his wallet address bar, it’s not all, of course, due to the chain of blocks is decentralized, need more people recognized to ensure that the deal is legitimate, not to tamper with, So Xiao Ming needs to show off this matter to six nodes.
Xiaoming: see, just dig of, hot don’t force coin, 10, I all give dozen my purse inside, don’t believe, this is bill, envy, envy dead you.
Node: Got it, roll.
After the confirmation of six nodes, the 10 bi coins were officially and legally assigned to Xiao Ming’s name.
Xiaoming: the money had, the rest is to go to the small green home to pay the bride price to marry the small green back, the rest of the 5 individual forced currency can also take the small green king valley to spend a honeymoon of what.
But don’t push currency and the dollar is different the notes, can’t say I give you ten fast, you find me 5 fast so simple, digital currency is safe, because in addition to the initial coinbase trading, all other sources of funding must be from the front of a transaction or a few UTXO, just like the list, one by one, This ensures that any transaction on the blockchain is traceable, and that if any transaction is tampered with, the list cannot be connected properly, so it is easy to verify that the transaction is legitimate. In blockchain, everyone can create orders for transactions, and digital currency as a currency has liquidity.
Now a lot of people are going to ask, who do you point to before the first transaction?
Good question (who asked?) In Bitcoin, the first transaction is preceded by a transaction of 0.
The second is that the input (source of funds) of any transaction must equal the output (destination of funds) of any transaction.
For Xiao Ming, he had 10 individual bi coins, but when he handed in the bride price, he could not only spend 5 individual bi coins at a time, but all the 10 individual bi coins were spent, but 5 of them were paid to the little green his mother, and 5 of them were paid to himself.
In the blockchain, Xiaoming’s order to pay bride price is roughly as shown in the figure below:
This order produced two outputs, namely two UTXOs, one for Little Green Motherfucker and one for Ming himself.
And we will find that there is no balance in the whole process of the concept, there is only the input and output of every transaction, some people may be confused at this time, you this is wrong, then I know the currency wallet clearly show me and then there were five COINS, this balance is not similar to the banking system shows that your account balance, Instead, the Bitcoin wallet scans all the transactions across the blockchain and calculates them by aggregating all the payees of your transactions.
When your purse at the time of scanning the entire block chain trade order, found that, alas, there is a New Deal for the address to fill in the address, and then added into your balance, when all the point to your trading order summary calculation, the value is what you have the correct balance in the currency is the number of COINS you have in the system.
Why must be the latest that a deal, such as xiao Ming’s output, in front of the mining of the order of a force 10 individual currency output and then pay the bride price and produce a force a sum of five individual currency output order, if direct additive polymerization, then get the balance of xiaoming is 15 individual force COINS, obviously it is wrong, Because a new business is built on the orders before, so when the birth of a New Deal before the order will be considered when statistics are out of date, and xiao Ming right balance calculation result of the output of the polymerization on the latest order, in this case, that is xiao Ming pay bride price to generate the order, That is, Xiao Ming has 5 yuan.
Highlight it. My friends are taking it.
Whether bitcoin or litecoin, at the end of the day, there is no such thing as a digital currency. Everything is just UTXO.
What is the advantage of UTXO versus account balance?
-
First: Since the UTOX transaction model traces each transaction back to the previous one until it is traced back to the block where it was created, where the list finds its head, this mechanism ensures that the blockchain is unforgerable, meaning that a transaction cannot be paid twice.
-
Second: Compared with the traditional account balance model, UTXO only records the final state, because it only needs to count the latest order when calculating the balance, and the database volume is much smaller than the traditional account balance model.
However, this does not mean that the traditional account balance has no advantage over UTXO. Firstly, the implementation of UTXO itself is logically much more complicated than the account balance. Secondly, the account balance can be easily seen as a whole, such as how the balance of the city owner has changed in recent years, which has a better space to play. And compared to bitcoin, which has 0.00000001 bitcoins at every turn, traditional account balances can easily control the accuracy of transactions.
Let’s start with the technical summary:
Party finally finished write this article, compared to the previous article, this article may be biased towards the concept of UTXO trading model for programming engineers often is not particularly difficult to understand, but for just contact programming or block chain technology who does have some abstract, in the process of writing this article is also under a lot of kung fu, It is intended that people at all stages can understand this article and know what the UTXO trading model is. I wanted to make an analogy with my life, but it turns out that UTXO seems to be naturally designed for blockchain digital currency. I can’t think of any particularly appropriate analogy, so I can only continue to write the context of the last article. After understanding the operation mechanism of UTXO, we will continue to start with the second of the two foreign blogs in the next article, and see how UTXO is implemented in the actual development from the perspective of a coder to realize a tradable blockchain system.
Relevant code has been uploaded to my Github. Make sure you hit “STAR” ahhhhhhh
Long march always feeling, to a star line
Hanshu development notes
Welcome to like, follow me, have good fruit to eat (funny)