This repository was archived by the owner on Sep 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.go
65 lines (57 loc) · 1.74 KB
/
api.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
// Package muse provides a Sia contract server and client.
package muse // import "lukechampine.com/muse"
import (
"crypto/ed25519"
"encoding/json"
"go.sia.tech/siad/modules"
"go.sia.tech/siad/types"
"lukechampine.com/us/hostdb"
"lukechampine.com/us/renter"
)
// A Contract represents a Sia file contract, along with additional metadata.
type Contract struct {
renter.Contract
HostAddress modules.NetAddress
EndHeight types.BlockHeight
}
type responseContracts []Contract
// MarshalJSON implements json.Marshaler.
func (r responseContracts) MarshalJSON() ([]byte, error) {
enc := make([]struct {
HostKey hostdb.HostPublicKey `json:"hostKey"`
ID types.FileContractID `json:"id"`
RenterKey ed25519.PrivateKey `json:"renterKey"`
HostAddress modules.NetAddress `json:"hostAddress"`
EndHeight types.BlockHeight `json:"endHeight"`
}, len(r))
for i := range enc {
enc[i].HostKey = r[i].HostKey
enc[i].ID = r[i].ID
enc[i].RenterKey = r[i].RenterKey
enc[i].HostAddress = r[i].HostAddress
enc[i].EndHeight = r[i].EndHeight
}
return json.Marshal(enc)
}
// RequestForm is the request type for the /form endpoint.
type RequestForm struct {
HostKey hostdb.HostPublicKey
Funds types.Currency
StartHeight types.BlockHeight
EndHeight types.BlockHeight
Settings hostdb.HostSettings
}
// RequestRenew is the request type for the /renew endpoint.
type RequestRenew struct {
ID types.FileContractID
Funds types.Currency
StartHeight types.BlockHeight
EndHeight types.BlockHeight
Settings hostdb.HostSettings
HostKey hostdb.HostPublicKey
RenterKey ed25519.PrivateKey
}
// RequestScan is the request type for the /scan endpoint.
type RequestScan struct {
HostKey hostdb.HostPublicKey
}