add documentation for AccountID
@@ -7,12 +7,15 @@ import (
"github.com/hashgraph/hedera-sdk-go/proto"
)
+// AccountID is the ID for a Hedera account
type AccountID struct {
Shard uint64
Realm uint64
Account uint64
}
+// AccountIDFromString constructs an AccountID from a string formatted as
+// `Shard.Realm.Account` (for example "0.0.3")
func AccountIDFromString(s string) (AccountID, error) {
shard, realm, num, err := idFromString(s)
if err != nil {
@@ -26,6 +29,8 @@ func AccountIDFromString(s string) (AccountID, error) {
}, nil
}
+// AccountIDFromSolidityAddress constructs an AccountID from a string
+// representation of a solidity address
func AccountIDFromSolidityAddress(s string) (AccountID, error) {
shard, realm, account, err := idFromSolidityAddress(s)
if err != nil {
@@ -39,10 +44,14 @@ func AccountIDFromSolidityAddress(s string) (AccountID, error) {
}, nil
}
+// String returns the string representation of an AccountID in
+// `Shart.Realm.Account` (for example "0.0.3")
func (id AccountID) String() string {
return fmt.Sprintf("%d.%d.%d", id.Shard, id.Realm, id.Account)
}
+// ToSolidityAddress returns the string representation of the AccountID as a
+// solidity address.
func (id AccountID) ToSolidityAddress() string {
return idToSolidityAddress(id.Shard, id.Realm, id.Account)
}
@@ -55,6 +64,7 @@ func (id AccountID) toProto() *proto.AccountID {
}
}
+// UnmarshalJSON implements the encoding.JSON interface.
func (id *AccountID) UnmarshalJSON(data []byte) error {
accountId, err := AccountIDFromString(strings.Replace(string(data), "\"", "", 2))
