-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Export get diff accounts in block api #431
Conversation
core/blockchain.go
Outdated
accounts = append(accounts, diffAccounts.Account) | ||
} | ||
|
||
if header.TxHash != types.EmptyRootHash && (accounts == nil || len(accounts) == 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.
accounts == nil || len(accounts) ==0
==> len(accounts)==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.
done
ethclient/ethclient.go
Outdated
} | ||
|
||
// GetDiffAccountsInBlock returns detailed changes of some interested accounts in a specific block number. | ||
func (ec *Client) GetDiffAccountsInBlock(ctx context.Context, number *big.Int, accounts []common.Address) (*types.DiffAccountsInBlock, 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.
It is confusing between GetDiffAccounts
and GetDiffAccountsInBlock
.
I will suggest change GetDiffAccountsInBlock
==> GetDiffAccountsWithScope
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.
good idea, done
internal/ethapi/api.go
Outdated
@@ -25,6 +25,8 @@ import ( | |||
"strings" | |||
"time" | |||
|
|||
"github.com/ethereum/go-ethereum/consensus" |
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.
format the import order
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.
done
internal/ethapi/api.go
Outdated
} | ||
|
||
// GetDiffAccountsInBlock returns detailed changes of some interested accounts in a specific block number. | ||
func (s *PublicBlockChainAPI) GetDiffAccountsInBlock(ctx context.Context, blockNr rpc.BlockNumber, accounts []common.Address) (*types.DiffAccountsInBlock, 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.
change the nameGetDiffAccountsInBlock
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.
done
|
||
if !skip { | ||
// Compute account balance diff. | ||
for _, account := range accounts { |
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.
If the account balance diff is zero, please do not record it in the map.
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.
done
Signed-off-by: Keefe-Liu <bianze.kernel@gmail.com>
ethclient/ethclient_test.go
Outdated
@@ -25,6 +25,9 @@ import ( | |||
"testing" | |||
"time" | |||
|
|||
"github.com/ethereum/go-ethereum/core/vm" | |||
"github.com/ethereum/go-ethereum/ethdb/memorydb" | |||
|
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 imports
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.
done
// Compute account balance diff. | ||
for _, account := range accounts { | ||
diffTx.Accounts[account] = new(big.Int).Sub(statedb.GetBalance(account), diffTx.Accounts[account]) | ||
if diffTx.Accounts[account].Cmp(big.NewInt(0)) == 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.
why not if equal to 0, then not record?
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.
sorry, I don't get your point, do you mean convert bigInt into int then compare with 0 directly?
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.
Sorry, just ignore.
Signed-off-by: Keefe-Liu <bianze.kernel@gmail.com>
Description
Export GetDiffAccounts and GetDiffAccountsWithScope, GetDiffAccounts can get all diff accounts in a block, GetDiffAccountsWithScope can pass the interested accounts and return their diff value in a block.
Rationale
To get diff accounts in a block easily.
Example
Changes
Preflight checks
Already reviewed by
...
Related issues
... reference related issue #'s here ...