Beispiel #1
0
//TODO:test
func (t *Tx) Len() int {
	tic := mymath.VarInt2HexRev(t.TxInCount)  //TODO: double check if it is Rev or not
	toc := mymath.VarInt2HexRev(t.TxOutCount) //TODO: double check if it is Rev or not

	totalLen := 0
	totalLen += len(t.Version)
	totalLen += len(tic)
	for i := 0; i < len(t.TxIn); i++ { //TODO:check if the pointer is working
		totalLen += t.TxIn[i].Len()
	}
	totalLen += len(toc)
	for i := 0; i < len(t.TxOut); i++ { //TODO:check if the pointer is working
		totalLen += t.TxOut[i].Len()
	}
	totalLen += len(t.LockTime)
	return totalLen
}
Beispiel #2
0
//TODO:test
func (t *Tx) Compile() []byte {

	tic := mymath.VarInt2HexRev(t.TxInCount)  //TODO: double check if it is Rev or not
	toc := mymath.VarInt2HexRev(t.TxOutCount) //TODO: double check if it is Rev or not

	totalLen := 0
	totalLen += len(t.Version)
	totalLen += len(tic)
	for i := 0; i < len(t.TxIn); i++ { //TODO:check if the pointer is working
		totalLen += t.TxIn[i].Len()
	}
	totalLen += len(toc)
	for i := 0; i < len(t.TxOut); i++ { //TODO:check if the pointer is working
		totalLen += t.TxOut[i].Len()
	}
	totalLen += len(t.LockTime)

	answer := make([]byte, totalLen)

	iterator := 0
	copy(answer[iterator:], t.Version[:])
	iterator += len(t.Version)
	copy(answer[iterator:], tic)
	iterator += len(tic)
	for i := 0; i < len(t.TxIn); i++ { //TODO:check if the pointer is working
		tmp := t.TxIn[i].Compile()[:]
		copy(answer[iterator:], tmp)
		iterator += len(tmp)
	}
	copy(answer[iterator:], toc)
	iterator += len(toc)
	for i := 0; i < len(t.TxOut); i++ { //TODO:check if the pointer is working
		tmp := t.TxOut[i].Compile()[:]
		copy(answer[iterator:], tmp)
		iterator += len(tmp)
	}
	copy(answer[iterator:], t.LockTime[:])

	return answer
}
Beispiel #3
0
//TODO: test
func (gh *GetHeaders) Compile() []byte {
	sc := mymath.VarInt2HexRev(gh.StartCount) //TODO: double check if it is Rev or not
	answer := make([]byte, len(sc)+len(gh.HashStart)+len(gh.HashStop))

	iterator := 0
	copy(answer[iterator:], sc)
	iterator += len(sc)
	copy(answer[iterator:], gh.HashStart[:])
	iterator += len(gh.HashStart)
	copy(answer[iterator:], gh.HashStop[:])

	return answer
}
Beispiel #4
0
//TODO:test
func (to *TxOut) Compile() []byte {
	vi := mymath.VarInt2HexRev(to.PkScriptLength) //TODO: check if Rev or not

	answer := make([]byte, len(to.Value)+len(vi)+len(to.PkScript))

	iterator := 0
	copy(answer[iterator:], to.Value[:])
	iterator += len(to.Value)
	copy(answer[iterator:], vi)
	iterator += len(vi)
	copy(answer[iterator:], to.PkScript)

	return answer
}
Beispiel #5
0
//TODO: double check if 36 is really the answer
func (i *Inv) Compile() []byte {
	vi := mymath.VarInt2HexRev(i.Count) //TODO: check if Rev or not

	answer := make([]byte, len(vi)+36*len(i.Inventory))

	iterator := 0
	copy(answer[iterator:], vi)
	iterator += len(vi)
	for j := 0; j < len(i.Inventory); j++ {
		copy(answer[iterator:], i.Inventory[j].Compile())
		iterator += 34
	}

	return answer
}
Beispiel #6
0
func (hs *Headers) Compile() []byte {

	vi := mymath.VarInt2HexRev(hs.Count) //TODO: check if Rev or not

	answer := make([]byte, len(vi)+81*len(hs.Headers)) //TODO: double check if it is 81

	iterator := 0
	copy(answer[iterator:], vi)
	iterator += len(vi)
	for i := 0; i < len(hs.Headers); i++ {
		copy(answer[iterator:], hs.Headers[i].Compile())
		iterator += 81
	}

	return answer
}
Beispiel #7
0
//TODO:test
func (ti *TxIn) Compile() []byte {
	sl := mymath.VarInt2HexRev(ti.ScriptLength) //TODO: check if Rev or not
	po := ti.PreviousOutput.Compile()

	answer := make([]byte, len(po)+len(sl)+len(ti.SignatureScript)+len(ti.Sequence))

	iterator := 0
	copy(answer[iterator:], po)
	iterator += len(po)
	copy(answer[iterator:], sl)
	iterator += len(sl)
	copy(answer[iterator:], ti.SignatureScript[:])
	iterator += len(ti.SignatureScript)
	copy(answer[iterator:], ti.Sequence[:])

	return answer
}
Beispiel #8
0
//TODO: test
func (gb *GetBlocks) Compile() []byte {

	sc := mymath.VarInt2HexRev(gb.StartCount) //TODO: double check if it is Rev or not
	answer := make([]byte, len(gb.Version)+len(sc)+32*len(gb.BlockLocatorHashes)+len(gb.HashStop))

	iterator := 0
	copy(answer[iterator:], gb.Version[:])
	iterator += len(gb.Version)
	copy(answer[iterator:], sc)
	iterator += len(sc)
	for i := 0; i < len(gb.BlockLocatorHashes); i++ {
		tmp := gb.BlockLocatorHashes[i]
		copy(answer[iterator:], tmp[:])
		iterator += len(tmp)
	}

	copy(answer[iterator:], gb.HashStop[:])

	return answer
}
Beispiel #9
0
func (b *Block) Compile() []byte {
	vi := mymath.VarInt2HexRev(b.TxnCount) //TODO: check if Rev or not

	totalLen := len(b.Version) + len(b.PrevBlock) + len(b.MerkleRoot) + len(b.Timestamp) + len(b.Bits) + len(b.Nonce) + len(vi)

	for i := 0; i < len(b.Txns); i++ { //TODO:check if the pointer is working
		totalLen += b.Txns[i].Len()
	}

	answer := make([]byte, totalLen)

	iterator := 0
	copy(answer[iterator:], b.Version[:])
	iterator += len(b.Version)
	copy(answer[iterator:], b.PrevBlock[:])
	iterator += len(b.PrevBlock)
	copy(answer[iterator:], b.MerkleRoot[:])
	iterator += len(b.MerkleRoot)
	copy(answer[iterator:], b.Timestamp[:])
	iterator += len(b.Timestamp)
	copy(answer[iterator:], b.Bits[:])
	iterator += len(b.Bits)
	copy(answer[iterator:], b.Nonce[:])
	iterator += len(b.Nonce)
	copy(answer[iterator:], vi[:])
	iterator += len(vi)

	for i := 0; i < len(b.Txns); i++ { //TODO:check if the pointer is working
		tmp := b.Txns[i].Compile()[:]
		//log.Printf("%X - tx", tmp)
		copy(answer[iterator:], tmp)
		iterator += len(tmp)
	}

	return answer

}