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.

35 lines
990 B

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