Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
3635c238
Commit
3635c238
authored
Sep 18, 2020
by
袁兴强
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add wasm rpc
parent
9b63bae9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
99 additions
and
16 deletions
+99
-16
wasm.go
plugin/dapp/wasm/commands/wasm.go
+1
-1
dice.cpp
plugin/dapp/wasm/contracts/dice/dice.cpp
+1
-1
exec.go
plugin/dapp/wasm/executor/exec.go
+1
-1
query.go
plugin/dapp/wasm/executor/query.go
+1
-1
plugin.go
plugin/dapp/wasm/plugin.go
+2
-2
wasm.proto
plugin/dapp/wasm/proto/wasm.proto
+1
-10
rpc.go
plugin/dapp/wasm/rpc/rpc.go
+60
-0
types.go
plugin/dapp/wasm/rpc/types.go
+30
-0
errors.go
plugin/dapp/wasm/types/errors.go
+2
-0
wasm.pb.go
plugin/dapp/wasm/types/wasm.pb.go
+0
-0
No files found.
plugin/dapp/wasm/commands/wasm.go
View file @
3635c238
...
@@ -74,7 +74,7 @@ func checkContract(cmd *cobra.Command, args []string) {
...
@@ -74,7 +74,7 @@ func checkContract(cmd *cobra.Command, args []string) {
params
:=
rpctypes
.
Query4Jrpc
{
params
:=
rpctypes
.
Query4Jrpc
{
Execer
:
wasmtypes
.
WasmX
,
Execer
:
wasmtypes
.
WasmX
,
FuncName
:
"Check"
,
FuncName
:
"Check"
,
Payload
:
types
.
MustPBToJSON
(
&
wasmtypes
.
QueryCheckConract
{
Payload
:
types
.
MustPBToJSON
(
&
wasmtypes
.
QueryCheckCon
t
ract
{
Name
:
name
,
Name
:
name
,
}),
}),
}
}
...
...
plugin/dapp/wasm/contracts/dice/dice.cpp
View file @
3635c238
#include "common.h"
#include "
../
common.h"
#include "dice.hpp"
#include "dice.hpp"
#include <string.h>
#include <string.h>
...
...
plugin/dapp/wasm/executor/exec.go
View file @
3635c238
...
@@ -108,7 +108,7 @@ func (w *Wasm) Exec_Call(payload *types2.WasmCall, tx *types.Transaction, index
...
@@ -108,7 +108,7 @@ func (w *Wasm) Exec_Call(payload *types2.WasmCall, tx *types.Transaction, index
KV
:
w
.
kvs
,
KV
:
w
.
kvs
,
Logs
:
logs
,
Logs
:
logs
,
}
}
if
ret
!=
0
{
if
ret
<
0
{
receipt
.
Ty
=
types
.
ExecPack
receipt
.
Ty
=
types
.
ExecPack
}
}
...
...
plugin/dapp/wasm/executor/query.go
View file @
3635c238
...
@@ -5,7 +5,7 @@ import (
...
@@ -5,7 +5,7 @@ import (
types2
"github.com/33cn/plugin/plugin/dapp/wasm/types"
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
.
QueryCheckCon
t
ract
)
(
types
.
Message
,
error
)
{
if
query
==
nil
{
if
query
==
nil
{
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
}
}
...
...
plugin/dapp/wasm/plugin.go
View file @
3635c238
...
@@ -4,7 +4,7 @@ import (
...
@@ -4,7 +4,7 @@ import (
"github.com/33cn/chain33/pluginmgr"
"github.com/33cn/chain33/pluginmgr"
"github.com/33cn/plugin/plugin/dapp/wasm/commands"
"github.com/33cn/plugin/plugin/dapp/wasm/commands"
"github.com/33cn/plugin/plugin/dapp/wasm/executor"
"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"
"github.com/33cn/plugin/plugin/dapp/wasm/types"
)
)
...
@@ -14,6 +14,6 @@ func init() {
...
@@ -14,6 +14,6 @@ func init() {
ExecName
:
executor
.
GetName
(),
ExecName
:
executor
.
GetName
(),
Exec
:
executor
.
Init
,
Exec
:
executor
.
Init
,
Cmd
:
commands
.
Cmd
,
Cmd
:
commands
.
Cmd
,
//
RPC: rpc.Init,
RPC
:
rpc
.
Init
,
})
})
}
}
plugin/dapp/wasm/proto/wasm.proto
View file @
3635c238
...
@@ -21,19 +21,10 @@ message wasmCall {
...
@@ -21,19 +21,10 @@ message wasmCall {
repeated
int64
parameters
=
3
;
repeated
int64
parameters
=
3
;
}
}
message
queryCheckConract
{
message
queryCheckCon
t
ract
{
string
name
=
1
;
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
{
message
customLog
{
repeated
string
info
=
1
;
repeated
string
info
=
1
;
}
}
...
...
plugin/dapp/wasm/rpc/rpc.go
View file @
3635c238
package
rpc
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
}
plugin/dapp/wasm/rpc/types.go
0 → 100644
View file @
3635c238
// 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
)
}
plugin/dapp/wasm/types/errors.go
View file @
3635c238
...
@@ -8,4 +8,6 @@ var (
...
@@ -8,4 +8,6 @@ var (
ErrCodeOversize
=
errors
.
New
(
"code oversize"
)
ErrCodeOversize
=
errors
.
New
(
"code oversize"
)
ErrInvalidMethod
=
errors
.
New
(
"invalid method"
)
ErrInvalidMethod
=
errors
.
New
(
"invalid method"
)
ErrInvalidContractName
=
errors
.
New
(
"invalid contract name"
)
ErrInvalidContractName
=
errors
.
New
(
"invalid contract name"
)
ErrInvalidParam
=
errors
.
New
(
"invalid parameters"
)
ErrUnknown
=
errors
.
New
(
"unknown error"
)
)
)
plugin/dapp/wasm/types/wasm.pb.go
View file @
3635c238
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment