-
Notifications
You must be signed in to change notification settings - Fork 0
/
embed.go
37 lines (31 loc) · 893 Bytes
/
embed.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
package contracts
import (
"bytes"
"embed"
"text/template"
)
//go:embed *.cdc
var Cdc embed.FS
// Tmpl ready to be used for execute
var Tmpl *template.Template
func init() {
Tmpl, _ = template.ParseFS(Cdc, "*.cdc")
}
// helper struct to include variables used in cdc template
type Val struct {
FungibleTokenAddr, BridgeAddr, PbAddr, PbPeggedAddr, DelayedTransferAddr, VolumeControlAddr string
// to deploy different PegToken.cdc contracts, eg. WETH, USDT, replace in PegToken.cdc
TokenName string
// FTMinterBurner, needed by PegBridge and PegToken
FTMBAddr string
}
// name is cdc file name like get_balance.cdc, data is struct with fields for template variable
// return replaced string
func RunTmpl(name string, data interface{}) (string, error) {
var b bytes.Buffer
err := Tmpl.Lookup(name).Execute(&b, data)
if err != nil {
return "", err
}
return b.String(), nil
}