-
Notifications
You must be signed in to change notification settings - Fork 28
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
base: 1.0.0
Are you sure you want to change the base?
Split interfaces #115
Conversation
use rpc namespace name be sub level same with full-node remove internal contract related codes, it will readd after abi-gen completed
There was a problem hiding this 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Fix typo;
- Use clean codes;
- Please split this PR as small as possible (too big to review).
accounts/account.go
Outdated
@@ -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. |
There was a problem hiding this comment.
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.
accounts/account.go
Outdated
// 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) { |
There was a problem hiding this comment.
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.
accounts/account.go
Outdated
// SignTransactionWithPassphraseAndEcode signs tx with given passphrase and return its RLP encoded data. | ||
func (m *KeystoreWallet) SignTransactionWithPassphraseAndEcode(tx types.UnsignedTransaction, passphrase string) ([]byte, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
cfxclient/client.go
Outdated
// pos *RpcPosClient | ||
} | ||
|
||
// NewClient creates an instance of Client with specified conflux node url, it will creat account manager if option.KeystorePath not empty. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo, creat=>create
cfxclient/client_core.go
Outdated
RequestTimeout time.Duration | ||
} | ||
|
||
// NewClient creates an instance of Client with specified conflux node url, it will creat account manager if option.KeystorePath not empty. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo creat=>create
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add TODO?
cfxclient/client_core.go
Outdated
realOption := ClientOption{} | ||
// if len(option) > 0 { | ||
// realOption = option[0] | ||
// } |
There was a problem hiding this comment.
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?
cfxclient/client_core.go
Outdated
realOption := ClientOption{} | ||
// if len(option) > 0 { | ||
// realOption = option[0] | ||
// } |
There was a problem hiding this comment.
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
cfxclient/client_core.go
Outdated
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) | ||
} |
There was a problem hiding this comment.
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?
cfxclient/client_core.go
Outdated
params := []interface{}{} | ||
for i := range args { | ||
// fmt.Printf("args %v:%v\n", i, args[i]) | ||
if !utils.IsNil(args[i]) { |
There was a problem hiding this comment.
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
}
Rename package cfxclient to client Simplify setting client option related functions Set config of ClientCore, Client, SignableClient by chain methods
There was a problem hiding this 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.
There was a problem hiding this 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)
There was a problem hiding this 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?
There was a problem hiding this 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
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