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")
)
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