Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split interfaces #115

Open
wants to merge 6 commits into
base: 1.0.0
Choose a base branch
from

Conversation

wangdayong228
Copy link
Contributor

@wangdayong228 wangdayong228 commented Oct 11, 2021

split client interface to seperated smaller interface
use rpc namespace name be sub level same with full-node
remove internal contract related codes, it will readd after abi-gen completed


This change is Reviewable

dayong added 2 commits October 11, 2021 18:45
use rpc namespace name be sub level same with full-node
remove internal contract related codes, it will readd after abi-gen completed
Copy link
Member

@Pana Pana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 45 of 45 files at r1, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @boqiu, @wangdayong228, and @wanliqun)

a discussion (no related file):
Consider this is a big upgrade, it's better to provide a document about the difference with the previous version, And how to migrate from previous version .



cfxclient/client.go, line 5 at r1 (raw file):

// See http://www.gnu.org/licenses/

package cfxclient

better name this package as "confluxclient" or "client", cause this client not only include cfx, also trace and pos


cfxclient/client.go, line 41 at r1 (raw file):

}

func (c *Client) Cfx() interfaces.RpcCfxCaller {

Through a method get the client, and then call it's method seems not friendly to developers. Is it possible to make cfx public ?


cfxclient/client_helper.go, line 20 at r1 (raw file):

// =========Helper==========
// NewAddress create conflux address by base32 string or hex40 string, if base32OrHex is base32 and networkID is passed it will create cfx Address use networkID of current c.rpcCaller.

It's better to move NewAddress to common helper or utils

Copy link
Collaborator

@wanliqun wanliqun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Fix typo;
  2. Use clean codes;
  3. Please split this PR as small as possible (too big to review).

@@ -347,8 +318,28 @@ func (m *AccountManager) SignTransactionWithPassphrase(tx types.UnsignedTransact
return signdTx, nil
}

// Sign signs tx by passphrase and returns the signature
func (m *AccountManager) Sign(tx types.UnsignedTransaction, passphrase string) (v byte, r, s []byte, err error) {
// SignTransaction signs tx and returns its RLP encoded data.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment doesn't match function name.

// Sign signs tx by passphrase and returns the signature
func (m *AccountManager) Sign(tx types.UnsignedTransaction, passphrase string) (v byte, r, s []byte, err error) {
// SignTransaction signs tx and returns its RLP encoded data.
func (m *KeystoreWallet) SignTransactionAndEncode(tx types.UnsignedTransaction) ([]byte, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems this function is not necessary, since the rlp encoding can be left to the user with one line code only.

Comment on lines 331 to 332
// SignTransactionWithPassphraseAndEcode signs tx with given passphrase and return its RLP encoded data.
func (m *KeystoreWallet) SignTransactionWithPassphraseAndEcode(tx types.UnsignedTransaction, passphrase string) ([]byte, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

// pos *RpcPosClient
}

// NewClient creates an instance of Client with specified conflux node url, it will creat account manager if option.KeystorePath not empty.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo, creat=>create

RequestTimeout time.Duration
}

// NewClient creates an instance of Client with specified conflux node url, it will creat account manager if option.KeystorePath not empty.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo creat=>create

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NewClientCore?

client.debug = &RpcDebugClient{&core}
client.pubsub = &RpcPubsubClient{&core}
client.trace = &RpcTraceClient{&core}
// client.pos = &RpcPosClient{&core}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add TODO?

Comment on lines 45 to 48
realOption := ClientOption{}
// if len(option) > 0 {
// realOption = option[0]
// }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using functional options (https://golang.cafe/blog/golang-functional-options-pattern.html) to build client?

Comment on lines 45 to 48
realOption := ClientOption{}
// if len(option) > 0 {
// realOption = option[0]
// }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using functional options pattern to build client?
https://golang.cafe/blog/golang-functional-options-pattern.html

Comment on lines 209 to 229
if tmp, ok := args[i].(cfxaddress.Address); ok {
tmp.CompleteByNetworkID(client.networkID)
args[i] = tmp
// fmt.Printf("complete by networkID,%v; after %v\n", client.networkID, args[i])
}

if tmp, ok := args[i].(*cfxaddress.Address); ok {
tmp.CompleteByNetworkID(client.networkID)
// fmt.Printf("complete by networkID,%v; after %v\n", client.networkID, args[i])
}

if tmp, ok := args[i].(types.CallRequest); ok {
tmp.From.CompleteByNetworkID(client.networkID)
tmp.To.CompleteByNetworkID(client.networkID)
args[i] = tmp
}

if tmp, ok := args[i].(*types.CallRequest); ok {
tmp.From.CompleteByNetworkID(client.networkID)
tmp.To.CompleteByNetworkID(client.networkID)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using type switch to make the codes more clean?

params := []interface{}{}
for i := range args {
// fmt.Printf("args %v:%v\n", i, args[i])
if !utils.IsNil(args[i]) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about use the following to skip embedding?
if utils.IsNil() {
continue
}

dayong added 2 commits October 15, 2021 17:22
Rename package cfxclient to client
Simplify setting client option related functions
Set config of ClientCore, Client, SignableClient by chain methods
Copy link
Contributor Author

@wangdayong228 wangdayong228 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 24 of 45 files reviewed, 16 unresolved discussions (waiting on @boqiu, @Pana, and @wanliqun)

a discussion (no related file):

Previously, Pana (W) wrote…

Consider this is a big upgrade, it's better to provide a document about the difference with the previous version, And how to migrate from previous version .

I will document after this version is stable



cfxclient/client.go, line 5 at r1 (raw file):

Previously, Pana (W) wrote…

better name this package as "confluxclient" or "client", cause this client not only include cfx, also trace and pos

Done.


cfxclient/client.go, line 23 at r1 (raw file):

Previously, wanliqun (wanliqun) wrote…

typo, creat=>create

Done.


cfxclient/client.go, line 35 at r1 (raw file):

Previously, wanliqun (wanliqun) wrote…

Add TODO?

Done.


cfxclient/client.go, line 41 at r1 (raw file):

Previously, Pana (W) wrote…

Through a method get the client, and then call it's method seems not friendly to developers. Is it possible to make cfx public ?

Done. Also could directly use client.xxx to call cfx namespace related rpcs


cfxclient/client.go, line 48 at r1 (raw file):

Previously, wanliqun (wanliqun) wrote…

Add TODO?

Done.


cfxclient/client_core.go, line 20 at r1 (raw file):

Previously, wanliqun (wanliqun) wrote…

ClientCore?

Done.


cfxclient/client_core.go, line 43 at r1 (raw file):

Previously, wanliqun (wanliqun) wrote…

NewClientCore?

Done.


cfxclient/client_core.go, line 48 at r1 (raw file):

Previously, wanliqun (wanliqun) wrote…

How about using functional options pattern to build client?
https://golang.cafe/blog/golang-functional-options-pattern.html

Functional options is good, but here becuase there are Client and SignableClient inherited ClientCore, it is not very applicative. Here used chain methods to set options


cfxclient/client_core.go, line 58 at r1 (raw file):

Previously, wanliqun (wanliqun) wrote…

Comment function name does not match real func name

Done.


cfxclient/client_core.go, line 206 at r1 (raw file):

Previously, wanliqun (wanliqun) wrote…

How about use the following to skip embedding?
if utils.IsNil() {
continue
}

Done.


cfxclient/client_core.go, line 229 at r1 (raw file):

Previously, wanliqun (wanliqun) wrote…

How about using type switch to make the codes more clean?

Done.


cfxclient/client_helper.go, line 20 at r1 (raw file):

Previously, Pana (W) wrote…

It's better to move NewAddress to common helper or utils

Done.


accounts/account.go, line 321 at r1 (raw file):

Previously, wanliqun (wanliqun) wrote…

Comment doesn't match function name.

Done.


accounts/account.go, line 322 at r1 (raw file):

Previously, wanliqun (wanliqun) wrote…

Seems this function is not necessary, since the rlp encoding can be left to the user with one line code only.

Done.


accounts/account.go, line 332 at r1 (raw file):

Previously, wanliqun (wanliqun) wrote…

ditto

Done.

Copy link
Member

@Pana Pana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 21 files at r2, all commit messages.
Reviewable status: 25 of 45 files reviewed, 12 unresolved discussions (waiting on @boqiu, @Pana, and @wanliqun)

Copy link
Collaborator

@wanliqun wanliqun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 20 of 21 files at r2, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @boqiu and @wangdayong228)


cfxclient/rpc_batch.go, line 54 at r2 (raw file):

 reflect.DeepEqual(be.Result, &types.BlockSummary{}

Should be reflect.DeepEqual(be.Result, &types.Transaction{})? Better do some testing here.


cfxclient/signalbe_client.go, line 27 at r2 (raw file):

//FixMe: Is there better name
func NewSignalbeClientByPath(nodeURL string, keyStorePath string) (SignableClient, error) {

NewSignableClientByPath?

Copy link
Contributor Author

@wangdayong228 wangdayong228 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 42 of 45 files reviewed, 2 unresolved discussions (waiting on @boqiu and @wanliqun)


cfxclient/signalbe_client.go, line 27 at r2 (raw file):

Previously, wanliqun (wanliqun) wrote…

NewSignableClientByPath?

Done.


cfxclient/rpc_batch.go, line 54 at r2 (raw file):

Previously, wanliqun (wanliqun) wrote…
 reflect.DeepEqual(be.Result, &types.BlockSummary{}

Should be reflect.DeepEqual(be.Result, &types.Transaction{})? Better do some testing here.

Removed batch functions and will be replaced by the bulk caller

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants