package chain33

import (
	"context"
	"google.golang.org/grpc"
	"github.com/33cn/chain33/types"

)

type PaiClient struct {

}

var (
	paiClient types.Chain33Client
	paiNetgrpcAddr = "localhost:8802"
)

func init() {
	maxReceLimit := grpc.WithMaxMsgSize(30*1024*1024)
	conn, err := grpc.Dial(paiNetgrpcAddr, grpc.WithInsecure(),maxReceLimit)
	if err != nil {
		panic(err)
	}
	paiClient = types.NewChain33Client(conn)
}

func (p *PaiClient) GetWalletStatus() (*types.WalletStatus,error) {
	return paiClient.GetWalletStatus(context.Background(),&types.ReqNil{})
}

func (p *PaiClient) GetPeerInfo() (*types.PeerList,error) {
	return paiClient.GetPeerInfo(context.Background(),&types.P2PGetPeerReq{})
}

func (p *PaiClient) IsNtpClockSync() (*types.Reply,error) {
	return paiClient.IsNtpClockSync(context.Background(),&types.ReqNil{})
}

func (p *PaiClient) GetNetInfo() (*types.NodeNetInfo,error) {
	return paiClient.NetInfo(context.Background(),&types.P2PGetNetInfoReq{})
}

func (p *PaiClient) Version()(*types.VersionInfo,error){
	return paiClient.Version(context.Background(),&types.ReqNil{})
}

func (p *PaiClient) Close() (*types.Reply,error) {
	return paiClient.CloseQueue(context.Background(),&types.ReqNil{})
}

func (p *PaiClient) Unlock(lock *types.WalletUnLock)(*types.Reply,error){
	return paiClient.UnLock(context.Background(),lock)
}

func (p *PaiClient) IsSync() (*types.Reply,error) {
	return paiClient.IsSync(context.Background(),&types.ReqNil{})
}
