Esempio n. 1
0
func TestMsgACK(t *testing.T) {
	t.Log("\nTestAck===========================================================================")
	ack := wire.NewMsgAcknowledgement(1, 2, nil, wire.END_MINUTE_10)

	// Sign the ack using server private keys
	b, _ := ack.GetBinaryForSignature()
	serverPrivKey, err := common.NewPrivateKeyFromHex("07c0d52cb74f4ca3106d80c4a70488426886bccc6ebc10c6bafb37bf8a65f4c38cee85c62a9e48039d4ac294da97943c2001be1539809ea5f54721f0c5477a0a")
	plMgr := consensus.NewProcessListMgr(1, 1, 10, serverPrivKey)
	ack.Signature = *plMgr.SignAck(b).Sig

	buf := bytes.Buffer{}
	err = ack.BtcEncode(&buf, 1)
	if err != nil {
		t.Errorf("Error:", err)
	}

	b1 := buf.Bytes()
	err = ack.BtcDecode(&buf, 1)

	buf2 := bytes.Buffer{}
	err = ack.BtcEncode(&buf2, 1)
	if err != nil {
		t.Errorf("Error:", err)
	}

	b2 := buf2.Bytes()

	if bytes.Compare(b1, b2) != 0 {
		t.Errorf("Invalid output")
	}

}
Esempio n. 2
0
// Create a new process list item and add it to the MyProcessList
func (plMgr *ProcessListMgr) AddMyProcessListItem(msg wire.FtmInternalMsg, hash *wire.ShaHash, msgType byte) (ack *wire.MsgAcknowledgement, err error) {

	ack = wire.NewMsgAcknowledgement(plMgr.NextDBlockHeight, uint32(plMgr.MyProcessList.nextIndex), hash, msgType)
	// Sign the ack using server private keys
	bytes, _ := ack.GetBinaryForSignature()
	ack.Signature = *plMgr.SignAck(bytes).Sig

	plMgr.MyProcessList.nextIndex++

	plItem := &ProcessListItem{
		Ack:     ack,
		Msg:     msg,
		MsgHash: hash,
	}
	plMgr.MyProcessList.AddToProcessList(plItem)

	return ack, nil
}