// Reset this Factoid state to an empty state at a dbheight following the // given dbstate. func (fs *FactoidState) Reset(dbstate *DBState) { ht := dbstate.DirectoryBlock.GetHeader().GetDBHeight() if fs.DBHeight > ht+1 { fs.DBHeight = ht dbstate := fs.State.DBStates.Get(int(fs.DBHeight)) fBlock := factoid.NewFBlock(dbstate.FactoidBlock) fBlock.SetExchRate(dbstate.FinalExchangeRate) fs.CurrentBlock = fBlock t := factoid.GetCoinbase(dbstate.NextTimestamp) fs.State.FactoshisPerEC = dbstate.FinalExchangeRate fs.State.LeaderTimestamp = dbstate.NextTimestamp err := fs.CurrentBlock.AddCoinbase(t) if err != nil { panic(err.Error()) } fs.UpdateTransaction(true, t) fs.DBHeight++ } }
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 }
func (fs *FactoidState) GetCurrentBlock() interfaces.IFBlock { if fs.CurrentBlock == nil { fs.CurrentBlock = factoid.NewFBlock(nil) fs.CurrentBlock.SetExchRate(fs.State.GetFactoshisPerEC()) fs.CurrentBlock.SetDBHeight(fs.DBHeight) t := factoid.GetCoinbase(fs.State.GetLeaderTimestamp()) err := fs.CurrentBlock.AddCoinbase(t) if err != nil { panic(err.Error()) } fs.UpdateTransaction(true, t) } return fs.CurrentBlock }
// End of Block means packing the current block away, and setting // up the next func (fs *FactoidState) ProcessEndOfBlock(state interfaces.IState) { if fs.GetCurrentBlock() == nil { panic("Invalid state on initialization") } // outstr := fs.CurrentBlock.String() // if len(outstr) < 10000 { // if state.GetOut() { // fs.State.Println("888888888888888888 ",fs.State.GetFactomNodeName()," 8888888888888888888") // fs.State.Println(outstr) // } // } fBlock := factoid.NewFBlock(fs.CurrentBlock) fBlock.SetExchRate(fs.State.GetFactoshisPerEC()) fs.CurrentBlock = fBlock leaderTS := fs.State.GetLeaderTimestamp() if leaderTS.GetTimeMilli() == 0 { fmt.Println("WELL WELL WELLLLL", fs.State.FactomNodeName, fs.State.GetDBHeightComplete()) } t := factoid.GetCoinbase(leaderTS) dbstate := fs.State.DBStates.Get(int(fs.DBHeight)) if dbstate != nil { dbstate.FinalExchangeRate = fs.State.GetFactoshisPerEC() dbstate.NextTimestamp = leaderTS } err := fs.CurrentBlock.AddCoinbase(t) if err != nil { panic(err.Error()) } fs.UpdateTransaction(true, t) fs.DBHeight++ }