47 lines
902 B
Go
47 lines
902 B
Go
// Package models provides the models for the KermaGo application
|
|
package models
|
|
|
|
import (
|
|
"github.com/docker/go/canonical/json"
|
|
)
|
|
|
|
/*
|
|
A Chaintip is an object that has a type "chaintip" and a block ID
|
|
*/
|
|
type Chaintip struct {
|
|
Type string `json:"type" binding:"required"`
|
|
BlockID string `json:"blockid" binding:"required"`
|
|
}
|
|
|
|
/*
|
|
Construct creates a new Chaintip object for this instance
|
|
*/
|
|
func (c *Chaintip) Construct(bid string) {
|
|
c.Type = "chaintip"
|
|
c.BlockID = bid
|
|
}
|
|
|
|
/*
|
|
MarshalJson returns the canonical json of the chaintip object
|
|
*/
|
|
func (c *Chaintip) MarshalJson() ([]byte, error) {
|
|
return json.MarshalCanonical(c)
|
|
}
|
|
|
|
/*
|
|
UnmarshalJSON returns a new Chaintip object from a byte array
|
|
*/
|
|
func (c *Chaintip) UnmarshalJSON(data []byte) error {
|
|
if len(data) == 0 {
|
|
return nil
|
|
}
|
|
|
|
type tmp Chaintip
|
|
err := json.Unmarshal(data, (*tmp)(c))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|