Commit a1236aaa authored by vipwzw's avatar vipwzw

add js plugin

parent edd90338
......@@ -7,6 +7,7 @@ import (
_ "github.com/33cn/plugin/plugin/dapp/evm" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/game" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/hashlock" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/js" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/lottery" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/multisig" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/norm" //auto gen
......
all:
chmod +x ./build.sh
./build.sh $(OUT) $(FLAG)
\ No newline at end of file
#!/bin/sh
strpwd=$(pwd)
strcmd=${strpwd##*dapp/}
strapp=${strcmd%/cmd*}
OUT_DIR="${1}/$strapp"
#FLAG=$2
mkdir -p "${OUT_DIR}"
cp ./build/* "${OUT_DIR}"
package executor
import (
"github.com/33cn/chain33/types"
"github.com/33cn/plugin/plugin/dapp/js/types/jsproto"
)
func (c *js) Exec_Create(payload *jsproto.Create, tx *types.Transaction, index int) (*types.Receipt, error) {
return &types.Receipt{}, nil
}
func (c *js) Exec_Call(payload *jsproto.Call, tx *types.Transaction, index int) (*types.Receipt, error) {
return &types.Receipt{}, nil
}
package executor
import (
"github.com/33cn/chain33/types"
"github.com/33cn/plugin/plugin/dapp/js/types/jsproto"
)
func (c *js) ExecDelLocal_Create(payload *jsproto.Create, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return &types.LocalDBSet{}, nil
}
func (c *js) ExecDelLocal_Call(payload *jsproto.Call, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return &types.LocalDBSet{}, nil
}
package executor
import (
"github.com/33cn/chain33/types"
"github.com/33cn/plugin/plugin/dapp/js/types/jsproto"
)
func (c *js) ExecLocal_Create(payload *jsproto.Create, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return &types.LocalDBSet{}, nil
}
func (c *js) ExecLocal_Call(payload *jsproto.Call, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return &types.LocalDBSet{}, nil
}
package executor
import (
log "github.com/33cn/chain33/common/log/log15"
drivers "github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
ptypes "github.com/33cn/plugin/plugin/dapp/js/types"
)
var (
ptylog = log.New("module", "execs.js")
)
var driverName = ptypes.JsX
func init() {
ety := types.LoadExecutorType(driverName)
ety.InitFuncList(types.ListMethod(&js{}))
}
//Init 插件初始化
func Init(name string, sub []byte) {
drivers.Register(GetName(), newjs, 0)
}
type js struct {
drivers.DriverBase
}
func newjs() drivers.Driver {
t := &js{}
t.SetChild(t)
t.SetExecutorType(types.LoadExecutorType(driverName))
return t
}
//GetName 获取名字
func GetName() string {
return newjs().GetName()
}
//GetDriverName 获取插件的名字
func (u *js) GetDriverName() string {
return driverName
}
package unfreeze
import (
"github.com/33cn/chain33/pluginmgr"
"github.com/33cn/plugin/plugin/dapp/js/executor"
ptypes "github.com/33cn/plugin/plugin/dapp/js/types"
)
func init() {
pluginmgr.Register(&pluginmgr.PluginBase{
Name: ptypes.JsX,
ExecName: executor.GetName(),
Exec: executor.Init,
Cmd: nil,
RPC: nil,
})
}
all:
./create_protobuf.sh
#!/bin/sh
protoc --go_out=plugins=grpc:../types/jsproto/ ./*.proto
syntax = "proto3";
package jsproto;
// create action
message Create {
string code = 1;
string name = 2;
}
// call action
message Call {
string funcname = 1; //call function name
string args = 2; //json args
}
message JsAction {
oneof value {
Create create = 1;
Call call = 2;
}
int32 ty = 3;
}
package rpc
import (
ptypes "github.com/33cn/chain33/plugin/dapp/js/types"
rpctypes "github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types"
)
type channelClient struct {
rpctypes.ChannelClient
}
type Jrpc struct {
cli *channelClient
}
type Grpc struct {
*channelClient
}
func Init(name string, s rpctypes.RPCServer) {
cli := &channelClient{}
grpc := &Grpc{channelClient: cli}
cli.Init(name, s, &Jrpc{cli: cli}, grpc)
ptypes.RegisterTradeServer(s.GRPC(), grpc)
}
package types
import (
"github.com/33cn/chain33/types"
"github.com/33cn/plugin/plugin/dapp/js/types/jsproto"
)
// action for executor
const (
jsActionCreate = 0
jsActionCall = 1
)
//日志类型
const (
TyLogJsCreate = iota + 1
TyLogJsCall
)
var (
typeMap = map[string]int32{
"Create": jsActionCreate,
"Call": jsActionCall,
}
logMap = map[int64]*types.LogInfo{}
)
//JsX 插件名字
var JsX = "js"
func init() {
types.AllowUserExec = append(types.AllowUserExec, []byte(JsX))
types.RegistorExecutor(JsX, NewType())
}
//JsType 类型
type JsType struct {
types.ExecTypeBase
}
//NewType 新建一个plugin 类型
func NewType() *JsType {
c := &JsType{}
c.SetChild(c)
return c
}
//GetPayload 获取 交易构造
func (t *JsType) GetPayload() types.Message {
return &jsproto.JsAction{}
}
//GetTypeMap 获取类型映射
func (t *JsType) GetTypeMap() map[string]int32 {
return typeMap
}
//GetLogMap 获取日志映射
func (t *JsType) GetLogMap() map[int64]*types.LogInfo {
return logMap
}
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: js.proto
package jsproto
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
// create action
type Create struct {
Code string `protobuf:"bytes,1,opt,name=code,proto3" json:"code,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Create) Reset() { *m = Create{} }
func (m *Create) String() string { return proto.CompactTextString(m) }
func (*Create) ProtoMessage() {}
func (*Create) Descriptor() ([]byte, []int) {
return fileDescriptor_js_5c2b7f71b678e48e, []int{0}
}
func (m *Create) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Create.Unmarshal(m, b)
}
func (m *Create) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Create.Marshal(b, m, deterministic)
}
func (dst *Create) XXX_Merge(src proto.Message) {
xxx_messageInfo_Create.Merge(dst, src)
}
func (m *Create) XXX_Size() int {
return xxx_messageInfo_Create.Size(m)
}
func (m *Create) XXX_DiscardUnknown() {
xxx_messageInfo_Create.DiscardUnknown(m)
}
var xxx_messageInfo_Create proto.InternalMessageInfo
func (m *Create) GetCode() string {
if m != nil {
return m.Code
}
return ""
}
func (m *Create) GetName() string {
if m != nil {
return m.Name
}
return ""
}
// call action
type Call struct {
Funcname string `protobuf:"bytes,1,opt,name=funcname,proto3" json:"funcname,omitempty"`
Args string `protobuf:"bytes,2,opt,name=args,proto3" json:"args,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Call) Reset() { *m = Call{} }
func (m *Call) String() string { return proto.CompactTextString(m) }
func (*Call) ProtoMessage() {}
func (*Call) Descriptor() ([]byte, []int) {
return fileDescriptor_js_5c2b7f71b678e48e, []int{1}
}
func (m *Call) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Call.Unmarshal(m, b)
}
func (m *Call) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Call.Marshal(b, m, deterministic)
}
func (dst *Call) XXX_Merge(src proto.Message) {
xxx_messageInfo_Call.Merge(dst, src)
}
func (m *Call) XXX_Size() int {
return xxx_messageInfo_Call.Size(m)
}
func (m *Call) XXX_DiscardUnknown() {
xxx_messageInfo_Call.DiscardUnknown(m)
}
var xxx_messageInfo_Call proto.InternalMessageInfo
func (m *Call) GetFuncname() string {
if m != nil {
return m.Funcname
}
return ""
}
func (m *Call) GetArgs() string {
if m != nil {
return m.Args
}
return ""
}
type JsAction struct {
// Types that are valid to be assigned to Value:
// *JsAction_Create
// *JsAction_Call
Value isJsAction_Value `protobuf_oneof:"value"`
Ty int32 `protobuf:"varint,3,opt,name=ty,proto3" json:"ty,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *JsAction) Reset() { *m = JsAction{} }
func (m *JsAction) String() string { return proto.CompactTextString(m) }
func (*JsAction) ProtoMessage() {}
func (*JsAction) Descriptor() ([]byte, []int) {
return fileDescriptor_js_5c2b7f71b678e48e, []int{2}
}
func (m *JsAction) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_JsAction.Unmarshal(m, b)
}
func (m *JsAction) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_JsAction.Marshal(b, m, deterministic)
}
func (dst *JsAction) XXX_Merge(src proto.Message) {
xxx_messageInfo_JsAction.Merge(dst, src)
}
func (m *JsAction) XXX_Size() int {
return xxx_messageInfo_JsAction.Size(m)
}
func (m *JsAction) XXX_DiscardUnknown() {
xxx_messageInfo_JsAction.DiscardUnknown(m)
}
var xxx_messageInfo_JsAction proto.InternalMessageInfo
type isJsAction_Value interface {
isJsAction_Value()
}
type JsAction_Create struct {
Create *Create `protobuf:"bytes,1,opt,name=create,proto3,oneof"`
}
type JsAction_Call struct {
Call *Call `protobuf:"bytes,2,opt,name=call,proto3,oneof"`
}
func (*JsAction_Create) isJsAction_Value() {}
func (*JsAction_Call) isJsAction_Value() {}
func (m *JsAction) GetValue() isJsAction_Value {
if m != nil {
return m.Value
}
return nil
}
func (m *JsAction) GetCreate() *Create {
if x, ok := m.GetValue().(*JsAction_Create); ok {
return x.Create
}
return nil
}
func (m *JsAction) GetCall() *Call {
if x, ok := m.GetValue().(*JsAction_Call); ok {
return x.Call
}
return nil
}
func (m *JsAction) GetTy() int32 {
if m != nil {
return m.Ty
}
return 0
}
// XXX_OneofFuncs is for the internal use of the proto package.
func (*JsAction) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) {
return _JsAction_OneofMarshaler, _JsAction_OneofUnmarshaler, _JsAction_OneofSizer, []interface{}{
(*JsAction_Create)(nil),
(*JsAction_Call)(nil),
}
}
func _JsAction_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
m := msg.(*JsAction)
// value
switch x := m.Value.(type) {
case *JsAction_Create:
b.EncodeVarint(1<<3 | proto.WireBytes)
if err := b.EncodeMessage(x.Create); err != nil {
return err
}
case *JsAction_Call:
b.EncodeVarint(2<<3 | proto.WireBytes)
if err := b.EncodeMessage(x.Call); err != nil {
return err
}
case nil:
default:
return fmt.Errorf("JsAction.Value has unexpected type %T", x)
}
return nil
}
func _JsAction_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
m := msg.(*JsAction)
switch tag {
case 1: // value.create
if wire != proto.WireBytes {
return true, proto.ErrInternalBadWireType
}
msg := new(Create)
err := b.DecodeMessage(msg)
m.Value = &JsAction_Create{msg}
return true, err
case 2: // value.call
if wire != proto.WireBytes {
return true, proto.ErrInternalBadWireType
}
msg := new(Call)
err := b.DecodeMessage(msg)
m.Value = &JsAction_Call{msg}
return true, err
default:
return false, nil
}
}
func _JsAction_OneofSizer(msg proto.Message) (n int) {
m := msg.(*JsAction)
// value
switch x := m.Value.(type) {
case *JsAction_Create:
s := proto.Size(x.Create)
n += 1 // tag and wire
n += proto.SizeVarint(uint64(s))
n += s
case *JsAction_Call:
s := proto.Size(x.Call)
n += 1 // tag and wire
n += proto.SizeVarint(uint64(s))
n += s
case nil:
default:
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
}
return n
}
func init() {
proto.RegisterType((*Create)(nil), "js.Create")
proto.RegisterType((*Call)(nil), "js.Call")
proto.RegisterType((*JsAction)(nil), "js.JsAction")
}
func init() { proto.RegisterFile("js.proto", fileDescriptor_js_5c2b7f71b678e48e) }
var fileDescriptor_js_5c2b7f71b678e48e = []byte{
// 195 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x3c, 0x8f, 0x3f, 0xaf, 0x82, 0x30,
0x14, 0xc5, 0xa1, 0x0f, 0x78, 0x7d, 0x97, 0xe4, 0x0d, 0x9d, 0x88, 0x83, 0x21, 0xc4, 0x81, 0x89,
0x18, 0x4c, 0xdc, 0x95, 0x85, 0x38, 0xf6, 0x1b, 0xd4, 0x5a, 0x0d, 0xa4, 0x52, 0x43, 0x8b, 0x09,
0xdf, 0xde, 0xf4, 0xa2, 0x6e, 0xe7, 0x9e, 0x73, 0x7f, 0xf7, 0x0f, 0xd0, 0xde, 0x56, 0x8f, 0xd1,
0x38, 0xc3, 0x48, 0x6f, 0x8b, 0x2d, 0x24, 0xcd, 0xa8, 0x84, 0x53, 0x8c, 0x41, 0x24, 0xcd, 0x45,
0x65, 0x61, 0x1e, 0x96, 0x7f, 0x1c, 0xb5, 0xf7, 0x06, 0x71, 0x57, 0x19, 0x59, 0x3c, 0xaf, 0x8b,
0x3d, 0x44, 0x8d, 0xd0, 0x9a, 0xad, 0x80, 0x5e, 0xa7, 0x41, 0x62, 0xbe, 0x30, 0xdf, 0xda, 0x73,
0x62, 0xbc, 0xd9, 0x0f, 0xe7, 0x75, 0xd1, 0x01, 0x3d, 0xd9, 0x83, 0x74, 0x9d, 0x19, 0xd8, 0x06,
0x12, 0x89, 0x5b, 0x91, 0x4c, 0x6b, 0xa8, 0x7a, 0x5b, 0x2d, 0x77, 0xb4, 0x01, 0x7f, 0x67, 0x6c,
0x0d, 0x91, 0x14, 0x5a, 0xe3, 0x94, 0xb4, 0xa6, 0xd8, 0x23, 0xb4, 0x6e, 0x03, 0x8e, 0x3e, 0xfb,
0x07, 0xe2, 0xe6, 0xec, 0x27, 0x0f, 0xcb, 0x98, 0x13, 0x37, 0x1f, 0x7f, 0x21, 0x7e, 0x0a, 0x3d,
0xa9, 0x73, 0x82, 0xff, 0xed, 0x5e, 0x01, 0x00, 0x00, 0xff, 0xff, 0x15, 0xae, 0x42, 0xe3, 0xeb,
0x00, 0x00, 0x00,
}
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