/
oracle.go
127 lines (110 loc) · 2.94 KB
/
oracle.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package scaffolder
import (
"context"
"fmt"
"github.com/gobuffalo/genny/v2"
"github.com/ignite/cli/ignite/pkg/cache"
"github.com/ignite/cli/ignite/pkg/cmdrunner"
"github.com/ignite/cli/ignite/pkg/cmdrunner/step"
"github.com/ignite/cli/ignite/pkg/gocmd"
"github.com/ignite/cli/ignite/pkg/multiformatname"
"github.com/ignite/cli/ignite/pkg/placeholder"
"github.com/ignite/cli/ignite/pkg/xgenny"
"github.com/ignite/cli/ignite/templates/ibc"
)
const (
bandImport = "github.com/bandprotocol/bandchain-packet"
bandVersion = "v0.0.2"
)
// OracleOption configures options for AddOracle.
type OracleOption func(*oracleOptions)
type oracleOptions struct {
signer string
}
// newOracleOptions returns a oracleOptions with default options
//
// Deprecated: This function is no longer maintained.
func newOracleOptions() oracleOptions {
return oracleOptions{
signer: "creator",
}
}
// OracleWithSigner provides a custom signer name for the message
//
// Deprecated: This function is no longer maintained.
func OracleWithSigner(signer string) OracleOption {
return func(m *oracleOptions) {
m.signer = signer
}
}
// AddOracle adds a new BandChain oracle envtest.
//
// Deprecated: This function is no longer maintained.
func (s *Scaffolder) AddOracle(
ctx context.Context,
cacheStorage cache.Storage,
tracer *placeholder.Tracer,
moduleName,
queryName string,
options ...OracleOption,
) (sm xgenny.SourceModification, err error) {
if err := s.installBandPacket(); err != nil {
return sm, err
}
o := newOracleOptions()
for _, apply := range options {
apply(&o)
}
mfName, err := multiformatname.NewName(moduleName, multiformatname.NoNumber)
if err != nil {
return sm, err
}
moduleName = mfName.LowerCase
name, err := multiformatname.NewName(queryName)
if err != nil {
return sm, err
}
if err := checkComponentValidity(s.path, moduleName, name, false); err != nil {
return sm, err
}
mfSigner, err := multiformatname.NewName(o.signer, checkForbiddenOracleFieldName)
if err != nil {
return sm, err
}
// Module must implement IBC
ok, err := isIBCModule(s.path, moduleName)
if err != nil {
return sm, err
}
if !ok {
return sm, fmt.Errorf("the module %s doesn't implement IBC module interface", moduleName)
}
// Generate the packet
var (
g *genny.Generator
opts = &ibc.OracleOptions{
AppName: s.modpath.Package,
AppPath: s.path,
ModulePath: s.modpath.RawPath,
ModuleName: moduleName,
QueryName: name,
MsgSigner: mfSigner,
}
)
g, err = ibc.NewOracle(tracer, opts)
if err != nil {
return sm, err
}
sm, err = xgenny.RunWithValidation(tracer, g)
if err != nil {
return sm, err
}
return sm, finish(ctx, cacheStorage, opts.AppPath, s.modpath.RawPath)
}
// Deprecated: This function is no longer maintained.
func (s Scaffolder) installBandPacket() error {
return cmdrunner.New().
Run(context.Background(),
step.New(step.Exec(gocmd.Name(), "get", gocmd.PackageLiteral(bandImport, bandVersion))),
)
}