Skip to content

Commit 966eaa3

Browse files
AST
1 parent 3783958 commit 966eaa3

File tree

466 files changed

+709338
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

466 files changed

+709338
-9
lines changed

go.mod

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ module github.com/dipdup-net/go-lib
33
go 1.15
44

55
require (
6+
github.com/ebellocchia/go-base58 v0.1.0
67
github.com/gorilla/websocket v1.4.2
78
github.com/iancoleman/strcase v0.1.3
89
github.com/json-iterator/go v1.1.10
910
github.com/pkg/errors v0.9.1
10-
github.com/sirupsen/logrus v1.4.2
11-
github.com/stretchr/testify v1.5.1
12-
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect
11+
github.com/sergi/go-diff v1.2.0
12+
github.com/sirupsen/logrus v1.7.0
13+
github.com/stretchr/testify v1.7.0
14+
github.com/tidwall/gjson v1.8.1
15+
github.com/yhirose/go-peg v0.0.0-20210119023502-a1af152bac31
16+
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
1317
gopkg.in/yaml.v2 v2.4.0
1418
gorm.io/driver/mysql v1.0.5
1519
gorm.io/driver/postgres v1.0.8

go.sum

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do
77
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
88
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
99
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
10+
github.com/ebellocchia/go-base58 v0.1.0 h1:0w/ODEfZnOPW5KW0QY/Xpb1fxba/BxQJMUa5iYzpljk=
11+
github.com/ebellocchia/go-base58 v0.1.0/go.mod h1:RHE/6C6Ru6YAH9Tc+A9eHQ6ZKEooLC0jw+YLnpt3CAU=
1012
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
1113
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
1214
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
@@ -116,12 +118,16 @@ github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
116118
github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=
117119
github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
118120
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
121+
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
122+
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
119123
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
120124
github.com/shopspring/decimal v0.0.0-20200227202807-02e2044944cc h1:jUIKcSPO9MoMJBbEoyE/RJoE8vz7Mb8AjvifMMwSyvY=
121125
github.com/shopspring/decimal v0.0.0-20200227202807-02e2044944cc/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
122126
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
123127
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
124128
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
129+
github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
130+
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
125131
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
126132
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
127133
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
@@ -130,6 +136,16 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
130136
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
131137
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
132138
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
139+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
140+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
141+
github.com/tidwall/gjson v1.8.1 h1:8j5EE9Hrh3l9Od1OIEDAb7IpezNA20UdRngNAj5N0WU=
142+
github.com/tidwall/gjson v1.8.1/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk=
143+
github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
144+
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
145+
github.com/tidwall/pretty v1.1.0 h1:K3hMW5epkdAVwibsQEfR/7Zj0Qgt4DxtNumTq/VloO8=
146+
github.com/tidwall/pretty v1.1.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
147+
github.com/yhirose/go-peg v0.0.0-20210119023502-a1af152bac31 h1:aNSHj19ft+y9wg2wvOBpNdBSNTa766NrGy4ljTFoYu0=
148+
github.com/yhirose/go-peg v0.0.0-20210119023502-a1af152bac31/go.mod h1:q2QWLflHsZxT6ixYcXveTYicEvxGh5Uv6CnI7f7BfjQ=
133149
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
134150
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
135151
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
@@ -164,6 +180,7 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
164180
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
165181
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
166182
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
183+
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
167184
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
168185
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
169186
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
@@ -188,11 +205,16 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
188205
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
189206
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
190207
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
208+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
209+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
191210
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
192211
gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s=
193212
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
213+
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
194214
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
195215
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
216+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
217+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
196218
gorm.io/driver/mysql v1.0.5 h1:WAAmvLK2rG0tCOqrf5XcLi2QUwugd4rcVJ/W3aoon9o=
197219
gorm.io/driver/mysql v1.0.5/go.mod h1:N1OIhHAIhx5SunkMGqWbGFVeh4yTNWKmMo1GOAsohLI=
198220
gorm.io/driver/postgres v1.0.8 h1:PAgM+PaHOSAeroTjHkCHCBIHHoBIf9RgPWGo8dF2DA8=

node/data.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,8 @@ type HeadMetadata struct {
231231
Cycle uint64 `json:"cycle,omitempty"`
232232
} `json:"balance_updates"`
233233
}
234+
235+
// IsManager -
236+
func IsManager(kind string) bool {
237+
return kind == KindDelegation || kind == KindOrigination || kind == KindReveal || kind == KindTransaction
238+
}

tools/ast/address.go

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package ast
2+
3+
import (
4+
"strings"
5+
6+
"github.com/dipdup-net/go-lib/tools/base"
7+
"github.com/dipdup-net/go-lib/tools/consts"
8+
"github.com/dipdup-net/go-lib/tools/forge"
9+
)
10+
11+
//
12+
// Address
13+
//
14+
15+
// Address -
16+
type Address struct {
17+
Default
18+
}
19+
20+
// NewAddress -
21+
func NewAddress(depth int) *Address {
22+
return &Address{
23+
Default: NewDefault(consts.ADDRESS, 0, depth),
24+
}
25+
}
26+
27+
// ToBaseNode -
28+
func (a *Address) ToBaseNode(optimized bool) (*base.Node, error) {
29+
val := a.Value.(string)
30+
if a.ValueKind == valueKindBytes {
31+
return toBaseNodeBytes(val), nil
32+
}
33+
if optimized {
34+
value, err := forge.Contract(val)
35+
if err != nil {
36+
return nil, err
37+
}
38+
return toBaseNodeBytes(value), nil
39+
}
40+
return toBaseNodeString(val), nil
41+
}
42+
43+
// ToMiguel -
44+
func (a *Address) ToMiguel() (*MiguelNode, error) {
45+
name := a.GetTypeName()
46+
var value string
47+
if a.Value != nil {
48+
value = a.Value.(string)
49+
if a.ValueKind == valueKindBytes {
50+
v, err := forge.UnforgeContract(value)
51+
if err != nil {
52+
return nil, err
53+
}
54+
value = v
55+
}
56+
}
57+
return &MiguelNode{
58+
Prim: a.Prim,
59+
Type: strings.ToLower(a.Prim),
60+
Value: value,
61+
Name: &name,
62+
}, nil
63+
}
64+
65+
// GetJSONModel -
66+
func (a *Address) GetJSONModel(model JSONModel) {
67+
if a.Value != nil {
68+
value := a.Value.(string)
69+
if a.ValueKind == valueKindBytes {
70+
v, err := forge.UnforgeContract(value)
71+
if err == nil {
72+
value = v
73+
}
74+
}
75+
model[a.GetName()] = value
76+
} else {
77+
model[a.GetName()] = ""
78+
}
79+
}
80+
81+
// ToJSONSchema -
82+
func (a *Address) ToJSONSchema() (*JSONSchema, error) {
83+
return getAddressJSONSchema(a.Default), nil
84+
}
85+
86+
// Compare -
87+
func (a *Address) Compare(second Comparable) (int, error) {
88+
secondAddress, ok := second.(*Address)
89+
if !ok {
90+
return 0, consts.ErrTypeIsNotComparable
91+
}
92+
if a.Value == secondAddress.Value {
93+
return 0, nil
94+
}
95+
if a.ValueKind == secondAddress.ValueKind {
96+
return strings.Compare(a.Value.(string), secondAddress.Value.(string)), nil
97+
}
98+
return compareNotOptimizedTypes(a.Default, secondAddress.Default, forge.Contract)
99+
}
100+
101+
// Distinguish -
102+
func (a *Address) Distinguish(x Distinguishable) (*MiguelNode, error) {
103+
second, ok := x.(*Address)
104+
if !ok {
105+
return nil, nil
106+
}
107+
if err := a.optimizeStringValue(forge.UnforgeContract); err != nil {
108+
return nil, err
109+
}
110+
if err := second.optimizeStringValue(forge.UnforgeContract); err != nil {
111+
return nil, err
112+
}
113+
return a.Default.Distinguish(&second.Default)
114+
}
115+
116+
// FromJSONSchema -
117+
func (a *Address) FromJSONSchema(data map[string]interface{}) error {
118+
setOptimizedJSONSchema(&a.Default, data, forge.UnforgeContract)
119+
return nil
120+
}
121+
122+
// FindByName -
123+
func (a *Address) FindByName(name string, isEntrypoint bool) Node {
124+
if a.GetName() == name {
125+
return a
126+
}
127+
return nil
128+
}

0 commit comments

Comments
 (0)