Skip to content

Commit

Permalink
delete useless method (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
bxq2011hust authored Jan 9, 2024
1 parent bc614c6 commit 7d061dc
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 94 deletions.
17 changes: 3 additions & 14 deletions v3/abi/bind/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package bind
import (
"context"
"errors"
"math/big"

"github.com/FISCO-BCOS/go-sdk/v3/types"
"github.com/ethereum/go-ethereum"
Expand All @@ -46,20 +45,10 @@ var (
type ContractCaller interface {
// CodeAt returns the code of the given account. This is needed to differentiate
// between contract internal errors and the local chain being out of sync.
CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error)
CodeAt(ctx context.Context, contract common.Address) ([]byte, error)
// ContractCall executes a Solidity contract call with the specified data as the
// input.
CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
}

// PendingContractCaller defines methods to perform contract calls on the pending state.
// Call will try to discover this interface when access to the pending state is requested.
// If the backend does not support the pending state, Call returns ErrNoPendingState.
type PendingContractCaller interface {
// PendingCodeAt returns the code of the given account in the pending state.
PendingCodeAt(ctx context.Context, contract common.Address) ([]byte, error)
// PendingCallContract executes a Solidity contract call against the pending state.
PendingCallContract(ctx context.Context, call ethereum.CallMsg) ([]byte, error)
CallContract(ctx context.Context, call ethereum.CallMsg) ([]byte, error)
}

// ContractTransactor defines the methods needed to allow operating with contract
Expand Down Expand Up @@ -94,7 +83,7 @@ type ContractFilterer interface {
// DeployBackend wraps the operations needed by WaitMined and WaitDeployed.
type DeployBackend interface {
TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)
CodeAt(ctx context.Context, account common.Address) ([]byte, error)
}

// ContractBackend defines the methods needed to work with contracts on a read-write basis.
Expand Down
31 changes: 7 additions & 24 deletions v3/abi/bind/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,30 +160,13 @@ func (c *BoundContract) Call(opts *CallOpts, result interface{}, method string,
code []byte
output []byte
)

if opts.Pending {
pb, ok := c.caller.(PendingContractCaller)
if !ok {
return ErrNoPendingState
}
output, err = pb.PendingCallContract(ctx, msg)
if err == nil && len(output) == 0 {
// Make sure we have a contract to operate on, and bail out otherwise.
if code, err = pb.PendingCodeAt(ctx, c.address); err != nil {
return err
} else if len(code) == 0 {
return ErrNoCode
}
}
} else {
output, err = c.caller.CallContract(ctx, msg, opts.BlockNumber)
if err == nil && len(output) == 0 {
// Make sure we have a contract to operate on, and bail out otherwise.
if code, err = c.caller.CodeAt(ctx, c.address, opts.BlockNumber); err != nil {
return err
} else if len(code) == 0 {
return ErrNoCode
}
output, err = c.caller.CallContract(ctx, msg)
if err == nil && len(output) == 0 {
// Make sure we have a contract to operate on, and bail out otherwise.
if code, err = c.caller.CodeAt(ctx, c.address); err != nil {
return err
} else if len(code) == 0 {
return ErrNoCode
}
}
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion v3/abi/bind/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func WaitDeployed(ctx context.Context, b DeployBackend, tx *types.Transaction) (
// Check that code has indeed been deployed at the address.
// This matters on pre-Homestead chains: OOG in the constructor
// could leave an empty account behind.
code, err := b.CodeAt(ctx, common.HexToAddress(receipt.ContractAddress), nil)
code, err := b.CodeAt(ctx, common.HexToAddress(receipt.ContractAddress))
if err == nil && len(code) == 0 {
err = ErrNoCodeAfterDeploy
}
Expand Down
47 changes: 3 additions & 44 deletions v3/client/go_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package client

import (
"context"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -153,7 +152,7 @@ func (c *Client) SMCrypto() bool {

// CodeAt returns the contract code of the given account.
// The block number can be nil, in which case the code is taken from the latest known block.
func (c *Client) CodeAt(ctx context.Context, address common.Address, blockNumber *big.Int) ([]byte, error) {
func (c *Client) CodeAt(ctx context.Context, address common.Address) ([]byte, error) {
var raw interface{}
err := c.conn.CallContext(ctx, &raw, "getCode", address.Hex())
if err != nil {
Expand Down Expand Up @@ -191,7 +190,7 @@ func (c *Client) PendingCodeAt(ctx context.Context, address common.Address) ([]b
}

// CallContract invoke the call method of rpc api
func (c *Client) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) {
func (c *Client) CallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error) {
var hexBytes hexutil.Bytes
var cr *callResult
err := c.conn.CallContext(ctx, &cr, "call", toCallArg(msg))
Expand All @@ -210,30 +209,6 @@ func (c *Client) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNu
return hexBytes, nil
}

// PendingCallContract executes a message call transaction using the EVM.
// The state seen by the contract call is the pending state.
func (c *Client) PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error) {
var hexBytes hexutil.Bytes
var cr *callResult
err := c.conn.CallContext(ctx, &cr, "call", toCallArg(msg))
if err != nil {
return nil, err
}
if cr.Status != 0 {
var errorMessage string
if len(cr.Output) >= 138 {
outputBytes, err := hex.DecodeString(cr.Output[2:])
if err != nil {
return nil, fmt.Errorf("call error of status %d, hex.DecodeString failed", cr.Status)
}
errorMessage = string(outputBytes[68:])
}
return nil, fmt.Errorf("call error of status %d, %v", cr.Status, errorMessage)
}
hexBytes = common.FromHex(cr.Output)
return hexBytes, nil
}

// SendTransaction injects a signed transaction into the pending pool for execution.
//
// If the transaction was a contract creation use the TransactionReceipt method to get the
Expand Down Expand Up @@ -337,7 +312,6 @@ func (c *Client) TransactionReceipt(ctx context.Context, txHash common.Hash) (*t
return c.GetTransactionReceipt(ctx, txHash, true)
}

// eventlog
func (c *Client) SubscribeEventLogs(ctx context.Context, eventLogParams types.EventLogParams, handler func(int, []types.Log)) (string, error) {
return c.conn.SubscribeEventLogs(eventLogParams, handler)
}
Expand All @@ -347,7 +321,6 @@ func (c *Client) UnSubscribeEventLogs(ctx context.Context, taskId string) error
return nil
}

// amop
func (c *Client) SubscribeAmopTopic(ctx context.Context, topic string, handler func([]byte, *[]byte)) error {
return c.conn.SubscribeAmopTopic(topic, handler)
}
Expand Down Expand Up @@ -404,20 +377,6 @@ func (c *Client) GetBlockNumber(ctx context.Context) (int64, error) {
return raw, err
}

// // GetBlockLimit returns the blocklimit for current blocknumber
// func (c *Client) GetBlockLimit(ctx context.Context) (*big.Int, error) {
// var blockLimit *big.Int
// defaultNumber := big.NewInt(BlockLimit)
// var raw int
// err := c.conn.CallContext(ctx, &raw, "getBlockNumber")
// if err != nil {
// return nil, err
// }

// blockLimit = defaultNumber.Add(defaultNumber, big.NewInt(int64(raw)))
// return blockLimit, nil
// }

// GetPBFTView returns the latest PBFT view(hex format) of the specific group and it will returns a wrong sentence
// if the consensus algorithm is not the PBFT.
func (c *Client) GetPBFTView(ctx context.Context) ([]byte, error) {
Expand Down Expand Up @@ -492,7 +451,7 @@ func (c *Client) GetPeers(ctx context.Context) ([]byte, error) {
return js, err
}

// GetGroupPeers returns the nodes and the overser nodes list on a specific group
// GetGroupPeers returns the nodes and the observer nodes list on a specific group
func (c *Client) GetGroupPeers(ctx context.Context) ([]byte, error) {
var raw interface{}
err := c.conn.CallContext(ctx, &raw, "getGroupPeers")
Expand Down
10 changes: 5 additions & 5 deletions v3/ios/contract_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ type ContractProxy struct {

// CodeAt returns the code of the given account. This is needed to differentiate
// between contract internal errors and the local chain being out of sync.
func (c *ContractProxy) CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error) {
func (c *ContractProxy) CodeAt(ctx context.Context, contract common.Address) ([]byte, error) {
return []byte{}, nil
}

// ContractCall executes a Solidity contract call with the specified data as the
// input.
func (c *ContractProxy) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) {
func (c *ContractProxy) CallContract(ctx context.Context, call ethereum.CallMsg) ([]byte, error) {
return c.Call(ctx, c.groupID, call)
}

Expand All @@ -49,7 +49,7 @@ func (c *ContractProxy) PendingCodeAt(ctx context.Context, account common.Addres

// SendTransaction injects the transaction into the pending pool for execution.
// todo ios 怎么处理?
func (c *ContractProxy) SendTransaction(ctx context.Context, tx *types.Transaction, contract *common.Address, input []byte) (*types.Receipt, error) {
func (c *ContractProxy) SendTransaction(ctx context.Context, tx *types.Transaction) (*types.Receipt, error) {
data, err := rlp.EncodeToBytes(tx)
if err != nil {
fmt.Printf("rlp encode tx error!")
Expand Down Expand Up @@ -87,8 +87,8 @@ func (c *ContractProxy) SendTransaction(ctx context.Context, tx *types.Transacti
}

// AsyncSendTransaction injects the transaction into the pending pool for execution.
func (c *ContractProxy) AsyncSendTransaction(ctx context.Context, tx *types.Transaction, contract *common.Address, input []byte, handler func(*types.Receipt, error)) error {
receipt, err := c.SendTransaction(ctx, tx, contract, nil)
func (c *ContractProxy) AsyncSendTransaction(ctx context.Context, tx *types.Transaction, handler func(*types.Receipt, error)) error {
receipt, err := c.SendTransaction(ctx, tx)
handler(receipt, err)
return err
}
Expand Down
2 changes: 1 addition & 1 deletion v3/ios/fisco_bcos_ios_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (sdk *BcosSDK) DeployContract(contractAbi string, contractBin string, param
if err != nil {
return toReceiptResult(nil, errors.New("params error: "+err.Error()))
}
_, receipt, _, err := bind.DeployContractGetReceipt(sdk.auth, parsedAbi, common.FromHex(contractBin), sdk.backend, goParam...)
_, receipt, _, err := bind.DeployContractGetReceipt(sdk.auth, parsedAbi, common.FromHex(contractBin), contractAbi, sdk.backend, goParam...)
return toReceiptResult(receipt, err)
}

Expand Down
7 changes: 2 additions & 5 deletions v3/precompiled/consensus/consensus_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/hex"
"os"
"regexp"
"testing"

"github.com/FISCO-BCOS/go-sdk/v3/client"
Expand Down Expand Up @@ -46,12 +45,10 @@ func getNodeID(t *testing.T) {
if err != nil {
t.Fatalf("sealer list not found: %v", err)
}
reg := regexp.MustCompile(`[\w]+`)
nodeList := reg.FindAllString(string(sealerList), -1)
if len(nodeList) < 2 {
if len(sealerList) < 2 {
t.Fatalf("the number of nodes does not exceed 2")
}
nodeID = nodeList[1]
nodeID = sealerList[1].ID
}

func TestMain(m *testing.M) {
Expand Down

0 comments on commit 7d061dc

Please sign in to comment.