-
Notifications
You must be signed in to change notification settings - Fork 1
/
contracts.go
56 lines (46 loc) · 1.38 KB
/
contracts.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
package wow
import "encoding/gob"
type CostFunction = int
const (
Sha256 CostFunction = iota
)
type ChallengeRequest struct {
}
type Challenge struct {
// What function to be used to search for an answer
CostFunction CostFunction
// Starting number from where the search for the solution should start (inclusive)
// Big-endian unsigned integer
BlockStart []byte
// End number where the search for the solution should stop (exclusive)
// Big-endian unsigned integer
BlockEnd []byte
// Required number of zero bits in the beginning of CostFunction output
Difficulty int
// time in Unix seconds, when the challenge expires
ExpireAt int64
}
type ChallengeResponse struct {
// Challenge, which should be solved
Challenge *Challenge
// Challenge signature, which should be passed as-is with further requests
Signature []byte
}
type QuoteRequest struct {
ChallengeResponse
// Solution of the challenge on the range starting from BlockStart to BlockEnd
// CostFunction applied on the Solution should return the result, which has number of leading zero bytes equal to
// Difficulty.
// Big-endian unsigned integer
Solution []byte
}
type QuoteResponse struct {
Quote string
}
func init() {
// required for encoding/decoding to/from interface work
gob.Register(&ChallengeRequest{})
gob.Register(&ChallengeResponse{})
gob.Register(&QuoteRequest{})
gob.Register(&QuoteResponse{})
}