-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathapi.go
More file actions
74 lines (65 loc) · 2.07 KB
/
Copy pathapi.go
File metadata and controls
74 lines (65 loc) · 2.07 KB
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
67
68
69
70
71
72
73
74
package template
/*
The api.go defines the methods that can be called from the outside. Most
of the methods will take a roster so that the service knows which nodes
it should work with.
This part of the service runs on the client or the app.
*/
import (
"github.com/cypherium_private/mvp/blockchain"
"github.com/dedis/cothority"
"github.com/dedis/onet"
"github.com/dedis/onet/log"
"github.com/dedis/onet/network"
)
// ServiceName is used for registration on the onet.
const ServiceName = "Template"
// Client is a structure to communicate with the template
// service
type Client struct {
*onet.Client
}
// NewClient instantiates a new template.Client
func NewClient() *Client {
return &Client{Client: onet.NewClient(cothority.Suite, ServiceName)}
}
// Clock chooses one server from the Roster at random. It
// sends a Clock to it, which is then processed on the server side
// via the code in the service package.
//
// Clock will return the time in seconds it took to run the protocol.
func (c *Client) Clock(r *onet.Roster) (*ClockReply, error) {
dst := r.RandomServerIdentity()
log.Lvl4("Sending message to", dst)
reply := &ClockReply{}
err := c.SendProtobuf(dst, &Clock{r}, reply)
if err != nil {
return nil, err
}
return reply, nil
}
// Count will return the number of times `Clock` has been called on this
// service-node.
func (c *Client) Count(si *network.ServerIdentity) (int, error) {
reply := &CountReply{}
err := c.SendProtobuf(si, &Count{}, reply)
if err != nil {
return -1, err
}
return reply.Count, nil
}
// Send chooses one server from the Roster at random. It
// sends a transactions to it, which is then processed on the server side
// via the code in the service package.
//
// Send will return the result status to run the protocol.
func (c *Client) Send(r *onet.Roster, transactions []blockchain.STransaction) (*TransReply, error) {
dst := r.RandomServerIdentity()
log.Lvl4("Sending message to", dst)
reply := &TransReply{}
err := c.SendProtobuf(dst, &Transaction{Roster: r, TransMsg: transactions}, reply)
if err != nil {
return nil, err
}
return reply, nil
}