Decred's serialized format for transactions split the 32-bit version field into two 16-bit components such that the upper bits are used to encode a serialization type and the lower 16 bits are the actual transaction version. Unfortunately, when this was done, the in-memory transaction struct was not also updated to hide this complexity, which means that callers currently have to understand and take special care when dealing with the version field of the transaction. Since the main purpose of the wire package is precisely to hide these details, this remedies the situation by introducing a new field on the in-memory transaction struct named SerType which houses the serialization type and changes the Version field back to having the desired semantics of actually being the real transaction version. Also, since the maximum version can only be a 16-bit value, the Version field has been changed to a uint16 to properly reflect this. The serialization and deserialization functions now deal with properly converting to and from these fields to the actual serialized format as intended. Finally, these changes also include a fairly significant amount of related code cleanup and optimization along with some bug fixes in order to allow the transaction version to be bumped as intended. The following is an overview of all changes: - Introduce new SerType field to MsgTx to specify the serialization type - Change MsgTx.Version to a uint16 to properly reflect its maximum allowed value - Change the semantics of MsgTx.Version to be the actual transaction version as intended - Update all callers that had special code to deal with the previous Version field semantics to use the new semantics - Switch all of the code that deals with encoding and decoding the serialized version field to use more efficient masks and shifts instead of binary writes into buffers which cause allocations - Correct several issues that would prevent producing expected serializations for transactions with actual transaction versions that are not 1 - Simplify the various serialize functions to use a single func which accepts the serialization type to reduce code duplication - Make serialization type switch usage more consistent with the rest of the code base - Update the utxoview and related code to use uint16s for the transaction version as well since it should not care about the serialization type due to using its own - Make code more consistent in how it uses bytes.Buffer - Clean up several of the comments regarding hashes and add some new comments to better describe the serialization types |
||
|---|---|---|
| .. | ||
| data | ||
| consensus.go | ||
| doc.go | ||
| engine_test.go | ||
| engine.go | ||
| error.go | ||
| example_test.go | ||
| internal_test.go | ||
| log.go | ||
| opcode_test.go | ||
| opcode.go | ||
| README.md | ||
| reference_test.go | ||
| script_test.go | ||
| script.go | ||
| scriptbuilder_test.go | ||
| scriptbuilder.go | ||
| scriptnum_test.go | ||
| scriptnum.go | ||
| sigcache_test.go | ||
| sigcache.go | ||
| sign_test.go | ||
| sign.go | ||
| stack_test.go | ||
| stack.go | ||
| standard_test.go | ||
| standard.go | ||
txscript
Package txscript implements the decred transaction script language. There is a comprehensive test suite.
This package has intentionally been designed so it can be used as a standalone package for any projects needing to use or validate decred transaction scripts.
Decred Scripts
Decred provides a stack-based, FORTH-like language for the scripts in the decred transactions. This language is not turing complete although it is still fairly powerful.
Installation and Updating
$ go get -u github.com/decred/dcrd/txscript
Examples
-
Standard Pay-to-pubkey-hash Script
Demonstrates creating a script which pays to a decred address. It also prints the created script hex and uses the DisasmString function to display the disassembled script. -
Extracting Details from Standard Scripts
Demonstrates extracting information from a standard public key script. -
Manually Signing a Transaction Output
Demonstrates manually creating and signing a redeem transaction.
License
Package txscript is licensed under the copyfree ISC License.