Rearrange method to remove unneeded goroutine (since we are already in

a goroutine at this point)
This commit is contained in:
Peter Fox 2018-09-20 13:26:12 +01:00
parent 93793cff0b
commit 237bdbace5
1 changed files with 32 additions and 26 deletions

View File

@ -1453,24 +1453,36 @@ type AsyncSendTxArgs struct {
CallbackUrl string `json:"callbackUrl"`
}
type AsyncResult struct {
TxHash common.Hash `json:"txHash,omitempty"`
Error string `json:"error,omitempty"`
type AsyncResultSuccess struct {
Id string `json:"id,omitempty"`
TxHash common.Hash `json:"txHash"`
}
type AsyncResultFailure struct {
Id string `json:"id,omitempty"`
Error string `json:"error"`
}
func (s *PublicTransactionPoolAPI) send(ctx context.Context, asyncArgs AsyncSendTxArgs) {
res := new(AsyncResult)
txHash, err := s.SendTransaction(ctx, asyncArgs.SendTxArgs)
if asyncArgs.CallbackUrl != "" {
//don't need to nil check this since id is required for every geth rpc call
//even though this is stated in the specification as an "optional" parameter
id := ctx.Value("id").(*json.RawMessage)
res.Id = string(*id)
jsonId := ctx.Value("id").(*json.RawMessage)
id := string(*jsonId)
var resultResponse interface{}
if err != nil {
resultResponse = &AsyncResultFailure{Id: id, Error: err.Error()}
} else {
resultResponse = &AsyncResultSuccess{Id: id, TxHash: txHash}
}
if asyncArgs.CallbackUrl != "" {
defer func() {
buf := new(bytes.Buffer)
err := json.NewEncoder(buf).Encode(res)
err := json.NewEncoder(buf).Encode(resultResponse)
if err != nil {
log.Info("Error encoding callback JSON: %v", err)
return
@ -1480,14 +1492,8 @@ func (s *PublicTransactionPoolAPI) send(ctx context.Context, asyncArgs AsyncSend
log.Info("Error sending callback: %v", err)
return
}
}()
}
var err error
res.TxHash, err = s.SendTransaction(ctx, asyncArgs.SendTxArgs)
if err != nil {
res.Error = err.Error()
}
}