OSDN Git Service

Change spv wallet send tx
authorYahtoo Ma <yahtoo.ma@gmail.com>
Fri, 24 Aug 2018 06:42:47 +0000 (14:42 +0800)
committerYahtoo Ma <yahtoo.ma@gmail.com>
Fri, 24 Aug 2018 06:42:47 +0000 (14:42 +0800)
api/transact.go
blockchain/txbuilder/finalize.go

index 338a15c..c662606 100644 (file)
@@ -140,7 +140,8 @@ type submitTxResp struct {
 func (a *API) submit(ctx context.Context, ins struct {
        Tx types.Tx `json:"raw_transaction"`
 }) Response {
-       if err := txbuilder.FinalizeTx(ctx, a.chain, &ins.Tx); err != nil {
+       txCh := a.sync.GetNewTxCh()
+       if err := txbuilder.FinalizeTx(ctx, txCh, &ins.Tx); err != nil {
                return NewErrorResponse(err)
        }
 
index 83ce4c7..3340dbc 100644 (file)
@@ -5,7 +5,6 @@ import (
        "context"
 
        "github.com/bytom/errors"
-       "github.com/bytom/protocol"
        "github.com/bytom/protocol/bc/types"
        "github.com/bytom/protocol/vm"
 )
@@ -22,7 +21,7 @@ var (
 // FinalizeTx validates a transaction signature template,
 // assembles a fully signed tx, and stores the effects of
 // its changes on the UTXO set.
-func FinalizeTx(ctx context.Context, c *protocol.Chain, tx *types.Tx) error {
+func FinalizeTx(ctx context.Context, txCh chan *types.Tx,tx *types.Tx) error {
        if err := checkTxSighashCommitment(tx); err != nil {
                return err
        }
@@ -35,13 +34,7 @@ func FinalizeTx(ctx context.Context, c *protocol.Chain, tx *types.Tx) error {
        tx.TxData.SerializedSize = uint64(len(data))
        tx.Tx.SerializedSize = uint64(len(data))
 
-       _, err = c.ValidateTx(tx)
-       if errors.Root(err) == protocol.ErrBadTx {
-               return errors.Sub(ErrRejected, err)
-       }
-       if err != nil {
-               return errors.WithDetail(err, "tx rejected: "+err.Error())
-       }
+       txCh <- tx
 
        return errors.Wrap(err)
 }