-
Notifications
You must be signed in to change notification settings - Fork 330
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
Change send action #1544
Merged
koseoyoung
merged 9 commits into
iotexproject:master
from
koseoyoung:change_send_action
Oct 15, 2019
Merged
Change send action #1544
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c4f8488
change sendaction to add to local pool directly
koseoyoung c62ae33
refactor
koseoyoung bc06420
fix unit test
koseoyoung 7cd19ae
fix unit test
koseoyoung a8c18f3
Merge branch 'master' into change_send_action
koseoyoung 48f83f9
fixed unit tests
koseoyoung 59f303c
wrap error with status
koseoyoung 313d1d2
Merge branch 'master' into change_send_action
koseoyoung f4698eb
fix unit test
koseoyoung 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,6 @@ import ( | |
"github.com/iotexproject/iotex-core/blockchain/block" | ||
"github.com/iotexproject/iotex-core/config" | ||
"github.com/iotexproject/iotex-core/db" | ||
"github.com/iotexproject/iotex-core/dispatcher" | ||
"github.com/iotexproject/iotex-core/gasstation" | ||
"github.com/iotexproject/iotex-core/pkg/log" | ||
"github.com/iotexproject/iotex-core/pkg/util/byteutil" | ||
|
@@ -88,7 +87,6 @@ func WithNativeElection(committee committee.Committee) Option { | |
// Server provides api for user to query blockchain data | ||
type Server struct { | ||
bc blockchain.Blockchain | ||
dp dispatcher.Dispatcher | ||
ap actpool.ActPool | ||
gs *gasstation.GasStation | ||
broadcastHandler BroadcastOutbound | ||
|
@@ -104,7 +102,6 @@ type Server struct { | |
func NewServer( | ||
cfg config.Config, | ||
chain blockchain.Blockchain, | ||
dispatcher dispatcher.Dispatcher, | ||
actPool actpool.ActPool, | ||
registry *protocol.Registry, | ||
opts ...Option, | ||
|
@@ -127,7 +124,6 @@ func NewServer( | |
|
||
svr := &Server{ | ||
bc: chain, | ||
dp: dispatcher, | ||
ap: actPool, | ||
broadcastHandler: apiCfg.broadcastHandler, | ||
cfg: cfg, | ||
|
@@ -302,22 +298,24 @@ func (api *Server) GetServerMeta(ctx context.Context, | |
} | ||
|
||
// SendAction is the API to send an action to blockchain. | ||
func (api *Server) SendAction(ctx context.Context, in *iotexapi.SendActionRequest) (res *iotexapi.SendActionResponse, err error) { | ||
func (api *Server) SendAction(ctx context.Context, in *iotexapi.SendActionRequest) (*iotexapi.SendActionResponse, error) { | ||
log.L().Debug("receive send action request") | ||
|
||
// broadcast to the network | ||
if err = api.broadcastHandler(context.Background(), api.bc.ChainID(), in.Action); err != nil { | ||
log.L().Warn("Failed to broadcast SendAction request.", zap.Error(err)) | ||
} | ||
// send to actpool via dispatcher | ||
api.dp.HandleBroadcast(context.Background(), api.bc.ChainID(), in.Action) | ||
|
||
var selp action.SealedEnvelope | ||
var err error | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. declarations should never be cuddled (from |
||
if err = selp.LoadProto(in.Action); err != nil { | ||
return | ||
return nil, status.Error(codes.InvalidArgument, err.Error()) | ||
} | ||
// Add to local actpool | ||
if err = api.ap.Add(selp); err != nil { | ||
log.L().Debug(err.Error()) | ||
return nil, status.Error(codes.Internal, err.Error()) | ||
} | ||
// If there is no error putting into local actpool, | ||
// Broadcast it to the network | ||
if err = api.broadcastHandler(context.Background(), api.bc.ChainID(), in.Action); err != nil { | ||
log.L().Warn("Failed to broadcast SendAction request.", zap.Error(err)) | ||
} | ||
hash := selp.Hash() | ||
|
||
return &iotexapi.SendActionResponse{ActionHash: hex.EncodeToString(hash[:])}, nil | ||
} | ||
|
||
|
@@ -411,7 +409,7 @@ func (api *Server) EstimateGasForAction(ctx context.Context, in *iotexapi.Estima | |
return &iotexapi.EstimateGasForActionResponse{Gas: estimateGas}, nil | ||
} | ||
|
||
// EstimateActionGasConsumption estimate gas consume for exectution and transfer | ||
// EstimateActionGasConsumption estimate gas consume for execution and transfer | ||
func (api *Server) EstimateActionGasConsumption(ctx context.Context, in *iotexapi.EstimateActionGasConsumptionRequest) (*iotexapi.EstimateActionGasConsumptionResponse, error) { | ||
switch { | ||
case in.GetExecution() != nil: | ||
|
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
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
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.
line is 122 characters (from
lll
)