-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat(cosmosutil): add InteractingWallet and a scaffold of the ChainClient #18
feat(cosmosutil): add InteractingWallet and a scaffold of the ChainClient #18
Conversation
Current dependencies on/for this PR:
This stack of pull requests is managed by Graphite. |
e2b2b39
to
5f13b65
Compare
ccf3352
to
8c83841
Compare
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.
Added Coments
8c83841
to
3f371b7
Compare
WalkthroughThe project has integrated a new module named Changes
TipsChat with CodeRabbit Bot (
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... Files ignored due to filter (2)
Files selected for processing (6)
TipsChat with CodeRabbit Bot (
|
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.
Review Status
Actionable comments generated: 5
Configuration used: CodeRabbit UI
Files ignored due to filter (2)
- cosmosutil/go.mod
- cosmosutil/go.sum
Files selected for processing (6)
- .github/workflows/lint.yml (2 hunks)
- cosmosutil/bank.go (1 hunks)
- cosmosutil/client.go (1 hunks)
- cosmosutil/wallet.go (1 hunks)
- types/chain.go (1 hunks)
- util/wait.go (1 hunks)
Files skipped from review due to trivial changes (1)
- .github/workflows/lint.yml
Additional comments: 6
util/wait.go (1)
- 9-13: The addition of a context parameter to
WaitForCondition
is a good practice for timeout management. Ensure that the calling code passes the appropriate context to this function.cosmosutil/client.go (1)
- 9-12: The
ChainClient
struct is well-defined with clear fields. It's important to ensure that theChain
andEncodingConfig
are properly initialized before use.types/chain.go (1)
- 11-15: The new methods added to the
ChainI
interface expand its functionality. Verify that all implementations ofChainI
are updated to include these new methods.cosmosutil/bank.go (2)
12-47: The
Balances
method correctly handles pagination and appends balances. Ensure that thegetBankClient
method is implemented correctly and handles errors as expected.73-117: The methods
DenomMetadata
andDenomsMetadata
are consistent withBalances
in their handling of pagination and errors. This consistency is good for maintainability.cosmosutil/wallet.go (1)
- 25-30: The
InteractingWallet
struct is well-defined. Ensure that thewallet
,chain
, andencodingConfig
are properly initialized and used within the 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.
Review Status
Actionable comments generated: 4
Configuration used: CodeRabbit UI
Files ignored due to filter (2)
- cosmosutil/go.mod
- cosmosutil/go.sum
Files selected for processing (6)
- .github/workflows/lint.yml (2 hunks)
- cosmosutil/bank.go (1 hunks)
- cosmosutil/client.go (1 hunks)
- cosmosutil/wallet.go (1 hunks)
- types/chain.go (1 hunks)
- util/wait.go (1 hunks)
Additional comments: 15
util/wait.go (1)
- 9-13: The addition of
context.Context
as a parameter toWaitForCondition
is a good practice for managing timeouts and cancellations. Ensure that all calls to this function have been updated to pass the appropriate context.cosmosutil/client.go (1)
- 9-12: The
ChainClient
struct is well-defined with clear responsibilities. It's important to ensure that theChain
andEncodingConfig
fields are properly initialized before use..github/workflows/lint.yml (1)
- 18-18: The inclusion of
cosmosutil
in the linting modules list is a necessary update to maintain code quality as the module is developed. This change aligns with the PR objectives.types/chain.go (1)
- 13-15: The new methods
GetGPRCClient
,GetTMClient
, andGetTxConfig
in theChainI
interface are essential for blockchain interaction. Ensure that all implementations ofChainI
are updated to include these new methods.cosmosutil/bank.go (7)
- 12-47: The
Balances
method correctly paginates through all balances. Ensure that the pagination logic is tested thoroughly to handle all edge cases.Verification successful
I will adjust the ast-grep pattern to be more inclusive and try to match the pagination logic within the
Balances
method again.
I will use
rg
(ripgrep) to search for theBalances
method within thebank.go
file to manually inspect the pagination logic.
The output from the
rg
command confirms the presence of a pagination loop within theBalances
method in thebank.go
file. The method retrieves all balances by paginating through the results using anextToken
. If thenextToken
isnil
, the loop breaks, which indicates the end of the pagination. This matches the expected behavior for correctly handling pagination.Based on the provided output, the pagination logic in the
Balances
method appears to be implemented as expected.
- The
for
loop continues to request pages of balances.- The
nextToken
is used to request the next page of results.- The loop breaks when
nextToken
isnil
, indicating there are no more pages to retrieve.* 50-70: The `Balance` method is well-implemented for fetching the balance of a specific denomination. It correctly handles the case where the balance is nil.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the Balances method handles pagination correctly. ast-grep --lang go --pattern $'func (c *ChainClient) Balances($_, $_) $_ { $$$ for { $$$ if $_ == nil { break } $$$ } $$$ }'Length of output: 155
Script:
#!/bin/bash # Verify that the Balances method handles pagination correctly by checking for the presence of a loop and pagination logic. ast-grep --lang go --pattern $'func (c *ChainClient) Balances($_, $_) $_ { $$$ for { $$$ $_, err := $_.AllBalances($_, $_) if err != nil { return nil, err } $$$ if $_.Pagination.GetNextKey() == nil { break } $$$ } $$$ }'Length of output: 273
Script:
#!/bin/bash # Search for the Balances method in the bank.go file to manually inspect the pagination logic. rg "func \(c \*ChainClient\) Balances" -A 30 cosmosutil/bank.goLength of output: 626
73-88: The
DenomMetadata
method properly retrieves metadata for a given denomination. It's important to ensure that error cases are handled correctly in the calling code.91-117: The
DenomsMetadata
method uses pagination to fetch metadata for all denominations. As withBalances
, ensure that the pagination is tested for correctness.Verification successful
The output from the ripgrep command has provided the implementation of the
DenomsMetadata
method from thecosmosutil/bank.go
file. Based on the snippet provided, the method implements a loop that fetches metadata for all denominations using pagination. The pagination logic appears to be handled by checking for anil
value innextToken
, which is obtained fromres.Pagination.GetNextKey()
.Given the information provided, the pagination logic in the
DenomsMetadata
method seems to be implemented as expected. However, since the output is truncated and does not show the complete loop, including the condition that would end the loop, I cannot fully verify the correctness of the pagination logic.To ensure a thorough review, I will need to see the rest of the loop to confirm that the pagination token is being used correctly in subsequent requests and that the loop terminates appropriately.
The extended output from the
rg
command provides the complete loop within theDenomsMetadata
method. The pagination logic is as follows:
- It initializes a
nextToken
variable.- It enters a loop where it calls
bankClient.DenomsMetadata
.- After each call, it appends the results to the
metadatas
slice.- It updates the
nextToken
with the value fromres.Pagination.GetNextKey()
.- If
nextToken
isnil
, it breaks out of the loop.- Finally, it returns the accumulated
metadatas
.This logic appears to correctly handle pagination by continuously fetching metadata until there are no more pages to fetch (indicated by a
nil
nextToken
). The loop will terminate properly once all pages have been retrieved.Based on the provided code and the review comment, the pagination in the
DenomsMetadata
method is implemented correctly, and the method should function as intended when fetching all denominations metadata.* 120-146: The `TotalSupplyAll` method correctly fetches the total supply for all denominations. Ensure that the pagination logic is tested thoroughly.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the DenomsMetadata method handles pagination correctly. ast-grep --lang go --pattern $'func (c *ChainClient) DenomsMetadata($_) $_ { $$$ for { $$$ if $_ == nil { break } $$$ } $$$ }'Length of output: 157
Script:
#!/bin/bash # Adjusting the ast-grep pattern to be more inclusive and to ensure it matches the structure of the DenomsMetadata method. ast-grep --lang go --pattern $'func (c *ChainClient) DenomsMetadata($_) $_ { $$$ for { $$$ } $$$ }'Length of output: 112
Script:
#!/bin/bash # Using ripgrep to search for the DenomsMetadata method in the codebase to confirm its existence and review its implementation. rg 'func \(c \*ChainClient\) DenomsMetadata'Length of output: 155
Script:
#!/bin/bash # Extract the complete implementation of the DenomsMetadata method from the bank.go file for manual review. rg -A 20 'func \(c \*ChainClient\) DenomsMetadata' cosmosutil/bank.goLength of output: 528
Script:
#!/bin/bash # Extract the remaining part of the DenomsMetadata method to review the complete pagination logic. rg -A 10 -B 10 'nextToken = res.Pagination.GetNextKey()' cosmosutil/bank.goLength of output: 1090
Verification successful
The pagination logic in the
TotalSupplyAll
method, as shown in the provided code snippet, appears to be implemented correctly. It uses a loop to fetch pages of total supply data and breaks out of the loop when there are no more pages to fetch, indicated by anil
next token. Since the ast-grep command did not yield results, but the provided code snippet shows the expected behavior, the pagination logic can be considered verified based on the snippet.* 149-164: The `BankTotalSupplySingle` method is implemented correctly to fetch the supply of a single denomination. Ensure that error handling is consistent with the rest of the module.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the TotalSupplyAll method handles pagination correctly. ast-grep --lang go --pattern $'func (c *ChainClient) TotalSupplyAll($_) $_ { $$$ for { $$$ if $_ == nil { break } $$$ } $$$ }'Length of output: 157
Script:
#!/bin/bash # Verify that the TotalSupplyAll method handles pagination correctly by matching the structure of the method. ast-grep --lang go --pattern $'func (c *ChainClient) TotalSupplyAll($_) $_ { $$$ for { $$$ res, err := bankClient.TotalSupply($_, $_) $$$ if $_ == nil { break } $$$ } $$$ }'Length of output: 212
- 169-178: The
BankSend
method appears to correctly create and broadcast a bank send transaction. It's important to ensure that theCreateAndBroadcastTx
method is robust and handles errors as expected.Verification successful
The search with ripgrep has successfully identified the
CreateAndBroadcastTx
method, and it is defined as a method of theInteractingWallet
type, not theChainClient
type as initially assumed. This method is located in thecosmosutil/wallet.go
file.Given this information, the
BankSend
method in theChainClient
type correctly uses theCreateAndBroadcastTx
method from theInteractingWallet
type to create and broadcast a transaction. The error handling withinBankSend
is also appropriate, as it returns the error fromCreateAndBroadcastTx
directly if one occurs.Based on the information gathered:
- The
CreateAndBroadcastTx
method exists and is a member of theInteractingWallet
type.- The
BankSend
method ofChainClient
usesCreateAndBroadcastTx
correctly.- Error handling in
BankSend
is consistent with standard Go practices, where the error is returned to the caller of the method.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the BankSend method correctly uses CreateAndBroadcastTx and handles errors. ast-grep --lang go --pattern $'func (c *ChainClient) BankSend($_, $_, $_, $_, $_) $_ { $$$ CreateAndBroadcastTx($_, $_, $_, $_, $_) $$$ }'Length of output: 145
Script:
#!/bin/bash # Verify the existence and usage of CreateAndBroadcastTx within the ChainClient type. ast-grep --lang go --pattern $'type ChainClient struct { $$$ } func ($_ ChainClient) CreateAndBroadcastTx($_, $_, $_, $_, $_) $_ { $$$ }'Length of output: 674
Script:
#!/bin/bash # Verify the existence of the ChainClient struct. ast-grep --lang go --pattern $'type ChainClient struct { $$$ }' # Verify the existence and implementation of the CreateAndBroadcastTx method for ChainClient. ast-grep --lang go --pattern $'func ($_ ChainClient) CreateAndBroadcastTx($_, $_, $_, $_, $_) $_ { $$$ }'Length of output: 371
Script:
#!/bin/bash # Search for the CreateAndBroadcastTx method in the codebase without specifying the receiver type. ast-grep --lang go --pattern $'func $_ CreateAndBroadcastTx($_, $_, $_, $_, $_) $_ { $$$ }'Length of output: 94
Script:
#!/bin/bash # Use ripgrep to search for the CreateAndBroadcastTx method in the codebase. rg "func .*CreateAndBroadcastTx"Length of output: 212
cosmosutil/wallet.go (4)
25-30: The
InteractingWallet
struct is well-defined. Ensure that thewallet
,chain
, andencodingConfig
fields are properly initialized and used throughout the methods.96-165: The
CreateTx
method constructs a transaction with the provided messages, gas, and fees. Ensure that the signing process is secure and that theSetSignatures
method is called with the correct parameters.Verification successful
The shell script output confirms the presence of the
CreateTx
method within thecosmosutil/wallet.go
file and shows that theSetSignatures
method is called twice within it. The first call sets up a signature with a public key and no signature data, and the second call sets the actual signature after signing the transaction with the private key.Based on this information, it appears that the
CreateTx
method is correctly setting up the transaction and signatures, as it first initializes the transaction with an empty signature to prepare the signer data and then sets the actual signature after signing with the private key.Therefore, the review comment regarding the security of the signing process and the correct use of the
SetSignatures
method seems to have been addressed in the code.* 168-196: The `BroadcastTx` method correctly encodes and broadcasts the transaction. Ensure that the broadcast mode is appropriate for the use case and that error handling is consistent.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the CreateTx method sets up the transaction and signatures correctly. ast-grep --lang go --pattern $'func (w *InteractingWallet) CreateTx($_, $_, $_, $$$) $_ { $$$ SetSignatures($_) $$$ }'Length of output: 125
Script:
#!/bin/bash # Search for the CreateTx method and the usage of SetSignatures within the cosmosutil/wallet.go file. rg "func \(w \*InteractingWallet\) CreateTx" cosmosutil/wallet.go rg "SetSignatures" cosmosutil/wallet.goLength of output: 318
- 199-225: The
Account
method retrieves account information. Ensure that theInterfaceRegistry
is used securely and that the unpacking of the account information is handled correctly.Verification successful
The verification process has successfully identified the
Account
method within theInteractingWallet
type in thecosmosutil/wallet.go
file. The method includes a call tow.encodingConfig.InterfaceRegistry.UnpackAny
, which is used to unpack the account information from the response.Based on the provided output, the
Account
method appears to be implemented correctly with respect to the usage ofInterfaceRegistry.UnpackAny
. The method retrieves the account information from the blockchain and attempts to unpack it into aBaseAccount
type. Proper error handling is also in place, as the method returns an error if the unpacking fails.Given this information, the review comment's request to ensure that the
InterfaceRegistry
is used securely and that the unpacking of the account information is handled correctly has been verified with the available code context.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the Account method correctly unpacks the account information. ast-grep --lang go --pattern $'func (w *InteractingWallet) Account($_) $_ { $$$ InterfaceRegistry.UnpackAny($_, $_) $$$ }'Length of output: 129
Script:
#!/bin/bash # Re-attempt to verify that the Account method correctly unpacks the account information using InterfaceRegistry.UnpackAny. ast-grep --lang go --pattern $'func (w *InteractingWallet) Account($_) $_ { $$$ err := w.encodingConfig.InterfaceRegistry.UnpackAny($_, $_) $$$ }'Length of output: 153
Script:
#!/bin/bash # Attempt to verify the Account method in the InteractingWallet type without specifying the InterfaceRegistry.UnpackAny call. ast-grep --lang go --pattern $'func (w *InteractingWallet) Account($_) $_ { $$$ }'Length of output: 1387
3f371b7
to
072ba62
Compare
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files ignored due to filter (2)
- cosmosutil/go.mod
- cosmosutil/go.sum
Files selected for processing (6)
- .github/workflows/lint.yml (2 hunks)
- cosmosutil/bank.go (1 hunks)
- cosmosutil/client.go (1 hunks)
- cosmosutil/wallet.go (1 hunks)
- types/chain.go (1 hunks)
- util/wait.go (1 hunks)
Files skipped from review as they are similar to previous changes (6)
- .github/workflows/lint.yml
- cosmosutil/bank.go
- cosmosutil/client.go
- cosmosutil/wallet.go
- types/chain.go
- util/wait.go
072ba62
to
cf7e20e
Compare
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files ignored due to filter (2)
- cosmosutil/go.mod
- cosmosutil/go.sum
Files selected for processing (6)
- .github/workflows/lint.yml (2 hunks)
- cosmosutil/bank.go (1 hunks)
- cosmosutil/client.go (1 hunks)
- cosmosutil/wallet.go (1 hunks)
- types/chain.go (1 hunks)
- util/wait.go (1 hunks)
Files skipped from review as they are similar to previous changes (6)
- .github/workflows/lint.yml
- cosmosutil/bank.go
- cosmosutil/client.go
- cosmosutil/wallet.go
- types/chain.go
- util/wait.go
Merge activity
|
Summary by CodeRabbit
New Features
Refactor
Chores