Skip to content

Commit

Permalink
fix: remove nep5 contract pending data (#1201)
Browse files Browse the repository at this point in the history
* refactor: disable NEP5 pending

Signed-off-by: Goren G <[email protected]>

* feat: remove nep5 contract pending data

* fix: PoV pub/sub

- format code

Signed-off-by: Goren G <[email protected]>

* feat: remove nep5 contract pendings

Co-authored-by: Goren G <[email protected]>
  • Loading branch information
zengchen221 and Goren G authored Jul 27, 2020
1 parent 389227a commit 6c2c460
Show file tree
Hide file tree
Showing 19 changed files with 81 additions and 33 deletions.
4 changes: 3 additions & 1 deletion cmd/client/commands/kyc_admin_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package commands
import (
"encoding/hex"
"fmt"

"github.com/abiosoft/ishell"
rpc "github.com/qlcchain/jsonrpc2"

"github.com/qlcchain/go-qlc/cmd/util"
"github.com/qlcchain/go-qlc/common/types"
cutil "github.com/qlcchain/go-qlc/common/util"
"github.com/qlcchain/go-qlc/rpc/api"
rpc "github.com/qlcchain/jsonrpc2"
)

func addKYCAdminUpdateCmdByShell(parentCmd *ishell.Cmd) {
Expand Down
4 changes: 3 additions & 1 deletion cmd/client/commands/kyc_operator_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package commands
import (
"encoding/hex"
"fmt"

"github.com/abiosoft/ishell"
rpc "github.com/qlcchain/jsonrpc2"

"github.com/qlcchain/go-qlc/cmd/util"
"github.com/qlcchain/go-qlc/common/types"
cutil "github.com/qlcchain/go-qlc/common/util"
"github.com/qlcchain/go-qlc/rpc/api"
rpc "github.com/qlcchain/jsonrpc2"
)

func addKYOperatorUpdateCmdByShell(parentCmd *ishell.Cmd) {
Expand Down
4 changes: 3 additions & 1 deletion cmd/client/commands/kyc_status_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package commands
import (
"encoding/hex"
"fmt"

"github.com/abiosoft/ishell"
rpc "github.com/qlcchain/jsonrpc2"

"github.com/qlcchain/go-qlc/cmd/util"
"github.com/qlcchain/go-qlc/common/types"
cutil "github.com/qlcchain/go-qlc/common/util"
"github.com/qlcchain/go-qlc/rpc/api"
rpc "github.com/qlcchain/jsonrpc2"
)

func addKYCStatusUpdateCmdByShell(parentCmd *ishell.Cmd) {
Expand Down
4 changes: 3 additions & 1 deletion cmd/client/commands/kyc_trade_address_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package commands
import (
"encoding/hex"
"fmt"

"github.com/abiosoft/ishell"
rpc "github.com/qlcchain/jsonrpc2"

"github.com/qlcchain/go-qlc/cmd/util"
"github.com/qlcchain/go-qlc/common/types"
cutil "github.com/qlcchain/go-qlc/common/util"
"github.com/qlcchain/go-qlc/rpc/api"
rpc "github.com/qlcchain/jsonrpc2"
)

func addKYCTradeAddressUpdateCmdByShell(parentCmd *ishell.Cmd) {
Expand Down
3 changes: 2 additions & 1 deletion consensus/dpos/dpos_impl_testnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
package dpos

import (
"testing"

"github.com/qlcchain/go-qlc/common/types"
"github.com/qlcchain/go-qlc/common/vmcontract/contractaddress"
"github.com/qlcchain/go-qlc/mock"
cabi "github.com/qlcchain/go-qlc/vm/contract/abi"
"testing"
)

func TestDispatchAckedBlock(t *testing.T) {
Expand Down
28 changes: 28 additions & 0 deletions ledger/migration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ func (m MigrationV15ToV16) Migrate(store storage.Store) error {
reset := false
bs := make([]bytesKV, 0)
pendingKvs := make([]*pendingKV, 0)
nep5PendingKvs := make([]*pendingKV, 0)

// get all pending infos from db
prefix, _ := storage.GetKeyOfParts(storage.KeyPrefixPending)
Expand All @@ -290,6 +291,10 @@ func (m MigrationV15ToV16) Migrate(store storage.Store) error {
}
bs = append(bs, c)

pi := new(types.PendingInfo)
if err := pi.Deserialize(value); err != nil {
return fmt.Errorf("pendingInfo deserialize err: %s", err)
}
pk := new(types.PendingKey)
if err := pk.Deserialize(key[1:]); err != nil {
if _, err := pk.UnmarshalMsg(key[1:]); err != nil {
Expand All @@ -302,6 +307,11 @@ func (m MigrationV15ToV16) Migrate(store storage.Store) error {
value: value,
}
pendingKvs = append(pendingKvs, pkv)

// if pending is from nep5 contract
if pi.Source == contractaddress.NEP5PledgeAddress {
nep5PendingKvs = append(nep5PendingKvs, pkv)
}
return nil
})
if err != nil {
Expand Down Expand Up @@ -346,10 +356,28 @@ func (m MigrationV15ToV16) Migrate(store storage.Store) error {
return err
}
}
for _, pkv := range nep5PendingKvs {
pKey, err := storage.GetKeyOfParts(storage.KeyPrefixPending, pkv.key)
if err != nil {
return err
}
if err := batch.Delete(pKey); err != nil {
return err
}
}
return updateVersion(m, batch)
})
} else {
return store.BatchWrite(false, func(batch storage.Batch) error {
for _, pkv := range nep5PendingKvs {
pKey, err := storage.GetKeyOfParts(storage.KeyPrefixPending, pkv.key)
if err != nil {
return err
}
if err := batch.Delete(pKey); err != nil {
return err
}
}
return updateVersion(m, batch)
})
}
Expand Down
3 changes: 2 additions & 1 deletion p2p/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import (
dht "github.com/libp2p/go-libp2p-kad-dht"
libp2pps "github.com/libp2p/go-libp2p-pubsub"
localdiscovery "github.com/libp2p/go-libp2p/p2p/discovery"
"go.uber.org/zap"

chaincontext "github.com/qlcchain/go-qlc/chain/context"
"github.com/qlcchain/go-qlc/config"
ping "github.com/qlcchain/go-qlc/p2p/pinger"
"github.com/qlcchain/go-qlc/p2p/pubsub"
"go.uber.org/zap"

"github.com/google/uuid"
//"github.com/qlcchain/go-qlc/ledger"
Expand Down
3 changes: 2 additions & 1 deletion rpc/api/kyc.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package api

import (
"go.uber.org/zap"

chainctx "github.com/qlcchain/go-qlc/chain/context"
"github.com/qlcchain/go-qlc/common/types"
"github.com/qlcchain/go-qlc/common/vmcontract/contractaddress"
Expand All @@ -9,7 +11,6 @@ import (
"github.com/qlcchain/go-qlc/vm/contract"
"github.com/qlcchain/go-qlc/vm/contract/abi"
"github.com/qlcchain/go-qlc/vm/vmstore"
"go.uber.org/zap"
)

type KYCApi struct {
Expand Down
3 changes: 2 additions & 1 deletion rpc/api/kyc_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package api

import (
"testing"

"github.com/qlcchain/go-qlc/common/statedb"
"github.com/qlcchain/go-qlc/common/types"
"github.com/qlcchain/go-qlc/common/vmcontract/contractaddress"
"github.com/qlcchain/go-qlc/ledger"
"github.com/qlcchain/go-qlc/mock"
"github.com/qlcchain/go-qlc/vm/contract/abi"
"testing"
)

func addKYCTestAdmin(t *testing.T, l *ledger.Ledger, admin *abi.KYCAdminAccount, povHeight uint64) {
Expand Down
3 changes: 2 additions & 1 deletion rpc/api/ledger_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
package api

import (
"github.com/qlcchain/go-qlc/common/types"
"testing"

"github.com/qlcchain/go-qlc/common/types"
)

func TestLedgerAPI_GenesisInfo1(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion rpc/api/ledger_testnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
package api

import (
"github.com/qlcchain/go-qlc/common/types"
"testing"

"github.com/qlcchain/go-qlc/common/types"
)

func TestLedgerAPI_GenesisInfo(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion rpc/api/pov_pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (r *PovSubscription) subscribeEvent() {
case *types.PovBlock:
r.setBlocks(msg)
}
}))
}), r.eb)

if err := r.subscriber.Subscribe(topic.EventPovConnectBestBlock); err != nil {
r.logger.Error("subscribe EventPovConnectBestBlock error, ", err)
Expand Down
3 changes: 2 additions & 1 deletion vm/contract/abi/abi_kyc.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package abi

import (
"strings"

"github.com/qlcchain/go-qlc/common/statedb"
"github.com/qlcchain/go-qlc/common/types"
cfg "github.com/qlcchain/go-qlc/config"
"github.com/qlcchain/go-qlc/vm/abi"
"github.com/qlcchain/go-qlc/vm/vmstore"
"strings"
)

const (
Expand Down
3 changes: 2 additions & 1 deletion vm/contract/abi/abi_kyc_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package abi

import (
"testing"

"github.com/qlcchain/go-qlc/common/statedb"
"github.com/qlcchain/go-qlc/common/types"
"github.com/qlcchain/go-qlc/common/vmcontract/contractaddress"
cfg "github.com/qlcchain/go-qlc/config"
"github.com/qlcchain/go-qlc/ledger"
"github.com/qlcchain/go-qlc/mock"
"github.com/qlcchain/go-qlc/vm/vmstore"
"testing"
)

func addKYCTestAdmin(t *testing.T, l *ledger.Ledger, admin *KYCAdminAccount, povHeight uint64) {
Expand Down
1 change: 1 addition & 0 deletions vm/contract/abi/abi_kyc_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package abi

import (
"errors"

"github.com/qlcchain/go-qlc/common/types"
)

Expand Down
1 change: 1 addition & 0 deletions vm/contract/kyc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package contract
import (
"errors"
"fmt"

"github.com/qlcchain/go-qlc/common/statedb"
"github.com/qlcchain/go-qlc/common/types"
cfg "github.com/qlcchain/go-qlc/config"
Expand Down
5 changes: 3 additions & 2 deletions vm/contract/kyc_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package contract

import (
"strings"
"testing"

"github.com/qlcchain/go-qlc/common/statedb"
"github.com/qlcchain/go-qlc/common/types"
"github.com/qlcchain/go-qlc/common/vmcontract/contractaddress"
Expand All @@ -9,8 +12,6 @@ import (
"github.com/qlcchain/go-qlc/mock"
"github.com/qlcchain/go-qlc/vm/contract/abi"
"github.com/qlcchain/go-qlc/vm/vmstore"
"strings"
"testing"
)

func addKYCTestAdmin(t *testing.T, l *ledger.Ledger, admin *abi.KYCAdminAccount, povHeight uint64) {
Expand Down
27 changes: 14 additions & 13 deletions vm/contract/nep5_pledge.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,20 @@ func (*Nep5Pledge) DoSend(ctx *vmstore.VMContext, block *types.StateBlock) error
}

func (*Nep5Pledge) DoPending(block *types.StateBlock) (*types.PendingKey, *types.PendingInfo, error) {
param, err := cabi.ParsePledgeParam(block.GetData())
if err != nil {
return nil, nil, fmt.Errorf("invalid beneficial address, %s", err)
}

return &types.PendingKey{
Address: param.Beneficial,
Hash: block.GetHash(),
}, &types.PendingInfo{
Source: types.Address(block.GetLink()),
Amount: types.ZeroBalance,
Type: block.Token,
}, nil
return nil, nil, errors.New("not implemented")
//param, err := cabi.ParsePledgeParam(block.GetData())
//if err != nil {
// return nil, nil, fmt.Errorf("invalid beneficial address, %s", err)
//}
//
//return &types.PendingKey{
// Address: param.Beneficial,
// Hash: block.GetHash(),
// }, &types.PendingInfo{
// Source: types.Address(block.GetLink()),
// Amount: types.ZeroBalance,
// Type: block.Token,
// }, nil
}

func (*Nep5Pledge) DoReceive(ctx *vmstore.VMContext, block, input *types.StateBlock) ([]*ContractBlock, error) {
Expand Down
10 changes: 5 additions & 5 deletions vm/contract/nep5_pledge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ func TestNep5Pledge_And_Withdraw(t *testing.T) {
t.Fatal(err)
}

if pending, info, err := pledge.DoPending(send); err != nil {
t.Fatal(err)
} else {
t.Log(pending, info)
}
//if pending, info, err := pledge.DoPending(send); err != nil {
// t.Fatal(err)
//} else {
// t.Log(pending, info)
//}

if receiver, err := pledge.GetTargetReceiver(ctx, send); err != nil {
t.Fatal(err)
Expand Down

0 comments on commit 6c2c460

Please sign in to comment.