-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpackages.go
53 lines (43 loc) · 957 Bytes
/
packages.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
package mscrpc
import (
"net/rpc"
"fmt"
)
// Simplistic argument structure
// Validates amount of arguments and throws
// errors if it's unable to satisfy.
type Args struct {
Vals []interface{}
}
func NewArgs() *Args {
return &Args{}
}
func (args *Args) Add(v interface{}) *Args {
args.Vals = append(args.Vals, v)
// Returns args so we can chain
return args
}
func (args *Args) Require(num int) error {
l := len(args.Vals)
if l != num {
return fmt.Errorf("invalid args %d for %d", l, num)
}
return nil
}
type SimpleSendPackage struct {}
func (p *SimpleSendPackage) ListTxs(args *Args, reply *int) error {
return nil
}
func (p *SimpleSendPackage) CreateTx(args *Args, reply *string) error {
// Require 2: receiver, amount (In that order)
err := args.Require(2)
if err != nil {
return err
}
*reply = "Test"
return nil
}
// Registers all RPC packages
func RegisterPackagesRpcPackages() {
rpc.Register(new(SimpleSendPackage))
}