Skip to content

Commit

Permalink
Merge c9cea3e into 0c6862b
Browse files Browse the repository at this point in the history
  • Loading branch information
chadlagore committed Jul 23, 2017
2 parents 0c6862b + c9cea3e commit 19e5aeb
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 10 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ cumulus:
test:
go test $(PACKAGES) --cover

run-console:
make clean && make cumulus && ./cumulus run -c

deps:
glide install

clean:
rm cumulus
rm cumulus || true

install-glide:
sh scripts/install_glide.sh
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func Run(cfg conf.Config) {
if err != nil {
log.WithError(err).Fatal("Failed to redirect logs to log file")
}
log.Warn("Redirecting logs to logfile")
log.Info("Redirecting logs to logfile")
log.SetOutput(logFile)
go RunConsole()
}
Expand Down
15 changes: 13 additions & 2 deletions app/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/ubclaunchpad/cumulus/blockchain"
"github.com/ubclaunchpad/cumulus/conn"
"github.com/ubclaunchpad/cumulus/peer"
"gopkg.in/kyokomi/emoji.v1"
)

var shell *ishell.Shell
Expand Down Expand Up @@ -42,7 +43,7 @@ func RunConsole() {
})

shell.Start()
shell.Println("Cumulus Console")
emoji.Println(":cloud: Welcome to the :sunny: Cumulus console :cloud:")
}

func create(ctx *ishell.Context) {
Expand All @@ -51,7 +52,7 @@ func create(ctx *ishell.Context) {
"Transaction",
}, "What would you like to create?")
if choice == 0 {
ctx.Println("New Wallet:", blockchain.NewWallet().Public())
createHotWallet(ctx)
} else {
shell.Print("Sender wallet ID: ")
senderID := shell.ReadLine()
Expand Down Expand Up @@ -109,3 +110,13 @@ func connect(ctx *ishell.Context) {
shell.Println("Connected to", addr)
}
}

func createHotWallet(ctx *ishell.Context) {
shell.Print("Enter wallet name: ")
walletName := shell.ReadLine()
wallet := HotWallet{walletName, blockchain.NewWallet()}
currentUser.HotWallet = wallet
emoji.Println(":credit_card: New hot wallet created!")
emoji.Println(":raising_hand: Name: " + wallet.Name)
emoji.Println(":mailbox: Address: " + wallet.Wallet.Public().Repr())
}
15 changes: 12 additions & 3 deletions app/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ import "github.com/ubclaunchpad/cumulus/blockchain"

// User holds basic user information.
type User struct {
// Wallet holds the users wallets (currently just support 1).
Wallet blockchain.Wallet
// Account holds the users wallet(s).
HotWallet
// UserBlockSize is the maximum size of a block in bytes when marshaled
// as specified by the user.
BlockSize uint32
}

// HotWallet is a representation of the users wallet.
type HotWallet struct {
Name string
blockchain.Wallet
}

var currentUser *User

const defaultBlockSize = 1 << 18
Expand All @@ -23,7 +29,10 @@ func init() {
// NewUser creates a new user
func NewUser() *User {
return &User{
Wallet: blockchain.NewWallet(),
HotWallet: HotWallet{
Wallet: blockchain.NewWallet(),
Name: "default",
},
BlockSize: defaultBlockSize,
}
}
Expand Down
6 changes: 6 additions & 0 deletions blockchain/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

log "github.com/Sirupsen/logrus"
"github.com/stretchr/testify/assert"
)

func TestMain(t *testing.T) {
Expand Down Expand Up @@ -38,3 +39,8 @@ func TestCopyBlock(t *testing.T) {
t.FailNow()
}
}

func TestWalletRepr(t *testing.T) {
w := NewWallet()
assert.Equal(t, len(w.Public().Repr()), 40)
}
26 changes: 26 additions & 0 deletions blockchain/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"crypto/ecdsa"
"crypto/elliptic"
crand "crypto/rand"
"crypto/sha256"
"encoding/hex"
"io"
"math/big"

Expand All @@ -17,6 +19,8 @@ const (
AddrLen = 2 * CoordLen
// SigLen is the length in bytes of signatures.
SigLen = AddrLen
// AddressVersion is the version of the address shortening protocol.
AddressVersion = 0
)

var (
Expand All @@ -33,6 +37,28 @@ type Address struct {
X, Y *big.Int
}

// Repr returns a string representation of the address. We follow
// ethereums protocol, replacing Keccak hash with SHA256.
// Where pr is the private key.
// A(pr) = SHA256(ECDSAPUBLICKEY(pr))[96:255],
// Resources:
// http://gavwood.com/paper.pdf (fig 213)
func (a Address) Repr() string {
// 1. Concatenate X and Y and version the result.
concat := a.Marshal()
prefix := append([]byte{AddressVersion}, concat...)

// 2. Perform SHA-256 on result.
hash := sha256.Sum256(prefix) // 256 bit

return hex.EncodeToString(hash[96/8 : 256/8])
}

// Emoji returns the users address as a string of emojis (TODO).
func (a Address) Emoji() string {
return a.Repr()
}

// Marshal converts an Address to a byte slice.
func (a Address) Marshal() []byte {
buf := make([]byte, 0, AddrLen)
Expand Down
14 changes: 11 additions & 3 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ import:
subpackages:
- assert
- package: github.com/abiosoft/ishell
- package: gopkg.in/kyokomi/emoji.v1
version: ^1.5.0

0 comments on commit 19e5aeb

Please sign in to comment.