Commit 3a9d1123 authored by lihailei's avatar lihailei

add log module.

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