2022-11-23 04:06:29 -08:00
|
|
|
// Package observations handle the request of observations data from governor endpoint defined in the api.
|
2022-11-17 07:37:29 -08:00
|
|
|
package observations
|
|
|
|
|
|
|
|
import (
|
2022-12-14 11:26:45 -08:00
|
|
|
"encoding/json"
|
|
|
|
"strconv"
|
2022-11-17 07:37:29 -08:00
|
|
|
"time"
|
2022-11-23 04:06:29 -08:00
|
|
|
|
2023-01-23 06:45:09 -08:00
|
|
|
"github.com/wormhole-foundation/wormhole/sdk/vaa"
|
2022-11-17 07:37:29 -08:00
|
|
|
)
|
|
|
|
|
2022-11-23 04:06:29 -08:00
|
|
|
// ObservationDoc represent an observation document.
|
2022-11-17 07:37:29 -08:00
|
|
|
type ObservationDoc struct {
|
|
|
|
ID string `bson:"_id" json:"id"`
|
|
|
|
Version uint8 `bson:"version" json:"version"`
|
|
|
|
EmitterChain vaa.ChainID `bson:"emitterChain" json:"emitterChain"`
|
|
|
|
EmitterAddr string `bson:"emitterAddr" json:"emitterAddr"`
|
2022-12-14 11:26:45 -08:00
|
|
|
Sequence string `bson:"sequence" json:"sequence"`
|
2023-01-18 07:31:25 -08:00
|
|
|
Hash []byte `bson:"hash" json:"hash"`
|
2022-11-17 07:37:29 -08:00
|
|
|
TxHash []byte `bson:"txHash" json:"txHash"`
|
|
|
|
GuardianAddr string `bson:"guardianAddr" json:"guardianAddr"`
|
|
|
|
Signature []byte `bson:"signature" json:"signature"`
|
2022-11-23 04:06:29 -08:00
|
|
|
UpdatedAt *time.Time `bson:"updatedAt" json:"updatedAt"`
|
|
|
|
IndexedAt *time.Time `bson:"indexedAt" json:"indexedAt"`
|
2022-11-17 07:37:29 -08:00
|
|
|
}
|
2022-12-14 11:26:45 -08:00
|
|
|
|
|
|
|
// MarshalJSON interface implementation for ObservationDoc.
|
|
|
|
func (o *ObservationDoc) MarshalJSON() ([]byte, error) {
|
|
|
|
sequence, err := strconv.ParseUint(o.Sequence, 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
return []byte{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
type Alias ObservationDoc
|
|
|
|
return json.Marshal(&struct {
|
|
|
|
Sequence uint64 `json:"sequence"`
|
|
|
|
*Alias
|
|
|
|
}{
|
|
|
|
Sequence: sequence,
|
|
|
|
Alias: (*Alias)(o),
|
|
|
|
})
|
|
|
|
}
|