Commit 6d5a890a authored by suyanlong's avatar suyanlong

Add evmxgo plugin

parent de3be454
......@@ -96,3 +96,6 @@ check: aligner-check checkgofmt
modmated:
@go list -u -m -json all | go-mod-outdated
proto:
cd proto && protoc --go_out=. ./*.proto --proto_path=.
This diff is collapsed.
package config
import (
"path/filepath"
"strings"
"github.com/spf13/viper"
)
const (
ConfigName = "chain33.toml"
)
type Config struct {
Chain33 Chain33 `toml:"chain33" json:"chain33"`
Services []Service `mapstructure:"services" json:"services"`
}
type Chain33 struct {
Addr string `toml:"addr" json:"addr"`
Name string `toml:"name" json:"name"`
EventFilter string `mapstructure:"event_filter" toml:"event_filter" json:"event_filter"`
PrivateKey string `mapstructure:"private_key" toml:"private_key" json:"private_key"`
TimeoutHeight int64 `mapstructure:"timeout_height" json:"timeout_height"`
ChainID string `mapstructure:"chain_id" json:"chain_id"`
}
type Service struct {
ID string `toml:"id" json:"id"`
Name string `toml:"name" json:"name"`
Type string `toml:"type" json:"type"`
}
func DefaultConfig() *Config {
return &Config{
Chain33: Chain33{
Addr: "40.125.164.122:8801",
Name: "chain33",
},
Services: nil,
}
}
func UnmarshalConfig(configPath string) (*Config, error) {
viper.SetConfigFile(filepath.Join(configPath, ConfigName))
viper.SetConfigType("toml")
viper.AutomaticEnv()
viper.SetEnvPrefix("CHAIN33")
replacer := strings.NewReplacer(".", "_")
viper.SetEnvKeyReplacer(replacer)
if err := viper.ReadInConfig(); err != nil {
return nil, err
}
config := DefaultConfig()
if err := viper.Unmarshal(config); err != nil {
return nil, err
}
return config, nil
}
package main
import (
"fmt"
chain33sdk "gitlab.33.cn/link33/chain33-sdk-go/client"
"gitlab.33.cn/link33/chain33-sdk-go/event"
)
type MessageHandler interface {
HandleMessage(deliveries *event.CCEvent, payload []byte)
}
type Consumer struct {
jsonClient *chain33sdk.JSONClient
meta *ContractMeta
msgH MessageHandler
registration chan<- event.Registration
errCh <-chan error
ctx chan bool
}
func NewConsumer(config *Config, meta *ContractMeta, msgH MessageHandler, ctx chan bool) (*Consumer, error) {
client, err := chain33sdk.NewJSONClient("", config.Chain33.Addr)
if err != nil {
return nil, fmt.Errorf("create chain33 sdk jsonclient fail: %s\n", err)
}
c := &Consumer{
msgH: msgH,
jsonClient: client,
meta: meta,
ctx: ctx,
}
return c, nil
}
// 这里采用笨方法,轮循不断拉取交易去判断
func (c *Consumer) Start() error {
registration, notifier, errCh := c.jsonClient.RegisterTxEvent(0, c.meta.CCID, c.meta.EventFilter)
c.registration = registration
c.errCh = errCh
// todo: add context
go func() {
for {
select {
case ccEvent := <-notifier:
if ccEvent != nil {
c.handle(ccEvent)
}
case err := <-errCh:
fmt.Errorf("have err:", err.Error())
return
case <-c.ctx:
return
}
}
}()
return nil
}
func (c *Consumer) Shutdown() error {
c.registration <- struct{}{}
return nil
}
func (c *Consumer) handle(deliveries *event.CCEvent) {
//t, err := c.jsonClient.QueryTransaction(deliveries.TxID)
//if err != nil {
// return
//}
//var action types.BrokerAction
//if err:=types.Decode(t.Tx.Payload,&action);err !=nil {
// return
//}
//action.GetEmitInterchainEvent()
c.msgH.HandleMessage(deliveries, deliveries.Payload)
}
package main
package event
import (
"fmt"
......
This diff is collapsed.
module gitlab.33.cn/link33/sidecar-client-chain33
go 1.13
go 1.18
replace github.com/33cn/plugin v1.66.3 => /Users/suyanlong/fuzhamei/plugin
require (
github.com/Rican7/retry v0.1.0
github.com/33cn/plugin v1.66.3
github.com/Rican7/retry v0.3.1
github.com/bitly/go-simplejson v0.5.0
github.com/cloudflare/cfssl v0.0.0-20190409034051-768cd563887f
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd
github.com/hashicorp/go-plugin v1.3.0
github.com/spf13/viper v1.7.0
github.com/cloudflare/cfssl v1.6.1
github.com/hashicorp/go-hclog v1.2.0
github.com/hashicorp/go-plugin v1.4.3
github.com/spf13/viper v1.10.1
gitlab.33.cn/link33/chain33-sdk-go v0.0.0-20211208090718-d6e59899ef37
gitlab.33.cn/link33/sidecar v0.0.0-20211213060412-f3eee2232093
go.starlark.net v0.0.0-20220302181546-5411bad688d1 // indirect
gitlab.33.cn/link33/sidecar v0.0.0-20220120062340-04eb4a2e720f
go.starlark.net v0.0.0-20220302181546-5411bad688d1
)
replace (
github.com/go-kit/kit => github.com/go-kit/kit v0.8.0
github.com/golang/protobuf => github.com/golang/protobuf v1.3.2
github.com/prometheus/client_golang => github.com/prometheus/client_golang v0.9.3
google.golang.org/genproto => google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884
require (
github.com/33cn/chain33 v1.67.0 // indirect
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de // indirect
github.com/btcsuite/btcd v0.22.0-beta // indirect
github.com/bxcodec/faker/v3 v3.6.0 // indirect
github.com/cbergoon/merkletree v0.2.0 // indirect
github.com/creasty/defaults v1.5.2 // indirect
github.com/decred/base58 v1.0.3 // indirect
github.com/decred/dcrd/crypto/blake256 v1.0.0 // indirect
github.com/ethereum/go-ethereum v1.10.16 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/gobuffalo/envy v1.7.0 // indirect
github.com/gobuffalo/packd v1.0.0 // indirect
github.com/gobuffalo/packr v1.30.1 // indirect
github.com/goccy/go-json v0.7.10 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/gookit/goutil v0.3.15 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/log15 v0.0.0-20201112154412-8562bdadbbac // indirect
github.com/jinzhu/copier v0.3.2 // indirect
github.com/jinzhu/now v1.1.2 // indirect
github.com/joho/godotenv v1.3.0 // indirect
github.com/juju/errors v0.0.0-20210818161939-5560c4c073ff // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/meshplus/bitxhub-kit v1.2.1-0.20210524063043-9afae78ac098 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rogpeppe/go-internal v1.8.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/spf13/afero v1.6.0 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/thoas/go-funk v0.9.1 // indirect
github.com/tjfoc/gmsm v1.3.2 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.4 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871 // indirect
golang.org/x/exp v0.0.0-20220317015231-48e79f11773a // indirect
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
golang.org/x/sys v0.0.0-20211210111614-af8b64212486 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa // indirect
google.golang.org/grpc v1.43.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
This source diff could not be displayed because it is too large. You can view the blob instead.
package main
import (
"fmt"
"github.com/hashicorp/go-plugin"
"gitlab.33.cn/link33/sidecar-client-chain33/evmxgo"
"gitlab.33.cn/link33/sidecar-client-chain33/paracross"
"gitlab.33.cn/link33/sidecar/pkg/plugins"
)
func main() {
plugin.Serve(&plugin.ServeConfig{
HandshakeConfig: plugins.Handshake,
Plugins: map[string]plugin.Plugin{
// plugins.PluginName: &plugins.AppchainGRPCPlugin{Impl: &Client{}},
evmxgo.PluginName: &plugins.AppchainGRPCPlugin{Impl: &evmxgo.Evmxgo{}},
paracross.PluginParacross: &plugins.AppchainGRPCPlugin{Impl: &paracross.Paracross{}},
},
GRPCServer: plugin.DefaultGRPCServer,
})
fmt.Println("Plugin server down")
}
package paracross
import (
"gitlab.33.cn/link33/sidecar/model/pb"
"gitlab.33.cn/link33/sidecar/pkg/plugins"
)
const (
PluginParacross = "paracross"
)
type Paracross struct{}
func (p *Paracross) Start() error {
// TODO implement me
panic("implement me")
}
func (p *Paracross) Stop() error {
// TODO implement me
panic("implement me")
}
func (p *Paracross) Bind(kern plugins.Kernel) {
// TODO implement me
panic("implement me")
}
func (p *Paracross) Initialize(configPath string, ID string, extra []byte) error {
// TODO implement me
panic("implement me")
}
func (p *Paracross) GetIBTP() chan *pb.IBTP {
// TODO implement me
panic("implement me")
}
func (p *Paracross) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) {
// TODO implement me
panic("implement me")
}
func (p *Paracross) RollbackIBTP(ibtp *pb.IBTP, isSrcChain bool) (*pb.RollbackIBTPResponse, error) {
// TODO implement me
panic("implement me")
}
func (p *Paracross) IncreaseInMeta(ibtp *pb.IBTP) (*pb.IBTP, error) {
// TODO implement me
panic("implement me")
}
func (p *Paracross) GetOutMessage(to string, idx uint64) (*pb.IBTP, error) {
// TODO implement me
panic("implement me")
}
func (p *Paracross) GetInMessage(from string, idx uint64) ([][]byte, error) {
// TODO implement me
panic("implement me")
}
func (p *Paracross) GetInMeta() (map[string]uint64, error) {
// TODO implement me
panic("implement me")
}
func (p *Paracross) GetOutMeta() (map[string]uint64, error) {
// TODO implement me
panic("implement me")
}
func (p *Paracross) GetCallbackMeta() (map[string]uint64, error) {
// TODO implement me
panic("implement me")
}
func (p *Paracross) CommitCallback(ibtp *pb.IBTP) error {
// TODO implement me
panic("implement me")
}
func (p *Paracross) GetReceipt(ibtp *pb.IBTP) (*pb.IBTP, error) {
// TODO implement me
panic("implement me")
}
func (p *Paracross) Name() string {
// TODO implement me
panic("implement me")
}
func (p *Paracross) Type() string {
// TODO implement me
panic("implement me")
}
func (p *Paracross) ID() string {
// TODO implement me
panic("implement me")
}
syntax = "proto3";
package types;
option go_package = "../types";
enum Status {
True = 0;
False = 1;
TimeOut = 2;
}
message Req {
Event event = 1;
}
message Res {
Event event = 1;
Status status = 2;
}
message Ret {
Event event = 1;
uint32 status = 2;
}
message Record {
string ID = 1;
string fromChainID = 2;
string toChainID = 3;
Event event = 4;
}
message Event {
string txID = 1;
uint64 blockNumber = 2;
Contract contract = 3;
MapAssetInfo payload = 4;
}
enum EventType {
Lock = 0;
Mint = 1;
UnLock = 2;
Burn = 3;
}
message MapAssetInfo {
EventType eventType = 1;
string lockAddress = 4;
int64 lockAmount = 5;
string mintAddress = 6;
int64 mintAmount = 7;
string unlockAddress = 8;
int64 unlockAmount = 9;
string burnAddress = 10;
int64 burnAmount = 11;
string symbol = 12;
bytes extra = 13;
}
message Contract {
string chainID = 1;
string execName = 2;
string address = 3;
string callMethod = 4;
}
message EventPair {
Event fromEvent = 1;
Event toEvent = 2;
}
package main
import (
"fmt"
"gitlab.33.cn/link33/sidecar/model/pb"
)
func (c *Client) generateCallback(original *pb.IBTP, args [][]byte, status bool) (result *pb.IBTP, err error) {
if original == nil {
return nil, fmt.Errorf("got nil ibtp To generate receipt: %w", err)
}
pd := &pb.Payload{}
if err := pd.Unmarshal(original.Payload); err != nil {
return nil, fmt.Errorf("ibtp payload unmarshal: %w", err)
}
originalContent := &pb.Content{}
if err := originalContent.Unmarshal(pd.Content); err != nil {
return nil, fmt.Errorf("ibtp payload unmarshal: %w", err)
}
content := &pb.Content{}
typ := pb.IBTP_RECEIPT_SUCCESS
if status {
content.Func = originalContent.Callback
content.Args = append(originalContent.ArgsCb, args...)
} else {
content.Func = originalContent.Rollback
content.Args = originalContent.ArgsRb
typ = pb.IBTP_RECEIPT_FAILURE
}
// TODO
if original.Type == pb.IBTP_ROLLBACK {
typ = pb.IBTP_RECEIPT_ROLLBACK
}
b, err := content.Marshal()
if err != nil {
return nil, err
}
retPd := &pb.Payload{
Content: b,
}
pdb, err := retPd.Marshal()
if err != nil {
return nil, err
}
return &pb.IBTP{
From: original.From,
To: original.To,
Nonce: original.Nonce,
Type: typ,
Proof: original.Proof,
Payload: pdb,
Version: original.Version,
}, nil
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment