/
address.go
45 lines (38 loc) · 1.1 KB
/
address.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
package types
import (
"github.com/dave/jennifer/jen"
"github.com/dipdup-net/go-lib/tzkt/data"
)
// Address -
type Address struct{}
// AsField -
func (Address) AsField(name, path string, schema data.JSONSchema, isRequired bool, result *ContractTypeResult) (jen.Code, error) {
tags := map[string]string{
"json": name,
}
if isRequired {
tags["validate"] = TagRequired
}
return jen.Id(fieldName("Address", name)).Add(
jen.Qual("github.com/dipdup-net/go-lib/tools/tezgen", "Address"),
).Tag(tags), nil
}
// AsCode -
func (Address) AsCode(name, path string, schema data.JSONSchema, result *ContractTypeResult) (Code, error) {
typName := result.GetName("Address", name)
return Code{
Statement: jen.Comment(typName).Line().Type().Id(typName).Add(
jen.Qual("github.com/dipdup-net/go-lib/tools/tezgen", "Address"),
).Line(),
Name: typName,
}, nil
}
// AsType -
func (Address) AsType(name, path string, schema data.JSONSchema, result *ContractTypeResult) (Code, error) {
return Code{
Statement: jen.Add(
jen.Qual("github.com/dipdup-net/go-lib/tools/tezgen", "Address"),
),
Name: name,
}, nil
}