Example #1
0
// NewTxRecordFromMsgTx creates a new transaction record that may be inserted
// into the store.
func NewTxRecordFromMsgTx(msgTx *wire.MsgTx, received time.Time) (*TxRecord, error) {
	buf := bytes.NewBuffer(make([]byte, 0, msgTx.SerializeSize()))
	err := msgTx.Serialize(buf)
	if err != nil {
		str := "failed to serialize transaction"
		return nil, storeError(ErrInput, str, err)
	}
	rec := &TxRecord{
		MsgTx:        *msgTx,
		Received:     received,
		SerializedTx: buf.Bytes(),
	}
	copy(rec.Hash[:], wire.DoubleSha256(rec.SerializedTx))
	return rec, nil
}
Example #2
0
func equalTxs(t *testing.T, got, exp *wire.MsgTx) {
	var bufGot, bufExp bytes.Buffer
	err := got.Serialize(&bufGot)
	if err != nil {
		t.Fatal(err)
	}
	err = exp.Serialize(&bufExp)
	if err != nil {
		t.Fatal(err)
	}
	if !bytes.Equal(bufGot.Bytes(), bufExp.Bytes()) {
		t.Errorf("Found unexpected wire.MsgTx:")
		t.Errorf("Got: %v", got)
		t.Errorf("Expected: %v", exp)
	}
}