-
Notifications
You must be signed in to change notification settings - Fork 17
/
script.go
65 lines (56 loc) · 1.57 KB
/
script.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
package contract
import (
"bytes"
"github.com/baking-bad/bcdhub/internal/models/types"
"github.com/lib/pq"
"github.com/uptrace/bun"
)
// Scripts -
type Script struct {
bun.BaseModel `bun:"scripts"`
ID int64 `bun:"id,pk,notnull,autoincrement"`
Level int64 `bun:"level"`
Hash string `bun:"hash,type:text"`
Code []byte `bun:",type:bytea"`
Parameter []byte `bun:",type:bytea"`
Storage []byte `bun:",type:bytea"`
Views []byte `bun:",type:bytea"`
Entrypoints pq.StringArray `bun:",type:text[]"`
FailStrings pq.StringArray `bun:",type:text[]"`
Annotations pq.StringArray `bun:",type:text[]"`
Hardcoded pq.StringArray `bun:",type:text[]"`
Tags types.Tags
Constants []GlobalConstant `bun:"m2m:script_constants,join:Script=GlobalConstant"`
}
// GetID -
func (s *Script) GetID() int64 {
return s.ID
}
func (Script) TableName() string {
return "scripts"
}
// Full -
func (s *Script) Full() ([]byte, error) {
var buf bytes.Buffer
buf.WriteString(`[{"prim":"parameter","args":`)
if _, err := buf.Write(s.Parameter); err != nil {
return nil, err
}
buf.WriteString(`},{"prim":"storage","args":`)
if _, err := buf.Write(s.Storage); err != nil {
return nil, err
}
buf.WriteString(`},{"prim":"code","args":`)
if _, err := buf.Write(s.Code); err != nil {
return nil, err
}
buf.WriteByte('}')
if len(s.Views) > 2 {
buf.WriteByte(',')
if _, err := buf.Write(s.Views[1 : len(s.Views)-1]); err != nil {
return nil, err
}
}
buf.WriteByte(']')
return buf.Bytes(), nil
}