This commit adds support for bech32 encoded segwit
addresses, namely AddressWitnessPubKeyHash and
AddressWitnessScriptHash. These are both specified
in BIP 173.
The bech32 format is used to encode base32 data
in a string format specified in BIP 173. This is
among other things used to encode native segwit
addresses, also specified in the same BIP.
This commit adds the package bech32, which
contains the necessary utility methods to create
bech32 encoded strings from arbitrary data.
Allow users to create custom ExtendedKeys by exporting the newExtendedKey function.
The comment is updated to reflect that this function is only intended to be used
by custom applications.
The github markdown interpreter has been changed such that it no longer
allows spaces in between the brackets and parenthesis of links. This
updates all of the markdown files accordingly.
While here, it also corrects a couple of inconsistencies in regards to
other README.md files in the project.
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.
Also, address a few style and consistent nits while here:
- Prefer t.Fatalf over t.Errorf followed by a return
- Use the consistent style of starting a test function comments with the
test name
- Prefix test errors by the function being called instead of the one
doing the calling since the caller itself is already logged by the
test framework
- Check err in max depth test before checking the returned key is nil
BIP32 keys serialize the depth as a uint8 over the wire. I noticed
uint16 was being used and that the depth was being taken modulo 256
during serialization.
This seems like a bug, as the behaviour is not described in the BIP,
and also introduces incompatibilities which can be hard to make sense
of. For example, the parent fingerprint should be 0x00000000 for a key
of depth zero, whereas with the existing code if depth=256, then the
serialization will set 0 but still set a parent fingerprint.
This updates all code in the main package and subpackages to make use of
the new chainhash package since the old wire.ShaHash type and functions
have been removed in favor of the abstracted package.
Also, since this required API changes anyways and the hash algorithm is
no longer tied specifically to SHA, all other functions throughout the
code base which had "Sha" in their name have been changed to Hash so
they are not incorrectly implying the hash algorithm.
The following is an overview of the changes:
- Update all references to wire.ShaHash to the new chainhash.Hash type
- Rename the following functions and update all references:
- Block.Sha -> Hash
- Block.TxSha -> TxHash
- Tx.Sha -> Hash
- bloom.Filter.AddShaHash -> AddHash
- Rename all variables that included sha in their name to include hash
instead
- Add license headers to coinset package files
The vet tool moved into the Go source tree as of Go 1.5. Its previous
location in the x/tools repo was deprecated at that time and has now
been removed.
This commit updates the .travis.yml configuration to avoid fetching vet
from the old location and to simply use the version now available as
part of the standard Go install.
Also, while here, remove the check for changing the tool path since it
is no longer needed.
Interpreting a 0 as the lower limit of 1e-9 seems more intuitive behavior when receiving an out-of-bounds argument.
davecgh's fixes to TestFilterFPRange
This corrects an issue with the serialization of extended private keys
where certain underlying derivations could cause lead to printing
extended privkeys that did not have the expected xprv prefix.
In addition, tests for private key derivation have been added as well as
a specific test which triggers the previously failing case.
This changes the NewMaster function to accept the network the generated
extended master key is associated with. This could previously be done
by calling SetNet on the returned extended key, but that approach is
more error prone since it is easy for a caller to forget to do it or
never know they should to begin with.
First, it removes the documentation section from all the README.md files
and instead puts a web-based godoc badge and link at the top with the
other badges. This is being done since the local godoc tool no longer
ships with Go by default, so the instructions no longer work without
first installing godoc. Due to this, pretty much everyone uses the
web-based godoc these days anyways. Anyone who has manually installed
godoc won't need instructions.
Second, it makes sure the ISC license badge is at the top with the other
badges and removes the textual reference in the overview section.
Third, it's modifies the Installation section to Installation and
Updating and adds a -u to the go get command since it works for both and
thus is simpler.
Finally, it replaces the badges with SVG versions from shields.io so
they are consistent.
This adds a new function with loud warnings which allows sorting a
transaction in place by mutating it. This is more efficient for the
caller if they are the ones creating the transaction and are sure it
will not invalid any cache or containing structures.
The Sort function which makes a copy and is therefore does not mutate
the passed transaction is still available and the default method.
- Move hex for test txns into separate files in the testdata directory
- Convert tests to table-driven tests
- Make comments more consistent with the rest of the codebase
- Optimize the input sorting function to perform the hash equivalence
check before reversing the bytes so it can be avoided in that case
This converts the txsort code into a separate package and renames
'TxSort' and 'IsTxSorted' to 'Sort' an `IsSorted`, respectively.
It also adds a 'doc.go' and 'README.md' so it is consistent with the
other packages.
These functions sort transaction inputs and outputs according to BIP LI01
(https://github.com/kristovatlas/rfc/blob/master/bips/bip-li01.mediawiki)
This is useful to standardize transactions for faster multi-party
agreement as well as preventing information leaks in a single-party
use case.
- Documentation update to NewAmount.
Call out the fact it's specifically for converting BTC to Satoshi.
The caller should perform a simple type cast to an Amount when dealing
with int64 values which denote a quantity of Satoshi.
This commit converts all block height references to int32 instead of
int64. The current target block production rate is 10 mins per block
which means it will take roughly 40,800 years to reach the maximum
height an int32 affords. Even if the target rate were lowered to one
block per minute, it would still take roughly another 4,080 years to
reach the maximum.
In the mean time, there is no reason to use a larger type which results
in higher memory usage.
This commit modifies the NewMerkleBlock function to return the matched
transaction indices instead of their hashes. This is being done because
it is much easier for the caller to lookup the matched transactions from
the original passed block based on their transaction index within the
block versus their hashes.
Fix imports, fix output pretty print
Use btcutil.Amount() instead of btcutil.NewAmount()
Trim off unnecessary .String()
Testable example for Amount
Improve example for btcutil.Amount