2015-03-26 21:30:42 -07:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-04-07 11:44:25 -07:00
|
|
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
2015-04-01 17:30:16 -07:00
|
|
|
"github.com/tendermint/tendermint/state"
|
|
|
|
"github.com/tendermint/tendermint/types"
|
2015-03-26 21:30:42 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Note: tx must be signed
|
2015-08-10 20:38:45 -07:00
|
|
|
func BroadcastTx(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
|
2015-03-26 21:30:42 -07:00
|
|
|
err := mempoolReactor.BroadcastTx(tx)
|
|
|
|
if err != nil {
|
2015-03-28 23:10:05 -07:00
|
|
|
return nil, fmt.Errorf("Error broadcasting transaction: %v", err)
|
2015-03-26 21:30:42 -07:00
|
|
|
}
|
|
|
|
|
2015-07-10 05:56:38 +00:00
|
|
|
txHash := types.TxID(mempoolReactor.Mempool.GetState().ChainID, tx)
|
2015-03-28 21:22:39 -07:00
|
|
|
var createsContract uint8
|
2015-03-26 21:30:42 -07:00
|
|
|
var contractAddr []byte
|
|
|
|
// check if creates new contract
|
|
|
|
if callTx, ok := tx.(*types.CallTx); ok {
|
2015-03-31 04:53:34 -07:00
|
|
|
if len(callTx.Address) == 0 {
|
2015-03-28 21:22:39 -07:00
|
|
|
createsContract = 1
|
2015-06-25 20:28:34 -07:00
|
|
|
contractAddr = state.NewContractAddress(callTx.Input.Address, callTx.Input.Sequence)
|
2015-03-26 21:30:42 -07:00
|
|
|
}
|
|
|
|
}
|
2015-08-10 20:38:45 -07:00
|
|
|
return &ctypes.ResultBroadcastTx{ctypes.Receipt{txHash, createsContract, contractAddr}}, nil
|
2015-03-26 21:30:42 -07:00
|
|
|
}
|
|
|
|
|
2015-08-10 20:38:45 -07:00
|
|
|
func ListUnconfirmedTxs() (*ctypes.ResultListUnconfirmedTxs, error) {
|
2015-09-25 12:55:59 -04:00
|
|
|
txs := mempoolReactor.Mempool.GetProposalTxs()
|
|
|
|
return &ctypes.ResultListUnconfirmedTxs{len(txs), txs}, nil
|
2015-04-25 13:26:36 -07:00
|
|
|
}
|