Skip to content

Commit

Permalink
wallet: Fix ephemeral output handling
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechampine committed Aug 8, 2024
1 parent fc72ec0 commit c13491e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
22 changes: 5 additions & 17 deletions wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,12 @@ func (sw *SingleAddressWallet) Balance() (balance Balance, err error) {
tpoolSpent[types.Hash256(si.Parent.ID)] = true
delete(tpoolUtxos, types.Hash256(si.Parent.ID))
}
txnID := txn.ID()
for i, sco := range txn.SiacoinOutputs {
if sco.Address != sw.addr {
continue
}

outputID := txn.SiacoinOutputID(txnID, i)
tpoolUtxos[types.Hash256(outputID)] = types.SiacoinElement{
StateElement: types.StateElement{
ID: types.Hash256(types.SiacoinOutputID(outputID)),
},
SiacoinOutput: sco,
}
sce := txn.EphemeralSiacoinOutput(i)
tpoolUtxos[sce.ID] = sce
}
}

Expand Down Expand Up @@ -252,14 +245,9 @@ func (sw *SingleAddressWallet) selectUTXOs(amount types.Currency, inputs int, us
tpoolSpent[types.Hash256(sci.Parent.ID)] = true
delete(tpoolUtxos, types.Hash256(sci.Parent.ID))
}
txnID := txn.ID()
for i, sco := range txn.SiacoinOutputs {
tpoolUtxos[types.Hash256(txn.SiacoinOutputID(txnID, i))] = types.SiacoinElement{
StateElement: types.StateElement{
ID: types.Hash256(types.SiacoinOutputID(txn.SiacoinOutputID(txnID, i))),
},
SiacoinOutput: sco,
}
for i := range txn.SiacoinOutputs {
sce := txn.EphemeralSiacoinOutput(i)
tpoolUtxos[sce.ID] = sce
}
}

Expand Down
9 changes: 4 additions & 5 deletions wallet/wallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,6 @@ func TestFundTransaction(t *testing.T) {
t.Fatal(err)
}
sendAmt := balance.Confirmed
fmt.Println("sendAmt", sendAmt)

txnV2 := types.V2Transaction{
SiacoinOutputs: []types.SiacoinOutput{
Expand Down Expand Up @@ -1392,20 +1391,20 @@ func TestFundTransaction(t *testing.T) {
}

// try again using unconfirmed balance, should work
txnV2 = types.V2Transaction{
txnV3 := types.V2Transaction{
SiacoinOutputs: []types.SiacoinOutput{
{
Address: w.Address(),
Value: sendAmt,
},
},
}
state, toSignV2, err = w.FundV2Transaction(&txnV2, sendAmt, true)
state, toSignV2, err = w.FundV2Transaction(&txnV3, sendAmt, true)
if err != nil {
t.Fatal(err)
}
w.SignV2Inputs(state, &txnV2, toSignV2)
_, err = cm.AddV2PoolTransactions(cm.Tip(), []types.V2Transaction{txnV2})
w.SignV2Inputs(state, &txnV3, toSignV2)
_, err = cm.AddV2PoolTransactions(cm.Tip(), []types.V2Transaction{txnV2, txnV3})
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit c13491e

Please sign in to comment.