log.WithFields(log.Fields{"module": logModule, "err": err}).Error("wallet fail on saveUnconfirmedTx")
}
- utxos := txOutToUtxos(txD.Tx, txD.StatusFail, 0, 0)
+ utxos := txOutToUtxos(txD.Tx, txD.StatusFail, 0)
utxos = w.filterAccountUtxo(utxos)
w.AccountMgr.AddUnconfirmedUtxo(utxos)
}
}
//hand update the transaction output utxos
- validHeight := uint64(0)
- if txIndex == 0 {
- validHeight = b.Height + consensus.CoinbasePendingBlockNumber
- }
- outputUtxos := txOutToUtxos(tx, statusFail, validHeight, b.Height)
+ outputUtxos := txOutToUtxos(tx, statusFail, b.Height)
utxos := w.filterAccountUtxo(outputUtxos)
if err := batchSaveUtxos(utxos, batch); err != nil {
log.WithFields(log.Fields{"module": logModule, "err": err}).Error("attachUtxos fail on batchSaveUtxos")
return utxos
}
-func txOutToUtxos(tx *types.Tx, statusFail bool, vaildHeight, blockHeight uint64) []*account.UTXO {
+func txOutToUtxos(tx *types.Tx, statusFail bool, blockHeight uint64) []*account.UTXO {
+ validHeight := uint64(0)
+ if tx.Inputs[0].InputType() == types.CoinbaseInputType {
+ validHeight = blockHeight + consensus.CoinbasePendingBlockNumber
+ }
+
utxos := []*account.UTXO{}
for i, out := range tx.Outputs {
entryOutput, err := tx.Entry(*tx.ResultIds[i])
ControlProgram: out.ControlProgram(),
SourceID: *bcOut.Source.Ref,
SourcePos: bcOut.Source.Position,
- ValidHeight: vaildHeight,
+ ValidHeight: validHeight,
}
case *bc.VoteOutput:
}
voteValidHeight := blockHeight + consensus.VotePendingBlockNumber
- if vaildHeight < voteValidHeight {
- vaildHeight = voteValidHeight
+ if validHeight < voteValidHeight {
+ validHeight = voteValidHeight
}
utxo = &account.UTXO{
ControlProgram: out.ControlProgram(),
SourceID: *bcOut.Source.Ref,
SourcePos: bcOut.Source.Position,
- ValidHeight: vaildHeight,
+ ValidHeight: validHeight,
Vote: bcOut.Vote,
}
cases := []struct {
tx *types.Tx
statusFail bool
- vaildHeight uint64
+ blockHeight uint64
wantUtxos []*account.UTXO
}{
{
},
}),
statusFail: false,
- vaildHeight: 98,
+ blockHeight: 98,
wantUtxos: []*account.UTXO{
&account.UTXO{
OutputID: bc.Hash{V0: 1728735075694344097, V1: 884766857607786922, V2: 12293210594955921685, V3: 11109045974561998790},
ControlProgram: []byte{0x51},
SourceID: bc.NewHash([32]byte{0xb4, 0x7e, 0x94, 0x31, 0x88, 0xfe, 0xd3, 0xe9, 0xac, 0x99, 0x7c, 0xfc, 0x99, 0x6d, 0xd7, 0x4d, 0x04, 0x10, 0x77, 0xcb, 0x1c, 0xf8, 0x95, 0x14, 0x00, 0xe3, 0x42, 0x00, 0x8d, 0x05, 0xec, 0xdc}),
SourcePos: 0,
- ValidHeight: 98,
+ ValidHeight: 198,
},
},
},
},
}),
statusFail: false,
- vaildHeight: 0,
+ blockHeight: 0,
wantUtxos: []*account.UTXO{
&account.UTXO{
OutputID: bc.Hash{V0: 8675398163687045889, V1: 7549510466747714094, V2: 13693077838209211470, V3: 6878568403630757599},
},
}),
statusFail: true,
- vaildHeight: 0,
+ blockHeight: 0,
wantUtxos: []*account.UTXO{
&account.UTXO{
OutputID: bc.Hash{V0: 7067560744282869147, V1: 8991714784298240423, V2: 2595857933262917893, V3: 11490631006811252506},
},
}),
statusFail: false,
- vaildHeight: 0,
+ blockHeight: 0,
wantUtxos: []*account.UTXO{
&account.UTXO{
OutputID: bc.Hash{V0: 8675398163687045889, V1: 7549510466747714094, V2: 13693077838209211470, V3: 6878568403630757599},
},
}),
statusFail: false,
- vaildHeight: 0,
+ blockHeight: 0,
wantUtxos: []*account.UTXO{
&account.UTXO{
OutputID: bc.Hash{V0: 396952592194652166, V1: 9806684391645699244, V2: 484243382648745315, V3: 16988093808435014689},
}
for i, c := range cases {
- if gotUtxos := txOutToUtxos(c.tx, c.statusFail, c.vaildHeight, 0); !testutil.DeepEqual(gotUtxos, c.wantUtxos) {
+ if gotUtxos := txOutToUtxos(c.tx, c.statusFail, c.blockHeight); !testutil.DeepEqual(gotUtxos, c.wantUtxos) {
t.Errorf("case %d: got %v want %v", i, gotUtxos, c.wantUtxos)
for j, u := range gotUtxos {