tx.Inputs = append(tx.Inputs, in)
}
- txSerialized, err := tx.MarshalText()
- if err != nil {
- return nil, nil, err
- }
-
- tx.SerializedSize = uint64(len(txSerialized))
tpl.Transaction = types.NewTx(*tx)
return tpl, tx, nil
}
// 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 {
- err := checkTxSighashCommitment(tx)
- if err != nil {
+ if err := checkTxSighashCommitment(tx); err != nil {
return err
}
- _, err = c.ValidateTx(tx)
+ // This paret is use for prevent tx size is 0
+ if tx.SerializedSize == 0 {
+ data, err := tx.TxData.MarshalText()
+ if err != nil {
+ return err
+ }
+ if err := tx.UnmarshalText(data); err != nil {
+ return err
+ }
+ }
+
+ _, err := c.ValidateTx(tx)
if errors.Root(err) == protocol.ErrBadTx {
return errors.Sub(ErrRejected, err)
}
want := &Template{
Transaction: types.NewTx(types.TxData{
- Version: 1,
- SerializedSize: 330,
+ Version: 1,
Inputs: []*types.TxInput{
types.NewSpendInput(nil, bc.NewHash([32]byte{0xff}), assetID1, 5, 0, nil),
},
t.Fatal(err)
}
+ tx.SerializedSize = 1
if _, err = validation.ValidateTx(types.MapTx(tx), test.MockBlock()); err != nil {
t.Fatal(err)
}
t.Fatal(err)
}
+ tx.SerializedSize = 1
if _, err = validation.ValidateTx(types.MapTx(tx), test.MockBlock()); err != nil {
t.Fatal(err)
}
t.Fatal("sign progress is not finish, but both xpub1 and xpub2 is signed")
}
+ tx.SerializedSize = 1
if _, err = validation.ValidateTx(types.MapTx(tx), test.MockBlock()); err != nil {
t.Fatal(err)
}