Fixed up business logic in build/send

This commit is contained in:
Ethan Frey 2017-07-29 09:28:45 -04:00
parent d4ab79ece0
commit de82c03804
2 changed files with 13 additions and 19 deletions

View File

@ -196,8 +196,8 @@ func doSend(w http.ResponseWriter, r *http.Request) {
if si.To == nil { if si.To == nil {
errsList = append(errsList, `"to" cannot be nil`) errsList = append(errsList, `"to" cannot be nil`)
} }
if si.Fees == nil { if len(si.Amount) == 0 {
errsList = append(errsList, `"fees" cannot be nil`) errsList = append(errsList, `"amount" cannot be empty`)
} }
if len(errsList) > 0 { if len(errsList) > 0 {
err := &ErrorResponse{ err := &ErrorResponse{
@ -208,21 +208,13 @@ func doSend(w http.ResponseWriter, r *http.Request) {
return return
} }
coins := []coin.Coin{*si.Fees} tx := coin.NewSendOneTx(*si.From, *si.To, si.Amount)
in := []coin.TxInput{ // fees are optional
coin.NewTxInput(*si.From, coins), if si.Fees != nil && !si.Fees.IsZero() {
}
out := []coin.TxOutput{
coin.NewTxOutput(*si.To, coins),
}
tx := coin.NewSendTx(in, out)
tx = fee.NewFee(tx, *si.Fees, *si.From) tx = fee.NewFee(tx, *si.Fees, *si.From)
signers := []basecoin.Actor{
*si.From,
*si.To,
} }
// only add the actual signer to the nonce
signers := []basecoin.Actor{*si.From}
tx = nonce.NewTx(si.Sequence, signers, tx) tx = nonce.NewTx(si.Sequence, signers, tx)
tx = base.NewChainTx(commands.GetChainID(), 0, tx) tx = base.NewChainTx(commands.GetChainID(), 0, tx)
@ -231,4 +223,5 @@ func doSend(w http.ResponseWriter, r *http.Request) {
} else { } else {
tx = auth.NewSig(tx).Wrap() tx = auth.NewSig(tx).Wrap()
} }
writeSuccess(w, tx)
} }

View File

@ -60,12 +60,13 @@ type CreateKeyResponse struct {
// many fields so it would be nice to figure out all the invalid // many fields so it would be nice to figure out all the invalid
// inputs and report them back to the caller, in one shot. // inputs and report them back to the caller, in one shot.
type SendInput struct { type SendInput struct {
Fees *coin.Coin `json:"amount"` Fees *coin.Coin `json:"fees"`
Multi bool `json:"multi,omitempty"` Multi bool `json:"multi,omitempty"`
Sequence uint32 `json:"sequence"` Sequence uint32 `json:"sequence"`
To *basecoin.Actor `json:"to"` To *basecoin.Actor `json:"to"`
From *basecoin.Actor `json:"from"` From *basecoin.Actor `json:"from"`
Amount coin.Coins `json:"amount"`
} }
// Validators // Validators