Commit graph

23 commits

Author SHA1 Message Date
Yuchuan
e3017c9aab Update block.go
Fix bound check in block.tx(txNum int)
2020-07-13 09:48:38 -04:00
Olaoluwa Osuntokun
6950f39a70
add new BytesNoWitness method to Block
This commit adds a new method to btcutil.Block for obtaining the
serialization of a Block *without* any witness data (if any).
2017-07-26 11:36:09 -07:00
David Hill
f6a0d000db Reduce allocs in Block.Bytes() 2016-11-16 12:40:24 -05:00
Dave Collins
22c91fa80a Update for recent chainhash-related API changes. (#78)
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
2016-08-08 12:38:16 -05:00
Dave Collins
1c7f05922f Convert block heights to int32.
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.
2015-08-07 22:30:27 -05:00
Dave Collins
1b73e9828d Relicense to the btcsuite developers. 2015-05-01 12:41:58 -05:00
Dave Collins
9556412b01 Update for recent wire API hash error changes. 2015-04-17 01:13:40 -05:00
Dave Collins
e330838900 Remove error return from Block.Sha function.
This commit remove the error return from the Block.Sha function since it
can never fail and ends up causing a lot of unneeded error checking
throughout the code base.
2015-04-17 00:42:08 -05:00
Dave Collins
80b97479bd Update btcwire path import paths to new location. 2015-02-05 14:48:38 -06:00
Dave Collins
fdc00f8eff Update btcwire import paths to new location. 2015-01-16 15:26:50 -06:00
Dave Collins
6c4b5928ab goimports -w . 2014-07-02 19:29:48 -05:00
Josh Rickmar
b3e031c1f9 Add NewBlockFromReader and NewTxFromReader.
While here, remove the serializedTx field from Tx.  This field was
originally intended to be used to cache the bytes of the serialized
transaction, but it was never used and can effectively leak memory if
the Tx was created with a call to NewTxFromBytes.

ok @davecgh
2014-06-24 18:46:06 -05:00
Josh Rickmar
9a3f83d493 Switch bytes.Buffer to Reader where possible.
bytes.Reader is a little bit more efficient than a bytes.Buffer when
just reading, so in situations where only an io.Reader is needed (for
Block and Tx deserialization), switch to a bytes.Reader.

ok @davecgh
2014-06-23 21:39:04 -05:00
Dave Collins
2db41b1f56 Remove deprecated TxShas func from btcutil.Block.
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.
2014-03-24 13:56:43 -05:00
Dave Collins
4edc4ceb9e Update for recent btcwire API changes. 2014-01-18 20:59:07 -06:00
Dave Collins
2af3c8263a Add 2014 to copyright dates. 2014-01-08 23:46:05 -06:00
Dave Collins
8e97f32e68 Add funcs to Block API for wrapped transactions.
This commit adds two new functions to the Block API for working with the
recently added Tx type from the Block.

These new functions are named Tx and Transactions.  Tx returns a
transactions for the specified index as a Tx and also memoizes it so
subsequent calls are more efficient.  Transactions returns a slice of all
transactions in the Block wrapped in a Tx.

This is part of the ongoing transaction hash optimization effort
noted in conformal/btcd#25.
2013-10-28 10:34:27 -05:00
Dave Collins
43095c66bc Remove dependency on protocol version.
This commit unfortunately changes the public API of Block which I
ordinarily don't like to do, but in this case, I felt it was necessary.

The blocks used throughout the database and elsewhere should be indepedent
of the protocol version which is used to encode the block to wire format.
Each block has its own Version field which should be the deciding factor
for the serialization and deserialization of blocks.  In practice, they
are currently the same encoding, but that may not always be the case, and
it's important the blocks are stable depending on their own version
regardless of the protocol version.

This makes use of the new Serialize and Deserialize functions on MsgBlock
which are intended for long-term storage as opposed to wire encoding.
2013-08-05 16:28:55 -05:00
Dave Collins
b8843a0fb6 Make TxLoc comment consistent with others. 2013-05-30 11:39:43 -05:00
Dave Collins
e98dc50b69 Convert TxLoc to use normal returns. 2013-05-30 11:31:22 -05:00
Dave Collins
969fbd1500 Cleanup TxLoc function variable names. 2013-05-30 11:13:08 -05:00
Dave Collins
af89ed1c2e Correct documentation of the Block.TxLoc function. 2013-05-28 18:43:13 -05:00
Dave Collins
ef6c01960f Initial implementation. 2013-05-28 18:21:26 -05:00