/
address.go
40 lines (32 loc) · 1.02 KB
/
address.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
package address
import (
"github.com/iotaledger/hive.go/stringify"
"github.com/mr-tron/base58"
"github.com/iotaledger/goshimmer/packages/ledgerstate"
)
// Address represents an address in a wallet. It extends the normal address type with an index number that was used to
// generate the address from its seed.
type Address struct {
AddressBytes [ledgerstate.AddressLength]byte
Index uint64
}
// Address returns the ledgerstate Address of this wallet Address.
func (a Address) Address() (ledgerStateAddress ledgerstate.Address) {
ledgerStateAddress, _, err := ledgerstate.AddressFromBytes(a.AddressBytes[:])
if err != nil {
panic(err)
}
return
}
// Base58 returns the base58 encoded address.
func (a Address) Base58() string {
return base58.Encode(a.AddressBytes[:])
}
func (a Address) String() string {
return stringify.Struct("Address",
stringify.StructField("Address", a.Address()),
stringify.StructField("Index", a.Index),
)
}
// AddressEmpty represents the 0-value of an address.
var AddressEmpty = Address{}