Skip to content

Commit 2bc98c7

Browse files
committed
all contracts
1 parent c379b4f commit 2bc98c7

File tree

9 files changed

+66
-58
lines changed

9 files changed

+66
-58
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ FROM golang:1.17
22
RUN mkdir /app
33
ADD . /app
44
WORKDIR /app
5-
RUN go build -o main .
6-
CMD ["/app/main"]
5+
RUN go build -o ff .
6+
CMD ["/app/ff"]

docker-compose.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ services:
44
ff:
55
build:
66
context: ./
7-
dockerfile: Dockerfile
8-
container_name: ff
7+
dockerfile: Dockerfile
98
ports:
109
- '2112:2112'
1110

@@ -23,8 +22,7 @@ services:
2322
- 9090:9090
2423

2524
grafana:
26-
image: grafana/grafana:latest
27-
container_name: grafana
25+
image: grafana/grafana:latest
2826
ports:
2927
- "3000:3000"
3028
volumes:

follower/cadence.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package follower
2+
3+
import (
4+
"regexp"
5+
)
6+
7+
var knownImports = map[string]string{
8+
"c1e4f4f4c4257510": "TopShotMarket",
9+
"329feb3ab062d289": "RaceDay",
10+
"64f83c60989ce555": "ChainmonstersMarket",
11+
"3c5959b568896393": "FUSD",
12+
}
13+
14+
type CadenceImport struct {
15+
Contract string
16+
Address string
17+
}
18+
19+
func GetImports(code string) []CadenceImport {
20+
r, _ := regexp.Compile("import (?P<Contract>\\w*) from 0x(?P<Address>[0-9a-f]*)")
21+
matches := r.FindAllStringSubmatch(code, -1)
22+
23+
var returnList []CadenceImport
24+
for i := range matches {
25+
returnList = append(returnList, CadenceImport{
26+
Contract: matches[i][1],
27+
Address: matches[i][2],
28+
})
29+
}
30+
31+
return returnList
32+
}

follower/follower.go

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"strings"
77
"tehranifar/fflow/storage"
8-
"tehranifar/fflow/tags"
98
"time"
109

1110
"github.com/onflow/flow-go-sdk"
@@ -75,25 +74,33 @@ func (f *Follower) processBlock(ctx context.Context, block *flow.Block) error {
7574
}
7675

7776
txError := ""
77+
failed := false
7878
if txRes.Error != nil {
7979
txError = txRes.Error.Error()
80+
failed = true
8081
}
8182

82-
importTags := tags.ProcessImportTags(string(tx.Script))
83-
for _, tag := range importTags {
84-
failed := false
85-
if txRes.Error != nil {
86-
failed = true
87-
}
88-
RegisterTagMetrics(tag, failed)
83+
var tagList []string
84+
CadenceImports := GetImports(string(tx.Script))
85+
for _, imp := range CadenceImports {
86+
RegisterImportMetrics(imp, failed)
87+
tagList = append(tagList, imp.Contract)
88+
tagList = append(tagList, imp.Address)
8989
}
90-
dbTags := strings.Join(importTags, ",")
90+
dbImportTags := strings.Join(tagList, ",")
91+
92+
var authAddressList []string
93+
for _, auth := range tx.Authorizers {
94+
authAddressList = append(authAddressList, auth.String())
95+
}
96+
dbAuthorizer := strings.Join(authAddressList, ",")
9197

9298
f.storage.Save(&storage.Transaction{
93-
Tx: txID.String(),
94-
Code: string(tx.Script),
95-
Error: txError,
96-
Tags: dbTags,
99+
Authorizers: dbAuthorizer,
100+
Tx: txID.String(),
101+
Code: string(tx.Script),
102+
Error: txError,
103+
ImportTags: dbImportTags,
97104
})
98105

99106
}

follower/metrics.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ var (
1212
Name: "import_tag_total",
1313
Help: "The total number of observed known imports",
1414
}, []string{
15-
"contract", "failed",
15+
"contract", "address", "failed",
1616
})
1717
)
1818

19-
func RegisterTagMetrics(contract string, failed bool) {
20-
tagsObserved.WithLabelValues(contract, strconv.FormatBool(failed)).Inc()
19+
func RegisterImportMetrics(imp CadenceImport, failed bool) {
20+
tagsObserved.WithLabelValues(imp.Contract, imp.Address, strconv.FormatBool(failed)).Inc()
2121
}

main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
//
1818
//
1919
// - deploy to ec2
20-
// - more contracts
2120
// - create panels
2221
// - event listener (from tx list)
2322
// - event metrics

prometheus/prometheus.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
global:
2-
scrape_interval: 1s
3-
evaluation_interval: 1s
2+
scrape_interval: 15s
3+
evaluation_interval: 15s
44

55
scrape_configs:
66
- job_name: prometheus

storage/store.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ type Storage struct {
1616
type Transaction struct {
1717
gorm.Model
1818

19-
Tx string
20-
Code string
21-
Error string
22-
Tags string
19+
Authorizers string
20+
Tx string
21+
Code string
22+
Error string
23+
ImportTags string
2324
}
2425

2526
func NewSqliteStorage() (Provider, error) {

tags/import_tag.go

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)