2020-03-29 21:32:01 +08:00
|
|
|
package orderplg
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
|
|
|
"plugin"
|
|
|
|
|
|
|
|
"github.com/meshplus/bitxhub/pkg/order"
|
|
|
|
)
|
|
|
|
|
|
|
|
//Load order plugin
|
|
|
|
func New(opts ...order.Option) (order.Order, error) {
|
|
|
|
config, err := order.GenerateConfig(opts...)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
pluginPath := config.PluginPath
|
|
|
|
|
|
|
|
if !filepath.IsAbs(pluginPath) {
|
|
|
|
pluginPath = filepath.Join(config.RepoRoot, pluginPath)
|
|
|
|
}
|
|
|
|
|
|
|
|
p, err := plugin.Open(pluginPath)
|
|
|
|
if err != nil {
|
2020-04-28 17:08:21 +08:00
|
|
|
return nil, fmt.Errorf("plugin open: %s", err)
|
2020-03-29 21:32:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
m, err := p.Lookup("NewNode")
|
|
|
|
if err != nil {
|
2020-04-28 17:08:21 +08:00
|
|
|
return nil, fmt.Errorf("plugin lookup: %s", err)
|
2020-03-29 21:32:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
NewNode, ok := m.(func(...order.Option) (order.Order, error))
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("assert NewOrder error")
|
|
|
|
}
|
|
|
|
return NewNode(opts...)
|
|
|
|
}
|