Commit Graph

52 Commits

Author SHA1 Message Date
Dave Collins
8354a310bc
main: Consume latest module minors and patches.
This updates the main module to use the latest available minor and patch
versions of all modules and reverts the recent change that incorrectly
removed all of the blake256 references from the various go.sum files.

The following required direct dependencies are bumped as follows:

- github.com/decred/dcrd/blockchain/stake@v1.2.1
- github.com/decred/dcrd/blockchain/stake/v2@v2.0.1
- github.com/decred/dcrd/certgen@v1.1.0
- github.com/decred/dcrd/chaincfg@v1.5.2
- github.com/decred/dcrd/chaincfg/chainhash@v1.0.2
- github.com/decred/dcrd/chaincfg/v2@v2.2.0
- github.com/decred/dcrd/dcrutil/v2@v2.0.0
- github.com/decred/dcrd/gcs@v1.1.0
- github.com/decred/dcrd/hdkeychain/v2@v2.0.1
- github.com/decred/dcrd/txscript/v2@v2.0.0
- github.com/decred/dcrwallet/rpc/jsonrpc/types@v1.2.0
2019-08-08 10:05:35 -05:00
Nicola Larosa
1149d54cb9 multi: Use crypto/blake256.
This updates the code to make use of the new crypto/blake256 module instead of
github.com/dchest/blake256.

* change the references in the chaincfg/chainhash and gcs modules
* update chaincfg/chainhash to use the new Sum256 API
* remove references to dchest/blake256 from all go.sum files
2019-08-07 18:54:55 -05:00
Dave Collins
ed43e59df5
release: Introduce dcrutil v2 module. 2019-06-19 12:09:19 -05:00
Dave Collins
9b753598df
dcrutil: Update to use chaincfg/v2 module. 2019-06-19 12:09:18 -05:00
Dave Collins
e1840ea6cc
dcrutil: Use mock addr params in tests.
This implements a mock address params struct that implements the new
interface and modifies the test code to make use of the mock params
instead of chaincfg.  This completely decouples the tests, with the
exception of the example code, from chaincfg and therefore any updates
to it such as introducing new test networks will not require changes to
the tests.
2019-06-19 12:09:18 -05:00
Dave Collins
2779e67a20
dcrutil: Introduce AddressParams interface.
This introduces a new interface named AddressParams and updates the
functions that currently take a pointer to a chaincfg.Params struct to
accept the interface instead.

This removes the tight coupling between the two packages at the API
boundary and allows callers to easily provide custom values without
having to create and register and entire chaincfg network as previously
required.

It also updates the tests to make use of the interface.
2019-06-19 12:09:17 -05:00
Dave Collins
423c3344d6
dcrutil: Accept magic bytes directly in NewWIF.
This modifies NewWIF to accept the required network magic bytes directly
versus a chaincfg.Params struct in order to remove the tight coupling
between the two packages at the API boundary and allows callers to
easily provide custom values without having to create and register and
entire chaincfg network as previously required.

It also removes the now unused error return and updates the tests
accordingly.
2019-06-19 12:09:16 -05:00
Dave Collins
5ca5f814cd
dcrutil: Require network on WIF decode.
This modifies DecodeWIF to accept the required network parameters for
the provided encoded WIF string and introduces a new error to indicate
the provided WIF string is for the wrong network.

This means that DecodeWIF will now return ErrWrongWIFNetwork if the WIF
string being decoded is not for the provided network.  This differs from
the previous behavior that would accept arbirtary network bytes and
relied on globally-registered networks in chaincfg to determine which
network the string was for followed by requiring the caller to check if
the WIF was for the specific network it desired upon return.

Finally, it removes the no longer necessary IsForNet method and updates
the documentation accordingly.
2019-06-19 12:09:16 -05:00
Dave Collins
736e0317b8
dcrutil: Don't store net ref in addr impls.
This modifies the concrete address implementations to only store the
necessary individual parameters instead of the entire params struct to
further decouple from chaincfg.
2019-06-19 12:09:15 -05:00
Dave Collins
07786d83e1
dcrutil: Rename EncodeAddress to Address.
This renames the EncodeAddress method on the Address interface to
Address and updates all of the concrete implementations and tests
accordingly.
2019-06-19 12:09:14 -05:00
Dave Collins
37531d2b35
dcrutil: Remove Net from Address interface.
This removes the no longer necessary Net method from the Address
interface and all concrete address implementations.
2019-06-19 12:09:14 -05:00
Dave Collins
54cd596803
dcrutil: Remove DSA from Address interface.
This removes the DSA method from the Address interface in favor of only
defining it on the specific concrete address implementations to which it
applies.  It also modifies the remaining instances to remove the network
parameters since they are already available on the type.

Finnaly, it updates the example code accordingly.
2019-06-19 12:09:13 -05:00
Dave Collins
b13eb4511f
dcrutil: Remove IsForNet from Address interface.
This removes the no longer necessary IsForNet method from the Address
interface and all concrete address implementations.

It also updates the tests accordingly.
2019-06-19 12:09:12 -05:00
Dave Collins
0ba5ac74e5
dcrutil: Require network on address decode.
This modifies DecodeAddress to accept the required network parameters
for the provided encoded address and return an error when the provided
address is for the wrong network.

This means that DecodeAddress will now return ErrUnknownAddressType if
the address being decoded is not for the provided network.  This differs
from the previous behavior relied on globally-registered networks in
chaincfg to determine which network the encoded address was for followed
by requiring the caller to check if the address was for the specific
network it desired upon return.

It also updates the tests and example accordingly.
2019-06-19 12:09:12 -05:00
Dave Collins
ff1268a1ef
dcurtil: Remove unused ErrMissingDefaultNet. 2019-06-19 12:09:11 -05:00
Dave Collins
be589d216c
dcrutil: Remove unused ErrAddressCollision. 2019-06-19 12:09:10 -05:00
Dave Collins
2142c4037c
dcrutil: Make docs example testable and correct it.
This adds a tested example for address decoding and removes the previous
non-functioning version of it from the pacakge documentation.  The
previous example appers to have been missed when porting the code and
was no longer correct for Decred.
2019-06-19 12:09:10 -05:00
David Hill
893aa30dce multi: Use https links where available. 2019-06-18 14:20:06 -05:00
Dave Collins
8deeee97c4
dcrutil: Prepare v1.3.0.
This updates the dcrutil dependencies and serves as a base for
dcrutil/v1.3.0.

The updated direct dependencies are as follows:

- github.com/decred/dcrd/chaincfg@v1.5.1
- github.com/decred/dcrd/dcrec@v1.0.0
- github.com/decred/dcrd/dcrec/edwards@v1.0.0
- golang.org/x/crypto@v0.0.0-20190611184440-5c40567a22f8
2019-06-13 14:08:53 -05:00
Hamid
c6f9186083 dcrutil: Fix NewTxDeepTxIns implementation.
This fixes NewTxDeepTxIns implementation. The current implementation
of NewTxDeepTxIns is wrong and has many issues. This commit fixes
this issues and adds tests for ensuring the API works correctly.
2019-03-26 15:36:14 -05:00
Hamid
edba35c971 dcrutil: Add tests for NewTxDeep.
This adds tests for NewTxDeep to make sure new MsgTx is deeply copied.
2019-03-21 15:48:40 -05:00
Dave Collins
0f50fd5f8c
multi: Add go 1.11 directive to all modules.
This adds the go 1.11 directive to all of the modules in order to
clearly mark they build and work with that version.  Go 1.12 modified
the tools such that tidy will automatically add the new version to
modules that do not already have a directive and that would prevent
builds on Go 1.11 through Go 1.11.3 which is not desirable.
2019-03-18 02:02:35 -05:00
Dave Collins
bd9629caeb
dcrutil: Consolidate tests into package.
Putting the test code in the same package makes it easier for forks
since they don't have to change the import paths as much and it also
gets rid of the need for internal_test.go to bridge.
2019-03-16 20:41:23 -05:00
Dave Collins
3f87a3e8cb
dcrutil: Reduce global refs in addr unit tests.
This modifies the test code for the address unit tests to prefer using
local references over accessing the global parameters directly from the
chaincfg package.  It is a good idea to avoid global references as much
as possible in general for several reasons, but the primary goal of this
change is to help reduce the tight coupling and therefore simplify
refactors.
2019-03-16 20:26:31 -05:00
Dave Collins
cc484f03d5
dcrutil: Lookup params by addr prefix in chaincfg.
This modifies the code that looks up the params by a given network
prefix to make use of the new function provided by chaincfg in order to
ensure that it works with all registered networks as the package was
intended.
2019-03-16 19:54:44 -05:00
David Hill
d25931fd35
multi: preallocate memory. 2019-03-09 16:43:48 -06:00
Dave Collins
cf3f55f6b0
dcrutil: Fix typos found by misspell. 2019-02-14 22:59:08 -06:00
Dave Collins
e052b9cbf2
multi: Remove non-root module replacements.
This modifies all of the modules, with the exception of the root module,
to remove all replacement directives from their go.mod files and update
the requirements and module sums accordingly.

While it is nice to be able to build and test directly from each module
directory and have it pull in the latest untagged changes when
developing, having all of the overrides in each module makes it
infeasible to use the module tools to help maintain the modules and thus
makes it quite difficult to ensure they are all independently accurate
for external consumers.

By maintaining all of the overrides in the root module and invoking all
builds and tests from it, the overrides will apply to ensure the latest
code is being built and tested.

This also modifies the tests script used with in CI to run all of the
tests from the root module accordingly.
2019-02-08 18:01:43 -06:00
Jonathan Chappelow
3a5281156b dcrutil: Block does not cache the header bytes
This fixes a bug in dcrutil where (*Block).BlockHeaderBytes would
incorrectly return a cached byte slice of the serialized block instead
of just the header. This would only happen after the cache had been
set, such as through a call to block.Bytes(), or construction via
NewBlockFromBytes or NewBlockFromBlockAndBytes.

The comments are also changed accordingly and wrapped after 80 columns.

Update TestBlock with a test for (*Block).BlockHeaderBytes that follows
(*Block).Bytes.
2019-01-18 16:37:30 -06:00
Sarlor
e7c5589285 dcrutil: Return deep copied tx in NewTxDeepTxIns.
This updates the NewTxDeepTxIns function to return the deep copied
transaction instead of the original.
2019-01-03 20:29:33 -06:00
Dave Collins
1a370d38d6
release: Tidy module files with published versions. 2018-12-12 12:18:11 -06:00
Dave Collins
220d434b6e
release: Bump module versions and deps.
This bumps the various module versions as follows:

- github.com/decred/dcrd/dcrec/secp256k1@v1.0.1
- github.com/decred/dcrd/dcrjson@v1.1.0
- github.com/decred/dcrd/database@v1.0.3
- github.com/decred/dcrd/blockchain/stake@v1.1.0
- github.com/decred/dcrd/mining@v1.1.0
- github.com/decred/dcrd/certgen@v1.0.2
- github.com/decred/dcrd/connmgr@v1.0.2
- github.com/decred/dcrd/mempool@v1.1.0

In addition, it serves as a base for tagging releases of the following
module versions that have previous been bumped since the last release,
but not yet tagged:

- github.com/decred/dcrd/wire@v1.2.0
- github.com/decred/dcrd/chaincfg@v1.2.0
- github.com/decred/dcrd/dcrutil@v1.2.0
- github.com/decred/dcrd/txscript@v1.0.2
- github.com/decred/dcrd/blockchain@v1.1.0
- github.com/decred/dcrd/hdkeychain@v1.1.1
- github.com/decred/dcrd/peer@v1.1.0
- github.com/decred/dcrd/rpcclient@v1.1.0

Finally, it updates all of the dependencies for every module accordingly,
adds a few missing overrides for transitive dependencies, and tidies up
some of the go module sum files.
2018-12-10 11:18:00 -06:00
Dave Collins
6f9b6f1c6e
multi: Use regression test network in unit tests.
This modifies the majority of the tests that make use of chain
parameters and the RPC tests to use the resurrected regression test
network.

It also bumps the affected module versions as follows:

- github.com/decred/dcrd/txscript@v1.0.2
- github.com/decred/dcrd/blockchain/stake@v1.0.3
- github.com/decred/dcrd/mempool@v1.0.2

The blockchain and dcrutil modules are also affected, but since their
version has already been bumped since their last release tags, they are
not bumped again.
2018-10-09 19:40:10 -05:00
Dave Collins
47ade78c1a
multi: Resurrect regression network.
This resurrects the regression test network that was removed before
initial launch although it really should not have been.  The simulation
test network and the regression test network do not serve the same
purpose.  Specifically, the regression test network is intended for unit
tests, RPC server tests, and consensus tests.  On the other hand, the
simulation test network is intended for private use within a group of
individuals doing simulation testing and full integration tests between
different applications such as wallets, voting service providers, mining
pools, block explorers, and other services that build on Decred.

Keeping the concerns separate will allow the simulation test network to
be modified in ways such as activating consensus changes that have been
successfully voted into mainnet without also needing to vote them in on
the simulation test network while still preserving the ability for the
unit tests to properly test the voting semantics and handling to help
prevent regressions.

In addition to resurrecting the regression test network, this also fully
fleshes out new values for the various addresses prefixes (Rk, Rs, Re,
etc), HD key prefixes (rprv, rpub), and treasury multisig details.

As a part of resurrecting the network, a new CLI flag `--regnet` is
added to allow the RPC test harness connect to a running instance, the
areas of the code which involve votes have been modified to allow the
votes to apply to the new network, and tests have been added to the
relevant modules.

This bumps the affected module versions as follows:

- github.com/decred/dcrd/wire@v1.2.0
- github.com/decred/dcrd/chaincfg@v1.2.0
- github.com/decred/dcrd/dcrutil@v1.2.0
- github.com/decred/dcrd/hdkeychain@v1.1.1

The blockchain module is also affected, but since its version has
already been bumped since the last release tag, it is not bumped again.

Finally, this does not include switching unit tests or the RPC test
harness over the new network since that will be done in a separate
commit.
2018-10-09 18:52:13 -05:00
Dave Collins
36f61d8ebd build: Tidy module sums (go mod tidy). 2018-08-16 20:03:27 -05:00
Dave Collins
9536f0c88f
release: Bump module versions and deps.
This bumps the various module versions as follows:

- github.com/decred/dcrd/addrmgr@v1.0.2
- github.com/decred/dcrd/wire@v1.1.0
- github.com/decred/dcrd/chaincfg@v1.1.1
- github.com/decred/dcrd/connmgr@v1.0.1
- github.com/decred/dcrd/dcrutil@v1.1.1
- github.com/decred/dcrd/database@v1.0.1
- github.com/decred/dcrd/hdkeychain@v1.1.0
- github.com/decred/dcrd/txscript@v1.0.1
- github.com/decred/dcrd/blockchain/stake@v1.0.1
- github.com/decred/dcrd/gcs@v1.0.1
- github.com/decred/dcrd/blockchain@v1.0.1
- github.com/decred/dcrd/mining@v1.0.1
- github.com/decred/dcrd/mempool@v1.0.1
- github.com/decred/dcrd/peer@v1.0.1
- github.com/decred/dcrd/rpcclient@v1.0.1

It also updates all of the dependencies for every module accordingly and
adds a few missing overrides for transitive dependencies.
2018-08-09 14:30:22 -05:00
Dave Collins
9e1579771b
multi: Reset testnet and bump to version 3.
This adds a new testnet3 network with new genesis block, block one
ledger, treasury address, and network magic.

All consensus rules that were voted in by testnet2 are automatically
active on the new testnet3 without having to vote them in again.
Consequently, there are no consensus vote agendas defined for it.
2018-08-08 08:09:32 -05:00
Dave Collins
96a1a8546d
multi: Reduce testnet2 refs in unit tests.
This modifies the test code for several unit tests to prefer using
another network, such as mainnet or simnet, when not specifically
testing something that requires testnet.

In the cases where where testnet is required, it also now prefers a
local reference over directly accessing the testnet parameters directly
from the chaincfg package.

This is being done because the test network undergoes periodic resets
and by reducing the number of direct references, it simplifies the
process of resetting it.
2018-08-08 06:41:50 -05:00
Dave Collins
295179fc0d
build: Refine build module support.
This further refines the modules to add the following new modules
instead of depending on the entire dcrd module:

- github.com/decred/dcrd/dcrjson@v1.0.0
- github.com/decred/dcrd/blockchain@v1.0.0
- github.com/decred/dcrd/blockchain/stake@v1.0.0
- github.com/decred/dcrd/gcs@v1.0.0
- github.com/decred/dcrd/mining@v1.0.0
- github.com/decred/dcrd/mempool@v1.0.0
- github.com/decred/dcrd/peer@v1.0.0
- github.com/decred/dcrd/rpcclient@v1.0.0

Also, it ensures modules that rely on other modules within the repo are
provided replacements to the latest repo code to ensure builds against
master and continuous integration use the latest code.

- github.com/decred/dcrd/addrmgr
- github.com/decred/dcrd/blockchain
- github.com/decred/dcrd/blockchain/stake
- github.com/decred/dcrd/chaincfg
- github.com/decred/dcrd/connmgr
- github.com/decred/dcrd/database
- github.com/decred/dcrd/dcrec/secp256k1
- github.com/decred/dcrd/dcrjson
- github.com/decred/dcrd/dcrutil
- github.com/decred/dcrd/gcs
- github.com/decred/dcrd/hdkeychain
- github.com/decred/dcrd/mempool
- github.com/decred/dcrd/mining
- github.com/decred/dcrd/peer
- github.com/decred/dcrd/rpcclient
- github.com/decred/dcrd/txscript
- github.com/decred/dcrd/wire
2018-08-05 20:45:45 -05:00
Dave Collins
5369a485ac
dcrutil: Refine go build module support.
Now that the base58, chaincfg, chainhash, dcrec, secp256k1, and wire
modules have been defined, update the dcrutil module to only depend on
them instead of the entire dcrd module.
2018-07-20 22:10:28 -05:00
David Hill
01316e20f3 multi: Continue conversion from chainec to dcrec. 2018-07-04 11:21:43 -04:00
Dave Collins
45e313e6d2
multi: Define vgo modules.
This adds module support for the versioned go toolchain.  In particular,
the following packages are defined as modules:

* addrmgr
* blockchain
* certgen
* chaincfg
* connmgr
* database
* dcrjson
* dcrutil
* gcs
* hdkeychain
* mempool
* mining
* peer
* rpcclient
* txscript
* wire

It does not update the travis build environment or README since it is
experimental at this point.
2018-05-25 15:38:16 -05:00
Josh Rickmar
dcc58786d3 dcrutil: Disallow creation of hybrid P2PK addrs.
Hybrid pubkeys, which are a relic of OpenSSL used in Bitcoin Core, are
not usable with OP_CHECKSIG and we can potentially prevent creating
unspendable outputs by never allowing the creation of P2PK (or derived
P2PKH) addresses for these pubkeys.
2018-03-20 17:44:25 -04:00
Markus Richter
1e42b8524d multi: Properly capitalize Decred.
Decred is inconsistencly capitalized in the code base,
change all occurences of decred to Decred.
2018-03-01 17:41:35 -06:00
David Hill
5fc31ca578 multi: fix misspell linter warnings 2018-02-18 12:26:52 -06:00
Dave Collins
8922295ae5
txsort: Implement stable tx sorting package.
This adds a new package under dcrutil named txsort which implements a
standard lexicographical sort order of transaction inputs and outputs.
This is useful to standardize transactions for faster multi-party
agreement as well as preventing information leaks in a single-party use
case.  It is a modified form of BIP69 which has been updated to account
for differences with Decred-specific transactions.

The sort order for transaction inputs is defined as follows:
- Previous transaction tree in ascending order
- Previous transaction hash (treated as a big-endian uint256)
  lexicographically in ascending order
- Previous output index in ascending order

The sort order for transaction outputs is defined as follows:
- Amount in ascending order
- Public key script version in ascending order
- Raw public key script bytes lexicographically in ascending order
2017-12-08 11:22:21 -06:00
David Hill
fc31a0b39e multi: remove unused funcs and vars 2017-12-07 21:46:25 -06:00
David Hill
20686cd775 travis: add gosimple linter 2017-11-20 18:49:55 -06:00
Josh Rickmar
65001cd49e hdkeychain: Move to github.com/decred/dcrd/hdkeychain
This change moves the hdkeychain package outside of the dcrutil
directory into its own top-level package.  This change is being made
since hdkeychain only depends on dcrutil's address code, and if the
rpctest integration tests are ever moved outside of the dcrd repo,
hdkeychain will no longer be required to remain in dcrd to avoid a
cyclic dependency.
2017-10-12 08:31:54 -05:00
Dave Collins
83dd384ce7
hdkeychain: Work around go vet issue with examples. 2017-10-11 22:08:33 -05:00