Archived
2
0
This repository has been archived on 2023-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
kerma/models/chaintip.go
2023-03-02 15:28:43 +01:00

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
}