You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.2 KiB

  1. package rpc
  2. import (
  3. "net/http"
  4. "github.com/tendermint/tendermint/binary"
  5. blk "github.com/tendermint/tendermint/block"
  6. . "github.com/tendermint/tendermint/common"
  7. "github.com/tendermint/tendermint/merkle"
  8. "github.com/tendermint/tendermint/state"
  9. )
  10. func BroadcastTxHandler(w http.ResponseWriter, r *http.Request) {
  11. txJSON := GetParam(r, "tx")
  12. var err error
  13. var tx blk.Tx
  14. binary.ReadJSON(&tx, []byte(txJSON), &err)
  15. if err != nil {
  16. WriteAPIResponse(w, API_INVALID_PARAM, Fmt("Invalid tx: %v", err))
  17. return
  18. }
  19. err = mempoolReactor.BroadcastTx(tx)
  20. if err != nil {
  21. WriteAPIResponse(w, API_ERROR, Fmt("Error broadcasting transaction: %v", err))
  22. return
  23. }
  24. txHash := merkle.HashFromBinary(tx)
  25. var createsContract bool
  26. var contractAddr []byte
  27. if callTx, ok := tx.(*blk.CallTx); ok {
  28. if callTx.Address == nil {
  29. createsContract = true
  30. contractAddr = state.NewContractAddress(callTx.Input.Address, uint64(callTx.Input.Sequence))
  31. }
  32. }
  33. WriteAPIResponse(w, API_OK, struct {
  34. TxHash []byte
  35. CreatesContract bool
  36. ContractAddr []byte
  37. }{txHash, createsContract, contractAddr})
  38. return
  39. }
  40. /*
  41. curl -H 'content-type: text/plain;' http://127.0.0.1:8888/submit_tx?tx=...
  42. */