package models

type RaspConfig struct {
	//Model
	Height   int64 `json:"height"`
	Config   string `json:"config";gorm:"PRIMARY_KEY"`
}

// GetHeight get lastheight in chain33
func GetHeight() (int64, error) {
	var rasp RaspConfig
	err := db.Model(&RaspConfig{}).Where("config = ?","height").First(&rasp).Error
	if err != nil  {
		//if err == gorm.ErrRecordNotFound {
		//	return 0, err
		//}
		return 0,err
	}
	return rasp.Height, nil
}

// EditArticle modify a single article
func UpdateHeight(height int64) error {
	if err := db.Model(&RaspConfig{}).Update("Height",height).Error; err != nil {
		return err
	}

	return nil
}

// AddArticle add a single article
func InitHeight() error {
	config := RaspConfig{
		Height:         0,
		Config:      "height",
	}
	if err := db.Create(&config).Error; err != nil {
		return err
	}
	return nil
}


