Commit c7c6f16a authored by Litian's avatar Litian

Merge branch 'master' into evm_abi

parents 68ace11b 87d3a21b
......@@ -15,6 +15,7 @@ function filterLinter() {
--enable=varcheck \
--enable=structcheck \
--enable=goimports \
--enable=misspell \
--vendor ./...)
# --enable=staticcheck \
# --enable=gocyclo \
......
......@@ -148,5 +148,5 @@ func clearTestData() {
if err != nil {
fmt.Println("delete wallet have a err:", err.Error())
}
fmt.Println("test data clear sucessfully!")
fmt.Println("test data clear successfully!")
}
......@@ -175,5 +175,5 @@ func clearTestData() {
if err != nil {
fmt.Println("delete chain33_raft dir have a err:", err.Error())
}
fmt.Println("test data clear sucessfully!")
fmt.Println("test data clear successfully!")
}
......@@ -181,7 +181,7 @@ func remoteScp(si *ScpInfo, reqnum chan struct{}) {
}()
ScpFileFromLocalToRemote(si)
//session, err := sshconnect("ubuntu", "Fuzamei#123456", "raft15258.chinacloudapp.cn", 22)
fmt.Println("remoteScp file sucessfully!:")
fmt.Println("remoteScp file successfully!:")
}
......
......@@ -396,7 +396,7 @@ func (node *Node) stopAndRemovePeer(peer Peer, reason interface{}) {
peer.Stop()
}
// StopPeerForError called if error occured
// StopPeerForError called if error occurred
func (node *Node) StopPeerForError(peer Peer, reason interface{}) {
tendermintlog.Error("Stopping peer for error", "peer", peer, "err", reason)
addr, err := peer.RemoteAddr()
......
......@@ -161,7 +161,7 @@ func clearTestData() {
if err != nil {
fmt.Println("delete datadir have a err:", err.Error())
}
fmt.Println("test data clear sucessfully!")
fmt.Println("test data clear successfully!")
}
func NormPut() {
......
......@@ -51,7 +51,7 @@ func TestTicket(t *testing.T) {
//js, _ := json.MarshalIndent(detail, "", " ")
//fmt.Println(string(js))
assert.Equal(t, int32(2), detail.Receipt.Ty)
reply, err = mock33.GetAPI().ExecWalletFunc("ticket", "WalletAutoMiner", &ty.MinerFlag{Flag: 1})
_, err = mock33.GetAPI().ExecWalletFunc("ticket", "WalletAutoMiner", &ty.MinerFlag{Flag: 1})
assert.Nil(t, err)
err = mock33.WaitHeight(100)
assert.Nil(t, err)
......
......@@ -81,7 +81,7 @@ func blackwhiteCreate(cmd *cobra.Command, args []string) {
}
var res string
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "blackwhite.BlackwhiteCreateTx", params, &res)
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "blackwhite.BlackwhiteCreateTx", params, &res)
ctx.RunWithoutMarshal()
}
......@@ -141,7 +141,7 @@ func blackwhitePlay(cmd *cobra.Command, args []string) {
Fee: feeInt64,
}
var res string
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "blackwhite.BlackwhitePlayTx", params, &res)
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "blackwhite.BlackwhitePlayTx", params, &res)
ctx.RunWithoutMarshal()
}
......@@ -180,7 +180,7 @@ func blackwhiteShow(cmd *cobra.Command, args []string) {
Fee: feeInt64,
}
var res string
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "blackwhite.BlackwhiteShowTx", params, &res)
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "blackwhite.BlackwhiteShowTx", params, &res)
ctx.RunWithoutMarshal()
}
......@@ -213,7 +213,7 @@ func blackwhiteTimeoutDone(cmd *cobra.Command, args []string) {
Fee: feeInt64,
}
var res string
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "blackwhite.BlackwhiteTimeoutDoneTx", params, &res)
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "blackwhite.BlackwhiteTimeoutDoneTx", params, &res)
ctx.RunWithoutMarshal()
}
......@@ -290,6 +290,6 @@ func showBlackwhiteInfo(cmd *cobra.Command, args []string) {
rep = &gt.ReplyLoopResults{}
}
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "Chain33.Query", params, rep)
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.Query", params, rep)
ctx.Run()
}
......@@ -528,26 +528,26 @@ func (a *action) getWinner(round *gt.BlackwhiteRound) ([]*addrResult, *gt.ReplyL
addrRes := round.AddrResult
loop := int(round.Loop)
for _, addres := range addrRes {
if len(addres.ShowSecret) > 0 && len(addres.HashValues) == loop {
for _, address := range addrRes {
if len(address.ShowSecret) > 0 && len(address.HashValues) == loop {
var isBlack []bool
// 加入分叉高度判断:分叉高度在ForkV25BlackWhite到ForkV25BlackWhiteV2之间的执行原来逻辑,大于ForkV25BlackWhiteV2执行新逻辑,
// 小于ForkV25BlackWhite则无法进入
if !types.IsDappFork(a.height, gt.BlackwhiteX, "ForkBlackWhiteV2") {
for _, hash := range addres.HashValues {
if bytes.Equal(common.Sha256([]byte(addres.ShowSecret+black)), hash) {
for _, hash := range address.HashValues {
if bytes.Equal(common.Sha256([]byte(address.ShowSecret+black)), hash) {
isBlack = append(isBlack, true)
} else if bytes.Equal(common.Sha256([]byte(addres.ShowSecret+white)), hash) {
} else if bytes.Equal(common.Sha256([]byte(address.ShowSecret+white)), hash) {
isBlack = append(isBlack, false)
} else {
isBlack = append(isBlack, false)
}
}
} else {
for i, hash := range addres.HashValues {
if bytes.Equal(common.Sha256([]byte(strconv.Itoa(i)+addres.ShowSecret+black)), hash) {
for i, hash := range address.HashValues {
if bytes.Equal(common.Sha256([]byte(strconv.Itoa(i)+address.ShowSecret+black)), hash) {
isBlack = append(isBlack, true)
} else if bytes.Equal(common.Sha256([]byte(strconv.Itoa(i)+addres.ShowSecret+white)), hash) {
} else if bytes.Equal(common.Sha256([]byte(strconv.Itoa(i)+address.ShowSecret+white)), hash) {
isBlack = append(isBlack, false)
} else {
isBlack = append(isBlack, false)
......@@ -555,8 +555,8 @@ func (a *action) getWinner(round *gt.BlackwhiteRound) ([]*addrResult, *gt.ReplyL
}
}
addresX := &resultCalc{
Addr: addres.Addr,
amount: addres.Amount,
Addr: address.Addr,
amount: address.Amount,
IsWin: true,
IsBlack: isBlack,
}
......
......@@ -217,7 +217,7 @@ func Test_getWinnerAndLoser(t *testing.T) {
Loop: 4,
}
addres := &gt.AddressResult{
address := &gt.AddressResult{
Addr: "1",
HashValues: [][]byte{common.Sha256([]byte(strconv.Itoa(0) + showSecret + black)),
common.Sha256([]byte(strconv.Itoa(1) + showSecret + white)),
......@@ -225,9 +225,9 @@ func Test_getWinnerAndLoser(t *testing.T) {
common.Sha256([]byte(strconv.Itoa(3) + showSecret + white))},
ShowSecret: showSecret,
}
addrRes = append(addrRes, addres)
addrRes = append(addrRes, address)
addres = &gt.AddressResult{
address = &gt.AddressResult{
Addr: "2",
HashValues: [][]byte{common.Sha256([]byte(strconv.Itoa(0) + showSecret + black)),
common.Sha256([]byte(strconv.Itoa(1) + showSecret + white)),
......@@ -235,9 +235,9 @@ func Test_getWinnerAndLoser(t *testing.T) {
common.Sha256([]byte(strconv.Itoa(3) + showSecret + white))},
ShowSecret: showSecret,
}
addrRes = append(addrRes, addres)
addrRes = append(addrRes, address)
addres = &gt.AddressResult{
address = &gt.AddressResult{
Addr: "3",
HashValues: [][]byte{common.Sha256([]byte(strconv.Itoa(0) + showSecret + black)),
common.Sha256([]byte(strconv.Itoa(1) + showSecret + white)),
......@@ -245,7 +245,7 @@ func Test_getWinnerAndLoser(t *testing.T) {
common.Sha256([]byte(strconv.Itoa(3) + showSecret + black))},
ShowSecret: showSecret,
}
addrRes = append(addrRes, addres)
addrRes = append(addrRes, address)
round.AddrResult = addrRes
......@@ -257,7 +257,7 @@ func Test_getWinnerAndLoser(t *testing.T) {
//t.Logf("winers1 is %v", winers)
//t.Logf("losers1 is %v", losers)
addres = &gt.AddressResult{
address = &gt.AddressResult{
Addr: "4",
HashValues: [][]byte{common.Sha256([]byte(strconv.Itoa(0) + showSecret + black)),
common.Sha256([]byte(strconv.Itoa(1) + showSecret + white)),
......@@ -265,9 +265,9 @@ func Test_getWinnerAndLoser(t *testing.T) {
common.Sha256([]byte(strconv.Itoa(3) + showSecret + black))},
ShowSecret: showSecret,
}
addrRes = append(addrRes, addres)
addrRes = append(addrRes, address)
addres = &gt.AddressResult{
address = &gt.AddressResult{
Addr: "5",
HashValues: [][]byte{common.Sha256([]byte(strconv.Itoa(0) + showSecret + black)),
common.Sha256([]byte(strconv.Itoa(1) + showSecret + white)),
......@@ -275,7 +275,7 @@ func Test_getWinnerAndLoser(t *testing.T) {
common.Sha256([]byte(strconv.Itoa(3) + showSecret + white))},
ShowSecret: showSecret,
}
addrRes = append(addrRes, addres)
addrRes = append(addrRes, address)
round.AddrResult = addrRes
......@@ -286,7 +286,7 @@ func Test_getWinnerAndLoser(t *testing.T) {
//t.Logf("winers2 is %v", winers)
//t.Logf("losers2 is %v", losers)
addres = &gt.AddressResult{
address = &gt.AddressResult{
Addr: "6",
HashValues: [][]byte{common.Sha256([]byte(strconv.Itoa(0) + showSecret + black)),
common.Sha256([]byte(strconv.Itoa(1) + showSecret + white)),
......@@ -298,7 +298,7 @@ func Test_getWinnerAndLoser(t *testing.T) {
common.Sha256([]byte(strconv.Itoa(7) + showSecret + white))},
ShowSecret: showSecret,
}
addrRes = append(addrRes, addres)
addrRes = append(addrRes, address)
round.AddrResult = addrRes
......
......@@ -285,3 +285,8 @@ func heightIndexToIndex(height int64, index int32) int64 {
func (c *Blackwhite) GetPayloadValue() types.Message {
return &gt.BlackwhiteAction{}
}
// CheckReceiptExecOk return true to check if receipt ty is ok
func (c *Blackwhite) CheckReceiptExecOk() bool {
return true
}
......@@ -67,7 +67,7 @@ func (b BlackwhiteType) ActionName(tx *types.Transaction) string {
var g BlackwhiteAction
err := types.Decode(tx.Payload, &g)
if err != nil {
return "unkown-Blackwhite-action-err"
return "unknown-Blackwhite-action-err"
}
if g.Ty == BlackwhiteActionCreate && g.GetCreate() != nil {
return "BlackwhiteCreate"
......@@ -78,7 +78,7 @@ func (b BlackwhiteType) ActionName(tx *types.Transaction) string {
} else if g.Ty == BlackwhiteActionTimeoutDone && g.GetTimeoutDone() != nil {
return "BlackwhiteTimeoutDone"
}
return "unkown"
return "unknown"
}
// Amount ...
......
......@@ -97,7 +97,7 @@ func (c *Cert) loadHistoryByPrefix() error {
Direction: 0,
Count: 0,
}
result, err := c.DriverBase.GetApi().LocalList(parm)
result, err := c.DriverBase.GetAPI().LocalList(parm)
if err != nil {
return err
}
......@@ -126,7 +126,7 @@ func (c *Cert) loadHistoryByPrefix() error {
func (c *Cert) loadHistoryByHeight() error {
key := calcCertHeightKey(c.GetHeight())
parm := &types.LocalDBGet{Keys: [][]byte{key}}
result, err := c.DriverBase.GetApi().LocalGet(parm)
result, err := c.DriverBase.GetAPI().LocalGet(parm)
if err != nil {
return err
}
......@@ -139,3 +139,8 @@ func (c *Cert) loadHistoryByHeight() error {
}
return ct.ErrGetHistoryCertData
}
// CheckReceiptExecOk return true to check if receipt ty is ok
func (c *Cert) CheckReceiptExecOk() bool {
return true
}
......@@ -22,9 +22,6 @@ func (c *Cert) ExecLocal_New(payload *ct.CertNew, tx *types.Transaction, receipt
clog.Error("Authority is not available. Please check the authority config or authority initialize error logs.")
return nil, ct.ErrInitializeAuthority
}
if receiptData.GetTy() != types.ExecOk {
return &types.LocalDBSet{}, nil
}
var set types.LocalDBSet
historityCertdata := &types.HistoryCertStore{}
......@@ -54,9 +51,6 @@ func (c *Cert) ExecLocal_Update(payload *ct.CertUpdate, tx *types.Transaction, r
clog.Error("Authority is not available. Please check the authority config or authority initialize error logs.")
return nil, ct.ErrInitializeAuthority
}
if receiptData.GetTy() != types.ExecOk {
return &types.LocalDBSet{}, nil
}
var set types.LocalDBSet
// 写入上一纪录的next-height
......@@ -87,9 +81,6 @@ func (c *Cert) ExecLocal_Normal(payload *ct.CertNormal, tx *types.Transaction, r
clog.Error("Authority is not available. Please check the authority config or authority initialize error logs.")
return nil, ct.ErrInitializeAuthority
}
if receiptData.GetTy() != types.ExecOk {
return &types.LocalDBSet{}, nil
}
var set types.LocalDBSet
return &set, nil
......
......@@ -160,7 +160,7 @@ func evmBalance(cmd *cobra.Command, args []string) {
StateHash: "",
}
var res []*rpctypes.Account
ctx := jsonclient.NewRpcCtx(rpcLaddr, "Chain33.GetBalance", params, &res)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.GetBalance", params, &res)
ctx.SetResultCb(parseGetBalanceRes)
ctx.Run()
}
......@@ -240,7 +240,7 @@ func createContract(cmd *cobra.Command, args []string) {
Data: data,
}
ctx := jsonclient.NewRpcCtx(rpcLaddr, "Chain33.SendTransaction", params, nil)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.SendTransaction", params, nil)
ctx.RunWithoutMarshal()
}
......@@ -376,7 +376,7 @@ func callContract(cmd *cobra.Command, args []string) {
Data: data,
}
ctx := jsonclient.NewRpcCtx(rpcLaddr, "Chain33.SendTransaction", params, nil)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.SendTransaction", params, nil)
ctx.RunWithoutMarshal()
}
......@@ -681,7 +681,7 @@ func evmTransfer(cmd *cobra.Command, args []string) {
Data: data,
}
ctx := jsonclient.NewRpcCtx(rpcLaddr, "Chain33.SendTransaction", params, nil)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.SendTransaction", params, nil)
ctx.RunWithoutMarshal()
}
......@@ -729,7 +729,7 @@ func evmWithdraw(cmd *cobra.Command, args []string) {
Data: data,
}
ctx := jsonclient.NewRpcCtx(rpcLaddr, "Chain33.SendTransaction", params, nil)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.SendTransaction", params, nil)
ctx.RunWithoutMarshal()
}
......
......@@ -117,6 +117,11 @@ func (evm *EVMExecutor) IsFriend(myexec, writekey []byte, othertx *types.Transac
return false
}
// CheckReceiptExecOk return true to check if receipt ty is ok
func (c *EVMExecutor) CheckReceiptExecOk() bool {
return true
}
// 生成一个新的合约对象地址
func (evm *EVMExecutor) getNewAddr(txHash []byte) common.Address {
return common.NewAddress(txHash)
......@@ -150,7 +155,7 @@ func (evm *EVMExecutor) NewEVMContext(msg *common.Message) runtime.Context {
return runtime.Context{
CanTransfer: CanTransfer,
Transfer: Transfer,
GetHash: GetHashFn(evm.GetApi()),
GetHash: GetHashFn(evm.GetAPI()),
Origin: msg.From(),
Coinbase: nil,
BlockNumber: new(big.Int).SetInt64(evm.GetHeight()),
......
......@@ -106,7 +106,7 @@ func runDir(tt *testing.T, basePath string) {
}
func runCase(tt *testing.T, c VMCase, file string) {
tt.Logf("runing test case:%s in file:%s", c.name, file)
tt.Logf("running test case:%s in file:%s", c.name, file)
// 1 构建预置环境 pre
inst := evm.NewEVMExecutor()
......
......@@ -12,9 +12,6 @@ import (
// roll back local db data
func (g *Game) execDelLocal(receiptData *types.ReceiptData) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{}
if receiptData.GetTy() != types.ExecOk {
return dbSet, nil
}
for _, log := range receiptData.Logs {
switch log.GetTy() {
case gt.TyLogCreateGame, gt.TyLogMatchGame, gt.TyLogCloseGame, gt.TyLogCancleGame:
......
......@@ -12,9 +12,6 @@ import (
// save receiptData to local db
func (g *Game) execLocal(receiptData *types.ReceiptData) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{}
if receiptData.GetTy() != types.ExecOk {
return dbSet, nil
}
for _, log := range receiptData.Logs {
switch log.Ty {
case gt.TyLogCreateGame, gt.TyLogMatchGame, gt.TyLogCloseGame, gt.TyLogCancleGame:
......
......@@ -174,3 +174,8 @@ func (g *Game) GetTypeMap() map[string]int32 {
"Close": gt.GameActionClose,
}
}
// CheckReceiptExecOk return true to check if receipt ty is ok
func (g *Game) CheckReceiptExecOk() bool {
return true
}
......@@ -93,7 +93,7 @@ func hashlockLockCmd(cmd *cobra.Command, args []string) {
ActionName: "HashlockLock",
Payload: payLoad,
}
ctx := jsonclient.NewRpcCtx(rpcLaddr, "Chain33.CreateTransaction", paramWithExecAction, nil)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.CreateTransaction", paramWithExecAction, nil)
ctx.RunWithoutMarshal()
}
......@@ -136,7 +136,7 @@ func hashlockUnlockCmd(cmd *cobra.Command, args []string) {
ActionName: "HashlockUnlock",
Payload: payLoad,
}
ctx := jsonclient.NewRpcCtx(rpcLaddr, "Chain33.CreateTransaction", paramWithExecAction, nil)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.CreateTransaction", paramWithExecAction, nil)
ctx.RunWithoutMarshal()
}
......@@ -171,6 +171,6 @@ func hashlockSendCmd(cmd *cobra.Command, args []string) {
ActionName: "HashlockSend",
Payload: payLoad,
}
ctx := jsonclient.NewRpcCtx(rpcLaddr, "Chain33.CreateTransaction", paramWithExecAction, nil)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.CreateTransaction", paramWithExecAction, nil)
ctx.RunWithoutMarshal()
}
......@@ -12,9 +12,6 @@ import (
// ExecDelLocal_Hlock Action
func (h *Hashlock) ExecDelLocal_Hlock(hlock *pty.HashlockLock, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) {
if receipt.GetTy() != types.ExecOk {
return &types.LocalDBSet{}, nil
}
info := pty.Hashlockquery{Time: hlock.Time, Status: hashlockLocked, Amount: hlock.Amount, CreateTime: h.GetBlockTime(), CurrentTime: 0}
kv, err := UpdateHashReciver(h.GetLocalDB(), hlock.Hash, info)
if err != nil {
......@@ -25,9 +22,6 @@ func (h *Hashlock) ExecDelLocal_Hlock(hlock *pty.HashlockLock, tx *types.Transac
// ExecDelLocal_Hsend Action
func (h *Hashlock) ExecDelLocal_Hsend(hsend *pty.HashlockSend, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) {
if receipt.GetTy() != types.ExecOk {
return &types.LocalDBSet{}, nil
}
info := pty.Hashlockquery{Time: 0, Status: hashlockSent, Amount: 0, CreateTime: 0, CurrentTime: 0}
kv, err := UpdateHashReciver(h.GetLocalDB(), common.Sha256(hsend.Secret), info)
if err != nil {
......@@ -38,9 +32,6 @@ func (h *Hashlock) ExecDelLocal_Hsend(hsend *pty.HashlockSend, tx *types.Transac
// ExecDelLocal_Hunlock Action
func (h *Hashlock) ExecDelLocal_Hunlock(hunlock *pty.HashlockUnlock, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) {
if receipt.GetTy() != types.ExecOk {
return &types.LocalDBSet{}, nil
}
info := pty.Hashlockquery{Time: 0, Status: hashlockUnlocked, Amount: 0, CreateTime: 0, CurrentTime: 0}
kv, err := UpdateHashReciver(h.GetLocalDB(), common.Sha256(hunlock.Secret), info)
if err != nil {
......
......@@ -12,9 +12,6 @@ import (
// ExecLocal_Hlock Action
func (h *Hashlock) ExecLocal_Hlock(hlock *pty.HashlockLock, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) {
if receipt.GetTy() != types.ExecOk {
return &types.LocalDBSet{}, nil
}
info := pty.Hashlockquery{Time: hlock.Time, Status: hashlockLocked, Amount: hlock.Amount, CreateTime: h.GetBlockTime(), CurrentTime: 0}
clog.Error("ExecLocal", "info", info)
kv, err := UpdateHashReciver(h.GetLocalDB(), hlock.Hash, info)
......@@ -26,9 +23,6 @@ func (h *Hashlock) ExecLocal_Hlock(hlock *pty.HashlockLock, tx *types.Transactio
// ExecLocal_Hsend Action
func (h *Hashlock) ExecLocal_Hsend(hsend *pty.HashlockSend, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) {
if receipt.GetTy() != types.ExecOk {
return &types.LocalDBSet{}, nil
}
info := pty.Hashlockquery{Time: 0, Status: hashlockSent, Amount: 0, CreateTime: 0, CurrentTime: 0}
clog.Error("ExecLocal", "info", info)
kv, err := UpdateHashReciver(h.GetLocalDB(), common.Sha256(hsend.Secret), info)
......@@ -40,9 +34,6 @@ func (h *Hashlock) ExecLocal_Hsend(hsend *pty.HashlockSend, tx *types.Transactio
// ExecLocal_Hunlock Action
func (h *Hashlock) ExecLocal_Hunlock(hunlock *pty.HashlockUnlock, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) {
if receipt.GetTy() != types.ExecOk {
return &types.LocalDBSet{}, nil
}
info := pty.Hashlockquery{Time: 0, Status: hashlockUnlocked, Amount: 0, CreateTime: 0, CurrentTime: 0}
clog.Error("ExecLocal", "info", info)
kv, err := UpdateHashReciver(h.GetLocalDB(), common.Sha256(hunlock.Secret), info)
......
......@@ -52,3 +52,8 @@ func (h *Hashlock) GetDriverName() string {
func (h *Hashlock) CheckTx(tx *types.Transaction, index int) error {
return nil
}
// CheckReceiptExecOk return true to check if receipt ty is ok
func (h *Hashlock) CheckReceiptExecOk() bool {
return true
}
......@@ -188,7 +188,7 @@ func estHashlock(t *testing.T) {
func estHashunlock(t *testing.T) {
fmt.Println("TestHashunlock start")
defer fmt.Println("TestHashunlock end")
//not sucess as time not enough
//not success as time not enough
time.Sleep(5 * time.Second)
err := unlock(secret)
if err != nil {
......
......@@ -33,8 +33,8 @@ message Hashlockquery {
}
message HashRecv {
bytes HashlockId = 1;
Hashlockquery Infomation = 2;
bytes HashlockId = 1;
Hashlockquery Information = 2;
}
message HashlockUnlock {
......
......@@ -291,7 +291,7 @@ func (m *Hashlockquery) GetCurrentTime() int64 {
type HashRecv struct {
HashlockId []byte `protobuf:"bytes,1,opt,name=HashlockId,proto3" json:"HashlockId,omitempty"`
Infomation *Hashlockquery `protobuf:"bytes,2,opt,name=Infomation,proto3" json:"Infomation,omitempty"`
Information *Hashlockquery `protobuf:"bytes,2,opt,name=Information,proto3" json:"Information,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
......@@ -329,9 +329,9 @@ func (m *HashRecv) GetHashlockId() []byte {
return nil
}
func (m *HashRecv) GetInfomation() *Hashlockquery {
func (m *HashRecv) GetInformation() *Hashlockquery {
if m != nil {
return m.Infomation
return m.Information
}
return nil
}
......@@ -576,32 +576,32 @@ func init() {
func init() { proto.RegisterFile("hashlock.proto", fileDescriptor_acb83e90536b5ff8) }
var fileDescriptor_acb83e90536b5ff8 = []byte{
// 420 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x93, 0xcd, 0x6e, 0x9b, 0x40,
0x10, 0xc7, 0xbd, 0xd8, 0xd8, 0xf5, 0x60, 0xfb, 0xb0, 0xfd, 0x10, 0x87, 0xaa, 0x42, 0xa8, 0xaa,
0x90, 0x2a, 0x59, 0xaa, 0xdb, 0x17, 0x70, 0x7b, 0xc1, 0x52, 0x4f, 0x9b, 0xe4, 0x1e, 0x02, 0x6b,
0xd9, 0x8a, 0xbd, 0xeb, 0x2c, 0x8b, 0x25, 0xf2, 0x18, 0x91, 0xf2, 0x2a, 0x79, 0x9c, 0x3c, 0x4b,
0xb4, 0x03, 0x64, 0x31, 0x49, 0x6e, 0xb9, 0x31, 0x7f, 0x7e, 0xcc, 0xc7, 0x7f, 0x06, 0x98, 0x6d,
0x92, 0x7c, 0xb3, 0x93, 0xe9, 0xf5, 0xfc, 0xa0, 0xa4, 0x96, 0xd4, 0xd5, 0xe5, 0x81, 0xe7, 0xe1,
0x23, 0x81, 0x0f, 0x71, 0xfd, 0x86, 0x7e, 0x03, 0x68, 0xa8, 0x55, 0xe6, 0x93, 0x80, 0x44, 0x13,
0xd6, 0x52, 0xe8, 0x17, 0x18, 0xe6, 0x3a, 0xd1, 0x45, 0xee, 0x3b, 0x01, 0x89, 0x5c, 0x56, 0x47,
0xe6, 0xbb, 0x7f, 0x8a, 0x27, 0x9a, 0x9f, 0x6f, 0xf7, 0xdc, 0xef, 0x07, 0x24, 0xea, 0xb3, 0x96,
0x42, 0xbf, 0xc2, 0x58, 0xcb, 0x65, 0x96, 0x29, 0x9e, 0xe7, 0xfe, 0x20, 0x20, 0xd1, 0x98, 0x59,
0x81, 0x7e, 0x87, 0xa9, 0xe2, 0xba, 0x50, 0xa2, 0x21, 0x5c, 0x24, 0x4e, 0x45, 0x53, 0x3b, 0xd9,
0xcb, 0x42, 0x68, 0x7f, 0x88, 0xf9, 0xeb, 0xc8, 0xd4, 0x5e, 0x2b, 0x79, 0xcb, 0x85, 0x36, 0xb5,
0x47, 0x55, 0x6d, 0xab, 0x84, 0x77, 0x04, 0x26, 0xcd, 0x80, 0xff, 0xcd, 0x90, 0x36, 0x11, 0x39,
0x49, 0x44, 0x61, 0x80, 0x29, 0x1c, 0x54, 0xf1, 0xd9, 0x68, 0x66, 0x7c, 0x1c, 0x69, 0xc2, 0xf0,
0xf9, 0x3d, 0x86, 0x09, 0x7f, 0xd8, 0x9e, 0xce, 0xb8, 0xa8, 0x8c, 0xe5, 0xa9, 0xe2, 0xba, 0x36,
0xbd, 0x8e, 0xc2, 0x7b, 0x02, 0xd3, 0x06, 0xbc, 0x29, 0xb8, 0x2a, 0x9f, 0xbb, 0x24, 0xad, 0x2e,
0xdf, 0x5a, 0x8b, 0x9d, 0xb4, 0xdf, 0xb5, 0x2c, 0xb5, 0xeb, 0x1a, 0x54, 0x96, 0x59, 0x85, 0x06,
0xe0, 0xa5, 0x85, 0x52, 0x5c, 0x68, 0x04, 0x5c, 0x04, 0xda, 0x52, 0x78, 0x59, 0x1d, 0x0d, 0xe3,
0xe9, 0xd1, 0x64, 0x8b, 0x5f, 0x1c, 0x8d, 0x55, 0xe8, 0x1f, 0x80, 0x95, 0x58, 0xcb, 0x7d, 0xa2,
0xb7, 0x52, 0x60, 0x87, 0xde, 0xe2, 0xd3, 0x1c, 0xaf, 0x6f, 0x7e, 0x32, 0x1b, 0x6b, 0x71, 0x61,
0x04, 0xb3, 0xe6, 0xe5, 0x85, 0xd8, 0xd5, 0x7b, 0x7b, 0xd5, 0xa3, 0x07, 0x62, 0xd1, 0x65, 0x6a,
0x3e, 0xa6, 0x3f, 0xc1, 0xc5, 0x10, 0x49, 0x6f, 0xf1, 0xb1, 0x53, 0xcd, 0x9c, 0x41, 0xdc, 0x63,
0x15, 0x83, 0x70, 0xce, 0x45, 0x56, 0xb7, 0xd6, 0x85, 0xcd, 0x7e, 0x10, 0x36, 0x0c, 0xfd, 0x05,
0xa3, 0x4d, 0x81, 0xfd, 0xa0, 0xa7, 0xde, 0xe2, 0x73, 0x07, 0xaf, 0x9a, 0x8d, 0x7b, 0xac, 0xe1,
0xe8, 0x0c, 0x1c, 0x5d, 0xa2, 0xcb, 0x2e, 0x73, 0x74, 0xf9, 0x77, 0x04, 0xee, 0x31, 0xd9, 0x15,
0xfc, 0x6a, 0x88, 0x3f, 0xe2, 0xef, 0xa7, 0x00, 0x00, 0x00, 0xff, 0xff, 0x56, 0x5e, 0xa0, 0xf4,
0x9a, 0x03, 0x00, 0x00,
// 421 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x93, 0xcd, 0x6a, 0xdb, 0x40,
0x10, 0xc7, 0xbd, 0xb2, 0x65, 0xd7, 0x23, 0xdb, 0x87, 0xed, 0x07, 0x3a, 0x94, 0x22, 0x44, 0x29,
0x82, 0x82, 0xa1, 0x2e, 0xf4, 0xee, 0xf6, 0x22, 0x43, 0x4f, 0x9b, 0xe4, 0x01, 0x64, 0x69, 0x8d,
0x4d, 0xec, 0x5d, 0x67, 0xb5, 0x32, 0x28, 0x8f, 0x11, 0xc8, 0xab, 0xe4, 0x71, 0xf2, 0x2c, 0x61,
0x47, 0x52, 0x56, 0x56, 0x92, 0x5b, 0x6e, 0x9a, 0xbf, 0x7e, 0x9a, 0x8f, 0xff, 0x8c, 0x60, 0xb6,
0x4d, 0xf2, 0xed, 0x5e, 0xa6, 0xd7, 0xf3, 0xa3, 0x92, 0x5a, 0x52, 0x57, 0x97, 0x47, 0x9e, 0x87,
0x8f, 0x04, 0x3e, 0xc4, 0xf5, 0x1b, 0xfa, 0x0d, 0xa0, 0xa1, 0x56, 0x99, 0x4f, 0x02, 0x12, 0x4d,
0x58, 0x4b, 0xa1, 0x5f, 0x60, 0x98, 0xeb, 0x44, 0x17, 0xb9, 0xef, 0x04, 0x24, 0x72, 0x59, 0x1d,
0x99, 0xef, 0xfe, 0x29, 0x9e, 0x68, 0x7e, 0xb9, 0x3b, 0x70, 0xbf, 0x1f, 0x90, 0xa8, 0xcf, 0x5a,
0x0a, 0xfd, 0x0a, 0x63, 0x2d, 0x97, 0x59, 0xa6, 0x78, 0x9e, 0xfb, 0x83, 0x80, 0x44, 0x63, 0x66,
0x05, 0xfa, 0x1d, 0xa6, 0x8a, 0xeb, 0x42, 0x89, 0x86, 0x70, 0x91, 0x38, 0x17, 0x4d, 0xed, 0xe4,
0x20, 0x0b, 0xa1, 0xfd, 0x21, 0xe6, 0xaf, 0x23, 0x53, 0x7b, 0xa3, 0xe4, 0x2d, 0x17, 0xda, 0xd4,
0x1e, 0x55, 0xb5, 0xad, 0x12, 0xde, 0x11, 0x98, 0x34, 0x03, 0xfe, 0x37, 0x43, 0xda, 0x44, 0xe4,
0x2c, 0x11, 0x85, 0x01, 0xa6, 0x70, 0x50, 0xc5, 0x67, 0xa3, 0x99, 0xf1, 0x71, 0xa4, 0x09, 0xc3,
0xe7, 0xf7, 0x18, 0x26, 0xfc, 0x61, 0x7b, 0xba, 0xe0, 0xa2, 0x32, 0x96, 0xa7, 0x8a, 0xeb, 0xda,
0xf4, 0x3a, 0x0a, 0xef, 0x09, 0x4c, 0x1b, 0xf0, 0xa6, 0xe0, 0xaa, 0x7c, 0xee, 0x92, 0xb4, 0xba,
0x7c, 0x6b, 0x2d, 0x76, 0xd2, 0x7e, 0xd7, 0xb2, 0xd4, 0xae, 0x6b, 0x50, 0x59, 0x66, 0x15, 0x1a,
0x80, 0x97, 0x16, 0x4a, 0x71, 0xa1, 0x11, 0x70, 0x11, 0x68, 0x4b, 0xe1, 0xba, 0x3a, 0x1a, 0xc6,
0xd3, 0x93, 0xc9, 0x16, 0xbf, 0x38, 0x1a, 0xab, 0xd0, 0x3f, 0xe0, 0xad, 0xc4, 0x46, 0xaa, 0x43,
0xa2, 0x77, 0x52, 0x60, 0x8b, 0xde, 0xe2, 0xd3, 0x1c, 0xcf, 0x6f, 0x7e, 0x36, 0x1c, 0x6b, 0x83,
0x61, 0x04, 0xb3, 0xe6, 0xed, 0x95, 0xd8, 0xd7, 0x9b, 0x7b, 0xd5, 0xa5, 0x07, 0x62, 0xd1, 0x65,
0x6a, 0x3e, 0xa6, 0x3f, 0xc1, 0xc5, 0x10, 0x49, 0x6f, 0xf1, 0xb1, 0x53, 0xce, 0x1c, 0x42, 0xdc,
0x63, 0x15, 0x83, 0x70, 0xce, 0x45, 0x56, 0xf7, 0xd6, 0x85, 0xcd, 0x86, 0x10, 0x36, 0x0c, 0xfd,
0x05, 0xa3, 0x6d, 0x81, 0xfd, 0xa0, 0xab, 0xde, 0xe2, 0x73, 0x07, 0xaf, 0x9a, 0x8d, 0x7b, 0xac,
0xe1, 0xe8, 0x0c, 0x1c, 0x5d, 0xa2, 0xcf, 0x2e, 0x73, 0x74, 0xf9, 0x77, 0x04, 0xee, 0x29, 0xd9,
0x17, 0x7c, 0x3d, 0xc4, 0x5f, 0xf1, 0xf7, 0x53, 0x00, 0x00, 0x00, 0xff, 0xff, 0x38, 0xf6, 0x91,
0xc1, 0x9c, 0x03, 0x00, 0x00,
}
......@@ -12,9 +12,6 @@ import (
func (l *Lottery) execDelLocal(tx *types.Transaction, receiptData *types.ReceiptData) (*types.LocalDBSet, error) {
set := &types.LocalDBSet{}
if receiptData.GetTy() != types.ExecOk {
return set, nil
}
for _, item := range receiptData.Logs {
switch item.Ty {
case pty.TyLogLotteryCreate, pty.TyLogLotteryBuy, pty.TyLogLotteryDraw, pty.TyLogLotteryClose:
......
......@@ -12,9 +12,6 @@ import (
func (l *Lottery) execLocal(tx *types.Transaction, receipt *types.ReceiptData) (*types.LocalDBSet, error) {
set := &types.LocalDBSet{}
if receipt.GetTy() != types.ExecOk {
return set, nil
}
for _, item := range receipt.Logs {
switch item.Ty {
case pty.TyLogLotteryCreate, pty.TyLogLotteryBuy, pty.TyLogLotteryDraw, pty.TyLogLotteryClose:
......
......@@ -229,3 +229,8 @@ func dellottery(lotteryID string, status int32) *types.KeyValue {
func (lott *Lottery) GetPayloadValue() types.Message {
return &pty.LotteryAction{}
}
// CheckReceiptExecOk return true to check if receipt ty is ok
func (lott *Lottery) CheckReceiptExecOk() bool {
return true
}
......@@ -136,7 +136,7 @@ func NewLotteryAction(l *Lottery, tx *types.Transaction, index int) *Action {
grpcClient := types.NewChain33Client(conn)
return &Action{l.GetCoinsAccount(), l.GetStateDB(), hash, fromaddr, l.GetBlockTime(),
l.GetHeight(), dapp.ExecAddress(string(tx.Execer)), l.GetDifficulty(), l.GetApi(), conn, grpcClient, index}
l.GetHeight(), dapp.ExecAddress(string(tx.Execer)), l.GetDifficulty(), l.GetAPI(), conn, grpcClient, index}
}
// GetReceiptLog generate logs for all lottery action
......@@ -548,11 +548,11 @@ func (action *Action) GetCalculableHash(beg, end int64, randMolNum int64) ([]byt
return modify, nil
}
//random used for verfication in solo
//random used for verification in solo
func (action *Action) findLuckyNum(isSolo bool, lott *LotteryDB) int64 {
var num int64
if isSolo {
//used for internal verfication
//used for internal verification
num = 12345
} else {
randMolNum := (lott.TotalPurchasedTxNum+action.height-lott.LastTransToPurState)%3 + 2 //3~5
......
......@@ -58,3 +58,8 @@ func Key(str []byte) (key []byte) {
key = append(key, str...)
return key
}
// CheckReceiptExecOk return true to check if receipt ty is ok
func (n *Norm) CheckReceiptExecOk() bool {
return true
}
......@@ -36,7 +36,7 @@ func newAction(t *Paracross, tx *types.Transaction) *action {
hash := tx.Hash()
fromaddr := tx.From()
return &action{t.GetCoinsAccount(), t.GetStateDB(), t.GetLocalDB(), hash, fromaddr,
t.GetBlockTime(), t.GetHeight(), dapp.ExecAddress(string(tx.Execer)), t.GetApi(), tx, t}
t.GetBlockTime(), t.GetHeight(), dapp.ExecAddress(string(tx.Execer)), t.GetAPI(), tx, t}
}
func getNodes(db dbm.KV, title string) (map[string]struct{}, error) {
......
......@@ -55,7 +55,7 @@ func (suite *AssetTransferTestSuite) SetupTest() {
suite.exec.SetLocalDB(suite.localDB)
suite.exec.SetStateDB(suite.stateDB)
suite.exec.SetEnv(0, 0, 0)
suite.exec.SetApi(suite.api)
suite.exec.SetAPI(suite.api)
enableParacrossTransfer = true
// setup block
......
......@@ -50,7 +50,7 @@ func (suite *AssetWithdrawTestSuite) SetupTest() {
suite.exec.SetLocalDB(suite.localDB)
suite.exec.SetStateDB(suite.stateDB)
suite.exec.SetEnv(0, 0, 0)
suite.exec.SetApi(suite.api)
suite.exec.SetAPI(suite.api)
enableParacrossTransfer = true
// setup block
......
......@@ -113,7 +113,7 @@ func (c *Paracross) saveLocalParaTxs(tx *types.Transaction, isDel bool) (*types.
for i := 0; i < len(commit.Status.CrossTxHashs); i++ {
success := util.BitMapBit(commit.Status.CrossTxResult, uint32(i))
paraTx, err := GetTx(c.GetApi(), commit.Status.CrossTxHashs[i])
paraTx, err := GetTx(c.GetAPI(), commit.Status.CrossTxHashs[i])
if err != nil {
clog.Crit("paracross.Commit Load Tx failed", "para title", commit.Status.Title,
"para height", commit.Status.Height, "para tx index", i, "error", err, "txHash",
......@@ -354,3 +354,8 @@ func (c *Paracross) allowIsParaAssetTx(execer []byte) bool {
}
return false
}
// CheckReceiptExecOk return true to check if receipt ty is ok
func (c *Paracross) CheckReceiptExecOk() bool {
return true
}
......@@ -103,7 +103,7 @@ func (suite *CommitTestSuite) SetupSuite() {
suite.exec.SetLocalDB(suite.localDB)
suite.exec.SetStateDB(suite.stateDB)
suite.exec.SetEnv(0, 0, 0)
suite.exec.SetApi(suite.api)
suite.exec.SetAPI(suite.api)
enableParacrossTransfer = false
// TODO, more fields
......@@ -355,7 +355,7 @@ func TestCrossLimits(t *testing.T) {
exec.SetLocalDB(localDB)
exec.SetStateDB(stateDB)
exec.SetEnv(0, 0, 0)
exec.SetApi(api)
exec.SetAPI(api)
tx := &types.Transaction{Execer: []byte("p.user.test.paracross")}
......
......@@ -67,7 +67,7 @@ func pokerbullStart(cmd *cobra.Command, args []string) {
}
var res string
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "pokerbull.PokerBullStartTx", params, &res)
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "pokerbull.PokerBullStartTx", params, &res)
ctx.RunWithoutMarshal()
}
......@@ -100,7 +100,7 @@ func pokerbullContinue(cmd *cobra.Command, args []string) {
}
var res string
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "pokerbull.PokerBullContinueTx", params, &res)
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "pokerbull.PokerBullContinueTx", params, &res)
ctx.RunWithoutMarshal()
}
......@@ -133,7 +133,7 @@ func pokerbullQuit(cmd *cobra.Command, args []string) {
}
var res string
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "pokerbull.PokerBullQuitTx", params, &res)
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "pokerbull.PokerBullQuitTx", params, &res)
ctx.RunWithoutMarshal()
}
......@@ -178,17 +178,17 @@ func pokerbullQuery(cmd *cobra.Command, args []string) {
if gameID != "" {
params.FuncName = pkt.FuncNameQueryGameByID
var res pkt.ReplyPBGame
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.Run()
} else if address != "" {
params.FuncName = pkt.FuncNameQueryGameByAddr
var res pkt.PBGameRecords
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.Run()
} else if statusStr != "" {
params.FuncName = pkt.FuncNameQueryGameByStatus
var res pkt.PBGameRecords
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.Run()
} else if gameIDs != "" {
params.FuncName = pkt.FuncNameQueryGameListByIDs
......@@ -198,7 +198,7 @@ func pokerbullQuery(cmd *cobra.Command, args []string) {
req := &pkt.QueryPBGameInfos{GameIds: gameIDsS}
params.Payload = req
var res pkt.ReplyPBGameList
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.Run()
} else {
fmt.Println("Error: requeres at least one of gameID, address or status")
......
......@@ -25,9 +25,6 @@ func (g *PokerBull) rollbackIndex(log *pkt.ReceiptPBGame) (kvs []*types.KeyValue
func (g *PokerBull) execDelLocal(receiptData *types.ReceiptData) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{}
if receiptData.GetTy() != types.ExecOk {
return dbSet, nil
}
for _, log := range receiptData.Logs {
switch log.GetTy() {
case pkt.TyLogPBGameStart, pkt.TyLogPBGameContinue, pkt.TyLogPBGameQuit:
......
......@@ -55,9 +55,6 @@ func (c *PokerBull) updateIndex(log *pkt.ReceiptPBGame) (kvs []*types.KeyValue)
func (c *PokerBull) execLocal(receipt *types.ReceiptData) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{}
if receipt.GetTy() != types.ExecOk {
return dbSet, nil
}
for i := 0; i < len(receipt.Logs); i++ {
item := receipt.Logs[i]
if item.Ty == pkt.TyLogPBGameStart || item.Ty == pkt.TyLogPBGameContinue || item.Ty == pkt.TyLogPBGameQuit {
......
......@@ -139,3 +139,8 @@ func delPBGameStatusAndPlayer(status int32, player int32, value, index int64) *t
kv.Value = nil
return kv
}
// CheckReceiptExecOk return true to check if receipt ty is ok
func (g *PokerBull) CheckReceiptExecOk() bool {
return true
}
......@@ -520,9 +520,9 @@ func (action *Action) checkPlayerExistInGame() bool {
}
var value pkt.PBGameRecord
lenght := len(values)
if lenght != 0 {
valueBytes := values[lenght-1]
length := len(values)
if length != 0 {
valueBytes := values[length-1]
err := types.Decode(valueBytes, &value)
if err == nil && value.Status == pkt.PBGameActionQuit {
return false
......
......@@ -74,7 +74,7 @@ func showPrivacyKey(cmd *cobra.Command, args []string) {
Data: addr,
}
var res pty.ReplyPrivacyPkPair
ctx := jsonclient.NewRpcCtx(rpcLaddr, "privacy.ShowPrivacykey", params, &res)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "privacy.ShowPrivacykey", params, &res)
ctx.Run()
}
......@@ -138,7 +138,7 @@ func public2Privacy(cmd *cobra.Command, args []string) {
}
var res rpctypes.ReplyHash
ctx := jsonclient.NewRpcCtx(rpcLaddr, "privacy.MakeTxPublic2privacy", params, &res)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "privacy.MakeTxPublic2privacy", params, &res)
ctx.Run()
}
......@@ -204,7 +204,7 @@ func privacy2Privacy(cmd *cobra.Command, args []string) {
}
var res rpctypes.ReplyHash
ctx := jsonclient.NewRpcCtx(rpcLaddr, "privacy.MakeTxPrivacy2privacy", params, &res)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "privacy.MakeTxPrivacy2privacy", params, &res)
ctx.Run()
}
......@@ -271,7 +271,7 @@ func privacy2Public(cmd *cobra.Command, args []string) {
}
var res rpctypes.ReplyHash
ctx := jsonclient.NewRpcCtx(rpcLaddr, "privacy.MakeTxPrivacy2public", params, &res)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "privacy.MakeTxPrivacy2public", params, &res)
ctx.Run()
}
......@@ -300,7 +300,7 @@ func showPrivacyAccountSpend(cmd *cobra.Command, args []string) {
}
var res pty.UTXOHaveTxHashs
ctx := jsonclient.NewRpcCtx(rpcLaddr, "privacy.ShowPrivacyAccountSpend", params, &res)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "privacy.ShowPrivacyAccountSpend", params, &res)
ctx.SetResultCb(parseShowPrivacyAccountSpendRes)
ctx.Run()
}
......@@ -370,7 +370,7 @@ func showAmountOfUTXO(cmd *cobra.Command, args []string) {
params.Payload = reqPrivacyToken
var res pty.ReplyPrivacyAmounts
ctx := jsonclient.NewRpcCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.SetResultCb(parseShowAmountOfUTXORes)
ctx.Run()
}
......@@ -413,7 +413,7 @@ func showUTXOs4SpecifiedAmount(cmd *cobra.Command, args []string) {
params.Payload = reqPrivacyToken
var res pty.ReplyUTXOsOfAmount
ctx := jsonclient.NewRpcCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.SetResultCb(parseShowUTXOs4SpecifiedAmountRes)
ctx.Run()
}
......@@ -479,7 +479,7 @@ func createUTXOs(cmd *cobra.Command, args []string) {
}
var res rpctypes.ReplyHash
ctx := jsonclient.NewRpcCtx(rpcLaddr, "privacy.CreateUTXOs", params, &res)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "privacy.CreateUTXOs", params, &res)
ctx.Run()
}
......@@ -499,7 +499,7 @@ func showPrivacyAccountInfoFlag(cmd *cobra.Command) {
cmd.MarkFlagRequired("addr")
cmd.Flags().StringP("token", "t", types.BTY, "coins token, BTY supported.")
cmd.Flags().Int32P("displaymode", "d", 0, "display mode.(0: display collect. 1:display avaliable detail. 2:display frozen detail. 3:display all")
cmd.Flags().Int32P("displaymode", "d", 0, "display mode.(0: display collect. 1:display available detail. 2:display frozen detail. 3:display all")
}
func showPrivacyAccountInfo(cmd *cobra.Command, args []string) {
......@@ -519,7 +519,7 @@ func showPrivacyAccountInfo(cmd *cobra.Command, args []string) {
}
var res pty.ReplyPrivacyAccount
ctx := jsonclient.NewRpcCtx(rpcLaddr, "privacy.ShowPrivacyAccountInfo", params, &res)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "privacy.ShowPrivacyAccountInfo", params, &res)
ctx.SetResultCb(parseshowPrivacyAccountInfo)
ctx.Run()
}
......@@ -612,7 +612,7 @@ func listPrivacyTxsFlags(cmd *cobra.Command, args []string) {
Seedtxhash: []byte(seedtxhash),
}
var res rpctypes.WalletTxDetails
ctx := jsonclient.NewRpcCtx(rpcLaddr, "privacy.PrivacyTxList", params, &res)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "privacy.PrivacyTxList", params, &res)
ctx.SetResultCb(parseWalletTxListRes)
ctx.Run()
}
......@@ -671,7 +671,7 @@ func rescanUtxosOpt(cmd *cobra.Command, args []string) {
}
var res pty.RepRescanUtxos
ctx := jsonclient.NewRpcCtx(rpcLaddr, "privacy.RescanUtxos", params, &res)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "privacy.RescanUtxos", params, &res)
ctx.SetResultCb(parseRescanUtxosOpt)
ctx.Run()
}
......@@ -726,7 +726,7 @@ func enablePrivacy(cmd *cobra.Command, args []string) {
}
var res pty.RepEnablePrivacy
ctx := jsonclient.NewRpcCtx(rpcLaddr, "privacy.EnablePrivacy", params, &res)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "privacy.EnablePrivacy", params, &res)
ctx.SetResultCb(parseEnablePrivacy)
ctx.Run()
}
......
......@@ -108,17 +108,22 @@ func TestGenerateRingSignature1(t *testing.T) {
var signs [maxCount]*Sign
index := 0
prefixHash, err := common.FromHex("fd1f64844a7d6a9f74fc2141bceba9d9d69b1fd6104f93bfa42a6d708a6ab22c")
assert.Nil(t, err)
tmp, err := common.FromHex("e7d85d6e81512c5650adce0499d6c17a83e2e29a05c1166cd2171b6b9288b3c4")
assert.Nil(t, err)
copy(image[:], tmp)
tmp, err = common.FromHex("15e3cc7cdb904d62f7c20d7fa51923fa2839f9e0a92ff0eddf8c12bd09089c15")
assert.Nil(t, err)
for i := 0; i < maxCount; i++ {
pub := PubKeyPrivacy{}
copy(pub[:], tmp[32*i:32*(i+1)])
pubs[i] = &pub
}
tmp, err = common.FromHex("fd8de2e12410e3da20350e6f4083b73cc3396b4812c09af633d7c223bfb2560b")
assert.Nil(t, err)
copy(sec[:], tmp)
tmp, err = common.FromHex("b5c0a53bce99106e74284ee1d2c64a68a14e8b4c1735e8ab9ca7215a414f97084749935d87d516b5659a01e84b08279c42e649b2e500e2ede443fe68885b0206")
assert.Nil(t, err)
for i := 0; i < maxCount; i++ {
signs[i] = &Sign{}
}
......@@ -139,14 +144,17 @@ func TestCheckRingSignature1(t *testing.T) {
t.Error("initialize public key from hex failed.")
}
tmp, err := common.FromHex("e7d85d6e81512c5650adce0499d6c17a83e2e29a05c1166cd2171b6b9288b3c4")
assert.Nil(t, err)
copy(image[:], tmp)
tmp, err = common.FromHex("15e3cc7cdb904d62f7c20d7fa51923fa2839f9e0a92ff0eddf8c12bd09089c15")
assert.Nil(t, err)
for i := 0; i < maxCount; i++ {
pub := PubKeyPrivacy{}
copy(pub[:], tmp[32*i:32*(i+1)])
pubs[i] = &pub
}
tmp, err = common.FromHex("a142d0180a6047cf883125a83617c7dd56e9d8153ec04a96b3c5d9a5e03cd70cfd6827b200d6c2f4b41fb5b0162117a5447e327c29482c358a0a3c82db88fb0f")
assert.Nil(t, err)
for i := 0; i < maxCount; i++ {
sign := Sign{}
copy(sign[:], tmp[64*i:64*(i+1)])
......@@ -172,11 +180,13 @@ func TestCheckRingSignatureAPI1(t *testing.T) {
}
tmp, err := common.FromHex("15e3cc7cdb904d62f7c20d7fa51923fa2839f9e0a92ff0eddf8c12bd09089c15")
assert.Nil(t, err)
for i := 0; i < maxCount; i++ {
publickeys[i] = append(publickeys[i], tmp...)
}
tmp, err = common.FromHex("a142d0180a6047cf883125a83617c7dd56e9d8153ec04a96b3c5d9a5e03cd70cfd6827b200d6c2f4b41fb5b0162117a5447e327c29482c358a0a3c82db88fb0f")
assert.Nil(t, err)
data := make([][]byte, maxCount)
for i := 0; i < maxCount; i++ {
data[i] = make([]byte, 0)
......@@ -200,14 +210,17 @@ func TestCheckRingSignature3(t *testing.T) {
t.Error("initialize public key from hex failed.")
}
tmp, err := common.FromHex("04e593e5e4028ce1c1194eb473efc21359b114737e5a64f14420b3cf5b22204b")
assert.Nil(t, err)
copy(image[:], tmp)
tmp, err = common.FromHex("6bfc9654082a7da3055121aa69ddb46852577be71d6c9a204aae3492f0db7e41194f27c9fe4d81cc8421bf8256374edf660806d78b4ed7914a3b74359c8ac0bd65ff1bca674607f7948ea0ae8e83b6d9c5092942b52d2847b6cf44c9c609264d")
assert.Nil(t, err)
for i := 0; i < maxCount; i++ {
pub := PubKeyPrivacy{}
copy(pub[:], tmp[32*i:32*(i+1)])
pubs[i] = &pub
}
tmp, err = common.FromHex("30041e9694c3184980c3bb87f817eab3f973cd969810ec9df4d2feeee907970693eba4bc5436dc7cf49ce476e091bf74d20003f0f73f6d0412909ed8c1a10701c9c4ec11623dd3c50980ead83865a03dfa27614e5e9fb875d75667c11ced390d438f5dd04a137c73a0ec9ca36dfab62c948ce596722067de0315b570db1f720bab7fb7ea1b124f55c9633548f06d1bb403d7e2e15a1fed70ab2865e324ef340327f6d0ad0a7129b272ce12a5a63836a4e96e95897ee44cc22a7048023f438006")
assert.Nil(t, err)
for i := 0; i < maxCount; i++ {
sign := Sign{}
copy(sign[:], tmp[64*i:64*(i+1)])
......@@ -250,15 +263,18 @@ func TestCheckRingSignature17(t *testing.T) {
t.Error("initialize public key from hex failed.")
}
tmp, err := common.FromHex("199c5e78a71b320b704e01850a67c371fed3aca11a04077a36e10c808fdc5f57")
assert.Nil(t, err)
copy(image[:], tmp)
for i := 0; i < maxCount; i++ {
pub := PubKeyPrivacy{}
tmp, err = common.FromHex(pubstrs[i])
assert.Nil(t, err)
copy(pub[:], tmp)
pubs[i] = &pub
}
tmp, err = common.FromHex("f5b1a5079f6122d2370da403efc2e5504b07d67ade7ca57ad3720c7e00a676096ad418262cd9f8c9afee8e58be894cb2bf6387a5018f67d629bf8845bdc9b307aee86f85f8612f74ed870abc81d54cb38f2f9108c20dbf81eb7c1160935bc801cdca5d3f09f1d4bac810cb03ec32753f65a2071a97ba787c2d550ea5ff4d890ac398a1576d108ee67138e7596af54199247c6413e06124af8db76c0ad67c160f351e53029cac4a073c8b188eb8b5151ebf1f34a6693ddbf467ac8c20eec51204c3ca29fd5814f0848b966d2bca9543fc953a0d04bb4782950123d87bd378f60d3cdc5e44160ed4265b7cd84a8200244fa24bac86c50c35b885a15f1bc1de9909fabab87d504fc0cb0b263564e606505477ded1f89543bd4d6ed87ce61918f705359c525c0e0a4cc1d77043c71dfdf9c6834e2623197af1629e34962d940eb4080d06dddaa6e12953232595906289e4712f6aa8c1189f336b823a6a38ac95390b63c508a3409256f0c4df687d4b49990d9878fc5c97af32aa99bc9ffa1215860f69fc141c763fe1f4ed3ccc72e6817e926164752686d55238e74032c47c8c580f7042a62bd74858768815a05b58887f9828bf0f184eceba1416ac294abe453105a0de353316374b1c0560acc0f98181e3229084721a0d2a6ed891d57b805984044372cbb566c91696f5d63e7e5d8cc906c5fb029e71e87a339fcbaee9502f3d01dfd203dbd04797c33370dd0626baabfb9577ca1c294d1d8c6b82ac9624496f04893ad6b2222799cfd1d4ec525b011ecf72b01f6f3b8a6a165f0169fa7cc0960025787d4253e1064e71190d36965605adb850e72e17685e35772cdd3fdfb3d505e96e5eb0ecf8c11bcef62c79e0d49e3ebc76e56d18753403a880b7d7ed399c0e143df235ac8b0748d99e1b0cdcc511abc079c1bdbfead04265d9ad44e5dd7c0e97e4afbacba478539071db02315cc9326c8edb3d8530c7fc78af9ca12b241c04f87bffab95d85f8486ff01aec75e7e38a75ff023e4b2b0f59999c4ac067b500863a63de803da2c89de74878879a39aec6cf800b117ef89ea068a71db5ef70200163d1b4beaeea8c642430e15a64baefd350cb16ca5dae6563c13162904908301485d2c4e5bac6d55dd947a169a38df2848d5e227482760f6d818c45f66a6380507d691ef87e3550626254da3ec65411e8e5aa2ab4846222e208c9ba18cd5ee09617398af31b9eac38b59180bfaec538e5542d698da20016720ced6edb7ba270059c1e1e7107d71524e4a9cf562b5da263b52368f477c5205c768ac36975a250310c37d1f40f5a6eac857ed6082c12f5cf20a0403afcde3f1ea2e4743cb1ba10fd5d92038b1fc65d09467aeac9fe7cd24f78b9376d47d2ef1d3677ede62b2640544dd1b301292b8d082a97bd910ca24fbb5eea878f2cfa4e983bb25a8a66a25065988477eec0c1815a3fa2ff421621707954e9eacdf823eea02c2e3742797c6097e570479b36ca4580c5be9bab187de6a1fa6609768b3fa6448b5bc56d6de820d")
assert.Nil(t, err)
for i := 0; i < maxCount; i++ {
sign := Sign{}
copy(sign[:], tmp[64*i:64*(i+1)])
......
......@@ -13,10 +13,6 @@ import (
func (p *privacy) execDelLocal(tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
txhashstr := common.Bytes2Hex(tx.Hash())
dbSet := &types.LocalDBSet{}
if receiptData.GetTy() != types.ExecOk {
privacylog.Error("execDelLocal", "txhash", txhashstr, "receipt.GetTy() = ", receiptData.GetTy())
return dbSet, nil
}
localDB := p.GetLocalDB()
for i, item := range receiptData.Logs {
if item.Ty != ty.TyLogPrivacyOutput {
......
......@@ -272,7 +272,7 @@ func (p *privacy) CheckTx(tx *types.Transaction, index int) error {
totalOutput += output.Amount
}
feeAmount := int64(0)
var feeAmount int64
if action.Ty == pty.ActionPrivacy2Privacy {
feeAmount = totalInput - totalOutput
} else {
......@@ -331,3 +331,8 @@ func (p *privacy) checkPubKeyValid(keys [][]byte, pubkeys [][]byte) (bool, int32
return true, invalidIndex
}
// CheckReceiptExecOk return true to check if receipt ty is ok
func (p *privacy) CheckReceiptExecOk() bool {
return true
}
......@@ -178,7 +178,7 @@ func (c *Jrpc) PrivacyTxList(in *pty.ReqPrivacyTransactionList, result *interfac
return err
}
var txdetails rpctypes.WalletTxDetails
err = rpctypes.ConvertWalletTxDetailToJson(reply.(*types.WalletTxDetails), &txdetails)
err = rpctypes.ConvertWalletTxDetailToJSON(reply.(*types.WalletTxDetails), &txdetails)
if err != nil {
return err
}
......
......@@ -38,7 +38,7 @@ func (policy *privacyPolicy) rescanAllTxAddToUpdateUTXOs() {
go policy.rescanReqTxDetailByAddr(acc.Addr, policy.rescanwg)
}
policy.rescanwg.Wait()
bizlog.Debug("rescanAllTxToUpdateUTXOs sucess!")
bizlog.Debug("rescanAllTxToUpdateUTXOs success!")
}
//从blockchain模块同步addr参与的所有交易详细信息
......@@ -312,8 +312,8 @@ func (policy *privacyPolicy) showPrivacyKeyPair(reqAddr *types.ReqString) (*priv
return nil, err
}
pair := privacyInfo.ViewPubkey[:]
pair = append(pair, privacyInfo.SpendPubkey[:]...)
//pair := privacyInfo.ViewPubkey[:]
//pair = append(pair, privacyInfo.SpendPubkey[:]...)
replyPrivacyPkPair := &privacytypes.ReplyPrivacyPkPair{
ShowSuccessful: true,
......@@ -333,6 +333,10 @@ func (policy *privacyPolicy) getPrivacyAccountInfo(req *privacytypes.ReqPPrivacy
// 搜索可用余额
privacyDBStore, err := policy.store.listAvailableUTXOs(token, addr)
if err != nil {
bizlog.Error("getPrivacyAccountInfo", "listAvailableUTXOs")
return nil, err
}
utxos := make([]*privacytypes.UTXO, 0)
for _, ele := range privacyDBStore {
utxoBasic := &privacytypes.UTXOBasic{
......@@ -820,7 +824,7 @@ func (policy *privacyPolicy) rescanReqUtxosByAddr(addrs []string) {
defer policy.getWalletOperate().GetWaitGroup().Done()
bizlog.Debug("RescanAllUTXO begin!")
policy.reqUtxosByAddr(addrs)
bizlog.Debug("RescanAllUTXO sucess!")
bizlog.Debug("RescanAllUTXO success!")
}
func (policy *privacyPolicy) reqUtxosByAddr(addrs []string) {
......
......@@ -118,7 +118,7 @@ func (mock *testDataMock) importPrivateKey(PrivKey *types.ReqWalletImportPrivkey
defer wallet.GetMutex().Unlock()
ok, err := wallet.CheckWalletStatus()
if !ok {
if !ok || err != nil {
return
}
......@@ -128,7 +128,7 @@ func (mock *testDataMock) importPrivateKey(PrivKey *types.ReqWalletImportPrivkey
//校验label是否已经被使用
Account, err := wallet.GetAccountByLabel(PrivKey.GetLabel())
if Account != nil {
if Account != nil || err != nil {
return
}
......@@ -161,7 +161,7 @@ func (mock *testDataMock) importPrivateKey(PrivKey *types.ReqWalletImportPrivkey
Encrypteredstr := common.ToHex(Encryptered)
//校验PrivKey对应的addr是否已经存在钱包中
Account, err = wallet.GetAccountByAddr(addr)
if Account != nil {
if Account != nil || err != nil {
if Account.Privkey == Encrypteredstr {
return
} else {
......@@ -277,7 +277,7 @@ func Test_EnablePrivacy(t *testing.T) {
req: &ty.ReqEnablePrivacy{Addrs: []string{testAddrs[0]}},
needReply: &ty.RepEnablePrivacy{
Results: []*ty.PriAddrResult{
{IsOK: true, Addr: testAddrs[0]}},
{Addr: testAddrs[0], Msg: "ErrAddrNotExist"}},
},
},
}
......@@ -305,14 +305,15 @@ func Test_ShowPrivacyKey(t *testing.T) {
}{
{
req: &types.ReqString{Data: testAddrs[1]},
needError: ty.ErrPrivacyNotEnabled,
needError: types.ErrAddrNotExist,
},
{
req: &types.ReqString{Data: testAddrs[0]},
needReply: &ty.ReplyPrivacyPkPair{
/*needReply: &ty.ReplyPrivacyPkPair{
ShowSuccessful: true,
Pubkeypair: "92fe6cfec2e19cd15f203f83b5d440ddb63d0cb71559f96dc81208d819fea85886b08f6e874fca15108d244b40f9086d8c03260d4b954a40dfb3cbe41ebc7389",
},
},*/
needError: types.ErrAddrNotExist,
},
}
......@@ -349,6 +350,7 @@ func Test_CreateUTXOs(t *testing.T) {
Sender: testAddrs[0],
Pubkeypair: testPubkeyPairs[0],
},
needError: types.ErrAddrNotExist,
},
}
......@@ -379,6 +381,7 @@ func Test_SendPublic2PrivacyTransaction(t *testing.T) {
Pubkeypair: testPubkeyPairs[0],
},
needReply: &types.Reply{IsOk: true},
needError: types.ErrAddrNotExist,
},
}
......@@ -418,6 +421,7 @@ func Test_SendPrivacy2PrivacyTransaction(t *testing.T) {
Pubkeypair: testPubkeyPairs[1],
},
needReply: &types.Reply{IsOk: true},
needError: types.ErrAddrNotExist,
},
}
......@@ -457,6 +461,7 @@ func Test_SendPrivacy2PublicTransaction(t *testing.T) {
Receiver: testAddrs[0],
},
needReply: &types.Reply{IsOk: true},
needError: types.ErrAddrNotExist,
},
}
......@@ -496,6 +501,7 @@ func Test_CreateTransaction(t *testing.T) {
From: testAddrs[0],
Pubkeypair: testPubkeyPairs[0],
},
//needError:types.ErrAddrNotExist,
},
{ // 私对私测试
req: &types.ReqCreateTransaction{
......@@ -505,6 +511,7 @@ func Test_CreateTransaction(t *testing.T) {
From: testAddrs[0],
Pubkeypair: testPubkeyPairs[1],
},
needError: types.ErrAddrNotExist,
},
{ // 私对公测试
req: &types.ReqCreateTransaction{
......@@ -514,6 +521,7 @@ func Test_CreateTransaction(t *testing.T) {
From: testAddrs[0],
Pubkeypair: testPubkeyPairs[0],
},
needError: types.ErrAddrNotExist,
},
}
for index, testCase := range testCases {
......@@ -621,7 +629,7 @@ func Test_RescanUTXOs(t *testing.T) {
Addrs: testAddrs,
Flag: 0,
},
needError: ty.ErrPrivacyNotEnabled,
needError: types.ErrAccountNotExist,
},
{
enable: true,
......@@ -629,6 +637,7 @@ func Test_RescanUTXOs(t *testing.T) {
Addrs: testAddrs,
Flag: 0,
},
needError: types.ErrAccountNotExist,
},
}
for index, testCase := range testCases {
......
......@@ -255,8 +255,10 @@ func testStore_listAvailableUTXOs(t *testing.T) {
err = store.Set(key, []byte("AccKey"))
assert.NoError(t, err)
utxos, err = store.listAvailableUTXOs(token, addr)
assert.Nil(t, utxos)
assert.NotNil(t, err)
err = store.Set([]byte("AccKey"), bt)
assert.NoError(t, err)
utxos, err = store.listAvailableUTXOs(token, addr)
assert.NoError(t, err)
assert.Equal(t, 1, len(utxos))
......@@ -290,6 +292,7 @@ func testStore_getAccountByAddr(t *testing.T) {
bt, err := proto.Marshal(account)
assert.NoError(t, err)
err = store.Set(calcAddrKey(addr), bt)
assert.NoError(t, err)
was, err = store.getAccountByAddr(addr)
assert.Equal(t, true, proto.Equal(was, account))
assert.NoError(t, err)
......@@ -345,6 +348,7 @@ func testStore_getVersion(t *testing.T) {
bt, err = json.Marshal(PRIVACYDBVERSION)
assert.NoError(t, err)
err = store.Set(calcPrivacyDBVersion(), bt)
assert.NoError(t, err)
version = store.getVersion()
assert.Equal(t, PRIVACYDBVERSION, version)
}
......@@ -398,7 +398,7 @@ func relayOrder(cmd *cobra.Command, args []string) {
}
var res string
ctx := jsonclient.NewRpcCtx(rpcLaddr, "relay.CreateRawRelayOrderTx", params, &res)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "relay.CreateRawRelayOrderTx", params, &res)
ctx.RunWithoutMarshal()
}
......@@ -441,7 +441,7 @@ func relayAccept(cmd *cobra.Command, args []string) {
CoinWaits: coinwait,
}
var res string
ctx := jsonclient.NewRpcCtx(rpcLaddr, "relay.CreateRawRelayAcceptTx", params, &res)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "relay.CreateRawRelayAcceptTx", params, &res)
ctx.RunWithoutMarshal()
}
......@@ -481,7 +481,7 @@ func relayRevoke(cmd *cobra.Command, args []string) {
Action: act,
}
var res string
ctx := jsonclient.NewRpcCtx(rpcLaddr, "relay.CreateRawRelayRevokeTx", params, &res)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "relay.CreateRawRelayRevokeTx", params, &res)
ctx.RunWithoutMarshal()
}
......@@ -516,7 +516,7 @@ func relayConfirm(cmd *cobra.Command, args []string) {
TxHash: txHash,
}
var res string
ctx := jsonclient.NewRpcCtx(rpcLaddr, "relay.CreateRawRelayConfirmTx", params, &res)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "relay.CreateRawRelayConfirmTx", params, &res)
ctx.RunWithoutMarshal()
}
......@@ -566,7 +566,7 @@ func relaySaveBtcHead(cmd *cobra.Command, args []string) {
}
var res string
ctx := jsonclient.NewRpcCtx(rpcLaddr, "relay.CreateRawRelaySaveBTCHeadTx", params, &res)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "relay.CreateRawRelaySaveBTCHeadTx", params, &res)
ctx.RunWithoutMarshal()
}
......@@ -617,6 +617,6 @@ func relayVerifyBTC(cmd *cobra.Command, args []string) {
}
var res string
ctx := jsonclient.NewRpcCtx(rpcLaddr, "relay.CreateRawRelayVerifyBTCTx", params, &res)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "relay.CreateRawRelayVerifyBTCTx", params, &res)
ctx.RunWithoutMarshal()
}
......@@ -243,3 +243,8 @@ func deleteCreateOrderKeyValue(kv []*types.KeyValue, order *ty.RelayOrder, statu
return kv
}
// CheckReceiptExecOk return true to check if receipt ty is ok
func (r *relay) CheckReceiptExecOk() bool {
return true
}
......@@ -74,7 +74,7 @@ func (s *suiteRelay) SetupSuite() {
relay.SetLocalDB(s.kvdb)
relay.SetEnv(10, 100, 1)
relay.SetIsFree(false)
relay.SetApi(nil)
relay.SetAPI(nil)
relay.SetChild(relay)
relay.SetExecutorType(types.LoadExecutorType(driverName))
s.relay = relay
......@@ -406,7 +406,7 @@ func (s *suiteBtcHeader) SetupSuite() {
relay.SetLocalDB(s.kvdb)
relay.SetEnv(10, 100, 1)
relay.SetIsFree(false)
relay.SetApi(nil)
relay.SetAPI(nil)
relay.SetChild(relay)
relay.SetExecutorType(types.LoadExecutorType(driverName))
s.relay = relay
......
......@@ -154,7 +154,7 @@ func (s *suiteRelayDB) SetupSuite() {
relay.SetLocalDB(s.kvdb)
relay.SetEnv(10, 100, 1)
relay.SetIsFree(false)
relay.SetApi(nil)
relay.SetAPI(nil)
relay.SetChild(relay)
s.relay = relay
......@@ -337,7 +337,7 @@ func (s *suiteAccept) SetupSuite() {
relay.SetLocalDB(s.kvdb)
relay.SetEnv(10, 100, 1)
relay.SetIsFree(false)
relay.SetApi(nil)
relay.SetAPI(nil)
relay.SetChild(relay)
s.relay = relay
......@@ -535,7 +535,7 @@ func (s *suiteConfirm) SetupSuite() {
relay.SetLocalDB(s.kvdb)
relay.SetEnv(10, 100, 1)
relay.SetIsFree(false)
relay.SetApi(nil)
relay.SetAPI(nil)
relay.SetChild(relay)
s.relay = relay
......@@ -824,7 +824,7 @@ func (s *suiteVerify) SetupSuite() {
relay.SetLocalDB(s.kvdb)
relay.SetEnv(10, 100, 1)
relay.SetIsFree(false)
relay.SetApi(nil)
relay.SetAPI(nil)
relay.SetChild(relay)
s.relay = relay
......@@ -1055,7 +1055,7 @@ func (s *suiteVerifyCli) SetupSuite() {
relay.SetLocalDB(s.kvdb)
relay.SetEnv(10, 100, 1)
relay.SetIsFree(false)
relay.SetApi(nil)
relay.SetAPI(nil)
relay.SetChild(relay)
s.relay = relay
......@@ -1130,7 +1130,7 @@ func (s *suiteSaveBtcHeader) SetupSuite() {
relay.SetLocalDB(s.kvdb)
relay.SetEnv(10, 100, 1)
relay.SetIsFree(false)
relay.SetApi(nil)
relay.SetAPI(nil)
relay.SetChild(relay)
s.relay = relay
......
......@@ -81,7 +81,7 @@ func backupCmd(cmd *cobra.Command, args []string) {
DelayPeriod: delay,
Fee: feeInt64,
}
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "retrieve.CreateRawRetrieveBackupTx", params, nil)
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "retrieve.CreateRawRetrieveBackupTx", params, nil)
ctx.RunWithoutMarshal()
}
......@@ -118,7 +118,7 @@ func prepareCmd(cmd *cobra.Command, args []string) {
DefaultAddr: defaultAddr,
Fee: feeInt64,
}
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "retrieve.CreateRawRetrievePrepareTx", params, nil)
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "retrieve.CreateRawRetrievePrepareTx", params, nil)
ctx.RunWithoutMarshal()
}
......@@ -145,7 +145,7 @@ func performCmd(cmd *cobra.Command, args []string) {
DefaultAddr: defaultAddr,
Fee: feeInt64,
}
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "retrieve.CreateRawRetrievePerformTx", params, nil)
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "retrieve.CreateRawRetrievePerformTx", params, nil)
ctx.RunWithoutMarshal()
}
......@@ -172,7 +172,7 @@ func cancelCmd(cmd *cobra.Command, args []string) {
DefaultAddr: defaultAddr,
Fee: feeInt64,
}
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "retrieve.CreateRawRetrieveCancelTx", params, nil)
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "retrieve.CreateRawRetrieveCancelTx", params, nil)
ctx.RunWithoutMarshal()
}
......@@ -232,7 +232,7 @@ func queryRetrieveCmd(cmd *cobra.Command, args []string) {
params.Payload = req
var res rt.RetrieveQuery
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.SetResultCb(parseRerieveDetail)
ctx.Run()
}
......@@ -51,9 +51,6 @@ func DelRetrieveInfo(info *rt.RetrieveQuery, Status int64, db dbm.KVDB) (*types.
// ExecDelLocal_Backup Action
func (c *Retrieve) ExecDelLocal_Backup(backup *rt.BackupRetrieve, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
set := &types.LocalDBSet{}
if receiptData.GetTy() != types.ExecOk {
return set, nil
}
rlog.Debug("Retrieve ExecDelLocal_Backup")
info := rt.RetrieveQuery{BackupAddress: backup.BackupAddress, DefaultAddress: backup.DefaultAddress, DelayPeriod: backup.DelayPeriod, PrepareTime: zeroPrepareTime, RemainTime: zeroRemainTime, Status: retrieveBackup}
......@@ -72,9 +69,6 @@ func (c *Retrieve) ExecDelLocal_Backup(backup *rt.BackupRetrieve, tx *types.Tran
// ExecDelLocal_Prepare Action
func (c *Retrieve) ExecDelLocal_Prepare(pre *rt.PrepareRetrieve, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
set := &types.LocalDBSet{}
if receiptData.GetTy() != types.ExecOk {
return set, nil
}
rlog.Debug("Retrieve ExecDelLocal_Prepare")
info := rt.RetrieveQuery{BackupAddress: pre.BackupAddress, DefaultAddress: pre.DefaultAddress, DelayPeriod: zeroDelay, PrepareTime: c.GetBlockTime(), RemainTime: zeroRemainTime, Status: retrievePrepare}
......@@ -93,9 +87,6 @@ func (c *Retrieve) ExecDelLocal_Prepare(pre *rt.PrepareRetrieve, tx *types.Trans
// ExecDelLocal_Perform Action
func (c *Retrieve) ExecDelLocal_Perform(perf *rt.PerformRetrieve, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
set := &types.LocalDBSet{}
if receiptData.GetTy() != types.ExecOk {
return set, nil
}
rlog.Debug("Retrieve ExecDelLocal_Perform")
info := rt.RetrieveQuery{BackupAddress: perf.BackupAddress, DefaultAddress: perf.DefaultAddress, DelayPeriod: zeroDelay, PrepareTime: zeroPrepareTime, RemainTime: zeroRemainTime, Status: retrievePerform}
......@@ -114,9 +105,6 @@ func (c *Retrieve) ExecDelLocal_Perform(perf *rt.PerformRetrieve, tx *types.Tran
// ExecDelLocal_Cancel Action
func (c *Retrieve) ExecDelLocal_Cancel(cancel *rt.CancelRetrieve, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
set := &types.LocalDBSet{}
if receiptData.GetTy() != types.ExecOk {
return set, nil
}
rlog.Debug("Retrieve ExecDelLocal_Cancel")
info := rt.RetrieveQuery{BackupAddress: cancel.BackupAddress, DefaultAddress: cancel.DefaultAddress, DelayPeriod: zeroDelay, PrepareTime: zeroPrepareTime, RemainTime: zeroRemainTime, Status: retrieveCancel}
......
......@@ -54,9 +54,6 @@ func SaveRetrieveInfo(info *rt.RetrieveQuery, Status int64, db dbm.KVDB) (*types
// ExecLocal_Backup Action
func (c *Retrieve) ExecLocal_Backup(backup *rt.BackupRetrieve, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
set := &types.LocalDBSet{}
if receiptData.GetTy() != types.ExecOk {
return set, nil
}
rlog.Debug("Retrieve ExecLocal_Backup")
info := rt.RetrieveQuery{BackupAddress: backup.BackupAddress, DefaultAddress: backup.DefaultAddress, DelayPeriod: backup.DelayPeriod, PrepareTime: zeroPrepareTime, RemainTime: zeroRemainTime, Status: retrieveBackup}
kv, err := SaveRetrieveInfo(&info, retrieveBackup, c.GetLocalDB())
......@@ -74,9 +71,6 @@ func (c *Retrieve) ExecLocal_Backup(backup *rt.BackupRetrieve, tx *types.Transac
// ExecLocal_Prepare Action
func (c *Retrieve) ExecLocal_Prepare(pre *rt.PrepareRetrieve, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
set := &types.LocalDBSet{}
if receiptData.GetTy() != types.ExecOk {
return set, nil
}
rlog.Debug("Retrieve ExecLocal_Prepare")
info := rt.RetrieveQuery{BackupAddress: pre.BackupAddress, DefaultAddress: pre.DefaultAddress, DelayPeriod: zeroDelay, PrepareTime: zeroPrepareTime, RemainTime: zeroRemainTime, Status: retrievePrepare}
......@@ -95,9 +89,6 @@ func (c *Retrieve) ExecLocal_Prepare(pre *rt.PrepareRetrieve, tx *types.Transact
// ExecLocal_Perform Action
func (c *Retrieve) ExecLocal_Perform(perf *rt.PerformRetrieve, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
set := &types.LocalDBSet{}
if receiptData.GetTy() != types.ExecOk {
return set, nil
}
rlog.Debug("Retrieve ExecLocal_Perf")
info := rt.RetrieveQuery{BackupAddress: perf.BackupAddress, DefaultAddress: perf.DefaultAddress, DelayPeriod: zeroDelay, PrepareTime: zeroPrepareTime, RemainTime: zeroRemainTime, Status: retrievePerform}
......@@ -116,9 +107,6 @@ func (c *Retrieve) ExecLocal_Perform(perf *rt.PerformRetrieve, tx *types.Transac
// ExecLocal_Cancel Action
func (c *Retrieve) ExecLocal_Cancel(cancel *rt.CancelRetrieve, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
set := &types.LocalDBSet{}
if receiptData.GetTy() != types.ExecOk {
return set, nil
}
rlog.Debug("Retrieve ExecLocal_Cancel")
info := rt.RetrieveQuery{BackupAddress: cancel.BackupAddress, DefaultAddress: cancel.DefaultAddress, DelayPeriod: zeroDelay, PrepareTime: zeroPrepareTime, RemainTime: zeroRemainTime, Status: retrieveCancel}
......
......@@ -82,3 +82,8 @@ func getRetrieveInfo(db dbm.KVDB, backupAddr string, defaultAddr string) (*rt.Re
}
return &info, nil
}
// CheckReceiptExecOk return true to check if receipt ty is ok
func (r *Retrieve) CheckReceiptExecOk() bool {
return true
}
......@@ -344,7 +344,7 @@ func estRetrievePerform(t *testing.T) {
func estRetrieveCancel(t *testing.T) {
fmt.Println("\nTestRetrieveCancel start")
fmt.Println("*This case is used for checking cancel operation\n*Cancel action is done with privkey of account A/B, although the cancel action for A could succeed, but the balance have been transfered by last action with backup a\n*currBalanceA = currBalanceA - 2*fee currBalanceB = currBalanceB + 1e8 - 2*fee")
fmt.Println("*This case is used for checking cancel operation\n*Cancel action is done with privkey of account A/B, although the cancel action for A could succeed, but the balance have been transferred by last action with backup a\n*currBalanceA = currBalanceA - 2*fee currBalanceB = currBalanceB + 1e8 - 2*fee")
defer fmt.Println("TestRetrieveCancel end")
var hashes [][]byte
......
......@@ -91,7 +91,7 @@ func CountTicketCmd() *cobra.Command {
func countTicket(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
var res int64
ctx := jsonclient.NewRpcCtx(rpcLaddr, "ticket.GetTicketCount", nil, &res)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "ticket.GetTicketCount", nil, &res)
ctx.Run()
}
......@@ -188,6 +188,6 @@ func coldAddressOfMiner(cmd *cobra.Command, args []string) {
params.Payload = reqaddr
var res types.ReplyStrings
ctx := jsonclient.NewRpcCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.Run()
}
......@@ -11,9 +11,6 @@ import (
func (t *Ticket) execDelLocal(receiptData *types.ReceiptData) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{}
if receiptData.GetTy() != types.ExecOk {
return dbSet, nil
}
for _, item := range receiptData.Logs {
//这三个是ticket 的log
if item.Ty == ty.TyLogNewTicket || item.Ty == ty.TyLogMinerTicket || item.Ty == ty.TyLogCloseTicket {
......
......@@ -11,9 +11,6 @@ import (
func (t *Ticket) execLocal(receiptData *types.ReceiptData) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{}
if receiptData.GetTy() != types.ExecOk {
return dbSet, nil
}
for _, item := range receiptData.Logs {
//这三个是ticket 的log
if item.Ty == ty.TyLogNewTicket || item.Ty == ty.TyLogMinerTicket || item.Ty == ty.TyLogCloseTicket {
......
......@@ -186,3 +186,8 @@ func (t *Ticket) CheckTx(tx *types.Transaction, index int) error {
}
return nil
}
// CheckReceiptExecOk return true to check if receipt ty is ok
func (t *Ticket) CheckReceiptExecOk() bool {
return true
}
......@@ -59,7 +59,7 @@ func init() {
types.AllowUserExec = append(types.AllowUserExec, []byte(TicketX))
types.RegistorExecutor(TicketX, NewType())
types.RegisterDappFork(TicketX, "Enable", 0)
types.RegisterDappFork(TicketX, "ForkTicketId", 1200000)
types.RegisterDappFork(TicketX, "ForkTicketId", 1062000)
}
// TicketType ticket exec type
......
......@@ -255,7 +255,7 @@ func tokenAssets(cmd *cobra.Command, args []string) {
params.Payload = req
var res tokenty.ReplyAccountTokenAssets
ctx := jsonclient.NewRpcCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.SetResultCb(parseTokenAssetsRes)
ctx.Run()
}
......@@ -314,7 +314,7 @@ func tokenBalance(cmd *cobra.Command, args []string) {
Execer: execer,
}
var res []*rpctypes.Account
ctx := jsonclient.NewRpcCtx(rpcLaddr, "token.GetTokenBalance", params, &res)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "token.GetTokenBalance", params, &res)
ctx.SetResultCb(parseTokenBalanceRes)
ctx.Run()
}
......@@ -388,7 +388,7 @@ func tokenPrecreated(cmd *cobra.Command, args []string) {
Owner: ownerAddr,
Total: total * types.TokenPrecision,
}
ctx := jsonclient.NewRpcCtx(rpcLaddr, "token.CreateRawTokenPreCreateTx", params, nil)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "token.CreateRawTokenPreCreateTx", params, nil)
ctx.RunWithoutMarshal()
}
......@@ -422,7 +422,7 @@ func tokenFinish(cmd *cobra.Command, args []string) {
Owner: ownerAddr,
}
ctx := jsonclient.NewRpcCtx(rpcLaddr, "token.CreateRawTokenFinishTx", params, nil)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "token.CreateRawTokenFinishTx", params, nil)
ctx.RunWithoutMarshal()
}
......@@ -457,6 +457,6 @@ func tokenRevoke(cmd *cobra.Command, args []string) {
Owner: ownerAddr,
}
ctx := jsonclient.NewRpcCtx(rpcLaddr, "token.CreateRawTokenRevokeTx", params, nil)
ctx := jsonclient.NewRPCCtx(rpcLaddr, "token.CreateRawTokenRevokeTx", params, nil)
ctx.RunWithoutMarshal()
}
......@@ -338,3 +338,8 @@ func (t *token) getTxByToken(req *tokenty.ReqTokenTx) (types.Message, error) {
}
return &replyTxInfos, nil
}
// CheckReceiptExecOk return true to check if receipt ty is ok
func (t *token) CheckReceiptExecOk() bool {
return true
}
......@@ -77,7 +77,7 @@ func showOnesSellOrders(cmd *cobra.Command, args []string) {
Payload: reqAddrtokens,
}
var res pty.ReplySellOrders
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.SetResultCb(parseSellOrders)
ctx.Run()
}
......@@ -118,7 +118,7 @@ func showOnesSellOrdersStatus(cmd *cobra.Command, args []string) {
params.FuncName = "GetOnesSellOrderWithStatus"
params.Payload = reqAddrtokens
var res pty.ReplySellOrders
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.SetResultCb(parseSellOrders)
ctx.Run()
}
......@@ -171,7 +171,7 @@ func showTokenSellOrdersStatus(cmd *cobra.Command, args []string) {
params.FuncName = "GetTokenSellOrderByStatus"
params.Payload = req
var res pty.ReplySellOrders
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.SetResultCb(parseSellOrders)
ctx.Run()
}
......@@ -234,7 +234,7 @@ func showOnesBuyOrders(cmd *cobra.Command, args []string) {
params.FuncName = "GetOnesBuyOrder"
params.Payload = reqAddrtokens
var res pty.ReplyBuyOrders
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.SetResultCb(parseBuyOrders)
ctx.Run()
}
......@@ -274,7 +274,7 @@ func showOnesBuyOrdersStatus(cmd *cobra.Command, args []string) {
params.FuncName = "GetOnesBuyOrderWithStatus"
params.Payload = reqAddrtokens
var res pty.ReplyBuyOrders
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.SetResultCb(parseBuyOrders)
ctx.Run()
}
......@@ -327,7 +327,7 @@ func showTokenBuyOrdersStatus(cmd *cobra.Command, args []string) {
params.FuncName = "GetTokenBuyOrderByStatus"
params.Payload = req
var res pty.ReplyBuyOrders
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.SetResultCb(parseBuyOrders)
ctx.Run()
}
......@@ -401,7 +401,7 @@ func showOnesOrdersStatus(cmd *cobra.Command, args []string) {
params.FuncName = "GetOnesOrderWithStatus"
params.Payload = reqAddrtokens
var res pty.ReplyTradeOrders
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.SetResultCb(parseTradeOrders)
ctx.Run()
}
......@@ -482,7 +482,7 @@ func tokenSell(cmd *cobra.Command, args []string) {
AssetExec: "token",
}
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "trade.CreateRawTradeSellTx", params, nil)
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "trade.CreateRawTradeSellTx", params, nil)
ctx.RunWithoutMarshal()
}
......@@ -518,7 +518,7 @@ func tokenBuy(cmd *cobra.Command, args []string) {
Fee: feeInt64 * 1e4,
}
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "trade.CreateRawTradeBuyTx", params, nil)
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "trade.CreateRawTradeBuyTx", params, nil)
ctx.RunWithoutMarshal()
}
......@@ -551,6 +551,6 @@ func tokenSellRevoke(cmd *cobra.Command, args []string) {
Fee: feeInt64 * 1e4,
}
ctx := jsonrpc.NewRpcCtx(rpcLaddr, "trade.CreateRawTradeRevokeTx", params, nil)
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "trade.CreateRawTradeRevokeTx", params, nil)
ctx.RunWithoutMarshal()
}
......@@ -202,3 +202,8 @@ func saveBuyMarketOrderKeyValue(kv []*types.KeyValue, receipt *pty.ReceiptBuyBas
func deleteBuyMarketOrderKeyValue(kv []*types.KeyValue, receipt *pty.ReceiptBuyBase, status int32, height int64) []*types.KeyValue {
return genBuyMarketOrderKeyValue(kv, receipt, status, height, nil)
}
// CheckReceiptExecOk return true to check if receipt ty is ok
func (t *trade) CheckReceiptExecOk() bool {
return true
}
......@@ -12,9 +12,6 @@ import (
// ExecDelLocal_Node method
func (val *ValNode) ExecDelLocal_Node(node *pty.ValNode, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) {
set := &types.LocalDBSet{}
if receipt.GetTy() != types.ExecOk {
return set, nil
}
key := CalcValNodeUpdateHeightIndexKey(val.GetHeight(), index)
set.KV = append(set.KV, &types.KeyValue{Key: key, Value: nil})
return set, nil
......@@ -23,9 +20,6 @@ func (val *ValNode) ExecDelLocal_Node(node *pty.ValNode, tx *types.Transaction,
// ExecDelLocal_BlockInfo method
func (val *ValNode) ExecDelLocal_BlockInfo(blockInfo *pty.TendermintBlockInfo, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) {
set := &types.LocalDBSet{}
if receipt.GetTy() != types.ExecOk {
return set, nil
}
key := CalcValNodeBlockInfoHeightKey(val.GetHeight())
set.KV = append(set.KV, &types.KeyValue{Key: key, Value: nil})
return set, nil
......
......@@ -14,9 +14,6 @@ import (
// ExecLocal_Node method
func (val *ValNode) ExecLocal_Node(node *pty.ValNode, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) {
set := &types.LocalDBSet{}
if receipt.GetTy() != types.ExecOk {
return set, nil
}
if len(node.GetPubKey()) == 0 {
return nil, errors.New("validator pubkey is empty")
}
......@@ -32,9 +29,6 @@ func (val *ValNode) ExecLocal_Node(node *pty.ValNode, tx *types.Transaction, rec
// ExecLocal_BlockInfo method
func (val *ValNode) ExecLocal_BlockInfo(blockInfo *pty.TendermintBlockInfo, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) {
set := &types.LocalDBSet{}
if receipt.GetTy() != types.ExecOk {
return set, nil
}
key := CalcValNodeBlockInfoHeightKey(val.GetHeight())
set.KV = append(set.KV, &types.KeyValue{Key: key, Value: types.Encode(blockInfo)})
return set, nil
......
......@@ -68,3 +68,8 @@ func CalcValNodeUpdateHeightKey(height int64) []byte {
func CalcValNodeBlockInfoHeightKey(height int64) []byte {
return []byte(fmt.Sprintf("LODB-valnode-BlockInfo:%18d:", height))
}
// CheckReceiptExecOk return true to check if receipt ty is ok
func (val *ValNode) CheckReceiptExecOk() bool {
return true
}
BSD 2-Clause License
BSD 3-Clause License
Copyright (c) 2018, 33.cn
All rights reserved.
......@@ -13,6 +13,10 @@ modification, are permitted provided that the following conditions are met:
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
......
......@@ -16,6 +16,7 @@ SRC_AUTOTEST := github.com/33cn/chain33/cmd/autotest
LDFLAGS := -ldflags "-w -s"
PKG_LIST := `go list ./... | grep -v "vendor" | grep -v "mocks"`
PKG_LIST_VET := `go list ./... | grep -v "vendor" | grep -v "common/crypto/sha3" | grep -v "common/log/log15"`
PKG_LIST_INEFFASSIGN= `go list -f {{.Dir}} ./... | grep -v "vendor" | grep -v "common/crypto/sha3" | grep -v "common/log/log15" | grep -v "common/ed25519"`
PKG_LIST_Q := `go list ./... | grep -v "vendor" | grep -v "mocks"`
BUILD_FLAGS = -ldflags "-X github.com/33cn/chain33/common/version.GitCommit=`git rev-parse --short=8 HEAD`"
MKPATH=$(abspath $(lastword $(MAKEFILE_LIST)))
......@@ -87,7 +88,7 @@ build_ci: depends ## Build the binary file for CI
@go build $(BUILD_FLAGS) -v -o $(APP) $(SRC)
@cp cmd/chain33/chain33.toml build/
linter: ## Use gometalinter check code, ignore some unserious warning
linter: vet ineffassign ## Use gometalinter check code, ignore some unserious warning
@./golinter.sh "filter"
@find . -name '*.sh' -not -path "./vendor/*" | xargs shellcheck
......@@ -101,6 +102,9 @@ race: ## Run data race detector
vet:
@go vet ${PKG_LIST_VET}
ineffassign:
@ineffassign -n ${PKG_LIST_INEFFASSIGN}
test: ## Run unittests
@go test -race $(PKG_LIST)
......
......@@ -640,7 +640,7 @@ func testGetSeqByHash(t *testing.T, blockchain *blockchain.BlockChain) {
}
}
seq, err := blockchain.ProcGetSeqByHash(hashes[0])
seq, _ := blockchain.ProcGetSeqByHash(hashes[0])
if seq != -1 {
t.Error("testGetSeqByHash only para chain GetSeqByHash ")
}
......
......@@ -102,7 +102,6 @@ func (show *ShowMinerAccount) Get(in *TimeAt, out *interface{}) error {
miner = calcIncrease(miner, curAcc, lastAcc, header)
*out = &miner
seconds = seconds - statInterval
//}
return nil
......
......@@ -195,12 +195,12 @@ func scanWrite() {
Expire: "0",
}
var signed string
err = rpc.Call("Chain33.SignRawTx", paramsReqSignRawTx, &signed)
rpc.Call("Chain33.SignRawTx", paramsReqSignRawTx, &signed)
paramsRaw := rpctypes.RawParm{
Data: signed,
}
var sent string
err = rpc.Call("Chain33.SendTransaction", paramsRaw, &sent)
rpc.Call("Chain33.SendTransaction", paramsRaw, &sent)
f, _ := os.OpenFile(heightFile, os.O_RDWR, 0666)
height := strconv.FormatInt(currentHeight, 10)
index := strconv.FormatInt(currentIndex, 10)
......
......@@ -372,8 +372,7 @@ func (dbit *PegasusIt) findInPage(key []byte) int {
//Seek 查找
func (dbit *PegasusIt) Seek(key []byte) bool {
pos := -1
pos = dbit.findInPage(key)
pos := dbit.findInPage(key)
// 如果第一页已经找到,不会走入此逻辑
for pos == -1 && dbit.nextPage {
......
......@@ -378,8 +378,7 @@ func (dbit *ssDBIt) findInPage(key string) int {
func (dbit *ssDBIt) Seek(key []byte) bool {
keyStr := string(key)
pos := -1
pos = dbit.findInPage(keyStr)
pos := dbit.findInPage(keyStr)
// 如果第一页已经找到,不会走入此逻辑
for pos == -1 && dbit.nextPage {
......
......@@ -336,7 +336,6 @@ func (c *SDBClient) send(args []interface{}) error {
return nil
}
func (c *SDBClient) recv() (resp []string, err error) {
bufSize := 0
packetBuf := []byte{}
//设置读取数据超时,
if err = c.sock.SetReadDeadline(time.Now().Add(time.Second * ReadTimeOut)); err != nil {
......@@ -345,7 +344,7 @@ func (c *SDBClient) recv() (resp []string, err error) {
//数据包分解,发现长度,找到结尾,循环发现,发现空行,结束
readBuf := make([]byte, ReadBufSize)
for {
bufSize, err = c.sock.Read(readBuf)
bufSize, err := c.sock.Read(readBuf)
if err != nil {
return nil, newErrorf(err, "client socket read error")
}
......@@ -359,7 +358,7 @@ func (c *SDBClient) recv() (resp []string, err error) {
if n == -1 {
break
} else if n == -2 {
return
return nil, newErrorf(err, "parse error")
} else {
resp = append(resp, rsp)
packetBuf = packetBuf[n+1:]
......@@ -370,7 +369,6 @@ func (c *SDBClient) recv() (resp []string, err error) {
func (c *SDBClient) parse(buf []byte) (resp string, size int) {
n := bytes.IndexByte(buf, ENDN)
blockSize := -1
size = -1
if n != -1 {
if n == 0 || n == 1 && buf[0] == ENDR { //空行,说明一个数据包结束
......@@ -378,7 +376,7 @@ func (c *SDBClient) parse(buf []byte) (resp string, size int) {
return
}
//数据包开始,包长度解析
blockSize = ToNum(buf[:n])
blockSize := ToNum(buf[:n])
bufSize := len(buf)
if n+blockSize < bufSize {
......
......@@ -150,7 +150,7 @@ func TestVersionSetAndGet(t *testing.T) {
assert.Equal(t, v, []byte("v03"))
m.Trash(3)
v, err = m.GetV([]byte("k0"), 0)
_, err = m.GetV([]byte("k0"), 0)
assert.Equal(t, err, types.ErrNotFound)
v, err = m.GetV([]byte("k3"), 4)
......@@ -192,23 +192,23 @@ func TestAddDelMVCC(t *testing.T) {
m.db.Set(v.Key, v.Value)
}
kvlist, err = m.AddMVCC(genkv(2), hashN(2), hashN(1), 1)
_, err = m.AddMVCC(genkv(2), hashN(2), hashN(1), 1)
assert.Equal(t, err, types.ErrPrevVersion)
kvlist, err = m.AddMVCC(genkv(2), hashN(2), hashN(0), 3)
_, err = m.AddMVCC(genkv(2), hashN(2), hashN(0), 3)
assert.Equal(t, err, types.ErrPrevVersion)
kvlist, err = m.AddMVCC(genkv(2), hashN(2), hashN(3), 3)
_, err = m.AddMVCC(genkv(2), hashN(2), hashN(3), 3)
assert.Equal(t, err, types.ErrNotFound)
maxv, err := m.GetMaxVersion()
assert.Nil(t, err)
assert.Equal(t, int64(1), maxv)
kvlist, err = m.DelMVCC(hashN(2), 1, true)
_, err = m.DelMVCC(hashN(2), 1, true)
assert.Equal(t, err, types.ErrNotFound)
kvlist, err = m.DelMVCC(hashN(0), 0, true)
_, err = m.DelMVCC(hashN(0), 0, true)
assert.Equal(t, err, types.ErrCanOnlyDelTopVersion)
kvlist, err = m.DelMVCC(hashN(1), 1, true)
......
......@@ -190,8 +190,6 @@ func abs(t time.Duration) time.Duration {
}
func maxSubList(list []time.Duration) (sub []time.Duration) {
start := 0
end := 0
if len(list) == 0 {
return list
}
......@@ -202,6 +200,8 @@ func maxSubList(list []time.Duration) (sub []time.Duration) {
} else {
nextheight = list[i+1]
}
var start int
var end int
if abs(nextheight-list[i]) > time.Millisecond*100 {
end = i + 1
if len(sub) < (end - start) {
......
......@@ -98,11 +98,11 @@ func (s *Suite) TestUnsubAll(c *check.C) {
ps.Unsub(ch1)
m, ok := <-ch1
_, ok := <-ch1
c.Check(ok, check.Equals, false)
ps.Pub("hi", "t1")
m, ok = <-ch2
m := <-ch2
c.Check(m, check.Equals, "hi")
ps.Shutdown()
......
......@@ -136,7 +136,7 @@ func (e *executor) setEnv(exec drivers.Driver) {
exec.SetStateDB(e.stateDB)
exec.SetLocalDB(e.localDB)
exec.SetEnv(e.height, e.blocktime, e.difficulty)
exec.SetApi(e.api)
exec.SetAPI(e.api)
exec.SetTxs(e.txs)
exec.SetReceipt(e.receipts)
}
......
......@@ -185,4 +185,5 @@ func TestKeyLocalAllow(t *testing.T) {
err = isAllowLocalKey([]byte("exec"), []byte("-exec------aa"))
assert.Equal(t, err, types.ErrLocalPrefix)
err = isAllowLocalKey([]byte("paracross"), []byte("LODB-user.p.para.paracross-xxxx"))
assert.Equal(t, err, types.ErrLocalPrefix)
}
......@@ -513,7 +513,7 @@ func (mem *Mempool) getSync() {
panic("client not bind message queue.")
}
msg := mem.client.NewMessage("blockchain", types.EventIsSync, nil)
err := mem.client.Send(msg, true)
mem.client.Send(msg, true)
resp, err := mem.client.Wait(msg)
if err != nil {
time.Sleep(time.Second)
......
......@@ -517,7 +517,7 @@ func TestAddBlockedTx(t *testing.T) {
t.Error(err)
return
}
msg1, err = mem.client.Wait(msg1)
_, err = mem.client.Wait(msg1)
if err != nil {
t.Error(err)
return
......
......@@ -34,7 +34,7 @@ func (a *AddrBook) Close() {
type AddrBook struct {
mtx sync.Mutex
ourAddrs map[string]*NetAddress
addrPeer map[string]*knownAddress
addrPeer map[string]*KnownAddress
cfg *types.P2P
keymtx sync.Mutex
privkey string
......@@ -43,7 +43,8 @@ type AddrBook struct {
Quit chan struct{}
}
type knownAddress struct {
// KnownAddress defines known address type
type KnownAddress struct {
kmtx sync.Mutex
Addr *NetAddress `json:"addr"`
Attempts uint `json:"attempts"`
......@@ -52,7 +53,7 @@ type knownAddress struct {
}
// GetPeerStat get peer stat
func (a *AddrBook) GetPeerStat(addr string) *knownAddress {
func (a *AddrBook) GetPeerStat(addr string) *KnownAddress {
a.mtx.Lock()
defer a.mtx.Unlock()
if peer, ok := a.addrPeer[addr]; ok {
......@@ -62,7 +63,7 @@ func (a *AddrBook) GetPeerStat(addr string) *knownAddress {
}
func (a *AddrBook) setAddrStat(addr string, run bool) (*knownAddress, bool) {
func (a *AddrBook) setAddrStat(addr string, run bool) (*KnownAddress, bool) {
a.mtx.Lock()
defer a.mtx.Unlock()
if peer, ok := a.addrPeer[addr]; ok {
......@@ -82,7 +83,7 @@ func NewAddrBook(cfg *types.P2P) *AddrBook {
a := &AddrBook{
ourAddrs: make(map[string]*NetAddress),
addrPeer: make(map[string]*knownAddress),
addrPeer: make(map[string]*KnownAddress),
cfg: cfg,
Quit: make(chan struct{}, 1),
}
......@@ -90,8 +91,8 @@ func NewAddrBook(cfg *types.P2P) *AddrBook {
return a
}
func newKnownAddress(addr *NetAddress) *knownAddress {
return &knownAddress{
func newKnownAddress(addr *NetAddress) *KnownAddress {
return &KnownAddress{
kmtx: sync.Mutex{},
Addr: addr,
Attempts: 0,
......@@ -99,7 +100,7 @@ func newKnownAddress(addr *NetAddress) *knownAddress {
}
}
func (ka *knownAddress) markGood() {
func (ka *KnownAddress) markGood() {
ka.kmtx.Lock()
defer ka.kmtx.Unlock()
now := types.Now()
......@@ -109,10 +110,10 @@ func (ka *knownAddress) markGood() {
}
// Copy a KnownAddress
func (ka *knownAddress) Copy() *knownAddress {
func (ka *KnownAddress) Copy() *KnownAddress {
ka.kmtx.Lock()
ret := knownAddress{
ret := KnownAddress{
Addr: ka.Addr.Copy(),
Attempts: ka.Attempts,
LastAttempt: ka.LastAttempt,
......@@ -122,7 +123,7 @@ func (ka *knownAddress) Copy() *knownAddress {
return &ret
}
func (ka *knownAddress) markAttempt() {
func (ka *KnownAddress) markAttempt() {
ka.kmtx.Lock()
defer ka.kmtx.Unlock()
......@@ -133,7 +134,7 @@ func (ka *knownAddress) markAttempt() {
}
// GetAttempts return attempts
func (ka *knownAddress) GetAttempts() uint {
func (ka *KnownAddress) GetAttempts() uint {
ka.kmtx.Lock()
defer ka.kmtx.Unlock()
return ka.Attempts
......@@ -176,13 +177,13 @@ func (a *AddrBook) Size() int {
}
type addrBookJSON struct {
Addrs []*knownAddress `json:"addrs"`
Addrs []*KnownAddress `json:"addrs"`
}
func (a *AddrBook) saveToDb() {
a.mtx.Lock()
defer a.mtx.Unlock()
addrs := []*knownAddress{}
addrs := []*KnownAddress{}
seeds := a.cfg.Seeds
seedsMap := make(map[string]int)
......@@ -294,7 +295,7 @@ out:
// AddAddress add a address for ours
// NOTE: addr must not be nil
func (a *AddrBook) AddAddress(addr *NetAddress, ka *knownAddress) {
func (a *AddrBook) AddAddress(addr *NetAddress, ka *KnownAddress) {
a.mtx.Lock()
defer a.mtx.Unlock()
......
......@@ -16,7 +16,8 @@ import (
"google.golang.org/grpc"
)
type downloadJob struct {
// DownloadJob defines download job type
type DownloadJob struct {
wg sync.WaitGroup
retryList *list.List
p2pcli *Cli
......@@ -32,8 +33,8 @@ type peerJob struct {
}
// NewDownloadJob create a downloadjob object
func NewDownloadJob(p2pcli *Cli, peers []*Peer) *downloadJob {
job := new(downloadJob)
func NewDownloadJob(p2pcli *Cli, peers []*Peer) *DownloadJob {
job := new(DownloadJob)
job.retryList = list.New()
job.p2pcli = p2pcli
job.busyPeer = make(map[string]*peerJob)
......@@ -41,7 +42,7 @@ func NewDownloadJob(p2pcli *Cli, peers []*Peer) *downloadJob {
return job
}
func (d *downloadJob) isBusyPeer(pid string) bool {
func (d *DownloadJob) isBusyPeer(pid string) bool {
d.mtx.Lock()
defer d.mtx.Unlock()
if pjob, ok := d.busyPeer[pid]; ok {
......@@ -50,7 +51,7 @@ func (d *downloadJob) isBusyPeer(pid string) bool {
return false
}
func (d *downloadJob) setBusyPeer(peer *pb.Peer) {
func (d *DownloadJob) setBusyPeer(peer *pb.Peer) {
d.mtx.Lock()
defer d.mtx.Unlock()
if pjob, ok := d.busyPeer[peer.GetName()]; ok {
......@@ -62,7 +63,7 @@ func (d *downloadJob) setBusyPeer(peer *pb.Peer) {
d.busyPeer[peer.GetName()] = &peerJob{peer, 1}
}
func (d *downloadJob) setFreePeer(pid string) {
func (d *DownloadJob) setFreePeer(pid string) {
d.mtx.Lock()
defer d.mtx.Unlock()
......@@ -76,7 +77,7 @@ func (d *downloadJob) setFreePeer(pid string) {
}
// GetFreePeer get free peer ,return peer
func (d *downloadJob) GetFreePeer(joblimit int64) *Peer {
func (d *DownloadJob) GetFreePeer(joblimit int64) *Peer {
_, infos := d.p2pcli.network.node.GetActivePeers()
for _, peer := range d.downloadPeers {
pbpeer, ok := infos[peer.Addr()]
......@@ -99,16 +100,16 @@ func (d *downloadJob) GetFreePeer(joblimit int64) *Peer {
}
// CancelJob cancel the downloadjob object
func (d *downloadJob) CancelJob() {
func (d *DownloadJob) CancelJob() {
atomic.StoreInt32(&d.canceljob, 1)
}
func (d *downloadJob) isCancel() bool {
func (d *DownloadJob) isCancel() bool {
return atomic.LoadInt32(&d.canceljob) == 1
}
// DownloadBlock download the block
func (d *downloadJob) DownloadBlock(invs []*pb.Inventory,
func (d *DownloadJob) DownloadBlock(invs []*pb.Inventory,
bchan chan *pb.BlockPid) []*pb.Inventory {
var errinvs []*pb.Inventory
if d.isCancel() {
......@@ -140,7 +141,7 @@ func (d *downloadJob) DownloadBlock(invs []*pb.Inventory,
return d.restOfInvs(bchan)
}
func (d *downloadJob) restOfInvs(bchan chan *pb.BlockPid) []*pb.Inventory {
func (d *DownloadJob) restOfInvs(bchan chan *pb.BlockPid) []*pb.Inventory {
var errinvs []*pb.Inventory
if d.isCancel() {
return errinvs
......@@ -166,7 +167,7 @@ func (d *downloadJob) restOfInvs(bchan chan *pb.BlockPid) []*pb.Inventory {
return invs
}
func (d *downloadJob) syncDownloadBlock(peer *Peer, inv *pb.Inventory, bchan chan *pb.BlockPid) error {
func (d *DownloadJob) syncDownloadBlock(peer *Peer, inv *pb.Inventory, bchan chan *pb.BlockPid) error {
//每次下载一个高度的数据,通过bchan返回上层
if peer == nil {
return fmt.Errorf("peer is not exist")
......
......@@ -64,7 +64,7 @@ func (j *JSONRPCServer) Listen() (int, error) {
return
}
if !checkIpWhitelist(ip) {
if !checkIPWhitelist(ip) {
writeError(w, r, 0, fmt.Sprintf(`The %s Address is not authorized!`, ip))
return
}
......@@ -75,7 +75,7 @@ func (j *JSONRPCServer) Listen() (int, error) {
return
}
//格式做一个检查
client, err := parseJsonRpcParams(data)
client, err := parseJSONRpcParams(data)
errstr := "nil"
if err != nil {
errstr = err.Error()
......@@ -90,7 +90,7 @@ func (j *JSONRPCServer) Listen() (int, error) {
if !ipaddr.IsLoopback() {
funcName := strings.Split(client.Method, ".")[len(strings.Split(client.Method, "."))-1]
if checkJrpcFuncBlacklist(funcName) || !checkJrpcFuncWhitelist(funcName) {
writeError(w, r, client.Id, fmt.Sprintf(`The %s method is not authorized!`, funcName))
writeError(w, r, client.ID, fmt.Sprintf(`The %s method is not authorized!`, funcName))
return
}
}
......@@ -114,7 +114,7 @@ func (j *JSONRPCServer) Listen() (int, error) {
}
type serverResponse struct {
Id uint64 `json:"id"`
ID uint64 `json:"id"`
Result interface{} `json:"result"`
Error interface{} `json:"error"`
}
......@@ -161,7 +161,7 @@ func auth(ctx context.Context, info *grpc.UnaryServerInfo) error {
return fmt.Errorf("the %s Address is not authorized", ip)
}
if !checkIpWhitelist(ip) {
if !checkIPWhitelist(ip) {
return fmt.Errorf("the %s Address is not authorized", ip)
}
......@@ -177,10 +177,10 @@ func auth(ctx context.Context, info *grpc.UnaryServerInfo) error {
type clientRequest struct {
Method string `json:"method"`
Params [1]interface{} `json:"params"`
Id uint64 `json:"id"`
ID uint64 `json:"id"`
}
func parseJsonRpcParams(data []byte) (*clientRequest, error) {
func parseJSONRpcParams(data []byte) (*clientRequest, error) {
var req clientRequest
err := json.Unmarshal(data, &req)
if err != nil {
......
......@@ -422,7 +422,7 @@ func (c *Chain33) WalletTxList(in rpctypes.ReqWalletTransactionList, result *int
}
{
var txdetails rpctypes.WalletTxDetails
rpctypes.ConvertWalletTxDetailToJson(reply, &txdetails)
rpctypes.ConvertWalletTxDetailToJSON(reply, &txdetails)
*result = &txdetails
}
return nil
......
......@@ -42,11 +42,11 @@ func New(prefix, url string) (*JSONClient, error) {
type clientRequest struct {
Method string `json:"method"`
Params [1]interface{} `json:"params"`
Id uint64 `json:"id"`
ID uint64 `json:"id"`
}
type clientResponse struct {
Id uint64 `json:"id"`
ID uint64 `json:"id"`
Result *json.RawMessage `json:"result"`
Error interface{} `json:"error"`
}
......
......@@ -10,9 +10,9 @@ import (
"os"
)
// RpcCtx rpc ctx interface
// RPCCtx rpc ctx interface
// TODO: SetPostRunCb()
type RpcCtx struct {
type RPCCtx struct {
Addr string
Method string
Params interface{}
......@@ -23,9 +23,9 @@ type RpcCtx struct {
// Callback a callback function
type Callback func(res interface{}) (interface{}, error)
// NewRpcCtx produce a object of rpcctx
func NewRpcCtx(laddr, method string, params, res interface{}) *RpcCtx {
return &RpcCtx{
// NewRPCCtx produce a object of rpcctx
func NewRPCCtx(laddr, method string, params, res interface{}) *RPCCtx {
return &RPCCtx{
Addr: laddr,
Method: method,
Params: params,
......@@ -34,12 +34,12 @@ func NewRpcCtx(laddr, method string, params, res interface{}) *RpcCtx {
}
// SetResultCb rpcctx callback
func (c *RpcCtx) SetResultCb(cb Callback) {
func (c *RPCCtx) SetResultCb(cb Callback) {
c.cb = cb
}
// RunResult format rpc result
func (c *RpcCtx) RunResult() (interface{}, error) {
func (c *RPCCtx) RunResult() (interface{}, error) {
rpc, err := NewJSONClient(c.Addr)
if err != nil {
return nil, err
......@@ -63,7 +63,7 @@ func (c *RpcCtx) RunResult() (interface{}, error) {
}
// Run rpcctx to runresult
func (c *RpcCtx) Run() {
func (c *RPCCtx) Run() {
result, err := c.RunResult()
if err != nil {
fmt.Fprintln(os.Stderr, err)
......@@ -78,7 +78,7 @@ func (c *RpcCtx) Run() {
}
// RunWithoutMarshal return source result of string
func (c *RpcCtx) RunWithoutMarshal() {
func (c *RPCCtx) RunWithoutMarshal() {
var res string
rpc, err := NewJSONClient(c.Addr)
if err != nil {
......
......@@ -20,7 +20,7 @@ import (
)
var (
remoteIpWhitelist = make(map[string]bool)
remoteIPWhitelist = make(map[string]bool)
rpcCfg *types.RPC
jrpcFuncWhitelist = make(map[string]bool)
grpcFuncWhitelist = make(map[string]bool)
......@@ -67,7 +67,7 @@ func (s *JSONRPCServer) Close() {
}
}
func checkIpWhitelist(addr string) bool {
func checkIPWhitelist(addr string) bool {
//回环网络直接允许
ip := net.ParseIP(addr)
if ip.IsLoopback() {
......@@ -77,10 +77,10 @@ func checkIpWhitelist(addr string) bool {
if ipv4 != nil {
addr = ipv4.String()
}
if _, ok := remoteIpWhitelist["0.0.0.0"]; ok {
if _, ok := remoteIPWhitelist["0.0.0.0"]; ok {
return true
}
if _, ok := remoteIpWhitelist[addr]; ok {
if _, ok := remoteIPWhitelist[addr]; ok {
return true
}
return false
......@@ -177,7 +177,7 @@ type RPC struct {
// InitCfg interfaces
func InitCfg(cfg *types.RPC) {
rpcCfg = cfg
InitIpWhitelist(cfg)
InitIPWhitelist(cfg)
InitJrpcFuncWhitelist(cfg)
InitGrpcFuncWhitelist(cfg)
InitJrpcFuncBlacklist(cfg)
......@@ -265,29 +265,29 @@ func (r *RPC) Close() {
}
}
// InitIpWhitelist init ip whitelist
func InitIpWhitelist(cfg *types.RPC) {
// InitIPWhitelist init ip whitelist
func InitIPWhitelist(cfg *types.RPC) {
if len(cfg.Whitelist) == 0 && len(cfg.Whitlist) == 0 {
remoteIpWhitelist["127.0.0.1"] = true
remoteIPWhitelist["127.0.0.1"] = true
return
}
if len(cfg.Whitelist) == 1 && cfg.Whitelist[0] == "*" {
remoteIpWhitelist["0.0.0.0"] = true
remoteIPWhitelist["0.0.0.0"] = true
return
}
if len(cfg.Whitlist) == 1 && cfg.Whitlist[0] == "*" {
remoteIpWhitelist["0.0.0.0"] = true
remoteIPWhitelist["0.0.0.0"] = true
return
}
if len(cfg.Whitelist) != 0 {
for _, addr := range cfg.Whitelist {
remoteIpWhitelist[addr] = true
remoteIPWhitelist[addr] = true
}
return
}
if len(cfg.Whitlist) != 0 {
for _, addr := range cfg.Whitlist {
remoteIpWhitelist[addr] = true
remoteIPWhitelist[addr] = true
}
return
}
......
......@@ -22,18 +22,18 @@ import (
func TestCheckIpWhitelist(t *testing.T) {
address := "127.0.0.1"
assert.True(t, checkIpWhitelist(address))
assert.True(t, checkIPWhitelist(address))
address = "::1"
assert.True(t, checkIpWhitelist(address))
assert.True(t, checkIPWhitelist(address))
address = "192.168.3.1"
remoteIpWhitelist[address] = true
assert.False(t, checkIpWhitelist("192.168.3.2"))
remoteIPWhitelist[address] = true
assert.False(t, checkIPWhitelist("192.168.3.2"))
remoteIpWhitelist["0.0.0.0"] = true
assert.True(t, checkIpWhitelist(address))
assert.True(t, checkIpWhitelist("192.168.3.2"))
remoteIPWhitelist["0.0.0.0"] = true
assert.True(t, checkIPWhitelist(address))
assert.True(t, checkIPWhitelist("192.168.3.2"))
}
......
......@@ -47,8 +47,8 @@ func DecodeLog(execer []byte, rlog *ReceiptData) (*ReceiptDataResult, error) {
return rd, nil
}
// ConvertWalletTxDetailToJson conver the wallet tx detail to json
func ConvertWalletTxDetailToJson(in *types.WalletTxDetails, out *WalletTxDetails) error {
// ConvertWalletTxDetailToJSON conver the wallet tx detail to json
func ConvertWalletTxDetailToJSON(in *types.WalletTxDetails, out *WalletTxDetails) error {
if in == nil || out == nil {
return types.ErrInvalidParam
}
......
......@@ -7,18 +7,18 @@ package autotest
import (
"reflect"
. "github.com/33cn/chain33/cmd/autotest/types"
"github.com/33cn/chain33/cmd/autotest/types"
)
type coinsAutoTest struct {
SimpleCaseArr []SimpleCase `toml:"SimpleCase,omitempty"`
TransferCaseArr []TransferCase `toml:"TransferCase,omitempty"`
WithdrawCaseArr []WithdrawCase `toml:"WithdrawCase,omitempty"`
SimpleCaseArr []types.SimpleCase `toml:"SimpleCase,omitempty"`
TransferCaseArr []TransferCase `toml:"TransferCase,omitempty"`
WithdrawCaseArr []WithdrawCase `toml:"WithdrawCase,omitempty"`
}
func init() {
RegisterAutoTest(coinsAutoTest{})
types.RegisterAutoTest(coinsAutoTest{})
}
......
......@@ -7,12 +7,12 @@ package autotest
import (
"strconv"
. "github.com/33cn/chain33/cmd/autotest/types"
"github.com/33cn/chain33/cmd/autotest/types"
)
// TransferCase transfer case
type TransferCase struct {
BaseCase
types.BaseCase
From string `toml:"from"`
To string `toml:"to"`
Amount string `toml:"amount"`
......@@ -20,19 +20,19 @@ type TransferCase struct {
// TransferPack transfer pack
type TransferPack struct {
BaseCasePack
types.BaseCasePack
}
// SendCommand sed command
func (testCase *TransferCase) SendCommand(packID string) (PackFunc, error) {
func (testCase *TransferCase) SendCommand(packID string) (types.PackFunc, error) {
return DefaultSend(testCase, &TransferPack{}, packID)
return types.DefaultSend(testCase, &TransferPack{}, packID)
}
// GetCheckHandlerMap get check handle for map
func (pack *TransferPack) GetCheckHandlerMap() interface{} {
funcMap := make(CheckHandlerMapDiscard, 2)
funcMap := make(types.CheckHandlerMapDiscard, 2)
funcMap["balance"] = pack.checkBalance
return funcMap
......@@ -61,10 +61,10 @@ func (pack *TransferPack) checkBalance(txInfo map[string]interface{}) bool {
//transfer to contract, deposit
if len(logArr) == 4 {
logDeposit := logArr[3].(map[string]interface{})["log"].(map[string]interface{})
depositCheck = CheckBalanceDeltaWithAddr(logDeposit, interCase.From, Amount)
depositCheck = types.CheckBalanceDeltaWithAddr(logDeposit, interCase.From, Amount)
}
return CheckBalanceDeltaWithAddr(logFee, interCase.From, -fee) &&
CheckBalanceDeltaWithAddr(logSend, interCase.From, -Amount) &&
CheckBalanceDeltaWithAddr(logRecv, interCase.To, Amount) && depositCheck
return types.CheckBalanceDeltaWithAddr(logFee, interCase.From, -fee) &&
types.CheckBalanceDeltaWithAddr(logSend, interCase.From, -Amount) &&
types.CheckBalanceDeltaWithAddr(logRecv, interCase.To, Amount) && depositCheck
}
......@@ -7,31 +7,31 @@ package autotest
import (
"strconv"
. "github.com/33cn/chain33/cmd/autotest/types"
"github.com/33cn/chain33/cmd/autotest/types"
)
// WithdrawCase defines the withdraw case
type WithdrawCase struct {
BaseCase
types.BaseCase
Addr string `toml:"addr"`
Amount string `toml:"amount"`
}
// WithdrawPack defines the withdraw pack
type WithdrawPack struct {
BaseCasePack
types.BaseCasePack
}
// SendCommand send command of withdrawcase
func (testCase *WithdrawCase) SendCommand(packID string) (PackFunc, error) {
func (testCase *WithdrawCase) SendCommand(packID string) (types.PackFunc, error) {
return DefaultSend(testCase, &WithdrawPack{}, packID)
return types.DefaultSend(testCase, &WithdrawPack{}, packID)
}
// GetCheckHandlerMap get check handler for map
func (pack *WithdrawPack) GetCheckHandlerMap() interface{} {
funcMap := make(CheckHandlerMapDiscard, 1)
funcMap := make(types.CheckHandlerMapDiscard, 1)
funcMap["balance"] = pack.checkBalance
return funcMap
......@@ -62,8 +62,8 @@ func (pack *WithdrawPack) checkBalance(txInfo map[string]interface{}) bool {
"ToPrev", logRecv["prev"].(map[string]interface{})["balance"].(string),
"ToCurr", logRecv["current"].(map[string]interface{})["balance"].(string))
return CheckBalanceDeltaWithAddr(logFee, interCase.Addr, -fee) &&
CheckBalanceDeltaWithAddr(logWithdraw, interCase.Addr, -Amount) &&
CheckBalanceDeltaWithAddr(logSend, withdrawFrom, -Amount) &&
CheckBalanceDeltaWithAddr(logRecv, interCase.Addr, Amount)
return types.CheckBalanceDeltaWithAddr(logFee, interCase.Addr, -fee) &&
types.CheckBalanceDeltaWithAddr(logWithdraw, interCase.Addr, -Amount) &&
types.CheckBalanceDeltaWithAddr(logSend, withdrawFrom, -Amount) &&
types.CheckBalanceDeltaWithAddr(logRecv, interCase.Addr, Amount)
}
......@@ -59,8 +59,16 @@ func (c *Coins) GetDriverName() string {
return driverName
}
// CheckTx check transaction
// CheckTx check transaction amount 必须不能为负数
func (c *Coins) CheckTx(tx *types.Transaction, index int) error {
ety := c.GetExecutorType()
amount, err := ety.Amount(tx)
if err != nil {
return err
}
if amount < 0 {
return types.ErrAmount
}
return nil
}
......@@ -76,3 +84,8 @@ func (c *Coins) IsFriend(myexec, writekey []byte, othertx *types.Transaction) bo
}
return false
}
// CheckReceiptExecOk return true to check if receipt ty is ok
func (c *Coins) CheckReceiptExecOk() bool {
return true
}
......@@ -10,9 +10,6 @@ import (
// ExecDelLocal_Transfer delete transfer of local exec
func (c *Coins) ExecDelLocal_Transfer(transfer *types.AssetsTransfer, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) {
if receipt.GetTy() != types.ExecOk {
return &types.LocalDBSet{}, nil
}
kv, err := updateAddrReciver(c.GetLocalDB(), tx.GetRealToAddr(), transfer.Amount, false)
if err != nil {
return nil, err
......@@ -22,9 +19,6 @@ func (c *Coins) ExecDelLocal_Transfer(transfer *types.AssetsTransfer, tx *types.
// ExecDelLocal_TransferToExec delete transfer of local exec to exec
func (c *Coins) ExecDelLocal_TransferToExec(transfer *types.AssetsTransferToExec, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) {
if receipt.GetTy() != types.ExecOk {
return &types.LocalDBSet{}, nil
}
kv, err := updateAddrReciver(c.GetLocalDB(), tx.GetRealToAddr(), transfer.Amount, false)
if err != nil {
return nil, err
......@@ -34,9 +28,6 @@ func (c *Coins) ExecDelLocal_TransferToExec(transfer *types.AssetsTransferToExec
// ExecDelLocal_Withdraw delete withdraw of local exec
func (c *Coins) ExecDelLocal_Withdraw(withdraw *types.AssetsWithdraw, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) {
if receipt.GetTy() != types.ExecOk {
return &types.LocalDBSet{}, nil
}
from := tx.From()
kv, err := updateAddrReciver(c.GetLocalDB(), from, withdraw.Amount, false)
if err != nil {
......
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