Bitcoin: Pycoin/Python consumes part of Utxo
It is likely that as a Bitcoin enthusiast and creator, you know that it is important to deal with events in your program. One important thing to consider is the update of the UTXO (confrontation) database, when coins are used to scan bitcoins received at the Pycoin Library.
In this article, our doll is into the consumer component information that updates the UTX database after use.
What is UTXO?
UTXO means Bitcoin event withdrawal. It consists of unused feed addresses and similar scenarios. It is not used in the UTX database when obtaining a coin. On the contrary, when using a coin, the respective result is updated when used.
Pycoin and scan got coins
Pycoin is a Python wrapper in Bitcoin’s subscription to communicate with Bitcoin network. You use Pycoin portfolio for Bitcoins and update the UTXO database accordingly.
By scanning the resulting coins, Pycoin creates a list of unused events (UTXO) related to each coin. If you want to include this information in your application, you need to update the UTXO database by checking the appropriate output.
part
Create a part of your application use to update the UTX database after you consume coins:
`Python
Pycoin imports
Class Bitcoinspender:
Def __init __ (yourself, Blockchain):
Self.blockchain = blockchain
Def scan_receved_coins (yourself, tx_hash):
Scan the resulting bitcoins using Pycoin help
Departure = self.blockchain.get_outputts (tx_hash)
Ite through each printing and update the UTXO database
For results:
Get UTXO (UTXO) tied to this departure
Utxo = output.get_txout ()
Sold UTXO (replace it with a new, empty scenario)
Self.update_utxo (tx_hash, utxo, nothing)
Def upday_utxo (yourself, tx_hash, utxo, new_script_hash):
Update the Utxo database by checking the output part of the output
Utxo [‘script’] = new_script_hash
Save the updated UTX disk (you have to install a permanent storage solution)
Open (Utxo.json, W) with F:
Bring json
Json.dump (utxo, f)
Example Usage:
Blockchain = pycoin.blockchain ()
Speender = Bitcoinspender (blockchain)
Scan the resulting bitcoins and mark them used
TX_HASH = “0C9B6E7F63F8A4D5ACHFB1B1B9F76B3BA51E78DD”
Change in real event
Speender.scan_receved_coins (tx_hash)
`
In this example, we have created a class Bitcoinspender, which takes care of scanning using the Bitcoins obtained with Pycoin and updates the UTX database accordingly. When the result is used as used (ie its “script” field is replaced by a new scenario), it is recorded in a JSON file called Utxo.json.
Note: This implementation assumes that you have a permanent storage solution, such as a database or file system. You must customize this code to match the specific case of use.
By performing these steps, the UTXO database should be able to update after Pycoin and Bitcoinspender Consumer Coins.
دیدگاهتان را بنویسید