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
1.1 KiB

  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. // Note: tx must be signed
  10. func BroadcastTx(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
  11. err := mempoolReactor.BroadcastTx(tx)
  12. if err != nil {
  13. return nil, fmt.Errorf("Error broadcasting transaction: %v", err)
  14. }
  15. txHash := types.TxID(mempoolReactor.Mempool.GetState().ChainID, tx)
  16. var createsContract uint8
  17. var contractAddr []byte
  18. // check if creates new contract
  19. if callTx, ok := tx.(*types.CallTx); ok {
  20. if len(callTx.Address) == 0 {
  21. createsContract = 1
  22. contractAddr = state.NewContractAddress(callTx.Input.Address, callTx.Input.Sequence)
  23. }
  24. }
  25. return &ctypes.ResultBroadcastTx{ctypes.Receipt{txHash, createsContract, contractAddr}}, nil
  26. }
  27. func ListUnconfirmedTxs() (*ctypes.ResultListUnconfirmedTxs, error) {
  28. txs := mempoolReactor.Mempool.GetProposalTxs()
  29. return &ctypes.ResultListUnconfirmedTxs{len(txs), txs}, nil
  30. }