Merge pull request #49 from WeMeetAgain/develop

add pushtx to api
pull/150/head
Jeffrey Wilcke 10 years ago
commit 369e8c4150
  1. 6
      ethpipe/js_pipe.go
  2. 9
      ethpipe/pipe.go
  3. 21
      ethrpc/packages.go

@ -225,6 +225,12 @@ func (self *JSPipe) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr
return NewJSReciept(contractCreation, tx.CreationAddress(), tx.Hash(), keyPair.Address()), nil return NewJSReciept(contractCreation, tx.CreationAddress(), tx.Hash(), keyPair.Address()), nil
} }
func (self *JSPipe) PushTx(txStr string) (*JSReceipt, error) {
tx := ethchain.NewTransactionFromBytes(ethutil.Hex2Bytes(txStr))
self.obj.TxPool().QueueTransaction(tx)
return NewJSReciept(tx.CreatesContract(), tx.CreationAddress(), tx.Hash(), tx.Sender()), nil
}
func (self *JSPipe) CompileMutan(code string) string { func (self *JSPipe) CompileMutan(code string) string {
data, err := self.Pipe.CompileMutan(code) data, err := self.Pipe.CompileMutan(code)
if err != nil { if err != nil {

@ -149,6 +149,15 @@ func (self *Pipe) Transact(key *ethcrypto.KeyPair, rec []byte, value, gas, price
return tx.Hash(), nil return tx.Hash(), nil
} }
func (self *Pipe) PushTx(tx *ethchain.Transaction) ([]byte, error) {
self.obj.TxPool().QueueTransaction(tx)
if tx.Recipient == nil {
logger.Infof("Contract addr %x", tx.CreationAddress())
return tx.CreationAddress(), nil
}
return tx.Hash(), nil
}
func (self *Pipe) CompileMutan(code string) ([]byte, error) { func (self *Pipe) CompileMutan(code string) ([]byte, error) {
data, err := ethutil.Compile(code, false) data, err := ethutil.Compile(code, false)
if err != nil { if err != nil {

@ -145,6 +145,27 @@ func (p *EthereumApi) Create(args *NewTxArgs, reply *string) error {
return nil return nil
} }
type PushTxArgs struct {
Tx string
}
func (a *PushTxArgs) requirementsPushTx() error {
if a.Tx == "" {
return NewErrorResponse("PushTx requires a 'tx' as argument")
}
return nil
}
func (p *EthereumApi) PushTx(args *PushTxArgs, reply *string) error {
err := args.requirementsPushTx()
if err != nil {
return err
}
result, _ := p.pipe.PushTx(args.Tx)
*reply = NewSuccessRes(result)
return nil
}
func (p *EthereumApi) GetKey(args interface{}, reply *string) error { func (p *EthereumApi) GetKey(args interface{}, reply *string) error {
*reply = NewSuccessRes(p.pipe.Key()) *reply = NewSuccessRes(p.pipe.Key())
return nil return nil

Loading…
Cancel
Save