This change removes all occurances of btcwire.BitcoinNet from exported
APIs, replacing each with *btcnet.Params. This simplifies the logic
for verifying string encodings of addresses and WIF private keys which
use leading identifier numbers to differentiate between address types
and the network they are intended for. It also allows the use of this
package for non-standard networks (not mainnet, regtest, or testnet3)
and future proofs it for the possible addition of future testnet
networks.
To update across this change, replace each btcwire.BitcoinNet
parameter with the associated *btcnet.Params. For the standard
networks, these changes are:
btcwire.MainNet -> &btcnet.MainNetParams
btcwire.TestNet -> &btcnet.RegressionNetParams
btcwire.TestNet3 -> &btcnet.TestNet3Params
ok @davecgh
The old functions DecodePrivateKey and EncodePrivateKey have been
removed in favor of the DecodeWIF function and the String method of
the new WIF type.
ok @davecgh
This change adds the Hash160 methods to AddressPubKeyHash and
AddressScriptHash so the hash may be accessed as an array, rather than
a byte slice with the ScriptAddress method of the Address interface.
In situations where arrays are more appropiate than slices (such as
for map keys), accessing the array directly this way can significantly
improve performance by reducing copying into local arrays.
Amount should still be a usable type even if the monetary amount being
described is not an amount at a single instance in time, for example,
the total of all BTC received by an address. Therefore, the bounds
checks that the amount is within the total amount of bitcoin ever
producable have been removed.
The checks for NaN and +-Infinity remain.
This commit removes the previously deprecated TxShas function from
btcutil.Block. The preferred method to access transaction hashes is via
the Sha function on each btcutil.Tx contained within the block.
For example, the following illustrates how convert the old TxShas approach
to the new method:
OLD:
for i, sha := range block.TxShas() {
// use sha
}
NEW:
for i, tx := range block.Transactions() {
// use tx.Sha()
}
This commit also updates the tests for the removed function.
This commit contains a basic definition for CoinSelector along with some
utility classes and some basic algos to make creating transactions from
a set of available unspent outpoints easier.
Thanks to @dajohi, @davec, @jrick for all the feedback and suggestions
regarding interfaces, organization, optimization, comments and
documentation.
This commit modifies DecodeAddress to accept and decode pay-to-pubkey
addresses (raw serialized public keys). Since the resulting Address
needs to have a network associated with it, and a raw serialized public
key does not encode the network with it, a new parameter has been added
which requires the caller to specify a default network to use when
decoding addresses.
In the case the address has a network encoded with it such as for
pay-to-pubkey-hash and pay-to-script-hash addresses, the network will be
decoded from the address and the resulting Address instance will have that
network associated with it. When the address does NOT have a network
encoded with it, such as a pay-to-pubkey address, the provided default
network will be associated with the returned Address instance.
Also, the tests have been updated to test the new functionality.
ok @owainga and @jrick.
Address is a generic interface for any type of "address" a
transaction can be sent to, including but not limited to
pay-to-pubkey, pay-to-pubkey-hash, and pay-to-script-hash.
This change implements Address and concrete types for P2PKH and P2SH
addresses with 100% test coverage. Pay-to-pubkey support will be
added in the future.
This API is intended to replace the old EncodeAddress/DecodeAddress
functions which are now deprecated.
This commit adds both positive and negative tests for the new Tx type to
bring its coverage to 100%.
This is part of the ongoing transaction hash optimization effort noted
in conformal/btcd#25.