2015-03-26 21:30:42 -07:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-04-01 17:30:16 -07:00
|
|
|
. "github.com/tendermint/tendermint/common"
|
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
|
|
|
)
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// pass pointer?
|
|
|
|
// Note: tx must be signed
|
2015-04-07 11:44:25 -07:00
|
|
|
func BroadcastTx(tx types.Tx) (*ctypes.ResponseBroadcastTx, 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-03-29 18:43:27 -07:00
|
|
|
txHash := types.TxId(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-03-26 21:30:42 -07:00
|
|
|
contractAddr = state.NewContractAddress(callTx.Input.Address, uint64(callTx.Input.Sequence))
|
|
|
|
}
|
|
|
|
}
|
2015-04-07 11:44:25 -07:00
|
|
|
return &ctypes.ResponseBroadcastTx{ctypes.Receipt{txHash, createsContract, contractAddr}}, nil
|
2015-03-26 21:30:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
curl -H 'content-type: text/plain;' http://127.0.0.1:8888/submit_tx?tx=...
|
|
|
|
*/
|