-
Notifications
You must be signed in to change notification settings - Fork 3
/
plugins.go
37 lines (29 loc) · 1011 Bytes
/
plugins.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 rosetta
import (
"fmt"
"os"
"plugin"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
)
func LoadPlugin(ir codectypes.InterfaceRegistry, pluginLocation string) (err error) {
pluginPathMain := fmt.Sprintf("./plugins/%s/main.so", pluginLocation)
if _, err := os.Stat(pluginPathMain); os.IsExist(err) {
return fmt.Errorf("plugin file '%s' does not exist %s", pluginPathMain, err.Error())
}
// load module
plug, err := plugin.Open(pluginPathMain)
if err != nil {
return fmt.Errorf("there was an error while opening plugin on %s - %s", pluginPathMain, err.Error())
}
initZone, err := plug.Lookup("InitZone")
if err != nil {
return fmt.Errorf("there was an error while initializing the zone %s", err.Error())
}
initZone.(func())()
registerInterfaces, err := plug.Lookup("RegisterInterfaces")
if err != nil {
return fmt.Errorf("there was an error while registering interfaces %s", err.Error())
}
registerInterfaces.(func(codectypes.InterfaceRegistry))(ir)
return nil
}