-
Notifications
You must be signed in to change notification settings - Fork 291
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
[rosetta] Mempool Endpoint #3339
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d7b9c3d
[rosetta] Implement mempool endpoint
rhazberries bd9158b
[rosetta] Add Mempool API to the Router
rhazberries 1bd27e4
[rosetta] Update block test file with public function
rhazberries a99d999
[rosetta] Add comments to explain estimated transaction receipt
rhazberries a82aedc
[rosetta] Revert making function public
rhazberries b2688da
[rosetta] Fix hash conversion for looking up transaction in pool
rhazberries 0d8b458
[rosetta] Fix lint
rhazberries e2cacf3
[rosetta] Fix lint (again)
rhazberries 869ab87
[rosetta] Fake logs for CollectReward transaction
rhazberries 09fad49
[rosetta] Fix lint
rhazberries dbca516
[rosetta] Fix lint again...
rhazberries File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package services | ||
|
||
import ( | ||
"context" | ||
"math/big" | ||
|
||
"github.com/coinbase/rosetta-sdk-go/server" | ||
"github.com/coinbase/rosetta-sdk-go/types" | ||
ethCommon "github.com/ethereum/go-ethereum/common" | ||
hmyTypes "github.com/harmony-one/harmony/core/types" | ||
"github.com/harmony-one/harmony/hmy" | ||
"github.com/harmony-one/harmony/rosetta/common" | ||
"github.com/harmony-one/harmony/staking" | ||
) | ||
|
||
// MempoolAPI implements the server.MempoolAPIServicer interface | ||
type MempoolAPI struct { | ||
hmy *hmy.Harmony | ||
} | ||
|
||
// NewMempoolAPI creates a new instance of MempoolAPI | ||
func NewMempoolAPI(hmy *hmy.Harmony) server.MempoolAPIServicer { | ||
return &MempoolAPI{ | ||
hmy: hmy, | ||
} | ||
} | ||
|
||
// Mempool ... | ||
func (s *MempoolAPI) Mempool( | ||
ctx context.Context, req *types.NetworkRequest, | ||
) (*types.MempoolResponse, *types.Error) { | ||
if err := assertValidNetworkIdentifier(req.NetworkIdentifier, s.hmy.ShardID); err != nil { | ||
return nil, err | ||
} | ||
|
||
pool, err := s.hmy.GetPoolTransactions() | ||
if err != nil { | ||
return nil, common.NewError(common.CatchAllError, map[string]interface{}{ | ||
"message": "unable to fetch pool transactions", | ||
}) | ||
} | ||
txIDs := make([]*types.TransactionIdentifier, pool.Len()) | ||
for i, tx := range pool { | ||
txIDs[i] = &types.TransactionIdentifier{ | ||
Hash: tx.Hash().String(), | ||
} | ||
} | ||
return &types.MempoolResponse{ | ||
TransactionIdentifiers: txIDs, | ||
}, nil | ||
} | ||
|
||
// MempoolTransaction ... | ||
func (s *MempoolAPI) MempoolTransaction( | ||
ctx context.Context, req *types.MempoolTransactionRequest, | ||
) (*types.MempoolTransactionResponse, *types.Error) { | ||
if err := assertValidNetworkIdentifier(req.NetworkIdentifier, s.hmy.ShardID); err != nil { | ||
return nil, err | ||
} | ||
|
||
hash := ethCommon.HexToHash(req.TransactionIdentifier.Hash) | ||
poolTx := s.hmy.GetPoolTransaction(hash) | ||
if poolTx == nil { | ||
return nil, &common.TransactionNotFoundError | ||
} | ||
|
||
var nilAddress ethCommon.Address | ||
senderAddr, _ := poolTx.SenderAddress() | ||
estLog := &hmyTypes.Log{ | ||
Address: senderAddr, | ||
Topics: []ethCommon.Hash{staking.CollectRewardsTopic}, | ||
Data: big.NewInt(0).Bytes(), | ||
BlockNumber: s.hmy.CurrentBlock().NumberU64(), | ||
} | ||
|
||
estReceipt := &hmyTypes.Receipt{ | ||
PostState: []byte{}, | ||
Status: hmyTypes.ReceiptStatusSuccessful, // Assume transaction will succeed | ||
CumulativeGasUsed: poolTx.Gas(), | ||
Bloom: [256]byte{}, | ||
Logs: []*hmyTypes.Log{estLog}, | ||
TxHash: poolTx.Hash(), | ||
ContractAddress: nilAddress, // ContractAddress is only for smart contract creation & can not be determined until transaction is finalized | ||
GasUsed: poolTx.Gas(), | ||
} | ||
|
||
respTx, err := formatTransaction(poolTx, estReceipt) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &types.MempoolTransactionResponse{ | ||
Transaction: respTx, | ||
}, nil | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Maybe a good idea to also give the
err
message here.