Commit 3a9d1123 authored by lihailei's avatar lihailei

add log module.

parent 47f0d776
...@@ -3,13 +3,14 @@ package common ...@@ -3,13 +3,14 @@ package common
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"os"
log "github.com/inconshreveable/log15"
jsonrpc "gitlab.33.cn/chain33/chain33/rpc" jsonrpc "gitlab.33.cn/chain33/chain33/rpc"
) )
var ( var (
chain33_jrpcUrl = "http://localhost:8801" chain33_jrpcUrl = "http://localhost:8801"
clog = log.New("module", "common")
) )
func SetJrpcURL(url string) { func SetJrpcURL(url string) {
...@@ -43,50 +44,16 @@ func NewRpcCtx(laddr, methed string, params, res interface{}) *RpcCtx { ...@@ -43,50 +44,16 @@ func NewRpcCtx(laddr, methed string, params, res interface{}) *RpcCtx {
func (c *RpcCtx) SetResultCb(cb Callback) { func (c *RpcCtx) SetResultCb(cb Callback) {
c.cb = cb c.cb = cb
} }
//func (c *RpcCtx) Run() {
// rpc, err := jsonrpc.NewJSONClient(c.Addr)
// if err != nil {
// fmt.Fprintln(os.Stderr, err)
// return
// }
//
// err = rpc.Call(c.Method, c.Params, c.Res)
// if err != nil {
// fmt.Fprintln(os.Stderr, err)
// return
// }
//
// // maybe format rpc result
// var result interface{}
// if c.cb != nil {
// result, err = c.cb(c.Res)
// if err != nil {
// fmt.Fprintln(os.Stderr, err)
// return
// }
// } else {
// result = c.Res
// }
//
// data, err := json.MarshalIndent(result, "", " ")
// if err != nil {
// fmt.Fprintln(os.Stderr, err)
// return
// }
//
// fmt.Println(string(data))
//}
func (c *RpcCtx) ReplyData() ([]byte, error) { func (c *RpcCtx) ReplyData() ([]byte, error) {
rpc, err := jsonrpc.NewJSONClient(c.Addr) rpc, err := jsonrpc.NewJSONClient(c.Addr)
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err) clog.Error(fmt.Sprintf("NewJsonClient have err:%v", err.Error()))
return nil, err return nil, err
} }
err = rpc.Call(c.Method, c.Params, c.Res) err = rpc.Call(c.Method, c.Params, c.Res)
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err) clog.Error(fmt.Sprintf("rpc.Call have err:%v", err.Error()))
return nil, err return nil, err
} }
...@@ -95,7 +62,7 @@ func (c *RpcCtx) ReplyData() ([]byte, error) { ...@@ -95,7 +62,7 @@ func (c *RpcCtx) ReplyData() ([]byte, error) {
if c.cb != nil { if c.cb != nil {
result, err = c.cb(c.Res) result, err = c.cb(c.Res)
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err) clog.Error(fmt.Sprintf("rpc.CallBack have err:%v", err.Error()))
return nil, err return nil, err
} }
} else { } else {
...@@ -104,9 +71,8 @@ func (c *RpcCtx) ReplyData() ([]byte, error) { ...@@ -104,9 +71,8 @@ func (c *RpcCtx) ReplyData() ([]byte, error) {
data, err := json.MarshalIndent(result, "", " ") data, err := json.MarshalIndent(result, "", " ")
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err) clog.Error(fmt.Sprintf("MarshalIndent have err:%v", err.Error()))
return nil, err return nil, err
} }
return data, nil return data, nil
//fmt.Println(string(data))
} }
...@@ -4,10 +4,15 @@ import ( ...@@ -4,10 +4,15 @@ import (
"fmt" "fmt"
"strconv" "strconv"
log "github.com/inconshreveable/log15"
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"
) )
var (
mlog = log.New("module", "common")
)
type AccountsResult struct { type AccountsResult struct {
Wallets []*WalletResult `json:"wallets"` Wallets []*WalletResult `json:"wallets"`
} }
...@@ -279,7 +284,7 @@ func decodeLog(rlog jsonrpc.ReceiptDataResult) *ReceiptData { ...@@ -279,7 +284,7 @@ func decodeLog(rlog jsonrpc.ReceiptDataResult) *ReceiptData {
Current: decodeAccount(constructAccFromLog(l, "current"), types.TokenPrecision), Current: decodeAccount(constructAccFromLog(l, "current"), types.TokenPrecision),
} }
default: default:
fmt.Printf("---The log with vlaue:%d is not decoded --------------------\n", l.Ty) mlog.Warn(fmt.Sprintf("---The log with vlaue:%d is not decoded --------------------\n", l.Ty))
return nil return nil
} }
rd.Logs = append(rd.Logs, rl) rd.Logs = append(rd.Logs, rl)
......
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