Example #1
0
func CreateTestFactoidBlock(prev interfaces.IFBlock) interfaces.IFBlock {
	fBlock := CreateTestFactoidBlockWithCoinbase(prev, NewFactoidAddress(0), DefaultCoinbaseAmount)

	ecTx := new(factoid.Transaction)
	ecTx.AddInput(NewFactoidAddress(0), fBlock.GetExchRate()*100)
	ecTx.AddECOutput(NewECAddress(0), fBlock.GetExchRate()*100)
	ecTx.SetTimestamp(primitives.NewTimestampFromSeconds(60 * 10 * uint32(fBlock.GetDBHeight())))

	fee, err := ecTx.CalculateFee(1000)
	if err != nil {
		panic(err)
	}
	in, err := ecTx.GetInput(0)
	if err != nil {
		panic(err)
	}
	in.SetAmount(in.GetAmount() + fee)

	SignFactoidTransaction(0, ecTx)

	err = fBlock.AddTransaction(ecTx)
	if err != nil {
		panic(err)
	}

	return fBlock
}
Example #2
0
func CreateTestFactoidBlockWithCoinbase(prev interfaces.IFBlock, address interfaces.IAddress, amount uint64) interfaces.IFBlock {
	block := factoid.NewFBlock(prev)
	tx := new(factoid.Transaction)
	tx.AddOutput(address, amount)
	tx.SetTimestamp(primitives.NewTimestampFromSeconds(60 * 10 * uint32(block.GetDBHeight())))
	err := block.AddCoinbase(tx)
	if err != nil {
		panic(err)
	}
	return block
}