forked from hiero-ledger/hiero-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconsensus_topic_id.go
48 lines (41 loc) · 1.16 KB
/
consensus_topic_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
package hedera
import (
"fmt"
"github.com/hashgraph/hedera-sdk-go/proto"
)
// ConsensusTopicID is a unique identifier for a topic (used by the consensus service)
type ConsensusTopicID struct {
Shard uint64
Realm uint64
Topic uint64
}
// TopicIDFromString constructs a TopicID from a string formatted as `Shard.Realm.Topic` (for example "0.0.3")
func TopicIDFromString(s string) (ConsensusTopicID, error) {
shard, realm, num, err := idFromString(s)
if err != nil {
return ConsensusTopicID{}, err
}
return ConsensusTopicID{
Shard: uint64(shard),
Realm: uint64(realm),
Topic: uint64(num),
}, nil
}
// String returns the string representation of a TopicID in `Shard.Realm.Topic` (for example "0.0.3")
func (id ConsensusTopicID) String() string {
return fmt.Sprintf("%d.%d.%d", id.Shard, id.Realm, id.Topic)
}
func (id ConsensusTopicID) toProto() *proto.TopicID {
return &proto.TopicID{
ShardNum: int64(id.Shard),
RealmNum: int64(id.Realm),
TopicNum: int64(id.Topic),
}
}
func consensusTopicIDFromProto(pb *proto.TopicID) ConsensusTopicID {
return ConsensusTopicID{
Shard: uint64(pb.ShardNum),
Realm: uint64(pb.RealmNum),
Topic: uint64(pb.TopicNum),
}
}