-
Notifications
You must be signed in to change notification settings - Fork 440
Add support for offline transaction signing #2907
base: master
Are you sure you want to change the base?
Changes from 1 commit
d39e94f
1c7efd4
4fa416a
e959025
6332d01
b3741e7
41c5410
32059e7
277d93a
873500b
043674b
a2bcb24
90566ab
d408cc1
4050676
64ff690
78c2a13
d2c89fc
c5098c8
c1c14d7
0514348
6b22c87
477a497
c36c14e
30a5854
83967e1
4fccafd
c97a9d7
f174e41
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package wallet | |
import ( | ||
"bytes" | ||
"errors" | ||
"math" | ||
"sort" | ||
|
||
"github.com/NebulousLabs/Sia/crypto" | ||
|
@@ -642,6 +643,7 @@ func (w *Wallet) SpendableOutputs() []modules.SpendableOutput { | |
// ensure durability of reported outputs | ||
w.syncDB() | ||
|
||
// build initial list of confirmed outputs | ||
var outputs []modules.SpendableOutput | ||
dbForEachSiacoinOutput(w.dbTx, func(scoid types.SiacoinOutputID, sco types.SiacoinOutput) { | ||
outputs = append(outputs, modules.SpendableOutput{ | ||
|
@@ -660,6 +662,23 @@ func (w *Wallet) SpendableOutputs() []modules.SpendableOutput { | |
}) | ||
}) | ||
|
||
// don't include outputs marked as spent in pending transactions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DavidVorick this seemed like a reasonable thing to do, but would like to hear your thoughts |
||
pending := make(map[types.OutputID]struct{}) | ||
for _, pt := range w.unconfirmedProcessedTransactions { | ||
for _, input := range pt.Inputs { | ||
if input.WalletAddress { | ||
pending[input.ParentID] = struct{}{} | ||
} | ||
} | ||
} | ||
filtered := outputs[:0] | ||
for _, o := range outputs { | ||
if _, ok := pending[o.ID]; !ok { | ||
filtered = append(filtered, o) | ||
} | ||
} | ||
outputs = filtered | ||
|
||
// set the confirmation height for each output | ||
outer: | ||
for i, o := range outputs { | ||
|
@@ -678,6 +697,21 @@ outer: | |
} | ||
} | ||
|
||
// add unconfirmed outputs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto here |
||
for _, pt := range w.unconfirmedProcessedTransactions { | ||
for _, o := range pt.Outputs { | ||
if o.WalletAddress { | ||
outputs = append(outputs, modules.SpendableOutput{ | ||
FundType: types.SpecifierSiacoinOutput, | ||
ID: o.ID, | ||
UnlockHash: o.RelatedAddress, | ||
Value: o.Value, | ||
ConfirmationHeight: types.BlockHeight(math.MaxUint64), // unconfirmed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure what the best approach is here. I guess this is an argument for making the field |
||
}) | ||
} | ||
} | ||
} | ||
|
||
return outputs | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to sync here? Once you got the outputs and created a transaction, the transaction pool will decide if the transaction is valid. Therefore I think it is not really an issue if the output disappears from the wallet due to a crash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's more about the principle. If the wallet reports that it has an output, and then it crashes, it should still have that output next time you ask it. The general rule is: "don't give the user any data that won't survive a crash."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see 👍