Unverified Commit 88dd7aa3 authored by andyYuanFZM's avatar andyYuanFZM Committed by GitHub

Merge pull request #9 from yann-sjtu/wasm_support

Wasm support
parents dab02fa2 50c8a8ae
package wasm
// action for executor
const (
WasmActionCreate = iota + 1
WasmActionCall
)
const (
WasmX = "wasm"
)
package wasm
import (
"io/ioutil"
"math/rand"
"time"
sdk "github.com/33cn/chain33-sdk-go"
"github.com/33cn/chain33-sdk-go/crypto"
"github.com/33cn/chain33-sdk-go/types"
)
var r *rand.Rand
func init() {
r = rand.New(rand.NewSource(time.Now().UnixNano()))
}
func CreateWasmCreateTx(paraName, path, name string, privKey, cert, uid []byte) (*types.Transaction, error) {
code, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
payload := &types.WasmAction{
Ty: WasmActionCreate,
Value: &types.WasmAction_Create{
Create: &types.WasmCreate{
Name: name,
Code: code,
},
},
}
tx := &types.Transaction{Execer: []byte(paraName + WasmX), Payload: types.Encode(payload), Fee: 1e5, Nonce: r.Int63(), To: crypto.GetExecAddress(paraName + WasmX)}
tx, err = sdk.Sign(tx, privKey, crypto.SM2, uid)
if err != nil {
return nil, err
}
tx.Signature.Signature = crypto.EncodeCertToSignature(tx.Signature.Signature, cert, uid)
return tx, nil
}
func CreateWasmCallTx(paraName, contract, method string, param []int64, env []string, privKey, cert, uid []byte) (*types.Transaction, error) {
payload := &types.WasmAction{
Ty: WasmActionCall,
Value: &types.WasmAction_Call{
Call: &types.WasmCall{
Contract: contract,
Method: method,
Parameters: param,
Env: env,
},
},
}
tx := &types.Transaction{Execer: []byte(paraName + WasmX), Payload: types.Encode(payload), Fee: 1e5, Nonce: r.Int63(), To: crypto.GetExecAddress(paraName + WasmX)}
var err error
tx, err = sdk.Sign(tx, privKey, crypto.SM2, uid)
if err != nil {
return nil, err
}
tx.Signature.Signature = crypto.EncodeCertToSignature(tx.Signature.Signature, cert, uid)
return tx, nil
}
File mode changed from 100644 to 100755
syntax = "proto3";
package types;
message wasmAction {
oneof value {
wasmCreate create = 1;
wasmCall call = 2;
}
int32 ty = 3;
}
message wasmCreate {
string name = 1;
bytes code = 2;
}
message wasmCall {
string contract = 1;
string method = 2;
repeated int64 parameters = 3;
repeated string env = 4;
}
message queryCheckContract {
string name = 1;
}
message customLog {
repeated string info = 1;
}
message createContractLog {
string name = 1;
string code = 2;
}
message callContractLog {
string contract = 1;
string method = 2;
int32 result = 3;
}
message localDataLog {
bytes key = 1;
bytes value = 2;
}
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