forked from trezor/blockbook
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from trezor/master
MErge
- Loading branch information
Showing
16 changed files
with
564 additions
and
51 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package xzc | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
|
||
"github.com/martinboehm/btcd/chaincfg/chainhash" | ||
"github.com/martinboehm/btcd/wire" | ||
) | ||
|
||
// ZcoinMsgTx encapsulate zcoin tx and extra | ||
type ZcoinMsgTx struct { | ||
wire.MsgTx | ||
Extra []byte | ||
} | ||
|
||
// TxHash calculate hash of transaction | ||
func (msg *ZcoinMsgTx) TxHash() chainhash.Hash { | ||
extraSize := uint64(len(msg.Extra)) | ||
sizeOfExtraSize := 0 | ||
if extraSize != 0 { | ||
sizeOfExtraSize = wire.VarIntSerializeSize(extraSize) | ||
} | ||
|
||
// Original payload | ||
buf := bytes.NewBuffer(make([]byte, 0, | ||
msg.SerializeSizeStripped()+sizeOfExtraSize+len(msg.Extra))) | ||
_ = msg.SerializeNoWitness(buf) | ||
|
||
// Extra payload | ||
if extraSize != 0 { | ||
wire.WriteVarInt(buf, 0, extraSize) | ||
buf.Write(msg.Extra) | ||
} | ||
|
||
return chainhash.DoubleHashH(buf.Bytes()) | ||
} | ||
|
||
// XzcDecode to decode bitcoin tx and extra | ||
func (msg *ZcoinMsgTx) XzcDecode(r io.Reader, pver uint32, enc wire.MessageEncoding) error { | ||
if err := msg.MsgTx.BtcDecode(r, pver, enc); err != nil { | ||
return err | ||
} | ||
|
||
// extra | ||
version := uint32(msg.Version) | ||
txVersion := version & 0xffff | ||
txType := (version >> 16) & 0xffff | ||
if txVersion == 3 && txType != 0 { | ||
|
||
extraSize, err := wire.ReadVarInt(r, 0) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
msg.Extra = make([]byte, extraSize) | ||
_, err = io.ReadFull(r, msg.Extra[:]) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.