Skip to content
Snippets Groups Projects
Commit b2d0b4d4 authored by Benjamin Bollen's avatar Benjamin Bollen
Browse files

remove from pipe Send, and SendAndHold


Signed-off-by: default avatarBenjamin Bollen <ben@erisindustries.com>
parent 5b490cf6
No related branches found
No related tags found
No related merge requests found
...@@ -212,92 +212,6 @@ func (this *transactor) TransactAndHold(privKey, address, data []byte, gasLimit, ...@@ -212,92 +212,6 @@ func (this *transactor) TransactAndHold(privKey, address, data []byte, gasLimit,
return ret, rErr return ret, rErr
} }
func (this *transactor) Send(privKey, toAddress []byte, amount int64) (*Receipt, error) {
var toAddr []byte
if len(toAddress) == 0 {
toAddr = nil
} else if len(toAddress) != 20 {
return nil, fmt.Errorf("To-address is not of the right length: %d\n", len(toAddress))
} else {
toAddr = toAddress
}
if len(privKey) != 64 {
return nil, fmt.Errorf("Private key is not of the right length: %d\n", len(privKey))
}
pk := &[64]byte{}
copy(pk[:], privKey)
this.txMtx.Lock()
defer this.txMtx.Unlock()
pa := account.GenPrivAccountFromPrivKeyBytes(privKey)
cache := this.mempoolReactor.Mempool.GetCache()
acc := cache.GetAccount(pa.Address)
var sequence int
if acc == nil {
sequence = 1
} else {
sequence = acc.Sequence + 1
}
tx := types.NewSendTx()
txInput := &types.TxInput{
Address: pa.Address,
Amount: amount,
Sequence: sequence,
PubKey: pa.PubKey,
}
tx.Inputs = append(tx.Inputs, txInput)
txOutput := &types.TxOutput{toAddr, amount}
tx.Outputs = append(tx.Outputs, txOutput)
// Got ourselves a tx.
txS, errS := this.SignTx(tx, []*account.PrivAccount{pa})
if errS != nil {
return nil, errS
}
return this.BroadcastTx(txS)
}
func (this *transactor) SendAndHold(privKey, toAddress []byte, amount int64) (*Receipt, error) {
rec, tErr := this.Send(privKey, toAddress, amount)
if tErr != nil {
return nil, tErr
}
wc := make(chan *types.SendTx)
subId := fmt.Sprintf("%X", rec.TxHash)
this.eventEmitter.Subscribe(subId, types.EventStringAccOutput(toAddress), func(evt types.EventData) {
event := evt.(types.EventDataTx)
tx := event.Tx.(*types.SendTx)
wc <- tx
})
timer := time.NewTimer(300 * time.Second)
toChan := timer.C
var rErr error
pa := account.GenPrivAccountFromPrivKeyBytes(privKey)
select {
case <-toChan:
rErr = fmt.Errorf("Transaction timed out. Hash: " + subId)
case e := <-wc:
if bytes.Equal(e.Inputs[0].Address, pa.Address) && e.Inputs[0].Amount == amount {
timer.Stop()
this.eventEmitter.Unsubscribe(subId)
return rec, rErr
}
}
return nil, rErr
}
func (this *transactor) TransactNameReg(privKey []byte, name, data string, amount, fee int64) (*Receipt, error) { func (this *transactor) TransactNameReg(privKey []byte, name, data string, amount, fee int64) (*Receipt, error) {
if len(privKey) != 64 { if len(privKey) != 64 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment