1 package btcwire
2 3 import (
4 "git.smesh.lol/nostrino/pkg/crypto/chainhash"
5 )
6 7 // Tx is a raw transaction. This package does not parse transactions: the
8 // payload is carried verbatim, which is all a compact-filter light client
9 // needs to relay or hash it.
10 type Tx struct {
11 // Raw is the serialized transaction, without the frame header.
12 Raw []byte
13 }
14 15 // EncodePayload returns the raw transaction bytes. The result aliases Raw.
16 func (t *Tx) EncodePayload() ([]byte, error) {
17 return t.Raw, nil
18 }
19 20 // DecodePayload stores the raw transaction bytes. The stored slice aliases b.
21 func (t *Tx) DecodePayload(b []byte) error {
22 t.Raw = b
23 return nil
24 }
25 26 // TxID returns SHA256d of the raw transaction, in internal byte order. For a
27 // transaction that spends no witness data the txid and wtxid are equal.
28 func (t *Tx) TxID() chainhash.Hash {
29 return chainhash.DoubleHashH(t.Raw)
30 }
31