mirror of
https://github.com/FlipsideCrypto/dcrd.git
synced 2026-02-06 10:56:47 +00:00
Merge in btcd commit '2adfb3b56acd280e84451e94dd0c06203eef9832'
Merges in btcd commit 2adfb3b56a.
This commit is contained in:
commit
3d5b9c81fc
@ -71,14 +71,15 @@ func (msg *MsgAddr) BtcDecode(r io.Reader, pver uint32) error {
|
||||
return messageError("MsgAddr.BtcDecode", str)
|
||||
}
|
||||
|
||||
addrList := make([]NetAddress, count)
|
||||
msg.AddrList = make([]*NetAddress, 0, count)
|
||||
for i := uint64(0); i < count; i++ {
|
||||
na := NetAddress{}
|
||||
err := readNetAddress(r, pver, &na, true)
|
||||
na := &addrList[i]
|
||||
err := readNetAddress(r, pver, na, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msg.AddAddress(&na)
|
||||
msg.AddAddress(na)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -68,14 +68,17 @@ func (msg *MsgGetBlocks) BtcDecode(r io.Reader, pver uint32) error {
|
||||
return messageError("MsgGetBlocks.BtcDecode", str)
|
||||
}
|
||||
|
||||
// Create a contiguous slice of hashes to deserialize into in order to
|
||||
// reduce the number of allocations.
|
||||
locatorHashes := make([]chainhash.Hash, count)
|
||||
msg.BlockLocatorHashes = make([]*chainhash.Hash, 0, count)
|
||||
for i := uint64(0); i < count; i++ {
|
||||
sha := chainhash.Hash{}
|
||||
err := readElement(r, &sha)
|
||||
hash := &locatorHashes[i]
|
||||
err := readElement(r, hash)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msg.AddBlockLocatorHash(&sha)
|
||||
msg.AddBlockLocatorHash(hash)
|
||||
}
|
||||
|
||||
err = readElement(r, &msg.HashStop)
|
||||
|
||||
@ -50,14 +50,17 @@ func (msg *MsgGetData) BtcDecode(r io.Reader, pver uint32) error {
|
||||
return messageError("MsgGetData.BtcDecode", str)
|
||||
}
|
||||
|
||||
// Create a contiguous slice of inventory vectors to deserialize into in
|
||||
// order to reduce the number of allocations.
|
||||
invList := make([]InvVect, count)
|
||||
msg.InvList = make([]*InvVect, 0, count)
|
||||
for i := uint64(0); i < count; i++ {
|
||||
iv := InvVect{}
|
||||
err := readInvVect(r, pver, &iv)
|
||||
iv := &invList[i]
|
||||
err := readInvVect(r, pver, iv)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msg.AddInvVect(&iv)
|
||||
msg.AddInvVect(iv)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@ -65,14 +65,17 @@ func (msg *MsgGetHeaders) BtcDecode(r io.Reader, pver uint32) error {
|
||||
return messageError("MsgGetHeaders.BtcDecode", str)
|
||||
}
|
||||
|
||||
// Create a contiguous slice of hashes to deserialize into in order to
|
||||
// reduce the number of allocations.
|
||||
locatorHashes := make([]chainhash.Hash, count)
|
||||
msg.BlockLocatorHashes = make([]*chainhash.Hash, 0, count)
|
||||
for i := uint64(0); i < count; i++ {
|
||||
sha := chainhash.Hash{}
|
||||
err := readElement(r, &sha)
|
||||
hash := &locatorHashes[i]
|
||||
err := readElement(r, hash)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msg.AddBlockLocatorHash(&sha)
|
||||
msg.AddBlockLocatorHash(hash)
|
||||
}
|
||||
|
||||
err = readElement(r, &msg.HashStop)
|
||||
|
||||
@ -50,10 +50,13 @@ func (msg *MsgHeaders) BtcDecode(r io.Reader, pver uint32) error {
|
||||
return messageError("MsgHeaders.BtcDecode", str)
|
||||
}
|
||||
|
||||
// Create a contiguous slice of headers to deserialize into in order to
|
||||
// reduce the number of allocations.
|
||||
headers := make([]BlockHeader, count)
|
||||
msg.Headers = make([]*BlockHeader, 0, count)
|
||||
for i := uint64(0); i < count; i++ {
|
||||
bh := BlockHeader{}
|
||||
err := readBlockHeader(r, pver, &bh)
|
||||
bh := &headers[i]
|
||||
err := readBlockHeader(r, pver, bh)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -69,7 +72,7 @@ func (msg *MsgHeaders) BtcDecode(r io.Reader, pver uint32) error {
|
||||
"transactions [count %v]", txCount)
|
||||
return messageError("MsgHeaders.BtcDecode", str)
|
||||
}
|
||||
msg.AddBlockHeader(&bh)
|
||||
msg.AddBlockHeader(bh)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@ -58,14 +58,17 @@ func (msg *MsgInv) BtcDecode(r io.Reader, pver uint32) error {
|
||||
return messageError("MsgInv.BtcDecode", str)
|
||||
}
|
||||
|
||||
// Create a contiguous slice of inventory vectors to deserialize into in
|
||||
// order to reduce the number of allocations.
|
||||
invList := make([]InvVect, count)
|
||||
msg.InvList = make([]*InvVect, 0, count)
|
||||
for i := uint64(0); i < count; i++ {
|
||||
iv := InvVect{}
|
||||
err := readInvVect(r, pver, &iv)
|
||||
iv := &invList[i]
|
||||
err := readInvVect(r, pver, iv)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msg.AddInvVect(&iv)
|
||||
msg.AddInvVect(iv)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@ -79,14 +79,17 @@ func (msg *MsgMerkleBlock) BtcDecode(r io.Reader, pver uint32) error {
|
||||
return messageError("MsgMerkleBlock.BtcDecode", str)
|
||||
}
|
||||
|
||||
// Create a contiguous slice of hashes to deserialize into in order to
|
||||
// reduce the number of allocations.
|
||||
hashes := make([]chainhash.Hash, count)
|
||||
msg.Hashes = make([]*chainhash.Hash, 0, count)
|
||||
for i := uint64(0); i < count; i++ {
|
||||
var sha chainhash.Hash
|
||||
err := readElement(r, &sha)
|
||||
hash := &hashes[i]
|
||||
err := readElement(r, hash)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msg.AddTxHash(&sha)
|
||||
msg.AddTxHash(hash)
|
||||
}
|
||||
|
||||
err = readElement(r, &msg.STransactions)
|
||||
@ -105,14 +108,15 @@ func (msg *MsgMerkleBlock) BtcDecode(r io.Reader, pver uint32) error {
|
||||
return messageError("MsgMerkleBlock.BtcDecode", str)
|
||||
}
|
||||
|
||||
hashes = make([]chainhash.Hash, count)
|
||||
msg.SHashes = make([]*chainhash.Hash, 0, scount)
|
||||
for i := uint64(0); i < scount; i++ {
|
||||
var sha chainhash.Hash
|
||||
err := readElement(r, &sha)
|
||||
hash := &hashes[i]
|
||||
err := readElement(r, hash)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msg.AddSTxHash(&sha)
|
||||
msg.AddSTxHash(hash)
|
||||
}
|
||||
|
||||
msg.Flags, err = ReadVarBytes(r, pver, maxFlagsPerMerkleBlock,
|
||||
|
||||
@ -47,14 +47,17 @@ func (msg *MsgNotFound) BtcDecode(r io.Reader, pver uint32) error {
|
||||
return messageError("MsgNotFound.BtcDecode", str)
|
||||
}
|
||||
|
||||
// Create a contiguous slice of inventory vectors to deserialize into in
|
||||
// order to reduce the number of allocations.
|
||||
invList := make([]InvVect, count)
|
||||
msg.InvList = make([]*InvVect, 0, count)
|
||||
for i := uint64(0); i < count; i++ {
|
||||
iv := InvVect{}
|
||||
err := readInvVect(r, pver, &iv)
|
||||
iv := &invList[i]
|
||||
err := readInvVect(r, pver, iv)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msg.AddInvVect(&iv)
|
||||
msg.AddInvVect(iv)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@ -573,14 +573,15 @@ func (msg *MsgTx) decodePrefix(r io.Reader, pver uint32) error {
|
||||
}
|
||||
|
||||
// TxIns.
|
||||
txIns := make([]TxIn, count)
|
||||
msg.TxIn = make([]*TxIn, count)
|
||||
for i := uint64(0); i < count; i++ {
|
||||
ti := TxIn{}
|
||||
err = readTxInPrefix(r, pver, msg.Version, &ti)
|
||||
ti := &txIns[i]
|
||||
err = readTxInPrefix(r, pver, msg.Version, ti)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msg.TxIn[i] = &ti
|
||||
msg.TxIn[i] = ti
|
||||
}
|
||||
|
||||
count, err = ReadVarInt(r, pver)
|
||||
@ -599,14 +600,15 @@ func (msg *MsgTx) decodePrefix(r io.Reader, pver uint32) error {
|
||||
}
|
||||
|
||||
// TxOuts.
|
||||
txOuts := make([]TxOut, count)
|
||||
msg.TxOut = make([]*TxOut, count)
|
||||
for i := uint64(0); i < count; i++ {
|
||||
to := TxOut{}
|
||||
err = readTxOut(r, pver, msg.Version, &to)
|
||||
to := &txOuts[i]
|
||||
err = readTxOut(r, pver, msg.Version, to)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msg.TxOut[i] = &to
|
||||
msg.TxOut[i] = to
|
||||
}
|
||||
|
||||
// Locktime and expiry.
|
||||
@ -642,14 +644,15 @@ func (msg *MsgTx) decodeWitness(r io.Reader, pver uint32, isFull bool) error {
|
||||
return messageError("MsgTx.decodeWitness", str)
|
||||
}
|
||||
|
||||
txIns := make([]TxIn, count)
|
||||
msg.TxIn = make([]*TxIn, count)
|
||||
for i := uint64(0); i < count; i++ {
|
||||
ti := TxIn{}
|
||||
err = readTxInWitness(r, pver, msg.Version, &ti)
|
||||
ti := &txIns[i]
|
||||
err = readTxInWitness(r, pver, msg.Version, ti)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msg.TxIn[i] = &ti
|
||||
msg.TxIn[i] = ti
|
||||
}
|
||||
msg.TxOut = make([]*TxOut, 0)
|
||||
} else {
|
||||
@ -683,9 +686,10 @@ func (msg *MsgTx) decodeWitness(r io.Reader, pver uint32, isFull bool) error {
|
||||
|
||||
// Read in the witnesses, and copy them into the already generated
|
||||
// by decodePrefix TxIns.
|
||||
txIns := make([]TxIn, count)
|
||||
for i := uint64(0); i < count; i++ {
|
||||
ti := TxIn{}
|
||||
err = readTxInWitness(r, pver, msg.Version, &ti)
|
||||
ti := &txIns[i]
|
||||
err = readTxInWitness(r, pver, msg.Version, ti)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -719,14 +723,15 @@ func (msg *MsgTx) decodeWitnessSigning(r io.Reader, pver uint32) error {
|
||||
return messageError("MsgTx.decodeWitness", str)
|
||||
}
|
||||
|
||||
txIns := make([]TxIn, count)
|
||||
msg.TxIn = make([]*TxIn, count)
|
||||
for i := uint64(0); i < count; i++ {
|
||||
ti := TxIn{}
|
||||
err = readTxInWitnessSigning(r, pver, msg.Version, &ti)
|
||||
ti := &txIns[i]
|
||||
err = readTxInWitnessSigning(r, pver, msg.Version, ti)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msg.TxIn[i] = &ti
|
||||
msg.TxIn[i] = ti
|
||||
}
|
||||
msg.TxOut = make([]*TxOut, 0)
|
||||
|
||||
@ -752,14 +757,15 @@ func (msg *MsgTx) decodeWitnessValueSigning(r io.Reader, pver uint32) error {
|
||||
return messageError("MsgTx.decodeWitness", str)
|
||||
}
|
||||
|
||||
txIns := make([]TxIn, count)
|
||||
msg.TxIn = make([]*TxIn, count)
|
||||
for i := uint64(0); i < count; i++ {
|
||||
ti := TxIn{}
|
||||
err = readTxInWitnessValueSigning(r, pver, msg.Version, &ti)
|
||||
ti := &txIns[i]
|
||||
err = readTxInWitnessValueSigning(r, pver, msg.Version, ti)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msg.TxIn[i] = &ti
|
||||
msg.TxIn[i] = ti
|
||||
}
|
||||
msg.TxOut = make([]*TxOut, 0)
|
||||
|
||||
@ -843,14 +849,16 @@ func (msg *MsgTx) LegacyBtcDecode(r io.Reader, pver uint32) error {
|
||||
return messageError("MsgTx.BtcDecode", str)
|
||||
}
|
||||
|
||||
// Deserialize the inputs.
|
||||
txIns := make([]TxIn, count)
|
||||
msg.TxIn = make([]*TxIn, count)
|
||||
for i := uint64(0); i < count; i++ {
|
||||
ti := TxIn{}
|
||||
err = legacyReadTxIn(r, pver, msg.Version, &ti)
|
||||
ti := &txIns[i]
|
||||
err = legacyReadTxIn(r, pver, msg.Version, ti)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msg.TxIn[i] = &ti
|
||||
msg.TxIn[i] = ti
|
||||
}
|
||||
|
||||
count, err = ReadVarInt(r, pver)
|
||||
@ -868,14 +876,16 @@ func (msg *MsgTx) LegacyBtcDecode(r io.Reader, pver uint32) error {
|
||||
return messageError("MsgTx.BtcDecode", str)
|
||||
}
|
||||
|
||||
// Deserialize the outputs.
|
||||
txOuts := make([]TxOut, count)
|
||||
msg.TxOut = make([]*TxOut, count)
|
||||
for i := uint64(0); i < count; i++ {
|
||||
to := TxOut{}
|
||||
err = legacyReadTxOut(r, pver, msg.Version, &to)
|
||||
to := &txOuts[i]
|
||||
err = legacyReadTxOut(r, pver, msg.Version, to)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msg.TxOut[i] = &to
|
||||
msg.TxOut[i] = to
|
||||
}
|
||||
|
||||
msg.LockTime, err = binarySerializer.Uint32(r, littleEndian)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user