Commit ec41feb6 authored by Luke Champine's avatar Luke Champine

AddOutput returns index

parent 515d7fb5
......@@ -37,8 +37,9 @@ type Wallet interface {
// AddMinerFee adds a single miner fee of value `fee`.
AddMinerFee(id string, fee consensus.Currency) error
// AddOutput adds an output to a transaction.
AddOutput(id string, output consensus.Output) error
// AddOutput adds an output to a transaction. It returns the index of the
// output in the transaction.
AddOutput(id string, output consensus.Output) (uint64, error)
// AddFileContract adds a file contract to a transaction.
AddFileContract(id string, fc consensus.FileContract) error
......
......@@ -99,17 +99,20 @@ func (w *Wallet) AddMinerFee(id string, fee consensus.Currency) error {
}
// AddOutput adds an output to the transaction, but will not add any inputs.
func (w *Wallet) AddOutput(id string, output consensus.Output) error {
// It returns the index of the output in the transaction.
func (w *Wallet) AddOutput(id string, output consensus.Output) (index uint64, err error) {
w.mu.Lock()
defer w.mu.Unlock()
openTxn, exists := w.transactions[id]
if !exists {
return errors.New("no transaction found for given id")
err = errors.New("no transaction found for given id")
return
}
openTxn.transaction.Outputs = append(openTxn.transaction.Outputs, output)
return nil
index = uint64(len(openTxn.transaction.Outputs) - 1)
return
}
// AddFileContract implements the core.Wallet interface.
......
......@@ -106,7 +106,7 @@ func (w *Wallet) SpendCoins(amount consensus.Currency, dest consensus.CoinAddres
if err != nil {
return
}
err = w.AddOutput(id, output)
_, err = w.AddOutput(id, output)
if err != nil {
return
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment