This refactors the consensus code which extracts the null data from the coinbase from txscript.ExtractCoinbaseNullData so that it is performed directly in the validation code where it more properly belongs. The only reason the extraction was previously done in txscript is because it was not possible to parse scripts outside of it, but that is no longer the case now that txscript offers an exported tokenizer for that purpose. The extraction code is ever so slightly more efficient now that it no longer needs to be as generic since it now has direct knowledge of the conditions that need to be handled. Great care was taken to ensure the semantics are not changed while refactoring the code and no additional tests are added in this commit because all of the conditions and code paths are covered by the tests recently added to the full block tests. While here, also perform some related code cleanup in the function and improve the error messages . Since the txscript.ExtractCoinbaseNullData is no longer necessary, this deprecates the function and releated error code and constant so they can be removed in the next major version of txscript. Finally, since this relies on the script tokenizer which is not yet in a released version of the txscript module, bump the requirement to include an as yet unreleased version of txscript to ensure the next time the blockchain module is released, it will require a newer version of txscript to be released first. |
||
|---|---|---|
| .. | ||
| data | ||
| bench_test.go | ||
| consensus_test.go | ||
| consensus.go | ||
| doc.go | ||
| engine_test.go | ||
| engine.go | ||
| error_test.go | ||
| error.go | ||
| example_test.go | ||
| go.mod | ||
| go.sum | ||
| 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 | ||
| sighash_test.go | ||
| sighash.go | ||
| sign_test.go | ||
| sign.go | ||
| stack_test.go | ||
| stack.go | ||
| standard_test.go | ||
| standard.go | ||
| tokenizer_test.go | ||
| tokenizer.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.
-
Counting Opcodes in Scripts Demonstrates creating a script tokenizer instance and using it to count the number of opcodes a script contains.
License
Package txscript is licensed under the copyfree ISC License.