-
Notifications
You must be signed in to change notification settings - Fork 12
/
blob.go
73 lines (63 loc) · 2.81 KB
/
blob.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// SPDX-FileCopyrightText: 2023 PK Lab AG <contact@pklab.io>
// SPDX-License-Identifier: MIT
package responses
import (
"encoding/base64"
"net/http"
"time"
"github.com/celenium-io/celestia-indexer/internal/storage"
"github.com/celenium-io/celestia-indexer/pkg/node/types"
pkgTypes "github.com/celenium-io/celestia-indexer/pkg/types"
)
type Blob struct {
Namespace string `example:"AAAAAAAAAAAAAAAAAAAAAAAAAAAAs2bWWU6FOB0=" format:"base64" json:"namespace" swaggertype:"string"`
Data string `example:"b2sgZGVtbyBkYQ==" format:"base64" json:"data" swaggertype:"string"`
ShareVersion int `example:"0" format:"integer" json:"share_version" swaggertype:"integer"`
Commitment string `example:"vbGakK59+Non81TE3ULg5Ve5ufT9SFm/bCyY+WLR3gg=" format:"base64" json:"commitment" swaggertype:"string"`
ContentType string `example:"image/png" format:"string" json:"content_type" swaggertype:"string"`
}
func NewBlob(blob types.Blob) (Blob, error) {
b := Blob{
Namespace: blob.Namespace,
Data: blob.Data,
Commitment: blob.Commitment,
ShareVersion: blob.ShareVersion,
}
data, err := base64.StdEncoding.DecodeString(blob.Data)
if err != nil {
return b, err
}
b.ContentType = http.DetectContentType(data)
return b, nil
}
type BlobLog struct {
Commitment string `example:"vbGakK59+Non81TE3ULg5Ve5ufT9SFm/bCyY+WLR3gg=" format:"base64" json:"commitment" swaggertype:"string"`
Size int64 `example:"10" format:"integer" json:"size" swaggertype:"integer"`
Height pkgTypes.Level `example:"100" format:"integer" json:"height" swaggertype:"integer"`
Time time.Time `example:"2023-07-04T03:10:57+00:00" format:"date-time" json:"time" swaggertype:"string"`
Signer string `example:"celestia1jc92qdnty48pafummfr8ava2tjtuhfdw774w60" format:"string" json:"signer,omitempty" swaggertype:"string"`
ContentType string `example:"image/png" format:"string" json:"content_type" swaggertype:"string"`
Namespace *Namespace `json:"namespace,omitempty"`
Tx *Tx `json:"tx,omitempty"`
}
func NewBlobLog(blob storage.BlobLog) BlobLog {
b := BlobLog{
Commitment: blob.Commitment,
Size: blob.Size,
Height: blob.Height,
Time: blob.Time,
ContentType: blob.ContentType,
}
if blob.Namespace != nil {
ns := NewNamespace(*blob.Namespace)
b.Namespace = &ns
}
if blob.Signer != nil {
b.Signer = blob.Signer.Address
}
if blob.Tx != nil {
tx := NewTx(*blob.Tx)
b.Tx = &tx
}
return b
}