dcrd/txscript
Dave Collins fce24223cd
multi: Separate tx serialization type from version.
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
2017-08-07 14:10:27 -05:00
..
data txscript: Use native encoding in json test data. 2017-08-03 23:43:37 -05:00
consensus.go blockchain: Rework to use new db interface. 2016-08-18 15:42:18 -04:00
doc.go blockchain: Rework to use new db interface. 2016-08-18 15:42:18 -04:00
engine_test.go multi: Separate tx serialization type from version. 2017-08-07 14:10:27 -05:00
engine.go travis: enable gometalinter (#603) 2017-03-08 15:44:15 -05:00
error.go blockchain: Rework to use new db interface. 2016-08-18 15:42:18 -04:00
example_test.go multi: Update DecodeAddress function signature 2017-07-21 23:41:24 -05:00
internal_test.go blockchain: Rework to use new db interface. 2016-08-18 15:42:18 -04:00
log.go all: Remove seelog logger. 2017-06-20 10:58:10 -04:00
opcode_test.go Integrate a valid ECDSA signature cache 2016-05-18 13:37:06 -05:00
opcode.go remove deadcode 2017-07-17 15:06:47 -05:00
README.md multi: Update markdown in README files to match change in github parser. 2017-05-26 12:06:19 -04:00
reference_test.go txscript: Cleanup reference test code. 2017-08-04 03:05:42 -05:00
script_test.go multi: Separate tx serialization type from version. 2017-08-07 14:10:27 -05:00
script.go Preallocate the exact number of bytes if known. 2017-03-20 21:46:33 -05:00
scriptbuilder_test.go txscript: Expose AddOps on ScriptBuilder. 2016-11-18 12:58:00 -06:00
scriptbuilder.go travis: enable gometalinter (#603) 2017-03-08 15:44:15 -05:00
scriptnum_test.go txscript: Sync upstream makeScriptNum tests. 2016-05-17 16:34:03 -05:00
scriptnum.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
sigcache_test.go multi: Upstream chainhash abstraction sync 2016-11-16 12:48:40 -06:00
sigcache.go Merge in btcd '7f07fb1093dd80105d36d61c8fb8a16f6e9d9b29' 2016-09-23 14:40:27 -04:00
sign_test.go multi: Separate tx serialization type from version. 2017-08-07 14:10:27 -05:00
sign.go txscript: Expose AddOps on ScriptBuilder. 2016-11-18 12:58:00 -06:00
stack_test.go travis: enable gometalinter (#603) 2017-03-08 15:44:15 -05:00
stack.go blockchain: Rework to use new db interface. 2016-08-18 15:42:18 -04:00
standard_test.go txscript: Force extracted addrs to compressed. 2017-08-02 00:34:35 +00:00
standard.go txscript: Force extracted addrs to compressed. 2017-08-02 00:34:35 +00:00

txscript

Build Status ISC License GoDoc

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

License

Package txscript is licensed under the copyfree ISC License.