-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathart-app4.go
66 lines (57 loc) · 1.6 KB
/
art-app4.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
A trivial application to illustrate how the blockartlib library can be
used from an application in project 1 for UBC CS 416 2017W2.
Usage:
go run art-app.go
*/
package main
import (
"blockartlib"
"fmt"
"keys"
"os"
)
func main() {
validateNum := 0 // TODO: Change this to a bigger number for submission
shapes := []string{}
blocks := []string{}
minerAddr := os.Args[1]
privateKey, _, err := keys.Generate()
fmt.Printf("%v\n", privateKey.PublicKey)
colour := "black"
// Open a canvas.
// TODO: use settings
fmt.Printf("ART-APP: Calling OpenCanvas to Miner with address %s\n", minerAddr)
canvas, _, err := blockartlib.OpenCanvas(minerAddr, *privateKey)
fmt.Println("ART-APP: Canvas is ", canvas)
if checkError(err) != nil {
fmt.Println("ART-APP: there was an error opening the canvas", err)
return
}
// Draw squares along left side
for i := 0; i < 5000; i++ {
fmt.Printf("ART-APP2: Drawing square at x = %v.\n", i)
svg := fmt.Sprintf("M 1 , %v h 1 v 1 h -1 v -1", i, i)
shapeHash, blockHash, _, err := canvas.AddShape(uint8(validateNum), blockartlib.PATH, svg, "filled", colour)
if checkError(err) != nil {
fmt.Printf("ART-APP: There was an error with calling AddShape: \n")
fmt.Println(err)
}
shapes = append(shapes, shapeHash)
blocks = append(blocks, blockHash)
}
fmt.Println("Closing the canvas")
// Close the canvas.
_, err = canvas.CloseCanvas()
if checkError(err) != nil {
return
}
}
// If error is non-nil, print it out and return it.
func checkError(err error) error {
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err.Error())
return err
}
return nil
}