-
Notifications
You must be signed in to change notification settings - Fork 65
/
file_id.go
77 lines (64 loc) · 1.44 KB
/
file_id.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
67
68
69
70
71
72
73
74
75
76
77
package hedera
import (
"fmt"
"github.com/hashgraph/hedera-sdk-go/proto"
)
type FileID struct {
Shard uint64
Realm uint64
File uint64
}
// The public node address book for the current network
func FileIDForAddressBook() FileID {
return FileID{File: 102}
}
// The current fee schedule for the network
func FileIDForFeeSchedule() FileID {
return FileID{File: 111}
}
// The current exchange rates of HBAR to USD
func FileIDForExchangeRate() FileID {
return FileID{File: 112}
}
func FileIDFromString(s string) (FileID, error) {
shard, realm, num, err := idFromString(s)
if err != nil {
return FileID{}, err
}
return FileID{
Shard: uint64(shard),
Realm: uint64(realm),
File: uint64(num),
}, nil
}
func FileIDFromSolidityAddress(s string) (FileID, error) {
shard, realm, file, err := idFromSolidityAddress(s)
if err != nil {
return FileID{}, err
}
return FileID{
Shard: shard,
Realm: realm,
File: file,
}, nil
}
func (id FileID) String() string {
return fmt.Sprintf("%d.%d.%d", id.Shard, id.Realm, id.File)
}
func (id FileID) ToSolidityAddress() string {
return idToSolidityAddress(id.Shard, id.Realm, id.File)
}
func (id FileID) toProto() *proto.FileID {
return &proto.FileID{
ShardNum: int64(id.Shard),
RealmNum: int64(id.Realm),
FileNum: int64(id.File),
}
}
func fileIDFromProto(pb *proto.FileID) FileID {
return FileID{
Shard: uint64(pb.ShardNum),
Realm: uint64(pb.RealmNum),
File: uint64(pb.FileNum),
}
}