-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
160 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ run-console: cumulus | |
deps: | ||
glide install | ||
|
||
clean: | ||
clean: cumulus | ||
rm cumulus | ||
|
||
install-glide: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,58 @@ | ||
package app | ||
|
||
import "github.com/ubclaunchpad/cumulus/blockchain" | ||
import ( | ||
"github.com/ubclaunchpad/cumulus/blockchain" | ||
"github.com/ubclaunchpad/cumulus/msg" | ||
|
||
crand "crypto/rand" | ||
) | ||
|
||
// User holds basic user information. | ||
type User struct { | ||
HotWallet | ||
*blockchain.Wallet | ||
BlockSize uint32 | ||
} | ||
|
||
// HotWallet is a representation of the users wallet. | ||
type HotWallet struct { | ||
Name string | ||
blockchain.Wallet | ||
} | ||
|
||
// NewUser creates a new user | ||
func NewUser() *User { | ||
return &User{ | ||
HotWallet: HotWallet{ | ||
Wallet: blockchain.NewWallet(), | ||
Name: "default", | ||
}, | ||
Wallet: blockchain.NewWallet(), | ||
BlockSize: blockchain.DefaultBlockSize, | ||
} | ||
} | ||
|
||
// getCurrentUser gets the current user. | ||
// getCurrentUser gets the current user function only used for app initalization. | ||
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 { | ||
// Two atomic steps must occur. | ||
|
||
// 1. A legitimate transaction must be built. | ||
tbody := blockchain.TxBody{ | ||
Sender: getCurrentUser().Wallet.Public(), | ||
Outputs: []blockchain.TxOutput{ | ||
blockchain.TxOutput{ | ||
Recipient: to, | ||
Amount: amount, | ||
}, | ||
}, | ||
} | ||
|
||
// 2. The transaction must be signed and broadcasted. | ||
if txn, err := tbody.Sign(*a.CurrentUser.Wallet, crand.Reader); err != nil { | ||
a.PeerStore.Broadcast(msg.Push{ | ||
ResourceType: msg.ResourceTransaction, | ||
Resource: txn, | ||
}) | ||
a.CurrentUser.Wallet.SetPending(txn) | ||
} else { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.