Skip to content
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

Added Dockerfile #1

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
duckcoin
9 changes: 9 additions & 0 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM golang:alpine

WORKDIR /go/src/app

COPY . .

RUN go build

ENTRYPOINT [ "./duckcoin" ]
17 changes: 17 additions & 0 deletions client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Duckcoin CLI Client

## Usage

### Unix

```sh
$ go build
$ ./duckcoin
```

### Docker

```sh
$ docker build -t duckcoin-client .
$ docker run -it -d -v $HOME/.config/duckcoin:/root/.config/duckcoin -e NAME=$USER --name duckcoin-client duckcoin-client
```
Binary file added client/duckcoin.exe
Binary file not shown.
60 changes: 51 additions & 9 deletions client/duckcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ When run without arguments, Duckcoin mines Quacks to the key in ~/.config/duckco
Examples:
duckcoin
duckcoin 4 # mines 4 blocks
duckcoin 1 -t nSvl+K7RauJ5IagU+ID/slhDoR+435+NSLHOXzFBRmo= -a 3 -m "Payment of 1 Quack to Ishan"`
duckcoin 1 -t nSvl+K7RauJ5IagU+ID/slhDoR+435+NSLHOXzFBRmo= -a 3 -m "Payment of 3 Quacks to Ishan"`
)

type Block struct {
Expand Down Expand Up @@ -87,6 +87,10 @@ func main() {
data := ""
numOfBlocks = math.MaxInt64

if os.Getenv("NAME") != "" {
username = os.Getenv("NAME")
}

if ok, _ := argsHaveOption("help", "h"); ok {
fmt.Println(helpMsg)
return
Expand Down Expand Up @@ -151,9 +155,9 @@ func main() {

var i int64
//stopChan := make(chan struct{})
doneChan := make(chan interface{}, 1)
blockChan := make(chan Block, 1)
for ; i < numOfBlocks; i++ {
doneChan := make(chan interface{}, 1)
blockChan := make(chan Block, 1)
r, err := http.Get(url + "/blocks/newest")
if err != nil {
fmt.Println(err)
Expand All @@ -174,6 +178,7 @@ func main() {
select {
case <-doneChan:
//fmt.Println("Stopping mining")
//close(blockChan)
break Monitor
default:
c := time.After(time.Second)
Expand All @@ -191,12 +196,12 @@ func main() {
//i--
//break Monitor
}
fmt.Println("Monitor")
//fmt.Println("Monitor")
<-c
//time.Sleep(time.Second / 2)
}
}
fmt.Println("Next block")
//fmt.Println("Next block")
//resp, ierr := ioutil.ReadAll(r.Body)
//if ierr != nil {
// fmt.Println(ierr)
Expand Down Expand Up @@ -237,16 +242,19 @@ Mine:
for i := 0; ; i++ {
select {
case b := <-blockChan:
//if b == *new(Block) {
// break Mine
//}
if oldBlock != b {
oldBlock = b
//fmt.Println("Stopping mining")
fmt.Println("Restart, someone already mined block number " + strconv.FormatInt(newBlock.Index, 10))
goto Start
}
default:
newBlock.Solution = strconv.Itoa(i)
if !isHashSolution(calculateHash(newBlock)) {
if i%100000 == 0 {
fmt.Println(i)
if i%100000 == 0 && i != 0 {
fmt.Printf("Approx hashrate: %0.2f. Have checked %d hashes.\n", float64(i)/time.Since(t).Seconds(), i)
}
// fmt.Println(calculateHash(newBlock))
//time.Sleep(time.Second)
Expand Down Expand Up @@ -276,7 +284,7 @@ Mine:
}
}
}
fmt.Println("Stopping mining")
//fmt.Println("Stopping mining")
return
}

Expand Down Expand Up @@ -447,9 +455,43 @@ func makeSignature(privkey string, message string) (string, error) {
return b64(data), nil
}

//type Block struct {
// // Index is the Block number in the Icoin Blockchain
// Index int64
// // Timestamp is the Unix timestamp of the date of creation of this Block
// Timestamp int64
// // Data stores any (arbitrary) additional data.
// Data string
// //Hash stores the hex value of the sha256 sum of the block represented as JSON with the indent as " " and Hash as ""
// Hash string
// // PrevHash is the hash of the previous Block in the Blockchain
// PrevHash string
// // Solution is the nonce value that makes the Hash have a prefix of Difficulty zeros
// Solution string
// // Solver is the public key of the sender
// Solver string
// // Transaction is the transaction associated with this block
// Tx Transaction
//}
//
//type Transaction struct {
// // Data is any (arbitrary) additional data.
// Data string
// //Sender is the address of the sender.
// Sender string
// //Receiver is the address of the receiver.
// Receiver string
// //Amount is the amount to be payed by the Sender to the Receiver. It is always a positive number.
// Amount int
// //PubKey is the Duckcoin formatted public key of the sender
// PubKey string
// Signature string
//}

func calculateHash(block Block) string {
block.Hash = ""
block.Tx.Signature = ""
//s :=
return shasum([]byte(toJson(block)))
}

Expand Down