Commit 3635c238 authored by 袁兴强's avatar 袁兴强

add wasm rpc

parent 9b63bae9
......@@ -74,7 +74,7 @@ func checkContract(cmd *cobra.Command, args []string) {
params := rpctypes.Query4Jrpc{
Execer: wasmtypes.WasmX,
FuncName: "Check",
Payload: types.MustPBToJSON(&wasmtypes.QueryCheckConract{
Payload: types.MustPBToJSON(&wasmtypes.QueryCheckContract{
Name: name,
}),
}
......
#include "common.h"
#include "../common.h"
#include "dice.hpp"
#include <string.h>
......
......@@ -108,7 +108,7 @@ func (w *Wasm) Exec_Call(payload *types2.WasmCall, tx *types.Transaction, index
KV: w.kvs,
Logs: logs,
}
if ret != 0 {
if ret < 0 {
receipt.Ty = types.ExecPack
}
......
......@@ -5,7 +5,7 @@ import (
types2 "github.com/33cn/plugin/plugin/dapp/wasm/types"
)
func (w *Wasm) Query_Check(query *types2.QueryCheckConract) (types.Message, error) {
func (w *Wasm) Query_Check(query *types2.QueryCheckContract) (types.Message, error) {
if query == nil {
return nil, types.ErrInvalidParam
}
......
......@@ -4,7 +4,7 @@ import (
"github.com/33cn/chain33/pluginmgr"
"github.com/33cn/plugin/plugin/dapp/wasm/commands"
"github.com/33cn/plugin/plugin/dapp/wasm/executor"
_ "github.com/33cn/plugin/plugin/dapp/wasm/rpc"
"github.com/33cn/plugin/plugin/dapp/wasm/rpc"
"github.com/33cn/plugin/plugin/dapp/wasm/types"
)
......@@ -14,6 +14,6 @@ func init() {
ExecName: executor.GetName(),
Exec: executor.Init,
Cmd: commands.Cmd,
//RPC: rpc.Init,
RPC: rpc.Init,
})
}
......@@ -21,19 +21,10 @@ message wasmCall {
repeated int64 parameters = 3;
}
message queryCheckConract {
message queryCheckContract {
string name = 1;
}
message queryCreateTransaction{
int32 ty = 1;
string name = 2;
bytes code = 3;
string method = 4;
repeated int64 parameters = 5;
int64 fee = 6;
}
message customLog {
repeated string info = 1;
}
......
package rpc
import (
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/types"
types2 "github.com/33cn/plugin/plugin/dapp/wasm/types"
)
func (c *channelClient) check(in *types2.QueryCheckContract) (*types.Reply, error) {
if in == nil {
return nil, types2.ErrInvalidParam
}
m, err := c.Query(types2.WasmX, "Check", in)
if err != nil {
return nil, err
}
if reply, ok := m.(*types.Reply); ok {
return reply, nil
}
return nil, types2.ErrUnknown
}
func (j *Jrpc) CheckContract(param *types2.QueryCheckContract, result *interface{}) error {
res, err := j.cli.check(param)
if err != nil {
return err
}
if res != nil {
*result = res.IsOk
} else {
*result = false
}
return nil
}
func (j *Jrpc) CreateContract(param *types2.WasmCreate, result *interface{}) error {
if param == nil {
return types2.ErrInvalidParam
}
cfg := types.LoadExecutorType(types2.WasmX).GetConfig()
data, err := types.CallCreateTx(cfg, cfg.ExecName(types2.WasmX), "Create", param)
if err != nil {
return err
}
*result = common.ToHex(data)
return nil
}
func (j *Jrpc) CallContract(param *types2.WasmCall, result *interface{}) error {
if param == nil {
return types2.ErrInvalidParam
}
cfg := types.LoadExecutorType(types2.WasmX).GetConfig()
data, err := types.CallCreateTx(cfg, cfg.ExecName(types2.WasmX), "Call", param)
if err != nil {
return err
}
*result = common.ToHex(data)
return nil
}
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package rpc
import (
"github.com/33cn/chain33/rpc/types"
)
// Jrpc json rpc struct
type Jrpc struct {
cli *channelClient
}
// Grpc grpc struct
type Grpc struct {
*channelClient
}
type channelClient struct {
types.ChannelClient
}
// Init init grpc param
func Init(name string, s types.RPCServer) {
cli := &channelClient{}
grpc := &Grpc{channelClient: cli}
cli.Init(name, s, &Jrpc{cli: cli}, grpc)
}
......@@ -8,4 +8,6 @@ var (
ErrCodeOversize = errors.New("code oversize")
ErrInvalidMethod = errors.New("invalid method")
ErrInvalidContractName = errors.New("invalid contract name")
ErrInvalidParam = errors.New("invalid parameters")
ErrUnknown = errors.New("unknown error")
)
......@@ -210,124 +210,45 @@ func (m *WasmCall) GetParameters() []int64 {
return nil
}
type QueryCheckConract struct {
type QueryCheckContract struct {
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *QueryCheckConract) Reset() { *m = QueryCheckConract{} }
func (m *QueryCheckConract) String() string { return proto.CompactTextString(m) }
func (*QueryCheckConract) ProtoMessage() {}
func (*QueryCheckConract) Descriptor() ([]byte, []int) {
func (m *QueryCheckContract) Reset() { *m = QueryCheckContract{} }
func (m *QueryCheckContract) String() string { return proto.CompactTextString(m) }
func (*QueryCheckContract) ProtoMessage() {}
func (*QueryCheckContract) Descriptor() ([]byte, []int) {
return fileDescriptor_7d78909ad64e3bbb, []int{3}
}
func (m *QueryCheckConract) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_QueryCheckConract.Unmarshal(m, b)
func (m *QueryCheckContract) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_QueryCheckContract.Unmarshal(m, b)
}
func (m *QueryCheckConract) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_QueryCheckConract.Marshal(b, m, deterministic)
func (m *QueryCheckContract) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_QueryCheckContract.Marshal(b, m, deterministic)
}
func (m *QueryCheckConract) XXX_Merge(src proto.Message) {
xxx_messageInfo_QueryCheckConract.Merge(m, src)
func (m *QueryCheckContract) XXX_Merge(src proto.Message) {
xxx_messageInfo_QueryCheckContract.Merge(m, src)
}
func (m *QueryCheckConract) XXX_Size() int {
return xxx_messageInfo_QueryCheckConract.Size(m)
func (m *QueryCheckContract) XXX_Size() int {
return xxx_messageInfo_QueryCheckContract.Size(m)
}
func (m *QueryCheckConract) XXX_DiscardUnknown() {
xxx_messageInfo_QueryCheckConract.DiscardUnknown(m)
func (m *QueryCheckContract) XXX_DiscardUnknown() {
xxx_messageInfo_QueryCheckContract.DiscardUnknown(m)
}
var xxx_messageInfo_QueryCheckConract proto.InternalMessageInfo
var xxx_messageInfo_QueryCheckContract proto.InternalMessageInfo
func (m *QueryCheckConract) GetName() string {
func (m *QueryCheckContract) GetName() string {
if m != nil {
return m.Name
}
return ""
}
type QueryCreateTransaction struct {
Ty int32 `protobuf:"varint,1,opt,name=ty,proto3" json:"ty,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
Code []byte `protobuf:"bytes,3,opt,name=code,proto3" json:"code,omitempty"`
Method string `protobuf:"bytes,4,opt,name=method,proto3" json:"method,omitempty"`
Parameters []int64 `protobuf:"varint,5,rep,packed,name=parameters,proto3" json:"parameters,omitempty"`
Fee int64 `protobuf:"varint,6,opt,name=fee,proto3" json:"fee,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *QueryCreateTransaction) Reset() { *m = QueryCreateTransaction{} }
func (m *QueryCreateTransaction) String() string { return proto.CompactTextString(m) }
func (*QueryCreateTransaction) ProtoMessage() {}
func (*QueryCreateTransaction) Descriptor() ([]byte, []int) {
return fileDescriptor_7d78909ad64e3bbb, []int{4}
}
func (m *QueryCreateTransaction) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_QueryCreateTransaction.Unmarshal(m, b)
}
func (m *QueryCreateTransaction) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_QueryCreateTransaction.Marshal(b, m, deterministic)
}
func (m *QueryCreateTransaction) XXX_Merge(src proto.Message) {
xxx_messageInfo_QueryCreateTransaction.Merge(m, src)
}
func (m *QueryCreateTransaction) XXX_Size() int {
return xxx_messageInfo_QueryCreateTransaction.Size(m)
}
func (m *QueryCreateTransaction) XXX_DiscardUnknown() {
xxx_messageInfo_QueryCreateTransaction.DiscardUnknown(m)
}
var xxx_messageInfo_QueryCreateTransaction proto.InternalMessageInfo
func (m *QueryCreateTransaction) GetTy() int32 {
if m != nil {
return m.Ty
}
return 0
}
func (m *QueryCreateTransaction) GetName() string {
if m != nil {
return m.Name
}
return ""
}
func (m *QueryCreateTransaction) GetCode() []byte {
if m != nil {
return m.Code
}
return nil
}
func (m *QueryCreateTransaction) GetMethod() string {
if m != nil {
return m.Method
}
return ""
}
func (m *QueryCreateTransaction) GetParameters() []int64 {
if m != nil {
return m.Parameters
}
return nil
}
func (m *QueryCreateTransaction) GetFee() int64 {
if m != nil {
return m.Fee
}
return 0
}
type CustomLog struct {
Info []string `protobuf:"bytes,1,rep,name=info,proto3" json:"info,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
......@@ -339,7 +260,7 @@ func (m *CustomLog) Reset() { *m = CustomLog{} }
func (m *CustomLog) String() string { return proto.CompactTextString(m) }
func (*CustomLog) ProtoMessage() {}
func (*CustomLog) Descriptor() ([]byte, []int) {
return fileDescriptor_7d78909ad64e3bbb, []int{5}
return fileDescriptor_7d78909ad64e3bbb, []int{4}
}
func (m *CustomLog) XXX_Unmarshal(b []byte) error {
......@@ -379,7 +300,7 @@ func (m *CreateContractLog) Reset() { *m = CreateContractLog{} }
func (m *CreateContractLog) String() string { return proto.CompactTextString(m) }
func (*CreateContractLog) ProtoMessage() {}
func (*CreateContractLog) Descriptor() ([]byte, []int) {
return fileDescriptor_7d78909ad64e3bbb, []int{6}
return fileDescriptor_7d78909ad64e3bbb, []int{5}
}
func (m *CreateContractLog) XXX_Unmarshal(b []byte) error {
......@@ -427,7 +348,7 @@ func (m *CallContractLog) Reset() { *m = CallContractLog{} }
func (m *CallContractLog) String() string { return proto.CompactTextString(m) }
func (*CallContractLog) ProtoMessage() {}
func (*CallContractLog) Descriptor() ([]byte, []int) {
return fileDescriptor_7d78909ad64e3bbb, []int{7}
return fileDescriptor_7d78909ad64e3bbb, []int{6}
}
func (m *CallContractLog) XXX_Unmarshal(b []byte) error {
......@@ -482,7 +403,7 @@ func (m *LocalDataLog) Reset() { *m = LocalDataLog{} }
func (m *LocalDataLog) String() string { return proto.CompactTextString(m) }
func (*LocalDataLog) ProtoMessage() {}
func (*LocalDataLog) Descriptor() ([]byte, []int) {
return fileDescriptor_7d78909ad64e3bbb, []int{8}
return fileDescriptor_7d78909ad64e3bbb, []int{7}
}
func (m *LocalDataLog) XXX_Unmarshal(b []byte) error {
......@@ -528,8 +449,7 @@ func init() {
proto.RegisterType((*WasmAction)(nil), "types.wasmAction")
proto.RegisterType((*WasmCreate)(nil), "types.wasmCreate")
proto.RegisterType((*WasmCall)(nil), "types.wasmCall")
proto.RegisterType((*QueryCheckConract)(nil), "types.queryCheckConract")
proto.RegisterType((*QueryCreateTransaction)(nil), "types.queryCreateTransaction")
proto.RegisterType((*QueryCheckContract)(nil), "types.queryCheckContract")
proto.RegisterType((*CustomLog)(nil), "types.customLog")
proto.RegisterType((*CreateContractLog)(nil), "types.createContractLog")
proto.RegisterType((*CallContractLog)(nil), "types.callContractLog")
......@@ -539,30 +459,27 @@ func init() {
func init() { proto.RegisterFile("wasm.proto", fileDescriptor_7d78909ad64e3bbb) }
var fileDescriptor_7d78909ad64e3bbb = []byte{
// 393 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x52, 0x3d, 0x0f, 0xd3, 0x30,
0x10, 0x6d, 0xe2, 0x26, 0x34, 0x47, 0x45, 0x5b, 0x0f, 0x55, 0xc4, 0x00, 0x91, 0x25, 0x44, 0x24,
0xa4, 0x0e, 0xc0, 0xc6, 0x04, 0x61, 0xe8, 0xc0, 0x64, 0x21, 0xc4, 0x02, 0x92, 0x71, 0x5d, 0x5a,
0xd5, 0x89, 0x83, 0xe3, 0x80, 0xf2, 0x57, 0xf8, 0xb5, 0xc8, 0x1f, 0x0d, 0x11, 0xaa, 0x3a, 0xb0,
0xdd, 0xc7, 0xbb, 0x7b, 0x77, 0xf7, 0x0e, 0xe0, 0x17, 0xeb, 0xea, 0x5d, 0xab, 0x95, 0x51,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e6, 0xf9, 0x9d, 0x99, 0x93, 0x7f, 0x67, 0xc6, 0x6b,
0x40, 0x47, 0x21, 0xf2, 0xb4, 0x88, 0x4a, 0x44, 0xad, 0x49, 0x9e, 0x42, 0xc6, 0xfb, 0xce, 0xa8,
0xfa, 0x83, 0xfa, 0x6e, 0xa9, 0xce, 0xcd, 0x51, 0xe5, 0x51, 0x81, 0x2c, 0xbd, 0xb5, 0xc9, 0x1b,
0xd8, 0x78, 0x19, 0xab, 0x70, 0xb0, 0x00, 0xbc, 0xab, 0x41, 0x16, 0x34, 0xf8, 0x02, 0x2b, 0x2b,
0xed, 0xb4, 0xf4, 0x7f, 0xa4, 0xd8, 0x42, 0xaa, 0x45, 0xd7, 0x4b, 0xe3, 0x8e, 0x80, 0x68, 0xf0,
0xc8, 0x67, 0x58, 0x4a, 0xc5, 0x99, 0x7c, 0xcf, 0x0c, 0xb3, 0xbd, 0xd7, 0x80, 0x2e, 0xc2, 0xdf,
0x73, 0x49, 0xad, 0x69, 0xd9, 0x5a, 0x2d, 0x3e, 0xd9, 0x37, 0x0a, 0xcf, 0x31, 0xfa, 0x6e, 0x92,
0x5e, 0xfb, 0x9c, 0x3f, 0xee, 0xe8, 0x7f, 0x4b, 0xdd, 0xef, 0xbf, 0xfa, 0x13, 0x00, 0x00, 0xff,
0xff, 0xb4, 0xb4, 0xce, 0xf0, 0x09, 0x03, 0x00, 0x00,
// 342 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x52, 0xbf, 0x4f, 0xf3, 0x30,
0x10, 0x6d, 0xea, 0x36, 0x5f, 0x73, 0x5f, 0x45, 0xa9, 0x87, 0x2a, 0x62, 0x80, 0xc8, 0x12, 0x52,
0x24, 0xa4, 0x0e, 0xc0, 0xc6, 0x04, 0x65, 0xe8, 0xc0, 0xe4, 0x01, 0xb1, 0x80, 0x64, 0x5c, 0x43,
0xab, 0x3a, 0x71, 0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 0x51, 0xc5, 0x83,
0x7a, 0xb7, 0x84, 0x5d, 0xf9, 0xa6, 0xd2, 0x28, 0x43, 0x96, 0x60, 0x63, 0x72, 0x03, 0x73, 0xbf,
0xaa, 0x4e, 0x26, 0x10, 0x7f, 0x9d, 0x33, 0x09, 0x73, 0x3e, 0xc3, 0xcc, 0xae, 0xaf, 0xdf, 0xfa,
0x97, 0x71, 0x17, 0x10, 0x6b, 0x51, 0x37, 0xd2, 0xb8, 0x0b, 0x20, 0x1a, 0x10, 0x79, 0x82, 0xa9,
0x54, 0x9c, 0xc9, 0x7b, 0x66, 0x98, 0xd5, 0x3e, 0x06, 0xb4, 0x17, 0xad, 0x93, 0x9d, 0x52, 0x1b,
0x5a, 0xb7, 0x4a, 0x8b, 0x47, 0x7b, 0xaa, 0x70, 0x80, 0x03, 0x76, 0x2f, 0x69, 0xb4, 0xaf, 0x21,
0x5f, 0xeb, 0xf0, 0x6b, 0xec, 0xfe, 0xd7, 0xd5, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0xdb, 0xfa,
0x9e, 0x4d, 0x6d, 0x02, 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