Commit 9c8815d3 authored by lihailei's avatar lihailei

Fix checked out bugs.

parent 3990abb9
...@@ -4,12 +4,15 @@ import ( ...@@ -4,12 +4,15 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"bytes"
log "github.com/inconshreveable/log15" log "github.com/inconshreveable/log15"
"gitlab.33.cn/chain33/chain33/account" "gitlab.33.cn/chain33/chain33/account"
common "gitlab.33.cn/chain33/chain33/common" common "gitlab.33.cn/chain33/chain33/common"
crypto "gitlab.33.cn/chain33/chain33/common/crypto" crypto "gitlab.33.cn/chain33/chain33/common/crypto"
jsonrpc "gitlab.33.cn/chain33/chain33/rpc" jsonrpc "gitlab.33.cn/chain33/chain33/rpc"
"gitlab.33.cn/chain33/chain33/types" "gitlab.33.cn/chain33/chain33/types"
"io/ioutil"
"net/http"
"os" "os"
) )
...@@ -122,6 +125,21 @@ func (c *RpcCtx) RunWithoutMarshal() (string, error) { ...@@ -122,6 +125,21 @@ func (c *RpcCtx) RunWithoutMarshal() (string, error) {
} }
return res, nil return res, nil
} }
func SendTransaction(tx *types.Transaction) (string, error) {
poststr := fmt.Sprintf(`{"jsonrpc":"2.0","id":2,"method":"Chain33.SendTransaction","params":[{"data":"%v"}]}`,
common.ToHex(types.Encode(tx)))
resp, err := http.Post(GetJrpcURL(), "application/json", bytes.NewBufferString(poststr))
if err != nil {
panic(err)
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
return string(b), err
}
func Getprivkey(key string) crypto.PrivKey { func Getprivkey(key string) crypto.PrivKey {
cr, err := crypto.New(types.GetSignatureTypeName(types.SECP256K1)) cr, err := crypto.New(types.GetSignatureTypeName(types.SECP256K1))
if err != nil { if err != nil {
......
...@@ -2,16 +2,14 @@ package controllers ...@@ -2,16 +2,14 @@ package controllers
import ( import (
"github.com/astaxie/beego" "github.com/astaxie/beego"
"gitlab.33.cn/chain33/chain33/account"
. "gitlab.33.cn/chain33/chain33/common"
jsonrpc "gitlab.33.cn/chain33/chain33/rpc" jsonrpc "gitlab.33.cn/chain33/chain33/rpc"
"gitlab.33.cn/chain33/chain33/types" "gitlab.33.cn/chain33/chain33/types"
. "gitlab.33.cn/lihailei/chain33_sdk/src/common" . "gitlab.33.cn/lihailei/chain33_sdk/src/common"
"encoding/json" "encoding/json"
"fmt"
blacklist "gitlab.33.cn/lihailei/chain33_sdk/src/models/contract/blacklist/types" blacklist "gitlab.33.cn/lihailei/chain33_sdk/src/models/contract/blacklist/types"
r "math/rand"
"net/http" "net/http"
) )
...@@ -35,11 +33,11 @@ func (c *ContractController) Invoke() { ...@@ -35,11 +33,11 @@ func (c *ContractController) Invoke() {
if c.Ctx.Request.Method == http.MethodPost && funcName == blacklist.FuncName_CreateOrg { if c.Ctx.Request.Method == http.MethodPost && funcName == blacklist.FuncName_CreateOrg {
var org blacklist.Org var org blacklist.Org
json.Unmarshal(c.Ctx.Input.RequestBody, &org) json.Unmarshal(c.Ctx.Input.RequestBody, &org)
fmt.Println("orgName:", org.OrgName)
action := &blacklist.BlackAction{Value: &blacklist.BlackAction_Or{&org}, FuncName: blacklist.FuncName_CreateOrg} action := &blacklist.BlackAction{Value: &blacklist.BlackAction_Or{&org}, FuncName: blacklist.FuncName_CreateOrg}
privKey := "CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944" addr, priv := Genaddress()
res, err := sendTx("user.blacklist", privKey, types.Encode(action)) tx := &types.Transaction{Execer: []byte("user.blacklist"), Payload: types.Encode(action), Fee: 1e6, To: addr}
fmt.Println(res) tx.Sign(types.SECP256K1, priv)
res, err := SendTransaction(tx)
if err != nil { if err != nil {
c.Data["json"] = err.Error() c.Data["json"] = err.Error()
c.ServeJSON() c.ServeJSON()
...@@ -71,8 +69,10 @@ func (c *ContractController) Invoke() { ...@@ -71,8 +69,10 @@ func (c *ContractController) Invoke() {
var tr blacklist.Transaction var tr blacklist.Transaction
json.Unmarshal(c.Ctx.Input.RequestBody, &tr) json.Unmarshal(c.Ctx.Input.RequestBody, &tr)
action := &blacklist.BlackAction{Value: &blacklist.BlackAction_Tr{&tr}, FuncName: blacklist.FuncName_Transfer} action := &blacklist.BlackAction{Value: &blacklist.BlackAction_Tr{&tr}, FuncName: blacklist.FuncName_Transfer}
privKey := "CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944" addr, priv := Genaddress()
res, err := sendTx("user.blacklist", privKey, types.Encode(action)) tx := &types.Transaction{Execer: []byte("user.blacklist"), Payload: types.Encode(action), Fee: 1e6, To: addr}
tx.Sign(types.SECP256K1, priv)
res, err := SendTransaction(tx)
if err != nil { if err != nil {
c.Data["json"] = err.Error() c.Data["json"] = err.Error()
c.ServeJSON() c.ServeJSON()
...@@ -83,22 +83,6 @@ func (c *ContractController) Invoke() { ...@@ -83,22 +83,6 @@ func (c *ContractController) Invoke() {
} }
} }
func sendTx(execer string, privKey string, body []byte) (string, error) {
tx := &types.Transaction{Execer: []byte(execer), Payload: body, Fee: 1e6}
tx.Nonce = r.Int63()
_, priv := Genaddress()
tx.Sign(types.SECP256K1, priv)
tx.To = account.ExecAddress(execer).String()
data := ToHex(types.Encode(tx))
params := jsonrpc.RawParm{
Data: data,
}
ctx := NewRpcCtx(GetJrpcURL(), "Chain33.SendTransaction", params, nil)
res, err := ctx.RunWithoutMarshal()
return res, err
}
func queryChain(req jsonrpc.Query4Jrpc) ([]byte, error) { func queryChain(req jsonrpc.Query4Jrpc) ([]byte, error) {
var res interface{} var res interface{}
ctx := NewRpcCtx(GetJrpcURL(), "Chain33.Query", req, &res) ctx := NewRpcCtx(GetJrpcURL(), "Chain33.Query", req, &res)
......
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