Esempio n. 1
0
// End of Block means packing the current block away, and setting
// up the next block.
// this function is to replace the existing function: ProcessEndOfBlock
func (fs *FactoidState) ProcessEndOfBlock2(nextBlkHeight uint32) {
	var hash, hash2 fct.IHash

	if fs.currentBlock != nil { // If no blocks, the current block is nil
		hash = fs.currentBlock.GetHash()
		hash2 = fs.currentBlock.GetLedgerKeyMR()
	}

	fs.currentBlock = block.NewFBlock(fs.GetFactoshisPerEC(), nextBlkHeight)

	t := block.GetCoinbase(fs.GetTimeMilli())
	err := fs.currentBlock.AddCoinbase(t)
	if err != nil {
		panic(err.Error())
	}
	fs.UpdateTransaction(t)

	if hash != nil {
		fs.currentBlock.SetPrevKeyMR(hash.Bytes())
		fs.currentBlock.SetPrevLedgerKeyMR(hash2.Bytes())
	}

	cp.CP.AddUpdate(
		"blockheight", // tag
		"status",      // Category
		fmt.Sprintf("Directory Block Height: %d", nextBlkHeight), // Title
		"", // Msg
		0)

}
Esempio n. 2
0
// End of Block means packing the current block away, and setting
// up the next block.
func (fs *FactoidState) ProcessEndOfBlock() {
	var hash, hash2 fct.IHash

	if fs.GetCurrentBlock() == nil {
		panic("Invalid state on initialization")
	}

	hash = fs.currentBlock.GetHash()
	hash2 = fs.currentBlock.GetLedgerKeyMR()

	fs.PutTransactionBlock(hash, fs.currentBlock)
	fs.PutTransactionBlock(fct.FACTOID_CHAINID_HASH, fs.currentBlock)

	fs.dbheight += 1
	fs.currentBlock = block.NewFBlock(fs.GetFactoshisPerEC(), fs.dbheight)

	t := block.GetCoinbase(fs.GetTimeMilli())
	err := fs.currentBlock.AddCoinbase(t)
	if err != nil {
		panic(err.Error())
	}
	fs.UpdateTransaction(t)

	if hash != nil {
		fs.currentBlock.SetPrevKeyMR(hash.Bytes())
		fs.currentBlock.SetPrevLedgerKeyMR(hash2.Bytes())
	}

	cp.CP.AddUpdate(
		"blockheight", // tag
		"status",      // Category
		fmt.Sprintf("Directory Block Height: %d", fs.GetDBHeight()), // Title
		"", // Msg
		0)
}
Esempio n. 3
0
func Test_create_block(test *testing.T) {
	w := new(wallet.SCWallet) // make me a wallet
	w.Init()
	w.NewSeed([]byte("slfkjasdlfjasflajsfl"))
	scb := block.NewFBlock(1000, 0)
	cb := w.CreateTransaction(uint64(time.Now().UnixNano() / 1000000))
	scb.AddCoinbase(cb)

	for i := 0; i < 3; i++ {
		h0, err := w.GenerateFctAddress([]byte("test "+cv.Itoa(i)+"-0"), 1, 1)
		if err != nil {
			sc.Prtln("Error 1")
			test.Fail()
		}
		h1, err := w.GenerateFctAddress([]byte("test "+cv.Itoa(i)+"-1"), 1, 1)
		if err != nil {
			sc.Prtln("Error 2")
			test.Fail()
		}
		h2, err := w.GenerateFctAddress([]byte("test "+cv.Itoa(i)+"-2"), 1, 1)
		if err != nil {
			sc.Prtln("Error 3")
			test.Fail()
		}
		h3, err := w.GenerateFctAddress([]byte("test "+cv.Itoa(i)+"-3"), 1, 1)
		if err != nil {
			sc.Prtln("Error 4")
			test.Fail()
		}
		h4, err := w.GenerateFctAddress([]byte("test "+cv.Itoa(i)+"-4"), 1, 1)
		if err != nil {
			sc.Prtln("Error 5")
			test.Fail()
		}
		h5, err := w.GenerateFctAddress([]byte("test "+cv.Itoa(i)+"-5"), 1, 1)
		if err != nil {
			sc.Prtln("Error 6")
			test.Fail()
		}

		t := w.CreateTransaction(uint64(time.Now().UnixNano() / 1000000))

		w.AddInput(t, h1, 1000000)
		w.AddInput(t, h2, 1000000)
		w.AddOutput(t, h3, 1000000)
		w.AddOutput(t, h4, 500000)
		w.AddECOutput(t, h5, 500000)
		w.AddInput(t, h0, 0)
		fee, err := t.CalculateFee(1000)
		w.UpdateInput(t, 2, h0, fee)

		signed, err := w.SignInputs(t)
		if err != nil {
			sc.Prtln("Error found: ", err)
			test.Fail()
			return
		}
		if !signed {
			sc.Prtln("Not valid")
			test.Fail()
			return
		}

		err = scb.AddTransaction(t)
		if err != nil {
			sc.Prtln("Error found: ", err)
			test.Fail()
			return
		}
	}
	data, err := scb.MarshalBinary()
	if err != nil {
		fmt.Println(err)
		test.Fail()
		return
	}
	scb2 := new(block.FBlock)
	_, err = scb2.UnmarshalBinaryData(data)

	fmt.Println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n", scb2)

	if err != nil {
		fmt.Println(err)
		test.Fail()
		return
	}
	//sc.Prtln("FIRST\n",scb,"SECOND\n",scb2)
	if scb.IsEqual(scb2) != nil {
		fmt.Println(err)
		test.Fail()
		return
	}

}