예제 #1
0
파일: tx.go 프로젝트: haowang1013/kaiju
// Returns the data size of serialized Tx
func (t *Tx) ByteSize() int {
	opLen := 32 /*OutPoint.Hash*/ + 4 /*OutPoint.Index*/
	totalLen := 4                     // Version
	totalLen += klib.VarUint(len(t.TxIns)).ByteSize()
	for _, txin := range t.TxIns {
		totalLen += opLen
		totalLen += klib.VarString(txin.SigScript).ByteSize()
		totalLen += 4 // Sequence
	}
	totalLen += klib.VarUint(len(t.TxOuts)).ByteSize()
	for _, txout := range t.TxOuts {
		totalLen += 8 // Value
		totalLen += klib.VarString(txout.PKScript).ByteSize()
	}
	totalLen += 4 // LockTime
	return totalLen
}
예제 #2
0
func (d *collisionData) toBytes() []byte {
	s := d.toSlice()
	var p bytes.Buffer
	for _, val := range s {
		p.Write(klib.VarString(val).Bytes())
	}
	return p.Bytes()
}
예제 #3
0
파일: tx.go 프로젝트: haowang1013/kaiju
// Returns the serialized byte of the Tx
func (t *Tx) Bytes() []byte {
	p := new(bytes.Buffer)
	binary.Write(p, binary.LittleEndian, t.Version)

	p.Write(klib.VarUint(len(t.TxIns)).Bytes())
	for _, txin := range t.TxIns {
		binary.Write(p, binary.LittleEndian, txin.PreviousOutput)
		p.Write(klib.VarString(txin.SigScript).Bytes())
		binary.Write(p, binary.LittleEndian, txin.Sequence)
	}
	p.Write(klib.VarUint(len(t.TxOuts)).Bytes())
	for _, txout := range t.TxOuts {
		binary.Write(p, binary.LittleEndian, txout.Value)
		p.Write(klib.VarString(txout.PKScript).Bytes())
	}
	binary.Write(p, binary.LittleEndian, t.LockTime)
	return p.Bytes()
}
예제 #4
0
func NewLocalVersionMsg(addrRecv *PeerInfo) *Message_version {
	addrFrom := NewPeerInfo() // We don't accept incoming connections
	return &Message_version{
		kaiju.ProtocolVersion,
		kaiju.NodeServices,
		time.Now().Unix(),
		addrRecv,
		addrFrom,
		kaiju.NounceInVersionMsg,
		klib.VarString(kaiju.UserAgent),
		1,
		0,
	}
}