-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Transaction Command #120
Conversation
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.
Really like the create transaction flow. We need to consider how we compute wallet balances, but we can leave that to a different PR. It's quite a large task and out of scope of this issue.
func getCurrentUser() *User { | ||
// TODO: Check for local user information on disk, | ||
// If doesnt exist, create new user. | ||
return NewUser() | ||
} | ||
|
||
// Pay pays an amount of coin to an address `to`. | ||
func (a *App) Pay(to string, amount uint64) error { |
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 think we need to make some changes to this function.
We should:
- Create a signed transaction
- Broadcast it to all connected nodes
Independently of this function, the balance of the current user's wallet should be computed each time a new block is added to our chain.
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.
Good point, so the wallet balance is only updated when our transaction has landed in a block - makes total sense.
blockchain/wallet.go
Outdated
Public() Address | ||
Sign(digest Hash, random io.Reader) (Signature, error) | ||
Debit(amount uint64) error |
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.
Similar to above, I don't think we should modify a user account directly, it should be a function of the blockchain and should be recomputed each time we add a block to the chain.
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.
Looking good
// The transaction must be signed. | ||
if txn, err := tbody.Sign(*a.CurrentUser.Wallet, crand.Reader); err == nil { | ||
|
||
// The transaction must be broadcasted to the peers. |
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.
The comment here doesn't fit what's happening
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.
Fixed up in inputs PR 😅
func (w *Wallet) GetEffectiveBalance() uint64 { | ||
r := w.Balance | ||
for _, t := range w.PendingTxns { | ||
r -= t.GetTotalOutput() |
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.
Is this mathematically correct? Won't part of the output to each transaction go back to the sender, meaning the total output is not actually how much you're spending?
Status: Open for visibility
Related Issue
101
Description
Transactions
,Wallets
,console
etc.Address
.WIKI Updates
Todos
Wallet
methods.Wallet
when new blocks come in to kill pending transactions.General: