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.

36 lines
1.0 KiB

  1. package core
  2. import (
  3. "fmt"
  4. . "github.com/tendermint/tendermint/common"
  5. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  6. "github.com/tendermint/tendermint/state"
  7. "github.com/tendermint/tendermint/types"
  8. )
  9. //-----------------------------------------------------------------------------
  10. // pass pointer?
  11. // Note: tx must be signed
  12. func BroadcastTx(tx types.Tx) (*ctypes.ResponseBroadcastTx, error) {
  13. err := mempoolReactor.BroadcastTx(tx)
  14. if err != nil {
  15. return nil, fmt.Errorf("Error broadcasting transaction: %v", err)
  16. }
  17. txHash := types.TxId(tx)
  18. var createsContract uint8
  19. var contractAddr []byte
  20. // check if creates new contract
  21. if callTx, ok := tx.(*types.CallTx); ok {
  22. if len(callTx.Address) == 0 {
  23. createsContract = 1
  24. contractAddr = state.NewContractAddress(callTx.Input.Address, uint64(callTx.Input.Sequence))
  25. }
  26. }
  27. return &ctypes.ResponseBroadcastTx{ctypes.Receipt{txHash, createsContract, contractAddr}}, nil
  28. }
  29. /*
  30. curl -H 'content-type: text/plain;' http://127.0.0.1:8888/submit_tx?tx=...
  31. */